32require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
43 const TRIGGER_PREFIX =
'BILLREC';
47 public $element =
'facturerec';
52 public $table_element =
'facture_rec';
57 public $table_element_line =
'facturedet_rec';
62 public $fk_element =
'fk_facture';
67 public $picto =
'bill';
93 public $multicurrency_subprice;
113 public $date_last_gen;
128 public $unit_frequency;
131 public $special_code;
133 public $usenewprice = 0;
135 public $date_lim_reglement;
136 public $cond_reglement_code;
137 public $mode_reglement_code;
141 public $auto_validate;
142 public $generate_pdf;
173 public $fields = array(
174 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
175 'titre' =>array(
'type'=>
'varchar(100)',
'label'=>
'Titre',
'enabled'=>1,
'showoncombobox' => 1,
'visible'=>-1,
'position'=>15),
176 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>20,
'index'=>1),
177 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>
'isModEnabled("societe")',
'visible'=>-1,
'notnull'=>1,
'position'=>25),
178 'subtype' =>array(
'type'=>
'smallint(6)',
'label'=>
'InvoiceSubtype',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>30),
179 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>35),
180 'total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'Tva',
'enabled'=>1,
'visible'=>-1,
'position'=>55,
'isameasure'=>1),
181 'localtax1' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax1',
'enabled'=>1,
'visible'=>-1,
'position'=>60,
'isameasure'=>1),
182 'localtax2' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax2',
'enabled'=>1,
'visible'=>-1,
'position'=>65,
'isameasure'=>1),
183 'total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'Total',
'enabled'=>1,
'visible'=>-1,
'position'=>70,
'isameasure'=>1),
184 'total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'Total ttc',
'enabled'=>1,
'visible'=>-1,
'position'=>75,
'isameasure'=>1),
185 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
186 '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),
187 'fk_cond_reglement' =>array(
'type'=>
'integer',
'label'=>
'Fk cond reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
188 'fk_mode_reglement' =>array(
'type'=>
'integer',
'label'=>
'Fk mode reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
189 'date_lim_reglement' =>array(
'type'=>
'date',
'label'=>
'Date lim reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
190 'note_private' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>105),
191 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>110),
192 'modelpdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Modelpdf',
'enabled'=>1,
'visible'=>-1,
'position'=>115),
193 'date_when' =>array(
'type'=>
'datetime',
'label'=>
'Date when',
'enabled'=>1,
'visible'=>-1,
'position'=>130),
194 'date_last_gen' =>array(
'type'=>
'datetime',
'label'=>
'Date last gen',
'enabled'=>1,
'visible'=>-1,
'position'=>135),
195 'nb_gen_done' =>array(
'type'=>
'integer',
'label'=>
'Nb gen done',
'enabled'=>1,
'visible'=>-1,
'position'=>140),
196 'nb_gen_max' =>array(
'type'=>
'integer',
'label'=>
'Nb gen max',
'enabled'=>1,
'visible'=>-1,
'position'=>145),
197 'frequency' =>array(
'type'=>
'integer',
'label'=>
'Frequency',
'enabled'=>1,
'visible'=>-1,
'position'=>150),
198 'unit_frequency' =>array(
'type'=>
'varchar(2)',
'label'=>
'UnitFrequency',
'enabled'=>1,
'visible'=>-1,
'position'=>152),
199 'usenewprice' =>array(
'type'=>
'integer',
'label'=>
'UseNewPrice',
'enabled'=>1,
'visible'=>0,
'position'=>155),
200 'revenuestamp' =>array(
'type'=>
'double(24,8)',
'label'=>
'RevenueStamp',
'enabled'=>1,
'visible'=>-1,
'position'=>160,
'isameasure'=>1),
201 'auto_validate' =>array(
'type'=>
'integer',
'label'=>
'Auto validate',
'enabled'=>1,
'visible'=>-1,
'position'=>165),
202 'generate_pdf' =>array(
'type'=>
'integer',
'label'=>
'Generate pdf',
'enabled'=>1,
'visible'=>-1,
'position'=>170),
203 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'Fk account',
'enabled'=>
'isModEnabled("banque")',
'visible'=>-1,
'position'=>175),
204 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'Fk multicurrency',
'enabled'=>1,
'visible'=>-1,
'position'=>180),
205 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'Multicurrency code',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
206 'multicurrency_tx' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency tx',
'enabled'=>1,
'visible'=>-1,
'position'=>190,
'isameasure'=>1),
207 'multicurrency_total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total ht',
'enabled'=>1,
'visible'=>-1,
'position'=>195,
'isameasure'=>1),
208 'multicurrency_total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total tva',
'enabled'=>1,
'visible'=>-1,
'position'=>200,
'isameasure'=>1),
209 'multicurrency_total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total ttc',
'enabled'=>1,
'visible'=>-1,
'position'=>205,
'isameasure'=>1),
210 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>210),
211 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>215),
212 'suspended' =>array(
'type'=>
'integer',
'label'=>
'Suspended',
'enabled'=>1,
'visible'=>-1,
'position'=>225),
216 const STATUS_NOTSUSPENDED = 0;
217 const STATUS_SUSPENDED = 1;
240 public function create($user, $facid, $notrigger = 0, $onlylines = array())
248 $this->titre = trim(isset($this->titre) ? $this->titre : $this->title);
249 $this->title = trim($this->title);
250 $this->usenewprice = empty($this->usenewprice) ? 0 : $this->usenewprice;
251 if (empty($this->suspended)) {
252 $this->suspended = 0;
256 if (empty($this->frequency)) {
257 $this->frequency = 0;
258 $this->date_when =
null;
261 $this->frequency = abs($this->frequency);
262 $this->nb_gen_done = 0;
263 $this->nb_gen_max = empty($this->nb_gen_max) ? 0 : $this->nb_gen_max;
264 $this->auto_validate = empty($this->auto_validate) ? 0 : $this->auto_validate;
265 $this->generate_pdf = empty($this->generate_pdf) ? 0 : $this->generate_pdf;
270 $facsrc =
new Facture($this->db);
271 $result = $facsrc->fetch($facid);
273 $this->socid = $facsrc->socid;
275 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facture_rec (";
283 $sql .=
", note_private";
284 $sql .=
", note_public";
285 $sql .=
", modelpdf";
286 $sql .=
", fk_user_author";
287 $sql .=
", fk_projet";
288 $sql .=
", fk_account";
289 $sql .=
", fk_cond_reglement";
290 $sql .=
", fk_mode_reglement";
291 $sql .=
", usenewprice";
292 $sql .=
", frequency";
293 $sql .=
", unit_frequency";
294 $sql .=
", date_when";
295 $sql .=
", date_last_gen";
296 $sql .=
", nb_gen_done";
297 $sql .=
", nb_gen_max";
298 $sql .=
", auto_validate";
299 $sql .=
", generate_pdf";
300 $sql .=
", fk_multicurrency";
301 $sql .=
", multicurrency_code";
302 $sql .=
", multicurrency_tx";
303 $sql .=
", suspended";
304 $sql .=
") VALUES (";
305 $sql .=
"'".$this->db->escape($this->titre ? $this->titre : $this->title).
"'";
306 $sql .=
", ".((int) $this->socid);
307 $sql .=
", ".($this->subtype ?
"'".$this->db->escape($this->subtype).
"'" :
"null");
308 $sql .=
", ".((int) $conf->entity);
309 $sql .=
", '".$this->db->idate($now).
"'";
310 $sql .=
", ".(!empty($facsrc->total_ttc) ? ((float) $facsrc->total_ttc) :
'0');
312 $sql .=
", ".(!empty($this->note_private) ? (
"'".$this->db->escape($this->note_private).
"'") :
"NULL");
313 $sql .=
", ".(!empty($this->note_public) ? (
"'".$this->db->escape($this->note_public).
"'") :
"NULL");
314 $sql .=
", ".(!empty($this->model_pdf) ? (
"'".$this->db->escape($this->model_pdf).
"'") :
"NULL");
315 $sql .=
", ".((int) $user->id);
316 $sql .=
", ".(!empty($this->fk_project) ? ((int) $this->fk_project) :
"null");
317 $sql .=
", ".(!empty($facsrc->fk_account) ? ((int) $facsrc->fk_account) :
"null");
318 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
"null");
319 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
"null");
320 $sql .=
", ".((int) $this->usenewprice);
321 $sql .=
", ".((int) $this->frequency);
322 $sql .=
", '".$this->db->escape($this->unit_frequency).
"'";
323 $sql .=
", ".(!empty($this->date_when) ?
"'".$this->db->idate($this->date_when).
"'" :
'NULL');
324 $sql .=
", ".(!empty($this->date_last_gen) ?
"'".$this->db->idate($this->date_last_gen).
"'" :
'NULL');
325 $sql .=
", ".((int) $this->nb_gen_done);
326 $sql .=
", ".((int) $this->nb_gen_max);
327 $sql .=
", ".((int) $this->auto_validate);
328 $sql .=
", ".((int) $this->generate_pdf);
329 $sql .=
", ".((int) $facsrc->fk_multicurrency);
330 $sql .=
", '".$this->db->escape($facsrc->multicurrency_code).
"'";
331 $sql .=
", ".((float) $facsrc->multicurrency_tx);
332 $sql .=
", ".((int) $this->suspended);
335 if ($this->db->query($sql)) {
336 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"facture_rec");
339 $this->fk_multicurrency = $facsrc->fk_multicurrency;
340 $this->multicurrency_code = $facsrc->multicurrency_code;
341 $this->multicurrency_tx = $facsrc->multicurrency_tx;
346 $num = count($facsrc->lines);
347 for ($i = 0; $i < $num; $i++) {
348 if (!empty($onlylines) && !in_array($facsrc->lines[$i]->id, $onlylines)) {
353 if (($facsrc->lines[$i]->product_type != 9 && empty($facsrc->lines[$i]->fk_parent_line)) || $facsrc->lines[$i]->product_type == 9) {
357 $tva_tx = $facsrc->lines[$i]->tva_tx;
358 if (!empty($facsrc->lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
359 $tva_tx .=
' ('.$facsrc->lines[$i]->vat_src_code.
')';
362 $default_start_fill =
getDolGlobalInt(
'INVOICEREC_SET_AUTOFILL_DATE_START');
363 $default_end_fill =
getDolGlobalInt(
'INVOICEREC_SET_AUTOFILL_DATE_END');
365 $result_insert = $this->
addline(
366 $facsrc->lines[$i]->desc,
367 $facsrc->lines[$i]->subprice,
368 $facsrc->lines[$i]->qty,
370 $facsrc->lines[$i]->localtax1_tx,
371 $facsrc->lines[$i]->localtax2_tx,
372 $facsrc->lines[$i]->fk_product,
373 $facsrc->lines[$i]->remise_percent,
375 $facsrc->lines[$i]->info_bits,
378 $facsrc->lines[$i]->product_type,
379 $facsrc->lines[$i]->rang,
380 $facsrc->lines[$i]->special_code,
381 $facsrc->lines[$i]->label,
382 $facsrc->lines[$i]->fk_unit,
383 $facsrc->lines[$i]->multicurrency_subprice,
387 $facsrc->lines[$i]->pa_ht,
392 if ($result_insert > 0 && $facsrc->lines[$i]->product_type == 9) {
393 $fk_parent_line = $result_insert;
396 if ($result_insert < 0) {
401 $result2 = $objectline->fetch($result_insert);
404 if (method_exists($facsrc->lines[$i],
'fetch_optionals')) {
405 $facsrc->lines[$i]->fetch_optionals($facsrc->lines[$i]->id);
406 $objectline->array_options = $facsrc->lines[$i]->array_options;
409 $result = $objectline->insertExtraFields();
413 } elseif ($result2 < 0) {
414 $this->errors[] = $objectline->error;
420 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
421 $this->linked_objects = $this->linkedObjectsIds;
425 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
426 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
427 if (is_array($tmp_origin_id)) {
428 foreach ($tmp_origin_id as $origin_id) {
431 $this->error = $this->db->lasterror();
436 $origin_id = $tmp_origin_id;
439 $this->error = $this->db->lasterror();
453 if (!$error && !$notrigger) {
457 $this->db->rollback();
464 $this->db->rollback();
471 $this->error = $this->db->lasterror();
472 $this->db->rollback();
476 $this->db->rollback();
493 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_rec SET";
494 $sql .=
" entity = ".((int) $this->entity).
",";
495 $sql .=
" titre = '".$this->db->escape($this->title).
"',";
496 $sql .=
" suspended = ".((int) $this->suspended).
",";
497 $sql .=
" fk_soc = ".((int) $this->socid).
",";
498 $sql .=
" total_tva = ".((float) $this->total_tva).
",";
499 $sql .=
" localtax1 = ".((float) $this->total_localtax1).
",";
500 $sql .=
" localtax2 = ".((float) $this->total_localtax2).
",";
501 $sql .=
" total_ht = ".((float) $this->total_ht).
",";
502 $sql .=
" total_ttc = ".((float) $this->total_ttc);
504 $sql .=
" WHERE rowid = ".((int) $this->
id);
508 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
510 $resql = $this->db->query($sql);
519 if (!$error && !$notrigger) {
523 $this->db->rollback();
531 $this->error = $this->db->lasterror();
532 $this->db->rollback();
547 public function fetch($rowid, $ref =
'', $ref_ext =
'', $noextrafields = 0, $nolines = 0)
551 $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';
552 $sql .=
', f.date_lim_reglement as dlr';
553 $sql .=
', f.note_private, f.note_public, f.fk_user_author';
554 $sql .=
', f.modelpdf as model_pdf';
555 $sql .=
', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet as fk_project';
556 $sql .=
', f.fk_account';
557 $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';
558 $sql .=
', f.generate_pdf';
559 $sql .=
", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
560 $sql .=
', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
561 $sql .=
', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
563 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as f';
564 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
565 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as p ON f.fk_mode_reglement = p.id';
567 $sql .=
' WHERE f.entity IN ('.getEntity(
'invoice').
')';
569 $sql .=
' AND f.rowid = '.((int) $rowid);
571 $sql .=
" AND f.titre = '".$this->db->escape($ref).
"'";
573 $sql .=
' AND f.rowid = 0';
579 $result = $this->db->query($sql);
581 if ($this->db->num_rows($result)) {
582 $obj = $this->db->fetch_object($result);
584 $this->
id = $obj->rowid;
585 $this->entity = $obj->entity;
586 $this->titre = $obj->title;
587 $this->title = $obj->title;
588 $this->
ref = $obj->title;
589 $this->subtype = $obj->subtype;
590 $this->suspended = $obj->suspended;
591 $this->total_ht = $obj->total_ht;
592 $this->total_tva = $obj->total_tva;
593 $this->total_localtax1 = $obj->localtax1;
594 $this->total_localtax2 = $obj->localtax2;
595 $this->total_ttc = $obj->total_ttc;
596 $this->socid = $obj->fk_soc;
597 $this->date_lim_reglement = $this->db->jdate($obj->dlr);
598 $this->mode_reglement_id = $obj->fk_mode_reglement;
599 $this->mode_reglement_code = $obj->mode_reglement_code;
600 $this->mode_reglement = $obj->mode_reglement_libelle;
601 $this->cond_reglement_id = $obj->fk_cond_reglement;
602 $this->cond_reglement_code = $obj->cond_reglement_code;
603 $this->cond_reglement = $obj->cond_reglement_libelle;
604 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
605 $this->fk_project = $obj->fk_project;
606 $this->fk_account = $obj->fk_account;
607 $this->note_private = $obj->note_private;
608 $this->note_public = $obj->note_public;
609 $this->user_author = $obj->fk_user_author;
610 $this->model_pdf = $obj->model_pdf;
612 $this->frequency = $obj->frequency;
613 $this->unit_frequency = $obj->unit_frequency;
614 $this->date_when = $this->db->jdate($obj->date_when);
615 $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
616 $this->nb_gen_done = $obj->nb_gen_done;
617 $this->nb_gen_max = $obj->nb_gen_max;
618 $this->usenewprice = $obj->usenewprice;
619 $this->auto_validate = $obj->auto_validate;
620 $this->generate_pdf = $obj->generate_pdf;
623 $this->fk_multicurrency = $obj->fk_multicurrency;
624 $this->multicurrency_code = $obj->multicurrency_code;
625 $this->multicurrency_tx = $obj->multicurrency_tx;
626 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
627 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
628 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
632 if (empty($noextrafields)) {
635 $this->error = $this->db->lasterror();
641 if (empty($nolines)) {
644 $this->error = $this->db->lasterror();
651 $this->error =
'Bill with id '.$rowid.
' or ref '.$ref.
' not found';
652 dol_syslog(
'Facture::Fetch Error '.$this->error, LOG_ERR);
656 $this->error = $this->db->error();
683 $this->lines = array();
685 dol_syslog(
'FactureRec::fetch_lines', LOG_DEBUG);
687 $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, ';
688 $sql .=
' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
689 $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,';
690 $sql .=
' l.rang, l.special_code,';
691 $sql .=
' l.fk_unit, l.fk_contract_line,';
692 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
693 $sql .=
' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
694 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facturedet_rec as l';
695 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
696 $sql .=
' WHERE l.fk_facture = '.((int) $this->
id);
697 $sql .=
' ORDER BY l.rang';
699 $result = $this->db->query($sql);
701 $num = $this->db->num_rows($result);
704 $objp = $this->db->fetch_object($result);
707 $line->id = $objp->rowid;
708 $line->rowid = $objp->rowid;
709 $line->fk_facture = $objp->fk_facture;
710 $line->fk_parent_line = $objp->fk_parent_line;
711 $line->desc = $objp->description;
712 $line->description = $objp->description;
713 $line->ref = $objp->product_ref;
714 $line->product_ref = $objp->product_ref;
715 $line->libelle = $objp->product_label;
716 $line->product_label = $objp->product_label;
717 $line->product_desc = $objp->product_desc;
718 $line->product_type = $objp->product_type;
719 $line->fk_product_type = $objp->fk_product_type;
720 $line->qty = $objp->qty;
721 $line->subprice = $objp->subprice;
723 $line->label = $objp->custom_label;
725 $line->vat_src_code = $objp->vat_src_code;
726 $line->tva_tx = $objp->tva_tx;
727 $line->localtax1_tx = $objp->localtax1_tx;
728 $line->localtax2_tx = $objp->localtax2_tx;
729 $line->localtax1_type = $objp->localtax1_type;
730 $line->localtax2_type = $objp->localtax2_type;
731 $line->remise_percent = $objp->remise_percent;
733 $line->fk_product = $objp->fk_product;
734 $line->date_start_fill = $objp->date_start_fill;
735 $line->date_end_fill = $objp->date_end_fill;
736 $line->info_bits = $objp->info_bits;
737 $line->total_ht = $objp->total_ht;
738 $line->total_tva = $objp->total_tva;
739 $line->total_ttc = $objp->total_ttc;
741 $line->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
742 $line->fk_fournprice = $objp->fk_product_fournisseur_price;
744 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $objp->fk_product_fournisseur_price, $objp->pa_ht);
746 $line->buyprice = $marginInfos[0];
747 $line->pa_ht = $marginInfos[0];
748 $line->marge_tx = $marginInfos[1];
749 $line->marque_tx = $marginInfos[2];
750 $line->rang = $objp->rang;
751 $line->special_code = $objp->special_code;
752 $line->fk_unit = $objp->fk_unit;
753 $line->fk_contract_line = $objp->fk_contract_line;
756 $line->price = $objp->price;
757 $line->remise = $objp->remise;
759 $line->fetch_optionals();
762 $line->fk_multicurrency = $objp->fk_multicurrency;
763 $line->multicurrency_code = $objp->multicurrency_code;
764 $line->multicurrency_subprice = $objp->multicurrency_subprice;
765 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
766 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
767 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
769 $this->lines[$i] = $line;
774 $this->db->free($result);
777 $this->error = $this->db->lasterror();
791 public function delete(
User $user, $notrigger = 0, $idwarehouse = -1)
795 dol_syslog(get_class($this).
"::delete rowid=".((
int) $rowid), LOG_DEBUG);
800 $main = MAIN_DB_PREFIX.
'facturedet_rec';
801 $ef = $main.
"_extrafields";
803 $sqlef =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_facture = ".((int) $rowid).
")";
804 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"facturedet_rec WHERE fk_facture = ".((int) $rowid);
806 if ($this->db->query($sqlef) && $this->db->query($sql)) {
807 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"facture_rec WHERE rowid = ".((int) $rowid);
809 if ($this->db->query($sql)) {
821 $this->error = $this->db->lasterror();
825 $this->error = $this->db->lasterror();
828 if (!$error && !$notrigger) {
840 $this->db->rollback();
874 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)
880 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);
881 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
893 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
894 $vat_src_code = $reg[1];
895 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
900 $remise_percent =
price2num($remise_percent);
901 if (empty($remise_percent)) {
907 if (!preg_match(
'/\((.*)\)/', $txtva)) {
915 if (empty($txlocaltax1)) {
918 if (empty($txlocaltax2)) {
921 if (empty($info_bits)) {
925 if ($price_base_type ==
'HT') {
936 $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);
937 $total_ht = $tabprice[0];
938 $total_tva = $tabprice[1];
939 $total_ttc = $tabprice[2];
940 $total_localtax1 = $tabprice[9];
941 $total_localtax2 = $tabprice[10];
942 $pu_ht = $tabprice[3];
945 $multicurrency_total_ht = $tabprice[16];
946 $multicurrency_total_tva = $tabprice[17];
947 $multicurrency_total_ttc = $tabprice[18];
948 $pu_ht_devise = $tabprice[19];
950 $product_type = $type;
952 $product =
new Product($this->db);
953 $result = $product->fetch($fk_product);
954 $product_type = $product->type;
957 if (empty($fk_parent_line) || $fk_parent_line < 0) {
963 if ($ranktouse == -1) {
965 $ranktouse = $rangmax + 1;
968 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facturedet_rec (";
969 $sql .=
"fk_facture";
970 $sql .=
", fk_parent_line";
972 $sql .=
", description";
976 $sql .=
", vat_src_code";
977 $sql .=
", localtax1_tx";
978 $sql .=
", localtax1_type";
979 $sql .=
", localtax2_tx";
980 $sql .=
", localtax2_type";
981 $sql .=
", fk_product";
982 $sql .=
", product_type";
983 $sql .=
", remise_percent";
984 $sql .=
", subprice";
986 $sql .=
", total_ht";
987 $sql .=
", total_tva";
988 $sql .=
", total_localtax1";
989 $sql .=
", total_localtax2";
990 $sql .=
", total_ttc";
991 $sql .=
", date_start_fill";
992 $sql .=
", date_end_fill";
993 $sql .=
", fk_product_fournisseur_price";
994 $sql .=
", buy_price_ht";
995 $sql .=
", info_bits";
997 $sql .=
", special_code";
999 $sql .=
', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
1000 $sql .=
") VALUES (";
1001 $sql .=
" ".((int) $facid);
1002 $sql .=
", ".($fk_parent_line > 0 ? ((int) $fk_parent_line) :
"null");
1003 $sql .=
", ".(!empty($label) ?
"'".$this->db->escape($label).
"'" :
"null");
1004 $sql .=
", '".$this->db->escape($desc).
"'";
1005 $sql .=
", ".price2num($pu_ht);
1006 $sql .=
", ".price2num($qty);
1007 $sql .=
", ".price2num($txtva);
1008 $sql .=
", '".$this->db->escape($vat_src_code).
"'";
1009 $sql .=
", ".price2num($txlocaltax1);
1010 $sql .=
", '".$this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] :
'').
"'";
1011 $sql .=
", ".price2num($txlocaltax2);
1012 $sql .=
", '".$this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] :
'').
"'";
1013 $sql .=
", ".(!empty($fk_product) ?
"'".$this->db->escape($fk_product).
"'" :
"null");
1014 $sql .=
", ".((int) $product_type);
1015 $sql .=
", ".price2num($remise_percent);
1016 $sql .=
", ".price2num($pu_ht);
1018 $sql .=
", ".price2num($total_ht);
1019 $sql .=
", ".price2num($total_tva);
1020 $sql .=
", ".price2num($total_localtax1);
1021 $sql .=
", ".price2num($total_localtax2);
1022 $sql .=
", ".price2num($total_ttc);
1023 $sql .=
", ".(int) $date_start_fill;
1024 $sql .=
", ".(int) $date_end_fill;
1025 $sql .=
", ".($fk_fournprice > 0 ? $fk_fournprice :
'null');
1026 $sql .=
", ".($pa_ht ?
price2num($pa_ht) : 0);
1027 $sql .=
", ".((int) $info_bits);
1028 $sql .=
", ".((int) $ranktouse);
1029 $sql .=
", ".((int) $special_code);
1030 $sql .=
", ".($fk_unit ? ((int) $fk_unit) :
"null");
1031 $sql .=
", ".(int) $this->fk_multicurrency;
1032 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1033 $sql .=
", ".price2num($pu_ht_devise,
'CU');
1034 $sql .=
", ".price2num($multicurrency_total_ht,
'CT');
1035 $sql .=
", ".price2num($multicurrency_total_tva,
'CT');
1036 $sql .=
", ".price2num($multicurrency_total_ttc,
'CT');
1039 dol_syslog(get_class($this).
"::addline", LOG_DEBUG);
1040 if ($this->db->query($sql)) {
1041 $lineId = $this->db->last_insert_id(MAIN_DB_PREFIX.
"facturedet_rec");
1046 $this->error = $this->db->lasterror();
1081 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)
1087 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);
1088 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1091 if (empty($remise_percent)) {
1092 $remise_percent = 0;
1101 $remise_percent =
price2num($remise_percent);
1103 if (empty($info_bits)) {
1108 $pu_ht_devise =
price2num($pu_ht_devise);
1109 if (!preg_match(
'/\((.*)\)/', $txtva)) {
1114 if (empty($txlocaltax1)) {
1117 if (empty($txlocaltax2)) {
1121 if (empty($this->multicurrency_subprice)) {
1122 $this->multicurrency_subprice = 0;
1124 if (empty($this->multicurrency_total_ht)) {
1125 $this->multicurrency_total_ht = 0;
1127 if (empty($this->multicurrency_total_tva)) {
1128 $this->multicurrency_total_tva = 0;
1130 if (empty($this->multicurrency_total_ttc)) {
1131 $this->multicurrency_total_ttc = 0;
1134 if ($price_base_type ==
'HT') {
1149 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
1150 $vat_src_code = $reg[1];
1151 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
1154 $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);
1156 $total_ht = $tabprice[0];
1157 $total_tva = $tabprice[1];
1158 $total_ttc = $tabprice[2];
1159 $total_localtax1 = $tabprice[9];
1160 $total_localtax2 = $tabprice[10];
1161 $pu_ht = $tabprice[3];
1162 $pu_tva = $tabprice[4];
1163 $pu_ttc = $tabprice[5];
1166 $multicurrency_total_ht = $tabprice[16];
1167 $multicurrency_total_tva = $tabprice[17];
1168 $multicurrency_total_ttc = $tabprice[18];
1169 $pu_ht_devise = $tabprice[19];
1171 $product_type = $type;
1173 $product =
new Product($this->db);
1174 $result = $product->fetch($fk_product);
1175 $product_type = $product->type;
1178 if (empty($fk_parent_line) || $fk_parent_line < 0) {
1179 $fk_parent_line = 0;
1182 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet_rec SET ";
1183 $sql .=
"fk_facture = ".((int) $facid);
1184 $sql .=
", fk_parent_line = ".($fk_parent_line > 0 ? ((int) $fk_parent_line) :
"null");
1185 $sql .=
", label=".(!empty($label) ?
"'".$this->db->escape($label).
"'" :
"null");
1186 $sql .=
", description='".$this->db->escape($desc).
"'";
1187 $sql .=
", price=".price2num($pu_ht);
1188 $sql .=
", qty=".price2num($qty);
1189 $sql .=
", tva_tx=".price2num($txtva);
1190 $sql .=
", vat_src_code='".$this->db->escape($vat_src_code).
"'";
1191 $sql .=
", localtax1_tx=".((float) $txlocaltax1);
1192 $sql .=
", localtax1_type='".$this->db->escape($localtaxes_type[0]).
"'";
1193 $sql .=
", localtax2_tx=".((float) $txlocaltax2);
1194 $sql .=
", localtax2_type='".$this->db->escape($localtaxes_type[2]).
"'";
1195 $sql .=
", fk_product=".(!empty($fk_product) ?
"'".$this->db->escape($fk_product).
"'" :
"null");
1196 $sql .=
", product_type=".((int) $product_type);
1197 $sql .=
", remise_percent='".price2num($remise_percent).
"'";
1198 $sql .=
", subprice='".price2num($pu_ht).
"'";
1199 $sql .=
", total_ht='".price2num($total_ht).
"'";
1200 $sql .=
", total_tva='".price2num($total_tva).
"'";
1201 $sql .=
", total_localtax1='".price2num($total_localtax1).
"'";
1202 $sql .=
", total_localtax2='".price2num($total_localtax2).
"'";
1203 $sql .=
", total_ttc='".price2num($total_ttc).
"'";
1204 $sql .=
", date_start_fill=".((int) $date_start_fill);
1205 $sql .=
", date_end_fill=".((int) $date_end_fill);
1206 $sql .=
", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice :
'null');
1207 $sql .=
", buy_price_ht=".($pa_ht ?
price2num($pa_ht) : 0);
1208 $sql .=
", info_bits=".((int) $info_bits);
1209 $sql .=
", rang=".((int) $rang);
1210 $sql .=
", special_code=".((int) $special_code);
1211 $sql .=
", fk_unit=".($fk_unit ?
"'".$this->db->escape($fk_unit).
"'" :
"null");
1212 $sql .=
', multicurrency_subprice = '.price2num($pu_ht_devise);
1213 $sql .=
', multicurrency_total_ht = '.price2num($multicurrency_total_ht);
1214 $sql .=
', multicurrency_total_tva = '.price2num($multicurrency_total_tva);
1215 $sql .=
', multicurrency_total_ttc = '.price2num($multicurrency_total_ttc);
1216 $sql .=
" WHERE rowid = ".((int) $rowid);
1218 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
1219 if ($this->db->query($sql)) {
1224 $this->error = $this->db->lasterror();
1237 if (empty($this->date_when)) {
1251 if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) {
1266 return ($this->
isMaxNbGenReached() ?
'<strike>' :
'').$ret.($this->isMaxNbGenReached() ?
'</strike>' :
'');
1282 global $conf, $langs, $db, $user, $hookmanager;
1288 $langs->loadLangs(array(
"main",
"bills"));
1292 $today =
dol_mktime(23, 59, 59, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year']);
1294 $this->output =
null;
1296 dol_syslog(
"createRecurringInvoices restrictioninvoiceid=".$restrictioninvoiceid.
" forcevalidation=".$forcevalidation);
1298 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'facture_rec';
1299 $sql .=
' WHERE frequency > 0';
1300 $sql .=
" AND (date_when IS NULL OR date_when <= '".$this->db->idate($today).
"')";
1301 $sql .=
' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
1302 $sql .=
' AND suspended = 0';
1303 $sql .=
' AND entity = '.$conf->entity;
1304 if ($restrictioninvoiceid > 0) {
1305 $sql .=
' AND rowid = '.((int) $restrictioninvoiceid);
1307 $sql .= $this->db->order(
'entity',
'ASC');
1309 $parameters = array(
1310 'restrictioninvoiceid' => $restrictioninvoiceid,
1311 'forcevalidation' => $forcevalidation,
1313 $reshook = $hookmanager->executeHooks(
'beforeCreationOfRecurringInvoices', $parameters, $sql);
1315 $resql = $this->db->query($sql);
1318 $num = $this->db->num_rows($resql);
1321 $this->output .= $langs->trans(
"FoundXQualifiedRecurringInvoiceTemplate", $num).
"\n";
1323 $this->output .= $langs->trans(
"NoQualifiedRecurringInvoiceTemplateFound");
1326 $saventity = $conf->entity;
1329 $line = $this->db->fetch_object($resql);
1333 $invoiceidgenerated = 0;
1337 $facturerec->fetch($line->rowid);
1339 if ($facturerec->id > 0) {
1341 $conf->entity = $facturerec->entity;
1343 dol_syslog(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref.
", entity=".$facturerec->entity);
1345 $facture =
new Facture($this->db);
1346 $facture->fac_rec = $facturerec->id;
1347 $facture->fk_fac_rec_source = $facturerec->id;
1350 $facture->subtype = $facturerec->subtype;
1353 $facture->date = (empty($facturerec->date_when) ? $now : $facturerec->date_when);
1354 $facture->socid = $facturerec->socid;
1355 if (!empty($facturerec->fk_multicurrency)) {
1356 $facture->fk_multicurrency = $facturerec->fk_multicurrency;
1357 $facture->multicurrency_code = $facturerec->multicurrency_code;
1358 $facture->multicurrency_tx = $facturerec->multicurrency_tx;
1361 if (isset($facture->array_options) && isset($facturerec->array_options)) {
1362 foreach ($facturerec->array_options as $key => $value) {
1363 if (isset($facture->array_options[$key])) {
1364 $facture->array_options[$key] = $value;
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;
1395 if (!$error && !$notrigger) {
1397 $result = $facturerec->call_trigger(
'BILLREC_CREATEBILL', $user);
1399 $this->errors = $facturerec->errors;
1400 $this->error = $facturerec->error;
1407 $this->error =
"Failed to load invoice template with id=".$line->rowid.
", entity=".$conf->entity.
"\n";
1408 $this->errors[] =
"Failed to load invoice template with id=".$line->rowid.
", entity=".$conf->entity;
1409 dol_syslog(
"createRecurringInvoices Failed to load invoice template with id=".$line->rowid.
", entity=".$conf->entity);
1412 if (!$error && $invoiceidgenerated >= 0) {
1413 $this->db->commit(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref);
1414 dol_syslog(
"createRecurringInvoices Process invoice template ".$facturerec->ref.
" is finished with a success generation");
1416 $this->output .= $langs->trans(
"InvoiceGeneratedFromTemplate", $facture->ref, $facturerec->ref).
"\n";
1418 $this->db->rollback(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref);
1421 $parameters = array(
1424 'errorCount' => $error,
1425 'invoiceidgenerated' => $invoiceidgenerated,
1426 'facturerec' => $facturerec,
1429 $reshook = $hookmanager->executeHooks(
'afterCreationOfRecurringInvoice', $parameters, $facture);
1434 $conf->entity = $saventity;
1439 $this->output = trim($this->output);
1441 return $error ? $error : 0;
1456 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'', $notooltip = 0, $save_lastsearch_value = -1)
1458 global $langs, $hookmanager;
1462 $label =
'<u>'.$langs->trans(
"RepeatableInvoice").
'</u>';
1463 if (!empty($this->
ref)) {
1464 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1466 if ($this->frequency > 0) {
1467 $label .=
'<br><b>'.$langs->trans(
'Frequency').
':</b> '.$langs->trans(
'FrequencyPer_'.$this->unit_frequency, $this->frequency);
1469 if (!empty($this->date_last_gen)) {
1470 $label .=
'<br><b>'.$langs->trans(
'DateLastGeneration').
':</b> '.
dol_print_date($this->date_last_gen,
'dayhour');
1472 if ($this->frequency > 0) {
1473 if (!empty($this->date_when)) {
1474 $label .=
'<br><b>'.$langs->trans(
'NextDateToExecution').
':</b> ';
1475 $label .= (empty($this->suspended) ?
'' :
'<strike>').
dol_print_date($this->date_when,
'day').(empty($this->suspended) ?
'' :
'</strike>');
1476 if (!empty($this->suspended)) {
1477 $label .=
' ('.$langs->trans(
"Disabled").
')';
1482 $url = DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$this->id;
1488 if ($option !=
'nolink') {
1490 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1491 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1492 $add_save_lastsearch_values = 1;
1494 if ($add_save_lastsearch_values) {
1495 $url .=
'&save_lastsearch_values=1';
1499 $linkstart =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
1502 $result .= $linkstart;
1504 $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);
1506 if ($withpicto != 2) {
1507 $result .= $this->ref;
1509 $result .= $linkend;
1511 $hookmanager->initHooks(array($this->element .
'dao'));
1512 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1513 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1515 $result = $hookmanager->resPrint;
1517 $result .= $hookmanager->resPrint;
1531 return $this->
LibStatut($this->frequency ? 1 : 0, $this->suspended, $mode, $alreadypaid, empty($this->
type) ? 0 : $this->type);
1545 public function LibStatut($recur, $status, $mode = 0, $alreadypaid = -1, $type = 0)
1549 $langs->load(
'bills');
1551 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1552 $statusType =
'status0';
1557 if ($status == self::STATUS_SUSPENDED) {
1558 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1560 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1563 if ($status == self::STATUS_SUSPENDED) {
1564 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1566 $labelStatus = $langs->transnoentitiesnoconv(
"Draft");
1569 } elseif ($mode == 1) {
1572 if ($status == self::STATUS_SUSPENDED) {
1573 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1575 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1578 if ($status == self::STATUS_SUSPENDED) {
1579 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1581 $labelStatus = $langs->transnoentitiesnoconv(
"Draft");
1584 } elseif ($mode == 2) {
1586 if ($status == self::STATUS_SUSPENDED) {
1587 $statusType =
'status6';
1588 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1590 $statusType =
'status4';
1591 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1594 if ($status == self::STATUS_SUSPENDED) {
1595 $statusType =
'status6';
1596 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1598 $statusType =
'status0';
1599 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1602 } elseif ($mode == 3) {
1605 if ($status == self::STATUS_SUSPENDED) {
1606 $statusType =
'status6';
1607 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1609 $statusType =
'status4';
1610 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1613 if ($status == self::STATUS_SUSPENDED) {
1614 $statusType =
'status6';
1615 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1617 $statusType =
'status0';
1618 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1621 } elseif ($mode == 4) {
1624 if ($status == self::STATUS_SUSPENDED) {
1625 $statusType =
'status6';
1626 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1628 $statusType =
'status4';
1629 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1632 if ($status == self::STATUS_SUSPENDED) {
1633 $statusType =
'status6';
1634 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1636 $statusType =
'status0';
1637 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1640 } elseif ($mode == 5 || $mode == 6) {
1646 if ($status == self::STATUS_SUSPENDED) {
1647 $statusType =
'status6';
1648 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1650 $statusType =
'status4';
1651 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1654 if ($status == self::STATUS_SUSPENDED) {
1655 $statusType =
'status6';
1656 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1658 $statusType =
'status0';
1659 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1664 $labelStatusShort = $labelStatus;
1666 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1690 $sql =
'SELECT c.rowid, datec, tms as datem,';
1691 $sql .=
' fk_user_author, fk_user_modif';
1692 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as c';
1693 $sql .=
' WHERE c.rowid = '.((int) $id);
1695 $result = $this->db->query($sql);
1697 if ($this->db->num_rows($result)) {
1698 $obj = $this->db->fetch_object($result);
1700 $this->
id = $obj->rowid;
1702 $this->user_creation_id = $obj->fk_user_author;
1703 $this->user_modification_id = $obj->fk_user_modif;
1704 $this->date_creation = $this->db->jdate($obj->datec);
1705 $this->date_modification = $this->db->jdate($obj->datem);
1707 $this->db->free($result);
1727 $nownotime =
dol_mktime(0, 0, 0, $arraynow[
'mon'], $arraynow[
'mday'], $arraynow[
'year']);
1733 $sql =
"SELECT rowid";
1734 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
1735 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
1736 $sql .= $this->db->plimit(100);
1738 $resql = $this->db->query($sql);
1740 $num_prods = $this->db->num_rows($resql);
1742 while ($i < $num_prods) {
1744 $row = $this->db->fetch_row($resql);
1745 $prodids[$i] = $row[0];
1751 $this->
ref =
'SPECIMEN';
1752 $this->title =
'SPECIMEN';
1753 $this->specimen = 1;
1755 $this->date = $nownotime;
1756 $this->date_lim_reglement = $nownotime + 3600 * 24 * 30;
1757 $this->cond_reglement_id = 1;
1758 $this->cond_reglement_code =
'RECEP';
1760 $this->mode_reglement_id = 0;
1761 $this->mode_reglement_code =
'';
1762 $this->note_public =
'This is a comment (public)';
1763 $this->note_private =
'This is a comment (private)';
1764 $this->note =
'This is a comment (private)';
1765 $this->fk_incoterms = 0;
1766 $this->location_incoterms =
'';
1768 if (empty($option) || $option !=
'nolines') {
1772 while ($xnbp < $nbp) {
1774 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1776 $line->subprice = 100;
1777 $line->tva_tx = 19.6;
1778 $line->localtax1_tx = 0;
1779 $line->localtax2_tx = 0;
1780 $line->remise_percent = 0;
1782 $prodid = mt_rand(1, $num_prods);
1783 $line->fk_product = $prodids[$prodid];
1785 $line->total_ht = -100;
1786 $line->total_ttc = -119.6;
1787 $line->total_tva = -19.6;
1788 } elseif ($xnbp == 2) {
1789 $line->subprice = -100;
1790 $line->total_ht = -100;
1791 $line->total_ttc = -119.6;
1792 $line->total_tva = -19.6;
1793 $line->remise_percent = 0;
1794 } elseif ($xnbp == 3) {
1795 $prodid = mt_rand(1, $num_prods);
1796 $line->fk_product = $prodids[$prodid];
1797 $line->total_ht = 50;
1798 $line->total_ttc = 59.8;
1799 $line->total_tva = 9.8;
1800 $line->remise_percent = 50;
1802 $prodid = mt_rand(1, $num_prods);
1803 $line->fk_product = $prodids[$prodid];
1804 $line->total_ht = 100;
1805 $line->total_ttc = 119.6;
1806 $line->total_tva = 19.6;
1807 $line->remise_percent = 00;
1810 $this->lines[$xnbp] = $line;
1813 $this->total_ht += $line->total_ht;
1814 $this->total_tva += $line->total_tva;
1815 $this->total_ttc += $line->total_ttc;
1817 $this->revenuestamp = 0;
1821 $line->desc = $langs->trans(
"Description").
" (offered line)";
1823 $line->subprice = 100;
1824 $line->tva_tx = 19.6;
1825 $line->localtax1_tx = 0;
1826 $line->localtax2_tx = 0;
1827 $line->remise_percent = 100;
1828 $line->total_ht = 0;
1829 $line->total_ttc = 0;
1830 $line->total_tva = 0;
1831 $prodid = mt_rand(1, $num_prods);
1832 $line->fk_product = $prodids[$prodid];
1834 $this->lines[$xnbp] = $line;
1838 $this->usenewprice = 0;
1887 if (!$this->table_element) {
1888 dol_syslog(get_class($this).
"::setFrequencyAndUnit was called on objet with property table_element not defined", LOG_ERR);
1892 if (!empty($frequency) && empty($unit)) {
1893 dol_syslog(get_class($this).
"::setFrequencyAndUnit was called on objet with params frequency defined but unit not defined", LOG_ERR);
1897 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1898 $sql .=
' SET frequency = '.($frequency ? $this->db->escape($frequency) :
'null');
1899 if (!empty($unit)) {
1900 $sql .=
', unit_frequency = \''.$this->db->escape($unit).
'\'';
1902 $sql .=
" WHERE rowid = ".((int) $this->
id);
1904 dol_syslog(get_class($this).
"::setFrequencyAndUnit", LOG_DEBUG);
1905 if ($this->db->query($sql)) {
1906 $this->frequency = $frequency;
1907 if (!empty($unit)) {
1908 $this->unit_frequency = $unit;
1913 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
1935 public function setNextDate($date, $increment_nb_gen_done = 0, $notrigger = 0)
1939 if (!$this->table_element) {
1940 dol_syslog(get_class($this).
"::setNextDate was called on objet with property table_element not defined", LOG_ERR);
1943 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1944 $sql .=
" SET date_when = ".($date ?
"'".$this->db->idate($date).
"'" :
"null");
1945 if ($increment_nb_gen_done > 0) {
1946 $sql .=
', nb_gen_done = nb_gen_done + 1';
1948 $sql .=
" WHERE rowid = ".((int) $this->
id);
1950 dol_syslog(get_class($this).
"::setNextDate", LOG_DEBUG);
1951 if ($this->db->query($sql)) {
1952 $this->date_when = $date;
1953 if ($increment_nb_gen_done > 0) {
1954 $this->nb_gen_done++;
1959 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
1983 if (!$this->table_element) {
1984 dol_syslog(get_class($this).
"::setMaxPeriod was called on objet with property table_element not defined", LOG_ERR);
1992 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1993 $sql .=
' SET nb_gen_max = '.((int) $nb);
1994 $sql .=
" WHERE rowid = ".((int) $this->
id);
1996 dol_syslog(get_class($this).
"::setMaxPeriod", LOG_DEBUG);
1997 if ($this->db->query($sql)) {
1998 $this->nb_gen_max = $nb;
2002 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2027 if (!$this->table_element) {
2028 dol_syslog(get_class($this).
"::setAutoValidate was called on objet with property table_element not defined", LOG_ERR);
2032 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2033 $sql .=
' SET auto_validate = '.((int) $validate);
2034 $sql .=
" WHERE rowid = ".((int) $this->
id);
2036 dol_syslog(get_class($this).
"::setAutoValidate", LOG_DEBUG);
2037 if ($this->db->query($sql)) {
2038 $this->auto_validate = $validate;
2042 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2067 if (!$this->table_element) {
2068 dol_syslog(get_class($this).
"::setGeneratePdf was called on objet with property table_element not defined", LOG_ERR);
2072 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2073 $sql .=
' SET generate_pdf = '.((int) $validate);
2074 $sql .=
" WHERE rowid = ".((int) $this->
id);
2076 dol_syslog(get_class($this).
"::setGeneratePdf", LOG_DEBUG);
2077 if ($this->db->query($sql)) {
2078 $this->generate_pdf = $validate;
2082 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2106 if (!$this->table_element) {
2107 dol_syslog(get_class($this).
"::setModelPdf was called on objet with property table_element not defined", LOG_ERR);
2111 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2112 $sql .=
" SET modelpdf = '".$this->db->escape($model).
"'";
2113 $sql .=
" WHERE rowid = ".((int) $this->
id);
2115 dol_syslog(get_class($this).
"::setModelPdf", LOG_DEBUG);
2116 if ($this->db->query($sql)) {
2117 $this->model_pdf = $model;
2121 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2147 public $element =
'facturedetrec';
2152 public $table_element =
'facturedet_rec';
2160 public $fk_product_fournisseur_price;
2161 public $fk_fournprice;
2167 public $description;
2169 public $fk_product_type;
2171 public $fk_contract_line;
2181 public function delete(
User $user, $notrigger = 0)
2190 $result = $this->
call_trigger(
'LINEBILLREC_DELETE', $user);
2206 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
' WHERE rowid='.((int) $this->
id);
2208 $res = $this->db->query($sql);
2211 $this->errors[] = $this->db->lasterror();
2217 $this->db->rollback();
2220 $this->db->commit();
2234 $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,';
2235 $sql .=
' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
2236 $sql .=
' l.date_start_fill, l.date_end_fill, l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
2237 $sql .=
' l.rang, l.special_code,';
2238 $sql .=
' l.fk_unit, l.fk_contract_line,';
2239 $sql .=
' l.import_key, l.fk_multicurrency,';
2240 $sql .=
' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
2241 $sql .=
' l.buy_price_ht, l.fk_product_fournisseur_price,';
2242 $sql .=
' l.fk_user_author, l.fk_user_modif,';
2243 $sql .=
' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
2244 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facturedet_rec as l';
2245 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
2246 $sql .=
' WHERE l.rowid = '.((int) $rowid);
2247 $sql .=
' ORDER BY l.rang';
2250 $result = $this->db->query($sql);
2252 $objp = $this->db->fetch_object($result);
2254 $this->
id = $objp->rowid;
2255 $this->fk_facture = $objp->fk_facture;
2256 $this->fk_parent_line = $objp->fk_parent_line;
2257 $this->label = $objp->custom_label;
2258 $this->desc = $objp->description;
2260 $this->product_type = $objp->product_type;
2261 $this->
ref = $objp->product_ref;
2262 $this->product_ref = $objp->product_ref;
2263 $this->libelle = $objp->product_label;
2264 $this->product_label = $objp->product_label;
2265 $this->product_desc = $objp->product_desc;
2266 $this->fk_product_type = $objp->fk_product_type;
2267 $this->qty = $objp->qty;
2268 $this->
price = $objp->price;
2269 $this->subprice = $objp->subprice;
2270 $this->vat_src_code = $objp->vat_src_code;
2271 $this->tva_tx = $objp->tva_tx;
2272 $this->localtax1_tx = $objp->localtax1_tx;
2273 $this->localtax2_tx = $objp->localtax2_tx;
2274 $this->localtax1_type = $objp->localtax1_type;
2275 $this->localtax2_type = $objp->localtax2_type;
2276 $this->remise_percent = $objp->remise_percent;
2278 $this->fk_product = $objp->fk_product;
2279 $this->date_start_fill = $objp->date_start_fill;
2280 $this->date_end_fill = $objp->date_end_fill;
2281 $this->info_bits = $objp->info_bits;
2282 $this->total_ht = $objp->total_ht;
2283 $this->total_tva = $objp->total_tva;
2284 $this->total_ttc = $objp->total_ttc;
2286 $this->rang = $objp->rang;
2287 $this->special_code = $objp->special_code;
2288 $this->fk_unit = $objp->fk_unit;
2289 $this->fk_contract_line = $objp->fk_contract_line;
2290 $this->import_key = $objp->import_key;
2291 $this->fk_multicurrency = $objp->fk_multicurrency;
2292 $this->multicurrency_code = $objp->multicurrency_code;
2293 $this->multicurrency_subprice = $objp->multicurrency_subprice;
2294 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
2295 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
2296 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2298 $this->buy_price_ht = $objp->buy_price_ht;
2300 $this->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
2301 $this->fk_user_author = $objp->fk_user_author;
2302 $this->fk_user_modif = $objp->fk_user_modif;
2304 $this->db->free($result);
2307 $this->error = $this->db->lasterror();
2327 if (empty($this->fk_parent_line)) {
2328 $this->fk_parent_line = 0;
2331 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2333 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet_rec SET";
2334 $sql .=
" fk_facture = ".((int) $this->fk_facture);
2335 $sql .=
", fk_parent_line=".($this->fk_parent_line > 0 ? $this->fk_parent_line :
"null");
2336 $sql .=
", label=".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null");
2337 $sql .=
", description='".$this->db->escape($this->desc).
"'";
2338 $sql .=
", price=".price2num($this->
price);
2339 $sql .=
", qty=".price2num($this->qty);
2340 $sql .=
", tva_tx=".price2num($this->tva_tx);
2341 $sql .=
", vat_src_code='".$this->db->escape($this->vat_src_code).
"'";
2342 $sql .=
", localtax1_tx=".price2num($this->localtax1_tx);
2343 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
2344 $sql .=
", localtax2_tx=".price2num($this->localtax2_tx);
2345 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
2346 $sql .=
", fk_product=".($this->fk_product > 0 ? $this->fk_product :
"null");
2347 $sql .=
", product_type=".((int) $this->product_type);
2348 $sql .=
", remise_percent=".price2num($this->remise_percent);
2349 $sql .=
", subprice=".price2num($this->subprice);
2350 $sql .=
", info_bits=".price2num($this->info_bits);
2351 $sql .=
", date_start_fill=".(int) $this->date_start_fill;
2352 $sql .=
", date_end_fill=".(int) $this->date_end_fill;
2353 if (empty($this->skip_update_total)) {
2354 $sql .=
", total_ht=".price2num($this->total_ht);
2355 $sql .=
", total_tva=".price2num($this->total_tva);
2356 $sql .=
", total_localtax1=".price2num($this->total_localtax1);
2357 $sql .=
", total_localtax2=".price2num($this->total_localtax2);
2358 $sql .=
", total_ttc=".price2num($this->total_ttc);
2360 $sql .=
", rang=".((int) $this->rang);
2361 $sql .=
", special_code=".((int) $this->special_code);
2362 $sql .=
", fk_unit=".($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
"null");
2363 $sql .=
", fk_contract_line=".($this->fk_contract_line ? $this->fk_contract_line :
"null");
2364 $sql .=
" WHERE rowid = ".((int) $this->
id);
2368 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
2370 $resql = $this->db->query($sql);
2379 if (!$error && !$notrigger) {
2381 $result = $this->
call_trigger(
'LINEBILLREC_MODIFY', $user);
2389 $this->db->rollback();
2392 $this->db->commit();
2396 $this->error = $this->db->lasterror();
2397 $this->db->rollback();
Superclass for invoices classes.
const TYPE_STANDARD
Standard invoice.
calculate_date_lim_reglement($cond_reglement=0)
Returns an invoice payment deadline based on the invoice settlement conditions and billing date.
const STATUS_DRAFT
Draft status.
Parent class of all other business classes for details of elements (invoices, contracts,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
update_price($exclspec=0, $roundingadjust='none', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage invoices.
Class to manage invoice lines.
Class to manage invoice lines of templates.
$fk_parent_line
Id parent line.
fetch($rowid)
Get line of template invoice.
$fk_facture
From llx_facturedet_rec Id facture.
update(User $user, $notrigger=0)
Update a line to invoice_rec.
Class to manage invoice templates.
setFrequencyAndUnit($frequency, $unit, $notrigger=0)
Update frequency and unit.
getLibStatut($mode=0, $alreadypaid=-1)
Return label of object status.
addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except=0, $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise=0, $date_start_fill=0, $date_end_fill=0, $fk_fournprice=null, $pa_ht=0, $fk_parent_line=0)
Add a line to invoice.
LibStatut($recur, $status, $mode=0, $alreadypaid=-1, $type=0)
Return label of a status.
updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except=0, $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise=0, $notrigger=0, $date_start_fill=0, $date_end_fill=0, $fk_fournprice=null, $pa_ht=0, $fk_parent_line=0)
Update a line to invoice.
fetch_lines()
Get lines of template invoices into this->lines.
info($id)
Load miscellaneous information for tab "Info".
getLinesArray()
Create an array of invoice lines.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $moretitle='', $notooltip=0, $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
isMaxNbGenReached()
Return if maximum number of generation is reached.
setModelPdf($model, $notrigger=0)
Update the model for documents.
getNextNumRef($soc, $mode='next')
Return next reference of invoice not already used (or last reference)
__construct(DoliDB $db)
Constructor.
setNextDate($date, $increment_nb_gen_done=0, $notrigger=0)
Update the next date of execution.
setAutoValidate($validate, $notrigger=0)
Update the auto validate flag of invoice.
initAsSpecimen($option='')
Initialise an instance with random values.
setMaxPeriod($nb, $notrigger=0)
Update the maximum period.
update(User $user, $notrigger=0)
Update a line invoice_rec.
create($user, $facid, $notrigger=0, $onlylines=array())
Create a predefined invoice.
strikeIfMaxNbGenReached($ret)
Format string to output with by striking the string if max number of generation was reached.
fetch($rowid, $ref='', $ref_ext='', $noextrafields=0, $nolines=0)
Load object and lines.
setGeneratePdf($validate, $notrigger=0)
Update the auto generate documents.
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
getNextDate()
Return the next date of.
createRecurringInvoices($restrictioninvoiceid=0, $forcevalidation=0, $notrigger=0)
Create all recurrents invoices (for all entities if multicompany is used).
Class to manage products or services.
Class to manage Dolibarr users.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
getMarginInfos($pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $paht)
Return an array with margins information of a line.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array='', $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type