dolibarr 21.0.0-alpha
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-2024 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2023-2024 William Mead <william.mead@manchenumerique.fr>
11 * Copyright (C) 2024 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', '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' => 'Ref ext', '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
149 public $statut = 0; // 0=draft, 1=validated, 2=invoiced, 3=Terminate
150
154 public $description;
155
159 public $fk_contrat = 0;
160
164 public $fk_project = 0;
165
170 public $ref_client;
171
175 public $extraparams = array();
176
180 public $lines = array();
181
185 const STATUS_DRAFT = 0;
186
191
195 const STATUS_BILLED = 2;
196
200 const STATUS_CLOSED = 3;
201
206 public $date_delivery;
207
212 public $user_author_id;
213
214
220 public function __construct($db)
221 {
222 $this->db = $db;
223 }
224
230 public function loadStateBoard()
231 {
232 global $user;
233
234 $this->nb = array();
235 $clause = "WHERE";
236
237 $sql = "SELECT count(fi.rowid) as nb";
238 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as fi";
239 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON fi.fk_soc = s.rowid";
240 if (!$user->hasRight('societe', 'client', 'voir')) {
241 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
242 $sql .= " WHERE sc.fk_user = ".((int) $user->id);
243 $clause = "AND";
244 }
245 $sql .= " ".$clause." fi.entity IN (".getEntity('intervention').")";
246
247 $resql = $this->db->query($sql);
248 if ($resql) {
249 while ($obj = $this->db->fetch_object($resql)) {
250 $this->nb["interventions"] = $obj->nb;
251 }
252 $this->db->free($resql);
253 return 1;
254 } else {
255 dol_print_error($this->db);
256 $this->error = $this->db->error();
257 return -1;
258 }
259 }
260
268 public function create($user, $notrigger = 0)
269 {
270 global $conf, $langs;
271
272 $error = 0;
273
274 dol_syslog(get_class($this)."::create ref=".$this->ref);
275
276 // Check parameters
277 if (!empty($this->ref)) { // We check that ref is not already used
278 $result = self::isExistingObject($this->element, 0, $this->ref); // Check ref is not yet used
279 if ($result > 0) {
280 $this->error = 'ErrorRefAlreadyExists';
281 dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING);
282 $this->db->rollback();
283 return -1;
284 }
285 }
286 if (!is_numeric($this->duration)) {
287 $this->duration = 0;
288 }
289 if (isset($this->ref_client)) {
290 $this->ref_client = trim($this->ref_client);
291 }
292
293 if ($this->socid <= 0) {
294 $this->error = 'ErrorFicheinterCompanyDoesNotExist';
295 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
296 return -1;
297 }
298
299 $soc = new Societe($this->db);
300 $result = $soc->fetch($this->socid);
301
302 $now = dol_now();
303
304 $this->db->begin();
305
306 $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter (";
307 $sql .= "fk_soc";
308 $sql .= ", datec";
309 $sql .= ", ref";
310 $sql .= ", ref_client";
311 $sql .= ", entity";
312 $sql .= ", fk_user_author";
313 $sql .= ", fk_user_modif";
314 $sql .= ", description";
315 $sql .= ", model_pdf";
316 $sql .= ", fk_projet";
317 $sql .= ", fk_contrat";
318 $sql .= ", fk_statut";
319 $sql .= ", signed_status";
320 $sql .= ", note_private";
321 $sql .= ", note_public";
322 $sql .= ") ";
323 $sql .= " VALUES (";
324 $sql .= $this->socid;
325 $sql .= ", '".$this->db->idate($now)."'";
326 $sql .= ", '".$this->db->escape($this->ref)."'";
327 $sql .= ", ".($this->ref_client ? "'".$this->db->escape($this->ref_client)."'" : "null");
328 $sql .= ", ".((int) $conf->entity);
329 $sql .= ", ".((int) $user->id);
330 $sql .= ", ".((int) $user->id);
331 $sql .= ", ".($this->description ? "'".$this->db->escape($this->description)."'" : "null");
332 $sql .= ", '".$this->db->escape($this->model_pdf)."'";
333 $sql .= ", ".($this->fk_project ? ((int) $this->fk_project) : 0);
334 $sql .= ", ".($this->fk_contrat ? ((int) $this->fk_contrat) : 0);
335 $sql .= ", ".((int) $this->statut);
336 $sql .= ", ".($this->signed_status);
337 $sql .= ", ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
338 $sql .= ", ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
339 $sql .= ")";
340
341 dol_syslog(get_class($this)."::create", LOG_DEBUG);
342 $result = $this->db->query($sql);
343 if ($result) {
344 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."fichinter");
345
346 if ($this->id) {
347 $this->ref = '(PROV'.$this->id.')';
348 $sql = 'UPDATE '.MAIN_DB_PREFIX."fichinter SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".((int) $this->id);
349
350 dol_syslog(get_class($this)."::create", LOG_DEBUG);
351 $resql = $this->db->query($sql);
352 if (!$resql) {
353 $error++;
354 }
355 }
356
357 if (!$error) {
358 $result = $this->insertExtraFields();
359 if ($result < 0) {
360 $error++;
361 }
362 }
363
364 // Add linked object
365 if (!$error && $this->origin && $this->origin_id) {
366 $ret = $this->add_object_linked();
367 if (!$ret) {
368 dol_print_error($this->db);
369 }
370 }
371
372
373 if (!$error && !$notrigger) {
374 // Call trigger
375 $result = $this->call_trigger('FICHINTER_CREATE', $user);
376 if ($result < 0) {
377 $error++;
378 }
379 // End call triggers
380 }
381
382 if (!$error) {
383 $this->db->commit();
384 return $this->id;
385 } else {
386 $this->db->rollback();
387 $this->error = implode(',', $this->errors);
388 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
389 return -1;
390 }
391 } else {
392 $this->error = $this->db->error();
393 $this->db->rollback();
394 return -1;
395 }
396 }
397
405 public function update($user, $notrigger = 0)
406 {
407 global $conf;
408
409 if (!is_numeric($this->duration)) {
410 $this->duration = 0;
411 }
412 if (!dol_strlen((string) $this->fk_project)) {
413 $this->fk_project = 0;
414 }
415 if (isset($this->ref_client)) {
416 $this->ref_client = trim($this->ref_client);
417 }
418
419 $error = 0;
420
421 $this->db->begin();
422
423 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET ";
424 $sql .= "description = '".$this->db->escape($this->description)."'";
425 $sql .= ", duree = ".((int) $this->duration);
426 $sql .= ", ref_client = ".($this->ref_client ? "'".$this->db->escape($this->ref_client)."'" : "null");
427 $sql .= ", fk_projet = ".((int) $this->fk_project);
428 $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
429 $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
430 $sql .= ", fk_user_modif = ".((int) $user->id);
431 $sql .= " WHERE rowid = ".((int) $this->id);
432
433 dol_syslog(get_class($this)."::update", LOG_DEBUG);
434 if ($this->db->query($sql)) {
435 if (!$error) {
436 $result = $this->insertExtraFields();
437 if ($result < 0) {
438 $error++;
439 }
440 }
441
442 if (!$error && !$notrigger) {
443 // Call trigger
444 $result = $this->call_trigger('FICHINTER_MODIFY', $user);
445 if ($result < 0) {
446 $error++;
447 $this->db->rollback();
448 return -1;
449 }
450 // End call triggers
451 }
452
453 $this->db->commit();
454 return 1;
455 } else {
456 $this->error = $this->db->error();
457 $this->db->rollback();
458 return -1;
459 }
460 }
461
469 public function fetch($rowid, $ref = '')
470 {
471 $sql = "SELECT f.rowid, f.ref, f.ref_client, f.description, f.fk_soc, f.fk_statut as status, f.signed_status,";
472 $sql .= " f.datec, f.dateo, f.datee, f.datet, f.fk_user_author,";
473 $sql .= " f.date_valid as datev,";
474 $sql .= " f.tms as datem,";
475 $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";
476 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
477 if ($ref) {
478 $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
479 $sql .= " AND f.ref = '".$this->db->escape($ref)."'";
480 } else {
481 $sql .= " WHERE f.rowid = ".((int) $rowid);
482 }
483
484 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
485 $resql = $this->db->query($sql);
486 if ($resql) {
487 if ($this->db->num_rows($resql)) {
488 $obj = $this->db->fetch_object($resql);
489
490 $this->id = $obj->rowid;
491 $this->ref = $obj->ref;
492 $this->ref_client = $obj->ref_client;
493 $this->description = $obj->description;
494 $this->socid = $obj->fk_soc;
495 $this->status = $obj->status;
496 $this->statut = $obj->status; // deprecated
497 $this->signed_status = $obj->signed_status;
498 $this->duration = $obj->duree;
499 $this->datec = $this->db->jdate($obj->datec);
500 $this->dateo = $this->db->jdate($obj->dateo);
501 $this->datee = $this->db->jdate($obj->datee);
502 $this->datet = $this->db->jdate($obj->datet);
503 $this->datev = $this->db->jdate($obj->datev);
504 $this->datem = $this->db->jdate($obj->datem);
505 $this->fk_project = $obj->fk_project;
506 $this->note_public = $obj->note_public;
507 $this->note_private = $obj->note_private;
508 $this->model_pdf = $obj->model_pdf;
509 $this->fk_contrat = $obj->fk_contrat;
510 $this->entity = $obj->entity;
511
512 $this->user_creation_id = $obj->fk_user_author;
513
514 $this->extraparams = is_null($obj->extraparams) ? [] : (array) json_decode($obj->extraparams, true);
515
516 $this->last_main_doc = $obj->last_main_doc;
517
518 // Retrieve extrafields
519 $this->fetch_optionals();
520
521 /*
522 * Lines
523 */
524 $result = $this->fetch_lines();
525 if ($result < 0) {
526 return -3;
527 }
528 $this->db->free($resql);
529 return 1;
530 }
531
532 return 0;
533 } else {
534 $this->error = $this->db->lasterror();
535 return -1;
536 }
537 }
538
545 public function setDraft($user)
546 {
547 $error = 0;
548
549 // Protection
550 if ($this->statut <= self::STATUS_DRAFT) {
551 return 0;
552 }
553
554 dol_syslog(get_class($this)."::setDraft", LOG_DEBUG);
555
556 $this->oldcopy = dol_clone($this, 2);
557
558 $this->db->begin();
559
560 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
561 $sql .= " SET fk_statut = ".self::STATUS_DRAFT;
562 $sql .= " WHERE rowid = ".((int) $this->id);
563
564 $resql = $this->db->query($sql);
565 if ($resql) {
566 if (!$error) {
567 // Call trigger
568 $result = $this->call_trigger('FICHINTER_UNVALIDATE', $user);
569 if ($result < 0) {
570 $error++;
571 }
572 }
573
574 if (!$error) {
575 $this->statut = self::STATUS_DRAFT;
576 $this->db->commit();
577 return 1;
578 } else {
579 $this->db->rollback();
580 return -1;
581 }
582 } else {
583 $this->db->rollback();
584 $this->error = $this->db->lasterror();
585 return -1;
586 }
587 }
588
596 public function setValid($user, $notrigger = 0)
597 {
598 global $conf;
599 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
600
601 $error = 0;
602
603 if ($this->status != self::STATUS_VALIDATED) {
604 $this->db->begin();
605
606 $now = dol_now();
607
608 // Define new ref
609 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
610 $num = $this->getNextNumRef($this->thirdparty);
611 } else {
612 $num = $this->ref;
613 }
614 $this->newref = dol_sanitizeFileName($num);
615
616 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
617 $sql .= " SET fk_statut = 1";
618 $sql .= ", ref = '".$this->db->escape($num)."'";
619 $sql .= ", date_valid = '".$this->db->idate($now)."'";
620 $sql .= ", fk_user_valid = ".($user->id > 0 ? (int) $user->id : "null");
621 $sql .= " WHERE rowid = ".((int) $this->id);
622 $sql .= " AND entity = ".((int) $this->entity);
623
624 $sql .= " AND fk_statut = 0";
625
626 dol_syslog(get_class($this)."::setValid", LOG_DEBUG);
627 $resql = $this->db->query($sql);
628 if (!$resql) {
629 dol_print_error($this->db);
630 $error++;
631 }
632
633 if (!$error && !$notrigger) {
634 // Call trigger
635 $result = $this->call_trigger('FICHINTER_VALIDATE', $user);
636 if ($result < 0) {
637 $error++;
638 }
639 // End call triggers
640 }
641
642 if (!$error) {
643 $this->oldref = $this->ref;
644
645 // Rename directory if dir was a temporary ref
646 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
647 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
648
649 // Now we rename also files into index
650 $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)."'";
651 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'ficheinter/".$this->db->escape($this->ref)."' and entity = ".((int) $this->entity);
652 $resql = $this->db->query($sql);
653 if (!$resql) {
654 $error++;
655 $this->error = $this->db->lasterror();
656 }
657 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'ficheinter/".$this->db->escape($this->newref)."'";
658 $sql .= " WHERE filepath = 'ficheinter/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
659 $resql = $this->db->query($sql);
660 if (!$resql) {
661 $error++;
662 $this->error = $this->db->lasterror();
663 }
664
665 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
666 $oldref = dol_sanitizeFileName($this->ref);
667 $newref = dol_sanitizeFileName($num);
668 $dirsource = $conf->ficheinter->dir_output.'/'.$oldref;
669 $dirdest = $conf->ficheinter->dir_output.'/'.$newref;
670 if (!$error && file_exists($dirsource)) {
671 dol_syslog(get_class($this)."::setValid rename dir ".$dirsource." into ".$dirdest);
672
673 if (@rename($dirsource, $dirdest)) {
674 dol_syslog("Rename ok");
675 // Rename docs starting with $oldref with $newref
676 $listoffiles = dol_dir_list($conf->ficheinter->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
677 foreach ($listoffiles as $fileentry) {
678 $dirsource = $fileentry['name'];
679 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
680 $dirsource = $fileentry['path'].'/'.$dirsource;
681 $dirdest = $fileentry['path'].'/'.$dirdest;
682 @rename($dirsource, $dirdest);
683 }
684 }
685 }
686 }
687 }
688
689 // Set new ref and define current status
690 if (!$error) {
691 $this->ref = $num;
693 $this->statut = self::STATUS_VALIDATED; // deprecated
694 $this->date_validation = $now;
695 $this->db->commit();
696 return 1;
697 } else {
698 $this->db->rollback();
699 dol_syslog(get_class($this)."::setValid ".$this->error, LOG_ERR);
700 return -1;
701 }
702 }
703
704 return 0;
705 }
706
714 public function setClose($user, $notrigger = 0)
715 {
716 global $conf;
717
718 $error = 0;
719
720 if ($this->statut == self::STATUS_CLOSED) {
721 return 0;
722 } else {
723 $this->db->begin();
724
725 $now = dol_now();
726
727 $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element;
728 $sql .= ' SET fk_statut = ' . self::STATUS_CLOSED . ',';
729 $sql .= " datet = '" . $this->db->idate($now) . "',";
730 $sql .= " fk_user_modif = " . ((int) $user->id);
731 $sql .= " WHERE rowid = " . ((int) $this->id);
732 $sql .= " AND fk_statut > " . self::STATUS_DRAFT;
733 $sql .= " AND entity = " . ((int) $conf->entity);
734
735 if ($this->db->query($sql)) {
736 if (!$notrigger) {
737 // Call trigger
738 $result = $this->call_trigger('FICHINTER_CLOSE', $user);
739 if ($result < 0) {
740 $error++;
741 }
742 // End call triggers
743 }
744
745 if (!$error) {
746 $this->statut = self::STATUS_CLOSED;
747 $this->db->commit();
748 return 1;
749 } else {
750 $this->db->rollback();
751 return -1;
752 }
753 } else {
754 $this->error = $this->db->lasterror();
755 $this->db->rollback();
756 return -1;
757 }
758 }
759 }
760
766 public function getAmount()
767 {
768 $amount = 0;
769
770 $this->author = new User($this->db);
771 $this->author->fetch($this->user_creation_id);
772
773 $thm = $this->author->thm;
774
775 foreach ($this->lines as $line) {
776 $amount += ($line->duration / 60 / 60 * (float) $thm);
777 }
778
779 return (float) price2num($amount, 'MT');
780 }
781
782
794 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
795 {
796 global $conf;
797
798 $outputlangs->load("interventions");
799
800 if (!dol_strlen($modele)) {
801 $modele = 'soleil';
802
803 if (!empty($this->model_pdf)) {
804 $modele = $this->model_pdf;
805 } elseif (getDolGlobalString('FICHEINTER_ADDON_PDF')) {
806 $modele = getDolGlobalString('FICHEINTER_ADDON_PDF');
807 }
808 }
809
810 $modelpath = "core/modules/fichinter/doc/";
811
812 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
813 }
814
821 public function getLibStatut($mode = 0)
822 {
823 return $this->LibStatut((isset($this->statut) ? $this->statut : $this->status), $mode);
824 }
825
826 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
834 public function LibStatut($status, $mode = 0)
835 {
836 // phpcs:enable
837 global $langs;
838 // Init/load array of translation of status
839 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
840 $langs->load("interventions");
841 $langs->load("propal");
842
843 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
844 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
845 $this->labelStatus[self::STATUS_BILLED] = $langs->transnoentitiesnoconv('StatusInterInvoiced');
846 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Done');
847 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
848 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
849 $this->labelStatusShort[self::STATUS_BILLED] = $langs->transnoentitiesnoconv('StatusInterInvoiced');
850 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Done');
851 }
852
853 $statuscode = 'status'.$status;
854 if ($status == self::STATUS_BILLED || $status == self::STATUS_CLOSED) {
855 $statuscode = 'status6';
856 }
857
858 $signed_label = ' (' . $this->getLibSignedStatus() . ')';
859 $status_label = $this->signed_status ? $this->labelStatus[$status] . $signed_label : $this->labelStatus[$status];
860 $status_label_short = $this->signed_status ? $this->labelStatusShort[$status] . $signed_label : $this->labelStatusShort[$status];
861
862 return dolGetStatus($status_label, $status_label_short, '', $statuscode, $mode);
863 }
864
871 public function getTooltipContentArray($params)
872 {
873 global $langs;
874
875 $langs->load('interventions');
876
877 $datas = [];
878 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Intervention").'</u>';
879 if (isset($this->status)) {
880 $datas['picto'] .= ' '.$this->getLibStatut(5);
881 }
882 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
883
884 return $datas;
885 }
886
897 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $save_lastsearch_value = -1, $morecss = '')
898 {
899 global $conf, $langs, $hookmanager;
900
901 if (!empty($conf->dol_no_mouse_hover)) {
902 $notooltip = 1; // Force disable tooltips
903 }
904
905 $result = '';
906 $params = [
907 'id' => $this->id,
908 'objecttype' => $this->element,
909 'option' => $option,
910 ];
911 $classfortooltip = 'classfortooltip';
912 $dataparams = '';
913 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
914 $classfortooltip = 'classforajaxtooltip';
915 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
916 $label = '';
917 } else {
918 $label = implode($this->getTooltipContentArray($params));
919 }
920
921 $url = DOL_URL_ROOT.'/fichinter/card.php?id='.$this->id;
922
923 if ($option !== 'nolink') {
924 // Add param to save lastsearch_values or not
925 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
926 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
927 $add_save_lastsearch_values = 1;
928 }
929 if ($add_save_lastsearch_values) {
930 $url .= '&save_lastsearch_values=1';
931 }
932 }
933
934 $linkclose = '';
935 if (empty($notooltip)) {
936 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
937 $label = $langs->trans("ShowIntervention");
938 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
939 }
940 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
941 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
942 } else {
943 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
944 }
945
946 if ($option == 'nolink' || empty($url)) {
947 $linkstart = '<span';
948 } else {
949 $linkstart = '<a href="'.$url.'"';
950 }
951 $linkstart .= $linkclose.'>';
952 if ($option == 'nolink' || empty($url)) {
953 $linkend = '</span>';
954 } else {
955 $linkend = '</a>';
956 }
957
958 $result .= $linkstart;
959 if ($withpicto) {
960 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
961 }
962
963 if ($withpicto != 2) {
964 $result .= $this->ref;
965 }
966
967 $result .= $linkend;
968
969 global $action;
970 $hookmanager->initHooks(array('interventiondao'));
971 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
972 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
973 if ($reshook > 0) {
974 $result = $hookmanager->resPrint;
975 } else {
976 $result .= $hookmanager->resPrint;
977 }
978
979 return $result;
980 }
981
982
990 public function getNextNumRef($soc)
991 {
992 global $conf, $db, $langs;
993 $langs->load("interventions");
994
995 if (getDolGlobalString('FICHEINTER_ADDON')) {
996 $mybool = false;
997
998 $file = "mod_" . getDolGlobalString('FICHEINTER_ADDON').".php";
999 $classname = "mod_" . getDolGlobalString('FICHEINTER_ADDON');
1000
1001 // Include file with class
1002 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1003
1004 foreach ($dirmodels as $reldir) {
1005 $dir = dol_buildpath($reldir."core/modules/fichinter/");
1006
1007 // Load file with numbering class (if found)
1008 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1009 }
1010
1011 if (!$mybool) {
1012 dol_print_error(null, "Failed to include file ".$file);
1013 return '';
1014 }
1015
1016 $obj = new $classname();
1017 '@phan-var-force ModeleNumRefFicheinter $obj';
1018 $numref = "";
1019 $numref = $obj->getNextValue($soc, $this);
1020
1021 if ($numref != "") {
1022 return $numref;
1023 } else {
1024 dol_print_error($db, "Fichinter::getNextNumRef ".$obj->error);
1025 return "";
1026 }
1027 } else {
1028 $langs->load("errors");
1029 print $langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined");
1030 return "";
1031 }
1032 }
1033
1040 public function info($id)
1041 {
1042 $sql = "SELECT f.rowid,";
1043 $sql .= " f.datec,";
1044 $sql .= " f.tms as date_modification,";
1045 $sql .= " f.date_valid as datev,";
1046 $sql .= " f.fk_user_author,";
1047 $sql .= " f.fk_user_modif as fk_user_modification,";
1048 $sql .= " f.fk_user_valid";
1049 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
1050 $sql .= " WHERE f.rowid = ".((int) $id);
1051
1052 $resql = $this->db->query($sql);
1053 if ($resql) {
1054 if ($this->db->num_rows($resql)) {
1055 $obj = $this->db->fetch_object($resql);
1056
1057 $this->id = $obj->rowid;
1058
1059 $this->date_creation = $this->db->jdate($obj->datec);
1060 $this->date_modification = $this->db->jdate($obj->date_modification);
1061 $this->date_validation = $this->db->jdate($obj->datev);
1062
1063 $this->user_creation_id = $obj->fk_user_author;
1064 $this->user_validation_id = $obj->fk_user_valid;
1065 $this->user_modification_id = $obj->fk_user_modification;
1066 }
1067 $this->db->free($resql);
1068 } else {
1069 dol_print_error($this->db);
1070 }
1071 }
1072
1080 public function delete(User $user, $notrigger = 0)
1081 {
1082 global $conf, $langs;
1083 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1084
1085 $error = 0;
1086
1087 $this->db->begin();
1088
1089 if (!$error && !$notrigger) {
1090 // Call trigger
1091 $result = $this->call_trigger('FICHINTER_DELETE', $user);
1092 if ($result < 0) {
1093 $error++;
1094 $this->db->rollback();
1095 return -1;
1096 }
1097 // End call triggers
1098 }
1099
1100 // Delete linked object
1101 if (!$error) {
1102 $res = $this->deleteObjectLinked();
1103 if ($res < 0) {
1104 $error++;
1105 }
1106 }
1107
1108 // Delete linked contacts
1109 if (!$error) {
1110 $res = $this->delete_linked_contact();
1111 if ($res < 0) {
1112 $this->error = 'ErrorFailToDeleteLinkedContact';
1113 $error++;
1114 }
1115 }
1116
1117 if (!$error) {
1118 $main = MAIN_DB_PREFIX.'fichinterdet';
1119 $ef = $main."_extrafields";
1120 $sql = "DELETE FROM ".$this->db->sanitize($ef)." WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main)." WHERE fk_fichinter = ".((int) $this->id).")";
1121
1122 $resql = $this->db->query($sql);
1123 if (!$resql) {
1124 $error++;
1125 }
1126 }
1127
1128 if (!$error) {
1129 $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet";
1130 $sql .= " WHERE fk_fichinter = ".((int) $this->id);
1131
1132 $resql = $this->db->query($sql);
1133 if (!$resql) {
1134 $error++;
1135 }
1136 }
1137
1138 if (!$error) {
1139 // Remove extrafields
1140 $res = $this->deleteExtraFields();
1141 if ($res < 0) {
1142 $error++;
1143 }
1144 }
1145
1146 if (!$error) {
1147 // Delete object
1148 $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter";
1149 $sql .= " WHERE rowid = ".((int) $this->id);
1150
1151 dol_syslog("Fichinter::delete", LOG_DEBUG);
1152 $resql = $this->db->query($sql);
1153 if (!$resql) {
1154 $error++;
1155 }
1156 }
1157
1158 if (!$error) {
1159 // Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive
1160 $this->deleteEcmFiles(0); // Deleting files physically is done later with the dol_delete_dir_recursive
1161 $this->deleteEcmFiles(1); // Deleting files physically is done later with the dol_delete_dir_recursive
1162
1163 // Remove directory with files
1164 $fichinterref = dol_sanitizeFileName($this->ref);
1165 if ($conf->ficheinter->dir_output) {
1166 $dir = $conf->ficheinter->dir_output."/".$fichinterref;
1167 $file = $conf->ficheinter->dir_output."/".$fichinterref."/".$fichinterref.".pdf";
1168 if (file_exists($file)) {
1169 dol_delete_preview($this);
1170
1171 if (!dol_delete_file($file, 0, 0, 0, $this)) { // For triggers
1172 $langs->load("errors");
1173 $this->error = $langs->trans("ErrorFailToDeleteFile", $file);
1174 return 0;
1175 }
1176 }
1177 if (file_exists($dir)) {
1178 if (!dol_delete_dir_recursive($dir)) {
1179 $langs->load("errors");
1180 $this->error = $langs->trans("ErrorFailToDeleteDir", $dir);
1181 return 0;
1182 }
1183 }
1184 }
1185 }
1186
1187 if (!$error) {
1188 $this->db->commit();
1189 return 1;
1190 } else {
1191 $this->db->rollback();
1192 return -1;
1193 }
1194 }
1195
1196 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1204 public function set_date_delivery($user, $date_delivery)
1205 {
1206 // phpcs:enable
1207 if ($user->hasRight('ficheinter', 'creer')) {
1208 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
1209 $sql .= " SET datei = '".$this->db->idate($date_delivery)."'";
1210 $sql .= " WHERE rowid = ".((int) $this->id);
1211 $sql .= " AND fk_statut = 0";
1212
1213 if ($this->db->query($sql)) {
1214 $this->date_delivery = $date_delivery;
1215 return 1;
1216 } else {
1217 $this->error = $this->db->error();
1218 dol_syslog("Fichinter::set_date_delivery Erreur SQL");
1219 return -1;
1220 }
1221 }
1222
1223 return 0;
1224 }
1225
1226 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1234 public function set_description($user, $description)
1235 {
1236 // phpcs:enable
1237 if ($user->hasRight('ficheinter', 'creer')) {
1238 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
1239 $sql .= " SET description = '".$this->db->escape($description)."',";
1240 $sql .= " fk_user_modif = ".((int) $user->id);
1241 $sql .= " WHERE rowid = ".((int) $this->id);
1242
1243 if ($this->db->query($sql)) {
1244 $this->description = $description;
1245 return 1;
1246 } else {
1247 $this->error = $this->db->error();
1248 dol_syslog("Fichinter::set_description Erreur SQL");
1249 return -1;
1250 }
1251 }
1252
1253 return 0;
1254 }
1255
1256
1257 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1265 public function set_contrat($user, $contractid)
1266 {
1267 // phpcs:enable
1268 if ($user->hasRight('ficheinter', 'creer')) {
1269 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
1270 $sql .= " SET fk_contrat = ".((int) $contractid);
1271 $sql .= " WHERE rowid = ".((int) $this->id);
1272
1273 if ($this->db->query($sql)) {
1274 $this->fk_contrat = $contractid;
1275 return 1;
1276 } else {
1277 $this->error = $this->db->error();
1278 return -1;
1279 }
1280 }
1281
1282 return -2;
1283 }
1284
1285
1286
1294 public function createFromClone(User $user, $socid = 0)
1295 {
1296 global $hookmanager;
1297
1298 $error = 0;
1299
1300 $this->db->begin();
1301
1302 // get extrafields so they will be clone
1303 foreach ($this->lines as $line) {
1304 $line->fetch_optionals();
1305 }
1306
1307 // Load source object
1308 $objFrom = clone $this;
1309
1310 // Change socid if needed
1311 if (!empty($socid) && $socid != $this->socid) {
1312 $objsoc = new Societe($this->db);
1313
1314 if ($objsoc->fetch($socid) > 0) {
1315 $this->socid = $objsoc->id;
1316 //$this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1317 //$this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1318 $this->fk_project = 0;
1319 $this->fk_delivery_address = 0;
1320 }
1321
1322 // TODO Change product price if multi-prices
1323 }
1324
1325 $this->id = 0;
1326 $this->ref = '';
1327 $this->status = self::STATUS_DRAFT;
1328 $this->statut = self::STATUS_DRAFT; // deprecated
1329
1330 // Clear fields
1331 $this->user_author_id = $user->id;
1332 $this->user_validation_id = 0;
1333 $this->date_creation = '';
1334 $this->date_validation = '';
1335
1336 $this->ref_client = '';
1337
1338 // Create clone
1339 $this->context['createfromclone'] = 'createfromclone';
1340 $result = $this->create($user);
1341 if ($result < 0) {
1342 $error++;
1343 }
1344
1345 if (!$error) {
1346 // Add lines because it is not included into create function
1347 foreach ($this->lines as $line) {
1348 $this->addline($user, $this->id, $line->desc, $line->datei, $line->duration, $line->array_options);
1349 }
1350
1351 // Hook of thirdparty module
1352 if (is_object($hookmanager)) {
1353 $parameters = array('objFrom' => $objFrom);
1354 $action = '';
1355 $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1356 if ($reshook < 0) {
1357 $this->setErrorsFromObject($hookmanager);
1358 $error++;
1359 }
1360 }
1361 }
1362
1363 unset($this->context['createfromclone']);
1364
1365 // End
1366 if (!$error) {
1367 $this->db->commit();
1368 return $this->id;
1369 } else {
1370 $this->db->rollback();
1371 return -1;
1372 }
1373 }
1374
1375
1387 public function addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options = [])
1388 {
1389 dol_syslog(get_class($this)."::addline $fichinterid, $desc, $date_intervention, $duration");
1390
1391 if ($this->status == self::STATUS_DRAFT) {
1392 $this->db->begin();
1393
1394 // Insertion ligne
1395 $line = new FichinterLigne($this->db);
1396
1397 $line->fk_fichinter = $fichinterid;
1398 $line->desc = $desc;
1399 $line->date = $date_intervention;
1400 $line->datei = $date_intervention; // For backward compatibility
1401 $line->duration = $duration;
1402
1403 if (is_array($array_options) && count($array_options) > 0) {
1404 $line->array_options = $array_options;
1405 }
1406
1407 $result = $line->insert($user);
1408
1409 if ($result >= 0) {
1410 $this->db->commit();
1411 return 1;
1412 } else {
1413 $this->error = $this->db->error();
1414 $this->db->rollback();
1415 return -1;
1416 }
1417 }
1418
1419 return 0;
1420 }
1421
1422
1430 public function initAsSpecimen()
1431 {
1432 global $langs;
1433
1434 $now = dol_now();
1435
1436 // Initialise parameters
1437 $this->id = 0;
1438 $this->ref = 'SPECIMEN';
1439 $this->ref_client = 'SPECIMEN CLIENT';
1440 $this->specimen = 1;
1441 $this->socid = 1;
1442 $this->datec = $now;
1443 $this->note_private = 'Private note';
1444 $this->note_public = 'SPECIMEN';
1445 $this->duration = 0;
1446 $nbp = 25;
1447 $xnbp = 0;
1448 while ($xnbp < $nbp) {
1449 $line = new FichinterLigne($this->db);
1450 $line->desc = $langs->trans("Description")." ".$xnbp;
1451 $line->date = ($now - 3600 * (1 + $xnbp));
1452 $line->datei = ($now - 3600 * (1 + $xnbp)); // For backward compatibility
1453 $line->duration = 600;
1454 $line->fk_fichinter = 0;
1455 $this->lines[$xnbp] = $line;
1456 $xnbp++;
1457
1458 $this->duration += $line->duration;
1459 }
1460
1461 return 1;
1462 }
1463
1464 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1470 public function fetch_lines()
1471 {
1472 // phpcs:enable
1473 $this->lines = array();
1474
1475 $sql = "SELECT rowid, fk_fichinter, description, duree, date, rang";
1476 $sql .= " FROM ".MAIN_DB_PREFIX."fichinterdet";
1477 $sql .= " WHERE fk_fichinter = ".((int) $this->id);
1478 $sql .= " ORDER BY rang ASC, date ASC";
1479
1480 dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
1481
1482 $resql = $this->db->query($sql);
1483 if ($resql) {
1484 $num = $this->db->num_rows($resql);
1485 $i = 0;
1486 while ($i < $num) {
1487 $objp = $this->db->fetch_object($resql);
1488
1489 $line = new FichinterLigne($this->db);
1490 $line->id = $objp->rowid;
1491 $line->fk_fichinter = $objp->fk_fichinter;
1492 $line->desc = $objp->description;
1493 $line->duration = $objp->duree;
1494 //For invoicing we calculing hours
1495 $line->qty = round($objp->duree / 3600, 2);
1496 $line->date = $this->db->jdate($objp->date);
1497 $line->datei = $this->db->jdate($objp->date); // For backward compatibility
1498 $line->rang = $objp->rang;
1499 $line->product_type = 1;
1500 $line->fetch_optionals();
1501
1502 $this->lines[$i] = $line;
1503 $i++;
1504 }
1505 $this->db->free($resql);
1506
1507 return 1;
1508 } else {
1509 $this->error = $this->db->error();
1510 return -1;
1511 }
1512 }
1513
1522 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1523 {
1524 $tables = array(
1525 'fichinter'
1526 );
1527
1528 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1529 }
1530
1539 public function setRefClient($user, $ref_client, $notrigger = 0)
1540 {
1541 // phpcs:enable
1542 if ($user->hasRight('ficheinter', 'creer')) {
1543 $error = 0;
1544
1545 $this->db->begin();
1546
1547 $this->oldcopy = dol_clone($this, 2);
1548
1549 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ref_client = ".(empty($ref_client) ? 'NULL' : "'".$this->db->escape($ref_client)."'");
1550 $sql .= " WHERE rowid = ".((int) $this->id);
1551
1552 dol_syslog(__METHOD__.' $this->id='.$this->id.', ref_client='.$ref_client, LOG_DEBUG);
1553 $resql = $this->db->query($sql);
1554 if (!$resql) {
1555 $this->errors[] = $this->db->error();
1556 $error++;
1557 }
1558
1559 if (!$error) {
1560 $this->ref_client = $ref_client;
1561 }
1562
1563 if (!$notrigger && empty($error)) {
1564 // Call trigger
1565 $result = $this->call_trigger('FICHINTER_MODIFY', $user);
1566 if ($result < 0) {
1567 $error++;
1568 }
1569 // End call triggers
1570 }
1571
1572 if (!$error) {
1573 $this->db->commit();
1574 return 1;
1575 } else {
1576 foreach ($this->errors as $errmsg) {
1577 dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
1578 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1579 }
1580 $this->db->rollback();
1581 return -1 * $error;
1582 }
1583 } else {
1584 return -1;
1585 }
1586 }
1587
1595 public function getKanbanView($option = '', $arraydata = null)
1596 {
1597 global $langs;
1598
1599 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1600
1601 $return = '<div class="box-flex-item box-flex-grow-zero">';
1602 $return .= '<div class="info-box info-box-sm">';
1603 $return .= '<span class="info-box-icon bg-infobox-action">';
1604 $return .= img_picto('', $this->picto);
1605 $return .= '</span>';
1606 $return .= '<div class="info-box-content">';
1607 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1608 if ($selected >= 0) {
1609 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1610 }
1611 if (!empty($arraydata['thirdparty'])) {
1612 $tmpthirdparty = $arraydata['thirdparty'];
1613 '@phan-var-force Societe $tmpthirdparty';
1614 $return .= '<br><span class="info-box-label">'.$tmpthirdparty->getNomUrl(1).'</span>';
1615 }
1616 if (property_exists($this, 'duration')) {
1617 $return .= '<br><span class="info-box-label ">'.$langs->trans("Duration").' : '.convertSecondToTime($this->duration, 'allhourmin').'</span>';
1618 }
1619 if (method_exists($this, 'getLibStatut')) {
1620 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1621 }
1622 $return .= '</div>';
1623 $return .= '</div>';
1624 $return .= '</div>';
1625 return $return;
1626 }
1627}
$object ref
Definition info.php:79
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.
Class to manage Dolibarr database access.
const STATUS_BILLED
Billed.
initAsSpecimen()
Initialise an instance with random values.
getLibStatut($mode=0)
Returns the label status.
update($user, $notrigger=0)
Update an intervention.
createFromClone(User $user, $socid=0)
Load an object from its id and create a new one in database.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
setClose($user, $notrigger=0)
Close intervention.
set_date_delivery($user, $date_delivery)
Defines a delivery date of 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)
addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options=[])
Adding a line of intervention into data base.
const STATUS_VALIDATED
Validated status.
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.
fetch($rowid, $ref='')
Fetch a intervention.
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:162
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:242
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_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
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_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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
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 '.
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.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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...
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.