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