dolibarr  13.0.2
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-2020 Frédéric France <frederic.france@netlogic.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
30 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
32 
33 
37 class Fichinter extends CommonObject
38 {
39 
40  public $fields = array(
41  'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
42  'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>15),
43  'fk_projet' =>array('type'=>'integer:Project:projet/class/project.class.php:1:fk_statut=1', 'label'=>'Fk projet', 'enabled'=>1, 'visible'=>-1, 'position'=>20),
44  'fk_contrat' =>array('type'=>'integer', 'label'=>'Fk contrat', 'enabled'=>1, 'visible'=>-1, 'position'=>25),
45  'ref' =>array('type'=>'varchar(30)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'showoncombobox'=>1, 'position'=>30),
46  'ref_ext' =>array('type'=>'varchar(255)', 'label'=>'Ref ext', 'enabled'=>1, 'visible'=>0, 'position'=>35),
47  'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>40, 'index'=>1),
48  'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>45),
49  'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>50),
50  'date_valid' =>array('type'=>'datetime', 'label'=>'DateValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>55),
51  'datei' =>array('type'=>'date', 'label'=>'Datei', 'enabled'=>1, 'visible'=>-1, 'position'=>60),
52  'fk_user_author' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-1, 'position'=>65),
53  'fk_user_modif' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>70),
54  'fk_user_valid' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>75),
55  'fk_statut' =>array('type'=>'smallint(6)', 'label'=>'Fk statut', 'enabled'=>1, 'visible'=>-1, 'position'=>500),
56  'dateo' =>array('type'=>'date', 'label'=>'Dateo', 'enabled'=>1, 'visible'=>-1, 'position'=>85),
57  'datee' =>array('type'=>'date', 'label'=>'Datee', 'enabled'=>1, 'visible'=>-1, 'position'=>90),
58  'datet' =>array('type'=>'date', 'label'=>'Datet', 'enabled'=>1, 'visible'=>-1, 'position'=>95),
59  'duree' =>array('type'=>'double', 'label'=>'Duree', 'enabled'=>1, 'visible'=>-1, 'position'=>100),
60  'description' =>array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>-1, 'position'=>105, 'showoncombobox'=>1),
61  'note_private' =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>110),
62  'note_public' =>array('type'=>'text', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>115),
63  'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>1, 'visible'=>0, 'position'=>120),
64  'last_main_doc' =>array('type'=>'varchar(255)', 'label'=>'Last main doc', 'enabled'=>1, 'visible'=>-1, 'position'=>125),
65  'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>130),
66  'extraparams' =>array('type'=>'varchar(255)', 'label'=>'Extraparams', 'enabled'=>1, 'visible'=>-1, 'position'=>135),
67  );
71  public $element = 'fichinter';
72 
76  public $table_element = 'fichinter';
77 
81  public $fk_element = 'fk_fichinter';
82 
86  public $table_element_line = 'fichinterdet';
87 
91  public $picto = 'intervention';
92 
96  protected $table_ref_field = 'ref';
97 
101  public $socid;
102 
103  public $author;
104 
110  public $datec;
111 
112  public $datev;
113  public $dateo;
114  public $datee;
115  public $datet;
116 
122  public $datem;
123 
127  public $duration;
128 
132  public $statut = 0; // 0=draft, 1=validated, 2=invoiced, 3=Terminate
133 
137  public $description;
138 
142  public $fk_contrat = 0;
143 
147  public $fk_project = 0;
148 
152  public $extraparams = array();
153 
157  public $lines = array();
158 
162  const STATUS_DRAFT = 0;
163 
167  const STATUS_VALIDATED = 1;
168 
172  const STATUS_BILLED = 2;
173 
177  const STATUS_CLOSED = 3;
178 
179 
185  public function __construct($db)
186  {
187  $this->db = $db;
188  }
189 
190  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
196  public function load_state_board()
197  {
198  // phpcs:enable
199  global $user;
200 
201  $this->nb = array();
202  $clause = "WHERE";
203 
204  $sql = "SELECT count(fi.rowid) as nb";
205  $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as fi";
206  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON fi.fk_soc = s.rowid";
207  if (!$user->rights->societe->client->voir && !$user->socid)
208  {
209  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
210  $sql .= " WHERE sc.fk_user = ".$user->id;
211  $clause = "AND";
212  }
213  $sql .= " ".$clause." fi.entity IN (".getEntity('intervention').")";
214 
215  $resql = $this->db->query($sql);
216  if ($resql)
217  {
218  while ($obj = $this->db->fetch_object($resql))
219  {
220  $this->nb["interventions"] = $obj->nb;
221  }
222  $this->db->free($resql);
223  return 1;
224  } else {
225  dol_print_error($this->db);
226  $this->error = $this->db->error();
227  return -1;
228  }
229  }
230 
238  public function create($user, $notrigger = 0)
239  {
240  global $conf, $langs;
241 
242  $error = 0;
243 
244  dol_syslog(get_class($this)."::create ref=".$this->ref);
245 
246  // Check parameters
247  if (!empty($this->ref)) // We check that ref is not already used
248  {
249  $result = self::isExistingObject($this->element, 0, $this->ref); // Check ref is not yet used
250  if ($result > 0)
251  {
252  $this->error = 'ErrorRefAlreadyExists';
253  dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING);
254  $this->db->rollback();
255  return -1;
256  }
257  }
258  if (!is_numeric($this->duration)) $this->duration = 0;
259 
260  if ($this->socid <= 0)
261  {
262  $this->error = 'ErrorBadParameterForFunc';
263  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
264  return -1;
265  }
266 
267  $soc = new Societe($this->db);
268  $result = $soc->fetch($this->socid);
269 
270  $now = dol_now();
271 
272  $this->db->begin();
273 
274  $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter (";
275  $sql .= "fk_soc";
276  $sql .= ", datec";
277  $sql .= ", ref";
278  $sql .= ", entity";
279  $sql .= ", fk_user_author";
280  $sql .= ", fk_user_modif";
281  $sql .= ", description";
282  $sql .= ", model_pdf";
283  $sql .= ", fk_projet";
284  $sql .= ", fk_contrat";
285  $sql .= ", fk_statut";
286  $sql .= ", note_private";
287  $sql .= ", note_public";
288  $sql .= ") ";
289  $sql .= " VALUES (";
290  $sql .= $this->socid;
291  $sql .= ", '".$this->db->idate($now)."'";
292  $sql .= ", '".$this->db->escape($this->ref)."'";
293  $sql .= ", ".$conf->entity;
294  $sql .= ", ".$user->id;
295  $sql .= ", ".$user->id;
296  $sql .= ", ".($this->description ? "'".$this->db->escape($this->description)."'" : "null");
297  $sql .= ", '".$this->db->escape($this->model_pdf)."'";
298  $sql .= ", ".($this->fk_project ? $this->fk_project : 0);
299  $sql .= ", ".($this->fk_contrat ? $this->fk_contrat : 0);
300  $sql .= ", ".$this->statut;
301  $sql .= ", ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
302  $sql .= ", ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
303  $sql .= ")";
304 
305  dol_syslog(get_class($this)."::create", LOG_DEBUG);
306  $result = $this->db->query($sql);
307  if ($result)
308  {
309  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."fichinter");
310 
311  if ($this->id)
312  {
313  $this->ref = '(PROV'.$this->id.')';
314  $sql = 'UPDATE '.MAIN_DB_PREFIX."fichinter SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".$this->id;
315 
316  dol_syslog(get_class($this)."::create", LOG_DEBUG);
317  $resql = $this->db->query($sql);
318  if (!$resql) $error++;
319  }
320 
321  if (!$error)
322  {
323  $result = $this->insertExtraFields();
324  if ($result < 0)
325  {
326  $error++;
327  }
328  }
329 
330  // Add linked object
331  if (!$error && $this->origin && $this->origin_id)
332  {
333  $ret = $this->add_object_linked();
334  if (!$ret) dol_print_error($this->db);
335  }
336 
337 
338  if (!$error && !$notrigger)
339  {
340  // Call trigger
341  $result = $this->call_trigger('FICHINTER_CREATE', $user);
342  if ($result < 0) { $error++; }
343  // End call triggers
344  }
345 
346  if (!$error) {
347  $this->db->commit();
348  return $this->id;
349  } else {
350  $this->db->rollback();
351  $this->error = join(',', $this->errors);
352  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
353  return -1;
354  }
355  } else {
356  $this->error = $this->db->error();
357  $this->db->rollback();
358  return -1;
359  }
360  }
361 
369  public function update($user, $notrigger = 0)
370  {
371  global $conf;
372 
373  if (!is_numeric($this->duration)) {
374  $this->duration = 0;
375  }
376  if (!dol_strlen($this->fk_project)) {
377  $this->fk_project = 0;
378  }
379 
380  $error = 0;
381 
382  $this->db->begin();
383 
384  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET ";
385  $sql .= "description = '".$this->db->escape($this->description)."'";
386  $sql .= ", duree = ".$this->duration;
387  $sql .= ", fk_projet = ".$this->fk_project;
388  $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
389  $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
390  $sql .= ", fk_user_modif = ".$user->id;
391  $sql .= " WHERE rowid = ".$this->id;
392 
393  dol_syslog(get_class($this)."::update", LOG_DEBUG);
394  if ($this->db->query($sql))
395  {
396  if (!$error)
397  {
398  $result = $this->insertExtraFields();
399  if ($result < 0)
400  {
401  $error++;
402  }
403  }
404 
405  if (!$error && !$notrigger)
406  {
407  // Call trigger
408  $result = $this->call_trigger('FICHINTER_MODIFY', $user);
409  if ($result < 0) { $error++; $this->db->rollback(); return -1; }
410  // End call triggers
411  }
412 
413  $this->db->commit();
414  return 1;
415  } else {
416  $this->error = $this->db->error();
417  $this->db->rollback();
418  return -1;
419  }
420  }
421 
429  public function fetch($rowid, $ref = '')
430  {
431  $sql = "SELECT f.rowid, f.ref, f.description, f.fk_soc, f.fk_statut,";
432  $sql .= " f.datec, f.dateo, f.datee, f.datet, f.fk_user_author,";
433  $sql .= " f.date_valid as datev,";
434  $sql .= " f.tms as datem,";
435  $sql .= " f.duree, f.fk_projet as fk_project, f.note_public, f.note_private, f.model_pdf, f.extraparams, fk_contrat";
436  $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
437  if ($ref) {
438  $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
439  $sql .= " AND f.ref='".$this->db->escape($ref)."'";
440  } else $sql .= " WHERE f.rowid=".$rowid;
441 
442  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
443  $resql = $this->db->query($sql);
444  if ($resql)
445  {
446  if ($this->db->num_rows($resql))
447  {
448  $obj = $this->db->fetch_object($resql);
449 
450  $this->id = $obj->rowid;
451  $this->ref = $obj->ref;
452  $this->description = $obj->description;
453  $this->socid = $obj->fk_soc;
454  $this->statut = $obj->fk_statut;
455  $this->duration = $obj->duree;
456  $this->datec = $this->db->jdate($obj->datec);
457  $this->dateo = $this->db->jdate($obj->dateo);
458  $this->datee = $this->db->jdate($obj->datee);
459  $this->datet = $this->db->jdate($obj->datet);
460  $this->datev = $this->db->jdate($obj->datev);
461  $this->datem = $this->db->jdate($obj->datem);
462  $this->fk_project = $obj->fk_project;
463  $this->note_public = $obj->note_public;
464  $this->note_private = $obj->note_private;
465  $this->model_pdf = $obj->model_pdf;
466  $this->modelpdf = $obj->model_pdf; // deprecated
467  $this->fk_contrat = $obj->fk_contrat;
468 
469  $this->user_creation = $obj->fk_user_author;
470 
471  $this->extraparams = (array) json_decode($obj->extraparams, true);
472 
473  if ($this->statut == 0) $this->brouillon = 1;
474 
475  // Retrieve extrafields
476  $this->fetch_optionals();
477 
478  /*
479  * Lines
480  */
481  $result = $this->fetch_lines();
482  if ($result < 0)
483  {
484  return -3;
485  }
486  $this->db->free($resql);
487  return 1;
488  }
489  } else {
490  $this->error = $this->db->lasterror();
491  return -1;
492  }
493  }
494 
501  public function setDraft($user)
502  {
503  global $langs, $conf;
504 
505  $error = 0;
506 
507  // Protection
508  if ($this->statut <= self::STATUS_DRAFT)
509  {
510  return 0;
511  }
512 
513  dol_syslog(get_class($this)."::setDraft", LOG_DEBUG);
514 
515  $this->db->begin();
516 
517  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
518  $sql .= " SET fk_statut = ".self::STATUS_DRAFT;
519  $sql .= " WHERE rowid = ".$this->id;
520 
521  $resql = $this->db->query($sql);
522  if ($resql)
523  {
524  if (!$error) {
525  $this->oldcopy = clone $this;
526  }
527 
528  if (!$error) {
529  // Call trigger
530  $result = $this->call_trigger('FICHINTER_UNVALIDATE', $user);
531  if ($result < 0) $error++;
532  }
533 
534  if (!$error) {
535  $this->statut = self::STATUS_DRAFT;
536  $this->db->commit();
537  return 1;
538  } else {
539  $this->db->rollback();
540  return -1;
541  }
542  } else {
543  $this->db->rollback();
544  $this->error = $this->db->lasterror();
545  return -1;
546  }
547  }
548 
556  public function setValid($user, $notrigger = 0)
557  {
558  global $conf;
559  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
560 
561  $error = 0;
562 
563  if ($this->statut != 1)
564  {
565  $this->db->begin();
566 
567  $now = dol_now();
568 
569  // Define new ref
570  if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
571  {
572  $num = $this->getNextNumRef($this->thirdparty);
573  } else {
574  $num = $this->ref;
575  }
576  $this->newref = dol_sanitizeFileName($num);
577 
578  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
579  $sql .= " SET fk_statut = 1";
580  $sql .= ", ref = '".$num."'";
581  $sql .= ", date_valid = '".$this->db->idate($now)."'";
582  $sql .= ", fk_user_valid = ".$user->id;
583  $sql .= " WHERE rowid = ".$this->id;
584  $sql .= " AND entity = ".$conf->entity;
585  $sql .= " AND fk_statut = 0";
586 
587  dol_syslog(get_class($this)."::setValid", LOG_DEBUG);
588  $resql = $this->db->query($sql);
589  if (!$resql)
590  {
591  dol_print_error($this->db);
592  $error++;
593  }
594 
595  if (!$error && !$notrigger)
596  {
597  // Call trigger
598  $result = $this->call_trigger('FICHINTER_VALIDATE', $user);
599  if ($result < 0) { $error++; }
600  // End call triggers
601  }
602 
603  if (!$error)
604  {
605  $this->oldref = $this->ref;
606 
607  // Rename directory if dir was a temporary ref
608  if (preg_match('/^[\(]?PROV/i', $this->ref))
609  {
610  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
611 
612  // Now we rename also files into index
613  $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)."'";
614  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'ficheinter/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
615  $resql = $this->db->query($sql);
616  if (!$resql) { $error++; $this->error = $this->db->lasterror(); }
617 
618  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
619  $oldref = dol_sanitizeFileName($this->ref);
620  $newref = dol_sanitizeFileName($num);
621  $dirsource = $conf->ficheinter->dir_output.'/'.$oldref;
622  $dirdest = $conf->ficheinter->dir_output.'/'.$newref;
623  if (!$error && file_exists($dirsource))
624  {
625  dol_syslog(get_class($this)."::setValid rename dir ".$dirsource." into ".$dirdest);
626 
627  if (@rename($dirsource, $dirdest))
628  {
629  dol_syslog("Rename ok");
630  // Rename docs starting with $oldref with $newref
631  $listoffiles = dol_dir_list($conf->ficheinter->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
632  foreach ($listoffiles as $fileentry)
633  {
634  $dirsource = $fileentry['name'];
635  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
636  $dirsource = $fileentry['path'].'/'.$dirsource;
637  $dirdest = $fileentry['path'].'/'.$dirdest;
638  @rename($dirsource, $dirdest);
639  }
640  }
641  }
642  }
643  }
644 
645  // Set new ref and define current statut
646  if (!$error)
647  {
648  $this->ref = $num;
649  $this->statut = 1;
650  $this->brouillon = 0;
651  $this->date_validation = $now;
652  $this->db->commit();
653  return 1;
654  } else {
655  $this->db->rollback();
656  dol_syslog(get_class($this)."::setValid ".$this->error, LOG_ERR);
657  return -1;
658  }
659  }
660  }
661 
667  public function getAmount()
668  {
669  global $db;
670 
671  $amount = 0;
672 
673  $this->author = new User($db);
674  $this->author->fetch($this->user_creation);
675 
676  $thm = $this->author->thm;
677 
678  foreach ($this->lines as $line) {
679  $amount += ($line->duration / 60 / 60 * $thm);
680  }
681 
682  return price2num($amount, 'MT');
683  }
684 
685 
697  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
698  {
699  global $conf;
700 
701  $outputlangs->load("interventions");
702 
703  if (!dol_strlen($modele)) {
704  $modele = 'soleil';
705 
706  if (!empty($this->model_pdf)) {
707  $modele = $this->model_pdf;
708  } elseif (!empty($this->modelpdf)) { // deprecated
709  $modele = $this->modelpdf;
710  } elseif (!empty($conf->global->FICHEINTER_ADDON_PDF)) {
711  $modele = $conf->global->FICHEINTER_ADDON_PDF;
712  }
713  }
714 
715  $modelpath = "core/modules/fichinter/doc/";
716 
717  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
718  }
719 
726  public function getLibStatut($mode = 0)
727  {
728  return $this->LibStatut((isset($this->statut) ? $this->statut : $this->status), $mode);
729  }
730 
731  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
739  public function LibStatut($status, $mode = 0)
740  {
741  // phpcs:enable
742  // Init/load array of translation of status
743  if (empty($this->statuts) || empty($this->statuts_short) || empty($this->statuts_logo))
744  {
745  global $langs;
746  $langs->load("fichinter");
747 
748  $this->statuts[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
749  $this->statuts[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
750  $this->statuts[self::STATUS_BILLED] = $langs->transnoentitiesnoconv('StatusInterInvoiced');
751  $this->statuts[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Done');
752  $this->statuts_short[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
753  $this->statuts_short[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
754  $this->statuts_short[self::STATUS_BILLED] = $langs->transnoentitiesnoconv('StatusInterInvoiced');
755  $this->statuts_short[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Done');
756  $this->statuts_logo[self::STATUS_DRAFT] = 'status0';
757  $this->statuts_logo[self::STATUS_VALIDATED] = 'status1';
758  $this->statuts_logo[self::STATUS_BILLED] = 'status6';
759  $this->statuts_logo[self::STATUS_CLOSED] = 'status6';
760  }
761 
762  return dolGetStatus($this->statuts[$status], $this->statuts_short[$status], '', $this->statuts_logo[$status], $mode);
763  }
764 
774  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $save_lastsearch_value = -1)
775  {
776  global $conf, $langs, $hookmanager;
777 
778  $result = '';
779 
780  $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Intervention").'</u>';
781  if (isset($this->status)) {
782  $label .= ' '.$this->getLibStatut(5);
783  }
784  $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
785 
786  $url = DOL_URL_ROOT.'/fichinter/card.php?id='.$this->id;
787 
788  if ($option !== 'nolink')
789  {
790  // Add param to save lastsearch_values or not
791  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
792  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
793  if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
794  }
795 
796  $linkclose = '';
797  if (empty($notooltip))
798  {
799  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
800  {
801  $label = $langs->trans("ShowIntervention");
802  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
803  }
804  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
805  $linkclose .= ' class="classfortooltip"';
806 
807  /*
808  $hookmanager->initHooks(array('fichinterdao'));
809  $parameters=array('id'=>$this->id);
810  $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
811  if ($reshook > 0) $linkclose = $hookmanager->resPrint;
812  */
813  }
814 
815  $linkstart = '<a href="'.$url.'"';
816  $linkstart .= $linkclose.'>';
817  $linkend = '</a>';
818 
819  $result .= $linkstart;
820  if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
821  if ($withpicto != 2) $result .= $this->ref;
822  $result .= $linkend;
823 
824  global $action;
825  $hookmanager->initHooks(array('interventiondao'));
826  $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
827  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
828  if ($reshook > 0) $result = $hookmanager->resPrint;
829  else $result .= $hookmanager->resPrint;
830 
831  return $result;
832  }
833 
834 
842  public function getNextNumRef($soc)
843  {
844  global $conf, $db, $langs;
845  $langs->load("interventions");
846 
847  if (!empty($conf->global->FICHEINTER_ADDON))
848  {
849  $mybool = false;
850 
851  $file = "mod_".$conf->global->FICHEINTER_ADDON.".php";
852  $classname = "mod_".$conf->global->FICHEINTER_ADDON;
853 
854  // Include file with class
855  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
856 
857  foreach ($dirmodels as $reldir) {
858  $dir = dol_buildpath($reldir."core/modules/fichinter/");
859 
860  // Load file with numbering class (if found)
861  $mybool |= @include_once $dir.$file;
862  }
863 
864  if ($mybool === false) {
865  dol_print_error('', "Failed to include file ".$file);
866  return '';
867  }
868 
869  $obj = new $classname();
870  $numref = "";
871  $numref = $obj->getNextValue($soc, $this);
872 
873  if ($numref != "")
874  {
875  return $numref;
876  } else {
877  dol_print_error($db, "Fichinter::getNextNumRef ".$obj->error);
878  return "";
879  }
880  } else {
881  $langs->load("errors");
882  print $langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined");
883  return "";
884  }
885  }
886 
893  public function info($id)
894  {
895  global $conf;
896 
897  $sql = "SELECT f.rowid,";
898  $sql .= " f.datec,";
899  $sql .= " f.tms as date_modification,";
900  $sql .= " f.date_valid as datev,";
901  $sql .= " f.fk_user_author,";
902  $sql .= " f.fk_user_modif as fk_user_modification,";
903  $sql .= " f.fk_user_valid";
904  $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
905  $sql .= " WHERE f.rowid = ".$id;
906 
907  $resql = $this->db->query($sql);
908  if ($resql)
909  {
910  if ($this->db->num_rows($resql))
911  {
912  $obj = $this->db->fetch_object($resql);
913 
914  $this->id = $obj->rowid;
915 
916  $this->date_creation = $this->db->jdate($obj->datec);
917  $this->date_modification = $this->db->jdate($obj->date_modification);
918  $this->date_validation = $this->db->jdate($obj->datev);
919 
920  $cuser = new User($this->db);
921  $cuser->fetch($obj->fk_user_author);
922  $this->user_creation = $cuser;
923 
924  if ($obj->fk_user_valid)
925  {
926  $vuser = new User($this->db);
927  $vuser->fetch($obj->fk_user_valid);
928  $this->user_validation = $vuser;
929  }
930  if ($obj->fk_user_modification)
931  {
932  $muser = new User($this->db);
933  $muser->fetch($obj->fk_user_modification);
934  $this->user_modification = $muser;
935  }
936  }
937  $this->db->free($resql);
938  } else {
939  dol_print_error($this->db);
940  }
941  }
942 
950  public function delete($user, $notrigger = 0)
951  {
952  global $conf, $langs;
953  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
954 
955  $error = 0;
956 
957  $this->db->begin();
958 
959  if (!$error && !$notrigger)
960  {
961  // Call trigger
962  $result = $this->call_trigger('FICHINTER_DELETE', $user);
963  if ($result < 0) { $error++; $this->db->rollback(); return -1; }
964  // End call triggers
965  }
966 
967  // Delete linked object
968  if (!$error)
969  {
970  $res = $this->deleteObjectLinked();
971  if ($res < 0) $error++;
972  }
973 
974  // Delete linked contacts
975  if (!$error)
976  {
977  $res = $this->delete_linked_contact();
978  if ($res < 0)
979  {
980  $this->error = 'ErrorFailToDeleteLinkedContact';
981  $error++;
982  }
983  }
984 
985  if (!$error) {
986  $main = MAIN_DB_PREFIX.'fichinterdet';
987  $ef = $main."_extrafields";
988  $sql = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_fichinter = ".$this->id.")";
989 
990  $resql = $this->db->query($sql);
991  if (!$resql) $error++;
992  }
993 
994  if (!$error)
995  {
996  $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet";
997  $sql .= " WHERE fk_fichinter = ".$this->id;
998 
999  $resql = $this->db->query($sql);
1000  if (!$resql) $error++;
1001  }
1002 
1003  if (!$error)
1004  {
1005  // Remove extrafields
1006  $res = $this->deleteExtraFields();
1007  if ($res < 0) $error++;
1008  }
1009 
1010  if (!$error)
1011  {
1012  // Delete object
1013  $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter";
1014  $sql .= " WHERE rowid = ".$this->id;
1015 
1016  dol_syslog("Fichinter::delete", LOG_DEBUG);
1017  $resql = $this->db->query($sql);
1018  if (!$resql) $error++;
1019  }
1020 
1021  if (!$error)
1022  {
1023  // Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive
1024  $this->deleteEcmFiles();
1025 
1026  // Remove directory with files
1027  $fichinterref = dol_sanitizeFileName($this->ref);
1028  if ($conf->ficheinter->dir_output)
1029  {
1030  $dir = $conf->ficheinter->dir_output."/".$fichinterref;
1031  $file = $conf->ficheinter->dir_output."/".$fichinterref."/".$fichinterref.".pdf";
1032  if (file_exists($file))
1033  {
1034  dol_delete_preview($this);
1035 
1036  if (!dol_delete_file($file, 0, 0, 0, $this)) // For triggers
1037  {
1038  $langs->load("errors");
1039  $this->error = $langs->trans("ErrorFailToDeleteFile", $file);
1040  return 0;
1041  }
1042  }
1043  if (file_exists($dir))
1044  {
1045  if (!dol_delete_dir_recursive($dir))
1046  {
1047  $langs->load("errors");
1048  $this->error = $langs->trans("ErrorFailToDeleteDir", $dir);
1049  return 0;
1050  }
1051  }
1052  }
1053  }
1054 
1055  if (!$error)
1056  {
1057  $this->db->commit();
1058  return 1;
1059  } else {
1060  $this->db->rollback();
1061  return -1;
1062  }
1063  }
1064 
1065  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1073  public function set_date_delivery($user, $date_delivery)
1074  {
1075  // phpcs:enable
1076  global $conf;
1077 
1078  if ($user->rights->ficheinter->creer)
1079  {
1080  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
1081  $sql .= " SET datei = '".$this->db->idate($date_delivery)."'";
1082  $sql .= " WHERE rowid = ".$this->id;
1083  $sql .= " AND fk_statut = 0";
1084 
1085  if ($this->db->query($sql))
1086  {
1087  $this->date_delivery = $date_delivery;
1088  return 1;
1089  } else {
1090  $this->error = $this->db->error();
1091  dol_syslog("Fichinter::set_date_delivery Erreur SQL");
1092  return -1;
1093  }
1094  }
1095  }
1096 
1097  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1105  public function set_description($user, $description)
1106  {
1107  // phpcs:enable
1108  global $conf;
1109 
1110  if ($user->rights->ficheinter->creer)
1111  {
1112  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
1113  $sql .= " SET description = '".$this->db->escape($description)."',";
1114  $sql .= " fk_user_modif = ".$user->id;
1115  $sql .= " WHERE rowid = ".$this->id;
1116 
1117  if ($this->db->query($sql))
1118  {
1119  $this->description = $description;
1120  return 1;
1121  } else {
1122  $this->error = $this->db->error();
1123  dol_syslog("Fichinter::set_description Erreur SQL");
1124  return -1;
1125  }
1126  }
1127  }
1128 
1129 
1130  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1138  public function set_contrat($user, $contractid)
1139  {
1140  // phpcs:enable
1141  global $conf;
1142 
1143  if ($user->rights->ficheinter->creer)
1144  {
1145  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
1146  $sql .= " SET fk_contrat = ".((int) $contractid);
1147  $sql .= " WHERE rowid = ".$this->id;
1148 
1149  if ($this->db->query($sql))
1150  {
1151  $this->fk_contrat = $contractid;
1152  return 1;
1153  } else {
1154  $this->error = $this->db->error();
1155  return -1;
1156  }
1157  }
1158  return -2;
1159  }
1160 
1161 
1162 
1170  public function createFromClone(User $user, $socid = 0)
1171  {
1172  global $hookmanager;
1173 
1174  $error = 0;
1175 
1176  $this->db->begin();
1177 
1178  // get extrafields so they will be clone
1179  foreach ($this->lines as $line)
1180  $line->fetch_optionals();
1181 
1182  // Load source object
1183  $objFrom = clone $this;
1184 
1185  // Change socid if needed
1186  if (!empty($socid) && $socid != $this->socid)
1187  {
1188  $objsoc = new Societe($this->db);
1189 
1190  if ($objsoc->fetch($socid) > 0)
1191  {
1192  $this->socid = $objsoc->id;
1193  //$this->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1194  //$this->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1195  $this->fk_project = '';
1196  $this->fk_delivery_address = '';
1197  }
1198 
1199  // TODO Change product price if multi-prices
1200  }
1201 
1202  $this->id = 0;
1203  $this->ref = '';
1204  $this->statut = 0;
1205 
1206  // Clear fields
1207  $this->user_author_id = $user->id;
1208  $this->user_valid = '';
1209  $this->date_creation = '';
1210  $this->date_validation = '';
1211  $this->ref_client = '';
1212 
1213  // Create clone
1214  $this->context['createfromclone'] = 'createfromclone';
1215  $result = $this->create($user);
1216  if ($result < 0) $error++;
1217 
1218  if (!$error)
1219  {
1220  // Add lines because it is not included into create function
1221  foreach ($this->lines as $line)
1222  {
1223  $this->addline($user, $this->id, $line->desc, $line->datei, $line->duration);
1224  }
1225 
1226  // Hook of thirdparty module
1227  if (is_object($hookmanager))
1228  {
1229  $parameters = array('objFrom'=>$objFrom);
1230  $action = '';
1231  $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1232  if ($reshook < 0) $error++;
1233  }
1234  }
1235 
1236  unset($this->context['createfromclone']);
1237 
1238  // End
1239  if (!$error)
1240  {
1241  $this->db->commit();
1242  return $this->id;
1243  } else {
1244  $this->db->rollback();
1245  return -1;
1246  }
1247  }
1248 
1249 
1261  public function addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options = '')
1262  {
1263  dol_syslog(get_class($this)."::addline $fichinterid, $desc, $date_intervention, $duration");
1264 
1265  if ($this->statut == 0)
1266  {
1267  $this->db->begin();
1268 
1269  // Insertion ligne
1270  $line = new FichinterLigne($this->db);
1271 
1272  $line->fk_fichinter = $fichinterid;
1273  $line->desc = $desc;
1274  $line->datei = $date_intervention;
1275  $line->duration = $duration;
1276 
1277  if (is_array($array_options) && count($array_options) > 0) {
1278  $line->array_options = $array_options;
1279  }
1280 
1281  $result = $line->insert($user);
1282 
1283  if ($result >= 0)
1284  {
1285  $this->db->commit();
1286  return 1;
1287  } else {
1288  $this->error = $this->db->error();
1289  $this->db->rollback();
1290  return -1;
1291  }
1292  }
1293  }
1294 
1295 
1303  public function initAsSpecimen()
1304  {
1305  global $user, $langs, $conf;
1306 
1307  $now = dol_now();
1308 
1309  // Initialise parametres
1310  $this->id = 0;
1311  $this->ref = 'SPECIMEN';
1312  $this->specimen = 1;
1313  $this->socid = 1;
1314  $this->datec = $now;
1315  $this->note_private = 'Private note';
1316  $this->note_public = 'SPECIMEN';
1317  $this->duration = 0;
1318  $nbp = 25;
1319  $xnbp = 0;
1320  while ($xnbp < $nbp)
1321  {
1322  $line = new FichinterLigne($this->db);
1323  $line->desc = $langs->trans("Description")." ".$xnbp;
1324  $line->datei = ($now - 3600 * (1 + $xnbp));
1325  $line->duration = 600;
1326  $line->fk_fichinter = 0;
1327  $this->lines[$xnbp] = $line;
1328  $xnbp++;
1329 
1330  $this->duration += $line->duration;
1331  }
1332  }
1333 
1334  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1340  public function fetch_lines()
1341  {
1342  // phpcs:enable
1343  $this->lines = array();
1344 
1345  $sql = 'SELECT rowid, fk_fichinter, description, duree, date, rang';
1346  $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet';
1347  $sql .= ' WHERE fk_fichinter = '.$this->id.' ORDER BY rang ASC, date ASC';
1348 
1349  dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
1350  $resql = $this->db->query($sql);
1351  if ($resql)
1352  {
1353  $num = $this->db->num_rows($resql);
1354  $i = 0;
1355  while ($i < $num)
1356  {
1357  $objp = $this->db->fetch_object($resql);
1358 
1359  $line = new FichinterLigne($this->db);
1360  $line->id = $objp->rowid;
1361  $line->fk_fichinter = $objp->fk_fichinter;
1362  $line->desc = $objp->description;
1363  $line->duration = $objp->duree;
1364  //For invoicing we calculing hours
1365  $line->qty = round($objp->duree / 3600, 2);
1366  $line->date = $this->db->jdate($objp->date);
1367  $line->datei = $this->db->jdate($objp->date);
1368  $line->rang = $objp->rang;
1369  $line->product_type = 1;
1370  $line->fetch_optionals();
1371 
1372  $this->lines[$i] = $line;
1373 
1374  $i++;
1375  }
1376  $this->db->free($resql);
1377 
1378  return 1;
1379  } else {
1380  $this->error = $this->db->error();
1381  return -1;
1382  }
1383  }
1384 
1393  public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
1394  {
1395  $tables = array(
1396  'fichinter'
1397  );
1398 
1399  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
1400  }
1401 }
1402 
1407 {
1411  public $db;
1412 
1416  public $error = '';
1417 
1418  // From llx_fichinterdet
1422  public $fk_fichinter;
1423 
1424  public $desc; // Description ligne
1425  public $datei; // Date intervention
1426  public $duration; // Duree de l'intervention
1427  public $rang = 0;
1428 
1432  public $element = 'fichinterdet';
1433 
1437  public $table_element = 'fichinterdet';
1438 
1442  public $fk_element = 'fk_fichinter';
1443 
1449  public function __construct($db)
1450  {
1451  $this->db = $db;
1452  }
1453 
1460  public function fetch($rowid)
1461  {
1462  $sql = 'SELECT ft.rowid, ft.fk_fichinter, ft.description, ft.duree, ft.rang,';
1463  $sql .= ' ft.date as datei';
1464  $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft';
1465  $sql .= ' WHERE ft.rowid = '.$rowid;
1466 
1467  dol_syslog("FichinterLigne::fetch", LOG_DEBUG);
1468  $result = $this->db->query($sql);
1469  if ($result)
1470  {
1471  $objp = $this->db->fetch_object($result);
1472  $this->rowid = $objp->rowid;
1473  $this->id = $objp->rowid;
1474  $this->fk_fichinter = $objp->fk_fichinter;
1475  $this->datei = $this->db->jdate($objp->datei);
1476  $this->desc = $objp->description;
1477  $this->duration = $objp->duree;
1478  $this->rang = $objp->rang;
1479 
1480  $this->db->free($result);
1481  return 1;
1482  } else {
1483  $this->error = $this->db->error().' sql='.$sql;
1484  return -1;
1485  }
1486  }
1487 
1495  public function insert($user, $notrigger = 0)
1496  {
1497  global $langs, $conf;
1498 
1499  $error = 0;
1500 
1501  dol_syslog("FichinterLigne::insert rang=".$this->rang);
1502 
1503  $this->db->begin();
1504 
1505  $rangToUse = $this->rang;
1506  if ($rangToUse == -1)
1507  {
1508  // Recupere rang max de la ligne d'intervention dans $rangmax
1509  $sql = 'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.'fichinterdet';
1510  $sql .= ' WHERE fk_fichinter ='.$this->fk_fichinter;
1511  $resql = $this->db->query($sql);
1512  if ($resql)
1513  {
1514  $obj = $this->db->fetch_object($resql);
1515  $rangToUse = $obj->max + 1;
1516  } else {
1517  dol_print_error($this->db);
1518  $this->db->rollback();
1519  return -1;
1520  }
1521  }
1522 
1523  // Insertion dans base de la ligne
1524  $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'fichinterdet';
1525  $sql .= ' (fk_fichinter, description, date, duree, rang)';
1526  $sql .= " VALUES (".$this->fk_fichinter.",";
1527  $sql .= " '".$this->db->escape($this->desc)."',";
1528  $sql .= " '".$this->db->idate($this->datei)."',";
1529  $sql .= " ".$this->duration.",";
1530  $sql .= ' '.$rangToUse;
1531  $sql .= ')';
1532 
1533  dol_syslog("FichinterLigne::insert", LOG_DEBUG);
1534  $resql = $this->db->query($sql);
1535  if ($resql)
1536  {
1537  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'fichinterdet');
1538  $this->rowid = $this->id;
1539 
1540  if (!$error)
1541  {
1542  $result = $this->insertExtraFields();
1543  if ($result < 0)
1544  {
1545  $error++;
1546  }
1547  }
1548 
1549 
1550  $result = $this->update_total();
1551 
1552  if ($result > 0)
1553  {
1554  $this->rang = $rangToUse;
1555 
1556  if (!$notrigger)
1557  {
1558  // Call trigger
1559  $result = $this->call_trigger('LINEFICHINTER_CREATE', $user);
1560  if ($result < 0) { $error++; }
1561  // End call triggers
1562  }
1563  }
1564 
1565  if (!$error) {
1566  $this->db->commit();
1567  return $result;
1568  } else {
1569  $this->db->rollback();
1570  return -1;
1571  }
1572  } else {
1573  $this->error = $this->db->error()." sql=".$sql;
1574  $this->db->rollback();
1575  return -1;
1576  }
1577  }
1578 
1579 
1587  public function update($user, $notrigger = 0)
1588  {
1589  global $langs, $conf;
1590 
1591  $error = 0;
1592 
1593  $this->db->begin();
1594 
1595  // Mise a jour ligne en base
1596  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinterdet SET";
1597  $sql .= " description='".$this->db->escape($this->desc)."'";
1598  $sql .= ",date='".$this->db->idate($this->datei)."'";
1599  $sql .= ",duree=".$this->duration;
1600  $sql .= ",rang='".$this->db->escape($this->rang)."'";
1601  $sql .= " WHERE rowid = ".$this->id;
1602 
1603  dol_syslog("FichinterLigne::update", LOG_DEBUG);
1604  $resql = $this->db->query($sql);
1605  if ($resql)
1606  {
1607  if (!$error)
1608  {
1609  $result = $this->insertExtraFields();
1610  if ($result < 0)
1611  {
1612  $error++;
1613  }
1614  }
1615 
1616  $result = $this->update_total();
1617  if ($result > 0)
1618  {
1619  if (!$notrigger)
1620  {
1621  // Call trigger
1622  $result = $this->call_trigger('LINEFICHINTER_UPDATE', $user);
1623  if ($result < 0) { $error++; }
1624  // End call triggers
1625  }
1626  }
1627 
1628  if (!$error)
1629  {
1630  $this->db->commit();
1631  return $result;
1632  } else {
1633  $this->error = $this->db->lasterror();
1634  $this->db->rollback();
1635  return -1;
1636  }
1637  } else {
1638  $this->error = $this->db->lasterror();
1639  $this->db->rollback();
1640  return -1;
1641  }
1642  }
1643 
1644  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1650  public function update_total()
1651  {
1652  // phpcs:enable
1653  global $conf;
1654 
1655  $this->db->begin();
1656 
1657  $sql = "SELECT SUM(duree) as total_duration, min(date) as dateo, max(date) as datee ";
1658  $sql .= " FROM ".MAIN_DB_PREFIX."fichinterdet";
1659  $sql .= " WHERE fk_fichinter=".$this->fk_fichinter;
1660 
1661  dol_syslog("FichinterLigne::update_total", LOG_DEBUG);
1662  $resql = $this->db->query($sql);
1663  if ($resql)
1664  {
1665  $obj = $this->db->fetch_object($resql);
1666  $total_duration = 0;
1667  if (!empty($obj->total_duration)) $total_duration = $obj->total_duration;
1668 
1669  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
1670  $sql .= " SET duree = ".$total_duration;
1671  $sql .= " , dateo = ".(!empty($obj->dateo) ? "'".$this->db->idate($obj->dateo)."'" : "null");
1672  $sql .= " , datee = ".(!empty($obj->datee) ? "'".$this->db->idate($obj->datee)."'" : "null");
1673  $sql .= " WHERE rowid = ".$this->fk_fichinter;
1674 
1675  dol_syslog("FichinterLigne::update_total", LOG_DEBUG);
1676  $resql = $this->db->query($sql);
1677  if ($resql)
1678  {
1679  $this->db->commit();
1680  return 1;
1681  } else {
1682  $this->error = $this->db->error();
1683  $this->db->rollback();
1684  return -2;
1685  }
1686  } else {
1687  $this->error = $this->db->error();
1688  $this->db->rollback();
1689  return -1;
1690  }
1691  }
1692 
1700  public function deleteline($user, $notrigger = 0)
1701  {
1702  global $langs, $conf;
1703 
1704  $error = 0;
1705 
1706  if ($this->statut == 0)
1707  {
1708  dol_syslog(get_class($this)."::deleteline lineid=".$this->id);
1709  $this->db->begin();
1710 
1711  $result = $this->deleteExtraFields();
1712  if ($result < 0) {
1713  $error++;
1714  $this->db->rollback();
1715  return -1;
1716  }
1717 
1718  $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet WHERE rowid = ".$this->id;
1719  $resql = $this->db->query($sql);
1720 
1721  if ($resql)
1722  {
1723  $result = $this->update_total();
1724  if ($result > 0)
1725  {
1726  if (!$notrigger)
1727  {
1728  // Call trigger
1729  $result = $this->call_trigger('LINEFICHINTER_DELETE', $user);
1730  if ($result < 0) { $error++; $this->db->rollback(); return -1; }
1731  // End call triggers
1732  }
1733 
1734  $this->db->commit();
1735  return $result;
1736  } else {
1737  $this->db->rollback();
1738  return -1;
1739  }
1740  } else {
1741  $this->error = $this->db->error()." sql=".$sql;
1742  $this->db->rollback();
1743  return -1;
1744  }
1745  } else {
1746  return -2;
1747  }
1748  }
1749 }
getLibStatut($mode=0)
Returns the label status.
getAmount()
Returns amount based on user thm.
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
Definition: list.php:632
info($id)
Load information on object.
setDraft($user)
Set status to draft.
deleteline($user, $notrigger=0)
Delete a intervention line.
addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options= '')
Adding a line of intervention into data base.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:750
create($user, $notrigger=0)
Create an intervention into data base.
</td >< tdcolspan="3">< spanclass="opacitymedium"></span ></td ></tr >< trclass="liste_total"> CREANCES DETTES< tdcolspan="3"class="right"></td >< tdcolspan="3"class="right"></td ></tr > CREANCES DETTES RECETTES DEPENSES trips CREANCES DETTES Y m expensereport p date_valid Y m expensereport pe datep $db idate($date_start)."' AND $column < p rowid
Class to manage interventions.
dol_now($mode= 'auto')
Return date for now.
dol_delete_preview($object)
Delete all preview files linked to object instance.
Definition: files.lib.php:1335
delete_linked_contact($source= '', $code= '')
Delete all links between an object $this and all its contacts.
Class to manage Dolibarr users.
Definition: user.class.php:44
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Class to manage Dolibarr database access.
createFromClone(User $user, $socid=0)
Load an object from its id and create a new one in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
update($user, $notrigger=0)
Update an intervention.
const STATUS_DRAFT
Draft status.
set_date_delivery($user, $date_delivery)
Defines a delivery date of intervention.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
const STATUS_VALIDATED
Validated status.
getNextNumRef($soc)
Returns the next non used reference of intervention depending on the module numbering assets within F...
$conf db
API class for accounts.
Definition: inc.php:54
initAsSpecimen()
Initialise an instance with random values.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
__construct($db)
Constructor.
__construct($db)
Constructor.
Class to manage third parties objects (customers, suppliers, prospects...)
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
set_contrat($user, $contractid)
Link intervention to a contract.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
update($user, $notrigger=0)
Update intervention into database.
deleteEcmFiles($mode=0)
Delete related files of object in database.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
set_description($user, $description)
Define the label of the intervention.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories) ...
Definition: files.lib.php:1286
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
Definition: files.lib.php:1144
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
deleteExtraFields()
Delete all extra fields values for the current object.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
const STATUS_CLOSED
Closed.
fetch_lines()
Load array lines -&gt;lines.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this-&gt;array_options This method is in most cases call...
deleteObjectLinked($sourceid=null, $sourcetype= '', $targetid=null, $targettype= '', $rowid= '')
Delete all links between an object $this.
LibStatut($status, $mode=0)
Returns the label of a status.
print $_SERVER["PHP_SELF"]
Edit parameters.
setValid($user, $notrigger=0)
Validate a intervention.
print
Draft customers invoices.
Definition: index.php:89
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage intervention lines.
insert($user, $notrigger=0)
Insert the line into database.
const STATUS_BILLED
Billed.
update_total()
Update total duration into llx_fichinter.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
fetch($rowid)
Retrieve the line of intervention.
load_state_board()
Load indicators into this-&gt;nb for board.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
add_object_linked($origin=null, $origin_id=null)
Add objects linked in llx_element_element.
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
getNomUrl($withpicto=0, $option= '', $notooltip=0, $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
fetch($rowid, $ref= '')
Fetch a intervention.