diff --git a/htdocs/admin/ihm.php b/htdocs/admin/ihm.php index 18a38ca3d8f..84c160351bd 100644 --- a/htdocs/admin/ihm.php +++ b/htdocs/admin/ihm.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -236,7 +236,7 @@ if ($action == 'edit') // Edit print ' '; print ''; - if ($conf->global->MAIN_FEATURES_LEVEL > 1) + if ($conf->global->MAIN_FEATURES_LEVEL >= 1 || ! empty($conf->global->MAIN_BUGTRACK_ENABLELINK)) { // Show bugtrack link $var=!$var; @@ -390,7 +390,7 @@ else // Show print yn((isset($conf->global->MAIN_HELP_DISABLELINK)?$conf->global->MAIN_HELP_DISABLELINK:0),1); print ''; - if ($conf->global->MAIN_FEATURES_LEVEL > 1) + if ($conf->global->MAIN_FEATURES_LEVEL >= 1 || ! empty($conf->global->MAIN_BUGTRACK_ENABLELINK)) { // Show bugtrack link $var=!$var; diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index b021db48448..b0d2c997d05 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -601,7 +601,7 @@ function dol_get_first_day_week($day,$month,$year,$gm=false) } /** - * Fonction retournant le nombre de jour fieries samedis et dimanches entre 2 dates entrees en timestamp + * Fonction retournant le nombre de jour feries samedis et dimanches entre 2 dates entrees en timestamp * Called by function num_open_day * * @param timestamp $timestampStart Timestamp de debut @@ -733,11 +733,12 @@ function num_public_holiday($timestampStart, $timestampEnd, $countrycode='FR') /** * Fonction retournant le nombre de jour entre deux dates + * Example: 2012-01-01 2012-01-02 => 1 if lastday=0, 2 if lastday=1 * * @param timestamp $timestampStart Timestamp de debut * @param timestamp $timestampEnd Timestamp de fin - * @param int $lastday On prend en compte le dernier jour, 0: non, 1:oui - * @return int Nombre de jours + * @param int $lastday Last day is included, 0: non, 1:oui + * @return int Number of days */ function num_between_day($timestampStart, $timestampEnd, $lastday=0) { @@ -751,8 +752,9 @@ function num_between_day($timestampStart, $timestampEnd, $lastday=0) { $bit = 1; } - $nbjours = round(($timestampEnd - $timestampStart)/(60*60*24)-$bit); + $nbjours = (int) floor(($timestampEnd - $timestampStart)/(60*60*24)) + 1 - $bit; } + //print ($timestampEnd - $timestampStart) - $lastday; return $nbjours; } @@ -762,22 +764,29 @@ function num_between_day($timestampStart, $timestampEnd, $lastday=0) * @param timestamp $timestampStart Timestamp de debut * @param timestamp $timestampEnd Timestamp de fin * @param int $inhour 0: sort le nombre de jour , 1: sort le nombre d'heure (72 max) - * @param int $lastday On prend en compte le dernier jour, 0: non, 1:oui + * @param int $lastday We include last day, 0: non, 1:oui * @return int Nombre de jours ou d'heures */ function num_open_day($timestampStart, $timestampEnd,$inhour=0,$lastday=0) { global $langs; + dol_syslog('num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday); + //print 'num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday; if ($timestampStart < $timestampEnd) { - $bit = 0; - if ($lastday == 1) $bit = 1; - $nbOpenDay = num_between_day($timestampStart, $timestampEnd, $bit) - num_public_holiday($timestampStart, $timestampEnd); + //print num_between_day($timestampStart, $timestampEnd, $lastday).' - '.num_public_holiday($timestampStart, $timestampEnd); + $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; } + elseif ($timestampStart == $timestampEnd) + { + $nbOpenDay=$lastday; + if ($inhour == 1) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort"); + return $nbOpenDay=1; + } else { return $langs->trans("Error"); diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index 3a476b109a5..83c1a38ed0a 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -109,8 +109,8 @@ class Holiday extends CommonObject } $sql.= " NOW(),"; $sql.= " '".addslashes($this->description)."',"; - $sql.= " '".$this->date_debut."',"; - $sql.= " '".$this->date_fin."',"; + $sql.= " '".$this->db->idate($this->date_debut)."',"; + $sql.= " '".$this->db->idate($this->date_fin)."',"; $sql.= " '1',"; if(is_numeric($this->fk_validator)) { $sql.= " '".$this->fk_validator."'"; @@ -196,17 +196,17 @@ class Holiday extends CommonObject $this->rowid = $obj->rowid; $this->fk_user = $obj->fk_user; - $this->date_create = $obj->date_create; + $this->date_create = $this->db->jdate($obj->date_create); $this->description = $obj->description; - $this->date_debut = $obj->date_debut; - $this->date_fin = $obj->date_fin; + $this->date_debut = $this->db->jdate($obj->date_debut); + $this->date_fin = $this->db->jdate($obj->date_fin); $this->statut = $obj->statut; $this->fk_validator = $obj->fk_validator; - $this->date_valid = $obj->date_valid; + $this->date_valid = $this->db->jdate($obj->date_valid); $this->fk_user_valid = $obj->fk_user_valid; - $this->date_refuse = $obj->date_refuse; + $this->date_refuse = $this->db->jdate($obj->date_refuse); $this->fk_user_refuse = $obj->fk_user_refuse; - $this->date_cancel = $obj->date_cancel; + $this->date_cancel = $this->db->jdate($obj->date_cancel); $this->fk_user_cancel = $obj->fk_user_cancel; $this->detail_refuse = $obj->detail_refuse; @@ -289,17 +289,17 @@ class Holiday extends CommonObject $tab_result[$i]['rowid'] = $obj->rowid; $tab_result[$i]['fk_user'] = $obj->fk_user; - $tab_result[$i]['date_create'] = $obj->date_create; + $tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create); $tab_result[$i]['description'] = $obj->description; - $tab_result[$i]['date_debut'] = $obj->date_debut; - $tab_result[$i]['date_fin'] = $obj->date_fin; + $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]['statut'] = $obj->statut; $tab_result[$i]['fk_validator'] = $obj->fk_validator; - $tab_result[$i]['date_valid'] = $obj->date_valid; + $tab_result[$i]['date_valid'] = $this->db->jdate($obj->date_valid); $tab_result[$i]['fk_user_valid'] = $obj->fk_user_valid; - $tab_result[$i]['date_refuse'] = $obj->date_refuse; + $tab_result[$i]['date_refuse'] = $this->db->jdate($obj->date_refuse); $tab_result[$i]['fk_user_refuse'] = $obj->fk_user_refuse; - $tab_result[$i]['date_cancel'] = $obj->date_cancel; + $tab_result[$i]['date_cancel'] = $this->db->jdate($obj->date_cancel); $tab_result[$i]['fk_user_cancel'] = $obj->fk_user_cancel; $tab_result[$i]['detail_refuse'] = $obj->detail_refuse; @@ -430,12 +430,12 @@ class Holiday extends CommonObject $sql.= " description= '".addslashes($this->description)."',"; if(!empty($this->date_debut)) { - $sql.= " date_debut = '".$this->date_debut."',"; + $sql.= " date_debut = '".$this->db->idate($this->date_debut)."',"; } else { $error++; } if(!empty($this->date_fin)) { - $sql.= " date_fin = '".$this->date_fin."',"; + $sql.= " date_fin = '".$this->db->idate($this->date_fin)."',"; } else { $error++; } @@ -450,7 +450,7 @@ class Holiday extends CommonObject $error++; } if(!empty($this->date_valid)) { - $sql.= " date_valid = '".$this->date_valid."',"; + $sql.= " date_valid = '".$this->db->idate($this->date_valid)."',"; } else { $sql.= " date_valid = NULL,"; } @@ -460,7 +460,7 @@ class Holiday extends CommonObject $sql.= " fk_user_valid = NULL,"; } if(!empty($this->date_refuse)) { - $sql.= " date_refuse = '".$this->date_refuse."',"; + $sql.= " date_refuse = '".$this->db->idate($this->date_refuse)."',"; } else { $sql.= " date_refuse = NULL,"; } @@ -470,7 +470,7 @@ class Holiday extends CommonObject $sql.= " fk_user_refuse = NULL,"; } if(!empty($this->date_cancel)) { - $sql.= " date_cancel = '".$this->date_cancel."',"; + $sql.= " date_cancel = '".$this->db->idate($this->date_cancel)."',"; } else { $sql.= " date_cancel = NULL,"; } @@ -1214,56 +1214,6 @@ class Holiday extends CommonObject } - /** - * Retourne le nombre de jours ouvrés entre deux dates - * Prise en compte des jours fériés en France - * - * @param date $date_start Start date - * @param date $date_stop Stop date - * @return int Nb of days - */ - - function getOpenDays($date_start, $date_stop) { - - // Tableau des jours feriés - $arr_bank_holidays = array(); - - // On boucle dans le cas où l'année de départ serait différente de l'année d'arrivée - $diff_year = date('Y', $date_stop) - date('Y', $date_start); - - for ($i = 0; $i <= $diff_year; $i++) { - $year = (int) date('Y', $date_start) + $i; - // Liste des jours feriés - $arr_bank_holidays[] = '1_1_'.$year; // Jour de l'an - $arr_bank_holidays[] = '1_5_'.$year; // Fete du travail - $arr_bank_holidays[] = '8_5_'.$year; // Victoire 1945 - $arr_bank_holidays[] = '14_7_'.$year; // Fete nationale - $arr_bank_holidays[] = '15_8_'.$year; // Assomption - $arr_bank_holidays[] = '1_11_'.$year; // Toussaint - $arr_bank_holidays[] = '11_11_'.$year; // Armistice 1918 - $arr_bank_holidays[] = '25_12_'.$year; // Noel - // Récupération de paques. Permet ensuite d'obtenir le jour de l'ascension et celui de la pentecote - $easter = easter_date($year); - $arr_bank_holidays[] = date('j_n_'.$year, $easter + 86400); // Paques - $arr_bank_holidays[] = date('j_n_'.$year, $easter + (86400*39)); // Ascension - $arr_bank_holidays[] = date('j_n_'.$year, $easter + (86400*50)); // Pentecote - } - - $nb_days_open = 0; - - while ($date_start <= $date_stop) { - // Si le jour suivant n'est ni un dimanche (0) ou un samedi (6), ni un jour férié, on incrémente les jours ouvrés - if (!in_array(date('w', $date_start), array(0, 6)) && !in_array(date('j_n_'.date('Y', $date_start), $date_start), $arr_bank_holidays)) { - $nb_days_open++; - } - - $date_start = mktime(date('H', $date_start), date('i', $date_start), date('s', $date_start), date('m', $date_start), date('d', $date_start) + 1, date('Y', $date_start)); - } - - // On retourne le nombre de jours ouvrés - return $nb_days_open; - } - /** * Liste les évènements de congés payés enregistré * diff --git a/htdocs/holiday/fiche.php b/htdocs/holiday/fiche.php index 11ba6d0eb3e..9bfaaf8b32f 100644 --- a/htdocs/holiday/fiche.php +++ b/htdocs/holiday/fiche.php @@ -28,11 +28,13 @@ require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php'; // Get parameters $myparam = GETPOST("myparam"); $action=GETPOST('action'); +$id=GETPOST('id'); // Protection if external user if ($user->societe_id > 0) accessforbidden(); @@ -46,7 +48,7 @@ $user_id = $user->id; ********************************************************************/ // Si création de la demande -if ($action == 'add') +if ($action == 'create') { // Si pas le droit de créer une demande @@ -92,14 +94,15 @@ if ($action == 'add') $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 - if(!$verifCP) + if (! $verifCP) { header('Location: fiche.php?action=request&error=alreadyCP'); exit; } // Si aucun jours ouvrés dans la demande - if($cp->getOpenDays($testDateDebut,$testDateFin) < 1) + $nbopenedday=num_open_day($testDateDebut,$testDateFin,0,1); + if($nbopenedday < 1) { header('Location: fiche.php?action=request&error=DureeHoliday'); exit; @@ -137,6 +140,8 @@ if ($action == 'add') 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']); // Si pas le droit de modifier une demande if(!$user->rights->holiday->write) @@ -151,12 +156,9 @@ if ($action == 'update') // Si en attente de validation if ($cp->statut == 1) { - // Si c'est le créateur ou qu'il a le droit de tout lire / modifier if ($user->id == $cp->fk_user || $user->rights->holiday->lire_tous) { - $date_debut = $_POST['date_debut_year'].'-'.str_pad($_POST['date_debut_month'],2,"0",STR_PAD_LEFT).'-'.str_pad($_POST['date_debut_day'],2,"0",STR_PAD_LEFT); - $date_fin = $_POST['date_fin_year'].'-'.str_pad($_POST['date_fin_month'],2,"0",STR_PAD_LEFT).'-'.str_pad($_POST['date_fin_day'],2,"0",STR_PAD_LEFT); $valideur = $_POST['valideur']; $description = trim($_POST['description']); @@ -172,8 +174,8 @@ if ($action == 'update') exit; } - $testDateDebut = strtotime($date_debut); - $testDateFin = strtotime($date_fin); + $testDateDebut = $date_debut; + $testDateFin = $date_fin; // Si date de début après la date de fin if ($testDateDebut > $testDateFin) { @@ -188,7 +190,9 @@ if ($action == 'update') } // Si pas de jours ouvrés dans la demande - if ($cp->getOpenDays($testDateDebut,$testDateFin) < 1) { + $nbopenedday=num_open_day($testDateDebut,$testDateFin,0,1); + if ($nbopenedday < 1) + { header('Location: fiche.php?id='.$_POST['holiday_id'].'&action=edit&error=DureeHoliday'); exit; } @@ -284,9 +288,10 @@ if ($action == 'confirm_send') $message.= "Veuillez trouver ci-dessous une demande de congés payés à valider.\n"; $delayForRequest = $cp->getConfCP('delayForRequest'); - $delayForRequest = $delayForRequest * (60*60*24); + //$delayForRequest = $delayForRequest * (60*60*24); - $nextMonth = date('Y-m-d', time()+$delayForRequest); + $now=dol_now(); + $nextMonth = dol_time_plus_duree($now, $delayForRequest, 'd'); // Si l'option pour avertir le valideur en cas de délai trop court if($cp->getConfCP('AlertValidatorDelay')) { @@ -299,7 +304,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->getOpenDays(strtotime($cp->date_debut),strtotime($cp->date_fin)) > $cp->getCPforUser($cp->fk_user)) { + $nbopenedday=num_open_day($cp->date_debut,$cp->date_fin,0,1); + if ($nbopenedday > $cp->getCPforUser($cp->fk_user)) + { $message.= "\n"; $message.= "L'utilisateur ayant fait cette demande de congés payés n'a pas le solde requis.\n"; } @@ -331,10 +338,10 @@ if ($action == 'confirm_send') } } + // Si Validation de la demande if($action == 'confirm_valid') { - $cp = new Holiday($db); $cp->fetch($_GET['id']); @@ -344,7 +351,7 @@ if($action == 'confirm_valid') if($cp->statut == 2 && $userID == $cp->fk_validator) { - $cp->date_valid = date('Y-m-d H:i:s', time()); + $cp->date_valid = dol_now(); $cp->fk_user_valid = $user->id; $cp->statut = 3; @@ -354,7 +361,7 @@ if($action == 'confirm_valid') if($verif > 0) { // Retrait du nombre de jours prit - $nbJour = $cp->getOpenDays(strtotime($cp->date_debut),strtotime($cp->date_fin)); + $nbJour = $nbopenedday=num_open_day($cp->date_debut,$cp->date_fin,0,1); $soldeActuel = $cp->getCpforUser($cp->fk_user); $newSolde = $soldeActuel - ($nbJour*$cp->getConfCP('nbHolidayDeducted')); @@ -570,7 +577,7 @@ if ($action == 'confirm_cancel' && $_GET['confirm'] == 'yes') llxHeader(array(),$langs->trans('CPTitreMenu')); -if ($action == 'request') +if (empty($id) || $action == 'add' || $action == 'request') { // Si l'utilisateur n'a pas le droit de faire une demande if(!$user->rights->holiday->write) @@ -619,9 +626,9 @@ if ($action == 'request') $cp = new Holiday($db); $delayForRequest = $cp->getConfCP('delayForRequest'); - $delayForRequest = $delayForRequest * (60*60*24); + //$delayForRequest = $delayForRequest * (60*60*24); - $nextMonth = date('Y-m-d', time()+$delayForRequest); + $nextMonth = dol_time_plus_duree($now, $delayForRequest, 'd'); print '