dolibarr 25.0.0-alpha
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2011-2020 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
7 * Copyright (C) 2014-2018 Ferran Marcet <fmarcet@2byte.es>
8 * Copyright (C) 2014-2026 Charlene Benke <charlene@patas-monkey.com>
9 * Copyright (C) 2015-2016 Abbes Bahfir <bafbes@gmail.com>
10 * Copyright (C) 2018-2022 Philippe Grand <philippe.grand@atoo-net.com>
11 * Copyright (C) 2020-2026 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2023 Benjamin Grembi <benjamin@oarces.fr>
13 * Copyright (C) 2023-2024 William Mead <william.mead@manchenumerique.fr>
14 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
15 * Copyright (C) 2024-2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
16 * Copyright (C) 2025 Pierre Ardoin <developpeur@lesmetiersdubatiment.fr>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 3 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <https://www.gnu.org/licenses/>.
30 */
31
38// Load Dolibarr environment
39require '../main.inc.php';
48require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
49require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
50require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
51require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
52require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
53if (isModEnabled('project')) {
54 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
55 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
56}
57if (isModEnabled('contract')) {
58 require_once DOL_DOCUMENT_ROOT."/core/class/html.formcontract.class.php";
59 require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php";
60}
61if (getDolGlobalString('FICHEINTER_ADDON') && is_readable(DOL_DOCUMENT_ROOT."/core/modules/fichinter/mod_" . getDolGlobalString('FICHEINTER_ADDON').".php")) {
62 require_once DOL_DOCUMENT_ROOT."/core/modules/fichinter/mod_" . getDolGlobalString('FICHEINTER_ADDON').'.php';
63}
64if (isModEnabled('category')) {
65 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
66}
67require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
68
69// Load translation files required by the page
70$langs->loadLangs(array('bills', 'companies', 'interventions', 'stocks'));
71
72$id = GETPOSTINT('id');
73$ref = GETPOST('ref', 'alpha');
74$ref_client = GETPOST('ref_client', 'alpha');
75$socid = GETPOSTINT('socid');
76$contratid = GETPOSTINT('contratid');
77$action = GETPOST('action', 'alpha');
78$cancel = GETPOST('cancel', 'alpha');
79$confirm = GETPOST('confirm', 'alpha');
80$backtopage = GETPOST('backtopage', 'alpha');
81$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
82
83$mesg = GETPOST('msg', 'alpha');
84$origin = GETPOST('origin', 'alpha');
85$originid = (GETPOSTINT('originid') ? GETPOSTINT('originid') : GETPOSTINT('origin_id')); // For backward compatibility
86$note_public = GETPOST('note_public', 'restricthtml');
87$note_private = GETPOST('note_private', 'restricthtml');
88$lineid = GETPOSTINT('line_id');
89
90$error = 0;
91
92// PDF
93$hidedetails = (GETPOSTINT('hidedetails') ? GETPOSTINT('hidedetails') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));
94$hidedesc = (GETPOSTINT('hidedesc') ? GETPOSTINT('hidedesc') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));
95$hideref = (GETPOSTINT('hideref') ? GETPOSTINT('hideref') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0));
96
97// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
98$hookmanager->initHooks(array('fichintercard', 'interventioncard', 'globalcard'));
99
100$object = new Fichinter($db);
101
102$objectsrc = null;
103
104$extrafields->fetch_name_optionals_label($object->table_element);
105
106// Load object
107if ($id > 0 || !empty($ref)) {
108 $ret = $object->fetch($id, $ref);
109 if ($ret > 0) {
110 $id = $object->id; // The page may be called with the ref only: the security check must be done on the object found
111 $ret = $object->fetch_thirdparty();
112 }
113 if ($ret < 0) {
114 dol_print_error(null, $object->error);
115 }
116}
117
118// Security check
119if ($user->isExternalUser()) {
120 $socid = $user->isExternalUser();
121}
122$result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
123
124$permissionnote = $user->hasRight('ficheinter', 'creer'); // Used by the include of actions_setnotes.inc.php
125$permissiondellink = $user->hasRight('ficheinter', 'creer'); // Used by the include of actions_dellink.inc.php
126$permissiontodelete = (($object->status == Fichinter::STATUS_DRAFT && $user->hasRight('ficheinter', 'creer')) || $user->hasRight('ficheinter', 'supprimer'));
127$permissiontoread = $user->hasRight('ficheinter', 'lire');
128$permissiontoadd = $user->hasRight('ficheinter', 'creer');
129$permissiontoeditextra = $permissiontoadd;
130if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
131 // For action 'update_extras', is there a specific permission set for the attribute to update
132 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
133}
134
135
136/*
137 * Actions
138 */
139
140$parameters = array('socid' => $socid);
141$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
142if ($reshook < 0) {
143 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
144}
145
146if (empty($reshook)) {
147 $backurlforlist = DOL_URL_ROOT.'/fichinter/list.php';
148
149 if (empty($backtopage) || ($cancel && empty($id))) {
150 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
151 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
152 $backtopage = $backurlforlist;
153 } else {
154 $backtopage = DOL_URL_ROOT.'/fichinter/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
155 }
156 }
157 }
158
159 if ($cancel) {
160 if (!empty($backtopageforcancel)) {
161 header("Location: ".$backtopageforcancel);
162 exit;
163 } elseif (!empty($backtopage)) {
164 header("Location: ".$backtopage);
165 exit;
166 }
167 $action = '';
168 }
169
170 include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be 'include', not 'include_once'
171
172 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
173
174 // Action clone object
175 if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
176 if (false && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
177 setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
178 } else {
179 if ($object->id > 0) {
180 // Because createFromClone modifies the object, we must clone it so that we can restore it later
181 $orig = clone $object;
182 $clone_notes = false;
183 if (GETPOSTISSET('clone_notes') && GETPOST('clone_notes') === 'on') {
184 $clone_notes = true;
185 }
186 $clone_contacts = false;
187 if (GETPOSTISSET('clone_contacts') && GETPOST('clone_contacts') === 'on') {
188 $clone_contacts = true;
189 }
190
191 $result = $object->createFromClone($user, $socid, $clone_contacts, $clone_notes);
192 if ($result > 0) {
193 header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
194 exit;
195 } else {
196 setEventMessages($object->error, $object->errors, 'errors');
197 $object = $orig;
198 $action = '';
199 }
200 }
201 }
202 }
203
204 if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) {
205 $result = $object->setValid($user);
206
207 if ($result >= 0) {
208 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
209 // Define output language
210 $outputlangs = $langs;
211 $newlang = '';
212 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
213 $newlang = GETPOST('lang_id', 'aZ09');
214 }
215 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
216 $newlang = $object->thirdparty->default_lang;
217 }
218 if (!empty($newlang)) {
219 $outputlangs = new Translate("", $conf);
220 $outputlangs->setDefaultLang($newlang);
221 }
222 $result = fichinter_create($db, $object, (!GETPOST('model', 'alpha')) ? $object->model_pdf : GETPOST('model', 'alpha'), $outputlangs);
223 }
224
225 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
226 exit;
227 } else {
228 $mesg = $object->error;
229 }
230 } elseif ($action == 'confirm_sign' && $confirm == 'yes' && $permissiontoadd) {
231 $result = $object->setSignedStatus($user, GETPOSTINT('signed_status'), 0, 'FICHINTER_MODIFY');
232 if ($result >= 0) {
233 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
234 // Define output language
235 $outputlangs = $langs;
236 $newlang = '';
237 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
238 $newlang = GETPOST('lang_id', 'aZ09');
239 }
240 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
241 $newlang = $object->thirdparty->default_lang;
242 }
243 if (!empty($newlang)) {
244 $outputlangs = new Translate("", $conf);
245 $outputlangs->setDefaultLang($newlang);
246 }
247 $result = fichinter_create($db, $object, (!GETPOST('model', 'alpha')) ? $object->model_pdf : GETPOST('model', 'alpha'), $outputlangs);
248 }
249
250 header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
251 exit;
252 } else {
253 $mesg = $object->error;
254 }
255 } elseif ($action == 'confirm_unsign' && $confirm == 'yes' && $permissiontoadd) {
256 $result = $object->setSignedStatus($user, Fichinter::$SIGNED_STATUSES['STATUS_NO_SIGNATURE'], 0, 'FICHINTER_MODIFY');
257 if ($result >= 0) {
258 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
259 // Define output language
260 $outputlangs = $langs;
261 $newlang = '';
262 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
263 $newlang = GETPOST('lang_id', 'aZ09');
264 }
265 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
266 $newlang = $object->thirdparty->default_lang;
267 }
268 if (!empty($newlang)) {
269 $outputlangs = new Translate("", $conf);
270 $outputlangs->setDefaultLang($newlang);
271 }
272 $result = fichinter_create($db, $object, (!GETPOST('model', 'alpha')) ? $object->model_pdf : GETPOST('model', 'alpha'), $outputlangs);
273 }
274
275 header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
276 exit;
277 } else {
278 $mesg = $object->error;
279 }
280 } elseif ($action == 'confirm_modify' && $confirm == 'yes' && $permissiontoadd) {
281 $result = $object->setDraft($user);
282 if ($result >= 0) {
283 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
284 // Define output language
285 $outputlangs = $langs;
286 $newlang = '';
287 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
288 $newlang = GETPOST('lang_id', 'aZ09');
289 }
290 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
291 $newlang = $object->thirdparty->default_lang;
292 }
293 if (!empty($newlang)) {
294 $outputlangs = new Translate("", $conf);
295 $outputlangs->setDefaultLang($newlang);
296 }
297 $result = fichinter_create($db, $object, (!GETPOST('model', 'alpha')) ? $object->model_pdf : GETPOST('model', 'alpha'), $outputlangs);
298 }
299
300 header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
301 exit;
302 } else {
303 $mesg = $object->error;
304 }
305 } elseif ($action == 'confirm_done' && $confirm == 'yes' && $permissiontoadd) {
306 $result = $object->setClose($user);
307
308 if ($result >= 0) {
309 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
310 // Define output language
311 $outputlangs = $langs;
312 $newlang = '';
313 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
314 $newlang = GETPOST('lang_id', 'aZ09');
315 }
316 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
317 $newlang = $object->thirdparty->default_lang;
318 }
319 if (!empty($newlang)) {
320 $outputlangs = new Translate("", $conf);
321 $outputlangs->setDefaultLang($newlang);
322 }
323 $result = fichinter_create($db, $object, (!GETPOST('model', 'alpha')) ? $object->model_pdf : GETPOST('model', 'alpha'), $outputlangs);
324 }
325
326 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
327 exit;
328 } else {
329 $mesg = $object->error;
330 }
331 } elseif ($action == 'add' && $permissiontoadd) {
332 $selectedLines = GETPOST('toselect', 'array:int');
333 $object->socid = $socid;
334 $object->duration = GETPOSTINT('duration');
335 $object->fk_project = GETPOSTINT('projectid');
336 $object->fk_contrat = GETPOSTINT('contratid');
337 $object->user_author_id = $user->id;
338 $object->description = GETPOST('description', 'restricthtml');
339 $object->ref = $ref;
340 $object->ref_client = $ref_client;
341 $object->model_pdf = GETPOST('model', 'alpha');
342 $object->note_private = GETPOST('note_private', 'restricthtml');
343 $object->note_public = GETPOST('note_public', 'restricthtml');
344
345 if ($object->socid > 0) {
346 // If creation from another object of another module (Example: origin=propal, originid=1)
347 if (!empty($origin) && !empty($originid)) {
348 $object->origin = $origin;
349 $object->origin_id = $originid;
350
351 // Possibility to add external linked objects with hooks
352 $object->linked_objects[$object->origin] = $object->origin_id;
353 if (GETPOSTISARRAY('other_linked_objects')) {
354 $object->linked_objects = array_merge($object->linked_objects, GETPOST('other_linked_objects', 'array:int'));
355 }
356
357 // Extrafields
358
359 // Fill array 'array_options' with data from add form
360 $ret = $extrafields->setOptionalsFromPost(null, $object);
361 if ($ret < 0) {
362 $error++;
363 $action = 'create';
364 }
365 //$array_options = $extrafields->getOptionalsFromPost($object->table_element);
366
367 //$object->array_options = $array_options;
368
369 $id = $object->create($user);
370
371 if ($id > 0) {
372 dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
373
374 // Resolve and load the source object from its element type (propal, commande, contract, ...)
375 $srcobject = fetchObjectByElement($object->origin_id, $origin);
376
377 if (is_object($srcobject) && $srcobject->id > 0) {
378 '@phan-var-force Commande|Propal|Contrat $srcobject'; // Can be other class, but CommonObject is too generic
380 $srcobject->fetch_thirdparty();
381 $lines = $srcobject->lines;
382 if (empty($lines) && method_exists($srcobject, 'fetch_lines')) {
383 $srcobject->fetch_lines();
384 $lines = $srcobject->lines;
385 }
386
387 if (is_array($lines)) {
388 $num = count($lines);
389
390 for ($i = 0; $i < $num; $i++) {
391 if (!in_array($lines[$i]->id, $selectedLines)) {
392 continue; // Skip unselected lines
393 }
394
395 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : Product::TYPE_PRODUCT);
396
397 if ($product_type == Product::TYPE_SERVICE || getDolGlobalString('FICHINTER_PRINT_PRODUCTS')) { //only services except if config includes products
398 $duration = 3600; // Default to one hour
399 $desc = '';
400 // Predefined products & services
401 if ($lines[$i]->fk_product > 0) {
402 $prod = new Product($db);
403 $prod->id = $lines[$i]->fk_product;
404
405 // Define output language
406 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
407 $prod->getMultiLangs();
408 // We show if duration is present on service (so we get it)
409 $prod->fetch($lines[$i]->fk_product);
410 $outputlangs = $langs;
411 $newlang = '';
412 if (/* empty($newlang) && */ GETPOST('lang_id', 'aZ09')) {
413 $newlang = GETPOST('lang_id', 'aZ09');
414 }
415 if (empty($newlang)) {
416 $newlang = $srcobject->thirdparty->default_lang;
417 }
418 if (!empty($newlang)) {
419 $outputlangs = new Translate("", $conf);
420 $outputlangs->setDefaultLang($newlang);
421 }
422 $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product_label;
423 } else {
424 $prod->fetch($lines[$i]->fk_product);
425 $label = $lines[$i]->product_label;
426 }
427
428 if ($prod->duration_value && getDolGlobalString('FICHINTER_USE_SERVICE_DURATION')) {
429 switch ($prod->duration_unit) {
430 case 's':
431 $mult = 1;
432 break;
433 case 'mn':
434 $mult = 60;
435 break;
436 default:
437 case 'h':
438 $mult = 3600;
439 break;
440 case 'd':
441 $mult = 3600 * 24;
442 break;
443 case 'w':
444 $mult = 3600 * 24 * 7;
445 break;
446 case 'm':
447 $mult = (int) (3600 * 24 * (365 / 12)); // Average month duration
448 break;
449 case 'y':
450 $mult = 3600 * 24 * 365;
451 break;
452 }
453 $duration = (int) round(((float) $prod->duration_value) * $mult * $lines[$i]->qty);
454 }
455
456 $desc = $lines[$i]->product_ref;
457 $desc .= ' - ';
458 $desc .= $label;
459 $desc .= '<br>';
460 }
461 // Common part (predefined or free line)
462 $desc .= dol_htmlentitiesbr($lines[$i]->desc);
463 $desc .= '<br>';
464 $unit_label = '';
465 if ($lines[$i]->fk_unit) {
466 $langs->load('measuring_units');
467 $unit_label = $langs->trans($lines[$i]->getLabelOfUnit('short'));
468 }
469 $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.($unit_label ? ' '.$unit_label : '').')';
470
471 $source_date = (!empty($srcobject->delivery_date) ? $srcobject->delivery_date : dol_now());
472 $timearray = dol_getdate($source_date);
473 $date_intervention = dol_mktime($timearray['hours'], $timearray['minutes'], 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
474
475 if ($product_type == Product::TYPE_PRODUCT) {
476 $duration = 0;
477 }
478
479 $predef = '';
480
481 // Extrafields
482 $extrafields->fetch_name_optionals_label($object->table_element_line);
483 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
484
485 $result = $object->addline(
486 $user,
487 $id,
488 $desc,
489 $date_intervention,
490 $duration,
491 $array_options
492 );
493
494 if ($result < 0) {
495 $error++;
496 break;
497 }
498 }
499 }
500 }
501 } else {
502 $langs->load("errors");
503 if (is_object($srcobject) && !empty($srcobject->error)) {
504 setEventMessages($srcobject->error, $srcobject->errors, 'errors');
505 } else {
506 setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
507 }
508 $action = 'create';
509 $error++;
510 }
511 } else {
512 $langs->load("errors");
513 setEventMessages($object->error, $object->errors, 'errors');
514 $action = 'create';
515 $error++;
516 }
517 } else {
518 // Fill array 'array_options' with data from add form
519 $ret = $extrafields->setOptionalsFromPost(null, $object);
520 if ($ret < 0) {
521 $error++;
522 $action = 'create';
523 }
524
525 if (!$error) {
526 // Extrafields
527 $array_options = $extrafields->getOptionalsFromPost($object->table_element);
528
529 $object->array_options = $array_options;
530
531 $result = $object->create($user);
532
533 if ($result > 0) {
534 $id = $result; // Force refresh on a newly created record
535
536 // Category association
537 $categories = GETPOST('categories', 'array');
538 $object->setCategories($categories);
539 } else {
540 $langs->load("errors");
541 setEventMessages($object->error, $object->errors, 'errors');
542 $action = 'create';
543 $error++;
544 }
545 }
546 }
547 } else {
548 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdParty"));
549 $action = 'create';
550 $error++;
551 }
552 } elseif ($action == 'update' && $permissiontoadd) {
553 $object->socid = $socid;
554 $object->fk_project = GETPOSTINT('projectid');
555 $object->fk_contrat = GETPOSTINT('contratid');
556 $object->user_author_id = $user->id;
557 $object->description = GETPOST('description', 'restricthtml');
558 $object->ref = $ref;
559 $object->ref_client = $ref_client;
560
561 $result = $object->update($user);
562 if ($result < 0) {
563 setEventMessages($object->error, $object->errors, 'errors');
564 }
565 } elseif ($action == 'classin' && $permissiontoadd) {
566 // Set into a project
567 $result = $object->setProject(GETPOSTINT('projectid'));
568 if ($result < 0) {
569 dol_print_error($db, $object->error);
570 }
571 } elseif ($action == 'setcontract' && $permissiontoadd) {
572 // Set into a contract
573 $result = $object->set_contrat($user, GETPOSTINT('contratid'));
574 if ($result < 0) {
575 dol_print_error($db, $object->error);
576 }
577 } elseif ($action == 'settags' && isModEnabled('category') && $permissiontoadd) {
578 // Set tags
579 $result = $object->setCategories(GETPOST('categories', 'array'));
580 if ($result < 0) {
581 setEventMessages($object->error, $object->errors, 'errors');
582 }
583 } elseif ($action == 'setref_client' && $permissiontoadd) {
584 // Set customer reference
585 $result = $object->setRefClient($user, GETPOST('ref_client', 'alpha'));
586 if ($result < 0) {
587 setEventMessages($object->error, $object->errors, 'errors');
588 }
589 } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) {
590 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
591 $result = $object->delete($user);
592 if ($result < 0) {
593 setEventMessages($object->error, $object->errors, 'errors');
594 }
595
596 header('Location: '.DOL_URL_ROOT.'/fichinter/list.php?leftmenu=ficheinter&restore_lastsearch_values=1');
597 exit;
598 } elseif ($action == 'setdescription' && $permissiontoadd) {
599 $result = $object->set_description($user, GETPOST('description'));
600 if ($result < 0) {
601 dol_print_error($db, $object->error);
602 }
603 } elseif ($action == "addline" && $permissiontoadd) {
604 // Add line
605 if (!GETPOST('np_desc', 'restricthtml') && !getDolGlobalString('FICHINTER_EMPTY_LINE_DESC')) {
606 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description"));
607 $error++;
608 }
609 if (!getDolGlobalString('FICHINTER_WITHOUT_DURATION') && !GETPOSTINT('durationhour') && !GETPOSTINT('durationmin')) {
610 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Duration"));
611 $error++;
612 }
613 if (!getDolGlobalString('FICHINTER_WITHOUT_DURATION') && GETPOSTINT('durationhour') >= 24 && GETPOSTINT('durationmin') > 0) {
614 $mesg = $langs->trans("ErrorValueTooHigh");
615 $error++;
616 }
617 if (!$error) {
618 $db->begin();
619
620 $desc = GETPOST('np_desc', 'restricthtml');
621 $date_intervention = dol_mktime(GETPOSTINT('dihour'), GETPOSTINT('dimin'), 0, GETPOSTINT('dimonth'), GETPOSTINT('diday'), GETPOSTINT('diyear'));
622 $duration = !getDolGlobalString('FICHINTER_WITHOUT_DURATION') ? convertTime2Seconds(GETPOSTINT('durationhour'), GETPOSTINT('durationmin')) : 0;
623
624 // Extrafields
625 $extrafields->fetch_name_optionals_label($object->table_element_line);
626 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
627
628 $result = $object->addline(
629 $user,
630 $id,
631 $desc,
632 $date_intervention,
633 $duration,
634 $array_options
635 );
636
637 // Define output language
638 $outputlangs = $langs;
639 $newlang = '';
640 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
641 $newlang = GETPOST('lang_id', 'aZ09');
642 }
643 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
644 $newlang = $object->thirdparty->default_lang;
645 }
646 if (!empty($newlang)) {
647 $outputlangs = new Translate("", $conf);
648 $outputlangs->setDefaultLang($newlang);
649 }
650
651 if ($result >= 0) {
652 $db->commit();
653
654 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
655 fichinter_create($db, $object, $object->model_pdf, $outputlangs);
656 }
657 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
658 exit;
659 } else {
660 $mesg = $object->error;
661 $db->rollback();
662 }
663 }
664 } elseif ($action == 'confirm_addtitleline' && $permissiontoadd) {
665 // Handling adding a new title line for subtotals module
666
667 $langs->load('subtotals');
668
669 $desc = GETPOST('subtotallinedesc', 'alphanohtml');
670 $depth = GETPOSTINT('subtotallinelevel') ?? 1;
671
672 $subtotal_options = array();
673
674 foreach (Fichinter::$TITLE_OPTIONS as $option) {
675 $value = GETPOST($option, 'alphanohtml');
676 if ($value) {
677 $subtotal_options[$option] = $value == 'on' ? 1 : $value;
678 }
679 }
680
681 // Insert line
682 $result = $object->addSubtotalLine($langs, $desc, (int) $depth, $subtotal_options);
683
684 if ($result >= 0) {
685 if ($result == 0) {
686 setEventMessages($object->error, $object->errors, 'warnings');
687 }
688 $ret = $object->fetch($object->id); // Reload to get new records
689 $object->fetch_thirdparty();
690
691 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
692 // Define output language
693 $outputlangs = $langs;
694 $newlang = GETPOST('lang_id', 'alpha');
695 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
696 $newlang = $object->thirdparty->default_lang;
697 }
698 if (!empty($newlang)) {
699 $outputlangs = new Translate("", $conf);
700 $outputlangs->setDefaultLang($newlang);
701 }
702
703 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
704 }
705 } else {
706 setEventMessages($object->error, $object->errors, 'errors');
707 }
708 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
709 exit();
710 } elseif ($action == 'confirm_addsubtotalline' && $permissiontoadd) {
711 // Handling adding a new subtotal line for subtotals module
712
713 $langs->load('subtotals');
714
715 $choosen_line = GETPOST('subtotaltitleline', 'alphanohtml');
716 foreach ($object->lines as $line) {
717 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
718 $desc = $line->desc;
719 $depth = -$line->qty;
720 }
721 }
722
723 $subtotal_options = array();
724
725 foreach (Fichinter::$SUBTOTAL_OPTIONS as $option) {
726 $value = GETPOST($option, 'alphanohtml');
727 if ($value) {
728 $subtotal_options[$option] = $value == 'on' ? 1 : $value;
729 }
730 }
731
732 // Insert line
733 if (isset($desc) && isset($depth)) {
734 $result = $object->addSubtotalLine($langs, $desc, (int) $depth, $subtotal_options);
735 } else {
736 $result = -1;
737 $object->errors[] = $langs->trans("CorrespondingTitleNotFound");
738 }
739
740 if ($result >= 0) {
741 $ret = $object->fetch($object->id); // Reload to get new records
742 $object->fetch_thirdparty();
743
744 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
745 // Define output language
746 $outputlangs = $langs;
747 $newlang = GETPOST('lang_id', 'alpha');
748 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
749 $newlang = $object->thirdparty->default_lang;
750 }
751 if (!empty($newlang)) {
752 $outputlangs = new Translate("", $conf);
753 $outputlangs->setDefaultLang($newlang);
754 }
755
756 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
757 }
758 } else {
759 setEventMessages($object->error, $object->errors, 'errors');
760 }
761 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
762 exit();
763 } elseif ($action == 'confirm_addtextline' && $permissiontoadd) {
764 // Handling adding a new text line for subtotals module
765
766 $langs->load('subtotals');
767
768 $desc = GETPOST('subtotaltextcontent', 'restricthtml');
769
770 // Insert line
771 $result = $object->addSubtotalLine($langs, $desc, 0, array());
772
773 if ($result >= 0) {
774 if ($result == 0) {
775 setEventMessages($object->error, $object->errors, 'warnings');
776 }
777 $ret = $object->fetch($object->id); // Reload to get new records
778 $object->fetch_thirdparty();
779
780 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
781 // Define output language
782 $outputlangs = $langs;
783 $newlang = GETPOST('lang_id', 'alpha');
784 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
785 $newlang = $object->thirdparty->default_lang;
786 }
787 if (!empty($newlang)) {
788 $outputlangs = new Translate("", $conf);
789 $outputlangs->setDefaultLang($newlang);
790 }
791
792 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
793 }
794 } else {
795 setEventMessages($object->error, $object->errors, 'errors');
796 }
797 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
798 exit();
799 } elseif ($action == 'classifybilled' && $permissiontoadd) {
800 // Classify Billed
801 $result = $object->setStatut(Fichinter::STATUS_BILLED);
802 if ($result > 0) {
803 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
804 exit;
805 } else {
806 setEventMessages($object->error, $object->errors, 'errors');
807 }
808 } elseif ($action == 'classifyunbilled' && $permissiontoadd) {
809 // Classify unbilled
810 $result = $object->setStatut(Fichinter::STATUS_VALIDATED);
811 if ($result > 0) {
812 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
813 exit;
814 } else {
815 $mesg = $object->error;
816 }
817 } elseif ($action == 'confirm_reopen' && $permissiontoadd) {
818 // Reopen
819 $result = $object->setReopen($user);
820 if ($result > 0) {
821 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
822 exit;
823 } else {
824 $mesg = $object->error;
825 }
826 } elseif ($action == 'confirm_cancel' && $confirm == 'yes' && $permissiontoadd) {
827 $result = $object->setCanceled($user);
828
829 if ($result < 0) {
830 setEventMessages($object->error, $object->errors, 'errors');
831 }
832 } elseif ($action == 'updateline' && $permissiontoadd && GETPOST('save', 'alpha')) {
833 // Update an intervention line
834 $objectline = new FichinterLigne($db);
835 if ($objectline->fetch($lineid) <= 0) {
836 dol_print_error($db);
837 exit;
838 }
839
840 if ($object->fetch($objectline->fk_fichinter) <= 0) {
841 dol_print_error($db);
842 exit;
843 }
844 $object->fetch_thirdparty();
845
846 $desc = GETPOST('np_desc', 'restricthtml');
847 $date_inter = dol_mktime(GETPOSTINT('dihour'), GETPOSTINT('dimin'), 0, GETPOSTINT('dimonth'), GETPOSTINT('diday'), GETPOSTINT('diyear'));
848 $duration = convertTime2Seconds(GETPOSTINT('durationhour'), GETPOSTINT('durationmin'));
849
850 $objectline->date = $date_inter;
851 $objectline->desc = $desc;
852 if ($objectline->special_code != SUBTOTALS_SPECIAL_CODE) {
853 $objectline->duration = $duration;
854 }
855
856 // Extrafields
857 $extrafields->fetch_name_optionals_label($object->table_element_line);
858 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
859 if (is_array($array_options)) {
860 $objectline->array_options = array_merge($objectline->array_options, $array_options);
861 }
862
863 $result = $objectline->update($user);
864 if ($result < 0) {
865 // Surface validation errors (e.g. mandatory extrafield left empty) as an
866 // event message on the same page instead of breaking with a full Dolibarr
867 // error screen that loses the user's edit context.
868 setEventMessages($objectline->error, $objectline->errors, 'errors');
869 }
870
871 // Define output language
872 $outputlangs = $langs;
873 $newlang = '';
874 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
875 $newlang = GETPOST('lang_id', 'aZ09');
876 }
877 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
878 $newlang = $object->thirdparty->default_lang;
879 }
880 if (!empty($newlang)) {
881 $outputlangs = new Translate("", $conf);
882 $outputlangs->setDefaultLang($newlang);
883 }
884 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
885 fichinter_create($db, $object, $object->model_pdf, $outputlangs);
886 }
887
888 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
889 exit;
890 } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $permissiontoadd) {
891 // Delete an intervention line WITH confirmation
892 $objectline = new FichinterLigne($db);
893 if ($objectline->fetch($lineid) <= 0) {
894 dol_print_error($db);
895 exit;
896 }
897 $result = $objectline->deleteLine($user);
898
899 if ($object->fetch($objectline->fk_fichinter) <= 0) {
900 dol_print_error($db);
901 exit;
902 }
903
904 // Define output language
905 $outputlangs = $langs;
906 $newlang = '';
907 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
908 $newlang = GETPOST('lang_id', 'aZ09');
909 }
910 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
911 $newlang = $object->thirdparty->default_lang;
912 }
913 if (!empty($newlang)) {
914 $outputlangs = new Translate("", $conf);
915 $outputlangs->setDefaultLang($newlang);
916 }
917 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
918 fichinter_create($db, $object, $object->model_pdf, $outputlangs);
919 }
920 } elseif ($action == 'confirm_delete_subtotalline' && $confirm == 'yes' && $permissiontoadd) {
921 // Remove a subtotal / title / text line (subtotals module)
922 $object->fetch($id);
923
924 $result = $object->deleteSubtotalLine($langs, GETPOSTINT('lineid'), (bool) GETPOST('deletecorrespondingsubtotalline'));
925 if ($result > 0) {
926 $object->line_order(true);
927 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
928 exit;
929 } else {
930 setEventMessages($object->error, $object->errors, 'errors');
931 $action = '';
932 }
933 } elseif ($action == 'up' && $permissiontoadd) {
934 // Set position of lines
935 $object->line_up($lineid);
936
937 // Define output language
938 $outputlangs = $langs;
939 $newlang = '';
940 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
941 $newlang = GETPOST('lang_id', 'aZ09');
942 }
943 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
944 $newlang = $object->thirdparty->default_lang;
945 }
946 if (!empty($newlang)) {
947 $outputlangs = new Translate("", $conf);
948 $outputlangs->setDefaultLang($newlang);
949 }
950 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
951 fichinter_create($db, $object, $object->model_pdf, $outputlangs);
952 }
953
954 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid);
955 exit;
956 } elseif ($action == 'down' && $permissiontoadd) {
957 $object->line_down($lineid);
958
959 // Define output language
960 $outputlangs = $langs;
961 $newlang = '';
962 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
963 $newlang = GETPOST('lang_id', 'aZ09');
964 }
965 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
966 $newlang = $object->thirdparty->default_lang;
967 }
968 if (!empty($newlang)) {
969 $outputlangs = new Translate("", $conf);
970 $outputlangs->setDefaultLang($newlang);
971 }
972 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
973 fichinter_create($db, $object, $object->model_pdf, $outputlangs);
974 }
975
976 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid);
977 exit;
978 }
979
980 // Actions when printing a doc from card
981 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
982
983 // Actions to send emails
984 $triggersendname = 'FICHINTER_SENTBYMAIL';
985 $autocopy = 'MAIN_MAIL_AUTOCOPY_FICHINTER_TO';
986 $trackid = 'int'.$object->id;
987 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
988
989 // Actions to build doc
990 $upload_dir = getMultidirOutput($object);
991 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
992
993 if ($action == 'update_extras' && $permissiontoeditextra) {
994 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
995
996 $attribute_name = GETPOST('attribute', 'aZ09');
997
998 // Fill array 'array_options' with data from update form
999 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
1000 if ($ret < 0) {
1001 $error++;
1002 }
1003
1004 if (!$error) {
1005 // Actions on extra fields
1006 $result = $object->updateExtraField($attribute_name, 'FICHINTER_MODIFY');
1007 if ($result < 0) {
1008 setEventMessages($object->error, $object->errors, 'errors');
1009 $error++;
1010 }
1011 }
1012
1013 if ($error) {
1014 $action = 'edit_extras';
1015 }
1016 }
1017
1018 if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
1019 if ($action == 'addcontact' && $permissiontoadd) {
1020 if ($result > 0 && $id > 0) {
1021 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
1022 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
1023 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
1024 }
1025
1026 if ($result >= 0) {
1027 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1028 exit;
1029 } else {
1030 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
1031 $langs->load("errors");
1032 $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
1033 } else {
1034 $mesg = $object->error;
1035 }
1036 }
1037 } elseif ($action == 'swapstatut' && $permissiontoadd) {
1038 // Toggle the status of a contact
1039 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
1040 } elseif ($action == 'deletecontact' && $permissiontoadd) {
1041 // Delete a contact
1042 $result = $object->delete_contact(GETPOSTINT('lineid'));
1043
1044 if ($result >= 0) {
1045 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1046 exit;
1047 } else {
1048 dol_print_error($db);
1049 }
1050 }
1051 }
1052}
1053
1054
1055/*
1056 * View
1057 */
1058
1059$form = new Form($db);
1060$formfile = new FormFile($db);
1061$formcontract = null;
1062$formproject = null;
1063if (isModEnabled('contract')) {
1064 $formcontract = new FormContract($db);
1065}
1066if (isModEnabled('project')) {
1067 $formproject = new FormProjets($db);
1068}
1069
1070$title = $object->ref . " - " . $langs->trans('Card');
1071if ($action == 'create') {
1072 $title = $langs->trans("NewIntervention");
1073}
1074$help_url = 'EN:Module_Interventions|FR:Module_Fiches_d\'interventions';
1075
1076llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-fichinter page-card');
1077
1078// Create new intervention
1079if ($action == 'create') {
1080 $soc = new Societe($db);
1081 if ($socid > 0) {
1082 $soc->fetch($socid);
1083 }
1084 $projectid = GETPOSTINT('projectid');
1085
1086 print load_fiche_titre($langs->trans("NewIntervention"), '', 'intervention');
1087
1088 if ($error > 0) {
1089 dol_htmloutput_errors($mesg);
1090 } else {
1091 dol_htmloutput_mesg($mesg);
1092 }
1093
1094 if (GETPOST('origin', 'alphanohtml') && GETPOSTINT('originid')) {
1095 // Parse element (ex: project_task -> project) just to detect the 'project' origin handled below
1096 $regs = array();
1097 $element = GETPOST('origin', 'alphanohtml');
1098 if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin', 'alphanohtml'), $regs)) {
1099 $element = $regs[1];
1100 }
1101
1102 if ($element == 'project') {
1103 $projectid = GETPOSTINT('originid');
1104 } else {
1105 // Resolve and load the source object from its element type (propal, commande, contract, ...)
1106 $objectsrc = fetchObjectByElement($originid, $origin);
1107
1108 if (is_object($objectsrc) && $objectsrc->id > 0) {
1109 '@phan-var-force Commande|Propal|Contrat $objectsrc';
1110 if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {
1111 $objectsrc->fetch_lines();
1112 }
1113 $objectsrc->fetch_thirdparty();
1114
1115 $projectid = (int) $objectsrc->fk_project;
1116
1117 $soc = $objectsrc->thirdparty;
1118
1119 $note_private = (!empty($objectsrc->note) ? $objectsrc->note : (!empty($objectsrc->note_private) ? $objectsrc->note_private : GETPOST('note_private', 'restricthtml')));
1120 $note_public = (!empty($objectsrc->note_public) ? $objectsrc->note_public : GETPOST('note_public', 'restricthtml'));
1121
1122 // Replicate extrafields
1123 $objectsrc->fetch_optionals();
1124 $object->array_options = $objectsrc->array_options;
1125
1126 // Object source contacts list
1127 $srccontactslist = $objectsrc->liste_contact(-1, 'external', 1);
1128 } else {
1129 $objectsrc = null;
1130 }
1131 }
1132 } else {
1133 $projectid = GETPOSTINT('projectid');
1134 $note_private = GETPOST("note_private", "alpha");
1135 $note_public = GETPOST("note_public", "alpha");
1136 }
1137
1138 if (!$conf->global->FICHEINTER_ADDON) {
1139 dol_print_error($db, $langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined"));
1140 exit;
1141 }
1142
1143 $object->datec = dol_now();
1144
1145 $obj = getDolGlobalString('FICHEINTER_ADDON');
1146 $obj = "mod_".$obj;
1147
1148 //$modFicheinter = new $obj;
1149 //$numpr = $modFicheinter->getNextValue($soc, $object);
1150
1151 print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
1152 print '<input type="hidden" name="token" value="'.newToken().'">';
1153 print '<input type="hidden" name="socid" value='.$soc->id.'>';
1154 print '<input type="hidden" name="action" value="add">';
1155 print '<input type="hidden" name="socid" value="'.$soc->id.'">'."\n";
1156 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1157 if ($backtopageforcancel) {
1158 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
1159 }
1160
1161 print dol_get_fiche_head([]);
1162
1163 print '<table class="border centpercent">';
1164
1165 // Ref
1166 print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td>'.$langs->trans("Draft").'</td></tr>';
1167
1168 // Ref customer
1169 print '<tr class="field_ref_client"><td class="titlefieldcreate">'.$langs->trans('RefCustomer').'</td><td class="valuefieldcreate">';
1170 print '<input type="text" name="ref_client" value="'.GETPOST('ref_client').'"></td>';
1171 print '</tr>';
1172
1173 // Thirdparty
1174 print '<tr>';
1175 print '<td class="fieldrequired">'.$langs->trans('ThirdParty').'</td>';
1176 if ($socid > 0) {
1177 print '<td>';
1178 print $soc->getNomUrl(1);
1179 print '<input type="hidden" name="socid" value="'.$soc->id.'">';
1180 print '</td>';
1181 } else {
1182 print '<td>';
1183 print img_picto('', 'company', 'class="pictofixedwidth"');
1184 $filter = '(s.status:=:1)';
1185 print $form->select_company('', 'socid', $filter, 'SelectThirdParty', 1, 0, array(), 0, 'minwidth150 widthcentpercentminusxx maxwidth500');
1186 print ' <a href="'.dolBuildUrl(DOL_URL_ROOT . '/societe/card.php', ['action' => 'create', 'customer' => 3, 'backtopage' => dolBuildUrl($_SERVER["PHP_SELF"], ['action' => 'create'])]).'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
1187 print '</td>';
1188 }
1189 print '</tr>'."\n";
1190
1191 // Description (must be a textarea and not html must be allowed (used in list view)
1192 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
1193 print '<td>';
1194 print '<textarea name="description" class="quatrevingtpercent" rows="'.ROWS_3.'">'.GETPOST('description').'</textarea>';
1195 print '</td></tr>';
1196
1197 // Project
1198 if (isModEnabled('project')) {
1199 $formproject = new FormProjets($db);
1200
1201 $langs->load("project");
1202
1203 print '<tr><td>'.$langs->trans("Project").'</td><td>';
1204 print img_picto('', 'project', 'class="pictofixedwidth"');
1205 /* Fix: If a project must be linked to any companies (suppliers or not), project must be not be set as limited to customer but must be not linked to any particular thirdparty
1206 if ($societe->fournisseur==1)
1207 $numprojet=select_projects(-1, GETPOST("projectid", 'int'), 'projectid');
1208 else
1209 $numprojet=select_projects($societe->id, GETPOST("projectid", 'int'), 'projectid');
1210 */
1211 $numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 0, 0, 'maxwidth500 widthcentpercentminusxx');
1212 if ($numprojet == 0) {
1213 print ' &nbsp; <a href="' . dolBuildUrl(DOL_URL_ROOT . '/projet/card.php', ['socid' => $soc->id, 'action' => 'create', 'status' => 1, 'backtopage' => dolBuildUrl($_SERVER["PHP_SELF"], ['action' => 'create', 'socid' => $soc->id])]) . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddProject").'"></span></a>';
1214 }
1215 print '</td></tr>';
1216 }
1217
1218 // Category
1219 if (isModEnabled('category')) {
1220 // Categories
1221 print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
1222 print $form->selectCategories(Categorie::TYPE_FICHINTER, 'categories', $object);
1223 print "</td></tr>";
1224 }
1225
1226 // Contract
1227 if (isModEnabled('contract') && is_object($formcontract)) {
1228 // This feature hang the application on large list of contracts, because the select component is not complete: it does not work like select of thirdparty or product to support large lists
1229 // So we add a hidden option to avoid to have it used and the application locked, until the select_contract is fixed.
1230 if (getDolGlobalString("CONTRACT_CAN_USE_THE_BUGGED_SELECT_COMPONENT")) {
1231 $langs->load("contracts");
1232 print '<tr><td>'.$langs->trans("Contract").'</td><td>';
1233 $numcontrat = $formcontract->select_contract($soc->id, GETPOSTINT('contratid'), 'contratid', 0, 1, 1);
1234 if ($numcontrat == 0) {
1235 print ' &nbsp; <a href="'.DOL_URL_ROOT.'/contrat/card.php?socid='.$soc->id.'&action=create"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddContract").'"></span></a>';
1236 }
1237 print '</td></tr>';
1238 }
1239 }
1240
1241 // Model
1243 if (count($liste) > 0) {
1244 print '<tr>';
1245 print '<td>'.$langs->trans("DefaultModel").'</td>';
1246 print '<td>';
1247 print $form->selectarray('model', $liste, getDolGlobalString('FICHEINTER_ADDON_PDF'));
1248 print "</td></tr>";
1249 }
1250
1251 // Public note
1252 print '<tr>';
1253 print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
1254 print '<td>';
1255 $doleditor = new DolEditor('note_public', (string) $note_public, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
1256 print $doleditor->Create(1);
1257 //print '<textarea name="note_public" cols="80" rows="'.ROWS_3.'">'.$note_public.'</textarea>';
1258 print '</td></tr>';
1259
1260 // Private note
1261 if (empty($user->socid)) {
1262 print '<tr>';
1263 print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
1264 print '<td>';
1265 $doleditor = new DolEditor('note_private', (string) $note_private, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
1266 print $doleditor->Create(1);
1267 //print '<textarea name="note_private" cols="80" rows="'.ROWS_3.'">'.$note_private.'</textarea>';
1268 print '</td></tr>';
1269 }
1270
1271 // Other attributes
1272 $parameters = array();
1273 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1274 print $hookmanager->resPrint;
1275 if (empty($reshook)) {
1276 print $object->showOptionals($extrafields, 'create');
1277 }
1278
1279 // Show link to origin object
1280 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1281 $newclassname = get_class($objectsrc);
1282 if ($newclassname == 'Propal') {
1283 $langs->load('propal');
1284 $newclassname = 'CommercialProposal';
1285 }
1286 print '<tr><td>'.$langs->trans($newclassname).'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
1287
1288 // Amount
1289 /* Hide amount because we only copy services so amount may differ than source
1290 print '<tr><td>' . $langs->trans('AmountHT') . '</td><td>' . price($objectsrc->total_ht) . '</td></tr>';
1291 print '<tr><td>' . $langs->trans('AmountVAT') . '</td><td>' . price($objectsrc->total_tva) . "</td></tr>";
1292 if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) // Localtax1 RE
1293 {
1294 print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td><td>' . price($objectsrc->total_localtax1) . "</td></tr>";
1295 }
1296
1297 if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) // Localtax2 IRPF
1298 {
1299 print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td><td>' . price($objectsrc->total_localtax2) . "</td></tr>";
1300 }
1301
1302 print '<tr><td>' . $langs->trans('AmountTTC') . '</td><td>' . price($objectsrc->total_ttc) . "</td></tr>";
1303
1304 if (isModEnabled("multicurrency"))
1305 {
1306 print '<tr><td>' . $langs->trans('MulticurrencyAmountHT') . '</td><td>' . price($objectsrc->multicurrency_total_ht) . '</td></tr>';
1307 print '<tr><td>' . $langs->trans('MulticurrencyAmountVAT') . '</td><td>' . price($objectsrc->multicurrency_total_tva) . "</td></tr>";
1308 print '<tr><td>' . $langs->trans('MulticurrencyAmountTTC') . '</td><td>' . price($objectsrc->multicurrency_total_ttc) . "</td></tr>";
1309 }
1310 */
1311 }
1312
1313 print '</table>';
1314
1315 if (is_object($objectsrc)) {
1316 print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
1317 print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
1318 } elseif ($origin == 'project' && !empty($projectid)) {
1319 print '<input type="hidden" name="projectid" value="'.$projectid.'">';
1320 }
1321
1322 print dol_get_fiche_end();
1323
1324 print $form->buttonsSaveCancel("CreateDraftIntervention");
1325
1326 // Show origin lines
1327 if (!empty($origin) && !empty($originid) && is_object($objectsrc) && !getDolGlobalInt('FICHINTER_DISABLE_DETAILS')) {
1328 $title = $langs->trans('Services');
1329 print load_fiche_titre($title);
1330
1331 print '<div class="div-table-responsive-no-min">';
1332 print '<table class="noborder centpercent">';
1333
1334 $objectsrc->printOriginLinesList(!getDolGlobalString('FICHINTER_PRINT_PRODUCTS') ? 'services' : ''); // Show only service, except if option FICHINTER_PRINT_PRODUCTS is on
1335
1336 print '</table>';
1337 print '</div>';
1338 }
1339
1340 print '</form>';
1341} elseif ($id > 0 || !empty($ref)) {
1342 // View mode
1343
1344 $object->fetch($id, $ref);
1345 $object->fetch_thirdparty();
1346
1347 $soc = new Societe($db);
1348 $soc->fetch($object->socid);
1349
1350 if ($error > 0) {
1351 dol_htmloutput_errors($mesg);
1352 } else {
1353 dol_htmloutput_mesg($mesg);
1354 }
1355
1356 $head = fichinter_prepare_head($object);
1357
1358 print dol_get_fiche_head($head, 'card', $langs->trans("InterventionCard"), -1, $object->picto, 0, '', '', 0, '', 1);
1359
1360 $formconfirm = '';
1361
1362 // Confirm deletion of intervention
1363 if ($action == 'delete') {
1364 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteIntervention'), $langs->trans('ConfirmDeleteIntervention'), 'confirm_delete', '', 0, 1);
1365 }
1366
1367 // Confirm validation
1368 if ($action == 'validate') {
1369 // Verify if the object's number os temporary
1370 $ref = substr($object->ref, 1, 4);
1371 if ($ref == 'PROV') {
1372 $numref = $object->getNextNumRef($soc);
1373 if (empty($numref)) {
1374 $error++;
1375 setEventMessages($object->error, $object->errors, 'errors');
1376 }
1377 } else {
1378 $numref = (string) $object->ref;
1379 }
1380 $text = $langs->trans('ConfirmValidateIntervention', $numref);
1381 if (isModEnabled('notification')) {
1382 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1383 $notify = new Notify($db);
1384 $text .= '<br>';
1385 $text .= $notify->confirmMessage('FICHINTER_VALIDATE', $object->socid, $object);
1386 }
1387
1388 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateIntervention'), $text, 'confirm_validate', '', 1, 1);
1389 }
1390
1391 // Confirm sign
1392 if ($action == 'sign') {
1393 $text = $langs->trans('ConfirmSignIntervention');
1394 if (isModEnabled('notification')) {
1395 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1396 $notify = new Notify($db);
1397 $text .= '<br>';
1398 $text .= $notify->confirmMessage('FICHINTER_MODIFY', $object->socid, $object);
1399 }
1400 $formquestion = [];
1401 $formquestion[] = [
1402 'type' => 'select',
1403 'name' => 'signed_status',
1404 'select_show_empty' => 0,
1405 'label' => '<span class="fieldrequired">'.$langs->trans('SignStatus').'</span>',
1406 'values' => $object->getSignedStatusLocalisedArray()
1407 ];
1408 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SignIntervention'), $text, 'confirm_sign', $formquestion, 0, 1);
1409 }
1410
1411 // Confirm unsign
1412 if ($action == 'unsign') {
1413 $text = $langs->trans('ConfirmUnsignIntervention');
1414 if (isModEnabled('notification')) {
1415 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1416 $notify = new Notify($db);
1417 $text .= '<br>';
1418 $text .= $notify->confirmMessage('FICHINTER_MODIFY', $object->socid, $object);
1419 }
1420 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('UnsignIntervention'), $text, 'confirm_unsign', '', 0, 1);
1421 }
1422
1423 // Confirm done
1424 if ($action == 'classifydone') {
1425 $text = $langs->trans('ConfirmCloseIntervention');
1426 if (isModEnabled('notification')) {
1427 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1428 $notify = new Notify($db);
1429 $text .= '<br>';
1430 $text .= $notify->confirmMessage('FICHINTER_CLOSE', $object->socid, $object);
1431 }
1432 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('CloseIntervention'), $text, 'confirm_done', '', 0, 1);
1433 }
1434
1435 // Confirm back to draft
1436 if ($action == 'modify') {
1437 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ModifyIntervention'), $langs->trans('ConfirmModifyIntervention'), 'confirm_modify', '', 0, 1);
1438 }
1439
1440 // Confirm back to open
1441 if ($action == 'reopen') {
1442 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReopenIntervention', $object->ref), 'confirm_reopen', '', 0, 1);
1443 }
1444
1445 // Confirm back to open
1446 if ($action == 'cancel') {
1447 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("Cancel"), $langs->trans('ConfirmCancelIntervention', $object->ref), 'confirm_cancel', '', 0, 1);
1448 }
1449
1450 // Confirm deletion of line
1451 if ($action == 'ask_deleteline') {
1452 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&line_id='.$lineid, $langs->trans('DeleteInterventionLine'), $langs->trans('ConfirmDeleteInterventionLine'), 'confirm_deleteline', '', 0, 1);
1453 }
1454
1455 // Confirmation to delete a subtotal / title / text line (subtotals module)
1456 if ($action == 'ask_subtotal_deleteline') {
1457 $langs->load('subtotals');
1458 $subtotaltitle = 'DeleteSubtotalLine';
1459 $subtotalquestion = 'ConfirmDeleteSubtotalLine';
1460 $subtotalformquestion = array();
1461 if (GETPOST('type') == 'title') {
1462 $subtotalformquestion = array(array('type' => 'checkbox', 'name' => 'deletecorrespondingsubtotalline', 'label' => $langs->trans('DeleteCorrespondingSubtotalLine'), 'value' => 0));
1463 $subtotaltitle = 'DeleteTitleLine';
1464 $subtotalquestion = 'ConfirmDeleteTitleLine';
1465 }
1466 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.GETPOSTINT('lineid'), $langs->trans($subtotaltitle), $langs->trans($subtotalquestion), 'confirm_delete_subtotalline', $subtotalformquestion, 'no', 1);
1467 }
1468
1469 // Clone confirmation
1470 if ($action == 'clone') {
1471 // Create an array for form
1472 $formquestion = array(
1473 // 'text' => $langs->trans("ConfirmClone"),
1474 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
1475 array(
1476 'type' => 'other',
1477 'name' => 'socid',
1478 'label' => $langs->trans("SelectThirdParty"),
1479 'value' => $form->select_company(GETPOSTINT('socid'), 'socid', '', '', 0, 0, array(), 0, 'minwidth200')
1480 ),
1481 array(
1482 'type' => 'checkbox',
1483 'name' => 'clone_contacts',
1484 'label' => $langs->trans("CloneContacts"),
1485 'value' => 1
1486 ),
1487 array(
1488 'type' => 'checkbox',
1489 'name' => 'clone_notes',
1490 'label' => $langs->trans("CloneNotes"),
1491 'value' => 1
1492 )
1493 );
1494
1495 // Paiement incomplet. On demande si motif = escompte ou autre
1496 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneIntervention', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
1497 }
1498
1499 // Subtotal line form
1500 if ($action == 'add_title_line') {
1501 $langs->load('subtotals');
1502 $type = 'title';
1503 $depth_array = $object->getPossibleLevels($langs);
1504 require dol_buildpath('/core/tpl/subtotal_create.tpl.php');
1505 } elseif ($action == 'add_subtotal_line') {
1506 $langs->load('subtotals');
1507 $type = 'subtotal';
1508 $titles = $object->getPossibleTitles();
1509 require dol_buildpath('/core/tpl/subtotal_create.tpl.php');
1510 } elseif ($action == 'add_text_line') {
1511 $langs->load('subtotals');
1512 $type = 'text';
1513 require dol_buildpath('/core/tpl/subtotal_create.tpl.php');
1514 }
1515
1516 if (!$formconfirm) {
1517 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
1518 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1519 if (empty($reshook)) {
1520 $formconfirm .= $hookmanager->resPrint;
1521 } elseif ($reshook > 0) {
1522 $formconfirm = $hookmanager->resPrint;
1523 }
1524 }
1525
1526 // Print form confirm
1527 print $formconfirm;
1528
1529
1530 // Intervention card
1531 $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1532
1533
1534 $morehtmlref = '<div class="refidno">';
1535 // Ref customer
1536 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $permissiontoadd, 'string', '', 0, 1);
1537 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $permissiontoadd, 'string', '', null, null, '', 1);
1538 // Thirdparty
1539 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
1540 // Project
1541 if (isModEnabled('project')) {
1542 $langs->load("projects");
1543 $morehtmlref .= '<br>';
1544 if ($permissiontoadd) {
1545 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
1546 if ($action != 'classify') {
1547 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
1548 }
1549 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
1550 } else {
1551 if (!empty($object->fk_project)) {
1552 $proj = new Project($db);
1553 $proj->fetch($object->fk_project);
1554 $morehtmlref .= $proj->getNomUrl(1);
1555 if ($proj->title) {
1556 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
1557 }
1558 }
1559 }
1560 }
1561 $morehtmlref .= '</div>';
1562
1563 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
1564
1565
1566 print '<div class="fichecenter">';
1567 print '<div class="fichehalfleft">';
1568 print '<div class="underbanner clearboth"></div>';
1569
1570 print '<table class="border tableforfield centpercent">';
1571
1572 if (getDolGlobalString('FICHINTER_USE_PLANNED_AND_DONE_DATES')) {
1573 // Date Start
1574 print '<tr><td class="titlefield">'.$langs->trans("Dateo").'</td>';
1575 print '<td>';
1576 print $object->dateo ? dol_print_date($object->dateo, 'daytext') : '&nbsp;';
1577 print '</td>';
1578 print '</tr>';
1579
1580 // Date End
1581 print '<tr><td>'.$langs->trans("Datee").'</td>';
1582 print '<td>';
1583 print $object->datee ? dol_print_date($object->datee, 'daytext') : '&nbsp;';
1584 print '</td>';
1585 print '</tr>';
1586
1587 // Date Terminate/close
1588 print '<tr><td>'.$langs->trans("Datet").'</td>';
1589 print '<td>';
1590 print $object->datet ? dol_print_date($object->datet, 'daytext') : '&nbsp;';
1591 print '</td>';
1592 print '</tr>';
1593 }
1594
1595 // Description (must be a textarea and not html must be allowed (used in list view)
1596 print '<tr><td class="titlefield">';
1597 print $form->editfieldkey("Description", 'description', $object->description, $object, $permissiontoadd, 'textarea');
1598 print '</td><td>';
1599 print $form->editfieldval("Description", 'description', $object->description, $object, $permissiontoadd, 'textarea:8');
1600 print '</td>';
1601 print '</tr>';
1602
1603 // Categories
1604 if (isModEnabled('category')) {
1605 print '<tr><td>';
1606 print '<table class="nobordernopadding centpercent"><tr><td>';
1607 print $langs->trans("Categories");
1608 print '<td><td class="right">';
1609 if ($permissiontoadd) {
1610 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/fichinter/card.php?id='.$object->id.'&action=edittags&token='.newToken().'">'.img_edit().'</a>';
1611 } else {
1612 print '&nbsp;';
1613 }
1614 print '</td></tr></table>';
1615 print '</td>';
1616 print '<td>';
1617 if ($action == 'edittags') {
1618 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
1619 print '<input type="hidden" name="action" value="settags">';
1620 print '<input type="hidden" name="token" value="'.newToken().'">';
1621 print $form->selectCategories(Categorie::TYPE_FICHINTER, 'categories', $object);
1622 print '<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans("Modify").'">';
1623 print '</form>';
1624 } else {
1625 print $form->showCategories($object->id, Categorie::TYPE_FICHINTER, 1);
1626 }
1627 print "</td></tr>";
1628 }
1629
1630 // Contract
1631 if (isModEnabled('contract')) {
1632 // This feature hang the application on large list of contracts, because the select component is not complete: it does not work like select of thirdparty or product to support large lists
1633 // So we add a hidden option to avoid to have it used and the application locked, until the select_contract is fixed.
1634 if (getDolGlobalString("CONTRACT_CAN_USE_THE_BUGGED_SELECT_COMPONENT")) {
1635 $langs->load('contracts');
1636 print '<tr>';
1637 print '<td>';
1638
1639 print '<table class="nobordernopadding centpercent"><tr><td>';
1640 print $langs->trans('Contract');
1641 print '</td>';
1642 if ($action != 'editcontract') {
1643 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editcontract&id='.$object->id.'">';
1644 print img_edit($langs->trans('SetContract'), 1);
1645 print '</a></td>';
1646 }
1647 print '</tr></table>';
1648 print '</td><td>';
1649 if ($action == 'editcontract') {
1650 $formcontract = new FormContract($db);
1651 $formcontract->formSelectContract($_SERVER["PHP_SELF"].'?id='.$object->id, $object->socid, $object->fk_contrat, 'contratid', 0, 1, 1);
1652 } else {
1653 if ($object->fk_contrat) {
1654 $contratstatic = new Contrat($db);
1655 $contratstatic->fetch($object->fk_contrat);
1656 //print '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$selected.'">'.$projet->title.'</a>';
1657 print $contratstatic->getNomUrl(0, 0, 1);
1658 } else {
1659 print "&nbsp;";
1660 }
1661 }
1662 print '</td>';
1663 print '</tr>';
1664 }
1665 }
1666
1667 // Other attributes
1668 $cols = 2;
1669 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1670
1671 print '</table>';
1672
1673 print '</div>';
1674 print '<div class="fichehalfright">';
1675 print '<div class="underbanner clearboth"></div>';
1676
1677 print '<table class="border tableforfield centpercent">';
1678
1679 if (!getDolGlobalString('FICHINTER_DISABLE_DETAILS') || getDolGlobalString('FICHINTER_DISABLE_DETAILS') == '2') {
1680 // Duration in time
1681 print '<tr><td class="titlefield">'.$langs->trans("TotalDuration").'</td>';
1682 print '<td>'.convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).' ('.convertDurationtoHour($object->duration, "s").' '.$langs->trans("HourShort").')</td>';
1683 print '</tr>';
1684 }
1685
1686 print "</table>";
1687
1688 print '</div>';
1689 print '</div>';
1690
1691 print '<div class="clearboth"></div><br>';
1692
1693
1694 if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
1695 $blocname = 'contacts';
1696 $title = $langs->trans('ContactsAddresses');
1697 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1698 }
1699
1700 if (getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
1701 $blocname = 'notes';
1702 $title = $langs->trans('Notes');
1703 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1704 }
1705
1706 // Line of interventions
1707 if (!getDolGlobalString('FICHINTER_DISABLE_DETAILS') || getDolGlobalString('FICHINTER_DISABLE_DETAILS') == '2') {
1708 print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" name="addinter" method="post">';
1709 print '<input type="hidden" name="token" value="'.newToken().'">';
1710 print '<input type="hidden" name="id" value="'.$object->id.'">';
1711 if ($action == 'editline') {
1712 print '<input type="hidden" name="action" value="updateline">';
1713 print '<input type="hidden" name="line_id" value="'.GETPOSTINT('line_id').'">';
1714 } else {
1715 print '<input type="hidden" name="action" value="addline">';
1716 }
1717 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1718
1719 // Intervention lines
1720 $sql = 'SELECT ft.rowid, ft.description, ft.fk_fichinter, ft.duree, ft.rang,';
1721 $sql .= ' ft.special_code, ft.product_type, ft.extraparams,';
1722 $sql .= ' ft.date as date_intervention';
1723 $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft';
1724 $sql .= ' WHERE ft.fk_fichinter = '.((int) $object->id);
1725 if (getDolGlobalString('FICHINTER_HIDE_EMPTY_DURATION')) {
1726 $sql .= ' AND ft.duree <> 0';
1727 }
1728 $sql .= ' ORDER BY ft.rang ASC, ft.date ASC, ft.rowid';
1729
1730 $resql = $db->query($sql);
1731 if ($resql) {
1732 $num = $db->num_rows($resql);
1733 $i = 0;
1734
1735 if ($num) {
1736 print '<br>';
1737 print '<table class="noborder centpercent">';
1738 print '<tr class="liste_titre">';
1739
1740 // No.
1741 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1742 print '<td width="5" class="center linecolnum"></td>';
1743 }
1744
1745 print '<td class="liste_titre">'.$langs->trans('Description').'</td>';
1746 print '<td class="liste_titre center">'.$langs->trans('Date').'</td>';
1747 print '<td class="liste_titre right">'.(!getDolGlobalString('FICHINTER_WITHOUT_DURATION') ? $langs->trans('Duration') : '').'</td>';
1748 print '<td class="liste_titre">&nbsp;</td>';
1749 print '<td class="liste_titre">&nbsp;</td>';
1750 print "</tr>\n";
1751 }
1752 while ($i < $num) {
1753 $objp = $db->fetch_object($resql);
1754
1755 // Line in view mode
1756 if ($action != 'editline' || GETPOSTINT('line_id') != $objp->rowid) {
1757 print '<tr class="oddeven">';
1758
1759 // No.
1760 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1761 print '<td class="center linecolnum">'.($i + 1).'</td>';
1762 }
1763 if (!empty($objp->special_code) || $objp->product_type == 9) {
1764 $line_color = $object->getSubtotalColors($objp->duree);
1765 $line_options = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams, true) : array();
1766 $line_options = $line_options['subtotal'] ?? array();
1767 print '<td colspan="3" ><strong>'.dol_htmlentitiesbr($objp->description).'</strong>';
1768 if (array_key_exists('titleshowuponpdf', $line_options)) {
1769 echo '&nbsp;' . img_picto($langs->trans("ShowUPOnPDF"), 'invoicing');
1770 }
1771 if (array_key_exists('titleshowtotalexludingvatonpdf', $line_options)) {
1772 echo '&nbsp; <span title="' . $langs->trans("ShowTotalExludingVATOnPDF") . '">%</span>';
1773 }
1774 if (array_key_exists('titleforcepagebreak', $line_options)) {
1775 echo '&nbsp;' . img_picto($langs->trans("ForcePageBreak"), 'file');
1776 }
1777 print "</td>";
1778 } else {
1779 print '<td>';
1780 print '<a name="'.$objp->rowid.'"></a>'; // Anchor to return to the line
1781 print dol_htmlentitiesbr($objp->description);
1782
1783 $objectline = new FichinterLigne($db);
1784 $objectline->fetch($objp->rowid);
1785 $objectline->fetch_optionals();
1786
1787 $extrafields->fetch_name_optionals_label($objectline->table_element);
1788
1789 $temps = $objectline->showOptionals($extrafields, 'view', array(), '', '', '1', 'line');
1790 if (!empty($temps)) {
1791 print '<div style="padding-top: 10px" id="extrafield_lines_area_'.$objp->rowid.'" name="extrafield_lines_area_'.$objp->rowid.'">';
1792 print $temps;
1793 print '</div>';
1794 }
1795
1796 print '</td>';
1797
1798 // Date
1799 print '<td class="center" width="150">'.(!getDolGlobalString('FICHINTER_DATE_WITHOUT_HOUR') ? dol_print_date($db->jdate($objp->date_intervention), 'dayhour') : dol_print_date($db->jdate($objp->date_intervention), 'day')).'</td>';
1800
1801 // Duration
1802 print '<td class="right" width="150">'.(!getDolGlobalString('FICHINTER_WITHOUT_DURATION') ? convertSecondToTime($objp->duree) : '').'</td>';
1803
1804 print "</td>\n";
1805 }
1806 // Icon to edit and delete
1807 if ($object->status == 0 && $permissiontoadd) {
1808 print '<td class="center">';
1809 print '<a class="editfielda marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editline&token='.newToken().'&line_id='.$objp->rowid.'#'.$objp->rowid.'">';
1810 print img_edit();
1811 print '</a>';
1812 print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=ask_deleteline&token='.newToken().'&line_id='.$objp->rowid.'">';
1813 print img_delete();
1814 print '</a></td>';
1815 print '<td class="center">';
1816 if ($num > 1) {
1817 if ($i > 0) {
1818 print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=up&token='.newToken().'&line_id='.$objp->rowid.'">';
1819 print img_up();
1820 print '</a>';
1821 }
1822 if ($i < $num - 1) {
1823 print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=down&token='.newToken().'&line_id='.$objp->rowid.'">';
1824 print img_down();
1825 print '</a>';
1826 }
1827 }
1828 print '</td>';
1829 } else {
1830 print '<td colspan="2">&nbsp;</td>';
1831 }
1832
1833 print '</tr>';
1834 }
1835
1836 // Line in update mode
1837 if ($object->status == 0 && $action == 'editline' && $permissiontoadd && GETPOSTINT('line_id') == $objp->rowid) {
1838 print '<tr class="oddeven nohover">';
1839
1840 // No.
1841 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1842 print '<td class="center linecolnum">'.($i + 1).'</td>';
1843 }
1844
1845 print '<td>';
1846 print '<a name="'.$objp->rowid.'"></a>'; // Anchor to return to the line
1847
1848 // Editeur wysiwyg
1849 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1850 $doleditor = new DolEditor('np_desc', $objp->description, '', 164, 'dolibarr_details', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_2, '90%');
1851 $doleditor->Create();
1852
1853 $objectline = new FichinterLigne($db);
1854 $objectline->fetch($objp->rowid);
1855 $objectline->fetch_optionals();
1856
1857 $extrafields->fetch_name_optionals_label($objectline->table_element);
1858
1859 $temps = $objectline->showOptionals($extrafields, 'edit', array(), '', '', '1', 'line');
1860 if (!empty($temps)) {
1861 print '<div style="padding-top: 10px" id="extrafield_lines_area_'.$objectline->id.'" name="extrafield_lines_area_'.$objectline->id.'">';
1862 print $temps;
1863 print '</div>';
1864 }
1865
1866 print '</td>';
1867
1868 // Date d'intervention
1869 print '<td class="center nowrap">';
1870 if (getDolGlobalString('FICHINTER_DATE_WITHOUT_HOUR')) {
1871 print $form->selectDate($db->jdate($objp->date_intervention), 'di', 0, 0, 0, "date_intervention");
1872 } else {
1873 print $form->selectDate($db->jdate($objp->date_intervention), 'di', 1, 1, 0, "date_intervention");
1874 }
1875 print '</td>';
1876
1877 // Duration
1878 print '<td class="right">';
1879 if (!getDolGlobalString('FICHINTER_WITHOUT_DURATION')) {
1880 $selectmode = 'select';
1881 if (getDolGlobalString('INTERVENTION_ADDLINE_FREEDUREATION')) {
1882 $selectmode = 'text';
1883 }
1884 $form->select_duration('duration', $objp->duree, 0, $selectmode);
1885 }
1886 print '</td>';
1887
1888 print '<td class="center" colspan="5" valign="center">';
1889 print '<input type="submit" class="button buttongen marginbottomonly button-save" name="save" value="'.$langs->trans("Save").'">';
1890 print '<input type="submit" class="button buttongen marginbottomonly button-cancel" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
1891 print '</tr>'."\n";
1892 }
1893
1894 $i++;
1895 }
1896
1897 $db->free($resql);
1898
1899 // Add new line
1900 if ($object->status == 0 && $permissiontoadd && $action != 'editline' && (!getDolGlobalString('FICHINTER_DISABLE_DETAILS') || getDolGlobalString('FICHINTER_DISABLE_DETAILS') == '2')) {
1901 if (!$num) {
1902 print '<br>';
1903 print '<table class="noborder centpercent">';
1904 print '<tr class="liste_titre">';
1905
1906 // No.
1907 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1908 print '<td width="5" class="center linecolnum"></td>';
1909 }
1910
1911 print '<td>';
1912 print '<a name="add"></a>'; // ancre
1913 print $langs->trans('Description').'</td>';
1914 print '<td class="center">'.$langs->trans('Date').'</td>';
1915 print '<td class="right">'.(!getDolGlobalString('FICHINTER_WITHOUT_DURATION') ? $langs->trans('Duration') : '').'</td>';
1916 print '<td colspan="3">&nbsp;</td>';
1917 print "</tr>\n";
1918 }
1919
1920 print '<tr class="oddeven nohover">'."\n";
1921
1922 // No.
1923 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1924 print '<td class="center linecolnum">'.($i + 1).'</td>';
1925 }
1926
1927 print '<td>';
1928 // editeur wysiwyg
1929 if (!getDolGlobalString('FICHINTER_EMPTY_LINE_DESC')) {
1930 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1931 $doleditor = new DolEditor('np_desc', GETPOST('np_desc', 'restricthtml'), '', 100, 'dolibarr_details', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_DETAILS'), ROWS_2, '90%');
1932 $doleditor->Create();
1933 }
1934
1935 $objectline = new FichinterLigne($db);
1936 $extrafields->fetch_name_optionals_label($objectline->table_element);
1937
1938 if (is_object($objectline)) {
1939 $temps = $objectline->showOptionals($extrafields, 'create', array(), '', '', '1', 'line');
1940
1941 if (!empty($temps)) {
1942 print '<div style="padding-top: 10px" id="extrafield_lines_area_create" name="extrafield_lines_area_create">';
1943 print $temps;
1944 print '</div>';
1945 }
1946 }
1947
1948 print '</td>';
1949
1950 // Date intervention
1951 print '<td class="center nowrap">';
1952 $now = dol_now();
1953 $timearray = dol_getdate($now);
1954 if (!GETPOSTINT('diday')) {
1955 if (getDolGlobalInt('FICHINTER_DATE_WITHOUT_HOUR')) {
1956 $timewithnohour = dol_mktime(0, 0, 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
1957 } else {
1958 $timewithnohour = dol_mktime($timearray['hours'], $timearray['minutes'], 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
1959 }
1960 } else {
1961 $timewithnohour = dol_mktime(GETPOSTINT('dihour'), GETPOSTINT('dimin'), 0, GETPOSTINT('dimonth'), GETPOSTINT('diday'), GETPOSTINT('diyear'));
1962 }
1963 if (getDolGlobalInt('FICHINTER_DATE_WITHOUT_HOUR')) {
1964 print $form->selectDate($timewithnohour, 'di', 0, 0, 0, "addinter");
1965 } else {
1966 print $form->selectDate($timewithnohour, 'di', 1, 1, 0, "addinter");
1967 }
1968 print '</td>';
1969
1970 // Duration
1971 print '<td class="right">';
1972 if (!getDolGlobalString('FICHINTER_WITHOUT_DURATION')) {
1973 $selectmode = 'select';
1974 if (getDolGlobalString('INTERVENTION_ADDLINE_FREEDUREATION')) {
1975 $selectmode = 'text';
1976 }
1977 $form->select_duration('duration', (!GETPOSTINT('durationhour') && !GETPOSTINT('durationmin')) ? 3600 : (60 * 60 * GETPOSTINT('durationhour') + 60 * GETPOSTINT('durationmin')), 0, $selectmode);
1978 }
1979 print '</td>';
1980
1981 print '<td class="center" valign="middle" colspan="3"><input type="submit" class="button button-add" value="'.$langs->trans('Add').'" name="addline"></td>';
1982 print '</tr>';
1983
1984 if (!$num) {
1985 print '</table>';
1986 }
1987 }
1988
1989 if ($num) {
1990 print '</table>';
1991 }
1992 } else {
1993 dol_print_error($db);
1994 }
1995
1996 print '</form>'."\n";
1997 }
1998
1999 print dol_get_fiche_end();
2000
2001 print "\n";
2002
2003
2004 /*
2005 * Actions buttons
2006 */
2007
2008 print '<div class="tabsAction">';
2009
2010 $parameters = array();
2011 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
2012 // modified by hook
2013 if (empty($reshook)) {
2014 $params = array();
2015 if ($user->socid == 0) {
2016 if ($action != 'editdescription' && $action != 'presend' && $action != 'editline') {
2017 // Subtotal
2018 if ($object->status == Fichinter::STATUS_DRAFT && isModEnabled('subtotals')
2019 && (getDolGlobalString('SUBTOTAL_TITLE_'.strtoupper($object->element)) || getDolGlobalString('SUBTOTAL_'.strtoupper($object->element)) || getDolGlobalString('SUBTOTAL_TEXT_'.strtoupper($object->element)))) {
2020 $langs->load('subtotals');
2021
2022 $url_button = array();
2023 $url_button[] = array(
2024 'lang' => 'subtotals',
2025 'enabled' => (isModEnabled('intervention') && $object->status == Fichinter::STATUS_DRAFT),
2026 'perm' => (bool) $permissiontoadd,
2027 'label' => $langs->trans('AddTitleLine'),
2028 'url' => '/fichinter/card.php?id='.$object->id.'&action=add_title_line&token='.newToken()
2029 );
2030
2031 $url_button[] = array(
2032 'lang' => 'subtotals',
2033 'enabled' => (isModEnabled('intervention') && $object->status == Fichinter::STATUS_DRAFT),
2034 'perm' => (bool) $permissiontoadd,
2035 'label' => $langs->trans('AddSubtotalLine'),
2036 'url' => '/fichinter/card.php?id='.$object->id.'&action=add_subtotal_line&token='.newToken()
2037 );
2038
2039 $url_button[] = array(
2040 'lang' => 'subtotals',
2041 'enabled' => (isModEnabled('intervention') && $object->status == Fichinter::STATUS_DRAFT),
2042 'perm' => (bool) $permissiontoadd,
2043 'label' => $langs->trans('AddTextLine'),
2044 'url' => '/fichinter/card.php?id='.$object->id.'&action=add_text_line&token='.newToken()
2045 );
2046 print dolGetButtonAction('', $langs->trans('SubTotal'), 'default', $url_button, '', true);
2047 }
2048
2049 // Validate
2050 if ($object->status == Fichinter::STATUS_DRAFT && (count($object->lines) > 0 || getDolGlobalString('FICHINTER_DISABLE_DETAILS') == '1')) {
2051 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $permissiontoadd) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('ficheinter', 'ficheinter_advance', 'validate'))) {
2052 print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=validate&token='.newToken().'">'.$langs->trans("Validate").'</a></div>';
2053 } else {
2054 print '<div class="inline-block divButActionRefused"><span class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Validate").'</span></div>';
2055 }
2056 }
2057
2058 // Modify
2059 if ($object->status == Fichinter::STATUS_VALIDATED && ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $permissiontoadd) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('ficheinter', 'ficheinter_advance', 'unvalidate')))) {
2060 print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=modify&token='.newToken().'">';
2061 if (!getDolGlobalString('FICHINTER_DISABLE_DETAILS') || getDolGlobalString('FICHINTER_DISABLE_DETAILS') == '2') {
2062 print $langs->trans("Modify");
2063 } else {
2064 print $langs->trans("SetToDraft");
2065 }
2066 print '</a></div>';
2067 }
2068
2069 // Reopen
2070 if ($object->status >= Fichinter::STATUS_CLOSED) {
2071 if ($permissiontoadd) {
2072 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans('ReOpen').'</a></div>';
2073 } else {
2074 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('ReOpen').'</a></div>';
2075 }
2076 }
2077
2078 // Send
2079 if (empty($user->socid)) {
2081 if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight('ficheinter', 'ficheinter_advance', 'send')) {
2082 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id, 'action' => 'presend', 'mode' => 'init'], true).'#formmailbeforetitle', '');
2083 } else {
2084 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', '#', '', false);
2085 }
2086 }
2087 }
2088
2089 // Create intervention model
2090 if ($object->status == Fichinter::STATUS_DRAFT && $permissiontoadd && (count($object->lines) > 0)) {
2091 print '<div class="inline-block divButAction">';
2092 print '<a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$object->id.'&action=create&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$object->id).'">'.$langs->trans("ChangeIntoRepeatableIntervention").'</a>';
2093 print '</div>';
2094 }
2095
2096 $arrayofcreatebutton = array();
2097 // Proposal
2098 if (isModEnabled("service") && isModEnabled("propal") && $object->status > Fichinter::STATUS_DRAFT) {
2099 $langs->load("propal");
2100 if ($object->status < Fichinter::STATUS_BILLED) {
2101 $arrayofcreatebutton[] = array(
2102 'url' => '/comm/propal/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid,
2103 'label' => $langs->trans('AddProp'),
2104 'lang' => 'propal',
2105 'perm' => $user->hasRight('propal', 'creer'),
2106 'enabled' => true,
2107 );
2108 }
2109 }
2110
2111 // Invoicing
2112 if (isModEnabled('invoice') && $object->status > Fichinter::STATUS_DRAFT) {
2113 $langs->load("bills");
2114 if ($object->status < Fichinter::STATUS_BILLED) {
2115 $arrayofcreatebutton[] = array(
2116 'url' => '/compta/facture/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid,
2117 'label' => $langs->trans('AddBill'),
2118 'lang' => 'bills',
2119 'perm' => $user->hasRight('facture', 'creer') ? true : false,
2120 'enabled' => true,
2121 );
2122 }
2123
2124 if (getDolGlobalString('FICHINTER_CLASSIFY_BILLED')) { // Option deprecated. In a future, billed must be managed with a dedicated field to 0 or 1
2125 if ($object->status != Fichinter::STATUS_BILLED) {
2126 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifybilled&token='.newToken().'">'.$langs->trans("InterventionClassifyBilled").'</a></div>';
2127 } else {
2128 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifyunbilled&token='.newToken().'">'.$langs->trans("InterventionClassifyUnBilled").'</a></div>';
2129 }
2130 }
2131 }
2132
2133 if (count($arrayofcreatebutton)) {
2134 print dolGetButtonAction('', $langs->trans("Create"), 'default', $arrayofcreatebutton, '', true, $params);
2135 }
2136
2137 // Sign
2139 if ($object->signed_status != Fichinter::$SIGNED_STATUSES['STATUS_SIGNED_ALL']) {
2140 print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=sign&token=' . newToken() . '">' . $langs->trans("InterventionSign") . '</a></div>';
2141 } else {
2142 print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=unsign&token=' . newToken() . '">' . $langs->trans("InterventionUnsign") . '</a></div>';
2143 }
2144 }
2145
2146 // Done
2147 if (!getDolGlobalString('FICHINTER_CLASSIFY_BILLED') && $object->status > Fichinter::STATUS_DRAFT && $object->status < Fichinter::STATUS_CLOSED) {
2148 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifydone&token='.newToken().'">'.$langs->trans("InterventionClassifyDone").'</a></div>';
2149 }
2150
2151 // Clone
2152 if ($permissiontoadd) {
2153 print '<div class="inline-block divButAction">'.dolGetButtonAction($langs->trans("ToClone"), $langs->trans("ToClone"), 'clone', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&token='.newToken().'&object=ficheinter', '', true, array('attr' => array('class' => 'reposition'))).'</div>';
2154 }
2155
2156 // Cancel fichinter
2157 if ($object->status == Fichinter::STATUS_VALIDATED) {
2158 if ($user->hasRight('ficheinter', 'supprimer')) {
2159 print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'">'.$langs->trans("Cancel").'</a></div>';
2160 } else {
2161 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('Cancel').'</a></div>';
2162 }
2163 }
2164
2165 // Delete
2166 print '<div class="inline-block divButAction">';
2167 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id, 'action' => 'delete'], true), 'delete', $permissiontodelete, array('attr' => array('class' => 'reposition')))."\n";
2168 print '</div>';
2169 }
2170 }
2171 }
2172
2173 print '</div>';
2174
2175 // Select mail models is same action as presend
2176 if (GETPOST('modelselected')) {
2177 $action = 'presend';
2178 }
2179
2180 if ($action != 'presend') {
2181 print '<div class="fichecenter"><div class="fichehalfleft">';
2182
2183 /*
2184 * Built documents
2185 */
2186 $filename = dol_sanitizeFileName($object->ref);
2187 $filedir = getMultidirOutput($object)."/".$filename;
2188 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
2189 $genallowed = $permissiontoread;
2190 $delallowed = $permissiontoadd;
2191 print $formfile->showdocuments('ficheinter', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang, '', $object);
2192
2193 // Show links to link elements
2194 $tmparray = $form->showLinkToObjectBlock($object, array(), array('fichinter'), 1);
2195 $linktoelem = $tmparray['linktoelem'];
2196 $htmltoenteralink = $tmparray['htmltoenteralink'];
2197 print $htmltoenteralink;
2198
2199 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
2200
2201 // Show direct download link
2202 if ($object->status != Fichinter::STATUS_DRAFT && getDolGlobalString('FICHINTER_ALLOW_EXTERNAL_DOWNLOAD')) {
2203 print '<br><!-- Link to download main doc -->'."\n";
2204 print showDirectDownloadLink($object).'<br>';
2205 }
2206
2207 // Show online signature link
2208 if ($object->status != Fichinter::STATUS_DRAFT && getDolGlobalString('FICHINTER_ALLOW_ONLINE_SIGN')) {
2209 print '<br><!-- Link to sign -->';
2210 require_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php';
2211
2212 print showOnlineSignatureUrl('fichinter', $object->ref, $object).'<br>';
2213 }
2214
2215 print '</div><div class="fichehalfright">';
2216
2217 $MAXEVENT = 10;
2218
2219 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/fichinter/agenda.php?id='.$object->id);
2220
2221 // List of actions on element
2222 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2223 $formactions = new FormActions($db);
2224 $somethingshown = $formactions->showactions($object, 'fichinter', $socid, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for thirdparty
2225
2226 print '</div></div>';
2227 }
2228
2229 // Presend form
2230 $modelmail = 'fichinter_send';
2231 $defaulttopic = 'SendInterventionRef';
2232 $diroutput = $conf->ficheinter->multidir_output[$object->entity];
2233 $trackid = 'int'.$object->id;
2234
2235 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2236}
2237
2238
2239llxFooter();
2240
2241$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage a WYSIWYG editor.
const STATUS_BILLED
Billed.
const STATUS_DRAFT
Draft status.
const STATUS_CANCELED
Canceled status.
const STATUS_VALIDATED
Validated status.
const STATUS_CLOSED
Closed.
Class to manage intervention lines.
Class to manage building of HTML components.
Class to manage generation of HTML components for contract module.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage building of HTML components.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage the table of subscription to notifications.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
convertDurationtoHour($duration_value, $duration_unit)
Convert duration to hour.
Definition date.lib.php:357
convertTime2Seconds($iHours=0, $iMinutes=0, $iSeconds=0)
Convert hours and minutes into seconds.
Definition date.lib.php:234
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
Definition date.lib.php:263
fichinter_prepare_head($object)
Prepare array with list of tabs.
dol_now($mode='gmt')
Return date for now.
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...
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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.
Definition html.lib.php:542
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.
Definition html.lib.php:740
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
showDirectDownloadLink($object)
Return string with full Url.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formatted messages to output (Used to show messages on html output).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formatted error messages to output (Used to show messages on html output).
fichinter_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create an intervention document on disk using template defined into FICHEINTER_ADDON_PDF.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.