33require_once DOL_DOCUMENT_ROOT.
'/core/class/commoninvoice.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/factureligne.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
46 const TRIGGER_PREFIX =
'BILLREC';
50 public $element =
'facturerec';
55 public $table_element =
'facture_rec';
60 public $table_element_line =
'facturedet_rec';
65 public $fk_element =
'fk_facture';
70 public $picto =
'bill';
96 public $multicurrency_subprice;
130 public $date_last_gen;
157 public $unit_frequency;
167 public $special_code;
172 public $usenewprice = 0;
177 public $date_lim_reglement;
181 public $cond_reglement_code;
185 public $mode_reglement_code;
190 public $fk_societe_rib;
200 public $auto_validate;
204 public $generate_pdf;
208 const PAYMENTCODETOEDITSOCIETERIB =
"PRE";
239 public $fields = array(
240 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
241 'titre' => array(
'type' =>
'varchar(100)',
'label' =>
'Titre',
'enabled' => 1,
'showoncombobox' => 1,
'visible' => -1,
'position' => 15),
242 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 20,
'index' => 1),
243 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => -1,
'notnull' => 1,
'position' => 25),
244 'subtype' => array(
'type' =>
'smallint(6)',
'label' =>
'InvoiceSubtype',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 30),
245 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 35),
246 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'Tva',
'enabled' => 1,
'visible' => -1,
'position' => 55,
'isameasure' => 1),
247 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'Localtax1',
'enabled' => 1,
'visible' => -1,
'position' => 60,
'isameasure' => 1),
248 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'Localtax2',
'enabled' => 1,
'visible' => -1,
'position' => 65,
'isameasure' => 1),
249 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'Total',
'enabled' => 1,
'visible' => -1,
'position' => 70,
'isameasure' => 1),
250 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'Total ttc',
'enabled' => 1,
'visible' => -1,
'position' => 75,
'isameasure' => 1),
251 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fk user author',
'enabled' => 1,
'visible' => -1,
'position' => 80),
252 '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),
253 'fk_cond_reglement' => array(
'type' =>
'integer',
'label' =>
'Fk cond reglement',
'enabled' => 1,
'visible' => -1,
'position' => 90),
254 'fk_mode_reglement' => array(
'type' =>
'integer',
'label' =>
'Fk mode reglement',
'enabled' => 1,
'visible' => -1,
'position' => 95),
255 'date_lim_reglement' => array(
'type' =>
'date',
'label' =>
'Date lim reglement',
'enabled' => 1,
'visible' => -1,
'position' => 100),
256 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 105),
257 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 110),
258 'modelpdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Modelpdf',
'enabled' => 1,
'visible' => -1,
'position' => 115),
259 'date_when' => array(
'type' =>
'datetime',
'label' =>
'Date when',
'enabled' => 1,
'visible' => -1,
'position' => 130),
260 'date_last_gen' => array(
'type' =>
'datetime',
'label' =>
'Date last gen',
'enabled' => 1,
'visible' => -1,
'position' => 135),
261 'nb_gen_done' => array(
'type' =>
'integer',
'label' =>
'Nb gen done',
'enabled' => 1,
'visible' => -1,
'position' => 140),
262 'nb_gen_max' => array(
'type' =>
'integer',
'label' =>
'Nb gen max',
'enabled' => 1,
'visible' => -1,
'position' => 145),
263 'frequency' => array(
'type' =>
'integer',
'label' =>
'Frequency',
'enabled' => 1,
'visible' => -1,
'position' => 150),
264 'unit_frequency' => array(
'type' =>
'varchar(2)',
'label' =>
'UnitFrequency',
'enabled' => 1,
'visible' => -1,
'position' => 152),
265 'usenewprice' => array(
'type' =>
'integer',
'label' =>
'UseNewPrice',
'enabled' => 1,
'visible' => 0,
'position' => 155),
266 'revenuestamp' => array(
'type' =>
'double(24,8)',
'label' =>
'RevenueStamp',
'enabled' => 1,
'visible' => -1,
'position' => 160,
'isameasure' => 1),
267 'auto_validate' => array(
'type' =>
'integer',
'label' =>
'Auto validate',
'enabled' => 1,
'visible' => -1,
'position' => 165),
268 'generate_pdf' => array(
'type' =>
'integer',
'label' =>
'Generate pdf',
'enabled' => 1,
'visible' => -1,
'position' => 170),
269 'fk_account' => array(
'type' =>
'integer',
'label' =>
'Fk account',
'enabled' =>
'isModEnabled("bank")',
'visible' => -1,
'position' => 175),
270 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'Fk multicurrency',
'enabled' => 1,
'visible' => -1,
'position' => 180),
271 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'Multicurrency code',
'enabled' => 1,
'visible' => -1,
'position' => 185),
272 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'Multicurrency tx',
'enabled' => 1,
'visible' => -1,
'position' => 190,
'isameasure' => 1),
273 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'Multicurrency total ht',
'enabled' => 1,
'visible' => -1,
'position' => 195,
'isameasure' => 1),
274 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'Multicurrency total tva',
'enabled' => 1,
'visible' => -1,
'position' => 200,
'isameasure' => 1),
275 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'Multicurrency total ttc',
'enabled' => 1,
'visible' => -1,
'position' => 205,
'isameasure' => 1),
276 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 210),
277 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 215),
278 'suspended' => array(
'type' =>
'integer',
'label' =>
'Suspended',
'enabled' => 1,
'visible' => -1,
'position' => 225),
279 'fk_societe_rib' => array(
'type' =>
'integer',
'label' =>
'Fk Societe RIB',
'enabled' =>
'isModEnabled("bank")',
'visible' => -1,
'position' => 175),
283 const STATUS_NOTSUSPENDED = 0;
284 const STATUS_SUSPENDED = 1;
307 public function create($user, $facid, $notrigger = 0, $onlylines = array())
315 $this->titre = trim(isset($this->titre) ? $this->titre : $this->title);
316 $this->title = trim($this->title);
317 $this->usenewprice = empty($this->usenewprice) ? 0 : $this->usenewprice;
318 if (empty($this->suspended)) {
319 $this->suspended = 0;
323 if (empty($this->frequency)) {
324 $this->frequency = 0;
325 $this->date_when =
null;
328 $this->frequency = abs($this->frequency);
329 $this->nb_gen_done = 0;
330 $this->nb_gen_max = empty($this->nb_gen_max) ? 0 : $this->nb_gen_max;
331 $this->auto_validate = empty($this->auto_validate) ? 0 : $this->auto_validate;
332 $this->generate_pdf = empty($this->generate_pdf) ? 0 : $this->generate_pdf;
337 $facsrc =
new Facture($this->db);
338 $result = $facsrc->fetch($facid);
340 $this->socid = $facsrc->socid;
342 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facture_rec (";
350 $sql .=
", note_private";
351 $sql .=
", note_public";
352 $sql .=
", modelpdf";
353 $sql .=
", fk_user_author";
354 $sql .=
", fk_projet";
355 $sql .=
", fk_account";
356 $sql .=
", fk_cond_reglement";
357 $sql .=
", fk_mode_reglement";
358 $sql .=
", usenewprice";
359 $sql .=
", frequency";
360 $sql .=
", unit_frequency";
361 $sql .=
", date_when";
362 $sql .=
", date_last_gen";
363 $sql .=
", nb_gen_done";
364 $sql .=
", nb_gen_max";
365 $sql .=
", auto_validate";
366 $sql .=
", generate_pdf";
367 $sql .=
", fk_multicurrency";
368 $sql .=
", multicurrency_code";
369 $sql .=
", multicurrency_tx";
370 $sql .=
", suspended";
371 $sql .=
", fk_societe_rib";
372 $sql .=
") VALUES (";
373 $sql .=
"'".$this->db->escape($this->titre ? $this->titre : $this->title).
"'";
374 $sql .=
", ".((int) $this->socid);
375 $sql .=
", ".($this->subtype ?
"'".$this->db->escape($this->subtype).
"'" :
"null");
376 $sql .=
", ".((int)
$conf->entity);
377 $sql .=
", '".$this->db->idate($now).
"'";
378 $sql .=
", ".(!empty($facsrc->total_ttc) ? ((float) $facsrc->total_ttc) :
'0');
380 $sql .=
", ".(!empty($this->note_private) ? (
"'".$this->db->escape($this->note_private).
"'") :
"NULL");
381 $sql .=
", ".(!empty($this->note_public) ? (
"'".$this->db->escape($this->note_public).
"'") :
"NULL");
382 $sql .=
", ".(!empty($this->model_pdf) ? (
"'".$this->db->escape($this->model_pdf).
"'") :
"NULL");
383 $sql .=
", ".((int) $user->id);
384 $sql .=
", ".(!empty($this->fk_project) ? ((int) $this->fk_project) :
"null");
385 $sql .=
", ".(!empty($facsrc->fk_account) ? ((int) $facsrc->fk_account) :
"null");
386 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
"null");
387 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
"null");
388 $sql .=
", ".((int) $this->usenewprice);
389 $sql .=
", ".((int) $this->frequency);
390 $sql .=
", '".$this->db->escape($this->unit_frequency).
"'";
391 $sql .=
", ".(!empty($this->date_when) ?
"'".$this->db->idate($this->date_when).
"'" :
'NULL');
392 $sql .=
", ".(!empty($this->date_last_gen) ?
"'".$this->db->idate($this->date_last_gen).
"'" :
'NULL');
393 $sql .=
", ".((int) $this->nb_gen_done);
394 $sql .=
", ".((int) $this->nb_gen_max);
395 $sql .=
", ".((int) $this->auto_validate);
396 $sql .=
", ".((int) $this->generate_pdf);
397 $sql .=
", ".((int) $facsrc->fk_multicurrency);
398 $sql .=
", '".$this->db->escape($facsrc->multicurrency_code).
"'";
399 $sql .=
", ".((float) $facsrc->multicurrency_tx);
400 $sql .=
", ".((int) $this->suspended);
401 $sql .=
", ".((int) $this->fk_societe_rib);
404 if ($this->db->query($sql)) {
405 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"facture_rec");
408 $this->fk_multicurrency = $facsrc->fk_multicurrency;
409 $this->multicurrency_code = $facsrc->multicurrency_code;
410 $this->multicurrency_tx = $facsrc->multicurrency_tx;
415 $num = count($facsrc->lines);
416 for ($i = 0; $i < $num; $i++) {
417 $facline = $facsrc->lines[$i];
418 '@phan-var-force FactureLigneRec $facline';
419 if (!empty($onlylines) && !in_array($facline->id, $onlylines)) {
424 if (($facline->product_type != 9 && empty($facline->fk_parent_line)) || $facline->product_type == 9) {
428 $tva_tx = $facline->tva_tx;
429 if (!empty($facline->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
430 $tva_tx .=
' ('.$facline->vat_src_code.
')';
433 $default_start_fill =
getDolGlobalInt(
'INVOICEREC_SET_AUTOFILL_DATE_START');
434 $default_end_fill =
getDolGlobalInt(
'INVOICEREC_SET_AUTOFILL_DATE_END');
436 $result_insert = $this->
addline(
441 $facline->localtax1_tx,
442 $facline->localtax2_tx,
443 $facline->fk_product,
444 $facline->remise_percent,
449 $facline->product_type,
451 $facline->special_code,
454 $facline->multicurrency_subprice,
463 if ($result_insert > 0 && $facline->product_type == 9) {
464 $fk_parent_line = $result_insert;
467 if ($result_insert < 0) {
472 $result2 = $objectline->fetch($result_insert);
475 if (method_exists($facline,
'fetch_optionals')) {
476 $facline->fetch_optionals($facline->id);
477 $objectline->array_options = $facline->array_options;
480 $result = $objectline->insertExtraFields();
484 } elseif ($result2 < 0) {
485 $this->errors[] = $objectline->error;
491 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
492 $this->linked_objects = $this->linkedObjectsIds;
496 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
497 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
498 if (is_array($tmp_origin_id)) {
499 foreach ($tmp_origin_id as $origin_id) {
502 $this->error = $this->db->lasterror();
507 $origin_id = $tmp_origin_id;
510 $this->error = $this->db->lasterror();
524 if (!$error && !$notrigger) {
528 $this->db->rollback();
535 $this->db->rollback();
542 $this->error = $this->db->lasterror();
543 $this->db->rollback();
547 $this->db->rollback();
564 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_rec SET";
565 $sql .=
" entity = ".((int) $this->entity).
",";
566 $sql .=
" titre = '".$this->db->escape($this->title).
"',";
567 $sql .=
" suspended = ".((int) $this->suspended).
",";
568 $sql .=
" fk_soc = ".((int) $this->socid).
",";
569 $sql .=
" total_tva = ".((float) $this->total_tva).
",";
570 $sql .=
" localtax1 = ".((float) $this->total_localtax1).
",";
571 $sql .=
" localtax2 = ".((float) $this->total_localtax2).
",";
572 $sql .=
" total_ht = ".((float) $this->total_ht).
",";
573 $sql .=
" total_ttc = ".((float) $this->total_ttc).
",";
574 $sql .=
" fk_societe_rib = ".((int) $this->fk_societe_rib);
576 $sql .=
" WHERE rowid = ".((int) $this->
id);
580 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
582 $resql = $this->db->query($sql);
591 if (!$error && !$notrigger) {
595 $this->db->rollback();
603 $this->error = $this->db->lasterror();
604 $this->db->rollback();
619 public function fetch($rowid, $ref =
'', $ref_ext =
'', $noextrafields = 0, $nolines = 0)
623 $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';
624 $sql .=
', f.date_lim_reglement as dlr';
625 $sql .=
', f.note_private, f.note_public, f.fk_user_author';
626 $sql .=
', f.modelpdf as model_pdf';
627 $sql .=
', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet as fk_project';
628 $sql .=
', f.fk_account, f.fk_societe_rib';
629 $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';
630 $sql .=
', f.generate_pdf';
631 $sql .=
", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
632 $sql .=
', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
633 $sql .=
', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
635 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as f';
636 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
637 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as p ON f.fk_mode_reglement = p.id';
639 $sql .=
' WHERE f.entity IN ('.getEntity(
'invoice').
')';
641 $sql .=
' AND f.rowid = '.((int) $rowid);
643 $sql .=
" AND f.titre = '".$this->db->escape($ref).
"'";
645 $sql .=
' AND f.rowid = 0';
651 $result = $this->db->query($sql);
653 if ($this->db->num_rows($result)) {
654 $obj = $this->db->fetch_object($result);
656 $this->
id = $obj->rowid;
657 $this->entity = $obj->entity;
658 $this->titre = $obj->title;
659 $this->title = $obj->title;
660 $this->
ref = $obj->title;
661 $this->subtype = $obj->subtype;
662 $this->suspended = $obj->suspended;
663 $this->total_ht = $obj->total_ht;
664 $this->total_tva = $obj->total_tva;
665 $this->total_localtax1 = $obj->localtax1;
666 $this->total_localtax2 = $obj->localtax2;
667 $this->total_ttc = $obj->total_ttc;
668 $this->socid = $obj->fk_soc;
669 $this->date_lim_reglement = $this->db->jdate($obj->dlr);
670 $this->mode_reglement_id = $obj->fk_mode_reglement;
671 $this->mode_reglement_code = $obj->mode_reglement_code;
672 $this->mode_reglement = $obj->mode_reglement_libelle;
673 $this->cond_reglement_id = $obj->fk_cond_reglement;
674 $this->cond_reglement_code = $obj->cond_reglement_code;
675 $this->cond_reglement = $obj->cond_reglement_libelle;
676 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
677 $this->fk_project = $obj->fk_project;
678 $this->fk_account = $obj->fk_account;
679 $this->fk_societe_rib = $obj->fk_societe_rib;
680 $this->note_private = $obj->note_private;
681 $this->note_public = $obj->note_public;
682 $this->user_author = $obj->fk_user_author;
683 $this->user_creation_id = $obj->fk_user_author;
684 $this->model_pdf = $obj->model_pdf;
686 $this->frequency = $obj->frequency;
687 $this->unit_frequency = $obj->unit_frequency;
688 $this->date_when = $this->db->jdate($obj->date_when);
689 $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
690 $this->nb_gen_done = $obj->nb_gen_done;
691 $this->nb_gen_max = $obj->nb_gen_max;
692 $this->usenewprice = $obj->usenewprice;
693 $this->auto_validate = $obj->auto_validate;
694 $this->generate_pdf = $obj->generate_pdf;
697 $this->fk_multicurrency = $obj->fk_multicurrency;
698 $this->multicurrency_code = $obj->multicurrency_code;
699 $this->multicurrency_tx = $obj->multicurrency_tx;
700 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
701 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
702 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
706 if (empty($noextrafields)) {
709 $this->error = $this->db->lasterror();
715 if (empty($nolines)) {
718 $this->error = $this->db->lasterror();
725 $this->error =
'Bill with id '.$rowid.
' or ref '.$ref.
' not found';
726 dol_syslog(
'Facture::Fetch Error '.$this->error, LOG_ERR);
730 $this->error = $this->db->error();
757 $this->lines = array();
759 dol_syslog(
'FactureRec::fetch_lines', LOG_DEBUG);
761 $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, ';
762 $sql .=
' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
763 $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,';
764 $sql .=
' l.rang, l.special_code,';
765 $sql .=
' l.fk_unit, l.fk_contract_line,';
766 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
767 $sql .=
' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
768 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facturedet_rec as l';
769 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
770 $sql .=
' WHERE l.fk_facture = '.((int) $this->
id);
771 $sql .=
' ORDER BY l.rang';
773 $result = $this->db->query($sql);
775 $num = $this->db->num_rows($result);
778 $objp = $this->db->fetch_object($result);
781 $line->id = $objp->rowid;
782 $line->rowid = $objp->rowid;
783 $line->fk_facture = $objp->fk_facture;
784 $line->fk_parent_line = $objp->fk_parent_line;
785 $line->desc = $objp->description;
786 $line->description = $objp->description;
787 $line->ref = $objp->product_ref;
788 $line->product_ref = $objp->product_ref;
789 $line->libelle = $objp->product_label;
790 $line->product_label = $objp->product_label;
791 $line->product_desc = $objp->product_desc;
792 $line->product_type = $objp->product_type;
793 $line->fk_product_type = $objp->fk_product_type;
794 $line->qty = $objp->qty;
795 $line->subprice = $objp->subprice;
797 $line->label = $objp->custom_label;
799 $line->vat_src_code = $objp->vat_src_code;
800 $line->tva_tx = $objp->tva_tx;
801 $line->localtax1_tx = $objp->localtax1_tx;
802 $line->localtax2_tx = $objp->localtax2_tx;
803 $line->localtax1_type = $objp->localtax1_type;
804 $line->localtax2_type = $objp->localtax2_type;
805 $line->remise_percent = $objp->remise_percent;
807 $line->fk_product = $objp->fk_product;
808 $line->date_start_fill = $objp->date_start_fill;
809 $line->date_end_fill = $objp->date_end_fill;
810 $line->info_bits = $objp->info_bits;
811 $line->total_ht = $objp->total_ht;
812 $line->total_tva = $objp->total_tva;
813 $line->total_ttc = $objp->total_ttc;
815 $line->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
816 $line->fk_fournprice = $objp->fk_product_fournisseur_price;
818 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $objp->fk_product_fournisseur_price, $objp->pa_ht);
820 $line->buyprice = $marginInfos[0];
821 $line->pa_ht = $marginInfos[0];
822 $line->marge_tx = (string) $marginInfos[1];
823 $line->marque_tx = (string) $marginInfos[2];
824 $line->rang = $objp->rang;
825 $line->special_code = $objp->special_code;
826 $line->fk_unit = $objp->fk_unit;
827 $line->fk_contract_line = $objp->fk_contract_line;
830 $line->price = $objp->price;
831 $line->remise = $objp->remise;
833 $line->fetch_optionals();
836 $line->fk_multicurrency = $objp->fk_multicurrency;
837 $line->multicurrency_code = $objp->multicurrency_code;
838 $line->multicurrency_subprice = $objp->multicurrency_subprice;
839 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
840 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
841 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
843 $this->lines[$i] = $line;
848 $this->db->free($result);
851 $this->error = $this->db->lasterror();
865 public function delete(
User $user, $notrigger = 0, $idwarehouse = -1)
869 dol_syslog(get_class($this).
"::delete rowid=".((
int) $rowid), LOG_DEBUG);
874 $main = MAIN_DB_PREFIX.
'facturedet_rec';
875 $ef = $main.
"_extrafields";
877 $sqlef =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_facture = ".((int) $rowid).
")";
878 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"facturedet_rec WHERE fk_facture = ".((int) $rowid);
880 if ($this->db->query($sqlef) && $this->db->query($sql)) {
881 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"facture_rec WHERE rowid = ".((int) $rowid);
883 if ($this->db->query($sql)) {
895 $this->error = $this->db->lasterror();
899 $this->error = $this->db->lasterror();
902 if (!$error && !$notrigger) {
914 $this->db->rollback();
948 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)
954 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);
955 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
967 if (preg_match(
'/\((.*)\)/', (
string) $txtva, $reg)) {
968 $vat_src_code = $reg[1];
969 $txtva = preg_replace(
'/\s*\(.*\)/',
'', (
string) $txtva);
974 $remise_percent =
price2num($remise_percent);
975 if (empty($remise_percent)) {
981 if (!preg_match(
'/\((.*)\)/', $txtva)) {
989 if (empty($txlocaltax1)) {
992 if (empty($txlocaltax2)) {
995 if (empty($info_bits)) {
999 if ($price_base_type ==
'HT') {
1010 $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);
1011 $total_ht = $tabprice[0];
1012 $total_tva = $tabprice[1];
1013 $total_ttc = $tabprice[2];
1014 $total_localtax1 = $tabprice[9];
1015 $total_localtax2 = $tabprice[10];
1016 $pu_ht = $tabprice[3];
1019 $multicurrency_total_ht = $tabprice[16];
1020 $multicurrency_total_tva = $tabprice[17];
1021 $multicurrency_total_ttc = $tabprice[18];
1022 $pu_ht_devise = $tabprice[19];
1024 $product_type = $type;
1026 $product =
new Product($this->db);
1027 $result = $product->fetch($fk_product);
1028 $product_type = $product->type;
1031 if (empty($fk_parent_line) || $fk_parent_line < 0) {
1032 $fk_parent_line = 0;
1037 if ($ranktouse == -1) {
1039 $ranktouse = $rangmax + 1;
1042 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facturedet_rec (";
1043 $sql .=
"fk_facture";
1044 $sql .=
", fk_parent_line";
1046 $sql .=
", description";
1050 $sql .=
", vat_src_code";
1051 $sql .=
", localtax1_tx";
1052 $sql .=
", localtax1_type";
1053 $sql .=
", localtax2_tx";
1054 $sql .=
", localtax2_type";
1055 $sql .=
", fk_product";
1056 $sql .=
", product_type";
1057 $sql .=
", remise_percent";
1058 $sql .=
", subprice";
1060 $sql .=
", total_ht";
1061 $sql .=
", total_tva";
1062 $sql .=
", total_localtax1";
1063 $sql .=
", total_localtax2";
1064 $sql .=
", total_ttc";
1065 $sql .=
", date_start_fill";
1066 $sql .=
", date_end_fill";
1067 $sql .=
", fk_product_fournisseur_price";
1068 $sql .=
", buy_price_ht";
1069 $sql .=
", info_bits";
1071 $sql .=
", special_code";
1072 $sql .=
", fk_unit";
1073 $sql .=
', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
1074 $sql .=
") VALUES (";
1075 $sql .=
" ".((int) $facid);
1076 $sql .=
", ".($fk_parent_line > 0 ? ((int) $fk_parent_line) :
"null");
1077 $sql .=
", ".(!empty($label) ?
"'".$this->db->escape($label).
"'" :
"null");
1078 $sql .=
", '".$this->db->escape($desc).
"'";
1079 $sql .=
", ".price2num($pu_ht);
1080 $sql .=
", ".price2num($qty);
1081 $sql .=
", ".price2num($txtva);
1082 $sql .=
", '".$this->db->escape($vat_src_code).
"'";
1083 $sql .=
", ".price2num($txlocaltax1);
1084 $sql .=
", '".$this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] :
'').
"'";
1085 $sql .=
", ".price2num($txlocaltax2);
1086 $sql .=
", '".$this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] :
'').
"'";
1087 $sql .=
", ".(!empty($fk_product) ?
"'".$this->db->escape($fk_product).
"'" :
"null");
1088 $sql .=
", ".((int) $product_type);
1089 $sql .=
", ".price2num($remise_percent);
1090 $sql .=
", ".price2num($pu_ht);
1092 $sql .=
", ".price2num($total_ht);
1093 $sql .=
", ".price2num($total_tva);
1094 $sql .=
", ".price2num($total_localtax1);
1095 $sql .=
", ".price2num($total_localtax2);
1096 $sql .=
", ".price2num($total_ttc);
1097 $sql .=
", ".(int) $date_start_fill;
1098 $sql .=
", ".(int) $date_end_fill;
1099 $sql .=
", ".($fk_fournprice > 0 ? $fk_fournprice :
'null');
1100 $sql .=
", ".($pa_ht ?
price2num($pa_ht) : 0);
1101 $sql .=
", ".((int) $info_bits);
1102 $sql .=
", ".((int) $ranktouse);
1103 $sql .=
", ".((int) $special_code);
1104 $sql .=
", ".($fk_unit ? ((int) $fk_unit) :
"null");
1105 $sql .=
", ".(int) $this->fk_multicurrency;
1106 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1107 $sql .=
", ".price2num($pu_ht_devise,
'CU');
1108 $sql .=
", ".price2num($multicurrency_total_ht,
'CT');
1109 $sql .=
", ".price2num($multicurrency_total_tva,
'CT');
1110 $sql .=
", ".price2num($multicurrency_total_ttc,
'CT');
1113 dol_syslog(get_class($this).
"::addline", LOG_DEBUG);
1114 if ($this->db->query($sql)) {
1115 $lineId = $this->db->last_insert_id(MAIN_DB_PREFIX.
"facturedet_rec");
1120 $this->error = $this->db->lasterror();
1155 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)
1161 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);
1162 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1165 if (empty($remise_percent)) {
1166 $remise_percent = 0;
1175 $remise_percent = (float)
price2num($remise_percent);
1177 if (empty($info_bits)) {
1182 $pu_ht_devise = (float)
price2num($pu_ht_devise);
1183 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
1188 if (empty($txlocaltax1)) {
1191 if (empty($txlocaltax2)) {
1195 if (empty($this->multicurrency_subprice)) {
1196 $this->multicurrency_subprice = 0;
1198 if (empty($this->multicurrency_total_ht)) {
1199 $this->multicurrency_total_ht = 0;
1201 if (empty($this->multicurrency_total_tva)) {
1202 $this->multicurrency_total_tva = 0;
1204 if (empty($this->multicurrency_total_ttc)) {
1205 $this->multicurrency_total_ttc = 0;
1208 if ($price_base_type ==
'HT') {
1223 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
1224 $vat_src_code = $reg[1];
1225 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
1228 $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);
1230 $total_ht = $tabprice[0];
1231 $total_tva = $tabprice[1];
1232 $total_ttc = $tabprice[2];
1233 $total_localtax1 = $tabprice[9];
1234 $total_localtax2 = $tabprice[10];
1235 $pu_ht = $tabprice[3];
1236 $pu_tva = $tabprice[4];
1237 $pu_ttc = $tabprice[5];
1240 $multicurrency_total_ht = $tabprice[16];
1241 $multicurrency_total_tva = $tabprice[17];
1242 $multicurrency_total_ttc = $tabprice[18];
1243 $pu_ht_devise = $tabprice[19];
1245 $product_type = $type;
1247 $product =
new Product($this->db);
1248 $result = $product->fetch($fk_product);
1249 $product_type = $product->type;
1252 if (empty($fk_parent_line) || $fk_parent_line < 0) {
1253 $fk_parent_line = 0;
1256 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet_rec SET ";
1257 $sql .=
"fk_facture = ".((int) $facid);
1258 $sql .=
", fk_parent_line = ".($fk_parent_line > 0 ? ((int) $fk_parent_line) :
"null");
1259 $sql .=
", label=".(!empty($label) ?
"'".$this->db->escape($label).
"'" :
"null");
1260 $sql .=
", description='".$this->db->escape($desc).
"'";
1261 $sql .=
", price=".price2num($pu_ht);
1262 $sql .=
", qty=".price2num($qty);
1263 $sql .=
", tva_tx=".price2num($txtva);
1264 $sql .=
", vat_src_code='".$this->db->escape($vat_src_code).
"'";
1265 $sql .=
", localtax1_tx=".((float) $txlocaltax1);
1266 $sql .=
", localtax1_type='".$this->db->escape($localtaxes_type[0]).
"'";
1267 $sql .=
", localtax2_tx=".((float) $txlocaltax2);
1268 $sql .=
", localtax2_type='".$this->db->escape($localtaxes_type[2]).
"'";
1269 $sql .=
", fk_product=".(!empty($fk_product) ?
"'".$this->db->escape($fk_product).
"'" :
"null");
1270 $sql .=
", product_type=".((int) $product_type);
1271 $sql .=
", remise_percent='".price2num($remise_percent).
"'";
1272 $sql .=
", subprice='".price2num($pu_ht).
"'";
1273 $sql .=
", total_ht='".price2num($total_ht).
"'";
1274 $sql .=
", total_tva='".price2num($total_tva).
"'";
1275 $sql .=
", total_localtax1='".price2num($total_localtax1).
"'";
1276 $sql .=
", total_localtax2='".price2num($total_localtax2).
"'";
1277 $sql .=
", total_ttc='".price2num($total_ttc).
"'";
1278 $sql .=
", date_start_fill=".((int) $date_start_fill);
1279 $sql .=
", date_end_fill=".((int) $date_end_fill);
1280 $sql .=
", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice :
'null');
1281 $sql .=
", buy_price_ht=".($pa_ht ?
price2num($pa_ht) : 0);
1282 $sql .=
", info_bits=".((int) $info_bits);
1283 $sql .=
", rang=".((int) $rang);
1284 $sql .=
", special_code=".((int) $special_code);
1285 $sql .=
", fk_unit=".($fk_unit ?
"'".$this->db->escape($fk_unit).
"'" :
"null");
1286 $sql .=
', multicurrency_subprice = '.price2num($pu_ht_devise);
1287 $sql .=
', multicurrency_total_ht = '.price2num($multicurrency_total_ht);
1288 $sql .=
', multicurrency_total_tva = '.price2num($multicurrency_total_tva);
1289 $sql .=
', multicurrency_total_ttc = '.price2num($multicurrency_total_ttc);
1290 $sql .=
" WHERE rowid = ".((int) $rowid);
1292 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
1293 if ($this->db->query($sql)) {
1298 $this->error = $this->db->lasterror();
1311 if (empty($this->date_when)) {
1325 if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) {
1355 global
$conf, $langs, $db, $user, $hookmanager;
1361 $langs->loadLangs(array(
"main",
"bills"));
1365 $today =
dol_mktime(23, 59, 59, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year']);
1369 dol_syslog(
"createRecurringInvoices restrictioninvoiceid=".$restrictioninvoiceid.
" forcevalidation=".$forcevalidation);
1371 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'facture_rec';
1372 $sql .=
' WHERE frequency > 0';
1373 $sql .=
" AND (date_when IS NULL OR date_when <= '".$this->db->idate($today).
"')";
1374 $sql .=
' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
1375 $sql .=
' AND suspended = 0';
1376 $sql .=
' AND entity = '.$conf->entity;
1377 if ($restrictioninvoiceid > 0) {
1378 $sql .=
' AND rowid = '.((int) $restrictioninvoiceid);
1380 $sql .= $this->db->order(
'entity',
'ASC');
1382 $parameters = array(
1383 'restrictioninvoiceid' => $restrictioninvoiceid,
1384 'forcevalidation' => $forcevalidation,
1386 $reshook = $hookmanager->executeHooks(
'beforeCreationOfRecurringInvoices', $parameters, $sql);
1388 $resql = $this->db->query($sql);
1391 $num = $this->db->num_rows($resql);
1394 $this->output .= $langs->trans(
"FoundXQualifiedRecurringInvoiceTemplate", $num).
"\n";
1396 $this->output .= $langs->trans(
"NoQualifiedRecurringInvoiceTemplateFound");
1399 $saventity =
$conf->entity;
1402 $line = $this->db->fetch_object($resql);
1406 $invoiceidgenerated = 0;
1410 $facturerec->fetch($line->rowid);
1412 if ($facturerec->id > 0) {
1414 $conf->entity = $facturerec->entity;
1416 dol_syslog(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref.
", entity=".$facturerec->entity);
1418 $facture =
new Facture($this->db);
1419 $facture->fac_rec = $facturerec->id;
1420 $facture->fk_fac_rec_source = $facturerec->id;
1423 $facture->subtype = $facturerec->subtype;
1426 $facture->date = (empty($facturerec->date_when) ? $now : $facturerec->date_when);
1427 $facture->socid = $facturerec->socid;
1428 if (!empty($facturerec->fk_multicurrency)) {
1429 $facture->fk_multicurrency = $facturerec->fk_multicurrency;
1430 $facture->multicurrency_code = $facturerec->multicurrency_code;
1431 $facture->multicurrency_tx = $facturerec->multicurrency_tx;
1434 if (isset($facture->array_options) && isset($facturerec->array_options)) {
1435 foreach ($facturerec->array_options as $key => $value) {
1436 if (isset($facture->array_options[$key])) {
1437 $facture->array_options[$key] = $value;
1442 $invoiceidgenerated = $facture->create($user);
1443 if ($invoiceidgenerated <= 0) {
1444 $this->errors = $facture->errors;
1445 $this->error = $facture->error;
1450 if (!$error && ($facturerec->auto_validate || $forcevalidation)) {
1451 $result = $facture->validate($user);
1453 $this->errors = $facture->errors;
1454 $this->error = $facture->error;
1458 if (!$error && $facturerec->generate_pdf) {
1460 $facture->fetch($facture->id);
1461 $result = $facture->generateDocument($facturerec->model_pdf, $langs);
1463 $this->errors = $facture->errors;
1464 $this->error = $facture->error;
1470 $this->error =
"Failed to load invoice template with id=".$line->rowid.
", entity=".
$conf->entity.
"\n";
1471 $this->errors[] =
"Failed to load invoice template with id=".$line->rowid.
", entity=".
$conf->entity;
1472 dol_syslog(
"createRecurringInvoices Failed to load invoice template with id=".$line->rowid.
", entity=".
$conf->entity);
1475 if (!$error && $invoiceidgenerated >= 0) {
1476 $this->db->commit(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref);
1477 dol_syslog(
"createRecurringInvoices Process invoice template ".$facturerec->ref.
" is finished with a success generation");
1479 $this->output .= $langs->trans(
"InvoiceGeneratedFromTemplate", $facture->ref, $facturerec->ref).
"\n";
1481 $this->db->rollback(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref);
1484 $parameters = array(
1487 'errorCount' => $error,
1488 'invoiceidgenerated' => $invoiceidgenerated,
1489 'facturerec' => $facturerec,
1492 $reshook = $hookmanager->executeHooks(
'afterCreationOfRecurringInvoice', $parameters, $facture);
1497 $conf->entity = $saventity;
1502 $this->output = trim($this->output);
1504 return $error ? $error : 0;
1519 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'', $notooltip = 0, $save_lastsearch_value = -1)
1521 global $langs, $hookmanager;
1525 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"RepeatableInvoice").
'</u>';
1526 if (!empty($this->
ref)) {
1527 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1529 if ($this->frequency > 0) {
1530 $label .=
'<br><b>'.$langs->trans(
'Frequency').
':</b> '.$langs->trans(
'FrequencyPer_'.$this->unit_frequency, $this->frequency);
1532 if (!empty($this->date_last_gen)) {
1533 $label .=
'<br><b>'.$langs->trans(
'DateLastGeneration').
':</b> '.
dol_print_date($this->date_last_gen,
'dayhour');
1535 if ($this->frequency > 0) {
1536 if (!empty($this->date_when)) {
1537 $label .=
'<br><b>'.$langs->trans(
'NextDateToExecution').
':</b> ';
1538 $label .= (empty($this->suspended) ?
'' :
'<strike>').
dol_print_date($this->date_when,
'day').(empty($this->suspended) ?
'' :
'</strike>');
1539 if (!empty($this->suspended)) {
1540 $label .=
' ('.$langs->trans(
"Disabled").
')';
1545 $url = DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$this->id;
1551 if ($option !=
'nolink') {
1553 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1554 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1555 $add_save_lastsearch_values = 1;
1557 if ($add_save_lastsearch_values) {
1558 $url .=
'&save_lastsearch_values=1';
1562 $linkstart =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
1565 $result .= $linkstart;
1567 $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);
1569 if ($withpicto != 2) {
1572 $result .= $linkend;
1574 $hookmanager->initHooks(array($this->element .
'dao'));
1575 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1576 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1578 $result = $hookmanager->resPrint;
1580 $result .= $hookmanager->resPrint;
1594 return $this->
LibStatut($this->frequency ? 1 : 0, $this->suspended, $mode, $alreadypaid, empty($this->
type) ? 0 : $this->type);
1608 public function LibStatut($recur, $status, $mode = 0, $alreadypaid = -1, $type = 0)
1612 $langs->load(
'bills');
1614 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1615 $statusType =
'status0';
1620 if ($status == self::STATUS_SUSPENDED) {
1621 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1623 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1626 if ($status == self::STATUS_SUSPENDED) {
1627 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1629 $labelStatus = $langs->transnoentitiesnoconv(
"Draft");
1632 } elseif ($mode == 1) {
1635 if ($status == self::STATUS_SUSPENDED) {
1636 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1638 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1641 if ($status == self::STATUS_SUSPENDED) {
1642 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1644 $labelStatus = $langs->transnoentitiesnoconv(
"Draft");
1647 } elseif ($mode == 2) {
1649 if ($status == self::STATUS_SUSPENDED) {
1650 $statusType =
'status6';
1651 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1653 $statusType =
'status4';
1654 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1657 if ($status == self::STATUS_SUSPENDED) {
1658 $statusType =
'status6';
1659 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1661 $statusType =
'status0';
1662 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1665 } elseif ($mode == 3) {
1668 if ($status == self::STATUS_SUSPENDED) {
1669 $statusType =
'status6';
1670 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1672 $statusType =
'status4';
1673 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1676 if ($status == self::STATUS_SUSPENDED) {
1677 $statusType =
'status6';
1678 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1680 $statusType =
'status0';
1681 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1684 } elseif ($mode == 4) {
1687 if ($status == self::STATUS_SUSPENDED) {
1688 $statusType =
'status6';
1689 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1691 $statusType =
'status4';
1692 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1695 if ($status == self::STATUS_SUSPENDED) {
1696 $statusType =
'status6';
1697 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1699 $statusType =
'status0';
1700 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1703 } elseif ($mode == 5 || $mode == 6) {
1709 if ($status == self::STATUS_SUSPENDED) {
1710 $statusType =
'status6';
1711 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1713 $statusType =
'status4';
1714 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1717 if ($status == self::STATUS_SUSPENDED) {
1718 $statusType =
'status6';
1719 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1721 $statusType =
'status0';
1722 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1727 $labelStatusShort = $labelStatus;
1729 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1753 $sql =
'SELECT c.rowid, datec, tms as datem,';
1754 $sql .=
' fk_user_author, fk_user_modif';
1755 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as c';
1756 $sql .=
' WHERE c.rowid = '.((int) $id);
1758 $result = $this->db->query($sql);
1760 if ($this->db->num_rows($result)) {
1761 $obj = $this->db->fetch_object($result);
1763 $this->
id = $obj->rowid;
1765 $this->user_creation_id = $obj->fk_user_author;
1766 $this->user_modification_id = $obj->fk_user_modif;
1767 $this->date_creation = $this->db->jdate($obj->datec);
1768 $this->date_modification = $this->db->jdate($obj->datem);
1770 $this->db->free($result);
1790 $nownotime =
dol_mktime(0, 0, 0, $arraynow[
'mon'], $arraynow[
'mday'], $arraynow[
'year']);
1796 $sql =
"SELECT rowid";
1797 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
1798 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
1799 $sql .= $this->db->plimit(100);
1801 $resql = $this->db->query($sql);
1803 $num_prods = $this->db->num_rows($resql);
1805 while ($i < $num_prods) {
1807 $row = $this->db->fetch_row($resql);
1808 $prodids[$i] = $row[0];
1814 $this->
ref =
'SPECIMEN';
1815 $this->title =
'SPECIMEN';
1816 $this->specimen = 1;
1818 $this->date = $nownotime;
1819 $this->date_lim_reglement = $nownotime + 3600 * 24 * 30;
1820 $this->cond_reglement_id = 1;
1821 $this->cond_reglement_code =
'RECEP';
1823 $this->mode_reglement_id = 0;
1824 $this->mode_reglement_code =
'';
1825 $this->note_public =
'This is a comment (public)';
1826 $this->note_private =
'This is a comment (private)';
1827 $this->note =
'This is a comment (private)';
1828 $this->fk_incoterms = 0;
1829 $this->location_incoterms =
'';
1831 if (empty($option) || $option !=
'nolines') {
1835 while ($xnbp < $nbp) {
1837 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1839 $line->subprice = 100;
1840 $line->tva_tx = 19.6;
1841 $line->localtax1_tx = 0;
1842 $line->localtax2_tx = 0;
1843 $line->remise_percent = 0;
1845 $prodid = mt_rand(1, $num_prods);
1846 $line->fk_product = $prodids[$prodid];
1848 $line->total_ht = -100;
1849 $line->total_ttc = -119.6;
1850 $line->total_tva = -19.6;
1851 } elseif ($xnbp == 2) {
1852 $line->subprice = -100;
1853 $line->total_ht = -100;
1854 $line->total_ttc = -119.6;
1855 $line->total_tva = -19.6;
1856 $line->remise_percent = 0;
1857 } elseif ($xnbp == 3) {
1858 $prodid = mt_rand(1, $num_prods);
1859 $line->fk_product = $prodids[$prodid];
1860 $line->total_ht = 50;
1861 $line->total_ttc = 59.8;
1862 $line->total_tva = 9.8;
1863 $line->remise_percent = 50;
1865 $prodid = mt_rand(1, $num_prods);
1866 $line->fk_product = $prodids[$prodid];
1867 $line->total_ht = 100;
1868 $line->total_ttc = 119.6;
1869 $line->total_tva = 19.6;
1870 $line->remise_percent = 00;
1873 $this->lines[$xnbp] = $line;
1876 $this->total_ht += $line->total_ht;
1877 $this->total_tva += $line->total_tva;
1878 $this->total_ttc += $line->total_ttc;
1880 $this->revenuestamp = 0;
1884 $line->desc = $langs->trans(
"Description").
" (offered line)";
1886 $line->subprice = 100;
1887 $line->tva_tx = 19.6;
1888 $line->localtax1_tx = 0;
1889 $line->localtax2_tx = 0;
1890 $line->remise_percent = 100;
1891 $line->total_ht = 0;
1892 $line->total_ttc = 0;
1893 $line->total_tva = 0;
1894 $prodid = mt_rand(1, $num_prods);
1895 $line->fk_product = $prodids[$prodid];
1897 $this->lines[$xnbp] = $line;
1901 $this->usenewprice = 0;
1952 if (!$this->table_element) {
1953 dol_syslog(get_class($this).
"::setFrequencyAndUnit was called on object with property table_element not defined", LOG_ERR);
1957 if (!empty($frequency) && empty($unit)) {
1958 dol_syslog(get_class($this).
"::setFrequencyAndUnit was called on object with params frequency defined but unit not defined", LOG_ERR);
1962 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1963 $sql .=
' SET frequency = '.($frequency ? $this->db->escape($frequency) :
'null');
1964 if (!empty($unit)) {
1965 $sql .=
', unit_frequency = \''.$this->db->escape($unit).
'\'';
1967 $sql .=
" WHERE rowid = ".((int) $this->
id);
1969 dol_syslog(get_class($this).
"::setFrequencyAndUnit", LOG_DEBUG);
1970 if ($this->db->query($sql)) {
1971 $this->frequency = $frequency;
1972 if (!empty($unit)) {
1973 $this->unit_frequency = $unit;
1978 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2000 public function setNextDate($date, $increment_nb_gen_done = 0, $notrigger = 0)
2004 if (!$this->table_element) {
2005 dol_syslog(get_class($this).
"::setNextDate was called on object with property table_element not defined", LOG_ERR);
2008 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2009 $sql .=
" SET date_when = ".($date ?
"'".$this->db->idate($date).
"'" :
"null");
2010 if ($increment_nb_gen_done > 0) {
2011 $sql .=
', nb_gen_done = nb_gen_done + 1';
2013 $sql .=
" WHERE rowid = ".((int) $this->
id);
2015 dol_syslog(get_class($this).
"::setNextDate", LOG_DEBUG);
2016 if ($this->db->query($sql)) {
2017 $this->date_when = $date;
2018 if ($increment_nb_gen_done > 0) {
2019 $this->nb_gen_done++;
2024 if ($resSuspend <= 0) {
2025 dol_syslog(__METHOD__ .
'::setValueFrom Error : ' . $this->error, LOG_ERR);
2033 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2057 if (!$this->table_element) {
2058 dol_syslog(get_class($this).
"::setMaxPeriod was called on object with property table_element not defined", LOG_ERR);
2066 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2067 $sql .=
' SET nb_gen_max = '.((int) $nb);
2068 $sql .=
" WHERE rowid = ".((int) $this->
id);
2070 dol_syslog(get_class($this).
"::setMaxPeriod", LOG_DEBUG);
2071 if ($this->db->query($sql)) {
2072 $this->nb_gen_max = $nb;
2076 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2101 if (!$this->table_element) {
2102 dol_syslog(get_class($this).
"::setAutoValidate was called on object with property table_element not defined", LOG_ERR);
2106 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2107 $sql .=
' SET auto_validate = '.((int) $validate);
2108 $sql .=
" WHERE rowid = ".((int) $this->
id);
2110 dol_syslog(get_class($this).
"::setAutoValidate", LOG_DEBUG);
2111 if ($this->db->query($sql)) {
2112 $this->auto_validate = $validate;
2116 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2141 if (!$this->table_element) {
2142 dol_syslog(get_class($this).
"::setGeneratePdf was called on object with property table_element not defined", LOG_ERR);
2146 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2147 $sql .=
' SET generate_pdf = '.((int) $validate);
2148 $sql .=
" WHERE rowid = ".((int) $this->
id);
2150 dol_syslog(get_class($this).
"::setGeneratePdf", LOG_DEBUG);
2151 if ($this->db->query($sql)) {
2152 $this->generate_pdf = $validate;
2156 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2180 if (!$this->table_element) {
2181 dol_syslog(get_class($this).
"::setModelPdf was called on object with property table_element not defined", LOG_ERR);
2185 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2186 $sql .=
" SET modelpdf = '".$this->db->escape($model).
"'";
2187 $sql .=
" WHERE rowid = ".((int) $this->
id);
2189 dol_syslog(get_class($this).
"::setModelPdf", LOG_DEBUG);
2190 if ($this->db->query($sql)) {
2191 $this->model_pdf = $model;
2195 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2221 public $element =
'facturedetrec';
2226 public $table_element =
'facturedet_rec';
2246 public $fk_parent_line;
2251 public $fk_product_fournisseur_price;
2256 public $fk_fournprice;
2271 public $description;
2277 public $fk_product_type;
2282 public $fk_contract_line;
2292 public function delete(
User $user, $notrigger = 0)
2301 $result = $this->
call_trigger(
'LINEBILLREC_DELETE', $user);
2317 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
' WHERE rowid='.((int) $this->
id);
2319 $res = $this->db->query($sql);
2322 $this->errors[] = $this->db->lasterror();
2328 $this->db->rollback();
2331 $this->db->commit();
2345 $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,';
2346 $sql .=
' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
2347 $sql .=
' l.date_start_fill, l.date_end_fill, l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
2348 $sql .=
' l.rang, l.special_code,';
2349 $sql .=
' l.fk_unit, l.fk_contract_line,';
2350 $sql .=
' l.import_key, l.fk_multicurrency,';
2351 $sql .=
' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
2352 $sql .=
' l.buy_price_ht, l.fk_product_fournisseur_price,';
2353 $sql .=
' l.fk_user_author, l.fk_user_modif,';
2354 $sql .=
' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
2355 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facturedet_rec as l';
2356 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
2357 $sql .=
' WHERE l.rowid = '.((int) $rowid);
2358 $sql .=
' ORDER BY l.rang';
2361 $result = $this->db->query($sql);
2363 $objp = $this->db->fetch_object($result);
2365 $this->
id = $objp->rowid;
2366 $this->fk_facture = $objp->fk_facture;
2367 $this->fk_parent_line = $objp->fk_parent_line;
2368 $this->label = $objp->custom_label;
2369 $this->desc = $objp->description;
2371 $this->product_type = $objp->product_type;
2372 $this->
ref = $objp->product_ref;
2373 $this->product_ref = $objp->product_ref;
2374 $this->libelle = $objp->product_label;
2375 $this->product_label = $objp->product_label;
2376 $this->product_desc = $objp->product_desc;
2377 $this->fk_product_type = $objp->fk_product_type;
2378 $this->qty = $objp->qty;
2379 $this->
price = $objp->price;
2380 $this->subprice = $objp->subprice;
2381 $this->vat_src_code = $objp->vat_src_code;
2382 $this->tva_tx = $objp->tva_tx;
2383 $this->localtax1_tx = $objp->localtax1_tx;
2384 $this->localtax2_tx = $objp->localtax2_tx;
2385 $this->localtax1_type = $objp->localtax1_type;
2386 $this->localtax2_type = $objp->localtax2_type;
2387 $this->remise_percent = $objp->remise_percent;
2389 $this->fk_product = $objp->fk_product;
2390 $this->date_start_fill = $objp->date_start_fill;
2391 $this->date_end_fill = $objp->date_end_fill;
2392 $this->info_bits = $objp->info_bits;
2393 $this->total_ht = $objp->total_ht;
2394 $this->total_tva = $objp->total_tva;
2395 $this->total_ttc = $objp->total_ttc;
2397 $this->rang = $objp->rang;
2398 $this->special_code = $objp->special_code;
2399 $this->fk_unit = $objp->fk_unit;
2400 $this->fk_contract_line = $objp->fk_contract_line;
2401 $this->import_key = $objp->import_key;
2402 $this->fk_multicurrency = $objp->fk_multicurrency;
2403 $this->multicurrency_code = $objp->multicurrency_code;
2404 $this->multicurrency_subprice = $objp->multicurrency_subprice;
2405 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
2406 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
2407 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2409 $this->buy_price_ht = $objp->buy_price_ht;
2411 $this->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
2412 $this->fk_user_author = $objp->fk_user_author;
2413 $this->fk_user_modif = $objp->fk_user_modif;
2415 $this->db->free($result);
2418 $this->error = $this->db->lasterror();
2438 if (empty($this->fk_parent_line)) {
2439 $this->fk_parent_line = 0;
2442 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2444 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet_rec SET";
2445 $sql .=
" fk_facture = ".((int) $this->fk_facture);
2446 $sql .=
", fk_parent_line=".($this->fk_parent_line > 0 ? $this->fk_parent_line :
"null");
2447 $sql .=
", label=".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null");
2448 $sql .=
", description='".$this->db->escape($this->desc).
"'";
2449 $sql .=
", price=".price2num($this->
price);
2450 $sql .=
", qty=".price2num($this->qty);
2451 $sql .=
", tva_tx=".price2num($this->tva_tx);
2452 $sql .=
", vat_src_code='".$this->db->escape($this->vat_src_code).
"'";
2453 $sql .=
", localtax1_tx=".price2num($this->localtax1_tx);
2454 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
2455 $sql .=
", localtax2_tx=".price2num($this->localtax2_tx);
2456 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
2457 $sql .=
", fk_product=".($this->fk_product > 0 ? $this->fk_product :
"null");
2458 $sql .=
", product_type=".((int) $this->product_type);
2459 $sql .=
", remise_percent=".price2num($this->remise_percent);
2460 $sql .=
", subprice=".price2num($this->subprice);
2461 $sql .=
", info_bits=".price2num($this->info_bits);
2462 $sql .=
", date_start_fill=".(int) $this->date_start_fill;
2463 $sql .=
", date_end_fill=".(int) $this->date_end_fill;
2464 if (empty($this->skip_update_total)) {
2465 $sql .=
", total_ht=".price2num($this->total_ht);
2466 $sql .=
", total_tva=".price2num($this->total_tva);
2467 $sql .=
", total_localtax1=".price2num($this->total_localtax1);
2468 $sql .=
", total_localtax2=".price2num($this->total_localtax2);
2469 $sql .=
", total_ttc=".price2num($this->total_ttc);
2471 $sql .=
", rang=".((int) $this->rang);
2472 $sql .=
", special_code=".((int) $this->special_code);
2473 $sql .=
", fk_unit=".($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
"null");
2474 $sql .=
", fk_contract_line=".($this->fk_contract_line ? $this->fk_contract_line :
"null");
2475 $sql .=
" WHERE rowid = ".((int) $this->
id);
2479 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
2481 $resql = $this->db->query($sql);
2490 if (!$error && !$notrigger) {
2492 $result = $this->
call_trigger(
'LINEBILLREC_MODIFY', $user);
2500 $this->db->rollback();
2503 $this->db->commit();
2507 $this->error = $this->db->lasterror();
2508 $this->db->rollback();
Superclass for invoice 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...
update_price($exclspec=0, $roundingadjust='auto', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
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.
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.
setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif')
Setter generic.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage invoices.
Class to manage invoice lines.
Class to manage invoice lines of templates.
fetch($rowid)
Get line of template invoice.
update(User $user, $notrigger=0)
Update a line to invoice_rec.
Class to manage invoice templates.
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 clickable 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 information (by default a local PHP server timestamp) Rep...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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_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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
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($pv_ht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $pa_ht)
Return an array with margins information of a line.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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