dolibarr  19.0.0-dev
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-2019 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-2020 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 <https://www.gnu.org/licenses/>.
23  */
24 
31 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35 
36 
41 {
42  const TRIGGER_PREFIX = 'BILLREC';
46  public $element = 'facturerec';
47 
51  public $table_element = 'facture_rec';
52 
56  public $table_element_line = 'facturedet_rec';
57 
61  public $fk_element = 'fk_facture';
62 
66  public $picto = 'bill';
67 
71  public $entity;
72 
76  protected $table_ref_field = 'titre';
77 
81  public $title;
82 
87  public $titre;
88 
89  public $socid;
90  public $number;
91  public $date;
92  public $remise;
93  public $remise_absolue;
94  public $remise_percent;
95 
100  public $total;
101 
106  public $tva;
107 
108  public $date_last_gen;
109  public $date_when;
110  public $nb_gen_done;
111  public $nb_gen_max;
112 
113  public $user_author;
114 
118  public $frequency;
119 
123  public $unit_frequency;
124 
125  public $rang;
126  public $special_code;
127 
128  public $usenewprice = 0;
129 
130  public $date_lim_reglement;
131  public $cond_reglement_code; // Code in llx_c_paiement
132  public $mode_reglement_code; // Code in llx_c_paiement
133 
134  public $suspended; // status
135 
136  public $auto_validate; // 0 to create in draft, 1 to create and validate the new invoice
137  public $generate_pdf; // 1 to generate PDF on invoice generation (default)
138 
143  public $brouillon;
144 
145 
170  // BEGIN MODULEBUILDER PROPERTIES
174  public $fields = array(
175  'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
176  'titre' =>array('type'=>'varchar(100)', 'label'=>'Titre', 'enabled'=>1, 'showoncombobox' => 1, 'visible'=>-1, 'position'=>15),
177  'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>20, 'index'=>1),
178  'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'enabled'=>'isModEnabled("societe")', 'visible'=>-1, 'notnull'=>1, 'position'=>25),
179  'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>30),
180  //'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>35),
181  'remise' =>array('type'=>'double', 'label'=>'Remise', 'enabled'=>1, 'visible'=>-1, 'position'=>40),
182  //'remise_percent' =>array('type'=>'double', 'label'=>'Remise percent', 'enabled'=>1, 'visible'=>-1, 'position'=>45),
183  //'remise_absolue' =>array('type'=>'double', 'label'=>'Remise absolue', 'enabled'=>1, 'visible'=>-1, 'position'=>50),
184  'total_tva' =>array('type'=>'double(24,8)', 'label'=>'Tva', 'enabled'=>1, 'visible'=>-1, 'position'=>55, 'isameasure'=>1),
185  'localtax1' =>array('type'=>'double(24,8)', 'label'=>'Localtax1', 'enabled'=>1, 'visible'=>-1, 'position'=>60, 'isameasure'=>1),
186  'localtax2' =>array('type'=>'double(24,8)', 'label'=>'Localtax2', 'enabled'=>1, 'visible'=>-1, 'position'=>65, 'isameasure'=>1),
187  'total_ht' =>array('type'=>'double(24,8)', 'label'=>'Total', 'enabled'=>1, 'visible'=>-1, 'position'=>70, 'isameasure'=>1),
188  'total_ttc' =>array('type'=>'double(24,8)', 'label'=>'Total ttc', 'enabled'=>1, 'visible'=>-1, 'position'=>75, 'isameasure'=>1),
189  'fk_user_author' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-1, 'position'=>80),
190  'fk_projet' =>array('type'=>'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label'=>'Fk projet', 'enabled'=>"isModEnabled('project')", 'visible'=>-1, 'position'=>85),
191  'fk_cond_reglement' =>array('type'=>'integer', 'label'=>'Fk cond reglement', 'enabled'=>1, 'visible'=>-1, 'position'=>90),
192  'fk_mode_reglement' =>array('type'=>'integer', 'label'=>'Fk mode reglement', 'enabled'=>1, 'visible'=>-1, 'position'=>95),
193  'date_lim_reglement' =>array('type'=>'date', 'label'=>'Date lim reglement', 'enabled'=>1, 'visible'=>-1, 'position'=>100),
194  'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>105),
195  'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>110),
196  'modelpdf' =>array('type'=>'varchar(255)', 'label'=>'Modelpdf', 'enabled'=>1, 'visible'=>-1, 'position'=>115),
197  'date_when' =>array('type'=>'datetime', 'label'=>'Date when', 'enabled'=>1, 'visible'=>-1, 'position'=>130),
198  'date_last_gen' =>array('type'=>'datetime', 'label'=>'Date last gen', 'enabled'=>1, 'visible'=>-1, 'position'=>135),
199  'nb_gen_done' =>array('type'=>'integer', 'label'=>'Nb gen done', 'enabled'=>1, 'visible'=>-1, 'position'=>140),
200  'nb_gen_max' =>array('type'=>'integer', 'label'=>'Nb gen max', 'enabled'=>1, 'visible'=>-1, 'position'=>145),
201  'frequency' =>array('type'=>'integer', 'label'=>'Frequency', 'enabled'=>1, 'visible'=>-1, 'position'=>150),
202  'unit_frequency' =>array('type'=>'varchar(2)', 'label'=>'UnitFrequency', 'enabled'=>1, 'visible'=>-1, 'position'=>152),
203  'usenewprice' =>array('type'=>'integer', 'label'=>'UseNewPrice', 'enabled'=>1, 'visible'=>0, 'position'=>155),
204  'revenuestamp' =>array('type'=>'double(24,8)', 'label'=>'RevenueStamp', 'enabled'=>1, 'visible'=>-1, 'position'=>160, 'isameasure'=>1),
205  'auto_validate' =>array('type'=>'integer', 'label'=>'Auto validate', 'enabled'=>1, 'visible'=>-1, 'position'=>165),
206  'generate_pdf' =>array('type'=>'integer', 'label'=>'Generate pdf', 'enabled'=>1, 'visible'=>-1, 'position'=>170),
207  'fk_account' =>array('type'=>'integer', 'label'=>'Fk account', 'enabled'=>'isModEnabled("banque")', 'visible'=>-1, 'position'=>175),
208  'fk_multicurrency' =>array('type'=>'integer', 'label'=>'Fk multicurrency', 'enabled'=>1, 'visible'=>-1, 'position'=>180),
209  'multicurrency_code' =>array('type'=>'varchar(255)', 'label'=>'Multicurrency code', 'enabled'=>1, 'visible'=>-1, 'position'=>185),
210  'multicurrency_tx' =>array('type'=>'double(24,8)', 'label'=>'Multicurrency tx', 'enabled'=>1, 'visible'=>-1, 'position'=>190, 'isameasure'=>1),
211  'multicurrency_total_ht' =>array('type'=>'double(24,8)', 'label'=>'Multicurrency total ht', 'enabled'=>1, 'visible'=>-1, 'position'=>195, 'isameasure'=>1),
212  'multicurrency_total_tva' =>array('type'=>'double(24,8)', 'label'=>'Multicurrency total tva', 'enabled'=>1, 'visible'=>-1, 'position'=>200, 'isameasure'=>1),
213  'multicurrency_total_ttc' =>array('type'=>'double(24,8)', 'label'=>'Multicurrency total ttc', 'enabled'=>1, 'visible'=>-1, 'position'=>205, 'isameasure'=>1),
214  'fk_user_modif' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>210),
215  'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>215),
216  'suspended' =>array('type'=>'integer', 'label'=>'Suspended', 'enabled'=>1, 'visible'=>-1, 'position'=>225),
217  );
218  // END MODULEBUILDER PROPERTIES
219 
220  const STATUS_NOTSUSPENDED = 0;
221  const STATUS_SUSPENDED = 1;
222 
223 
224 
230  public function __construct(DoliDB $db)
231  {
232  $this->db = $db;
233  }
234 
243  public function create($user, $facid, $notrigger = 0)
244  {
245  global $conf;
246 
247  $error = 0;
248  $now = dol_now();
249 
250  // Clean parameters
251  $this->titre = trim(isset($this->titre) ? $this->titre : $this->title); // deprecated
252  $this->title = trim($this->title);
253  $this->usenewprice = empty($this->usenewprice) ? 0 : $this->usenewprice;
254  if (empty($this->suspended)) {
255  $this->suspended = 0;
256  }
257 
258  // No frequency defined then no next date to execution
259  if (empty($this->frequency)) {
260  $this->frequency = 0;
261  $this->date_when = null;
262  }
263 
264  $this->frequency = abs($this->frequency);
265  $this->nb_gen_done = 0;
266  $this->nb_gen_max = empty($this->nb_gen_max) ? 0 : $this->nb_gen_max;
267  $this->auto_validate = empty($this->auto_validate) ? 0 : $this->auto_validate;
268  $this->generate_pdf = empty($this->generate_pdf) ? 0 : $this->generate_pdf;
269 
270  $this->db->begin();
271 
272  // Charge facture modele
273  $facsrc = new Facture($this->db);
274  $result = $facsrc->fetch($facid);
275  if ($result > 0) {
276  // On positionne en mode brouillon la facture
277  $this->brouillon = 1;
278  $this->fk_soc = $facsrc->socid;
279 
280  $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec (";
281  $sql .= "titre";
282  $sql .= ", fk_soc";
283  $sql .= ", entity";
284  $sql .= ", datec";
285  $sql .= ", amount";
286  $sql .= ", remise";
287  $sql .= ", note_private";
288  $sql .= ", note_public";
289  $sql .= ", modelpdf";
290  $sql .= ", fk_user_author";
291  $sql .= ", fk_projet";
292  $sql .= ", fk_account";
293  $sql .= ", fk_cond_reglement";
294  $sql .= ", fk_mode_reglement";
295  $sql .= ", usenewprice";
296  $sql .= ", frequency";
297  $sql .= ", unit_frequency";
298  $sql .= ", date_when";
299  $sql .= ", date_last_gen";
300  $sql .= ", nb_gen_done";
301  $sql .= ", nb_gen_max";
302  $sql .= ", auto_validate";
303  $sql .= ", generate_pdf";
304  $sql .= ", fk_multicurrency";
305  $sql .= ", multicurrency_code";
306  $sql .= ", multicurrency_tx";
307  $sql .= ", suspended";
308  $sql .= ") VALUES (";
309  $sql .= "'".$this->db->escape($this->titre ? $this->titre : $this->title)."'";
310  $sql .= ", ".((int) $this->fk_soc);
311  $sql .= ", ".((int) $conf->entity);
312  $sql .= ", '".$this->db->idate($now)."'";
313  $sql .= ", ".(!empty($facsrc->total_ttc) ? ((float) $facsrc->total_ttc) : '0');
314  $sql .= ", ".(!empty($facsrc->remise_absolue) ? ((float) $this->remise_absolue) : '0');
315  $sql .= ", ".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL");
316  $sql .= ", ".(!empty($this->note_public) ? ("'".$this->db->escape($this->note_public)."'") : "NULL");
317  $sql .= ", ".(!empty($this->model_pdf) ? ("'".$this->db->escape($this->model_pdf)."'") : "NULL");
318  $sql .= ", ".((int) $user->id);
319  $sql .= ", ".(!empty($this->fk_project) ? ((int) $this->fk_project) : "null");
320  $sql .= ", ".(!empty($facsrc->fk_account) ? ((int) $facsrc->fk_account) : "null");
321  $sql .= ", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) : "null");
322  $sql .= ", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) : "null");
323  $sql .= ", ".((int) $this->usenewprice);
324  $sql .= ", ".((int) $this->frequency);
325  $sql .= ", '".$this->db->escape($this->unit_frequency)."'";
326  $sql .= ", ".(!empty($this->date_when) ? "'".$this->db->idate($this->date_when)."'" : 'NULL');
327  $sql .= ", ".(!empty($this->date_last_gen) ? "'".$this->db->idate($this->date_last_gen)."'" : 'NULL');
328  $sql .= ", ".((int) $this->nb_gen_done);
329  $sql .= ", ".((int) $this->nb_gen_max);
330  $sql .= ", ".((int) $this->auto_validate);
331  $sql .= ", ".((int) $this->generate_pdf);
332  $sql .= ", ".((int) $facsrc->fk_multicurrency);
333  $sql .= ", '".$this->db->escape($facsrc->multicurrency_code)."'";
334  $sql .= ", ".((float) $facsrc->multicurrency_tx);
335  $sql .= ", ".((int) $this->suspended);
336  $sql .= ")";
337 
338  if ($this->db->query($sql)) {
339  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_rec");
340 
341  // Fields used into addline later
342  $this->fk_multicurrency = $facsrc->fk_multicurrency;
343  $this->multicurrency_code = $facsrc->multicurrency_code;
344  $this->multicurrency_tx = $facsrc->multicurrency_tx;
345 
346  // Add lines
347  $num = count($facsrc->lines);
348  for ($i = 0; $i < $num; $i++) {
349  $tva_tx = $facsrc->lines[$i]->tva_tx;
350  if (!empty($facsrc->lines[$i]->vat_src_code) && !preg_match('/\‍(/', $tva_tx)) {
351  $tva_tx .= ' ('.$facsrc->lines[$i]->vat_src_code.')';
352  }
353 
354  $default_start_fill = getDolGlobalInt('INVOICEREC_SET_AUTOFILL_DATE_START');
355  $default_end_fill = getDolGlobalInt('INVOICEREC_SET_AUTOFILL_DATE_END');
356 
357  $result_insert = $this->addline(
358  $facsrc->lines[$i]->desc,
359  $facsrc->lines[$i]->subprice,
360  $facsrc->lines[$i]->qty,
361  $tva_tx,
362  $facsrc->lines[$i]->localtax1_tx,
363  $facsrc->lines[$i]->localtax2_tx,
364  $facsrc->lines[$i]->fk_product,
365  $facsrc->lines[$i]->remise_percent,
366  'HT',
367  $facsrc->lines[$i]->info_bits,
368  '',
369  0,
370  $facsrc->lines[$i]->product_type,
371  $facsrc->lines[$i]->rang,
372  $facsrc->lines[$i]->special_code,
373  $facsrc->lines[$i]->label,
374  $facsrc->lines[$i]->fk_unit,
375  $facsrc->lines[$i]->multicurrency_subprice,
376  $default_start_fill,
377  $default_end_fill,
378  null,
379  $facsrc->lines[$i]->pa_ht
380  );
381 
382  if ($result_insert < 0) {
383  $error++;
384  } else {
385  $objectline = new FactureLigneRec($this->db);
386 
387  $result2 = $objectline->fetch($result_insert);
388  if ($result2 > 0) {
389  // Extrafields
390  if (method_exists($facsrc->lines[$i], 'fetch_optionals')) {
391  $facsrc->lines[$i]->fetch_optionals($facsrc->lines[$i]->id);
392  $objectline->array_options = $facsrc->lines[$i]->array_options;
393  }
394 
395  $result = $objectline->insertExtraFields();
396  if ($result < 0) {
397  $error++;
398  }
399  } elseif ($result2 < 0) {
400  $this->errors[] = $objectline->error;
401  $error++;
402  }
403  }
404  }
405 
406  if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) { // To use new linkedObjectsIds instead of old linked_objects
407  $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds
408  }
409 
410  // Add object linked
411  if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
412  foreach ($this->linked_objects as $origin => $tmp_origin_id) {
413  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, ...))
414  foreach ($tmp_origin_id as $origin_id) {
415  $ret = $this->add_object_linked($origin, $origin_id);
416  if (!$ret) {
417  $this->error = $this->db->lasterror();
418  $error++;
419  }
420  }
421  } else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1))
422  {
423  $origin_id = $tmp_origin_id;
424  $ret = $this->add_object_linked($origin, $origin_id);
425  if (!$ret) {
426  $this->error = $this->db->lasterror();
427  $error++;
428  }
429  }
430  }
431  }
432 
433  if (!$error) {
434  $result = $this->insertExtraFields();
435  if ($result < 0) {
436  $error++;
437  }
438  }
439 
440  if (!$error && !$notrigger) {
441  // Call trigger
442  $result = $this->call_trigger('BILLREC_CREATE', $user);
443  if ($result < 0) {
444  $this->db->rollback();
445  return -2;
446  }
447  // End call triggers
448  }
449 
450  if ($error) {
451  $this->db->rollback();
452  return -3;
453  } else {
454  $this->db->commit();
455  return $this->id;
456  }
457  } else {
458  $this->error = $this->db->lasterror();
459  $this->db->rollback();
460  return -2;
461  }
462  } else {
463  $this->db->rollback();
464  return -1;
465  }
466  }
467 
468 
476  public function update(User $user, $notrigger = 0)
477  {
478  $error = 0;
479 
480  $sql = "UPDATE ".MAIN_DB_PREFIX."facture_rec SET";
481  $sql .= " entity = ".((int) $this->entity).",";
482  $sql .= " titre = '".$this->db->escape($this->title)."',";
483  $sql .= " suspended = ".((int) $this->suspended).",";
484  $sql .= " fk_soc = ".((int) $this->socid).",";
485  $sql .= " total_tva = ".((float) $this->total_tva).",";
486  $sql .= " localtax1 = ".((float) $this->total_localtax1).",";
487  $sql .= " localtax2 = ".((float) $this->total_localtax2).",";
488  $sql .= " total_ht = ".((float) $this->total_ht).",";
489  $sql .= " total_ttc = ".((float) $this->total_ttc).",";
490  $sql .= " remise_percent = ".((float) $this->remise_percent);
491  // TODO Add missing fields
492  $sql .= " WHERE rowid = ".((int) $this->id);
493 
494  $this->db->begin();
495 
496  dol_syslog(get_class($this)."::update", LOG_DEBUG);
497 
498  $resql = $this->db->query($sql);
499  if ($resql) {
500  if (!$error) {
501  $result = $this->insertExtraFields();
502  if ($result < 0) {
503  $error++;
504  }
505  }
506 
507  if (!$error && !$notrigger) {
508  // Call trigger
509  $result = $this->call_trigger('BILLREC_MODIFY', $user);
510  if ($result < 0) {
511  $this->db->rollback();
512  return -2;
513  }
514  // End call triggers
515  }
516  $this->db->commit();
517  return 1;
518  } else {
519  $this->error = $this->db->lasterror();
520  $this->db->rollback();
521  return -1;
522  }
523  }
524 
533  public function fetch($rowid, $ref = '', $ref_ext = '')
534  {
535  dol_syslog('FactureRec::fetch', LOG_DEBUG);
536 
537  $sql = 'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc, f.total_tva, f.localtax1, f.localtax2, f.total_ht, f.total_ttc';
538  $sql .= ', f.remise_percent, f.remise_absolue, f.remise';
539  $sql .= ', f.date_lim_reglement as dlr';
540  $sql .= ', f.note_private, f.note_public, f.fk_user_author';
541  $sql .= ', f.modelpdf as model_pdf';
542  $sql .= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet as fk_project';
543  $sql .= ', f.fk_account';
544  $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';
545  $sql .= ', f.generate_pdf';
546  $sql .= ", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
547  $sql .= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
548  $sql .= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
549  //$sql.= ', el.fk_source';
550  $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_rec as f';
551  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
552  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id';
553  //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = f.rowid AND el.targettype = 'facture'";
554  $sql .= ' WHERE f.entity IN ('.getEntity('invoice').')';
555  if ($rowid) {
556  $sql .= ' AND f.rowid = '.((int) $rowid);
557  } elseif ($ref) {
558  $sql .= " AND f.titre = '".$this->db->escape($ref)."'";
559  } else {
560  $sql .= ' AND f.rowid = 0';
561  }
562  /* This field are not used for template invoice
563  if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'";
564  */
565 
566  $result = $this->db->query($sql);
567  if ($result) {
568  if ($this->db->num_rows($result)) {
569  $obj = $this->db->fetch_object($result);
570 
571  $this->id = $obj->rowid;
572  $this->entity = $obj->entity;
573  $this->titre = $obj->title; // deprecated
574  $this->title = $obj->title;
575  $this->ref = $obj->title;
576  $this->suspended = $obj->suspended;
577  $this->remise_percent = $obj->remise_percent;
578  $this->remise_absolue = $obj->remise_absolue;
579  $this->remise = $obj->remise;
580  $this->total_ht = $obj->total_ht;
581  $this->total_tva = $obj->total_tva;
582  $this->total_localtax1 = $obj->localtax1;
583  $this->total_localtax2 = $obj->localtax2;
584  $this->total_ttc = $obj->total_ttc;
585  $this->socid = $obj->fk_soc;
586  $this->date_lim_reglement = $this->db->jdate($obj->dlr);
587  $this->mode_reglement_id = $obj->fk_mode_reglement;
588  $this->mode_reglement_code = $obj->mode_reglement_code;
589  $this->mode_reglement = $obj->mode_reglement_libelle;
590  $this->cond_reglement_id = $obj->fk_cond_reglement;
591  $this->cond_reglement_code = $obj->cond_reglement_code;
592  $this->cond_reglement = $obj->cond_reglement_libelle;
593  $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
594  $this->fk_project = $obj->fk_project;
595  $this->fk_account = $obj->fk_account;
596  $this->note_private = $obj->note_private;
597  $this->note_public = $obj->note_public;
598  $this->user_author = $obj->fk_user_author;
599  $this->modelpdf = $obj->model_pdf; // deprecated
600  $this->model_pdf = $obj->model_pdf;
601  //$this->special_code = $obj->special_code;
602  $this->frequency = $obj->frequency;
603  $this->unit_frequency = $obj->unit_frequency;
604  $this->date_when = $this->db->jdate($obj->date_when);
605  $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
606  $this->nb_gen_done = $obj->nb_gen_done;
607  $this->nb_gen_max = $obj->nb_gen_max;
608  $this->usenewprice = $obj->usenewprice;
609  $this->auto_validate = $obj->auto_validate;
610  $this->generate_pdf = $obj->generate_pdf;
611 
612  // Multicurrency
613  $this->fk_multicurrency = $obj->fk_multicurrency;
614  $this->multicurrency_code = $obj->multicurrency_code;
615  $this->multicurrency_tx = $obj->multicurrency_tx;
616  $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
617  $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
618  $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
619 
620  if ($this->statut == self::STATUS_DRAFT) {
621  $this->brouillon = 1;
622  }
623 
624  // Retrieve all extrafield
625  // fetch optionals attributes and labels
626  $this->fetch_optionals();
627 
628  /*
629  * Lines
630  */
631  $result = $this->fetch_lines();
632  if ($result < 0) {
633  $this->error = $this->db->lasterror();
634  return -3;
635  }
636  return 1;
637  } else {
638  $this->error = 'Bill with id '.$rowid.' or ref '.$ref.' not found';
639  dol_syslog('Facture::Fetch Error '.$this->error, LOG_ERR);
640  return -2;
641  }
642  } else {
643  $this->error = $this->db->error();
644  return -1;
645  }
646  }
647 
648 
654  public function getLinesArray()
655  {
656  return $this->fetch_lines();
657  }
658 
659 
660  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
666  public function fetch_lines()
667  {
668  // phpcs:enable
669 
670  $this->lines = array();
671 
672  // Retrieve all extrafield for line
673  // fetch optionals attributes and labels
674  /*if (!is_object($extrafields)) {
675  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
676  $extrafields = new ExtraFields($this->db);
677  }
678  $extrafields->fetch_name_optionals_label($this->table_element_line, true);
679  */
680 
681  dol_syslog('FactureRec::fetch_lines', LOG_DEBUG);
682 
683  $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, ';
684  $sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
685  $sql .= ' l.info_bits, l.date_start_fill, l.date_end_fill, l.total_ht, l.total_tva, l.total_ttc, l.fk_product_fournisseur_price, l.buy_price_ht as pa_ht,';
686  $sql .= ' l.rang, l.special_code,';
687  $sql .= ' l.fk_unit, l.fk_contract_line,';
688  $sql .= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
689  $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
690  $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l';
691  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
692  $sql .= ' WHERE l.fk_facture = '.((int) $this->id);
693  $sql .= ' ORDER BY l.rang';
694 
695  $result = $this->db->query($sql);
696  if ($result) {
697  $num = $this->db->num_rows($result);
698  $i = 0;
699  while ($i < $num) {
700  $objp = $this->db->fetch_object($result);
701  $line = new FactureLigneRec($this->db);
702 
703  $line->id = $objp->rowid;
704  $line->rowid = $objp->rowid;
705  $line->desc = $objp->description; // Description line
706  $line->description = $objp->description; // Description line
707  $line->ref = $objp->product_ref; // Ref product
708  $line->product_ref = $objp->product_ref; // Ref product
709  $line->libelle = $objp->product_label; // deprecated
710  $line->product_label = $objp->product_label; // Label product
711  $line->product_desc = $objp->product_desc; // Description product
712  $line->product_type = $objp->product_type; // Type of line
713  $line->fk_product_type = $objp->fk_product_type; // Type of product
714  $line->qty = $objp->qty;
715  $line->subprice = $objp->subprice;
716 
717  $line->label = $objp->custom_label; // @deprecated
718 
719  $line->vat_src_code = $objp->vat_src_code;
720  $line->tva_tx = $objp->tva_tx;
721  $line->localtax1_tx = $objp->localtax1_tx;
722  $line->localtax2_tx = $objp->localtax2_tx;
723  $line->localtax1_type = $objp->localtax1_type;
724  $line->localtax2_type = $objp->localtax2_type;
725  $line->remise_percent = $objp->remise_percent;
726  //$line->fk_remise_except = $objp->fk_remise_except;
727  $line->fk_product = $objp->fk_product;
728  $line->date_start_fill = $objp->date_start_fill;
729  $line->date_end_fill = $objp->date_end_fill;
730  $line->info_bits = $objp->info_bits;
731  $line->total_ht = $objp->total_ht;
732  $line->total_tva = $objp->total_tva;
733  $line->total_ttc = $objp->total_ttc;
734 
735  //$line->code_ventilation = $objp->fk_code_ventilation;
736 
737  $line->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
738  $line->fk_fournprice = $objp->fk_product_fournisseur_price; // For backward compatibility
739 
740  $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $objp->fk_product_fournisseur_price, $objp->pa_ht);
741 
742  $line->buyprice = $marginInfos[0];
743  $line->pa_ht = $marginInfos[0]; // For backward compatibility
744  $line->marge_tx = $marginInfos[1];
745  $line->marque_tx = $marginInfos[2];
746  $line->rang = $objp->rang;
747  $line->special_code = $objp->special_code;
748  $line->fk_unit = $objp->fk_unit;
749  $line->fk_contract_line = $objp->fk_contract_line;
750 
751  // Ne plus utiliser
752  $line->price = $objp->price;
753  $line->remise = $objp->remise;
754 
755  $line->fetch_optionals();
756 
757  // Multicurrency
758  $line->fk_multicurrency = $objp->fk_multicurrency;
759  $line->multicurrency_code = $objp->multicurrency_code;
760  $line->multicurrency_subprice = $objp->multicurrency_subprice;
761  $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
762  $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
763  $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
764 
765  $this->lines[$i] = $line;
766 
767  $i++;
768  }
769 
770  $this->db->free($result);
771  return 1;
772  } else {
773  $this->error = $this->db->lasterror();
774  return -3;
775  }
776  }
777 
778 
787  public function delete(User $user, $notrigger = 0, $idwarehouse = -1)
788  {
789  $rowid = $this->id;
790 
791  dol_syslog(get_class($this)."::delete rowid=".((int) $rowid), LOG_DEBUG);
792 
793  $error = 0;
794  $this->db->begin();
795 
796  $main = MAIN_DB_PREFIX.'facturedet_rec';
797  $ef = $main."_extrafields";
798 
799  $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM ".$main." WHERE fk_facture = ".((int) $rowid).")";
800  $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = ".((int) $rowid);
801 
802  if ($this->db->query($sqlef) && $this->db->query($sql)) {
803  $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_rec WHERE rowid = ".((int) $rowid);
804  dol_syslog($sql);
805  if ($this->db->query($sql)) {
806  // Delete linked object
807  $res = $this->deleteObjectLinked();
808  if ($res < 0) {
809  $error = -3;
810  }
811  // Delete extrafields
812  $res = $this->deleteExtraFields();
813  if ($res < 0) {
814  $error = -4;
815  }
816  } else {
817  $this->error = $this->db->lasterror();
818  $error = -1;
819  }
820  } else {
821  $this->error = $this->db->lasterror();
822  $error = -2;
823  }
824  if (!$error && !$notrigger) {
825  // Call trigger
826  $result = $this->call_trigger('BILLREC_DELETE', $user);
827  if ($result < 0) {
828  $error++;
829  }
830  // End call triggers
831  }
832  if (!$error) {
833  $this->db->commit();
834  return 1;
835  } else {
836  $this->db->rollback();
837  return $error;
838  }
839  }
840 
841 
869  public 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, $fk_fournprice = null, $pa_ht = 0)
870  {
871  global $mysoc;
872 
873  $facid = $this->id;
874 
875  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,pa_ht=$pa_ht", LOG_DEBUG);
876  include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
877 
878  // Check parameters
879  if ($type < 0) {
880  return -1;
881  }
882 
883  $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
884 
885  // Clean vat code
886  $reg = array();
887  $vat_src_code = '';
888  if (preg_match('/\‍((.*)\‍)/', $txtva, $reg)) {
889  $vat_src_code = $reg[1];
890  $txtva = preg_replace('/\s*\‍(.*\‍)/', '', $txtva); // Remove code into vatrate.
891  }
892 
893  if ($this->brouillon) {
894  // Clean parameters
895  $remise_percent = price2num($remise_percent);
896  if (empty($remise_percent)) {
897  $remise_percent = 0;
898  }
899  $qty = price2num($qty);
900  $pu_ht = price2num($pu_ht);
901  $pu_ttc = price2num($pu_ttc);
902  if (!preg_match('/\‍((.*)\‍)/', $txtva)) {
903  $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
904  }
905  $txlocaltax1 = price2num($txlocaltax1);
906  $txlocaltax2 = price2num($txlocaltax2);
907  if (empty($txtva)) {
908  $txtva = 0;
909  }
910  if (empty($txlocaltax1)) {
911  $txlocaltax1 = 0;
912  }
913  if (empty($txlocaltax2)) {
914  $txlocaltax2 = 0;
915  }
916  if (empty($info_bits)) {
917  $info_bits = 0;
918  }
919 
920  if ($price_base_type == 'HT') {
921  $pu = $pu_ht;
922  } else {
923  $pu = $pu_ttc;
924  }
925 
926  // Calcul du total TTC et de la TVA pour la ligne a partir de
927  // qty, pu, remise_percent et txtva
928  // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
929  // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
930 
931  $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);
932  $total_ht = $tabprice[0];
933  $total_tva = $tabprice[1];
934  $total_ttc = $tabprice[2];
935  $total_localtax1 = $tabprice[9];
936  $total_localtax2 = $tabprice[10];
937  $pu_ht = $tabprice[3];
938 
939  // MultiCurrency
940  $multicurrency_total_ht = $tabprice[16];
941  $multicurrency_total_tva = $tabprice[17];
942  $multicurrency_total_ttc = $tabprice[18];
943  $pu_ht_devise = $tabprice[19];
944 
945  $product_type = $type;
946  if ($fk_product) {
947  $product = new Product($this->db);
948  $result = $product->fetch($fk_product);
949  $product_type = $product->type;
950  }
951 
952  // Rank to use
953  $ranktouse = $rang;
954  if ($ranktouse == -1) {
955  $rangmax = $this->line_max(0);
956  $ranktouse = $rangmax + 1;
957  }
958 
959  $sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (";
960  $sql .= "fk_facture";
961  $sql .= ", label";
962  $sql .= ", description";
963  $sql .= ", price";
964  $sql .= ", qty";
965  $sql .= ", tva_tx";
966  $sql .= ", vat_src_code";
967  $sql .= ", localtax1_tx";
968  $sql .= ", localtax1_type";
969  $sql .= ", localtax2_tx";
970  $sql .= ", localtax2_type";
971  $sql .= ", fk_product";
972  $sql .= ", product_type";
973  $sql .= ", remise_percent";
974  $sql .= ", subprice";
975  $sql .= ", remise";
976  $sql .= ", total_ht";
977  $sql .= ", total_tva";
978  $sql .= ", total_localtax1";
979  $sql .= ", total_localtax2";
980  $sql .= ", total_ttc";
981  $sql .= ", date_start_fill";
982  $sql .= ", date_end_fill";
983  $sql .= ", fk_product_fournisseur_price";
984  $sql .= ", buy_price_ht";
985  $sql .= ", info_bits";
986  $sql .= ", rang";
987  $sql .= ", special_code";
988  $sql .= ", fk_unit";
989  $sql .= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
990  $sql .= ") VALUES (";
991  $sql .= " ".((int) $facid);
992  $sql .= ", ".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
993  $sql .= ", '".$this->db->escape($desc)."'";
994  $sql .= ", ".price2num($pu_ht);
995  $sql .= ", ".price2num($qty);
996  $sql .= ", ".price2num($txtva);
997  $sql .= ", '".$this->db->escape($vat_src_code)."'";
998  $sql .= ", ".price2num($txlocaltax1);
999  $sql .= ", '".$this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] : '')."'";
1000  $sql .= ", ".price2num($txlocaltax2);
1001  $sql .= ", '".$this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] : '')."'";
1002  $sql .= ", ".(!empty($fk_product) ? "'".$this->db->escape($fk_product)."'" : "null");
1003  $sql .= ", ".((int) $product_type);
1004  $sql .= ", ".price2num($remise_percent);
1005  $sql .= ", ".price2num($pu_ht);
1006  $sql .= ", null";
1007  $sql .= ", ".price2num($total_ht);
1008  $sql .= ", ".price2num($total_tva);
1009  $sql .= ", ".price2num($total_localtax1);
1010  $sql .= ", ".price2num($total_localtax2);
1011  $sql .= ", ".price2num($total_ttc);
1012  $sql .= ", ".(int) $date_start_fill;
1013  $sql .= ", ".(int) $date_end_fill;
1014  $sql .= ", ".($fk_fournprice > 0 ? $fk_fournprice : 'null');
1015  $sql .= ", ".($pa_ht ? price2num($pa_ht) : 0);
1016  $sql .= ", ".((int) $info_bits);
1017  $sql .= ", ".((int) $ranktouse);
1018  $sql .= ", ".((int) $special_code);
1019  $sql .= ", ".($fk_unit ? ((int) $fk_unit) : "null");
1020  $sql .= ", ".(int) $this->fk_multicurrency;
1021  $sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
1022  $sql .= ", ".price2num($pu_ht_devise, 'CU');
1023  $sql .= ", ".price2num($multicurrency_total_ht, 'CT');
1024  $sql .= ", ".price2num($multicurrency_total_tva, 'CT');
1025  $sql .= ", ".price2num($multicurrency_total_ttc, 'CT');
1026  $sql .= ")";
1027 
1028  dol_syslog(get_class($this)."::addline", LOG_DEBUG);
1029  if ($this->db->query($sql)) {
1030  $lineId = $this->db->last_insert_id(MAIN_DB_PREFIX."facturedet_rec");
1031  $this->id = $facid;
1032  $this->update_price(1);
1033  return $lineId;
1034  } else {
1035  $this->error = $this->db->lasterror();
1036  return -1;
1037  }
1038  } else {
1039  $this->error = 'Recurring Invoice is suspended. adding lines not allowed.';
1040 
1041  return -1;
1042  }
1043  }
1044 
1074  public 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, $fk_fournprice = null, $pa_ht = 0)
1075  {
1076  global $mysoc;
1077 
1078  $facid = $this->id;
1079 
1080  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);
1081  include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
1082 
1083  // Clean parameters
1084  if (empty($remise_percent)) {
1085  $remise_percent = 0;
1086  }
1087 
1088  // Check parameters
1089  if ($type < 0) {
1090  return -1;
1091  }
1092 
1093  if ($this->brouillon) {
1094  // Clean parameters
1095  $remise_percent = price2num($remise_percent);
1096  $qty = price2num($qty);
1097  if (empty($info_bits)) {
1098  $info_bits = 0;
1099  }
1100  $pu_ht = price2num($pu_ht);
1101  $pu_ttc = price2num($pu_ttc);
1102  $pu_ht_devise = price2num($pu_ht_devise);
1103  if (!preg_match('/\‍((.*)\‍)/', $txtva)) {
1104  $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
1105  }
1106  $txlocaltax1 = price2num($txlocaltax1);
1107  $txlocaltax2 = price2num($txlocaltax2);
1108  if (empty($txlocaltax1)) {
1109  $txlocaltax1 = 0;
1110  }
1111  if (empty($txlocaltax2)) {
1112  $txlocaltax2 = 0;
1113  }
1114 
1115  if (empty($this->multicurrency_subprice)) {
1116  $this->multicurrency_subprice = 0;
1117  }
1118  if (empty($this->multicurrency_total_ht)) {
1119  $this->multicurrency_total_ht = 0;
1120  }
1121  if (empty($this->multicurrency_total_tva)) {
1122  $this->multicurrency_total_tva = 0;
1123  }
1124  if (empty($this->multicurrency_total_ttc)) {
1125  $this->multicurrency_total_ttc = 0;
1126  }
1127 
1128  if ($price_base_type == 'HT') {
1129  $pu = $pu_ht;
1130  } else {
1131  $pu = $pu_ttc;
1132  }
1133 
1134  // Calculate total with, without tax and tax from qty, pu, remise_percent and txtva
1135  // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
1136  // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
1137 
1138  $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
1139 
1140  // Clean vat code
1141  $vat_src_code = '';
1142  $reg = array();
1143  if (preg_match('/\‍((.*)\‍)/', $txtva, $reg)) {
1144  $vat_src_code = $reg[1];
1145  $txtva = preg_replace('/\s*\‍(.*\‍)/', '', $txtva); // Remove code into vatrate.
1146  }
1147 
1148  $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);
1149 
1150  $total_ht = $tabprice[0];
1151  $total_tva = $tabprice[1];
1152  $total_ttc = $tabprice[2];
1153  $total_localtax1 = $tabprice[9];
1154  $total_localtax2 = $tabprice[10];
1155  $pu_ht = $tabprice[3];
1156  $pu_tva = $tabprice[4];
1157  $pu_ttc = $tabprice[5];
1158 
1159  // MultiCurrency
1160  $multicurrency_total_ht = $tabprice[16];
1161  $multicurrency_total_tva = $tabprice[17];
1162  $multicurrency_total_ttc = $tabprice[18];
1163  $pu_ht_devise = $tabprice[19];
1164 
1165  $product_type = $type;
1166  if ($fk_product) {
1167  $product = new Product($this->db);
1168  $result = $product->fetch($fk_product);
1169  $product_type = $product->type;
1170  }
1171 
1172  $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET ";
1173  $sql .= "fk_facture = ".((int) $facid);
1174  $sql .= ", label=".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
1175  $sql .= ", description='".$this->db->escape($desc)."'";
1176  $sql .= ", price=".price2num($pu_ht);
1177  $sql .= ", qty=".price2num($qty);
1178  $sql .= ", tva_tx=".price2num($txtva);
1179  $sql .= ", vat_src_code='".$this->db->escape($vat_src_code)."'";
1180  $sql .= ", localtax1_tx=".((float) $txlocaltax1);
1181  $sql .= ", localtax1_type='".$this->db->escape($localtaxes_type[0])."'";
1182  $sql .= ", localtax2_tx=".((float) $txlocaltax2);
1183  $sql .= ", localtax2_type='".$this->db->escape($localtaxes_type[2])."'";
1184  $sql .= ", fk_product=".(!empty($fk_product) ? "'".$this->db->escape($fk_product)."'" : "null");
1185  $sql .= ", product_type=".((int) $product_type);
1186  $sql .= ", remise_percent='".price2num($remise_percent)."'";
1187  $sql .= ", subprice='".price2num($pu_ht)."'";
1188  $sql .= ", total_ht='".price2num($total_ht)."'";
1189  $sql .= ", total_tva='".price2num($total_tva)."'";
1190  $sql .= ", total_localtax1='".price2num($total_localtax1)."'";
1191  $sql .= ", total_localtax2='".price2num($total_localtax2)."'";
1192  $sql .= ", total_ttc='".price2num($total_ttc)."'";
1193  $sql .= ", date_start_fill=".((int) $date_start_fill);
1194  $sql .= ", date_end_fill=".((int) $date_end_fill);
1195  $sql .= ", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice : 'null');
1196  $sql .= ", buy_price_ht=".($pa_ht ? price2num($pa_ht) : 0);
1197  $sql .= ", info_bits=".((int) $info_bits);
1198  $sql .= ", rang=".((int) $rang);
1199  $sql .= ", special_code=".((int) $special_code);
1200  $sql .= ", fk_unit=".($fk_unit ? "'".$this->db->escape($fk_unit)."'" : "null");
1201  $sql .= ', multicurrency_subprice = '.price2num($pu_ht_devise);
1202  $sql .= ', multicurrency_total_ht = '.price2num($multicurrency_total_ht);
1203  $sql .= ', multicurrency_total_tva = '.price2num($multicurrency_total_tva);
1204  $sql .= ', multicurrency_total_ttc = '.price2num($multicurrency_total_ttc);
1205  $sql .= " WHERE rowid = ".((int) $rowid);
1206 
1207  dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
1208  if ($this->db->query($sql)) {
1209  $this->id = $facid;
1210  $this->update_price(1);
1211  return 1;
1212  } else {
1213  $this->error = $this->db->lasterror();
1214  return -1;
1215  }
1216  }
1217  return -1;
1218  }
1219 
1220 
1226  public function getNextDate()
1227  {
1228  if (empty($this->date_when)) {
1229  return false;
1230  }
1231  return dol_time_plus_duree($this->date_when, $this->frequency, $this->unit_frequency);
1232  }
1233 
1239  public function isMaxNbGenReached()
1240  {
1241  $ret = false;
1242  if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) {
1243  $ret = true;
1244  }
1245  return $ret;
1246  }
1247 
1254  public function strikeIfMaxNbGenReached($ret)
1255  {
1256  // Special case to strike the date
1257  return ($this->isMaxNbGenReached() ? '<strike>' : '').$ret.($this->isMaxNbGenReached() ? '</strike>' : '');
1258  }
1259 
1271  public function createRecurringInvoices($restrictioninvoiceid = 0, $forcevalidation = 0, $notrigger = 0)
1272  {
1273  global $conf, $langs, $db, $user, $hookmanager;
1274 
1275  $error = 0;
1276  $nb_create = 0;
1277 
1278  // Load translation files required by the page
1279  $langs->loadLangs(array("main", "bills"));
1280 
1281  $now = dol_now();
1282  $tmparray = dol_getdate($now);
1283  $today = dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year']); // Today is last second of current day
1284 
1285  $this->output = null;
1286 
1287  dol_syslog("createRecurringInvoices restrictioninvoiceid=".$restrictioninvoiceid." forcevalidation=".$forcevalidation);
1288 
1289  $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture_rec';
1290  $sql .= ' WHERE frequency > 0'; // A recurring invoice is an invoice with a frequency
1291  $sql .= " AND (date_when IS NULL OR date_when <= '".$this->db->idate($today)."')";
1292  $sql .= ' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
1293  $sql .= ' AND suspended = 0';
1294  $sql .= ' AND entity = '.$conf->entity; // MUST STAY = $conf->entity here
1295  if ($restrictioninvoiceid > 0) {
1296  $sql .= ' AND rowid = '.((int) $restrictioninvoiceid);
1297  }
1298  $sql .= $this->db->order('entity', 'ASC');
1299  //print $sql;exit;
1300  $parameters = array(
1301  'restrictioninvoiceid' => $restrictioninvoiceid,
1302  'forcevalidation' => $forcevalidation,
1303  );
1304  $reshook = $hookmanager->executeHooks('beforeCreationOfRecurringInvoices', $parameters, $sql); // note that $sql might be modified by hooks
1305 
1306  $resql = $this->db->query($sql);
1307  if ($resql) {
1308  $i = 0;
1309  $num = $this->db->num_rows($resql);
1310 
1311  if ($num) {
1312  $this->output .= $langs->trans("FoundXQualifiedRecurringInvoiceTemplate", $num)."\n";
1313  } else {
1314  $this->output .= $langs->trans("NoQualifiedRecurringInvoiceTemplateFound");
1315  }
1316 
1317  $saventity = $conf->entity;
1318 
1319  while ($i < $num) { // Loop on each template invoice. If $num = 0, test is false at first pass.
1320  $line = $this->db->fetch_object($resql);
1321 
1322  $this->db->begin();
1323 
1324  $invoiceidgenerated = 0;
1325 
1326  $facture = null;
1327  $facturerec = new FactureRec($this->db);
1328  $facturerec->fetch($line->rowid);
1329 
1330  if ($facturerec->id > 0) {
1331  // Set entity context
1332  $conf->entity = $facturerec->entity;
1333 
1334  dol_syslog("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref.", entity=".$facturerec->entity);
1335 
1336  $facture = new Facture($this->db);
1337  $facture->fac_rec = $facturerec->id; // We will create $facture from this recurring invoice
1338  $facture->fk_fac_rec_source = $facturerec->id; // We will create $facture from this recurring invoice
1339 
1340  $facture->type = self::TYPE_STANDARD;
1341  $facture->brouillon = 1;
1342  $facture->statut = self::STATUS_DRAFT;
1343  $facture->status = self::STATUS_DRAFT;
1344  $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.
1345  $facture->socid = $facturerec->socid;
1346  if (!empty($facturerec->fk_multicurrency)) {
1347  $facture->fk_multicurrency = $facturerec->fk_multicurrency;
1348  $facture->multicurrency_code = $facturerec->multicurrency_code;
1349  $facture->multicurrency_tx = $facturerec->multicurrency_tx;
1350  }
1351 
1352  $invoiceidgenerated = $facture->create($user);
1353  if ($invoiceidgenerated <= 0) {
1354  $this->errors = $facture->errors;
1355  $this->error = $facture->error;
1356  $error++;
1357  }
1358 
1359 
1360  if (!$error && ($facturerec->auto_validate || $forcevalidation)) {
1361  $result = $facture->validate($user);
1362  if ($result <= 0) {
1363  $this->errors = $facture->errors;
1364  $this->error = $facture->error;
1365  $error++;
1366  }
1367  }
1368  if (!$error && $facturerec->generate_pdf) {
1369  // We refresh the object in order to have all necessary data (like date_lim_reglement)
1370  $facture->fetch($facture->id);
1371  $result = $facture->generateDocument($facturerec->model_pdf, $langs);
1372  if ($result <= 0) {
1373  $this->errors = $facture->errors;
1374  $this->error = $facture->error;
1375  $error++;
1376  }
1377  }
1378  if (!$error && !$notrigger) {
1379  // Call trigger
1380  $result = $facturerec->call_trigger('BILLREC_CREATEBILL', $user);
1381  if ($result < 0) {
1382  $this->errors = $facturerec->errors;
1383  $this->error = $facturerec->error;
1384  $error++;
1385  }
1386  // End call triggers
1387  }
1388  } else {
1389  $error++;
1390  $this->error = "Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity."\n";
1391  $this->errors[] = "Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity;
1392  dol_syslog("createRecurringInvoices Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity);
1393  }
1394 
1395  if (!$error && $invoiceidgenerated >= 0) {
1396  $this->db->commit("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
1397  dol_syslog("createRecurringInvoices Process invoice template ".$facturerec->ref." is finished with a success generation");
1398  $nb_create++;
1399  $this->output .= $langs->trans("InvoiceGeneratedFromTemplate", $facture->ref, $facturerec->ref)."\n";
1400  } else {
1401  $this->db->rollback("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
1402  }
1403 
1404  $parameters = array(
1405  'cpt' => $i,
1406  'total' => $num,
1407  'errorCount' => $error,
1408  'invoiceidgenerated' => $invoiceidgenerated,
1409  'facturerec' => $facturerec, // it's an object which PHP passes by "reference", so modifiable by hooks.
1410  'this' => $this, // it's an object which PHP passes by "reference", so modifiable by hooks.
1411  );
1412  $reshook = $hookmanager->executeHooks('afterCreationOfRecurringInvoice', $parameters, $facture); // note: $facture can be modified by hooks (warning: $facture can be null)
1413 
1414  $i++;
1415  }
1416 
1417  $conf->entity = $saventity; // Restore entity context
1418  } else {
1419  dol_print_error($this->db);
1420  }
1421 
1422  $this->output = trim($this->output);
1423 
1424  return $error ? $error : 0;
1425  }
1426 
1439  public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '', $notooltip = '', $save_lastsearch_value = -1)
1440  {
1441  global $langs, $hookmanager;
1442 
1443  $result = '';
1444 
1445  $label = '<u>'.$langs->trans("RepeatableInvoice").'</u>';
1446  if (!empty($this->ref)) {
1447  $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1448  }
1449  if ($this->frequency > 0) {
1450  $label .= '<br><b>'.$langs->trans('Frequency').':</b> '.$langs->trans('FrequencyPer_'.$this->unit_frequency, $this->frequency);
1451  }
1452  if (!empty($this->date_last_gen)) {
1453  $label .= '<br><b>'.$langs->trans('DateLastGeneration').':</b> '.dol_print_date($this->date_last_gen, 'dayhour');
1454  }
1455  if ($this->frequency > 0) {
1456  if (!empty($this->date_when)) {
1457  $label .= '<br><b>'.$langs->trans('NextDateToExecution').':</b> ';
1458  $label .= (empty($this->suspended) ? '' : '<strike>').dol_print_date($this->date_when, 'day').(empty($this->suspended) ? '' : '</strike>'); // No hour for this property
1459  if (!empty($this->suspended)) {
1460  $label .= ' ('.$langs->trans("Disabled").')';
1461  }
1462  }
1463  }
1464 
1465  $url = DOL_URL_ROOT.'/compta/facture/card-rec.php?facid='.$this->id;
1466 
1467  if ($short) {
1468  return $url;
1469  }
1470 
1471  if ($option != 'nolink') {
1472  // Add param to save lastsearch_values or not
1473  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1474  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1475  $add_save_lastsearch_values = 1;
1476  }
1477  if ($add_save_lastsearch_values) {
1478  $url .= '&save_lastsearch_values=1';
1479  }
1480  }
1481 
1482  $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1483  $linkend = '</a>';
1484 
1485  $result .= $linkstart;
1486  if ($withpicto) {
1487  $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);
1488  }
1489  if ($withpicto != 2) {
1490  $result .= $this->ref;
1491  }
1492  $result .= $linkend;
1493  global $action;
1494  $hookmanager->initHooks(array($this->element . 'dao'));
1495  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
1496  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1497  if ($reshook > 0) {
1498  $result = $hookmanager->resPrint;
1499  } else {
1500  $result .= $hookmanager->resPrint;
1501  }
1502  return $result;
1503  }
1504 
1512  public function getLibStatut($mode = 0, $alreadypaid = -1)
1513  {
1514  return $this->LibStatut($this->frequency ? 1 : 0, $this->suspended, $mode, $alreadypaid, empty($this->type) ? 0 : $this->type);
1515  }
1516 
1517  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1528  public function LibStatut($recur, $status, $mode = 0, $alreadypaid = -1, $type = 0)
1529  {
1530  // phpcs:enable
1531  global $langs;
1532  $langs->load('bills');
1533 
1534  $labelStatus = $langs->transnoentitiesnoconv('Active');
1535  $statusType = 'status0';
1536 
1537  //print "$recur,$status,$mode,$alreadypaid,$type";
1538  if ($mode == 0) {
1539  if ($recur) {
1540  if ($status == self::STATUS_SUSPENDED) {
1541  $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1542  } else {
1543  $labelStatus = $langs->transnoentitiesnoconv('Active');
1544  }
1545  } else {
1546  if ($status == self::STATUS_SUSPENDED) {
1547  $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1548  } else {
1549  $labelStatus = $langs->transnoentitiesnoconv("Draft");
1550  }
1551  }
1552  } elseif ($mode == 1) {
1553  $prefix = 'Short';
1554  if ($recur) {
1555  if ($status == self::STATUS_SUSPENDED) {
1556  $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1557  } else {
1558  $labelStatus = $langs->transnoentitiesnoconv('Active');
1559  }
1560  } else {
1561  if ($status == self::STATUS_SUSPENDED) {
1562  $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1563  } else {
1564  $labelStatus = $langs->transnoentitiesnoconv("Draft");
1565  }
1566  }
1567  } elseif ($mode == 2) {
1568  if ($recur) {
1569  if ($status == self::STATUS_SUSPENDED) {
1570  $statusType = 'status6';
1571  $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1572  } else {
1573  $statusType = 'status4';
1574  $labelStatus = $langs->transnoentitiesnoconv('Active');
1575  }
1576  } else {
1577  if ($status == self::STATUS_SUSPENDED) {
1578  $statusType = 'status6';
1579  $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1580  } else {
1581  $statusType = 'status0';
1582  $labelStatus = $langs->transnoentitiesnoconv('Draft');
1583  }
1584  }
1585  } elseif ($mode == 3) {
1586  if ($recur) {
1587  $prefix = 'Short';
1588  if ($status == self::STATUS_SUSPENDED) {
1589  $statusType = 'status6';
1590  $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1591  } else {
1592  $statusType = 'status4';
1593  $labelStatus = $langs->transnoentitiesnoconv('Active');
1594  }
1595  } else {
1596  if ($status == self::STATUS_SUSPENDED) {
1597  $statusType = 'status6';
1598  $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1599  } else {
1600  $statusType = 'status0';
1601  $labelStatus = $langs->transnoentitiesnoconv('Draft');
1602  }
1603  }
1604  } elseif ($mode == 4) {
1605  $prefix = '';
1606  if ($recur) {
1607  if ($status == self::STATUS_SUSPENDED) {
1608  $statusType = 'status6';
1609  $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1610  } else {
1611  $statusType = 'status4';
1612  $labelStatus = $langs->transnoentitiesnoconv('Active');
1613  }
1614  } else {
1615  if ($status == self::STATUS_SUSPENDED) {
1616  $statusType = 'status6';
1617  $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1618  } else {
1619  $statusType = 'status0';
1620  $labelStatus = $langs->transnoentitiesnoconv('Draft');
1621  }
1622  }
1623  } elseif ($mode == 5 || $mode == 6) {
1624  $prefix = '';
1625  if ($mode == 5) {
1626  $prefix = 'Short';
1627  }
1628  if ($recur) {
1629  if ($status == self::STATUS_SUSPENDED) {
1630  $statusType = 'status6';
1631  $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1632  } else {
1633  $statusType = 'status4';
1634  $labelStatus = $langs->transnoentitiesnoconv('Active');
1635  }
1636  } else {
1637  if ($status == self::STATUS_SUSPENDED) {
1638  $statusType = 'status6';
1639  $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1640  } else {
1641  $statusType = 'status0';
1642  $labelStatus = $langs->transnoentitiesnoconv('Draft');
1643  }
1644  }
1645  }
1646 
1647  $labelStatusShort = $labelStatus;
1648 
1649  return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
1650  }
1651 
1658  public function info($id)
1659  {
1660  $sql = 'SELECT c.rowid, datec, tms as datem,';
1661  $sql .= ' fk_user_author, fk_user_modif';
1662  $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_rec as c';
1663  $sql .= ' WHERE c.rowid = '.((int) $id);
1664 
1665  $result = $this->db->query($sql);
1666  if ($result) {
1667  if ($this->db->num_rows($result)) {
1668  $obj = $this->db->fetch_object($result);
1669  $this->id = $obj->rowid;
1670  if ($obj->fk_user_author) {
1671  $cuser = new User($this->db);
1672  $cuser->fetch($obj->fk_user_author);
1673  $this->user_creation = $cuser;
1674  }
1675  if ($obj->fk_user_modif) {
1676  $muser = new User($this->db);
1677  $muser->fetch($obj->fk_user_modif);
1678  $this->user_modification = $muser;
1679  }
1680 
1681  $this->date_creation = $this->db->jdate($obj->datec);
1682  $this->date_modification = $this->db->jdate($obj->datem);
1683  }
1684  $this->db->free($result);
1685  } else {
1686  dol_print_error($this->db);
1687  }
1688  }
1689 
1698  public function initAsSpecimen($option = '')
1699  {
1700  global $user, $langs, $conf;
1701 
1702  $now = dol_now();
1703  $arraynow = dol_getdate($now);
1704  $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
1705 
1706  // Load array of products prodids
1707  $num_prods = 0;
1708  $prodids = array();
1709 
1710  $sql = "SELECT rowid";
1711  $sql .= " FROM ".MAIN_DB_PREFIX."product";
1712  $sql .= " WHERE entity IN (".getEntity('product').")";
1713  $sql .= $this->db->plimit(100);
1714 
1715  $resql = $this->db->query($sql);
1716  if ($resql) {
1717  $num_prods = $this->db->num_rows($resql);
1718  $i = 0;
1719  while ($i < $num_prods) {
1720  $i++;
1721  $row = $this->db->fetch_row($resql);
1722  $prodids[$i] = $row[0];
1723  }
1724  }
1725 
1726  // Initialize parameters
1727  $this->id = 0;
1728  $this->ref = 'SPECIMEN';
1729  $this->title = 'SPECIMEN';
1730  $this->specimen = 1;
1731  $this->socid = 1;
1732  $this->date = $nownotime;
1733  $this->date_lim_reglement = $nownotime + 3600 * 24 * 30;
1734  $this->cond_reglement_id = 1;
1735  $this->cond_reglement_code = 'RECEP';
1736  $this->date_lim_reglement = $this->calculate_date_lim_reglement();
1737  $this->mode_reglement_id = 0; // Not forced to show payment mode CHQ + VIR
1738  $this->mode_reglement_code = ''; // Not forced to show payment mode CHQ + VIR
1739  $this->note_public = 'This is a comment (public)';
1740  $this->note_private = 'This is a comment (private)';
1741  $this->note = 'This is a comment (private)';
1742  $this->fk_incoterms = 0;
1743  $this->location_incoterms = '';
1744 
1745  if (empty($option) || $option != 'nolines') {
1746  // Lines
1747  $nbp = 5;
1748  $xnbp = 0;
1749  while ($xnbp < $nbp) {
1750  $line = new FactureLigne($this->db);
1751  $line->desc = $langs->trans("Description")." ".$xnbp;
1752  $line->qty = 1;
1753  $line->subprice = 100;
1754  $line->tva_tx = 19.6;
1755  $line->localtax1_tx = 0;
1756  $line->localtax2_tx = 0;
1757  $line->remise_percent = 0;
1758  if ($xnbp == 1) { // Qty is negative (product line)
1759  $prodid = mt_rand(1, $num_prods);
1760  $line->fk_product = $prodids[$prodid];
1761  $line->qty = -1;
1762  $line->total_ht = -100;
1763  $line->total_ttc = -119.6;
1764  $line->total_tva = -19.6;
1765  } elseif ($xnbp == 2) { // UP is negative (free line)
1766  $line->subprice = -100;
1767  $line->total_ht = -100;
1768  $line->total_ttc = -119.6;
1769  $line->total_tva = -19.6;
1770  $line->remise_percent = 0;
1771  } elseif ($xnbp == 3) { // Discount is 50% (product line)
1772  $prodid = mt_rand(1, $num_prods);
1773  $line->fk_product = $prodids[$prodid];
1774  $line->total_ht = 50;
1775  $line->total_ttc = 59.8;
1776  $line->total_tva = 9.8;
1777  $line->remise_percent = 50;
1778  } else // (product line)
1779  {
1780  $prodid = mt_rand(1, $num_prods);
1781  $line->fk_product = $prodids[$prodid];
1782  $line->total_ht = 100;
1783  $line->total_ttc = 119.6;
1784  $line->total_tva = 19.6;
1785  $line->remise_percent = 00;
1786  }
1787 
1788  $this->lines[$xnbp] = $line;
1789  $xnbp++;
1790 
1791  $this->total_ht += $line->total_ht;
1792  $this->total_tva += $line->total_tva;
1793  $this->total_ttc += $line->total_ttc;
1794  }
1795  $this->revenuestamp = 0;
1796 
1797  // Add a line "offered"
1798  $line = new FactureLigne($this->db);
1799  $line->desc = $langs->trans("Description")." (offered line)";
1800  $line->qty = 1;
1801  $line->subprice = 100;
1802  $line->tva_tx = 19.6;
1803  $line->localtax1_tx = 0;
1804  $line->localtax2_tx = 0;
1805  $line->remise_percent = 100;
1806  $line->total_ht = 0;
1807  $line->total_ttc = 0; // 90 * 1.196
1808  $line->total_tva = 0;
1809  $prodid = mt_rand(1, $num_prods);
1810  $line->fk_product = $prodids[$prodid];
1811 
1812  $this->lines[$xnbp] = $line;
1813  $xnbp++;
1814  }
1815 
1816  $this->usenewprice = 0;
1817  }
1818 
1827  public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1828  {
1829  $tables = array(
1830  'facture_rec'
1831  );
1832 
1833  return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1834  }
1835 
1844  public static function replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
1845  {
1846  $tables = array(
1847  'facturedet_rec'
1848  );
1849 
1850  return CommonObject::commonReplaceProduct($dbs, $origin_id, $dest_id, $tables);
1851  }
1852 
1861  public function setFrequencyAndUnit($frequency, $unit, $notrigger = 0)
1862  {
1863  global $user;
1864 
1865  if (!$this->table_element) {
1866  dol_syslog(get_class($this)."::setFrequencyAndUnit was called on objet with property table_element not defined", LOG_ERR);
1867  return -1;
1868  }
1869 
1870  if (!empty($frequency) && empty($unit)) {
1871  dol_syslog(get_class($this)."::setFrequencyAndUnit was called on objet with params frequency defined but unit not defined", LOG_ERR);
1872  return -2;
1873  }
1874 
1875  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1876  $sql .= ' SET frequency = '.($frequency ? $this->db->escape($frequency) : 'null');
1877  if (!empty($unit)) {
1878  $sql .= ', unit_frequency = \''.$this->db->escape($unit).'\'';
1879  }
1880  $sql .= " WHERE rowid = ".((int) $this->id);
1881 
1882  dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
1883  if ($this->db->query($sql)) {
1884  $this->frequency = $frequency;
1885  if (!empty($unit)) {
1886  $this->unit_frequency = $unit;
1887  }
1888 
1889  if (!$notrigger) {
1890  // Call trigger
1891  $result = $this->call_trigger('BILLREC_MODIFY', $user);
1892  if ($result < 0) {
1893  return $result;
1894  }
1895  // End call triggers
1896  }
1897 
1898  return 1;
1899  } else {
1900  dol_print_error($this->db);
1901  return -1;
1902  }
1903  }
1904 
1913  public function setNextDate($date, $increment_nb_gen_done = 0, $notrigger = 0)
1914  {
1915 
1916  global $user;
1917 
1918  if (!$this->table_element) {
1919  dol_syslog(get_class($this)."::setNextDate was called on objet with property table_element not defined", LOG_ERR);
1920  return -1;
1921  }
1922  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1923  $sql .= " SET date_when = ".($date ? "'".$this->db->idate($date)."'" : "null");
1924  if ($increment_nb_gen_done > 0) {
1925  $sql .= ', nb_gen_done = nb_gen_done + 1';
1926  }
1927  $sql .= " WHERE rowid = ".((int) $this->id);
1928 
1929  dol_syslog(get_class($this)."::setNextDate", LOG_DEBUG);
1930  if ($this->db->query($sql)) {
1931  $this->date_when = $date;
1932  if ($increment_nb_gen_done > 0) {
1933  $this->nb_gen_done++;
1934  }
1935 
1936  if (!$notrigger) {
1937  // Call trigger
1938  $result = $this->call_trigger('BILLREC_MODIFY', $user);
1939  if ($result < 0) {
1940  return $result;
1941  }
1942  // End call triggers
1943  }
1944  return 1;
1945  } else {
1946  dol_print_error($this->db);
1947  return -1;
1948  }
1949  }
1950 
1958  public function setMaxPeriod($nb, $notrigger = 0)
1959  {
1960 
1961  global $user;
1962 
1963  if (!$this->table_element) {
1964  dol_syslog(get_class($this)."::setMaxPeriod was called on objet with property table_element not defined", LOG_ERR);
1965  return -1;
1966  }
1967 
1968  if (empty($nb)) {
1969  $nb = 0;
1970  }
1971 
1972  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1973  $sql .= ' SET nb_gen_max = '.((int) $nb);
1974  $sql .= " WHERE rowid = ".((int) $this->id);
1975 
1976  dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
1977  if ($this->db->query($sql)) {
1978  $this->nb_gen_max = $nb;
1979 
1980  if (!$notrigger) {
1981  // Call trigger
1982  $result = $this->call_trigger('BILLREC_MODIFY', $user);
1983  if ($result < 0) {
1984  return $result;
1985  }
1986  // End call triggers
1987  }
1988 
1989  return 1;
1990  } else {
1991  dol_print_error($this->db);
1992  return -1;
1993  }
1994  }
1995 
2003  public function setAutoValidate($validate, $notrigger = 0)
2004  {
2005  global $user;
2006 
2007  if (!$this->table_element) {
2008  dol_syslog(get_class($this)."::setAutoValidate was called on objet with property table_element not defined", LOG_ERR);
2009  return -1;
2010  }
2011 
2012  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2013  $sql .= ' SET auto_validate = '.((int) $validate);
2014  $sql .= " WHERE rowid = ".((int) $this->id);
2015 
2016  dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
2017  if ($this->db->query($sql)) {
2018  $this->auto_validate = $validate;
2019 
2020  if (!$notrigger) {
2021  // Call trigger
2022  $result = $this->call_trigger('BILLREC_MODIFY', $user);
2023  if ($result < 0) {
2024  return $result;
2025  }
2026  // End call triggers
2027  }
2028 
2029  return 1;
2030  } else {
2031  dol_print_error($this->db);
2032  return -1;
2033  }
2034  }
2035 
2043  public function setGeneratePdf($validate, $notrigger = 0)
2044  {
2045  global $user;
2046 
2047  if (!$this->table_element) {
2048  dol_syslog(get_class($this)."::setGeneratePdf was called on objet with property table_element not defined", LOG_ERR);
2049  return -1;
2050  }
2051 
2052  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2053  $sql .= ' SET generate_pdf = '.((int) $validate);
2054  $sql .= " WHERE rowid = ".((int) $this->id);
2055 
2056  dol_syslog(get_class($this)."::setGeneratePdf", LOG_DEBUG);
2057  if ($this->db->query($sql)) {
2058  $this->generate_pdf = $validate;
2059 
2060  if (!$notrigger) {
2061  // Call trigger
2062  $result = $this->call_trigger('BILLREC_MODIFY', $user);
2063  if ($result < 0) {
2064  return $result;
2065  }
2066  // End call triggers
2067  }
2068 
2069  return 1;
2070  } else {
2071  dol_print_error($this->db);
2072  return -1;
2073  }
2074  }
2075 
2083  public function setModelPdf($model, $notrigger = 0)
2084  {
2085  global $user;
2086  if (!$this->table_element) {
2087  dol_syslog(get_class($this)."::setModelPdf was called on objet with property table_element not defined", LOG_ERR);
2088  return -1;
2089  }
2090 
2091  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2092  $sql .= " SET modelpdf = '".$this->db->escape($model)."'";
2093  $sql .= " WHERE rowid = ".((int) $this->id);
2094 
2095  dol_syslog(get_class($this)."::setModelPdf", LOG_DEBUG);
2096  if ($this->db->query($sql)) {
2097  $this->model_pdf = $model;
2098 
2099  if (!$notrigger) {
2100  // Call trigger
2101  $result = $this->call_trigger('BILLREC_MODIFY', $user);
2102  if ($result < 0) {
2103  return $result;
2104  }
2105  // End call triggers
2106  }
2107 
2108  return 1;
2109  } else {
2110  dol_print_error($this->db);
2111  return -1;
2112  }
2113  }
2114 }
2115 
2116 
2117 
2123 {
2127  public $element = 'facturedetrec';
2128 
2132  public $table_element = 'facturedet_rec';
2133 
2134 
2135  public $fk_product_fournisseur_price;
2136  public $fk_fournprice; // For backward compatibility
2137 
2138  public $rang;
2139 
2140  public $desc;
2141  public $description;
2142 
2143  public $fk_product_type; // Use instead product_type
2144 
2145  public $fk_contract_line;
2146 
2147 
2155  public function delete(User $user, $notrigger = false)
2156  {
2157  $error = 0;
2158 
2159  $this->db->begin();
2160 
2161  if (!$error) {
2162  if (!$notrigger) {
2163  // Call triggers
2164  $result = $this->call_trigger('LINEBILLREC_DELETE', $user);
2165  if ($result < 0) {
2166  $error++;
2167  } // Do also here what you must do to rollback action if trigger fail
2168  // End call triggers
2169  }
2170  }
2171 
2172  if (!$error) {
2173  $result = $this->deleteExtraFields();
2174  if ($result < 0) {
2175  $error++;
2176  }
2177  }
2178 
2179  if (!$error) {
2180  $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.((int) $this->id);
2181 
2182  $res = $this->db->query($sql);
2183  if (!$res) {
2184  $error++;
2185  $this->errors[] = $this->db->lasterror();
2186  }
2187  }
2188 
2189  // Commit or rollback
2190  if ($error) {
2191  $this->db->rollback();
2192  return -1;
2193  } else {
2194  $this->db->commit();
2195  return 1;
2196  }
2197  }
2198 
2199 
2206  public function fetch($rowid)
2207  {
2208  $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,';
2209  $sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
2210  $sql .= ' l.date_start_fill, l.date_end_fill, l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
2211  $sql .= ' l.rang, l.special_code,';
2212  $sql .= ' l.fk_unit, l.fk_contract_line,';
2213  $sql .= ' l.import_key, l.fk_multicurrency,';
2214  $sql .= ' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
2215  $sql .= ' l.buy_price_ht, l.fk_product_fournisseur_price,';
2216  $sql .= ' l.fk_user_author, l.fk_user_modif,';
2217  $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
2218  $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l';
2219  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
2220  $sql .= ' WHERE l.rowid = '.((int) $rowid);
2221  $sql .= ' ORDER BY l.rang';
2222 
2223  dol_syslog('FactureRec::fetch', LOG_DEBUG);
2224  $result = $this->db->query($sql);
2225  if ($result) {
2226  $objp = $this->db->fetch_object($result);
2227 
2228  $this->id = $objp->rowid;
2229  $this->label = $objp->custom_label; // Label line
2230  $this->desc = $objp->description; // Description line
2231  $this->description = $objp->description; // Description line
2232  $this->product_type = $objp->product_type; // Type of line
2233  $this->ref = $objp->product_ref; // Ref product
2234  $this->product_ref = $objp->product_ref; // Ref product
2235  $this->libelle = $objp->product_label; // deprecated
2236  $this->product_label = $objp->product_label; // Label product
2237  $this->product_desc = $objp->product_desc; // Description product
2238  $this->fk_product_type = $objp->fk_product_type; // Type of product
2239  $this->qty = $objp->qty;
2240  $this->price = $objp->price;
2241  $this->subprice = $objp->subprice;
2242  $this->fk_facture = $objp->fk_facture;
2243  $this->vat_src_code = $objp->vat_src_code;
2244  $this->tva_tx = $objp->tva_tx;
2245  $this->localtax1_tx = $objp->localtax1_tx;
2246  $this->localtax2_tx = $objp->localtax2_tx;
2247  $this->localtax1_type = $objp->localtax1_type;
2248  $this->localtax2_type = $objp->localtax2_type;
2249  $this->remise_percent = $objp->remise_percent;
2250  //$this->fk_remise_except = $objp->fk_remise_except;
2251  $this->fk_product = $objp->fk_product;
2252  $this->date_start_fill = $objp->date_start_fill;
2253  $this->date_end_fill = $objp->date_end_fill;
2254  $this->info_bits = $objp->info_bits;
2255  $this->total_ht = $objp->total_ht;
2256  $this->total_tva = $objp->total_tva;
2257  $this->total_ttc = $objp->total_ttc;
2258  //$this->code_ventilation = $objp->fk_code_ventilation;
2259  $this->rang = $objp->rang;
2260  $this->special_code = $objp->special_code;
2261  $this->fk_unit = $objp->fk_unit;
2262  $this->fk_contract_line = $objp->fk_contract_line;
2263  $this->import_key = $objp->import_key;
2264  $this->fk_multicurrency = $objp->fk_multicurrency;
2265  $this->multicurrency_code = $objp->multicurrency_code;
2266  $this->multicurrency_subprice = $objp->multicurrency_subprice;
2267  $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
2268  $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
2269  $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2270 
2271  $this->buy_price_ht = $objp->buy_price_ht;
2272 
2273  $this->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
2274  $this->fk_user_author = $objp->fk_user_author;
2275  $this->fk_user_modif = $objp->fk_user_modif;
2276 
2277  $this->db->free($result);
2278  return 1;
2279  } else {
2280  $this->error = $this->db->lasterror();
2281  return -3;
2282  }
2283  }
2284 
2285 
2293  public function update(User $user, $notrigger = 0)
2294  {
2295  global $conf;
2296 
2297  $error = 0;
2298 
2299  include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
2300 
2301  $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET";
2302  $sql .= " fk_facture = ".((int) $this->fk_facture);
2303  $sql .= ", label=".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
2304  $sql .= ", description='".$this->db->escape($this->desc)."'";
2305  $sql .= ", price=".price2num($this->price);
2306  $sql .= ", qty=".price2num($this->qty);
2307  $sql .= ", tva_tx=".price2num($this->tva_tx);
2308  $sql .= ", vat_src_code='".$this->db->escape($this->vat_src_code)."'";
2309  $sql .= ", localtax1_tx=".price2num($this->localtax1_tx);
2310  $sql .= ", localtax1_type='".$this->db->escape($this->localtax1_type)."'";
2311  $sql .= ", localtax2_tx=".price2num($this->localtax2_tx);
2312  $sql .= ", localtax2_type='".$this->db->escape($this->localtax2_type)."'";
2313  $sql .= ", fk_product=".($this->fk_product > 0 ? $this->fk_product : "null");
2314  $sql .= ", product_type=".((int) $this->product_type);
2315  $sql .= ", remise_percent=".price2num($this->remise_percent);
2316  $sql .= ", subprice=".price2num($this->subprice);
2317  $sql .= ", info_bits=".price2num($this->info_bits);
2318  $sql .= ", date_start_fill=".(int) $this->date_start_fill;
2319  $sql .= ", date_end_fill=".(int) $this->date_end_fill;
2320  if (empty($this->skip_update_total)) {
2321  $sql .= ", total_ht=".price2num($this->total_ht);
2322  $sql .= ", total_tva=".price2num($this->total_tva);
2323  $sql .= ", total_localtax1=".price2num($this->total_localtax1);
2324  $sql .= ", total_localtax2=".price2num($this->total_localtax2);
2325  $sql .= ", total_ttc=".price2num($this->total_ttc);
2326  }
2327  $sql .= ", rang=".((int) $this->rang);
2328  $sql .= ", special_code=".((int) $this->special_code);
2329  $sql .= ", fk_unit=".($this->fk_unit ? "'".$this->db->escape($this->fk_unit)."'" : "null");
2330  $sql .= ", fk_contract_line=".($this->fk_contract_line ? $this->fk_contract_line : "null");
2331  $sql .= " WHERE rowid = ".((int) $this->id);
2332 
2333  $this->db->begin();
2334 
2335  dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
2336 
2337  $resql = $this->db->query($sql);
2338  if ($resql) {
2339  if (!$error) {
2340  $result = $this->insertExtraFields();
2341  if ($result < 0) {
2342  $error++;
2343  }
2344  }
2345 
2346  if (!$error && !$notrigger) {
2347  // Call trigger
2348  $result = $this->call_trigger('LINEBILLREC_MODIFY', $user);
2349  if ($result < 0) {
2350  $error++;
2351  }
2352  // End call triggers
2353  }
2354 
2355  if ($error) {
2356  $this->db->rollback();
2357  return -2;
2358  } else {
2359  $this->db->commit();
2360  return 1;
2361  }
2362  } else {
2363  $this->error = $this->db->lasterror();
2364  $this->db->rollback();
2365  return -2;
2366  }
2367  }
2368 }
$object ref
Definition: info.php:78
Superclass for invoices classes.
const TYPE_STANDARD
Standard invoice.
calculate_date_lim_reglement($cond_reglement=0)
Returns an invoice payment deadline based on the invoice settlement conditions and billing date.
const STATUS_DRAFT
Draft status.
Parent class of all other business classes for details of elements (invoices, contracts,...
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...
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='', $f_user=null, $notrigger=0)
Delete all links between an object $this.
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).
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage invoices.
Class to manage invoice lines.
Class to manage invoice lines of templates.
fetch($rowid)
Get line of template invoice.
update(User $user, $notrigger=0)
Update a line to invoice_rec.
Class to manage invoice templates.
create($user, $facid, $notrigger=0)
Create a predefined invoice.
setFrequencyAndUnit($frequency, $unit, $notrigger=0)
Update frequency and unit.
getLibStatut($mode=0, $alreadypaid=-1)
Return label of object status.
LibStatut($recur, $status, $mode=0, $alreadypaid=-1, $type=0)
Return label of a status.
fetch_lines()
Get lines of template invoices into this->lines.
info($id)
Load miscellaneous information for tab "Info".
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, $fk_fournprice=null, $pa_ht=0)
Add a line to invoice.
getLinesArray()
Create an array of invoice lines.
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, $fk_fournprice=null, $pa_ht=0)
Update a line to invoice.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $moretitle='', $notooltip='', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
isMaxNbGenReached()
Return if maximum number of generation is reached.
setModelPdf($model, $notrigger=0)
Update the model for documents.
__construct(DoliDB $db)
Constructor.
setNextDate($date, $increment_nb_gen_done=0, $notrigger=0)
Update the next date of execution.
setAutoValidate($validate, $notrigger=0)
Update the auto validate flag of invoice.
initAsSpecimen($option='')
Initialise an instance with random values.
setMaxPeriod($nb, $notrigger=0)
Update the maximum period.
update(User $user, $notrigger=0)
Update a line invoice_rec.
fetch($rowid, $ref='', $ref_ext='')
Load object and lines.
strikeIfMaxNbGenReached($ret)
Format string to output with by striking the string if max number of generation was reached.
setGeneratePdf($validate, $notrigger=0)
Update the auto generate documents.
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
getNextDate()
Return the next date of.
createRecurringInvoices($restrictioninvoiceid=0, $forcevalidation=0, $notrigger=0)
Create all recurrents invoices (for all entities if multicompany is used).
Class to manage products or services.
Class to manage Dolibarr users.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:122
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
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...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
getMarginInfos($pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $paht)
Return an array with margins information of a line.
div float
Buy price without taxes.
Definition: style.css.php:921
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
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:120