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';
45 public $element=
'facturerec';
50 public $table_element=
'facture_rec';
55 public $table_element_line=
'facturedet_rec';
60 public $fk_element=
'fk_facture';
81 public $date_last_gen;
87 public $unit_frequency;
92 public $usenewprice=0;
96 const STATUS_NOTSUSPENDED = 0;
97 const STATUS_SUSPENDED = 1;
126 $this->titre=trim($this->titre);
127 $this->usenewprice=empty($this->usenewprice)?0:$this->usenewprice;
128 if (empty($this->suspended)) $this->suspended=0;
131 if (empty($this->frequency))
134 $this->date_when=null;
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;
147 $facsrc=
new Facture($this->db);
148 $result=$facsrc->fetch($facid);
152 $this->brouillon = 1;
154 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facture_rec (";
161 $sql.=
", note_private";
162 $sql.=
", note_public";
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";
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);
212 if ($this->db->query($sql))
214 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"facture_rec");
217 $this->fk_multicurrency = $facsrc->fk_multicurrency;
218 $this->multicurrency_code = $facsrc->multicurrency_code;
219 $this->multicurrency_tx = $facsrc->multicurrency_tx;
222 $num=count($facsrc->lines);
223 for ($i = 0; $i < $num; $i++)
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.
')';
228 $result_insert = $this->
addline(
229 $facsrc->lines[$i]->desc,
230 $facsrc->lines[$i]->subprice,
231 $facsrc->lines[$i]->qty,
233 $facsrc->lines[$i]->localtax1_tx,
234 $facsrc->lines[$i]->localtax2_tx,
235 $facsrc->lines[$i]->fk_product,
236 $facsrc->lines[$i]->remise_percent,
238 $facsrc->lines[$i]->info_bits,
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
249 if ($result_insert < 0)
255 if (! empty($this->linkedObjectsIds) && empty($this->linked_objects))
257 $this->linked_objects = $this->linkedObjectsIds;
261 if (! $error && $this->
id && is_array($this->linked_objects) && ! empty($this->linked_objects))
263 foreach($this->linked_objects as $origin => $tmp_origin_id)
265 if (is_array($tmp_origin_id))
267 foreach($tmp_origin_id as $origin_id)
272 $this->error=$this->db->lasterror();
279 $origin_id = $tmp_origin_id;
283 $this->error=$this->db->lasterror();
292 $this->db->rollback();
302 $this->error=$this->db->lasterror();
303 $this->db->rollback();
309 $this->db->rollback();
324 function fetch($rowid, $ref=
'', $ref_ext=
'', $ref_int=
'')
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';
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';
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).
"'";
351 $result = $this->db->query($sql);
354 if ($this->db->num_rows($result))
356 $obj = $this->db->fetch_object($result);
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;
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;
415 if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1;
427 $this->error=$this->db->lasterror();
434 $this->error=
'Bill with id '.$rowid.
' or ref '.$ref.
' not found sql='.$sql;
435 dol_syslog(
'Facture::Fetch Error '.$this->error, LOG_ERR);
441 $this->error=$this->db->error();
467 $this->lines=array();
471 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
473 $extrafieldsline=$extrafieldsline->fetch_name_optionals_label(
'facturedet_rec',
true);
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,';
480 $sql.=
' l.rang, l.special_code,';
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';
490 dol_syslog(
'FactureRec::fetch_lines', LOG_DEBUG);
491 $result = $this->db->query($sql);
494 $num = $this->db->num_rows($result);
498 $objp = $this->db->fetch_object($result);
501 $line->id = $objp->rowid;
502 $line->rowid = $objp->rowid;
503 $line->desc = $objp->description;
504 $line->description = $objp->description;
505 $line->product_type = $objp->product_type;
506 $line->ref = $objp->product_ref;
507 $line->product_ref = $objp->product_ref;
508 $line->libelle = $objp->product_label;
509 $line->product_label = $objp->product_label;
510 $line->product_desc = $objp->product_desc;
511 $line->fk_product_type = $objp->fk_product_type;
512 $line->qty = $objp->qty;
513 $line->subprice = $objp->subprice;
515 $line->label = $objp->custom_label;
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;
539 $line->price = $objp->price;
540 $line->remise = $objp->remise;
542 $extralabelsline = $line->fetch_optionals($line->id);
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;
552 $this->lines[$i] = $line;
557 $this->db->free($result);
562 $this->error=$this->db->lasterror();
576 function delete(
User $user, $notrigger=0, $idwarehouse=-1)
580 dol_syslog(get_class($this).
"::delete rowid=".$rowid, LOG_DEBUG);
585 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"facturedet_rec WHERE fk_facture = ".$rowid;
587 if ($this->db->query($sql))
589 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"facture_rec WHERE rowid = ".$rowid;
591 if ($this->db->query($sql))
595 if ($res < 0) $error=-3;
599 $this->error=$this->db->lasterror();
605 $this->error=$this->db->lasterror();
616 $this->db->rollback();
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)
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';
657 if ($type < 0)
return -1;
663 if (preg_match(
'/\((.*)\)/', $txtva, $reg))
665 $vat_src_code = $reg[1];
666 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
669 if ($this->brouillon)
672 $remise_percent=
price2num($remise_percent);
673 if (empty($remise_percent)) $remise_percent=0;
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;
685 if ($price_base_type==
'HT')
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];
708 $multicurrency_total_ht = $tabprice[16];
709 $multicurrency_total_tva = $tabprice[17];
710 $multicurrency_total_ttc = $tabprice[18];
711 $pu_ht_devise = $tabprice[19];
716 $product=
new Product($this->db);
717 $result=$product->fetch($fk_product);
718 $product_type=$product->type;
721 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facturedet_rec (";
724 $sql.=
", description";
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";
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";
747 $sql.=
", special_code";
749 $sql.=
', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
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);
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;
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);
786 dol_syslog(get_class($this).
"::addline", LOG_DEBUG);
787 if ($this->db->query($sql))
789 $lineId = $this->db->last_insert_id(MAIN_DB_PREFIX.
"facturedet_rec");
796 $this->error=$this->db->lasterror();
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)
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';
839 if (empty($remise_percent)) $remise_percent = 0;
842 if ($type < 0)
return -1;
848 if (preg_match(
'/\((.*)\)/', $txtva, $reg))
850 $vat_src_code = $reg[1];
851 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
854 if ($this->brouillon)
857 $remise_percent=
price2num($remise_percent);
859 if (empty($info_bits)) $info_bits=0;
865 if (empty($txlocaltax1)) $txlocaltax1=0;
866 if (empty($txlocaltax2)) $txlocaltax2=0;
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;
873 if ($price_base_type==
'HT')
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);
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];
898 $multicurrency_total_ht = $tabprice[16];
899 $multicurrency_total_tva = $tabprice[17];
900 $multicurrency_total_ttc = $tabprice[18];
901 $pu_ht_devise = $tabprice[19];
906 $product=
new Product($this->db);
907 $result=$product->fetch($fk_product);
908 $product_type=$product->type;
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;
944 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
945 if ($this->db->query($sql))
953 $this->error=$this->db->lasterror();
967 if (empty($this->date_when))
return false;
979 if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) $ret =
true;
992 return ($this->
isMaxNbGenReached()?
'<strike>':
'').$ret.($this->isMaxNbGenReached()?
'</strike>':
'');
1007 global $conf, $langs, $db, $user;
1012 $langs->loadLangs(array(
"main",
"bills"));
1018 $today =
dol_mktime(23,59,59,$tmparray[
'mon'],$tmparray[
'mday'],$tmparray[
'year']);
1020 dol_syslog(
"createRecurringInvoices restictoninvoiceid=".$restictoninvoiceid.
" forcevalidation=".$forcevalidation);
1022 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'facture_rec';
1023 $sql.=
' WHERE frequency > 0';
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;
1028 if ($restictoninvoiceid > 0) $sql.=
' AND rowid = '.$restictoninvoiceid;
1029 $sql.= $db->order(
'entity',
'ASC');
1032 $resql = $db->query($sql);
1036 $num = $db->num_rows(
$resql);
1038 if ($num) $this->output.=$langs->trans(
"FoundXQualifiedRecurringInvoiceTemplate", $num).
"\n";
1039 else $this->output.=$langs->trans(
"NoQualifiedRecurringInvoiceTemplateFound");
1041 $saventity = $conf->entity;
1045 $line = $db->fetch_object(
$resql);
1049 $invoiceidgenerated = 0;
1052 $facturerec->fetch($line->rowid);
1054 if ($facturerec->id > 0)
1057 $conf->entity = $facturerec->entity;
1059 dol_syslog(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref.
", entity=".$facturerec->entity);
1062 $facture->fac_rec = $facturerec->id;
1063 $facture->fk_fac_rec_source = $facturerec->id;
1065 $facture->type = self::TYPE_STANDARD;
1066 $facture->brouillon = 1;
1067 $facture->date = (empty($facturerec->date_when)?$now:$facturerec->date_when);
1068 $facture->socid = $facturerec->socid;
1070 $invoiceidgenerated = $facture->create($user);
1071 if ($invoiceidgenerated <= 0)
1073 $this->errors = $facture->errors;
1074 $this->error = $facture->error;
1077 if (! $error && ($facturerec->auto_validate || $forcevalidation))
1079 $result = $facture->validate($user);
1082 $this->errors = $facture->errors;
1083 $this->error = $facture->error;
1087 if (! $error && $facturerec->generate_pdf)
1090 $facture->fetch($facture->id);
1091 $result = $facture->generateDocument($facturerec->modelpdf, $langs);
1094 $this->errors = $facture->errors;
1095 $this->error = $facture->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);
1108 if (! $error && $invoiceidgenerated >= 0)
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");
1113 $this->output.=$langs->trans(
"InvoiceGeneratedFromTemplate", $facture->ref, $facturerec->ref).
"\n";
1117 $db->rollback(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref);
1123 $conf->entity = $saventity;
1127 $this->output=trim($this->output);
1129 return $error?$error:0;
1144 function getNomUrl($withpicto=0,$option=
'',$max=0,$short=0,$moretitle=
'',$notooltip=
'',$save_lastsearch_value=-1)
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)
1157 if (! empty($this->date_when))
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>');
1161 if (! empty($this->suspended)) $label .=
' ('.$langs->trans(
"Disabled").
')';
1165 $url = DOL_URL_ROOT.
'/compta/facture/fiche-rec.php?facid='.$this->id;
1167 if ($short)
return $url;
1169 if ($option !=
'nolink')
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';
1177 $linkstart =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
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;
1198 return $this->
LibStatut($this->frequency?1:0, $this->suspended, $mode, $alreadypaid, empty($this->
type)?0:$this->
type);
1212 function LibStatut($recur, $status, $mode=0, $alreadypaid=-1, $type=0)
1216 $langs->load(
'bills');
1224 if ($status == self::STATUS_SUSPENDED)
return $langs->trans(
'Disabled');
1225 else return $langs->trans(
'Active');
1229 if ($status == self::STATUS_SUSPENDED)
return $langs->trans(
'Disabled');
1230 else return $langs->trans(
"Draft");
1238 if ($status == self::STATUS_SUSPENDED)
return $langs->trans(
'Disabled');
1239 else return $langs->trans(
'Active');
1243 if ($status == self::STATUS_SUSPENDED)
return $langs->trans(
'Disabled');
1244 else return $langs->trans(
"Draft");
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');
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');
1265 if ($status == self::STATUS_SUSPENDED)
return img_picto($langs->trans(
'Disabled'),
'statut6');
1266 else return img_picto($langs->trans(
'Active'),
'statut4');
1270 if ($status == self::STATUS_SUSPENDED)
return img_picto($langs->trans(
'Disabled'),
'statut6');
1271 else return img_picto($langs->trans(
'Draft'),
'statut0');
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');
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');
1288 elseif ($mode == 5 || $mode == 6)
1291 if ($mode == 5) $prefix=
'Short';
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');
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');
1315 global $user,$langs,$conf;
1319 $nownotime=
dol_mktime(0, 0, 0, $arraynow[
'mon'], $arraynow[
'mday'], $arraynow[
'year']);
1325 $sql =
"SELECT rowid";
1326 $sql.=
" FROM ".MAIN_DB_PREFIX.
"product";
1327 $sql.=
" WHERE entity IN (".getEntity(
'product').
")";
1328 $resql = $this->db->query($sql);
1331 $num_prods = $this->db->num_rows(
$resql);
1333 while ($i < $num_prods)
1336 $row = $this->db->fetch_row(
$resql);
1337 $prodids[$i] = $row[0];
1343 $this->ref =
'SPECIMEN';
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';
1351 $this->mode_reglement_id = 0;
1352 $this->mode_reglement_code =
'';
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=
'';
1359 if (empty($option) || $option !=
'nolines')
1364 while ($xnbp < $nbp)
1367 $line->desc=$langs->trans(
"Description").
" ".$xnbp;
1369 $line->subprice=100;
1371 $line->localtax1_tx=0;
1372 $line->localtax2_tx=0;
1373 $line->remise_percent=0;
1376 $prodid = mt_rand(1, $num_prods);
1377 $line->fk_product=$prodids[$prodid];
1379 $line->total_ht=-100;
1380 $line->total_ttc=-119.6;
1381 $line->total_tva=-19.6;
1383 else if ($xnbp == 2)
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;
1391 else if ($xnbp == 3)
1393 $prodid = mt_rand(1, $num_prods);
1394 $line->fk_product=$prodids[$prodid];
1396 $line->total_ttc=59.8;
1397 $line->total_tva=9.8;
1398 $line->remise_percent=50;
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;
1410 $this->lines[$xnbp]=$line;
1413 $this->total_ht += $line->total_ht;
1414 $this->total_tva += $line->total_tva;
1415 $this->total_ttc += $line->total_ttc;
1417 $this->revenuestamp = 0;
1421 $line->desc=$langs->trans(
"Description").
" (offered line)";
1423 $line->subprice=100;
1425 $line->localtax1_tx=0;
1426 $line->localtax2_tx=0;
1427 $line->remise_percent=100;
1431 $prodid = mt_rand(1, $num_prods);
1432 $line->fk_product=$prodids[$prodid];
1434 $this->lines[$xnbp]=$line;
1438 $this->usenewprice = 1;
1467 if (! $this->table_element)
1469 dol_syslog(get_class($this).
"::setFrequencyAndUnit was called on objet with property table_element not defined",LOG_ERR);
1473 if (!empty($frequency) && empty($unit))
1475 dol_syslog(get_class($this).
"::setFrequencyAndUnit was called on objet with params frequency defined but unit not defined",LOG_ERR);
1479 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1480 $sql.=
' SET frequency = '.($frequency?$this->db->escape($frequency):
'null');
1483 $sql.=
', unit_frequency = \''.$this->db->escape($unit).
'\'';
1485 $sql.=
' WHERE rowid = '.$this->id;
1487 dol_syslog(get_class($this).
"::setFrequencyAndUnit", LOG_DEBUG);
1488 if ($this->db->query($sql))
1490 $this->frequency = $frequency;
1491 if (!empty($unit)) $this->unit_frequency = $unit;
1510 if (! $this->table_element)
1512 dol_syslog(get_class($this).
"::setNextDate was called on objet with property table_element not defined",LOG_ERR);
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;
1520 dol_syslog(get_class($this).
"::setNextDate", LOG_DEBUG);
1521 if ($this->db->query($sql))
1523 $this->date_when = $date;
1524 if ($increment_nb_gen_done>0) $this->nb_gen_done++;
1542 if (! $this->table_element)
1544 dol_syslog(get_class($this).
"::setMaxPeriod was called on objet with property table_element not defined",LOG_ERR);
1548 if (empty($nb)) $nb=0;
1550 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1551 $sql.=
' SET nb_gen_max = '.$nb;
1552 $sql.=
' WHERE rowid = '.$this->id;
1554 dol_syslog(get_class($this).
"::setMaxPeriod", LOG_DEBUG);
1555 if ($this->db->query($sql))
1557 $this->nb_gen_max = $nb;
1575 if (! $this->table_element)
1577 dol_syslog(get_class($this).
"::setAutoValidate was called on objet with property table_element not defined",LOG_ERR);
1581 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1582 $sql.=
' SET auto_validate = '.$validate;
1583 $sql.=
' WHERE rowid = '.$this->id;
1585 dol_syslog(get_class($this).
"::setAutoValidate", LOG_DEBUG);
1586 if ($this->db->query($sql))
1588 $this->auto_validate = $validate;
1606 if (! $this->table_element)
1608 dol_syslog(get_class($this).
"::setGeneratePdf was called on objet with property table_element not defined",LOG_ERR);
1612 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1613 $sql.=
' SET generate_pdf = '.$validate;
1614 $sql.=
' WHERE rowid = '.$this->id;
1616 dol_syslog(get_class($this).
"::setGeneratePdf", LOG_DEBUG);
1617 if ($this->db->query($sql))
1619 $this->generate_pdf = $validate;
1637 if (! $this->table_element)
1639 dol_syslog(get_class($this).
"::setModelPdf was called on objet with property table_element not defined",LOG_ERR);
1643 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1644 $sql.=
' SET modelpdf = "' . $model .
'"';
1645 $sql.=
' WHERE rowid = '.$this->id;
1647 dol_syslog(get_class($this).
"::setModelPdf", LOG_DEBUG);
1648 if ($this->db->query($sql))
1650 $this->modelpdf = $model;
1672 public $element=
'facturedetrec';
1677 public $table_element=
'facturedet_rec';
1679 var $date_start_fill;
1690 function delete(
User $user, $notrigger =
false)
1699 $result=$this->
call_trigger(
'LINEBILLREC_DELETE', $user);
1700 if ($result < 0) { $error++; }
1707 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
' WHERE rowid='.$this->id;
1709 $res = $this->db->query($sql);
1712 $this->errors[] = $this->db->lasterror();
1718 $this->db->rollback();
1721 $this->db->commit();
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';
1747 $result = $this->db->query($sql);
1751 $objp = $this->db->fetch_object($result);
1753 $this->
id = $objp->rowid;
1754 $this->
label = $objp->custom_label;
1755 $this->desc = $objp->description;
1757 $this->product_type = $objp->product_type;
1758 $this->ref = $objp->product_ref;
1759 $this->product_ref = $objp->product_ref;
1760 $this->libelle = $objp->product_label;
1761 $this->product_label = $objp->product_label;
1762 $this->product_desc = $objp->product_desc;
1763 $this->fk_product_type = $objp->fk_product_type;
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;
1790 $this->db->free($result);
1795 $this->error=$this->db->lasterror();
1812 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
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))
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);
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;
1847 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
1848 $resql=$this->db->query($sql);
1851 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))
1860 if (! $error && ! $notrigger)
1863 $result=$this->
call_trigger(
'LINEBILL_REC_UPDATE', $user);
1866 $this->db->rollback();
1871 $this->db->commit();
1876 $this->error=$this->db->lasterror();
1877 $this->db->rollback();
print $object label
hash of file content (md5_file(dol_osencode($destfull))
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.
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.
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
Class to manage products or services.
Class to manage invoice templates.
Class to manage Dolibarr users.
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...
__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.
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.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
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.