diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 19b46f8f75c..0f0b2474d51 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -1319,11 +1319,11 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr global $daytoparse; $tmparray = dol_getdate($daytoparse, true); // detail of current day - $idw = $tmparray['wday']; + $idw = ($tmparray['wday'] - (empty($conf->global->MAIN_START_WEEK)?0:1)); global $numstartworkingday, $numendworkingday; $cssweekend = ''; - if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday) // This is a day is not inside the setup of working days, so we use a week-end css. + if ((($idw + 1) < $numstartworkingday) || (($idw + 1) > $numendworkingday)) // This is a day is not inside the setup of working days, so we use a week-end css. { $cssweekend = 'weekend'; } @@ -1702,12 +1702,13 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ global $numstartworkingday, $numendworkingday; $cssweekend = ''; - if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday) // This is a day is not inside the setup of working days, so we use a week-end css. + if (($idw + 1 < $numstartworkingday) || ($idw + 1 > $numendworkingday)) // This is a day is not inside the setup of working days, so we use a week-end css. { $cssweekend = 'weekend'; } $tableCell = ''; + //$tableCell .= 'idw='.$idw.' '.$conf->global->MAIN_START_WEEK.' '.$numstartworkingday.'-'.$numendworkingday; $placeholder = ''; if ($alreadyspent) { diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index a0f640f0cd3..262185df4c5 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -1102,7 +1102,7 @@ class Holiday extends CommonObject /** - * Check that a user is not on holiday for a particular timestamp + * Check that a user is not on holiday for a particular timestamp. Can check approved leave requests and not into public holidays of company. * * @param int $fk_user Id user * @param integer $timestamp Time stamp date for a day (YYYY-MM-DD) without hours (= 12:00AM in english and not 12:00PM that is 12:00) @@ -1117,6 +1117,7 @@ class Holiday extends CommonObject $isavailablemorning = true; $isavailableafternoon = true; + // Check into leave requests $sql = "SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut"; $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp"; $sql .= " WHERE cp.entity IN (".getEntity('holiday').")"; @@ -1161,7 +1162,10 @@ class Holiday extends CommonObject } } else dol_print_error($this->db); - return array('morning'=>$isavailablemorning, 'afternoon'=>$isavailableafternoon); + $result = array('morning'=>$isavailablemorning, 'afternoon'=>$isavailableafternoon); + if (!$isavailablemorning) $result['morning_reason'] = 'leave_request'; + if (!$isavailableafternoon) $result['afternoon_reason'] = 'leave_request'; + return $result; } diff --git a/htdocs/projet/activity/perday.php b/htdocs/projet/activity/perday.php index 361e70c3cf7..cb16f4685bf 100644 --- a/htdocs/projet/activity/perday.php +++ b/htdocs/projet/activity/perday.php @@ -48,8 +48,7 @@ $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'per $mine = 0; if ($mode == 'mine') $mine = 1; -$projectid = ''; -$projectid = isset($_GET["id"]) ? $_GET["id"] : $_POST["projectid"]; +$projectid = isset($_GET["id"]) ? GETPOST("id", "int", 1) : GETPOST("projectid", "int"); $hookmanager->initHooks(array('timesheetperdaycard')); @@ -612,20 +611,24 @@ if (!empty($conf->global->MAIN_DEFAULT_WORKING_DAYS)) } } -$statusofholidaytocheck = '3'; +$statusofholidaytocheck = Holiday::STATUS_APPROVED; $isavailablefordayanduser = $holiday->verifDateHolidayForTimestamp($usertoprocess->id, $daytoparse, $statusofholidaytocheck); // $daytoparse is a date with hours = 0 $isavailable[$daytoparse] = $isavailablefordayanduser; // in projectLinesPerWeek later, we are using $firstdaytoshow and dol_time_plus_duree to loop on each day -$tmparray = dol_getdate($daytoparse, true); // detail of current day -$idw = $tmparray['wday']; +$test = num_public_holiday($daytoparse, $daytoparse + 86400, $mysoc->country_code); +if ($test) $isavailable[$daytoparse] = array('morning'=>false, 'afternoon'=>false, 'morning_reason'=>'public_holiday', 'afternoon_reason'=>'public_holiday'); +$tmparray = dol_getdate($daytoparse, true); // detail of current day +// For monday, must be 0 for monday if MAIN_START_WEEK = 1, must be 1 for monday if MAIN_START_WEEK = 0 +$idw = ($tmparray['wday'] - (empty($conf->global->MAIN_START_WEEK)?0:1)); +// numstartworkingday and numendworkingday are default start and end date of working days (1 means sunday if MAIN_START_WEEK is 0, 1 means monday if MAIN_START_WEEK is 1) $cssweekend = ''; -if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday) // This is a day is not inside the setup of working days, so we use a week-end css. +if ((($idw + 1) < $numstartworkingday) || (($idw + 1) > $numendworkingday)) // This is a day is not inside the setup of working days, so we use a week-end css. { $cssweekend = 'weekend'; } -$tmpday = dol_time_plus_duree($firstdaytoshow, $idw, 'd'); +$tmpday = dol_time_plus_duree($daytoparse, $idw, 'd'); $cssonholiday = ''; if (!$isavailable[$daytoparse]['morning'] && !$isavailable[$daytoparse]['afternoon']) $cssonholiday .= 'onholidayallday '; @@ -651,20 +654,6 @@ if ($conf->use_javascript_ajax) //print ' - '.$langs->trans("ExpectedWorkedHours").': '.price($usertoprocess->weeklyhours, 1, $langs, 0, 0).''; print ''; - $tmparray = dol_getdate($daytoparse, true); // detail of current day - $idw = $tmparray['wday']; - - $cssweekend = ''; - if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday) // This is a day is not inside the setup of working days, so we use a week-end css. - { - $cssweekend = 'weekend'; - } - - $cssonholiday = ''; - if (!$isavailable[$daytoparse]['morning'] && !$isavailable[$daytoparse]['afternoon']) $cssonholiday .= 'onholidayallday '; - elseif (!$isavailable[$daytoparse]['morning']) $cssonholiday .= 'onholidaymorning '; - elseif (!$isavailable[$daytoparse]['afternoon']) $cssonholiday .= 'onholidayafternoon '; - print '
 
'; print ''; @@ -752,20 +741,6 @@ if (count($tasksarray) > 0) //print ' - '.$langs->trans("ExpectedWorkedHours").': '.price($usertoprocess->weeklyhours, 1, $langs, 0, 0).''; print ''; - $tmparray = dol_getdate($daytoparse, true); // detail of current day - $idw = $tmparray['wday']; - - $cssweekend = ''; - if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday) // This is a day is not inside the setup of working days, so we use a week-end css. - { - $cssweekend = 'weekend'; - } - - $cssonholiday = ''; - if (!$isavailable[$daytoparse]['morning'] && !$isavailable[$daytoparse]['afternoon']) $cssonholiday .= 'onholidayallday '; - elseif (!$isavailable[$daytoparse]['morning']) $cssonholiday .= 'onholidaymorning '; - elseif (!$isavailable[$daytoparse]['afternoon']) $cssonholiday .= 'onholidayafternoon '; - print '
 
'; print ' diff --git a/htdocs/projet/activity/perweek.php b/htdocs/projet/activity/perweek.php index 748f1c307d4..1f808304991 100644 --- a/htdocs/projet/activity/perweek.php +++ b/htdocs/projet/activity/perweek.php @@ -48,8 +48,7 @@ $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'per $mine = 0; if ($mode == 'mine') $mine = 1; -$projectid = ''; -$projectid = isset($_GET["id"]) ? $_GET["id"] : $_POST["projectid"]; +$projectid = isset($_GET["id"]) ? GETPOST("id", "int", 1) : GETPOST("projectid", "int"); $hookmanager->initHooks(array('timesheetperweekcard')); @@ -364,7 +363,6 @@ if ($action == 'addtime' && $user->rights->projet->lire && GETPOST('formfilterac } - /* * View */ @@ -530,11 +528,16 @@ for ($idw = 0; $idw < 7; $idw++) //print dol_print_date($dayinloopwithouthours, 'dayhour').' '; //print dol_print_date($dayinloopfromfirstdaytoshow, 'dayhour').'
'; - $statusofholidaytocheck = '3'; + $statusofholidaytocheck = Holiday::STATUS_APPROVED; $isavailablefordayanduser = $holiday->verifDateHolidayForTimestamp($usertoprocess->id, $dayinloopfromfirstdaytoshow, $statusofholidaytocheck); $isavailable[$dayinloopfromfirstdaytoshow] = $isavailablefordayanduser; // in projectLinesPerWeek later, we are using $firstdaytoshow and dol_time_plus_duree to loop on each day + + $test = num_public_holiday($dayinloopfromfirstdaytoshow, $dayinloopfromfirstdaytoshow + 86400, $mysoc->country_code); + if ($test) $isavailable[$dayinloopfromfirstdaytoshow] = array('morning'=>false, 'afternoon'=>false, 'morning_reason'=>'public_holiday', 'afternoon_reason'=>'public_holiday'); } +//var_dump($isavailable); + $moreforfilter = ''; @@ -656,7 +659,7 @@ for ($idw = 0; $idw < 7; $idw++) $dayinloop = dol_time_plus_duree($startday, $idw, 'd'); $cssweekend = ''; - if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday) // This is a day is not inside the setup of working days, so we use a week-end css. + if ((($idw + 1) < $numstartworkingday) || (($idw + 1) > $numendworkingday)) // This is a day is not inside the setup of working days, so we use a week-end css. { $cssweekend = 'weekend'; } @@ -689,7 +692,7 @@ if ($conf->use_javascript_ajax) for ($idw = 0; $idw < 7; $idw++) { $cssweekend = ''; - if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday) // This is a day is not inside the setup of working days, so we use a week-end css. + if ((($idw + 1) < $numstartworkingday) || (($idw + 1) > $numendworkingday)) // This is a day is not inside the setup of working days, so we use a week-end css. { $cssweekend = 'weekend'; } @@ -700,7 +703,6 @@ if ($conf->use_javascript_ajax) if (!$isavailable[$tmpday]['morning'] && !$isavailable[$tmpday]['afternoon']) $cssonholiday .= 'onholidayallday '; elseif (!$isavailable[$tmpday]['morning']) $cssonholiday .= 'onholidaymorning '; elseif (!$isavailable[$tmpday]['afternoon']) $cssonholiday .= 'onholidayafternoon '; - print '
 
'; } print '
 
'; @@ -775,7 +777,7 @@ if (count($tasksarray) > 0) for ($idw = 0; $idw < 7; $idw++) { $cssweekend = ''; - if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday) // This is a day is not inside the setup of working days, so we use a week-end css. + if ((($idw + 1) < $numstartworkingday) || (($idw + 1) > $numendworkingday)) // This is a day is not inside the setup of working days, so we use a week-end css. { $cssweekend = 'weekend'; } @@ -803,10 +805,9 @@ if (count($tasksarray) > 0) print ' - '.$langs->trans("ExpectedWorkedHours").': '.price($usertoprocess->weeklyhours, 1, $langs, 0, 0).''; print ''; - for ($idw = 0; $idw < 7; $idw++) - { + for ($idw = 0; $idw < 7; $idw++) { $cssweekend = ''; - if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday) // This is a day is not inside the setup of working days, so we use a week-end css. + if ((($idw + 1) < $numstartworkingday) || (($idw + 1) > $numendworkingday)) // This is a day is not inside the setup of working days, so we use a week-end css. { $cssweekend = 'weekend'; }