dolibarr  9.0.0
facture-rec.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@inodbox.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) 2017 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 
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.'/compta/facture/class/facture.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35 
36 
41 {
45  public $element='facturerec';
46 
50  public $table_element='facture_rec';
51 
55  public $table_element_line='facturedet_rec';
56 
60  public $fk_element='fk_facture';
61 
65  public $picto='bill';
66 
70  public $entity;
71 
72  public $number;
73  public $date;
74  public $amount;
75  public $remise;
76  public $tva;
77  public $total;
78  public $db_table;
79  public $propalid;
80 
81  public $date_last_gen;
82  public $date_when;
83  public $nb_gen_done;
84  public $nb_gen_max;
85 
86  public $frequency;
87  public $unit_frequency;
88 
89  public $rang;
90  public $special_code;
91 
92  public $usenewprice=0;
93 
94  public $suspended; // status
95 
96  const STATUS_NOTSUSPENDED = 0;
97  const STATUS_SUSPENDED = 1;
98 
99 
100 
106  function __construct($db)
107  {
108  $this->db = $db;
109  }
110 
118  function create($user, $facid)
119  {
120  global $conf;
121 
122  $error=0;
123  $now=dol_now();
124 
125  // Clean parameters
126  $this->titre=trim($this->titre);
127  $this->usenewprice=empty($this->usenewprice)?0:$this->usenewprice;
128  if (empty($this->suspended)) $this->suspended=0;
129 
130  // No frequency defined then no next date to execution
131  if (empty($this->frequency))
132  {
133  $this->frequency=0;
134  $this->date_when=null;
135  }
136 
137 
138  $this->frequency=abs($this->frequency);
139  $this->nb_gen_done=0;
140  $this->nb_gen_max=empty($this->nb_gen_max)?0:$this->nb_gen_max;
141  $this->auto_validate=empty($this->auto_validate)?0:$this->auto_validate;
142  $this->generate_pdf = empty($this->generate_pdf)?0:$this->generate_pdf;
143 
144  $this->db->begin();
145 
146  // Charge facture modele
147  $facsrc=new Facture($this->db);
148  $result=$facsrc->fetch($facid);
149  if ($result > 0)
150  {
151  // On positionne en mode brouillon la facture
152  $this->brouillon = 1;
153 
154  $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec (";
155  $sql.= "titre";
156  $sql.= ", fk_soc";
157  $sql.= ", entity";
158  $sql.= ", datec";
159  $sql.= ", amount";
160  $sql.= ", remise";
161  $sql.= ", note_private";
162  $sql.= ", note_public";
163  $sql.= ", modelpdf";
164  $sql.= ", fk_user_author";
165  $sql.= ", fk_projet";
166  $sql.= ", fk_account";
167  $sql.= ", fk_cond_reglement";
168  $sql.= ", fk_mode_reglement";
169  $sql.= ", usenewprice";
170  $sql.= ", frequency";
171  $sql.= ", unit_frequency";
172  $sql.= ", date_when";
173  $sql.= ", date_last_gen";
174  $sql.= ", nb_gen_done";
175  $sql.= ", nb_gen_max";
176  $sql.= ", auto_validate";
177  $sql.= ", generate_pdf";
178  $sql.= ", fk_multicurrency";
179  $sql.= ", multicurrency_code";
180  $sql.= ", multicurrency_tx";
181  $sql.= ", suspended";
182  $sql.= ") VALUES (";
183  $sql.= "'".$this->db->escape($this->titre)."'";
184  $sql.= ", ".$facsrc->socid;
185  $sql.= ", ".$conf->entity;
186  $sql.= ", '".$this->db->idate($now)."'";
187  $sql.= ", ".(!empty($facsrc->amount)?$facsrc->amount:'0');
188  $sql.= ", ".(!empty($facsrc->remise)?$this->remise:'0');
189  $sql.= ", ".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL");
190  $sql.= ", ".(!empty($this->note_public)?("'".$this->db->escape($this->note_public)."'"):"NULL");
191  $sql.= ", ".(!empty($this->modelpdf)?("'".$this->db->escape($this->modelpdf)."'"):"NULL");
192  $sql.= ", '".$this->db->escape($user->id)."'";
193  $sql.= ", ".(! empty($facsrc->fk_project)?"'".$facsrc->fk_project."'":"null");
194  $sql.= ", ".(! empty($facsrc->fk_account)?"'".$facsrc->fk_account."'":"null");
195  $sql.= ", ".($facsrc->cond_reglement_id > 0 ? $this->db->escape($facsrc->cond_reglement_id) : "null");
196  $sql.= ", ".($facsrc->mode_reglement_id > 0 ? $this->db->escape($facsrc->mode_reglement_id) : "null");
197  $sql.= ", ".$this->usenewprice;
198  $sql.= ", ".$this->frequency;
199  $sql.= ", '".$this->db->escape($this->unit_frequency)."'";
200  $sql.= ", ".(!empty($this->date_when)?"'".$this->db->idate($this->date_when)."'":'NULL');
201  $sql.= ", ".(!empty($this->date_last_gen)?"'".$this->db->idate($this->date_last_gen)."'":'NULL');
202  $sql.= ", ".$this->db->escape($this->nb_gen_done);
203  $sql.= ", ".$this->db->escape($this->nb_gen_max);
204  $sql.= ", ".$this->db->escape($this->auto_validate);
205  $sql.= ", ".$this->db->escape($this->generate_pdf);
206  $sql.= ", ".$this->db->escape($facsrc->fk_multicurrency);
207  $sql.= ", '".$this->db->escape($facsrc->multicurrency_code)."'";
208  $sql.= ", ".$this->db->escape($facsrc->multicurrency_tx);
209  $sql.= ", ".$this->db->escape($this->suspended);
210  $sql.= ")";
211 
212  if ($this->db->query($sql))
213  {
214  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_rec");
215 
216  // Fields used into addline later
217  $this->fk_multicurrency = $facsrc->fk_multicurrency;
218  $this->multicurrency_code = $facsrc->multicurrency_code;
219  $this->multicurrency_tx = $facsrc->multicurrency_tx;
220 
221  // Add lines
222  $num=count($facsrc->lines);
223  for ($i = 0; $i < $num; $i++)
224  {
225  $tva_tx = $facsrc->lines[$i]->tva_tx;
226  if (! empty($facsrc->lines[$i]->vat_src_code) && ! preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$facsrc->lines[$i]->vat_src_code.')';
227 
228  $result_insert = $this->addline(
229  $facsrc->lines[$i]->desc,
230  $facsrc->lines[$i]->subprice,
231  $facsrc->lines[$i]->qty,
232  $tva_tx,
233  $facsrc->lines[$i]->localtax1_tx,
234  $facsrc->lines[$i]->localtax2_tx,
235  $facsrc->lines[$i]->fk_product,
236  $facsrc->lines[$i]->remise_percent,
237  'HT',
238  $facsrc->lines[$i]->info_bits,
239  '',
240  0,
241  $facsrc->lines[$i]->product_type,
242  $facsrc->lines[$i]->rang,
243  $facsrc->lines[$i]->special_code,
244  $facsrc->lines[$i]->label,
245  $facsrc->lines[$i]->fk_unit,
246  $facsrc->lines[$i]->multicurrency_subprice
247  );
248 
249  if ($result_insert < 0)
250  {
251  $error++;
252  }
253  }
254 
255  if (! empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects
256  {
257  $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds
258  }
259 
260  // Add object linked
261  if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects))
262  {
263  foreach($this->linked_objects as $origin => $tmp_origin_id)
264  {
265  if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
266  {
267  foreach($tmp_origin_id as $origin_id)
268  {
269  $ret = $this->add_object_linked($origin, $origin_id);
270  if (! $ret)
271  {
272  $this->error=$this->db->lasterror();
273  $error++;
274  }
275  }
276  }
277  else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1))
278  {
279  $origin_id = $tmp_origin_id;
280  $ret = $this->add_object_linked($origin, $origin_id);
281  if (! $ret)
282  {
283  $this->error=$this->db->lasterror();
284  $error++;
285  }
286  }
287  }
288  }
289 
290  if ($error)
291  {
292  $this->db->rollback();
293  }
294  else
295  {
296  $this->db->commit();
297  return $this->id;
298  }
299  }
300  else
301  {
302  $this->error=$this->db->lasterror();
303  $this->db->rollback();
304  return -2;
305  }
306  }
307  else
308  {
309  $this->db->rollback();
310  return -1;
311  }
312  }
313 
314 
324  function fetch($rowid, $ref='', $ref_ext='', $ref_int='')
325  {
326  $sql = 'SELECT f.rowid, f.entity, f.titre, f.suspended, f.fk_soc, f.amount, f.tva, f.localtax1, f.localtax2, f.total, f.total_ttc';
327  $sql.= ', f.remise_percent, f.remise_absolue, f.remise';
328  $sql.= ', f.date_lim_reglement as dlr';
329  $sql.= ', f.note_private, f.note_public, f.fk_user_author';
330  $sql.= ', f.modelpdf';
331  $sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet';
332  $sql.= ', f.fk_account';
333  $sql.= ', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.usenewprice, f.auto_validate';
334  $sql.= ', f.generate_pdf';
335  $sql.= ", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
336  $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
337  $sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
338  //$sql.= ', el.fk_source';
339  $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_rec as f';
340  $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
341  $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id';
342  //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = f.rowid AND el.targettype = 'facture'";
343  $sql.= ' WHERE f.entity IN ('.getEntity('facture').')';
344  if ($rowid) $sql.= ' AND f.rowid='.$rowid;
345  elseif ($ref) $sql.= " AND f.titre='".$this->db->escape($ref)."'";
346  /* This field are not used for template invoice
347  if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'";
348  if ($ref_int) $sql.= " AND f.ref_int='".$this->db->escape($ref_int)."'";
349  */
350 
351  $result = $this->db->query($sql);
352  if ($result)
353  {
354  if ($this->db->num_rows($result))
355  {
356  $obj = $this->db->fetch_object($result);
357 
358  $this->id = $obj->rowid;
359  $this->entity = $obj->entity;
360  $this->titre = $obj->titre;
361  $this->ref = $obj->titre;
362  $this->ref_client = $obj->ref_client;
363  $this->suspended = $obj->suspended;
364  $this->type = $obj->type;
365  $this->datep = $obj->dp;
366  $this->date = $obj->df;
367  $this->amount = $obj->amount;
368  $this->remise_percent = $obj->remise_percent;
369  $this->remise_absolue = $obj->remise_absolue;
370  $this->remise = $obj->remise;
371  $this->total_ht = $obj->total;
372  $this->total_tva = $obj->tva;
373  $this->total_localtax1 = $obj->localtax1;
374  $this->total_localtax2 = $obj->localtax2;
375  $this->total_ttc = $obj->total_ttc;
376  $this->paye = $obj->paye;
377  $this->close_code = $obj->close_code;
378  $this->close_note = $obj->close_note;
379  $this->socid = $obj->fk_soc;
380  $this->date_lim_reglement = $this->db->jdate($obj->dlr);
381  $this->mode_reglement_id = $obj->fk_mode_reglement;
382  $this->mode_reglement_code = $obj->mode_reglement_code;
383  $this->mode_reglement = $obj->mode_reglement_libelle;
384  $this->cond_reglement_id = $obj->fk_cond_reglement;
385  $this->cond_reglement_code = $obj->cond_reglement_code;
386  $this->cond_reglement = $obj->cond_reglement_libelle;
387  $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
388  $this->fk_project = $obj->fk_projet;
389  $this->fk_account = $obj->fk_account;
390  $this->fk_facture_source = $obj->fk_facture_source;
391  $this->note_private = $obj->note_private;
392  $this->note_public = $obj->note_public;
393  $this->user_author = $obj->fk_user_author;
394  $this->modelpdf = $obj->modelpdf;
395  $this->rang = $obj->rang;
396  $this->special_code = $obj->special_code;
397  $this->frequency = $obj->frequency;
398  $this->unit_frequency = $obj->unit_frequency;
399  $this->date_when = $this->db->jdate($obj->date_when);
400  $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
401  $this->nb_gen_done = $obj->nb_gen_done;
402  $this->nb_gen_max = $obj->nb_gen_max;
403  $this->usenewprice = $obj->usenewprice;
404  $this->auto_validate = $obj->auto_validate;
405  $this->generate_pdf = $obj->generate_pdf;
406 
407  // Multicurrency
408  $this->fk_multicurrency = $obj->fk_multicurrency;
409  $this->multicurrency_code = $obj->multicurrency_code;
410  $this->multicurrency_tx = $obj->multicurrency_tx;
411  $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
412  $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
413  $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
414 
415  if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1;
416 
417  // Retreive all extrafield
418  // fetch optionals attributes and labels
419  $this->fetch_optionals();
420 
421  /*
422  * Lines
423  */
424  $result=$this->fetch_lines();
425  if ($result < 0)
426  {
427  $this->error=$this->db->lasterror();
428  return -3;
429  }
430  return 1;
431  }
432  else
433  {
434  $this->error='Bill with id '.$rowid.' or ref '.$ref.' not found sql='.$sql;
435  dol_syslog('Facture::Fetch Error '.$this->error, LOG_ERR);
436  return -2;
437  }
438  }
439  else
440  {
441  $this->error=$this->db->error();
442  return -1;
443  }
444  }
445 
446 
452  function getLinesArray()
453  {
454  return $this->fetch_lines();
455  }
456 
457 
458  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
464  function fetch_lines()
465  {
466  // phpcs:enable
467  $this->lines=array();
468 
469  // Retreive all extrafield for line
470  // fetch optionals attributes and labels
471  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
472  $extrafieldsline=new ExtraFields($this->db);
473  $extrafieldsline=$extrafieldsline->fetch_name_optionals_label('facturedet_rec',true);
474 
475  $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx, ';
476  $sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
477  $sql.= ' l.info_bits, l.date_start_fill, l.date_end_fill, l.total_ht, l.total_tva, l.total_ttc,';
478  //$sql.= ' l.situation_percent, l.fk_prev_id,';
479  //$sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise_percent, l.fk_remise_except, l.subprice,';
480  $sql.= ' l.rang, l.special_code,';
481  //$sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_localtax1, l.total_localtax2, l.total_ttc, l.fk_code_ventilation, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht,';
482  $sql.= ' l.fk_unit, l.fk_contract_line,';
483  $sql.= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
484  $sql.= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
485  $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l';
486  $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
487  $sql.= ' WHERE l.fk_facture = '.$this->id;
488  $sql.= ' ORDER BY l.rang';
489 
490  dol_syslog('FactureRec::fetch_lines', LOG_DEBUG);
491  $result = $this->db->query($sql);
492  if ($result)
493  {
494  $num = $this->db->num_rows($result);
495  $i = 0;
496  while ($i < $num)
497  {
498  $objp = $this->db->fetch_object($result);
499  $line = new FactureLigneRec($this->db);
500 
501  $line->id = $objp->rowid;
502  $line->rowid = $objp->rowid;
503  $line->desc = $objp->description; // Description line
504  $line->description = $objp->description; // Description line
505  $line->product_type = $objp->product_type; // Type of line
506  $line->ref = $objp->product_ref; // Ref product
507  $line->product_ref = $objp->product_ref; // Ref product
508  $line->libelle = $objp->product_label; // deprecated
509  $line->product_label = $objp->product_label; // Label product
510  $line->product_desc = $objp->product_desc; // Description product
511  $line->fk_product_type = $objp->fk_product_type; // Type of product
512  $line->qty = $objp->qty;
513  $line->subprice = $objp->subprice;
514 
515  $line->label = $objp->custom_label; // @deprecated
516 
517  $line->vat_src_code = $objp->vat_src_code;
518  $line->tva_tx = $objp->tva_tx;
519  $line->localtax1_tx = $objp->localtax1_tx;
520  $line->localtax2_tx = $objp->localtax2_tx;
521  $line->localtax1_type = $objp->localtax1_type;
522  $line->localtax2_type = $objp->localtax2_type;
523  $line->remise_percent = $objp->remise_percent;
524  $line->fk_remise_except = $objp->fk_remise_except;
525  $line->fk_product = $objp->fk_product;
526  $line->date_start_fill = $objp->date_start_fill;
527  $line->date_end_fill = $objp->date_end_fill;
528  $line->info_bits = $objp->info_bits;
529  $line->total_ht = $objp->total_ht;
530  $line->total_tva = $objp->total_tva;
531  $line->total_ttc = $objp->total_ttc;
532  $line->code_ventilation = $objp->fk_code_ventilation;
533  $line->rang = $objp->rang;
534  $line->special_code = $objp->special_code;
535  $line->fk_unit = $objp->fk_unit;
536  $line->fk_contract_line = $objp->fk_contract_line;
537 
538  // Ne plus utiliser
539  $line->price = $objp->price;
540  $line->remise = $objp->remise;
541 
542  $extralabelsline = $line->fetch_optionals($line->id);
543 
544  // Multicurrency
545  $line->fk_multicurrency = $objp->fk_multicurrency;
546  $line->multicurrency_code = $objp->multicurrency_code;
547  $line->multicurrency_subprice = $objp->multicurrency_subprice;
548  $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
549  $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
550  $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
551 
552  $this->lines[$i] = $line;
553 
554  $i++;
555  }
556 
557  $this->db->free($result);
558  return 1;
559  }
560  else
561  {
562  $this->error=$this->db->lasterror();
563  return -3;
564  }
565  }
566 
567 
576  function delete(User $user, $notrigger=0, $idwarehouse=-1)
577  {
578  $rowid=$this->id;
579 
580  dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG);
581 
582  $error=0;
583  $this->db->begin();
584 
585  $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = ".$rowid;
586  dol_syslog($sql);
587  if ($this->db->query($sql))
588  {
589  $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_rec WHERE rowid = ".$rowid;
590  dol_syslog($sql);
591  if ($this->db->query($sql))
592  {
593  // Delete linked object
594  $res = $this->deleteObjectLinked();
595  if ($res < 0) $error=-3;
596  }
597  else
598  {
599  $this->error=$this->db->lasterror();
600  $error=-1;
601  }
602  }
603  else
604  {
605  $this->error=$this->db->lasterror();
606  $error=-2;
607  }
608 
609  if (! $error)
610  {
611  $this->db->commit();
612  return 1;
613  }
614  else
615  {
616  $this->db->rollback();
617  return $error;
618  }
619  }
620 
621 
647  function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise=0, $date_start_fill=0, $date_end_fill=0)
648  {
649  global $mysoc;
650 
651  $facid=$this->id;
652 
653  dol_syslog(get_class($this)."::addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,txlocaltax1=$txlocaltax1,txlocaltax2=$txlocaltax2,fk_product=$fk_product,remise_percent=$remise_percent,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit,pu_ht_devise=$pu_ht_devise,date_start_fill=$date_start_fill,date_end_fill=$date_end_fill", LOG_DEBUG);
654  include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
655 
656  // Check parameters
657  if ($type < 0) return -1;
658 
659  $localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
660 
661  // Clean vat code
662  $vat_src_code='';
663  if (preg_match('/\((.*)\)/', $txtva, $reg))
664  {
665  $vat_src_code = $reg[1];
666  $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
667  }
668 
669  if ($this->brouillon)
670  {
671  // Clean parameters
672  $remise_percent=price2num($remise_percent);
673  if (empty($remise_percent)) $remise_percent=0;
674  $qty=price2num($qty);
675  $pu_ht = price2num($pu_ht);
676  $pu_ttc = price2num($pu_ttc);
677  $txtva = price2num($txtva);
678  $txlocaltax1 = price2num($txlocaltax1);
679  $txlocaltax2 = price2num($txlocaltax2);
680  if (empty($txtva)) $txtva=0;
681  if (empty($txlocaltax1)) $txlocaltax1=0;
682  if (empty($txlocaltax2)) $txlocaltax2=0;
683  if (empty($info_bits)) $info_bits=0;
684 
685  if ($price_base_type=='HT')
686  {
687  $pu=$pu_ht;
688  }
689  else
690  {
691  $pu=$pu_ttc;
692  }
693 
694  // Calcul du total TTC et de la TVA pour la ligne a partir de
695  // qty, pu, remise_percent et txtva
696  // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
697  // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
698 
699  $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
700  $total_ht = $tabprice[0];
701  $total_tva = $tabprice[1];
702  $total_ttc = $tabprice[2];
703  $total_localtax1=$tabprice[9];
704  $total_localtax2=$tabprice[10];
705  $pu_ht = $tabprice[3];
706 
707  // MultiCurrency
708  $multicurrency_total_ht = $tabprice[16];
709  $multicurrency_total_tva = $tabprice[17];
710  $multicurrency_total_ttc = $tabprice[18];
711  $pu_ht_devise = $tabprice[19];
712 
713  $product_type=$type;
714  if ($fk_product)
715  {
716  $product=new Product($this->db);
717  $result=$product->fetch($fk_product);
718  $product_type=$product->type;
719  }
720 
721  $sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (";
722  $sql.= "fk_facture";
723  $sql.= ", label";
724  $sql.= ", description";
725  $sql.= ", price";
726  $sql.= ", qty";
727  $sql.= ", tva_tx";
728  $sql.= ", vat_src_code";
729  $sql.= ", localtax1_tx";
730  $sql.= ", localtax1_type";
731  $sql.= ", localtax2_tx";
732  $sql.= ", localtax2_type";
733  $sql.= ", fk_product";
734  $sql.= ", product_type";
735  $sql.= ", remise_percent";
736  $sql.= ", subprice";
737  $sql.= ", remise";
738  $sql.= ", total_ht";
739  $sql.= ", total_tva";
740  $sql.= ", total_localtax1";
741  $sql.= ", total_localtax2";
742  $sql.= ", total_ttc";
743  $sql.= ", date_start_fill";
744  $sql.= ", date_end_fill";
745  $sql.= ", info_bits";
746  $sql.= ", rang";
747  $sql.= ", special_code";
748  $sql.= ", fk_unit";
749  $sql.= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
750  $sql.= ") VALUES (";
751  $sql.= "'".$facid."'";
752  $sql.= ", ".(! empty($label)?"'".$this->db->escape($label)."'":"null");
753  $sql.= ", '".$this->db->escape($desc)."'";
754  $sql.= ", ".price2num($pu_ht);
755  $sql.= ", ".price2num($qty);
756  $sql.= ", ".price2num($txtva);
757  $sql.= ", '".$this->db->escape($vat_src_code)."'";
758  $sql.= ", ".price2num($txlocaltax1);
759  $sql.= ", '".$this->db->escape($localtaxes_type[0])."'";
760  $sql.= ", ".price2num($txlocaltax2);
761  $sql.= ", '".$this->db->escape($localtaxes_type[2])."'";
762  $sql.= ", ".(! empty($fk_product)?"'".$fk_product."'":"null");
763  $sql.= ", ".$product_type;
764  $sql.= ", ".price2num($remise_percent);
765  $sql.= ", ".price2num($pu_ht);
766  $sql.= ", null";
767  $sql.= ", ".price2num($total_ht);
768  $sql.= ", ".price2num($total_tva);
769  $sql.= ", ".price2num($total_localtax1);
770  $sql.= ", ".price2num($total_localtax2);
771  $sql.= ", ".price2num($total_ttc);
772  $sql.= ", ".(int) $date_start_fill;
773  $sql.= ", ".(int) $date_end_fill;
774  $sql.= ", ".$info_bits;
775  $sql.= ", ".$rang;
776  $sql.= ", ".$special_code;
777  $sql.= ", ".($fk_unit?"'".$this->db->escape($fk_unit)."'":"null");
778  $sql.= ", ".(int) $this->fk_multicurrency;
779  $sql.= ", '".$this->db->escape($this->multicurrency_code)."'";
780  $sql.= ", ".price2num($pu_ht_devise);
781  $sql.= ", ".price2num($multicurrency_total_ht);
782  $sql.= ", ".price2num($multicurrency_total_tva);
783  $sql.= ", ".price2num($multicurrency_total_ttc);
784  $sql.= ")";
785 
786  dol_syslog(get_class($this)."::addline", LOG_DEBUG);
787  if ($this->db->query($sql))
788  {
789  $lineId = $this->db->last_insert_id(MAIN_DB_PREFIX."facturedet_rec");
790  $this->id=$facid;
791  $this->update_price();
792  return $lineId;
793  }
794  else
795  {
796  $this->error=$this->db->lasterror();
797  return -1;
798  }
799  }
800  }
801 
829  function updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise = 0, $notrigger=0, $date_start_fill=0, $date_end_fill=0)
830  {
831  global $mysoc;
832 
833  $facid=$this->id;
834 
835  dol_syslog(get_class($this)."::updateline facid=".$facid." rowid=$rowid, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, fk_product=$fk_product, remise_percent=$remise_percent, info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, type=$type, fk_unit=$fk_unit, pu_ht_devise=$pu_ht_devise", LOG_DEBUG);
836  include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
837 
838  // Clean parameters
839  if (empty($remise_percent)) $remise_percent = 0;
840 
841  // Check parameters
842  if ($type < 0) return -1;
843 
844  $localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
845 
846  // Clean vat code
847  $vat_src_code='';
848  if (preg_match('/\((.*)\)/', $txtva, $reg))
849  {
850  $vat_src_code = $reg[1];
851  $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
852  }
853 
854  if ($this->brouillon)
855  {
856  // Clean parameters
857  $remise_percent=price2num($remise_percent);
858  $qty=price2num($qty);
859  if (empty($info_bits)) $info_bits=0;
860  $pu_ht=price2num($pu_ht);
861  $pu_ttc=price2num($pu_ttc);
862  $txtva=price2num($txtva);
863  $txlocaltax1 = price2num($txlocaltax1);
864  $txlocaltax2 = price2num($txlocaltax2);
865  if (empty($txlocaltax1)) $txlocaltax1=0;
866  if (empty($txlocaltax2)) $txlocaltax2=0;
867 
868  if (empty($this->multicurrency_subprice)) $this->multicurrency_subprice=0;
869  if (empty($this->multicurrency_total_ht)) $this->multicurrency_total_ht=0;
870  if (empty($this->multicurrency_total_tva)) $this->multicurrency_total_tva=0;
871  if (empty($this->multicurrency_total_ttc)) $this->multicurrency_total_ttc=0;
872 
873  if ($price_base_type=='HT')
874  {
875  $pu=$pu_ht;
876  }
877  else
878  {
879  $pu=$pu_ttc;
880  }
881 
882  // Calcul du total TTC et de la TVA pour la ligne a partir de
883  // qty, pu, remise_percent et txtva
884  // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
885  // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
886  $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
887 
888  $total_ht = $tabprice[0];
889  $total_tva = $tabprice[1];
890  $total_ttc = $tabprice[2];
891  $total_localtax1=$tabprice[9];
892  $total_localtax2=$tabprice[10];
893  $pu_ht = $tabprice[3];
894  $pu_tva = $tabprice[4];
895  $pu_ttc = $tabprice[5];
896 
897  // MultiCurrency
898  $multicurrency_total_ht = $tabprice[16];
899  $multicurrency_total_tva = $tabprice[17];
900  $multicurrency_total_ttc = $tabprice[18];
901  $pu_ht_devise = $tabprice[19];
902 
903  $product_type=$type;
904  if ($fk_product)
905  {
906  $product=new Product($this->db);
907  $result=$product->fetch($fk_product);
908  $product_type=$product->type;
909  }
910 
911  $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET ";
912  $sql.= "fk_facture = '".$facid."'";
913  $sql.= ", label=".(! empty($label)?"'".$this->db->escape($label)."'":"null");
914  $sql.= ", description='".$this->db->escape($desc)."'";
915  $sql.= ", price=".price2num($pu_ht);
916  $sql.= ", qty=".price2num($qty);
917  $sql.= ", tva_tx=".price2num($txtva);
918  $sql.= ", vat_src_code='".$this->db->escape($vat_src_code)."'";
919  $sql.= ", localtax1_tx=".$txlocaltax1;
920  $sql.= ", localtax1_type='".$this->db->escape($localtaxes_type[0])."'";
921  $sql.= ", localtax2_tx=".$txlocaltax2;
922  $sql.= ", localtax2_type='".$this->db->escape($localtaxes_type[2])."'";
923  $sql.= ", fk_product=".(! empty($fk_product)?"'".$fk_product."'":"null");
924  $sql.= ", product_type=".$product_type;
925  $sql.= ", remise_percent='".price2num($remise_percent)."'";
926  $sql.= ", subprice='".price2num($pu_ht)."'";
927  $sql.= ", total_ht='".price2num($total_ht)."'";
928  $sql.= ", total_tva='".price2num($total_tva)."'";
929  $sql.= ", total_localtax1='".price2num($total_localtax1)."'";
930  $sql.= ", total_localtax2='".price2num($total_localtax2)."'";
931  $sql.= ", total_ttc='".price2num($total_ttc)."'";
932  $sql.= ", date_start_fill=".((int) $date_start_fill);
933  $sql.= ", date_end_fill=".((int) $date_end_fill);
934  $sql.= ", info_bits=".$info_bits;
935  $sql.= ", rang=".$rang;
936  $sql.= ", special_code=".$special_code;
937  $sql.= ", fk_unit=".($fk_unit?"'".$this->db->escape($fk_unit)."'":"null");
938  $sql.= ', multicurrency_subprice = '.$pu_ht_devise;
939  $sql.= ', multicurrency_total_ht = '.$multicurrency_total_ht;
940  $sql.= ', multicurrency_total_tva = '.$multicurrency_total_tva;
941  $sql.= ', multicurrency_total_ttc = '.$multicurrency_total_ttc;
942  $sql.= " WHERE rowid = ".$rowid;
943 
944  dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
945  if ($this->db->query($sql))
946  {
947  $this->id=$facid;
948  $this->update_price();
949  return 1;
950  }
951  else
952  {
953  $this->error=$this->db->lasterror();
954  return -1;
955  }
956  }
957  }
958 
959 
965  function getNextDate()
966  {
967  if (empty($this->date_when)) return false;
968  return dol_time_plus_duree($this->date_when, $this->frequency, $this->unit_frequency);
969  }
970 
976  function isMaxNbGenReached()
977  {
978  $ret = false;
979  if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) $ret = true;
980  return $ret;
981  }
982 
989  function strikeIfMaxNbGenReached($ret)
990  {
991  // Special case to strike the date
992  return ($this->isMaxNbGenReached()?'<strike>':'').$ret.($this->isMaxNbGenReached()?'</strike>':'');
993  }
994 
1005  function createRecurringInvoices($restictoninvoiceid=0, $forcevalidation=0)
1006  {
1007  global $conf, $langs, $db, $user;
1008 
1009  $error=0;
1010 
1011  // Load translation files required by the page
1012  $langs->loadLangs(array("main","bills"));
1013 
1014  $nb_create=0;
1015 
1016  $now = dol_now();
1017  $tmparray=dol_getdate($now);
1018  $today = dol_mktime(23,59,59,$tmparray['mon'],$tmparray['mday'],$tmparray['year']); // Today is last second of current day
1019 
1020  dol_syslog("createRecurringInvoices restictoninvoiceid=".$restictoninvoiceid." forcevalidation=".$forcevalidation);
1021 
1022  $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture_rec';
1023  $sql.= ' WHERE frequency > 0'; // A recurring invoice is an invoice with a frequency
1024  $sql.= " AND (date_when IS NULL OR date_when <= '".$db->idate($today)."')";
1025  $sql.= ' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
1026  $sql.= ' AND suspended = 0';
1027  $sql.= ' AND entity = '.$conf->entity; // MUST STAY = $conf->entity here
1028  if ($restictoninvoiceid > 0) $sql.=' AND rowid = '.$restictoninvoiceid;
1029  $sql.= $db->order('entity', 'ASC');
1030  //print $sql;exit;
1031 
1032  $resql = $db->query($sql);
1033  if ($resql)
1034  {
1035  $i=0;
1036  $num = $db->num_rows($resql);
1037 
1038  if ($num) $this->output.=$langs->trans("FoundXQualifiedRecurringInvoiceTemplate", $num)."\n";
1039  else $this->output.=$langs->trans("NoQualifiedRecurringInvoiceTemplateFound");
1040 
1041  $saventity = $conf->entity;
1042 
1043  while ($i < $num) // Loop on each template invoice. If $num = 0, test is false at first pass.
1044  {
1045  $line = $db->fetch_object($resql);
1046 
1047  $db->begin();
1048 
1049  $invoiceidgenerated = 0;
1050 
1051  $facturerec = new FactureRec($db);
1052  $facturerec->fetch($line->rowid);
1053 
1054  if ($facturerec->id > 0)
1055  {
1056  // Set entity context
1057  $conf->entity = $facturerec->entity;
1058 
1059  dol_syslog("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref.", entity=".$facturerec->entity);
1060 
1061  $facture = new Facture($db);
1062  $facture->fac_rec = $facturerec->id; // We will create $facture from this recurring invoice
1063  $facture->fk_fac_rec_source = $facturerec->id; // We will create $facture from this recurring invoice
1064 
1065  $facture->type = self::TYPE_STANDARD;
1066  $facture->brouillon = 1;
1067  $facture->date = (empty($facturerec->date_when)?$now:$facturerec->date_when); // We could also use dol_now here but we prefer date_when so invoice has real date when we would like even if we generate later.
1068  $facture->socid = $facturerec->socid;
1069 
1070  $invoiceidgenerated = $facture->create($user);
1071  if ($invoiceidgenerated <= 0)
1072  {
1073  $this->errors = $facture->errors;
1074  $this->error = $facture->error;
1075  $error++;
1076  }
1077  if (! $error && ($facturerec->auto_validate || $forcevalidation))
1078  {
1079  $result = $facture->validate($user);
1080  if ($result <= 0)
1081  {
1082  $this->errors = $facture->errors;
1083  $this->error = $facture->error;
1084  $error++;
1085  }
1086  }
1087  if (! $error && $facturerec->generate_pdf)
1088  {
1089  // We refresh the object in order to have all necessary data (like date_lim_reglement)
1090  $facture->fetch($facture->id);
1091  $result = $facture->generateDocument($facturerec->modelpdf, $langs);
1092  if ($result <= 0)
1093  {
1094  $this->errors = $facture->errors;
1095  $this->error = $facture->error;
1096  $error++;
1097  }
1098  }
1099  }
1100  else
1101  {
1102  $error++;
1103  $this->error="Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity."\n";
1104  $this->errors[]="Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity;
1105  dol_syslog("createRecurringInvoices Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity);
1106  }
1107 
1108  if (! $error && $invoiceidgenerated >= 0)
1109  {
1110  $db->commit("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
1111  dol_syslog("createRecurringInvoices Process invoice template ".$facturerec->ref." is finished with a success generation");
1112  $nb_create++;
1113  $this->output.=$langs->trans("InvoiceGeneratedFromTemplate", $facture->ref, $facturerec->ref)."\n";
1114  }
1115  else
1116  {
1117  $db->rollback("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
1118  }
1119 
1120  $i++;
1121  }
1122 
1123  $conf->entity = $saventity; // Restore entity context
1124  }
1125  else dol_print_error($db);
1126 
1127  $this->output=trim($this->output);
1128 
1129  return $error?$error:0;
1130  }
1131 
1144  function getNomUrl($withpicto=0,$option='',$max=0,$short=0,$moretitle='',$notooltip='',$save_lastsearch_value=-1)
1145  {
1146  global $langs;
1147 
1148  $result='';
1149 
1150  $label = '<u>' . $langs->trans("ShowInvoice") . '</u>';
1151  if (! empty($this->ref))
1152  $label .= '<br><b>'.$langs->trans('Ref') . ':</b> ' . $this->ref;
1153  if (! empty($this->date_last_gen))
1154  $label .= '<br><b>'.$langs->trans('DateLastGeneration') . ':</b> ' . dol_print_date($this->date_last_gen, 'dayhour');
1155  if ($this->frequency > 0)
1156  {
1157  if (! empty($this->date_when))
1158  {
1159  $label .= '<br><b>'.$langs->trans('NextDateToExecution') . ':</b> ';
1160  $label .= (empty($this->suspended)?'':'<strike>'). dol_print_date($this->date_when, 'day').(empty($this->suspended)?'':'</strike>'); // No hour for this property
1161  if (! empty($this->suspended)) $label .= ' ('.$langs->trans("Disabled").')';
1162  }
1163  }
1164 
1165  $url = DOL_URL_ROOT.'/compta/facture/fiche-rec.php?facid='.$this->id;
1166 
1167  if ($short) return $url;
1168 
1169  if ($option != 'nolink')
1170  {
1171  // Add param to save lastsearch_values or not
1172  $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
1173  if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
1174  if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
1175  }
1176 
1177  $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1178  $linkend='</a>';
1179 
1180  $result .= $linkstart;
1181  if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
1182  if ($withpicto != 2) $result.= $this->ref;
1183  $result .= $linkend;
1184 
1185  return $result;
1186  }
1187 
1195  function getLibStatut($mode=0, $alreadypaid=-1)
1196  {
1197 
1198  return $this->LibStatut($this->frequency?1:0, $this->suspended, $mode, $alreadypaid, empty($this->type)?0:$this->type);
1199  }
1200 
1201  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1212  function LibStatut($recur, $status, $mode=0, $alreadypaid=-1, $type=0)
1213  {
1214  // phpcs:enable
1215  global $langs;
1216  $langs->load('bills');
1217 
1218  //print "$recur,$status,$mode,$alreadypaid,$type";
1219  if ($mode == 0)
1220  {
1221  $prefix='';
1222  if ($recur)
1223  {
1224  if ($status == self::STATUS_SUSPENDED) return $langs->trans('Disabled');
1225  else return $langs->trans('Active');
1226  }
1227  else
1228  {
1229  if ($status == self::STATUS_SUSPENDED) return $langs->trans('Disabled');
1230  else return $langs->trans("Draft");
1231  }
1232  }
1233  elseif ($mode == 1)
1234  {
1235  $prefix='Short';
1236  if ($recur)
1237  {
1238  if ($status == self::STATUS_SUSPENDED) return $langs->trans('Disabled');
1239  else return $langs->trans('Active');
1240  }
1241  else
1242  {
1243  if ($status == self::STATUS_SUSPENDED) return $langs->trans('Disabled');
1244  else return $langs->trans("Draft");
1245  }
1246  }
1247  elseif ($mode == 2)
1248  {
1249  if ($recur)
1250  {
1251  if ($status == self::STATUS_SUSPENDED) return img_picto($langs->trans('Disabled'),'statut6').' '.$langs->trans('Disabled');
1252  else return img_picto($langs->trans('Active'),'statut4').' '.$langs->trans('Active');
1253  }
1254  else
1255  {
1256  if ($status == self::STATUS_SUSPENDED) return img_picto($langs->trans('Disabled'),'statut6').' '.$langs->trans('Disabled');
1257  else return img_picto($langs->trans('Draft'),'statut0').' '.$langs->trans('Draft');
1258  }
1259  }
1260  elseif ($mode == 3)
1261  {
1262  if ($recur)
1263  {
1264  $prefix='Short';
1265  if ($status == self::STATUS_SUSPENDED) return img_picto($langs->trans('Disabled'),'statut6');
1266  else return img_picto($langs->trans('Active'),'statut4');
1267  }
1268  else
1269  {
1270  if ($status == self::STATUS_SUSPENDED) return img_picto($langs->trans('Disabled'),'statut6');
1271  else return img_picto($langs->trans('Draft'),'statut0');
1272  }
1273  }
1274  elseif ($mode == 4)
1275  {
1276  $prefix='';
1277  if ($recur)
1278  {
1279  if ($status == self::STATUS_SUSPENDED) return img_picto($langs->trans('Disabled'),'statut6').' '.$langs->trans('Disabled');
1280  else return img_picto($langs->trans('Active'),'statut4').' '.$langs->trans('Active');
1281  }
1282  else
1283  {
1284  if ($status == self::STATUS_SUSPENDED) return img_picto($langs->trans('Disabled'),'statut6').' '.$langs->trans('Disabled');
1285  else return img_picto($langs->trans('Draft'),'statut0').' '.$langs->trans('Draft');
1286  }
1287  }
1288  elseif ($mode == 5 || $mode == 6)
1289  {
1290  $prefix='';
1291  if ($mode == 5) $prefix='Short';
1292  if ($recur)
1293  {
1294  if ($status == self::STATUS_SUSPENDED) return '<span class="xhideonsmartphone">'.$langs->trans('Disabled').' </span>'.img_picto($langs->trans('Disabled'),'statut6');
1295  else return '<span class="xhideonsmartphone">'.$langs->trans('Active').' </span>'.img_picto($langs->trans('Active'),'statut4');
1296  }
1297  else
1298  {
1299  if ($status == self::STATUS_SUSPENDED) return '<span class="xhideonsmartphone">'.$langs->trans('Disabled').' </span>'.img_picto($langs->trans('Disabled'),'statut6');
1300  else return $langs->trans('Draft').' '.img_picto($langs->trans('Active'),'statut0');
1301  }
1302  }
1303  }
1304 
1313  function initAsSpecimen($option='')
1314  {
1315  global $user,$langs,$conf;
1316 
1317  $now=dol_now();
1318  $arraynow=dol_getdate($now);
1319  $nownotime=dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
1320 
1321  // Load array of products prodids
1322  $num_prods = 0;
1323  $prodids = array();
1324 
1325  $sql = "SELECT rowid";
1326  $sql.= " FROM ".MAIN_DB_PREFIX."product";
1327  $sql.= " WHERE entity IN (".getEntity('product').")";
1328  $resql = $this->db->query($sql);
1329  if ($resql)
1330  {
1331  $num_prods = $this->db->num_rows($resql);
1332  $i = 0;
1333  while ($i < $num_prods)
1334  {
1335  $i++;
1336  $row = $this->db->fetch_row($resql);
1337  $prodids[$i] = $row[0];
1338  }
1339  }
1340 
1341  // Initialize parameters
1342  $this->id=0;
1343  $this->ref = 'SPECIMEN';
1344  $this->specimen=1;
1345  $this->socid = 1;
1346  $this->date = $nownotime;
1347  $this->date_lim_reglement = $nownotime + 3600 * 24 *30;
1348  $this->cond_reglement_id = 1;
1349  $this->cond_reglement_code = 'RECEP';
1350  $this->date_lim_reglement=$this->calculate_date_lim_reglement();
1351  $this->mode_reglement_id = 0; // Not forced to show payment mode CHQ + VIR
1352  $this->mode_reglement_code = ''; // Not forced to show payment mode CHQ + VIR
1353  $this->note_public='This is a comment (public)';
1354  $this->note_private='This is a comment (private)';
1355  $this->note='This is a comment (private)';
1356  $this->fk_incoterms=0;
1357  $this->location_incoterms='';
1358 
1359  if (empty($option) || $option != 'nolines')
1360  {
1361  // Lines
1362  $nbp = 5;
1363  $xnbp = 0;
1364  while ($xnbp < $nbp)
1365  {
1366  $line=new FactureLigne($this->db);
1367  $line->desc=$langs->trans("Description")." ".$xnbp;
1368  $line->qty=1;
1369  $line->subprice=100;
1370  $line->tva_tx=19.6;
1371  $line->localtax1_tx=0;
1372  $line->localtax2_tx=0;
1373  $line->remise_percent=0;
1374  if ($xnbp == 1) // Qty is negative (product line)
1375  {
1376  $prodid = mt_rand(1, $num_prods);
1377  $line->fk_product=$prodids[$prodid];
1378  $line->qty=-1;
1379  $line->total_ht=-100;
1380  $line->total_ttc=-119.6;
1381  $line->total_tva=-19.6;
1382  }
1383  else if ($xnbp == 2) // UP is negative (free line)
1384  {
1385  $line->subprice=-100;
1386  $line->total_ht=-100;
1387  $line->total_ttc=-119.6;
1388  $line->total_tva=-19.6;
1389  $line->remise_percent=0;
1390  }
1391  else if ($xnbp == 3) // Discount is 50% (product line)
1392  {
1393  $prodid = mt_rand(1, $num_prods);
1394  $line->fk_product=$prodids[$prodid];
1395  $line->total_ht=50;
1396  $line->total_ttc=59.8;
1397  $line->total_tva=9.8;
1398  $line->remise_percent=50;
1399  }
1400  else // (product line)
1401  {
1402  $prodid = mt_rand(1, $num_prods);
1403  $line->fk_product=$prodids[$prodid];
1404  $line->total_ht=100;
1405  $line->total_ttc=119.6;
1406  $line->total_tva=19.6;
1407  $line->remise_percent=00;
1408  }
1409 
1410  $this->lines[$xnbp]=$line;
1411  $xnbp++;
1412 
1413  $this->total_ht += $line->total_ht;
1414  $this->total_tva += $line->total_tva;
1415  $this->total_ttc += $line->total_ttc;
1416  }
1417  $this->revenuestamp = 0;
1418 
1419  // Add a line "offered"
1420  $line=new FactureLigne($this->db);
1421  $line->desc=$langs->trans("Description")." (offered line)";
1422  $line->qty=1;
1423  $line->subprice=100;
1424  $line->tva_tx=19.6;
1425  $line->localtax1_tx=0;
1426  $line->localtax2_tx=0;
1427  $line->remise_percent=100;
1428  $line->total_ht=0;
1429  $line->total_ttc=0; // 90 * 1.196
1430  $line->total_tva=0;
1431  $prodid = mt_rand(1, $num_prods);
1432  $line->fk_product=$prodids[$prodid];
1433 
1434  $this->lines[$xnbp]=$line;
1435  $xnbp++;
1436  }
1437 
1438  $this->usenewprice = 1;
1439  }
1440 
1449  public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
1450  {
1451  $tables = array(
1452  'facture_rec'
1453  );
1454 
1455  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
1456  }
1457 
1465  function setFrequencyAndUnit($frequency,$unit)
1466  {
1467  if (! $this->table_element)
1468  {
1469  dol_syslog(get_class($this)."::setFrequencyAndUnit was called on objet with property table_element not defined",LOG_ERR);
1470  return -1;
1471  }
1472 
1473  if (!empty($frequency) && empty($unit))
1474  {
1475  dol_syslog(get_class($this)."::setFrequencyAndUnit was called on objet with params frequency defined but unit not defined",LOG_ERR);
1476  return -2;
1477  }
1478 
1479  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1480  $sql.= ' SET frequency = '.($frequency?$this->db->escape($frequency):'null');
1481  if (!empty($unit))
1482  {
1483  $sql.= ', unit_frequency = \''.$this->db->escape($unit).'\'';
1484  }
1485  $sql.= ' WHERE rowid = '.$this->id;
1486 
1487  dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
1488  if ($this->db->query($sql))
1489  {
1490  $this->frequency = $frequency;
1491  if (!empty($unit)) $this->unit_frequency = $unit;
1492  return 1;
1493  }
1494  else
1495  {
1496  dol_print_error($this->db);
1497  return -1;
1498  }
1499  }
1500 
1508  function setNextDate($date, $increment_nb_gen_done=0)
1509  {
1510  if (! $this->table_element)
1511  {
1512  dol_syslog(get_class($this)."::setNextDate was called on objet with property table_element not defined",LOG_ERR);
1513  return -1;
1514  }
1515  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1516  $sql.= " SET date_when = ".($date ? "'".$this->db->idate($date)."'" : "null");
1517  if ($increment_nb_gen_done>0) $sql.= ', nb_gen_done = nb_gen_done + 1';
1518  $sql.= ' WHERE rowid = '.$this->id;
1519 
1520  dol_syslog(get_class($this)."::setNextDate", LOG_DEBUG);
1521  if ($this->db->query($sql))
1522  {
1523  $this->date_when = $date;
1524  if ($increment_nb_gen_done>0) $this->nb_gen_done++;
1525  return 1;
1526  }
1527  else
1528  {
1529  dol_print_error($this->db);
1530  return -1;
1531  }
1532  }
1533 
1540  function setMaxPeriod($nb)
1541  {
1542  if (! $this->table_element)
1543  {
1544  dol_syslog(get_class($this)."::setMaxPeriod was called on objet with property table_element not defined",LOG_ERR);
1545  return -1;
1546  }
1547 
1548  if (empty($nb)) $nb=0;
1549 
1550  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1551  $sql.= ' SET nb_gen_max = '.$nb;
1552  $sql.= ' WHERE rowid = '.$this->id;
1553 
1554  dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
1555  if ($this->db->query($sql))
1556  {
1557  $this->nb_gen_max = $nb;
1558  return 1;
1559  }
1560  else
1561  {
1562  dol_print_error($this->db);
1563  return -1;
1564  }
1565  }
1566 
1573  function setAutoValidate($validate)
1574  {
1575  if (! $this->table_element)
1576  {
1577  dol_syslog(get_class($this)."::setAutoValidate was called on objet with property table_element not defined",LOG_ERR);
1578  return -1;
1579  }
1580 
1581  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1582  $sql.= ' SET auto_validate = '.$validate;
1583  $sql.= ' WHERE rowid = '.$this->id;
1584 
1585  dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
1586  if ($this->db->query($sql))
1587  {
1588  $this->auto_validate = $validate;
1589  return 1;
1590  }
1591  else
1592  {
1593  dol_print_error($this->db);
1594  return -1;
1595  }
1596  }
1597 
1604  function setGeneratePdf($validate)
1605  {
1606  if (! $this->table_element)
1607  {
1608  dol_syslog(get_class($this)."::setGeneratePdf was called on objet with property table_element not defined",LOG_ERR);
1609  return -1;
1610  }
1611 
1612  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1613  $sql.= ' SET generate_pdf = '.$validate;
1614  $sql.= ' WHERE rowid = '.$this->id;
1615 
1616  dol_syslog(get_class($this)."::setGeneratePdf", LOG_DEBUG);
1617  if ($this->db->query($sql))
1618  {
1619  $this->generate_pdf = $validate;
1620  return 1;
1621  }
1622  else
1623  {
1624  dol_print_error($this->db);
1625  return -1;
1626  }
1627  }
1628 
1635  function setModelPdf($model)
1636  {
1637  if (! $this->table_element)
1638  {
1639  dol_syslog(get_class($this)."::setModelPdf was called on objet with property table_element not defined",LOG_ERR);
1640  return -1;
1641  }
1642 
1643  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1644  $sql.= ' SET modelpdf = "' . $model . '"';
1645  $sql.= ' WHERE rowid = '.$this->id;
1646 
1647  dol_syslog(get_class($this)."::setModelPdf", LOG_DEBUG);
1648  if ($this->db->query($sql))
1649  {
1650  $this->modelpdf = $model;
1651  return 1;
1652  }
1653  else
1654  {
1655  dol_print_error($this->db);
1656  return -1;
1657  }
1658  }
1659 }
1660 
1661 
1662 
1668 {
1672  public $element='facturedetrec';
1673 
1677  public $table_element='facturedet_rec';
1678 
1679  var $date_start_fill;
1680  var $date_end_fill;
1681 
1682 
1690  function delete(User $user, $notrigger = false)
1691  {
1692  $error=0;
1693 
1694  $this->db->begin();
1695 
1696  if (! $error) {
1697  if (! $notrigger) {
1698  // Call triggers
1699  $result=$this->call_trigger('LINEBILLREC_DELETE', $user);
1700  if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail
1701  // End call triggers
1702  }
1703  }
1704 
1705  if (! $error)
1706  {
1707  $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id;
1708 
1709  $res = $this->db->query($sql);
1710  if($res===false) {
1711  $error++;
1712  $this->errors[] = $this->db->lasterror();
1713  }
1714  }
1715 
1716  // Commit or rollback
1717  if ($error) {
1718  $this->db->rollback();
1719  return -1;
1720  } else {
1721  $this->db->commit();
1722  return 1;
1723  }
1724  }
1725 
1726 
1733  function fetch($rowid)
1734  {
1735  $sql = 'SELECT l.rowid, l.fk_facture ,l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx,';
1736  $sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
1737  $sql.= ' l.date_start_fill, l.date_end_fill, l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
1738  $sql.= ' l.rang, l.special_code,';
1739  $sql.= ' l.fk_unit, l.fk_contract_line,';
1740  $sql.= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
1741  $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l';
1742  $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
1743  $sql.= ' WHERE l.rowid = '.$rowid;
1744  $sql.= ' ORDER BY l.rang';
1745 
1746  dol_syslog('FactureRec::fetch', LOG_DEBUG);
1747  $result = $this->db->query($sql);
1748  if ($result)
1749  {
1750 
1751  $objp = $this->db->fetch_object($result);
1752 
1753  $this->id = $objp->rowid;
1754  $this->label = $objp->custom_label; // Label line
1755  $this->desc = $objp->description; // Description line
1756  $this->description = $objp->description; // Description line
1757  $this->product_type = $objp->product_type; // Type of line
1758  $this->ref = $objp->product_ref; // Ref product
1759  $this->product_ref = $objp->product_ref; // Ref product
1760  $this->libelle = $objp->product_label; // deprecated
1761  $this->product_label = $objp->product_label; // Label product
1762  $this->product_desc = $objp->product_desc; // Description product
1763  $this->fk_product_type = $objp->fk_product_type; // Type of product
1764  $this->qty = $objp->qty;
1765  $this->price = $objp->price;
1766  $this->subprice = $objp->subprice;
1767  $this->fk_facture = $objp->fk_facture;
1768  $this->vat_src_code = $objp->vat_src_code;
1769  $this->tva_tx = $objp->tva_tx;
1770  $this->localtax1_tx = $objp->localtax1_tx;
1771  $this->localtax2_tx = $objp->localtax2_tx;
1772  $this->localtax1_type = $objp->localtax1_type;
1773  $this->localtax2_type = $objp->localtax2_type;
1774  $this->remise_percent = $objp->remise_percent;
1775  $this->fk_remise_except = $objp->fk_remise_except;
1776  $this->fk_product = $objp->fk_product;
1777  $this->date_start_fill = $objp->date_start_fill;
1778  $this->date_end_fill = $objp->date_end_fill;
1779  $this->info_bits = $objp->info_bits;
1780  $this->total_ht = $objp->total_ht;
1781  $this->total_tva = $objp->total_tva;
1782  $this->total_ttc = $objp->total_ttc;
1783  $this->code_ventilation = $objp->fk_code_ventilation;
1784  $this->rang = $objp->rang;
1785  $this->special_code = $objp->special_code;
1786  $this->fk_unit = $objp->fk_unit;
1787  $this->fk_contract_line = $objp->fk_contract_line;
1788 
1789 
1790  $this->db->free($result);
1791  return 1;
1792  }
1793  else
1794  {
1795  $this->error=$this->db->lasterror();
1796  return -3;
1797  }
1798  }
1799 
1800 
1808  function update(User $user, $notrigger=0)
1809  {
1810  global $conf;
1811 
1812  include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
1813 
1814  $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET";
1815  $sql.= " fk_facture = ".$this->fk_facture;
1816  $sql.= ", label=".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null");
1817  $sql.= ", description='".$this->db->escape($this->desc)."'";
1818  $sql.= ", price=".price2num($this->price);
1819  $sql.= ", qty=".price2num($this->qty);
1820  $sql.= ", tva_tx=".price2num($this->tva_tx);
1821  $sql.= ", vat_src_code='".$this->db->escape($this->vat_src_code)."'";
1822  $sql.= ", localtax1_tx=".price2num($this->localtax1_tx);
1823  $sql.= ", localtax1_type='".$this->db->escape($this->localtax1_type)."'";
1824  $sql.= ", localtax2_tx=".price2num($this->localtax2_tx);
1825  $sql.= ", localtax2_type='".$this->db->escape($this->localtax2_type)."'";
1826  $sql.= ", fk_product=".($this->fk_product > 0 ? $this->fk_product :"null");
1827  $sql.= ", product_type=".$this->product_type;
1828  $sql.= ", remise_percent='".price2num($this->remise_percent)."'";
1829  $sql.= ", subprice='".price2num($this->subprice)."'";
1830  $sql.= ", info_bits='".price2num($this->info_bits)."'";
1831  $sql.= ", date_start_fill=".(int) $this->date_start_fill;
1832  $sql.= ", date_end_fill=".(int) $this->date_end_fill;
1833  if (empty($this->skip_update_total))
1834  {
1835  $sql.= ", total_ht=".price2num($this->total_ht);
1836  $sql.= ", total_tva=".price2num($this->total_tva);
1837  $sql.= ", total_localtax1=".price2num($this->total_localtax1);
1838  $sql.= ", total_localtax2=".price2num($this->total_localtax2);
1839  $sql.= ", total_ttc=".price2num($this->total_ttc);
1840  }
1841  $sql.= ", rang=".$this->rang;
1842  $sql.= ", special_code=".$this->special_code;
1843  $sql.= ", fk_unit=".($this->fk_unit ?"'".$this->db->escape($this->fk_unit )."'":"null");
1844  $sql.= ", fk_contract_line=".($this->fk_contract_line?$this->fk_contract_line:"null");
1845  $sql.= " WHERE rowid = ".$this->id;
1846 
1847  dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
1848  $resql=$this->db->query($sql);
1849  if ($resql)
1850  {
1851  if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1852  {
1853  $result=$this->insertExtraFields();
1854  if ($result < 0)
1855  {
1856  $error++;
1857  }
1858  }
1859 
1860  if (! $error && ! $notrigger)
1861  {
1862  // Call trigger
1863  $result=$this->call_trigger('LINEBILL_REC_UPDATE', $user);
1864  if ($result < 0)
1865  {
1866  $this->db->rollback();
1867  return -2;
1868  }
1869  // End call triggers
1870  }
1871  $this->db->commit();
1872  return 1;
1873  }
1874  else
1875  {
1876  $this->error=$this->db->lasterror();
1877  $this->db->rollback();
1878  return -2;
1879  }
1880  }
1881 }
print $object label
hash of file content (md5_file(dol_osencode($destfull))
Definition: edit.php:153
setNextDate($date, $increment_nb_gen_done=0)
Update the next date of execution.
calculate_date_lim_reglement($cond_reglement=0)
Renvoi une date limite de reglement de facture en fonction des conditions de reglements de la facture...
Class to manage invoice lines of templates.
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
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='')
Delete all links between an object $this.
</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
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
if(! empty($search_group)) natural_search(array("g.nom" g note
Definition: list.php:123
Class to manage products or services.
Class to manage invoice templates.
Class to manage Dolibarr users.
Definition: user.class.php:41
Class to manage Dolibarr database access.
setAutoValidate($validate)
Update the auto validate flag of invoice.
fetch($rowid, $ref='', $ref_ext='', $ref_int='')
Load object and lines.
setGeneratePdf($validate)
Update the auto generate documents.
getLinesArray()
Create an array of invoice lines.
getNextDate()
Return the next date of.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
initAsSpecimen($option='')
Initialise an instance with random values.
Parent class of all other business classes for details of elements (invoices, contracts, proposals, orders, ...)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
Class to manage standard extra fields.
__construct($db)
Constructor.
fetch_lines()
Recupere les lignes de factures predefinies dans this->lines.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
type
Definition: viewcat.php:284
setMaxPeriod($nb)
Update the maximum period.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
update_price($exclspec=0, $roundingadjust='none', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines)...
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
createRecurringInvoices($restictoninvoiceid=0, $forcevalidation=0)
Create all recurrents invoices (for all entities if multicompany is used).
update(User $user, $notrigger=0)
Update a line to invoice_rec.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $moretitle='', $notooltip='', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
dol_now($mode='gmt')
Return date for now.
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...
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)
Calculate totals (net, vat, ...) of a line.
Definition: price.lib.php:85
Superclass for invoices classes.
strikeIfMaxNbGenReached($ret)
Format string to output with by striking the string if max number of generation was reached...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
fetch($rowid)
Recupere les lignes de factures predefinies dans this->lines.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise=0, $date_start_fill=0, $date_end_fill=0)
Add a line to invoice.
create($user, $facid)
Create a predefined invoice.
setFrequencyAndUnit($frequency, $unit)
Update frequency and unit.
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
LibStatut($recur, $status, $mode=0, $alreadypaid=-1, $type=0)
Return label of a status.
setModelPdf($model)
Update the model for documents.
updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise=0, $notrigger=0, $date_start_fill=0, $date_end_fill=0)
Update a line to invoice.
isMaxNbGenReached()
Return if maximum number of generation is reached.
Class to manage invoices.
dol_getdate($timestamp, $fast=false)
Return an array with locale date info.
call_trigger($trigger_name, $user)
Call trigger based on this instance.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
add_object_linked($origin=null, $origin_id=null)
Add objects linked in llx_element_element.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
Definition: date.lib.php:116
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
getLibStatut($mode=0, $alreadypaid=-1)
Return label of object status.
Class to manage invoice lines.