Skip to content

Commit

Permalink
#187 [Dashboard] add: select timespent dataset month for dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Feb 13, 2023
1 parent 3695d64 commit 4fccb92
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
20 changes: 11 additions & 9 deletions class/dolisirhstats.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,13 @@ public function getTimeSpendingInfos(): array
global $db, $langs, $user;

$userID = GETPOSTISSET('search_userid') ? GETPOST('search_userid', 'int') : $user->id;
$month = GETPOSTISSET('search_month') ? GETPOST('search_month', 'int') : date('m');

$firstdaytoshow = dol_get_first_day(date('Y'), date('m'));
$firstdaytoshow = dol_get_first_day(date('Y'), $month);
$lastdayofmonth = strtotime(date('Y-m-t', $firstdaytoshow));

$currentMonth = date('m', dol_now());
if ($currentMonth == date('m')) {
if ($currentMonth == $month) {
$currentDate = dol_getdate(dol_now());
$lastdaytoshow = dol_mktime(0, 0, 0, $currentDate['mon'], $currentDate['mday'], $currentDate['year']);
} else {
Expand Down Expand Up @@ -678,7 +679,7 @@ public function getTimeSpendingInfos(): array

// Planned working time
$planned_working_time = loadPlannedTimeWithinRange($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
$array['planned']['label'] = $langs->trans('Total') . ' - ' . $langs->trans('ExpectedWorkedHoursMonth', dol_print_date(dol_mktime(0, 0, 0, date('m'), date('d'), date('Y')), '%B %Y'));
$array['planned']['label'] = $langs->trans('Total') . ' - ' . $langs->trans('ExpectedWorkedHoursMonth', dol_print_date(dol_mktime(0, 0, 0, $month, date('d'), date('Y')), '%B %Y'));
$array['planned']['content'] = (($planned_working_time['minutes'] != 0) ? convertSecondToTime($planned_working_time['minutes'] * 60, 'allhourmin') : '00:00');

// Hours passed
Expand Down Expand Up @@ -795,11 +796,12 @@ public function getTimeSpentCurrentMonthByTaskAndProject(int $showNotConsumedWor
global $db, $langs, $user;

$userID = GETPOSTISSET('search_userid') ? GETPOST('search_userid', 'int') : $user->id;
$month = GETPOSTISSET('search_month') ? GETPOST('search_month', 'int') : date('m');

$datasetOrder = $user->conf->DOLISIRH_TIMESPENT_DATASET_ORDER;

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

// Graph parameters
Expand All @@ -811,11 +813,11 @@ public function getTimeSpentCurrentMonthByTaskAndProject(int $showNotConsumedWor
$workinghours = new Workinghours($db);
$workingHours = $workinghours->fetchCurrentWorkingHours($userID, 'user');

$firstdaytoshow = dol_get_first_day(date('Y'), date('m'));
$firstdaytoshow = dol_get_first_day(date('Y'), $month);
$lastdayofmonth = strtotime(date('Y-m-t', $firstdaytoshow));

$currentMonth = date('m', dol_now());
if ($currentMonth == date('m')) {
if ($currentMonth == $month) {
$currentDate = dol_getdate(dol_now());
$lastdaytoshow = dol_mktime(0, 0, 0, $currentDate['mon'], $currentDate['mday'], $currentDate['year']);
} else {
Expand All @@ -828,11 +830,11 @@ public function getTimeSpentCurrentMonthByTaskAndProject(int $showNotConsumedWor
for ($idw = 0; $idw < $daysInMonth; $idw++) {
$dayInLoop = dol_time_plus_duree($firstdaytoshow, $idw, 'd');
if (isDayAvailable($dayInLoop, $userID)) {
$isavailable[$dayInLoop] = ['morning'=>1, 'afternoon'=>1];
$isavailable[$dayInLoop] = ['morning' => 1, 'afternoon' => 1];
} else if (date('N', $dayInLoop) >= 6) {
$isavailable[$dayInLoop] = ['morning'=>false, 'afternoon'=>false, 'morning_reason'=>'week_end', 'afternoon_reason'=>'week_end'];
$isavailable[$dayInLoop] = ['morning' => false, 'afternoon' => false, 'morning_reason' => 'week_end', 'afternoon_reason' => 'week_end'];
} else {
$isavailable[$dayInLoop] = ['morning'=>false, 'afternoon'=>false, 'morning_reason'=>'public_holiday', 'afternoon_reason'=>'public_holiday'];
$isavailable[$dayInLoop] = ['morning' => false, 'afternoon' => false, 'morning_reason' => 'public_holiday', 'afternoon_reason' => 'public_holiday'];
}

}
Expand Down
6 changes: 5 additions & 1 deletion dolisirhindex.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@

llxHeader('', $title . ' ' . $modDoliSIRH->version, $help_url, '', 0, 0, $morejs, $morecss);

$morehtmlright = img_picto($langs->trans('Filter') . ' ' . $langs->trans('User'), 'user', 'class="paddingright pictofixedwidth"') . $form->select_dolusers($userID, 'search_userid', '', null, 0, '', null, 0, 0, 0, ' AND u.employee = 1', 0, '', 'maxwidth300 select-user-dashboard', 1);
$currentMonth = date('m', dol_now());

$months = [1 => $langs->trans('January'), 2 => $langs->trans('February'), 3 => $langs->trans('March'), 4 => $langs->trans('April'), 5 => $langs->trans('May'), 6 => $langs->trans('June'), 7 => $langs->trans('July'), 8 => $langs->trans('August'), 9 => $langs->trans('September'), 10 => $langs->trans('October'), 11 => $langs->trans('November'), 12 => $langs->trans('December')];
$morehtmlright = img_picto($langs->trans('Filter') . ' ' . $langs->trans('Month'), 'title_agenda', 'class="paddingright pictofixedwidth"') . $form->selectarray('search_month', $months, $currentMonth, 0,0, 0, '', 1, 0, 0, '', 'maxwidth100 select-timespent-dataset-month');
$morehtmlright .= ' ' . img_picto($langs->trans('Filter') . ' ' . $langs->trans('User'), 'user', 'class="paddingright pictofixedwidth"') . $form->select_dolusers($userID, 'search_userid', '', null, 0, '', null, 0, 0, 0, ' AND u.employee = 1', 0, '', 'maxwidth300 select-user-dashboard', 1);

print load_fiche_titre($title . ' ' . $modDoliSIRH->version, $morehtmlright, 'dolisirh_red.png@dolisirh');

Expand Down
32 changes: 31 additions & 1 deletion js/dolisirh.js
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,7 @@ window.eoxiaJS.dashboard.event = function() {
$( document ).on( 'change', '.add-dashboard-widget', window.eoxiaJS.dashboard.addDashBoardInfo );
$( document ).on( 'click', '.close-dashboard-widget', window.eoxiaJS.dashboard.closeDashBoardInfo );
$( document ).on( 'change', '.select-user-dashboard', window.eoxiaJS.dashboard.selectUserDashboard );
$( document ).on( 'change', '.select-timespent-dataset-month', window.eoxiaJS.dashboard.selectTimeSpentDatasetMonth );
};

/**
Expand Down Expand Up @@ -1345,7 +1346,7 @@ window.eoxiaJS.dashboard.selectUserDashboard = function() {
window.eoxiaJS.loader.display($('.fichecenter'));

$.ajax({
url: document.URL + querySeparator + 'action=selectuserdashboar&token=' + token + '&search_userid=' + userID,
url: document.URL + querySeparator + 'action=selectuserdashboard&token=' + token + '&search_userid=' + userID,
type: "POST",
processData: false,
contentType: false,
Expand All @@ -1355,3 +1356,32 @@ window.eoxiaJS.dashboard.selectUserDashboard = function() {
error: function() {}
});
};

/**
* Select timespent dataset month.
*
* @since 1.2.1
* @version 1.2.1
*
* @return {void}
*/
window.eoxiaJS.dashboard.selectTimeSpentDatasetMonth = function() {
let month = this.value;

let querySeparator = '?';
let token = $('.dashboard').find('input[name="token"]').val();
document.URL.match(/\?/) ? querySeparator = '&' : 1

window.eoxiaJS.loader.display($('.fichecenter'));

$.ajax({
url: document.URL + querySeparator + 'action=selecttimespentdatasetmonth&token=' + token + '&search_month=' + month,
type: "POST",
processData: false,
contentType: false,
success: function(resp) {
$('.fichecenter').replaceWith($(resp).find('.fichecenter'));
},
error: function() {}
});
};

0 comments on commit 4fccb92

Please sign in to comment.