Skip to content

Commit

Permalink
#159 #160 [Dashboard] add: Dashboard on global timeSpent
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Feb 8, 2023
1 parent dd915af commit c610239
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
4 changes: 2 additions & 2 deletions class/dashboarddolisirhstats.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function show_dashboard($load_timespent = 1)
print '<div class="opened-dash-board-wrap"><div class="box-flex-container">' . $openedDashBoard . '</div></div>';
}

print '<div class="box-flex-container graph-dashboard">';
print '<div class="graph-dashboard wpeo-gridlayout grid-2">';

if (is_array($dashboard_data['graphs']) && !empty($dashboard_data['graphs'])) {
foreach ($dashboard_data['graphs'] as $keyelement => $datagraph) {
Expand Down Expand Up @@ -192,7 +192,7 @@ public function show_dashboard($load_timespent = 1)
$graph->SetHeight($datagraph2['height'] ?? $HEIGHT);
$graph->setShowLegend(2);
$graph->draw($filename[$keyelement2], $fileurl[$keyelement2]);
print '<div class="box-flex-item">';
print '<div>';
print load_fiche_titre($datagraph2['title'], $datagraph2['morehtmlright'], $datagraph2['picto']);
print $graph->show();
print '</div>';
Expand Down
35 changes: 19 additions & 16 deletions class/dolisirhstats.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,10 @@ public function load_dashboard()
{
global $langs;

$timeSpendingInfos = $this->getTimeSpendingInfos();
$timeSpentReport = $this->getTimeSpentReport();
$timeSpentCurrentMonthByTaskAndProject = $this->getTimeSpentCurrentMonthByTaskAndProject();
$timeSpendingInfos = $this->getTimeSpendingInfos();
$timeSpentReport = $this->getTimeSpentReport();
$timeSpentCurrentMonthByTaskAndProject = $this->getTimeSpentCurrentMonthByTaskAndProject();
$globalTimeSpentCurrentMonthByTaskAndProject = $this->getTimeSpentCurrentMonthByTaskAndProject(1);

$array['widgets'] = [
0 => [
Expand All @@ -626,18 +627,18 @@ public function load_dashboard()
],
];

$array['graphs'] = [$timeSpentReport, $timeSpentCurrentMonthByTaskAndProject];
$array['graphs'] = [$timeSpentReport, $timeSpentCurrentMonthByTaskAndProject, $globalTimeSpentCurrentMonthByTaskAndProject];

return $array;
}

/**
* Get all timespent infos.
*
* @return array
* @return array Widget datas label/content
* @throws Exception
*/
public function getTimeSpendingInfos()
public function getTimeSpendingInfos(): array
{
require_once __DIR__ . '/../lib/dolisirh_function.lib.php';

Expand Down Expand Up @@ -701,10 +702,10 @@ public function getTimeSpendingInfos()
/**
* Get timespent report on current year.
*
* @return array
* @return array Graph datas (label/color/type/title/data etc..)
* @throws Exception
*/
public function getTimeSpentReport()
public function getTimeSpentReport(): array
{
require_once __DIR__ . '/../lib/dolisirh_function.lib.php';

Expand Down Expand Up @@ -783,10 +784,11 @@ public function getTimeSpentReport()
/**
* Get timespent on current month by task and project.
*
* @return array
* @param int $showNotConsumedWorkedHours Display not consumed worked hours
* @return array Graph datas (label/color/type/title/data etc..)
* @throws Exception
*/
public function getTimeSpentCurrentMonthByTaskAndProject()
public function getTimeSpentCurrentMonthByTaskAndProject(int $showNotConsumedWorkedHours = 0): array
{
require_once __DIR__ . '/../lib/dolisirh_function.lib.php';

Expand All @@ -795,7 +797,7 @@ public function getTimeSpentCurrentMonthByTaskAndProject()
$userID = GETPOSTISSET('search_userid') ? GETPOST('search_userid', 'int') : $user->id;

// Graph Title parameters
$array['title'] = $langs->transnoentities('TimeSpentCurrentMonthByTaskAndProject', dol_print_date(dol_mktime(0, 0, 0, date('m'), date('d'), date('Y')), '%B %Y'));
$array['title'] = $langs->transnoentities(($showNotConsumedWorkedHours > 0 ? 'GlobalTimeSpentCurrentMonthByTaskAndProject' : 'TimeSpentCurrentMonthByTaskAndProject'), dol_print_date(dol_mktime(0, 0, 0, date('m'), date('d'), date('Y')), '%B %Y'));
$array['picto'] = 'projecttask';

// Graph parameters
Expand Down Expand Up @@ -851,9 +853,6 @@ public function getTimeSpentCurrentMonthByTaskAndProject()
}
}

$plannedWorkingTime = loadPlannedTimeWithinRange($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
$plannedWorkingTimeData = (($plannedWorkingTime['minutes'] != 0) ? convertSecondToTime($plannedWorkingTime['minutes'] * 60, 'fullhour') : 0);

if (is_array($datas) && !empty($datas)) {
$array['data'] = [];
$array['labels'] = [];
Expand All @@ -867,8 +866,12 @@ public function getTimeSpentCurrentMonthByTaskAndProject()
}
}

$array['labels'][] = ['color' => '#008ECC'];
$array['data'][] = [$langs->transnoentities('NotConsumedWorkedHours'), $plannedWorkingTimeData - $totalTimeSpent, '', $plannedWorkingTimeData - $totalTimeSpent];
if ($showNotConsumedWorkedHours > 0) {
$plannedWorkingTime = loadPlannedTimeWithinRange($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
$plannedWorkingTimeData = (($plannedWorkingTime['minutes'] != 0) ? convertSecondToTime($plannedWorkingTime['minutes'] * 60, 'fullhour') : 0);
$array['labels'][] = ['color' => '#008ECC'];
$array['data'][] = [$langs->transnoentities('NotConsumedWorkedHours'), $plannedWorkingTimeData - $totalTimeSpent, '', $plannedWorkingTimeData - $totalTimeSpent];
}

return $array;
}
Expand Down
1 change: 1 addition & 0 deletions langs/fr_FR/dolisirh.lang
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ KeyEventTips = La touche 'Enter' permet de lancer la recherche. <br> Les touches
TimeSpentAutoCreate = Temps consommé ajouté depuis l'événement : %s
TimeSpentCurrentMonthByTaskAndProject = Répartition du temps consommé au mois de %s par tâche sur chaque projet
NotConsumedWorkedHours = Heures de travail non consommées
GlobalTimeSpentCurrentMonthByTaskAndProject = Répartition du temps consommé global au mois de %s par tâche sur chaque projet



Expand Down
2 changes: 1 addition & 1 deletion view/timesheet/timesheet_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@
}
// Confirmation to delete
if ($action == 'delete') {
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteTimeSheet'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteTimeSheet'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 'yes', 1);
}
// Confirmation to delete line
if ($action == 'ask_deleteline') {
Expand Down

0 comments on commit c610239

Please sign in to comment.