Skip to content

Commit

Permalink
#88 [TimeSheet] add: show only tasks with timespent on timesheet docu…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
evarisk-theo committed Dec 8, 2022
1 parent 53e6317 commit 713048e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
10 changes: 10 additions & 0 deletions admin/timesheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@
print '</td>';
print '</tr>';

print '<tr class="oddeven"><td>';
print $langs->trans('ShowOnlyTasksWithTimespentOnTimeSheet');
print "</td><td>";
print $langs->trans('ShowOnlyTasksWithTimespentOnTimeSheetDescription');
print '</td>';
print '<td class="center">';
print ajax_constantonoff('DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT_ON_TIMESHEET');
print '</td>';
print '</tr>';

print '</table>';

// Page end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid

$daystarttoshow = $object->date_start - 12 * 3600;
$lastdaytoshow = $object->date_end - 12 * 3600;

$daysInRange = num_between_day($object->date_start, $object->date_end, 1);
$daysInRange = !empty($daysInRange) ? $daysInRange : 1;
$daysInRangeArray = array();
Expand All @@ -327,7 +328,7 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
}
}

$timeSpentOnTasks = loadTimeSpentOnTasksWithinRange($daystarttoshow, $lastdaytoshow, $isavailable, $object->fk_user_assign);
$timeSpentOnTasks = loadTimeSpentOnTasksWithinRange($daystarttoshow, $lastdaytoshow + 1, $isavailable, $object->fk_user_assign);

$tmparray['employee_firstname'] = $usertmp->firstname;
$tmparray['employee_lastname'] = $usertmp->lastname;
Expand Down Expand Up @@ -435,7 +436,7 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
}

// Get all tasks except HR project task
$totaltime = array();
$totaltimewithoutHRproject = array();
$foundtagforlines = 1;
try {
$listlines = $odfHandler->setSegment('times');
Expand All @@ -452,24 +453,25 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
if (is_array($tasksArray) && !empty($tasksArray)) {
foreach ($tasksArray as $tasksingle) {
for ($idw = 1; $idw <= 31; $idw++) {
$tmparray['task_ref'] = $tasksingle->ref;
$tmparray['task_label'] = dol_trunc($tasksingle->label, 16);
$tmparray['task_ref'] = $tasksingle->ref;
$tmparray['task_label'] = dol_trunc($tasksingle->label, 16);
if (in_array($idw, $daysInRangeArray)) {
$dayInLoop = dol_time_plus_duree($daystarttoshow, array_search($idw, $daysInRangeArray), 'd');
$dayInLoop = dol_time_plus_duree($daystarttoshow, $idw - 1, 'd');
$tmparray['time' . $idw] = (($timeSpentOnTasks[$tasksingle->id][dol_print_date($dayInLoop, 'day')] != 0) ? convertSecondToTime($timeSpentOnTasks[$tasksingle->id][dol_print_date($dayInLoop, 'day')], (is_float($timeSpentOnTasks[$tasksingle->id][dol_print_date($dayInLoop, 'day')]/3600) ? 'allhourmin' : 'allhour')) : '-');
$totaltime[$dayInLoop] += $timeSpentOnTasks[$tasksingle->id][dol_print_date($dayInLoop, 'day')];
$totaltimewithoutHRproject[$dayInLoop] += $timeSpentOnTasks[$tasksingle->id][dol_print_date($dayInLoop, 'day')];
} else {
$tmparray['time' . $idw] = '-';
}
}

$this->setTmparrayVars($tmparray, $listlines);
if ($conf->global->DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT_ON_TIMESHEET && $timeSpentOnTasks[$tasksingle->id] > 0) {
$this->setTmparrayVars($tmparray, $listlines);
}
}
$odfHandler->mergeSegment($listlines);
}
}

// Get HR project task
// Get HR project task
$i = 0;
$segment = array(
array('csss', 'cps', 'rtts', 'jfs', 'cms',), // Row name
Expand All @@ -491,7 +493,7 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
if ($foundtagforlines) {
for ($idw = 1; $idw <= 31; $idw++) {
if (in_array($idw, $daysInRangeArray)) {
$dayInLoop = dol_time_plus_duree($daystarttoshow, array_search($idw, $daysInRangeArray), 'd');
$dayInLoop = dol_time_plus_duree($daystarttoshow, $idw - 1, 'd');
$tmparray[$segment[1][$i] . $idw] = (($timeSpentOnTasks[$tasksingle->id][dol_print_date($dayInLoop, 'day')] != 0) ? convertSecondToTime($timeSpentOnTasks[$tasksingle->id][dol_print_date($dayInLoop, 'day')], (is_float($timeSpentOnTasks[$tasksingle->id][dol_print_date($dayInLoop, 'day')]/3600) ? 'allhourmin' : 'allhour')) : '-');
$totaltimehrproject[$dayInLoop] += $timeSpentOnTasks[$tasksingle->id][dol_print_date($dayInLoop, 'day')];
} else {
Expand Down Expand Up @@ -519,7 +521,7 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
if ($foundtagforlines) {
for ($idw = 1; $idw <= 31; $idw++) {
if (in_array($idw, $daysInRangeArray)) {
$dayInLoop = dol_time_plus_duree($daystarttoshow, array_search($idw, $daysInRangeArray), 'd');
$dayInLoop = dol_time_plus_duree($daystarttoshow, $idw - 1, 'd');
$tmparray['totalrh' . $idw] = (($totaltimehrproject[$dayInLoop] != 0) ? convertSecondToTime($totaltimehrproject[$dayInLoop], (is_float($totaltimehrproject[$dayInLoop]/3600) ? 'allhourmin' : 'allhour')) : '-');
} else {
$tmparray['totalrh' . $idw] = '-';
Expand All @@ -530,7 +532,7 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
$odfHandler->mergeSegment($listlines);
}

// Total time spent whithout Project RH
// Total time spent without Project RH
$foundtagforlines = 1;
try {
$listlines = $odfHandler->setSegment('totaltimes');
Expand All @@ -543,8 +545,8 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
if ($foundtagforlines) {
for ($idw = 1; $idw <= 31; $idw++) {
if (in_array($idw, $daysInRangeArray)) {
$dayInLoop = dol_time_plus_duree($daystarttoshow, array_search($idw, $daysInRangeArray), 'd');
$tmparray['totaltime' . $idw] = (($totaltime[$dayInLoop] != 0) ? convertSecondToTime($totaltime[$dayInLoop], (is_float($totaltime[$dayInLoop]/3600) ? 'allhourmin' : 'allhour')) : '-');
$dayInLoop = dol_time_plus_duree($daystarttoshow, $idw - 1, 'd');
$tmparray['totaltime' . $idw] = (($totaltimewithoutHRproject[$dayInLoop] != 0) ? convertSecondToTime($totaltimewithoutHRproject[$dayInLoop], (is_float($totaltimewithoutHRproject[$dayInLoop]/3600) ? 'allhourmin' : 'allhour')) : '-');
} else {
$tmparray['totaltime' . $idw] = '-';
}
Expand All @@ -565,12 +567,13 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
dol_syslog($e->getMessage());
}


if ($foundtagforlines) {
for ($idw = 1; $idw <= 31; $idw++) {
if (in_array($idw, $daysInRangeArray)) {
$dayInLoop = dol_time_plus_duree($daystarttoshow, array_search($idw, $daysInRangeArray), 'd');
$totaltimespent[$dayInLoop] = $totaltime[$dayInLoop] + $totaltimehrproject[$dayInLoop];
$tmparray['totaltps' . $idw] = (($totaltime[$dayInLoop] != 0 && $totaltimehrproject[$dayInLoop] != 0) ? convertSecondToTime($totaltimespent[$dayInLoop], (is_float($totaltimespent[$dayInLoop]) ? 'allhourmin' : 'allhour')) : '-');
$dayInLoop = dol_time_plus_duree($daystarttoshow, $idw - 1, 'd');
$totaltimespent[$dayInLoop] = $totaltimewithoutHRproject[$dayInLoop] + $totaltimehrproject[$dayInLoop];
$tmparray['totaltps' . $idw] = (($totaltimewithoutHRproject[$dayInLoop] != 0 && $totaltimehrproject[$dayInLoop] != 0) ? convertSecondToTime($totaltimespent[$dayInLoop], (is_float($totaltimespent[$dayInLoop]) ? 'allhourmin' : 'allhour')) : '-');
} else {
$tmparray['totaltps' . $idw] = '-';
}
Expand All @@ -595,7 +598,7 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
if ($foundtagforlines) {
for ($idw = 1; $idw <= 31; $idw++) {
if (in_array($idw, $daysInRangeArray)) {
$dayInLoop = dol_time_plus_duree($daystarttoshow, array_search($idw, $daysInRangeArray), 'd');
$dayInLoop = dol_time_plus_duree($daystarttoshow, $idw - 1, 'd');
$totaltimeplanned[$dayInLoop] = loadPassedTimeWithinRange($dayInLoop, dol_time_plus_duree($dayInLoop, 1, 'd'), $workingHours, $isavailable);
$tmparray['ta' . $idw] = (($totaltimeplanned[$dayInLoop]['minutes'] != 0) ? convertSecondToTime($totaltimeplanned[$dayInLoop]['minutes'] * 60, (is_float($totaltimeplanned[$dayInLoop]['minutes']/60) ? 'allhourmin' : 'allhour')) : '-');
} else {
Expand All @@ -607,7 +610,7 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
$odfHandler->mergeSegment($listlines);
}

// Diff between time consumed and time spent
// Diff between time planned and time spent
$foundtagforlines = 1;
try {
$listlines = $odfHandler->setSegment('diffs');
Expand All @@ -620,7 +623,7 @@ public function write_file($objectDocument, $outputlangs, $srctemplatepath, $hid
if ($foundtagforlines) {
for ($idw = 1; $idw <= 31; $idw++) {
if (in_array($idw, $daysInRangeArray)) {
$dayInLoop = dol_time_plus_duree($daystarttoshow, array_search($idw, $daysInRangeArray), 'd');
$dayInLoop = dol_time_plus_duree($daystarttoshow, $idw - 1, 'd');
$difftotaltime[$dayInLoop] = $totaltimeplanned[$dayInLoop]['minutes'] * 60 - $totaltimespent[$dayInLoop];
$tmparray['diff' . $idw] = (($difftotaltime[$dayInLoop] != 0) ? convertSecondToTime(abs($difftotaltime[$dayInLoop]), (is_float($difftotaltime[$dayInLoop]/3600) ? 'allhourmin' : 'allhour')) : '-');
} else {
Expand Down
3 changes: 2 additions & 1 deletion core/modules/modDoliSIRH.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,13 @@ public function __construct($db)
$i++ => array('DOLISIRH_TIMESHEET_PREFILL_DATE', 'integer', 1, '', 0, 'current'),
$i++ => array('DOLISIRH_TIMESHEET_ADD_ATTENDANTS', 'integer', 0, '', 0, 'current'),
$i++ => array('DOLISIRH_TIMESHEET_CHECK_DATE_END', 'integer', 1, '', 0, 'current'),
$i++ => array('DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT_ON_TIMESHEET', 'integer', 0, '', 0, 'current'),

// CONST TIMESHEET DOCUMENT
$i++ => array('DOLISIRH_TIMESHEETDOCUMENT_ADDON', 'chaine', 'mod_timesheetdocument_standard', '', 0, 'current'),
$i++ => array('DOLISIRH_TIMESHEETDOCUMENT_ADDON_ODT_PATH', 'chaine', 'DOL_DOCUMENT_ROOT/custom/dolisirh/documents/doctemplates/timesheetdocument/', '', 0, 'current'),
$i++ => array('DOLISIRH_TIMESHEETDOCUMENT_CUSTOM_ADDON_ODT_PATH', 'chaine', 'DOL_DATA_ROOT' . (($conf->entity == 1 ) ? '/' : '/' . $conf->entity . '/') . 'ecm/dolisirh/timesheetdocument/', '', 0, 'current'),
$i++ => array('DOLISIRH_TIMESHEETDOCUMENT_DEFAULT_MODEL', 'chaine', 'timesheetdocument_odt', '', 0, 'current'),
$i++ => array('DOLISIRH_TIMESHEETDOCUMENT_DEFAULT_MODEL', 'chaine', 'timesheetdocument_odt', '', 0, 'current'),

// CONST CERTIFICATE
$i++ => array('DOLISIRH_CERTIFICATE_ADDON', 'chaine', 'mod_certificate_standard', '', 0, 'current'),
Expand Down
Binary file not shown.
3 changes: 2 additions & 1 deletion langs/fr_FR/dolisirh.lang
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ ExpectedWorkedHoursMonthTimeSheet = Heures de travail prévues du %s au %s
CheckDateEnd = Vérifier la date fin de navette
CheckDateEndDescription = Vérification si la date fin de navette est supérieure à la date du jour <br> (évite la création de temps consommés dans le futur)
TimeSheetManagement = Gestion des navettes

ShowOnlyTasksWithTimespentOnTimeSheet = Afficher seulement les tâches avec du temps consommé
ShowOnlyTasksWithTimespentOnTimeSheetDescription = Permet d'afficher les tâches avec du temps consommé dans la fiche de navette plutôt que toutes les tâches

#
# TimeSheetDocument - Document Navette
Expand Down

0 comments on commit 713048e

Please sign in to comment.