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