dolibarr 23.0.4
time.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2006-2023 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-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2019-2021 Christophe Battarel <christophe@altairis.fr>
9 * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
10 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2024 Vincent de Grandpré <vincent@de-grandpre.quebec>
12 * Copyright (C) 2024 Solution Libre SAS <contact@solution-libre.fr>
13 * Copyright (C) 2026 Joachim Kueter <git-jk@bloxera.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 */
28
35// Load Dolibarr environment
36require '../../main.inc.php';
45'
46@phan-var-force ?string $uploaddir
47';
48require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
49require_once DOL_DOCUMENT_ROOT . '/projet/class/task.class.php';
50require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
51require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
52require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
53require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
54require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
55require_once DOL_DOCUMENT_ROOT . '/core/class/html.formintervention.class.php';
56require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
57
58// Load translation files required by the page
59$langsLoad = array('projects', 'bills', 'orders', 'companies');
60if (isModEnabled('eventorganization')) {
61 $langsLoad[] = 'eventorganization';
62}
63
64$langs->loadLangs($langsLoad);
65
66$action = GETPOST('action', 'aZ09');
67$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
68$confirm = GETPOST('confirm', 'alpha');
69$cancel = GETPOST('cancel', 'alpha');
70$toselect = GETPOST('toselect', 'array:int'); // Array of ids of elements selected into a list
71$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'timespentlist'; // To manage different context of search
72$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
73$optioncss = GETPOST('optioncss', 'alpha');
74$mode = GETPOST('mode', 'alpha');
75
76$id = GETPOSTINT('id'); // Id of task
77$ref = GETPOST('ref', 'alpha'); // Ref of task
78$projectid = GETPOSTINT('projectid'); // Id of project
79$lineid = GETPOSTINT('lineid'); // Id of time spent line
80$withproject = GETPOSTINT('withproject');
81$project_ref = GETPOST('project_ref', 'alpha');
82$tab = GETPOST('tab', 'aZ09');
83
84$search_day = GETPOSTINT('search_day');
85$search_month = GETPOSTINT('search_month');
86$search_year = GETPOSTINT('search_year');
87$search_date_startday = GETPOSTINT('search_date_startday');
88$search_date_startmonth = GETPOSTINT('search_date_startmonth');
89$search_date_startyear = GETPOSTINT('search_date_startyear');
90$search_date_endday = GETPOSTINT('search_date_endday');
91$search_date_endmonth = GETPOSTINT('search_date_endmonth');
92$search_date_endyear = GETPOSTINT('search_date_endyear');
93$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
94$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
95$search_note = GETPOST('search_note', 'alpha');
96$search_duration = GETPOST('search_duration', 'alpha');
97$search_task_ref = GETPOST('search_task_ref', 'alpha');
98$search_task_label = GETPOST('search_task_label', 'alpha');
99$search_user = GETPOST('search_user', 'intcomma');
100$search_valuebilled = GETPOST('search_valuebilled', 'intcomma');
101$search_product_ref = GETPOST('search_product_ref', 'alpha');
102$search_company = GETPOST('$search_company', 'alpha');
103$search_company_alias = GETPOST('$search_company_alias', 'alpha');
104$search_project_ref = GETPOST('$search_project_ref', 'alpha');
105$search_project_label = GETPOST('$search_project_label', 'alpha');
106$search_timespent_starthour = GETPOSTINT("search_timespent_duration_starthour");
107$search_timespent_startmin = GETPOSTINT("search_timespent_duration_startmin");
108$search_timespent_endhour = GETPOSTINT("search_timespent_duration_endhour");
109$search_timespent_endmin = GETPOSTINT("search_timespent_duration_endmin");
110
111$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
112$sortfield = GETPOST('sortfield', 'aZ09comma');
113$sortorder = GETPOST('sortorder', 'aZ09comma');
114$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
115if (empty($page) || $page == -1) {
116 $page = 0;
117} // If $page is not defined, or '' or -1
118$offset = $limit * $page;
119$pageprev = $page - 1;
120$pagenext = $page + 1;
121if (!$sortfield) {
122 $sortfield = 't.element_date,t.element_datehour,t.rowid';
123}
124if (!$sortorder) {
125 $sortorder = 'DESC,DESC,DESC';
126}
127
128$childids = $user->getAllChildIds(1);
129
130// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
131//$object = new TaskTime($db);
132$hookmanager->initHooks(array('projecttasktime', 'globalcard'));
133
134$object = new Task($db);
135$extrafields = new ExtraFields($db);
136$projectstatic = new Project($db);
137
138// fetch optionals attributes and labels
139$extrafields->fetch_name_optionals_label($projectstatic->table_element);
140$extrafields->fetch_name_optionals_label($object->table_element);
141
142$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
143
144// Load task
145if ($id > 0 || $ref) {
146 $object->fetch($id, $ref);
147 $id = $object->id; // So when doing a search from ref, id is also set correctly.
148}
149
150
151// Security check
152$socid = 0;
153//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 assignment.
154if (!$user->hasRight('projet', 'lire')) {
156}
157
158if ($object->fk_project > 0) {
159 restrictedArea($user, 'projet', $object->fk_project, 'projet&project');
160} else {
161 restrictedArea($user, 'projet', 0, 'projet&project');
162 // We check user has permission to see all tasks of all users
163 if (empty($projectid) && !$user->hasRight('projet', 'all', 'lire')) {
164 $search_user = $user->id;
165 }
166}
167
168
169/*
170 * Actions
171 */
172
173$error = 0;
174
175if (GETPOST('cancel', 'alpha')) {
176 $action = '';
177}
178if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_generateinvoice' && $massaction != 'confirm_generateinter') {
179 $massaction = '';
180}
181
182$parameters = array('socid' => $socid, 'projectid' => $projectid);
183$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
184if ($reshook < 0) {
185 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
186}
187
188include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php';
189
190// Purge search criteria
191if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
192 $search_day = '';
193 $search_month = '';
194 $search_year = '';
195 $search_note = '';
196 $search_duration = '';
197 $search_date_startday = '';
198 $search_date_startmonth = '';
199 $search_date_startyear = '';
200 $search_date_endday = '';
201 $search_date_endmonth = '';
202 $search_date_endyear = '';
203 $search_date_start = '';
204 $search_date_end = '';
205 $search_task_ref = '';
206 $search_company = '';
207 $search_company_alias = '';
208 $search_project_ref = '';
209 $search_project_label = '';
210 $search_task_label = '';
211 $search_user = -1;
212 $search_valuebilled = '';
213 $search_product_ref = '';
214 $toselect = array();
215 $search_array_options = array();
216 $search_timespent_starthour = '';
217 $search_timespent_startmin = '';
218 $search_timespent_endhour = '';
219 $search_timespent_endmin = '';
220 $action = '';
221}
222
223if ($action == 'addtimespent' && $user->hasRight('projet', 'time')) {
224 $timespent_durationhour = GETPOSTINT('timespent_durationhour');
225 $timespent_durationmin = GETPOSTINT('timespent_durationmin');
226 if (empty($timespent_durationhour) && empty($timespent_durationmin)) {
227 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Duration")), null, 'errors');
228 $error++;
229 }
230 if (!GETPOSTINT("userid")) {
231 $langs->load("errors");
232 setEventMessages($langs->trans('ErrorUserNotAssignedToTask'), null, 'errors');
233 $error++;
234 }
235
236 if (!$error) {
237 if ($id || $ref) {
238 $object->fetch($id, $ref);
239 } else {
240 if (!GETPOSTINT('taskid') || GETPOSTINT('taskid') < 0) {
241 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Task")), null, 'errors');
242 $action = 'createtime';
243 $error++;
244 } else {
245 $object->fetch(GETPOSTINT('taskid'));
246 }
247 }
248
249 if (!$error) {
250 $object->fetchProject();
251
252 if (empty($object->project->status)) {
253 setEventMessages($langs->trans("ProjectMustBeValidatedFirst"), null, 'errors');
254 $action = 'createtime';
255 $error++;
256 } else {
257 $object->timespent_note = GETPOST("timespent_note", 'alpha');
258 if (GETPOSTINT('progress') > 0) {
259 $object->progress = GETPOSTINT('progress'); // If progress is -1 (not defined), we do not change value
260 }
261 $object->timespent_duration = GETPOSTINT("timespent_durationhour") * 60 * 60; // We store duration in seconds
262 $object->timespent_duration += (GETPOSTINT('timespent_durationmin') ? GETPOSTINT('timespent_durationmin') : 0) * 60; // We store duration in seconds
263 if (GETPOST("timehour") != '' && GETPOST("timehour") >= 0) { // If hour was entered
264 $object->timespent_date = dol_mktime(GETPOSTINT("timehour"), GETPOSTINT("timemin"), 0, GETPOSTINT("timemonth"), GETPOSTINT("timeday"), GETPOSTINT("timeyear"));
265 $object->timespent_withhour = 1;
266 } else {
267 $object->timespent_date = dol_mktime(12, 0, 0, GETPOSTINT("timemonth"), GETPOSTINT("timeday"), GETPOSTINT("timeyear"));
268 $object->timespent_withhour = 0;
269 }
270 $object->timespent_fk_user = GETPOSTINT("userid");
271 $object->timespent_fk_product = GETPOSTINT("fk_product");
272
273 $result = $object->addTimeSpent($user);
274
275 if ($result >= 0) {
276 setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
277 } else {
278 setEventMessages($langs->trans($object->error), null, 'errors');
279 $error++;
280 }
281 }
282 }
283 } else {
284 $action = 'createtime';
285 }
286}
287
288if (($action == 'updateline' || $action == 'updatesplitline') && !$cancel && $user->hasRight('projet', 'lire')) {
289 if (!GETPOST("new_durationhour") && !GETPOST("new_durationmin")) {
290 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Duration")), null, 'errors');
291 $error++;
292 }
293
294 //If timespent date is not provided in POST (for eg, because in list the column date is hidden) we keep the actual date
295 $timespent_date = dol_mktime(12, 0, 0, GETPOSTINT("timelinemonth"), GETPOSTINT("timelineday"), GETPOSTINT("timelineyear"));
296
297 if (!$error) {
298 if ($id && GETPOSTINT('taskid') != $id) { // GETPOSTINT('taskid') is the id of new task
299 $id_temp = GETPOSTINT('taskid'); // should not overwrite $id
300
301 $object->fetchTimeSpent($lineid);
302 $timespentoldowner = $object->timespent_fk_user; // Owner of the line, before the value of the form is set
303
304 $result = 0;
305
306 $object->fetch($id_temp, $ref);
307
308 $object->timespent_note = GETPOST("timespent_note_line", "alphanohtml");
309 $object->timespent_old_duration = GETPOSTINT("old_duration");
310 $object->timespent_duration = GETPOSTINT("new_durationhour") * 60 * 60; // We store duration in seconds
311 $object->timespent_duration += (GETPOSTINT("new_durationmin") ? GETPOSTINT('new_durationmin') : 0) * 60; // We store duration in seconds
312 if (GETPOST("timelinehour") != '' && GETPOST("timelinehour") >= 0 && !empty($timespent_date)) { // If hour was entered
313 $object->timespent_date = dol_mktime(GETPOSTINT("timelinehour"), GETPOSTINT("timelinemin"), 0, GETPOSTINT("timelinemonth"), GETPOSTINT("timelineday"), GETPOSTINT("timelineyear"));
314 $object->timespent_withhour = 1;
315 } elseif (!empty($timespent_date)) {
316 $object->timespent_date = $timespent_date;
317 $object->timespent_withhour = 0;
318 }
319 // If column "by" is hidden, no userid_line is posted; keep the existing fk_user instead of resetting it to 0.
320 if (GETPOSTISSET("userid_line")) {
321 $object->timespent_fk_user = GETPOSTINT("userid_line");
322 }
323 $object->timespent_fk_product = GETPOSTINT("fk_product");
324 $object->timespent_invoiceid = GETPOSTINT("invoiceid");
325 $object->timespent_invoicelineid = GETPOSTINT("invoicelineid");
326
327 $result = 0;
328 if ((in_array($timespentoldowner, $childids) || $user->hasRight('projet', 'all', 'creer')) && (in_array($object->timespent_fk_user, $childids) || $user->hasRight('projet', 'all', 'creer'))) {
329 $result = $object->updateTimeSpent($user);
330 if ($result >= 0) {
331 setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
332 } else {
333 setEventMessages($langs->trans($object->error), null, 'errors');
334 $error++;
335 }
336 }
337 } else {
338 $object->fetch($id, $ref); // $object is Task
339
340 $object->fetchTimeSpent(GETPOSTINT('lineid'));
341 $timespentoldowner = $object->timespent_fk_user; // Owner of the line, before the value of the form is set
342
343 $object->timespent_note = GETPOST("timespent_note_line", "alphanohtml");
344 $object->timespent_old_duration = GETPOSTINT("old_duration");
345 $object->timespent_duration = GETPOSTINT("new_durationhour") * 60 * 60; // We store duration in seconds
346 $object->timespent_duration += (GETPOSTINT("new_durationmin") ? GETPOSTINT('new_durationmin') : 0) * 60; // We store duration in seconds
347
348 if (GETPOST("timelinehour") != '' && GETPOST("timelinehour") >= 0) { // If hour was entered
349 $object->timespent_date = dol_mktime(12, 0, 0, GETPOSTINT("timelinemonth"), GETPOSTINT("timelineday"), GETPOSTINT("timelineyear"));
350 $object->timespent_datehour = dol_mktime(GETPOSTINT("timelinehour"), GETPOSTINT("timelinemin"), 0, GETPOSTINT("timelinemonth"), GETPOSTINT("timelineday"), GETPOSTINT("timelineyear"));
351 $object->timespent_withhour = 1;
352 } elseif (!empty($timespent_date)) {
353 $object->timespent_date = $timespent_date;
354 $object->timespent_datehour = $timespent_date;
355 $object->timespent_withhour = 0;
356 }
357
358 // If column "by" is hidden, no userid_line is posted; keep the existing fk_user instead of resetting it to 0.
359 if (GETPOSTISSET("userid_line")) {
360 $object->timespent_fk_user = GETPOSTINT("userid_line");
361 }
362 $object->timespent_fk_product = GETPOSTINT("fk_product");
363 $object->timespent_invoiceid = GETPOSTINT("invoiceid");
364 $object->timespent_invoicelineid = GETPOSTINT("invoicelineid");
365
366 $result = 0;
367
368 if ((in_array($timespentoldowner, $childids) || $user->hasRight('projet', 'all', 'creer')) && (in_array($object->timespent_fk_user, $childids) || $user->hasRight('projet', 'all', 'creer'))) {
369 $result = $object->updateTimeSpent($user);
370
371 if ($result >= 0) {
372 setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
373 } else {
374 setEventMessages($langs->trans($object->error), null, 'errors');
375 $error++;
376 }
377 }
378 }
379 } else {
380 $action = '';
381 }
382}
383
384if ($action == 'confirm_deleteline' && $confirm == "yes" && ($user->hasRight('projet', 'time') || $user->hasRight('projet', 'all', 'creer'))) {
385 $object->fetchTimeSpent(GETPOSTINT('lineid')); // load properties like $object->timespent_xxx
386
387 if (in_array($object->timespent_fk_user, $childids) || $user->hasRight('projet', 'all', 'creer')) {
388 $result = $object->delTimeSpent($user); // delete line with $object->timespent_id
389
390 if ($result < 0) {
391 $langs->load("errors");
392 setEventMessages($langs->trans($object->error), null, 'errors');
393 $error++;
394 $action = '';
395 } else {
396 setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
397 }
398 }
399}
400
401// Retrieve First Task ID of Project if withproject is on to allow project prev next to work
402if (!empty($project_ref) && !empty($withproject)) {
403 if ($projectstatic->fetch(0, $project_ref) > 0) {
404 $tasksarray = $object->getTasksArray(null, null, $projectstatic->id, $socid, 0);
405 if (count($tasksarray) > 0) {
406 $id = $tasksarray[0]->id;
407 } else {
408 header("Location: " . DOL_URL_ROOT . '/projet/tasks.php?id=' . $projectstatic->id . ($withproject ? '&withproject=1' : '') . (empty($mode) ? '' : '&mode=' . $mode));
409 exit;
410 }
411 }
412}
413
414// To show all time lines for project
415$projectidforalltimes = 0;
416if (GETPOSTINT('projectid') > 0) {
417 $projectidforalltimes = GETPOSTINT('projectid');
418
419 $result = $projectstatic->fetch($projectidforalltimes);
420 if (!empty($projectstatic->socid)) {
421 $projectstatic->fetch_thirdparty();
422 }
423 $res = $projectstatic->fetch_optionals();
424
425 // Quick edit for project extrafields (pencil shown on the project summary of this page)
426 if ($action == 'update_extras' && $projectstatic->id > 0) { // Test on permission already done
427 $permissiontoeditextra = $user->hasRight('projet', 'creer');
428 if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$projectstatic->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
429 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$projectstatic->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
430 }
431
432 if ($permissiontoeditextra) {
433 $projectstatic->oldcopy = dol_clone($projectstatic, 2);
434
435 $attribute_name = GETPOST('attribute', 'aZ09');
436
437 // Fill array 'array_options' with data from update form
438 $ret = $extrafields->setOptionalsFromPost(null, $projectstatic, $attribute_name);
439 if ($ret < 0) {
440 $error++;
441 }
442
443 if (!$error) {
444 $result = $projectstatic->updateExtraField($attribute_name, 'PROJECT_MODIFY');
445 if ($result < 0) {
446 setEventMessages($projectstatic->error, $projectstatic->errors, 'errors');
447 $error++;
448 }
449 }
450 }
451
452 if ($error) {
453 $action = 'edit_extras';
454 }
455 }
456} elseif (GETPOST('project_ref', 'alpha')) {
457 $projectstatic->fetch(0, GETPOST('project_ref', 'alpha'));
458 $projectidforalltimes = $projectstatic->id;
459 $withproject = 1;
460} elseif ($id > 0) {
461 $object->fetch($id);
462 $result = $projectstatic->fetch($object->fk_project);
463}
464// If not task selected and no project selected
465$allprojectforuser = 0;
466
467if ($id <= 0 && $projectidforalltimes == 0) {
468 $allprojectforuser = $user->id;
469}
470
471if ($action == 'confirm_generateinvoice' && $user->hasRight('facture', 'creer')) {
472 if (!empty($projectstatic->socid)) {
473 $projectstatic->fetch_thirdparty();
474 }
475
476 if (!($projectstatic->thirdparty->id > 0)) {
477 setEventMessages($langs->trans("ThirdPartyRequiredToGenerateInvoice"), null, 'errors');
478 } else {
479 include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
480 include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
481 include_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
482
483 $tmpinvoice = new Facture($db);
484 $tmptimespent = new Task($db);
485 $tmpproduct = new Product($db);
486 $fuser = new User($db);
487 $remiseproject = price2num(GETPOST('remiseprojet', 'alphanohtml'));
488 $condidproject = GETPOSTINT('condidproject');
489
490 $db->begin();
491
492 $idprod = GETPOSTINT('productid');
493 $generateinvoicemode = GETPOST('generateinvoicemode', 'alphanohtml');
494 $invoiceToUse = GETPOSTINT('invoiceid');
495
496 $prodDurationHoursBase = 1.0;
497 $product_data_cache = array();
498 if ($idprod > 0) {
499 $tmpproduct->fetch($idprod);
500 if ($result < 0) {
501 $error++;
502 setEventMessages($tmpproduct->error, $tmpproduct->errors, 'errors');
503 }
504
505 $prodDurationHoursBase = $tmpproduct->getProductDurationHours();
506 if ($prodDurationHoursBase < 0) {
507 $error++;
508 $langs->load("errors");
509 setEventMessages(null, $tmpproduct->errors, 'errors');
510 }
511
512 $dataforprice = $tmpproduct->getSellPrice($mysoc, $projectstatic->thirdparty, 0);
513
514 $pu_ht = empty($dataforprice['pu_ht']) ? 0 : $dataforprice['pu_ht'];
515 $txtva = $dataforprice['tva_tx'];
516 $localtax1 = get_localtax($txtva, 1, $projectstatic->thirdparty);
517 $localtax2 = get_localtax($txtva, 2, $projectstatic->thirdparty);
518 } else {
519 $prodDurationHoursBase = 1;
520
521 $pu_ht = 0;
522 $txtva = get_default_tva($mysoc, $projectstatic->thirdparty);
523 $localtax1 = get_default_localtax($mysoc, $projectstatic->thirdparty, 1);
524 $localtax2 = get_default_localtax($mysoc, $projectstatic->thirdparty, 2);
525 }
526
527 $tmpinvoice->socid = $projectstatic->thirdparty->id;
528 $tmpinvoice->date = dol_mktime(GETPOSTINT('rehour'), GETPOSTINT('remin'), GETPOSTINT('resec'), GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
529 $tmpinvoice->fk_project = $projectstatic->id;
530 $tmpinvoice->cond_reglement_id = $condidproject;
531 $tmpinvoice->mode_reglement_id = $projectstatic->thirdparty->mode_reglement_id;
532 $tmpinvoice->fk_account = $projectstatic->thirdparty->fk_account;
533
534 if ($invoiceToUse) {
535 $tmpinvoice->fetch($invoiceToUse);
536 } else {
537 $result = $tmpinvoice->create($user);
538 if ($result <= 0) {
539 $error++;
540 setEventMessages($tmpinvoice->error, $tmpinvoice->errors, 'errors');
541 }
542 }
543
544 if (!$error) {
545 if ($generateinvoicemode == 'onelineperuser') { // 1 line per user (and per product)
546 $arrayoftasks = array();
547 foreach ($toselect as $key => $value) {
548 // Get userid, timepent
549 $object->fetchTimeSpent($value); // $value is ID of 1 line in timespent table
550 $arrayoftasks[$object->timespent_fk_user][(int) $object->timespent_fk_product]['timespent'] += $object->timespent_duration;
551 $arrayoftasks[$object->timespent_fk_user][(int) $object->timespent_fk_product]['totalvaluetodivideby3600'] += ($object->timespent_duration * $object->timespent_thm);
552 }
553
554 foreach ($arrayoftasks as $userid => $data) { // @phan-suppress-current-line PhanEmptyForeach
555 $fuser->fetch($userid);
556 $username = $fuser->getFullName($langs);
557
558 foreach ($data as $fk_product => $timespent_data) {
559 // Define qty per hour
560 $qtyhour = $timespent_data['timespent'] / 3600;
561 $qtyhourtext = convertSecondToTime($timespent_data['timespent'], 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
562
563 // Set the unit price we want to sell the time, for this user
564 if (getDolGlobalInt('PROJECT_USE_REAL_COST_FOR_TIME_INVOICING')) {
565 // We set unit price to 0 to force the use of the rate saved during recording
566 $pu_ht = 0;
567 } elseif ($idprod <= 0) {
568 // We want to sell all the time spent with the last hourly rate of user
569 // -> but what about choice user selected ? add idprod test
570 $pu_ht = $fuser->thm;
571 }
572
573 // If no unit price known for user, we use the price recorded when recording timespent.
574 if (empty($pu_ht)) {
575 if ($timespent_data['timespent']) {
576 $pu_ht = price2num(($timespent_data['totalvaluetodivideby3600'] / $timespent_data['timespent']), 'MU');
577 }
578 }
579
580 // Add lines
581 $prodDurationHours = $prodDurationHoursBase;
582 $idprodline = $idprod;
583 $pu_htline = $pu_ht;
584 $txtvaline = $txtva;
585 $localtax1line = $localtax1;
586 $localtax2line = $localtax2;
587
588 // If a particular product/service was defined for the task
589 if (!empty($fk_product) && ($fk_product > 0) && ($fk_product !== $idprod)) {
590 if (!array_key_exists($fk_product, $product_data_cache)) {
591 $result = $tmpproduct->fetch($fk_product);
592 if ($result < 0) {
593 $error++;
594 setEventMessages($tmpproduct->error, $tmpproduct->errors, 'errors');
595 }
596 $prodDurationHours = $tmpproduct->getProductDurationHours();
597 if ($prodDurationHours < 0) {
598 $error++;
599 $langs->load("errors");
600 setEventMessages(null, $tmpproduct->errors, 'errors');
601 // Skip this entry: without it the loop reaches addline() and divides by the duration (#40805).
602 continue;
603 }
604
605 $dataforprice = $tmpproduct->getSellPrice($mysoc, $projectstatic->thirdparty, 0);
606
607 $pu_htline = empty($dataforprice['pu_ht']) ? 0 : $dataforprice['pu_ht'];
608 $txtvaline = $dataforprice['tva_tx'];
609 $localtax1line = $dataforprice['localtax1'];
610 $localtax2line = $dataforprice['localtax2'];
611
612 $product_data_cache[$fk_product] = array('duration' => $prodDurationHours, 'dataforprice' => $dataforprice);
613 } else {
614 $prodDurationHours = $product_data_cache[$fk_product]['duration'];
615 $pu_htline = empty($product_data_cache[$fk_product]['dataforprice']['pu_ht']) ? 0 : $product_data_cache[$fk_product]['dataforprice']['pu_ht'];
616 $txtvaline = $product_data_cache[$fk_product]['dataforprice']['tva_tx'];
617 $localtax1line = $product_data_cache[$fk_product]['dataforprice']['localtax1'];
618 $localtax2line = $product_data_cache[$fk_product]['dataforprice']['localtax2'];
619 }
620 $idprodline = $fk_product;
621 }
622
623 // Add lines. Pass type=1 (service) explicitly so the invoice line is tagged
624 // as a service even when no product is bound to the time entry. Otherwise
625 // the default $type=0 leaks through and the PDF labels the operation as
626 // "Delivery of goods" instead of "Provision of services" (issue #34571).
627 $lineid = $tmpinvoice->addline($langs->trans("TimeSpentForInvoice").' - '.$username . ' : ' . $qtyhourtext, $pu_htline, round($qtyhour / $prodDurationHours, 2), $txtvaline, $localtax1line, $localtax2line, ($idprodline > 0 ? $idprodline : 0), (float) $remiseproject, '', '', 0, 0, 0, 'HT', 0, Product::TYPE_SERVICE);
628 if ($lineid < 0) {
629 $error++;
630 setEventMessages(null, $tmpinvoice->errors, 'errors');
631 }
632
633 // Update lineid into line of timespent
634 $sql = 'UPDATE '.MAIN_DB_PREFIX.'element_time SET invoice_line_id = '.((int) $lineid).', invoice_id = '.((int) $tmpinvoice->id);
635 $sql .= ' WHERE rowid IN ('.$db->sanitize(implode(',', $toselect)).') AND fk_user = '.((int) $userid);
636 $result = $db->query($sql);
637 if (!$result) {
638 $error++;
639 setEventMessages($db->lasterror(), null, 'errors');
640 break;
641 }
642 }
643 }
644 } elseif ($generateinvoicemode == 'onelineperperiod') { // One line for each time spent line
645 $arrayoftasks = array();
646
647 $withdetail = GETPOST('detail_time_duration', 'alpha');
648 foreach ($toselect as $key => $value) {
649 // Get userid, timepent
650 $object->fetchTimeSpent($value);
651 // $object->id is the task id
652 $ftask = new Task($db);
653 $ftask->fetch($object->id);
654
655 $fuser->fetch($object->timespent_fk_user);
656 $username = $fuser->getFullName($langs);
657
658 $arrayoftasks[$object->timespent_id]['timespent'] = $object->timespent_duration;
659 $arrayoftasks[$object->timespent_id]['totalvaluetodivideby3600'] = $object->timespent_duration * $object->timespent_thm;
660 $arrayoftasks[$object->timespent_id]['note'] = $ftask->ref . ' - ' . $ftask->label . ' - ' . $username;
661 $arrayoftasks[$object->timespent_id]['note'] = dol_concatdesc($arrayoftasks[$object->timespent_id]['note'], $object->timespent_note);
662
663 if (!empty($withdetail)) {
664 if (!empty($object->timespent_withhour)) {
665 $arrayoftasks[$object->timespent_id]['note'] = dol_concatdesc($arrayoftasks[$object->timespent_id]['note'], $langs->trans("Date") . ': ' . dol_print_date($object->timespent_datehour));
666 } else {
667 $arrayoftasks[$object->timespent_id]['note'] = dol_concatdesc($arrayoftasks[$object->timespent_id]['note'], $langs->trans("Date") . ': ' . dol_print_date($object->timespent_date));
668 }
669 $arrayoftasks[$object->timespent_id]['note'] = dol_concatdesc($arrayoftasks[$object->timespent_id]['note'], $langs->trans("Duration") . ': ' . convertSecondToTime($object->timespent_duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY));
670 }
671 $arrayoftasks[$object->timespent_id]['user'] = $object->timespent_fk_user;
672 $arrayoftasks[$object->timespent_id]['fk_product'] = $object->timespent_fk_product;
673 }
674
675 $pu_ht_saved = $pu_ht; // Save the base unit price (price of the selected product/service if any, 0 otherwise)
676 foreach ($arrayoftasks as $timespent_id => $value) {
677 $pu_ht = $pu_ht_saved; // Reset for each line, so a line does not inherit the unit price computed for the previous one
678 $userid = $value['user'];
679 //$pu_ht = $value['timespent'] * $fuser->thm;
680
681 // Define qty per hour
682 $qtyhour = $value['timespent'] / 3600;
683
684 // If no unit price known
685 if (empty($pu_ht)) {
686 if ($value['timespent']) {
687 $pu_ht = price2num(($value['totalvaluetodivideby3600'] / $value['timespent']), 'MU');
688 }
689 }
690
691 // Add lines
692 $prodDurationHours = $prodDurationHoursBase;
693 $idprodline = $idprod;
694 $pu_htline = $pu_ht;
695 $txtvaline = $txtva;
696 $localtax1line = $localtax1;
697 $localtax2line = $localtax2;
698
699 if (!empty($value['fk_product']) && $value['fk_product'] !== $idprod) {
700 if (!array_key_exists($value['fk_product'], $product_data_cache)) {
701 $result = $tmpproduct->fetch($value['fk_product']);
702 if ($result < 0) {
703 $error++;
704 setEventMessages($tmpproduct->error, $tmpproduct->errors, 'errors');
705 }
706 $prodDurationHours = $tmpproduct->getProductDurationHours();
707 if ($prodDurationHours < 0) {
708 $error++;
709 $langs->load("errors");
710 setEventMessages(null, $tmpproduct->errors, 'errors');
711 // Skip this entry: without it the loop reaches addline() and divides by the duration (#40805).
712 continue;
713 }
714
715 $dataforprice = $tmpproduct->getSellPrice($mysoc, $projectstatic->thirdparty, 0);
716
717 $pu_htline = empty($dataforprice['pu_ht']) ? 0 : $dataforprice['pu_ht'];
718 $txtvaline = $dataforprice['tva_tx'];
719 $localtax1line = $dataforprice['localtax1'];
720 $localtax2line = $dataforprice['localtax2'];
721
722 $product_data_cache[$value['fk_product']] = array('duration' => $prodDurationHours, 'dataforprice' => $dataforprice);
723 } else {
724 $prodDurationHours = $product_data_cache[$value['fk_product']]['duration'];
725 $pu_htline = empty($product_data_cache[$value['fk_product']]['dataforprice']['pu_ht']) ? 0 : $product_data_cache[$value['fk_product']]['dataforprice']['pu_ht'];
726 $txtvaline = $product_data_cache[$value['fk_product']]['dataforprice']['tva_tx'];
727 $localtax1line = $product_data_cache[$value['fk_product']]['dataforprice']['localtax1'];
728 $localtax2line = $product_data_cache[$value['fk_product']]['dataforprice']['localtax2'];
729 }
730 $idprodline = $value['fk_product'];
731 }
732 // Pass type=1 (service) explicitly so the invoice line is tagged as a service
733 // even when no product is bound to the time entry. Otherwise the default
734 // $type=0 leaks through and the PDF labels the operation as
735 // "Delivery of goods" instead of "Provision of services" (issue #34571).
736 $lineid = $tmpinvoice->addline($value['note'], $pu_htline, round($qtyhour / $prodDurationHours, 2), $txtvaline, $localtax1line, $localtax2line, ($idprodline > 0 ? $idprodline : 0), (float) $remiseproject, '', '', 0, 0, 0, 'HT', 0, Product::TYPE_SERVICE);
737 if ($lineid < 0) {
738 $error++;
739 setEventMessages(null, $tmpinvoice->errors, 'errors');
740 }
741 //var_dump($lineid);exit;
742
743 // Update lineid into line of timespent
744 $sql = 'UPDATE '.MAIN_DB_PREFIX.'element_time SET invoice_line_id = '.((int) $lineid).', invoice_id = '.((int) $tmpinvoice->id);
745 $sql .= ' WHERE rowid = '.((int) $timespent_id).' AND fk_user = '.((int) $userid);
746 $result = $db->query($sql);
747 if (!$result) {
748 $error++;
749 setEventMessages($db->lasterror(), null, 'errors');
750 break;
751 }
752 }
753 } elseif ($generateinvoicemode == 'onelinepertask') { // One line for each different task
754 $arrayoftasks = array();
755 foreach ($toselect as $key => $value) {
756 // Get userid, timepent
757 $object->fetchTimeSpent($value); // Call method to get list of timespent for a timespent line id (We use the utility method found into Task object)
758 // $object->id is now the task id
759 $arrayoftasks[$object->id][(int) $object->timespent_fk_product]['timespent'] += $object->timespent_duration;
760 $arrayoftasks[$object->id][(int) $object->timespent_fk_product]['totalvaluetodivideby3600'] += ($object->timespent_duration * $object->timespent_thm);
761 }
762
763 foreach ($arrayoftasks as $task_id => $data) { // @phan-suppress-current-line PhanEmptyForeach
764 $ftask = new Task($db);
765 $ftask->fetch($task_id);
766
767 foreach ($data as $fk_product => $timespent_data) {
768 $qtyhour = $timespent_data['timespent'] / 3600;
769 $qtyhourtext = convertSecondToTime($timespent_data['timespent'], 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
770
771 // Add lines
772 $prodDurationHours = $prodDurationHoursBase;
773 $idprodline = $idprod;
774 $pu_htline = $pu_ht;
775 $txtvaline = $txtva;
776 $localtax1line = $localtax1;
777 $localtax2line = $localtax2;
778
779 if (!empty($fk_product) && $fk_product !== $idprod) {
780 if (!array_key_exists($fk_product, $product_data_cache)) {
781 $result = $tmpproduct->fetch($fk_product);
782 if ($result < 0) {
783 $error++;
784 setEventMessages($tmpproduct->error, $tmpproduct->errors, 'errors');
785 }
786 $prodDurationHours = $tmpproduct->getProductDurationHours();
787 if ($prodDurationHours < 0) {
788 $error++;
789 $langs->load("errors");
790 setEventMessages(null, $tmpproduct->errors, 'errors');
791 // Skip this entry: without it the loop reaches addline() and divides by the duration (#40805).
792 continue;
793 }
794
795 $dataforprice = $tmpproduct->getSellPrice($mysoc, $projectstatic->thirdparty, 0);
796
797 $pu_htline = empty($dataforprice['pu_ht']) ? 0 : $dataforprice['pu_ht'];
798 $txtvaline = $dataforprice['tva_tx'];
799 $localtax1line = $dataforprice['localtax1'];
800 $localtax2line = $dataforprice['localtax2'];
801
802 $product_data_cache[$fk_product] = array('duration' => $prodDurationHours, 'dataforprice' => $dataforprice);
803 } else {
804 $prodDurationHours = $product_data_cache[$fk_product]['duration'];
805 $pu_htline = empty($product_data_cache[$fk_product]['dataforprice']['pu_ht']) ? 0 : $product_data_cache[$fk_product]['dataforprice']['pu_ht'];
806 $txtvaline = $product_data_cache[$fk_product]['dataforprice']['tva_tx'];
807 $localtax1line = $product_data_cache[$fk_product]['dataforprice']['localtax1'];
808 $localtax2line = $product_data_cache[$fk_product]['dataforprice']['localtax2'];
809 }
810 $idprodline = $fk_product;
811 }
812
813
814 if ($idprodline > 0) {
815 // If a product is defined, we msut use the $prodDurationHours and $pu_ht of product (already set previously).
816 $pu_ht_for_task = $pu_htline;
817 // If we want to reuse the value of timespent (so use same price than cost price)
818 if (getDolGlobalString('PROJECT_TIME_SPENT_INTO_INVOICE_USE_VALUE')) {
819 $pu_ht_for_task = (float) price2num($timespent_data['totalvaluetodivideby3600'] / $timespent_data['timespent'], 'MU') * $prodDurationHours;
820 }
821 $pa_ht = (float) price2num($timespent_data['totalvaluetodivideby3600'] / $timespent_data['timespent'], 'MU') * $prodDurationHours;
822 } else {
823 // If not product used, we use the hour unit for duration and unit price.
824 $pu_ht_for_task = 0;
825 // If we want to reuse the value of timespent (so use same price than cost price)
826 if (getDolGlobalString('PROJECT_TIME_SPENT_INTO_INVOICE_USE_VALUE')) {
827 $pu_ht_for_task = price2num($timespent_data['totalvaluetodivideby3600'] / $timespent_data['timespent'], 'MU');
828 }
829 $pa_ht = price2num($timespent_data['totalvaluetodivideby3600'] / $timespent_data['timespent'], 'MU');
830 }
831
832 // Add lines
833 $date_start = '';
834 $date_end = '';
835 $lineName = $ftask->ref . ' - ' . $ftask->label;
836 $lineid = $tmpinvoice->addline($lineName, (float) $pu_ht_for_task, (float) price2num($qtyhour / $prodDurationHours, 'MS'), $txtvaline, $localtax1line, $localtax2line, ($idprodline > 0 ? $idprodline : 0), (float) $remiseproject, $date_start, $date_end, 0, 0, 0, 'HT', 0, 1, -1, 0, '', 0, 0, 0, $pa_ht);
837 if ($lineid < 0) {
838 $error++;
839 setEventMessages($tmpinvoice->error, $tmpinvoice->errors, 'errors');
840 break;
841 }
842
843 if (!$error) {
844 // Update lineid into line of timespent
845 $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'element_time SET invoice_line_id = ' . ((int) $lineid) . ', invoice_id = ' . ((int) $tmpinvoice->id);
846 $sql .= ' WHERE rowid IN (' . $db->sanitize(implode(',', $toselect)) . ')';
847 $result = $db->query($sql);
848 if (!$result) {
849 $error++;
850 setEventMessages($db->lasterror(), null, 'errors');
851 break;
852 }
853 }
854 }
855 }
856 }
857 }
858
859 if (!$error) {
860 $urltoinvoice = $tmpinvoice->getNomUrl(0);
861 $mesg = $langs->trans("InvoiceGeneratedFromTimeSpent", '{s1}');
862 $mesg = str_replace('{s1}', $urltoinvoice, $mesg);
863 setEventMessages($mesg, null, 'mesgs');
864
865 $db->commit();
866 } else {
867 $db->rollback();
868 }
869 }
870}
871
872if ($action == 'confirm_generateinter' && $user->hasRight('fichinter', 'creer')) {
873 $langs->load('interventions');
874
875 if (!empty($projectstatic->socid)) {
876 $projectstatic->fetch_thirdparty();
877 }
878
879 if (!($projectstatic->thirdparty->id > 0)) {
880 setEventMessages($langs->trans("ThirdPartyRequiredToGenerateIntervention"), null, 'errors');
881 } else {
882 include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
883 include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
884 include_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
885
886
887 require_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php';
888 $tmpinter = new Fichinter($db);
889 $tmptimespent = new Task($db);
890 $fuser = new User($db);
891
892 $db->begin();
893 $interToUse = GETPOSTINT('interid');
894
895
896 $tmpinter->socid = $projectstatic->thirdparty->id;
897 $tmpinter->date = dol_mktime(GETPOSTINT('rehour'), GETPOSTINT('remin'), GETPOSTINT('resec'), GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
898 $tmpinter->fk_project = $projectstatic->id;
899 $tmpinter->description = $projectstatic->title . (!empty($projectstatic->description) ? '-' . $projectstatic->description : '');
900
901 if ($interToUse) {
902 $tmpinter->fetch($interToUse);
903 } else {
904 $result = $tmpinter->create($user);
905 if ($result <= 0) {
906 $error++;
907 setEventMessages($tmpinter->error, $tmpinter->errors, 'errors');
908 }
909 }
910
911 if (!$error) {
912 $arrayoftasks = array();
913 foreach ($toselect as $key => $value) {
914 // Get userid, timespent
915 $object->fetchTimeSpent($value);
916 // $object->id is the task id
917 $arrayoftasks[$object->timespent_id]['id'] = $object->id;
918 $arrayoftasks[$object->timespent_id]['timespent'] = $object->timespent_duration;
919 $arrayoftasks[$object->timespent_id]['totalvaluetodivideby3600'] = $object->timespent_duration * $object->timespent_thm;
920 $arrayoftasks[$object->timespent_id]['note'] = $object->timespent_note;
921 $arrayoftasks[$object->timespent_id]['date'] = $object->timespent_datehour;
922 }
923
924 foreach ($arrayoftasks as $timespent_id => $value) {
925 $ftask = new Task($db);
926 $ftask->fetch($value['id']);
927 // Define qty per hour
928 $qtyhour = $value['timespent'] / 3600;
929 $qtyhourtext = convertSecondToTime($value['timespent'], 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
930
931 // Add lines
932 $lineid = $tmpinter->addline($user, $tmpinter->id, $ftask->label . (!empty($value['note']) ? ' - ' . $value['note'] : ''), (int) $value['date'], $value['timespent']);
933
934 if ($lineid > 0) {
935 // Link timespent to intervention
936 $timespent = new TimeSpent($db);
937 $timespent->fetch($timespent_id);
938 $timespent->intervention_id = $tmpinter->id;
939 $timespent->intervention_line_id = $lineid;
940 $result = $timespent->update($user);
941 if ($result < 0) {
942 $error++;
943 setEventMessages($timespent->error, $timespent->errors, 'errors');
944 }
945 }
946 }
947 }
948
949 if (!$error) {
950 $urltointer = $tmpinter->getNomUrl(0);
951 $mesg = $langs->trans("InterventionGeneratedFromTimeSpent", '{s1}');
952 $mesg = str_replace('{s1}', $urltointer, $mesg);
953 setEventMessages($mesg, null, 'mesgs');
954
955 //var_dump($tmpinvoice);
956
957 $db->commit();
958 } else {
959 $db->rollback();
960 }
961 }
962}
963
964
965/*
966 * View
967 */
968
969$form = new Form($db);
970$formother = new FormOther($db);
971$formproject = new FormProjets($db);
972$userstatic = new User($db);
973//$result = $projectstatic->fetch($object->fk_project);
974$arrayofselected = is_array($toselect) ? $toselect : array();
975
976$title = $object->ref . ' - ' . $langs->trans("TimeSpent");
977if (!empty($withproject)) {
978 $title .= ' | ' . $langs->trans("Project") . (!empty($projectstatic->ref) ? ': ' . $projectstatic->ref : '');
979}
980$help_url = '';
981
982llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-project project-tasks page-task_time');
983
984
985$param = ((!empty($mode) && $mode == 'mine') ? '&mode=mine' : '');
986if ($search_user) {
987 $param .= '&search_user=' . ((int) $search_user);
988}
989if ($search_month) {
990 $param .= '&search_month=' . ((int) $search_month);
991}
992if ($search_year) {
993 $param .= '&search_year=' . ((int) $search_year);
994}
995
996
997if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser > 0) {
998 // Project car in view mode
999 if ($projectidforalltimes > 0) {
1000 $result = $projectstatic->fetch($projectidforalltimes);
1001 if (!empty($projectstatic->socid)) {
1002 $projectstatic->fetch_thirdparty();
1003 }
1004 $res = $projectstatic->fetch_optionals();
1005 } elseif ($object->fetch($id, $ref) > 0) {
1006 if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_TASK') && empty($object->comments)) {
1007 $object->fetchComments();
1008 }
1009 $result = $projectstatic->fetch($object->fk_project);
1010 if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_PROJECT') && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) {
1011 $projectstatic->fetchComments();
1012 }
1013 if (!empty($projectstatic->socid)) {
1014 $projectstatic->fetch_thirdparty();
1015 }
1016 $res = $projectstatic->fetch_optionals();
1017
1018 $object->project = clone $projectstatic;
1019 }
1020
1021 $userRead = $projectstatic->restrictedProjectArea($user, 'read');
1022 $linktocreatetime = '';
1023
1024 if ($projectstatic->id > 0) {
1025 if ($withproject) {
1026 // Tabs for project
1027 if (empty($id) || $tab == 'timespent') {
1028 $tab = 'timespent';
1029 } else {
1030 $tab = 'tasks';
1031 }
1032
1033 $head = project_prepare_head($projectstatic);
1034 print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'));
1035
1036 // Project card
1037
1038 $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1039
1040 $morehtmlref = '<div class="refidno">';
1041 // Title
1042 $morehtmlref .= $projectstatic->title;
1043 // Thirdparty
1044 if (!empty($projectstatic->thirdparty->id) && $projectstatic->thirdparty->id > 0) {
1045 $morehtmlref .= '<br>' . $projectstatic->thirdparty->getNomUrl(1, 'project');
1046 }
1047 $morehtmlref .= '</div>';
1048
1049 // Define a complementary filter for search of next/prev ref.
1050 if (!$user->hasRight('projet', 'all', 'lire')) {
1051 $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
1052 $projectstatic->next_prev_filter = "rowid:IN:" . $db->sanitize(count($objectsListId) ? implode(',', array_keys($objectsListId)) : '0');
1053 }
1054
1055 dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
1056
1057 print '<div class="fichecenter">';
1058 print '<div class="fichehalfleft">';
1059 print '<div class="underbanner clearboth"></div>';
1060
1061 print '<table class="border tableforfield centpercent">';
1062
1063 // Usage
1064 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES') || !getDolGlobalString('PROJECT_HIDE_TASKS') || isModEnabled('eventorganization')) {
1065 print '<tr><td class="tdtop">';
1066 print $langs->trans("Usage");
1067 print '</td>';
1068 print '<td>';
1069 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
1070 print '<input type="checkbox" disabled name="usage_opportunity"' . (GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')) . '"> ';
1071 $htmltext = $langs->trans("ProjectFollowOpportunity");
1072 print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
1073 print '<br>';
1074 }
1075 if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
1076 print '<input type="checkbox" disabled name="usage_task"' . (GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')) . '"> ';
1077 $htmltext = $langs->trans("ProjectFollowTasks");
1078 print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
1079 print '<br>';
1080 }
1081 if (!getDolGlobalString('PROJECT_HIDE_TASKS') && getDolGlobalString('PROJECT_BILL_TIME_SPENT')) {
1082 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"' : '')) . '"> ';
1083 $htmltext = $langs->trans("ProjectBillTimeDescription");
1084 print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
1085 print '<br>';
1086 }
1087 if (isModEnabled('eventorganization')) {
1088 print '<input type="checkbox" disabled name="usage_organize_event"' . (GETPOSTISSET('usage_organize_event') ? (GETPOST('usage_organize_event', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_organize_event ? ' checked="checked"' : '')) . '"> ';
1089 $htmltext = $langs->trans("EventOrganizationDescriptionLong");
1090 print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
1091 }
1092 print '</td></tr>';
1093 }
1094
1095 // Budget
1096 print '<tr><td>' . $langs->trans("Budget") . '</td><td>';
1097 if (!is_null($projectstatic->budget_amount) && strcmp($projectstatic->budget_amount, '')) {
1098 print '<span class="amount">' . price($projectstatic->budget_amount, 0, $langs, 1, 0, 0, $conf->currency) . '</span>';
1099 }
1100 print '</td></tr>';
1101
1102 // Date start - end project
1103 print '<tr><td>' . $langs->trans("Dates") . '</td><td>';
1104 $start = dol_print_date($projectstatic->date_start, 'day');
1105 print($start ? $start : '?');
1106 $end = dol_print_date($projectstatic->date_end, 'day');
1107 print ' - ';
1108 print($end ? $end : '?');
1109 if ($projectstatic->hasDelay()) {
1110 print img_warning("Late");
1111 }
1112 print '</td></tr>';
1113
1114 // Visibility
1115 print '<tr><td class="titlefield">' . $langs->trans("Visibility") . '</td><td>';
1116 if ($projectstatic->public) {
1117 print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
1118 print $langs->trans('SharedProject');
1119 } else {
1120 print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
1121 print $langs->trans('PrivateProject');
1122 }
1123 print '</td></tr>';
1124
1125 // Other attributes
1126 $cols = 2;
1127 $savobject = $object;
1128 $object = $projectstatic;
1129 // On this page, the 'id' GET parameter is the task id, not the project id, so force the
1130 // edit link/form of the project extrafields to use 'projectid' instead, and keep 'withproject'
1131 // so the project summary (this whole block) stays visible after the edit link is followed.
1132 $forcefieldid = 'projectid';
1133 $moreparam = '&withproject=1';
1134 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
1135 unset($forcefieldid, $moreparam);
1136 $object = $savobject;
1137
1138 print '</table>';
1139
1140 print '</div>';
1141 print '<div class="fichehalfright">';
1142 print '<div class="underbanner clearboth"></div>';
1143
1144 print '<table class="border tableforfield centpercent">';
1145
1146 // Categories
1147 if (isModEnabled('category')) {
1148 print '<tr><td class="valignmiddle">' . $langs->trans("Categories") . '</td><td>';
1149 print $form->showCategories($projectstatic->id, 'project', 1);
1150 print "</td></tr>";
1151 }
1152
1153 // Description
1154 print '<tr><td class="titlefield'.($projectstatic->description ? ' noborderbottom' : '').'" colspan="2">'.$langs->trans("Description").'</td></tr>';
1155 if ($projectstatic->description) {
1156 print '<tr><td class="nottitleforfield" colspan="2">';
1157 print '<div class="longmessagecut">';
1158 print dolPrintHTML($projectstatic->description);
1159 print '</div>';
1160 print '</td></tr>';
1161 }
1162
1163 print '</table>';
1164
1165 print '</div>';
1166 print '</div>';
1167
1168 print '<div class="clearboth"></div>';
1169
1170 print dol_get_fiche_end();
1171
1172 print '<br>';
1173 }
1174
1175 // Link to create time
1176 $linktocreatetimeBtnStatus = 0;
1177 $linktocreatetimeUrl = '';
1178 $linktocreatetimeHelpText = '';
1179 if ($user->hasRight('projet', 'time')) {
1180 if ($projectstatic->public || $userRead > 0) {
1181 $linktocreatetimeBtnStatus = 1;
1182
1183 if (!empty($projectidforalltimes)) {
1184 // We are on tab 'Time Spent' of project
1185 $backtourl = $_SERVER['PHP_SELF'] . '?projectid=' . $projectstatic->id . ($withproject ? '&withproject=1' : '');
1186 $linktocreatetimeUrl = $_SERVER['PHP_SELF'] . '?' . ($withproject ? 'withproject=1' : '') . '&projectid=' . $projectstatic->id . '&action=createtime&token=' . newToken() . $param . '&backtopage=' . urlencode($backtourl);
1187 } else {
1188 // We are on tab 'Time Spent' of task
1189 $backtourl = $_SERVER['PHP_SELF'] . '?id=' . $object->id . ($withproject ? '&withproject=1' : '');
1190 $linktocreatetimeUrl = $_SERVER['PHP_SELF'] . '?' . ($withproject ? 'withproject=1' : '') . ($object->id > 0 ? '&id=' . $object->id : '&projectid=' . $projectstatic->id) . '&action=createtime&token=' . newToken() . $param . '&backtopage=' . urlencode($backtourl);
1191 }
1192 } else {
1193 $linktocreatetimeBtnStatus = -2;
1194 $linktocreatetimeHelpText = $langs->trans("NotOwnerOfProject");
1195 }
1196 } else {
1197 $linktocreatetimeBtnStatus = -2;
1198 $linktocreatetimeHelpText = $langs->trans("NotEnoughPermissions");
1199 }
1200
1201 $paramsbutton = array('morecss' => 'reposition');
1202 $linktocreatetime = dolGetButtonTitle($langs->trans('AddTimeSpent'), $linktocreatetimeHelpText, 'fa fa-plus-circle', $linktocreatetimeUrl, '', $linktocreatetimeBtnStatus, $paramsbutton);
1203 }
1204
1205 $massactionbutton = '';
1206 $arrayofmassactions = array();
1207
1208 if ($projectstatic->id > 0) {
1209 // If we are on a given project.
1210 if ($projectstatic->usage_bill_time) {
1211 $arrayofmassactions = array(
1212 'generateinvoice' => $langs->trans("GenerateBill"),
1213 //'builddoc'=>$langs->trans("PDFMerge"),
1214 );
1215 }
1216 if (isModEnabled('intervention') && $user->hasRight('ficheinter', 'creer')) {
1217 $langs->load("interventions");
1218 $arrayofmassactions['generateinter'] = $langs->trans("GenerateInter");
1219 }
1220 }
1221 if (in_array($massaction, array('presend', 'predelete', 'generateinvoice', 'generateinter'))) {
1222 $arrayofmassactions = array();
1223 }
1224 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
1225
1226 $formconfirm = '';
1227
1228 // Task
1229
1230 // Show section with information of task. If id of task is not defined and project id defined, then $projectidforalltimes is not empty.
1231 if (empty($projectidforalltimes) && empty($allprojectforuser)) {
1232 $head = task_prepare_head($object);
1233 print dol_get_fiche_head($head, 'task_time', $langs->trans("Task"), -1, 'projecttask', 0, '', 'reposition');
1234
1235 $param = (GETPOST('withproject') ? '&withproject=1' : '');
1236 $linkback = GETPOST('withproject') ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>' : '';
1237
1238 if ($action == 'deleteline') {
1239 $urlafterconfirm = $_SERVER["PHP_SELF"] . "?" . ($object->id > 0 ? "id=" . $object->id : 'projectid=' . $projectstatic->id) . '&lineid=' . GETPOSTINT("lineid") . $param;
1240 $formconfirm .= $form->formconfirm($urlafterconfirm, $langs->trans("DeleteATimeSpent"), $langs->trans("ConfirmDeleteATimeSpent"), "confirm_deleteline", '', '', 1);
1241 }
1242
1243 if (!GETPOST('withproject') || empty($projectstatic->id)) {
1244 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
1245 $object->next_prev_filter = "fk_projet:IN:" . $db->sanitize($projectsListId);
1246 } else {
1247 $object->next_prev_filter = "fk_projet:=:" . ((int) $projectstatic->id);
1248 }
1249
1250 $morehtmlref = '';
1251
1252 // Project
1253 if (empty($withproject)) {
1254 $morehtmlref .= '<div class="refidno">';
1255 $morehtmlref .= $langs->trans("Project") . ': ';
1256 $morehtmlref .= $projectstatic->getNomUrl(1);
1257 $morehtmlref .= '<br>';
1258
1259 // Third party
1260 $morehtmlref .= $langs->trans("ThirdParty") . ': ';
1261 if (!empty($projectstatic->thirdparty) && is_object($projectstatic->thirdparty)) {
1262 $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1);
1263 }
1264 $morehtmlref .= '</div>';
1265 }
1266
1267 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
1268
1269 print '<div class="fichecenter">';
1270 print '<div class="fichehalfleft">';
1271
1272 print '<div class="underbanner clearboth"></div>';
1273 print '<table class="border centpercent tableforfield">';
1274
1275 // Task parent
1276 print '<tr><td>' . $langs->trans("ParentTask") . '</td><td>';
1277 if ($object->fk_task_parent > 0) {
1278 $tasktmp = new Task($db);
1279 $tasktmp->fetch($object->fk_task_parent);
1280 print $tasktmp->getNomUrl(1);
1281 }
1282 print '</td></tr>';
1283
1284 // Date start - Date end task
1285 print '<tr><td class="titlefield">' . $langs->trans("DateStart") . ' - ' . $langs->trans("Deadline") . '</td><td>';
1286 $start = dol_print_date($object->date_start, 'dayhour');
1287 print($start ? $start : '?');
1288 $end = dol_print_date($object->date_end, 'dayhour');
1289 print ' - ';
1290 print($end ? $end : '?');
1291 if ($object->hasDelay()) {
1292 print img_warning("Late");
1293 }
1294 print '</td></tr>';
1295
1296 // Planned workload
1297 print '<tr><td>' . $langs->trans("PlannedWorkload") . '</td><td>';
1298 if ($object->planned_workload) {
1299 print convertSecondToTime($object->planned_workload, 'allhourmin');
1300 }
1301 print '</td></tr>';
1302
1303 print '</table>';
1304 print '</div>';
1305
1306 print '<div class="fichehalfright">';
1307
1308 print '<div class="underbanner clearboth"></div>';
1309 print '<table class="border tableforfield centpercent">';
1310
1311 // Progress declared
1312 print '<tr><td class="titlefield">' . $langs->trans("ProgressDeclared") . '</td><td>';
1313 print $object->progress != '' ? $object->progress . ' %' : '';
1314 print '</td></tr>';
1315
1316 // Progress calculated
1317 print '<tr><td>' . $langs->trans("ProgressCalculated") . '</td><td>';
1318 if ($object->planned_workload) {
1319 $tmparray = $object->getSummaryOfTimeSpent();
1320 if ($tmparray['total_duration'] > 0) {
1321 print round($tmparray['total_duration'] / $object->planned_workload * 100, 2) . ' %';
1322 } else {
1323 print '0 %';
1324 }
1325 } else {
1326 print '<span class="opacitymedium">' . $langs->trans("WorkloadNotDefined") . '</span>';
1327 }
1328 print '</td>';
1329
1330 print '</tr>';
1331
1332 print '</table>';
1333
1334 print '</div>';
1335
1336 print '</div>';
1337 print '<div class="clearboth"></div>';
1338
1339 print dol_get_fiche_end();
1340 } else {
1341 if ($action == 'deleteline') {
1342 $urlafterconfirm = $_SERVER["PHP_SELF"] . "?" . ($projectstatic->id > 0 ? 'projectid=' . $projectstatic->id : ($object->id > 0 ? "id=" . $object->id : '')) . '&lineid=' . GETPOSTINT("lineid") . ($withproject ? '&withproject=1' : ''). "&contextpage=" . urlencode($contextpage).$param;
1343 $formconfirm .= $form->formconfirm($urlafterconfirm, $langs->trans("DeleteATimeSpent"), $langs->trans("ConfirmDeleteATimeSpent"), "confirm_deleteline", '', '', 1);
1344 }
1345 }
1346
1347 // Call Hook formConfirm
1348 $parameters = array('formConfirm' => $formconfirm, "projectstatic" => $projectstatic, "withproject" => $withproject);
1349 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1350 if (empty($reshook)) {
1351 $formconfirm .= $hookmanager->resPrint;
1352 } elseif ($reshook > 0) {
1353 $formconfirm = $hookmanager->resPrint;
1354 }
1355
1356
1357 if ($projectstatic->id > 0 || $allprojectforuser > 0) {
1358 // Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
1359 $hookmanager->initHooks(array('tasktimelist'));
1360
1361 // Print form confirm
1362 print $formconfirm;
1363
1364 // Definition of fields for list
1365 $arrayfields = array();
1366 $arrayfields['t.element_date'] = array('label' => $langs->trans("Date"), 'checked' => '1');
1367 $arrayfields['p.fk_soc'] = array('label' => $langs->trans("ThirdParty"), 'type' => 'integer:Societe:/societe/class/societe.class.php:1','checked' => '1');
1368 $arrayfields['s.name_alias'] = array('label' => $langs->trans("AliasNameShort"), 'type' => 'integer:Societe:/societe/class/societe.class.php:1');
1369 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
1370 if (! empty($allprojectforuser)) {
1371 $arrayfields['p.project_ref'] = ['label' => $langs->trans('RefProject'), 'checked' => '1'];
1372 $arrayfields['p.project_label'] = ['label' => $langs->trans('ProjectLabel'), 'checked' => '1'];
1373 }
1374 $arrayfields['t.element_ref'] = array('label' => $langs->trans("RefTask"), 'checked' => '1');
1375 $arrayfields['t.element_label'] = array('label' => $langs->trans("LabelTask"), 'checked' => '1');
1376 }
1377 $arrayfields['author'] = array('label' => $langs->trans("By"), 'checked' => '1');
1378 $arrayfields['t.note'] = array('label' => $langs->trans("Note"), 'checked' => '1');
1379 if (isModEnabled('service') && !empty($projectstatic->thirdparty) && $projectstatic->thirdparty->id > 0 && $projectstatic->usage_bill_time) {
1380 $arrayfields['t.fk_product'] = array('label' => $langs->trans("Product"), 'checked' => '1');
1381 }
1382 $arrayfields['t.element_duration'] = array('label' => $langs->trans("Duration"), 'checked' => '1');
1383 $arrayfields['value'] = array('label' => $langs->trans("Value"), 'checked' => '1', 'enabled' => (string) (int) isModEnabled("salaries"));
1384 $arrayfields['valuebilled'] = array('label' => $langs->trans("Billed"), 'checked' => '1', 'enabled' => (string) (int) (((getDolGlobalInt('PROJECT_HIDE_TASKS') || !getDolGlobalInt('PROJECT_BILL_TIME_SPENT')) ? 0 : 1) && $projectstatic->usage_bill_time));
1385 // Extra fields
1386 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php';
1387
1388 $arrayfields = dol_sort_array($arrayfields, 'position');
1389
1390 $param = '';
1391 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
1392 $param .= '&contextpage=' . urlencode($contextpage);
1393 }
1394 if ($limit > 0 && $limit != $conf->liste_limit) {
1395 $param .= '&limit='.((int) $limit);
1396 }
1397 if ($id > 0) {
1398 $param .= '&id='.((int) $id);
1399 }
1400 if ($search_month > 0) {
1401 $param .= '&search_month=' . urlencode((string) ($search_month));
1402 }
1403 if ($search_year > 0) {
1404 $param .= '&search_year=' . urlencode((string) ($search_year));
1405 }
1406 if (!empty($search_user)) { // We keep param if -1 because default value is forced to user id if not set
1407 $param .= '&search_user='.urlencode($search_user);
1408 }
1409 if ($search_task_ref != '') {
1410 $param .= '&search_task_ref=' . urlencode($search_task_ref);
1411 }
1412 if ($search_company != '') {
1413 $param .= '&search_company=' . urlencode($search_company);
1414 }
1415 if ($search_company_alias != '') {
1416 $param .= '&search_company_alias=' . urlencode($search_company_alias);
1417 }
1418 if ($search_project_ref != '') {
1419 $param .= '&search_project_ref=' . urlencode($search_project_ref);
1420 }
1421 if ($search_project_label != '') {
1422 $param .= '&search_project_label=' . urlencode($search_project_label);
1423 }
1424 if ($search_task_label != '') {
1425 $param .= '&search_task_label=' . urlencode($search_task_label);
1426 }
1427 if ($search_note != '') {
1428 $param .= '&search_note=' . urlencode($search_note);
1429 }
1430 if ($search_duration != '') {
1431 $param .= '&search_field2=' . urlencode((string) ($search_duration));
1432 }
1433 if ($optioncss != '') {
1434 $param .= '&optioncss=' . urlencode($optioncss);
1435 }
1436 if ($search_date_startday) {
1437 $param .= '&search_date_startday=' . urlencode((string) ($search_date_startday));
1438 }
1439 if ($search_date_startmonth) {
1440 $param .= '&search_date_startmonth=' . urlencode((string) ($search_date_startmonth));
1441 }
1442 if ($search_date_startyear) {
1443 $param .= '&search_date_startyear=' . urlencode((string) ($search_date_startyear));
1444 }
1445 if ($search_date_endday) {
1446 $param .= '&search_date_endday=' . urlencode((string) ($search_date_endday));
1447 }
1448 if ($search_date_endmonth) {
1449 $param .= '&search_date_endmonth=' . urlencode((string) ($search_date_endmonth));
1450 }
1451 if ($search_date_endyear) {
1452 $param .= '&search_date_endyear=' . urlencode((string) ($search_date_endyear));
1453 }
1454 if ($search_timespent_starthour) {
1455 $param .= '&search_timespent_duration_starthour=' . urlencode((string) ($search_timespent_starthour));
1456 }
1457 if ($search_timespent_startmin) {
1458 $param .= '&search_timespent_duration_startmin=' . urlencode((string) ($search_timespent_startmin));
1459 }
1460 if ($search_timespent_endhour) {
1461 $param .= '&search_timespent_duration_endhour=' . urlencode((string) ($search_timespent_endhour));
1462 }
1463 if ($search_timespent_endmin) {
1464 $param .= '&search_timespent_duration_endmin=' . urlencode((string) ($search_timespent_endmin));
1465 }
1466 // Add $param from extra fields
1467 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1468 if ($id) {
1469 $param .= '&id=' . urlencode((string) ($id));
1470 }
1471 if ($projectid) {
1472 $param .= '&projectid=' . urlencode((string) ($projectid));
1473 }
1474 if ($withproject) {
1475 $param .= '&withproject=' . urlencode((string) ($withproject));
1476 }
1477 // Add $param from hooks
1478 $parameters = array('param' => &$param);
1479 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1480 $param .= $hookmanager->resPrint;
1481
1482 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
1483 if ($optioncss != '') {
1484 print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
1485 }
1486 print '<input type="hidden" name="token" value="' . newToken() . '">';
1487 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1488 if ($action == 'editline') {
1489 print '<input type="hidden" name="action" value="updateline">';
1490 } elseif ($action == 'splitline') {
1491 print '<input type="hidden" name="action" value="updatesplitline">';
1492 } elseif ($action == 'createtime' && $user->hasRight('projet', 'time')) {
1493 print '<input type="hidden" name="action" value="addtimespent">';
1494 } elseif ($massaction == 'generateinvoice' && $user->hasRight('facture', 'creer')) {
1495 print '<input type="hidden" name="action" value="confirm_generateinvoice">';
1496 } elseif ($massaction == 'generateinter' && $user->hasRight('ficheinter', 'creer')) {
1497 print '<input type="hidden" name="action" value="confirm_generateinter">';
1498 } else {
1499 print '<input type="hidden" name="action" value="list">';
1500 }
1501 print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
1502 print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
1503
1504 // Carry the task id through the filter submit so that the timespent list
1505 // stays scoped to the current task instead of falling back to the global view.
1506 print '<input type="hidden" name="id" value="' . ((int) $id) . '">';
1507 print '<input type="hidden" name="projectid" value="' . $projectidforalltimes . '">';
1508 print '<input type="hidden" name="withproject" value="' . $withproject . '">';
1509 print '<input type="hidden" name="tab" value="' . $tab . '">';
1510 print '<input type="hidden" name="page_y" value="">';
1511
1512 // Form to convert time spent into invoice
1513 if ($massaction == 'generateinvoice') {
1514 if (!empty($projectstatic->thirdparty) && $projectstatic->thirdparty->id > 0) {
1515 print '<table class="noborder centerpercent">';
1516 print '<tr>';
1517 print '<td class="titlefield">';
1518 print $langs->trans('DateInvoice');
1519 print '</td>';
1520 print '<td>';
1521 print $form->selectDate('', '', 0, 0, 0, '', 1, 1);
1522 print '</td>';
1523 print '</tr>';
1524
1525 print '<tr>';
1526 print '<td>';
1527 print $langs->trans('Mode');
1528 print '</td>';
1529 print '<td>';
1530 $tmparray = array(
1531 'onelineperuser' => 'OneLinePerUser',
1532 'onelinepertask' => 'OneLinePerTask',
1533 'onelineperperiod' => 'OneLinePerTimeSpentLine',
1534 );
1535 print $form->selectarray('generateinvoicemode', $tmparray, 'onelineperuser', 0, 0, 0, '', 1);
1536 print "\n" . '<script type="text/javascript">';
1537 print '
1538 $(document).ready(function () {
1539 setDetailVisibility();
1540 $("#generateinvoicemode").change(function() {
1541 setDetailVisibility();
1542 });
1543 function setDetailVisibility() {
1544 generateinvoicemode = $("#generateinvoicemode option:selected").val();
1545 if (generateinvoicemode=="onelineperperiod") {
1546 $("#detail_time_duration").show();
1547 } else {
1548 $("#detail_time_duration").hide();
1549 }
1550 }
1551 });
1552 ';
1553 print '</script>' . "\n";
1554 print '<span style="display:none" id="detail_time_duration"><input type="checkbox" value="detail" name="detail_time_duration"/>' . $langs->trans('AddDetailDateAndDuration') . '</span>';
1555 print '</td>';
1556 print '</tr>';
1557
1558 if (isModEnabled("service")) {
1559 print '<tr>';
1560 print '<td>';
1561 print $langs->trans('ServiceToUseOnLines');
1562 print '</td>';
1563 print '<td>';
1564 $form->select_produits(0, 'productid', 1, 0, $projectstatic->thirdparty->price_level, 1, 2, '', 0, array(), $projectstatic->thirdparty->id, 'None', 0, 'maxwidth500');
1565 print '</td>';
1566 print '</tr>';
1567 }
1568 print '<tr>';
1569 print '<td class="titlefield">';
1570 print $langs->trans('InvoiceToUse');
1571 print '</td>';
1572 print '<td>';
1573 print $form->selectInvoiceForTimeProject($projectstatic->thirdparty->id, '', 'invoiceid', 24, 0, $langs->trans('NewInvoice'), 1, 0, 0, 'maxwidth500', '', 'all');
1574 print '</td>';
1575 print '</tr>';
1576 print '<tr>';
1577 print '<td class="titlefield">';
1578 print $langs->trans("CustomerRelativeDiscount");
1579 print '</td>';
1580 print '<td>';
1581 print '<input type="text" size="5" name="remiseproject" value="'.$projectstatic->thirdparty->remise_percent.'">%';
1582 print '</td>';
1583 print '</tr>';
1584 print '<tr class="newinvoicedetail">';
1585 print '<td class="titlefield">';
1586 print $langs->trans("PaymentConditions");
1587 print '</td>';
1588 print '<td>';
1589 print $form->getSelectConditionsPaiements((int) $projectstatic->thirdparty->cond_reglement_id, 'condidproject');
1590 print '</td>';
1591 print '</tr>';
1592 /*print '<tr>';
1593 print '<td>';
1594 print $langs->trans('ValidateInvoices');
1595 print '</td>';
1596 print '<td>';
1597 print $form->selectyesno('validate_invoices', 0, 1);
1598 print '</td>';
1599 print '</tr>';*/
1600 print '</table>';
1601
1602 print '<br>';
1603 print '<div class="center">';
1604 print '<input type="submit" class="button" id="createbills" name="createbills" value="' . $langs->trans('GenerateBill') . '"> ';
1605 print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="' . $langs->trans("Cancel") . '">';
1606 print '</div>';
1607 print '<br>';
1608 } else {
1609 print '<div class="warning">' . $langs->trans("ThirdPartyRequiredToGenerateInvoice") . '</div>';
1610 print '<div class="center">';
1611 print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="' . $langs->trans("Cancel") . '">';
1612 print '</div>';
1613 $massaction = '';
1614 }
1615 } elseif ($massaction == 'generateinter') {
1616 // Form to convert time spent into invoice
1617 print '<input type="hidden" name="massaction" value="confirm_createinter">';
1618
1619 if (!empty($projectstatic->thirdparty) && $projectstatic->thirdparty->id > 0) {
1620 print '<br>';
1621 print '<table class="noborder centpercent">';
1622 print '<tr>';
1623 print '<td class="titlefield">';
1624 print img_picto('', 'intervention', 'class="pictofixedwidth"') . $langs->trans('InterToUse');
1625 print '</td>';
1626 print '<td>';
1627 $forminter = new FormIntervention($db);
1628 print $forminter->select_interventions($projectstatic->thirdparty->id, 0, 'interid', 24, $langs->trans('NewInter'), true);
1629 print '</td>';
1630 print '</tr>';
1631 print '</table>';
1632
1633 print '<div class="center">';
1634 print '<input type="submit" class="button" id="createinter" name="createinter" value="' . $langs->trans('GenerateInter') . '"> ';
1635 print '<input type="submit" class="button" id="cancel" name="cancel" value="' . $langs->trans('Cancel') . '">';
1636 print '</div>';
1637 print '<br>';
1638 } else {
1639 print '<div class="warning">' . $langs->trans("ThirdPartyRequiredToGenerateIntervention") . '</div>';
1640 print '<div class="center">';
1641 print '<input type="submit" class="button" id="cancel" name="cancel" value="' . $langs->trans('Cancel') . '">';
1642 print '</div>';
1643 $massaction = '';
1644 }
1645 }
1646
1647 // Allow Pre-Mass-Action hook (eg for confirmation dialog)
1648 $parameters = array(
1649 'toselect' => $toselect,
1650 'uploaddir' => isset($uploaddir) ? $uploaddir : null
1651 );
1652
1653 $reshook = $hookmanager->executeHooks('doPreMassActions', $parameters, $object, $action);
1654 if ($reshook < 0) {
1655 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1656 } else {
1657 print $hookmanager->resPrint;
1658 }
1659
1660 /*
1661 * List of time spent
1662 */
1663 $tasks = array();
1664
1665 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1666 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
1667
1668 // If project has usage "Bill time", we force visibility of field "billed"
1669 if ($projectstatic->usage_bill_time) {
1670 $arrayfields['valuebilled']['checked'] = 1;
1671 }
1672
1673 $sql = "SELECT t.rowid, t.fk_element, t.element_date, t.element_datehour, t.element_date_withhour, t.element_duration, t.fk_user, t.note, t.thm,";
1674 $sql .= " t.fk_product, t.invoice_line_id,";
1675 $sql .= " pt.rowid as taskid, pt.ref, pt.label, pt.fk_projet, pt.billable,";
1676 $sql .= " u.lastname, u.firstname, u.login, u.photo, u.gender, u.statut as user_status,";
1677 $sql .= " il.fk_facture as invoice_id, inv.fk_statut,";
1678 $sql .= " p.fk_soc,s.name_alias";
1679 if (!empty($extrafields->attributes['projet_task']['label'])) {
1680 foreach ($extrafields->attributes['projet_task']['label'] as $key => $val) {
1681 $sql .= ($extrafields->attributes['projet_task']['type'][$key] != 'separate' ? ",efpt.".$key." as options_".$key : '');
1682 }
1683 }
1684 // Add fields from hooks
1685 $parameters = array();
1686 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1687 $sql .= $hookmanager->resPrint;
1688 $sql = preg_replace('/,\s*$/', '', $sql);
1689
1690 $sqlfields = $sql; // $sql fields to remove for count total
1691
1692 $sql .= " FROM ".MAIN_DB_PREFIX."element_time as t";
1693 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facturedet as il ON il.rowid = t.invoice_line_id";
1694 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as inv ON inv.rowid = il.fk_facture";
1695 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as prod ON prod.rowid = t.fk_product";
1696 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."projet_task as pt ON pt.rowid = t.fk_element";
1697 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_extrafields as efpt ON pt.rowid = efpt.fk_object";
1698 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = pt.fk_projet";
1699 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON t.fk_user = u.rowid";
1700 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
1701
1702 // Add table from hooks
1703 $parameters = array();
1704 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1705 $sql .= $hookmanager->resPrint;
1706 $sql .= " WHERE elementtype = 'task'";
1707 $sql .= " AND p.entity IN (".getEntity('project').")";
1708 if (!$user->hasRight('projet', 'all', 'lire')) {
1709 // Get list of project id allowed to user (in a string list separated by comma)
1710 // TODO This may generate performance trouble when list of project is very large. Solution can be to complete $filterproj with filters on project.
1711 $filterproj = '';
1712 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $user->socid > 0 ? $user->socid : 0, $filterproj);
1713 $sql .= " AND p.rowid IN (".$db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
1714 }
1715 if (empty($projectidforalltimes) && empty($allprojectforuser)) {
1716 // Limit on one task
1717 $sql .= " AND t.fk_element =".((int) $object->id);
1718 } elseif (!empty($projectidforalltimes)) {
1719 // Limit on one project
1720 $sql .= " AND pt.fk_projet IN (" . $db->sanitize((string) $projectidforalltimes) . ")";
1721 } elseif (!empty($allprojectforuser)) {
1722 // Limit on on user
1723 if (empty($search_user) && !empty($arrayfields['author']['checked'])) {
1724 $search_user = $user->id;
1725 }
1726 if ($search_user > 0) {
1727 $sql .= " AND t.fk_user = " . ((int) $search_user);
1728 }
1729 }
1730
1731 if ($search_note) {
1732 $sql .= natural_search('t.note', $search_note);
1733 }
1734 if ($search_task_ref) {
1735 $sql .= natural_search('pt.ref', $search_task_ref);
1736 }
1737 if (empty($arrayfields['s.name_alias']['checked']) && $search_company) {
1738 $sql .= natural_search(array("s.nom", "s.name_alias"), $search_company);
1739 } else {
1740 if ($search_company) {
1741 $sql .= natural_search('s.nom', $search_company);
1742 }
1743 if ($search_company_alias) {
1744 $sql .= natural_search('s.name_alias', $search_company_alias);
1745 }
1746 }
1747 if ($search_project_ref) {
1748 $sql .= natural_search('p.ref', $search_project_ref);
1749 }
1750 if ($search_project_label) {
1751 $sql .= natural_search('p.title', $search_project_label);
1752 }
1753 if ($search_task_label) {
1754 $sql .= natural_search('pt.label', $search_task_label);
1755 }
1756 if ($search_user > 0) {
1757 $sql .= natural_search('t.fk_user', $search_user, 2);
1758 }
1759 if (!empty($search_product_ref)) {
1760 $sql .= natural_search('prod.ref', $search_product_ref);
1761 }
1762 if ($search_valuebilled == '1') {
1763 $sql .= ' AND t.invoice_id > 0';
1764 }
1765 if ($search_valuebilled == '0') {
1766 $sql .= ' AND (t.invoice_id = 0 OR t.invoice_id IS NULL)';
1767 }
1768
1769 if ($search_date_start) {
1770 $sql .= " AND t.element_date >= '".$db->idate($search_date_start)."'";
1771 }
1772 if ($search_date_end) {
1773 $sql .= " AND t.element_date <= '".$db->idate($search_date_end)."'";
1774 }
1775
1776 if (!empty($arrayfields['t.element_duration']['checked'])) {
1777 if ($search_timespent_starthour || $search_timespent_startmin) {
1778 $timespent_duration_start = $search_timespent_starthour * 60 * 60; // We store duration in seconds
1779 $timespent_duration_start += ($search_timespent_startmin ? $search_timespent_startmin : 0) * 60; // We store duration in seconds
1780 $sql .= " AND t.element_duration >= " . $timespent_duration_start;
1781 }
1782
1783 if ($search_timespent_endhour || $search_timespent_endmin) {
1784 $timespent_duration_end = $search_timespent_endhour * 60 * 60; // We store duration in seconds
1785 $timespent_duration_end += ($search_timespent_endmin ? $search_timespent_endmin : 0) * 60; // We store duration in seconds
1786 $sql .= " AND t.element_duration <= " . $timespent_duration_end;
1787 }
1788 }
1789
1790 $sql .= dolSqlDateFilter('t.element_datehour', $search_day, $search_month, $search_year);
1791
1792 // Add where from extra fields
1793 $extrafieldsobjectkey = 'projet_task';
1794 $extrafieldsobjectprefix = 'efpt.';
1795 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
1796
1797 // Add where from hooks
1798 $parameters = array();
1799 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1800 $sql .= $hookmanager->resPrint;
1801
1802 // Count total nb of records
1803 $nbtotalofrecords = '';
1804 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
1805 /* The fast and low memory method to get and count full list converts the sql into a sql count */
1806 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
1807 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
1808 $resql = $db->query($sqlforcount);
1809 if ($resql) {
1810 $objforcount = $db->fetch_object($resql);
1811 $nbtotalofrecords = $objforcount->nbtotalofrecords;
1812 } else {
1813 dol_print_error($db);
1814 }
1815
1816 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
1817 $page = 0;
1818 $offset = 0;
1819 }
1820 $db->free($resql);
1821 }
1822
1823 // Complete request and execute it with limit
1824 $sql .= $db->order($sortfield, $sortorder);
1825 if ($limit) {
1826 $sql .= $db->plimit($limit + 1, $offset);
1827 }
1828
1829 $resql = $db->query($sql);
1830 if (!$resql) {
1831 dol_print_error($db);
1832 exit;
1833 }
1834
1835 $num = $db->num_rows($resql);
1836
1837 if ($num >= 0) {
1838 if (!empty($projectidforalltimes)) {
1839 print '<!-- List of time spent for project -->' . "\n";
1840
1841 $title = $langs->trans("ListTaskTimeUserProject");
1842
1843 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'clock', 0, $linktocreatetime, '', $limit, 0, 0, 1);
1844 } else {
1845 print '<!-- List of time spent -->' . "\n";
1846
1847 $title = $langs->trans("ListTaskTimeForTask");
1848
1849 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'clock', 0, $linktocreatetime, '', $limit, 0, 0, 1);
1850 }
1851
1852 $i = 0;
1853 while ($i < $num) {
1854 $row = $db->fetch_object($resql);
1855
1856 $tasks[$i] = $row;
1857
1858 $i++;
1859 }
1860 $db->free($resql);
1861 } else {
1862 dol_print_error($db);
1863 }
1864
1865 /*
1866 * Form to add a new line of time spent
1867 */
1868 if ($action == 'createtime' && $user->hasRight('projet', 'time')) {
1869 print '<!-- table to add time spent -->' . "\n";
1870 if (!empty($id)) {
1871 print '<input type="hidden" name="taskid" value="' . $id . '">';
1872 }
1873
1874 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
1875 print '<table class="noborder nohover centpercent">';
1876
1877 print '<tr class="liste_titre">';
1878 print '<td>' . $langs->trans("Date") . '</td>';
1879 if (!empty($allprojectforuser)) {
1880 print '<td>' . $langs->trans("Project") . '</td>';
1881 }
1882 if (empty($id)) {
1883 print '<td>' . $langs->trans("Task") . '</td>';
1884 }
1885 print '<td>' . $langs->trans("By") . '</td>';
1886 print '<td>' . $langs->trans("Note") . '</td>';
1887 print '<td>' . $langs->trans("NewTimeSpent") . '</td>';
1888 print '<td>' . $langs->trans("ProgressDeclared") . '</td>';
1889 if (!getDolGlobalString('PROJECT_HIDE_TASKS') && getDolGlobalString('PROJECT_BILL_TIME_SPENT')) {
1890 print '<td></td>';
1891
1892 if (isModEnabled("service") && !empty($projectstatic->thirdparty) && $projectstatic->thirdparty->id > 0 && $projectstatic->usage_bill_time) {
1893 print '<td>'.$langs->trans("Product").'</td>';
1894 }
1895 }
1896 // Hook fields
1897 $parameters = array('mode' => 'create');
1898 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1899 print $hookmanager->resPrint;
1900 print '<td></td>';
1901 print "</tr>\n";
1902
1903 print '<tr class="oddeven nohover">';
1904
1905 // Date
1906 print '<td class="maxwidthonsmartphone">';
1907 $newdate = '';
1908 print $form->selectDate($newdate, 'time', ($conf->browser->layout == 'phone' ? 2 : 1), 1, 2, "timespent_date", 1, 0);
1909 print '</td>';
1910
1911 if (!empty($allprojectforuser)) {
1912 print '<td>';
1913 // Add project selector
1914 print '</td>';
1915 }
1916
1917 // Task
1918 $nboftasks = 0;
1919 if (empty($id)) {
1920 print '<td class="maxwidthonsmartphone">';
1921 $nboftasks = $formproject->selectTasks(-1, GETPOSTINT('taskid'), 'taskid', 0, 0, '1', 1, 0, 0, 'maxwidth300', (string) $projectstatic->id, 'progress');
1922 print '</td>';
1923 }
1924
1925 // Contributor
1926 print '<td class="maxwidthonsmartphone nowraponall">';
1927 $contactsofproject = $projectstatic->getListContactId('internal');
1928 if (count($contactsofproject) > 0) {
1929 print img_object('', 'user', 'class="hideonsmartphone"');
1930 if (in_array($user->id, $contactsofproject)) {
1931 $userid = $user->id;
1932 } else {
1933 $userid = $contactsofproject[0];
1934 }
1935
1936 if ($projectstatic->public) {
1937 $contactsofproject = array();
1938 }
1939 print $form->select_dolusers((GETPOSTINT('userid') ? GETPOSTINT('userid') : $userid), 'userid', 0, null, 0, '', $contactsofproject, '0', 0, 0, '', 0, $langs->trans("ResourceNotAssignedToProject"), 'minwidth150imp maxwidth200');
1940 } else {
1941 if ($nboftasks) {
1942 print img_error($langs->trans('FirstAddRessourceToAllocateTime')) . ' ' . $langs->trans('FirstAddRessourceToAllocateTime');
1943 }
1944 }
1945 print '</td>';
1946
1947 // Note
1948 print '<td>';
1949 print '<textarea name="timespent_note" class="maxwidth100onsmartphone" rows="' . ROWS_2 . '">' . (GETPOST('timespent_note') ? GETPOST('timespent_note') : '') . '</textarea>';
1950 print '</td>';
1951
1952 // Duration - Time spent
1953 print '<td class="nowraponall">';
1954 $durationtouse = (GETPOST('timespent_duration') ? GETPOST('timespent_duration') : '');
1955 if (GETPOSTISSET('timespent_durationhour') || GETPOSTISSET('timespent_durationmin')) {
1956 $durationtouse = ((int) GETPOST('timespent_durationhour') * 3600 + (int) GETPOST('timespent_durationmin') * 60);
1957 }
1958 print $form->select_duration('timespent_duration', $durationtouse, 0, 'text');
1959 print '</td>';
1960
1961 // Progress declared
1962 print '<td class="nowrap">';
1963 print $formother->select_percent(GETPOST('progress') ? GETPOST('progress') : $object->progress, 'progress', 0, 5, 0, 100, 1);
1964 print '</td>';
1965
1966 // Invoiced
1967 if (!getDolGlobalString('PROJECT_HIDE_TASKS') && getDolGlobalString('PROJECT_BILL_TIME_SPENT')) {
1968 print '<td>';
1969 print '</td>';
1970
1971 if (isModEnabled("service") && !empty($projectstatic->thirdparty) && $projectstatic->thirdparty->id > 0 && $projectstatic->usage_bill_time) {
1972 print '<td class="nowraponall">';
1973 print img_picto('', 'service');
1974 print $form->select_produits((GETPOSTISSET('fk_product') ? GETPOSTINT("fk_product") : ''), 'fk_product', 1, 0, $projectstatic->thirdparty->price_level, 1, 2, '', 1, array(), $projectstatic->thirdparty->id, 'None', 0, 'maxwidth150', ($user->hasRight('produit', 'lire') ? 0 : 1), '', null, 1);
1975 print '</td>';
1976 }
1977 }
1978
1979 // Fields from hook
1980 $parameters = array('mode' => 'create');
1981 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1982 print $hookmanager->resPrint;
1983
1984 print '<td class="center">';
1985 $form->buttonsSaveCancel();
1986 print '<input type="submit" name="save" class="button buttongen smallpaddingimp marginleftonly margintoponlyshort marginbottomonlyshort button-add reposition" value="'.$langs->trans("Add").'">';
1987 print '<input type="submit" name="cancel" class="button buttongen smallpaddingimp marginleftonly margintoponlyshort marginbottomonlyshort button-cancel" value="'.$langs->trans("Cancel").'">';
1988 print '</td></tr>';
1989
1990 print '</table>';
1991 print '</div>';
1992
1993 print '<br>';
1994 }
1995
1996 $moreforfilter = '';
1997
1998 $parameters = array();
1999 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2000 if (empty($reshook)) {
2001 $moreforfilter .= $hookmanager->resPrint;
2002 } else {
2003 $moreforfilter = $hookmanager->resPrint;
2004 }
2005
2006 if (!empty($moreforfilter)) {
2007 print '<div class="liste_titre liste_titre_bydiv centpercent">';
2008 print $moreforfilter;
2009 print '</div>';
2010 }
2011
2012 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
2013 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
2014 $selectedfields .= (is_array($arrayofmassactions) && count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
2015
2016 // If project has usage "Bill time", we force visibility of field "billed"
2017 if ($projectstatic->usage_bill_time) {
2018 $arrayfields['valuebilled']['checked'] = 1;
2019 }
2020
2021 print '<!-- Liste of time spent -->'."\n";
2022 print '<div class="div-table-responsive">';
2023 print '<table class="tagtable nobottomiftotal liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n";
2024
2025 // Fields title search
2026 // --------------------------------------------------------------------
2027 print '<tr class="liste_titre_filter">';
2028 // Action column
2029 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2030 print '<td class="liste_titre center">';
2031 $searchpicto = $form->showFilterButtons('left');
2032 print $searchpicto;
2033 print '</td>';
2034 }
2035 // Date
2036 if (!empty($arrayfields['t.element_date']['checked'])) {
2037 print '<td class="liste_titre left">';
2038 print '<div class="nowrapfordate paddingright">';
2039 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
2040 print '</div>';
2041 print '<div class="nowrapfordate">';
2042 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
2043 print '</div>';
2044 print '</td>';
2045 }
2046 // Thirdparty
2047 if (!empty($arrayfields['p.fk_soc']['checked'])) {
2048 print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="$search_company" value="' . dol_escape_htmltag($search_company) . '"></td>';
2049 }
2050
2051 // Thirdparty alias
2052 if (!empty($arrayfields['s.name_alias']['checked'])) {
2053 print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="$search_company_alias" value="' . dol_escape_htmltag($search_company_alias) . '"></td>';
2054 }
2055
2056 if (!empty($allprojectforuser)) {
2057 if (!empty($arrayfields['p.project_ref']['checked'])) {
2058 print '<td class="liste_titre"><input type="text" class="flat maxwidth125" name="$search_project_ref" value="' . dol_escape_htmltag($search_project_ref) . '"></td>';
2059 }
2060 if (!empty($arrayfields['p.project_label']['checked'])) {
2061 print '<td class="liste_titre"><input type="text" class="flat maxwidth125" name="$search_project_label" value="' . dol_escape_htmltag($search_project_label) . '"></td>';
2062 }
2063 }
2064 // Task
2065 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2066 if (!empty($arrayfields['t.element_ref']['checked'])) {
2067 print '<td class="liste_titre"><input type="text" class="flat maxwidth125" name="search_task_ref" value="'.dol_escape_htmltag($search_task_ref).'"></td>';
2068 }
2069 if (!empty($arrayfields['t.element_label']['checked'])) {
2070 print '<td class="liste_titre"><input type="text" class="flat maxwidth125" name="search_task_label" value="'.dol_escape_htmltag($search_task_label).'"></td>';
2071 }
2072 }
2073 // Author
2074 if (!empty($arrayfields['author']['checked'])) {
2075 print '<td class="liste_titre">'.$form->select_dolusers(($search_user > 0 ? $search_user : -1), 'search_user', 1, null, 0, '', '', '0', 0, 0, '', 0, '', 'maxwidth125').'</td>';
2076 }
2077 // Note
2078 if (!empty($arrayfields['t.note']['checked'])) {
2079 print '<td class="liste_titre"><input type="text" class="flat maxwidth75" name="search_note" value="' . dol_escape_htmltag($search_note) . '"></td>';
2080 }
2081 // Duration
2082 if (!empty($arrayfields['t.element_duration']['checked'])) {
2083 // Duration - Time spent
2084 print '<td class="liste_titre right">';
2085
2086 $durationtouse_start = '';
2087 if ($search_timespent_starthour || $search_timespent_startmin) {
2088 $durationtouse_start = ($search_timespent_starthour * 3600 + $search_timespent_startmin * 60);
2089 }
2090 print '<div class="nowraponall">' . $langs->trans('from') . ' ';
2091 print $form->select_duration('search_timespent_duration_start', $durationtouse_start, 0, 'text', 0, 1);
2092 print '</div>';
2093
2094 $durationtouse_end = '';
2095 if ($search_timespent_endhour || $search_timespent_endmin) {
2096 $durationtouse_end = ($search_timespent_endhour * 3600 + $search_timespent_endmin * 60);
2097 }
2098 print '<div class="nowraponall">' . $langs->trans('to') . ' ';
2099 print $form->select_duration('search_timespent_duration_end', $durationtouse_end, 0, 'text', 0, 1);
2100 print '</div>';
2101
2102 print '</td>';
2103 }
2104 // Product
2105 if (!empty($arrayfields['t.fk_product']['checked'])) {
2106 print '<td class="liste_titre right"></td>';
2107 }
2108 // Value in main currency
2109 if (!empty($arrayfields['value']['checked'])) {
2110 print '<td class="liste_titre"></td>';
2111 }
2112 // Value billed
2113 if (!empty($arrayfields['valuebilled']['checked'])) {
2114 print '<td class="liste_titre center">' . $form->selectyesno('search_valuebilled', $search_valuebilled, 1, false, 1) . '</td>';
2115 }
2116
2117 // Extra fields
2118 $extrafieldsobjectkey = 'projet_task';
2119 $extrafieldsobjectprefix = 'ef.';
2120 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
2121 // Fields from hook
2122 $parameters = array('arrayfields' => $arrayfields);
2123 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2124 print $hookmanager->resPrint;
2125 // Action column
2126 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2127 print '<td class="liste_titre center">';
2128 $searchpicto = $form->showFilterButtons();
2129 print $searchpicto;
2130 print '</td>';
2131 }
2132 print '</tr>' . "\n";
2133
2134
2135 $totalarray = array();
2136 $totalarray['nbfield'] = 0;
2137
2138 // Fields title label
2139 // --------------------------------------------------------------------
2140 print '<tr class="liste_titre">';
2141 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2142 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center maxwidthsearch ');
2143 $totalarray['nbfield']++;
2144 }
2145 if (!empty($arrayfields['t.element_date']['checked'])) {
2146 print_liste_field_titre($arrayfields['t.element_date']['label'], $_SERVER['PHP_SELF'], 't.element_date,t.element_datehour,t.rowid', '', $param, '', $sortfield, $sortorder);
2147 $totalarray['nbfield']++;
2148 }
2149 if (!empty($arrayfields['p.fk_soc']['checked'])) {
2150 print_liste_field_titre($arrayfields['p.fk_soc']['label'], $_SERVER['PHP_SELF'], 't.element_date,t.element_datehour,t.rowid', '', $param, '', $sortfield, $sortorder);
2151 $totalarray['nbfield']++;
2152 }
2153 if (!empty($arrayfields['s.name_alias']['checked'])) {
2154 // @phan-suppress-next-line PhanTypeInvalidDimOffset
2155 print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER['PHP_SELF'], 's.name_alias', '', $param, '', $sortfield, $sortorder);
2156 $totalarray['nbfield']++;
2157 }
2158 if (!empty($allprojectforuser)) {
2159 if (!empty($arrayfields['p.project_ref']['checked'])) {
2160 print_liste_field_titre($arrayfields['p.project_ref']['label'], $_SERVER['PHP_SELF'], 'p.ref', '', $param, '', $sortfield, $sortorder);
2161 $totalarray['nbfield']++;
2162 }
2163 if (!empty($arrayfields['p.project_label']['checked'])) {
2164 print_liste_field_titre($arrayfields['p.project_label']['label'], $_SERVER['PHP_SELF'], 'p.title', '', $param, '', $sortfield, $sortorder);
2165 $totalarray['nbfield']++;
2166 }
2167 }
2168 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2169 if (!empty($arrayfields['t.element_ref']['checked'])) {
2170 print_liste_field_titre($arrayfields['t.element_ref']['label'], $_SERVER['PHP_SELF'], 'pt.ref', '', $param, '', $sortfield, $sortorder);
2171 $totalarray['nbfield']++;
2172 }
2173 if (!empty($arrayfields['t.element_label']['checked'])) {
2174 print_liste_field_titre($arrayfields['t.element_label']['label'], $_SERVER['PHP_SELF'], 'pt.label', '', $param, '', $sortfield, $sortorder);
2175 $totalarray['nbfield']++;
2176 }
2177 }
2178 if (!empty($arrayfields['author']['checked'])) {
2179 print_liste_field_titre($arrayfields['author']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
2180 $totalarray['nbfield']++;
2181 }
2182 if (!empty($arrayfields['t.note']['checked'])) {
2183 print_liste_field_titre($arrayfields['t.note']['label'], $_SERVER['PHP_SELF'], 't.note', '', $param, '', $sortfield, $sortorder);
2184 $totalarray['nbfield']++;
2185 }
2186 if (!empty($arrayfields['t.element_duration']['checked'])) {
2187 print_liste_field_titre($arrayfields['t.element_duration']['label'], $_SERVER['PHP_SELF'], 't.element_duration', '', $param, '', $sortfield, $sortorder, 'right ');
2188 $totalarray['nbfield']++;
2189 }
2190 if (!empty($arrayfields['t.fk_product']['checked'])) {
2191 print_liste_field_titre($arrayfields['t.fk_product']['label'], $_SERVER['PHP_SELF'], 't.fk_product', '', $param, '', $sortfield, $sortorder);
2192 $totalarray['nbfield']++;
2193 }
2194
2195 if (!empty($arrayfields['value']['checked'])) {
2196 print_liste_field_titre($arrayfields['value']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
2197 $totalarray['nbfield']++;
2198 }
2199 if (!empty($arrayfields['valuebilled']['checked'])) {
2200 print_liste_field_titre($arrayfields['valuebilled']['label'], $_SERVER['PHP_SELF'], 'il.total_ht', '', $param, '', $sortfield, $sortorder, 'center ', $langs->trans("SelectLinesOfTimeSpentToInvoice"));
2201 $totalarray['nbfield']++;
2202 }
2203 // Extra fields
2204 $extrafieldsobjectkey = 'projet_task';
2205 $extrafieldsobjectprefix = 'ef.';
2206 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
2207 // Hook fields
2208 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
2209 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2210 print $hookmanager->resPrint;
2211 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2212 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center maxwidthsearch ');
2213 $totalarray['nbfield']++;
2214 }
2215 print "</tr>\n";
2216
2217 $tasktmp = new Task($db);
2218 $tmpinvoice = new Facture($db);
2219
2220 if ($page) {
2221 $param .= '&page='.((int) $page);
2222 }
2223 $param .= '&sortfield='.urlencode($sortfield).'&sortorder='.urlencode($sortorder);
2224
2225 $i = 0;
2226
2227 $savnbfield = $totalarray['nbfield'];
2228 $totalarray = array();
2229 $totalarray['nbfield'] = 0;
2230 //$imaxinloop = ($limit ? min($num, $limit) : $num);
2231 foreach ($tasks as $task_time) {
2232 if ($i >= $limit) {
2233 break;
2234 }
2235
2236 // Line is invoiced if it has an invoice_id
2237 $invoiced = $task_time->invoice_id ? true : false;
2238
2239 $date1 = $db->jdate($task_time->element_date);
2240 $date2 = $db->jdate($task_time->element_datehour);
2241
2242 // Show here line of result
2243 $j = 0;
2244 print '<tr data-rowid="'.$task_time->rowid.'" class="oddeven">';
2245
2246 // Action column
2247 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2248 print '<td class="center nowraponall">';
2249 if (($action == 'editline' || $action == 'splitline') && GETPOSTINT('lineid') == $task_time->rowid) {
2250 print '<input type="hidden" name="lineid" value="' . GETPOSTINT('lineid') . '">';
2251 if ($id) {
2252 print '<input type="hidden" name="id" value="' . $id . '">'; // If you enable this, the edit will go beack to task view
2253 }
2254 print '<input type="submit" class="button buttongen reposition smallpaddingimp margintoponlyshort marginbottomonlyshort button-save" name="save" value="'.$langs->trans("Save").'">';
2255 print '<br>';
2256 print '<input type="submit" class="button buttongen reposition smallpaddingimp margintoponlyshort marginbottomonlyshort button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
2257 } elseif ($user->hasRight('projet', 'time') || $user->hasRight('projet', 'all', 'creer')) { // Read project and enter time consumed on assigned tasks
2258 if (in_array($task_time->fk_user, $childids) || $user->hasRight('projet', 'all', 'creer')) {
2259 print '<a class="reposition editfielda" href="'.$_SERVER["PHP_SELF"].'?'.($withproject ? 'id='.$task_time->fk_element : '').'&action=editline&token='.newToken().'&lineid='.$task_time->rowid.$param.((empty($id) || $tab == 'timespent') ? '&tab=timespent' : '').'">';
2260 print img_edit('default', 0, 'class="pictofixedwidth paddingleft"');
2261 print '</a>';
2262
2263 if (getDolGlobalString('PROJECT_ALLOW_SPLIT_TIMESPENT')) {
2264 print '<a class="reposition editfielda paddingleft" href="' . $_SERVER["PHP_SELF"] . '?action=splitline&token=' . newToken() . '&lineid=' . $task_time->rowid . $param . ((empty($id) || $tab == 'timespent') ? '&tab=timespent' : '') . '">';
2265 print img_split('', 'class="pictofixedwidth paddingleft"');
2266 print '</a>';
2267 }
2268
2269 print '<a class="reposition paddingleft" href="'.$_SERVER["PHP_SELF"].'?'.($withproject ? 'id='.$task_time->fk_element : '').'&action=deleteline&token='.newToken().'&lineid='.$task_time->rowid.$param.((empty($id) || $tab == 'timespent') ? '&tab=timespent' : '').'">';
2270 print img_delete('default', 'class="pictodelete paddingleft"');
2271 print '</a>';
2272
2273 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2274 $selected = 0;
2275 if (in_array($task_time->rowid, $arrayofselected)) {
2276 $selected = 1;
2277 }
2278 print '&nbsp;';
2279
2280 // Disable select if task not billable or already invoiced
2281 $disabled = (intval($task_time->billable) != 1 || $invoiced);
2282 $ctrl = '<input '.($disabled ? 'disabled' : '').' id="cb' . $task_time->rowid . '" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="' . $task_time->rowid . '"' . ($selected ? ' checked="checked"' : '') . '>';
2283 if ($disabled) {
2284 // If disabled, a dbl-click very close outside the control
2285 // will re-enable it, so that user is not blocked if needed.
2286 print '<span id="cbsp'. $task_time->rowid . '">'.$ctrl.'</span>';
2287 print '<script>$("#cbsp' . $task_time->rowid . '").dblclick(()=>{ $("#cb' . $task_time->rowid . '").removeAttr("disabled") })</script>';
2288 } else {
2289 print $ctrl;
2290 }
2291 }
2292 }
2293 }
2294 print '</td>';
2295 if (!$i) {
2296 $totalarray['nbfield']++;
2297 }
2298 }
2299
2300 // Date
2301 if (!empty($arrayfields['t.element_date']['checked'])) {
2302 print '<td class="nowrap">';
2303 if ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) {
2304 if (empty($task_time->element_date_withhour)) {
2305 print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 4, 3, 2, "timespent_date", 1, 0);
2306 } else {
2307 print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 2, 1, 2, "timespent_date", 1, 0);
2308 }
2309 } else {
2310 print dol_print_date(($date2 ? $date2 : $date1), ($task_time->element_date_withhour ? 'dayhour' : 'day'));
2311 }
2312 print '</td>';
2313 if (!$i) {
2314 $totalarray['nbfield']++;
2315 }
2316 }
2317
2318 // Thirdparty
2319 if (!empty($arrayfields['p.fk_soc']['checked'])) {
2320 print '<td class="tdoverflowmax125">';
2321 if ($task_time->fk_soc > 0) {
2322 if (empty($conf->cache['thirdparty'][$task_time->fk_soc])) {
2323 $tmpsociete = new Societe($db);
2324 $tmpsociete->fetch($task_time->fk_soc);
2325 $conf->cache['thirdparty'][$task_time->fk_soc] = $tmpsociete;
2326 } else {
2327 $tmpsociete = $conf->cache['thirdparty'][$task_time->fk_soc];
2328 }
2329 print $tmpsociete->getNomUrl(1, '', 100, 0, 1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
2330 }
2331 print '</td>';
2332 if (!$i) {
2333 $totalarray['nbfield']++;
2334 }
2335 }
2336
2337 // Thirdparty alias
2338 if (!empty($arrayfields['s.name_alias']['checked'])) {
2339 $valtoshow = '';
2340 if ($task_time->fk_soc > 0) {
2341 if (empty($conf->cache['thirdparty'][$task_time->fk_soc])) {
2342 $tmpsociete = new Societe($db);
2343 $tmpsociete->fetch($task_time->fk_soc);
2344 $conf->cache['thirdparty'][$task_time->fk_soc] = $tmpsociete;
2345 } else {
2346 $tmpsociete = $conf->cache['thirdparty'][$task_time->fk_soc];
2347 }
2348 $valtoshow = $tmpsociete->name_alias;
2349 }
2350 print '<td class="nowrap tdoverflowmax150" title="'.dol_escape_htmltag($valtoshow).'">';
2351 print $valtoshow;
2352 print '</td>';
2353 if (!$i) {
2354 $totalarray['nbfield']++;
2355 }
2356 }
2357
2358 if (!empty($allprojectforuser)) {
2359 // Project ref
2360 if (!empty($arrayfields['p.project_ref']['checked'])) {
2361 if (empty($conf->cache['project'][$task_time->fk_projet])) {
2362 $tmpproject = new Project($db);
2363 $tmpproject->fetch($task_time->fk_projet);
2364 $conf->cache['project'][$task_time->fk_projet] = $tmpproject;
2365 } else {
2366 $tmpproject = $conf->cache['project'][$task_time->fk_projet];
2367 }
2368 print '<td class="nowraponall">';
2369 print $tmpproject->getNomUrl(1);
2370 print '</td>';
2371 if (!$i) {
2372 $totalarray['nbfield']++;
2373 }
2374 }
2375 // Project label
2376 if (!empty($arrayfields['p.project_label']['checked'])) {
2377 if (empty($conf->cache['project'][$task_time->fk_projet])) {
2378 $tmpproject = new Project($db);
2379 $tmpproject->fetch($task_time->fk_projet);
2380 $conf->cache['project'][$task_time->fk_projet] = $tmpproject;
2381 } else {
2382 $tmpproject = $conf->cache['project'][$task_time->fk_projet];
2383 }
2384 print '<td class="tdoverflowmax250" title="'.dolPrintHTMLForAttribute($tmpproject->title).'">';
2385 if (!empty($arrayfields['p.project_ref']['checked'])) {
2386 print dolPrintHTML($tmpproject->title);
2387 } else {
2388 print $tmpproject->getNomUrl(1, '', -1);
2389 }
2390 print '</td>';
2391 if (!$i) {
2392 $totalarray['nbfield']++;
2393 }
2394 }
2395 }
2396
2397 // Task ref
2398 if (!empty($arrayfields['t.element_ref']['checked'])) {
2399 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2400 print '<td class="nowrap">';
2401 if ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) {
2402 $formproject->selectTasks(-1, GETPOSTINT('taskid') ? GETPOSTINT('taskid') : $task_time->fk_element, 'taskid', 0, 0, '1', 1, 0, 0, 'maxwidth250', (string) $projectstatic->id, '');
2403 } else {
2404 $tasktmp->id = $task_time->fk_element;
2405 $tasktmp->ref = $task_time->ref;
2406 $tasktmp->label = $task_time->label;
2407 print $tasktmp->getNomUrl(1, 'withproject', 'time');
2408 }
2409 print '</td>';
2410 if (!$i) {
2411 $totalarray['nbfield']++;
2412 }
2413 }
2414 } elseif ($action !== 'createtime') {
2415 print '<input type="hidden" name="taskid" value="' . $id . '">';
2416 }
2417
2418 // Task label
2419 if (!empty($arrayfields['t.element_label']['checked'])) {
2420 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2421 print '<td class="tdoverflowmax250" title="'.dolPrintHTMLForAttribute($task_time->label).'">';
2422 if (!empty($arrayfields['t.element_ref']['checked'])) {
2423 print dolPrintHTML($task_time->label);
2424 } else {
2425 $tasktmp->id = $task_time->fk_element;
2426 $tasktmp->ref = $task_time->ref;
2427 $tasktmp->label = $task_time->label;
2428 print $tasktmp->getNomUrl(1, 'withproject', 'time', -1);
2429 }
2430 print '</td>';
2431 if (!$i) {
2432 $totalarray['nbfield']++;
2433 }
2434 }
2435 }
2436
2437 // User
2438 if (!empty($arrayfields['author']['checked'])) {
2439 print '<td class="tdoverflowmax125">';
2440 if ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) {
2441 // Here $object is task. TODO Add a cache
2442 if (empty($object->id)) {
2443 $object->fetch($task_time->fk_element);
2444 }
2445 $contactsoftask = $object->getListContactId('internal');
2446 if (!in_array($task_time->fk_user, $contactsoftask)) {
2447 $contactsoftask[] = $task_time->fk_user;
2448 }
2449 if (count($contactsoftask) > 0) {
2450 print img_object('', 'user', 'class="pictofixedwidth hideonsmartphone"');
2451 print $form->select_dolusers($task_time->fk_user, 'userid_line', 0, null, 0, '', $contactsoftask, '0', 0, 0, '', 0, '', 'minwidth100 maxwidth100'); // maxwidth must be lowed than minwidth of the td
2452 } else {
2453 print img_error($langs->trans('FirstAddRessourceToAllocateTime')) . $langs->trans('FirstAddRessourceToAllocateTime');
2454 }
2455 } else {
2456 $userstatic->id = $task_time->fk_user;
2457 $userstatic->lastname = $task_time->lastname;
2458 $userstatic->firstname = $task_time->firstname;
2459 $userstatic->photo = $task_time->photo;
2460 $userstatic->gender = $task_time->gender;
2461 $userstatic->status = $task_time->user_status;
2462
2463 print $userstatic->getNomUrl(-1);
2464 }
2465 print '</td>';
2466 if (!$i) {
2467 $totalarray['nbfield']++;
2468 }
2469 }
2470
2471 // Note
2472 if (!empty($arrayfields['t.note']['checked'])) {
2473 if ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) {
2474 print '<td class="small">';
2475 print '<textarea name="timespent_note_line" class="centpercentimp" rows="' . ROWS_2 . '">' . dol_escape_htmltag($task_time->note, 0, 1) . '</textarea>';
2476 print '</td>';
2477 } else {
2478 print '<td class="small tdoverflowmax150 classfortooltip" title="'.dol_string_onlythesehtmltags(dol_htmlentitiesbr($task_time->note)).'">';
2479 print dolGetFirstLineOfText($task_time->note);
2480 print '</td>';
2481 }
2482 if (!$i) {
2483 $totalarray['nbfield']++;
2484 }
2485 } elseif ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) {
2486 print '<input type="hidden" name="timespent_note_line" value="' . dol_escape_htmltag($task_time->note, 0, 1) . '">';
2487 }
2488
2489 // Time spent
2490 if (!empty($arrayfields['t.element_duration']['checked'])) {
2491 print '<td class="right nowraponall">';
2492 if ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) {
2493 print '<input type="hidden" name="old_duration" value="'.$task_time->element_duration.'">';
2494 print $form->select_duration('new_duration', $task_time->element_duration, 0, 'text');
2495 } else {
2496 print convertSecondToTime($task_time->element_duration, 'allhourmin');
2497 }
2498 print '</td>';
2499 if (!$i) {
2500 $totalarray['nbfield']++;
2501 }
2502 if (!$i) {
2503 $totalarray['pos'][$totalarray['nbfield']] = 't.element_duration';
2504 }
2505 if (empty($totalarray['val']['t.element_duration'])) {
2506 $totalarray['val']['t.element_duration'] = $task_time->element_duration;
2507 } else {
2508 $totalarray['val']['t.element_duration'] += $task_time->element_duration;
2509 }
2510 if (!$i) {
2511 $totalarray['totaldurationfield'] = $totalarray['nbfield'];
2512 }
2513 if (empty($totalarray['totalduration'])) {
2514 $totalarray['totalduration'] = $task_time->element_duration;
2515 } else {
2516 $totalarray['totalduration'] += $task_time->element_duration;
2517 }
2518 }
2519
2520 // Product
2521 if (!empty($arrayfields['t.fk_product']['checked'])) {
2522 print '<td class="nowraponall">';
2523 if ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) {
2524 print img_picto('', 'service');
2525 print $form->select_produits($task_time->fk_product, 'fk_product', 1, 0, $projectstatic->thirdparty->price_level, 1, 2, '', 1, array(), $projectstatic->thirdparty->id, 'None', 0, 'maxwidth500', ($user->hasRight('produit', 'lire') ? 0 : 1), '', null, 1);
2526 } elseif (!empty($task_time->fk_product)) {
2527 $product = new Product($db);
2528 $resultFetch = $product->fetch($task_time->fk_product);
2529 if ($resultFetch < 0) {
2530 setEventMessages($product->error, $product->errors, 'errors');
2531 } else {
2532 print $product->getNomUrl(1);
2533 }
2534 }
2535 print '</td>';
2536 if (!$i) {
2537 $totalarray['nbfield']++;
2538 }
2539 }
2540
2541 // Value spent
2542 if (!empty($arrayfields['value']['checked'])) {
2543 $langs->load("salaries");
2544 $value = price2num($task_time->thm * $task_time->element_duration / 3600, 'MT', 1);
2545
2546 print '<td class="nowraponall right">';
2547 print '<span class="amount" title="' . $langs->trans("THM") . ': ' . price($task_time->thm) . '">';
2548 print price($value, 1, $langs, 1, -1, -1, $conf->currency);
2549 print '</span>';
2550 print '</td>';
2551 if (!$i) {
2552 $totalarray['nbfield']++;
2553 }
2554 if (!$i) {
2555 $totalarray['pos'][$totalarray['nbfield']] = 'value';
2556 }
2557 if (empty($totalarray['val']['value'])) {
2558 $totalarray['val']['value'] = $value;
2559 } else {
2560 $totalarray['val']['value'] += $value;
2561 }
2562 if (!$i) {
2563 $totalarray['totalvaluefield'] = $totalarray['nbfield'];
2564 }
2565 if (empty($totalarray['totalvalue'])) {
2566 $totalarray['totalvalue'] = $value;
2567 } else {
2568 $totalarray['totalvalue'] += $value;
2569 }
2570 }
2571
2572 // Invoiced
2573 if (!empty($arrayfields['valuebilled']['checked'])) {
2574 print '<td class="center">'; // invoice_id and invoice_line_id
2575 if (!getDolGlobalString('PROJECT_HIDE_TASKS') && getDolGlobalString('PROJECT_BILL_TIME_SPENT')) {
2576 if ($projectstatic->usage_bill_time) {
2577 if ($task_time->invoice_id) {
2578 $result = $tmpinvoice->fetch($task_time->invoice_id);
2579 if ($result > 0) {
2580 if ($user->hasRight('facture', 'lire')) {
2581 if ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) {
2582 print $formproject->selectInvoiceAndLine($task_time->invoice_id, $task_time->invoice_line_id, 'invoiceid', 'invoicelineid', 'maxwidth500', array('p.rowid' => $projectstatic->id));
2583 } else {
2584 print $tmpinvoice->getNomUrl(1);
2585 if (!empty($task_time->invoice_line_id)) {
2586 $invoiceLine = new FactureLigne($db);
2587 $invoiceLine->fetch($task_time->invoice_line_id);
2588 if (!empty($invoiceLine->id)) {
2589 print '<br><span class="small opacitymedium">'.$langs->trans('Qty').':'.$invoiceLine->qty;
2590 print ' '.$langs->trans('TotalHT').':'.price($invoiceLine->total_ht);
2591 print '</span>';
2592 }
2593 }
2594 }
2595 } else {
2596 print $langs->trans("Yes");
2597 }
2598 }
2599 $invoiced = true;
2600 } else {
2601 if (intval($task_time->billable) == 1) {
2602 print $langs->trans("No");
2603 } else {
2604 print $langs->trans("Disabled");
2605 }
2606 }
2607 } else {
2608 print '<span class="opacitymedium">' . $langs->trans("NA") . '</span>';
2609 }
2610 }
2611 print '</td>';
2612 if (!$i) {
2613 $totalarray['nbfield']++;
2614 }
2615 }
2616
2617 // Extra fields
2618 $obj = $task_time;
2619 $extrafieldsobjectkey = 'projet_task';
2620 $extrafieldsobjectprefix = 'ef.';
2621 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
2622
2623 // Fields from hook
2624 $parameters = array('arrayfields' => $arrayfields, 'obj' => $task_time, 'i' => $i, 'totalarray' => &$totalarray);
2625 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2626 print $hookmanager->resPrint;
2627
2628 // Action column
2629 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2630 print '<td class="center nowraponall">';
2631 if (($action == 'editline' || $action == 'splitline') && GETPOSTINT('lineid') == $task_time->rowid) {
2632 print '<input type="hidden" name="lineid" value="'.GETPOSTINT('lineid').'">';
2633 print '<input type="submit" class="button buttongen smallpaddingimp margintoponlyshort marginbottomonlyshort button-save" name="save" value="'.$langs->trans("Save").'">';
2634 print '<br>';
2635 print '<input type="submit" class="button buttongen smallpaddingimp margintoponlyshort marginbottomonlyshort button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
2636 } elseif ($user->hasRight('projet', 'time') || $user->hasRight('projet', 'all', 'creer')) { // Read project and enter time consumed on assigned tasks
2637 if (in_array($task_time->fk_user, $childids) || $user->hasRight('projet', 'all', 'creer')) {
2638 print '<a class="reposition editfielda" href="'.$_SERVER["PHP_SELF"].'?'.($withproject ? 'id='.$task_time->fk_element : '').'&action=editline&token='.newToken().'&lineid='.$task_time->rowid.$param.((empty($id) || $tab == 'timespent') ? '&tab=timespent' : '').'">';
2639 print img_edit('default', 0, 'class="pictofixedwidth paddingleft"');
2640 print '</a>';
2641
2642 if (getDolGlobalString('PROJECT_ALLOW_SPLIT_TIMESPENT')) {
2643 print '<a class="reposition editfielda paddingleft" href="' . $_SERVER["PHP_SELF"] . '?action=splitline&token=' . newToken() . '&lineid=' . $task_time->rowid . $param . ((empty($id) || $tab == 'timespent') ? '&tab=timespent' : '') . '">';
2644 print img_split('', 'class="pictofixedwidth paddingleft"');
2645 print '</a>';
2646 }
2647
2648 print '<a class="reposition paddingleft" href="'.$_SERVER["PHP_SELF"].'?'.($withproject ? 'id='.$task_time->fk_element : '').'&action=deleteline&token='.newToken().'&lineid='.$task_time->rowid.$param.((empty($id) || $tab == 'timespent') ? '&tab=timespent' : '').'">';
2649 print img_delete('default', 'class="pictodelete paddingleft"');
2650 print '</a>';
2651
2652 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2653 $selected = 0;
2654 if (in_array($task_time->rowid, $arrayofselected)) {
2655 $selected = 1;
2656 }
2657 print '&nbsp;';
2658
2659 // Disable select if task not billable or already invoiced
2660 $disabled = (intval($task_time->billable) != 1 || $invoiced);
2661 $ctrl = '<input '.($disabled ? 'disabled' : '').' id="cb' . $task_time->rowid . '" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="' . $task_time->rowid . '"' . ($selected ? ' checked="checked"' : '') . '>';
2662 if ($disabled) {
2663 // If disabled, a dbl-click very close outside the control
2664 // will re-enable it, so that user is not blocked if needed.
2665 print '<span id="cbsp'. $task_time->rowid . '">'.$ctrl.'</span>';
2666 print '<script>$("#cbsp' . $task_time->rowid . '").dblclick(()=>{ $("#cb' . $task_time->rowid . '").removeAttr("disabled") })</script>';
2667 } else {
2668 print $ctrl;
2669 }
2670 }
2671 }
2672 }
2673 print '</td>';
2674 if (!$i) {
2675 $totalarray['nbfield']++;
2676 }
2677 }
2678
2679 print "</tr>\n";
2680
2681
2682 // Add the lines for the split feature
2683
2684 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2685 print '<!-- first line -->';
2686 print '<tr class="oddeven">';
2687
2688 // Action column
2689 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2690 print '<td></td>';
2691 }
2692
2693 // Date
2694 if (!empty($arrayfields['t.element_date']['checked'])) {
2695 print '<td class="nowrap">';
2696 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2697 if (empty($task_time->element_date_withhour)) {
2698 print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 3, 3, 2, "timespent_date", 1, 0);
2699 } else {
2700 print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 1, 1, 2, "timespent_date", 1, 0);
2701 }
2702 } else {
2703 print dol_print_date(($date2 ? $date2 : $date1), ($task_time->element_date_withhour ? 'dayhour' : 'day'));
2704 }
2705 print '</td>';
2706 }
2707
2708 // Thirdparty
2709 if (!empty($arrayfields['p.fk_soc']['checked'])) {
2710 print '<td class="nowrap">';
2711 print '</td>';
2712 }
2713
2714 // Thirdparty alias
2715 if (!empty($arrayfields['s.name_alias']['checked'])) {
2716 print '<td class="nowrap">';
2717 print '</td>';
2718 }
2719
2720 // Project ref
2721 if (!empty($allprojectforuser)) {
2722 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2723 print '<td class="nowrap">';
2724 print '</td>';
2725 }
2726 }
2727
2728 // Task ref
2729 if (!empty($arrayfields['t.element_ref']['checked'])) {
2730 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2731 print '<td class="nowrap">';
2732 $tasktmp->id = $task_time->fk_element;
2733 $tasktmp->ref = $task_time->ref;
2734 $tasktmp->label = $task_time->label;
2735 print $tasktmp->getNomUrl(1, 'withproject', 'time');
2736 print '</td>';
2737 }
2738 }
2739
2740 // Task label
2741 if (!empty($arrayfields['t.element_label']['checked'])) {
2742 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2743 print '<td class="tdoverflowmax300" title="'.dol_escape_htmltag($task_time->label).'">';
2744 print dol_escape_htmltag($task_time->label);
2745 print '</td>';
2746 }
2747 }
2748
2749 // User
2750 if (!empty($arrayfields['author']['checked'])) {
2751 print '<td class="nowraponall">';
2752 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2753 if (empty($object->id)) {
2754 $idTask = (!empty($id)) ? $id : $task_time->fk_element;
2755 $object->fetch($idTask);
2756 }
2757 $contactsoftask = $object->getListContactId('internal');
2758 if (!in_array($task_time->fk_user, $contactsoftask)) {
2759 $contactsoftask[] = $task_time->fk_user;
2760 }
2761 if (count($contactsoftask) > 0) {
2762 print img_object('', 'user', 'class="hideonsmartphone"');
2763 print $form->select_dolusers($task_time->fk_user, 'userid_line', 0, null, 0, '', $contactsoftask);
2764 } else {
2765 print img_error($langs->trans('FirstAddRessourceToAllocateTime')) . $langs->trans('FirstAddRessourceToAllocateTime');
2766 }
2767 } else {
2768 $userstatic->id = $task_time->fk_user;
2769 $userstatic->lastname = $task_time->lastname;
2770 $userstatic->firstname = $task_time->firstname;
2771 $userstatic->photo = $task_time->photo;
2772 $userstatic->status = $task_time->user_status;
2773 print $userstatic->getNomUrl(-1);
2774 }
2775 print '</td>';
2776 }
2777
2778 // Note
2779 if (!empty($arrayfields['t.note']['checked'])) {
2780 print '<td class="tdoverflowmax300">';
2781 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2782 print '<textarea name="timespent_note_line" class="centpercentimp" rows="' . ROWS_2 . '">' . dol_escape_htmltag($task_time->note, 0, 1) . '</textarea>';
2783 } else {
2784 print dol_nl2br($task_time->note);
2785 }
2786 print '</td>';
2787 } elseif ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2788 print '<input type="hidden" name="timespent_note_line" rows="' . ROWS_2 . '" value="' . dol_escape_htmltag($task_time->note, 0, 1) . '">';
2789 }
2790
2791 // Time spent
2792 if (!empty($arrayfields['t.element_duration']['checked'])) {
2793 print '<td class="right">';
2794 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2795 print '<input type="hidden" name="old_duration" value="'.$task_time->element_duration.'">';
2796 print $form->select_duration('new_duration', $task_time->element_duration, 0, 'text');
2797 } else {
2798 print convertSecondToTime($task_time->element_duration, 'allhourmin');
2799 }
2800 print '</td>';
2801 }
2802
2803 // Product
2804 if (!empty($arrayfields['t.fk_product']['checked'])) {
2805 print '<td class="nowraponall tdoverflowmax125">';
2806 print '</td>';
2807 }
2808
2809 // Value spent
2810 if (!empty($arrayfields['value']['checked'])) {
2811 print '<td class="right">';
2812 print '<span class="amount">';
2813 $value = price2num($task_time->thm * $task_time->element_duration / 3600, 'MT', 1);
2814 print price($value, 1, $langs, 1, -1, -1, $conf->currency);
2815 print '</span>';
2816 print '</td>';
2817 }
2818
2819 // Value billed
2820 if (!empty($arrayfields['valuebilled']['checked'])) {
2821 print '<td class="right">';
2822 $valuebilled = price2num($task_time->total_ht, '', 1);
2823 if (isset($task_time->total_ht)) {
2824 print price($valuebilled, 1, $langs, 1, -1, -1, $conf->currency);
2825 }
2826 print '</td>';
2827 }
2828
2829 // Extra fields
2830 $obj = $task_time;
2831 $extrafieldsobjectkey = 'projet_task';
2832 $extrafieldsobjectprefix = 'ef.';
2833 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
2834
2835 // Fields from hook
2836 $parameters = array('arrayfields' => $arrayfields, 'obj' => $task_time, 'mode' => 'split1');
2837 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2838 print $hookmanager->resPrint;
2839
2840 // Action column
2841 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2842 print '<td class="center nowraponall">';
2843 print '</td>';
2844 }
2845
2846 print "</tr>\n";
2847
2848
2849 // Line for second dispatching
2850
2851 print '<!-- second line --><tr class="oddeven">';
2852
2853 // Action column
2854 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2855 print '<td class="center nowraponall">';
2856 print '</td>';
2857 }
2858
2859 // Date
2860 if (!empty($arrayfields['t.element_date']['checked'])) {
2861 print '<td class="nowraponall">';
2862 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2863 if (empty($task_time->element_date_withhour)) {
2864 print $form->selectDate(($date2 ? $date2 : $date1), 'timeline_2', 3, 3, 2, "timespent_date", 1, 0);
2865 } else {
2866 print $form->selectDate(($date2 ? $date2 : $date1), 'timeline_2', 1, 1, 2, "timespent_date", 1, 0);
2867 }
2868 } else {
2869 print dol_print_date(($date2 ? $date2 : $date1), ($task_time->element_date_withhour ? 'dayhour' : 'day'));
2870 }
2871 print '</td>';
2872 }
2873
2874 // Thirdparty
2875 if (!empty($arrayfields['p.fk_soc']['checked'])) {
2876 print '<td>';
2877 print '</td>';
2878 }
2879
2880 // Thirdparty alias
2881 if (!empty($arrayfields['s.name_alias']['checked'])) {
2882 print '<td>';
2883 print '</td>';
2884 }
2885
2886 // Project ref
2887 if (!empty($allprojectforuser)) {
2888 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2889 print '<td>';
2890 print '</td>';
2891 }
2892 }
2893
2894 // Task ref
2895 if (!empty($arrayfields['t.element_ref']['checked'])) {
2896 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2897 print '<td class="nowraponall">';
2898 $tasktmp->id = $task_time->fk_element;
2899 $tasktmp->ref = $task_time->ref;
2900 $tasktmp->label = $task_time->label;
2901 print $tasktmp->getNomUrl(1, 'withproject', 'time');
2902 print '</td>';
2903 }
2904 }
2905
2906 // Task label
2907 if (!empty($arrayfields['t.element_label']['checked'])) {
2908 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2909 print '<td class="tdoverflowmax125" title="'.dol_escape_htmltag($task_time->label).'">';
2910 print dol_escape_htmltag($task_time->label);
2911 print '</td>';
2912 }
2913 }
2914
2915 // User
2916 if (!empty($arrayfields['author']['checked'])) {
2917 print '<td class="nowraponall tdoverflowmax100">';
2918 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2919 if (empty($object->id)) {
2920 $idTask = (!empty($id)) ? $id : $task_time->fk_element;
2921 $object->fetch($idTask);
2922 }
2923 $contactsoftask = $object->getListContactId('internal');
2924 if (!in_array($task_time->fk_user, $contactsoftask)) {
2925 $contactsoftask[] = $task_time->fk_user;
2926 }
2927 if (count($contactsoftask) > 0) {
2928 print img_object('', 'user', 'class="hideonsmartphone"');
2929 print $form->select_dolusers($task_time->fk_user, 'userid_line_2', 0, null, 0, '', $contactsoftask);
2930 } else {
2931 print img_error($langs->trans('FirstAddRessourceToAllocateTime')) . $langs->trans('FirstAddRessourceToAllocateTime');
2932 }
2933 } else {
2934 $userstatic->id = $task_time->fk_user;
2935 $userstatic->lastname = $task_time->lastname;
2936 $userstatic->firstname = $task_time->firstname;
2937 $userstatic->photo = $task_time->photo;
2938 $userstatic->status = $task_time->user_status;
2939 print $userstatic->getNomUrl(-1);
2940 }
2941 print '</td>';
2942 }
2943
2944 // Note
2945 if (!empty($arrayfields['t.note']['checked'])) {
2946 print '<td class="small tdoverflowmax300"">';
2947 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2948 print '<textarea name="timespent_note_line_2" class="centpercentimp" rows="' . ROWS_2 . '">' . dol_escape_htmltag($task_time->note, 0, 1) . '</textarea>';
2949 } else {
2950 print dol_nl2br($task_time->note);
2951 }
2952 print '</td>';
2953 } elseif ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2954 print '<input type="hidden" name="timespent_note_line_2" value="' . dol_escape_htmltag($task_time->note, 0, 1) . '">';
2955 }
2956
2957 // Time spent
2958 if (!empty($arrayfields['t.element_duration']['checked'])) {
2959 print '<td class="right">';
2960 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2961 print '<input type="hidden" name="old_duration_2" value="0">';
2962 print $form->select_duration('new_duration_2', 0, 0, 'text');
2963 } else {
2964 print convertSecondToTime($task_time->element_duration, 'allhourmin');
2965 }
2966 print '</td>';
2967 }
2968
2969 // Product
2970 if (!empty($arrayfields['t.fk_product']['checked'])) {
2971 print '<td class="nowraponall tdoverflowmax125">';
2972 print '</td>';
2973 }
2974
2975 // Value spent
2976 if (!empty($arrayfields['value']['checked'])) {
2977 print '<td class="right">';
2978 print '<span class="amount nowraponall">';
2979 $value = 0;
2980 print price($value, 1, $langs, 1, -1, -1, $conf->currency);
2981 // Note: On the transverse project view, we also have a warning if value is zero here
2982 print '</span>';
2983 print '</td>';
2984 }
2985
2986 // Value billed
2987 if (!empty($arrayfields['valuebilled']['checked'])) {
2988 print '<td class="right">';
2989 if (isset($task_time->total_ht)) {
2990 $valuebilled = price2num($task_time->total_ht, '', 1);
2991 print '<span class="amount nowraponall small">';
2992 print price($valuebilled, 1, $langs, 1, -1, -1, $conf->currency);
2993 print '</span>';
2994 }
2995 print '</td>';
2996 }
2997
2998 // Extra fields
2999 $obj = $task_time;
3000 $extrafieldsobjectkey = 'projet_task';
3001 $extrafieldsobjectprefix = 'ef.';
3002 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
3003
3004 // Fields from hook
3005 $parameters = array('arrayfields' => $arrayfields, 'obj' => $task_time, 'mode' => 'split2');
3006 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3007 print $hookmanager->resPrint;
3008
3009 // Action column
3010 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
3011 print '<td class="center nowraponall">';
3012 print '</td>';
3013 }
3014
3015 print "</tr>\n";
3016 }
3017
3018 $i++;
3019 }
3020
3021 // Show total line
3022 //include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
3023 if (isset($totalarray['totaldurationfield']) || isset($totalarray['totalvaluefield'])) {
3024 print '<tr class="liste_total">';
3025 $i = 0;
3026 while ($i < $totalarray['nbfield']) {
3027 $i++;
3028 if ($i == 1) {
3029 if ($num < $limit && empty($offset)) {
3030 print '<td class="left">' . $langs->trans("Total") . '</td>';
3031 } else {
3032 print '<td class="left">'.$form->textwithpicto($langs->trans("Total"), $langs->trans("Totalforthispage")).'</td>';
3033 }
3034 } elseif (isset($totalarray['totaldurationfield']) && $totalarray['totaldurationfield'] == $i) {
3035 print '<td class="right">' . convertSecondToTime($totalarray['totalduration'], 'allhourmin') . '</td>';
3036 } elseif (isset($totalarray['totalvaluefield']) && $totalarray['totalvaluefield'] == $i) {
3037 print '<td class="right">' . price($totalarray['totalvalue']) . '</td>';
3038 //} elseif ($totalarray['totalvaluebilledfield'] == $i) { print '<td class="center">'.price($totalarray['totalvaluebilled']).'</td>';
3039 } else {
3040 print '<td></td>';
3041 }
3042 }
3043 print '</tr>';
3044 }
3045
3046 if (!count($tasks)) {
3047 $totalnboffields = 1;
3048 foreach ($arrayfields as $value) {
3049 if (!empty($value['checked'])) {
3050 $totalnboffields++;
3051 }
3052 }
3053 print '<tr class="oddeven"><td colspan="' . $totalnboffields . '">';
3054 print '<span class="opacitymedium">' . $langs->trans("None") . '</span>';
3055 print '</td></tr>';
3056 }
3057
3058 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
3059 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3060 print $hookmanager->resPrint;
3061
3062 print "</table>";
3063 print '</div>';
3064 print "</form>";
3065 }
3066}
3067
3068// End of page
3069llxFooter();
3070$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$totalarray
Definition export.php:1216
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage standard extra fields.
Class to manage invoices.
Class to manage invoice lines.
Class to manage generation of HTML components Only common components must be here.
Class to manage generation of HTML components for intervention module.
Class permettant la generation de composants html autre Only common components are here.
Class to manage building of HTML components.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage tasks.
Class for TimeSpent.
Class to manage Dolibarr users.
global $mysoc
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
Definition date.lib.php:400
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:262
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
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) If ...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
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.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
img_split($titlealt='default', $other='class="pictosplit"')
Show split logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
img_error($titlealt='default')
Show error logo.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
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) VAT...
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
task_prepare_head($object)
Prepare array with list of tabs.
project_prepare_head(Project $project, $moreparam='')
Prepare array with list of tabs.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.