diff --git a/ChangeLog b/ChangeLog index d685811b92602d6bcc8401fade215de9b8411c5b..1fe09d88ccfcec2888d23b54965b52bdb7f8b900 100644 --- a/ChangeLog +++ b/ChangeLog @@ -57,6 +57,7 @@ For users: - New: [ task #923 ] Localtax support for ODT templates. - New: [ task #90 ] Barcode search. - New: Can send an email from thirdparty card. +- New: Can cancel holidays that were previously validated. For translators: - Qual: Normalized sort order of all languages files with english reference files. diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index c152895c0d7c52e4c0a9a9ee63a2163f7c8628c9..aefe54908026b82f0bfe314bd1704e0d6cf6685f 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -506,9 +506,9 @@ if ($step == 2 && $datatoexport) print '<td>'.$langs->trans("Entities").'</td>'; print '<td>'.$langs->trans("ExportableFields").'</td>'; print '<td width="100" align="center">'; - print '<a title='.$langs->trans("All").' alt='.$langs->trans("All").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field=all">'.$langs->trans("All")."</a>"; + print '<a class="liste_titre" title='.$langs->trans("All").' alt='.$langs->trans("All").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field=all">'.$langs->trans("All")."</a>"; print '/'; - print '<a title='.$langs->trans("None").' alt='.$langs->trans("None").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=unselectfield&field=all">'.$langs->trans("None")."</a>"; + print '<a class="liste_titre" title='.$langs->trans("None").' alt='.$langs->trans("None").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=unselectfield&field=all">'.$langs->trans("None")."</a>"; print '</td>'; print '<td width="44%">'.$langs->trans("ExportedFields").'</td>'; print '</tr>'; diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index f8e444470c3c9d02a7bd901cc9e4acc4126a36bf..dc949344ee6c6f6363c1cda38ece55ba508c2e2f 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -47,7 +47,7 @@ class Holiday extends CommonObject var $date_debut=''; var $date_fin=''; var $halfday=''; - var $statut=''; + var $statut=''; // 1=draft, 2=validated, 3=approved var $fk_validator; var $date_valid=''; var $fk_user_valid; @@ -871,7 +871,7 @@ class Holiday extends CommonObject * * @param int $userID Id of user * @param int $nbHoliday Nb of days - * @return void + * @return int 0=Nothing done, 1=OK, -1=KO */ function updateSoldeCP($userID='',$nbHoliday='') { @@ -907,7 +907,7 @@ class Holiday extends CommonObject $i = 0; - while($i < $nbUser) + while ($i < $nbUser) { $now_holiday = $this->getCPforUser($users[$i]['rowid']); $new_solde = $now_holiday + $this->getConfCP('nbHolidayEveryMonth'); @@ -922,11 +922,18 @@ class Holiday extends CommonObject $sql2.= " nb_holiday = nb_holiday + ".$nb_holiday; dol_syslog(get_class($this).'::updateSoldeCP sql='.$sql2); - $this->db->query($sql2); + $result= $this->db->query($sql2); + + if ($result) return 1; + else return -1; } - } else { + + return 0; + } + else + { // Mise à jour pour un utilisateur - $nbHoliday = number_format($nbHoliday,2,'.',''); + $nbHoliday = price2num($nbHoliday,2); // Mise à jour pour un utilisateur $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET"; @@ -934,7 +941,10 @@ class Holiday extends CommonObject $sql.= " WHERE fk_user = '".$userID."'"; dol_syslog(get_class($this).'::updateSoldeCP sql='.$sql); - $this->db->query($sql); + $result = $this->db->query($sql); + + if ($result) return 1; + else return -1; } } diff --git a/htdocs/holiday/fiche.php b/htdocs/holiday/fiche.php index 8176a80938c6ee25d014b2c660617a2bb31b969f..01c2e1fb5a16522b1485cee24575793e9827c629 100644 --- a/htdocs/holiday/fiche.php +++ b/htdocs/holiday/fiche.php @@ -1,8 +1,8 @@ <?php -/* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com> - * Copyright (C) 2012 Laurent Destailleur <eldy@users.sourceforge.net> - * Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com> - * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es> +/* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com> + * Copyright (C) 2012-2013 Laurent Destailleur <eldy@users.sourceforge.net> + * Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com> + * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -46,9 +46,9 @@ $user_id = $user->id; $now=dol_now(); -/******************************************************************* +/* * Actions -********************************************************************/ + */ // Si création de la demande if ($action == 'create') @@ -232,27 +232,41 @@ if ($action == 'update') } // Si suppression de la demande -if ($action == 'confirm_delete' && $_GET['confirm'] == 'yes') +if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes') { if($user->rights->holiday->delete) { + $error=0; + + $db->begin(); + $cp = new Holiday($db); $cp->fetch($id); // Si c'est bien un brouillon - if ($cp->statut == 1) + if ($cp->statut == 1 || $cp->statut == 3) { // Si l'utilisateur à le droit de lire cette demande, il peut la supprimer if ($user->id == $cp->fk_user || $user->rights->holiday->lire_tous) { - $cp->delete($id); - header('Location: index.php'); - exit; + $result=$cp->delete($id); } - else { + else + { $error = $langs->trans('ErrorCantDeleteCP'); } } + + if (! $error) + { + $db->commit(); + header('Location: index.php'); + exit; + } + else + { + $db->rollback(); + } } } @@ -315,9 +329,9 @@ if ($action == 'confirm_send') } // Si l'option pour avertir le valideur en cas de solde inférieur à la demande - if($cp->getConfCP('AlertValidatorSolde')) + if ($cp->getConfCP('AlertValidatorSolde')) { - $nbopenedday=num_open_day($cp->date_debut,$cp->date_fin,0,1); + $nbopenedday=num_open_day($cp->date_debut,$cp->date_fin,0,1,$cp->halfday); if ($nbopenedday > $cp->getCPforUser($cp->fk_user)) { $message.= "\n"; @@ -361,9 +375,8 @@ if($action == 'confirm_valid') $cp->fetch($id); // Si statut en attente de validation et valideur = utilisateur - if($cp->statut == 2 && $user->id == $cp->fk_validator) + if ($cp->statut == 2 && $user->id == $cp->fk_validator) { - $cp->date_valid = dol_now(); $cp->fk_user_valid = $user->id; $cp->statut = 3; @@ -371,13 +384,13 @@ if($action == 'confirm_valid') $verif = $cp->update($user->id); // Si pas d'erreur SQL on redirige vers la fiche de la demande - if($verif > 0) { - - // Retrait du nombre de jours prit - $nbJour = $nbopenedday=num_open_day($cp->date_debut,$cp->date_fin,0,1); + if ($verif > 0) + { + // Calculcate number of days consummed + $nbopenedday=num_open_day($cp->date_debut,$cp->date_fin,0,1); $soldeActuel = $cp->getCpforUser($cp->fk_user); - $newSolde = $soldeActuel - ($nbJour*$cp->getConfCP('nbHolidayDeducted')); + $newSolde = $soldeActuel - ($nbopenedday * $cp->getConfCP('nbHolidayDeducted')); // On ajoute la modification dans le LOG $cp->addLogCP($user->id, $cp->fk_user, $langs->transnoentitiesnoconv("Holidays"), $newSolde); @@ -441,13 +454,13 @@ if($action == 'confirm_valid') if ($action == 'confirm_refuse') { - if(!empty($_POST['detail_refuse'])) + if (!empty($_POST['detail_refuse'])) { $cp = new Holiday($db); $cp->fetch($_GET['id']); // Si statut en attente de validation et valideur = utilisateur - if($cp->statut == 2 && $user->id == $cp->fk_validator) + if ($cp->statut == 2 && $user->id == $cp->fk_validator) { $cp->date_refuse = date('Y-m-d H:i:s', time()); $cp->fk_user_refuse = $user->id; @@ -457,8 +470,8 @@ if ($action == 'confirm_refuse') $verif = $cp->update($user->id); // Si pas d'erreur SQL on redirige vers la fiche de la demande - if($verif > 0) { - + if ($verif > 0) + { // To $destinataire = new User($db); $destinataire->fetch($cp->fk_user); @@ -525,16 +538,48 @@ if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes') $cp->fetch($_GET['id']); // Si statut en attente de validation et valideur = utilisateur - if ($cp->statut == 2 && ($user->id == $cp->fk_validator || $user->id == $cp->fk_user)) + if (($cp->statut == 2 || $cp->statut == 3) && ($user->id == $cp->fk_validator || $user->id == $cp->fk_user)) { + $db->begin(); + + $oldstatus = $cp->statut; $cp->date_cancel = dol_now(); $cp->fk_user_cancel = $user->id; $cp->statut = 4; - $verif = $cp->update($user->id); + $result = $cp->update($user->id); + + if ($result >= 0 && $oldstatus == 3) // holiday was already validated, status 3, so we must increase back sold + { + // Calculcate number of days consummed + $nbopenedday=num_open_day($cp->date_debut,$cp->date_fin,0,1,$cp->halfday); + $soldeActuel = $cp->getCpforUser($cp->fk_user); + $newSolde = $soldeActuel + ($nbopenedday * $cp->getConfCP('nbHolidayDeducted')); + + // On ajoute la modification dans le LOG + $result1=$cp->addLogCP($user->id, $cp->fk_user, $langs->transnoentitiesnoconv("HolidaysCancelation"), $newSolde); + + // Mise à jour du solde + $result2=$cp->updateSoldeCP($cp->fk_user, $newSolde); + + if ($result1 < 0 || $result2 < 0) + { + $error = $langs->trans('ErrorCantDeleteCP'); + } + } + + if (! $error) + { + $db->commit(); + } + else + { + $db->rollback(); + } + // Si pas d'erreur SQL on redirige vers la fiche de la demande - if($verif > 0) + if (! $error && $result > 0) { // To $destinataire = new User($db); @@ -829,11 +874,11 @@ else if($user->id == $cp->fk_user || $user->rights->holiday->lire_tous) { - if ($action == 'delete' && $cp->statut == 1) { + if ($action == 'delete') + { if($user->rights->holiday->delete) { print $form->formconfirm("fiche.php?id=".$id,$langs->trans("TitleDeleteCP"),$langs->trans("ConfirmDeleteCP"),"confirm_delete", '', 0, 1); - if ($ret == 'html') print '<br />'; } } @@ -841,29 +886,25 @@ else if ($action == 'sendToValidate' && $cp->statut == 1 && $user->id == $cp->fk_user) { print $form->formconfirm("fiche.php?id=".$id,$langs->trans("TitleToValidCP"),$langs->trans("ConfirmToValidCP"),"confirm_send", '', 1, 1); - if ($ret == 'html') print '<br />'; } // Si validation de la demande - if ($action == 'valid' && $cp->statut == 2 && $user->id == $cp->fk_validator) + if ($action == 'valid') { print $form->formconfirm("fiche.php?id=".$id,$langs->trans("TitleValidCP"),$langs->trans("ConfirmValidCP"),"confirm_valid", '', 1, 1); - if ($ret == 'html') print '<br />'; } // Si refus de la demande - if ($action == 'refuse' && $cp->statut == 2 && $user->id == $cp->fk_validator) + if ($action == 'refuse') { $array_input = array(array('type'=>"text",'label'=> $langs->trans('DetailRefusCP'),'name'=>"detail_refuse",'size'=>"50",'value'=>"")); print $form->formconfirm("fiche.php?id=".$id."&action=confirm_refuse", $langs->trans("TitleRefuseCP"), $langs->trans('ConfirmRefuseCP'), "confirm_refuse", $array_input, 1, 0); - if ($ret == 'html') print '<br />'; } // Si annulation de la demande - if ($action == 'cancel' && $cp->statut == 2 && ($user->id == $cp->fk_validator || $user->id == $cp->fk_user)) + if ($action == 'cancel') { print $form->formconfirm("fiche.php?id=".$id,$langs->trans("TitleCancelCP"),$langs->trans("ConfirmCancelCP"),"confirm_cancel", '', 1, 1); - if ($ret == 'html') print '<br />'; } $head=holiday_prepare_head($cp); @@ -893,7 +934,8 @@ else $starthalfday=($cp->halfday == -1 || $cp->halfday == 2)?'afternoon':'morning'; $endhalfday=($cp->halfday == 1 || $cp->halfday == 2)?'morning':'afternoon'; - if(!$edit) { + if(!$edit) + { print '<tr>'; print '<td>'.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')</td>'; print '<td>'.dol_print_date($cp->date_debut,'day'); @@ -901,7 +943,9 @@ else print $langs->trans($listhalfday[$starthalfday]); print '</td>'; print '</tr>'; - } else { + } + else + { print '<tr>'; print '<td>'.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')</td>'; print '<td>'; @@ -921,7 +965,9 @@ else print $langs->trans($listhalfday[$endhalfday]); print '</td>'; print '</tr>'; - } else { + } + else + { print '<tr>'; print '<td>'.$langs->trans('DateFinCP').' ('.$langs->trans("LastDayOfHoliday").')</td>'; print '<td>'; @@ -1053,7 +1099,7 @@ else { print '<a href="fiche.php?id='.$_GET['id'].'&action=sendToValidate" class="butAction">'.$langs->trans("Validate").'</a>'; } - if($user->rights->holiday->delete && $cp->statut == 1) + if ($user->rights->holiday->delete && $cp->statut == 1) // If draft { print '<a href="fiche.php?id='.$_GET['id'].'&action=delete" class="butActionDelete">'.$langs->trans("DeleteCP").'</a>'; } @@ -1064,7 +1110,7 @@ else print '<a href="fiche.php?id='.$_GET['id'].'&action=refuse" class="butAction">'.$langs->trans("ActionRefuseCP").'</a>'; } - if (($user->id == $cp->fk_validator || $user->id == $cp->fk_user) && $cp->statut == 2) + if (($user->id == $cp->fk_validator || $user->id == $cp->fk_user) && ($cp->statut == 2 || $cp->statut == 3)) // Status validated or approved { if (($cp->date_debut > dol_now()) || $user->admin) print '<a href="fiche.php?id='.$_GET['id'].'&action=cancel" class="butAction">'.$langs->trans("ActionCancelCP").'</a>'; else print '<a href="#" class="butActionRefused" title="'.$langs->trans("HolidayStarted").'">'.$langs->trans("ActionCancelCP").'</a>'; diff --git a/htdocs/langs/en_US/holiday.lang b/htdocs/langs/en_US/holiday.lang index 73398da233bf4c6ad745135124f3d7eb147efb68..83f06495ffb396bc155540be49ef26b5d42cafa5 100644 --- a/htdocs/langs/en_US/holiday.lang +++ b/htdocs/langs/en_US/holiday.lang @@ -89,6 +89,7 @@ FirstDayOfHoliday=First day of holiday LastDayOfHoliday=Last day of holiday HolidaysMonthlyUpdate=Monthly update ManualUpdate=Manual update +HolidaysCancelation=Holidays cancelation ## Configuration du Module ## ConfCP=Configuration of holidays module diff --git a/htdocs/langs/fr_FR/holiday.lang b/htdocs/langs/fr_FR/holiday.lang index f690a9c764c57409a7e74096d4e83f9a4a20f6a5..b6569ee5f4d5c4f802d685bfdb9c1faa4dd750b5 100644 --- a/htdocs/langs/fr_FR/holiday.lang +++ b/htdocs/langs/fr_FR/holiday.lang @@ -89,6 +89,7 @@ FirstDayOfHoliday=Premier jour de congés LastDayOfHoliday=Dernier jour de congés HolidaysMonthlyUpdate=Mise à jour mensuelle ManualUpdate=Mise à jour manuelle +HolidaysCancelation=Annulation de congès ## Configuration du Module ## ConfCP=Configuration du module Congés diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index c01d2995db596eceb8dcb28042d9f035ebca4dd9..1af76aed9b5e73696bb4acf536e37850a9fb4d94 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -1759,6 +1759,7 @@ tr.liste_titre th, th.liste_titre, tr.liste_titre td, td.liste_titre, form.liste } .liste_titre td a { text-shadow: none !important; + color: #<?php echo $colortexttitle; ?>; } div.liste_titre { padding-left: 3px;