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.
'/core/lib/date.lib.php';
45 const TRIGGER_PREFIX =
'BILLREC';
49 public $element =
'facturerec';
54 public $table_element =
'facture_rec';
59 public $table_element_line =
'facturedet_rec';
64 public $fk_element =
'fk_facture';
69 public $picto =
'bill';
95 public $multicurrency_subprice;
115 public $date_last_gen;
130 public $unit_frequency;
137 public $special_code;
139 public $usenewprice = 0;
144 public $date_lim_reglement;
145 public $cond_reglement_code;
146 public $mode_reglement_code;
150 public $auto_validate;
151 public $generate_pdf;
182 public $fields = array(
183 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
184 'titre' => array(
'type' =>
'varchar(100)',
'label' =>
'Titre',
'enabled' => 1,
'showoncombobox' => 1,
'visible' => -1,
'position' => 15),
185 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 20,
'index' => 1),
186 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => -1,
'notnull' => 1,
'position' => 25),
187 'subtype' => array(
'type' =>
'smallint(6)',
'label' =>
'InvoiceSubtype',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 30),
188 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 35),
189 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'Tva',
'enabled' => 1,
'visible' => -1,
'position' => 55,
'isameasure' => 1),
190 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'Localtax1',
'enabled' => 1,
'visible' => -1,
'position' => 60,
'isameasure' => 1),
191 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'Localtax2',
'enabled' => 1,
'visible' => -1,
'position' => 65,
'isameasure' => 1),
192 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'Total',
'enabled' => 1,
'visible' => -1,
'position' => 70,
'isameasure' => 1),
193 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'Total ttc',
'enabled' => 1,
'visible' => -1,
'position' => 75,
'isameasure' => 1),
194 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fk user author',
'enabled' => 1,
'visible' => -1,
'position' => 80),
195 '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),
196 'fk_cond_reglement' => array(
'type' =>
'integer',
'label' =>
'Fk cond reglement',
'enabled' => 1,
'visible' => -1,
'position' => 90),
197 'fk_mode_reglement' => array(
'type' =>
'integer',
'label' =>
'Fk mode reglement',
'enabled' => 1,
'visible' => -1,
'position' => 95),
198 'date_lim_reglement' => array(
'type' =>
'date',
'label' =>
'Date lim reglement',
'enabled' => 1,
'visible' => -1,
'position' => 100),
199 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 105),
200 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 110),
201 'modelpdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Modelpdf',
'enabled' => 1,
'visible' => -1,
'position' => 115),
202 'date_when' => array(
'type' =>
'datetime',
'label' =>
'Date when',
'enabled' => 1,
'visible' => -1,
'position' => 130),
203 'date_last_gen' => array(
'type' =>
'datetime',
'label' =>
'Date last gen',
'enabled' => 1,
'visible' => -1,
'position' => 135),
204 'nb_gen_done' => array(
'type' =>
'integer',
'label' =>
'Nb gen done',
'enabled' => 1,
'visible' => -1,
'position' => 140),
205 'nb_gen_max' => array(
'type' =>
'integer',
'label' =>
'Nb gen max',
'enabled' => 1,
'visible' => -1,
'position' => 145),
206 'frequency' => array(
'type' =>
'integer',
'label' =>
'Frequency',
'enabled' => 1,
'visible' => -1,
'position' => 150),
207 'unit_frequency' => array(
'type' =>
'varchar(2)',
'label' =>
'UnitFrequency',
'enabled' => 1,
'visible' => -1,
'position' => 152),
208 'usenewprice' => array(
'type' =>
'integer',
'label' =>
'UseNewPrice',
'enabled' => 1,
'visible' => 0,
'position' => 155),
209 'revenuestamp' => array(
'type' =>
'double(24,8)',
'label' =>
'RevenueStamp',
'enabled' => 1,
'visible' => -1,
'position' => 160,
'isameasure' => 1),
210 'auto_validate' => array(
'type' =>
'integer',
'label' =>
'Auto validate',
'enabled' => 1,
'visible' => -1,
'position' => 165),
211 'generate_pdf' => array(
'type' =>
'integer',
'label' =>
'Generate pdf',
'enabled' => 1,
'visible' => -1,
'position' => 170),
212 'fk_account' => array(
'type' =>
'integer',
'label' =>
'Fk account',
'enabled' =>
'isModEnabled("bank")',
'visible' => -1,
'position' => 175),
213 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'Fk multicurrency',
'enabled' => 1,
'visible' => -1,
'position' => 180),
214 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'Multicurrency code',
'enabled' => 1,
'visible' => -1,
'position' => 185),
215 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'Multicurrency tx',
'enabled' => 1,
'visible' => -1,
'position' => 190,
'isameasure' => 1),
216 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'Multicurrency total ht',
'enabled' => 1,
'visible' => -1,
'position' => 195,
'isameasure' => 1),
217 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'Multicurrency total tva',
'enabled' => 1,
'visible' => -1,
'position' => 200,
'isameasure' => 1),
218 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'Multicurrency total ttc',
'enabled' => 1,
'visible' => -1,
'position' => 205,
'isameasure' => 1),
219 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 210),
220 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 215),
221 'suspended' => array(
'type' =>
'integer',
'label' =>
'Suspended',
'enabled' => 1,
'visible' => -1,
'position' => 225),
225 const STATUS_NOTSUSPENDED = 0;
226 const STATUS_SUSPENDED = 1;
249 public function create($user, $facid, $notrigger = 0, $onlylines = array())
257 $this->titre = trim(isset($this->titre) ? $this->titre : $this->title);
258 $this->title = trim($this->title);
259 $this->usenewprice = empty($this->usenewprice) ? 0 : $this->usenewprice;
260 if (empty($this->suspended)) {
261 $this->suspended = 0;
265 if (empty($this->frequency)) {
266 $this->frequency = 0;
267 $this->date_when =
null;
270 $this->frequency = abs($this->frequency);
271 $this->nb_gen_done = 0;
272 $this->nb_gen_max = empty($this->nb_gen_max) ? 0 : $this->nb_gen_max;
273 $this->auto_validate = empty($this->auto_validate) ? 0 : $this->auto_validate;
274 $this->generate_pdf = empty($this->generate_pdf) ? 0 : $this->generate_pdf;
279 $facsrc =
new Facture($this->db);
280 $result = $facsrc->fetch($facid);
282 $this->socid = $facsrc->socid;
284 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facture_rec (";
292 $sql .=
", note_private";
293 $sql .=
", note_public";
294 $sql .=
", modelpdf";
295 $sql .=
", fk_user_author";
296 $sql .=
", fk_projet";
297 $sql .=
", fk_account";
298 $sql .=
", fk_cond_reglement";
299 $sql .=
", fk_mode_reglement";
300 $sql .=
", usenewprice";
301 $sql .=
", frequency";
302 $sql .=
", unit_frequency";
303 $sql .=
", date_when";
304 $sql .=
", date_last_gen";
305 $sql .=
", nb_gen_done";
306 $sql .=
", nb_gen_max";
307 $sql .=
", auto_validate";
308 $sql .=
", generate_pdf";
309 $sql .=
", fk_multicurrency";
310 $sql .=
", multicurrency_code";
311 $sql .=
", multicurrency_tx";
312 $sql .=
", suspended";
313 $sql .=
") VALUES (";
314 $sql .=
"'".$this->db->escape($this->titre ? $this->titre : $this->title).
"'";
315 $sql .=
", ".((int) $this->socid);
316 $sql .=
", ".($this->subtype ?
"'".$this->db->escape($this->subtype).
"'" :
"null");
317 $sql .=
", ".((int) $conf->entity);
318 $sql .=
", '".$this->db->idate($now).
"'";
319 $sql .=
", ".(!empty($facsrc->total_ttc) ? ((float) $facsrc->total_ttc) :
'0');
321 $sql .=
", ".(!empty($this->note_private) ? (
"'".$this->db->escape($this->note_private).
"'") :
"NULL");
322 $sql .=
", ".(!empty($this->note_public) ? (
"'".$this->db->escape($this->note_public).
"'") :
"NULL");
323 $sql .=
", ".(!empty($this->model_pdf) ? (
"'".$this->db->escape($this->model_pdf).
"'") :
"NULL");
324 $sql .=
", ".((int) $user->id);
325 $sql .=
", ".(!empty($this->fk_project) ? ((int) $this->fk_project) :
"null");
326 $sql .=
", ".(!empty($facsrc->fk_account) ? ((int) $facsrc->fk_account) :
"null");
327 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
"null");
328 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
"null");
329 $sql .=
", ".((int) $this->usenewprice);
330 $sql .=
", ".((int) $this->frequency);
331 $sql .=
", '".$this->db->escape($this->unit_frequency).
"'";
332 $sql .=
", ".(!empty($this->date_when) ?
"'".$this->db->idate($this->date_when).
"'" :
'NULL');
333 $sql .=
", ".(!empty($this->date_last_gen) ?
"'".$this->db->idate($this->date_last_gen).
"'" :
'NULL');
334 $sql .=
", ".((int) $this->nb_gen_done);
335 $sql .=
", ".((int) $this->nb_gen_max);
336 $sql .=
", ".((int) $this->auto_validate);
337 $sql .=
", ".((int) $this->generate_pdf);
338 $sql .=
", ".((int) $facsrc->fk_multicurrency);
339 $sql .=
", '".$this->db->escape($facsrc->multicurrency_code).
"'";
340 $sql .=
", ".((float) $facsrc->multicurrency_tx);
341 $sql .=
", ".((int) $this->suspended);
344 if ($this->db->query($sql)) {
345 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"facture_rec");
348 $this->fk_multicurrency = $facsrc->fk_multicurrency;
349 $this->multicurrency_code = $facsrc->multicurrency_code;
350 $this->multicurrency_tx = $facsrc->multicurrency_tx;
355 $num = count($facsrc->lines);
356 for ($i = 0; $i < $num; $i++) {
357 if (!empty($onlylines) && !in_array($facsrc->lines[$i]->id, $onlylines)) {
362 if (($facsrc->lines[$i]->product_type != 9 && empty($facsrc->lines[$i]->fk_parent_line)) || $facsrc->lines[$i]->product_type == 9) {
366 $tva_tx = $facsrc->lines[$i]->tva_tx;
367 if (!empty($facsrc->lines[$i]->vat_src_code) && !preg_match(
'/\(/', (
string) $tva_tx)) {
368 $tva_tx .=
' ('.$facsrc->lines[$i]->vat_src_code.
')';
371 $default_start_fill =
getDolGlobalInt(
'INVOICEREC_SET_AUTOFILL_DATE_START');
372 $default_end_fill =
getDolGlobalInt(
'INVOICEREC_SET_AUTOFILL_DATE_END');
374 $result_insert = $this->
addline(
375 $facsrc->lines[$i]->desc,
376 $facsrc->lines[$i]->subprice,
377 $facsrc->lines[$i]->qty,
379 $facsrc->lines[$i]->localtax1_tx,
380 $facsrc->lines[$i]->localtax2_tx,
381 $facsrc->lines[$i]->fk_product,
382 $facsrc->lines[$i]->remise_percent,
384 $facsrc->lines[$i]->info_bits,
387 $facsrc->lines[$i]->product_type,
388 $facsrc->lines[$i]->rang,
389 $facsrc->lines[$i]->special_code,
390 $facsrc->lines[$i]->label,
391 $facsrc->lines[$i]->fk_unit,
392 $facsrc->lines[$i]->multicurrency_subprice,
396 $facsrc->lines[$i]->pa_ht,
401 if ($result_insert > 0 && $facsrc->lines[$i]->product_type == 9) {
402 $fk_parent_line = $result_insert;
405 if ($result_insert < 0) {
410 $result2 = $objectline->fetch($result_insert);
413 if (method_exists($facsrc->lines[$i],
'fetch_optionals')) {
414 $facsrc->lines[$i]->fetch_optionals($facsrc->lines[$i]->id);
415 $objectline->array_options = $facsrc->lines[$i]->array_options;
418 $result = $objectline->insertExtraFields();
422 } elseif ($result2 < 0) {
423 $this->errors[] = $objectline->error;
429 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
430 $this->linked_objects = $this->linkedObjectsIds;
434 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
435 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
436 if (is_array($tmp_origin_id)) {
437 foreach ($tmp_origin_id as $origin_id) {
440 $this->error = $this->db->lasterror();
445 $origin_id = $tmp_origin_id;
448 $this->error = $this->db->lasterror();
462 if (!$error && !$notrigger) {
466 $this->db->rollback();
473 $this->db->rollback();
480 $this->error = $this->db->lasterror();
481 $this->db->rollback();
485 $this->db->rollback();
502 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_rec SET";
503 $sql .=
" entity = ".((int) $this->entity).
",";
504 $sql .=
" titre = '".$this->db->escape($this->title).
"',";
505 $sql .=
" suspended = ".((int) $this->suspended).
",";
506 $sql .=
" fk_soc = ".((int) $this->socid).
",";
507 $sql .=
" total_tva = ".((float) $this->total_tva).
",";
508 $sql .=
" localtax1 = ".((float) $this->total_localtax1).
",";
509 $sql .=
" localtax2 = ".((float) $this->total_localtax2).
",";
510 $sql .=
" total_ht = ".((float) $this->total_ht).
",";
511 $sql .=
" total_ttc = ".((float) $this->total_ttc);
513 $sql .=
" WHERE rowid = ".((int) $this->
id);
517 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
519 $resql = $this->db->query($sql);
528 if (!$error && !$notrigger) {
532 $this->db->rollback();
540 $this->error = $this->db->lasterror();
541 $this->db->rollback();
556 public function fetch($rowid, $ref =
'', $ref_ext =
'', $noextrafields = 0, $nolines = 0)
560 $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';
561 $sql .=
', f.date_lim_reglement as dlr';
562 $sql .=
', f.note_private, f.note_public, f.fk_user_author';
563 $sql .=
', f.modelpdf as model_pdf';
564 $sql .=
', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet as fk_project';
565 $sql .=
', f.fk_account';
566 $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';
567 $sql .=
', f.generate_pdf';
568 $sql .=
", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
569 $sql .=
', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
570 $sql .=
', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
572 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as f';
573 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
574 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as p ON f.fk_mode_reglement = p.id';
576 $sql .=
' WHERE f.entity IN ('.getEntity(
'invoice').
')';
578 $sql .=
' AND f.rowid = '.((int) $rowid);
580 $sql .=
" AND f.titre = '".$this->db->escape($ref).
"'";
582 $sql .=
' AND f.rowid = 0';
588 $result = $this->db->query($sql);
590 if ($this->db->num_rows($result)) {
591 $obj = $this->db->fetch_object($result);
593 $this->
id = $obj->rowid;
594 $this->entity = $obj->entity;
595 $this->titre = $obj->title;
596 $this->title = $obj->title;
597 $this->
ref = $obj->title;
598 $this->subtype = $obj->subtype;
599 $this->suspended = $obj->suspended;
600 $this->total_ht = $obj->total_ht;
601 $this->total_tva = $obj->total_tva;
602 $this->total_localtax1 = $obj->localtax1;
603 $this->total_localtax2 = $obj->localtax2;
604 $this->total_ttc = $obj->total_ttc;
605 $this->socid = $obj->fk_soc;
606 $this->date_lim_reglement = $this->db->jdate($obj->dlr);
607 $this->mode_reglement_id = $obj->fk_mode_reglement;
608 $this->mode_reglement_code = $obj->mode_reglement_code;
609 $this->mode_reglement = $obj->mode_reglement_libelle;
610 $this->cond_reglement_id = $obj->fk_cond_reglement;
611 $this->cond_reglement_code = $obj->cond_reglement_code;
612 $this->cond_reglement = $obj->cond_reglement_libelle;
613 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
614 $this->fk_project = $obj->fk_project;
615 $this->fk_account = $obj->fk_account;
616 $this->note_private = $obj->note_private;
617 $this->note_public = $obj->note_public;
618 $this->user_author = $obj->fk_user_author;
619 $this->model_pdf = $obj->model_pdf;
621 $this->frequency = $obj->frequency;
622 $this->unit_frequency = $obj->unit_frequency;
623 $this->date_when = $this->db->jdate($obj->date_when);
624 $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
625 $this->nb_gen_done = $obj->nb_gen_done;
626 $this->nb_gen_max = $obj->nb_gen_max;
627 $this->usenewprice = $obj->usenewprice;
628 $this->auto_validate = $obj->auto_validate;
629 $this->generate_pdf = $obj->generate_pdf;
632 $this->fk_multicurrency = $obj->fk_multicurrency;
633 $this->multicurrency_code = $obj->multicurrency_code;
634 $this->multicurrency_tx = $obj->multicurrency_tx;
635 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
636 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
637 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
641 if (empty($noextrafields)) {
644 $this->error = $this->db->lasterror();
650 if (empty($nolines)) {
653 $this->error = $this->db->lasterror();
660 $this->error =
'Bill with id '.$rowid.
' or ref '.$ref.
' not found';
661 dol_syslog(
'Facture::Fetch Error '.$this->error, LOG_ERR);
665 $this->error = $this->db->error();
692 $this->lines = array();
694 dol_syslog(
'FactureRec::fetch_lines', LOG_DEBUG);
696 $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, ';
697 $sql .=
' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
698 $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,';
699 $sql .=
' l.rang, l.special_code,';
700 $sql .=
' l.fk_unit, l.fk_contract_line,';
701 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
702 $sql .=
' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
703 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facturedet_rec as l';
704 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
705 $sql .=
' WHERE l.fk_facture = '.((int) $this->
id);
706 $sql .=
' ORDER BY l.rang';
708 $result = $this->db->query($sql);
710 $num = $this->db->num_rows($result);
713 $objp = $this->db->fetch_object($result);
716 $line->id = $objp->rowid;
717 $line->rowid = $objp->rowid;
718 $line->fk_facture = $objp->fk_facture;
719 $line->fk_parent_line = $objp->fk_parent_line;
720 $line->desc = $objp->description;
721 $line->description = $objp->description;
722 $line->ref = $objp->product_ref;
723 $line->product_ref = $objp->product_ref;
724 $line->libelle = $objp->product_label;
725 $line->product_label = $objp->product_label;
726 $line->product_desc = $objp->product_desc;
727 $line->product_type = $objp->product_type;
728 $line->fk_product_type = $objp->fk_product_type;
729 $line->qty = $objp->qty;
730 $line->subprice = $objp->subprice;
732 $line->label = $objp->custom_label;
734 $line->vat_src_code = $objp->vat_src_code;
735 $line->tva_tx = $objp->tva_tx;
736 $line->localtax1_tx = $objp->localtax1_tx;
737 $line->localtax2_tx = $objp->localtax2_tx;
738 $line->localtax1_type = $objp->localtax1_type;
739 $line->localtax2_type = $objp->localtax2_type;
740 $line->remise_percent = $objp->remise_percent;
742 $line->fk_product = $objp->fk_product;
743 $line->date_start_fill = $objp->date_start_fill;
744 $line->date_end_fill = $objp->date_end_fill;
745 $line->info_bits = $objp->info_bits;
746 $line->total_ht = $objp->total_ht;
747 $line->total_tva = $objp->total_tva;
748 $line->total_ttc = $objp->total_ttc;
750 $line->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
751 $line->fk_fournprice = $objp->fk_product_fournisseur_price;
753 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $objp->fk_product_fournisseur_price, $objp->pa_ht);
755 $line->buyprice = $marginInfos[0];
756 $line->pa_ht = $marginInfos[0];
757 $line->marge_tx = $marginInfos[1];
758 $line->marque_tx = $marginInfos[2];
759 $line->rang = $objp->rang;
760 $line->special_code = $objp->special_code;
761 $line->fk_unit = $objp->fk_unit;
762 $line->fk_contract_line = $objp->fk_contract_line;
765 $line->price = $objp->price;
766 $line->remise = $objp->remise;
768 $line->fetch_optionals();
771 $line->fk_multicurrency = $objp->fk_multicurrency;
772 $line->multicurrency_code = $objp->multicurrency_code;
773 $line->multicurrency_subprice = $objp->multicurrency_subprice;
774 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
775 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
776 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
778 $this->lines[$i] = $line;
783 $this->db->free($result);
786 $this->error = $this->db->lasterror();
800 public function delete(
User $user, $notrigger = 0, $idwarehouse = -1)
804 dol_syslog(get_class($this).
"::delete rowid=".((
int) $rowid), LOG_DEBUG);
809 $main = MAIN_DB_PREFIX.
'facturedet_rec';
810 $ef = $main.
"_extrafields";
812 $sqlef =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_facture = ".((int) $rowid).
")";
813 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"facturedet_rec WHERE fk_facture = ".((int) $rowid);
815 if ($this->db->query($sqlef) && $this->db->query($sql)) {
816 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"facture_rec WHERE rowid = ".((int) $rowid);
818 if ($this->db->query($sql)) {
830 $this->error = $this->db->lasterror();
834 $this->error = $this->db->lasterror();
837 if (!$error && !$notrigger) {
849 $this->db->rollback();
883 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)
889 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);
890 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
902 if (preg_match(
'/\((.*)\)/', (
string) $txtva, $reg)) {
903 $vat_src_code = $reg[1];
904 $txtva = preg_replace(
'/\s*\(.*\)/',
'', (
string) $txtva);
909 $remise_percent =
price2num($remise_percent);
910 if (empty($remise_percent)) {
916 if (!preg_match(
'/\((.*)\)/', $txtva)) {
924 if (empty($txlocaltax1)) {
927 if (empty($txlocaltax2)) {
930 if (empty($info_bits)) {
934 if ($price_base_type ==
'HT') {
945 $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);
946 $total_ht = $tabprice[0];
947 $total_tva = $tabprice[1];
948 $total_ttc = $tabprice[2];
949 $total_localtax1 = $tabprice[9];
950 $total_localtax2 = $tabprice[10];
951 $pu_ht = $tabprice[3];
954 $multicurrency_total_ht = $tabprice[16];
955 $multicurrency_total_tva = $tabprice[17];
956 $multicurrency_total_ttc = $tabprice[18];
957 $pu_ht_devise = $tabprice[19];
959 $product_type = $type;
961 $product =
new Product($this->db);
962 $result = $product->fetch($fk_product);
963 $product_type = $product->type;
966 if (empty($fk_parent_line) || $fk_parent_line < 0) {
972 if ($ranktouse == -1) {
974 $ranktouse = $rangmax + 1;
977 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facturedet_rec (";
978 $sql .=
"fk_facture";
979 $sql .=
", fk_parent_line";
981 $sql .=
", description";
985 $sql .=
", vat_src_code";
986 $sql .=
", localtax1_tx";
987 $sql .=
", localtax1_type";
988 $sql .=
", localtax2_tx";
989 $sql .=
", localtax2_type";
990 $sql .=
", fk_product";
991 $sql .=
", product_type";
992 $sql .=
", remise_percent";
993 $sql .=
", subprice";
995 $sql .=
", total_ht";
996 $sql .=
", total_tva";
997 $sql .=
", total_localtax1";
998 $sql .=
", total_localtax2";
999 $sql .=
", total_ttc";
1000 $sql .=
", date_start_fill";
1001 $sql .=
", date_end_fill";
1002 $sql .=
", fk_product_fournisseur_price";
1003 $sql .=
", buy_price_ht";
1004 $sql .=
", info_bits";
1006 $sql .=
", special_code";
1007 $sql .=
", fk_unit";
1008 $sql .=
', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
1009 $sql .=
") VALUES (";
1010 $sql .=
" ".((int) $facid);
1011 $sql .=
", ".($fk_parent_line > 0 ? ((int) $fk_parent_line) :
"null");
1012 $sql .=
", ".(!empty($label) ?
"'".$this->db->escape($label).
"'" :
"null");
1013 $sql .=
", '".$this->db->escape($desc).
"'";
1014 $sql .=
", ".price2num($pu_ht);
1015 $sql .=
", ".price2num($qty);
1016 $sql .=
", ".price2num($txtva);
1017 $sql .=
", '".$this->db->escape($vat_src_code).
"'";
1018 $sql .=
", ".price2num($txlocaltax1);
1019 $sql .=
", '".$this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] :
'').
"'";
1020 $sql .=
", ".price2num($txlocaltax2);
1021 $sql .=
", '".$this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] :
'').
"'";
1022 $sql .=
", ".(!empty($fk_product) ?
"'".$this->db->escape($fk_product).
"'" :
"null");
1023 $sql .=
", ".((int) $product_type);
1024 $sql .=
", ".price2num($remise_percent);
1025 $sql .=
", ".price2num($pu_ht);
1027 $sql .=
", ".price2num($total_ht);
1028 $sql .=
", ".price2num($total_tva);
1029 $sql .=
", ".price2num($total_localtax1);
1030 $sql .=
", ".price2num($total_localtax2);
1031 $sql .=
", ".price2num($total_ttc);
1032 $sql .=
", ".(int) $date_start_fill;
1033 $sql .=
", ".(int) $date_end_fill;
1034 $sql .=
", ".($fk_fournprice > 0 ? $fk_fournprice :
'null');
1035 $sql .=
", ".($pa_ht ?
price2num($pa_ht) : 0);
1036 $sql .=
", ".((int) $info_bits);
1037 $sql .=
", ".((int) $ranktouse);
1038 $sql .=
", ".((int) $special_code);
1039 $sql .=
", ".($fk_unit ? ((int) $fk_unit) :
"null");
1040 $sql .=
", ".(int) $this->fk_multicurrency;
1041 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1042 $sql .=
", ".price2num($pu_ht_devise,
'CU');
1043 $sql .=
", ".price2num($multicurrency_total_ht,
'CT');
1044 $sql .=
", ".price2num($multicurrency_total_tva,
'CT');
1045 $sql .=
", ".price2num($multicurrency_total_ttc,
'CT');
1048 dol_syslog(get_class($this).
"::addline", LOG_DEBUG);
1049 if ($this->db->query($sql)) {
1050 $lineId = $this->db->last_insert_id(MAIN_DB_PREFIX.
"facturedet_rec");
1055 $this->error = $this->db->lasterror();
1090 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)
1096 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);
1097 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1100 if (empty($remise_percent)) {
1101 $remise_percent = 0;
1110 $remise_percent =
price2num($remise_percent);
1112 if (empty($info_bits)) {
1117 $pu_ht_devise =
price2num($pu_ht_devise);
1118 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
1123 if (empty($txlocaltax1)) {
1126 if (empty($txlocaltax2)) {
1130 if (empty($this->multicurrency_subprice)) {
1131 $this->multicurrency_subprice = 0;
1133 if (empty($this->multicurrency_total_ht)) {
1134 $this->multicurrency_total_ht = 0;
1136 if (empty($this->multicurrency_total_tva)) {
1137 $this->multicurrency_total_tva = 0;
1139 if (empty($this->multicurrency_total_ttc)) {
1140 $this->multicurrency_total_ttc = 0;
1143 if ($price_base_type ==
'HT') {
1158 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
1159 $vat_src_code = $reg[1];
1160 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
1163 $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);
1165 $total_ht = $tabprice[0];
1166 $total_tva = $tabprice[1];
1167 $total_ttc = $tabprice[2];
1168 $total_localtax1 = $tabprice[9];
1169 $total_localtax2 = $tabprice[10];
1170 $pu_ht = $tabprice[3];
1171 $pu_tva = $tabprice[4];
1172 $pu_ttc = $tabprice[5];
1175 $multicurrency_total_ht = $tabprice[16];
1176 $multicurrency_total_tva = $tabprice[17];
1177 $multicurrency_total_ttc = $tabprice[18];
1178 $pu_ht_devise = $tabprice[19];
1180 $product_type = $type;
1182 $product =
new Product($this->db);
1183 $result = $product->fetch($fk_product);
1184 $product_type = $product->type;
1187 if (empty($fk_parent_line) || $fk_parent_line < 0) {
1188 $fk_parent_line = 0;
1191 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet_rec SET ";
1192 $sql .=
"fk_facture = ".((int) $facid);
1193 $sql .=
", fk_parent_line = ".($fk_parent_line > 0 ? ((int) $fk_parent_line) :
"null");
1194 $sql .=
", label=".(!empty($label) ?
"'".$this->db->escape($label).
"'" :
"null");
1195 $sql .=
", description='".$this->db->escape($desc).
"'";
1196 $sql .=
", price=".price2num($pu_ht);
1197 $sql .=
", qty=".price2num($qty);
1198 $sql .=
", tva_tx=".price2num($txtva);
1199 $sql .=
", vat_src_code='".$this->db->escape($vat_src_code).
"'";
1200 $sql .=
", localtax1_tx=".((float) $txlocaltax1);
1201 $sql .=
", localtax1_type='".$this->db->escape($localtaxes_type[0]).
"'";
1202 $sql .=
", localtax2_tx=".((float) $txlocaltax2);
1203 $sql .=
", localtax2_type='".$this->db->escape($localtaxes_type[2]).
"'";
1204 $sql .=
", fk_product=".(!empty($fk_product) ?
"'".$this->db->escape($fk_product).
"'" :
"null");
1205 $sql .=
", product_type=".((int) $product_type);
1206 $sql .=
", remise_percent='".price2num($remise_percent).
"'";
1207 $sql .=
", subprice='".price2num($pu_ht).
"'";
1208 $sql .=
", total_ht='".price2num($total_ht).
"'";
1209 $sql .=
", total_tva='".price2num($total_tva).
"'";
1210 $sql .=
", total_localtax1='".price2num($total_localtax1).
"'";
1211 $sql .=
", total_localtax2='".price2num($total_localtax2).
"'";
1212 $sql .=
", total_ttc='".price2num($total_ttc).
"'";
1213 $sql .=
", date_start_fill=".((int) $date_start_fill);
1214 $sql .=
", date_end_fill=".((int) $date_end_fill);
1215 $sql .=
", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice :
'null');
1216 $sql .=
", buy_price_ht=".($pa_ht ?
price2num($pa_ht) : 0);
1217 $sql .=
", info_bits=".((int) $info_bits);
1218 $sql .=
", rang=".((int) $rang);
1219 $sql .=
", special_code=".((int) $special_code);
1220 $sql .=
", fk_unit=".($fk_unit ?
"'".$this->db->escape($fk_unit).
"'" :
"null");
1221 $sql .=
', multicurrency_subprice = '.price2num($pu_ht_devise);
1222 $sql .=
', multicurrency_total_ht = '.price2num($multicurrency_total_ht);
1223 $sql .=
', multicurrency_total_tva = '.price2num($multicurrency_total_tva);
1224 $sql .=
', multicurrency_total_ttc = '.price2num($multicurrency_total_ttc);
1225 $sql .=
" WHERE rowid = ".((int) $rowid);
1227 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
1228 if ($this->db->query($sql)) {
1233 $this->error = $this->db->lasterror();
1246 if (empty($this->date_when)) {
1260 if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) {
1290 global $conf, $langs, $db, $user, $hookmanager;
1296 $langs->loadLangs(array(
"main",
"bills"));
1300 $today =
dol_mktime(23, 59, 59, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year']);
1304 dol_syslog(
"createRecurringInvoices restrictioninvoiceid=".$restrictioninvoiceid.
" forcevalidation=".$forcevalidation);
1306 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'facture_rec';
1307 $sql .=
' WHERE frequency > 0';
1308 $sql .=
" AND (date_when IS NULL OR date_when <= '".$this->db->idate($today).
"')";
1309 $sql .=
' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
1310 $sql .=
' AND suspended = 0';
1311 $sql .=
' AND entity = '.$conf->entity;
1312 if ($restrictioninvoiceid > 0) {
1313 $sql .=
' AND rowid = '.((int) $restrictioninvoiceid);
1315 $sql .= $this->db->order(
'entity',
'ASC');
1317 $parameters = array(
1318 'restrictioninvoiceid' => $restrictioninvoiceid,
1319 'forcevalidation' => $forcevalidation,
1321 $reshook = $hookmanager->executeHooks(
'beforeCreationOfRecurringInvoices', $parameters, $sql);
1323 $resql = $this->db->query($sql);
1326 $num = $this->db->num_rows($resql);
1329 $this->output .= $langs->trans(
"FoundXQualifiedRecurringInvoiceTemplate", $num).
"\n";
1331 $this->output .= $langs->trans(
"NoQualifiedRecurringInvoiceTemplateFound");
1334 $saventity = $conf->entity;
1337 $line = $this->db->fetch_object($resql);
1341 $invoiceidgenerated = 0;
1345 $facturerec->fetch($line->rowid);
1347 if ($facturerec->id > 0) {
1349 $conf->entity = $facturerec->entity;
1351 dol_syslog(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref.
", entity=".$facturerec->entity);
1353 $facture =
new Facture($this->db);
1354 $facture->fac_rec = $facturerec->id;
1355 $facture->fk_fac_rec_source = $facturerec->id;
1358 $facture->subtype = $facturerec->subtype;
1361 $facture->date = (empty($facturerec->date_when) ? $now : $facturerec->date_when);
1362 $facture->socid = $facturerec->socid;
1363 if (!empty($facturerec->fk_multicurrency)) {
1364 $facture->fk_multicurrency = $facturerec->fk_multicurrency;
1365 $facture->multicurrency_code = $facturerec->multicurrency_code;
1366 $facture->multicurrency_tx = $facturerec->multicurrency_tx;
1369 $invoiceidgenerated = $facture->create($user);
1370 if ($invoiceidgenerated <= 0) {
1371 $this->errors = $facture->errors;
1372 $this->error = $facture->error;
1377 if (!$error && ($facturerec->auto_validate || $forcevalidation)) {
1378 $result = $facture->validate($user);
1380 $this->errors = $facture->errors;
1381 $this->error = $facture->error;
1385 if (!$error && $facturerec->generate_pdf) {
1387 $facture->fetch($facture->id);
1388 $result = $facture->generateDocument($facturerec->model_pdf, $langs);
1390 $this->errors = $facture->errors;
1391 $this->error = $facture->error;
1397 $this->error =
"Failed to load invoice template with id=".$line->rowid.
", entity=".$conf->entity.
"\n";
1398 $this->errors[] =
"Failed to load invoice template with id=".$line->rowid.
", entity=".$conf->entity;
1399 dol_syslog(
"createRecurringInvoices Failed to load invoice template with id=".$line->rowid.
", entity=".$conf->entity);
1402 if (!$error && $invoiceidgenerated >= 0) {
1403 $this->db->commit(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref);
1404 dol_syslog(
"createRecurringInvoices Process invoice template ".$facturerec->ref.
" is finished with a success generation");
1406 $this->output .= $langs->trans(
"InvoiceGeneratedFromTemplate", $facture->ref, $facturerec->ref).
"\n";
1408 $this->db->rollback(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref);
1411 $parameters = array(
1414 'errorCount' => $error,
1415 'invoiceidgenerated' => $invoiceidgenerated,
1416 'facturerec' => $facturerec,
1419 $reshook = $hookmanager->executeHooks(
'afterCreationOfRecurringInvoice', $parameters, $facture);
1424 $conf->entity = $saventity;
1429 $this->output = trim($this->output);
1431 return $error ? $error : 0;
1446 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'', $notooltip = 0, $save_lastsearch_value = -1)
1448 global $langs, $hookmanager;
1452 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"RepeatableInvoice").
'</u>';
1453 if (!empty($this->
ref)) {
1454 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1456 if ($this->frequency > 0) {
1457 $label .=
'<br><b>'.$langs->trans(
'Frequency').
':</b> '.$langs->trans(
'FrequencyPer_'.$this->unit_frequency, $this->frequency);
1459 if (!empty($this->date_last_gen)) {
1460 $label .=
'<br><b>'.$langs->trans(
'DateLastGeneration').
':</b> '.
dol_print_date($this->date_last_gen,
'dayhour');
1462 if ($this->frequency > 0) {
1463 if (!empty($this->date_when)) {
1464 $label .=
'<br><b>'.$langs->trans(
'NextDateToExecution').
':</b> ';
1465 $label .= (empty($this->suspended) ?
'' :
'<strike>').
dol_print_date($this->date_when,
'day').(empty($this->suspended) ?
'' :
'</strike>');
1466 if (!empty($this->suspended)) {
1467 $label .=
' ('.$langs->trans(
"Disabled").
')';
1472 $url = DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$this->id;
1478 if ($option !=
'nolink') {
1480 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1481 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1482 $add_save_lastsearch_values = 1;
1484 if ($add_save_lastsearch_values) {
1485 $url .=
'&save_lastsearch_values=1';
1489 $linkstart =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
1492 $result .= $linkstart;
1494 $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);
1496 if ($withpicto != 2) {
1499 $result .= $linkend;
1501 $hookmanager->initHooks(array($this->element .
'dao'));
1502 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1503 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1505 $result = $hookmanager->resPrint;
1507 $result .= $hookmanager->resPrint;
1521 return $this->
LibStatut($this->frequency ? 1 : 0, $this->suspended, $mode, $alreadypaid, empty($this->
type) ? 0 : $this->type);
1535 public function LibStatut($recur, $status, $mode = 0, $alreadypaid = -1, $type = 0)
1539 $langs->load(
'bills');
1541 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1542 $statusType =
'status0';
1547 if ($status == self::STATUS_SUSPENDED) {
1548 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1550 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1553 if ($status == self::STATUS_SUSPENDED) {
1554 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1556 $labelStatus = $langs->transnoentitiesnoconv(
"Draft");
1559 } elseif ($mode == 1) {
1562 if ($status == self::STATUS_SUSPENDED) {
1563 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1565 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1568 if ($status == self::STATUS_SUSPENDED) {
1569 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1571 $labelStatus = $langs->transnoentitiesnoconv(
"Draft");
1574 } elseif ($mode == 2) {
1576 if ($status == self::STATUS_SUSPENDED) {
1577 $statusType =
'status6';
1578 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1580 $statusType =
'status4';
1581 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1584 if ($status == self::STATUS_SUSPENDED) {
1585 $statusType =
'status6';
1586 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1588 $statusType =
'status0';
1589 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1592 } elseif ($mode == 3) {
1595 if ($status == self::STATUS_SUSPENDED) {
1596 $statusType =
'status6';
1597 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1599 $statusType =
'status4';
1600 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1603 if ($status == self::STATUS_SUSPENDED) {
1604 $statusType =
'status6';
1605 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1607 $statusType =
'status0';
1608 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1611 } elseif ($mode == 4) {
1614 if ($status == self::STATUS_SUSPENDED) {
1615 $statusType =
'status6';
1616 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1618 $statusType =
'status4';
1619 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1622 if ($status == self::STATUS_SUSPENDED) {
1623 $statusType =
'status6';
1624 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1626 $statusType =
'status0';
1627 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1630 } elseif ($mode == 5 || $mode == 6) {
1636 if ($status == self::STATUS_SUSPENDED) {
1637 $statusType =
'status6';
1638 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1640 $statusType =
'status4';
1641 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1644 if ($status == self::STATUS_SUSPENDED) {
1645 $statusType =
'status6';
1646 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1648 $statusType =
'status0';
1649 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1654 $labelStatusShort = $labelStatus;
1656 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1680 $sql =
'SELECT c.rowid, datec, tms as datem,';
1681 $sql .=
' fk_user_author, fk_user_modif';
1682 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as c';
1683 $sql .=
' WHERE c.rowid = '.((int) $id);
1685 $result = $this->db->query($sql);
1687 if ($this->db->num_rows($result)) {
1688 $obj = $this->db->fetch_object($result);
1690 $this->
id = $obj->rowid;
1692 $this->user_creation_id = $obj->fk_user_author;
1693 $this->user_modification_id = $obj->fk_user_modif;
1694 $this->date_creation = $this->db->jdate($obj->datec);
1695 $this->date_modification = $this->db->jdate($obj->datem);
1697 $this->db->free($result);
1717 $nownotime =
dol_mktime(0, 0, 0, $arraynow[
'mon'], $arraynow[
'mday'], $arraynow[
'year']);
1723 $sql =
"SELECT rowid";
1724 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
1725 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
1726 $sql .= $this->db->plimit(100);
1728 $resql = $this->db->query($sql);
1730 $num_prods = $this->db->num_rows($resql);
1732 while ($i < $num_prods) {
1734 $row = $this->db->fetch_row($resql);
1735 $prodids[$i] = $row[0];
1741 $this->
ref =
'SPECIMEN';
1742 $this->title =
'SPECIMEN';
1743 $this->specimen = 1;
1745 $this->date = $nownotime;
1746 $this->date_lim_reglement = $nownotime + 3600 * 24 * 30;
1747 $this->cond_reglement_id = 1;
1748 $this->cond_reglement_code =
'RECEP';
1750 $this->mode_reglement_id = 0;
1751 $this->mode_reglement_code =
'';
1752 $this->note_public =
'This is a comment (public)';
1753 $this->note_private =
'This is a comment (private)';
1754 $this->note =
'This is a comment (private)';
1755 $this->fk_incoterms = 0;
1756 $this->location_incoterms =
'';
1758 if (empty($option) || $option !=
'nolines') {
1762 while ($xnbp < $nbp) {
1764 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1766 $line->subprice = 100;
1767 $line->tva_tx = 19.6;
1768 $line->localtax1_tx = 0;
1769 $line->localtax2_tx = 0;
1770 $line->remise_percent = 0;
1772 $prodid = mt_rand(1, $num_prods);
1773 $line->fk_product = $prodids[$prodid];
1775 $line->total_ht = -100;
1776 $line->total_ttc = -119.6;
1777 $line->total_tva = -19.6;
1778 } elseif ($xnbp == 2) {
1779 $line->subprice = -100;
1780 $line->total_ht = -100;
1781 $line->total_ttc = -119.6;
1782 $line->total_tva = -19.6;
1783 $line->remise_percent = 0;
1784 } elseif ($xnbp == 3) {
1785 $prodid = mt_rand(1, $num_prods);
1786 $line->fk_product = $prodids[$prodid];
1787 $line->total_ht = 50;
1788 $line->total_ttc = 59.8;
1789 $line->total_tva = 9.8;
1790 $line->remise_percent = 50;
1792 $prodid = mt_rand(1, $num_prods);
1793 $line->fk_product = $prodids[$prodid];
1794 $line->total_ht = 100;
1795 $line->total_ttc = 119.6;
1796 $line->total_tva = 19.6;
1797 $line->remise_percent = 00;
1800 $this->lines[$xnbp] = $line;
1803 $this->total_ht += $line->total_ht;
1804 $this->total_tva += $line->total_tva;
1805 $this->total_ttc += $line->total_ttc;
1807 $this->revenuestamp = 0;
1811 $line->desc = $langs->trans(
"Description").
" (offered line)";
1813 $line->subprice = 100;
1814 $line->tva_tx = 19.6;
1815 $line->localtax1_tx = 0;
1816 $line->localtax2_tx = 0;
1817 $line->remise_percent = 100;
1818 $line->total_ht = 0;
1819 $line->total_ttc = 0;
1820 $line->total_tva = 0;
1821 $prodid = mt_rand(1, $num_prods);
1822 $line->fk_product = $prodids[$prodid];
1824 $this->lines[$xnbp] = $line;
1828 $this->usenewprice = 0;
1879 if (!$this->table_element) {
1880 dol_syslog(get_class($this).
"::setFrequencyAndUnit was called on object with property table_element not defined", LOG_ERR);
1884 if (!empty($frequency) && empty($unit)) {
1885 dol_syslog(get_class($this).
"::setFrequencyAndUnit was called on object with params frequency defined but unit not defined", LOG_ERR);
1889 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1890 $sql .=
' SET frequency = '.($frequency ? $this->db->escape($frequency) :
'null');
1891 if (!empty($unit)) {
1892 $sql .=
', unit_frequency = \''.$this->db->escape($unit).
'\'';
1894 $sql .=
" WHERE rowid = ".((int) $this->
id);
1896 dol_syslog(get_class($this).
"::setFrequencyAndUnit", LOG_DEBUG);
1897 if ($this->db->query($sql)) {
1898 $this->frequency = $frequency;
1899 if (!empty($unit)) {
1900 $this->unit_frequency = $unit;
1905 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
1927 public function setNextDate($date, $increment_nb_gen_done = 0, $notrigger = 0)
1931 if (!$this->table_element) {
1932 dol_syslog(get_class($this).
"::setNextDate was called on object with property table_element not defined", LOG_ERR);
1935 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1936 $sql .=
" SET date_when = ".($date ?
"'".$this->db->idate($date).
"'" :
"null");
1937 if ($increment_nb_gen_done > 0) {
1938 $sql .=
', nb_gen_done = nb_gen_done + 1';
1940 $sql .=
" WHERE rowid = ".((int) $this->
id);
1942 dol_syslog(get_class($this).
"::setNextDate", LOG_DEBUG);
1943 if ($this->db->query($sql)) {
1944 $this->date_when = $date;
1945 if ($increment_nb_gen_done > 0) {
1946 $this->nb_gen_done++;
1951 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
1975 if (!$this->table_element) {
1976 dol_syslog(get_class($this).
"::setMaxPeriod was called on object with property table_element not defined", LOG_ERR);
1984 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1985 $sql .=
' SET nb_gen_max = '.((int) $nb);
1986 $sql .=
" WHERE rowid = ".((int) $this->
id);
1988 dol_syslog(get_class($this).
"::setMaxPeriod", LOG_DEBUG);
1989 if ($this->db->query($sql)) {
1990 $this->nb_gen_max = $nb;
1994 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2019 if (!$this->table_element) {
2020 dol_syslog(get_class($this).
"::setAutoValidate was called on object with property table_element not defined", LOG_ERR);
2024 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2025 $sql .=
' SET auto_validate = '.((int) $validate);
2026 $sql .=
" WHERE rowid = ".((int) $this->
id);
2028 dol_syslog(get_class($this).
"::setAutoValidate", LOG_DEBUG);
2029 if ($this->db->query($sql)) {
2030 $this->auto_validate = $validate;
2034 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2059 if (!$this->table_element) {
2060 dol_syslog(get_class($this).
"::setGeneratePdf was called on object with property table_element not defined", LOG_ERR);
2064 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2065 $sql .=
' SET generate_pdf = '.((int) $validate);
2066 $sql .=
" WHERE rowid = ".((int) $this->
id);
2068 dol_syslog(get_class($this).
"::setGeneratePdf", LOG_DEBUG);
2069 if ($this->db->query($sql)) {
2070 $this->generate_pdf = $validate;
2074 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2098 if (!$this->table_element) {
2099 dol_syslog(get_class($this).
"::setModelPdf was called on object with property table_element not defined", LOG_ERR);
2103 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2104 $sql .=
" SET modelpdf = '".$this->db->escape($model).
"'";
2105 $sql .=
" WHERE rowid = ".((int) $this->
id);
2107 dol_syslog(get_class($this).
"::setModelPdf", LOG_DEBUG);
2108 if ($this->db->query($sql)) {
2109 $this->model_pdf = $model;
2113 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2139 public $element =
'facturedetrec';
2144 public $table_element =
'facturedet_rec';
2162 public $fk_product_fournisseur_price;
2163 public $fk_fournprice;
2169 public $description;
2171 public $fk_product_type;
2173 public $fk_contract_line;
2183 public function delete(
User $user, $notrigger = 0)
2192 $result = $this->
call_trigger(
'LINEBILLREC_DELETE', $user);
2208 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
' WHERE rowid='.((int) $this->
id);
2210 $res = $this->db->query($sql);
2213 $this->errors[] = $this->db->lasterror();
2219 $this->db->rollback();
2222 $this->db->commit();
2236 $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,';
2237 $sql .=
' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
2238 $sql .=
' l.date_start_fill, l.date_end_fill, l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
2239 $sql .=
' l.rang, l.special_code,';
2240 $sql .=
' l.fk_unit, l.fk_contract_line,';
2241 $sql .=
' l.import_key, l.fk_multicurrency,';
2242 $sql .=
' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
2243 $sql .=
' l.buy_price_ht, l.fk_product_fournisseur_price,';
2244 $sql .=
' l.fk_user_author, l.fk_user_modif,';
2245 $sql .=
' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
2246 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facturedet_rec as l';
2247 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
2248 $sql .=
' WHERE l.rowid = '.((int) $rowid);
2249 $sql .=
' ORDER BY l.rang';
2252 $result = $this->db->query($sql);
2254 $objp = $this->db->fetch_object($result);
2256 $this->
id = $objp->rowid;
2257 $this->fk_facture = $objp->fk_facture;
2258 $this->fk_parent_line = $objp->fk_parent_line;
2259 $this->label = $objp->custom_label;
2260 $this->desc = $objp->description;
2262 $this->product_type = $objp->product_type;
2263 $this->
ref = $objp->product_ref;
2264 $this->product_ref = $objp->product_ref;
2265 $this->libelle = $objp->product_label;
2266 $this->product_label = $objp->product_label;
2267 $this->product_desc = $objp->product_desc;
2268 $this->fk_product_type = $objp->fk_product_type;
2269 $this->qty = $objp->qty;
2270 $this->
price = $objp->price;
2271 $this->subprice = $objp->subprice;
2272 $this->vat_src_code = $objp->vat_src_code;
2273 $this->tva_tx = $objp->tva_tx;
2274 $this->localtax1_tx = $objp->localtax1_tx;
2275 $this->localtax2_tx = $objp->localtax2_tx;
2276 $this->localtax1_type = $objp->localtax1_type;
2277 $this->localtax2_type = $objp->localtax2_type;
2278 $this->remise_percent = $objp->remise_percent;
2280 $this->fk_product = $objp->fk_product;
2281 $this->date_start_fill = $objp->date_start_fill;
2282 $this->date_end_fill = $objp->date_end_fill;
2283 $this->info_bits = $objp->info_bits;
2284 $this->total_ht = $objp->total_ht;
2285 $this->total_tva = $objp->total_tva;
2286 $this->total_ttc = $objp->total_ttc;
2288 $this->rang = $objp->rang;
2289 $this->special_code = $objp->special_code;
2290 $this->fk_unit = $objp->fk_unit;
2291 $this->fk_contract_line = $objp->fk_contract_line;
2292 $this->import_key = $objp->import_key;
2293 $this->fk_multicurrency = $objp->fk_multicurrency;
2294 $this->multicurrency_code = $objp->multicurrency_code;
2295 $this->multicurrency_subprice = $objp->multicurrency_subprice;
2296 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
2297 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
2298 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2300 $this->buy_price_ht = $objp->buy_price_ht;
2302 $this->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
2303 $this->fk_user_author = $objp->fk_user_author;
2304 $this->fk_user_modif = $objp->fk_user_modif;
2306 $this->db->free($result);
2309 $this->error = $this->db->lasterror();
2329 if (empty($this->fk_parent_line)) {
2330 $this->fk_parent_line = 0;
2333 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2335 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet_rec SET";
2336 $sql .=
" fk_facture = ".((int) $this->fk_facture);
2337 $sql .=
", fk_parent_line=".($this->fk_parent_line > 0 ? $this->fk_parent_line :
"null");
2338 $sql .=
", label=".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null");
2339 $sql .=
", description='".$this->db->escape($this->desc).
"'";
2340 $sql .=
", price=".price2num($this->
price);
2341 $sql .=
", qty=".price2num($this->qty);
2342 $sql .=
", tva_tx=".price2num($this->tva_tx);
2343 $sql .=
", vat_src_code='".$this->db->escape($this->vat_src_code).
"'";
2344 $sql .=
", localtax1_tx=".price2num($this->localtax1_tx);
2345 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
2346 $sql .=
", localtax2_tx=".price2num($this->localtax2_tx);
2347 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
2348 $sql .=
", fk_product=".($this->fk_product > 0 ? $this->fk_product :
"null");
2349 $sql .=
", product_type=".((int) $this->product_type);
2350 $sql .=
", remise_percent=".price2num($this->remise_percent);
2351 $sql .=
", subprice=".price2num($this->subprice);
2352 $sql .=
", info_bits=".price2num($this->info_bits);
2353 $sql .=
", date_start_fill=".(int) $this->date_start_fill;
2354 $sql .=
", date_end_fill=".(int) $this->date_end_fill;
2355 if (empty($this->skip_update_total)) {
2356 $sql .=
", total_ht=".price2num($this->total_ht);
2357 $sql .=
", total_tva=".price2num($this->total_tva);
2358 $sql .=
", total_localtax1=".price2num($this->total_localtax1);
2359 $sql .=
", total_localtax2=".price2num($this->total_localtax2);
2360 $sql .=
", total_ttc=".price2num($this->total_ttc);
2362 $sql .=
", rang=".((int) $this->rang);
2363 $sql .=
", special_code=".((int) $this->special_code);
2364 $sql .=
", fk_unit=".($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
"null");
2365 $sql .=
", fk_contract_line=".($this->fk_contract_line ? $this->fk_contract_line :
"null");
2366 $sql .=
" WHERE rowid = ".((int) $this->
id);
2370 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
2372 $resql = $this->db->query($sql);
2381 if (!$error && !$notrigger) {
2383 $result = $this->
call_trigger(
'LINEBILLREC_MODIFY', $user);
2391 $this->db->rollback();
2394 $this->db->commit();
2398 $this->error = $this->db->lasterror();
2399 $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...
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.
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 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)
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).
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.
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