32require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
43 const TRIGGER_PREFIX =
'BILLREC';
47 public $element =
'facturerec';
52 public $table_element =
'facture_rec';
57 public $table_element_line =
'facturedet_rec';
62 public $fk_element =
'fk_facture';
67 public $picto =
'bill';
93 public $multicurrency_subprice;
113 public $date_last_gen;
128 public $unit_frequency;
131 public $special_code;
133 public $usenewprice = 0;
135 public $date_lim_reglement;
136 public $cond_reglement_code;
137 public $mode_reglement_code;
139 public $fk_multicurrency;
140 public $multicurrency_code;
141 public $multicurrency_tx;
142 public $multicurrency_total_ht;
143 public $multicurrency_total_tva;
144 public $multicurrency_total_ttc;
148 public $auto_validate;
149 public $generate_pdf;
180 public $fields = array(
181 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
182 'titre' =>array(
'type'=>
'varchar(100)',
'label'=>
'Titre',
'enabled'=>1,
'showoncombobox' => 1,
'visible'=>-1,
'position'=>15),
183 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>20,
'index'=>1),
184 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>
'isModEnabled("societe")',
'visible'=>-1,
'notnull'=>1,
'position'=>25),
185 'subtype' =>array(
'type'=>
'smallint(6)',
'label'=>
'InvoiceSubtype',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>30),
186 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>35),
187 'total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'Tva',
'enabled'=>1,
'visible'=>-1,
'position'=>55,
'isameasure'=>1),
188 'localtax1' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax1',
'enabled'=>1,
'visible'=>-1,
'position'=>60,
'isameasure'=>1),
189 'localtax2' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax2',
'enabled'=>1,
'visible'=>-1,
'position'=>65,
'isameasure'=>1),
190 'total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'Total',
'enabled'=>1,
'visible'=>-1,
'position'=>70,
'isameasure'=>1),
191 'total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'Total ttc',
'enabled'=>1,
'visible'=>-1,
'position'=>75,
'isameasure'=>1),
192 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
193 '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),
194 'fk_cond_reglement' =>array(
'type'=>
'integer',
'label'=>
'Fk cond reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
195 'fk_mode_reglement' =>array(
'type'=>
'integer',
'label'=>
'Fk mode reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
196 'date_lim_reglement' =>array(
'type'=>
'date',
'label'=>
'Date lim reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
197 'note_private' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>105),
198 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>110),
199 'modelpdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Modelpdf',
'enabled'=>1,
'visible'=>-1,
'position'=>115),
200 'date_when' =>array(
'type'=>
'datetime',
'label'=>
'Date when',
'enabled'=>1,
'visible'=>-1,
'position'=>130),
201 'date_last_gen' =>array(
'type'=>
'datetime',
'label'=>
'Date last gen',
'enabled'=>1,
'visible'=>-1,
'position'=>135),
202 'nb_gen_done' =>array(
'type'=>
'integer',
'label'=>
'Nb gen done',
'enabled'=>1,
'visible'=>-1,
'position'=>140),
203 'nb_gen_max' =>array(
'type'=>
'integer',
'label'=>
'Nb gen max',
'enabled'=>1,
'visible'=>-1,
'position'=>145),
204 'frequency' =>array(
'type'=>
'integer',
'label'=>
'Frequency',
'enabled'=>1,
'visible'=>-1,
'position'=>150),
205 'unit_frequency' =>array(
'type'=>
'varchar(2)',
'label'=>
'UnitFrequency',
'enabled'=>1,
'visible'=>-1,
'position'=>152),
206 'usenewprice' =>array(
'type'=>
'integer',
'label'=>
'UseNewPrice',
'enabled'=>1,
'visible'=>0,
'position'=>155),
207 'revenuestamp' =>array(
'type'=>
'double(24,8)',
'label'=>
'RevenueStamp',
'enabled'=>1,
'visible'=>-1,
'position'=>160,
'isameasure'=>1),
208 'auto_validate' =>array(
'type'=>
'integer',
'label'=>
'Auto validate',
'enabled'=>1,
'visible'=>-1,
'position'=>165),
209 'generate_pdf' =>array(
'type'=>
'integer',
'label'=>
'Generate pdf',
'enabled'=>1,
'visible'=>-1,
'position'=>170),
210 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'Fk account',
'enabled'=>
'isModEnabled("banque")',
'visible'=>-1,
'position'=>175),
211 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'Fk multicurrency',
'enabled'=>1,
'visible'=>-1,
'position'=>180),
212 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'Multicurrency code',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
213 'multicurrency_tx' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency tx',
'enabled'=>1,
'visible'=>-1,
'position'=>190,
'isameasure'=>1),
214 'multicurrency_total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total ht',
'enabled'=>1,
'visible'=>-1,
'position'=>195,
'isameasure'=>1),
215 'multicurrency_total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total tva',
'enabled'=>1,
'visible'=>-1,
'position'=>200,
'isameasure'=>1),
216 'multicurrency_total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total ttc',
'enabled'=>1,
'visible'=>-1,
'position'=>205,
'isameasure'=>1),
217 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>210),
218 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>215),
219 'suspended' =>array(
'type'=>
'integer',
'label'=>
'Suspended',
'enabled'=>1,
'visible'=>-1,
'position'=>225),
223 const STATUS_NOTSUSPENDED = 0;
224 const STATUS_SUSPENDED = 1;
247 public function create($user, $facid, $notrigger = 0, $onlylines = array())
255 $this->titre = trim(isset($this->titre) ? $this->titre : $this->title);
256 $this->title = trim($this->title);
257 $this->usenewprice = empty($this->usenewprice) ? 0 : $this->usenewprice;
258 if (empty($this->suspended)) {
259 $this->suspended = 0;
263 if (empty($this->frequency)) {
264 $this->frequency = 0;
265 $this->date_when =
null;
268 $this->frequency = abs($this->frequency);
269 $this->nb_gen_done = 0;
270 $this->nb_gen_max = empty($this->nb_gen_max) ? 0 : $this->nb_gen_max;
271 $this->auto_validate = empty($this->auto_validate) ? 0 : $this->auto_validate;
272 $this->generate_pdf = empty($this->generate_pdf) ? 0 : $this->generate_pdf;
277 $facsrc =
new Facture($this->db);
278 $result = $facsrc->fetch($facid);
280 $this->socid = $facsrc->socid;
282 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facture_rec (";
290 $sql .=
", note_private";
291 $sql .=
", note_public";
292 $sql .=
", modelpdf";
293 $sql .=
", fk_user_author";
294 $sql .=
", fk_projet";
295 $sql .=
", fk_account";
296 $sql .=
", fk_cond_reglement";
297 $sql .=
", fk_mode_reglement";
298 $sql .=
", usenewprice";
299 $sql .=
", frequency";
300 $sql .=
", unit_frequency";
301 $sql .=
", date_when";
302 $sql .=
", date_last_gen";
303 $sql .=
", nb_gen_done";
304 $sql .=
", nb_gen_max";
305 $sql .=
", auto_validate";
306 $sql .=
", generate_pdf";
307 $sql .=
", fk_multicurrency";
308 $sql .=
", multicurrency_code";
309 $sql .=
", multicurrency_tx";
310 $sql .=
", suspended";
311 $sql .=
") VALUES (";
312 $sql .=
"'".$this->db->escape($this->titre ? $this->titre : $this->title).
"'";
313 $sql .=
", ".((int) $this->socid);
314 $sql .=
", ".($this->subtype ?
"'".$this->db->escape($this->subtype).
"'" :
"null");
315 $sql .=
", ".((int) $conf->entity);
316 $sql .=
", '".$this->db->idate($now).
"'";
317 $sql .=
", ".(!empty($facsrc->total_ttc) ? ((float) $facsrc->total_ttc) :
'0');
319 $sql .=
", ".(!empty($this->note_private) ? (
"'".$this->db->escape($this->note_private).
"'") :
"NULL");
320 $sql .=
", ".(!empty($this->note_public) ? (
"'".$this->db->escape($this->note_public).
"'") :
"NULL");
321 $sql .=
", ".(!empty($this->model_pdf) ? (
"'".$this->db->escape($this->model_pdf).
"'") :
"NULL");
322 $sql .=
", ".((int) $user->id);
323 $sql .=
", ".(!empty($this->fk_project) ? ((int) $this->fk_project) :
"null");
324 $sql .=
", ".(!empty($facsrc->fk_account) ? ((int) $facsrc->fk_account) :
"null");
325 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
"null");
326 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
"null");
327 $sql .=
", ".((int) $this->usenewprice);
328 $sql .=
", ".((int) $this->frequency);
329 $sql .=
", '".$this->db->escape($this->unit_frequency).
"'";
330 $sql .=
", ".(!empty($this->date_when) ?
"'".$this->db->idate($this->date_when).
"'" :
'NULL');
331 $sql .=
", ".(!empty($this->date_last_gen) ?
"'".$this->db->idate($this->date_last_gen).
"'" :
'NULL');
332 $sql .=
", ".((int) $this->nb_gen_done);
333 $sql .=
", ".((int) $this->nb_gen_max);
334 $sql .=
", ".((int) $this->auto_validate);
335 $sql .=
", ".((int) $this->generate_pdf);
336 $sql .=
", ".((int) $facsrc->fk_multicurrency);
337 $sql .=
", '".$this->db->escape($facsrc->multicurrency_code).
"'";
338 $sql .=
", ".((float) $facsrc->multicurrency_tx);
339 $sql .=
", ".((int) $this->suspended);
342 if ($this->db->query($sql)) {
343 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"facture_rec");
346 $this->fk_multicurrency = $facsrc->fk_multicurrency;
347 $this->multicurrency_code = $facsrc->multicurrency_code;
348 $this->multicurrency_tx = $facsrc->multicurrency_tx;
353 $num = count($facsrc->lines);
354 for ($i = 0; $i < $num; $i++) {
355 if (!empty($onlylines) && !in_array($facsrc->lines[$i]->id, $onlylines)) {
360 if (($facsrc->lines[$i]->product_type != 9 && empty($facsrc->lines[$i]->fk_parent_line)) || $facsrc->lines[$i]->product_type == 9) {
364 $tva_tx = $facsrc->lines[$i]->tva_tx;
365 if (!empty($facsrc->lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
366 $tva_tx .=
' ('.$facsrc->lines[$i]->vat_src_code.
')';
369 $default_start_fill =
getDolGlobalInt(
'INVOICEREC_SET_AUTOFILL_DATE_START');
370 $default_end_fill =
getDolGlobalInt(
'INVOICEREC_SET_AUTOFILL_DATE_END');
372 $result_insert = $this->
addline(
373 $facsrc->lines[$i]->desc,
374 $facsrc->lines[$i]->subprice,
375 $facsrc->lines[$i]->qty,
377 $facsrc->lines[$i]->localtax1_tx,
378 $facsrc->lines[$i]->localtax2_tx,
379 $facsrc->lines[$i]->fk_product,
380 $facsrc->lines[$i]->remise_percent,
382 $facsrc->lines[$i]->info_bits,
385 $facsrc->lines[$i]->product_type,
386 $facsrc->lines[$i]->rang,
387 $facsrc->lines[$i]->special_code,
388 $facsrc->lines[$i]->label,
389 $facsrc->lines[$i]->fk_unit,
390 $facsrc->lines[$i]->multicurrency_subprice,
394 $facsrc->lines[$i]->pa_ht,
399 if ($result_insert > 0 && $facsrc->lines[$i]->product_type == 9) {
400 $fk_parent_line = $result_insert;
403 if ($result_insert < 0) {
408 $result2 = $objectline->fetch($result_insert);
411 if (method_exists($facsrc->lines[$i],
'fetch_optionals')) {
412 $facsrc->lines[$i]->fetch_optionals($facsrc->lines[$i]->id);
413 $objectline->array_options = $facsrc->lines[$i]->array_options;
416 $result = $objectline->insertExtraFields();
420 } elseif ($result2 < 0) {
421 $this->errors[] = $objectline->error;
427 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
428 $this->linked_objects = $this->linkedObjectsIds;
432 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
433 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
434 if (is_array($tmp_origin_id)) {
435 foreach ($tmp_origin_id as $origin_id) {
438 $this->error = $this->db->lasterror();
443 $origin_id = $tmp_origin_id;
446 $this->error = $this->db->lasterror();
460 if (!$error && !$notrigger) {
464 $this->db->rollback();
471 $this->db->rollback();
478 $this->error = $this->db->lasterror();
479 $this->db->rollback();
483 $this->db->rollback();
500 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_rec SET";
501 $sql .=
" entity = ".((int) $this->entity).
",";
502 $sql .=
" titre = '".$this->db->escape($this->title).
"',";
503 $sql .=
" suspended = ".((int) $this->suspended).
",";
504 $sql .=
" fk_soc = ".((int) $this->socid).
",";
505 $sql .=
" total_tva = ".((float) $this->total_tva).
",";
506 $sql .=
" localtax1 = ".((float) $this->total_localtax1).
",";
507 $sql .=
" localtax2 = ".((float) $this->total_localtax2).
",";
508 $sql .=
" total_ht = ".((float) $this->total_ht).
",";
509 $sql .=
" total_ttc = ".((float) $this->total_ttc);
511 $sql .=
" WHERE rowid = ".((int) $this->
id);
515 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
517 $resql = $this->db->query($sql);
526 if (!$error && !$notrigger) {
530 $this->db->rollback();
538 $this->error = $this->db->lasterror();
539 $this->db->rollback();
554 public function fetch($rowid, $ref =
'', $ref_ext =
'', $noextrafields = 0, $nolines = 0)
558 $sql =
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc, f.subtype, f.total_tva, f.localtax1, f.localtax2, f.total_ht, f.total_ttc';
559 $sql .=
', f.date_lim_reglement as dlr';
560 $sql .=
', f.note_private, f.note_public, f.fk_user_author';
561 $sql .=
', f.modelpdf as model_pdf';
562 $sql .=
', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet as fk_project';
563 $sql .=
', f.fk_account';
564 $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';
565 $sql .=
', f.generate_pdf';
566 $sql .=
", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
567 $sql .=
', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
568 $sql .=
', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
570 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as f';
571 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
572 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as p ON f.fk_mode_reglement = p.id';
574 $sql .=
' WHERE f.entity IN ('.getEntity(
'invoice').
')';
576 $sql .=
' AND f.rowid = '.((int) $rowid);
578 $sql .=
" AND f.titre = '".$this->db->escape($ref).
"'";
580 $sql .=
' AND f.rowid = 0';
586 $result = $this->db->query($sql);
588 if ($this->db->num_rows($result)) {
589 $obj = $this->db->fetch_object($result);
591 $this->
id = $obj->rowid;
592 $this->entity = $obj->entity;
593 $this->titre = $obj->title;
594 $this->title = $obj->title;
595 $this->
ref = $obj->title;
596 $this->subtype = $obj->subtype;
597 $this->suspended = $obj->suspended;
598 $this->total_ht = $obj->total_ht;
599 $this->total_tva = $obj->total_tva;
600 $this->total_localtax1 = $obj->localtax1;
601 $this->total_localtax2 = $obj->localtax2;
602 $this->total_ttc = $obj->total_ttc;
603 $this->socid = $obj->fk_soc;
604 $this->date_lim_reglement = $this->db->jdate($obj->dlr);
605 $this->mode_reglement_id = $obj->fk_mode_reglement;
606 $this->mode_reglement_code = $obj->mode_reglement_code;
607 $this->mode_reglement = $obj->mode_reglement_libelle;
608 $this->cond_reglement_id = $obj->fk_cond_reglement;
609 $this->cond_reglement_code = $obj->cond_reglement_code;
610 $this->cond_reglement = $obj->cond_reglement_libelle;
611 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
612 $this->fk_project = $obj->fk_project;
613 $this->fk_account = $obj->fk_account;
614 $this->note_private = $obj->note_private;
615 $this->note_public = $obj->note_public;
616 $this->user_author = $obj->fk_user_author;
617 $this->model_pdf = $obj->model_pdf;
619 $this->frequency = $obj->frequency;
620 $this->unit_frequency = $obj->unit_frequency;
621 $this->date_when = $this->db->jdate($obj->date_when);
622 $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
623 $this->nb_gen_done = $obj->nb_gen_done;
624 $this->nb_gen_max = $obj->nb_gen_max;
625 $this->usenewprice = $obj->usenewprice;
626 $this->auto_validate = $obj->auto_validate;
627 $this->generate_pdf = $obj->generate_pdf;
630 $this->fk_multicurrency = $obj->fk_multicurrency;
631 $this->multicurrency_code = $obj->multicurrency_code;
632 $this->multicurrency_tx = $obj->multicurrency_tx;
633 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
634 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
635 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
639 if (empty($noextrafields)) {
642 $this->error = $this->db->lasterror();
648 if (empty($nolines)) {
651 $this->error = $this->db->lasterror();
658 $this->error =
'Bill with id '.$rowid.
' or ref '.$ref.
' not found';
659 dol_syslog(
'Facture::Fetch Error '.$this->error, LOG_ERR);
663 $this->error = $this->db->error();
690 $this->lines = array();
692 dol_syslog(
'FactureRec::fetch_lines', LOG_DEBUG);
694 $sql =
'SELECT l.rowid, l.fk_facture, l.fk_product, l.fk_parent_line, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx, ';
695 $sql .=
' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
696 $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,';
697 $sql .=
' l.rang, l.special_code,';
698 $sql .=
' l.fk_unit, l.fk_contract_line,';
699 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
700 $sql .=
' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
701 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facturedet_rec as l';
702 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
703 $sql .=
' WHERE l.fk_facture = '.((int) $this->
id);
704 $sql .=
' ORDER BY l.rang';
706 $result = $this->db->query($sql);
708 $num = $this->db->num_rows($result);
711 $objp = $this->db->fetch_object($result);
714 $line->id = $objp->rowid;
715 $line->rowid = $objp->rowid;
716 $line->fk_facture = $objp->fk_facture;
717 $line->fk_parent_line = $objp->fk_parent_line;
718 $line->desc = $objp->description;
719 $line->description = $objp->description;
720 $line->ref = $objp->product_ref;
721 $line->product_ref = $objp->product_ref;
722 $line->libelle = $objp->product_label;
723 $line->product_label = $objp->product_label;
724 $line->product_desc = $objp->product_desc;
725 $line->product_type = $objp->product_type;
726 $line->fk_product_type = $objp->fk_product_type;
727 $line->qty = $objp->qty;
728 $line->subprice = $objp->subprice;
730 $line->label = $objp->custom_label;
732 $line->vat_src_code = $objp->vat_src_code;
733 $line->tva_tx = $objp->tva_tx;
734 $line->localtax1_tx = $objp->localtax1_tx;
735 $line->localtax2_tx = $objp->localtax2_tx;
736 $line->localtax1_type = $objp->localtax1_type;
737 $line->localtax2_type = $objp->localtax2_type;
738 $line->remise_percent = $objp->remise_percent;
740 $line->fk_product = $objp->fk_product;
741 $line->date_start_fill = $objp->date_start_fill;
742 $line->date_end_fill = $objp->date_end_fill;
743 $line->info_bits = $objp->info_bits;
744 $line->total_ht = $objp->total_ht;
745 $line->total_tva = $objp->total_tva;
746 $line->total_ttc = $objp->total_ttc;
748 $line->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
749 $line->fk_fournprice = $objp->fk_product_fournisseur_price;
751 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $objp->fk_product_fournisseur_price, $objp->pa_ht);
753 $line->buyprice = $marginInfos[0];
754 $line->pa_ht = $marginInfos[0];
755 $line->marge_tx = $marginInfos[1];
756 $line->marque_tx = $marginInfos[2];
757 $line->rang = $objp->rang;
758 $line->special_code = $objp->special_code;
759 $line->fk_unit = $objp->fk_unit;
760 $line->fk_contract_line = $objp->fk_contract_line;
763 $line->price = $objp->price;
764 $line->remise = $objp->remise;
766 $line->fetch_optionals();
769 $line->fk_multicurrency = $objp->fk_multicurrency;
770 $line->multicurrency_code = $objp->multicurrency_code;
771 $line->multicurrency_subprice = $objp->multicurrency_subprice;
772 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
773 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
774 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
776 $this->lines[$i] = $line;
781 $this->db->free($result);
784 $this->error = $this->db->lasterror();
798 public function delete(
User $user, $notrigger = 0, $idwarehouse = -1)
802 dol_syslog(get_class($this).
"::delete rowid=".((
int) $rowid), LOG_DEBUG);
807 $main = MAIN_DB_PREFIX.
'facturedet_rec';
808 $ef = $main.
"_extrafields";
810 $sqlef =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_facture = ".((int) $rowid).
")";
811 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"facturedet_rec WHERE fk_facture = ".((int) $rowid);
813 if ($this->db->query($sqlef) && $this->db->query($sql)) {
814 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"facture_rec WHERE rowid = ".((int) $rowid);
816 if ($this->db->query($sql)) {
828 $this->error = $this->db->lasterror();
832 $this->error = $this->db->lasterror();
835 if (!$error && !$notrigger) {
847 $this->db->rollback();
881 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 = 0, $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, $fk_parent_line = 0)
887 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);
888 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
900 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
901 $vat_src_code = $reg[1];
902 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
907 $remise_percent =
price2num($remise_percent);
908 if (empty($remise_percent)) {
914 if (!preg_match(
'/\((.*)\)/', $txtva)) {
922 if (empty($txlocaltax1)) {
925 if (empty($txlocaltax2)) {
928 if (empty($info_bits)) {
932 if ($price_base_type ==
'HT') {
943 $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);
944 $total_ht = $tabprice[0];
945 $total_tva = $tabprice[1];
946 $total_ttc = $tabprice[2];
947 $total_localtax1 = $tabprice[9];
948 $total_localtax2 = $tabprice[10];
949 $pu_ht = $tabprice[3];
952 $multicurrency_total_ht = $tabprice[16];
953 $multicurrency_total_tva = $tabprice[17];
954 $multicurrency_total_ttc = $tabprice[18];
955 $pu_ht_devise = $tabprice[19];
957 $product_type = $type;
959 $product =
new Product($this->db);
960 $result = $product->fetch($fk_product);
961 $product_type = $product->type;
964 if (empty($fk_parent_line) || $fk_parent_line < 0) {
970 if ($ranktouse == -1) {
972 $ranktouse = $rangmax + 1;
975 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facturedet_rec (";
976 $sql .=
"fk_facture";
977 $sql .=
", fk_parent_line";
979 $sql .=
", description";
983 $sql .=
", vat_src_code";
984 $sql .=
", localtax1_tx";
985 $sql .=
", localtax1_type";
986 $sql .=
", localtax2_tx";
987 $sql .=
", localtax2_type";
988 $sql .=
", fk_product";
989 $sql .=
", product_type";
990 $sql .=
", remise_percent";
991 $sql .=
", subprice";
993 $sql .=
", total_ht";
994 $sql .=
", total_tva";
995 $sql .=
", total_localtax1";
996 $sql .=
", total_localtax2";
997 $sql .=
", total_ttc";
998 $sql .=
", date_start_fill";
999 $sql .=
", date_end_fill";
1000 $sql .=
", fk_product_fournisseur_price";
1001 $sql .=
", buy_price_ht";
1002 $sql .=
", info_bits";
1004 $sql .=
", special_code";
1005 $sql .=
", fk_unit";
1006 $sql .=
', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
1007 $sql .=
") VALUES (";
1008 $sql .=
" ".((int) $facid);
1009 $sql .=
", ".($fk_parent_line > 0 ? ((int) $fk_parent_line) :
"null");
1010 $sql .=
", ".(!empty($label) ?
"'".$this->db->escape($label).
"'" :
"null");
1011 $sql .=
", '".$this->db->escape($desc).
"'";
1012 $sql .=
", ".price2num($pu_ht);
1013 $sql .=
", ".price2num($qty);
1014 $sql .=
", ".price2num($txtva);
1015 $sql .=
", '".$this->db->escape($vat_src_code).
"'";
1016 $sql .=
", ".price2num($txlocaltax1);
1017 $sql .=
", '".$this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] :
'').
"'";
1018 $sql .=
", ".price2num($txlocaltax2);
1019 $sql .=
", '".$this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] :
'').
"'";
1020 $sql .=
", ".(!empty($fk_product) ?
"'".$this->db->escape($fk_product).
"'" :
"null");
1021 $sql .=
", ".((int) $product_type);
1022 $sql .=
", ".price2num($remise_percent);
1023 $sql .=
", ".price2num($pu_ht);
1025 $sql .=
", ".price2num($total_ht);
1026 $sql .=
", ".price2num($total_tva);
1027 $sql .=
", ".price2num($total_localtax1);
1028 $sql .=
", ".price2num($total_localtax2);
1029 $sql .=
", ".price2num($total_ttc);
1030 $sql .=
", ".(int) $date_start_fill;
1031 $sql .=
", ".(int) $date_end_fill;
1032 $sql .=
", ".($fk_fournprice > 0 ? $fk_fournprice :
'null');
1033 $sql .=
", ".($pa_ht ?
price2num($pa_ht) : 0);
1034 $sql .=
", ".((int) $info_bits);
1035 $sql .=
", ".((int) $ranktouse);
1036 $sql .=
", ".((int) $special_code);
1037 $sql .=
", ".($fk_unit ? ((int) $fk_unit) :
"null");
1038 $sql .=
", ".(int) $this->fk_multicurrency;
1039 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1040 $sql .=
", ".price2num($pu_ht_devise,
'CU');
1041 $sql .=
", ".price2num($multicurrency_total_ht,
'CT');
1042 $sql .=
", ".price2num($multicurrency_total_tva,
'CT');
1043 $sql .=
", ".price2num($multicurrency_total_ttc,
'CT');
1046 dol_syslog(get_class($this).
"::addline", LOG_DEBUG);
1047 if ($this->db->query($sql)) {
1048 $lineId = $this->db->last_insert_id(MAIN_DB_PREFIX.
"facturedet_rec");
1053 $this->error = $this->db->lasterror();
1088 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 = 0, $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, $fk_parent_line = 0)
1094 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);
1095 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1098 if (empty($remise_percent)) {
1099 $remise_percent = 0;
1108 $remise_percent =
price2num($remise_percent);
1110 if (empty($info_bits)) {
1115 $pu_ht_devise =
price2num($pu_ht_devise);
1116 if (!preg_match(
'/\((.*)\)/', $txtva)) {
1121 if (empty($txlocaltax1)) {
1124 if (empty($txlocaltax2)) {
1128 if (empty($this->multicurrency_subprice)) {
1129 $this->multicurrency_subprice = 0;
1131 if (empty($this->multicurrency_total_ht)) {
1132 $this->multicurrency_total_ht = 0;
1134 if (empty($this->multicurrency_total_tva)) {
1135 $this->multicurrency_total_tva = 0;
1137 if (empty($this->multicurrency_total_ttc)) {
1138 $this->multicurrency_total_ttc = 0;
1141 if ($price_base_type ==
'HT') {
1156 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
1157 $vat_src_code = $reg[1];
1158 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
1161 $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);
1163 $total_ht = $tabprice[0];
1164 $total_tva = $tabprice[1];
1165 $total_ttc = $tabprice[2];
1166 $total_localtax1 = $tabprice[9];
1167 $total_localtax2 = $tabprice[10];
1168 $pu_ht = $tabprice[3];
1169 $pu_tva = $tabprice[4];
1170 $pu_ttc = $tabprice[5];
1173 $multicurrency_total_ht = $tabprice[16];
1174 $multicurrency_total_tva = $tabprice[17];
1175 $multicurrency_total_ttc = $tabprice[18];
1176 $pu_ht_devise = $tabprice[19];
1178 $product_type = $type;
1180 $product =
new Product($this->db);
1181 $result = $product->fetch($fk_product);
1182 $product_type = $product->type;
1185 if (empty($fk_parent_line) || $fk_parent_line < 0) {
1186 $fk_parent_line = 0;
1189 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet_rec SET ";
1190 $sql .=
"fk_facture = ".((int) $facid);
1191 $sql .=
", fk_parent_line = ".($fk_parent_line > 0 ? ((int) $fk_parent_line) :
"null");
1192 $sql .=
", label=".(!empty($label) ?
"'".$this->db->escape($label).
"'" :
"null");
1193 $sql .=
", description='".$this->db->escape($desc).
"'";
1194 $sql .=
", price=".price2num($pu_ht);
1195 $sql .=
", qty=".price2num($qty);
1196 $sql .=
", tva_tx=".price2num($txtva);
1197 $sql .=
", vat_src_code='".$this->db->escape($vat_src_code).
"'";
1198 $sql .=
", localtax1_tx=".((float) $txlocaltax1);
1199 $sql .=
", localtax1_type='".$this->db->escape($localtaxes_type[0]).
"'";
1200 $sql .=
", localtax2_tx=".((float) $txlocaltax2);
1201 $sql .=
", localtax2_type='".$this->db->escape($localtaxes_type[2]).
"'";
1202 $sql .=
", fk_product=".(!empty($fk_product) ?
"'".$this->db->escape($fk_product).
"'" :
"null");
1203 $sql .=
", product_type=".((int) $product_type);
1204 $sql .=
", remise_percent='".price2num($remise_percent).
"'";
1205 $sql .=
", subprice='".price2num($pu_ht).
"'";
1206 $sql .=
", total_ht='".price2num($total_ht).
"'";
1207 $sql .=
", total_tva='".price2num($total_tva).
"'";
1208 $sql .=
", total_localtax1='".price2num($total_localtax1).
"'";
1209 $sql .=
", total_localtax2='".price2num($total_localtax2).
"'";
1210 $sql .=
", total_ttc='".price2num($total_ttc).
"'";
1211 $sql .=
", date_start_fill=".((int) $date_start_fill);
1212 $sql .=
", date_end_fill=".((int) $date_end_fill);
1213 $sql .=
", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice :
'null');
1214 $sql .=
", buy_price_ht=".($pa_ht ?
price2num($pa_ht) : 0);
1215 $sql .=
", info_bits=".((int) $info_bits);
1216 $sql .=
", rang=".((int) $rang);
1217 $sql .=
", special_code=".((int) $special_code);
1218 $sql .=
", fk_unit=".($fk_unit ?
"'".$this->db->escape($fk_unit).
"'" :
"null");
1219 $sql .=
', multicurrency_subprice = '.price2num($pu_ht_devise);
1220 $sql .=
', multicurrency_total_ht = '.price2num($multicurrency_total_ht);
1221 $sql .=
', multicurrency_total_tva = '.price2num($multicurrency_total_tva);
1222 $sql .=
', multicurrency_total_ttc = '.price2num($multicurrency_total_ttc);
1223 $sql .=
" WHERE rowid = ".((int) $rowid);
1225 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
1226 if ($this->db->query($sql)) {
1231 $this->error = $this->db->lasterror();
1244 if (empty($this->date_when)) {
1258 if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) {
1273 return ($this->
isMaxNbGenReached() ?
'<strike>' :
'').$ret.($this->isMaxNbGenReached() ?
'</strike>' :
'');
1289 global $conf, $langs, $db, $user, $hookmanager;
1295 $langs->loadLangs(array(
"main",
"bills"));
1299 $today =
dol_mktime(23, 59, 59, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year']);
1301 $this->output =
null;
1303 dol_syslog(
"createRecurringInvoices restrictioninvoiceid=".$restrictioninvoiceid.
" forcevalidation=".$forcevalidation);
1305 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'facture_rec';
1306 $sql .=
' WHERE frequency > 0';
1307 $sql .=
" AND (date_when IS NULL OR date_when <= '".$this->db->idate($today).
"')";
1308 $sql .=
' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
1309 $sql .=
' AND suspended = 0';
1310 $sql .=
' AND entity = '.$conf->entity;
1311 if ($restrictioninvoiceid > 0) {
1312 $sql .=
' AND rowid = '.((int) $restrictioninvoiceid);
1314 $sql .= $this->db->order(
'entity',
'ASC');
1316 $parameters = array(
1317 'restrictioninvoiceid' => $restrictioninvoiceid,
1318 'forcevalidation' => $forcevalidation,
1320 $reshook = $hookmanager->executeHooks(
'beforeCreationOfRecurringInvoices', $parameters, $sql);
1322 $resql = $this->db->query($sql);
1325 $num = $this->db->num_rows($resql);
1328 $this->output .= $langs->trans(
"FoundXQualifiedRecurringInvoiceTemplate", $num).
"\n";
1330 $this->output .= $langs->trans(
"NoQualifiedRecurringInvoiceTemplateFound");
1333 $saventity = $conf->entity;
1336 $line = $this->db->fetch_object($resql);
1340 $invoiceidgenerated = 0;
1344 $facturerec->fetch($line->rowid);
1346 if ($facturerec->id > 0) {
1348 $conf->entity = $facturerec->entity;
1350 dol_syslog(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref.
", entity=".$facturerec->entity);
1352 $facture =
new Facture($this->db);
1353 $facture->fac_rec = $facturerec->id;
1354 $facture->fk_fac_rec_source = $facturerec->id;
1357 $facture->subtype = $facturerec->subtype;
1360 $facture->date = (empty($facturerec->date_when) ? $now : $facturerec->date_when);
1361 $facture->socid = $facturerec->socid;
1362 if (!empty($facturerec->fk_multicurrency)) {
1363 $facture->fk_multicurrency = $facturerec->fk_multicurrency;
1364 $facture->multicurrency_code = $facturerec->multicurrency_code;
1365 $facture->multicurrency_tx = $facturerec->multicurrency_tx;
1368 if (isset($facture->array_options) && isset($facturerec->array_options)) {
1369 foreach ($facturerec->array_options as $key => $value) {
1370 if (isset($facture->array_options[$key])) {
1371 $facture->array_options[$key] = $value;
1376 $invoiceidgenerated = $facture->create($user);
1377 if ($invoiceidgenerated <= 0) {
1378 $this->errors = $facture->errors;
1379 $this->error = $facture->error;
1384 if (!$error && ($facturerec->auto_validate || $forcevalidation)) {
1385 $result = $facture->validate($user);
1387 $this->errors = $facture->errors;
1388 $this->error = $facture->error;
1392 if (!$error && $facturerec->generate_pdf) {
1394 $facture->fetch($facture->id);
1395 $result = $facture->generateDocument($facturerec->model_pdf, $langs);
1397 $this->errors = $facture->errors;
1398 $this->error = $facture->error;
1402 if (!$error && !$notrigger) {
1404 $result = $facturerec->call_trigger(
'BILLREC_CREATEBILL', $user);
1406 $this->errors = $facturerec->errors;
1407 $this->error = $facturerec->error;
1414 $this->error =
"Failed to load invoice template with id=".$line->rowid.
", entity=".$conf->entity.
"\n";
1415 $this->errors[] =
"Failed to load invoice template with id=".$line->rowid.
", entity=".$conf->entity;
1416 dol_syslog(
"createRecurringInvoices Failed to load invoice template with id=".$line->rowid.
", entity=".$conf->entity);
1419 if (!$error && $invoiceidgenerated >= 0) {
1420 $this->db->commit(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref);
1421 dol_syslog(
"createRecurringInvoices Process invoice template ".$facturerec->ref.
" is finished with a success generation");
1423 $this->output .= $langs->trans(
"InvoiceGeneratedFromTemplate", $facture->ref, $facturerec->ref).
"\n";
1425 $this->output .= $langs->trans(
"InvoiceGeneratedFromTemplateError", $facture->ref, $facturerec->ref, $this->error).
"\n";
1426 $this->db->rollback(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref);
1429 $parameters = array(
1432 'errorCount' => $error,
1433 'invoiceidgenerated' => $invoiceidgenerated,
1434 'facturerec' => $facturerec,
1437 $reshook = $hookmanager->executeHooks(
'afterCreationOfRecurringInvoice', $parameters, $facture);
1442 $conf->entity = $saventity;
1447 $this->output = trim($this->output);
1449 return $error ? $error : 0;
1464 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'', $notooltip = 0, $save_lastsearch_value = -1)
1466 global $langs, $hookmanager;
1470 $label =
'<u>'.$langs->trans(
"RepeatableInvoice").
'</u>';
1471 if (!empty($this->
ref)) {
1472 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1474 if ($this->frequency > 0) {
1475 $label .=
'<br><b>'.$langs->trans(
'Frequency').
':</b> '.$langs->trans(
'FrequencyPer_'.$this->unit_frequency, $this->frequency);
1477 if (!empty($this->date_last_gen)) {
1478 $label .=
'<br><b>'.$langs->trans(
'DateLastGeneration').
':</b> '.
dol_print_date($this->date_last_gen,
'dayhour');
1480 if ($this->frequency > 0) {
1481 if (!empty($this->date_when)) {
1482 $label .=
'<br><b>'.$langs->trans(
'NextDateToExecution').
':</b> ';
1483 $label .= (empty($this->suspended) ?
'' :
'<strike>').
dol_print_date($this->date_when,
'day').(empty($this->suspended) ?
'' :
'</strike>');
1484 if (!empty($this->suspended)) {
1485 $label .=
' ('.$langs->trans(
"Disabled").
')';
1490 $url = DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$this->id;
1496 if ($option !=
'nolink') {
1498 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1499 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1500 $add_save_lastsearch_values = 1;
1502 if ($add_save_lastsearch_values) {
1503 $url .=
'&save_lastsearch_values=1';
1507 $linkstart =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
1510 $result .= $linkstart;
1512 $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);
1514 if ($withpicto != 2) {
1515 $result .= $this->ref;
1517 $result .= $linkend;
1519 $hookmanager->initHooks(array($this->element .
'dao'));
1520 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1521 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1523 $result = $hookmanager->resPrint;
1525 $result .= $hookmanager->resPrint;
1539 return $this->
LibStatut($this->frequency ? 1 : 0, $this->suspended, $mode, $alreadypaid, empty($this->
type) ? 0 : $this->type);
1553 public function LibStatut($recur, $status, $mode = 0, $alreadypaid = -1, $type = 0)
1557 $langs->load(
'bills');
1559 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1560 $statusType =
'status0';
1565 if ($status == self::STATUS_SUSPENDED) {
1566 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1568 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1571 if ($status == self::STATUS_SUSPENDED) {
1572 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1574 $labelStatus = $langs->transnoentitiesnoconv(
"Draft");
1577 } elseif ($mode == 1) {
1580 if ($status == self::STATUS_SUSPENDED) {
1581 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1583 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1586 if ($status == self::STATUS_SUSPENDED) {
1587 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1589 $labelStatus = $langs->transnoentitiesnoconv(
"Draft");
1592 } elseif ($mode == 2) {
1594 if ($status == self::STATUS_SUSPENDED) {
1595 $statusType =
'status6';
1596 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1598 $statusType =
'status4';
1599 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1602 if ($status == self::STATUS_SUSPENDED) {
1603 $statusType =
'status6';
1604 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1606 $statusType =
'status0';
1607 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1610 } elseif ($mode == 3) {
1613 if ($status == self::STATUS_SUSPENDED) {
1614 $statusType =
'status6';
1615 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1617 $statusType =
'status4';
1618 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1621 if ($status == self::STATUS_SUSPENDED) {
1622 $statusType =
'status6';
1623 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1625 $statusType =
'status0';
1626 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1629 } elseif ($mode == 4) {
1632 if ($status == self::STATUS_SUSPENDED) {
1633 $statusType =
'status6';
1634 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1636 $statusType =
'status4';
1637 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1640 if ($status == self::STATUS_SUSPENDED) {
1641 $statusType =
'status6';
1642 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1644 $statusType =
'status0';
1645 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1648 } elseif ($mode == 5 || $mode == 6) {
1654 if ($status == self::STATUS_SUSPENDED) {
1655 $statusType =
'status6';
1656 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1658 $statusType =
'status4';
1659 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1662 if ($status == self::STATUS_SUSPENDED) {
1663 $statusType =
'status6';
1664 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1666 $statusType =
'status0';
1667 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1672 $labelStatusShort = $labelStatus;
1674 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1698 $sql =
'SELECT c.rowid, datec, tms as datem,';
1699 $sql .=
' fk_user_author, fk_user_modif';
1700 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as c';
1701 $sql .=
' WHERE c.rowid = '.((int) $id);
1703 $result = $this->db->query($sql);
1705 if ($this->db->num_rows($result)) {
1706 $obj = $this->db->fetch_object($result);
1708 $this->
id = $obj->rowid;
1710 $this->user_creation_id = $obj->fk_user_author;
1711 $this->user_modification_id = $obj->fk_user_modif;
1712 $this->date_creation = $this->db->jdate($obj->datec);
1713 $this->date_modification = $this->db->jdate($obj->datem);
1715 $this->db->free($result);
1735 $nownotime =
dol_mktime(0, 0, 0, $arraynow[
'mon'], $arraynow[
'mday'], $arraynow[
'year']);
1741 $sql =
"SELECT rowid";
1742 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
1743 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
1744 $sql .= $this->db->plimit(100);
1746 $resql = $this->db->query($sql);
1748 $num_prods = $this->db->num_rows($resql);
1750 while ($i < $num_prods) {
1752 $row = $this->db->fetch_row($resql);
1753 $prodids[$i] = $row[0];
1759 $this->
ref =
'SPECIMEN';
1760 $this->title =
'SPECIMEN';
1761 $this->specimen = 1;
1763 $this->date = $nownotime;
1764 $this->date_lim_reglement = $nownotime + 3600 * 24 * 30;
1765 $this->cond_reglement_id = 1;
1766 $this->cond_reglement_code =
'RECEP';
1768 $this->mode_reglement_id = 0;
1769 $this->mode_reglement_code =
'';
1770 $this->note_public =
'This is a comment (public)';
1771 $this->note_private =
'This is a comment (private)';
1772 $this->note =
'This is a comment (private)';
1773 $this->fk_incoterms = 0;
1774 $this->location_incoterms =
'';
1776 if (empty($option) || $option !=
'nolines') {
1780 while ($xnbp < $nbp) {
1782 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1784 $line->subprice = 100;
1785 $line->tva_tx = 19.6;
1786 $line->localtax1_tx = 0;
1787 $line->localtax2_tx = 0;
1788 $line->remise_percent = 0;
1790 $prodid = mt_rand(1, $num_prods);
1791 $line->fk_product = $prodids[$prodid];
1793 $line->total_ht = -100;
1794 $line->total_ttc = -119.6;
1795 $line->total_tva = -19.6;
1796 } elseif ($xnbp == 2) {
1797 $line->subprice = -100;
1798 $line->total_ht = -100;
1799 $line->total_ttc = -119.6;
1800 $line->total_tva = -19.6;
1801 $line->remise_percent = 0;
1802 } elseif ($xnbp == 3) {
1803 $prodid = mt_rand(1, $num_prods);
1804 $line->fk_product = $prodids[$prodid];
1805 $line->total_ht = 50;
1806 $line->total_ttc = 59.8;
1807 $line->total_tva = 9.8;
1808 $line->remise_percent = 50;
1810 $prodid = mt_rand(1, $num_prods);
1811 $line->fk_product = $prodids[$prodid];
1812 $line->total_ht = 100;
1813 $line->total_ttc = 119.6;
1814 $line->total_tva = 19.6;
1815 $line->remise_percent = 00;
1818 $this->lines[$xnbp] = $line;
1821 $this->total_ht += $line->total_ht;
1822 $this->total_tva += $line->total_tva;
1823 $this->total_ttc += $line->total_ttc;
1825 $this->revenuestamp = 0;
1829 $line->desc = $langs->trans(
"Description").
" (offered line)";
1831 $line->subprice = 100;
1832 $line->tva_tx = 19.6;
1833 $line->localtax1_tx = 0;
1834 $line->localtax2_tx = 0;
1835 $line->remise_percent = 100;
1836 $line->total_ht = 0;
1837 $line->total_ttc = 0;
1838 $line->total_tva = 0;
1839 $prodid = mt_rand(1, $num_prods);
1840 $line->fk_product = $prodids[$prodid];
1842 $this->lines[$xnbp] = $line;
1846 $this->usenewprice = 0;
1895 if (!$this->table_element) {
1896 dol_syslog(get_class($this).
"::setFrequencyAndUnit was called on objet with property table_element not defined", LOG_ERR);
1900 if (!empty($frequency) && empty($unit)) {
1901 dol_syslog(get_class($this).
"::setFrequencyAndUnit was called on objet with params frequency defined but unit not defined", LOG_ERR);
1905 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1906 $sql .=
' SET frequency = '.($frequency ? $this->db->escape($frequency) :
'null');
1907 if (!empty($unit)) {
1908 $sql .=
', unit_frequency = \''.$this->db->escape($unit).
'\'';
1910 $sql .=
" WHERE rowid = ".((int) $this->
id);
1912 dol_syslog(get_class($this).
"::setFrequencyAndUnit", LOG_DEBUG);
1913 if ($this->db->query($sql)) {
1914 $this->frequency = $frequency;
1915 if (!empty($unit)) {
1916 $this->unit_frequency = $unit;
1921 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
1943 public function setNextDate($date, $increment_nb_gen_done = 0, $notrigger = 0)
1947 if (!$this->table_element) {
1948 dol_syslog(get_class($this).
"::setNextDate was called on objet with property table_element not defined", LOG_ERR);
1951 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1952 $sql .=
" SET date_when = ".($date ?
"'".$this->db->idate($date).
"'" :
"null");
1953 if ($increment_nb_gen_done > 0) {
1954 $sql .=
', nb_gen_done = nb_gen_done + 1';
1956 $sql .=
" WHERE rowid = ".((int) $this->
id);
1958 dol_syslog(get_class($this).
"::setNextDate", LOG_DEBUG);
1959 if ($this->db->query($sql)) {
1960 $this->date_when = $date;
1961 if ($increment_nb_gen_done > 0) {
1962 $this->nb_gen_done++;
1967 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
1991 if (!$this->table_element) {
1992 dol_syslog(get_class($this).
"::setMaxPeriod was called on objet with property table_element not defined", LOG_ERR);
2000 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2001 $sql .=
' SET nb_gen_max = '.((int) $nb);
2002 $sql .=
" WHERE rowid = ".((int) $this->
id);
2004 dol_syslog(get_class($this).
"::setMaxPeriod", LOG_DEBUG);
2005 if ($this->db->query($sql)) {
2006 $this->nb_gen_max = $nb;
2010 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2035 if (!$this->table_element) {
2036 dol_syslog(get_class($this).
"::setAutoValidate was called on objet with property table_element not defined", LOG_ERR);
2040 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2041 $sql .=
' SET auto_validate = '.((int) $validate);
2042 $sql .=
" WHERE rowid = ".((int) $this->
id);
2044 dol_syslog(get_class($this).
"::setAutoValidate", LOG_DEBUG);
2045 if ($this->db->query($sql)) {
2046 $this->auto_validate = $validate;
2050 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2075 if (!$this->table_element) {
2076 dol_syslog(get_class($this).
"::setGeneratePdf was called on objet with property table_element not defined", LOG_ERR);
2080 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2081 $sql .=
' SET generate_pdf = '.((int) $validate);
2082 $sql .=
" WHERE rowid = ".((int) $this->
id);
2084 dol_syslog(get_class($this).
"::setGeneratePdf", LOG_DEBUG);
2085 if ($this->db->query($sql)) {
2086 $this->generate_pdf = $validate;
2090 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2114 if (!$this->table_element) {
2115 dol_syslog(get_class($this).
"::setModelPdf was called on objet with property table_element not defined", LOG_ERR);
2119 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2120 $sql .=
" SET modelpdf = '".$this->db->escape($model).
"'";
2121 $sql .=
" WHERE rowid = ".((int) $this->
id);
2123 dol_syslog(get_class($this).
"::setModelPdf", LOG_DEBUG);
2124 if ($this->db->query($sql)) {
2125 $this->model_pdf = $model;
2129 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2155 public $element =
'facturedetrec';
2160 public $table_element =
'facturedet_rec';
2168 public $fk_product_fournisseur_price;
2169 public $fk_fournprice;
2175 public $description;
2177 public $fk_product_type;
2179 public $fk_contract_line;
2189 public function delete(
User $user, $notrigger = 0)
2198 $result = $this->
call_trigger(
'LINEBILLREC_DELETE', $user);
2214 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
' WHERE rowid='.((int) $this->
id);
2216 $res = $this->db->query($sql);
2219 $this->errors[] = $this->db->lasterror();
2225 $this->db->rollback();
2228 $this->db->commit();
2242 $sql =
'SELECT l.rowid, l.fk_facture, l.fk_parent_line, 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,';
2243 $sql .=
' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
2244 $sql .=
' l.date_start_fill, l.date_end_fill, l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
2245 $sql .=
' l.rang, l.special_code,';
2246 $sql .=
' l.fk_unit, l.fk_contract_line,';
2247 $sql .=
' l.import_key, l.fk_multicurrency,';
2248 $sql .=
' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
2249 $sql .=
' l.buy_price_ht, l.fk_product_fournisseur_price,';
2250 $sql .=
' l.fk_user_author, l.fk_user_modif,';
2251 $sql .=
' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
2252 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facturedet_rec as l';
2253 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
2254 $sql .=
' WHERE l.rowid = '.((int) $rowid);
2255 $sql .=
' ORDER BY l.rang';
2258 $result = $this->db->query($sql);
2260 $objp = $this->db->fetch_object($result);
2262 $this->
id = $objp->rowid;
2263 $this->fk_facture = $objp->fk_facture;
2264 $this->fk_parent_line = $objp->fk_parent_line;
2265 $this->label = $objp->custom_label;
2266 $this->desc = $objp->description;
2268 $this->product_type = $objp->product_type;
2269 $this->
ref = $objp->product_ref;
2270 $this->product_ref = $objp->product_ref;
2271 $this->libelle = $objp->product_label;
2272 $this->product_label = $objp->product_label;
2273 $this->product_desc = $objp->product_desc;
2274 $this->fk_product_type = $objp->fk_product_type;
2275 $this->qty = $objp->qty;
2276 $this->
price = $objp->price;
2277 $this->subprice = $objp->subprice;
2278 $this->vat_src_code = $objp->vat_src_code;
2279 $this->tva_tx = $objp->tva_tx;
2280 $this->localtax1_tx = $objp->localtax1_tx;
2281 $this->localtax2_tx = $objp->localtax2_tx;
2282 $this->localtax1_type = $objp->localtax1_type;
2283 $this->localtax2_type = $objp->localtax2_type;
2284 $this->remise_percent = $objp->remise_percent;
2286 $this->fk_product = $objp->fk_product;
2287 $this->date_start_fill = $objp->date_start_fill;
2288 $this->date_end_fill = $objp->date_end_fill;
2289 $this->info_bits = $objp->info_bits;
2290 $this->total_ht = $objp->total_ht;
2291 $this->total_tva = $objp->total_tva;
2292 $this->total_ttc = $objp->total_ttc;
2294 $this->rang = $objp->rang;
2295 $this->special_code = $objp->special_code;
2296 $this->fk_unit = $objp->fk_unit;
2297 $this->fk_contract_line = $objp->fk_contract_line;
2298 $this->import_key = $objp->import_key;
2299 $this->fk_multicurrency = $objp->fk_multicurrency;
2300 $this->multicurrency_code = $objp->multicurrency_code;
2301 $this->multicurrency_subprice = $objp->multicurrency_subprice;
2302 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
2303 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
2304 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2306 $this->buy_price_ht = $objp->buy_price_ht;
2308 $this->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
2309 $this->fk_user_author = $objp->fk_user_author;
2310 $this->fk_user_modif = $objp->fk_user_modif;
2312 $this->db->free($result);
2315 $this->error = $this->db->lasterror();
2335 if (empty($this->fk_parent_line)) {
2336 $this->fk_parent_line = 0;
2339 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2341 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet_rec SET";
2342 $sql .=
" fk_facture = ".((int) $this->fk_facture);
2343 $sql .=
", fk_parent_line=".($this->fk_parent_line > 0 ? $this->fk_parent_line :
"null");
2344 $sql .=
", label=".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null");
2345 $sql .=
", description='".$this->db->escape($this->desc).
"'";
2346 $sql .=
", price=".price2num($this->
price);
2347 $sql .=
", qty=".price2num($this->qty);
2348 $sql .=
", tva_tx=".price2num($this->tva_tx);
2349 $sql .=
", vat_src_code='".$this->db->escape($this->vat_src_code).
"'";
2350 $sql .=
", localtax1_tx=".price2num($this->localtax1_tx);
2351 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
2352 $sql .=
", localtax2_tx=".price2num($this->localtax2_tx);
2353 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
2354 $sql .=
", fk_product=".($this->fk_product > 0 ? $this->fk_product :
"null");
2355 $sql .=
", product_type=".((int) $this->product_type);
2356 $sql .=
", remise_percent=".price2num($this->remise_percent);
2357 $sql .=
", subprice=".price2num($this->subprice);
2358 $sql .=
", info_bits=".price2num($this->info_bits);
2359 $sql .=
", date_start_fill=".(int) $this->date_start_fill;
2360 $sql .=
", date_end_fill=".(int) $this->date_end_fill;
2361 if (empty($this->skip_update_total)) {
2362 $sql .=
", total_ht=".price2num($this->total_ht);
2363 $sql .=
", total_tva=".price2num($this->total_tva);
2364 $sql .=
", total_localtax1=".price2num($this->total_localtax1);
2365 $sql .=
", total_localtax2=".price2num($this->total_localtax2);
2366 $sql .=
", total_ttc=".price2num($this->total_ttc);
2368 $sql .=
", rang=".((int) $this->rang);
2369 $sql .=
", special_code=".((int) $this->special_code);
2370 $sql .=
", fk_unit=".($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
"null");
2371 $sql .=
", fk_contract_line=".($this->fk_contract_line ? $this->fk_contract_line :
"null");
2372 $sql .=
" WHERE rowid = ".((int) $this->
id);
2376 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
2378 $resql = $this->db->query($sql);
2387 if (!$error && !$notrigger) {
2389 $result = $this->
call_trigger(
'LINEBILLREC_MODIFY', $user);
2397 $this->db->rollback();
2400 $this->db->commit();
2404 $this->error = $this->db->lasterror();
2405 $this->db->rollback();
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=0, $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.
$fk_parent_line
Id parent line.
fetch($rowid)
Get line of template invoice.
$fk_facture
From llx_facturedet_rec Id facture.
update(User $user, $notrigger=0)
Update a line to invoice_rec.
Class to manage invoice templates.
setFrequencyAndUnit($frequency, $unit, $notrigger=0)
Update frequency and unit.
getLibStatut($mode=0, $alreadypaid=-1)
Return label of object status.
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=0, $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, $fk_parent_line=0)
Add a line to invoice.
LibStatut($recur, $status, $mode=0, $alreadypaid=-1, $type=0)
Return label of a status.
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=0, $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, $fk_parent_line=0)
Update a line to invoice.
fetch_lines()
Get lines of template invoices into this->lines.
info($id)
Load miscellaneous information for tab "Info".
getLinesArray()
Create an array of invoice lines.
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=0, $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.
getNextNumRef($soc, $mode='next')
Return next reference of invoice not already used (or last reference)
__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.
create($user, $facid, $notrigger=0, $onlylines=array())
Create a predefined invoice.
strikeIfMaxNbGenReached($ret)
Format string to output with by striking the string if max number of generation was reached.
fetch($rowid, $ref='', $ref_ext='', $noextrafields=0, $nolines=0)
Load object and lines.
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.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after 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 a 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.
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.
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.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type