diff --git a/htdocs/holiday/define_holiday.php b/htdocs/holiday/define_holiday.php index 0a557b0db76..85de7b09f61 100644 --- a/htdocs/holiday/define_holiday.php +++ b/htdocs/holiday/define_holiday.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2007-2022 Laurent Destailleur * Copyright (C) 2011 Dimitri Mouillard * Copyright (C) 2013 Marcos García * Copyright (C) 2016 Regis Houssin @@ -130,12 +130,15 @@ if (empty($reshook)) { // Si il y a une action de mise à jour if ($action == 'update' && GETPOSTISSET('update_cp')) { $error = 0; + $nbok = 0; $typeleaves = $holiday->getTypes(1, 1); $userID = array_keys(GETPOST('update_cp')); $userID = $userID[0]; + $db->begin(); + foreach ($typeleaves as $key => $val) { $userValue = GETPOST('nb_holiday_'.$val['rowid']); $userValue = $userValue[$userID]; @@ -150,20 +153,26 @@ if (empty($reshook)) { $note_holiday = GETPOST('note_holiday'); $comment = ((isset($note_holiday[$userID]) && !empty($note_holiday[$userID])) ? ' ('.$note_holiday[$userID].')' : ''); - //print 'holiday: '.$val['rowid'].'-'.$userValue; + //print 'holiday: '.$val['rowid'].'-'.$userValue;exit; if ($userValue != '') { - // We add the modification to the log (must be before update of sold because we read current value of sold) + // We add the modification to the log (must be done before the update of balance because we read current value of balance inside this method) $result = $holiday->addLogCP($user->id, $userID, $langs->transnoentitiesnoconv('ManualUpdate').$comment, $userValue, $val['rowid']); if ($result < 0) { setEventMessages($holiday->error, $holiday->errors, 'errors'); $error++; + } elseif ($result == 0) { + setEventMessages($langs->trans("HolidayQtyNotModified", $user->login), null, 'warnings'); } // Update of the days of the employee - $result = $holiday->updateSoldeCP($userID, $userValue, $val['rowid']); - if ($result < 0) { - setEventMessages($holiday->error, $holiday->errors, 'errors'); - $error++; + if ($result > 0) { + $nbok++; + + $result = $holiday->updateSoldeCP($userID, $userValue, $val['rowid']); + if ($result < 0) { + setEventMessages($holiday->error, $holiday->errors, 'errors'); + $error++; + } } // If it first update of balance, we set date to avoid to have sold incremented by new month @@ -179,7 +188,13 @@ if (empty($reshook)) { } if (!$error) { - setEventMessages('UpdateConfCPOK', '', 'mesgs'); + $db->commit(); + + if ($nbok > 0) { + setEventMessages('UpdateConfCPOK', '', 'mesgs'); + } + } else { + $db->rollback(); } } } diff --git a/htdocs/holiday/view_log.php b/htdocs/holiday/view_log.php index 57bcd134745..8396444719e 100644 --- a/htdocs/holiday/view_log.php +++ b/htdocs/holiday/view_log.php @@ -159,15 +159,15 @@ if (empty($reshook)) { // Definition of fields for lists $arrayfields = array( - 'cpl.rowid'=>array('label'=>$langs->trans("ID"), 'checked'=>1), - 'cpl.date_action'=>array('label'=>$langs->trans("Date"), 'checked'=>1), - 'cpl.fk_user_action'=>array('label'=>$langs->trans("ActionByCP"), 'checked'=>1), - 'cpl.fk_user_update'=>array('label'=>$langs->trans("UserUpdateCP"), 'checked'=>1), - 'cpl.type_action'=>array('label'=>$langs->trans("Description"), 'checked'=>1), - 'cpl.fk_type'=>array('label'=>$langs->trans("Type"), 'checked'=>1), - 'cpl.prev_solde'=>array('label'=>$langs->trans("PrevSoldeCP"), 'checked'=>1), - 'variation'=>array('label'=>$langs->trans("Variation"), 'checked'=>1), - 'cpl.new_solde'=>array('label'=>$langs->trans("NewSoldeCP"), 'checked'=>1), + 'cpl.rowid'=>array('label'=>"ID", 'checked'=>1), + 'cpl.date_action'=>array('label'=>"Date", 'checked'=>1), + 'cpl.fk_user_action'=>array('label'=>"ActionByCP", 'checked'=>1), + 'cpl.fk_user_update'=>array('label'=>"UserUpdateCP", 'checked'=>1), + 'cpl.type_action'=>array('label'=>"Description", 'checked'=>1), + 'cpl.fk_type'=>array('label'=>"Type", 'checked'=>1), + 'cpl.prev_solde'=>array('label'=>"PrevSoldeCP", 'checked'=>1), + 'variation'=>array('label'=>"Variation", 'checked'=>1), + 'cpl.new_solde'=>array('label'=>"NewSoldeCP", 'checked'=>1), ); @@ -403,7 +403,7 @@ print ''; print ''; if (!empty($arrayfields['cpl.rowid']['checked'])) { - print_liste_field_titre($arrayfields['cpl.rowid']['label'], $_SERVER["PHP_SELF"], 'rowid', '', '', '', $sortfield, $sortorder); + print_liste_field_titre($arrayfields['cpl.rowid']['label'], $_SERVER["PHP_SELF"], 'cpl.rowid', '', '', '', $sortfield, $sortorder); } if (!empty($arrayfields['cpl.date_action']['checked'])) { print_liste_field_titre($arrayfields['cpl.date_action']['label'], $_SERVER["PHP_SELF"], 'date_action', '', '', '', $sortfield, $sortorder, 'center '); @@ -484,7 +484,7 @@ while ($i < min($num, $limit)) { // Description if (!empty($arrayfields['cpl.type_action']['checked'])) { - print ''.$holidaylogstatic->description.''; + print ''.dol_escape_htmltag($holidaylogstatic->description).''; } // Type @@ -510,8 +510,13 @@ while ($i < min($num, $limit)) { // Variation if (!empty($arrayfields['variation']['checked'])) { $delta = price2num($holidaylogstatic->balance_new - $holidaylogstatic->balance_previous, 5); - $detasign = ($delta > 0 ? '+' : ''); - print ''.$detasign.$delta.''; + print ''; + if ($delta > 0) { + print '+'.$delta.''; + } else { + print ''.$delta.''; + } + print ''; } // New Balance diff --git a/htdocs/langs/en_US/holiday.lang b/htdocs/langs/en_US/holiday.lang index 3d0ae64be0f..66b6d83d930 100644 --- a/htdocs/langs/en_US/holiday.lang +++ b/htdocs/langs/en_US/holiday.lang @@ -137,3 +137,4 @@ 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 +HolidayQtyNotModified=Balance of remaining days for %s has not been changed \ No newline at end of file