Skip to content

Commit

Permalink
#19 [TimeSpent] add: show only tasks with time spent option
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-theo committed Nov 2, 2022
1 parent a4a0786 commit 2b66092
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 147 deletions.
29 changes: 29 additions & 0 deletions js/dolisirh.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@
$( document ).on( 'click', '.auto-fill-timespent', window.eoxiaJS.task.addTimeSpent );
$( document ).on( 'click', '.auto-fill-timespent-project', window.eoxiaJS.task.divideTimeSpent );
$( document ).on( 'click', '.show-only-favorite-tasks', window.eoxiaJS.task.showOnlyFavoriteTasks );
$( document ).on( 'click', '.show-only-tasks-with-timespent', window.eoxiaJS.task.showOnlyTasksWithTimeSpent );
};

/**
Expand Down Expand Up @@ -652,6 +653,34 @@
});
};

/**
* Active/désactive la configuration pour n'afficher que les tâches avec du temps pointé
*
* @since 1.1.0
* @version 1.1.0
*
* @param {MouseEvent} event [description]
* @return {void}
*/
window.eoxiaJS.task.showOnlyTasksWithTimeSpent = function( event ) {
let token = $('.id-container').find('input[name="token"]').val();
let querySeparator = '?';

document.URL.match(/\?/) ? querySeparator = '&' : 1

$.ajax({
url: document.URL + querySeparator + "action=showOnlyTasksWithTimeSpent&token=" + token,
type: "POST",
processData: false,
contentType: false,
success: function ( resp ) {
window.location.reload()
},
error: function ( ) {
}
});
};

/**
* Initialise l'objet "menu" ainsi que la méthode "init" obligatoire pour la bibliothèque EoxiaJS.
*
Expand Down
185 changes: 39 additions & 146 deletions lib/dolisirh_function.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,20 @@ function getFavoriteTasksArray($task_id = 0, $usert = null, $userp = null, $proj
if ($conf->global->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as elel ON (t.rowid = elel.fk_target AND elel.targettype='project_task')";
}
if ($conf->global->DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_time as ptt ON (t.rowid = ptt.fk_task)";
}
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_extrafields as efpt ON (t.rowid = efpt.fk_object)";
$sql .= " WHERE p.entity IN (".getEntity('project').")";
$sql .= " AND t.fk_projet = p.rowid";
if ($conf->global->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS) {
$sql .= " AND elel.fk_target = t.rowid";
$sql .= " AND elel.fk_source = " . $user->id;
}
if ($conf->global->DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT) {
$sql .= " AND ptt.fk_task = t.rowid";
}

} elseif ($mode == 1) {
if ($filteronprojuser > 0) {
$sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
Expand Down Expand Up @@ -879,7 +886,6 @@ function projectLinesPerDayOnMonth(&$inc, $firstdaytoshow, $lastdaytoshow, $fuse

if ($lines[$i]->fk_task_parent == $parent) {
$obj = &$lines[$i]; // To display extrafields

// If we want all or we have a role on task, we show it
if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
//dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
Expand Down Expand Up @@ -938,13 +944,23 @@ function projectLinesPerDayOnMonth(&$inc, $firstdaytoshow, $lastdaytoshow, $fuse
}

if ($conf->global->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS) {
$taskfavorite = isTaskFavorite($lines[$i]->id, $fuser->id);
$taskFavorite = isTaskFavorite($lines[$i]->id, $fuser->id);
} else {
$taskfavorite = 1;
$taskFavorite = 1;
}

if ($conf->global->DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT) {
$filter = ' AND ptt.fk_task = ' . $lines[$i]->id;
$timeSpentArray = $lines[$i]->fetchAllTimeSpent($fuser, $filter);
$taskHasTimeSpent = (is_array($timeSpentArray) && !empty($timeSpentArray));
} else {
$taskHasTimeSpent = 1;
}

$displayTask = $taskFavorite && $taskHasTimeSpent;

if (!$noprint) {
print '<tr class="oddeven trforbreak nobold"' . (!$taskfavorite ? 'style="display:none;"' : '') . '>' . "\n";
print '<tr class="oddeven trforbreak nobold"' . (!$displayTask ? 'style="display:none;"' : '') . '>' . "\n";
print '<td colspan="' . (2 + $addcolspan + $dayInMonth) . '">';
print $projectstatic->getNomUrl(1, '', 0, '<strong>' . $langs->transnoentitiesnoconv("YourRole") . ':</strong> ' . $projectsrole[$lines[$i]->fk_project]);
if ($thirdpartystatic->id > 0) {
Expand All @@ -956,65 +972,6 @@ function projectLinesPerDayOnMonth(&$inc, $firstdaytoshow, $lastdaytoshow, $fuse
}
}

/*$colspan=5+(empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:2);
print '<table class="">';
print '<tr class="liste_titre">';
// PROJECT fields
if (! empty($arrayfields['p.fk_opp_status']['checked'])) print_liste_field_titre($arrayfields['p.fk_opp_status']['label'], $_SERVER["PHP_SELF"], 'p.fk_opp_status', "", $param, '', $sortfield, $sortorder, 'center ');
if (! empty($arrayfields['p.opp_amount']['checked'])) print_liste_field_titre($arrayfields['p.opp_amount']['label'], $_SERVER["PHP_SELF"], 'p.opp_amount', "", $param, '', $sortfield, $sortorder, 'right ');
if (! empty($arrayfields['p.opp_percent']['checked'])) print_liste_field_titre($arrayfields['p.opp_percent']['label'], $_SERVER["PHP_SELF"], 'p.opp_percent', "", $param, '', $sortfield, $sortorder, 'right ');
if (! empty($arrayfields['p.budget_amount']['checked'])) print_liste_field_titre($arrayfields['p.budget_amount']['label'], $_SERVER["PHP_SELF"], 'p.budget_amount', "", $param, '', $sortfield, $sortorder, 'right ');
if (! empty($arrayfields['p.usage_bill_time']['checked'])) print_liste_field_titre($arrayfields['p.usage_bill_time']['label'], $_SERVER["PHP_SELF"], 'p.usage_bill_time', "", $param, '', $sortfield, $sortorder, 'right ');
$extrafieldsobjectkey='projet';
$extrafieldsobjectprefix='efp.';
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
print '</tr>';
print '<tr>';
// PROJECT fields
if (! empty($arrayfields['p.fk_opp_status']['checked']))
{
print '<td class="nowrap">';
$code = dol_getIdFromCode($db, $lines[$i]->fk_opp_status, 'c_lead_status', 'rowid', 'code');
if ($code) print $langs->trans("OppStatus".$code);
print "</td>\n";
}
if (! empty($arrayfields['p.opp_amount']['checked']))
{
print '<td class="nowrap">';
print price($lines[$i]->opp_amount, 0, $langs, 1, 0, -1, $conf->currency);
print "</td>\n";
}
if (! empty($arrayfields['p.opp_percent']['checked']))
{
print '<td class="nowrap">';
print price($lines[$i]->opp_percent, 0, $langs, 1, 0).' %';
print "</td>\n";
}
if (! empty($arrayfields['p.budget_amount']['checked']))
{
print '<td class="nowrap">';
print price($lines[$i]->budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
print "</td>\n";
}
if (! empty($arrayfields['p.usage_bill_time']['checked']))
{
print '<td class="nowrap">';
print yn($lines[$i]->usage_bill_time);
print "</td>\n";
}
$extrafieldsobjectkey='projet';
$extrafieldsobjectprefix='efp.';
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
print '</tr>';
print '</table>';
*/
if (!$noprint) {
print '</td>';
print '</tr>';
Expand All @@ -1026,23 +983,26 @@ function projectLinesPerDayOnMonth(&$inc, $firstdaytoshow, $lastdaytoshow, $fuse
}

if ($conf->global->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS) {
$taskfavorite = isTaskFavorite($lines[$i]->id, $fuser->id);
$taskFavorite = isTaskFavorite($lines[$i]->id, $fuser->id);
} else {
$taskfavorite = 1;
$taskFavorite = 1;
}

if (!$noprint) {
print '<tr class="oddeven"' . (!$taskfavorite ? 'style="display:none;"' : '') . 'data-taskid="' . $lines[$i]->id . '" >' . "\n";
if ($conf->global->DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT) {
$filter = ' AND ptt.fk_task = ' . $lines[$i]->id;
$timeSpentArray = $lines[$i]->fetchAllTimeSpent($fuser, $filter);
$taskHasTimeSpent = (is_array($timeSpentArray) && !empty($timeSpentArray));
} else {
$taskHasTimeSpent = 1;
}

$displayTask = $taskFavorite && $taskHasTimeSpent;

if (!$noprint) {
// User
/*
print '<td class="nowrap">';
print $fuser->getNomUrl(1, 'withproject', 'time');
print '</td>';
*/
print '<tr class="oddeven"' . (!$displayTask ? 'style="display:none;"' : '') . 'data-taskid="' . $lines[$i]->id . '" >' . "\n";
}

if (!$noprint) {
// Project
if (!empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)) {
print '<td class="nowrap">';
Expand Down Expand Up @@ -1421,12 +1381,12 @@ function projectLinesPerWeekDoliSIRH(&$inc, $firstdaytoshow, $fuser, $parent, $l
}

if ($conf->global->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS) {
$taskfavorite = isTaskFavorite($lines[$i]->id, $fuser->id);
$displayTask = isTaskFavorite($lines[$i]->id, $fuser->id);
} else {
$taskfavorite = 1;
$displayTask = 1;
}

print '<tr class="oddeven trforbreak nobold"'.(!$taskfavorite ? 'style="display:none;"': '').'>'."\n";
print '<tr class="oddeven trforbreak nobold"'.(!$displayTask ? 'style="display:none;"': '').'>'."\n";
print '<td colspan="'.(11 + $addcolspan).'">';
print $projectstatic->getNomUrl(1, '', 0, '<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
if ($thirdpartystatic->id > 0) {
Expand All @@ -1437,66 +1397,6 @@ function projectLinesPerWeekDoliSIRH(&$inc, $firstdaytoshow, $fuser, $parent, $l
print '<span class="secondary" title="'.$projectstatic->title.'">'.dol_trunc($projectstatic->title, '64').'</span>';
}

/*$colspan=5+(empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:2);
print '<table class="">';
print '<tr class="liste_titre">';
// PROJECT fields
if (! empty($arrayfields['p.fk_opp_status']['checked'])) print_liste_field_titre($arrayfields['p.fk_opp_status']['label'], $_SERVER["PHP_SELF"], 'p.fk_opp_status', "", $param, '', $sortfield, $sortorder, 'center ');
if (! empty($arrayfields['p.opp_amount']['checked'])) print_liste_field_titre($arrayfields['p.opp_amount']['label'], $_SERVER["PHP_SELF"], 'p.opp_amount', "", $param, '', $sortfield, $sortorder, 'right ');
if (! empty($arrayfields['p.opp_percent']['checked'])) print_liste_field_titre($arrayfields['p.opp_percent']['label'], $_SERVER["PHP_SELF"], 'p.opp_percent', "", $param, '', $sortfield, $sortorder, 'right ');
if (! empty($arrayfields['p.budget_amount']['checked'])) print_liste_field_titre($arrayfields['p.budget_amount']['label'], $_SERVER["PHP_SELF"], 'p.budget_amount', "", $param, '', $sortfield, $sortorder, 'right ');
if (! empty($arrayfields['p.usage_bill_time']['checked'])) print_liste_field_titre($arrayfields['p.usage_bill_time']['label'], $_SERVER["PHP_SELF"], 'p.usage_bill_time', "", $param, '', $sortfield, $sortorder, 'right ');
$extrafieldsobjectkey='projet';
$extrafieldsobjectprefix='efp.';
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
print '</tr>';
print '<tr>';
// PROJECT fields
if (! empty($arrayfields['p.fk_opp_status']['checked']))
{
print '<td class="nowrap">';
$code = dol_getIdFromCode($db, $lines[$i]->fk_opp_status, 'c_lead_status', 'rowid', 'code');
if ($code) print $langs->trans("OppStatus".$code);
print "</td>\n";
}
if (! empty($arrayfields['p.opp_amount']['checked']))
{
print '<td class="nowrap">';
print price($lines[$i]->opp_amount, 0, $langs, 1, 0, -1, $conf->currency);
print "</td>\n";
}
if (! empty($arrayfields['p.opp_percent']['checked']))
{
print '<td class="nowrap">';
print price($lines[$i]->opp_percent, 0, $langs, 1, 0).' %';
print "</td>\n";
}
if (! empty($arrayfields['p.budget_amount']['checked']))
{
print '<td class="nowrap">';
print price($lines[$i]->budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
print "</td>\n";
}
if (! empty($arrayfields['p.usage_bill_time']['checked']))
{
print '<td class="nowrap">';
print yn($lines[$i]->usage_bill_time);
print "</td>\n";
}
$extrafieldsobjectkey='projet';
$extrafieldsobjectprefix='efp.';
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
print '</tr>';
print '</table>';
*/

print '</td>';
print '</tr>';
}
Expand All @@ -1506,19 +1406,12 @@ function projectLinesPerWeekDoliSIRH(&$inc, $firstdaytoshow, $fuser, $parent, $l
}

if ($conf->global->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS) {
$taskfavorite = isTaskFavorite($lines[$i]->id, $fuser->id);
$displayTask = isTaskFavorite($lines[$i]->id, $fuser->id);
} else {
$taskfavorite = 1;
$displayTask = 1;
}

print '<tr class="oddeven"'.(!$taskfavorite ? 'style="display:none;"': '').'data-taskid="'.$lines[$i]->id.'">'."\n";

// User
/*
print '<td class="nowrap">';
print $fuser->getNomUrl(1, 'withproject', 'time');
print '</td>';
*/
print '<tr class="oddeven"'.(!$displayTask ? 'style="display:none;"': '').'data-taskid="'.$lines[$i]->id.'">'."\n";

// Project
if (!empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)) {
Expand Down
19 changes: 18 additions & 1 deletion view/timespent_month.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,14 @@
}
}

if ($action == 'showOnlyTasksWithTimeSpent') {
if ($conf->global->DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT == 1) {
dolibarr_set_const($db, 'DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT', 0, 'integer', 0, '', $conf->entity);
} else {
dolibarr_set_const($db, 'DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT', 1, 'integer', 0, '', $conf->entity);
}
}


/*
* View
Expand Down Expand Up @@ -452,7 +460,9 @@
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';

$tasksarray = $taskstatic->getTasksArray(0, 0, ($project->id ? $project->id : 0), $socid, 0, $search_project_ref, $onlyopenedproject, $morewherefilter, ($search_usertoprocessid ? $search_usertoprocessid : 0), 0, $extrafields);
//$tasksarray = getFavoriteTasksArray($taskstatic->id, 0, 0, ($project->id ? $project->id : 0), $socid, 0, $search_project_ref, $onlyopenedproject, $morewherefilter, ($search_usertoprocessid ? $search_usertoprocessid : 0), 0, $extrafields); // We want to see all tasks of open project i am allowed to see and that match filter, not only my tasks. Later only mine will be editable later.
//if ($conf->global->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS) {
// $tasksarray = getFavoriteTasksArray($taskstatic->id, 0, 0, ($project->id ? $project->id : 0), $socid, 0, $search_project_ref, $onlyopenedproject, $morewherefilter, ($search_usertoprocessid ? $search_usertoprocessid : 0), 0, $extrafields); // We want to see all tasks of open project i am allowed to see and that match filter, not only my tasks. Later only mine will be editable later.
//}
if (!empty($conf->global->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS)) { // Get all task without any filter, so we can show total of time spent for not visible tasks
$tasksarraywithoutfilter = $taskstatic->getTasksArray(0, 0, ($project->id ? $project->id : 0), $socid, 0, $search_project_ref, $onlyopenedproject, $morewherefilter, ($search_usertoprocessid ? $search_usertoprocessid : 0)); // We want to see all tasks of open project i am allowed to see and that match filter, not only my tasks. Later only mine will be editable later.
}
Expand Down Expand Up @@ -550,6 +560,13 @@
print '<div class="opacitymedium"><i class="fas fa-exclamation-triangle"></i>'.' '.$langs->trans('WarningShowOnlyFavoriteTasks').'</div>';
}

print '<div class="clearboth" style="padding-bottom: 20px;"></div>';
print $langs->trans('ShowOnlyTasksWithTimeSpent');
print '<input type="checkbox" class="show-only-tasks-with-timespent"'. ($conf->global->DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT ? ' checked' : '').' >';
if ($conf->global->DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT) {
print '<br>';
print '<div class="opacitymedium"><i class="fas fa-exclamation-triangle"></i>'.' '.$langs->trans('ShowOnlyTasksWithTimeSpent').'</div>';
}

$numendworkingday = 0;
$numstartworkingday = 0;
Expand Down

0 comments on commit 2b66092

Please sign in to comment.