dolibarr  13.0.2
time.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2006-2020 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
7  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
8  * Copyright (C) 2019 Christophe Battarel <christophe@altairis.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
30 require '../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
38 
39 // Load translation files required by the page
40 $langs->loadLangs(array('projects', 'bills', 'orders'));
41 
42 $action = GETPOST('action', 'alpha');
43 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
44 $confirm = GETPOST('confirm', 'alpha');
45 $cancel = GETPOST('cancel', 'alpha');
46 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
47 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'timespentlist'; // To manage different context of search
48 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
49 $optioncss = GETPOST('optioncss', 'alpha');
50 
51 $id = GETPOST('id', 'int');
52 $projectid = GETPOST('projectid', 'int');
53 $ref = GETPOST('ref', 'alpha');
54 $withproject = GETPOST('withproject', 'int');
55 $project_ref = GETPOST('project_ref', 'alpha');
56 $tab = GETPOST('tab', 'aZ09');
57 
58 $search_day = GETPOST('search_day', 'int');
59 $search_month = GETPOST('search_month', 'int');
60 $search_year = GETPOST('search_year', 'int');
61 $search_datehour = '';
62 $search_datewithhour = '';
63 $search_note = GETPOST('search_note', 'alpha');
64 $search_duration = GETPOST('search_duration', 'int');
65 $search_value = GETPOST('search_value', 'int');
66 $search_task_ref = GETPOST('search_task_ref', 'alpha');
67 $search_task_label = GETPOST('search_task_label', 'alpha');
68 $search_user = GETPOST('search_user', 'int');
69 $search_valuebilled = GETPOST('search_valuebilled', 'int');
70 
71 // Security check
72 $socid = 0;
73 //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement.
74 if (!$user->rights->projet->lire) accessforbidden();
75 
76 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
77 $sortfield = GETPOST("sortfield", 'alpha');
78 $sortorder = GETPOST("sortorder", 'alpha');
79 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
80 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
81 $offset = $limit * $page;
82 $pageprev = $page - 1;
83 $pagenext = $page + 1;
84 if (!$sortfield) $sortfield = 't.task_date,t.task_datehour,t.rowid';
85 if (!$sortorder) $sortorder = 'DESC,DESC,DESC';
86 
87 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
88 //$object = new TaskTime($db);
89 $hookmanager->initHooks(array('projecttasktime', 'globalcard'));
90 
91 $object = new Task($db);
92 $projectstatic = new Project($db);
93 $extrafields = new ExtraFields($db);
94 $extrafields->fetch_name_optionals_label($projectstatic->table_element);
95 $extrafields->fetch_name_optionals_label($object->table_element);
96 
97 
98 /*
99  * Actions
100  */
101 
102 if (GETPOST('cancel', 'alpha')) { $action = ''; }
103 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_generateinvoice') { $massaction = ''; }
104 
105 $parameters = array('socid'=>$socid, 'projectid'=>$projectid);
106 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
107 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
108 
109 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
110 
111 // Purge search criteria
112 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
113 {
114  $search_day = '';
115  $search_month = '';
116  $search_year = '';
117  $search_date = '';
118  $search_datehour = '';
119  $search_datewithhour = '';
120  $search_note = '';
121  $search_duration = '';
122  $search_value = '';
123  $search_date_creation = '';
124  $search_date_update = '';
125  $search_task_ref = '';
126  $search_task_label = '';
127  $search_user = 0;
128  $search_valuebilled = '';
129  $toselect = '';
130  $search_array_options = array();
131  $action = '';
132 }
133 
134 if ($action == 'addtimespent' && $user->rights->projet->lire)
135 {
136  $error = 0;
137 
138  $timespent_durationhour = GETPOST('timespent_durationhour', 'int');
139  $timespent_durationmin = GETPOST('timespent_durationmin', 'int');
140  if (empty($timespent_durationhour) && empty($timespent_durationmin))
141  {
142  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Duration")), null, 'errors');
143  $error++;
144  }
145  if (empty($_POST["userid"]))
146  {
147  $langs->load("errors");
148  setEventMessages($langs->trans('ErrorUserNotAssignedToTask'), null, 'errors');
149  $error++;
150  }
151 
152  if (!$error)
153  {
154  if ($id || $ref)
155  {
156  $object->fetch($id, $ref);
157  } else {
158  if (!GETPOST('taskid', 'int') || GETPOST('taskid', 'int') < 0)
159  {
160  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Task")), null, 'errors');
161  $action = 'createtime';
162  $error++;
163  } else {
164  $object->fetch(GETPOST('taskid', 'int'));
165  }
166  }
167 
168  if (!$error)
169  {
170  $object->fetch_projet();
171 
172  if (empty($object->project->statut))
173  {
174  setEventMessages($langs->trans("ProjectMustBeValidatedFirst"), null, 'errors');
175  $action = 'createtime';
176  $error++;
177  } else {
178  $object->timespent_note = $_POST["timespent_note"];
179  if (GETPOST('progress', 'int') > 0) $object->progress = GETPOST('progress', 'int'); // If progress is -1 (not defined), we do not change value
180  $object->timespent_duration = $_POST["timespent_durationhour"] * 60 * 60; // We store duration in seconds
181  $object->timespent_duration += ($_POST["timespent_durationmin"] ? $_POST["timespent_durationmin"] : 0) * 60; // We store duration in seconds
182  if (GETPOST("timehour") != '' && GETPOST("timehour") >= 0) // If hour was entered
183  {
184  $object->timespent_date = dol_mktime(GETPOST("timehour"), GETPOST("timemin"), 0, GETPOST("timemonth"), GETPOST("timeday"), GETPOST("timeyear"));
185  $object->timespent_withhour = 1;
186  } else {
187  $object->timespent_date = dol_mktime(12, 0, 0, GETPOST("timemonth"), GETPOST("timeday"), GETPOST("timeyear"));
188  }
189  $object->timespent_fk_user = $_POST["userid"];
190  $result = $object->addTimeSpent($user);
191  if ($result >= 0)
192  {
193  setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
194  } else {
195  setEventMessages($langs->trans($object->error), null, 'errors');
196  $error++;
197  }
198  }
199  }
200  } else {
201  if (empty($id)) $action = 'createtime';
202  else $action = 'createtime';
203  }
204 }
205 
206 if (($action == 'updateline' || $action == 'updatesplitline') && !$cancel && $user->rights->projet->lire)
207 {
208  $error = 0;
209 
210  if (!GETPOST("new_durationhour") && !GETPOST("new_durationmin"))
211  {
212  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Duration")), null, 'errors');
213  $error++;
214  }
215 
216  if (!$error)
217  {
218  if (GETPOST('taskid', 'int') != $id) // GETPOST('taskid') is id of new task
219  {
220  $id = GETPOST('taskid', 'int');
221 
222  $object->fetchTimeSpent(GETPOST('lineid', 'int'));
223  // TODO Check that ($task_time->fk_user == $user->id || in_array($task_time->fk_user, $childids))
224  $result = $object->delTimeSpent($user);
225 
226  $object->fetch($id, $ref);
227  $object->timespent_note = $_POST["timespent_note_line"];
228  $object->timespent_old_duration = $_POST["old_duration"];
229  $object->timespent_duration = $_POST["new_durationhour"] * 60 * 60; // We store duration in seconds
230  $object->timespent_duration += ($_POST["new_durationmin"] ? $_POST["new_durationmin"] : 0) * 60; // We store duration in seconds
231  if (GETPOST("timelinehour") != '' && GETPOST("timelinehour") >= 0) // If hour was entered
232  {
233  $object->timespent_date = dol_mktime(GETPOST("timelinehour"), GETPOST("timelinemin"), 0, GETPOST("timelinemonth"), GETPOST("timelineday"), GETPOST("timelineyear"));
234  $object->timespent_withhour = 1;
235  } else {
236  $object->timespent_date = dol_mktime(12, 0, 0, GETPOST("timelinemonth"), GETPOST("timelineday"), GETPOST("timelineyear"));
237  }
238  $object->timespent_fk_user = $_POST["userid_line"];
239  $result = $object->addTimeSpent($user);
240  if ($result >= 0)
241  {
242  setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
243  } else {
244  setEventMessages($langs->trans($object->error), null, 'errors');
245  $error++;
246  }
247  } else {
248  $object->fetch($id, $ref);
249  // TODO Check that ($task_time->fk_user == $user->id || in_array($task_time->fk_user, $childids))
250 
251  $object->timespent_id = $_POST["lineid"];
252  $object->timespent_note = $_POST["timespent_note_line"];
253  $object->timespent_old_duration = $_POST["old_duration"];
254  $object->timespent_duration = $_POST["new_durationhour"] * 60 * 60; // We store duration in seconds
255  $object->timespent_duration += ($_POST["new_durationmin"] ? $_POST["new_durationmin"] : 0) * 60; // We store duration in seconds
256  if (GETPOST("timelinehour") != '' && GETPOST("timelinehour") >= 0) // If hour was entered
257  {
258  $object->timespent_date = dol_mktime(GETPOST("timelinehour"), GETPOST("timelinemin"), 0, GETPOST("timelinemonth"), GETPOST("timelineday"), GETPOST("timelineyear"));
259  $object->timespent_withhour = 1;
260  } else {
261  $object->timespent_date = dol_mktime(12, 0, 0, GETPOST("timelinemonth"), GETPOST("timelineday"), GETPOST("timelineyear"));
262  }
263  $object->timespent_fk_user = $_POST["userid_line"];
264 
265  $result = $object->updateTimeSpent($user);
266  if ($result >= 0)
267  {
268  setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
269  } else {
270  setEventMessages($langs->trans($object->error), null, 'errors');
271  $error++;
272  }
273  }
274  } else {
275  $action = '';
276  }
277 }
278 
279 if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->projet->lire)
280 {
281  $object->fetchTimeSpent(GETPOST('lineid', 'int'));
282  // TODO Check that ($task_time->fk_user == $user->id || in_array($task_time->fk_user, $childids))
283  $result = $object->delTimeSpent($user);
284 
285  if ($result < 0)
286  {
287  $langs->load("errors");
288  setEventMessages($langs->trans($object->error), null, 'errors');
289  $error++;
290  $action = '';
291  } else {
292  setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
293  }
294 }
295 
296 // Retrieve First Task ID of Project if withprojet is on to allow project prev next to work
297 if (!empty($project_ref) && !empty($withproject))
298 {
299  if ($projectstatic->fetch(0, $project_ref) > 0)
300  {
301  $tasksarray = $object->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
302  if (count($tasksarray) > 0)
303  {
304  $id = $tasksarray[0]->id;
305  } else {
306  header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.($withproject ? '&withproject=1' : '').(empty($mode) ? '' : '&mode='.$mode));
307  exit;
308  }
309  }
310 }
311 
312 // To show all time lines for project
313 $projectidforalltimes = 0;
314 if (GETPOST('projectid', 'int') > 0)
315 {
316  $projectidforalltimes = GETPOST('projectid', 'int');
317 
318  $result = $projectstatic->fetch($projectidforalltimes);
319  if (!empty($projectstatic->socid)) $projectstatic->fetch_thirdparty();
320  $res = $projectstatic->fetch_optionals();
321 } elseif (GETPOST('project_ref', 'alpha'))
322 {
323  $projectstatic->fetch(0, GETPOST('project_ref', 'alpha'));
324  $projectidforalltimes = $projectstatic->id;
325  $withproject = 1;
326 } elseif ($id > 0)
327 {
328  $object->fetch($id);
329  $result = $projectstatic->fetch($object->fk_project);
330 }
331 
332 if ($action == 'confirm_generateinvoice')
333 {
334  if (!empty($projectstatic->socid)) $projectstatic->fetch_thirdparty();
335 
336  if (!($projectstatic->thirdparty->id > 0)) {
337  setEventMessages($langs->trans("ThirdPartyRequiredToGenerateInvoice"), null, 'errors');
338  } else {
339  include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
340  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
341  include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
342 
343  $tmpinvoice = new Facture($db);
344  $tmptimespent = new Task($db);
345  $tmpproduct = new Product($db);
346  $fuser = new User($db);
347 
348  $db->begin();
349  $idprod = GETPOST('productid', 'int');
350  $generateinvoicemode = GETPOST('generateinvoicemode', 'string');
351  $invoiceToUse = GETPOST('invoiceid', 'int');
352 
353  $prodDurationHours = 1.0;
354  if ($idprod > 0)
355  {
356  $tmpproduct->fetch($idprod);
357  if ($tmpproduct->duration_unit == 'i')
358  $prodDurationHours = 1. / 60;
359  if ($tmpproduct->duration_unit == 'h')
360  $prodDurationHours = 1.;
361  if ($tmpproduct->duration_unit == 'd')
362  $prodDurationHours = 24.;
363  if ($tmpproduct->duration_unit == 'w')
364  $prodDurationHours = 24. * 7;
365  if ($tmpproduct->duration_unit == 'm')
366  $prodDurationHours = 24. * 30;
367  if ($tmpproduct->duration_unit == 'y')
368  $prodDurationHours = 24. * 365;
369  $prodDurationHours *= $tmpproduct->duration_value;
370 
371  $dataforprice = $tmpproduct->getSellPrice($mysoc, $projectstatic->thirdparty, 0);
372 
373  $pu_ht = empty($dataforprice['pu_ht']) ? 0 : $dataforprice['pu_ht'];
374  $txtva = $dataforprice['tva_tx'];
375  $localtax1 = $dataforprice['localtax1'];
376  $localtax2 = $dataforprice['localtax2'];
377  } else {
378  $pu_ht = 0;
379  $txtva = get_default_tva($mysoc, $projectstatic->thirdparty);
380  $localtax1 = get_default_localtax($mysoc, $projectstatic->thirdparty, 1);
381  $localtax2 = get_default_localtax($mysoc, $projectstatic->thirdparty, 2);
382  }
383 
384  $tmpinvoice->socid = $projectstatic->thirdparty->id;
385  $tmpinvoice->date = dol_mktime(GETPOST('rehour', 'int'), GETPOST('remin', 'int'), GETPOST('resec', 'int'), GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
386  $tmpinvoice->fk_project = $projectstatic->id;
387 
388  if ($invoiceToUse) {
389  $tmpinvoice->fetch($invoiceToUse);
390  } else {
391  $result = $tmpinvoice->create($user);
392  if ($result <= 0)
393  {
394  $error++;
395  setEventMessages($tmpinvoice->error, $tmpinvoice->errors, 'errors');
396  }
397  }
398 
399  if (!$error)
400  {
401  if ($generateinvoicemode == 'onelineperuser') {
402  $arrayoftasks = array();
403  foreach ($toselect as $key => $value)
404  {
405  // Get userid, timepent
406  $object->fetchTimeSpent($value);
407  $arrayoftasks[$object->timespent_fk_user]['timespent'] += $object->timespent_duration;
408  $arrayoftasks[$object->timespent_fk_user]['totalvaluetodivideby3600'] += ($object->timespent_duration * $object->timespent_thm);
409  }
410 
411  foreach ($arrayoftasks as $userid => $value)
412  {
413  $fuser->fetch($userid);
414  //$pu_ht = $value['timespent'] * $fuser->thm;
415  $username = $fuser->getFullName($langs);
416 
417  // Define qty per hour
418  $qtyhour = $value['timespent'] / 3600;
419  $qtyhourtext = convertSecondToTime($value['timespent'], 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
420 
421  // If no unit price known
422  if (empty($pu_ht))
423  {
424  $pu_ht = price2num($value['totalvaluetodivideby3600'] / 3600, 'MU');
425  }
426 
427  // Add lines
428  $lineid = $tmpinvoice->addline($langs->trans("TimeSpentForInvoice", $username).' : '.$qtyhourtext, $pu_ht, round($qtyhour / $prodDurationHours, 2), $txtva, $localtax1, $localtax2, ($idprod > 0 ? $idprod : 0));
429 
430  // Update lineid into line of timespent
431  $sql = 'UPDATE '.MAIN_DB_PREFIX.'projet_task_time SET invoice_line_id = '.$lineid.', invoice_id = '.$tmpinvoice->id;
432  $sql .= ' WHERE rowid in ('.join(',', $toselect).') AND fk_user = '.$userid;
433  $result = $db->query($sql);
434  if (!$result)
435  {
436  $error++;
437  setEventMessages($db->lasterror(), null, 'errors');
438  break;
439  }
440  }
441  } elseif ($generateinvoicemode == 'onelineperperiod') {
442  $arrayoftasks = array();
443  foreach ($toselect as $key => $value)
444  {
445  // Get userid, timepent
446  $object->fetchTimeSpent($value);
447  $arrayoftasks[$object->timespent_id]['timespent'] = $object->timespent_duration;
448  $arrayoftasks[$object->timespent_id]['totalvaluetodivideby3600'] = $object->timespent_duration * $object->timespent_thm;
449  $arrayoftasks[$object->timespent_id]['note'] = $object->timespent_note;
450  $arrayoftasks[$object->timespent_id]['user'] = $object->timespent_fk_user;
451  }
452 
453  foreach ($arrayoftasks as $timespent_id => $value)
454  {
455  $userid = $value['user'];
456  $fuser->fetch($userid);
457  //$pu_ht = $value['timespent'] * $fuser->thm;
458  $username = $fuser->getFullName($langs);
459 
460  // Define qty per hour
461  $qtyhour = $value['timespent'] / 3600;
462  $qtyhourtext = convertSecondToTime($value['timespent'], 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
463 
464  // If no unit price known
465  if (empty($pu_ht))
466  {
467  $pu_ht = price2num($value['totalvaluetodivideby3600'] / 3600, 'MU');
468  }
469 
470  // Add lines
471  $lineid = $tmpinvoice->addline($value['note'], $pu_ht, round($qtyhour / $prodDurationHours, 2), $txtva, $localtax1, $localtax2, ($idprod > 0 ? $idprod : 0));
472 
473  // Update lineid into line of timespent
474  $sql = 'UPDATE '.MAIN_DB_PREFIX.'projet_task_time SET invoice_line_id = '.$lineid.', invoice_id = '.$tmpinvoice->id;
475  $sql .= ' WHERE rowid in ('.join(',', $toselect).') AND fk_user = '.$userid;
476  $result = $db->query($sql);
477  if (!$result)
478  {
479  $error++;
480  setEventMessages($db->lasterror(), null, 'errors');
481  break;
482  }
483  }
484  } elseif ($generateinvoicemode == 'onelinepertask') {
485  $arrayoftasks = array();
486  foreach ($toselect as $key => $value)
487  {
488  // Get userid, timepent
489  $object->fetchTimeSpent($value);
490  // $object->id is the task id
491  $arrayoftasks[$object->id]['timespent'] += $object->timespent_duration;
492  $arrayoftasks[$object->id]['totalvaluetodivideby3600'] += $object->timespent_duration * $object->timespent_thm;
493  }
494 
495  foreach ($arrayoftasks as $task_id => $value)
496  {
497  $ftask = new Task($db);
498  $ftask->fetch($task_id);
499  // Define qty per hour
500  $qtyhour = $value['timespent'] / 3600;
501  $qtyhourtext = convertSecondToTime($value['timespent'], 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
502 
503  // If no unit price known
504  if (empty($pu_ht))
505  {
506  $pu_ht = price2num($value['totalvaluetodivideby3600'] / 3600, 'MU');
507  }
508 
509  // Add lines
510  $lineName = $ftask->ref.' - '.$ftask->label;
511  $lineid = $tmpinvoice->addline($lineName, $pu_ht, round($qtyhour / $prodDurationHours, 2), $txtva, $localtax1, $localtax2, ($idprod > 0 ? $idprod : 0));
512 
513  // Update lineid into line of timespent
514  $sql = 'UPDATE '.MAIN_DB_PREFIX.'projet_task_time SET invoice_line_id = '.$lineid.', invoice_id = '.$tmpinvoice->id;
515  $sql .= ' WHERE rowid in ('.join(',', $toselect).')';
516  $result = $db->query($sql);
517  if (!$result)
518  {
519  $error++;
520  setEventMessages($db->lasterror(), null, 'errors');
521  break;
522  }
523  }
524  }
525  }
526 
527  if (!$error)
528  {
529  $urltoinvoice = $tmpinvoice->getNomUrl(0);
530  setEventMessages($langs->trans("InvoiceGeneratedFromTimeSpent", $urltoinvoice), null, 'mesgs');
531  //var_dump($tmpinvoice);
532 
533  $db->commit();
534  } else {
535  $db->rollback();
536  }
537  }
538 }
539 
540 
541 /*
542  * View
543  */
544 
545 $arrayofselected = is_array($toselect) ? $toselect : array();
546 
547 llxHeader("", $langs->trans("Task"));
548 
549 $form = new Form($db);
550 $formother = new FormOther($db);
551 $formproject = new FormProjets($db);
552 $userstatic = new User($db);
553 
554 if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0)
555 {
556  /*
557  * Fiche projet en mode visu
558  */
559  if ($projectidforalltimes > 0)
560  {
561  $result = $projectstatic->fetch($projectidforalltimes);
562  if (!empty($projectstatic->socid)) $projectstatic->fetch_thirdparty();
563  $res = $projectstatic->fetch_optionals();
564  } elseif ($object->fetch($id, $ref) >= 0)
565  {
566  if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK) && method_exists($object, 'fetchComments') && empty($object->comments)) $object->fetchComments();
567  $result = $projectstatic->fetch($object->fk_project);
568  if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) $projectstatic->fetchComments();
569  if (!empty($projectstatic->socid)) $projectstatic->fetch_thirdparty();
570  $res = $projectstatic->fetch_optionals();
571 
572  $object->project = clone $projectstatic;
573  }
574 
575  $userRead = $projectstatic->restrictedProjectArea($user, 'read');
576  $linktocreatetime = '';
577 
578  if ($projectstatic->id > 0)
579  {
580  if ($withproject)
581  {
582  // Tabs for project
583  if (empty($id) || $tab == 'timespent') $tab = 'timespent';
584  else $tab = 'tasks';
585 
586  $head = project_prepare_head($projectstatic);
587  print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'));
588 
589  $param = ($mode == 'mine' ? '&mode=mine' : '');
590 
591  // Project card
592 
593  $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
594 
595  $morehtmlref = '<div class="refidno">';
596  // Title
597  $morehtmlref .= $projectstatic->title;
598  // Thirdparty
599  if ($projectstatic->thirdparty->id > 0)
600  {
601  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$projectstatic->thirdparty->getNomUrl(1, 'project');
602  }
603  $morehtmlref .= '</div>';
604 
605  // Define a complementary filter for search of next/prev ref.
606  if (!$user->rights->projet->all->lire)
607  {
608  $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
609  $projectstatic->next_prev_filter = " rowid in (".(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
610  }
611 
612  dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
613 
614  print '<div class="fichecenter">';
615  print '<div class="fichehalfleft">';
616  print '<div class="underbanner clearboth"></div>';
617 
618  print '<table class="border tableforfield centpercent">';
619 
620  // Usage
621  print '<tr><td class="tdtop">';
622  print $langs->trans("Usage");
623  print '</td>';
624  print '<td>';
625  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
626  {
627  print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> ';
628  $htmltext = $langs->trans("ProjectFollowOpportunity");
629  print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
630  print '<br>';
631  }
632  if (empty($conf->global->PROJECT_HIDE_TASKS))
633  {
634  print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> ';
635  $htmltext = $langs->trans("ProjectFollowTasks");
636  print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
637  print '<br>';
638  }
639  if (!empty($conf->global->PROJECT_BILL_TIME_SPENT))
640  {
641  print '<input type="checkbox" disabled name="usage_bill_time"'.(GETPOSTISSET('usage_bill_time') ? (GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_bill_time ? ' checked="checked"' : '')).'"> ';
642  $htmltext = $langs->trans("ProjectBillTimeDescription");
643  print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
644  print '<br>';
645  }
646  print '</td></tr>';
647 
648  // Visibility
649  print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
650  if ($projectstatic->public) print $langs->trans('SharedProject');
651  else print $langs->trans('PrivateProject');
652  print '</td></tr>';
653 
654  // Date start - end
655  print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
656  $start = dol_print_date($projectstatic->date_start, 'day');
657  print ($start ? $start : '?');
658  $end = dol_print_date($projectstatic->date_end, 'day');
659  print ' - ';
660  print ($end ? $end : '?');
661  if ($projectstatic->hasDelay()) print img_warning("Late");
662  print '</td></tr>';
663 
664  // Budget
665  print '<tr><td>'.$langs->trans("Budget").'</td><td>';
666  if (strcmp($projectstatic->budget_amount, '')) print price($projectstatic->budget_amount, '', $langs, 1, 0, 0, $conf->currency);
667  print '</td></tr>';
668 
669  // Other attributes
670  $cols = 2;
671  //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
672 
673  print '</table>';
674 
675  print '</div>';
676  print '<div class="fichehalfright">';
677  print '<div class="ficheaddleft">';
678  print '<div class="underbanner clearboth"></div>';
679 
680  print '<table class="border tableforfield" width="100%">';
681 
682  // Description
683  print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
684  print nl2br($projectstatic->description);
685  print '</td></tr>';
686 
687  // Categories
688  if ($conf->categorie->enabled) {
689  print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
690  print $form->showCategories($projectstatic->id, 'project', 1);
691  print "</td></tr>";
692  }
693 
694  print '</table>';
695 
696  print '</div>';
697  print '</div>';
698  print '</div>';
699 
700  print '<div class="clearboth"></div>';
701 
703 
704  print '<br>';
705  }
706 
707  // Link to create time
708  $linktocreatetimeBtnStatus = 0;
709  $linktocreatetimeUrl = '';
710  $linktocreatetimeHelpText = '';
711  if ($user->rights->projet->all->lire || $user->rights->projet->lire) // To enter time, read permission is enough
712  {
713  if ($projectstatic->public || $userRead > 0)
714  {
715  $linktocreatetimeBtnStatus = 1;
716 
717  if (!empty($projectidforalltimes)) // We are on tab 'Time Spent' of project
718  {
719  $backtourl = $_SERVER['PHP_SELF'].'?projectid='.$projectstatic->id.($withproject ? '&withproject=1' : '');
720  $linktocreatetimeUrl = $_SERVER['PHP_SELF'].'?'.($withproject ? 'withproject=1' : '').'&projectid='.$projectstatic->id.'&action=createtime'.$param.'&backtopage='.urlencode($backtourl);
721  } else // We are on tab 'Time Spent' of task
722  {
723  $backtourl = $_SERVER['PHP_SELF'].'?id='.$object->id.($withproject ? '&withproject=1' : '');
724  $linktocreatetimeUrl = $_SERVER['PHP_SELF'].'?'.($withproject ? 'withproject=1' : '').($object->id > 0 ? '&id='.$object->id : '&projectid='.$projectstatic->id).'&action=createtime'.$param.'&backtopage='.urlencode($backtourl);
725  }
726  } else {
727  $linktocreatetimeBtnStatus = -2;
728  $linktocreatetimeHelpText = $langs->trans("NotOwnerOfProject");
729  }
730  }
731 
732  $linktocreatetime = dolGetButtonTitle($langs->trans('AddTimeSpent'), $linktocreatetimeHelpText, 'fa fa-plus-circle', $linktocreatetimeUrl, '', $linktocreatetimeBtnStatus);
733  }
734 
735  $massactionbutton = '';
736  if ($projectstatic->usage_bill_time)
737  {
738  $arrayofmassactions = array(
739  'generateinvoice'=>$langs->trans("GenerateBill"),
740  //'builddoc'=>$langs->trans("PDFMerge"),
741  );
742  //if ($user->rights->projet->creer) $arrayofmassactions['predelete']='<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
743  if (in_array($massaction, array('presend', 'predelete', 'generateinvoice'))) $arrayofmassactions = array();
744  $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
745  }
746 
747  // Show section with information of task. If id of task is not defined and project id defined, then $projectidforalltimes is not empty.
748  if (empty($projectidforalltimes))
749  {
750  $head = task_prepare_head($object);
751  print dol_get_fiche_head($head, 'task_time', $langs->trans("Task"), -1, 'projecttask', 0, '', 'reposition');
752 
753  if ($action == 'deleteline')
754  {
755  print $form->formconfirm($_SERVER["PHP_SELF"]."?".($object->id > 0 ? "id=".$object->id : 'projectid='.$projectstatic->id).'&lineid='.GETPOST("lineid", 'int').($withproject ? '&withproject=1' : ''), $langs->trans("DeleteATimeSpent"), $langs->trans("ConfirmDeleteATimeSpent"), "confirm_delete", '', '', 1);
756  }
757 
758  $param = ($withproject ? '&withproject=1' : '');
759  $linkback = $withproject ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>' : '';
760 
761  if (!GETPOST('withproject') || empty($projectstatic->id))
762  {
763  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
764  $object->next_prev_filter = " fk_projet in (".$projectsListId.")";
765  } else $object->next_prev_filter = " fk_projet = ".$projectstatic->id;
766 
767  $morehtmlref = '';
768 
769  // Project
770  if (empty($withproject))
771  {
772  $morehtmlref .= '<div class="refidno">';
773  $morehtmlref .= $langs->trans("Project").': ';
774  $morehtmlref .= $projectstatic->getNomUrl(1);
775  $morehtmlref .= '<br>';
776 
777  // Third party
778  $morehtmlref .= $langs->trans("ThirdParty").': ';
779  if (is_object($projectstatic->thirdparty)) {
780  $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1);
781  }
782  $morehtmlref .= '</div>';
783  }
784 
785  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
786 
787  print '<div class="fichecenter">';
788  print '<div class="fichehalfleft">';
789 
790  print '<div class="underbanner clearboth"></div>';
791  print '<table class="border tableforfield centpercent">';
792 
793  // Date start - Date end
794  print '<tr><td class="titlefield">'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
795  $start = dol_print_date($object->date_start, 'dayhour');
796  print ($start ? $start : '?');
797  $end = dol_print_date($object->date_end, 'dayhour');
798  print ' - ';
799  print ($end ? $end : '?');
800  if ($object->hasDelay()) print img_warning("Late");
801  print '</td></tr>';
802 
803  // Planned workload
804  print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td>';
805  if ($object->planned_workload)
806  {
807  print convertSecondToTime($object->planned_workload, 'allhourmin');
808  }
809  print '</td></tr>';
810 
811  print '</table>';
812  print '</div>';
813 
814  print '<div class="fichehalfright"><div class="ficheaddleft">';
815 
816  print '<div class="underbanner clearboth"></div>';
817  print '<table class="border tableforfield centpercent">';
818 
819  // Progress declared
820  print '<tr><td class="titlefield">'.$langs->trans("ProgressDeclared").'</td><td>';
821  print $object->progress != '' ? $object->progress.' %' : '';
822  print '</td></tr>';
823 
824  // Progress calculated
825  print '<tr><td>'.$langs->trans("ProgressCalculated").'</td><td>';
826  if ($object->planned_workload)
827  {
828  $tmparray = $object->getSummaryOfTimeSpent();
829  if ($tmparray['total_duration'] > 0) print round($tmparray['total_duration'] / $object->planned_workload * 100, 2).' %';
830  else print '0 %';
831  } else print '<span class="opacitymedium">'.$langs->trans("WorkloadNotDefined").'</span>';
832  print '</td>';
833 
834  print '</tr>';
835 
836  print '</table>';
837 
838  print '</div>';
839  print '</div>';
840 
841  print '</div>';
842  print '<div class="clearboth"></div>';
843 
845  }
846 
847 
848  if ($projectstatic->id > 0)
849  {
850  if ($action == 'deleteline' && !empty($projectidforalltimes))
851  {
852  print $form->formconfirm($_SERVER["PHP_SELF"]."?".($object->id > 0 ? "id=".$object->id : 'projectid='.$projectstatic->id).'&lineid='.GETPOST('lineid', 'int').($withproject ? '&withproject=1' : ''), $langs->trans("DeleteATimeSpent"), $langs->trans("ConfirmDeleteATimeSpent"), "confirm_delete", '', '', 1);
853  }
854 
855  // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
856  $hookmanager->initHooks(array('tasktimelist'));
857 
858  // Definition of fields for list
859  $arrayfields = array();
860  $arrayfields['t.task_date'] = array('label'=>$langs->trans("Date"), 'checked'=>1);
861  if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) // Not a dedicated task
862  {
863  $arrayfields['t.task_ref'] = array('label'=>$langs->trans("RefTask"), 'checked'=>1);
864  $arrayfields['t.task_label'] = array('label'=>$langs->trans("LabelTask"), 'checked'=>1);
865  }
866  $arrayfields['author'] = array('label'=>$langs->trans("By"), 'checked'=>1);
867  $arrayfields['t.note'] = array('label'=>$langs->trans("Note"), 'checked'=>1);
868  $arrayfields['t.task_duration'] = array('label'=>$langs->trans("Duration"), 'checked'=>1);
869  $arrayfields['value'] = array('label'=>$langs->trans("Value"), 'checked'=>1, 'enabled'=>(empty($conf->salaries->enabled) ? 0 : 1));
870  $arrayfields['valuebilled'] = array('label'=>$langs->trans("Billed"), 'checked'=>1, 'enabled'=>(((!empty($conf->global->PROJECT_HIDE_TASKS) || empty($conf->global->PROJECT_BILL_TIME_SPENT)) ? 0 : 1) && $projectstatic->usage_bill_time));
871  // Extra fields
872  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
873 
874  $arrayfields = dol_sort_array($arrayfields, 'position');
875 
876  $param = '';
877  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
878  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
879  if ($search_month > 0) $param .= '&search_month='.urlencode($search_month);
880  if ($search_year > 0) $param .= '&search_year='.urlencode($search_year);
881  if ($search_user > 0) $param .= '&search_user='.urlencode($search_user);
882  if ($search_task_ref != '') $param .= '&search_task_ref='.urlencode($search_task_ref);
883  if ($search_task_label != '') $param .= '&search_task_label='.urlencode($search_task_label);
884  if ($search_note != '') $param .= '&search_note='.urlencode($search_note);
885  if ($search_duration != '') $param .= '&amp;search_field2='.urlencode($search_duration);
886  if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
887  /*
888  // Add $param from extra fields
889  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
890  */
891  if ($id) $param .= '&id='.urlencode($id);
892  if ($projectid) $param .= '&projectid='.urlencode($projectid);
893  if ($withproject) $param .= '&withproject='.urlencode($withproject);
894 
895  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
896  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
897  print '<input type="hidden" name="token" value="'.newToken().'">';
898  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
899  if ($action == 'editline') print '<input type="hidden" name="action" value="updateline">';
900  elseif ($action == 'splitline') print '<input type="hidden" name="action" value="updatesplitline">';
901  elseif ($action == 'createtime' && $user->rights->projet->lire) print '<input type="hidden" name="action" value="addtimespent">';
902  elseif ($massaction == 'generateinvoice' && $user->rights->facture->lire) print '<input type="hidden" name="action" value="confirm_generateinvoice">';
903  else print '<input type="hidden" name="action" value="list">';
904  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
905  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
906 
907  print '<input type="hidden" name="id" value="'.$id.'">';
908  print '<input type="hidden" name="projectid" value="'.$projectidforalltimes.'">';
909  print '<input type="hidden" name="withproject" value="'.$withproject.'">';
910  print '<input type="hidden" name="tab" value="'.$tab.'">';
911 
912  // Form to convert time spent into invoice
913  if ($massaction == 'generateinvoice')
914  {
915  print '<input type="hidden" name="massaction" value="confirm_createbills">';
916 
917  if ($projectstatic->thirdparty->id > 0) {
918  print '<table class="noborder" width="100%" >';
919  print '<tr>';
920  print '<td class="titlefield">';
921  print $langs->trans('DateInvoice');
922  print '</td>';
923  print '<td>';
924  print $form->selectDate('', '', '', '', '', '', 1, 1);
925  print '</td>';
926  print '</tr>';
927 
928  print '<tr>';
929  print '<td>';
930  print $langs->trans('Mode');
931  print '</td>';
932  print '<td>';
933  $tmparray = array(
934  'onelineperuser'=>'OneLinePerUser',
935  'onelinepertask'=>'OneLinePerTask',
936  'onelineperperiod'=>'OneLinePerPeriod',
937  );
938  print $form->selectarray('generateinvoicemode', $tmparray, 'onelineperuser', 0, 0, 0, '', 1);
939  print '</td>';
940  print '</tr>';
941 
942  if ($conf->service->enabled)
943  {
944  print '<tr>';
945  print '<td>';
946  print $langs->trans('ServiceToUseOnLines');
947  print '</td>';
948  print '<td>';
949  $form->select_produits('', 'productid', '1', 0, $projectstatic->thirdparty->price_level, 1, 2, '', 0, array(), $projectstatic->thirdparty->id, 'None', 0, 'maxwidth500');
950  print '</td>';
951  print '</tr>';
952  }
953 
954  print '<tr>';
955  print '<td class="titlefield">';
956  print $langs->trans('InvoiceToUse');
957  print '</td>';
958  print '<td>';
959  $form->selectInvoice('invoice', '', 'invoiceid', 24, 0, $langs->trans('NewInvoice'), 1, 0, 0, 'maxwidth500', '', 'all');
960  print '</td>';
961  print '</tr>';
962  /*print '<tr>';
963  print '<td>';
964  print $langs->trans('ValidateInvoices');
965  print '</td>';
966  print '<td>';
967  print $form->selectyesno('validate_invoices', 0, 1);
968  print '</td>';
969  print '</tr>';*/
970  print '</table>';
971 
972  print '<br>';
973  print '<div class="center">';
974  print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('GenerateBill').'"> ';
975  print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
976  print '</div>';
977  print '<br>';
978  } else {
979  print '<div class="warning">'.$langs->trans("ThirdPartyRequiredToGenerateInvoice").'</div>';
980  print '<div class="center">';
981  print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
982  print '</div>';
983  $massaction = '';
984  }
985  }
986 
987  /*
988  * List of time spent
989  */
990  $tasks = array();
991 
992  $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,";
993  $sql .= " pt.ref, pt.label,";
994  $sql .= " u.lastname, u.firstname, u.login, u.photo, u.statut as user_status,";
995  $sql .= " il.fk_facture as invoice_id, inv.fk_statut";
996  $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
997  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facturedet as il ON il.rowid = t.invoice_line_id";
998  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as inv ON inv.rowid = il.fk_facture,";
999  $sql .= " ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
1000  $sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
1001  if (empty($projectidforalltimes)) $sql .= " AND t.fk_task =".$object->id;
1002  else $sql .= " AND pt.fk_projet IN (".$projectidforalltimes.")";
1003  if ($search_note) $sql .= natural_search('t.note', $search_note);
1004  if ($search_task_ref) $sql .= natural_search('pt.ref', $search_task_ref);
1005  if ($search_task_label) $sql .= natural_search('pt.label', $search_task_label);
1006  if ($search_user > 0) $sql .= natural_search('t.fk_user', $search_user);
1007  if ($search_valuebilled == '1') $sql .= ' AND t.invoice_id > 0';
1008  if ($search_valuebilled == '0') $sql .= ' AND (t.invoice_id = 0 OR t.invoice_id IS NULL)';
1009  $sql .= dolSqlDateFilter('t.task_datehour', $search_day, $search_month, $search_year);
1010  $sql .= $db->order($sortfield, $sortorder);
1011 
1012  // Count total nb of records
1013  $nbtotalofrecords = '';
1014  if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
1015  {
1016  $resql = $db->query($sql);
1017  $nbtotalofrecords = $db->num_rows($resql);
1018  if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0
1019  {
1020  $page = 0;
1021  $offset = 0;
1022  }
1023  }
1024  // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
1025  if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords)
1026  {
1027  $num = $nbtotalofrecords;
1028  } else {
1029  $sql .= $db->plimit($limit + 1, $offset);
1030 
1031  $resql = $db->query($sql);
1032  if (!$resql)
1033  {
1034  dol_print_error($db);
1035  exit;
1036  }
1037 
1038  $num = $db->num_rows($resql);
1039  }
1040 
1041  if ($num >= 0)
1042  {
1043  if (!empty($projectidforalltimes))
1044  {
1045  print '<!-- List of time spent for project -->'."\n";
1046 
1047  $title = $langs->trans("ListTaskTimeUserProject");
1048 
1049  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'clock', 0, $linktocreatetime, '', $limit, 0, 0, 1);
1050  } else {
1051  print '<!-- List of time spent for project -->'."\n";
1052 
1053  $title = $langs->trans("ListTaskTimeForTask");
1054 
1055  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'clock', 0, $linktocreatetime, '', $limit, 0, 0, 1);
1056  }
1057 
1058  $i = 0;
1059  while ($i < $num)
1060  {
1061  $row = $db->fetch_object($resql);
1062  $tasks[$i] = $row;
1063  $i++;
1064  }
1065  $db->free($resql);
1066  } else {
1067  dol_print_error($db);
1068  }
1069 
1070  /*
1071  * Form to add a new line of time spent
1072  */
1073  if ($action == 'createtime' && $user->rights->projet->lire)
1074  {
1075  print '<!-- table to add time spent -->'."\n";
1076  if (!empty($id)) print '<input type="hidden" name="taskid" value="'.$id.'">';
1077 
1078  print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
1079  print '<table class="noborder nohover centpercent">';
1080 
1081  print '<tr class="liste_titre">';
1082  print '<td>'.$langs->trans("Date").'</td>';
1083  if (empty($id)) print '<td>'.$langs->trans("Task").'</td>';
1084  print '<td>'.$langs->trans("By").'</td>';
1085  print '<td>'.$langs->trans("Note").'</td>';
1086  print '<td>'.$langs->trans("NewTimeSpent").'</td>';
1087  print '<td>'.$langs->trans("ProgressDeclared").'</td>';
1088  if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT))
1089  {
1090  print '<td></td>';
1091  }
1092  print '<td></td>';
1093  print "</tr>\n";
1094 
1095  print '<tr class="oddeven nohover">';
1096 
1097  // Date
1098  print '<td class="maxwidthonsmartphone">';
1099  //$newdate=dol_mktime(12,0,0,$_POST["timemonth"],$_POST["timeday"],$_POST["timeyear"]);
1100  $newdate = '';
1101  print $form->selectDate($newdate, 'time', ($conf->browser->layout == 'phone' ? 2 : 1), 1, 2, "timespent_date", 1, 0);
1102  print '</td>';
1103 
1104  // Task
1105  $nboftasks = 0;
1106  if (empty($id))
1107  {
1108  print '<td class="maxwidthonsmartphone">';
1109  $nboftasks = $formproject->selectTasks(-1, GETPOST('taskid', 'int'), 'taskid', 0, 0, 1, 1, 0, 0, 'maxwidth300', $projectstatic->id, '');
1110  print '</td>';
1111  }
1112 
1113  // Contributor
1114  print '<td class="maxwidthonsmartphone nowraponall">';
1115  $contactsofproject = $projectstatic->getListContactId('internal');
1116  if (count($contactsofproject) > 0)
1117  {
1118  print img_object('', 'user', 'class="hideonsmartphone"');
1119  if (in_array($user->id, $contactsofproject)) $userid = $user->id;
1120  else $userid = $contactsofproject[0];
1121 
1122  if ($projectstatic->public) $contactsofproject = array();
1123  print $form->select_dolusers((GETPOST('userid', 'int') ? GETPOST('userid', 'int') : $userid), 'userid', 0, '', 0, '', $contactsofproject, 0, 0, 0, '', 0, $langs->trans("ResourceNotAssignedToProject"), 'maxwidth250');
1124  } else {
1125  if ($nboftasks) {
1126  print img_error($langs->trans('FirstAddRessourceToAllocateTime')).' '.$langs->trans('FirstAddRessourceToAllocateTime');
1127  }
1128  }
1129  print '</td>';
1130 
1131  // Note
1132  print '<td>';
1133  print '<textarea name="timespent_note" class="maxwidth100onsmartphone" rows="'.ROWS_2.'">'.($_POST['timespent_note'] ? $_POST['timespent_note'] : '').'</textarea>';
1134  print '</td>';
1135 
1136  // Duration - Time spent
1137  print '<td>';
1138  $durationtouse = ($_POST['timespent_duration'] ? $_POST['timespent_duration'] : '');
1139  if (GETPOSTISSET('timespent_durationhour') || GETPOSTISSET('timespent_durationmin'))
1140  {
1141  $durationtouse = (GETPOST('timespent_durationhour') * 3600 + GETPOST('timespent_durationmin') * 60);
1142  }
1143  print $form->select_duration('timespent_duration', $durationtouse, 0, 'text');
1144  print '</td>';
1145 
1146  // Progress declared
1147  print '<td class="nowrap">';
1148  print $formother->select_percent(GETPOST('progress') ?GETPOST('progress') : $object->progress, 'progress', 0, 5, 0, 100, 1);
1149  print '</td>';
1150 
1151  // Invoiced
1152  if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT))
1153  {
1154  print '<td>';
1155  print '</td>';
1156  }
1157 
1158  print '<td class="center">';
1159  print '<input type="submit" name="save" class="button buttongen marginleftonly margintoponlyshort marginbottomonlyshort" value="'.$langs->trans("Add").'">';
1160  print '<input type="submit" name="cancel" class="button buttongen marginleftonly margintoponlyshort marginbottomonlyshort button-cancel" value="'.$langs->trans("Cancel").'">';
1161  print '</td></tr>';
1162 
1163  print '</table>';
1164  print '</div>';
1165 
1166  print '<br>';
1167  }
1168 
1169  $moreforfilter = '';
1170 
1171  $parameters = array();
1172  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
1173  if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
1174  else $moreforfilter = $hookmanager->resPrint;
1175 
1176  if (!empty($moreforfilter))
1177  {
1178  print '<div class="liste_titre liste_titre_bydiv centpercent">';
1179  print $moreforfilter;
1180  print '</div>';
1181  }
1182 
1183  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1184  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
1185  $selectedfields .= (is_array($arrayofmassactions) && count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1186 
1187  print '<div class="div-table-responsive">';
1188  print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1189 
1190  // Fields title search
1191  print '<tr class="liste_titre_filter">';
1192  // Date
1193  if (!empty($arrayfields['t.task_date']['checked']))
1194  {
1195  print '<td class="liste_titre">';
1196  if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_day" value="'.$search_day.'">';
1197  print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_month" value="'.$search_month.'">';
1198  $formother->select_year($search_year, 'search_year', 1, 20, 5);
1199  print '</td>';
1200  }
1201  if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) // Not a dedicated task
1202  {
1203  if (!empty($arrayfields['t.task_ref']['checked'])) print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_task_ref" value="'.dol_escape_htmltag($search_task_ref).'"></td>';
1204  if (!empty($arrayfields['t.task_label']['checked'])) print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_task_label" value="'.dol_escape_htmltag($search_task_label).'"></td>';
1205  }
1206  // Author
1207  if (!empty($arrayfields['author']['checked'])) print '<td class="liste_titre">'.$form->select_dolusers(($search_user > 0 ? $search_user : -1), 'search_user', 1, null, 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250').'</td>';
1208  // Note
1209  if (!empty($arrayfields['t.note']['checked'])) print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_note" value="'.dol_escape_htmltag($search_note).'"></td>';
1210  // Duration
1211  if (!empty($arrayfields['t.task_duration']['checked'])) print '<td class="liste_titre right"></td>';
1212  // Value in main currency
1213  if (!empty($arrayfields['value']['checked'])) print '<td class="liste_titre"></td>';
1214  // Value billed
1215  if (!empty($arrayfields['valuebilled']['checked'])) print '<td class="liste_titre center">'.$form->selectyesno('search_valuebilled', $search_valuebilled, 1, false, 1).'</td>';
1216 
1217  /*
1218  // Extra fields
1219  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1220  */
1221  // Fields from hook
1222  $parameters = array('arrayfields'=>$arrayfields);
1223  $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
1224  print $hookmanager->resPrint;
1225  // Action column
1226  print '<td class="liste_titre center">';
1227  $searchpicto = $form->showFilterButtons();
1228  print $searchpicto;
1229  print '</td>';
1230  print '</tr>'."\n";
1231 
1232  print '<tr class="liste_titre">';
1233  if (!empty($arrayfields['t.task_date']['checked'])) print_liste_field_titre($arrayfields['t.task_date']['label'], $_SERVER['PHP_SELF'], 't.task_date,t.task_datehour,t.rowid', '', $param, '', $sortfield, $sortorder);
1234  if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) // Not a dedicated task
1235  {
1236  if (!empty($arrayfields['t.task_ref']['checked'])) print_liste_field_titre($arrayfields['t.task_ref']['label'], $_SERVER['PHP_SELF'], 'pt.ref', '', $param, '', $sortfield, $sortorder);
1237  if (!empty($arrayfields['t.task_label']['checked'])) print_liste_field_titre($arrayfields['t.task_label']['label'], $_SERVER['PHP_SELF'], 'pt.label', '', $param, '', $sortfield, $sortorder);
1238  }
1239  if (!empty($arrayfields['author']['checked'])) print_liste_field_titre($arrayfields['author']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
1240  if (!empty($arrayfields['t.note']['checked'])) print_liste_field_titre($arrayfields['t.note']['label'], $_SERVER['PHP_SELF'], 't.note', '', $param, '', $sortfield, $sortorder);
1241  if (!empty($arrayfields['t.task_duration']['checked'])) print_liste_field_titre($arrayfields['t.task_duration']['label'], $_SERVER['PHP_SELF'], 't.task_duration', '', $param, '', $sortfield, $sortorder, 'right ');
1242  if (!empty($arrayfields['value']['checked'])) print_liste_field_titre($arrayfields['value']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
1243  if (!empty($arrayfields['valuebilled']['checked'])) print_liste_field_titre($arrayfields['valuebilled']['label'], $_SERVER['PHP_SELF'], 'il.total_ht', '', $param, '', $sortfield, $sortorder, 'center ');
1244  /*
1245  // Extra fields
1246  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1247  */
1248  // Hook fields
1249  $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
1250  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
1251  print $hookmanager->resPrint;
1252  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'width="80"', $sortfield, $sortorder, 'center maxwidthsearch ');
1253  print "</tr>\n";
1254 
1255  $tasktmp = new Task($db);
1256  $tmpinvoice = new Facture($db);
1257 
1258  $i = 0;
1259 
1260  $childids = $user->getAllChildIds();
1261 
1262  $total = 0;
1263  $totalvalue = 0;
1264  $totalarray = array();
1265  foreach ($tasks as $task_time)
1266  {
1267  if ($i >= $limit) break;
1268 
1269  print '<tr class="oddeven">';
1270 
1271  $date1 = $db->jdate($task_time->task_date);
1272  $date2 = $db->jdate($task_time->task_datehour);
1273 
1274  // Date
1275  if (!empty($arrayfields['t.task_date']['checked']))
1276  {
1277  print '<td class="nowrap">';
1278  if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid)
1279  {
1280  if (empty($task_time->task_date_withhour))
1281  {
1282  print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 3, 3, 2, "timespent_date", 1, 0);
1283  } else print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 1, 1, 2, "timespent_date", 1, 0);
1284  } else {
1285  print dol_print_date(($date2 ? $date2 : $date1), ($task_time->task_date_withhour ? 'dayhour' : 'day'));
1286  }
1287  print '</td>';
1288  if (!$i) $totalarray['nbfield']++;
1289  }
1290 
1291  // Task ref
1292  if (!empty($arrayfields['t.task_ref']['checked']))
1293  {
1294  if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) // Not a dedicated task
1295  {
1296  print '<td class="nowrap">';
1297  if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid)
1298  {
1299  $formproject->selectTasks(-1, GETPOST('taskid', 'int') ?GETPOST('taskid', 'int') : $task_time->fk_task, 'taskid', 0, 0, 1, 1, 0, 0, 'maxwidth300', $projectstatic->id, '');
1300  } else {
1301  $tasktmp->id = $task_time->fk_task;
1302  $tasktmp->ref = $task_time->ref;
1303  $tasktmp->label = $task_time->label;
1304  print $tasktmp->getNomUrl(1, 'withproject', 'time');
1305  }
1306  print '</td>';
1307  if (!$i) $totalarray['nbfield']++;
1308  }
1309  } else {
1310  print '<input type="hidden" name="taskid" value="'.$id.'">';
1311  }
1312 
1313  // Task label
1314  if (!empty($arrayfields['t.task_label']['checked']))
1315  {
1316  if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) // Not a dedicated task
1317  {
1318  print '<td class="nowrap">';
1319  print $task_time->label;
1320  print '</td>';
1321  if (!$i) $totalarray['nbfield']++;
1322  }
1323  }
1324 
1325  // By User
1326  if (!empty($arrayfields['author']['checked']))
1327  {
1328  print '<td class="nowrap">';
1329  if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid)
1330  {
1331  if (empty($object->id)) $object->fetch($id);
1332  $contactsoftask = $object->getListContactId('internal');
1333  if (!in_array($task_time->fk_user, $contactsoftask)) {
1334  $contactsoftask[] = $task_time->fk_user;
1335  }
1336  if (count($contactsoftask) > 0) {
1337  print img_object('', 'user', 'class="hideonsmartphone"');
1338  print $form->select_dolusers($task_time->fk_user, 'userid_line', 0, '', 0, '', $contactsoftask, '0', 0, 0, '', 0, '', 'maxwidth200');
1339  } else {
1340  print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime');
1341  }
1342  } else {
1343  $userstatic->id = $task_time->fk_user;
1344  $userstatic->lastname = $task_time->lastname;
1345  $userstatic->firstname = $task_time->firstname;
1346  $userstatic->photo = $task_time->photo;
1347  $userstatic->statut = $task_time->user_status;
1348  print $userstatic->getNomUrl(-1);
1349  }
1350  print '</td>';
1351  if (!$i) $totalarray['nbfield']++;
1352  }
1353 
1354  // Note
1355  if (!empty($arrayfields['t.note']['checked']))
1356  {
1357  print '<td class="left">';
1358  if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid)
1359  {
1360  print '<textarea name="timespent_note_line" width="95%" rows="'.ROWS_2.'">'.$task_time->note.'</textarea>';
1361  } else {
1362  print dol_nl2br($task_time->note);
1363  }
1364  print '</td>';
1365  if (!$i) $totalarray['nbfield']++;
1366  } elseif ($action == 'editline' && $_GET['lineid'] == $task_time->rowid)
1367  {
1368  print '<input type="hidden" name="timespent_note_line" value="'.$task_time->note.'">';
1369  }
1370 
1371  // Time spent
1372  if (!empty($arrayfields['t.task_duration']['checked']))
1373  {
1374  print '<td class="right">';
1375  if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid)
1376  {
1377  print '<input type="hidden" name="old_duration" value="'.$task_time->task_duration.'">';
1378  print $form->select_duration('new_duration', $task_time->task_duration, 0, 'text');
1379  } else {
1380  print convertSecondToTime($task_time->task_duration, 'allhourmin');
1381  }
1382  print '</td>';
1383  if (!$i) $totalarray['nbfield']++;
1384  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 't.task_duration';
1385  $totalarray['val']['t.task_duration'] += $task_time->task_duration;
1386  if (!$i) $totalarray['totaldurationfield'] = $totalarray['nbfield'];
1387  $totalarray['totalduration'] += $task_time->task_duration;
1388  }
1389 
1390  // Value spent
1391  if (!empty($arrayfields['value']['checked']))
1392  {
1393  print '<td class="nowraponall right">';
1394  $value = price2num($task_time->thm * $task_time->task_duration / 3600, 'MT', 1);
1395  print price($value, 1, $langs, 1, -1, -1, $conf->currency);
1396  print '</td>';
1397  if (!$i) $totalarray['nbfield']++;
1398  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'value';
1399  $totalarray['val']['value'] += $value;
1400  if (!$i) $totalarray['totalvaluefield'] = $totalarray['nbfield'];
1401  $totalarray['totalvalue'] += $value;
1402  }
1403 
1404  // Invoiced
1405  if (!empty($arrayfields['valuebilled']['checked']))
1406  {
1407  print '<td class="center">'; // invoice_id and invoice_line_id
1408  if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT))
1409  {
1410  if ($projectstatic->usage_bill_time)
1411  {
1412  if ($task_time->invoice_id)
1413  {
1414  $result = $tmpinvoice->fetch($task_time->invoice_id);
1415  if ($result > 0)
1416  {
1417  print $tmpinvoice->getNomUrl(1);
1418  }
1419  } else {
1420  print $langs->trans("No");
1421  }
1422  } else {
1423  print '<span class="opacitymedium">'.$langs->trans("NA").'</span>';
1424  }
1425  }
1426  print '</td>';
1427  if (!$i) $totalarray['nbfield']++;
1428  }
1429 
1430  /*
1431  // Extra fields
1432  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1433  */
1434 
1435  // Fields from hook
1436  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$task_time, 'i'=>$i, 'totalarray'=>&$totalarray);
1437  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1438  print $hookmanager->resPrint;
1439 
1440  // Action column
1441  print '<td class="center nowraponall">';
1442  if (($action == 'editline' || $action == 'splitline') && $_GET['lineid'] == $task_time->rowid)
1443  {
1444  print '<input type="hidden" name="lineid" value="'.$_GET['lineid'].'">';
1445  print '<input type="submit" class="button buttongen margintoponlyshort marginbottomonlyshort button-save" name="save" value="'.$langs->trans("Save").'">';
1446  print '<br>';
1447  print '<input type="submit" class="button buttongen margintoponlyshort marginbottomonlyshort button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1448  } elseif ($user->rights->projet->lire || $user->rights->projet->all->creer) // Read project and enter time consumed on assigned tasks
1449  {
1450  if ($task_time->fk_user == $user->id || in_array($task_time->fk_user, $childids) || $user->rights->projet->all->creer)
1451  {
1452  if ($conf->MAIN_FEATURES_LEVEL >= 2)
1453  {
1454  print '&nbsp;';
1455  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$task_time->fk_task.'&amp;action=splitline&amp;lineid='.$task_time->rowid.$param.((empty($id) || $tab == 'timespent') ? '&tab=timespent' : '').'">';
1456  print img_split();
1457  print '</a>';
1458  }
1459 
1460  print '&nbsp;';
1461  print '<a class="reposition editfielda" href="'.$_SERVER["PHP_SELF"].'?id='.$task_time->fk_task.'&amp;action=editline&amp;lineid='.$task_time->rowid.$param.((empty($id) || $tab == 'timespent') ? '&tab=timespent' : '').'">';
1462  print img_edit();
1463  print '</a>';
1464 
1465  print '&nbsp;';
1466  print '<a class="reposition paddingleft" href="'.$_SERVER["PHP_SELF"].'?id='.$task_time->fk_task.'&amp;action=deleteline&amp;token='.newToken().'&amp;lineid='.$task_time->rowid.$param.((empty($id) || $tab == 'timespent') ? '&tab=timespent' : '').'">';
1467  print img_delete('default', 'class="pictodelete paddingleft"');
1468  print '</a>';
1469 
1470  if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1471  {
1472  $selected = 0;
1473  if (in_array($task_time->rowid, $arrayofselected)) $selected = 1;
1474  print '&nbsp;';
1475  print '<input id="cb'.$task_time->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$task_time->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1476  }
1477  }
1478  }
1479  print '</td>';
1480  if (!$i) $totalarray['nbfield']++;
1481 
1482  print "</tr>\n";
1483 
1484 
1485  // Add line to split
1486 
1487  if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
1488  {
1489  print '<tr class="oddeven">';
1490 
1491  // Date
1492  if (!empty($arrayfields['t.task_date']['checked']))
1493  {
1494  print '<td class="nowrap">';
1495  if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
1496  {
1497  if (empty($task_time->task_date_withhour))
1498  {
1499  print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 3, 3, 2, "timespent_date", 1, 0);
1500  } else print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 1, 1, 2, "timespent_date", 1, 0);
1501  } else {
1502  print dol_print_date(($date2 ? $date2 : $date1), ($task_time->task_date_withhour ? 'dayhour' : 'day'));
1503  }
1504  print '</td>';
1505  }
1506 
1507  // Task ref
1508  if (!empty($arrayfields['t.task_ref']['checked']))
1509  {
1510  if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) // Not a dedicated task
1511  {
1512  print '<td class="nowrap">';
1513  $tasktmp->id = $task_time->fk_task;
1514  $tasktmp->ref = $task_time->ref;
1515  $tasktmp->label = $task_time->label;
1516  print $tasktmp->getNomUrl(1, 'withproject', 'time');
1517  print '</td>';
1518  }
1519  }
1520 
1521  // Task label
1522  if (!empty($arrayfields['t.task_label']['checked']))
1523  {
1524  if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) // Not a dedicated task
1525  {
1526  print '<td>';
1527  print $task_time->label;
1528  print '</td>';
1529  }
1530  }
1531 
1532  // User
1533  if (!empty($arrayfields['author']['checked']))
1534  {
1535  print '<td>';
1536  if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
1537  {
1538  if (empty($object->id)) $object->fetch($id);
1539  $contactsoftask = $object->getListContactId('internal');
1540  if (!in_array($task_time->fk_user, $contactsoftask)) {
1541  $contactsoftask[] = $task_time->fk_user;
1542  }
1543  if (count($contactsoftask) > 0) {
1544  print img_object('', 'user', 'class="hideonsmartphone"');
1545  print $form->select_dolusers($task_time->fk_user, 'userid_line', 0, '', 0, '', $contactsoftask);
1546  } else {
1547  print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime');
1548  }
1549  } else {
1550  $userstatic->id = $task_time->fk_user;
1551  $userstatic->lastname = $task_time->lastname;
1552  $userstatic->firstname = $task_time->firstname;
1553  $userstatic->photo = $task_time->photo;
1554  $userstatic->statut = $task_time->user_status;
1555  print $userstatic->getNomUrl(-1);
1556  }
1557  print '</td>';
1558  }
1559 
1560  // Note
1561  if (!empty($arrayfields['t.note']['checked']))
1562  {
1563  print '<td class="left">';
1564  if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
1565  {
1566  print '<textarea name="timespent_note_line" width="95%" rows="'.ROWS_2.'">'.$task_time->note.'</textarea>';
1567  } else {
1568  print dol_nl2br($task_time->note);
1569  }
1570  print '</td>';
1571  } elseif ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
1572  {
1573  print '<input type="hidden" name="timespent_note_line" value="'.$task_time->note.'">';
1574  }
1575 
1576  // Time spent
1577  if (!empty($arrayfields['t.task_duration']['checked']))
1578  {
1579  print '<td class="right">';
1580  if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
1581  {
1582  print '<input type="hidden" name="old_duration" value="'.$task_time->task_duration.'">';
1583  print $form->select_duration('new_duration', $task_time->task_duration, 0, 'text');
1584  } else {
1585  print convertSecondToTime($task_time->task_duration, 'allhourmin');
1586  }
1587  print '</td>';
1588  }
1589 
1590  // Value spent
1591  if (!empty($arrayfields['value']['checked']))
1592  {
1593  print '<td class="right">';
1594  $value = price2num($task_time->thm * $task_time->task_duration / 3600, 'MT', 1);
1595  print price($value, 1, $langs, 1, -1, -1, $conf->currency);
1596  print '</td>';
1597  }
1598 
1599  // Value billed
1600  if (!empty($arrayfields['valuebilled']['checked']))
1601  {
1602  print '<td class="right">';
1603  $valuebilled = price2num($task_time->total_ht, '', 1);
1604  if (isset($task_time->total_ht)) print price($valuebilled, 1, $langs, 1, -1, -1, $conf->currency);
1605  print '</td>';
1606  }
1607 
1608  /*
1609  // Extra fields
1610  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1611  */
1612 
1613  // Fields from hook
1614  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$task_time);
1615  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1616  print $hookmanager->resPrint;
1617 
1618  // Action column
1619  print '<td class="center nowraponall">';
1620  print '</td>';
1621 
1622  print "</tr>\n";
1623 
1624 
1625  // Line for second dispatching
1626 
1627  print '<tr class="oddeven">';
1628 
1629  // Date
1630  if (!empty($arrayfields['t.task_date']['checked']))
1631  {
1632  print '<td class="nowrap">';
1633  if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
1634  {
1635  if (empty($task_time->task_date_withhour))
1636  {
1637  print $form->selectDate(($date2 ? $date2 : $date1), 'timeline_2', 3, 3, 2, "timespent_date", 1, 0);
1638  } else print $form->selectDate(($date2 ? $date2 : $date1), 'timeline_2', 1, 1, 2, "timespent_date", 1, 0);
1639  } else {
1640  print dol_print_date(($date2 ? $date2 : $date1), ($task_time->task_date_withhour ? 'dayhour' : 'day'));
1641  }
1642  print '</td>';
1643  }
1644 
1645  // Task ref
1646  if (!empty($arrayfields['t.task_ref']['checked']))
1647  {
1648  if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) // Not a dedicated task
1649  {
1650  print '<td class="nowrap">';
1651  $tasktmp->id = $task_time->fk_task;
1652  $tasktmp->ref = $task_time->ref;
1653  $tasktmp->label = $task_time->label;
1654  print $tasktmp->getNomUrl(1, 'withproject', 'time');
1655  print '</td>';
1656  }
1657  }
1658 
1659  // Task label
1660  if (!empty($arrayfields['t.task_label']['checked']))
1661  {
1662  if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) // Not a dedicated task
1663  {
1664  print '<td class="nowrap">';
1665  print $task_time->label;
1666  print '</td>';
1667  }
1668  }
1669 
1670  // User
1671  if (!empty($arrayfields['author']['checked']))
1672  {
1673  print '<td>';
1674  if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
1675  {
1676  if (empty($object->id)) $object->fetch($id);
1677  $contactsoftask = $object->getListContactId('internal');
1678  if (!in_array($task_time->fk_user, $contactsoftask)) {
1679  $contactsoftask[] = $task_time->fk_user;
1680  }
1681  if (count($contactsoftask) > 0) {
1682  print img_object('', 'user', 'class="hideonsmartphone"');
1683  print $form->select_dolusers($task_time->fk_user, 'userid_line_2', 0, '', 0, '', $contactsoftask);
1684  } else {
1685  print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime');
1686  }
1687  } else {
1688  $userstatic->id = $task_time->fk_user;
1689  $userstatic->lastname = $task_time->lastname;
1690  $userstatic->firstname = $task_time->firstname;
1691  $userstatic->photo = $task_time->photo;
1692  $userstatic->statut = $task_time->user_status;
1693  print $userstatic->getNomUrl(-1);
1694  }
1695  print '</td>';
1696  }
1697 
1698  // Note
1699  if (!empty($arrayfields['t.note']['checked']))
1700  {
1701  print '<td class="left">';
1702  if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
1703  {
1704  print '<textarea name="timespent_note_line_2" width="95%" rows="'.ROWS_2.'">'.$task_time->note.'</textarea>';
1705  } else {
1706  print dol_nl2br($task_time->note);
1707  }
1708  print '</td>';
1709  } elseif ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
1710  {
1711  print '<input type="hidden" name="timespent_note_line_2" value="'.$task_time->note.'">';
1712  }
1713 
1714  // Time spent
1715  if (!empty($arrayfields['t.task_duration']['checked']))
1716  {
1717  print '<td class="right">';
1718  if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
1719  {
1720  print '<input type="hidden" name="old_duration_2" value="0">';
1721  print $form->select_duration('new_duration_2', 0, 0, 'text');
1722  } else {
1723  print convertSecondToTime($task_time->task_duration, 'allhourmin');
1724  }
1725  print '</td>';
1726  }
1727 
1728  // Value spent
1729  if (!empty($arrayfields['value']['checked']))
1730  {
1731  print '<td class="right">';
1732  $value = 0;
1733  print price($value, 1, $langs, 1, -1, -1, $conf->currency);
1734  print '</td>';
1735  }
1736 
1737  // Value billed
1738  if (!empty($arrayfields['valuebilled']['checked']))
1739  {
1740  print '<td class="right">';
1741  $valuebilled = price2num($task_time->total_ht, '', 1);
1742  if (isset($task_time->total_ht)) print price($valuebilled, 1, $langs, 1, -1, -1, $conf->currency);
1743  print '</td>';
1744  }
1745 
1746  /*
1747  // Extra fields
1748  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1749  */
1750 
1751  // Fields from hook
1752  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$task_time);
1753  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1754  print $hookmanager->resPrint;
1755 
1756  // Action column
1757  print '<td class="center nowraponall">';
1758  print '</td>';
1759 
1760  print "</tr>\n";
1761  }
1762 
1763  $i++;
1764  }
1765 
1766  // Show total line
1767  //include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1768  if (isset($totalarray['totaldurationfield']) || isset($totalarray['totalvaluefield']))
1769  {
1770  print '<tr class="liste_total">';
1771  $i = 0;
1772  while ($i < $totalarray['nbfield'])
1773  {
1774  $i++;
1775  if ($i == 1)
1776  {
1777  if ($num < $limit && empty($offset)) print '<td class="left">'.$langs->trans("Total").'</td>';
1778  else print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
1779  } elseif ($totalarray['totaldurationfield'] == $i) print '<td class="right">'.convertSecondToTime($totalarray['totalduration'], 'allhourmin').'</td>';
1780  elseif ($totalarray['totalvaluefield'] == $i) print '<td class="right">'.price($totalarray['totalvalue']).'</td>';
1781  //elseif ($totalarray['totalvaluebilledfield'] == $i) print '<td class="center">'.price($totalarray['totalvaluebilled']).'</td>';
1782  else print '<td></td>';
1783  }
1784  print '</tr>';
1785  }
1786 
1787  if (!count($tasks))
1788  {
1789  $totalnboffields = 1;
1790  foreach ($arrayfields as $value)
1791  {
1792  if ($value['checked']) $totalnboffields++;
1793  }
1794  print '<tr class="oddeven"><td colspan="'.$totalnboffields.'">';
1795  print '<span class="opacitymedium">'.$langs->trans("None").'</span>';
1796  print '</td></tr>';
1797  }
1798 
1799 
1800  print "</table>";
1801  print '</div>';
1802  print "</form>";
1803  }
1804 }
1805 
1806 // End of page
1807 llxFooter();
1808 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dolGetButtonTitle($label, $helpText= '', $iconClass= 'fa fa-file', $url= '', $id= '', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
Class to manage products or services.
Class to manage Dolibarr users.
Definition: user.class.php:44
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
img_error($titlealt= 'default')
Show error logo.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
get_default_localtax($thirdparty_seller, $thirdparty_buyer, $local, $idprod=0)
Function that return localtax of a product line (according to seller, buyer and product vat rate) Si ...
Class to manage projects.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Class to manage building of HTML components.
Classe permettant la generation de composants html autre Only common components are here...
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:44
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0)
Generate a SQL string to make a filter into a range (for second of date until last second of date) ...
Definition: date.lib.php:281
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_sort_array(&$array, $index, $order= 'asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
project_prepare_head(Project $project)
Prepare array with list of tabs.
Definition: project.lib.php:36
print
Draft customers invoices.
Definition: index.php:89
Class to manage tasks.
Definition: task.class.php:35
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) Si ...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage invoices.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
img_split($titlealt= 'default', $other= 'class="pictosplit"')
Show split logo.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105
convertSecondToTime($iSecond, $format= 'all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
Definition: date.lib.php:180
task_prepare_head($object)
Prepare array with list of tabs.