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