dolibarr  19.0.0-dev
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  return -1;
249  } else {
250  $this->db->commit();
251  return $this->id;
252  }
253  } else {
254  $this->error = $this->db->error().' sql='.$sql;
255  $this->db->rollback();
256  return -2;
257  }
258  } else {
259  $this->db->rollback();
260  return -1;
261  }
262  }
263 
264 
273  public function fetch($rowid = 0, $ref = '', $ref_ext = '')
274  {
275  $sql = 'SELECT f.titre as title, f.fk_soc';
276  $sql .= ', f.datec, f.duree, f.fk_projet, f.fk_contrat, f.description';
277  $sql .= ', f.note_private, f.note_public, f.fk_user_author';
278  $sql .= ', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.auto_validate';
279  $sql .= ', f.note_private, f.note_public, f.fk_user_author';
280  $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinter_rec as f';
281  if ($rowid > 0) {
282  $sql .= " WHERE f.rowid = ".((int) $rowid);
283  } elseif ($ref) {
284  $sql .= " WHERE f.titre = '".$this->db->escape($ref)."'";
285  }
286 
287  dol_syslog(get_class($this)."::fetch rowid=".$rowid, LOG_DEBUG);
288 
289  $result = $this->db->query($sql);
290  if ($result) {
291  if ($this->db->num_rows($result)) {
292  $obj = $this->db->fetch_object($result);
293 
294  $this->id = $rowid;
295  $this->titre = $obj->title;
296  $this->title = $obj->title;
297  $this->ref = $obj->title;
298  $this->description = $obj->description;
299  $this->datec = $obj->datec;
300  $this->duration = $obj->duree;
301  $this->socid = $obj->fk_soc;
302  $this->statut = 0;
303  $this->fk_project = $obj->fk_projet;
304  $this->fk_contrat = $obj->fk_contrat;
305  $this->note_private = $obj->note_private;
306  $this->note_public = $obj->note_public;
307  $this->user_author = $obj->fk_user_author;
308  $this->model_pdf = !empty($obj->model_pdf) ? $obj->model_pdf : "";
309  $this->modelpdf = !empty($obj->model_pdf) ? $obj->model_pdf : ""; // deprecated
310  $this->rang = !empty($obj->rang) ? $obj->rang : "";
311  $this->special_code = !empty($obj->special_code) ? $obj->special_code : "";
312  $this->frequency = $obj->frequency;
313  $this->unit_frequency = $obj->unit_frequency;
314  $this->date_when = $this->db->jdate($obj->date_when);
315  $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
316  $this->nb_gen_done = $obj->nb_gen_done;
317  $this->nb_gen_max = $obj->nb_gen_max;
318  $this->auto_validate = $obj->auto_validate;
319 
320  $this->brouillon = 1;
321 
322  // Lines
323  $result = $this->fetch_lines();
324  if ($result < 0) {
325  $this->error = $this->db->error();
326  return -3;
327  }
328  return 1;
329  } else {
330  $this->error = 'Interventional with id '.$rowid.' not found sql='.$sql;
331  dol_syslog(get_class($this).'::Fetch Error '.$this->error, LOG_ERR);
332  return -2;
333  }
334  } else {
335  $this->error = $this->db->error();
336  return -1;
337  }
338  }
339 
340 
341  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
348  public function fetch_lines($sall = 0)
349  {
350  // phpcs:enable
351  $this->lines = array();
352 
353  $sql = 'SELECT l.rowid, l.fk_product, l.product_type as product_type, l.label as custom_label, l.description,';
354  $sql .= ' l.price, l.qty, l.tva_tx, l.remise_percent, l.subprice, l.duree, l.date,';
355  $sql .= ' l.total_ht, l.total_tva, l.total_ttc,';
356  $sql .= ' l.rang, l.special_code,';
357  $sql .= ' l.fk_unit, p.ref as product_ref, p.fk_product_type as fk_product_type,';
358  $sql .= ' p.label as product_label, p.description as product_desc';
359  $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet_rec as l';
360  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
361  $sql .= ' WHERE l.fk_fichinter = '.((int) $this->id);
362 
363  dol_syslog('FichinterRec::fetch_lines', LOG_DEBUG);
364 
365  $result = $this->db->query($sql);
366  if ($result) {
367  $num = $this->db->num_rows($result);
368  $i = 0;
369  while ($i < $num) {
370  $objp = $this->db->fetch_object($result);
371 
372  $line = new FichinterLigne($this->db);
373  $line->id = $objp->rowid;
374  $line->label = $objp->custom_label; // Label line
375  $line->desc = $objp->description; // Description line
376  $line->product_type = $objp->product_type; // Type of line
377  $line->product_ref = $objp->product_ref; // Ref product
378  $line->product_label = $objp->product_label; // Label product
379  $line->product_desc = $objp->product_desc; // Description product
380  $line->fk_product_type = $objp->fk_product_type; // Type in product
381  $line->qty = $objp->qty;
382  $line->duree = $objp->duree;
383  $line->duration = $objp->duree;
384  $line->date = $objp->date;
385  $line->subprice = $objp->subprice;
386  $line->tva_tx = $objp->tva_tx;
387  $line->remise_percent = $objp->remise_percent;
388  $line->fk_remise_except = !empty($objp->fk_remise_except) ? $objp->fk_remise_except : "";
389  $line->fk_product = $objp->fk_product;
390  $line->info_bits = !empty($objp->info_bits) ? $objp->info_bits : "";
391  $line->total_ht = $objp->total_ht;
392  $line->total_tva = $objp->total_tva;
393  $line->total_ttc = $objp->total_ttc;
394  $line->rang = $objp->rang;
395  $line->special_code = $objp->special_code;
396  $line->fk_unit = $objp->fk_unit;
397 
398  $this->lines[$i] = $line;
399 
400  $i++;
401  }
402 
403  $this->db->free($result);
404  return 1;
405  } else {
406  $this->error = $this->db->error();
407  return -3;
408  }
409  }
410 
411 
419  public function delete(User $user, $notrigger = 0)
420  {
421  $rowid = $this->id;
422 
423  dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG);
424 
425  $error = 0;
426  $this->db->begin();
427 
428  $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet_rec WHERE fk_fichinter = ".((int) $rowid);
429  dol_syslog($sql);
430  if ($this->db->query($sql)) {
431  $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter_rec WHERE rowid = ".((int) $rowid);
432  dol_syslog($sql);
433  if (!$this->db->query($sql)) {
434  $this->error = $this->db->lasterror();
435  $error = -1;
436  }
437  } else {
438  $this->error = $this->db->lasterror();
439  $error = -2;
440  }
441 
442  if (!$error) {
443  $this->db->commit();
444  return 1;
445  } else {
446  $this->db->rollback();
447  return $error;
448  }
449  }
450 
451 
474  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)
475  {
476  global $mysoc;
477 
478  include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
479 
480  // Check parameters
481  if ($type < 0) {
482  $this->error = 'Bad value for parameter type';
483  return -1;
484  }
485 
486  if ($this->brouillon) {
487  // Clean parameters
488  $remise_percent = price2num($remise_percent);
489  $qty = price2num($qty);
490  if (!$qty) {
491  $qty = 1;
492  }
493  if (!$info_bits) {
494  $info_bits = 0;
495  }
496  $pu_ht = price2num($pu_ht);
497  $pu_ttc = price2num($pu_ttc);
498  if (!preg_match('/\‍((.*)\‍)/', $txtva)) {
499  $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
500  }
501 
502  if ($price_base_type == 'HT') {
503  $pu = $pu_ht;
504  } else {
505  $pu = $pu_ttc;
506  }
507 
508  // Calcul du total TTC et de la TVA pour la ligne a partir de
509  // qty, pu, remise_percent et txtva
510  // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
511  // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
512  $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, 0, 0, $price_base_type, $info_bits, $type, $mysoc);
513 
514  $total_ht = $tabprice[0];
515  $total_tva = $tabprice[1];
516  $total_ttc = $tabprice[2];
517 
518  $pu_ht = $tabprice[3];
519 
520  $product_type = $type;
521  if ($fk_product) {
522  $product = new Product($this->db);
523  $result = $product->fetch($fk_product);
524  $product_type = $product->type;
525  }
526 
527  $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinterdet_rec (";
528  $sql .= "fk_fichinter";
529  $sql .= ", label";
530  $sql .= ", description";
531  $sql .= ", date";
532  $sql .= ", duree";
533  //$sql.= ", price";
534  //$sql.= ", qty";
535  //$sql.= ", tva_tx";
536  $sql .= ", fk_product";
537  $sql .= ", product_type";
538  $sql .= ", remise_percent";
539  $sql .= ", subprice";
540  $sql .= ", total_ht";
541  $sql .= ", total_tva";
542  $sql .= ", total_ttc";
543  $sql .= ", rang";
544  //$sql.= ", special_code";
545  $sql .= ", fk_unit";
546  $sql .= ") VALUES (";
547  $sql .= (int) $this->id;
548  $sql .= ", ".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
549  $sql .= ", ".(!empty($desc) ? "'".$this->db->escape($desc)."'" : "null");
550  $sql .= ", ".(!empty($date) ? "'".$this->db->idate($date)."'" : "null");
551  $sql .= ", ".$duration;
552  //$sql.= ", ".price2num($pu_ht);
553  //$sql.= ", ".(!empty($qty)? $qty :(!empty($duration)? $duration :"null"));
554  //$sql.= ", ".price2num($txtva);
555  $sql .= ", ".(!empty($fk_product) ? $fk_product : "null");
556  $sql .= ", ".$product_type;
557  $sql .= ", ".(!empty($remise_percent) ? $remise_percent : "null");
558  $sql.= ", '".price2num($pu_ht)."'";
559  $sql .= ", '".price2num($total_ht)."'";
560  $sql .= ", '".price2num($total_tva)."'";
561  $sql .= ", '".price2num($total_ttc)."'";
562  $sql .= ", ".(int) $rang;
563  //$sql.= ", ".$special_code;
564  $sql .= ", ".(!empty($fk_unit) ? $fk_unit : "null");
565  $sql .= ")";
566 
567  dol_syslog(get_class($this)."::addline", LOG_DEBUG);
568  if ($this->db->query($sql)) {
569  return 1;
570  } else {
571  $this->error = $this->db->lasterror();
572  return -1;
573  }
574  } else {
575  $this->error = 'Bad status of recurring intervention. Must be draft status to allow addition of lines';
576  return -1;
577  }
578  }
579 
580 
581  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
590  public function set_auto($user, $freq, $courant)
591  {
592  // phpcs:enable
593  if ($user->rights->fichinter->creer) {
594  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter_rec ";
595  $sql .= " SET frequency='".$this->db->escape($freq)."'";
596  $sql .= ", date_last_gen='".$this->db->escape($courant)."'";
597  $sql .= " WHERE rowid = ".((int) $this->id);
598 
599  $resql = $this->db->query($sql);
600 
601  if ($resql) {
602  $this->frequency = $freq;
603  $this->date_last_gen = $courant;
604  return 0;
605  } else {
606  dol_print_error($this->db);
607  return -1;
608  }
609  } else {
610  return -2;
611  }
612  }
613 
624  public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '')
625  {
626  global $langs, $hookmanager;
627 
628  $result = '';
629  $label = $langs->trans("ShowInterventionModel").': '.$this->ref;
630 
631  $url = DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$this->id;
632 
633  if ($short) {
634  return $url;
635  }
636 
637  $picto = 'intervention';
638 
639  $link = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
640  $linkend = '</a>';
641 
642  if ($withpicto) {
643  $result .= $link.img_object($label, $picto, 'class="classfortooltip"').$linkend;
644  }
645  if ($withpicto && $withpicto != 2) {
646  $result .= ' ';
647  }
648  if ($withpicto != 2) {
649  $result .= $link.$this->ref.$linkend;
650  }
651  global $action;
652  $hookmanager->initHooks(array($this->element . 'dao'));
653  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
654  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
655  if ($reshook > 0) {
656  $result = $hookmanager->resPrint;
657  } else {
658  $result .= $hookmanager->resPrint;
659  }
660  return $result;
661  }
662 
663 
671  public function initAsSpecimen()
672  {
673  //$now = dol_now();
674  //$arraynow = dol_getdate($now);
675  //$nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
676 
677  parent::initAsSpecimen();
678 
679  $this->usenewprice = 1;
680  }
681 
690  public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
691  {
692  $tables = array('fichinter_rec');
693 
694  return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
695  }
696 
705  public static function replaceProduct(DoliDB $db, $origin_id, $dest_id)
706  {
707  $tables = array(
708  'fichinterdet_rec'
709  );
710 
711  return CommonObject::commonReplaceProduct($db, $origin_id, $dest_id, $tables);
712  }
713 
721  public function setFrequencyAndUnit($frequency, $unit)
722  {
723  if (!$this->table_element) {
724  dol_syslog(get_class($this)."::setFrequencyAndUnit called with table_element not defined", LOG_ERR);
725  return -1;
726  }
727 
728  if (!empty($frequency) && empty($unit)) {
729  dol_syslog(get_class($this)."::setFrequencyAndUnit called with frequency defined but unit not ", LOG_ERR);
730  return -2;
731  }
732 
733  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
734  $sql .= ' SET frequency = '.($frequency ? $this->db->escape($frequency) : 'null');
735  if (!empty($unit)) {
736  $sql .= ', unit_frequency = "'.$this->db->escape($unit).'"';
737  }
738  $sql .= " WHERE rowid = ".((int) $this->id);
739 
740  dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
741  if ($this->db->query($sql)) {
742  $this->frequency = $frequency;
743  if (!empty($unit)) {
744  $this->unit_frequency = $unit;
745  }
746  return 1;
747  } else {
748  dol_print_error($this->db);
749  return -1;
750  }
751  }
752 
760  public function setNextDate($date, $increment_nb_gen_done = 0)
761  {
762  if (!$this->table_element) {
763  dol_syslog(get_class($this)."::setNextDate was called on objet with property table_element not defined", LOG_ERR);
764  return -1;
765  }
766  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
767  $sql .= " SET date_when = ".($date ? "'".$this->db->idate($date)."'" : "null");
768  if ($increment_nb_gen_done > 0) {
769  $sql .= ', nb_gen_done = nb_gen_done + 1';
770  }
771  $sql .= " WHERE rowid = ".((int) $this->id);
772 
773  dol_syslog(get_class($this)."::setNextDate", LOG_DEBUG);
774  if ($this->db->query($sql)) {
775  $this->date_when = $date;
776  if ($increment_nb_gen_done > 0) {
777  $this->nb_gen_done++;
778  }
779  return 1;
780  } else {
781  dol_print_error($this->db);
782  return -1;
783  }
784  }
785 
792  public function setMaxPeriod($nb)
793  {
794  if (!$this->table_element) {
795  dol_syslog(get_class($this)."::setMaxPeriod was called on objet with property table_element not defined", LOG_ERR);
796  return -1;
797  }
798 
799  if (empty($nb)) {
800  $nb = 0;
801  }
802 
803  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
804  $sql .= ' SET nb_gen_max = '.((int) $nb);
805  $sql .= ' WHERE rowid = '.((int) $this->id);
806 
807  dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
808  if ($this->db->query($sql)) {
809  $this->nb_gen_max = $nb;
810  return 1;
811  } else {
812  dol_print_error($this->db);
813  return -1;
814  }
815  }
816 
823  public function setAutoValidate($validate)
824  {
825  if (!$this->table_element) {
826  dol_syslog(get_class($this)."::setAutoValidate called with property table_element not defined", LOG_ERR);
827  return -1;
828  }
829 
830  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
831  $sql .= ' SET auto_validate = '.((int) $validate);
832  $sql .= ' WHERE rowid = '.((int) $this->id);
833 
834  dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
835  if ($this->db->query($sql)) {
836  $this->auto_validate = $validate;
837  return 1;
838  } else {
839  dol_print_error($this->db);
840  return -1;
841  }
842  }
843 
849  public function updateNbGenDone()
850  {
851  if (!$this->table_element) {
852  dol_syslog(get_class($this)."::updateNbGenDone called with property table_element not defined", LOG_ERR);
853  return -1;
854  }
855 
856  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
857  $sql .= ' SET nb_gen_done = nb_gen_done + 1';
858  $sql .= ' , date_last_gen = now()';
859  // si on et arrivé à la fin des génération
860  if ($this->nb_gen_max == $this->nb_gen_done + 1) {
861  $sql .= ' , statut = 1';
862  }
863 
864  $sql .= " WHERE rowid = ".((int) $this->id);
865 
866  dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
867  if ($this->db->query($sql)) {
868  $this->nb_gen_done = $this->nb_gen_done + 1;
869  $this->nb_gen_done = dol_now();
870  return 1;
871  } else {
872  dol_print_error($this->db);
873  return -1;
874  }
875  }
876 }
$object ref
Definition: info.php:78
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
Class to manage Dolibarr database access.
Class to manage interventions.
LibStatut($status, $mode=0)
Returns the label of a status.
fetch_lines()
Load array lines ->lines.
Class to manage intervention lines.
Classe de gestion des factures recurrentes/Modeles.
fetch($rowid=0, $ref='', $ref_ext='')
Get the template of intervention object and lines.
setMaxPeriod($nb)
Update the maximum period.
initAsSpecimen()
Initialise an instance with random values.
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.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $moretitle='')
Return clicable name (with picto eventually)
updateNbGenDone()
Update the Number of Generation Done.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
setFrequencyAndUnit($frequency, $unit)
Update frequency and unit.
create($user, $notrigger=0)
Create a predefined fichinter.
getLibStatut($mode=0)
Returns the label status.
__construct($db)
Constructor.
set_auto($user, $freq, $courant)
Rend la fichinter automatique.
fetch_lines($sall=0)
Load all lines of template of intervention into this->lines.
setAutoValidate($validate)
Update the auto validate fichinter.
setNextDate($date, $increment_nb_gen_done=0)
Update the next date of execution.
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
Class to manage products or services.
Class to manage Dolibarr users.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
Definition: index.php:746
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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