From 2db0f84f29847afecc6ea2448602aacd425268b5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 18 Jan 2019 20:06:33 +0100 Subject: [PATCH] NEW Pagination into list of time spent --- htdocs/projet/tasks/time.php | 135 ++++++++++++++++++++--------------- 1 file changed, 79 insertions(+), 56 deletions(-) diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 4319a11eb03..e2b00923eef 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -576,7 +576,7 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0) print ''."\n"; $title=$langs->trans("ListTaskTimeForTask"); - //print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $linktotasks, $num, $totalnboflines, 'title_generic.png', 0, '', '', 0, 1); + //print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $linktotasks, $num, $nbtotalofrecords, 'title_generic.png', 0, '', '', 0, 1); print load_fiche_titre($title, $linktocreatetime, 'title_generic.png'); /* @@ -703,6 +703,41 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0) $massactionbutton=$form->selectMassAction('', $arrayofmassactions); } + $param=''; + if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage); + if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); + if ($search_month > 0) $param.= '&search_month='.urlencode($search_month); + if ($search_year > 0) $param.= '&search_year='.urlencode($search_year); + if ($search_user > 0) $param.= '&search_user='.urlencode($search_user); + if ($search_task_ref != '') $param.= '&search_task_ref='.urlencode($search_task_ref); + if ($search_task_label != '') $param.= '&search_task_label='.urlencode($search_task_label); + if ($search_note != '') $param.= '&search_note='.urlencode($search_note); + if ($search_duration != '') $param.= '&search_field2='.urlencode($search_duration); + if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); + /* + // Add $param from extra fields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; + */ + if ($id) $param.='&id='.urlencode($id); + if ($projectid) $param.='&projectid='.urlencode($projectid); + if ($withproject) $param.='&withproject='.urlencode($withproject); + + print '
'; + if ($optioncss != '') print ''; + print ''; + print ''; + if ($action == 'editline') print ''; + elseif ($action == 'splitline') print ''; + elseif ($action == 'createtime' && empty($id) && $user->rights->projet->lire) print ''; + else print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + /* * List of time spent */ @@ -711,10 +746,11 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0) $sql = "SELECT t.rowid, t.fk_task, t.task_date, t.task_datehour, t.task_date_withhour, t.task_duration, t.fk_user, t.note, t.thm,"; $sql .= " pt.ref, pt.label,"; $sql .= " u.lastname, u.firstname, u.login, u.photo, u.statut as user_status,"; - $sql .= " il.fk_facture as invoice_id, il.total_ht"; + $sql .= " il.fk_facture as invoice_id, inv.fk_statut"; $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facturedet as il ON il.rowid = t.invoice_line_id"; - $sql .= ", ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as inv ON inv.rowid = il.fk_facture,"; + $sql .= " ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u"; $sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid"; if (empty($projectidforalltimes)) $sql .= " AND t.fk_task =".$object->id; else $sql.= " AND pt.fk_projet IN (".$projectidforalltimes.")"; @@ -738,23 +774,49 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0) { $sql.= " AND t.task_datehour BETWEEN '".$db->idate(dol_get_first_day($search_year,1,false))."' AND '".$db->idate(dol_get_last_day($search_year,12,false))."'"; } - + //$sql .= ' GROUP BY t.rowid, t.fk_task, t.task_date, t.task_datehour, t.task_date_withhour, t.task_duration, t.fk_user, t.note, t.thm, pt.ref, pt.label, u.lastname, u.firstname, u.login, u.photo, u.statut, il.fk_facture'; $sql .= $db->order($sortfield, $sortorder); - $resql = $db->query($sql); - if ($resql) + // Count total nb of records + $nbtotalofrecords = ''; + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { - $num = $db->num_rows($resql); - $totalnboflines=$num; + $resql = $db->query($sql); + $nbtotalofrecords = $db->num_rows($resql); + if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0 + { + $page = 0; + $offset = 0; + } + } + // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set. + if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) + { + $num = $nbtotalofrecords; + } + else + { + $sql.= $db->plimit($limit+1, $offset); + $resql=$db->query($sql); + if (! $resql) + { + dol_print_error($db); + exit; + } + + $num = $db->num_rows($resql); + } + + if ($num >= 0) + { if (! empty($projectidforalltimes)) { print ''."\n"; $title=$langs->trans("ListTaskTimeUserProject"); - //$linktotasks=''.$langs->trans("GoToListOfTasks").''; - //print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $linktotasks, $num, $totalnboflines, 'title_generic.png', 0, '', '', 0, 1); - print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_generic', 0, $linktocreatetime, '', $limit); + + print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_generic', 0, $linktocreatetime, '', $limit); } $i = 0; @@ -771,18 +833,12 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0) dol_print_error($db); } - /* * Form to add time spent */ if ($action == 'createtime' && empty($id) && $user->rights->projet->lire) { - print ''."\n"; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''."\n"; print ''; @@ -859,47 +915,11 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0) print ''; print ''; - print '
'; + print ''; print '
'; } - - $param=''; - if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage); - if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); - if ($search_month > 0) $param.= '&search_month='.urlencode($search_month); - if ($search_year > 0) $param.= '&search_year='.urlencode($search_year); - if ($search_user > 0) $param.= '&search_user='.urlencode($search_user); - if ($search_task_ref != '') $param.= '&search_task_ref='.urlencode($search_task_ref); - if ($search_task_label != '') $param.= '&search_task_label='.urlencode($search_task_label); - if ($search_note != '') $param.= '&search_note='.urlencode($search_note); - if ($search_duration != '') $param.= '&search_field2='.urlencode($search_duration); - if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); - /* - // Add $param from extra fields - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; - */ - if ($id) $param.='&id='.urlencode($id); - if ($projectid) $param.='&projectid='.urlencode($projectid); - if ($withproject) $param.='&withproject='.urlencode($withproject); - - - print '
'; - if ($optioncss != '') print ''; - print ''; - print ''; - if ($action == 'editline') print ''; - elseif ($action == 'splitline') print ''; - else print ''; - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - $moreforfilter = ''; $parameters=array(); @@ -916,6 +936,7 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0) $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields + $selectedfields.=(count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : ''); print '
'; print ''."\n"; @@ -957,7 +978,7 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0) print $hookmanager->resPrint; // Action column print ''; print ''."\n"; @@ -996,6 +1017,8 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0) $totalarray=array(); foreach ($tasks as $task_time) { + if ($i >= $limit) break; + print ''; $date1=$db->jdate($task_time->task_date);
'; - $searchpicto=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1); + $searchpicto=$form->showFilterButtons(); print $searchpicto; print '