dolibarr 24.0.3
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-2026 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 $result = $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 if (!array_key_exists($object->timespent_fk_user, $arrayoftasks)) {
551 $arrayoftasks[$object->timespent_fk_user] = [
552 (int) $object->timespent_fk_product => ['timespent' => 0, 'totalvaluetodivideby3600' => 0]
553 ];
554 }
555 $arrayoftasks[$object->timespent_fk_user][(int) $object->timespent_fk_product]['timespent'] += $object->timespent_duration;
556 $arrayoftasks[$object->timespent_fk_user][(int) $object->timespent_fk_product]['totalvaluetodivideby3600'] += ($object->timespent_duration * $object->timespent_thm);
557 }
558
559 foreach ($arrayoftasks as $userid => $data) { // @phan-suppress-current-line PhanEmptyForeach
560 $fuser->fetch($userid);
561 $username = $fuser->getFullName($langs);
562
563 foreach ($data as $fk_product => $timespent_data) {
564 // Define qty per hour
565 $qtyhour = $timespent_data['timespent'] / 3600;
566 $qtyhourtext = convertSecondToTime($timespent_data['timespent'], 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
567
568 // Set the unit price we want to sell the time, for this user
569 if (getDolGlobalInt('PROJECT_USE_REAL_COST_FOR_TIME_INVOICING')) {
570 // We set unit price to 0 to force the use of the rate saved during recording
571 $pu_ht = 0;
572 } elseif ($idprod <= 0) {
573 // We want to sell all the time spent with the last hourly rate of user
574 // -> but what about choice user selected ? add idprod test
575 $pu_ht = $fuser->thm;
576 }
577
578 // If no unit price known for user, we use the price recorded when recording timespent.
579 if (empty($pu_ht)) {
580 if ($timespent_data['timespent']) {
581 $pu_ht = price2num(($timespent_data['totalvaluetodivideby3600'] / $timespent_data['timespent']), 'MU');
582 }
583 }
584
585 // Add lines
586 $prodDurationHours = $prodDurationHoursBase;
587 $idprodline = $idprod;
588 $pu_htline = $pu_ht;
589 $txtvaline = $txtva;
590 $localtax1line = $localtax1;
591 $localtax2line = $localtax2;
592
593 // If a particular product/service was defined for the task
594 if (!empty($fk_product) && ($fk_product > 0) && ($fk_product !== $idprod)) {
595 if (!array_key_exists($fk_product, $product_data_cache)) {
596 $result = $tmpproduct->fetch($fk_product);
597 if ($result < 0) {
598 $error++;
599 setEventMessages($tmpproduct->error, $tmpproduct->errors, 'errors');
600 }
601 $prodDurationHours = $tmpproduct->getProductDurationHours();
602 if ($prodDurationHours < 0) {
603 $error++;
604 $langs->load("errors");
605 setEventMessages(null, $tmpproduct->errors, 'errors');
606 // Skip this entry: without it the loop reaches addline() and divides by the duration (#40805).
607 continue;
608 }
609
610 $dataforprice = $tmpproduct->getSellPrice($mysoc, $projectstatic->thirdparty, 0);
611
612 $pu_htline = empty($dataforprice['pu_ht']) ? 0 : $dataforprice['pu_ht'];
613 $txtvaline = $dataforprice['tva_tx'];
614 $localtax1line = $dataforprice['localtax1'];
615 $localtax2line = $dataforprice['localtax2'];
616
617 $product_data_cache[$fk_product] = array('duration' => $prodDurationHours, 'dataforprice' => $dataforprice);
618 } else {
619 $prodDurationHours = $product_data_cache[$fk_product]['duration'];
620 $pu_htline = empty($product_data_cache[$fk_product]['dataforprice']['pu_ht']) ? 0 : $product_data_cache[$fk_product]['dataforprice']['pu_ht'];
621 $txtvaline = $product_data_cache[$fk_product]['dataforprice']['tva_tx'];
622 $localtax1line = $product_data_cache[$fk_product]['dataforprice']['localtax1'];
623 $localtax2line = $product_data_cache[$fk_product]['dataforprice']['localtax2'];
624 }
625 $idprodline = $fk_product;
626 }
627
628 // Add lines. Pass type=1 (service) explicitly so the invoice line is tagged
629 // as a service even when no product is bound to the time entry. Otherwise
630 // the default $type=0 leaks through and the PDF labels the operation as
631 // "Delivery of goods" instead of "Provision of services" (issue #34571).
632 $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);
633 if ($lineid < 0) {
634 $error++;
635 setEventMessages(null, $tmpinvoice->errors, 'errors');
636 }
637
638 // Update lineid into line of timespent
639 $sql = 'UPDATE '.MAIN_DB_PREFIX.'element_time SET invoice_line_id = '.((int) $lineid).', invoice_id = '.((int) $tmpinvoice->id);
640 $sql .= ' WHERE rowid IN ('.$db->sanitize(implode(',', $toselect)).') AND fk_user = '.((int) $userid);
641 $result = $db->query($sql);
642 if (!$result) {
643 $error++;
644 setEventMessages($db->lasterror(), null, 'errors');
645 break;
646 }
647 }
648 }
649 } elseif ($generateinvoicemode == 'onelineperperiod') { // One line for each time spent line
650 $arrayoftasks = array();
651
652 $withdetail = GETPOST('detail_time_duration', 'alpha');
653 foreach ($toselect as $key => $value) {
654 // Get userid, timepent
655 $object->fetchTimeSpent($value);
656 // $object->id is the task id
657 $ftask = new Task($db);
658 $ftask->fetch($object->id);
659
660 $fuser->fetch($object->timespent_fk_user);
661 $username = $fuser->getFullName($langs);
662
663 $arrayoftasks[$object->timespent_id]['timespent'] = $object->timespent_duration;
664 $arrayoftasks[$object->timespent_id]['totalvaluetodivideby3600'] = $object->timespent_duration * $object->timespent_thm;
665 $arrayoftasks[$object->timespent_id]['note'] = $ftask->ref . ' - ' . $ftask->label . ' - ' . $username;
666 $arrayoftasks[$object->timespent_id]['note'] = dol_concatdesc($arrayoftasks[$object->timespent_id]['note'], $object->timespent_note);
667
668 if (!empty($withdetail)) {
669 if (!empty($object->timespent_withhour)) {
670 $arrayoftasks[$object->timespent_id]['note'] = dol_concatdesc($arrayoftasks[$object->timespent_id]['note'], $langs->trans("Date") . ': ' . dol_print_date($object->timespent_datehour));
671 } else {
672 $arrayoftasks[$object->timespent_id]['note'] = dol_concatdesc($arrayoftasks[$object->timespent_id]['note'], $langs->trans("Date") . ': ' . dol_print_date($object->timespent_date));
673 }
674 $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));
675 }
676 $arrayoftasks[$object->timespent_id]['user'] = $object->timespent_fk_user;
677 $arrayoftasks[$object->timespent_id]['fk_product'] = $object->timespent_fk_product;
678 }
679
680 $pu_ht_saved = $pu_ht; // Save the base unit price (price of the selected product/service if any, 0 otherwise)
681 foreach ($arrayoftasks as $timespent_id => $value) {
682 $pu_ht = $pu_ht_saved; // Reset for each line, so a line does not inherit the unit price computed for the previous one
683 $userid = $value['user'];
684 //$pu_ht = $value['timespent'] * $fuser->thm;
685
686 // Define qty per hour
687 $qtyhour = $value['timespent'] / 3600;
688
689 // If no unit price known
690 if (empty($pu_ht)) {
691 if ($value['timespent']) {
692 $pu_ht = price2num(($value['totalvaluetodivideby3600'] / $value['timespent']), 'MU');
693 }
694 }
695
696 // Add lines
697 $prodDurationHours = $prodDurationHoursBase;
698 $idprodline = $idprod;
699 $pu_htline = $pu_ht;
700 $txtvaline = $txtva;
701 $localtax1line = $localtax1;
702 $localtax2line = $localtax2;
703
704 if (!empty($value['fk_product']) && $value['fk_product'] !== $idprod) {
705 if (!array_key_exists($value['fk_product'], $product_data_cache)) {
706 $result = $tmpproduct->fetch($value['fk_product']);
707 if ($result < 0) {
708 $error++;
709 setEventMessages($tmpproduct->error, $tmpproduct->errors, 'errors');
710 }
711 $prodDurationHours = $tmpproduct->getProductDurationHours();
712 if ($prodDurationHours < 0) {
713 $error++;
714 $langs->load("errors");
715 setEventMessages(null, $tmpproduct->errors, 'errors');
716 // Skip this entry: without it the loop reaches addline() and divides by the duration (#40805).
717 continue;
718 }
719
720 $dataforprice = $tmpproduct->getSellPrice($mysoc, $projectstatic->thirdparty, 0);
721
722 $pu_htline = empty($dataforprice['pu_ht']) ? 0 : $dataforprice['pu_ht'];
723 $txtvaline = $dataforprice['tva_tx'];
724 $localtax1line = $dataforprice['localtax1'];
725 $localtax2line = $dataforprice['localtax2'];
726
727 $product_data_cache[$value['fk_product']] = array('duration' => $prodDurationHours, 'dataforprice' => $dataforprice);
728 } else {
729 $prodDurationHours = $product_data_cache[$value['fk_product']]['duration'];
730 $pu_htline = empty($product_data_cache[$value['fk_product']]['dataforprice']['pu_ht']) ? 0 : $product_data_cache[$value['fk_product']]['dataforprice']['pu_ht'];
731 $txtvaline = $product_data_cache[$value['fk_product']]['dataforprice']['tva_tx'];
732 $localtax1line = $product_data_cache[$value['fk_product']]['dataforprice']['localtax1'];
733 $localtax2line = $product_data_cache[$value['fk_product']]['dataforprice']['localtax2'];
734 }
735 $idprodline = $value['fk_product'];
736 }
737 // Pass type=1 (service) explicitly so the invoice line is tagged as a service
738 // even when no product is bound to the time entry. Otherwise the default
739 // $type=0 leaks through and the PDF labels the operation as
740 // "Delivery of goods" instead of "Provision of services" (issue #34571).
741 $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);
742 if ($lineid < 0) {
743 $error++;
744 setEventMessages(null, $tmpinvoice->errors, 'errors');
745 }
746 //var_dump($lineid);exit;
747
748 // Update lineid into line of timespent
749 $sql = 'UPDATE '.MAIN_DB_PREFIX.'element_time SET invoice_line_id = '.((int) $lineid).', invoice_id = '.((int) $tmpinvoice->id);
750 $sql .= ' WHERE rowid = '.((int) $timespent_id).' AND fk_user = '.((int) $userid);
751 $result = $db->query($sql);
752 if (!$result) {
753 $error++;
754 setEventMessages($db->lasterror(), null, 'errors');
755 break;
756 }
757 }
758 } elseif ($generateinvoicemode == 'onelinepertask') { // One line for each different task
759 $arrayoftasks = array();
760 foreach ($toselect as $key => $value) {
761 // Get userid, timepent
762 $object->fetchTimeSpent($value); // Call method to get list of timespent for a timespent line id (We use the utility method found into Task object)
763 // $object->id is now the task id
764 if (!isset($arrayoftasks[$object->id][(int) $object->timespent_fk_product])) {
765 $arrayoftasks[$object->id][(int) $object->timespent_fk_product] = array('timespent' => 0, 'totalvaluetodivideby3600' => 0, 'ids' => array());
766 }
767 $arrayoftasks[$object->id][(int) $object->timespent_fk_product]['timespent'] += $object->timespent_duration;
768 $arrayoftasks[$object->id][(int) $object->timespent_fk_product]['totalvaluetodivideby3600'] += ($object->timespent_duration * $object->timespent_thm);
769 // Keep the time spent lines that feed this invoice line, so the back link below
770 // points each of them at its own line and not at the last one created.
771 $arrayoftasks[$object->id][(int) $object->timespent_fk_product]['ids'][] = (int) $value;
772 }
773
774 foreach ($arrayoftasks as $task_id => $data) { // @phan-suppress-current-line PhanEmptyForeach
775 $ftask = new Task($db);
776 $ftask->fetch($task_id);
777
778 foreach ($data as $fk_product => $timespent_data) {
779 $qtyhour = $timespent_data['timespent'] / 3600;
780 $qtyhourtext = convertSecondToTime($timespent_data['timespent'], 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
781
782 // Add lines
783 $prodDurationHours = $prodDurationHoursBase;
784 $idprodline = $idprod;
785 $pu_htline = $pu_ht;
786 $txtvaline = $txtva;
787 $localtax1line = $localtax1;
788 $localtax2line = $localtax2;
789
790 if (!empty($fk_product) && $fk_product !== $idprod) {
791 if (!array_key_exists($fk_product, $product_data_cache)) {
792 $result = $tmpproduct->fetch($fk_product);
793 if ($result < 0) {
794 $error++;
795 setEventMessages($tmpproduct->error, $tmpproduct->errors, 'errors');
796 }
797 $prodDurationHours = $tmpproduct->getProductDurationHours();
798 if ($prodDurationHours < 0) {
799 $error++;
800 $langs->load("errors");
801 setEventMessages(null, $tmpproduct->errors, 'errors');
802 // Skip this entry: without it the loop reaches addline() and divides by the duration (#40805).
803 continue;
804 }
805
806 $dataforprice = $tmpproduct->getSellPrice($mysoc, $projectstatic->thirdparty, 0);
807
808 $pu_htline = empty($dataforprice['pu_ht']) ? 0 : $dataforprice['pu_ht'];
809 $txtvaline = $dataforprice['tva_tx'];
810 $localtax1line = $dataforprice['localtax1'];
811 $localtax2line = $dataforprice['localtax2'];
812
813 $product_data_cache[$fk_product] = array('duration' => $prodDurationHours, 'dataforprice' => $dataforprice);
814 } else {
815 $prodDurationHours = $product_data_cache[$fk_product]['duration'];
816 $pu_htline = empty($product_data_cache[$fk_product]['dataforprice']['pu_ht']) ? 0 : $product_data_cache[$fk_product]['dataforprice']['pu_ht'];
817 $txtvaline = $product_data_cache[$fk_product]['dataforprice']['tva_tx'];
818 $localtax1line = $product_data_cache[$fk_product]['dataforprice']['localtax1'];
819 $localtax2line = $product_data_cache[$fk_product]['dataforprice']['localtax2'];
820 }
821 $idprodline = $fk_product;
822 }
823
824
825 if ($idprodline > 0) {
826 // If a product is defined, we msut use the $prodDurationHours and $pu_ht of product (already set previously).
827 $pu_ht_for_task = $pu_htline;
828 // If we want to reuse the value of timespent (so use same price than cost price)
829 if (getDolGlobalString('PROJECT_TIME_SPENT_INTO_INVOICE_USE_VALUE')) {
830 $pu_ht_for_task = (float) price2num($timespent_data['totalvaluetodivideby3600'] / $timespent_data['timespent'], 'MU') * $prodDurationHours;
831 }
832 $pa_ht = (float) price2num($timespent_data['totalvaluetodivideby3600'] / $timespent_data['timespent'], 'MU') * $prodDurationHours;
833 } else {
834 // If not product used, we use the hour unit for duration and unit price.
835 $pu_ht_for_task = 0;
836 // If we want to reuse the value of timespent (so use same price than cost price)
837 if (getDolGlobalString('PROJECT_TIME_SPENT_INTO_INVOICE_USE_VALUE')) {
838 $pu_ht_for_task = price2num($timespent_data['totalvaluetodivideby3600'] / $timespent_data['timespent'], 'MU');
839 }
840 $pa_ht = price2num($timespent_data['totalvaluetodivideby3600'] / $timespent_data['timespent'], 'MU');
841 }
842
843 // Add lines
844 $date_start = '';
845 $date_end = '';
846 $lineName = $ftask->ref . ' - ' . $ftask->label;
847 $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);
848 if ($lineid < 0) {
849 $error++;
850 setEventMessages($tmpinvoice->error, $tmpinvoice->errors, 'errors');
851 break;
852 }
853
854 if (!$error) {
855 // Update lineid into line of timespent
856 $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'element_time SET invoice_line_id = ' . ((int) $lineid) . ', invoice_id = ' . ((int) $tmpinvoice->id);
857 $sql .= ' WHERE rowid IN (' . $db->sanitize(implode(',', $timespent_data['ids'])) . ')';
858 $result = $db->query($sql);
859 if (!$result) {
860 $error++;
861 setEventMessages($db->lasterror(), null, 'errors');
862 break;
863 }
864 }
865 }
866 }
867 }
868 }
869
870 if (!$error) {
871 $urltoinvoice = $tmpinvoice->getNomUrl(0);
872 $mesg = $langs->trans("InvoiceGeneratedFromTimeSpent", '{s1}');
873 $mesg = str_replace('{s1}', $urltoinvoice, $mesg);
874 setEventMessages($mesg, null, 'mesgs');
875
876 $db->commit();
877 } else {
878 $db->rollback();
879 }
880 }
881}
882
883if ($action == 'confirm_generateinter' && $user->hasRight('fichinter', 'creer')) {
884 $langs->load('interventions');
885
886 if (!empty($projectstatic->socid)) {
887 $projectstatic->fetch_thirdparty();
888 }
889
890 if (!($projectstatic->thirdparty->id > 0)) {
891 setEventMessages($langs->trans("ThirdPartyRequiredToGenerateIntervention"), null, 'errors');
892 } else {
893 include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
894 include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
895 include_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
896
897
898 require_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php';
899 $tmpinter = new Fichinter($db);
900 $tmptimespent = new Task($db);
901 $fuser = new User($db);
902
903 $db->begin();
904 $interToUse = GETPOSTINT('interid');
905
906
907 $tmpinter->socid = $projectstatic->thirdparty->id;
908 $tmpinter->date = dol_mktime(GETPOSTINT('rehour'), GETPOSTINT('remin'), GETPOSTINT('resec'), GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
909 $tmpinter->fk_project = $projectstatic->id;
910 $tmpinter->description = $projectstatic->title . (!empty($projectstatic->description) ? '-' . $projectstatic->description : '');
911
912 if ($interToUse) {
913 $tmpinter->fetch($interToUse);
914 } else {
915 $result = $tmpinter->create($user);
916 if ($result <= 0) {
917 $error++;
918 setEventMessages($tmpinter->error, $tmpinter->errors, 'errors');
919 }
920 }
921
922 if (!$error) {
923 $arrayoftasks = array();
924 foreach ($toselect as $key => $value) {
925 // Get userid, timespent
926 $object->fetchTimeSpent($value);
927 // $object->id is the task id
928 $arrayoftasks[$object->timespent_id]['id'] = $object->id;
929 $arrayoftasks[$object->timespent_id]['timespent'] = $object->timespent_duration;
930 $arrayoftasks[$object->timespent_id]['totalvaluetodivideby3600'] = $object->timespent_duration * $object->timespent_thm;
931 $arrayoftasks[$object->timespent_id]['note'] = $object->timespent_note;
932 $arrayoftasks[$object->timespent_id]['date'] = $object->timespent_datehour;
933 }
934
935 foreach ($arrayoftasks as $timespent_id => $value) {
936 $ftask = new Task($db);
937 $ftask->fetch($value['id']);
938 // Define qty per hour
939 $qtyhour = $value['timespent'] / 3600;
940 $qtyhourtext = convertSecondToTime($value['timespent'], 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
941
942 // Add lines
943 $lineid = $tmpinter->addline($user, $tmpinter->id, $ftask->label . (!empty($value['note']) ? ' - ' . $value['note'] : ''), (int) $value['date'], $value['timespent']);
944
945 if ($lineid > 0) {
946 // Link timespent to intervention
947 $timespent = new TimeSpent($db);
948 $timespent->fetch($timespent_id);
949 $timespent->intervention_id = $tmpinter->id;
950 $timespent->intervention_line_id = $lineid;
951 $result = $timespent->update($user);
952 if ($result < 0) {
953 $error++;
954 setEventMessages($timespent->error, $timespent->errors, 'errors');
955 }
956 }
957 }
958 }
959
960 if (!$error) {
961 $urltointer = $tmpinter->getNomUrl(0);
962 $mesg = $langs->trans("InterventionGeneratedFromTimeSpent", '{s1}');
963 $mesg = str_replace('{s1}', $urltointer, $mesg);
964 setEventMessages($mesg, null, 'mesgs');
965
966 //var_dump($tmpinvoice);
967
968 $db->commit();
969 } else {
970 $db->rollback();
971 }
972 }
973}
974
975
976/*
977 * View
978 */
979
980$form = new Form($db);
981$formother = new FormOther($db);
982$formproject = new FormProjets($db);
983$userstatic = new User($db);
984//$result = $projectstatic->fetch($object->fk_project);
985$arrayofselected = is_array($toselect) ? $toselect : array();
986
987$title = $object->ref . ' - ' . $langs->trans("TimeSpent");
988if (!empty($withproject)) {
989 $title .= ' | ' . $langs->trans("Project") . (!empty($projectstatic->ref) ? ': ' . $projectstatic->ref : '');
990}
991$help_url = '';
992
993llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-project project-tasks page-task_time');
994
995
996$param = ((!empty($mode) && $mode == 'mine') ? '&mode=mine' : '');
997if ($search_user) {
998 $param .= '&search_user=' . ((int) $search_user);
999}
1000if ($search_month) {
1001 $param .= '&search_month=' . ((int) $search_month);
1002}
1003if ($search_year) {
1004 $param .= '&search_year=' . ((int) $search_year);
1005}
1006
1007
1008if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser > 0) {
1009 // Project car in view mode
1010 if ($projectidforalltimes > 0) {
1011 $result = $projectstatic->fetch($projectidforalltimes);
1012 if (!empty($projectstatic->socid)) {
1013 $projectstatic->fetch_thirdparty();
1014 }
1015 $res = $projectstatic->fetch_optionals();
1016 } elseif ($object->fetch($id, $ref) > 0) {
1017 if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_TASK') && empty($object->comments)) {
1018 $object->fetchComments();
1019 }
1020 $result = $projectstatic->fetch($object->fk_project);
1021 if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_PROJECT') && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) {
1022 $projectstatic->fetchComments();
1023 }
1024 if (!empty($projectstatic->socid)) {
1025 $projectstatic->fetch_thirdparty();
1026 }
1027 $res = $projectstatic->fetch_optionals();
1028
1029 $object->project = clone $projectstatic;
1030 }
1031
1032 $userRead = $projectstatic->restrictedProjectArea($user, 'read');
1033 $linktocreatetime = '';
1034
1035 if ($projectstatic->id > 0) {
1036 if ($withproject) {
1037 // Tabs for project
1038 if (empty($id) || $tab == 'timespent') {
1039 $tab = 'timespent';
1040 } else {
1041 $tab = 'tasks';
1042 }
1043
1044 $head = project_prepare_head($projectstatic);
1045 print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'));
1046
1047 // Project card
1048
1049 $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1050
1051 $morehtmlref = '<div class="refidno">';
1052 // Title
1053 $morehtmlref .= $projectstatic->title;
1054 // Thirdparty
1055 if (!empty($projectstatic->thirdparty->id) && $projectstatic->thirdparty->id > 0) {
1056 $morehtmlref .= '<br>' . $projectstatic->thirdparty->getNomUrl(1, 'project');
1057 }
1058 $morehtmlref .= '</div>';
1059
1060 // Define a complementary filter for search of next/prev ref.
1061 if (!$user->hasRight('projet', 'all', 'lire')) {
1062 $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
1063 $projectstatic->next_prev_filter = "rowid:IN:" . $db->sanitize(count($objectsListId) ? implode(',', array_keys($objectsListId)) : '0');
1064 }
1065
1066 dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
1067
1068 print '<div class="fichecenter">';
1069 print '<div class="fichehalfleft">';
1070 print '<div class="underbanner clearboth"></div>';
1071
1072 print '<table class="border tableforfield centpercent">';
1073
1074 // Usage
1075 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES') || !getDolGlobalString('PROJECT_HIDE_TASKS') || isModEnabled('eventorganization')) {
1076 print '<tr><td class="tdtop">';
1077 print $langs->trans("Usage");
1078 print '</td>';
1079 print '<td>';
1080 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
1081 print '<input type="checkbox" disabled name="usage_opportunity"' . (GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')) . '"> ';
1082 $htmltext = $langs->trans("ProjectFollowOpportunity");
1083 print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
1084 print '<br>';
1085 }
1086 if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
1087 print '<input type="checkbox" disabled name="usage_task"' . (GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')) . '"> ';
1088 $htmltext = $langs->trans("ProjectFollowTasks");
1089 print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
1090 print '<br>';
1091 }
1092 if (!getDolGlobalString('PROJECT_HIDE_TASKS') && getDolGlobalString('PROJECT_BILL_TIME_SPENT')) {
1093 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"' : '')) . '"> ';
1094 $htmltext = $langs->trans("ProjectBillTimeDescription");
1095 print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
1096 print '<br>';
1097 }
1098 if (isModEnabled('eventorganization')) {
1099 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"' : '')) . '"> ';
1100 $htmltext = $langs->trans("EventOrganizationDescriptionLong");
1101 print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
1102 }
1103 print '</td></tr>';
1104 }
1105
1106 // Budget
1107 print '<tr><td>' . $langs->trans("Budget") . '</td><td>';
1108 if (!is_null($projectstatic->budget_amount) && strcmp($projectstatic->budget_amount, '')) {
1109 print '<span class="amount">' . price($projectstatic->budget_amount, 0, $langs, 1, 0, 0, $conf->currency) . '</span>';
1110 }
1111 print '</td></tr>';
1112
1113 // Date start - end project
1114 print '<tr><td>' . $langs->trans("Dates") . '</td><td>';
1115 $start = dol_print_date($projectstatic->date_start, 'day');
1116 print($start ? $start : '?');
1117 $end = dol_print_date($projectstatic->date_end, 'day');
1118 print ' - ';
1119 print($end ? $end : '?');
1120 if ($projectstatic->hasDelay()) {
1121 print img_warning("Late");
1122 }
1123 print '</td></tr>';
1124
1125 // Visibility
1126 print '<tr><td class="titlefield">' . $langs->trans("Visibility") . '</td><td>';
1127 if ($projectstatic->public) {
1128 print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
1129 print $langs->trans('SharedProject');
1130 } else {
1131 print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
1132 print $langs->trans('PrivateProject');
1133 }
1134 print '</td></tr>';
1135
1136 // Other attributes
1137 $cols = 2;
1138 $savobject = $object;
1139 $object = $projectstatic;
1140 // On this page, the 'id' GET parameter is the task id, not the project id, so force the
1141 // edit link/form of the project extrafields to use 'projectid' instead, and keep 'withproject'
1142 // so the project summary (this whole block) stays visible after the edit link is followed.
1143 $forcefieldid = 'projectid';
1144 $moreparam = '&withproject=1';
1145 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
1146 unset($forcefieldid, $moreparam);
1147 $object = $savobject;
1148
1149 print '</table>';
1150
1151 print '</div>';
1152 print '<div class="fichehalfright">';
1153 print '<div class="underbanner clearboth"></div>';
1154
1155 print '<table class="border tableforfield centpercent">';
1156
1157 // Categories
1158 if (isModEnabled('category')) {
1159 print '<tr><td class="valignmiddle">' . $langs->trans("Categories") . '</td><td>';
1160 print $form->showCategories($projectstatic->id, 'project', 1);
1161 print "</td></tr>";
1162 }
1163
1164 // Description
1165 print '<tr><td class="titlefield'.($projectstatic->description ? ' noborderbottom' : '').'" colspan="2">'.$langs->trans("Description").'</td></tr>';
1166 if ($projectstatic->description) {
1167 print '<tr><td class="nottitleforfield" colspan="2">';
1168 print '<div class="longmessagecut">';
1169 print dolPrintHTML($projectstatic->description);
1170 print '</div>';
1171 print '</td></tr>';
1172 }
1173
1174 print '</table>';
1175
1176 print '</div>';
1177 print '</div>';
1178
1179 print '<div class="clearboth"></div>';
1180
1181 print dol_get_fiche_end();
1182
1183 print '<br>';
1184 }
1185
1186 // Link to create time
1187 $linktocreatetimeBtnStatus = 0;
1188 $linktocreatetimeUrl = '';
1189 $linktocreatetimeHelpText = '';
1190 if ($user->hasRight('projet', 'time')) {
1191 if ($projectstatic->public || $userRead > 0) {
1192 $linktocreatetimeBtnStatus = 1;
1193
1194 if (!empty($projectidforalltimes)) {
1195 // We are on tab 'Time Spent' of project
1196 $backtourl = $_SERVER['PHP_SELF'] . '?projectid=' . $projectstatic->id . ($withproject ? '&withproject=1' : '');
1197 $linktocreatetimeUrl = $_SERVER['PHP_SELF'] . '?' . ($withproject ? 'withproject=1' : '') . '&projectid=' . $projectstatic->id . '&action=createtime&token=' . newToken() . $param . '&backtopage=' . urlencode($backtourl);
1198 } else {
1199 // We are on tab 'Time Spent' of task
1200 $backtourl = $_SERVER['PHP_SELF'] . '?id=' . $object->id . ($withproject ? '&withproject=1' : '');
1201 $linktocreatetimeUrl = $_SERVER['PHP_SELF'] . '?' . ($withproject ? 'withproject=1' : '') . ($object->id > 0 ? '&id=' . $object->id : '&projectid=' . $projectstatic->id) . '&action=createtime&token=' . newToken() . $param . '&backtopage=' . urlencode($backtourl);
1202 }
1203 } else {
1204 $linktocreatetimeBtnStatus = -2;
1205 $linktocreatetimeHelpText = $langs->trans("NotOwnerOfProject");
1206 }
1207 } else {
1208 $linktocreatetimeBtnStatus = -2;
1209 $linktocreatetimeHelpText = $langs->trans("NotEnoughPermissions");
1210 }
1211
1212 $paramsbutton = array('morecss' => 'reposition');
1213 $linktocreatetime = dolGetButtonTitle($langs->trans('AddTimeSpent'), $linktocreatetimeHelpText, 'fa fa-plus-circle', $linktocreatetimeUrl, '', $linktocreatetimeBtnStatus, $paramsbutton);
1214 }
1215
1216 $massactionbutton = '';
1217 $arrayofmassactions = array();
1218
1219 if ($projectstatic->id > 0) {
1220 // If we are on a given project.
1221 if ($projectstatic->usage_bill_time) {
1222 $arrayofmassactions = array(
1223 'generateinvoice' => $langs->trans("GenerateBill"),
1224 //'builddoc'=>$langs->trans("PDFMerge"),
1225 );
1226 }
1227 if (isModEnabled('intervention') && $user->hasRight('ficheinter', 'creer')) {
1228 $langs->load("interventions");
1229 $arrayofmassactions['generateinter'] = $langs->trans("GenerateInter");
1230 }
1231 }
1232 if (in_array($massaction, array('presend', 'predelete', 'generateinvoice', 'generateinter'))) {
1233 $arrayofmassactions = array();
1234 }
1235 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
1236
1237 $formconfirm = '';
1238
1239 // Task
1240
1241 // Show section with information of task. If id of task is not defined and project id defined, then $projectidforalltimes is not empty.
1242 if (empty($projectidforalltimes) && empty($allprojectforuser)) {
1243 $head = task_prepare_head($object);
1244 print dol_get_fiche_head($head, 'task_time', $langs->trans("Task"), -1, 'projecttask', 0, '', 'reposition');
1245
1246 $param = (GETPOST('withproject') ? '&withproject=1' : '');
1247 $linkback = GETPOST('withproject') ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>' : '';
1248
1249 if ($action == 'deleteline') {
1250 $urlafterconfirm = $_SERVER["PHP_SELF"] . "?" . ($object->id > 0 ? "id=" . $object->id : 'projectid=' . $projectstatic->id) . '&lineid=' . GETPOSTINT("lineid") . $param;
1251 $formconfirm .= $form->formconfirm($urlafterconfirm, $langs->trans("DeleteATimeSpent"), $langs->trans("ConfirmDeleteATimeSpent"), "confirm_deleteline", '', '', 1);
1252 }
1253
1254 if (!GETPOST('withproject') || empty($projectstatic->id)) {
1255 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
1256 $object->next_prev_filter = "fk_projet:IN:" . $db->sanitize($projectsListId);
1257 } else {
1258 $object->next_prev_filter = "fk_projet:=:" . ((int) $projectstatic->id);
1259 }
1260
1261 $morehtmlref = '';
1262
1263 // Project
1264 if (empty($withproject)) {
1265 $morehtmlref .= '<div class="refidno">';
1266 $morehtmlref .= $langs->trans("Project") . ': ';
1267 $morehtmlref .= $projectstatic->getNomUrl(1);
1268 $morehtmlref .= '<br>';
1269
1270 // Third party
1271 $morehtmlref .= $langs->trans("ThirdParty") . ': ';
1272 if (!empty($projectstatic->thirdparty) && is_object($projectstatic->thirdparty)) {
1273 $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1);
1274 }
1275 $morehtmlref .= '</div>';
1276 }
1277
1278 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
1279
1280 print '<div class="fichecenter">';
1281 print '<div class="fichehalfleft">';
1282
1283 print '<div class="underbanner clearboth"></div>';
1284 print '<table class="border centpercent tableforfield">';
1285
1286 // Task parent
1287 print '<tr><td>' . $langs->trans("ParentTask") . '</td><td>';
1288 if ($object->fk_task_parent > 0) {
1289 $tasktmp = new Task($db);
1290 $tasktmp->fetch($object->fk_task_parent);
1291 print $tasktmp->getNomUrl(1);
1292 }
1293 print '</td></tr>';
1294
1295 // Date start - Date end task
1296 print '<tr><td class="titlefield">' . $langs->trans("DateStart") . ' - ' . $langs->trans("Deadline") . '</td><td>';
1297 $start = dol_print_date($object->date_start, 'dayhour');
1298 print($start ? $start : '?');
1299 $end = dol_print_date($object->date_end, 'dayhour');
1300 print ' - ';
1301 print($end ? $end : '?');
1302 if ($object->hasDelay()) {
1303 print img_warning("Late");
1304 }
1305 print '</td></tr>';
1306
1307 // Planned workload
1308 print '<tr><td>' . $langs->trans("PlannedWorkload") . '</td><td>';
1309 if ($object->planned_workload) {
1310 print convertSecondToTime($object->planned_workload, 'allhourmin');
1311 }
1312 print '</td></tr>';
1313
1314 print '</table>';
1315 print '</div>';
1316
1317 print '<div class="fichehalfright">';
1318
1319 print '<div class="underbanner clearboth"></div>';
1320 print '<table class="border tableforfield centpercent">';
1321
1322 // Progress declared
1323 print '<tr><td class="titlefield">' . $langs->trans("ProgressDeclared") . '</td><td>';
1324 print $object->progress != '' ? $object->progress . ' %' : '';
1325 print '</td></tr>';
1326
1327 // Progress calculated
1328 print '<tr><td>' . $langs->trans("ProgressCalculated") . '</td><td>';
1329 if ($object->planned_workload) {
1330 $tmparray = $object->getSummaryOfTimeSpent();
1331 if ($tmparray['total_duration'] > 0) {
1332 print round($tmparray['total_duration'] / $object->planned_workload * 100, 2) . ' %';
1333 } else {
1334 print '0 %';
1335 }
1336 } else {
1337 print '<span class="opacitymedium">' . $langs->trans("WorkloadNotDefined") . '</span>';
1338 }
1339 print '</td>';
1340
1341 print '</tr>';
1342
1343 print '</table>';
1344
1345 print '</div>';
1346
1347 print '</div>';
1348 print '<div class="clearboth"></div>';
1349
1350 print dol_get_fiche_end();
1351 } else {
1352 if ($action == 'deleteline') {
1353 $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;
1354 $formconfirm .= $form->formconfirm($urlafterconfirm, $langs->trans("DeleteATimeSpent"), $langs->trans("ConfirmDeleteATimeSpent"), "confirm_deleteline", '', '', 1);
1355 }
1356 }
1357
1358 // Call Hook formConfirm
1359 $parameters = array('formConfirm' => $formconfirm, "projectstatic" => $projectstatic, "withproject" => $withproject);
1360 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1361 if (empty($reshook)) {
1362 $formconfirm .= $hookmanager->resPrint;
1363 } elseif ($reshook > 0) {
1364 $formconfirm = $hookmanager->resPrint;
1365 }
1366
1367
1368 if ($projectstatic->id > 0 || $allprojectforuser > 0) {
1369 // Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
1370 $hookmanager->initHooks(array('tasktimelist'));
1371
1372 // Print form confirm
1373 print $formconfirm;
1374
1375 // Definition of fields for list
1376 $arrayfields = array();
1377 $arrayfields['t.element_date'] = array('label' => $langs->trans("Date"), 'checked' => '1');
1378 $arrayfields['p.fk_soc'] = array('label' => $langs->trans("ThirdParty"), 'type' => 'integer:Societe:/societe/class/societe.class.php:1','checked' => '1');
1379 $arrayfields['s.name_alias'] = array('label' => $langs->trans("AliasNameShort"), 'type' => 'integer:Societe:/societe/class/societe.class.php:1');
1380 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
1381 if (! empty($allprojectforuser)) {
1382 $arrayfields['p.project_ref'] = ['label' => $langs->trans('RefProject'), 'checked' => '1'];
1383 $arrayfields['p.project_label'] = ['label' => $langs->trans('ProjectLabel'), 'checked' => '1'];
1384 }
1385 $arrayfields['t.element_ref'] = array('label' => $langs->trans("RefTask"), 'checked' => '1');
1386 $arrayfields['t.element_label'] = array('label' => $langs->trans("LabelTask"), 'checked' => '1');
1387 }
1388 $arrayfields['author'] = array('label' => $langs->trans("By"), 'checked' => '1');
1389 $arrayfields['t.note'] = array('label' => $langs->trans("Note"), 'checked' => '1');
1390 $arrayfields['t.tms'] = array('label' => $langs->trans("DateModification"), 'checked' => '0');
1391 if (isModEnabled('service') && !empty($projectstatic->thirdparty) && $projectstatic->thirdparty->id > 0 && $projectstatic->usage_bill_time) {
1392 $arrayfields['t.fk_product'] = array('label' => $langs->trans("Product"), 'checked' => '1');
1393 }
1394 $arrayfields['t.element_duration'] = array('label' => $langs->trans("Duration"), 'checked' => '1');
1395 $arrayfields['t.fk_product'] = array('label' => $langs->trans("Product"), 'checked' => '0', 'enabled' => (string) (int) (((getDolGlobalInt('PROJECT_HIDE_TASKS') || !getDolGlobalInt('PROJECT_BILL_TIME_SPENT')) ? 0 : 1) && $projectstatic->usage_bill_time));
1396 $arrayfields['value'] = array('label' => $langs->trans("Value"), 'checked' => '1', 'enabled' => (string) (int) isModEnabled("salaries"));
1397 $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));
1398 // Extra fields
1399 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php';
1400
1401 $arrayfields = dol_sort_array($arrayfields, 'position');
1402
1403 $param = '';
1404 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
1405 $param .= '&contextpage=' . urlencode($contextpage);
1406 }
1407 if ($limit > 0 && $limit != $conf->liste_limit) {
1408 $param .= '&limit='.((int) $limit);
1409 }
1410 if ($id > 0) {
1411 $param .= '&id='.((int) $id);
1412 }
1413 if ($search_month > 0) {
1414 $param .= '&search_month=' . urlencode((string) ($search_month));
1415 }
1416 if ($search_year > 0) {
1417 $param .= '&search_year=' . urlencode((string) ($search_year));
1418 }
1419 if (!empty($search_user)) { // We keep param if -1 because default value is forced to user id if not set
1420 $param .= '&search_user='.urlencode($search_user);
1421 }
1422 if ($search_task_ref != '') {
1423 $param .= '&search_task_ref=' . urlencode($search_task_ref);
1424 }
1425 if ($search_company != '') {
1426 $param .= '&search_company=' . urlencode($search_company);
1427 }
1428 if ($search_company_alias != '') {
1429 $param .= '&search_company_alias=' . urlencode($search_company_alias);
1430 }
1431 if ($search_project_ref != '') {
1432 $param .= '&search_project_ref=' . urlencode($search_project_ref);
1433 }
1434 if ($search_project_label != '') {
1435 $param .= '&search_project_label=' . urlencode($search_project_label);
1436 }
1437 if ($search_task_label != '') {
1438 $param .= '&search_task_label=' . urlencode($search_task_label);
1439 }
1440 if ($search_note != '') {
1441 $param .= '&search_note=' . urlencode($search_note);
1442 }
1443 if ($search_duration != '') {
1444 $param .= '&search_field2=' . urlencode((string) ($search_duration));
1445 }
1446 if ($optioncss != '') {
1447 $param .= '&optioncss=' . urlencode($optioncss);
1448 }
1449 if ($search_date_startday) {
1450 $param .= '&search_date_startday=' . urlencode((string) ($search_date_startday));
1451 }
1452 if ($search_date_startmonth) {
1453 $param .= '&search_date_startmonth=' . urlencode((string) ($search_date_startmonth));
1454 }
1455 if ($search_date_startyear) {
1456 $param .= '&search_date_startyear=' . urlencode((string) ($search_date_startyear));
1457 }
1458 if ($search_date_endday) {
1459 $param .= '&search_date_endday=' . urlencode((string) ($search_date_endday));
1460 }
1461 if ($search_date_endmonth) {
1462 $param .= '&search_date_endmonth=' . urlencode((string) ($search_date_endmonth));
1463 }
1464 if ($search_date_endyear) {
1465 $param .= '&search_date_endyear=' . urlencode((string) ($search_date_endyear));
1466 }
1467 if ($search_timespent_starthour) {
1468 $param .= '&search_timespent_duration_starthour=' . urlencode((string) ($search_timespent_starthour));
1469 }
1470 if ($search_timespent_startmin) {
1471 $param .= '&search_timespent_duration_startmin=' . urlencode((string) ($search_timespent_startmin));
1472 }
1473 if ($search_timespent_endhour) {
1474 $param .= '&search_timespent_duration_endhour=' . urlencode((string) ($search_timespent_endhour));
1475 }
1476 if ($search_timespent_endmin) {
1477 $param .= '&search_timespent_duration_endmin=' . urlencode((string) ($search_timespent_endmin));
1478 }
1479 // Add $param from extra fields
1480 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1481 if ($id) {
1482 $param .= '&id=' . urlencode((string) ($id));
1483 }
1484 if ($projectid) {
1485 $param .= '&projectid=' . urlencode((string) ($projectid));
1486 }
1487 if ($withproject) {
1488 $param .= '&withproject=' . urlencode((string) ($withproject));
1489 }
1490 // Add $param from hooks
1491 $parameters = array('param' => &$param);
1492 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1493 $param .= $hookmanager->resPrint;
1494
1495 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
1496 if ($optioncss != '') {
1497 print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
1498 }
1499 print '<input type="hidden" name="token" value="' . newToken() . '">';
1500 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1501 if ($action == 'editline') {
1502 print '<input type="hidden" name="action" value="updateline">';
1503 } elseif ($action == 'splitline') {
1504 print '<input type="hidden" name="action" value="updatesplitline">';
1505 } elseif ($action == 'createtime' && $user->hasRight('projet', 'time')) {
1506 print '<input type="hidden" name="action" value="addtimespent">';
1507 } elseif ($massaction == 'generateinvoice' && $user->hasRight('facture', 'creer')) {
1508 print '<input type="hidden" name="action" value="confirm_generateinvoice">';
1509 } elseif ($massaction == 'generateinter' && $user->hasRight('ficheinter', 'creer')) {
1510 print '<input type="hidden" name="action" value="confirm_generateinter">';
1511 } else {
1512 print '<input type="hidden" name="action" value="list">';
1513 }
1514 print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
1515 print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
1516
1517 // Carry the task id through the filter submit so that the timespent list
1518 // stays scoped to the current task instead of falling back to the global view.
1519 print '<input type="hidden" name="id" value="' . ((int) $id) . '">';
1520 print '<input type="hidden" name="projectid" value="' . $projectidforalltimes . '">';
1521 print '<input type="hidden" name="withproject" value="' . $withproject . '">';
1522 print '<input type="hidden" name="tab" value="' . $tab . '">';
1523 print '<input type="hidden" name="page_y" value="">';
1524
1525 // Form to convert time spent into invoice
1526 if ($massaction == 'generateinvoice') {
1527 if (!empty($projectstatic->thirdparty) && $projectstatic->thirdparty->id > 0) {
1528 print '<table class="noborder centerpercent">';
1529 print '<tr>';
1530 print '<td class="titlefield">';
1531 print $langs->trans('DateInvoice');
1532 print '</td>';
1533 print '<td>';
1534 print $form->selectDate('', '', 0, 0, 0, '', 1, 1);
1535 print '</td>';
1536 print '</tr>';
1537
1538 print '<tr>';
1539 print '<td>';
1540 print $langs->trans('Mode');
1541 print '</td>';
1542 print '<td>';
1543 $tmparray = array(
1544 'onelineperuser' => 'OneLinePerUser',
1545 'onelinepertask' => 'OneLinePerTask',
1546 'onelineperperiod' => 'OneLinePerTimeSpentLine',
1547 );
1548 print $form->selectarray('generateinvoicemode', $tmparray, 'onelineperuser', 0, 0, 0, '', 1);
1549 print "\n" . '<script type="text/javascript">';
1550 print '
1551 $(document).ready(function () {
1552 setDetailVisibility();
1553 $("#generateinvoicemode").change(function() {
1554 setDetailVisibility();
1555 });
1556 function setDetailVisibility() {
1557 generateinvoicemode = $("#generateinvoicemode option:selected").val();
1558 if (generateinvoicemode=="onelineperperiod") {
1559 $("#detail_time_duration").show();
1560 } else {
1561 $("#detail_time_duration").hide();
1562 }
1563 }
1564 });
1565 ';
1566 print '</script>' . "\n";
1567 print '<span style="display:none" id="detail_time_duration"><input type="checkbox" value="detail" name="detail_time_duration"/>' . $langs->trans('AddDetailDateAndDuration') . '</span>';
1568 print '</td>';
1569 print '</tr>';
1570
1571 if (isModEnabled("service")) {
1572 print '<tr>';
1573 print '<td>';
1574 print $langs->trans('ServiceToUseOnLines');
1575 print '</td>';
1576 print '<td>';
1577 $form->select_produits(0, 'productid', 1, 0, $projectstatic->thirdparty->price_level, 1, 2, '', 0, array(), $projectstatic->thirdparty->id, 'None', 0, 'maxwidth500');
1578 print '</td>';
1579 print '</tr>';
1580 }
1581 print '<tr>';
1582 print '<td class="titlefield">';
1583 print $langs->trans('InvoiceToUse');
1584 print '</td>';
1585 print '<td>';
1586 print $form->selectInvoiceForTimeProject($projectstatic->thirdparty->id, '', 'invoiceid', 24, 0, $langs->trans('NewInvoice'), 1, 0, 0, 'maxwidth500', '', 'all');
1587 print '</td>';
1588 print '</tr>';
1589 print '<tr>';
1590 print '<td class="titlefield">';
1591 print $langs->trans("CustomerRelativeDiscount");
1592 print '</td>';
1593 print '<td>';
1594 print '<input type="text" size="5" name="remiseproject" value="'.$projectstatic->thirdparty->remise_percent.'">%';
1595 print '</td>';
1596 print '</tr>';
1597 print '<tr class="newinvoicedetail">';
1598 print '<td class="titlefield">';
1599 print $langs->trans("PaymentConditions");
1600 print '</td>';
1601 print '<td>';
1602 print $form->getSelectConditionsPaiements((int) $projectstatic->thirdparty->cond_reglement_id, 'condidproject');
1603 print '</td>';
1604 print '</tr>';
1605 /*print '<tr>';
1606 print '<td>';
1607 print $langs->trans('ValidateInvoices');
1608 print '</td>';
1609 print '<td>';
1610 print $form->selectyesno('validate_invoices', 0, 1);
1611 print '</td>';
1612 print '</tr>';*/
1613 print '</table>';
1614
1615 print '<br>';
1616 print '<div class="center">';
1617 print '<input type="submit" class="button" id="createbills" name="createbills" value="' . $langs->trans('GenerateBill') . '"> ';
1618 print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="' . $langs->trans("Cancel") . '">';
1619 print '</div>';
1620 print '<br>';
1621 } else {
1622 print '<div class="warning">' . $langs->trans("ThirdPartyRequiredToGenerateInvoice") . '</div>';
1623 print '<div class="center">';
1624 print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="' . $langs->trans("Cancel") . '">';
1625 print '</div>';
1626 $massaction = '';
1627 }
1628 } elseif ($massaction == 'generateinter') {
1629 // Form to convert time spent into invoice
1630 print '<input type="hidden" name="massaction" value="confirm_createinter">';
1631
1632 if (!empty($projectstatic->thirdparty) && $projectstatic->thirdparty->id > 0) {
1633 print '<br>';
1634 print '<table class="noborder centpercent">';
1635 print '<tr>';
1636 print '<td class="titlefield">';
1637 print img_picto('', 'intervention', 'class="pictofixedwidth"') . $langs->trans('InterToUse');
1638 print '</td>';
1639 print '<td>';
1640 $forminter = new FormIntervention($db);
1641 print $forminter->select_interventions($projectstatic->thirdparty->id, 0, 'interid', 24, $langs->trans('NewInter'), true);
1642 print '</td>';
1643 print '</tr>';
1644 print '</table>';
1645
1646 print '<div class="center">';
1647 print '<input type="submit" class="button" id="createinter" name="createinter" value="' . $langs->trans('GenerateInter') . '"> ';
1648 print '<input type="submit" class="button" id="cancel" name="cancel" value="' . $langs->trans('Cancel') . '">';
1649 print '</div>';
1650 print '<br>';
1651 } else {
1652 print '<div class="warning">' . $langs->trans("ThirdPartyRequiredToGenerateIntervention") . '</div>';
1653 print '<div class="center">';
1654 print '<input type="submit" class="button" id="cancel" name="cancel" value="' . $langs->trans('Cancel') . '">';
1655 print '</div>';
1656 $massaction = '';
1657 }
1658 }
1659
1660 // Allow Pre-Mass-Action hook (eg for confirmation dialog)
1661 $parameters = array(
1662 'toselect' => $toselect,
1663 'uploaddir' => isset($uploaddir) ? $uploaddir : null
1664 );
1665
1666 $reshook = $hookmanager->executeHooks('doPreMassActions', $parameters, $object, $action);
1667 if ($reshook < 0) {
1668 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1669 } else {
1670 print $hookmanager->resPrint;
1671 }
1672
1673 /*
1674 * List of time spent
1675 */
1676 $tasks = array();
1677
1678 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1679 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields
1680
1681 // If project has usage "Bill time", we force visibility of field "billed"
1682 if ($projectstatic->usage_bill_time) {
1683 $arrayfields['valuebilled']['checked'] = 1;
1684 }
1685
1686 $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,";
1687 $sql .= " t.fk_product, t.invoice_line_id, t.import_key, t.datec, t.tms,";
1688 $sql .= " pt.rowid as taskid, pt.ref, pt.label, pt.fk_projet, pt.billable,";
1689 $sql .= " u.lastname, u.firstname, u.login, u.photo, u.gender, u.statut as user_status,";
1690 $sql .= " il.fk_facture as invoice_id, inv.fk_statut,";
1691 $sql .= " p.fk_soc, s.name_alias";
1692 if (!empty($extrafields->attributes['projet_task']['label'])) {
1693 foreach ($extrafields->attributes['projet_task']['label'] as $key => $val) {
1694 $sql .= ($extrafields->attributes['projet_task']['type'][$key] != 'separate' ? ",efpt.".$key." as options_".$key : '');
1695 }
1696 }
1697 // Add fields from hooks
1698 $parameters = array();
1699 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1700 $sql .= $hookmanager->resPrint;
1701 $sql = preg_replace('/,\s*$/', '', $sql);
1702
1703 $sqlfields = $sql; // $sql fields to remove for count total
1704
1705 $sql .= " FROM ".MAIN_DB_PREFIX."element_time as t";
1706 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facturedet as il ON il.rowid = t.invoice_line_id";
1707 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as inv ON inv.rowid = il.fk_facture";
1708 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as prod ON prod.rowid = t.fk_product";
1709 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."projet_task as pt ON pt.rowid = t.fk_element";
1710 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_extrafields as efpt ON pt.rowid = efpt.fk_object";
1711 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = pt.fk_projet";
1712 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON t.fk_user = u.rowid";
1713 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
1714
1715 // Add table from hooks
1716 $parameters = array();
1717 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1718 $sql .= $hookmanager->resPrint;
1719 $sql .= " WHERE elementtype = 'task'";
1720 $sql .= " AND p.entity IN (".getEntity('project').")";
1721 if (!$user->hasRight('projet', 'all', 'lire')) {
1722 // Get list of project id allowed to user (in a string list separated by comma)
1723 // TODO This may generate performance trouble when list of project is very large. Solution can be to complete $filterproj with filters on project.
1724 $filterproj = '';
1725 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $user->socid > 0 ? $user->socid : 0, $filterproj);
1726 $sql .= " AND p.rowid IN (".$db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
1727 }
1728 if (empty($projectidforalltimes) && empty($allprojectforuser)) {
1729 // Limit on one task
1730 $sql .= " AND t.fk_element =".((int) $object->id);
1731 } elseif (!empty($projectidforalltimes)) {
1732 // Limit on one project
1733 $sql .= " AND pt.fk_projet IN (" . $db->sanitize((string) $projectidforalltimes) . ")";
1734 } elseif (!empty($allprojectforuser)) {
1735 // Limit on on user
1736 if (empty($search_user) && !empty($arrayfields['author']['checked'])) {
1737 $search_user = $user->id;
1738 }
1739 if ($search_user > 0) {
1740 $sql .= " AND t.fk_user = " . ((int) $search_user);
1741 }
1742 }
1743
1744 if ($search_note) {
1745 $sql .= natural_search('t.note', $search_note);
1746 }
1747 if ($search_task_ref) {
1748 $sql .= natural_search('pt.ref', $search_task_ref);
1749 }
1750 if (empty($arrayfields['s.name_alias']['checked']) && $search_company) {
1751 $sql .= natural_search(array("s.nom", "s.name_alias"), $search_company);
1752 } else {
1753 if ($search_company) {
1754 $sql .= natural_search('s.nom', $search_company);
1755 }
1756 if ($search_company_alias) {
1757 $sql .= natural_search('s.name_alias', $search_company_alias);
1758 }
1759 }
1760 if ($search_project_ref) {
1761 $sql .= natural_search('p.ref', $search_project_ref);
1762 }
1763 if ($search_project_label) {
1764 $sql .= natural_search('p.title', $search_project_label);
1765 }
1766 if ($search_task_label) {
1767 $sql .= natural_search('pt.label', $search_task_label);
1768 }
1769 if ($search_user > 0) {
1770 $sql .= natural_search('t.fk_user', $search_user, 2);
1771 }
1772 if (!empty($search_product_ref)) {
1773 $sql .= natural_search('prod.ref', $search_product_ref);
1774 }
1775 if ($search_valuebilled == '1') {
1776 $sql .= ' AND t.invoice_id > 0';
1777 }
1778 if ($search_valuebilled == '0') {
1779 $sql .= ' AND (t.invoice_id = 0 OR t.invoice_id IS NULL)';
1780 }
1781
1782 if ($search_date_start) {
1783 $sql .= " AND t.element_date >= '".$db->idate($search_date_start)."'";
1784 }
1785 if ($search_date_end) {
1786 $sql .= " AND t.element_date <= '".$db->idate($search_date_end)."'";
1787 }
1788
1789 if (!empty($arrayfields['t.element_duration']['checked'])) {
1790 if ($search_timespent_starthour || $search_timespent_startmin) {
1791 $timespent_duration_start = $search_timespent_starthour * 60 * 60; // We store duration in seconds
1792 $timespent_duration_start += ($search_timespent_startmin ? $search_timespent_startmin : 0) * 60; // We store duration in seconds
1793 $sql .= " AND t.element_duration >= " . ((int) $timespent_duration_start);
1794 }
1795
1796 if ($search_timespent_endhour || $search_timespent_endmin) {
1797 $timespent_duration_end = $search_timespent_endhour * 60 * 60; // We store duration in seconds
1798 $timespent_duration_end += ($search_timespent_endmin ? $search_timespent_endmin : 0) * 60; // We store duration in seconds
1799 $sql .= " AND t.element_duration <= " . ((int) $timespent_duration_end);
1800 }
1801 }
1802
1803 $sql .= dolSqlDateFilter('t.element_datehour', $search_day, $search_month, $search_year);
1804
1805 // Add where from extra fields
1806 $extrafieldsobjectkey = 'projet_task';
1807 $extrafieldsobjectprefix = 'efpt.';
1808 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
1809
1810 // Add where from hooks
1811 $parameters = array();
1812 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1813 $sql .= $hookmanager->resPrint;
1814
1815 // Count total nb of records
1816 $nbtotalofrecords = '';
1817 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
1818 /* The fast and low memory method to get and count full list converts the sql into a sql count */
1819 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
1820 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
1821 $resql = $db->query($sqlforcount);
1822 if ($resql) {
1823 $objforcount = $db->fetch_object($resql);
1824 $nbtotalofrecords = $objforcount->nbtotalofrecords;
1825 } else {
1827 }
1828
1829 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
1830 $page = 0;
1831 $offset = 0;
1832 }
1833 $db->free($resql);
1834 }
1835
1836 // Complete request and execute it with limit
1837 $sql .= $db->order($sortfield, $sortorder);
1838 if ($limit) {
1839 $sql .= $db->plimit($limit + 1, $offset);
1840 }
1841
1842 $resql = $db->query($sql);
1843 if (!$resql) {
1845 exit;
1846 }
1847
1848 $num = $db->num_rows($resql);
1849
1850 if ($num >= 0) {
1851 if (!empty($projectidforalltimes)) {
1852 print '<!-- List of time spent for project -->' . "\n";
1853
1854 $title = $langs->trans("ListTaskTimeUserProject");
1855
1856 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'clock', 0, $linktocreatetime, '', $limit, 0, 0, 1);
1857 } else {
1858 print '<!-- List of time spent -->' . "\n";
1859
1860 $title = $langs->trans("ListTaskTimeForTask");
1861
1862 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'clock', 0, $linktocreatetime, '', $limit, 0, 0, 1);
1863 }
1864
1865 $i = 0;
1866 while ($i < $num) {
1867 $obj = $db->fetch_object($resql);
1868
1869 $tasks[$i] = $obj;
1870
1871 $i++;
1872 }
1873 $db->free($resql);
1874 } else {
1876 }
1877
1878 /*
1879 * Form to add a new line of time spent
1880 */
1881 if ($action == 'createtime' && $user->hasRight('projet', 'time')) {
1882 print '<!-- table to add time spent -->' . "\n";
1883 if (!empty($id)) {
1884 print '<input type="hidden" name="taskid" value="' . $id . '">';
1885 }
1886
1887 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
1888 print '<table class="noborder nohover centpercent">';
1889
1890 print '<tr class="liste_titre">';
1891 print '<td>' . $langs->trans("Date") . '</td>';
1892 if (!empty($allprojectforuser)) {
1893 print '<td>' . $langs->trans("Project") . '</td>';
1894 }
1895 if (empty($id)) {
1896 print '<td>' . $langs->trans("Task") . '</td>';
1897 }
1898 print '<td>' . $langs->trans("By") . '</td>';
1899 print '<td>' . $langs->trans("Note") . '</td>';
1900 print '<td>' . $langs->trans("NewTimeSpent") . '</td>';
1901 print '<td>' . $langs->trans("ProgressDeclared") . '</td>';
1902 if (!getDolGlobalString('PROJECT_HIDE_TASKS') && getDolGlobalString('PROJECT_BILL_TIME_SPENT')) {
1903 print '<td></td>';
1904
1905 if (isModEnabled("service") && !empty($projectstatic->thirdparty) && $projectstatic->thirdparty->id > 0 && $projectstatic->usage_bill_time) {
1906 print '<td>'.$langs->trans("Product").'</td>';
1907 }
1908 }
1909 // Hook fields
1910 $parameters = array('mode' => 'create');
1911 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1912 print $hookmanager->resPrint;
1913 print '<td></td>';
1914 print "</tr>\n";
1915
1916 print '<tr class="oddeven nohover">';
1917
1918 // Date
1919 print '<td class="maxwidthonsmartphone">';
1920 $newdate = '';
1921 print $form->selectDate($newdate, 'time', ($conf->browser->layout == 'phone' ? 2 : 1), 1, 2, "timespent_date", 1, 0);
1922 print '</td>';
1923
1924 if (!empty($allprojectforuser)) {
1925 print '<td>';
1926 // Add project selector
1927 print '</td>';
1928 }
1929
1930 // Task
1931 $nboftasks = 0;
1932 if (empty($id)) {
1933 print '<td class="maxwidthonsmartphone">';
1934 $nboftasks = $formproject->selectTasks(-1, GETPOSTINT('taskid'), 'taskid', 0, 0, '1', 1, 0, 0, 'maxwidth300', (string) $projectstatic->id, 'progress');
1935 print '</td>';
1936 }
1937
1938 // Contributor
1939 print '<td class="maxwidthonsmartphone nowraponall">';
1940 $contactsofproject = $projectstatic->getListContactId('internal');
1941 if (count($contactsofproject) > 0) {
1942 print img_object('', 'user', 'class="hideonsmartphone"');
1943 if (in_array($user->id, $contactsofproject)) {
1944 $userid = $user->id;
1945 } else {
1946 $userid = $contactsofproject[0];
1947 }
1948
1949 if ($projectstatic->public) {
1950 $contactsofproject = array();
1951 }
1952 print $form->select_dolusers((GETPOSTINT('userid') ? GETPOSTINT('userid') : $userid), 'userid', 0, null, 0, '', $contactsofproject, '0', 0, 0, '', 0, $langs->trans("ResourceNotAssignedToProject"), 'minwidth150imp maxwidth200');
1953 } else {
1954 if ($nboftasks) {
1955 print img_error($langs->trans('FirstAddRessourceToAllocateTime')) . ' ' . $langs->trans('FirstAddRessourceToAllocateTime');
1956 }
1957 }
1958 print '</td>';
1959
1960 // Note
1961 print '<td>';
1962 print '<textarea name="timespent_note" class="maxwidth100onsmartphone" rows="' . ROWS_2 . '">' . (GETPOST('timespent_note') ? GETPOST('timespent_note') : '') . '</textarea>';
1963 print '</td>';
1964
1965 // Duration - Time spent
1966 print '<td class="nowraponall">';
1967 $durationtouse = (GETPOST('timespent_duration') ? GETPOST('timespent_duration') : '');
1968 if (GETPOSTISSET('timespent_durationhour') || GETPOSTISSET('timespent_durationmin')) {
1969 $durationtouse = ((int) GETPOST('timespent_durationhour') * 3600 + (int) GETPOST('timespent_durationmin') * 60);
1970 }
1971 print $form->select_duration('timespent_duration', $durationtouse, 0, 'text');
1972 print '</td>';
1973
1974 // Progress declared
1975 print '<td class="nowrap">';
1976 print $formother->select_percent(GETPOST('progress') ? GETPOST('progress') : $object->progress, 'progress', 0, 5, 0, 100, 1);
1977 print '</td>';
1978
1979 // Billed
1980 if (!getDolGlobalString('PROJECT_HIDE_TASKS') && getDolGlobalString('PROJECT_BILL_TIME_SPENT')) {
1981 print '<td>';
1982 print '</td>';
1983
1984 if (isModEnabled("service") && !empty($projectstatic->thirdparty) && $projectstatic->thirdparty->id > 0 && $projectstatic->usage_bill_time) {
1985 print '<td class="nowraponall">';
1986 print img_picto('', 'service');
1987 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);
1988 print '</td>';
1989 }
1990 }
1991
1992 // Fields from hook
1993 $parameters = array('mode' => 'create');
1994 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1995 print $hookmanager->resPrint;
1996
1997 print '<td class="center">';
1998 $form->buttonsSaveCancel();
1999 print '<input type="submit" name="save" class="button buttongen smallpaddingimp marginleftonly margintoponlyshort marginbottomonlyshort button-add reposition" value="'.$langs->trans("Add").'">';
2000 print '<input type="submit" name="cancel" class="button buttongen smallpaddingimp marginleftonly margintoponlyshort marginbottomonlyshort button-cancel" value="'.$langs->trans("Cancel").'">';
2001 print '</td></tr>';
2002
2003 print '</table>';
2004 print '</div>';
2005
2006 print '<br>';
2007 }
2008
2009 $moreforfilter = '';
2010
2011 $parameters = array();
2012 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2013 if (empty($reshook)) {
2014 $moreforfilter .= $hookmanager->resPrint;
2015 } else {
2016 $moreforfilter = $hookmanager->resPrint;
2017 }
2018
2019 if (!empty($moreforfilter)) {
2020 print '<div class="liste_titre liste_titre_bydiv centpercent">';
2021 print $moreforfilter;
2022 print '</div>';
2023 }
2024
2025 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
2026 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields
2027 $selectedfields .= (is_array($arrayofmassactions) && count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
2028
2029 // If project has usage "Bill time", we force visibility of field "billed"
2030 if ($projectstatic->usage_bill_time) {
2031 $arrayfields['valuebilled']['checked'] = 1;
2032 }
2033
2034 print '<!-- Liste of time spent -->'."\n";
2035 print '<div class="div-table-responsive">';
2036 print '<table class="tagtable nobottomiftotal liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n";
2037
2038 // Fields title search
2039 // --------------------------------------------------------------------
2040 print '<tr class="liste_titre_filter">';
2041 // Action column
2042 if ($conf->main_checkbox_left_column) {
2043 print '<td class="liste_titre center">';
2044 $searchpicto = $form->showFilterButtons('left');
2045 print $searchpicto;
2046 print '</td>';
2047 }
2048 // Date
2049 if (!empty($arrayfields['t.element_date']['checked'])) {
2050 print '<td class="liste_titre left">';
2051 print '<div class="nowrapfordate paddingright">';
2052 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
2053 print '</div>';
2054 print '<div class="nowrapfordate">';
2055 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
2056 print '</div>';
2057 print '</td>';
2058 }
2059 // Thirdparty
2060 if (!empty($arrayfields['p.fk_soc']['checked'])) {
2061 print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="$search_company" value="' . dol_escape_htmltag($search_company) . '"></td>';
2062 }
2063
2064 // Thirdparty alias
2065 if (!empty($arrayfields['s.name_alias']['checked'])) {
2066 print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="$search_company_alias" value="' . dol_escape_htmltag($search_company_alias) . '"></td>';
2067 }
2068
2069 if (!empty($allprojectforuser)) {
2070 if (!empty($arrayfields['p.project_ref']['checked'])) {
2071 print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="$search_project_ref" value="' . dol_escape_htmltag($search_project_ref) . '"></td>';
2072 }
2073 if (!empty($arrayfields['p.project_label']['checked'])) {
2074 print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="$search_project_label" value="' . dol_escape_htmltag($search_project_label) . '"></td>';
2075 }
2076 }
2077 // Task
2078 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2079 if (!empty($arrayfields['t.element_ref']['checked'])) {
2080 print '<td class="liste_titre"><input type="text" class="flat maxwidth75" name="search_task_ref" value="'.dol_escape_htmltag($search_task_ref).'"></td>';
2081 }
2082 if (!empty($arrayfields['t.element_label']['checked'])) {
2083 print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_task_label" value="'.dol_escape_htmltag($search_task_label).'"></td>';
2084 }
2085 }
2086 // Author
2087 if (!empty($arrayfields['author']['checked'])) {
2088 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>';
2089 }
2090 // Note
2091 if (!empty($arrayfields['t.note']['checked'])) {
2092 print '<td class="liste_titre"><input type="text" class="flat maxwidth75" name="search_note" value="' . dol_escape_htmltag($search_note) . '"></td>';
2093 }
2094 // Last modification
2095 if (!empty($arrayfields['t.tms']['checked'])) {
2096 print '<td class="liste_titre"></td>';
2097 }
2098 // Duration
2099 if (!empty($arrayfields['t.element_duration']['checked'])) {
2100 // Duration - Time spent
2101 print '<td class="liste_titre right">';
2102
2103 $durationtouse_start = '';
2104 if ($search_timespent_starthour || $search_timespent_startmin) {
2105 $durationtouse_start = ($search_timespent_starthour * 3600 + $search_timespent_startmin * 60);
2106 }
2107 print '<div class="nowraponall"><span class="opacitymedium">' . $langs->trans('fromhour') . '</span> ';
2108 print $form->select_duration('search_timespent_duration_start', $durationtouse_start, 0, 'text', 0, 1);
2109 print '</div>';
2110
2111 $durationtouse_end = '';
2112 if ($search_timespent_endhour || $search_timespent_endmin) {
2113 $durationtouse_end = ($search_timespent_endhour * 3600 + $search_timespent_endmin * 60);
2114 }
2115 print '<div class="nowraponall"><span class="opacitymedium">' . $langs->trans('tohour') . '</span> ';
2116 print $form->select_duration('search_timespent_duration_end', $durationtouse_end, 0, 'text', 0, 1);
2117 print '</div>';
2118
2119 print '</td>';
2120 }
2121 // Product
2122 if (!empty($arrayfields['t.fk_product']['checked'])) {
2123 print '<td class="liste_titre"></td>';
2124 }
2125 // Value in main currency
2126 if (!empty($arrayfields['value']['checked'])) {
2127 print '<td class="liste_titre"></td>';
2128 }
2129 // Value billed
2130 if (!empty($arrayfields['valuebilled']['checked'])) {
2131 print '<td class="liste_titre center">' . $form->selectyesno('search_valuebilled', $search_valuebilled, 1, false, 1) . '</td>';
2132 }
2133
2134 // Extra fields
2135 $extrafieldsobjectkey = 'projet_task';
2136 $extrafieldsobjectprefix = 'ef.';
2137 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
2138 // Fields from hook
2139 $parameters = array('arrayfields' => $arrayfields);
2140 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2141 print $hookmanager->resPrint;
2142 // Action column
2143 if (!$conf->main_checkbox_left_column) {
2144 print '<td class="liste_titre center">';
2145 $searchpicto = $form->showFilterButtons();
2146 print $searchpicto;
2147 print '</td>';
2148 }
2149 print '</tr>' . "\n";
2150
2151
2152 $totalarray = array();
2153 $totalarray['nbfield'] = 0;
2154
2155 // Fields title label
2156 // --------------------------------------------------------------------
2157 print '<tr class="liste_titre">';
2158 if ($conf->main_checkbox_left_column) {
2159 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center maxwidthsearch ');
2160 $totalarray['nbfield']++;
2161 }
2162 if (!empty($arrayfields['t.element_date']['checked'])) {
2163 print_liste_field_titre($arrayfields['t.element_date']['label'], $_SERVER['PHP_SELF'], 't.element_date,t.element_datehour,t.rowid', '', $param, '', $sortfield, $sortorder);
2164 $totalarray['nbfield']++;
2165 }
2166 if (!empty($arrayfields['p.fk_soc']['checked'])) {
2167 print_liste_field_titre($arrayfields['p.fk_soc']['label'], $_SERVER['PHP_SELF'], 't.element_date,t.element_datehour,t.rowid', '', $param, '', $sortfield, $sortorder);
2168 $totalarray['nbfield']++;
2169 }
2170 if (!empty($arrayfields['s.name_alias']['checked'])) {
2171 // @phan-suppress-next-line PhanTypeInvalidDimOffset
2172 print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER['PHP_SELF'], 's.name_alias', '', $param, '', $sortfield, $sortorder);
2173 $totalarray['nbfield']++;
2174 }
2175 if (!empty($allprojectforuser)) {
2176 if (!empty($arrayfields['p.project_ref']['checked'])) {
2177 print_liste_field_titre($arrayfields['p.project_ref']['label'], $_SERVER['PHP_SELF'], 'p.ref', '', $param, '', $sortfield, $sortorder);
2178 $totalarray['nbfield']++;
2179 }
2180 if (!empty($arrayfields['p.project_label']['checked'])) {
2181 print_liste_field_titre($arrayfields['p.project_label']['label'], $_SERVER['PHP_SELF'], 'p.title', '', $param, '', $sortfield, $sortorder);
2182 $totalarray['nbfield']++;
2183 }
2184 }
2185 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2186 if (!empty($arrayfields['t.element_ref']['checked'])) {
2187 print_liste_field_titre($arrayfields['t.element_ref']['label'], $_SERVER['PHP_SELF'], 'pt.ref', '', $param, '', $sortfield, $sortorder);
2188 $totalarray['nbfield']++;
2189 }
2190 if (!empty($arrayfields['t.element_label']['checked'])) {
2191 print_liste_field_titre($arrayfields['t.element_label']['label'], $_SERVER['PHP_SELF'], 'pt.label', '', $param, '', $sortfield, $sortorder);
2192 $totalarray['nbfield']++;
2193 }
2194 }
2195 if (!empty($arrayfields['author']['checked'])) {
2196 print_liste_field_titre($arrayfields['author']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
2197 $totalarray['nbfield']++;
2198 }
2199 if (!empty($arrayfields['t.note']['checked'])) {
2200 print_liste_field_titre($arrayfields['t.note']['label'], $_SERVER['PHP_SELF'], 't.note', '', $param, '', $sortfield, $sortorder);
2201 $totalarray['nbfield']++;
2202 }
2203 if (!empty($arrayfields['t.tms']['checked'])) {
2204 print_liste_field_titre($arrayfields['t.tms']['label'], $_SERVER['PHP_SELF'], 't.tms', '', $param, '', $sortfield, $sortorder);
2205 $totalarray['nbfield']++;
2206 }
2207 if (!empty($arrayfields['t.element_duration']['checked'])) {
2208 print_liste_field_titre($arrayfields['t.element_duration']['label'], $_SERVER['PHP_SELF'], 't.element_duration', '', $param, '', $sortfield, $sortorder, 'right ');
2209 $totalarray['nbfield']++;
2210 }
2211 if (!empty($arrayfields['t.fk_product']['checked'])) {
2212 print_liste_field_titre($arrayfields['t.fk_product']['label'], $_SERVER['PHP_SELF'], 't.fk_product', '', $param, '', $sortfield, $sortorder);
2213 $totalarray['nbfield']++;
2214 }
2215
2216 if (!empty($arrayfields['value']['checked'])) {
2217 print_liste_field_titre($arrayfields['value']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
2218 $totalarray['nbfield']++;
2219 }
2220 if (!empty($arrayfields['valuebilled']['checked'])) {
2221 print_liste_field_titre($arrayfields['valuebilled']['label'], $_SERVER['PHP_SELF'], 'il.total_ht', '', $param, '', $sortfield, $sortorder, 'center ', $langs->trans("SelectLinesOfTimeSpentToInvoice"));
2222 $totalarray['nbfield']++;
2223 }
2224 // Extra fields
2225 $extrafieldsobjectkey = 'projet_task';
2226 $extrafieldsobjectprefix = 'ef.';
2227 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
2228 // Hook fields
2229 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
2230 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2231 print $hookmanager->resPrint;
2232 if (!$conf->main_checkbox_left_column) {
2233 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center maxwidthsearch ');
2234 $totalarray['nbfield']++;
2235 }
2236 print "</tr>\n";
2237
2238 $tasktmp = new Task($db);
2239 $tmpinvoice = new Facture($db);
2240
2241 if ($page) {
2242 $param .= '&page='.((int) $page);
2243 }
2244 $param .= '&sortfield='.urlencode($sortfield).'&sortorder='.urlencode($sortorder);
2245
2246 $i = 0;
2247
2248 $savnbfield = $totalarray['nbfield'];
2249 $totalarray = array();
2250 $totalarray['nbfield'] = 0;
2251 //$imaxinloop = ($limit ? min($num, $limit) : $num);
2252 foreach ($tasks as $task_time) {
2253 if ($i >= $limit) {
2254 break;
2255 }
2256
2257 // Line is invoiced if it has an invoice_id
2258 $invoiced = $task_time->invoice_id ? true : false;
2259
2260 $date1 = $db->jdate($task_time->element_date);
2261 $date2 = $db->jdate($task_time->element_datehour);
2262
2263 // Show here line of result
2264 $j = 0;
2265 print '<tr data-rowid="'.$task_time->rowid.'" class="oddeven">';
2266
2267 // Action column
2268 if ($conf->main_checkbox_left_column) {
2269 print '<td class="center nowraponall">';
2270 if (($action == 'editline' || $action == 'splitline') && GETPOSTINT('lineid') == $task_time->rowid) {
2271 print '<input type="hidden" name="lineid" value="' . GETPOSTINT('lineid') . '">';
2272 if ($id) {
2273 print '<input type="hidden" name="id" value="' . $id . '">'; // If you enable this, the edit will go beack to task view
2274 }
2275 print '<input type="submit" class="button buttongen reposition smallpaddingimp margintoponlyshort marginbottomonlyshort button-save" name="save" value="'.$langs->trans("Save").'">';
2276 print '<br>';
2277 print '<input type="submit" class="button buttongen reposition smallpaddingimp margintoponlyshort marginbottomonlyshort button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
2278 } elseif ($user->hasRight('projet', 'time') || $user->hasRight('projet', 'all', 'creer')) { // Read project and enter time consumed on assigned tasks
2279 if (in_array($task_time->fk_user, $childids) || $user->hasRight('projet', 'all', 'creer')) {
2280 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' : '').'">';
2281 print img_edit('default', 0, 'class="pictofixedwidth paddingleft"');
2282 print '</a>';
2283
2284 if (getDolGlobalString('PROJECT_ALLOW_SPLIT_TIMESPENT')) {
2285 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' : '') . '">';
2286 print img_split('', 'class="pictofixedwidth paddingleft"');
2287 print '</a>';
2288 }
2289
2290 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' : '').'">';
2291 print img_delete('default', 'class="pictodelete paddingleft"');
2292 print '</a>';
2293
2294 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2295 $selected = 0;
2296 if (in_array($task_time->rowid, $arrayofselected)) {
2297 $selected = 1;
2298 }
2299 print '&nbsp;';
2300
2301 // Disable select if task not billable or already invoiced
2302 $disabled = (intval($task_time->billable) != 1 || $invoiced);
2303 $ctrl = '<input '.($disabled ? 'disabled' : '').' id="cb' . $task_time->rowid . '" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="' . $task_time->rowid . '"' . ($selected ? ' checked="checked"' : '') . '>';
2304 if ($disabled) {
2305 // If disabled, a dbl-click very close outside the control
2306 // will re-enable it, so that user is not blocked if needed.
2307 print '<span id="cbsp'. $task_time->rowid . '">'.$ctrl.'</span>';
2308 print '<script>$("#cbsp' . $task_time->rowid . '").dblclick(()=>{ $("#cb' . $task_time->rowid . '").removeAttr("disabled") })</script>';
2309 } else {
2310 print $ctrl;
2311 }
2312 }
2313 }
2314 }
2315 print '</td>';
2316 if (!$i) {
2317 $totalarray['nbfield']++;
2318 }
2319 }
2320
2321 // Date
2322 if (!empty($arrayfields['t.element_date']['checked'])) {
2323 print '<td class="nowrap">';
2324 if ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) {
2325 if (empty($task_time->element_date_withhour)) {
2326 print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 4, 3, 2, "timespent_date", 1, 0);
2327 } else {
2328 print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 2, 1, 2, "timespent_date", 1, 0);
2329 }
2330 } else {
2331 print dol_print_date(($date2 ? $date2 : $date1), ($task_time->element_date_withhour ? 'dayhour' : 'day'));
2332 }
2333 print '</td>';
2334 if (!$i) {
2335 $totalarray['nbfield']++;
2336 }
2337 }
2338
2339 // Thirdparty
2340 if (!empty($arrayfields['p.fk_soc']['checked'])) {
2341 print '<td class="tdoverflowmax125">';
2342 if ($task_time->fk_soc > 0) {
2343 if (empty($conf->cache['thirdparty'][$task_time->fk_soc])) {
2344 $tmpsociete = new Societe($db);
2345 $tmpsociete->fetch($task_time->fk_soc);
2346 $conf->cache['thirdparty'][$task_time->fk_soc] = $tmpsociete;
2347 } else {
2348 $tmpsociete = $conf->cache['thirdparty'][$task_time->fk_soc];
2349 }
2350 print $tmpsociete->getNomUrl(1, '', 100, 0, 1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
2351 }
2352 print '</td>';
2353 if (!$i) {
2354 $totalarray['nbfield']++;
2355 }
2356 }
2357
2358 // Thirdparty alias
2359 if (!empty($arrayfields['s.name_alias']['checked'])) {
2360 $valtoshow = '';
2361 if ($task_time->fk_soc > 0) {
2362 if (empty($conf->cache['thirdparty'][$task_time->fk_soc])) {
2363 $tmpsociete = new Societe($db);
2364 $tmpsociete->fetch($task_time->fk_soc);
2365 $conf->cache['thirdparty'][$task_time->fk_soc] = $tmpsociete;
2366 } else {
2367 $tmpsociete = $conf->cache['thirdparty'][$task_time->fk_soc];
2368 }
2369 $valtoshow = $tmpsociete->name_alias;
2370 }
2371 print '<td class="nowrap tdoverflowmax150" title="'.dol_escape_htmltag($valtoshow).'">';
2372 print $valtoshow;
2373 print '</td>';
2374 if (!$i) {
2375 $totalarray['nbfield']++;
2376 }
2377 }
2378
2379 if (!empty($allprojectforuser)) {
2380 // Project ref
2381 if (!empty($arrayfields['p.project_ref']['checked'])) {
2382 if (empty($conf->cache['project'][$task_time->fk_projet])) {
2383 $tmpproject = new Project($db);
2384 $tmpproject->fetch($task_time->fk_projet);
2385 $conf->cache['project'][$task_time->fk_projet] = $tmpproject;
2386 } else {
2387 $tmpproject = $conf->cache['project'][$task_time->fk_projet];
2388 }
2389 print '<td class="nowraponall">';
2390 print $tmpproject->getNomUrl(1);
2391 print '</td>';
2392 if (!$i) {
2393 $totalarray['nbfield']++;
2394 }
2395 }
2396 // Project label
2397 if (!empty($arrayfields['p.project_label']['checked'])) {
2398 if (empty($conf->cache['project'][$task_time->fk_projet])) {
2399 $tmpproject = new Project($db);
2400 $tmpproject->fetch($task_time->fk_projet);
2401 $conf->cache['project'][$task_time->fk_projet] = $tmpproject;
2402 } else {
2403 $tmpproject = $conf->cache['project'][$task_time->fk_projet];
2404 }
2405 print '<td class="tdoverflowmax250" title="'.dolPrintHTMLForAttribute($tmpproject->title).'">';
2406 if (!empty($arrayfields['p.project_ref']['checked'])) {
2407 print dolPrintHTML($tmpproject->title);
2408 } else {
2409 print $tmpproject->getNomUrl(1, '', -1);
2410 }
2411 print '</td>';
2412 if (!$i) {
2413 $totalarray['nbfield']++;
2414 }
2415 }
2416 }
2417
2418 // Task ref
2419 if (!empty($arrayfields['t.element_ref']['checked'])) {
2420 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2421 print '<td class="nowrap">';
2422 if ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) {
2423 $formproject->selectTasks(-1, GETPOSTINT('taskid') ? GETPOSTINT('taskid') : $task_time->fk_element, 'taskid', 0, 0, '1', 1, 0, 0, 'maxwidth250', (string) $projectstatic->id, '');
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');
2429 }
2430 print '</td>';
2431 if (!$i) {
2432 $totalarray['nbfield']++;
2433 }
2434 }
2435 } elseif ($action !== 'createtime') {
2436 print '<input type="hidden" name="taskid" value="' . $id . '">';
2437 }
2438
2439 // Task label
2440 if (!empty($arrayfields['t.element_label']['checked'])) {
2441 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2442 print '<td class="tdoverflowmax250" title="'.dolPrintHTMLForAttribute($task_time->label).'">';
2443 if (!empty($arrayfields['t.element_ref']['checked'])) {
2444 print dolPrintHTML($task_time->label);
2445 } else {
2446 $tasktmp->id = $task_time->fk_element;
2447 $tasktmp->ref = $task_time->ref;
2448 $tasktmp->label = $task_time->label;
2449 print $tasktmp->getNomUrl(1, 'withproject', 'time', -1);
2450 }
2451 print '</td>';
2452 if (!$i) {
2453 $totalarray['nbfield']++;
2454 }
2455 }
2456 }
2457
2458 // User
2459 if (!empty($arrayfields['author']['checked'])) {
2460 print '<td class="tdoverflowmax125">';
2461 if ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) {
2462 // Here $object is task. TODO Add a cache
2463 if (empty($object->id)) {
2464 $object->fetch($task_time->fk_element);
2465 }
2466 $contactsoftask = $object->getListContactId('internal');
2467 if (!in_array($task_time->fk_user, $contactsoftask)) {
2468 $contactsoftask[] = $task_time->fk_user;
2469 }
2470 if (count($contactsoftask) > 0) {
2471 print img_object('', 'user', 'class="pictofixedwidth hideonsmartphone"');
2472 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
2473 } else {
2474 print img_error($langs->trans('FirstAddRessourceToAllocateTime')) . $langs->trans('FirstAddRessourceToAllocateTime');
2475 }
2476 } else {
2477 $userstatic->id = $task_time->fk_user;
2478 $userstatic->lastname = $task_time->lastname;
2479 $userstatic->firstname = $task_time->firstname;
2480 $userstatic->photo = $task_time->photo;
2481 $userstatic->gender = $task_time->gender;
2482 $userstatic->status = $task_time->user_status;
2483
2484 print $userstatic->getNomUrl(-1);
2485 }
2486 print '</td>';
2487 if (!$i) {
2488 $totalarray['nbfield']++;
2489 }
2490 }
2491
2492 // Note
2493 if (!empty($arrayfields['t.note']['checked'])) {
2494 if ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) {
2495 print '<td class="small">';
2496 print '<textarea name="timespent_note_line" class="centpercentimp" rows="' . ROWS_2 . '">' . dol_escape_htmltag($task_time->note, 0, 1) . '</textarea>';
2497 print '</td>';
2498 } else {
2499 print '<td class="small tdoverflowmax150 classfortooltip" title="'.dol_string_onlythesehtmltags(dol_htmlentitiesbr($task_time->note)).'">';
2500 print dolGetFirstLineOfText($task_time->note);
2501 print '</td>';
2502 }
2503 if (!$i) {
2504 $totalarray['nbfield']++;
2505 }
2506 } elseif ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) {
2507 print '<input type="hidden" name="timespent_note_line" value="' . dol_escape_htmltag($task_time->note, 0, 1) . '">';
2508 }
2509
2510 // Last modification
2511 if (!empty($arrayfields['t.tms']['checked'])) {
2512 print '<td class="nowraponall">';
2513 print dol_print_date($task_time->tms, 'dayhour');
2514 print '</td>';
2515 if (!$i) {
2516 $totalarray['nbfield']++;
2517 }
2518 }
2519
2520 // Time spent - Duration
2521 if (!empty($arrayfields['t.element_duration']['checked'])) {
2522 print '<td class="right nowraponall">';
2523 if ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) {
2524 print '<input type="hidden" name="old_duration" value="'.$task_time->element_duration.'">';
2525 print $form->select_duration('new_duration', $task_time->element_duration, 0, 'text');
2526 } else {
2527 print convertSecondToTime($task_time->element_duration, 'allhourmin');
2528 }
2529 print '</td>';
2530 if (!$i) {
2531 $totalarray['nbfield']++;
2532 }
2533 if (!$i) {
2534 $totalarray['pos'][$totalarray['nbfield']] = 't.element_duration';
2535 }
2536 if (empty($totalarray['val']['t.element_duration'])) {
2537 $totalarray['val']['t.element_duration'] = $task_time->element_duration;
2538 } else {
2539 $totalarray['val']['t.element_duration'] += $task_time->element_duration;
2540 }
2541 if (!$i) {
2542 $totalarray['totaldurationfield'] = $totalarray['nbfield'];
2543 }
2544 if (empty($totalarray['totalduration'])) {
2545 $totalarray['totalduration'] = $task_time->element_duration;
2546 } else {
2547 $totalarray['totalduration'] += $task_time->element_duration;
2548 }
2549 }
2550
2551 // Product
2552 if (!empty($arrayfields['t.fk_product']['checked'])) {
2553 print '<td class="nowraponall">';
2554 if ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) {
2555 print img_picto('', 'service');
2556 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);
2557 } elseif (!empty($task_time->fk_product)) {
2558 $product = new Product($db);
2559 $resultFetch = $product->fetch($task_time->fk_product);
2560 if ($resultFetch < 0) {
2561 setEventMessages($product->error, $product->errors, 'errors');
2562 } else {
2563 print $product->getNomUrl(1);
2564 }
2565 }
2566 print '</td>';
2567 if (!$i) {
2568 $totalarray['nbfield']++;
2569 }
2570 }
2571
2572 // Value spent
2573 if (!empty($arrayfields['value']['checked'])) {
2574 $langs->load("salaries");
2575 $value = price2num($task_time->thm * $task_time->element_duration / 3600, 'MT', 1);
2576
2577 print '<td class="nowraponall right">';
2578 print '<span class="amount" title="' . $langs->trans("THM") . ': ' . price($task_time->thm) . '">';
2579 print price($value, 1, $langs, 1, -1, -1, $conf->currency);
2580 print '</span>';
2581 print '</td>';
2582 if (!$i) {
2583 $totalarray['nbfield']++;
2584 }
2585 if (!$i) {
2586 $totalarray['pos'][$totalarray['nbfield']] = 'value';
2587 }
2588 if (empty($totalarray['val']['value'])) {
2589 $totalarray['val']['value'] = $value;
2590 } else {
2591 $totalarray['val']['value'] += $value;
2592 }
2593 if (!$i) {
2594 $totalarray['totalvaluefield'] = $totalarray['nbfield'];
2595 }
2596 if (empty($totalarray['totalvalue'])) {
2597 $totalarray['totalvalue'] = $value;
2598 } else {
2599 $totalarray['totalvalue'] += $value;
2600 }
2601 }
2602
2603 // Value billed
2604 if (!empty($arrayfields['valuebilled']['checked'])) {
2605 print '<td class="center">'; // invoice_id and invoice_line_id
2606 if (!getDolGlobalString('PROJECT_HIDE_TASKS') && getDolGlobalString('PROJECT_BILL_TIME_SPENT')) {
2607 if ($projectstatic->usage_bill_time) {
2608 if ($task_time->invoice_id) {
2609 $result = $tmpinvoice->fetch($task_time->invoice_id);
2610 if ($result > 0) {
2611 if ($user->hasRight('facture', 'lire')) {
2612 if ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) {
2613 print $formproject->selectInvoiceAndLine($task_time->invoice_id, $task_time->invoice_line_id, 'invoiceid', 'invoicelineid', 'maxwidth500', array('p.rowid' => $projectstatic->id));
2614 } else {
2615 print $tmpinvoice->getNomUrl(1);
2616 if (!empty($task_time->invoice_line_id)) {
2617 $invoiceLine = new FactureLigne($db);
2618 $invoiceLine->fetch($task_time->invoice_line_id);
2619 if (!empty($invoiceLine->id)) {
2620 print '<br><span class="small opacitymedium">'.$langs->trans('Qty').':'.$invoiceLine->qty;
2621 print ' '.$langs->trans('TotalHT').':'.price($invoiceLine->total_ht);
2622 print '</span>';
2623 }
2624 }
2625 }
2626 } else {
2627 print $langs->trans("Yes");
2628 }
2629 }
2630 $invoiced = true;
2631 } else {
2632 if (intval($task_time->billable) == 1) {
2633 print $langs->trans("No");
2634 } else {
2635 print $langs->trans("Disabled");
2636 }
2637 }
2638 } else {
2639 print '<span class="opacitymedium">' . $langs->trans("NA") . '</span>';
2640 }
2641 }
2642 print '</td>';
2643 if (!$i) {
2644 $totalarray['nbfield']++;
2645 }
2646 }
2647
2648 // Extra fields
2649 $obj = $task_time;
2650 $extrafieldsobjectkey = 'projet_task';
2651 $extrafieldsobjectprefix = 'ef.';
2652 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
2653
2654 // Fields from hook
2655 $parameters = array('arrayfields' => $arrayfields, 'obj' => $task_time, 'i' => $i, 'totalarray' => &$totalarray);
2656 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2657 print $hookmanager->resPrint;
2658
2659 // Action column
2660 if (!$conf->main_checkbox_left_column) {
2661 print '<td class="center nowraponall">';
2662 if (($action == 'editline' || $action == 'splitline') && GETPOSTINT('lineid') == $task_time->rowid) {
2663 print '<input type="hidden" name="lineid" value="'.GETPOSTINT('lineid').'">';
2664 print '<input type="submit" class="button buttongen smallpaddingimp margintoponlyshort marginbottomonlyshort button-save" name="save" value="'.$langs->trans("Save").'">';
2665 print '<br>';
2666 print '<input type="submit" class="button buttongen smallpaddingimp margintoponlyshort marginbottomonlyshort button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
2667 } elseif ($user->hasRight('projet', 'time') || $user->hasRight('projet', 'all', 'creer')) { // Read project and enter time consumed on assigned tasks
2668 if (in_array($task_time->fk_user, $childids) || $user->hasRight('projet', 'all', 'creer')) {
2669 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' : '').'">';
2670 print img_edit('default', 0, 'class="pictofixedwidth paddingleft"');
2671 print '</a>';
2672
2673 if (getDolGlobalString('PROJECT_ALLOW_SPLIT_TIMESPENT')) {
2674 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' : '') . '">';
2675 print img_split('', 'class="pictofixedwidth paddingleft"');
2676 print '</a>';
2677 }
2678
2679 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' : '').'">';
2680 print img_delete('default', 'class="pictodelete paddingleft"');
2681 print '</a>';
2682
2683 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2684 $selected = 0;
2685 if (in_array($task_time->rowid, $arrayofselected)) {
2686 $selected = 1;
2687 }
2688 print '&nbsp;';
2689
2690 // Disable select if task not billable or already invoiced
2691 $disabled = (intval($task_time->billable) != 1 || $invoiced);
2692 $ctrl = '<input '.($disabled ? 'disabled' : '').' id="cb' . $task_time->rowid . '" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="' . $task_time->rowid . '"' . ($selected ? ' checked="checked"' : '') . '>';
2693 if ($disabled) {
2694 // If disabled, a dbl-click very close outside the control
2695 // will re-enable it, so that user is not blocked if needed.
2696 print '<span id="cbsp'. $task_time->rowid . '">'.$ctrl.'</span>';
2697 print '<script>$("#cbsp' . $task_time->rowid . '").dblclick(()=>{ $("#cb' . $task_time->rowid . '").removeAttr("disabled") })</script>';
2698 } else {
2699 print $ctrl;
2700 }
2701 }
2702 }
2703 }
2704 print '</td>';
2705 if (!$i) {
2706 $totalarray['nbfield']++;
2707 }
2708 }
2709
2710 print "</tr>\n";
2711
2712
2713 // Add the lines for the split feature
2714
2715 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2716 print '<!-- first line -->';
2717 print '<tr class="oddeven">';
2718
2719 // Action column
2720 if ($conf->main_checkbox_left_column) {
2721 print '<td></td>';
2722 }
2723
2724 // Date
2725 if (!empty($arrayfields['t.element_date']['checked'])) {
2726 print '<td class="nowrap">';
2727 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2728 if (empty($task_time->element_date_withhour)) {
2729 print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 3, 3, 2, "timespent_date", 1, 0);
2730 } else {
2731 print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 1, 1, 2, "timespent_date", 1, 0);
2732 }
2733 } else {
2734 print dol_print_date(($date2 ? $date2 : $date1), ($task_time->element_date_withhour ? 'dayhour' : 'day'));
2735 }
2736 print '</td>';
2737 }
2738
2739 // Thirdparty
2740 if (!empty($arrayfields['p.fk_soc']['checked'])) {
2741 print '<td class="nowrap">';
2742 print '</td>';
2743 }
2744
2745 // Thirdparty alias
2746 if (!empty($arrayfields['s.name_alias']['checked'])) {
2747 print '<td class="nowrap">';
2748 print '</td>';
2749 }
2750
2751 // Project ref
2752 if (!empty($allprojectforuser)) {
2753 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2754 print '<td class="nowrap">';
2755 print '</td>';
2756 }
2757 }
2758
2759 // Task ref
2760 if (!empty($arrayfields['t.element_ref']['checked'])) {
2761 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2762 print '<td class="nowrap">';
2763 $tasktmp->id = $task_time->fk_element;
2764 $tasktmp->ref = $task_time->ref;
2765 $tasktmp->label = $task_time->label;
2766 print $tasktmp->getNomUrl(1, 'withproject', 'time');
2767 print '</td>';
2768 }
2769 }
2770
2771 // Task label
2772 if (!empty($arrayfields['t.element_label']['checked'])) {
2773 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2774 print '<td class="tdoverflowmax300" title="'.dol_escape_htmltag($task_time->label).'">';
2775 print dol_escape_htmltag($task_time->label);
2776 print '</td>';
2777 }
2778 }
2779
2780 // User
2781 if (!empty($arrayfields['author']['checked'])) {
2782 print '<td class="nowraponall">';
2783 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2784 if (empty($object->id)) {
2785 $idTask = (!empty($id)) ? $id : $task_time->fk_element;
2786 $object->fetch($idTask);
2787 }
2788 $contactsoftask = $object->getListContactId('internal');
2789 if (!in_array($task_time->fk_user, $contactsoftask)) {
2790 $contactsoftask[] = $task_time->fk_user;
2791 }
2792 if (count($contactsoftask) > 0) {
2793 print img_object('', 'user', 'class="hideonsmartphone"');
2794 print $form->select_dolusers($task_time->fk_user, 'userid_line', 0, null, 0, '', $contactsoftask);
2795 } else {
2796 print img_error($langs->trans('FirstAddRessourceToAllocateTime')) . $langs->trans('FirstAddRessourceToAllocateTime');
2797 }
2798 } else {
2799 $userstatic->id = $task_time->fk_user;
2800 $userstatic->lastname = $task_time->lastname;
2801 $userstatic->firstname = $task_time->firstname;
2802 $userstatic->photo = $task_time->photo;
2803 $userstatic->status = $task_time->user_status;
2804 print $userstatic->getNomUrl(-1);
2805 }
2806 print '</td>';
2807 }
2808
2809 // Note
2810 if (!empty($arrayfields['t.note']['checked'])) {
2811 print '<td class="tdoverflowmax300">';
2812 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2813 print '<textarea name="timespent_note_line" class="centpercentimp" rows="' . ROWS_2 . '">' . dol_escape_htmltag($task_time->note, 0, 1) . '</textarea>';
2814 } else {
2815 print dol_nl2br($task_time->note);
2816 }
2817 print '</td>';
2818 } elseif ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2819 print '<input type="hidden" name="timespent_note_line" rows="' . ROWS_2 . '" value="' . dol_escape_htmltag($task_time->note, 0, 1) . '">';
2820 }
2821
2822 // Last modification
2823 if (!empty($arrayfields['t.tms']['checked'])) {
2824 print '<td class="nowraponall">';
2825 print '</td>';
2826 }
2827
2828 // Time spent - duration
2829 if (!empty($arrayfields['t.element_duration']['checked'])) {
2830 print '<td class="right">';
2831 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2832 print '<input type="hidden" name="old_duration" value="'.$task_time->element_duration.'">';
2833 print $form->select_duration('new_duration', $task_time->element_duration, 0, 'text');
2834 } else {
2835 print convertSecondToTime($task_time->element_duration, 'allhourmin');
2836 }
2837 print '</td>';
2838 }
2839
2840 // Product
2841 if (!empty($arrayfields['t.fk_product']['checked'])) {
2842 print '<td class="nowraponall tdoverflowmax125">';
2843 print '</td>';
2844 }
2845
2846 // Value spent
2847 if (!empty($arrayfields['value']['checked'])) {
2848 print '<td class="right">';
2849 print '<span class="amount">';
2850 $value = price2num($task_time->thm * $task_time->element_duration / 3600, 'MT', 1);
2851 print price($value, 1, $langs, 1, -1, -1, $conf->currency);
2852 print '</span>';
2853 print '</td>';
2854 }
2855
2856 // Value billed
2857 if (!empty($arrayfields['valuebilled']['checked'])) {
2858 print '<td class="right">';
2859 $valuebilled = price2num($task_time->total_ht, '', 1);
2860 if (isset($task_time->total_ht)) {
2861 print price($valuebilled, 1, $langs, 1, -1, -1, $conf->currency);
2862 }
2863 print '</td>';
2864 }
2865
2866 // Extra fields
2867 $obj = $task_time;
2868 $extrafieldsobjectkey = 'projet_task';
2869 $extrafieldsobjectprefix = 'ef.';
2870 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
2871
2872 // Fields from hook
2873 $parameters = array('arrayfields' => $arrayfields, 'obj' => $task_time, 'mode' => 'split1');
2874 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2875 print $hookmanager->resPrint;
2876
2877 // Action column
2878 if (!$conf->main_checkbox_left_column) {
2879 print '<td class="center nowraponall">';
2880 print '</td>';
2881 }
2882
2883 print "</tr>\n";
2884
2885
2886 // Line for second dispatching
2887
2888 print '<!-- second line --><tr class="oddeven">';
2889
2890 // Action column
2891 if ($conf->main_checkbox_left_column) {
2892 print '<td class="center nowraponall">';
2893 print '</td>';
2894 }
2895
2896 // Date
2897 if (!empty($arrayfields['t.element_date']['checked'])) {
2898 print '<td class="nowraponall">';
2899 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2900 if (empty($task_time->element_date_withhour)) {
2901 print $form->selectDate(($date2 ? $date2 : $date1), 'timeline_2', 3, 3, 2, "timespent_date", 1, 0);
2902 } else {
2903 print $form->selectDate(($date2 ? $date2 : $date1), 'timeline_2', 1, 1, 2, "timespent_date", 1, 0);
2904 }
2905 } else {
2906 print dol_print_date(($date2 ? $date2 : $date1), ($task_time->element_date_withhour ? 'dayhour' : 'day'));
2907 }
2908 print '</td>';
2909 }
2910
2911 // Thirdparty
2912 if (!empty($arrayfields['p.fk_soc']['checked'])) {
2913 print '<td>';
2914 print '</td>';
2915 }
2916
2917 // Thirdparty alias
2918 if (!empty($arrayfields['s.name_alias']['checked'])) {
2919 print '<td>';
2920 print '</td>';
2921 }
2922
2923 // Project ref
2924 if (!empty($allprojectforuser)) {
2925 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2926 print '<td>';
2927 print '</td>';
2928 }
2929 }
2930
2931 // Task ref
2932 if (!empty($arrayfields['t.element_ref']['checked'])) {
2933 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2934 print '<td class="nowraponall">';
2935 $tasktmp->id = $task_time->fk_element;
2936 $tasktmp->ref = $task_time->ref;
2937 $tasktmp->label = $task_time->label;
2938 print $tasktmp->getNomUrl(1, 'withproject', 'time');
2939 print '</td>';
2940 }
2941 }
2942
2943 // Task label
2944 if (!empty($arrayfields['t.element_label']['checked'])) {
2945 if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
2946 print '<td class="tdoverflowmax125" title="'.dol_escape_htmltag($task_time->label).'">';
2947 print dol_escape_htmltag($task_time->label);
2948 print '</td>';
2949 }
2950 }
2951
2952 // User
2953 if (!empty($arrayfields['author']['checked'])) {
2954 print '<td class="nowraponall tdoverflowmax100">';
2955 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2956 if (empty($object->id)) {
2957 $idTask = (!empty($id)) ? $id : $task_time->fk_element;
2958 $object->fetch($idTask);
2959 }
2960 $contactsoftask = $object->getListContactId('internal');
2961 if (!in_array($task_time->fk_user, $contactsoftask)) {
2962 $contactsoftask[] = $task_time->fk_user;
2963 }
2964 if (count($contactsoftask) > 0) {
2965 print img_object('', 'user', 'class="hideonsmartphone"');
2966 print $form->select_dolusers($task_time->fk_user, 'userid_line_2', 0, null, 0, '', $contactsoftask);
2967 } else {
2968 print img_error($langs->trans('FirstAddRessourceToAllocateTime')) . $langs->trans('FirstAddRessourceToAllocateTime');
2969 }
2970 } else {
2971 $userstatic->id = $task_time->fk_user;
2972 $userstatic->lastname = $task_time->lastname;
2973 $userstatic->firstname = $task_time->firstname;
2974 $userstatic->photo = $task_time->photo;
2975 $userstatic->status = $task_time->user_status;
2976 print $userstatic->getNomUrl(-1);
2977 }
2978 print '</td>';
2979 }
2980
2981 // Note
2982 if (!empty($arrayfields['t.note']['checked'])) {
2983 print '<td class="small tdoverflowmax300"">';
2984 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2985 print '<textarea name="timespent_note_line_2" class="centpercentimp" rows="' . ROWS_2 . '">' . dol_escape_htmltag($task_time->note, 0, 1) . '</textarea>';
2986 } else {
2987 print dol_nl2br($task_time->note);
2988 }
2989 print '</td>';
2990 } elseif ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
2991 print '<input type="hidden" name="timespent_note_line_2" value="' . dol_escape_htmltag($task_time->note, 0, 1) . '">';
2992 }
2993
2994 // Last modification
2995 if (!empty($arrayfields['t.tms']['checked'])) {
2996 print '<td class="nowraponall">';
2997 print dol_print_date($task_time->tms, 'dayhour');
2998 print '</td>';
2999 }
3000
3001 // Time spent - duration
3002 if (!empty($arrayfields['t.element_duration']['checked'])) {
3003 print '<td class="right">';
3004 if ($action == 'splitline' && GETPOSTINT('lineid') == $task_time->rowid) {
3005 print '<input type="hidden" name="old_duration_2" value="0">';
3006 print $form->select_duration('new_duration_2', 0, 0, 'text');
3007 } else {
3008 print convertSecondToTime($task_time->element_duration, 'allhourmin');
3009 }
3010 print '</td>';
3011 }
3012
3013 // Product
3014 if (!empty($arrayfields['t.fk_product']['checked'])) {
3015 print '<td class="nowraponall tdoverflowmax125">';
3016 print '</td>';
3017 }
3018
3019 // Value spent - duration
3020 if (!empty($arrayfields['value']['checked'])) {
3021 print '<td class="right">';
3022 print '<span class="amount nowraponall">';
3023 $value = 0;
3024 print price($value, 1, $langs, 1, -1, -1, $conf->currency);
3025 // Note: On the transverse project view, we also have a warning if value is zero here
3026 print '</span>';
3027 print '</td>';
3028 }
3029
3030 // Value billed
3031 if (!empty($arrayfields['valuebilled']['checked'])) {
3032 print '<td class="right">';
3033 if (isset($task_time->total_ht)) {
3034 $valuebilled = price2num($task_time->total_ht, '', 1);
3035 print '<span class="amount nowraponall small">';
3036 print price($valuebilled, 1, $langs, 1, -1, -1, $conf->currency);
3037 print '</span>';
3038 }
3039 print '</td>';
3040 }
3041
3042 // Extra fields
3043 $obj = $task_time;
3044 $extrafieldsobjectkey = 'projet_task';
3045 $extrafieldsobjectprefix = 'ef.';
3046 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
3047
3048 // Fields from hook
3049 $parameters = array('arrayfields' => $arrayfields, 'obj' => $task_time, 'mode' => 'split2');
3050 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3051 print $hookmanager->resPrint;
3052
3053 // Action column
3054 if (!$conf->main_checkbox_left_column) {
3055 print '<td class="center nowraponall">';
3056 print '</td>';
3057 }
3058
3059 print "</tr>\n";
3060 }
3061
3062 $i++;
3063 }
3064
3065 // Show total line
3066 //include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
3067 if (isset($totalarray['totaldurationfield']) || isset($totalarray['totalvaluefield'])) {
3068 print '<tr class="liste_total">';
3069 $i = 0;
3070 while ($i < $totalarray['nbfield']) {
3071 $i++;
3072 if ($i == 1) {
3073 if ($num < $limit && empty($offset)) {
3074 print '<td class="left">' . $langs->trans("Total") . '</td>';
3075 } else {
3076 print '<td class="left">'.$form->textwithpicto($langs->trans("Total"), $langs->trans("Totalforthispage")).'</td>';
3077 }
3078 } elseif (isset($totalarray['totaldurationfield']) && $totalarray['totaldurationfield'] == $i) {
3079 print '<td class="right">' . convertSecondToTime($totalarray['totalduration'], 'allhourmin') . '</td>';
3080 } elseif (isset($totalarray['totalvaluefield']) && $totalarray['totalvaluefield'] == $i) {
3081 print '<td class="right">' . price($totalarray['totalvalue']) . '</td>';
3082 //} elseif ($totalarray['totalvaluebilledfield'] == $i) { print '<td class="center">'.price($totalarray['totalvaluebilled']).'</td>';
3083 } else {
3084 print '<td></td>';
3085 }
3086 }
3087 print '</tr>';
3088 }
3089
3090 if (!count($tasks)) {
3091 $totalnboffields = 1;
3092 foreach ($arrayfields as $value) {
3093 if (!empty($value['checked'])) {
3094 $totalnboffields++;
3095 }
3096 }
3097 print '<tr class="oddeven"><td colspan="' . $totalnboffields . '">';
3098 print '<span class="opacitymedium">' . $langs->trans("None") . '</span>';
3099 print '</td></tr>';
3100 }
3101
3102 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
3103 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3104 print $hookmanager->resPrint;
3105
3106 print "</table>";
3107 print '</div>';
3108 print "</form>";
3109 }
3110}
3111
3112// End of page
3113llxFooter();
3114$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 list.php:501
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 to help generate other html components 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:401
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:263
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
$date_start
Variables from include:
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.
dolPrintHTML($s, $allowiframe=0, $moreallowedtags=array())
Return a string (that can be on several lines) ready to be output on a HTML page.
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.
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'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
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.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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, $nodie=0, $mode='')
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.