dolibarr  16.0.5
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 <http://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 $remise;
68  public $tva;
69  public $total;
70 
74  public $propalid;
75 
76  public $date_last_gen;
77  public $date_when;
78 
82  public $nb_gen_done;
83 
87  public $nb_gen_max;
88 
92  public $rang;
93  public $special_code;
94 
95  public $usenewprice = 0;
96 
102  public function __construct($db)
103  {
104  $this->db = $db;
105 
106  //status dans l'ordre de l'intervention
107  $this->statuts[0] = 'Draft';
108  $this->statuts[1] = 'Closed';
109 
110  $this->statuts_short[0] = 'Draft';
111  $this->statuts_short[1] = 'Closed';
112 
113  $this->statuts_logo[0] = 'statut0';
114  $this->statuts_logo[1] = 'statut1';
115  }
116 
123  public function getLibStatut($mode = 0)
124  {
125  return $this->LibStatut($this->statut, $mode);
126  }
127 
128 
136  public function create($user, $notrigger = 0)
137  {
138  global $conf;
139 
140  $error = 0;
141  $now = dol_now();
142 
143  // Clean parameters
144  $this->title = trim($this->title);
145  $this->description = trim($this->description);
146 
147 
148  $this->db->begin();
149 
150  // Load fichinter model
151  $fichintsrc = new Fichinter($this->db);
152 
153  $result = $fichintsrc->fetch($this->id_origin);
154  $result = $fichintsrc->fetch_lines(1); // to get all lines
155 
156 
157  if ($result > 0) {
158  // On positionne en mode brouillon la facture
159  $this->brouillon = 1;
160 
161  $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter_rec (";
162  $sql .= "titre";
163  $sql .= ", fk_soc";
164  $sql .= ", entity";
165  $sql .= ", datec";
166  $sql .= ", duree";
167  $sql .= ", description";
168  $sql .= ", note_private";
169  $sql .= ", note_public";
170  $sql .= ", fk_user_author";
171  $sql .= ", fk_projet";
172  $sql .= ", fk_contrat";
173  $sql .= ", modelpdf";
174 
175  $sql .= ", frequency";
176  $sql .= ", unit_frequency";
177  $sql .= ", date_when";
178  $sql .= ", date_last_gen";
179  $sql .= ", nb_gen_done";
180  $sql .= ", nb_gen_max";
181  // $sql.= ", auto_validate";
182 
183  $sql .= ") VALUES (";
184  $sql .= "'".$this->db->escape($this->title)."'";
185  $sql .= ", ".($this->socid > 0 ? ((int) $this->socid) : 'null');
186  $sql .= ", ".((int) $conf->entity);
187  $sql .= ", '".$this->db->idate($now)."'";
188  $sql .= ", ".(!empty($fichintsrc->duration) ? ((int) $fichintsrc->duration) : '0');
189  $sql .= ", ".(!empty($this->description) ? ("'".$this->db->escape($this->description)."'") : "null");
190  $sql .= ", ".(!empty($fichintsrc->note_private) ? ("'".$this->db->escape($fichintsrc->note_private)."'") : "null");
191  $sql .= ", ".(!empty($fichintsrc->note_public) ? ("'".$this->db->escape($fichintsrc->note_public)."'") : "null");
192  $sql .= ", ".((int) $user->id);
193  // si c'est la même société on conserve les liens vers le projet et le contrat
194  if ($this->socid == $fichintsrc->socid) {
195  $sql .= ", ".(!empty($fichintsrc->fk_project) ? ((int) $fichintsrc->fk_project) : "null");
196  $sql .= ", ".(!empty($fichintsrc->fk_contrat) ? ((int) $fichintsrc->fk_contrat) : "null");
197  } else {
198  $sql .= ", null, null";
199  }
200 
201  $sql .= ", ".(!empty($fichintsrc->model_pdf) ? "'".$this->db->escape($fichintsrc->model_pdf)."'" : "''");
202 
203  // récurrence
204  $sql .= ", ".(!empty($this->frequency) ? ((int) $this->frequency) : "null");
205  $sql .= ", '".$this->db->escape($this->unit_frequency)."'";
206  $sql .= ", ".(!empty($this->date_when) ? "'".$this->db->idate($this->date_when)."'" : 'null');
207  $sql .= ", ".(!empty($this->date_last_gen) ? "'".$this->db->idate($this->date_last_gen)."'" : 'null');
208  $sql .= ", 0"; // we start à 0
209  $sql .= ", ".((int) $this->nb_gen_max);
210  // $sql.= ", ".$this->auto_validate;
211  $sql .= ")";
212 
213  if ($this->db->query($sql)) {
214  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
215 
216  /*
217  * Lines
218  */
219  $num = count($fichintsrc->lines);
220  for ($i = 0; $i < $num; $i++) {
221  //var_dump($fichintsrc->lines[$i]);
222  $result_insert = $this->addline(
223  $fichintsrc->lines[$i]->desc,
224  $fichintsrc->lines[$i]->duration,
225  $fichintsrc->lines[$i]->datei,
226  $fichintsrc->lines[$i]->rang,
227  $fichintsrc->lines[$i]->subprice,
228  $fichintsrc->lines[$i]->qty,
229  $fichintsrc->lines[$i]->tva_tx,
230  $fichintsrc->lines[$i]->fk_product,
231  $fichintsrc->lines[$i]->remise_percent,
232  'HT',
233  0,
234  '',
235  0,
236  $fichintsrc->lines[$i]->product_type,
237  $fichintsrc->lines[$i]->special_code,
238  $fichintsrc->lines[$i]->label,
239  $fichintsrc->lines[$i]->fk_unit
240  );
241 
242  if ($result_insert < 0) {
243  $error++;
244  }
245  }
246 
247  if ($error) {
248  $this->db->rollback();
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 = $obj->model_pdf;
309  $this->modelpdf = $obj->model_pdf; // deprecated
310  $this->rang = $obj->rang;
311  $this->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, ';
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->datei = $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 = $objp->fk_remise_except;
389  $line->fk_product = $objp->fk_product;
390  $line->date_start = $objp->date_start;
391  $line->date_end = $objp->date_end;
392  $line->info_bits = $objp->info_bits;
393  $line->total_ht = $objp->total_ht;
394  $line->total_tva = $objp->total_tva;
395  $line->total_ttc = $objp->total_ttc;
396  $line->code_ventilation = $objp->fk_code_ventilation;
397  $line->rang = $objp->rang;
398  $line->special_code = $objp->special_code;
399  $line->fk_unit = $objp->fk_unit;
400 
401  $this->lines[$i] = $line;
402 
403  $i++;
404  }
405 
406  $this->db->free($result);
407  return 1;
408  } else {
409  $this->error = $this->db->error();
410  return -3;
411  }
412  }
413 
414 
423  public function delete($rowid = 0, $notrigger = 0, $idwarehouse = -1)
424  {
425  if (empty($rowid)) {
426  $rowid = $this->id;
427  }
428 
429  dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG);
430 
431  $error = 0;
432  $this->db->begin();
433 
434  $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet_rec WHERE fk_fichinter = ".((int) $rowid);
435  dol_syslog($sql);
436  if ($this->db->query($sql)) {
437  $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter_rec WHERE rowid = ".((int) $rowid);
438  dol_syslog($sql);
439  if (!$this->db->query($sql)) {
440  $this->error = $this->db->lasterror();
441  $error = -1;
442  }
443  } else {
444  $this->error = $this->db->lasterror();
445  $error = -2;
446  }
447 
448  if (!$error) {
449  $this->db->commit();
450  return 1;
451  } else {
452  $this->db->rollback();
453  return $error;
454  }
455  }
456 
457 
480  public function addline($desc, $duration, $datei, $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)
481  {
482  global $mysoc;
483 
484  include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
485 
486  // Check parameters
487  if ($type < 0) {
488  return -1;
489  }
490 
491  if ($this->brouillon) {
492  // Clean parameters
493  $remise_percent = price2num($remise_percent);
494  $qty = price2num($qty);
495  if (!$qty) {
496  $qty = 1;
497  }
498  if (!$info_bits) {
499  $info_bits = 0;
500  }
501  $pu_ht = price2num($pu_ht);
502  $pu_ttc = price2num($pu_ttc);
503  if (!preg_match('/\((.*)\)/', $txtva)) {
504  $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
505  }
506 
507  if ($price_base_type == 'HT') {
508  $pu = $pu_ht;
509  } else {
510  $pu = $pu_ttc;
511  }
512 
513  // Calcul du total TTC et de la TVA pour la ligne a partir de
514  // qty, pu, remise_percent et txtva
515  // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
516  // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
517  $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, 0, 0, $price_base_type, $info_bits, $type, $mysoc);
518 
519  $total_ht = $tabprice[0];
520  $total_tva = $tabprice[1];
521  $total_ttc = $tabprice[2];
522 
523  $product_type = $type;
524  if ($fk_product) {
525  $product = new Product($this->db);
526  $result = $product->fetch($fk_product);
527  $product_type = $product->type;
528  }
529 
530  $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinterdet_rec (";
531  $sql .= "fk_fichinter";
532  $sql .= ", label";
533  $sql .= ", description";
534  $sql .= ", date";
535  $sql .= ", duree";
536  //$sql.= ", price";
537  //$sql.= ", qty";
538  //$sql.= ", tva_tx";
539  $sql .= ", fk_product";
540  $sql .= ", product_type";
541  $sql .= ", remise_percent";
542  //$sql.= ", subprice";
543  $sql .= ", remise";
544  $sql .= ", total_ht";
545  $sql .= ", total_tva";
546  $sql .= ", total_ttc";
547  $sql .= ", rang";
548  //$sql.= ", special_code";
549  $sql .= ", fk_unit";
550  $sql .= ") VALUES (";
551  $sql .= (int) $this->id;
552  $sql .= ", ".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
553  $sql .= ", ".(!empty($desc) ? "'".$this->db->escape($desc)."'" : "null");
554  $sql .= ", ".(!empty($datei) ? "'".$this->db->idate($datei)."'" : "null");
555  $sql .= ", ".$duration;
556  //$sql.= ", ".price2num($pu_ht);
557  //$sql.= ", ".(!empty($qty)? $qty :(!empty($duration)? $duration :"null"));
558  //$sql.= ", ".price2num($txtva);
559  $sql .= ", ".(!empty($fk_product) ? $fk_product : "null");
560  $sql .= ", ".$product_type;
561  $sql .= ", ".(!empty($remise_percent) ? $remise_percent : "null");
562  //$sql.= ", '".price2num($pu_ht)."'";
563  $sql .= ", null";
564  $sql .= ", '".price2num($total_ht)."'";
565  $sql .= ", '".price2num($total_tva)."'";
566  $sql .= ", '".price2num($total_ttc)."'";
567  $sql .= ", ".(int) $rang;
568  //$sql.= ", ".$special_code;
569  $sql .= ", ".(!empty($fk_unit) ? $fk_unit : "null");
570  $sql .= ")";
571 
572  dol_syslog(get_class($this)."::addline", LOG_DEBUG);
573  if ($this->db->query($sql)) {
574  return 1;
575  } else {
576  $this->error = $this->db->lasterror();
577  return -1;
578  }
579  }
580  }
581 
582 
583  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
592  public function set_auto($user, $freq, $courant)
593  {
594  // phpcs:enable
595  if ($user->rights->fichinter->creer) {
596  $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter_rec ";
597  $sql .= " SET frequency='".$this->db->escape($freq)."'";
598  $sql .= ", date_last_gen='".$this->db->escape($courant)."'";
599  $sql .= " WHERE rowid = ".((int) $this->id);
600 
601  $resql = $this->db->query($sql);
602 
603  if ($resql) {
604  $this->frequency = $freq;
605  $this->date_last_gen = $courant;
606  return 0;
607  } else {
608  dol_print_error($this->db);
609  return -1;
610  }
611  } else {
612  return -2;
613  }
614  }
615 
626  public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '')
627  {
628  global $langs, $hookmanager;
629 
630  $result = '';
631  $label = $langs->trans("ShowInterventionModel").': '.$this->ref;
632 
633  $url = DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$this->id;
634 
635  if ($short) {
636  return $url;
637  }
638 
639  $picto = 'intervention';
640 
641  $link = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
642  $linkend = '</a>';
643 
644  if ($withpicto) {
645  $result .= $link.img_object($label, $picto, 'class="classfortooltip"').$linkend;
646  }
647  if ($withpicto && $withpicto != 2) {
648  $result .= ' ';
649  }
650  if ($withpicto != 2) {
651  $result .= $link.$this->ref.$linkend;
652  }
653  global $action;
654  $hookmanager->initHooks(array($this->element . 'dao'));
655  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
656  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
657  if ($reshook > 0) {
658  $result = $hookmanager->resPrint;
659  } else {
660  $result .= $hookmanager->resPrint;
661  }
662  return $result;
663  }
664 
665 
674  public function initAsSpecimen($option = '')
675  {
676  global $user, $langs, $conf;
677 
678  $now = dol_now();
679  $arraynow = dol_getdate($now);
680  $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
681 
682  parent::initAsSpecimen($option);
683 
684  $this->usenewprice = 1;
685  }
686 
695  public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
696  {
697  $tables = array('fichinter_rec');
698 
699  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
700  }
701 
710  public static function replaceProduct(DoliDB $db, $origin_id, $dest_id)
711  {
712  $tables = array(
713  'fichinterdet_rec'
714  );
715 
716  return CommonObject::commonReplaceProduct($db, $origin_id, $dest_id, $tables);
717  }
718 
726  public function setFrequencyAndUnit($frequency, $unit)
727  {
728  if (!$this->table_element) {
729  dol_syslog(get_class($this)."::setFrequencyAndUnit called with table_element not defined", LOG_ERR);
730  return -1;
731  }
732 
733  if (!empty($frequency) && empty($unit)) {
734  dol_syslog(get_class($this)."::setFrequencyAndUnit called with frequency defined but unit not ", LOG_ERR);
735  return -2;
736  }
737 
738  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
739  $sql .= ' SET frequency = '.($frequency ? $this->db->escape($frequency) : 'null');
740  if (!empty($unit)) {
741  $sql .= ', unit_frequency = "'.$this->db->escape($unit).'"';
742  }
743  $sql .= " WHERE rowid = ".((int) $this->id);
744 
745  dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
746  if ($this->db->query($sql)) {
747  $this->frequency = $frequency;
748  if (!empty($unit)) {
749  $this->unit_frequency = $unit;
750  }
751  return 1;
752  } else {
753  dol_print_error($this->db);
754  return -1;
755  }
756  }
757 
765  public function setNextDate($date, $increment_nb_gen_done = 0)
766  {
767  if (!$this->table_element) {
768  dol_syslog(get_class($this)."::setNextDate was called on objet with property table_element not defined", LOG_ERR);
769  return -1;
770  }
771  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
772  $sql .= " SET date_when = ".($date ? "'".$this->db->idate($date)."'" : "null");
773  if ($increment_nb_gen_done > 0) {
774  $sql .= ', nb_gen_done = nb_gen_done + 1';
775  }
776  $sql .= " WHERE rowid = ".((int) $this->id);
777 
778  dol_syslog(get_class($this)."::setNextDate", LOG_DEBUG);
779  if ($this->db->query($sql)) {
780  $this->date_when = $date;
781  if ($increment_nb_gen_done > 0) {
782  $this->nb_gen_done++;
783  }
784  return 1;
785  } else {
786  dol_print_error($this->db);
787  return -1;
788  }
789  }
790 
797  public function setMaxPeriod($nb)
798  {
799  if (!$this->table_element) {
800  dol_syslog(get_class($this)."::setMaxPeriod was called on objet with property table_element not defined", LOG_ERR);
801  return -1;
802  }
803 
804  if (empty($nb)) {
805  $nb = 0;
806  }
807 
808  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
809  $sql .= ' SET nb_gen_max = '.((int) $nb);
810  $sql .= ' WHERE rowid = '.((int) $this->id);
811 
812  dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
813  if ($this->db->query($sql)) {
814  $this->nb_gen_max = $nb;
815  return 1;
816  } else {
817  dol_print_error($this->db);
818  return -1;
819  }
820  }
821 
828  public function setAutoValidate($validate)
829  {
830  if (!$this->table_element) {
831  dol_syslog(get_class($this)."::setAutoValidate called with property table_element not defined", LOG_ERR);
832  return -1;
833  }
834 
835  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
836  $sql .= ' SET auto_validate = '.((int) $validate);
837  $sql .= ' WHERE rowid = '.((int) $this->id);
838 
839  dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
840  if ($this->db->query($sql)) {
841  $this->auto_validate = $validate;
842  return 1;
843  } else {
844  dol_print_error($this->db);
845  return -1;
846  }
847  }
848 
854  public function updateNbGenDone()
855  {
856  if (!$this->table_element) {
857  dol_syslog(get_class($this)."::updateNbGenDone called with property table_element not defined", LOG_ERR);
858  return -1;
859  }
860 
861  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
862  $sql .= ' SET nb_gen_done = nb_gen_done + 1';
863  $sql .= ' , date_last_gen = now()';
864  // si on et arrivé à la fin des génération
865  if ($this->nb_gen_max == $this->nb_gen_done + 1) {
866  $sql .= ' , statut = 1';
867  }
868 
869  $sql .= " WHERE rowid = ".((int) $this->id);
870 
871  dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
872  if ($this->db->query($sql)) {
873  $this->nb_gen_done = $this->nb_gen_done + 1;
874  $this->nb_gen_done = dol_now();
875  return 1;
876  } else {
877  dol_print_error($this->db);
878  return -1;
879  }
880  }
881 }
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2713
FichinterRec\fetch_lines
fetch_lines($sall=0)
Load all lines of template of intervention into this->lines.
Definition: fichinterrec.class.php:348
db
$conf db
API class for accounts.
Definition: inc.php:41
FichinterRec\$rang
$rang
int rank
Definition: fichinterrec.class.php:92
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:1468
FichinterRec\getLibStatut
getLibStatut($mode=0)
Returns the label status.
Definition: fichinterrec.class.php:123
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:1339
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:4844
FichinterRec\create
create($user, $notrigger=0)
Create a predefined fichinter.
Definition: fichinterrec.class.php:136
FichinterRec
Classe de gestion des factures recurrentes/Modeles.
Definition: fichinterrec.class.php:39
ref
$object ref
Definition: info.php:77
FichinterRec\setMaxPeriod
setMaxPeriod($nb)
Update the maximum period.
Definition: fichinterrec.class.php:797
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:8376
FichinterRec\getNomUrl
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $moretitle='')
Return clicable name (with picto eventually)
Definition: fichinterrec.class.php:626
FichinterRec\set_auto
set_auto($user, $freq, $courant)
Rend la fichinter automatique.
Definition: fichinterrec.class.php:592
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
FichinterRec\fetch
fetch($rowid=0, $ref='', $ref_ext='')
Get the template of intervention object and lines.
Definition: fichinterrec.class.php:273
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:695
FichinterRec\initAsSpecimen
initAsSpecimen($option='')
Initialise an instance with random values.
Definition: fichinterrec.class.php:674
FichinterRec\replaceProduct
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
Definition: fichinterrec.class.php:710
FichinterLigne
Class to manage intervention lines.
Definition: fichinter.class.php:1460
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:8347
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
FichinterRec\updateNbGenDone
updateNbGenDone()
Update the Number of Generation Done.
Definition: fichinterrec.class.php:854
FichinterRec\setAutoValidate
setAutoValidate($validate)
Update the auto validate fichinter.
Definition: fichinterrec.class.php:828
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:726
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
FichinterRec\__construct
__construct($db)
Constructor.
Definition: fichinterrec.class.php:102
FichinterRec\setNextDate
setNextDate($date, $increment_nb_gen_done=0)
Update the next date of execution.
Definition: fichinterrec.class.php:765
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:2757
FichinterRec\addline
addline($desc, $duration, $datei, $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:480