From 5975536fcf7a8b73c004fb3bbd8eab85cca3bbc1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 Jun 2015 23:25:01 +0200 Subject: [PATCH] Support type of leave. --- htdocs/holiday/card.php | 113 ++++++++++++++++--------- htdocs/holiday/class/holiday.class.php | 28 +++--- htdocs/langs/en_US/holiday.lang | 1 + 3 files changed, 92 insertions(+), 50 deletions(-) diff --git a/htdocs/holiday/card.php b/htdocs/holiday/card.php index 308bbac2661..1a430ab84cf 100644 --- a/htdocs/holiday/card.php +++ b/htdocs/holiday/card.php @@ -51,7 +51,6 @@ $now=dol_now(); * Actions */ -// Si création de la demande if ($action == 'create') { $cp = new Holiday($db); @@ -66,12 +65,15 @@ if ($action == 'create') if (! $error) { + $db->begin(); + $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year')); $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year')); $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1); $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1); $starthalfday=GETPOST('starthalfday'); $endhalfday=GETPOST('endhalfday'); + $type=GETPOST('type'); $halfday=0; if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday=2; else if ($starthalfday == 'afternoon') $halfday=-1; @@ -131,17 +133,22 @@ if ($action == 'create') $cp->date_fin = $date_fin; $cp->fk_validator = $valideur; $cp->halfday = $halfday; + $cp->fk_type = $type; - $verif = $cp->create($userid); + $verif = $cp->create($user); // Si pas d'erreur SQL on redirige vers la fiche de la demande if ($verif > 0) { - header('Location: card.php?id='.$verif); + $db->commit(); + + header('Location: card.php?id='.$verif); exit; } else - { + { + $db->rollback(); + // Sinon on affiche le formulaire de demande avec le message d'erreur SQL header('Location: card.php?action=request&error=SQL_Create&msg='.$cp->error); exit; @@ -242,44 +249,41 @@ if ($action == 'update') } // Si suppression de la demande -if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes') +if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $user->rights->holiday->delete) { - if($user->rights->holiday->delete) - { - $error=0; + $error=0; - $db->begin(); + $db->begin(); - $cp = new Holiday($db); - $cp->fetch($id); + $cp = new Holiday($db); + $cp->fetch($id); - $canedit=(($user->id == $cp->fk_user && $user->rights->holiday->write) || ($user->id != $cp->fk_user && $user->rights->holiday->write_all)); + $canedit=(($user->id == $cp->fk_user && $user->rights->holiday->write) || ($user->id != $cp->fk_user && $user->rights->holiday->write_all)); - // Si c'est bien un brouillon - if ($cp->statut == 1 || $cp->statut == 3) - { - // Si l'utilisateur à le droit de lire cette demande, il peut la supprimer - if ($canedit) - { - $result=$cp->delete($id); - } - else - { - $error = $langs->trans('ErrorCantDeleteCP'); - } - } + // Si c'est bien un brouillon + if ($cp->statut == 1 || $cp->statut == 3) + { + // Si l'utilisateur à le droit de lire cette demande, il peut la supprimer + if ($canedit) + { + $result=$cp->delete($id); + } + else + { + $error = $langs->trans('ErrorCantDeleteCP'); + } + } - if (! $error) - { - $db->commit(); - header('Location: index.php'); - exit; - } - else - { - $db->rollback(); - } - } + if (! $error) + { + $db->commit(); + header('Location: index.php'); + exit; + } + else + { + $db->rollback(); + } } // Si envoi de la demande @@ -466,7 +470,7 @@ 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']); @@ -770,6 +774,8 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create print ''; print ''; + + // User print ''; print ''; print ''; print ''; + + // Type + print ''; + print ''; + print ''; + print ''; + + // Date start print ''; print ''; print ''; print ''; + + // Date end print ''; print ''; print '
'.$langs->trans("User").''; @@ -781,6 +787,24 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create else print $form->select_users(GETPOST('userid')?GETPOST('userid'):$user->id,'userid',0,'',0); print '
'.$langs->trans("Type").''; + $typeleaves=$cp->getTypes(1,1); + $arraytypeleaves=array(); + foreach($typeleaves as $key => $val) + { + $labeltoshow = $val['label']; + $labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')':''); + $arraytypeleaves[$val['rowid']]=$labeltoshow; + } + print $form->selectarray('type', $arraytypeleaves, (GETPOST('type')?GETPOST('type'):''), 1); + print '
'.$langs->trans("DateDebCP").' ('.$langs->trans("FirstDayOfHoliday").')'; @@ -795,6 +819,8 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday')?GETPOST('starthalfday'):'morning')); print '
'.$langs->trans("DateFinCP").' ('.$langs->trans("LastDayOfHoliday").')'; @@ -952,9 +978,9 @@ else if ($action == 'edit' && $cp->statut == 1) { $edit = true; - print '
'."\n"; + print ''."\n"; print ''."\n"; - print ''."\n"; + print ''."\n"; } print ''; @@ -974,6 +1000,15 @@ else print $userRequest->getNomUrl(1); print ''; + // Type + print ''; + print ''; + print ''; + print ''; + $starthalfday=($cp->halfday == -1 || $cp->halfday == 2)?'afternoon':'morning'; $endhalfday=($cp->halfday == 1 || $cp->halfday == 2)?'morning':'afternoon'; diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index 6743ce102a7..6e447d8cb95 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -53,7 +53,7 @@ class Holiday extends CommonObject var $date_debut_gmt=''; // Date start in GMT var $date_fin_gmt=''; // Date end in GMT var $halfday=''; - var $statut=''; // 1=draft, 2=validated, 3=approved + var $statut=''; // 1=draft, 2=validated, 3=approved var $fk_validator; var $date_valid=''; var $fk_user_valid; @@ -62,6 +62,7 @@ class Holiday extends CommonObject var $date_cancel=''; var $fk_user_cancel; var $detail_refuse=''; + var $fk_type; var $holiday = array(); var $events = array(); @@ -71,6 +72,7 @@ class Holiday extends CommonObject var $optValue = ''; var $optRowid = ''; + /** * Constructor * @@ -124,10 +126,10 @@ class Holiday extends CommonObject $sql.= "date_fin,"; $sql.= "halfday,"; $sql.= "statut,"; - $sql.= "fk_validator"; + $sql.= "fk_validator,"; + $sql.= "fk_type,"; + $sql.= "fk_user_create"; $sql.= ") VALUES ("; - - // User $sql.= "'".$this->fk_user."',"; $sql.= " '".$this->db->idate($now)."',"; $sql.= " '".$this->db->escape($this->description)."',"; @@ -135,8 +137,9 @@ class Holiday extends CommonObject $sql.= " '".$this->db->idate($this->date_fin)."',"; $sql.= " ".$this->halfday.","; $sql.= " '1',"; - $sql.= " '".$this->fk_validator."'"; - + $sql.= " '".$this->fk_validator."',"; + $sql.= " '".$this->fk_type."',"; + $sql.= " ".$user->id; $sql.= ")"; $this->db->begin(); @@ -150,7 +153,6 @@ class Holiday extends CommonObject if (! $error) { $this->rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday"); - } // Commit or rollback @@ -200,7 +202,9 @@ class Holiday extends CommonObject $sql.= " cp.fk_user_cancel,"; $sql.= " cp.detail_refuse,"; $sql.= " cp.note_private,"; - $sql.= " cp.note_public"; + $sql.= " cp.note_public,"; + $sql.= " cp.fk_user_create,"; + $sql.= " cp.fk_type"; $sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp"; $sql.= " WHERE cp.rowid = ".$id; @@ -213,8 +217,8 @@ class Holiday extends CommonObject $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; - $this->rowid = $obj->rowid; // deprecated - $this->ref = $obj->rowid; + $this->rowid = $obj->rowid; // deprecated + $this->ref = $obj->rowid; $this->fk_user = $obj->fk_user; $this->date_create = $this->db->jdate($obj->date_create); $this->description = $obj->description; @@ -234,6 +238,8 @@ class Holiday extends CommonObject $this->detail_refuse = $obj->detail_refuse; $this->note_private = $obj->note_private; $this->note_public = $obj->note_public; + $this->fk_user_create = $obj->fk_user_create; + $this->fk_type = $obj->fk_type; } $this->db->free($resql); @@ -1841,7 +1847,7 @@ class Holiday extends CommonObject { while ($obj = $this->db->fetch_object($result)) { - $types[] = array('rowid'=> $obj->rowid, 'code'=> $obj->code, 'label'=>$obj->label, 'affect'=>$obj->affect, 'delay'=>$obj->delay, 'newByMonth'=>$obj->newByMonth); + $types[$obj->rowid] = array('rowid'=> $obj->rowid, 'code'=> $obj->code, 'label'=>$obj->label, 'affect'=>$obj->affect, 'delay'=>$obj->delay, 'newByMonth'=>$obj->newByMonth); } return $types; diff --git a/htdocs/langs/en_US/holiday.lang b/htdocs/langs/en_US/holiday.lang index b693c594f87..f9d9f047411 100644 --- a/htdocs/langs/en_US/holiday.lang +++ b/htdocs/langs/en_US/holiday.lang @@ -127,6 +127,7 @@ ErrorMailNotSend=An error occurred while sending email: NoCPforMonth=No leave this month. nbJours=Number days TitleAdminCP=Configuration of Leaves +NoticePeriod=Notice period #Messages Hello=Hello HolidaysToValidate=Validate leave requests
'.$langs->trans("Type").''; + $typeleaves=$cp->getTypes(1,1); + print $typeleaves[$cp->fk_type]['label']; + print '