diff --git a/ChangeLog b/ChangeLog
index d685811b926..1fe09d88ccf 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 c152895c0d7..aefe5490802 100644
--- a/htdocs/exports/export.php
+++ b/htdocs/exports/export.php
@@ -506,9 +506,9 @@ if ($step == 2 && $datatoexport)
print '
'.$langs->trans("Entities").' | ';
print ''.$langs->trans("ExportableFields").' | ';
print '';
- print ''.$langs->trans("All")."";
+ print ''.$langs->trans("All")."";
print '/';
- print ''.$langs->trans("None")."";
+ print ''.$langs->trans("None")."";
print ' | ';
print ''.$langs->trans("ExportedFields").' | ';
print '';
diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php
index f8e444470c3..dc949344ee6 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 8176a80938c..01c2e1fb5a1 100644
--- a/htdocs/holiday/fiche.php
+++ b/htdocs/holiday/fiche.php
@@ -1,8 +1,8 @@
- * Copyright (C) 2012 Laurent Destailleur
- * Copyright (C) 2012 Regis Houssin
- * Copyright (C) 2013 Juanjo Menent
+/* Copyright (C) 2011 Dimitri Mouillard
+ * Copyright (C) 2012-2013 Laurent Destailleur
+ * Copyright (C) 2012 Regis Houssin
+ * Copyright (C) 2013 Juanjo Menent
*
* 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 '
';
}
}
@@ -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 '
';
}
// 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 '
';
}
// 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 '
';
}
// 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 '
';
}
$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 '';
print '| '.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").') | ';
print ''.dol_print_date($cp->date_debut,'day');
@@ -901,7 +943,9 @@ else
print $langs->trans($listhalfday[$starthalfday]);
print ' | ';
print '
';
- } else {
+ }
+ else
+ {
print '';
print '| '.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").') | ';
print '';
@@ -921,7 +965,9 @@ else
print $langs->trans($listhalfday[$endhalfday]);
print ' | ';
print '
';
- } else {
+ }
+ else
+ {
print '';
print '| '.$langs->trans('DateFinCP').' ('.$langs->trans("LastDayOfHoliday").') | ';
print '';
@@ -1053,7 +1099,7 @@ else
{
print ''.$langs->trans("Validate").'';
}
- if($user->rights->holiday->delete && $cp->statut == 1)
+ if ($user->rights->holiday->delete && $cp->statut == 1) // If draft
{
print ''.$langs->trans("DeleteCP").'';
}
@@ -1064,7 +1110,7 @@ else
print ''.$langs->trans("ActionRefuseCP").'';
}
- 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 ''.$langs->trans("ActionCancelCP").'';
else print ''.$langs->trans("ActionCancelCP").'';
diff --git a/htdocs/langs/en_US/holiday.lang b/htdocs/langs/en_US/holiday.lang
index 73398da233b..83f06495ffb 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 f690a9c764c..b6569ee5f4d 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 c01d2995db5..1af76aed9b5 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: #;
}
div.liste_titre {
padding-left: 3px;
|