dolibarr  9.0.0
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-2013 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
7  * Copyright (C) 2015 Charlie Benke <charlie@patas-monkey.com>
8  * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
9  * Copyright (C) 2018 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 <http://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 {
42  public $element='fichinter';
43 
47  public $table_element='fichinter';
48 
52  public $fk_element='fk_fichinter';
53 
57  public $table_element_line='fichinterdet';
58 
62  public $picto = 'intervention';
63 
67  protected $table_ref_field = 'ref';
68 
69  public $socid; // Id client
70 
71  public $author;
72  public $datec;
73  public $datev;
74  public $dateo;
75  public $datee;
76  public $datet;
77  public $datem;
78  public $duration;
79  public $statut = 0; // 0=draft, 1=validated, 2=invoiced, 3=Terminate
80 
84  public $description;
85 
89  public $fk_contrat = 0;
90 
94  public $fk_project = 0;
95 
96  public $extraparams=array();
97 
98  public $lines = array();
99 
103  const STATUS_DRAFT = 0;
104 
108  const STATUS_VALIDATED = 1;
109 
113  const STATUS_BILLED = 2;
114 
118  const STATUS_CLOSED = 3;
119 
125  function __construct($db)
126  {
127  $this->db = $db;
128 
129  $this->products = array();
130  }
131 
132  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
138  function load_state_board()
139  {
140  // phpcs:enable
141  global $user;
142 
143  $this->nb=array();
144  $clause = "WHERE";
145 
146  $sql = "SELECT count(fi.rowid) as nb";
147  $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as fi";
148  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON fi.fk_soc = s.rowid";
149  if (!$user->rights->societe->client->voir && !$user->societe_id)
150  {
151  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
152  $sql.= " WHERE sc.fk_user = " .$user->id;
153  $clause = "AND";
154  }
155  $sql.= " ".$clause." fi.entity IN (".getEntity('intervention').")";
156 
157  $resql=$this->db->query($sql);
158  if ($resql)
159  {
160  while ($obj=$this->db->fetch_object($resql))
161  {
162  $this->nb["fichinters"]=$obj->nb;
163  }
164  $this->db->free($resql);
165  return 1;
166  }
167  else
168  {
169  dol_print_error($this->db);
170  $this->error=$this->db->error();
171  return -1;
172  }
173  }
174 
182  function create($user, $notrigger=0)
183  {
184  global $conf, $langs;
185 
186  dol_syslog(get_class($this)."::create ref=".$this->ref);
187 
188  // Check parameters
189  if (! empty($this->ref)) // We check that ref is not already used
190  {
191  $result=self::isExistingObject($this->element, 0, $this->ref); // Check ref is not yet used
192  if ($result > 0)
193  {
194  $this->error='ErrorRefAlreadyExists';
195  dol_syslog(get_class($this)."::create ".$this->error,LOG_WARNING);
196  $this->db->rollback();
197  return -1;
198  }
199  }
200  if (! is_numeric($this->duration)) $this->duration = 0;
201 
202  if ($this->socid <= 0)
203  {
204  $this->error='ErrorBadParameterForFunc';
205  dol_syslog(get_class($this)."::create ".$this->error,LOG_ERR);
206  return -1;
207  }
208 
209  $soc = new Societe($this->db);
210  $result=$soc->fetch($this->socid);
211 
212  $now=dol_now();
213 
214  $this->db->begin();
215 
216  $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter (";
217  $sql.= "fk_soc";
218  $sql.= ", datec";
219  $sql.= ", ref";
220  $sql.= ", entity";
221  $sql.= ", fk_user_author";
222  $sql.= ", fk_user_modif";
223  $sql.= ", description";
224  $sql.= ", model_pdf";
225  $sql.= ", fk_projet";
226  $sql.= ", fk_contrat";
227  $sql.= ", fk_statut";
228  $sql.= ", note_private";
229  $sql.= ", note_public";
230  $sql.= ") ";
231  $sql.= " VALUES (";
232  $sql.= $this->socid;
233  $sql.= ", '".$this->db->idate($now)."'";
234  $sql.= ", '".$this->db->escape($this->ref)."'";
235  $sql.= ", ".$conf->entity;
236  $sql.= ", ".$user->id;
237  $sql.= ", ".$user->id;
238  $sql.= ", ".($this->description?"'".$this->db->escape($this->description)."'":"null");
239  $sql.= ", '".$this->db->escape($this->modelpdf)."'";
240  $sql.= ", ".($this->fk_project ? $this->fk_project : 0);
241  $sql.= ", ".($this->fk_contrat ? $this->fk_contrat : 0);
242  $sql.= ", ".$this->statut;
243  $sql.= ", ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null");
244  $sql.= ", ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null");
245  $sql.= ")";
246 
247  dol_syslog(get_class($this)."::create", LOG_DEBUG);
248  $result=$this->db->query($sql);
249  if ($result)
250  {
251  $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."fichinter");
252 
253  if ($this->id)
254  {
255  $this->ref='(PROV'.$this->id.')';
256  $sql = 'UPDATE '.MAIN_DB_PREFIX."fichinter SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".$this->id;
257 
258  dol_syslog(get_class($this)."::create", LOG_DEBUG);
259  $resql=$this->db->query($sql);
260  if (! $resql) $error++;
261  }
262 
263  if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))
264  {
265  $result=$this->insertExtraFields();
266  if ($result < 0)
267  {
268  $error++;
269  }
270  }
271 
272  // Add linked object
273  if (! $error && $this->origin && $this->origin_id)
274  {
275  $ret = $this->add_object_linked();
276  if (! $ret) dol_print_error($this->db);
277  }
278 
279 
280  if (! $error && ! $notrigger)
281  {
282  // Call trigger
283  $result=$this->call_trigger('FICHINTER_CREATE',$user);
284  if ($result < 0) { $error++; }
285  // End call triggers
286  }
287 
288  if (! $error)
289  {
290  $this->db->commit();
291  return $this->id;
292  }
293  else
294  {
295  $this->db->rollback();
296  $this->error=join(',',$this->errors);
297  dol_syslog(get_class($this)."::create ".$this->error,LOG_ERR);
298  return -1;
299  }
300  }
301  else
302  {
303  $this->error=$this->db->error();
304  $this->db->rollback();
305  return -1;
306  }
307  }
308 
316  function update($user, $notrigger=0)
317  {
318  if (! is_numeric($this->duration)) {
319  $this->duration = 0;
320  }
321  if (! dol_strlen($this->fk_project)) {
322  $this->fk_project = 0;
323  }
324 
325  $error = 0;
326 
327  $this->db->begin();
328 
329  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET ";
330  $sql.= "description = '".$this->db->escape($this->description)."'";
331  $sql.= ", duree = ".$this->duration;
332  $sql.= ", fk_projet = ".$this->fk_project;
333  $sql.= ", note_private = ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null");
334  $sql.= ", note_public = ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null");
335  $sql.= ", fk_user_modif = ".$user->id;
336  $sql.= " WHERE rowid = ".$this->id;
337 
338  dol_syslog(get_class($this)."::update", LOG_DEBUG);
339  if ($this->db->query($sql))
340  {
341  if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
342  {
343  $result=$this->insertExtraFields();
344  if ($result < 0)
345  {
346  $error++;
347  }
348  }
349 
350  if (! $error && ! $notrigger)
351  {
352  // Call trigger
353  $result=$this->call_trigger('FICHINTER_MODIFY',$user);
354  if ($result < 0) { $error++; $this->db->rollback(); return -1; }
355  // End call triggers
356  }
357 
358  $this->db->commit();
359  return 1;
360  }
361  else
362  {
363  $this->error=$this->db->error();
364  $this->db->rollback();
365  return -1;
366  }
367  }
368 
376  function fetch($rowid,$ref='')
377  {
378  $sql = "SELECT f.rowid, f.ref, f.description, f.fk_soc, f.fk_statut,";
379  $sql.= " f.datec, f.dateo, f.datee, f.datet, f.fk_user_author,";
380  $sql.= " f.date_valid as datev,";
381  $sql.= " f.tms as datem,";
382  $sql.= " f.duree, f.fk_projet, f.note_public, f.note_private, f.model_pdf, f.extraparams, fk_contrat";
383  $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f";
384  if ($ref) {
385  $sql.= " WHERE f.entity IN (".getEntity('intervention').")";
386  $sql.= " AND f.ref='".$this->db->escape($ref)."'";
387  }
388  else $sql.= " WHERE f.rowid=".$rowid;
389 
390  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
391  $resql=$this->db->query($sql);
392  if ($resql)
393  {
394  if ($this->db->num_rows($resql))
395  {
396  $obj = $this->db->fetch_object($resql);
397 
398  $this->id = $obj->rowid;
399  $this->ref = $obj->ref;
400  $this->description = $obj->description;
401  $this->socid = $obj->fk_soc;
402  $this->statut = $obj->fk_statut;
403  $this->duration = $obj->duree;
404  $this->datec = $this->db->jdate($obj->datec);
405  $this->dateo = $this->db->jdate($obj->dateo);
406  $this->datee = $this->db->jdate($obj->datee);
407  $this->datet = $this->db->jdate($obj->datet);
408  $this->datev = $this->db->jdate($obj->datev);
409  $this->datem = $this->db->jdate($obj->datem);
410  $this->fk_project = $obj->fk_projet;
411  $this->note_public = $obj->note_public;
412  $this->note_private = $obj->note_private;
413  $this->modelpdf = $obj->model_pdf;
414  $this->fk_contrat = $obj->fk_contrat;
415 
416  $this->user_creation= $obj->fk_user_author;
417 
418  $this->extraparams = (array) json_decode($obj->extraparams, true);
419 
420  if ($this->statut == 0) $this->brouillon = 1;
421 
422  // Retreive extrafields
423  $this->fetch_optionals();
424 
425  /*
426  * Lines
427  */
428  $result=$this->fetch_lines();
429  if ($result < 0)
430  {
431  return -3;
432  }
433  $this->db->free($resql);
434  return 1;
435  }
436  }
437  else
438  {
439  $this->error=$this->db->lasterror();
440  return -1;
441  }
442  }
443 
450  function setDraft($user)
451  {
452  global $langs, $conf;
453 
454  if ($this->statut != 0)
455  {
456  $this->db->begin();
457 
458  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
459  $sql.= " SET fk_statut = 0";
460  $sql.= " WHERE rowid = ".$this->id;
461  $sql.= " AND entity = ".$conf->entity;
462 
463  dol_syslog("Fichinter::setDraft", LOG_DEBUG);
464  $resql=$this->db->query($sql);
465  if ($resql)
466  {
467  $this->db->commit();
468  return 1;
469  }
470  else
471  {
472  $this->db->rollback();
473  $this->error=$this->db->lasterror();
474  return -1;
475  }
476  }
477  }
478 
486  function setValid($user, $notrigger=0)
487  {
488  global $conf;
489  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
490 
491  $error=0;
492 
493  if ($this->statut != 1)
494  {
495  $this->db->begin();
496 
497  $now=dol_now();
498 
499  // Define new ref
500  if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
501  {
502  $num = $this->getNextNumRef($this->thirdparty);
503  }
504  else
505  {
506  $num = $this->ref;
507  }
508  $this->newref = $num;
509 
510  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
511  $sql.= " SET fk_statut = 1";
512  $sql.= ", ref = '".$num."'";
513  $sql.= ", date_valid = '".$this->db->idate($now)."'";
514  $sql.= ", fk_user_valid = ".$user->id;
515  $sql.= " WHERE rowid = ".$this->id;
516  $sql.= " AND entity = ".$conf->entity;
517  $sql.= " AND fk_statut = 0";
518 
519  dol_syslog(get_class($this)."::setValid", LOG_DEBUG);
520  $resql=$this->db->query($sql);
521  if (! $resql)
522  {
523  dol_print_error($this->db);
524  $error++;
525  }
526 
527  if (! $error && ! $notrigger)
528  {
529  // Call trigger
530  $result=$this->call_trigger('FICHINTER_VALIDATE',$user);
531  if ($result < 0) { $error++; }
532  // End call triggers
533  }
534 
535  if (! $error)
536  {
537  $this->oldref = $this->ref;
538 
539  // Rename directory if dir was a temporary ref
540  if (preg_match('/^[\(]?PROV/i', $this->ref))
541  {
542  // Rename of object directory ($this->ref = old ref, $num = new ref)
543  // to not lose the linked files
544  $oldref = dol_sanitizeFileName($this->ref);
545  $newref = dol_sanitizeFileName($num);
546  $dirsource = $conf->ficheinter->dir_output.'/'.$oldref;
547  $dirdest = $conf->ficheinter->dir_output.'/'.$newref;
548  if (file_exists($dirsource))
549  {
550  dol_syslog(get_class($this)."::setValid rename dir ".$dirsource." into ".$dirdest);
551 
552  if (@rename($dirsource, $dirdest))
553  {
554  dol_syslog("Rename ok");
555  // Rename docs starting with $oldref with $newref
556  $listoffiles=dol_dir_list($conf->ficheinter->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
557  foreach($listoffiles as $fileentry)
558  {
559  $dirsource=$fileentry['name'];
560  $dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
561  $dirsource=$fileentry['path'].'/'.$dirsource;
562  $dirdest=$fileentry['path'].'/'.$dirdest;
563  @rename($dirsource, $dirdest);
564  }
565  }
566  }
567  }
568  }
569 
570  // Set new ref and define current statut
571  if (! $error)
572  {
573  $this->ref = $num;
574  $this->statut=1;
575  $this->brouillon=0;
576  $this->date_validation=$now;
577  }
578 
579  if (! $error)
580  {
581  $this->db->commit();
582  return 1;
583  }
584  else
585  {
586  $this->db->rollback();
587  dol_syslog(get_class($this)."::setValid ".$this->error,LOG_ERR);
588  return -1;
589  }
590  }
591  }
592 
598  function getAmount()
599  {
600  global $db;
601 
602  $amount = 0;
603 
604  $this->author = new User($db);
605  $this->author->fetch($this->user_creation);
606 
607  $thm = $this->author->thm;
608 
609  foreach($this->lines as $line) {
610  $amount += ($line->duration / 60 / 60 * $thm);
611  }
612 
613  return price2num($amount, 'MT');
614  }
615 
616 
628  public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
629  {
630  global $conf,$langs;
631 
632  $langs->load("interventions");
633 
634  if (! dol_strlen($modele)) {
635 
636  $modele = 'soleil';
637 
638  if ($this->modelpdf) {
639  $modele = $this->modelpdf;
640  } elseif (! empty($conf->global->FICHEINTER_ADDON_PDF)) {
641  $modele = $conf->global->FICHEINTER_ADDON_PDF;
642  }
643  }
644 
645  $modelpath = "core/modules/fichinter/doc/";
646 
647  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref,$moreparams);
648  }
649 
656  function getLibStatut($mode=0)
657  {
658  return $this->LibStatut($this->statut,$mode);
659  }
660 
661  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
669  function LibStatut($statut,$mode=0)
670  {
671  // phpcs:enable
672  // Init/load array of translation of status
673  if (empty($this->statuts) || empty($this->statuts_short))
674  {
675  global $langs;
676  $langs->load("fichinter");
677 
678  $this->statuts[0]=$langs->trans('Draft');
679  $this->statuts[1]=$langs->trans('Validated');
680  $this->statuts[2]=$langs->trans('StatusInterInvoiced');
681  $this->statuts[3]=$langs->trans('Done');
682  $this->statuts_short[0]=$langs->trans('Draft');
683  $this->statuts_short[1]=$langs->trans('Validated');
684  $this->statuts_short[2]=$langs->trans('StatusInterInvoiced');
685  $this->statuts_short[3]=$langs->trans('Done');
686  $this->statuts_logo[0]='statut0';
687  $this->statuts_logo[1]='statut1';
688  $this->statuts_logo[2]='statut6';
689  $this->statuts_logo[3]='statut6';
690  }
691 
692  if ($mode == 0)
693  return $this->statuts[$statut];
694  elseif ($mode == 1)
695  return $this->statuts_short[$statut];
696  elseif ($mode == 2)
697  return img_picto($this->statuts_short[$statut], $this->statuts_logo[$statut]).' '.$this->statuts_short[$statut];
698  elseif ($mode == 3)
699  return img_picto($this->statuts_short[$statut], $this->statuts_logo[$statut]);
700  elseif ($mode == 4)
701  return img_picto($this->statuts_short[$statut], $this->statuts_logo[$statut]).' '.$this->statuts[$statut];
702  elseif ($mode == 5)
703  return '<span class="hideonsmartphone">'.$this->statuts_short[$statut].' </span>'.img_picto($this->statuts[$statut],$this->statuts_logo[$statut]);
704  elseif ($mode == 6)
705  return '<span class="hideonsmartphone">'.$this->statuts[$statut].' </span>'.img_picto($this->statuts[$statut],$this->statuts_logo[$statut]);
706 
707  return '';
708  }
709 
719  function getNomUrl($withpicto=0, $option='', $notooltip=0, $save_lastsearch_value=-1)
720  {
721  global $conf, $langs, $hookmanager;
722 
723  $result='';
724 
725  $label = '<u>' . $langs->trans("ShowIntervention") . '</u>';
726  if (! empty($this->ref))
727  $label .= '<br><b>' . $langs->trans('Ref') . ':</b> '.$this->ref;
728 
729  $url = DOL_URL_ROOT.'/fichinter/card.php?id='.$this->id;
730 
731  if ($option !== 'nolink')
732  {
733  // Add param to save lastsearch_values or not
734  $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
735  if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
736  if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
737  }
738 
739  $linkclose='';
740  if (empty($notooltip))
741  {
742  if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
743  {
744  $label=$langs->trans("ShowIntervention");
745  $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
746  }
747  $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
748  $linkclose.=' class="classfortooltip"';
749 
750  /*
751  $hookmanager->initHooks(array('fichinterdao'));
752  $parameters=array('id'=>$this->id);
753  $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
754  if ($reshook > 0) $linkclose = $hookmanager->resPrint;
755  */
756  }
757 
758  $linkstart = '<a href="'.$url.'"';
759  $linkstart.=$linkclose.'>';
760  $linkend='</a>';
761 
762  $result .= $linkstart;
763  if ($withpicto) $result.=img_object(($notooltip?'':$label), $this->picto, ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
764  if ($withpicto != 2) $result.= $this->ref;
765  $result .= $linkend;
766 
767  global $action;
768  $hookmanager->initHooks(array('intervnetiondao'));
769  $parameters=array('id'=>$this->id, 'getnomurl'=>$result);
770  $reshook=$hookmanager->executeHooks('getNomUrl',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
771  if ($reshook > 0) $result = $hookmanager->resPrint;
772  else $result .= $hookmanager->resPrint;
773 
774  return $result;
775  }
776 
777 
785  function getNextNumRef($soc)
786  {
787  global $conf, $db, $langs;
788  $langs->load("interventions");
789 
790  if (! empty($conf->global->FICHEINTER_ADDON))
791  {
792  $mybool = false;
793 
794  $file = "mod_".$conf->global->FICHEINTER_ADDON.".php";
795  $classname = "mod_".$conf->global->FICHEINTER_ADDON;
796 
797  // Include file with class
798  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
799 
800  foreach ($dirmodels as $reldir) {
801 
802  $dir = dol_buildpath($reldir."core/modules/fichinter/");
803 
804  // Load file with numbering class (if found)
805  $mybool|=@include_once $dir.$file;
806  }
807 
808  if ($mybool === false) {
809  dol_print_error('', "Failed to include file ".$file);
810  return '';
811  }
812 
813  $obj = new $classname();
814  $numref = "";
815  $numref = $obj->getNextValue($soc, $this);
816 
817  if ( $numref != "")
818  {
819  return $numref;
820  }
821  else
822  {
823  dol_print_error($db,"Fichinter::getNextNumRef ".$obj->error);
824  return "";
825  }
826  }
827  else
828  {
829  $langs->load("errors");
830  print $langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined");
831  return "";
832  }
833  }
834 
841  function info($id)
842  {
843  global $conf;
844 
845  $sql = "SELECT f.rowid,";
846  $sql.= " f.datec,";
847  $sql.= " f.tms as date_modification,";
848  $sql.= " f.date_valid as datev,";
849  $sql.= " f.fk_user_author,";
850  $sql.= " f.fk_user_modif as fk_user_modification,";
851  $sql.= " f.fk_user_valid";
852  $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f";
853  $sql.= " WHERE f.rowid = ".$id;
854 
855  $resql = $this->db->query($sql);
856  if ($resql)
857  {
858  if ($this->db->num_rows($resql))
859  {
860  $obj = $this->db->fetch_object($resql);
861 
862  $this->id = $obj->rowid;
863 
864  $this->date_creation = $this->db->jdate($obj->datec);
865  $this->date_modification = $this->db->jdate($obj->date_modification);
866  $this->date_validation = $this->db->jdate($obj->datev);
867 
868  $cuser = new User($this->db);
869  $cuser->fetch($obj->fk_user_author);
870  $this->user_creation = $cuser;
871 
872  if ($obj->fk_user_valid)
873  {
874  $vuser = new User($this->db);
875  $vuser->fetch($obj->fk_user_valid);
876  $this->user_validation = $vuser;
877  }
878  if ($obj->fk_user_modification)
879  {
880  $muser = new User($this->db);
881  $muser->fetch($obj->fk_user_modification);
882  $this->user_modification = $muser;
883  }
884  }
885  $this->db->free($resql);
886  }
887  else
888  {
889  dol_print_error($this->db);
890  }
891  }
892 
900  function delete($user, $notrigger=0)
901  {
902  global $conf,$langs;
903  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
904 
905  $error=0;
906 
907  $this->db->begin();
908 
909  if (! $error && ! $notrigger)
910  {
911  // Call trigger
912  $result=$this->call_trigger('FICHINTER_DELETE',$user);
913  if ($result < 0) { $error++; $this->db->rollback(); return -1; }
914  // End call triggers
915  }
916 
917  // Delete linked object
918  if (! $error)
919  {
920  $res = $this->deleteObjectLinked();
921  if ($res < 0) $error++;
922  }
923 
924  // Delete linked contacts
925  if (! $error)
926  {
927  $res = $this->delete_linked_contact();
928  if ($res < 0)
929  {
930  $this->error='ErrorFailToDeleteLinkedContact';
931  $error++;
932  }
933  }
934 
935  if (! $error)
936  {
937  $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet";
938  $sql.= " WHERE fk_fichinter = ".$this->id;
939 
940  $resql = $this->db->query($sql);
941  if (! $resql) $error++;
942  }
943 
944  if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
945  {
946  // Remove extrafields
947  $res = $this->deleteExtraFields();
948  if ($res < 0) $error++;
949  }
950 
951  if (! $error)
952  {
953  // Delete object
954  $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter";
955  $sql.= " WHERE rowid = ".$this->id;
956 
957  dol_syslog("Fichinter::delete", LOG_DEBUG);
958  $resql = $this->db->query($sql);
959  if (! $resql) $error++;
960  }
961 
962  if (! $error)
963  {
964  // Remove directory with files
965  $fichinterref = dol_sanitizeFileName($this->ref);
966  if ($conf->ficheinter->dir_output)
967  {
968  $dir = $conf->ficheinter->dir_output . "/" . $fichinterref ;
969  $file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf";
970  if (file_exists($file))
971  {
972  dol_delete_preview($this);
973 
974  if (! dol_delete_file($file,0,0,0,$this)) // For triggers
975  {
976  $langs->load("errors");
977  $this->error=$langs->trans("ErrorFailToDeleteFile",$file);
978  return 0;
979  }
980  }
981  if (file_exists($dir))
982  {
983  if (! dol_delete_dir_recursive($dir))
984  {
985  $langs->load("errors");
986  $this->error=$langs->trans("ErrorFailToDeleteDir",$dir);
987  return 0;
988  }
989  }
990  }
991  }
992 
993  if (! $error)
994  {
995  $this->db->commit();
996  return 1;
997  }
998  else
999  {
1000  $this->db->rollback();
1001  return -1;
1002  }
1003  }
1004 
1005  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1013  function set_date_delivery($user, $date_delivery)
1014  {
1015  // phpcs:enable
1016  global $conf;
1017 
1018  if ($user->rights->ficheinter->creer)
1019  {
1020  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
1021  $sql.= " SET datei = '".$this->db->idate($date_delivery)."'";
1022  $sql.= " WHERE rowid = ".$this->id;
1023  $sql.= " AND fk_statut = 0";
1024 
1025  if ($this->db->query($sql))
1026  {
1027  $this->date_delivery = $date_delivery;
1028  return 1;
1029  }
1030  else
1031  {
1032  $this->error=$this->db->error();
1033  dol_syslog("Fichinter::set_date_delivery Erreur SQL");
1034  return -1;
1035  }
1036  }
1037  }
1038 
1039  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1047  function set_description($user, $description)
1048  {
1049  // phpcs:enable
1050  global $conf;
1051 
1052  if ($user->rights->ficheinter->creer)
1053  {
1054  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
1055  $sql.= " SET description = '".$this->db->escape($description)."',";
1056  $sql.= " fk_user_modif = ".$user->id;
1057  $sql.= " WHERE rowid = ".$this->id;
1058 
1059  if ($this->db->query($sql))
1060  {
1061  $this->description = $description;
1062  return 1;
1063  }
1064  else
1065  {
1066  $this->error=$this->db->error();
1067  dol_syslog("Fichinter::set_description Erreur SQL");
1068  return -1;
1069  }
1070  }
1071  }
1072 
1073 
1074  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1082  function set_contrat($user, $contractid)
1083  {
1084  // phpcs:enable
1085  global $conf;
1086 
1087  if ($user->rights->ficheinter->creer)
1088  {
1089  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
1090  $sql.= " SET fk_contrat = '".$contractid."'";
1091  $sql.= " WHERE rowid = ".$this->id;
1092 
1093  if ($this->db->query($sql))
1094  {
1095  $this->fk_contrat = $contractid;
1096  return 1;
1097  }
1098  else
1099  {
1100  $this->error=$this->db->error();
1101  return -1;
1102  }
1103  }
1104  return -2;
1105  }
1106 
1107 
1108 
1115  function createFromClone($socid=0)
1116  {
1117  global $user,$hookmanager;
1118 
1119  $error=0;
1120 
1121  $this->db->begin();
1122 
1123  // get extrafields so they will be clone
1124  foreach($this->lines as $line)
1125  $line->fetch_optionals($line->rowid);
1126 
1127  // Load source object
1128  $objFrom = clone $this;
1129 
1130  // Change socid if needed
1131  if (! empty($socid) && $socid != $this->socid)
1132  {
1133  $objsoc = new Societe($this->db);
1134 
1135  if ($objsoc->fetch($socid)>0)
1136  {
1137  $this->socid = $objsoc->id;
1138  //$this->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1139  //$this->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1140  $this->fk_project = '';
1141  $this->fk_delivery_address = '';
1142  }
1143 
1144  // TODO Change product price if multi-prices
1145  }
1146 
1147  $this->id=0;
1148  $this->ref = '';
1149  $this->statut=0;
1150 
1151  // Clear fields
1152  $this->user_author_id = $user->id;
1153  $this->user_valid = '';
1154  $this->date_creation = '';
1155  $this->date_validation = '';
1156  $this->ref_client = '';
1157 
1158  // Create clone
1159  $this->context['createfromclone'] = 'createfromclone';
1160  $result=$this->create($user);
1161  if ($result < 0) $error++;
1162 
1163  if (! $error)
1164  {
1165  // Add lines because it is not included into create function
1166  foreach ($this->lines as $line)
1167  {
1168  $this->addline($user, $this->id, $line->desc, $line->datei, $line->duration);
1169  }
1170 
1171  // Hook of thirdparty module
1172  if (is_object($hookmanager))
1173  {
1174  $parameters=array('objFrom'=>$objFrom);
1175  $action='';
1176  $reshook=$hookmanager->executeHooks('createFrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
1177  if ($reshook < 0) $error++;
1178  }
1179  }
1180 
1181  unset($this->context['createfromclone']);
1182 
1183  // End
1184  if (! $error)
1185  {
1186  $this->db->commit();
1187  return $this->id;
1188  }
1189  else
1190  {
1191  $this->db->rollback();
1192  return -1;
1193  }
1194  }
1195 
1196 
1208  function addline($user,$fichinterid, $desc, $date_intervention, $duration, $array_options='')
1209  {
1210  dol_syslog(get_class($this)."::addline $fichinterid, $desc, $date_intervention, $duration");
1211 
1212  if ($this->statut == 0)
1213  {
1214  $this->db->begin();
1215 
1216  // Insertion ligne
1217  $line=new FichinterLigne($this->db);
1218 
1219  $line->fk_fichinter = $fichinterid;
1220  $line->desc = $desc;
1221  $line->datei = $date_intervention;
1222  $line->duration = $duration;
1223 
1224  if (is_array($array_options) && count($array_options)>0) {
1225  $line->array_options=$array_options;
1226  }
1227 
1228  $result=$line->insert($user);
1229 
1230  if ($result >= 0)
1231  {
1232  $this->db->commit();
1233  return 1;
1234  }
1235  else
1236  {
1237  $this->error=$this->db->error();
1238  $this->db->rollback();
1239  return -1;
1240  }
1241  }
1242  }
1243 
1244 
1252  function initAsSpecimen()
1253  {
1254  global $user,$langs,$conf;
1255 
1256  $now=dol_now();
1257 
1258  // Initialise parametres
1259  $this->id=0;
1260  $this->ref = 'SPECIMEN';
1261  $this->specimen=1;
1262  $this->socid = 1;
1263  $this->datec = $now;
1264  $this->note_private='Private note';
1265  $this->note_public='SPECIMEN';
1266  $this->duration = 0;
1267  $nbp = 25;
1268  $xnbp = 0;
1269  while ($xnbp < $nbp)
1270  {
1271  $line=new FichinterLigne($this->db);
1272  $line->desc=$langs->trans("Description")." ".$xnbp;
1273  $line->datei=($now-3600*(1+$xnbp));
1274  $line->duration=600;
1275  $line->fk_fichinter=0;
1276  $this->lines[$xnbp]=$line;
1277  $xnbp++;
1278 
1279  $this->duration+=$line->duration;
1280  }
1281  }
1282 
1283  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1289  function fetch_lines()
1290  {
1291  // phpcs:enable
1292  $this->lines = array();
1293 
1294  $sql = 'SELECT rowid, description, duree, date, rang';
1295  $sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet';
1296  $sql.=' WHERE fk_fichinter = '.$this->id .' ORDER BY rang ASC, date ASC' ;
1297 
1298  dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
1299  $resql=$this->db->query($sql);
1300  if ($resql)
1301  {
1302  $num = $this->db->num_rows($resql);
1303  $i = 0;
1304  while ($i < $num)
1305  {
1306  $objp = $this->db->fetch_object($resql);
1307 
1308  $line = new FichinterLigne($this->db);
1309  $line->id = $objp->rowid;
1310  $line->desc = $objp->description;
1311  $line->duration = $objp->duree;
1312  //For invoicing we calculing hours
1313  $line->qty = round($objp->duree/3600,2);
1314  $line->date = $this->db->jdate($objp->date);
1315  $line->datei = $this->db->jdate($objp->date);
1316  $line->rang = $objp->rang;
1317  $line->product_type = 1;
1318 
1319  $this->lines[$i] = $line;
1320 
1321  $i++;
1322  }
1323  $this->db->free($resql);
1324 
1325  return 1;
1326  }
1327  else
1328  {
1329  $this->error=$this->db->error();
1330  return -1;
1331  }
1332  }
1333 
1342  public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
1343  {
1344  $tables = array(
1345  'fichinter'
1346  );
1347 
1348  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
1349  }
1350 }
1351 
1356 {
1360  public $db;
1361 
1365  public $error='';
1366 
1367  // From llx_fichinterdet
1371  public $fk_fichinter;
1372 
1373  public $desc; // Description ligne
1374  public $datei; // Date intervention
1375  public $duration; // Duree de l'intervention
1376  public $rang = 0;
1377 
1381  public $element='fichinterdet';
1382 
1386  public $table_element='fichinterdet';
1387 
1391  public $fk_element='fk_fichinter';
1392 
1398  function __construct($db)
1399  {
1400  $this->db = $db;
1401  }
1402 
1409  function fetch($rowid)
1410  {
1411  $sql = 'SELECT ft.rowid, ft.fk_fichinter, ft.description, ft.duree, ft.rang,';
1412  $sql.= ' ft.date as datei';
1413  $sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft';
1414  $sql.= ' WHERE ft.rowid = '.$rowid;
1415 
1416  dol_syslog("FichinterLigne::fetch", LOG_DEBUG);
1417  $result = $this->db->query($sql);
1418  if ($result)
1419  {
1420  $objp = $this->db->fetch_object($result);
1421  $this->rowid = $objp->rowid;
1422  $this->id = $objp->rowid;
1423  $this->fk_fichinter = $objp->fk_fichinter;
1424  $this->datei = $this->db->jdate($objp->datei);
1425  $this->desc = $objp->description;
1426  $this->duration = $objp->duree;
1427  $this->rang = $objp->rang;
1428 
1429  $this->db->free($result);
1430  return 1;
1431  }
1432  else
1433  {
1434  $this->error=$this->db->error().' sql='.$sql;
1435  return -1;
1436  }
1437  }
1438 
1446  function insert($user, $notrigger=0)
1447  {
1448  global $langs,$conf;
1449 
1450  dol_syslog("FichinterLigne::insert rang=".$this->rang);
1451 
1452  $this->db->begin();
1453 
1454  $rangToUse=$this->rang;
1455  if ($rangToUse == -1)
1456  {
1457  // Recupere rang max de la ligne d'intervention dans $rangmax
1458  $sql = 'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.'fichinterdet';
1459  $sql.= ' WHERE fk_fichinter ='.$this->fk_fichinter;
1460  $resql = $this->db->query($sql);
1461  if ($resql)
1462  {
1463  $obj = $this->db->fetch_object($resql);
1464  $rangToUse = $obj->max + 1;
1465  }
1466  else
1467  {
1468  dol_print_error($this->db);
1469  $this->db->rollback();
1470  return -1;
1471  }
1472  }
1473 
1474  // Insertion dans base de la ligne
1475  $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'fichinterdet';
1476  $sql.= ' (fk_fichinter, description, date, duree, rang)';
1477  $sql.= " VALUES (".$this->fk_fichinter.",";
1478  $sql.= " '".$this->db->escape($this->desc)."',";
1479  $sql.= " '".$this->db->idate($this->datei)."',";
1480  $sql.= " ".$this->duration.",";
1481  $sql.= ' '.$rangToUse;
1482  $sql.= ')';
1483 
1484  dol_syslog("FichinterLigne::insert", LOG_DEBUG);
1485  $resql=$this->db->query($sql);
1486  if ($resql)
1487  {
1488  $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX.'fichinterdet');
1489  $this->rowid=$this->id;
1490 
1491  if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1492  {
1493  $result=$this->insertExtraFields();
1494  if ($result < 0)
1495  {
1496  $error++;
1497  }
1498  }
1499 
1500 
1501  $result=$this->update_total();
1502 
1503  if ($result > 0)
1504  {
1505  $this->rang=$rangToUse;
1506 
1507  if (! $notrigger)
1508  {
1509  // Call trigger
1510  $result=$this->call_trigger('LINEFICHINTER_CREATE',$user);
1511  if ($result < 0) { $error++; }
1512  // End call triggers
1513  }
1514  }
1515 
1516  if (!$error) {
1517  $this->db->commit();
1518  return $result;
1519  }
1520  else
1521  {
1522  $this->db->rollback();
1523  return -1;
1524  }
1525  }
1526  else
1527  {
1528  $this->error=$this->db->error()." sql=".$sql;
1529  $this->db->rollback();
1530  return -1;
1531  }
1532  }
1533 
1534 
1542  function update($user,$notrigger=0)
1543  {
1544  global $langs,$conf;
1545 
1546  $this->db->begin();
1547 
1548  // Mise a jour ligne en base
1549  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinterdet SET";
1550  $sql.= " description='".$this->db->escape($this->desc)."'";
1551  $sql.= ",date='".$this->db->idate($this->datei)."'";
1552  $sql.= ",duree=".$this->duration;
1553  $sql.= ",rang='".$this->db->escape($this->rang)."'";
1554  $sql.= " WHERE rowid = ".$this->id;
1555 
1556  dol_syslog("FichinterLigne::update", LOG_DEBUG);
1557  $resql=$this->db->query($sql);
1558  if ($resql)
1559  {
1560 
1561  if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1562  {
1563  $result=$this->insertExtraFields();
1564  if ($result < 0)
1565  {
1566  $error++;
1567  }
1568  }
1569 
1570  $result=$this->update_total();
1571  if ($result > 0)
1572  {
1573 
1574  if (! $notrigger)
1575  {
1576  // Call trigger
1577  $result=$this->call_trigger('LINEFICHINTER_UPDATE',$user);
1578  if ($result < 0) { $error++; }
1579  // End call triggers
1580  }
1581  }
1582 
1583  if (!$error)
1584  {
1585  $this->db->commit();
1586  return $result;
1587  }
1588  else
1589  {
1590  $this->error=$this->db->lasterror();
1591  $this->db->rollback();
1592  return -1;
1593  }
1594  }
1595  else
1596  {
1597  $this->error=$this->db->lasterror();
1598  $this->db->rollback();
1599  return -1;
1600  }
1601  }
1602 
1603  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1609  function update_total()
1610  {
1611  // phpcs:enable
1612  global $conf;
1613 
1614  $this->db->begin();
1615 
1616  $sql = "SELECT SUM(duree) as total_duration, min(date) as dateo, max(date) as datee ";
1617  $sql.= " FROM ".MAIN_DB_PREFIX."fichinterdet";
1618  $sql.= " WHERE fk_fichinter=".$this->fk_fichinter;
1619 
1620  dol_syslog("FichinterLigne::update_total", LOG_DEBUG);
1621  $resql=$this->db->query($sql);
1622  if ($resql)
1623  {
1624  $obj=$this->db->fetch_object($resql);
1625  $total_duration=0;
1626  if (!empty($obj->total_duration)) $total_duration = $obj->total_duration;
1627 
1628  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
1629  $sql.= " SET duree = ".$total_duration;
1630  $sql.= " , dateo = ".(! empty($obj->dateo)?"'".$this->db->idate($obj->dateo)."'":"null");
1631  $sql.= " , datee = ".(! empty($obj->datee)?"'".$this->db->idate($obj->datee)."'":"null");
1632  $sql.= " WHERE rowid = ".$this->fk_fichinter;
1633 
1634  dol_syslog("FichinterLigne::update_total", LOG_DEBUG);
1635  $resql=$this->db->query($sql);
1636  if ($resql)
1637  {
1638  $this->db->commit();
1639  return 1;
1640  }
1641  else
1642  {
1643  $this->error=$this->db->error();
1644  $this->db->rollback();
1645  return -2;
1646  }
1647  }
1648  else
1649  {
1650  $this->error=$this->db->error();
1651  $this->db->rollback();
1652  return -1;
1653  }
1654  }
1655 
1663  function deleteline($user,$notrigger=0)
1664  {
1665  global $langs,$conf;
1666 
1667  $error=0;
1668 
1669  if ($this->statut == 0)
1670  {
1671  dol_syslog(get_class($this)."::deleteline lineid=".$this->id);
1672  $this->db->begin();
1673 
1674  $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet WHERE rowid = ".$this->id;
1675  $resql = $this->db->query($sql);
1676 
1677  if ($resql)
1678  {
1679  $result = $this->update_total();
1680  if ($result > 0)
1681  {
1682  if (! $notrigger)
1683  {
1684  // Call trigger
1685  $result=$this->call_trigger('LINEFICHINTER_DELETE',$user);
1686  if ($result < 0) { $error++; $this->db->rollback(); return -1; }
1687  // End call triggers
1688  }
1689 
1690  $this->db->commit();
1691  return $result;
1692  }
1693  else
1694  {
1695  $this->db->rollback();
1696  return -1;
1697  }
1698  }
1699  else
1700  {
1701  $this->error=$this->db->error()." sql=".$sql;
1702  $this->db->rollback();
1703  return -1;
1704  }
1705  }
1706  else
1707  {
1708  return -2;
1709  }
1710  }
1711 }
getLibStatut($mode=0)
Returns the label status.
getAmount()
Returns amount based on user thm.
print
Draft customers invoices.
Definition: index.php:91
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
info($id)
Load information on object.
setDraft($user)
Set status to draft.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='')
Delete all links between an object $this.
addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options='')
Adding a line of intervention into data base.
deleteline($user, $notrigger=0)
Delete a intervention line.
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
create($user, $notrigger=0)
Create an intervention into data base.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
fetch($rowid, $ref='')
Fetch a intervention.
Class to manage interventions.
dol_delete_preview($object)
Delete all preview files linked to object instance.
Definition: files.lib.php:1324
Class to manage Dolibarr users.
Definition: user.class.php:41
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.
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.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
set_date_delivery($user, $date_delivery)
Defines a delivery date of intervention.
createFromClone($socid=0)
Load an object from its id and create a new one in database.
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...
getNomUrl($withpicto=0, $option='', $notooltip=0, $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
initAsSpecimen()
Initialise an instance with random values.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
__construct($db)
Constructor.
__construct($db)
Constructor.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
set_contrat($user, $contractid)
Link intervention to a contract.
update($user, $notrigger=0)
Update intervention into database.
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
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:1273
LibStatut($statut, $mode=0)
Returns the label of a statut.
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:1139
deleteExtraFields()
Delete all extra fields values for the current object.
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:59
dol_now($mode='gmt')
Return date for now.
const STATUS_CLOSED
Closed.
fetch_lines()
Load array lines ->lines.
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...
setValid($user, $notrigger=0)
Validate a intervention.
Classe permettant la gestion des lignes d&#39;intervention.
insert($user, $notrigger=0)
Insert the line into database.
const STATUS_BILLED
Billed.
update_total()
Update total duration into llx_fichinter.
fetch($rowid)
Retrieve the line of intervention.
load_state_board()
Load indicators into this->nb for board.
call_trigger($trigger_name, $user)
Call trigger based on this instance.
add_object_linked($origin=null, $origin_id=null)
Add objects linked in llx_element_element.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)