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