diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index 88c6ee49f09..3d13a2a1515 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -759,15 +759,16 @@ function num_between_day($timestampStart, $timestampEnd, $lastday=0) } /** - * Function to return number of working days (and text of units) between two dates (jours ouvres) + * Function to return number of working days (and text of units) between two dates (working days) * - * @param timestamp $timestampStart Timestamp for start date - * @param timestamp $timestampEnd Timestamp for end date - * @param int $inhour 0: return number of days, 1: return number of hours (72 max) - * @param int $lastday We include last day, 0: no, 1:yes - * @return int Number of days or hours + * @param timestamp $timestampStart Timestamp for start date + * @param timestamp $timestampEnd Timestamp for end date + * @param int $inhour 0: return number of days, 1: return number of hours (72h max) + * @param int $lastday We include last day, 0: no, 1:yes + * @param int $halfday Tag to define half day when holiday start and end + * @return int Number of days or hours */ -function num_open_day($timestampStart, $timestampEnd,$inhour=0,$lastday=0) +function num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0) { global $langs; @@ -784,13 +785,13 @@ function num_open_day($timestampStart, $timestampEnd,$inhour=0,$lastday=0) $nbOpenDay = num_between_day($timestampStart, $timestampEnd, $lastday) - num_public_holiday($timestampStart, $timestampEnd, $lastday); $nbOpenDay.= " " . $langs->trans("Days"); if ($inhour == 1 && $nbOpenDay <= 3) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort"); - return $nbOpenDay; + return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday)); } elseif ($timestampStart == $timestampEnd) { $nbOpenDay=$lastday; if ($inhour == 1) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort"); - return $nbOpenDay; + return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday)); } else { diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index be90f452158..df38968a647 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -30,17 +30,22 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; */ class Holiday extends CommonObject { - var $db; + public $element='holiday'; + public $table_element='holiday'; + + var $db; var $error; var $errors=array(); var $rowid; - + var $ref; + var $fk_user; var $date_create=''; var $description; var $date_debut=''; var $date_fin=''; + var $halfday=''; var $statut=''; var $fk_validator; var $date_valid=''; @@ -97,15 +102,14 @@ class Holiday extends CommonObject // Insert request $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday("; - $sql.= "fk_user,"; $sql.= "date_create,"; $sql.= "description,"; $sql.= "date_debut,"; $sql.= "date_fin,"; + $sql.= "halfday,"; $sql.= "statut,"; $sql.= "fk_validator"; - $sql.= ") VALUES ("; // User @@ -114,6 +118,7 @@ class Holiday extends CommonObject $sql.= " '".addslashes($this->description)."',"; $sql.= " '".$this->db->idate($this->date_debut)."',"; $sql.= " '".$this->db->idate($this->date_fin)."',"; + $sql.= " ".$this->halfday.","; $sql.= " '1',"; $sql.= " '".$this->fk_validator."'"; @@ -170,6 +175,7 @@ class Holiday extends CommonObject $sql.= " cp.description,"; $sql.= " cp.date_debut,"; $sql.= " cp.date_fin,"; + $sql.= " cp.halfday,"; $sql.= " cp.statut,"; $sql.= " cp.fk_validator,"; $sql.= " cp.date_valid,"; @@ -193,11 +199,13 @@ class Holiday extends CommonObject $this->id = $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; $this->date_debut = $this->db->jdate($obj->date_debut); $this->date_fin = $this->db->jdate($obj->date_fin); + $this->halfday = $obj->halfday; $this->statut = $obj->statut; $this->fk_validator = $obj->fk_validator; $this->date_valid = $this->db->jdate($obj->date_valid); @@ -240,6 +248,7 @@ class Holiday extends CommonObject $sql.= " cp.description,"; $sql.= " cp.date_debut,"; $sql.= " cp.date_fin,"; + $sql.= " cp.halfday,"; $sql.= " cp.statut,"; $sql.= " cp.fk_validator,"; $sql.= " cp.date_valid,"; @@ -284,11 +293,13 @@ class Holiday extends CommonObject $obj = $this->db->fetch_object($resql); $tab_result[$i]['rowid'] = $obj->rowid; + $tab_result[$i]['ref'] = $obj->rowid; $tab_result[$i]['fk_user'] = $obj->fk_user; $tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create); $tab_result[$i]['description'] = $obj->description; $tab_result[$i]['date_debut'] = $this->db->jdate($obj->date_debut); $tab_result[$i]['date_fin'] = $this->db->jdate($obj->date_fin); + $tab_result[$i]['halfday'] = $obj->halfday; $tab_result[$i]['statut'] = $obj->statut; $tab_result[$i]['fk_validator'] = $obj->fk_validator; $tab_result[$i]['date_valid'] = $this->db->jdate($obj->date_valid); @@ -334,6 +345,7 @@ class Holiday extends CommonObject $sql.= " cp.description,"; $sql.= " cp.date_debut,"; $sql.= " cp.date_fin,"; + $sql.= " cp.halfday,"; $sql.= " cp.statut,"; $sql.= " cp.fk_validator,"; $sql.= " cp.date_valid,"; @@ -342,10 +354,16 @@ class Holiday extends CommonObject $sql.= " cp.fk_user_refuse,"; $sql.= " cp.date_cancel,"; $sql.= " cp.fk_user_cancel,"; - $sql.= " cp.detail_refuse"; + $sql.= " cp.detail_refuse,"; - $sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp"; - $sql.= " WHERE cp.rowid > '0'"; // Hack pour la recherche sur le tableau + $sql.= " uu.name as user_lastname,"; + $sql.= " uu.firstname as user_firstname,"; + + $sql.= " ua.name as validator_lastname,"; + $sql.= " ua.firstname as validator_firstname"; + + $sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua"; + $sql.= " WHERE cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau // Filtrage de séléction if(!empty($filter)) { @@ -378,11 +396,13 @@ class Holiday extends CommonObject $obj = $this->db->fetch_object($resql); $tab_result[$i]['rowid'] = $obj->rowid; + $tab_result[$i]['ref'] = $obj->rowid; $tab_result[$i]['fk_user'] = $obj->fk_user; $tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create); $tab_result[$i]['description'] = $obj->description; $tab_result[$i]['date_debut'] = $this->db->jdate($obj->date_debut); $tab_result[$i]['date_fin'] = $this->db->jdate($obj->date_fin); + $tab_result[$i]['halfday'] = $obj->halfday; $tab_result[$i]['statut'] = $obj->statut; $tab_result[$i]['fk_validator'] = $obj->fk_validator; $tab_result[$i]['date_valid'] = $this->db->jdate($obj->date_valid); @@ -393,6 +413,12 @@ class Holiday extends CommonObject $tab_result[$i]['fk_user_cancel'] = $obj->fk_user_cancel; $tab_result[$i]['detail_refuse'] = $obj->detail_refuse; + $tab_result[$i]['user_firstname'] = $obj->user_firstname; + $tab_result[$i]['user_lastname'] = $obj->user_lastname; + + $tab_result[$i]['validator_firstname'] = $obj->validator_firstname; + $tab_result[$i]['validator_lastname'] = $obj->validator_lastname; + $i++; } // Retourne 1 et ajoute le tableau à la variable @@ -403,7 +429,7 @@ class Holiday extends CommonObject { // Erreur SQL $this->error="Error ".$this->db->lasterror(); - dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::fetchAll ".$this->error, LOG_ERR); return -1; } } @@ -435,6 +461,7 @@ class Holiday extends CommonObject } else { $error++; } + $sql.= " halfday = ".$this->halfday.","; if(!empty($this->statut) && is_numeric($this->statut)) { $sql.= " statut = '".$this->statut."',"; } else { @@ -567,57 +594,112 @@ class Holiday extends CommonObject * @param int $fk_user Id user * @param date $dateDebut Start date * @param date $dateFin End date + * @param int $halfday Tag to define half day when holiday start and end * @return boolean */ - function verifDateHolidayCP($fk_user,$dateDebut,$dateFin) + function verifDateHolidayCP($fk_user, $dateDebut, $dateFin, $halfday=0) { $this->fetchByUser($fk_user,'',''); - foreach($this->holiday as $infos_CP) { - - if($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut']) { + foreach($this->holiday as $infos_CP) + { + if ($infos_CP['statut'] == 4) continue; // ignore not validated holidays + if ($infos_CP['statut'] == 5) continue; // ignore not validated holidays + + // TODO Also use halfday for the check + if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut']) + { return false; } - } return true; } - /** - * Retourne la traduction du statut d'un congé payé - * - * @param int $statut int du statut du congé - * @return string retourne la traduction du statut - */ - function getStatutCP($statut) { - global $langs; - - if(is_numeric($statut)) { - - switch($statut) { - case 1: // Brouillon - $statut = $langs->trans('DraftCP'); - break; - case 2: // En attente de validation - $statut = $langs->trans('ToValidateCP'); - break; - case 3: // Validée - $statut = $langs->trans('ValidateCP'); - break; - case 4: // Annulée - $statut = $langs->trans('CancelCP'); - break; - case 5: // Refusée - $statut = $langs->trans('RefuseCP'); - } - - return $statut; - } + /** + * Return clicable name (with picto eventually) + * + * @param int $withpicto 0=_No picto, 1=Includes the picto in the linkn, 2=Picto only + * @return string String with URL + */ + function getNomUrl($withpicto=0) + { + global $langs; + + $result=''; + + $lien = ''; + $lienfin=''; + + $picto='holiday'; + + $label=$langs->trans("Show").': '.$this->ref; + + if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin); + if ($withpicto && $withpicto != 2) $result.=' '; + if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin; + return $result; } + + /** + * Returns the label status + * + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto + * @return string Label + */ + function getLibStatut($mode=0) + { + return $this->LibStatut($this->statut, $mode, $this->date_debut); + } + + /** + * Returns the label of a statut + * + * @param int $statut id statut + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto + * @param date $startdate Date holiday should start + * @return string Label + */ + function LibStatut($statut, $mode=0, $startdate='') + { + global $langs; + + if ($mode == 0) + { + if ($statut == 1) return $langs->trans('DraftCP'); + if ($statut == 2) return $langs->trans('ToValidateCP'); + if ($statut == 3) return $langs->trans('ValidateCP'); + if ($statut == 4) return $langs->trans('CancelCP'); + if ($statut == 5) return $langs->trans('RefuseCP'); + } + if ($mode == 2) + { + $pictoapproved='statut6'; + if (! empty($startdate) && $startdate > dol_now()) $pictoapproved='statut4'; + if ($statut == 1) return img_picto($langs->trans('DraftCP'),'statut0').' '.$langs->trans('DraftCP'); // Draft + if ($statut == 2) return img_picto($langs->trans('ToValidateCP'),'statut1').' '.$langs->trans('ToValidateCP'); // Waiting approval + if ($statut == 3) return img_picto($langs->trans('ValidateCP'),$pictoapproved).' '.$langs->trans('ValidateCP'); + if ($statut == 4) return img_picto($langs->trans('CancelCP'),'statut5').' '.$langs->trans('CancelCP'); + if ($statut == 5) return img_picto($langs->trans('RefuseCP'),'statut5').' '.$langs->trans('RefuseCP'); + } + if ($mode == 5) + { + $pictoapproved='statut6'; + if (! empty($startdate) && $startdate > dol_now()) $pictoapproved='statut4'; + if ($statut == 1) return $langs->trans('DraftCP').' '.img_picto($langs->trans('DraftCP'),'statut0'); // Draft + if ($statut == 2) return $langs->trans('ToValidateCP').' '.img_picto($langs->trans('ToValidateCP'),'statut1'); // Waiting approval + if ($statut == 3) return $langs->trans('ValidateCP').' '.img_picto($langs->trans('ValidateCP'),$pictoapproved); + if ($statut == 4) return $langs->trans('CancelCP').' '.img_picto($langs->trans('CancelCP'),'statut5'); + if ($statut == 5) return $langs->trans('RefuseCP').' '.img_picto($langs->trans('RefuseCP'),'statut5'); + } + + return $statut; + } + + /** * Affiche un select HTML des statuts de congés payés * @@ -773,18 +855,19 @@ class Holiday extends CommonObject if (empty($userID) && empty($nbHoliday)) { - // Si mise à jour pour tous le monde en début de mois - + // Si mise à jour pour tout le monde en début de mois + $now=dol_now(); + // Mois actuel - $month = date('m',time()); + $month = date('m',$now); $lastUpdate = $this->getConfCP('lastUpdate'); $monthLastUpdate = date('m', $lastUpdate); - // Si la date du mois n'est pas la même que celle sauvegardé, on met à jour le timestamp + // Si la date du mois n'est pas la même que celle sauvegardée, on met à jour le timestamp if ($month != $monthLastUpdate) { $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET"; - $sql.= " value = '".dol_now()."'"; + $sql.= " value = '".$this->db->idate($now)."'"; $sql.= " WHERE name = 'lastUpdate'"; $result = $this->db->query($sql); @@ -838,7 +921,7 @@ class Holiday extends CommonObject */ function getCheckOption($name) { - $sql = "SELECT *"; + $sql = "SELECT value"; $sql.= " FROM ".MAIN_DB_PREFIX."holiday_config"; $sql.= " WHERE name = '".$name."'"; @@ -909,15 +992,15 @@ class Holiday extends CommonObject */ function getCPforUser($user_id) { - $sql = "SELECT *"; + $sql = "SELECT nb_holiday"; $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users"; $sql.= " WHERE fk_user = '".$user_id."'"; + dol_syslog(get_class($this).'::getCPforUser sql='.$sql); $result = $this->db->query($sql); - if($result) { - $obj = $this->db->fetch_array($result); - return number_format($obj['nb_holiday'],2); + $obj = $this->db->fetch_object($result); + return number_format($obj->nb_holiday,2); } else { return '0'; } @@ -1610,6 +1693,7 @@ class Holiday extends CommonObject $this->date_debut=dol_now(); $this->date_fin=dol_now()+(24*3600); $this->fk_validator=1; + $this->halfday=0; } } diff --git a/htdocs/holiday/fiche.php b/htdocs/holiday/fiche.php index 18af62b7feb..4e284fc0be4 100644 --- a/htdocs/holiday/fiche.php +++ b/htdocs/holiday/fiche.php @@ -52,6 +52,8 @@ $now=dol_now(); // Si création de la demande if ($action == 'create') { + $cp = new Holiday($db); + // Si pas le droit de créer une demande if(!$user->rights->holiday->write) { @@ -59,9 +61,15 @@ if ($action == 'create') exit; } - $date_debut = dol_mktime(0, 0, 0, $_POST['date_debut_month'], $_POST['date_debut_day'], $_POST['date_debut_year']); - $date_fin = dol_mktime(0, 0, 0, $_POST['date_fin_month'], $_POST['date_fin_day'], $_POST['date_fin_year']); - + $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')); + $starthalfday=GETPOST('starthalfday'); + $endhalfday=GETPOST('endhalfday'); + $halfday=0; + if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday=2; + else if ($starthalfday == 'afternoon') $halfday=-1; + else if ($endhalfday == 'morning') $halfday=1; + $valideur = GETPOST('valideur'); $description = trim(GETPOST('description')); $userID = GETPOST('userID'); @@ -80,21 +88,15 @@ if ($action == 'create') exit; } - $testDateDebut = $date_debut; - $testDateFin = $date_fin; - // Si date de début après la date de fin - if($testDateDebut > $testDateFin) + if ($date_debut > $date_fin) { header('Location: fiche.php?action=request&error=datefin'); exit; } - $cp = new Holiday($db); - - $verifCP = $cp->verifDateHolidayCP($userID,$date_debut,$date_fin); - - // On vérifie si il n'y a pas déjà des congés payés sur cette période + // Check if there is already holiday for this period + $verifCP = $cp->verifDateHolidayCP($userID, $date_debut, $date_fin, $halfday); if (! $verifCP) { header('Location: fiche.php?action=request&error=alreadyCP'); @@ -102,7 +104,7 @@ if ($action == 'create') } // Si aucun jours ouvrés dans la demande - $nbopenedday=num_open_day($testDateDebut,$testDateFin,0,1); + $nbopenedday=num_open_day($date_debut, $date_fin, 0, 1, $halfday); if($nbopenedday < 1) { header('Location: fiche.php?action=request&error=DureeHoliday'); @@ -121,7 +123,8 @@ if ($action == 'create') $cp->date_debut = $date_debut; $cp->date_fin = $date_fin; $cp->fk_validator = $valideur; - + $cp->halfday = $halfday; + $verif = $cp->create($user_id); // Si pas d'erreur SQL on redirige vers la fiche de la demande @@ -141,9 +144,15 @@ if ($action == 'create') if ($action == 'update') { - $date_debut = dol_mktime(0, 0, 0, $_POST['date_debut_month'], $_POST['date_debut_day'], $_POST['date_debut_year']); - $date_fin = dol_mktime(0, 0, 0, $_POST['date_fin_month'], $_POST['date_fin_day'], $_POST['date_fin_year']); - + $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')); + $starthalfday=GETPOST('starthalfday'); + $endhalfday=GETPOST('endhalfday'); + $halfday=0; + if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday=2; + else if ($starthalfday == 'afternoon') $halfday=-1; + else if ($endhalfday == 'morning') $halfday=1; + // Si pas le droit de modifier une demande if(!$user->rights->holiday->write) { @@ -175,11 +184,8 @@ if ($action == 'update') exit; } - $testDateDebut = $date_debut; - $testDateFin = $date_fin; - // Si date de début après la date de fin - if ($testDateDebut > $testDateFin) { + if ($date_debut > $date_fin) { header('Location: fiche.php?id='.$_POST['holiday_id'].'&action=edit&error=datefin'); exit; } @@ -191,7 +197,7 @@ if ($action == 'update') } // Si pas de jours ouvrés dans la demande - $nbopenedday=num_open_day($testDateDebut,$testDateFin,0,1); + $nbopenedday=num_open_day($date_debut, $date_fin, 0, 1, $halfday); if ($nbopenedday < 1) { header('Location: fiche.php?id='.$_POST['holiday_id'].'&action=edit&error=DureeHoliday'); @@ -202,10 +208,10 @@ if ($action == 'update') $cp->date_debut = $date_debut; $cp->date_fin = $date_fin; $cp->fk_validator = $valideur; - - $verif = $cp->update($user->id); - - // Si pas d'erreur SQL on redirige vers la fiche de la demande + $cp->halfday = $halfday; + + // Update + $verif = $cp->update($user->id); if ($verif > 0) { header('Location: fiche.php?id='.$_POST['holiday_id']); @@ -502,9 +508,9 @@ if ($action == 'confirm_cancel' && $_GET['confirm'] == 'yes') $userID = $user->id; // Si statut en attente de validation et valideur = utilisateur - if($cp->statut == 2 && $userID == $cp->fk_validator) + if ($cp->statut == 2 && $userID == $cp->fk_validator) { - $cp->date_cancel = date('Y-m-d H:i:s', time()); + $cp->date_cancel = dol_now(); $cp->fk_user_cancel = $user->id; $cp->statut = 4; @@ -569,6 +575,10 @@ if ($action == 'confirm_cancel' && $_GET['confirm'] == 'yes') */ $form = new Form($db); +$cp = new Holiday($db); + +$listhalfday=array('morning'=>$langs->trans("Morning"),"afternoon"=>$langs->trans("Afternoon")); + llxHeader(array(),$langs->trans('CPTitreMenu')); @@ -617,43 +627,39 @@ if (empty($id) || $action == 'add' || $action == 'request') dol_htmloutput_mesg('',$errors,'error'); } - $cp = new Holiday($db); $delayForRequest = $cp->getConfCP('delayForRequest'); //$delayForRequest = $delayForRequest * (60*60*24); $nextMonth = dol_time_plus_duree($now, $delayForRequest, 'd'); - print ''."\n"; // Formulaire de demande @@ -678,6 +684,8 @@ if (empty($id) || $action == 'add' || $action == 'request') $tmpdate = dol_mktime(0, 0, 0, GETPOST('datepmonth'), GETPOST('datepday'), GETPOST('datepyear')); $form->select_date($tmpdate,'date_debut_'); } + print '     '; + print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday')?GETPOST('starthalfday'):'morning')); print ''; print ''; print ''; @@ -690,6 +698,8 @@ if (empty($id) || $action == 'add' || $action == 'request') $tmpdate = dol_mktime(0, 0, 0, GETPOST('datefmonth'), GETPOST('datefday'), GETPOST('datefyear')); $form->select_date($tmpdate,'date_fin_'); } + print '     '; + print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday')?GETPOST('endhalfday'):'afternoon')); print ''; print ''; print ''; @@ -738,7 +748,6 @@ else // Affichage de la fiche d'une demande de congés payés if ($id > 0) { - $cp = new Holiday($db); $cp->fetch($id); $valideur = new User($db); @@ -834,7 +843,6 @@ else dol_fiche_head($head,'card',$langs->trans("CPTitreMenu"),0,'holiday'); - if ($action == 'edit' && $user->id == $cp->fk_user && $cp->statut == 1) { $edit = true; @@ -845,53 +853,69 @@ else print ''; print ''; - /*print ''; - print ''; - print '';*/ + $linkback=''; + print ''; print ''; - print ''; + print ''; print ''; + $starthalfday=($cp->halfday == -1 || $cp->halfday == 2)?'afternoon':'morning'; + $endhalfday=($cp->halfday == 1 || $cp->halfday == 2)?'morning':'afternoon'; + if(!$edit) { print ''; - print ''; - print ''; + print ''; + print ''; print ''; } else { print ''; - print ''; + print ''; print ''; print ''; } - if(!$edit) { + if (!$edit) + { print ''; - print ''; - print ''; + print ''; + print ''; print ''; } else { print ''; - print ''; + print ''; print ''; print ''; } print ''; print ''; - print ''; + print ''; print ''; // Status print ''; print ''; - print ''; + print ''; print ''; - if($cp->statut == 5) { + if ($cp->statut == 5) + { print ''; print ''; print ''; @@ -899,12 +923,15 @@ else } // Description - if(!$edit) { + if (!$edit) + { print ''; print ''; print ''; print ''; - } else { + } + else + { print ''; print ''; print ''; @@ -995,23 +1022,27 @@ else { print ''.$langs->trans("EditCP").''; } - if($user->rights->holiday->delete && $cp->statut == 1) - { - print ''.$langs->trans("DeleteCP").''; - } if($user->id == $cp->fk_user && $cp->statut == 1) { - print ''.$langs->trans("SendToValidationCP").''; + print ''.$langs->trans("Validate").''; } - + if($user->rights->holiday->delete && $cp->statut == 1) + { + print ''.$langs->trans("DeleteCP").''; + } + // Si le statut est en attente de validation et que le valideur est connecté - if($userID == $cp->fk_validator && $cp->statut == 2) + if ($userID == $cp->fk_validator && $cp->statut == 2) { - print ''.$langs->trans("ActionValidCP").''; + print ''.$langs->trans("Approve").''; print ''.$langs->trans("ActionRefuseCP").''; - print ''.$langs->trans("ActionCancelCP").''; } + if (($userID == $cp->fk_validator && $cp->statut == 2) || ($cp->date_debut > dol_now()) || $user->admin) + { + print ''.$langs->trans("ActionCancelCP").''; + } + print ''; } diff --git a/htdocs/holiday/index.php b/htdocs/holiday/index.php index 12e0c0fb493..7b4e163e569 100644 --- a/htdocs/holiday/index.php +++ b/htdocs/holiday/index.php @@ -57,7 +57,6 @@ $search_employe = GETPOST('search_employe'); $search_valideur = GETPOST('search_valideur'); $search_statut = GETPOST('select_statut'); -$holiday = new Holiday($db); /* * Actions @@ -71,6 +70,9 @@ $holiday = new Holiday($db); * View */ +$holiday = new Holiday($db); +$holidaystatic=new Holiday($db); + $max_year = 5; $min_year = 10; $filter=''; @@ -268,35 +270,44 @@ $holiday->selectStatutCP($search_statut); print ''; print "\n"; + +// Lines if (! empty($holiday->holiday)) { + $userstatic = new User($db); + $approbatorstatic = new User($db); + foreach($holiday->holiday as $infos_CP) { $var=!$var; // Utilisateur - $user = new User($db); - $user->fetch($infos_CP['fk_user']); + $userstatic->id=$infos_CP['fk_user']; + $userstatic->lastname=$infos_CP['user_lastname']; + $userstatic->firstname=$infos_CP['user_firstname']; // Valideur - $validator = new User($db); - $validator->fetch($infos_CP['fk_validator']); - + $approbatorstatic->id=$infos_CP['fk_validator']; + $approbatorstatic->lastname=$infos_CP['validator_lastname']; + $approbatorstatic->firstname=$infos_CP['validator_firstname']; + $date = $infos_CP['date_create']; - $statut = $holiday->getStatutCP($infos_CP['statut']); - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print ''."\n"; } diff --git a/htdocs/holiday/month_report.php b/htdocs/holiday/month_report.php index b581a3b5bfd..fe70a4d202a 100644 --- a/htdocs/holiday/month_report.php +++ b/htdocs/holiday/month_report.php @@ -44,6 +44,7 @@ if(!$user->rights->holiday->month_report) accessforbidden(); $html = new Form($db); $htmlother = new FormOther($db); +$holidaystatic = new Holiday($db); llxHeader(array(),$langs->trans('CPTitreMenu')); @@ -59,13 +60,12 @@ if(empty($year)) { $year = date('Y'); } -$sql = "SELECT cp.fk_user, cp.date_debut, cp.date_fin"; +$sql = "SELECT cp.rowid, cp.fk_user, cp.date_debut, cp.date_fin, cp.halfday"; $sql.= " FROM llx_holiday cp"; $sql.= " LEFT JOIN llx_user u ON cp.fk_user = u.rowid"; -$sql.= " WHERE cp.rowid > '0'"; -$sql.= " AND cp.statut = 3"; -$sql.= " AND (date_format(cp.date_debut, '%Y-%m') = '$year-$month' -OR date_format(cp.date_fin, '%Y-%m') = '$year-$month')"; +$sql.= " WHERE cp.statut = 3"; // Approved +// TODO Use BETWEEN instead of date_format +$sql.= " AND (date_format(cp.date_debut, '%Y-%m') = '$year-$month' OR date_format(cp.date_fin, '%Y-%m') = '$year-$month')"; $sql.= " ORDER BY u.name,cp.date_debut"; $result = $db->query($sql); @@ -77,53 +77,62 @@ print '
'; print '
'."\n"; -print 'Choix mois :  '; +print 'Choix mois :  '; $htmlother->select_year($year,'year_start',1,10,3); print ''; print ''; -print '
'; +print '
'; $var=true; print '
'.$langs->trans("InfosCP").'
'.$langs->trans("Ref").''.$cp->rowid.''; + print $form->showrefnav($cp, 'id', $linkback, 1, 'rowid', 'ref'); + print '
'.$langs->trans('DateDebCP').''.dol_print_date($cp->date_debut,'day').''.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')'.dol_print_date($cp->date_debut,'day'); + print '     '; + print $langs->trans($listhalfday[$starthalfday]); + print '
'.$langs->trans('DateDebCP').''.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')'; $form->select_date($cp->date_debut,'date_debut_'); + print '     '; + print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday')?GETPOST('starthalfday'):$starthalfday)); print '
'.$langs->trans('DateFinCP').''.dol_print_date($cp->date_fin,'day').''.$langs->trans('DateFinCP').' ('.$langs->trans("LastDayOfHoliday").')'.dol_print_date($cp->date_fin,'day'); + print '     '; + print $langs->trans($listhalfday[$endhalfday]); + print '
'.$langs->trans('DateFinCP').''.$langs->trans('DateFinCP').' ('.$langs->trans("LastDayOfHoliday").')'; $form->select_date($cp->date_fin,'date_fin_'); + print '     '; + print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday')?GETPOST('endhalfday'):$endhalfday)); print '
'.$langs->trans('NbUseDaysCP').''.num_open_day($cp->date_debut,$cp->date_fin,0,1).''.num_open_day($cp->date_debut, $cp->date_fin, 0, 1, $cp->halfday).'
'.$langs->trans('StatutCP').''.$cp->getStatutCP($cp->statut).''.$cp->getLibStatut(2).'
'.$langs->trans('DetailRefusCP').''.$cp->detail_refuse.'
'.$langs->trans('DescCP').''.nl2br($cp->description).'
'.$langs->trans('DescCP').'
CP '.$infos_CP['rowid'].''.dol_print_date($date,'day').''.$user->getNomUrl('1').''.$validator->getNomUrl('1').''.dol_print_date($infos_CP['date_debut'],'day').''.dol_print_date($infos_CP['date_fin'],'day').''; - $nbopenedday=num_open_day($infos_CP['date_debut'],$infos_CP['date_fin'],0,1); + $holidaystatic->id=$infos_CP['rowid']; + $holidaystatic->ref=$infos_CP['rowid']; + print $holidaystatic->getNomUrl(1); + print ''.dol_print_date($date,'day').''.$userstatic->getNomUrl('1').''.$approbatorstatic->getNomUrl('1').''.dol_print_date($infos_CP['date_debut'],'day').''.dol_print_date($infos_CP['date_fin'],'day').''; + $nbopenedday=num_open_day($infos_CP['date_debut'], $infos_CP['date_fin'] ,0, 1, $infos_CP['halfday']); print $nbopenedday; - print ''.$statut.''.$holidaystatic->LibStatut($infos_CP['statut'],5).'
'; print ''; +print ''; print ''; print ''; print ''; -print ''; +print ''; print ''; if($num == '0') { print ''; - print ''; + print ''; print ''; } else { - while($holiday = $db->fetch_array($result)){ + while ($holiday = $db->fetch_array($result)) + { $user = new User($db); $user->fetch($holiday['fk_user']); $var=!$var; - if(substr($holiday['date_debut'],5,2)==$month-1){ + $holidaystatic->id=$holiday['rowid']; + $holidaystatic->ref=$holiday['rowid']; + + $start_date=$db->jdate($holiday['date_debut']); + $end_date=$db->jdate($holiday['date_fin']); + /*if(substr($holiday['date_debut'],5,2)==$month-1){ $holiday['date_debut'] = date('Y-'.$month.'-01'); } if(substr($holiday['date_fin'],5,2)==$month+1){ $holiday['date_fin'] = date('Y-'.$month.'-t'); - } + }*/ print ''; + print ''; print ''; - print ''; - print ''; - print ''; + print ''; + print ''; print ''; diff --git a/htdocs/langs/en_US/holiday.lang b/htdocs/langs/en_US/holiday.lang index be69bbd2291..2b83b1fcb1d 100755 --- a/htdocs/langs/en_US/holiday.lang +++ b/htdocs/langs/en_US/holiday.lang @@ -15,12 +15,12 @@ DateFinCP=End date DateCreateCP=Creation date DraftCP=Draft ToValidateCP=Awaiting approval -ValidateCP=Validated +ValidateCP=Approved CancelCP=Canceled RefuseCP=Refused -ValidatorCP=Validator +ValidatorCP=Approbator ListeCP=List of holidays -ValidateByCP=Will be validated by +ValidateByCP=Will be approved by DescCP=Description SendRequestCP=Creating demand for holidays DelayToRequestCP=Applications for holidays must be made at least %s day(s) before them. @@ -47,17 +47,17 @@ StatutCP=Status SendToValidationCP=Send to validation TitleDeleteCP=Delete the request of holidays ConfirmDeleteCP=Confirm the deletion of this request for holidays? -ErrorCantDeleteCP=Error you don't have the right to delete this request of holidays. +ErrorCantDeleteCP=Error you don't have the right to delete this holiday request. CantCreateCP=You don't have the right to apply for holidays. -InvalidValidatorCP=You must choose a validator to your request of holidays. +InvalidValidatorCP=You must choose an approbator to your holiday request. UpdateButtonCP=Update CantUpdate=You cannot update this request of holidays. NoDateDebut=You must select a start date. NoDateFin=You must select an end date. ErrorDureeCP=Your request for holidays does not contain working day. -TitleValidCP=Validate the request holidays -ConfirmValidCP=Are you sure you want to validate the request of holidays? -DateValidCP=Date validation +TitleValidCP=Approve the request holidays +ConfirmValidCP=Are you sure you want to approve the holiday request? +DateValidCP=Date approved TitleToValidCP=Send request holidays ConfirmToValidCP=Are you sure you want to send the request of holidays? TitleRefuseCP=Refuse the request holidays @@ -91,15 +91,15 @@ LastDayOfHoliday=Last day of holiday ConfCP=Configuration of holidays module DescOptionCP=Description of the option ValueOptionCP=Value -GroupToValidateCP=Group with the ability to validate holidays +GroupToValidateCP=Group with the ability to approve holidays ConfirmConfigCP=Validate the configuration LastUpdateCP=Last updated automatically of holidays UpdateConfCPOK=Updated successfully. ErrorUpdateConfCP=An error occurred during the update, please try again. AddCPforUsers=Please add the balance of holidays of users by clicking here. DelayForSubmitCP=Deadline to apply for holidays -AlertValidatorDelayCP=Prevent the validator if the holiday request does not match the deadline -AlertValidorSoldeCP=Prevent the validator if the holiday request exceed the balance +AlertapprobatortorDelayCP=Prevent the approbator if the holiday request does not match the deadline +AlertValidorSoldeCP=Prevent the approbator if the holiday request exceed the balance nbUserCP=Number of users supported in the module holidays nbHolidayDeductedCP=Number of holidays to be deducted per day of holiday taken nbHolidayEveryMonthCP=Number of holidays added every month diff --git a/htdocs/langs/fr_FR/holiday.lang b/htdocs/langs/fr_FR/holiday.lang index a7358319bda..60c7594fe90 100644 --- a/htdocs/langs/fr_FR/holiday.lang +++ b/htdocs/langs/fr_FR/holiday.lang @@ -14,13 +14,13 @@ DateDebCP=Date Début DateFinCP=Date Fin DateCreateCP=Date de création DraftCP=Brouillon -ToValidateCP=En attente de validation -ValidateCP=Validée +ToValidateCP=En attente d'approbation +ValidateCP=Approuvé CancelCP=Annulée RefuseCP=Refusée -ValidatorCP=Valideur +ValidatorCP=Approbateur ListeCP=Liste des congés -ValidateByCP=Sera validée par +ValidateByCP=Sera approuvé par DescCP=Description SendRequestCP=Envoyer la demande de congés DelayToRequestCP=Les demandes de congés doivent être faites au moins %s jours avant la date de ceux-ci. @@ -49,7 +49,7 @@ TitleDeleteCP=Supprimer la demande de Congés ConfirmDeleteCP=Confirmer la suppression de cette demande de congés ? ErrorCantDeleteCP=Erreur, vous n'avez pas le droit de supprimer cette demande de congés. CantCreateCP=Vous n'avez pas le droit de faire des demandes de congés. -InvalidValidatorCP=Vous devez choisir un valideur pour votre demande de congés. +InvalidValidatorCP=Vous devez choisir un approbateur pour votre demande de congés. UpdateButtonCP=Mettre à jour CantUpdate=Vous ne pouvez pas mettre à jour cette demande de congés. NoDateDebut=Vous devez choisir une date de début. @@ -57,7 +57,7 @@ NoDateFin=Vous devez choisir une date de fin. ErrorDureeCP=Votre demande de congés payés ne contient aucun jour ouvré. TitleValidCP=Valider la demande de Congés Payés ConfirmValidCP=Êtes-vous sûr de vouloir valider la demande de congés ? -DateValidCP=Date de validation +DateValidCP=Date d'approbation TitleToValidCP=Envoyer la demande de Congés Payés ConfirmToValidCP=Êtes-vous sûr de vouloir envoyer la demande de congés ? TitleRefuseCP=Refuser la demande de Congés Payés
'.$langs->trans('Ref').''.$langs->trans('Employee').''.$langs->trans('DateDebCP').''.$langs->trans('DateFinCP').''.$langs->trans('nbJours').''.$langs->trans('nbJours').'
'.$langs->trans('NoCPforMonth').''.$langs->trans('None').'
'.$holidaystatic->getNomUrl(1).''.$user->nom.' '.$user->prenom.''.$holiday['date_debut'].''.$holiday['date_fin'].''; - $nbopenedday=num_open_day($holiday['date_debut'],$holiday['date_fin'],0,1); + print ''.dol_print_date($start_date,'day'); + print ''.dol_print_date($end_date,'day'); + print ''; + $nbopenedday=num_open_day($start_date, $end_date, 0, 1, $holiday['halfday']); print $nbopenedday; print '