dolibarr  17.0.3
fichinterrec.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
7  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9  * Copyright (C) 2016-2018 Charlie Benke <charlie@patas-monkey.com>
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 
31 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
34 
35 
39 class FichinterRec extends Fichinter
40 {
41  public $element = 'fichinterrec';
42  public $table_element = 'fichinter_rec';
43  public $table_element_line = 'fichinterdet_rec';
44 
48  public $fk_element = 'fk_fichinter';
49 
53  protected $table_ref_field = 'titre';
54 
58  public $picto = 'intervention';
59 
63  public $title;
64  public $number;
65  public $date;
66  public $amount;
67  public $tva;
68  public $total;
69 
73  public $propalid;
74 
75  public $date_last_gen;
76  public $date_when;
77 
81  public $nb_gen_done;
82 
86  public $nb_gen_max;
87 
91  public $rang;
92  public $special_code;
93 
94  public $usenewprice = 0;
95 
101  public function __construct($db)
102  {
103  $this->db = $db;
104 
105  //status dans l'ordre de l'intervention
106  $this->statuts[0] = 'Draft';
107  $this->statuts[1] = 'Closed';
108 
109  $this->statuts_short[0] = 'Draft';
110  $this->statuts_short[1] = 'Closed';
111 
112  $this->statuts_logo[0] = 'statut0';
113  $this->statuts_logo[1] = 'statut1';
114  }
115 
122  public function getLibStatut($mode = 0)
123  {
124  return $this->LibStatut($this->statut, $mode);
125  }
126 
127 
135  public function create($user, $notrigger = 0)
136  {
137  global $conf;
138 
139  $error = 0;
140  $now = dol_now();
141 
142  // Clean parameters
143  $this->title = trim($this->title);
144  $this->description = trim($this->description);
145 
146 
147  $this->db->begin();
148 
149  // Load fichinter model
150  $fichintsrc = new Fichinter($this->db);
151 
152  $result = $fichintsrc->fetch($this->id_origin);
153  $result = $fichintsrc->fetch_lines(); // to get all lines
154 
155 
156  if ($result > 0) {
157  // On positionne en mode brouillon la facture
158  $this->brouillon = 1;
159 
160  $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter_rec (";
161  $sql .= "titre";
162  $sql .= ", fk_soc";
163  $sql .= ", entity";
164  $sql .= ", datec";
165  $sql .= ", duree";
166  $sql .= ", description";
167  $sql .= ", note_private";
168  $sql .= ", note_public";
169  $sql .= ", fk_user_author";
170  $sql .= ", fk_projet";
171  $sql .= ", fk_contrat";
172  $sql .= ", modelpdf";
173 
174  $sql .= ", frequency";
175  $sql .= ", unit_frequency";
176  $sql .= ", date_when";
177  $sql .= ", date_last_gen";
178  $sql .= ", nb_gen_done";
179  $sql .= ", nb_gen_max";
180  // $sql.= ", auto_validate";
181 
182  $sql .= ") VALUES (";
183  $sql .= "'".$this->db->escape($this->title)."'";
184  $sql .= ", ".($this->socid > 0 ? ((int) $this->socid) : 'null');
185  $sql .= ", ".((int) $conf->entity);
186  $sql .= ", '".$this->db->idate($now)."'";
187  $sql .= ", ".(!empty($fichintsrc->duration) ? ((int) $fichintsrc->duration) : '0');
188  $sql .= ", ".(!empty($this->description) ? ("'".$this->db->escape($this->description)."'") : "null");
189  $sql .= ", ".(!empty($fichintsrc->note_private) ? ("'".$this->db->escape($fichintsrc->note_private)."'") : "null");
190  $sql .= ", ".(!empty($fichintsrc->note_public) ? ("'".$this->db->escape($fichintsrc->note_public)."'") : "null");
191  $sql .= ", ".((int) $user->id);
192  // si c'est la même société on conserve les liens vers le projet et le contrat
193  if ($this->socid == $fichintsrc->socid) {
194  $sql .= ", ".(!empty($fichintsrc->fk_project) ? ((int) $fichintsrc->fk_project) : "null");
195  $sql .= ", ".(!empty($fichintsrc->fk_contrat) ? ((int) $fichintsrc->fk_contrat) : "null");
196  } else {
197  $sql .= ", null, null";
198  }
199 
200  $sql .= ", ".(!empty($fichintsrc->model_pdf) ? "'".$this->db->escape($fichintsrc->model_pdf)."'" : "''");
201 
202  // récurrence
203  $sql .= ", ".(!empty($this->frequency) ? ((int) $this->frequency) : "null");
204  $sql .= ", '".$this->db->escape($this->unit_frequency)."'";
205  $sql .= ", ".(!empty($this->date_when) ? "'".$this->db->idate($this->date_when)."'" : 'null');
206  $sql .= ", ".(!empty($this->date_last_gen) ? "'".$this->db->idate($this->date_last_gen)."'" : 'null');
207  $sql .= ", 0"; // we start à 0
208  $sql .= ", ".((int) $this->nb_gen_max);
209  // $sql.= ", ".$this->auto_validate;
210  $sql .= ")";
211 
212  if ($this->db->query($sql)) {
213  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
214 
215  /*
216  * Lines
217  */
218  $num = count($fichintsrc->lines);
219  for ($i = 0; $i < $num; $i++) {
220  //var_dump($fichintsrc->lines[$i]);
221  $result_insert = $this->addline(
222  $fichintsrc->lines[$i]->desc,
223  $fichintsrc->lines[$i]->duration,
224  $fichintsrc->lines[$i]->date,
225  $fichintsrc->lines[$i]->rang,
226  $fichintsrc->lines[$i]->subprice,
227  $fichintsrc->lines[$i]->qty,
228  $fichintsrc->lines[$i]->tva_tx,
229  $fichintsrc->lines[$i]->fk_product,
230  $fichintsrc->lines[$i]->remise_percent,
231  'HT',
232  0,
233  '',
234  0,
235  $fichintsrc->lines[$i]->product_type,
236  $fichintsrc->lines[$i]->special_code,
237  !empty($fichintsrc->lines[$i]->label) ? $fichintsrc->lines[$i]->label : "",
238  $fichintsrc->lines[$i]->fk_unit
239  );
240 
241  if ($result_insert < 0) {
242  $error++;
243  }
244  }
245 
246  if ($error) {
247  $this->db->rollback();
248  } else {
249  $this->db->commit();
250  return $this->id;
251  }
252  } else {
253  $this->error = $this->db->error().' sql='.$sql;
254  $this->db->rollback();
255  return -2;
256  }
257  } else {
258  $this->db->rollback();
259  return -1;
260  }
261  }
262 
263 
272  public function fetch($rowid = 0, $ref = '', $ref_ext = '')
273  {
274  $sql = 'SELECT f.titre as title, f.fk_soc';
275  $sql .= ', f.datec, f.duree, f.fk_projet, f.fk_contrat, f.description';
276  $sql .= ', f.note_private, f.note_public, f.fk_user_author';
277  $sql .= ', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.auto_validate';
278  $sql .= ', f.note_private, f.note_public, f.fk_user_author';
279  $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinter_rec as f';
280  if ($rowid > 0) {
281  $sql .= " WHERE f.rowid = ".((int) $rowid);
282  } elseif ($ref) {
283  $sql .= " WHERE f.titre = '".$this->db->escape($ref)."'";
284  }
285 
286  dol_syslog(get_class($this)."::fetch rowid=".$rowid, LOG_DEBUG);
287 
288  $result = $this->db->query($sql);
289  if ($result) {
290  if ($this->db->num_rows($result)) {
291  $obj = $this->db->fetch_object($result);
292 
293  $this->id = $rowid;
294  $this->titre = $obj->title;
295  $this->title = $obj->title;
296  $this->ref = $obj->title;
297  $this->description = $obj->description;
298  $this->datec = $obj->datec;
299  $this->duration = $obj->duree;
300  $this->socid = $obj->fk_soc;
301  $this->statut = 0;
302  $this->fk_project = $obj->fk_projet;
303  $this->fk_contrat = $obj->fk_contrat;
304  $this->note_private = $obj->note_private;
305  $this->note_public = $obj->note_public;
306  $this->user_author = $obj->fk_user_author;
307  $this->model_pdf = !empty($obj->model_pdf) ? $obj->model_pdf : "";
308  $this->modelpdf = !empty($obj->model_pdf) ? $obj->model_pdf : ""; // deprecated
309  $this->rang = !empty($obj->rang) ? $obj->rang : "";
310  $this->special_code = !empty($obj->special_code) ? $obj->special_code : "";
311  $this->frequency = $obj->frequency;
312  $this->unit_frequency = $obj->unit_frequency;
313  $this->date_when = $this->db->jdate($obj->date_when);
314  $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
315  $this->nb_gen_done = $obj->nb_gen_done;
316  $this->nb_gen_max = $obj->nb_gen_max;
317  $this->auto_validate = $obj->auto_validate;
318 
319  $this->brouillon = 1;
320 
321  // Lines
322  $result = $this->fetch_lines();
323  if ($result < 0) {
324  $this->error = $this->db->error();
325  return -3;
326  }
327  return 1;
328  } else {
329  $this->error = 'Interventional with id '.$rowid.' not found sql='.$sql;
330  dol_syslog(get_class($this).'::Fetch Error '.$this->error, LOG_ERR);
331  return -2;
332  }
333  } else {
334  $this->error = $this->db->error();
335  return -1;
336  }
337  }
338 
339 
340  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
347  public function fetch_lines($sall = 0)
348  {
349  // phpcs:enable
350  $this->lines = array();
351 
352  $sql = 'SELECT l.rowid, l.fk_product, l.product_type as product_type, l.label as custom_label, l.description,';
353  $sql .= ' l.price, l.qty, l.tva_tx, l.remise_percent, l.subprice, l.duree, l.date,';
354  $sql .= ' l.total_ht, l.total_tva, l.total_ttc,';
355  $sql .= ' l.rang, l.special_code,';
356  $sql .= ' l.fk_unit, p.ref as product_ref, p.fk_product_type as fk_product_type,';
357  $sql .= ' p.label as product_label, p.description as product_desc';
358  $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet_rec as l';
359  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
360  $sql .= ' WHERE l.fk_fichinter = '.((int) $this->id);
361 
362  dol_syslog('FichinterRec::fetch_lines', LOG_DEBUG);
363 
364  $result = $this->db->query($sql);
365  if ($result) {
366  $num = $this->db->num_rows($result);
367  $i = 0;
368  while ($i < $num) {
369  $objp = $this->db->fetch_object($result);
370 
371  $line = new FichinterLigne($this->db);
372  $line->id = $objp->rowid;
373  $line->label = $objp->custom_label; // Label line
374  $line->desc = $objp->description; // Description line
375  $line->product_type = $objp->product_type; // Type of line
376  $line->product_ref = $objp->product_ref; // Ref product
377  $line->product_label = $objp->product_label; // Label product
378  $line->product_desc = $objp->product_desc; // Description product
379  $line->fk_product_type = $objp->fk_product_type; // Type in product
380  $line->qty = $objp->qty;
381  $line->duree = $objp->duree;
382  $line->duration = $objp->duree;
383  $line->date = $objp->date;
384  $line->subprice = $objp->subprice;
385  $line->tva_tx = $objp->tva_tx;
386  $line->remise_percent = $objp->remise_percent;
387  $line->fk_remise_except = !empty($objp->fk_remise_except) ? $objp->fk_remise_except : "";
388  $line->fk_product = $objp->fk_product;
389  $line->info_bits = !empty($objp->info_bits) ? $objp->info_bits : "";
390  $line->total_ht = $objp->total_ht;
391  $line->total_tva = $objp->total_tva;
392  $line->total_ttc = $objp->total_ttc;
393  $line->rang = $objp->rang;
394  $line->special_code = $objp->special_code;
395  $line->fk_unit = $objp->fk_unit;
396 
397  $this->lines[$i] = $line;
398 
399  $i++;
400  }
401 
402  $this->db->free($result);
403  return 1;
404  } else {
405  $this->error = $this->db->error();
406  return -3;
407  }
408  }
409 
410 
419  public function delete($rowid = 0, $notrigger = 0, $idwarehouse = -1)
420  {
421  if (empty($rowid)) {
422  $rowid = $this->id;
423  }
424 
425  dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG);
426 
427  $error = 0;
428  $this->db->begin();
429 
430  $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet_rec WHERE fk_fichinter = ".((int) $rowid);
431  dol_syslog($sql);
432  if ($this->db->query($sql)) {
433  $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter_rec WHERE rowid = ".((int) $rowid);
434  dol_syslog($sql);
435  if (!$this->db->query($sql)) {
436  $this->error = $this->db->lasterror();
437  $error = -1;
438  }
439  } else {
440  $this->error = $this->db->lasterror();
441  $error = -2;
442  }
443 
444  if (!$error) {
445  $this->db->commit();
446  return 1;
447  } else {
448  $this->db->rollback();
449  return $error;
450  }
451  }
452 
453 
476  public function addline($desc, $duration, $date, $rang = -1, $pu_ht = 0, $qty = 0, $txtva = 0, $fk_product = 0, $remise_percent = 0, $price_base_type = 'HT', $info_bits = 0, $fk_remise_except = '', $pu_ttc = 0, $type = 0, $special_code = 0, $label = '', $fk_unit = null)
477  {
478  global $mysoc;
479 
480  include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
481 
482  // Check parameters
483  if ($type < 0) {
484  return -1;
485  }
486 
487  if ($this->brouillon) {
488  // Clean parameters
489  $remise_percent = price2num($remise_percent);
490  $qty = price2num($qty);
491  if (!$qty) {
492  $qty = 1;
493  }
494  if (!$info_bits) {
495  $info_bits = 0;
496  }
497  $pu_ht = price2num($pu_ht);
498  $pu_ttc = price2num($pu_ttc);
499  if (!preg_match('/\((.*)\)/', $txtva)) {
500  $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
501  }
502 
503  if ($price_base_type == 'HT') {
504  $pu = $pu_ht;
505  } else {
506  $pu = $pu_ttc;
507  }
508 
509  // Calcul du total TTC et de la TVA pour la ligne a partir de
510  // qty, pu, remise_percent et txtva
511  // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
512  // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
513  $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, 0, 0, $price_base_type, $info_bits, $type, $mysoc);
514 
515  $total_ht = $tabprice[0];
516  $total_tva = $tabprice[1];
517  $total_ttc = $tabprice[2];
518 
519  $pu_ht = $tabprice[3];
520 
521  $product_type = $type;
522  if ($fk_product) {
523  $product = new Product($this->db);
524  $result = $product->fetch($fk_product);
525  $product_type = $product->type;
526  }
527 
528  $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinterdet_rec (";
529  $sql .= "fk_fichinter";
530  $sql .= ", label";
531  $sql .= ", description";
532  $sql .= ", date";
533  $sql .= ", duree";
534  //$sql.= ", price";
535  //$sql.= ", qty";
536  //$sql.= ", tva_tx";
537  $sql .= ", fk_product";
538  $sql .= ", product_type";
539  $sql .= ", remise_percent";
540  $sql .= ", subprice";
541  $sql .= ", total_ht";
542  $sql .= ", total_tva";
543  $sql .= ", total_ttc";
544  $sql .= ", rang";
545  //$sql.= ", special_code";
546  $sql .= ", fk_unit";
547  $sql .= ") VALUES (";
548  $sql .= (int) $this->id;
549  $sql .= ", ".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
550  $sql .= ", ".(!empty($desc) ? "'".$this->db->escape($desc)."'" : "null");
551  $sql .= ", ".(!empty($date) ? "'".$this->db->idate($date)."'" : "null");
552  $sql .= ", ".$duration;
553  //$sql.= ", ".price2num($pu_ht);
554  //$sql.= ", ".(!empty($qty)? $qty :(!empty($duration)? $duration :"null"));
555  //$sql.= ", ".price2num($txtva);
556  $sql .= ", ".(!empty($fk_product) ? $fk_product : "null");
557  $sql .= ", ".$product_type;
558  $sql .= ", ".(!empty($remise_percent) ? $remise_percent : "null");
559  $sql.= ", '".price2num($pu_ht)."'";
560  $sql .= ", '".price2num($total_ht)."'";
561  $sql .= ", '".price2num($total_tva)."'";
562  $sql .= ", '".price2num($total_ttc)."'";
563  $sql .= ", ".(int) $rang;
564  //$sql.= ", ".$special_code;
565  $sql .= ", ".(!empty($fk_unit) ? $fk_unit : "null");
566  $sql .= ")";
567 
568  dol_syslog(get_class($this)."::addline", LOG_DEBUG);
569  if ($this->db->query($sql)) {
570  return 1;
571  } else {
572  $this->error = $this->db->lasterror();
573  return -1;
574  }
575  }
576  }
577 
578 
579  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
588  public function set_auto($user, $freq, $courant)
589  {
590  // phpcs:enable
591  if ($user->rights->fichinter->creer) {
592  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter_rec ";
593  $sql .= " SET frequency='".$this->db->escape($freq)."'";
594  $sql .= ", date_last_gen='".$this->db->escape($courant)."'";
595  $sql .= " WHERE rowid = ".((int) $this->id);
596 
597  $resql = $this->db->query($sql);
598 
599  if ($resql) {
600  $this->frequency = $freq;
601  $this->date_last_gen = $courant;
602  return 0;
603  } else {
604  dol_print_error($this->db);
605  return -1;
606  }
607  } else {
608  return -2;
609  }
610  }
611 
622  public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '')
623  {
624  global $langs, $hookmanager;
625 
626  $result = '';
627  $label = $langs->trans("ShowInterventionModel").': '.$this->ref;
628 
629  $url = DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$this->id;
630 
631  if ($short) {
632  return $url;
633  }
634 
635  $picto = 'intervention';
636 
637  $link = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
638  $linkend = '</a>';
639 
640  if ($withpicto) {
641  $result .= $link.img_object($label, $picto, 'class="classfortooltip"').$linkend;
642  }
643  if ($withpicto && $withpicto != 2) {
644  $result .= ' ';
645  }
646  if ($withpicto != 2) {
647  $result .= $link.$this->ref.$linkend;
648  }
649  global $action;
650  $hookmanager->initHooks(array($this->element . 'dao'));
651  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
652  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
653  if ($reshook > 0) {
654  $result = $hookmanager->resPrint;
655  } else {
656  $result .= $hookmanager->resPrint;
657  }
658  return $result;
659  }
660 
661 
670  public function initAsSpecimen($option = '')
671  {
672  global $user, $langs, $conf;
673 
674  $now = dol_now();
675  $arraynow = dol_getdate($now);
676  $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
677 
678  parent::initAsSpecimen($option);
679 
680  $this->usenewprice = 1;
681  }
682 
691  public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
692  {
693  $tables = array('fichinter_rec');
694 
695  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
696  }
697 
706  public static function replaceProduct(DoliDB $db, $origin_id, $dest_id)
707  {
708  $tables = array(
709  'fichinterdet_rec'
710  );
711 
712  return CommonObject::commonReplaceProduct($db, $origin_id, $dest_id, $tables);
713  }
714 
722  public function setFrequencyAndUnit($frequency, $unit)
723  {
724  if (!$this->table_element) {
725  dol_syslog(get_class($this)."::setFrequencyAndUnit called with table_element not defined", LOG_ERR);
726  return -1;
727  }
728 
729  if (!empty($frequency) && empty($unit)) {
730  dol_syslog(get_class($this)."::setFrequencyAndUnit called with frequency defined but unit not ", LOG_ERR);
731  return -2;
732  }
733 
734  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
735  $sql .= ' SET frequency = '.($frequency ? $this->db->escape($frequency) : 'null');
736  if (!empty($unit)) {
737  $sql .= ', unit_frequency = "'.$this->db->escape($unit).'"';
738  }
739  $sql .= " WHERE rowid = ".((int) $this->id);
740 
741  dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
742  if ($this->db->query($sql)) {
743  $this->frequency = $frequency;
744  if (!empty($unit)) {
745  $this->unit_frequency = $unit;
746  }
747  return 1;
748  } else {
749  dol_print_error($this->db);
750  return -1;
751  }
752  }
753 
761  public function setNextDate($date, $increment_nb_gen_done = 0)
762  {
763  if (!$this->table_element) {
764  dol_syslog(get_class($this)."::setNextDate was called on objet with property table_element not defined", LOG_ERR);
765  return -1;
766  }
767  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
768  $sql .= " SET date_when = ".($date ? "'".$this->db->idate($date)."'" : "null");
769  if ($increment_nb_gen_done > 0) {
770  $sql .= ', nb_gen_done = nb_gen_done + 1';
771  }
772  $sql .= " WHERE rowid = ".((int) $this->id);
773 
774  dol_syslog(get_class($this)."::setNextDate", LOG_DEBUG);
775  if ($this->db->query($sql)) {
776  $this->date_when = $date;
777  if ($increment_nb_gen_done > 0) {
778  $this->nb_gen_done++;
779  }
780  return 1;
781  } else {
782  dol_print_error($this->db);
783  return -1;
784  }
785  }
786 
793  public function setMaxPeriod($nb)
794  {
795  if (!$this->table_element) {
796  dol_syslog(get_class($this)."::setMaxPeriod was called on objet with property table_element not defined", LOG_ERR);
797  return -1;
798  }
799 
800  if (empty($nb)) {
801  $nb = 0;
802  }
803 
804  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
805  $sql .= ' SET nb_gen_max = '.((int) $nb);
806  $sql .= ' WHERE rowid = '.((int) $this->id);
807 
808  dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
809  if ($this->db->query($sql)) {
810  $this->nb_gen_max = $nb;
811  return 1;
812  } else {
813  dol_print_error($this->db);
814  return -1;
815  }
816  }
817 
824  public function setAutoValidate($validate)
825  {
826  if (!$this->table_element) {
827  dol_syslog(get_class($this)."::setAutoValidate called with property table_element not defined", LOG_ERR);
828  return -1;
829  }
830 
831  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
832  $sql .= ' SET auto_validate = '.((int) $validate);
833  $sql .= ' WHERE rowid = '.((int) $this->id);
834 
835  dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
836  if ($this->db->query($sql)) {
837  $this->auto_validate = $validate;
838  return 1;
839  } else {
840  dol_print_error($this->db);
841  return -1;
842  }
843  }
844 
850  public function updateNbGenDone()
851  {
852  if (!$this->table_element) {
853  dol_syslog(get_class($this)."::updateNbGenDone called with property table_element not defined", LOG_ERR);
854  return -1;
855  }
856 
857  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
858  $sql .= ' SET nb_gen_done = nb_gen_done + 1';
859  $sql .= ' , date_last_gen = now()';
860  // si on et arrivé à la fin des génération
861  if ($this->nb_gen_max == $this->nb_gen_done + 1) {
862  $sql .= ' , statut = 1';
863  }
864 
865  $sql .= " WHERE rowid = ".((int) $this->id);
866 
867  dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
868  if ($this->db->query($sql)) {
869  $this->nb_gen_done = $this->nb_gen_done + 1;
870  $this->nb_gen_done = dol_now();
871  return 1;
872  } else {
873  dol_print_error($this->db);
874  return -1;
875  }
876  }
877 }
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2820
FichinterRec\fetch_lines
fetch_lines($sall=0)
Load all lines of template of intervention into this->lines.
Definition: fichinterrec.class.php:347
db
$conf db
API class for accounts.
Definition: inc.php:41
FichinterRec\$rang
$rang
int rank
Definition: fichinterrec.class.php:91
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1493
FichinterRec\getLibStatut
getLibStatut($mode=0)
Returns the label status.
Definition: fichinterrec.class.php:122
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
Fichinter\fetch_lines
fetch_lines()
Load array lines ->lines.
Definition: fichinter.class.php:1341
Fichinter\LibStatut
LibStatut($status, $mode=0)
Returns the label of a status.
Definition: fichinter.class.php:746
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4993
ref
$object ref
Definition: info.php:78
FichinterRec\create
create($user, $notrigger=0)
Create a predefined fichinter.
Definition: fichinterrec.class.php:135
FichinterRec
Classe de gestion des factures recurrentes/Modeles.
Definition: fichinterrec.class.php:39
FichinterRec\setMaxPeriod
setMaxPeriod($nb)
Update the maximum period.
Definition: fichinterrec.class.php:793
FichinterRec\$table_ref_field
$table_ref_field
{}
Definition: fichinterrec.class.php:53
CommonObject\commonReplaceProduct
static commonReplaceProduct(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
Definition: commonobject.class.php:8528
FichinterRec\getNomUrl
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $moretitle='')
Return clicable name (with picto eventually)
Definition: fichinterrec.class.php:622
FichinterRec\addline
addline($desc, $duration, $date, $rang=-1, $pu_ht=0, $qty=0, $txtva=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $special_code=0, $label='', $fk_unit=null)
Add a line to fichinter rec.
Definition: fichinterrec.class.php:476
FichinterRec\set_auto
set_auto($user, $freq, $courant)
Rend la fichinter automatique.
Definition: fichinterrec.class.php:588
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5823
FichinterRec\fetch
fetch($rowid=0, $ref='', $ref_ext='')
Get the template of intervention object and lines.
Definition: fichinterrec.class.php:272
calcul_price_total
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array='', $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
Definition: price.lib.php:86
FichinterRec\replaceThirdparty
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
Definition: fichinterrec.class.php:691
FichinterRec\initAsSpecimen
initAsSpecimen($option='')
Initialise an instance with random values.
Definition: fichinterrec.class.php:670
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
FichinterRec\replaceProduct
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
Definition: fichinterrec.class.php:706
FichinterLigne
Class to manage intervention lines.
Definition: fichinter.class.php:1463
CommonObject\commonReplaceThirdparty
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
Definition: commonobject.class.php:8499
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628
FichinterRec\updateNbGenDone
updateNbGenDone()
Update the Number of Generation Done.
Definition: fichinterrec.class.php:850
FichinterRec\setAutoValidate
setAutoValidate($validate)
Update the auto validate fichinter.
Definition: fichinterrec.class.php:824
Fichinter
Class to manage interventions.
Definition: fichinter.class.php:37
Product
Class to manage products or services.
Definition: product.class.php:46
FichinterRec\setFrequencyAndUnit
setFrequencyAndUnit($frequency, $unit)
Update frequency and unit.
Definition: fichinterrec.class.php:722
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2951
FichinterRec\__construct
__construct($db)
Constructor.
Definition: fichinterrec.class.php:101
FichinterRec\setNextDate
setNextDate($date, $increment_nb_gen_done=0)
Update the next date of execution.
Definition: fichinterrec.class.php:761
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2863