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