dolibarr 22.0.5
fichinter.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2011-2020 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
7 * Copyright (C) 2015-2020 Charlene Benke <charlie@patas-monkey.com>
8 * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
9 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2023-2024 William Mead <william.mead@manchenumerique.fr>
11 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
32require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
33require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinterligne.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/commonsignedobject.class.php';
35
42{
43 use CommonSignedObject;
44
45 public $fields = array(
46 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
47 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => 'isModEnabled("societe")', 'visible' => -1, 'notnull' => 1, 'position' => 15),
48 'fk_projet' => array('type' => 'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label' => 'Fk projet', 'enabled' => 'isModEnabled("project")', 'visible' => -1, 'position' => 20),
49 'fk_contrat' => array('type' => 'integer:Contrat:contrat/class/contrat.class.php', 'label' => 'Fk contrat', 'enabled' => '$conf->contrat->enabled', 'visible' => -1, 'position' => 25),
50 'ref' => array('type' => 'varchar(30)', 'label' => 'Ref', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'showoncombobox' => 1, 'position' => 30),
51 'ref_ext' => array('type' => 'varchar(255)', 'label' => 'RefExt', 'enabled' => 1, 'visible' => 0, 'position' => 35),
52 'ref_client' => array('type' => 'varchar(255)', 'label' => 'RefCustomer', 'enabled' => 1, 'visible' => -1, 'position' => 36),
53 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 40, 'index' => 1),
54 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 45),
55 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'position' => 50),
56 'date_valid' => array('type' => 'datetime', 'label' => 'DateValidation', 'enabled' => 1, 'visible' => -1, 'position' => 55),
57 'datei' => array('type' => 'date', 'label' => 'Datei', 'enabled' => 1, 'visible' => -1, 'position' => 60),
58 'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user author', 'enabled' => 1, 'visible' => -1, 'position' => 65),
59 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'position' => 70),
60 'fk_user_valid' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserValidation', 'enabled' => 1, 'visible' => -1, 'position' => 75),
61 'dateo' => array('type' => 'date', 'label' => 'Dateo', 'enabled' => 1, 'visible' => -1, 'position' => 85),
62 'datee' => array('type' => 'date', 'label' => 'Datee', 'enabled' => 1, 'visible' => -1, 'position' => 90),
63 'datet' => array('type' => 'date', 'label' => 'Datet', 'enabled' => 1, 'visible' => -1, 'position' => 95),
64 'duree' => array('type' => 'integer', 'label' => 'Duree', 'enabled' => 1, 'visible' => -1, 'position' => 100),
65 'signed_status' => array('type' => 'smallint(6)', 'label' => 'SignedStatus', 'enabled' => 1, 'visible' => -1, 'position' => 101, 'arrayofkeyval' => array(0 => 'NoSignature', 1 => 'SignedSender', 2 => 'SignedReceiver', 3 => 'SignedReceiverOnline', 9 => 'SignedAll')),
66 'description' => array('type' => 'html', 'label' => 'Description', 'enabled' => 1, 'visible' => -1, 'position' => 105, 'showoncombobox' => 2),
67 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 110),
68 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 115),
69 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 120),
70 'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'Last main doc', 'enabled' => 1, 'visible' => -1, 'position' => 125),
71 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 130),
72 'extraparams' => array('type' => 'varchar(255)', 'label' => 'Extraparams', 'enabled' => 1, 'visible' => -1, 'position' => 135),
73 'fk_statut' => array('type' => 'integer', 'label' => 'Fk statut', 'enabled' => 1, 'visible' => -1, 'position' => 500),
74 );
75
79 public $element = 'fichinter';
80
84 public $table_element = 'fichinter';
85
89 public $table_element_line = 'fichinterdet';
90
94 public $picto = 'intervention';
95
99 protected $table_ref_field = 'ref';
100
104 public $socid;
105
109 public $author;
110
114 public $datec;
115
119 public $datev;
123 public $dateo;
127 public $datee;
128
132 public $datet;
133
139 public $datem;
140
144 public $duration;
145
150 public $statut = 0; // 0=draft, 1=validated, 2=invoiced, 3=Terminate
151
155 public $status = 0; // 0=draft, 1=validated, 2=invoiced, 3=Terminate
156
160 public $description;
161
165 public $fk_contrat = 0;
166
170 public $fk_project;
171
176 public $ref_client;
177
181 public $extraparams = array();
182
186 public $lines = array();
187
191 const STATUS_DRAFT = 0;
192
197
201 const STATUS_BILLED = 2;
202
206 const STATUS_CLOSED = 3;
207
213 public $date_delivery;
214
219 public $delivery_date_receipt;
220
225 public $user_author_id;
226
227
233 public function __construct($db)
234 {
235 $this->db = $db;
236 }
237
243 public function loadStateBoard()
244 {
245 global $user;
246
247 $this->nb = array();
248 $clause = "WHERE";
249
250 $sql = "SELECT count(fi.rowid) as nb";
251 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as fi";
252 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON fi.fk_soc = s.rowid";
253 if (!$user->hasRight('societe', 'client', 'voir')) {
254 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
255 $sql .= " WHERE sc.fk_user = ".((int) $user->id);
256 $clause = "AND";
257 }
258 $sql .= " ".$clause." fi.entity IN (".getEntity('intervention').")";
259
260 $resql = $this->db->query($sql);
261 if ($resql) {
262 while ($obj = $this->db->fetch_object($resql)) {
263 $this->nb["interventions"] = $obj->nb;
264 }
265 $this->db->free($resql);
266 return 1;
267 } else {
268 dol_print_error($this->db);
269 $this->error = $this->db->error();
270 return -1;
271 }
272 }
273
281 public function create($user, $notrigger = 0)
282 {
283 global $conf, $langs;
284
285 $error = 0;
286
287 dol_syslog(get_class($this)."::create ref=".$this->ref);
288
289 // Check parameters
290 if (!empty($this->ref)) { // We check that ref is not already used
291 $result = self::isExistingObject($this->element, 0, $this->ref); // Check ref is not yet used
292 if ($result > 0) {
293 $this->error = 'ErrorRefAlreadyExists';
294 dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING);
295 $this->db->rollback();
296 return -1;
297 }
298 }
299 if (!is_numeric($this->duration)) {
300 $this->duration = 0;
301 }
302 if (isset($this->ref_client)) {
303 $this->ref_client = trim($this->ref_client);
304 }
305
306 if ($this->socid <= 0) {
307 $this->error = 'ErrorFicheinterCompanyDoesNotExist';
308 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
309 return -1;
310 }
311 $this->entity = setEntity($this);
312
313 $soc = new Societe($this->db);
314 $result = $soc->fetch($this->socid);
315
316 $now = dol_now();
317
318 $this->db->begin();
319
320 $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter (";
321 $sql .= "fk_soc";
322 $sql .= ", datec";
323 $sql .= ", ref";
324 $sql .= ", ref_client";
325 $sql .= ", entity";
326 $sql .= ", fk_user_author";
327 $sql .= ", fk_user_modif";
328 $sql .= ", description";
329 $sql .= ", model_pdf";
330 $sql .= ", fk_projet";
331 $sql .= ", fk_contrat";
332 $sql .= ", fk_statut";
333 $sql .= ", signed_status";
334 $sql .= ", note_private";
335 $sql .= ", note_public";
336 $sql .= ") ";
337 $sql .= " VALUES (";
338 $sql .= $this->socid;
339 $sql .= ", '".$this->db->idate($now)."'";
340 $sql .= ", '".$this->db->escape($this->ref)."'";
341 $sql .= ", ".($this->ref_client ? "'".$this->db->escape($this->ref_client)."'" : "null");
342 $sql .= ", ".((int) $this->entity);
343 $sql .= ", ".((int) $user->id);
344 $sql .= ", ".((int) $user->id);
345 $sql .= ", ".($this->description ? "'".$this->db->escape($this->description)."'" : "null");
346 $sql .= ", '".$this->db->escape($this->model_pdf)."'";
347 $sql .= ", ".((int) $this->fk_project > 0 ? ((int) $this->fk_project) : 0);
348 $sql .= ", ".((int) $this->fk_contrat > 0 ? ((int) $this->fk_contrat) : 0);
349 $sql .= ", ".((int) $this->status);
350 $sql .= ", ".((int) $this->signed_status);
351 $sql .= ", ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
352 $sql .= ", ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
353 $sql .= ")";
354
355 dol_syslog(get_class($this)."::create", LOG_DEBUG);
356 $result = $this->db->query($sql);
357 if ($result) {
358 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."fichinter");
359
360 if ($this->id) {
361 $this->ref = '(PROV'.$this->id.')';
362 $sql = 'UPDATE '.MAIN_DB_PREFIX."fichinter SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".((int) $this->id);
363
364 dol_syslog(get_class($this)."::create", LOG_DEBUG);
365 $resql = $this->db->query($sql);
366 if (!$resql) {
367 $error++;
368 }
369 }
370
371 if (!$error) {
372 $result = $this->insertExtraFields();
373 if ($result < 0) {
374 $error++;
375 }
376 }
377
378 // Add linked object
379 if (!$error && $this->origin && $this->origin_id) {
380 $ret = $this->add_object_linked();
381 if (!$ret) {
382 dol_print_error($this->db);
383 }
384 }
385
386
387 if (!$error && !$notrigger) {
388 // Call trigger
389 $result = $this->call_trigger('FICHINTER_CREATE', $user);
390 if ($result < 0) {
391 $error++;
392 }
393 // End call triggers
394 }
395
396 if (!$error) {
397 $this->db->commit();
398 return $this->id;
399 } else {
400 $this->db->rollback();
401 $this->error = implode(',', $this->errors);
402 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
403 return -1;
404 }
405 } else {
406 $this->error = $this->db->error();
407 $this->db->rollback();
408 return -1;
409 }
410 }
411
419 public function update($user, $notrigger = 0)
420 {
421 global $conf;
422
423 if (!is_numeric($this->duration)) {
424 $this->duration = 0;
425 }
426 if (!dol_strlen((string) $this->fk_project)) {
427 $this->fk_project = 0;
428 }
429 if (isset($this->ref_client)) {
430 $this->ref_client = trim($this->ref_client);
431 }
432
433 $error = 0;
434
435 $this->db->begin();
436
437 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET ";
438 $sql .= "description = '".$this->db->escape($this->description)."'";
439 $sql .= ", duree = ".((int) $this->duration);
440 $sql .= ", ref_client = ".($this->ref_client ? "'".$this->db->escape($this->ref_client)."'" : "null");
441 if ((int) $this->fk_project > 0) {
442 $sql .= ", fk_projet = ".((int) $this->fk_project);
443 }
444 if (isset($this->datec)) {
445 $sql .= ", datec = ".($this->datec ? "'".$this->db->idate($this->datec)."'" : "null");
446 }
447 if (isset($this->datev)) {
448 $sql .= ", date_valid = ".($this->datev ? "'".$this->db->idate($this->datev)."'" : "null");
449 }
450 if (isset($this->datet)) {
451 $sql .= ", datet = ".($this->datet ? "'".$this->db->idate($this->datet)."'" : "null");
452 }
453 $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
454 $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
455 $sql .= ", fk_user_modif = ".((int) $user->id);
456 $sql .= " WHERE rowid = ".((int) $this->id);
457
458 dol_syslog(get_class($this)."::update", LOG_DEBUG);
459 if ($this->db->query($sql)) {
460 if (!$error) {
461 $result = $this->insertExtraFields();
462 if ($result < 0) {
463 $error++;
464 }
465 }
466
467 if (!$error && !$notrigger) {
468 // Call trigger
469 $result = $this->call_trigger('FICHINTER_MODIFY', $user);
470 if ($result < 0) {
471 $error++;
472 $this->db->rollback();
473 return -1;
474 }
475 // End call triggers
476 }
477
478 $this->db->commit();
479 return 1;
480 } else {
481 $this->error = $this->db->error();
482 $this->db->rollback();
483 return -1;
484 }
485 }
486
495 public function fetch($rowid, $ref = '', $ref_ext = '')
496 {
497 $sql = "SELECT f.rowid, f.ref, f.ref_client, f.description, f.fk_soc, f.fk_statut as status, f.signed_status,";
498 $sql .= " f.datec, f.dateo, f.datee, f.datet, f.fk_user_author,";
499 $sql .= " f.date_valid as datev,";
500 $sql .= " f.tms as datem,";
501 $sql .= " f.duree, f.fk_projet as fk_project, f.note_public, f.note_private, f.model_pdf, f.last_main_doc, f.extraparams, fk_contrat, f.entity as entity";
502 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
503 $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
504 if ($ref) {
505 $sql .= " AND f.ref = '".$this->db->escape($ref)."'";
506 } elseif ($ref_ext) {
507 $sql .= " AND f.ref_ext = '".$this->db->escape($ref_ext)."'";
508 } else {
509 $sql .= " AND f.rowid = ".((int) $rowid);
510 }
511
512 $resql = $this->db->query($sql);
513 if ($resql) {
514 if ($this->db->num_rows($resql)) {
515 $obj = $this->db->fetch_object($resql);
516
517 $this->id = $obj->rowid;
518 $this->ref = $obj->ref;
519 $this->ref_client = $obj->ref_client;
520 $this->description = $obj->description;
521 $this->socid = $obj->fk_soc;
522 $this->status = $obj->status;
523 $this->statut = $obj->status; // deprecated
524 $this->signed_status = $obj->signed_status;
525 $this->duration = $obj->duree;
526 $this->datec = $this->db->jdate($obj->datec);
527 $this->dateo = $this->db->jdate($obj->dateo);
528 $this->datee = $this->db->jdate($obj->datee);
529 $this->datet = $this->db->jdate($obj->datet);
530 $this->datev = $this->db->jdate($obj->datev);
531 $this->datem = $this->db->jdate($obj->datem);
532 $this->fk_project = $obj->fk_project;
533 $this->note_public = $obj->note_public;
534 $this->note_private = $obj->note_private;
535 $this->model_pdf = $obj->model_pdf;
536 $this->fk_contrat = $obj->fk_contrat;
537 $this->entity = $obj->entity;
538
539 $this->user_creation_id = $obj->fk_user_author;
540
541 $this->extraparams = is_null($obj->extraparams) ? [] : (array) json_decode($obj->extraparams, true);
542
543 $this->last_main_doc = $obj->last_main_doc;
544
545 // Retrieve extrafields
546 $this->fetch_optionals();
547
548 /*
549 * Lines
550 */
551 $result = $this->fetch_lines();
552 if ($result < 0) {
553 return -3;
554 }
555 $this->db->free($resql);
556 return 1;
557 }
558
559 return 0;
560 } else {
561 $this->error = $this->db->lasterror();
562 return -1;
563 }
564 }
565
572 public function setDraft($user)
573 {
574 $error = 0;
575
576 // Protection
577 if ($this->status <= self::STATUS_DRAFT) {
578 return 0;
579 }
580
581 dol_syslog(get_class($this)."::setDraft", LOG_DEBUG);
582
583 $this->oldcopy = dol_clone($this, 2);
584
585 $this->db->begin();
586
587 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
588 $sql .= " SET fk_statut = ".self::STATUS_DRAFT;
589 $sql .= " WHERE rowid = ".((int) $this->id);
590
591 $resql = $this->db->query($sql);
592 if ($resql) {
593 if (!$error) {
594 // Call trigger
595 $result = $this->call_trigger('FICHINTER_UNVALIDATE', $user);
596 if ($result < 0) {
597 $error++;
598 }
599 }
600
601 if (!$error) {
602 $this->status = self::STATUS_DRAFT;
603 $this->statut = self::STATUS_DRAFT; // deprecated
604 $this->db->commit();
605 return 1;
606 } else {
607 $this->db->rollback();
608 return -1;
609 }
610 } else {
611 $this->db->rollback();
612 $this->error = $this->db->lasterror();
613 return -1;
614 }
615 }
616
624 public function setValid($user, $notrigger = 0)
625 {
626 global $conf;
627 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
628
629 $error = 0;
630
631 if ($this->status != self::STATUS_VALIDATED) {
632 $this->db->begin();
633
634 $now = dol_now();
635
636 // Define new ref
637 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
638 $num = $this->getNextNumRef($this->thirdparty);
639 } else {
640 $num = $this->ref;
641 }
642 $this->newref = dol_sanitizeFileName($num);
643
644 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
645 $sql .= " SET fk_statut = 1";
646 $sql .= ", ref = '".$this->db->escape($num)."'";
647 $sql .= ", date_valid = '".$this->db->idate($now)."'";
648 $sql .= ", fk_user_valid = ".($user->id > 0 ? (int) $user->id : "null");
649 $sql .= " WHERE rowid = ".((int) $this->id);
650 $sql .= " AND entity = ".((int) $this->entity);
651
652 $sql .= " AND fk_statut = 0";
653
654 dol_syslog(get_class($this)."::setValid", LOG_DEBUG);
655 $resql = $this->db->query($sql);
656 if (!$resql) {
657 dol_print_error($this->db);
658 $error++;
659 }
660
661 if (!$error && !$notrigger) {
662 // Call trigger
663 $result = $this->call_trigger('FICHINTER_VALIDATE', $user);
664 if ($result < 0) {
665 $error++;
666 }
667 // End call triggers
668 }
669
670 if (!$error) {
671 $this->oldref = $this->ref;
672
673 // Rename directory if dir was a temporary ref
674 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
675 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
676
677 // Now we rename also files into index
678 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'ficheinter/".$this->db->escape($this->newref)."'";
679 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'ficheinter/".$this->db->escape($this->ref)."' and entity = ".((int) $this->entity);
680 $resql = $this->db->query($sql);
681 if (!$resql) {
682 $error++;
683 $this->error = $this->db->lasterror();
684 }
685 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'ficheinter/".$this->db->escape($this->newref)."'";
686 $sql .= " WHERE filepath = 'ficheinter/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
687 $resql = $this->db->query($sql);
688 if (!$resql) {
689 $error++;
690 $this->error = $this->db->lasterror();
691 }
692
693 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
694 $oldref = dol_sanitizeFileName($this->ref);
695 $newref = dol_sanitizeFileName($num);
696 $dirsource = $conf->ficheinter->dir_output.'/'.$oldref;
697 $dirdest = $conf->ficheinter->dir_output.'/'.$newref;
698 if (!$error && file_exists($dirsource)) {
699 dol_syslog(get_class($this)."::setValid rename dir ".$dirsource." into ".$dirdest);
700
701 if (@rename($dirsource, $dirdest)) {
702 dol_syslog("Rename ok");
703 // Rename docs starting with $oldref with $newref
704 $listoffiles = dol_dir_list($conf->ficheinter->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
705 foreach ($listoffiles as $fileentry) {
706 $dirsource = $fileentry['name'];
707 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
708 $dirsource = $fileentry['path'].'/'.$dirsource;
709 $dirdest = $fileentry['path'].'/'.$dirdest;
710 @rename($dirsource, $dirdest);
711 }
712 }
713 }
714 }
715 }
716
717 // Set new ref and define current status
718 if (!$error) {
719 $this->ref = $num;
721 $this->statut = self::STATUS_VALIDATED; // deprecated
722 $this->date_validation = $now;
723 $this->db->commit();
724 return 1;
725 } else {
726 $this->db->rollback();
727 dol_syslog(get_class($this)."::setValid ".$this->error, LOG_ERR);
728 return -1;
729 }
730 }
731
732 return 0;
733 }
734
742 public function setClose($user, $notrigger = 0)
743 {
744 global $conf;
745
746 $error = 0;
747
748 if ($this->status == self::STATUS_CLOSED) {
749 return 0;
750 } else {
751 $this->db->begin();
752
753 $now = dol_now();
754
755 $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element;
756 $sql .= ' SET fk_statut = ' . self::STATUS_CLOSED . ',';
757 $sql .= " datet = '" . $this->db->idate($now) . "',";
758 $sql .= " fk_user_modif = " . ((int) $user->id);
759 $sql .= " WHERE rowid = " . ((int) $this->id);
760 $sql .= " AND fk_statut > " . self::STATUS_DRAFT;
761 $sql .= " AND entity = " . ((int) $conf->entity);
762
763 if ($this->db->query($sql)) {
764 if (!$notrigger) {
765 // Call trigger
766 $result = $this->call_trigger('FICHINTER_CLOSE', $user);
767 if ($result < 0) {
768 $error++;
769 }
770 // End call triggers
771 }
772
773 if (!$error) {
775 $this->statut = self::STATUS_CLOSED; // deprecated
776 $this->db->commit();
777 return 1;
778 } else {
779 $this->db->rollback();
780 return -1;
781 }
782 } else {
783 $this->error = $this->db->lasterror();
784 $this->db->rollback();
785 return -1;
786 }
787 }
788 }
789
795 public function getAmount()
796 {
797 $amount = 0;
798
799 $this->author = new User($this->db);
800 $this->author->fetch($this->user_creation_id);
801
802 $thm = $this->author->thm;
803
804 foreach ($this->lines as $line) {
805 $amount += ($line->duration / 60 / 60 * (float) $thm);
806 }
807
808 return (float) price2num($amount, 'MT');
809 }
810
811
823 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
824 {
825 global $conf;
826
827 $outputlangs->load("interventions");
828
829 if (!dol_strlen($modele)) {
830 $modele = 'soleil';
831
832 if (!empty($this->model_pdf)) {
833 $modele = $this->model_pdf;
834 } elseif (getDolGlobalString('FICHEINTER_ADDON_PDF')) {
835 $modele = getDolGlobalString('FICHEINTER_ADDON_PDF');
836 }
837 }
838
839 $modelpath = "core/modules/fichinter/doc/";
840
841 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
842 }
843
850 public function getLibStatut($mode = 0)
851 {
852 return $this->LibStatut((isset($this->statut) ? $this->statut : $this->status), $mode);
853 }
854
855 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
863 public function LibStatut($status, $mode = 0)
864 {
865 // phpcs:enable
866 global $langs;
867 // Init/load array of translation of status
868 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
869 $langs->load("interventions");
870 $langs->load("propal");
871
872 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
873 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
874 $this->labelStatus[self::STATUS_BILLED] = $langs->transnoentitiesnoconv('StatusInterInvoiced');
875 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Done');
876 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
877 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
878 $this->labelStatusShort[self::STATUS_BILLED] = $langs->transnoentitiesnoconv('StatusInterInvoiced');
879 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Done');
880 }
881
882 $statuscode = 'status'.$status;
883 if ($status == self::STATUS_BILLED || $status == self::STATUS_CLOSED) {
884 $statuscode = 'status6';
885 }
886
887 $signed_label = ' (' . $this->getLibSignedStatus() . ')';
888 $status_label = $this->signed_status ? $this->labelStatus[$status] . $signed_label : $this->labelStatus[$status];
889 $status_label_short = $this->signed_status ? $this->labelStatusShort[$status] . $signed_label : $this->labelStatusShort[$status];
890
891 return dolGetStatus($status_label, $status_label_short, '', $statuscode, $mode);
892 }
893
900 public function getTooltipContentArray($params)
901 {
902 global $langs;
903
904 $langs->load('interventions');
905
906 $datas = [];
907 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("ShowIntervention").'</u>';
908 $datas['picto'] .= ' '.$this->getLibStatut(5);
909 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
910
911 return $datas;
912 }
913
924 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $save_lastsearch_value = -1, $morecss = '')
925 {
926 global $conf, $langs, $hookmanager;
927
928 if (!empty($conf->dol_no_mouse_hover)) {
929 $notooltip = 1; // Force disable tooltips
930 }
931
932 $result = '';
933 $params = [
934 'id' => $this->id,
935 'objecttype' => $this->element,
936 'option' => $option,
937 ];
938 $classfortooltip = 'classfortooltip';
939 $dataparams = '';
940 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
941 $classfortooltip = 'classforajaxtooltip';
942 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
943 $label = '';
944 } else {
945 $label = implode($this->getTooltipContentArray($params));
946 }
947
948 $url = DOL_URL_ROOT.'/fichinter/card.php?id='.$this->id;
949
950 if ($option !== 'nolink') {
951 // Add param to save lastsearch_values or not
952 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
953 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
954 $add_save_lastsearch_values = 1;
955 }
956 if ($add_save_lastsearch_values) {
957 $url .= '&save_lastsearch_values=1';
958 }
959 }
960
961 $linkclose = '';
962 if (empty($notooltip)) {
963 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
964 $label = $langs->trans("ShowIntervention");
965 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
966 }
967 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
968 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
969 } else {
970 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
971 }
972
973 if ($option == 'nolink' || empty($url)) {
974 $linkstart = '<span';
975 } else {
976 $linkstart = '<a href="'.$url.'"';
977 }
978 $linkstart .= $linkclose.'>';
979 if ($option == 'nolink' || empty($url)) {
980 $linkend = '</span>';
981 } else {
982 $linkend = '</a>';
983 }
984
985 $result .= $linkstart;
986 if ($withpicto) {
987 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
988 }
989
990 if ($withpicto != 2) {
991 $result .= $this->ref;
992 }
993
994 $result .= $linkend;
995
996 global $action;
997 $hookmanager->initHooks(array('interventiondao'));
998 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
999 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1000 if ($reshook > 0) {
1001 $result = $hookmanager->resPrint;
1002 } else {
1003 $result .= $hookmanager->resPrint;
1004 }
1005
1006 return $result;
1007 }
1008
1009
1017 public function getNextNumRef($soc)
1018 {
1019 global $conf, $db, $langs;
1020 $langs->load("interventions");
1021
1022 if (getDolGlobalString('FICHEINTER_ADDON')) {
1023 $mybool = false;
1024
1025 $file = "mod_" . getDolGlobalString('FICHEINTER_ADDON').".php";
1026 $classname = "mod_" . getDolGlobalString('FICHEINTER_ADDON');
1027
1028 // Include file with class
1029 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1030
1031 foreach ($dirmodels as $reldir) {
1032 $dir = dol_buildpath($reldir."core/modules/fichinter/");
1033
1034 // Load file with numbering class (if found)
1035 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1036 }
1037
1038 if (!$mybool) {
1039 dol_print_error(null, "Failed to include file ".$file);
1040 return '';
1041 }
1042
1043 $obj = new $classname();
1044 '@phan-var-force ModeleNumRefFicheinter $obj';
1045 $numref = "";
1046 $numref = $obj->getNextValue($soc, $this);
1047
1048 if ($numref != "") {
1049 return $numref;
1050 } else {
1051 dol_print_error($db, "Fichinter::getNextNumRef ".$obj->error);
1052 return "";
1053 }
1054 } else {
1055 $langs->load("errors");
1056 print $langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined");
1057 return "";
1058 }
1059 }
1060
1067 public function info($id)
1068 {
1069 $sql = "SELECT f.rowid,";
1070 $sql .= " f.datec,";
1071 $sql .= " f.tms as date_modification,";
1072 $sql .= " f.date_valid as datev,";
1073 $sql .= " f.fk_user_author,";
1074 $sql .= " f.fk_user_modif as fk_user_modification,";
1075 $sql .= " f.fk_user_valid";
1076 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
1077 $sql .= " WHERE f.rowid = ".((int) $id);
1078
1079 $resql = $this->db->query($sql);
1080 if ($resql) {
1081 if ($this->db->num_rows($resql)) {
1082 $obj = $this->db->fetch_object($resql);
1083
1084 $this->id = $obj->rowid;
1085
1086 $this->date_creation = $this->db->jdate($obj->datec);
1087 $this->date_modification = $this->db->jdate($obj->date_modification);
1088 $this->date_validation = $this->db->jdate($obj->datev);
1089
1090 $this->user_creation_id = $obj->fk_user_author;
1091 $this->user_validation_id = $obj->fk_user_valid;
1092 $this->user_modification_id = $obj->fk_user_modification;
1093 }
1094 $this->db->free($resql);
1095 } else {
1096 dol_print_error($this->db);
1097 }
1098 }
1099
1107 public function delete(User $user, $notrigger = 0)
1108 {
1109 global $conf, $langs;
1110 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1111
1112 $error = 0;
1113
1114 $this->db->begin();
1115
1116 if (!$error && !$notrigger) {
1117 // Call trigger
1118 $result = $this->call_trigger('FICHINTER_DELETE', $user);
1119 if ($result < 0) {
1120 $error++;
1121 $this->db->rollback();
1122 return -1;
1123 }
1124 // End call triggers
1125 }
1126
1127 // Delete linked object
1128 if (!$error) {
1129 $res = $this->deleteObjectLinked();
1130 if ($res < 0) {
1131 $error++;
1132 }
1133 }
1134
1135 // Delete linked contacts
1136 if (!$error) {
1137 $res = $this->delete_linked_contact();
1138 if ($res < 0) {
1139 $this->error = 'ErrorFailToDeleteLinkedContact';
1140 $error++;
1141 }
1142 }
1143
1144 if (!$error) {
1145 $main = MAIN_DB_PREFIX.'fichinterdet';
1146 $ef = $main."_extrafields";
1147 $sql = "DELETE FROM ".$this->db->sanitize($ef)." WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main)." WHERE fk_fichinter = ".((int) $this->id).")";
1148
1149 $resql = $this->db->query($sql);
1150 if (!$resql) {
1151 $error++;
1152 }
1153 }
1154
1155 if (!$error) {
1156 $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet";
1157 $sql .= " WHERE fk_fichinter = ".((int) $this->id);
1158
1159 $resql = $this->db->query($sql);
1160 if (!$resql) {
1161 $error++;
1162 }
1163 }
1164
1165 if (!$error) {
1166 // Remove extrafields
1167 $res = $this->deleteExtraFields();
1168 if ($res < 0) {
1169 $error++;
1170 }
1171 }
1172
1173 if (!$error) {
1174 // Delete object
1175 $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter";
1176 $sql .= " WHERE rowid = ".((int) $this->id);
1177
1178 dol_syslog("Fichinter::delete", LOG_DEBUG);
1179 $resql = $this->db->query($sql);
1180 if (!$resql) {
1181 $error++;
1182 }
1183 }
1184
1185 if (!$error) {
1186 // Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive
1187 $this->deleteEcmFiles(0); // Deleting files physically is done later with the dol_delete_dir_recursive
1188 $this->deleteEcmFiles(1); // Deleting files physically is done later with the dol_delete_dir_recursive
1189
1190 // Remove directory with files
1191 $fichinterref = dol_sanitizeFileName($this->ref);
1192 if ($conf->ficheinter->dir_output) {
1193 $dir = $conf->ficheinter->dir_output."/".$fichinterref;
1194 $file = $conf->ficheinter->dir_output."/".$fichinterref."/".$fichinterref.".pdf";
1195 if (file_exists($file)) {
1196 dol_delete_preview($this);
1197
1198 if (!dol_delete_file($file, 0, 0, 0, $this)) { // For triggers
1199 $langs->load("errors");
1200 $this->error = $langs->trans("ErrorFailToDeleteFile", $file);
1201 return 0;
1202 }
1203 }
1204 if (file_exists($dir)) {
1205 if (!dol_delete_dir_recursive($dir)) {
1206 $langs->load("errors");
1207 $this->error = $langs->trans("ErrorFailToDeleteDir", $dir);
1208 return 0;
1209 }
1210 }
1211 }
1212 }
1213
1214 if (!$error) {
1215 $this->db->commit();
1216 return 1;
1217 } else {
1218 $this->db->rollback();
1219 return -1;
1220 }
1221 }
1222
1223 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1231 public function set_date_delivery($user, $delivery_date_receipt)
1232 {
1233 // phpcs:enable
1234 if ($user->hasRight('ficheinter', 'creer')) {
1235 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
1236 $sql .= " SET datei = '".$this->db->idate($delivery_date_receipt)."'";
1237 $sql .= " WHERE rowid = ".((int) $this->id);
1238 $sql .= " AND fk_statut = 0";
1239
1240 if ($this->db->query($sql)) {
1241 $this->date_delivery = $delivery_date_receipt;
1242 $this->delivery_date_receipt = $delivery_date_receipt;
1243 return 1;
1244 } else {
1245 $this->error = $this->db->error();
1246 dol_syslog("Fichinter::set_date_delivery Erreur SQL");
1247 return -1;
1248 }
1249 }
1250
1251 return 0;
1252 }
1253
1254 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1262 public function set_description($user, $description)
1263 {
1264 // phpcs:enable
1265 if ($user->hasRight('ficheinter', 'creer')) {
1266 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
1267 $sql .= " SET description = '".$this->db->escape($description)."',";
1268 $sql .= " fk_user_modif = ".((int) $user->id);
1269 $sql .= " WHERE rowid = ".((int) $this->id);
1270
1271 if ($this->db->query($sql)) {
1272 $this->description = $description;
1273 return 1;
1274 } else {
1275 $this->error = $this->db->error();
1276 dol_syslog("Fichinter::set_description Erreur SQL");
1277 return -1;
1278 }
1279 }
1280
1281 return 0;
1282 }
1283
1284
1285 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1293 public function set_contrat($user, $contractid)
1294 {
1295 // phpcs:enable
1296 if ($user->hasRight('ficheinter', 'creer')) {
1297 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
1298 $sql .= " SET fk_contrat = ".((int) $contractid);
1299 $sql .= " WHERE rowid = ".((int) $this->id);
1300
1301 if ($this->db->query($sql)) {
1302 $this->fk_contrat = $contractid;
1303 return 1;
1304 } else {
1305 $this->error = $this->db->error();
1306 return -1;
1307 }
1308 }
1309
1310 return -2;
1311 }
1312
1313
1314
1324 public function createFromClone(User $user, $socid = 0, $clone_contacts = false, $clone_notes = false)
1325 {
1326 global $hookmanager, $langs;
1327 $langs->load("errors");
1328
1329 $error = 0;
1330
1331 $this->db->begin();
1332
1333 // get extrafields so they will be clone
1334 foreach ($this->lines as $line) {
1335 $line->fetch_optionals();
1336 }
1337
1338 // Load source object
1339 $objFrom = clone $this;
1340
1341 // Change socid if needed
1342 if (!empty($socid) && $socid != $this->socid) {
1343 $objsoc = new Societe($this->db);
1344
1345 if ($objsoc->fetch($socid) > 0) {
1346 $this->socid = $objsoc->id;
1347 //$this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1348 //$this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1349 $this->fk_project = 0;
1350 $this->fk_delivery_address = 0;
1351 }
1352
1353 // TODO Change product price if multi-prices
1354 }
1355
1356 $this->id = 0;
1357 $this->ref = '';
1358 $this->status = self::STATUS_DRAFT;
1359 $this->statut = self::STATUS_DRAFT; // deprecated
1360
1361 // Clear fields
1362 $this->user_author_id = $user->id;
1363 $this->user_validation_id = 0;
1364 $this->date_creation = '';
1365 $this->date_validation = '';
1366
1367 $this->ref_client = '';
1368
1369 if (!$clone_notes) {
1370 $this->note_private = '';
1371 $this->note_public = '';
1372 }
1373
1374 // Create clone
1375 $this->context['createfromclone'] = 'createfromclone';
1376 $result = $this->create($user);
1377 if ($result < 0) {
1378 $error++;
1379 }
1380
1381 if (!$error) {
1382 // Add lines because it is not included into create function
1383 foreach ($this->lines as $line) {
1384 $this->addline($user, $this->id, $line->desc, $line->datei, $line->duration, $line->array_options);
1385 }
1386
1387 // Hook of thirdparty module
1388 if (is_object($hookmanager)) {
1389 $parameters = array('objFrom' => $objFrom);
1390 $action = '';
1391 $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1392 if ($reshook < 0) {
1393 $this->setErrorsFromObject($hookmanager);
1394 $error++;
1395 }
1396 }
1397 }
1398
1399 //Duplicate contact
1400 if ($clone_contacts) {
1401 foreach (array('internal', 'external') as $source) {
1402 $tab = $objFrom->liste_contact(-1, $source);
1403 if (is_array($tab) && count($tab) > 0) {
1404 foreach ($tab as $contacttoadd) {
1405 $retAddContact = $this->add_contact(
1406 $contacttoadd['id'],
1407 $contacttoadd['code'],
1408 $contacttoadd['source']
1409 );
1410 if ($this->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
1411 $this->error .= $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
1412 $error++;
1413 } elseif ($retAddContact < 0) {
1414 $error++;
1415 }
1416 }
1417 } elseif ($tab < 0) {
1418 $this->error .= $objFrom->error;
1419 $error++;
1420 }
1421 }
1422 }
1423
1424 unset($this->context['createfromclone']);
1425
1426 // End
1427 if (!$error) {
1428 $this->db->commit();
1429 return $this->id;
1430 } else {
1431 $this->db->rollback();
1432 return -1;
1433 }
1434 }
1435
1436
1448 public function addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options = [])
1449 {
1450 dol_syslog(get_class($this)."::addline $fichinterid, $desc, $date_intervention, $duration");
1451
1452 if ($this->status == self::STATUS_DRAFT) {
1453 $this->db->begin();
1454
1455 // Insertion ligne
1456 $line = new FichinterLigne($this->db);
1457
1458 $line->fk_fichinter = $fichinterid;
1459 $line->desc = $desc;
1460 $line->date = $date_intervention;
1461 $line->datei = $date_intervention; // For backward compatibility
1462 $line->duration = $duration;
1463
1464 if (is_array($array_options) && count($array_options) > 0) {
1465 $line->array_options = $array_options;
1466 }
1467
1468 $result = $line->insert($user);
1469
1470 if ($result >= 0) {
1471 $this->db->commit();
1472 return $line->id;
1473 } else {
1474 $this->error = $this->db->error();
1475 $this->db->rollback();
1476 return -1;
1477 }
1478 }
1479
1480 return 0;
1481 }
1482
1483
1491 public function initAsSpecimen()
1492 {
1493 global $langs;
1494
1495 $now = dol_now();
1496
1497 // Initialise parameters
1498 $this->id = 0;
1499 $this->ref = 'SPECIMEN';
1500 $this->ref_client = 'SPECIMEN CLIENT';
1501 $this->specimen = 1;
1502 $this->socid = 1;
1503 $this->datec = $now;
1504 $this->note_private = 'Private note';
1505 $this->note_public = 'SPECIMEN';
1506 $this->duration = 0;
1507 $nbp = 25;
1508 $xnbp = 0;
1509 while ($xnbp < $nbp) {
1510 $line = new FichinterLigne($this->db);
1511 $line->desc = $langs->trans("Description")." ".$xnbp;
1512 $line->date = ($now - 3600 * (1 + $xnbp));
1513 $line->datei = ($now - 3600 * (1 + $xnbp)); // For backward compatibility
1514 $line->duration = 600;
1515 $line->fk_fichinter = 0;
1516 $this->lines[$xnbp] = $line;
1517 $xnbp++;
1518
1519 $this->duration += $line->duration;
1520 }
1521
1522 return 1;
1523 }
1524
1525 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1531 public function fetch_lines()
1532 {
1533 // phpcs:enable
1534 $this->lines = array();
1535
1536 $sql = "SELECT rowid, fk_fichinter, description, duree, date, rang, extraparams";
1537 $sql .= " FROM ".MAIN_DB_PREFIX."fichinterdet";
1538 $sql .= " WHERE fk_fichinter = ".((int) $this->id);
1539 $sql .= " ORDER BY rang ASC, date ASC";
1540
1541 dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
1542
1543 $resql = $this->db->query($sql);
1544 if ($resql) {
1545 $num = $this->db->num_rows($resql);
1546 $i = 0;
1547 while ($i < $num) {
1548 $objp = $this->db->fetch_object($resql);
1549
1550 $line = new FichinterLigne($this->db);
1551 $line->id = $objp->rowid;
1552 $line->fk_fichinter = $objp->fk_fichinter;
1553 $line->desc = $objp->description;
1554 $line->duration = $objp->duree;
1555 //For invoicing we calculing hours
1556 $line->qty = round($objp->duree / 3600, 2);
1557 $line->date = $this->db->jdate($objp->date);
1558 $line->datei = $this->db->jdate($objp->date); // For backward compatibility
1559 $line->rang = $objp->rang;
1560 $line->product_type = 1;
1561 $line->fetch_optionals();
1562
1563 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams, true) : array();
1564
1565 $this->lines[$i] = $line;
1566 $i++;
1567 }
1568 $this->db->free($resql);
1569
1570 return 1;
1571 } else {
1572 $this->error = $this->db->error();
1573 return -1;
1574 }
1575 }
1576
1585 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1586 {
1587 $tables = array(
1588 'fichinter'
1589 );
1590
1591 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1592 }
1593
1602 public function setRefClient($user, $ref_client, $notrigger = 0)
1603 {
1604 // phpcs:enable
1605 if ($user->hasRight('ficheinter', 'creer')) {
1606 $error = 0;
1607
1608 $this->db->begin();
1609
1610 $this->oldcopy = dol_clone($this, 2);
1611
1612 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ref_client = ".(empty($ref_client) ? 'NULL' : "'".$this->db->escape($ref_client)."'");
1613 $sql .= " WHERE rowid = ".((int) $this->id);
1614
1615 dol_syslog(__METHOD__.' $this->id='.$this->id.', ref_client='.$ref_client, LOG_DEBUG);
1616 $resql = $this->db->query($sql);
1617 if (!$resql) {
1618 $this->errors[] = $this->db->error();
1619 $error++;
1620 }
1621
1622 if (!$error) {
1623 $this->ref_client = $ref_client;
1624 }
1625
1626 if (!$notrigger && empty($error)) {
1627 // Call trigger
1628 $result = $this->call_trigger('FICHINTER_MODIFY', $user);
1629 if ($result < 0) {
1630 $error++;
1631 }
1632 // End call triggers
1633 }
1634
1635 if (!$error) {
1636 $this->db->commit();
1637 return 1;
1638 } else {
1639 foreach ($this->errors as $errmsg) {
1640 dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
1641 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1642 }
1643 $this->db->rollback();
1644 return -1 * $error;
1645 }
1646 } else {
1647 return -1;
1648 }
1649 }
1650
1658 public function getKanbanView($option = '', $arraydata = null)
1659 {
1660 global $langs;
1661
1662 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1663
1664 $return = '<div class="box-flex-item box-flex-grow-zero">';
1665 $return .= '<div class="info-box info-box-sm">';
1666 $return .= '<span class="info-box-icon bg-infobox-action">';
1667 $return .= img_picto('', $this->picto);
1668 $return .= '</span>';
1669 $return .= '<div class="info-box-content">';
1670 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1671 if ($selected >= 0) {
1672 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1673 }
1674 if (!empty($arraydata['thirdparty'])) {
1675 $tmpthirdparty = $arraydata['thirdparty'];
1676 '@phan-var-force Societe $tmpthirdparty';
1677 $return .= '<br><span class="info-box-label">'.$tmpthirdparty->getNomUrl(1).'</span>';
1678 }
1679 if (property_exists($this, 'duration')) {
1680 $return .= '<br><span class="info-box-label ">'.$langs->trans("Duration").' : '.convertSecondToTime($this->duration, 'allhourmin').'</span>';
1681 }
1682 if (method_exists($this, 'getLibStatut')) {
1683 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1684 }
1685 $return .= '</div>';
1686 $return .= '</div>';
1687 $return .= '</div>';
1688 return $return;
1689 }
1690}
$object ref
Definition info.php:90
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteEcmFiles($mode=0)
Delete related files of object in database.
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
static isExistingObject($element, $id, $ref='', $ref_ext='')
Check if an object id or ref exists If you don't need or want to instantiate the object and just need...
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts in llx_element_contact.
call_trigger($triggerName, $user)
Call trigger based on this instance.
add_contact($fk_socpeople, $type_contact, $source='external', $notrigger=0)
Add a link between element $this->element and a contact.
Class to manage Dolibarr database access.
const STATUS_BILLED
Billed.
initAsSpecimen()
Initialise an instance with random values.
createFromClone(User $user, $socid=0, $clone_contacts=false, $clone_notes=false)
Load an object from its id and create a new one in database.
getLibStatut($mode=0)
Returns the label status.
update($user, $notrigger=0)
Update an intervention.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
setClose($user, $notrigger=0)
Close intervention.
const STATUS_DRAFT
Draft status.
create($user, $notrigger=0)
Create an intervention into data base.
set_description($user, $description)
Define the label of the intervention.
getTooltipContentArray($params)
getTooltipContentArray
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
set_date_delivery($user, $delivery_date_receipt)
Defines a delivery date of the receipt of intervention.
addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options=[])
Adding a line of intervention into data base.
const STATUS_VALIDATED
Validated status.
fetch($rowid, $ref='', $ref_ext='')
Fetch a intervention.
const STATUS_CLOSED
Closed.
setDraft($user)
Set status to draft.
getNextNumRef($soc)
Returns the next non used reference of intervention depending on the module numbering assets within F...
getAmount()
Returns amount based on user thm.
setRefClient($user, $ref_client, $notrigger=0)
Set customer reference number.
set_contrat($user, $contractid)
Link intervention to a contract.
LibStatut($status, $mode=0)
Returns the label of a status.
setValid($user, $notrigger=0)
Validate a intervention.
loadStateBoard()
Load indicators into this->nb for board.
getNomUrl($withpicto=0, $option='', $notooltip=0, $save_lastsearch_value=-1, $morecss='')
Return clickable name (with picto eventually)
__construct($db)
Constructor.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
info($id)
Load information on object.
fetch_lines()
Load array lines ->lines.
Class to manage intervention lines.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
getLibSignedStatus(int $mode=0)
Returns the label for signed status.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
Definition date.lib.php:244
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
dol_delete_preview($object)
Delete all preview files linked to object instance.
setEntity($currentobject)
Set entity id to use when to create an object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79