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