diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 2854a631e42..aa73c9cdc8a 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1507,6 +1507,57 @@ if (!$error && ($massaction == 'approveleave' || ($action == 'approveleave' && $ } } +if (!$error && ($massaction == 'increaseholiday' || ($action == 'increaseholiday' && $confirm == 'yes')) && $permissiontoapprove) { + $db->begin(); + $objecttmp = new $objectclass($db); + $nbok = 0; + $typeholiday = GETPOST('typeholiday', 'alpha'); + $nbdaysholidays = GETPOST('nbdaysholidays', 'double'); + + if ($nbdaysholidays <= 0) { + setEventMessages($langs->trans("WrongAmount"), "", 'errors'); + $error++; + } + + if (!$error) { + foreach ($toselect as $toselectid) { + $balancecpuser = $objecttmp->getCPforUser($toselectid, $typeholiday); + if (!empty($balancecpuser)) { + $newnbdaysholidays = $nbdaysholidays + $balancecpuser; + } else { + $newnbdaysholidays = $nbdaysholidays; + } + $result = $holiday->addLogCP($user->id, $toselectid, $langs->transnoentitiesnoconv('ManualUpdate'), $newnbdaysholidays, $typeholiday); + if ($result <= 0) { + setEventMessages($holiday->error, $holiday->errors, 'errors'); + $error++; + break; + } + + $objecttmp->updateSoldeCP($toselectid, $newnbdaysholidays, $typeholiday); + if ($result > 0) { + $nbok++; + } else { + setEventMessages("", $langs->trans("ErrorUpdatingUsersCP"), 'errors'); + $error++; + break; + } + } + } + + if (!$error) { + if ($nbok > 1) { + setEventMessages($langs->trans("HolidayRecordsIncreased", $nbok), null, 'mesgs'); + } elseif ($nbok == 1) { + setEventMessages($langs->trans("HolidayRecordIncreased"), null, 'mesgs'); + } + $db->commit(); + $toselect=array(); + } else { + $db->rollback(); + } +} + $parameters['toselect'] = $toselect; $parameters['uploaddir'] = $uploaddir; $parameters['massaction'] = $massaction; diff --git a/htdocs/core/tpl/massactions_pre.tpl.php b/htdocs/core/tpl/massactions_pre.tpl.php index 678bf219bef..d86f8074efd 100644 --- a/htdocs/core/tpl/massactions_pre.tpl.php +++ b/htdocs/core/tpl/massactions_pre.tpl.php @@ -283,6 +283,29 @@ if ($massaction == 'preapproveleave') { print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassLeaveApproval"), $langs->trans("ConfirmMassLeaveApprovalQuestion", count($toselect)), "approveleave", null, 'yes', 0, 200, 500, 1); } +if ($massaction == 'preincreaseholiday') { + $langs->load("holiday", "hrm"); + require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; + $staticholiday = new Holiday($db); + $arraytypeholidays = $staticholiday->getTypes(1, 1); + $formquestion[] = array(); + $labeltypes = array(); + foreach ($typeleaves as $key => $val) { + $labeltypes[$val['id']] = ($langs->trans($val['code']) != $val['code']) ? $langs->trans($val['code']) : $langs->trans($val['label']); + } + $formquestion [] = array( 'type' => 'other', + 'name' => 'typeofholiday', + 'label' => $langs->trans("Type"), + 'value' => $form->selectarray('typeholiday', $labeltypes, GETPOST('typeholiday', 'alpha'), 1) + ); + $formquestion [] = array( 'type' => 'other', + 'name' => 'nbdaysholydays', + 'label' => $langs->trans("NumberDayAddMass"), + 'value' => '' + ); + print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassIncreaseHoliday"), $langs->trans("ConfirmMassIncreaseHolidayQuestion", count($toselect)), "increaseholiday", $formquestion, 1, 0, 200, 500, 1); +} + // Allow Pre-Mass-Action hook (eg for confirmation dialog) $parameters = array( 'toselect' => $toselect, diff --git a/htdocs/holiday/define_holiday.php b/htdocs/holiday/define_holiday.php index 486315f36ac..f47a4128c65 100644 --- a/htdocs/holiday/define_holiday.php +++ b/htdocs/holiday/define_holiday.php @@ -46,6 +46,9 @@ $search_supervisor = GETPOST('search_supervisor', 'int'); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); +$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list +$confirm = GETPOST('confirm', 'alpha'); + $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; @@ -113,14 +116,13 @@ if (empty($reshook)) { } // Mass actions - /* - $objectclass='Skeleton'; - $objectlabel='Skeleton'; - $permissiontoread = $user->rights->skeleton->read; - $permissiontodelete = $user->rights->skeleton->delete; - $uploaddir = $conf->skeleton->dir_output; + $objectclass = 'Holiday'; + $objectlabel = 'Holiday'; + $permissiontoread = $user->hasRight('holiday', 'read'); + $permissiontodelete = $user->hasRight('holiday', 'delete'); + $permissiontoapprove = $user->hasRight('holiday', 'approve'); + $uploaddir = $conf->holiday->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; - */ // Si il y a une action de mise à jour if ($action == 'update' && GETPOSTISSET('update_cp')) { @@ -213,6 +215,17 @@ if ($result < 0) { setEventMessages($holiday->error, $holiday->errors, 'errors'); } +// List of mass actions available +$arrayofmassactions = array( + //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"), + //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), + //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), +); +if ($user->hasRight("holiday", "approve")) { + $arrayofmassactions['preincreaseholiday'] = img_picto('', 'add', 'class="pictofixedwidth"').$langs->trans("IncreaseHolidays"); +} +$massactionbutton = $form->selectMassAction('', $arrayofmassactions); + print '
'; if ($optioncss != '') { @@ -226,7 +239,10 @@ print ''; print ''; print ''; -print load_fiche_titre($langs->trans('MenuConfCP'), '', 'title_hrm.png'); +$title = $langs->trans("MenuConfCP"); +print_barre_liste($title, $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $massactionbutton, '', '', 'title_hrm', 0, '', '', $limit, 0, 0, 1); + +include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; print '
'.$langs->trans('LastUpdateCP').': '."\n"; $lastUpdate = $holiday->getConfCP('lastUpdate'); @@ -298,6 +314,7 @@ if (count($typeleaves) == 0) { print ''; } print ''; + print ''; // Action column print ''; @@ -320,11 +337,19 @@ if (count($typeleaves) == 0) { } print_liste_field_titre((empty($user->rights->holiday->define_holiday) ? '' : 'Note'), $_SERVER["PHP_SELF"]); print_liste_field_titre(''); + + if ($massactionbutton) { + $selectedfields = $form->showCheckAddButtons('checkforselect', 1); + } + + print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); print ''; $usersupervisor = new User($db); foreach ($listUsers as $users) { + $arrayofselected = is_array($toselect) ? $toselect : array(); + // If user has not permission to edit/read all, we must see only subordinates if (empty($user->rights->holiday->readall)) { if (($users['rowid'] != $user->id) && (!in_array($users['rowid'], $userchilds))) { @@ -389,11 +414,21 @@ if (count($typeleaves) == 0) { print ''; // Button modify - print ''; + print ''; if (!empty($user->rights->holiday->define_holiday)) { // Allowed to set the balance of any user print ''; } print ''."\n"; + print ''; + + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + $selected = 0; + if (in_array($userstatic->id, $arrayofselected)) { + $selected = 1; + } + print ''; + } + print ''; print ''; $i++; diff --git a/htdocs/langs/en_US/holiday.lang b/htdocs/langs/en_US/holiday.lang index 95c8f54d211..1921b9ed794 100644 --- a/htdocs/langs/en_US/holiday.lang +++ b/htdocs/langs/en_US/holiday.lang @@ -149,4 +149,10 @@ XIsAUsualNonWorkingDay=%s is usualy a NON working day BlockHolidayIfNegative=Block if balance negative LeaveRequestCreationBlockedBecauseBalanceIsNegative=The creation of this leave request is blocked because your balance is negative ErrorLeaveRequestMustBeDraftCanceledOrRefusedToBeDeleted=Leave request %s must be draft, canceled or refused to be deleted +IncreaseHolidays=Increase holiday +HolidayRecordsIncreased= %s holiday records increased +HolidayRecordIncreased=Holiday record increased +ConfirmMassIncreaseHoliday=Bulk holiday increase +NumberDayAddMass=Number of day to add to the selection +ConfirmMassIncreaseHolidayQuestion=Are you sure you want to increase holiday of the %s selected record(s)? HolidayQtyNotModified=Balance of remaining days for %s has not been changed