31require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
42 const TRIGGER_PREFIX =
'BILLREC';
46 public $element =
'facturerec';
51 public $table_element =
'facture_rec';
56 public $table_element_line =
'facturedet_rec';
61 public $fk_element =
'fk_facture';
66 public $picto =
'bill';
93 public $remise_absolue;
94 public $remise_percent;
108 public $date_last_gen;
123 public $unit_frequency;
126 public $special_code;
128 public $usenewprice = 0;
130 public $date_lim_reglement;
131 public $cond_reglement_code;
132 public $mode_reglement_code;
136 public $auto_validate;
137 public $generate_pdf;
174 public $fields = array(
175 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
176 'titre' =>array(
'type'=>
'varchar(100)',
'label'=>
'Titre',
'enabled'=>1,
'showoncombobox' => 1,
'visible'=>-1,
'position'=>15),
177 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>20,
'index'=>1),
178 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>
'isModEnabled("societe")',
'visible'=>-1,
'notnull'=>1,
'position'=>25),
179 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>30),
181 'remise' =>array(
'type'=>
'double',
'label'=>
'Remise',
'enabled'=>1,
'visible'=>-1,
'position'=>40),
184 'total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'Tva',
'enabled'=>1,
'visible'=>-1,
'position'=>55,
'isameasure'=>1),
185 'localtax1' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax1',
'enabled'=>1,
'visible'=>-1,
'position'=>60,
'isameasure'=>1),
186 'localtax2' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax2',
'enabled'=>1,
'visible'=>-1,
'position'=>65,
'isameasure'=>1),
187 'total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'Total',
'enabled'=>1,
'visible'=>-1,
'position'=>70,
'isameasure'=>1),
188 'total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'Total ttc',
'enabled'=>1,
'visible'=>-1,
'position'=>75,
'isameasure'=>1),
189 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
190 '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),
191 'fk_cond_reglement' =>array(
'type'=>
'integer',
'label'=>
'Fk cond reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
192 'fk_mode_reglement' =>array(
'type'=>
'integer',
'label'=>
'Fk mode reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
193 'date_lim_reglement' =>array(
'type'=>
'date',
'label'=>
'Date lim reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
194 'note_private' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>105),
195 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>110),
196 'modelpdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Modelpdf',
'enabled'=>1,
'visible'=>-1,
'position'=>115),
197 'date_when' =>array(
'type'=>
'datetime',
'label'=>
'Date when',
'enabled'=>1,
'visible'=>-1,
'position'=>130),
198 'date_last_gen' =>array(
'type'=>
'datetime',
'label'=>
'Date last gen',
'enabled'=>1,
'visible'=>-1,
'position'=>135),
199 'nb_gen_done' =>array(
'type'=>
'integer',
'label'=>
'Nb gen done',
'enabled'=>1,
'visible'=>-1,
'position'=>140),
200 'nb_gen_max' =>array(
'type'=>
'integer',
'label'=>
'Nb gen max',
'enabled'=>1,
'visible'=>-1,
'position'=>145),
201 'frequency' =>array(
'type'=>
'integer',
'label'=>
'Frequency',
'enabled'=>1,
'visible'=>-1,
'position'=>150),
202 'unit_frequency' =>array(
'type'=>
'varchar(2)',
'label'=>
'UnitFrequency',
'enabled'=>1,
'visible'=>-1,
'position'=>152),
203 'usenewprice' =>array(
'type'=>
'integer',
'label'=>
'UseNewPrice',
'enabled'=>1,
'visible'=>0,
'position'=>155),
204 'revenuestamp' =>array(
'type'=>
'double(24,8)',
'label'=>
'RevenueStamp',
'enabled'=>1,
'visible'=>-1,
'position'=>160,
'isameasure'=>1),
205 'auto_validate' =>array(
'type'=>
'integer',
'label'=>
'Auto validate',
'enabled'=>1,
'visible'=>-1,
'position'=>165),
206 'generate_pdf' =>array(
'type'=>
'integer',
'label'=>
'Generate pdf',
'enabled'=>1,
'visible'=>-1,
'position'=>170),
207 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'Fk account',
'enabled'=>
'isModEnabled("banque")',
'visible'=>-1,
'position'=>175),
208 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'Fk multicurrency',
'enabled'=>1,
'visible'=>-1,
'position'=>180),
209 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'Multicurrency code',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
210 'multicurrency_tx' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency tx',
'enabled'=>1,
'visible'=>-1,
'position'=>190,
'isameasure'=>1),
211 'multicurrency_total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total ht',
'enabled'=>1,
'visible'=>-1,
'position'=>195,
'isameasure'=>1),
212 'multicurrency_total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total tva',
'enabled'=>1,
'visible'=>-1,
'position'=>200,
'isameasure'=>1),
213 'multicurrency_total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total ttc',
'enabled'=>1,
'visible'=>-1,
'position'=>205,
'isameasure'=>1),
214 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>210),
215 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>215),
216 'suspended' =>array(
'type'=>
'integer',
'label'=>
'Suspended',
'enabled'=>1,
'visible'=>-1,
'position'=>225),
220 const STATUS_NOTSUSPENDED = 0;
221 const STATUS_SUSPENDED = 1;
243 public function create($user, $facid, $notrigger = 0)
251 $this->titre = trim(isset($this->titre) ? $this->titre : $this->title);
252 $this->title = trim($this->title);
253 $this->usenewprice = empty($this->usenewprice) ? 0 : $this->usenewprice;
254 if (empty($this->suspended)) {
255 $this->suspended = 0;
259 if (empty($this->frequency)) {
260 $this->frequency = 0;
261 $this->date_when =
null;
264 $this->frequency = abs($this->frequency);
265 $this->nb_gen_done = 0;
266 $this->nb_gen_max = empty($this->nb_gen_max) ? 0 : $this->nb_gen_max;
267 $this->auto_validate = empty($this->auto_validate) ? 0 : $this->auto_validate;
268 $this->generate_pdf = empty($this->generate_pdf) ? 0 : $this->generate_pdf;
273 $facsrc =
new Facture($this->db);
274 $result = $facsrc->fetch($facid);
277 $this->brouillon = 1;
278 $this->fk_soc = $facsrc->socid;
280 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facture_rec (";
287 $sql .=
", note_private";
288 $sql .=
", note_public";
289 $sql .=
", modelpdf";
290 $sql .=
", fk_user_author";
291 $sql .=
", fk_projet";
292 $sql .=
", fk_account";
293 $sql .=
", fk_cond_reglement";
294 $sql .=
", fk_mode_reglement";
295 $sql .=
", usenewprice";
296 $sql .=
", frequency";
297 $sql .=
", unit_frequency";
298 $sql .=
", date_when";
299 $sql .=
", date_last_gen";
300 $sql .=
", nb_gen_done";
301 $sql .=
", nb_gen_max";
302 $sql .=
", auto_validate";
303 $sql .=
", generate_pdf";
304 $sql .=
", fk_multicurrency";
305 $sql .=
", multicurrency_code";
306 $sql .=
", multicurrency_tx";
307 $sql .=
", suspended";
308 $sql .=
") VALUES (";
309 $sql .=
"'".$this->db->escape($this->titre ? $this->titre : $this->title).
"'";
310 $sql .=
", ".((int) $this->fk_soc);
311 $sql .=
", ".((int) $conf->entity);
312 $sql .=
", '".$this->db->idate($now).
"'";
313 $sql .=
", ".(!empty($facsrc->total_ttc) ? ((float) $facsrc->total_ttc) :
'0');
314 $sql .=
", ".(!empty($facsrc->remise_absolue) ? ((float) $this->remise_absolue) :
'0');
315 $sql .=
", ".(!empty($this->note_private) ? (
"'".$this->db->escape($this->note_private).
"'") :
"NULL");
316 $sql .=
", ".(!empty($this->note_public) ? (
"'".$this->db->escape($this->note_public).
"'") :
"NULL");
317 $sql .=
", ".(!empty($this->model_pdf) ? (
"'".$this->db->escape($this->model_pdf).
"'") :
"NULL");
318 $sql .=
", ".((int) $user->id);
319 $sql .=
", ".(!empty($this->fk_project) ? ((int) $this->fk_project) :
"null");
320 $sql .=
", ".(!empty($facsrc->fk_account) ? ((int) $facsrc->fk_account) :
"null");
321 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
"null");
322 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
"null");
323 $sql .=
", ".((int) $this->usenewprice);
324 $sql .=
", ".((int) $this->frequency);
325 $sql .=
", '".$this->db->escape($this->unit_frequency).
"'";
326 $sql .=
", ".(!empty($this->date_when) ?
"'".$this->db->idate($this->date_when).
"'" :
'NULL');
327 $sql .=
", ".(!empty($this->date_last_gen) ?
"'".$this->db->idate($this->date_last_gen).
"'" :
'NULL');
328 $sql .=
", ".((int) $this->nb_gen_done);
329 $sql .=
", ".((int) $this->nb_gen_max);
330 $sql .=
", ".((int) $this->auto_validate);
331 $sql .=
", ".((int) $this->generate_pdf);
332 $sql .=
", ".((int) $facsrc->fk_multicurrency);
333 $sql .=
", '".$this->db->escape($facsrc->multicurrency_code).
"'";
334 $sql .=
", ".((float) $facsrc->multicurrency_tx);
335 $sql .=
", ".((int) $this->suspended);
338 if ($this->db->query($sql)) {
339 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"facture_rec");
342 $this->fk_multicurrency = $facsrc->fk_multicurrency;
343 $this->multicurrency_code = $facsrc->multicurrency_code;
344 $this->multicurrency_tx = $facsrc->multicurrency_tx;
347 $num = count($facsrc->lines);
348 for ($i = 0; $i < $num; $i++) {
349 $tva_tx = $facsrc->lines[$i]->tva_tx;
350 if (!empty($facsrc->lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
351 $tva_tx .=
' ('.$facsrc->lines[$i]->vat_src_code.
')';
354 $default_start_fill =
getDolGlobalInt(
'INVOICEREC_SET_AUTOFILL_DATE_START');
355 $default_end_fill =
getDolGlobalInt(
'INVOICEREC_SET_AUTOFILL_DATE_END');
357 $result_insert = $this->
addline(
358 $facsrc->lines[$i]->desc,
359 $facsrc->lines[$i]->subprice,
360 $facsrc->lines[$i]->qty,
362 $facsrc->lines[$i]->localtax1_tx,
363 $facsrc->lines[$i]->localtax2_tx,
364 $facsrc->lines[$i]->fk_product,
365 $facsrc->lines[$i]->remise_percent,
367 $facsrc->lines[$i]->info_bits,
370 $facsrc->lines[$i]->product_type,
371 $facsrc->lines[$i]->rang,
372 $facsrc->lines[$i]->special_code,
373 $facsrc->lines[$i]->label,
374 $facsrc->lines[$i]->fk_unit,
375 $facsrc->lines[$i]->multicurrency_subprice,
379 $facsrc->lines[$i]->pa_ht
382 if ($result_insert < 0) {
387 $result2 = $objectline->fetch($result_insert);
390 if (method_exists($facsrc->lines[$i],
'fetch_optionals')) {
391 $facsrc->lines[$i]->fetch_optionals($facsrc->lines[$i]->id);
392 $objectline->array_options = $facsrc->lines[$i]->array_options;
395 $result = $objectline->insertExtraFields();
399 } elseif ($result2 < 0) {
400 $this->errors[] = $objectline->error;
406 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
407 $this->linked_objects = $this->linkedObjectsIds;
411 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
412 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
413 if (is_array($tmp_origin_id)) {
414 foreach ($tmp_origin_id as $origin_id) {
417 $this->error = $this->db->lasterror();
423 $origin_id = $tmp_origin_id;
426 $this->error = $this->db->lasterror();
440 if (!$error && !$notrigger) {
444 $this->db->rollback();
451 $this->db->rollback();
458 $this->error = $this->db->lasterror();
459 $this->db->rollback();
463 $this->db->rollback();
480 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_rec SET";
481 $sql .=
" entity = ".((int) $this->entity).
",";
482 $sql .=
" titre = '".$this->db->escape($this->title).
"',";
483 $sql .=
" suspended = ".((int) $this->suspended).
",";
484 $sql .=
" fk_soc = ".((int) $this->socid).
",";
485 $sql .=
" total_tva = ".((float) $this->total_tva).
",";
486 $sql .=
" localtax1 = ".((float) $this->total_localtax1).
",";
487 $sql .=
" localtax2 = ".((float) $this->total_localtax2).
",";
488 $sql .=
" total_ht = ".((float) $this->total_ht).
",";
489 $sql .=
" total_ttc = ".((float) $this->total_ttc).
",";
490 $sql .=
" remise_percent = ".((float) $this->remise_percent);
492 $sql .=
" WHERE rowid = ".((int) $this->
id);
496 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
498 $resql = $this->db->query($sql);
507 if (!$error && !$notrigger) {
511 $this->db->rollback();
519 $this->error = $this->db->lasterror();
520 $this->db->rollback();
533 public function fetch($rowid, $ref =
'', $ref_ext =
'')
537 $sql =
'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc, f.total_tva, f.localtax1, f.localtax2, f.total_ht, f.total_ttc';
538 $sql .=
', f.remise_percent, f.remise_absolue, f.remise';
539 $sql .=
', f.date_lim_reglement as dlr';
540 $sql .=
', f.note_private, f.note_public, f.fk_user_author';
541 $sql .=
', f.modelpdf as model_pdf';
542 $sql .=
', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet as fk_project';
543 $sql .=
', f.fk_account';
544 $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';
545 $sql .=
', f.generate_pdf';
546 $sql .=
", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
547 $sql .=
', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
548 $sql .=
', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
550 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as f';
551 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
552 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as p ON f.fk_mode_reglement = p.id';
554 $sql .=
' WHERE f.entity IN ('.getEntity(
'invoice').
')';
556 $sql .=
' AND f.rowid = '.((int) $rowid);
558 $sql .=
" AND f.titre = '".$this->db->escape($ref).
"'";
560 $sql .=
' AND f.rowid = 0';
566 $result = $this->db->query($sql);
568 if ($this->db->num_rows($result)) {
569 $obj = $this->db->fetch_object($result);
571 $this->
id = $obj->rowid;
572 $this->entity = $obj->entity;
573 $this->titre = $obj->title;
574 $this->title = $obj->title;
575 $this->
ref = $obj->title;
576 $this->suspended = $obj->suspended;
577 $this->remise_percent = $obj->remise_percent;
578 $this->remise_absolue = $obj->remise_absolue;
579 $this->remise = $obj->remise;
580 $this->total_ht = $obj->total_ht;
581 $this->total_tva = $obj->total_tva;
582 $this->total_localtax1 = $obj->localtax1;
583 $this->total_localtax2 = $obj->localtax2;
584 $this->total_ttc = $obj->total_ttc;
585 $this->socid = $obj->fk_soc;
586 $this->date_lim_reglement = $this->db->jdate($obj->dlr);
587 $this->mode_reglement_id = $obj->fk_mode_reglement;
588 $this->mode_reglement_code = $obj->mode_reglement_code;
589 $this->mode_reglement = $obj->mode_reglement_libelle;
590 $this->cond_reglement_id = $obj->fk_cond_reglement;
591 $this->cond_reglement_code = $obj->cond_reglement_code;
592 $this->cond_reglement = $obj->cond_reglement_libelle;
593 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
594 $this->fk_project = $obj->fk_project;
595 $this->fk_account = $obj->fk_account;
596 $this->note_private = $obj->note_private;
597 $this->note_public = $obj->note_public;
598 $this->user_author = $obj->fk_user_author;
599 $this->modelpdf = $obj->model_pdf;
600 $this->model_pdf = $obj->model_pdf;
602 $this->frequency = $obj->frequency;
603 $this->unit_frequency = $obj->unit_frequency;
604 $this->date_when = $this->db->jdate($obj->date_when);
605 $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
606 $this->nb_gen_done = $obj->nb_gen_done;
607 $this->nb_gen_max = $obj->nb_gen_max;
608 $this->usenewprice = $obj->usenewprice;
609 $this->auto_validate = $obj->auto_validate;
610 $this->generate_pdf = $obj->generate_pdf;
613 $this->fk_multicurrency = $obj->fk_multicurrency;
614 $this->multicurrency_code = $obj->multicurrency_code;
615 $this->multicurrency_tx = $obj->multicurrency_tx;
616 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
617 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
618 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
620 if ($this->
statut == self::STATUS_DRAFT) {
621 $this->brouillon = 1;
633 $this->error = $this->db->lasterror();
638 $this->error =
'Bill with id '.$rowid.
' or ref '.$ref.
' not found';
639 dol_syslog(
'Facture::Fetch Error '.$this->error, LOG_ERR);
643 $this->error = $this->db->error();
670 $this->lines = array();
672 dol_syslog(
'FactureRec::fetch_lines', LOG_DEBUG);
674 $sql =
'SELECT l.rowid, l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx, ';
675 $sql .=
' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
676 $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,';
677 $sql .=
' l.rang, l.special_code,';
678 $sql .=
' l.fk_unit, l.fk_contract_line,';
679 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
680 $sql .=
' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
681 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facturedet_rec as l';
682 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
683 $sql .=
' WHERE l.fk_facture = '.((int) $this->
id);
684 $sql .=
' ORDER BY l.rang';
686 $result = $this->db->query($sql);
688 $num = $this->db->num_rows($result);
691 $objp = $this->db->fetch_object($result);
694 $line->id = $objp->rowid;
695 $line->rowid = $objp->rowid;
696 $line->desc = $objp->description;
697 $line->description = $objp->description;
698 $line->ref = $objp->product_ref;
699 $line->product_ref = $objp->product_ref;
700 $line->libelle = $objp->product_label;
701 $line->product_label = $objp->product_label;
702 $line->product_desc = $objp->product_desc;
703 $line->product_type = $objp->product_type;
704 $line->fk_product_type = $objp->fk_product_type;
705 $line->qty = $objp->qty;
706 $line->subprice = $objp->subprice;
708 $line->label = $objp->custom_label;
710 $line->vat_src_code = $objp->vat_src_code;
711 $line->tva_tx = $objp->tva_tx;
712 $line->localtax1_tx = $objp->localtax1_tx;
713 $line->localtax2_tx = $objp->localtax2_tx;
714 $line->localtax1_type = $objp->localtax1_type;
715 $line->localtax2_type = $objp->localtax2_type;
716 $line->remise_percent = $objp->remise_percent;
718 $line->fk_product = $objp->fk_product;
719 $line->date_start_fill = $objp->date_start_fill;
720 $line->date_end_fill = $objp->date_end_fill;
721 $line->info_bits = $objp->info_bits;
722 $line->total_ht = $objp->total_ht;
723 $line->total_tva = $objp->total_tva;
724 $line->total_ttc = $objp->total_ttc;
728 $line->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
729 $line->fk_fournprice = $objp->fk_product_fournisseur_price;
731 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $objp->fk_product_fournisseur_price, $objp->pa_ht);
733 $line->buyprice = $marginInfos[0];
734 $line->pa_ht = $marginInfos[0];
735 $line->marge_tx = $marginInfos[1];
736 $line->marque_tx = $marginInfos[2];
737 $line->rang = $objp->rang;
738 $line->special_code = $objp->special_code;
739 $line->fk_unit = $objp->fk_unit;
740 $line->fk_contract_line = $objp->fk_contract_line;
743 $line->price = $objp->price;
744 $line->remise = $objp->remise;
746 $line->fetch_optionals();
749 $line->fk_multicurrency = $objp->fk_multicurrency;
750 $line->multicurrency_code = $objp->multicurrency_code;
751 $line->multicurrency_subprice = $objp->multicurrency_subprice;
752 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
753 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
754 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
756 $this->lines[$i] = $line;
761 $this->db->free($result);
764 $this->error = $this->db->lasterror();
778 public function delete(
User $user, $notrigger = 0, $idwarehouse = -1)
782 dol_syslog(get_class($this).
"::delete rowid=".((
int) $rowid), LOG_DEBUG);
787 $main = MAIN_DB_PREFIX.
'facturedet_rec';
788 $ef = $main.
"_extrafields";
790 $sqlef =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_facture = ".((int) $rowid).
")";
791 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"facturedet_rec WHERE fk_facture = ".((int) $rowid);
793 if ($this->db->query($sqlef) && $this->db->query($sql)) {
794 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"facture_rec WHERE rowid = ".((int) $rowid);
796 if ($this->db->query($sql)) {
808 $this->error = $this->db->lasterror();
812 $this->error = $this->db->lasterror();
815 if (!$error && !$notrigger) {
827 $this->db->rollback();
860 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 =
'', $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)
866 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);
867 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
879 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
880 $vat_src_code = $reg[1];
881 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
884 if ($this->brouillon) {
886 $remise_percent =
price2num($remise_percent);
887 if (empty($remise_percent)) {
893 if (!preg_match(
'/\((.*)\)/', $txtva)) {
901 if (empty($txlocaltax1)) {
904 if (empty($txlocaltax2)) {
907 if (empty($info_bits)) {
911 if ($price_base_type ==
'HT') {
922 $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);
923 $total_ht = $tabprice[0];
924 $total_tva = $tabprice[1];
925 $total_ttc = $tabprice[2];
926 $total_localtax1 = $tabprice[9];
927 $total_localtax2 = $tabprice[10];
928 $pu_ht = $tabprice[3];
931 $multicurrency_total_ht = $tabprice[16];
932 $multicurrency_total_tva = $tabprice[17];
933 $multicurrency_total_ttc = $tabprice[18];
934 $pu_ht_devise = $tabprice[19];
936 $product_type = $type;
938 $product =
new Product($this->db);
939 $result = $product->fetch($fk_product);
940 $product_type = $product->type;
945 if ($ranktouse == -1) {
947 $ranktouse = $rangmax + 1;
950 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facturedet_rec (";
951 $sql .=
"fk_facture";
953 $sql .=
", description";
957 $sql .=
", vat_src_code";
958 $sql .=
", localtax1_tx";
959 $sql .=
", localtax1_type";
960 $sql .=
", localtax2_tx";
961 $sql .=
", localtax2_type";
962 $sql .=
", fk_product";
963 $sql .=
", product_type";
964 $sql .=
", remise_percent";
965 $sql .=
", subprice";
967 $sql .=
", total_ht";
968 $sql .=
", total_tva";
969 $sql .=
", total_localtax1";
970 $sql .=
", total_localtax2";
971 $sql .=
", total_ttc";
972 $sql .=
", date_start_fill";
973 $sql .=
", date_end_fill";
974 $sql .=
", fk_product_fournisseur_price";
975 $sql .=
", buy_price_ht";
976 $sql .=
", info_bits";
978 $sql .=
", special_code";
980 $sql .=
', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
981 $sql .=
") VALUES (";
982 $sql .=
" ".((int) $facid);
983 $sql .=
", ".(!empty($label) ?
"'".$this->db->escape($label).
"'" :
"null");
984 $sql .=
", '".$this->db->escape($desc).
"'";
985 $sql .=
", ".price2num($pu_ht);
986 $sql .=
", ".price2num($qty);
987 $sql .=
", ".price2num($txtva);
988 $sql .=
", '".$this->db->escape($vat_src_code).
"'";
989 $sql .=
", ".price2num($txlocaltax1);
990 $sql .=
", '".$this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] :
'').
"'";
991 $sql .=
", ".price2num($txlocaltax2);
992 $sql .=
", '".$this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] :
'').
"'";
993 $sql .=
", ".(!empty($fk_product) ?
"'".$this->db->escape($fk_product).
"'" :
"null");
994 $sql .=
", ".((int) $product_type);
995 $sql .=
", ".price2num($remise_percent);
996 $sql .=
", ".price2num($pu_ht);
998 $sql .=
", ".price2num($total_ht);
999 $sql .=
", ".price2num($total_tva);
1000 $sql .=
", ".price2num($total_localtax1);
1001 $sql .=
", ".price2num($total_localtax2);
1002 $sql .=
", ".price2num($total_ttc);
1003 $sql .=
", ".(int) $date_start_fill;
1004 $sql .=
", ".(int) $date_end_fill;
1005 $sql .=
", ".($fk_fournprice > 0 ? $fk_fournprice :
'null');
1006 $sql .=
", ".($pa_ht ?
price2num($pa_ht) : 0);
1007 $sql .=
", ".((int) $info_bits);
1008 $sql .=
", ".((int) $ranktouse);
1009 $sql .=
", ".((int) $special_code);
1010 $sql .=
", ".($fk_unit ? ((int) $fk_unit) :
"null");
1011 $sql .=
", ".(int) $this->fk_multicurrency;
1012 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1013 $sql .=
", ".price2num($pu_ht_devise,
'CU');
1014 $sql .=
", ".price2num($multicurrency_total_ht,
'CT');
1015 $sql .=
", ".price2num($multicurrency_total_tva,
'CT');
1016 $sql .=
", ".price2num($multicurrency_total_ttc,
'CT');
1019 dol_syslog(get_class($this).
"::addline", LOG_DEBUG);
1020 if ($this->db->query($sql)) {
1021 $lineId = $this->db->last_insert_id(MAIN_DB_PREFIX.
"facturedet_rec");
1026 $this->error = $this->db->lasterror();
1030 $this->error =
'Recurring Invoice is suspended. adding lines not allowed.';
1065 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 =
'', $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)
1071 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);
1072 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1075 if (empty($remise_percent)) {
1076 $remise_percent = 0;
1084 if ($this->brouillon) {
1086 $remise_percent =
price2num($remise_percent);
1088 if (empty($info_bits)) {
1093 $pu_ht_devise =
price2num($pu_ht_devise);
1094 if (!preg_match(
'/\((.*)\)/', $txtva)) {
1099 if (empty($txlocaltax1)) {
1102 if (empty($txlocaltax2)) {
1106 if (empty($this->multicurrency_subprice)) {
1107 $this->multicurrency_subprice = 0;
1109 if (empty($this->multicurrency_total_ht)) {
1110 $this->multicurrency_total_ht = 0;
1112 if (empty($this->multicurrency_total_tva)) {
1113 $this->multicurrency_total_tva = 0;
1115 if (empty($this->multicurrency_total_ttc)) {
1116 $this->multicurrency_total_ttc = 0;
1119 if ($price_base_type ==
'HT') {
1134 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
1135 $vat_src_code = $reg[1];
1136 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
1139 $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);
1141 $total_ht = $tabprice[0];
1142 $total_tva = $tabprice[1];
1143 $total_ttc = $tabprice[2];
1144 $total_localtax1 = $tabprice[9];
1145 $total_localtax2 = $tabprice[10];
1146 $pu_ht = $tabprice[3];
1147 $pu_tva = $tabprice[4];
1148 $pu_ttc = $tabprice[5];
1151 $multicurrency_total_ht = $tabprice[16];
1152 $multicurrency_total_tva = $tabprice[17];
1153 $multicurrency_total_ttc = $tabprice[18];
1154 $pu_ht_devise = $tabprice[19];
1156 $product_type = $type;
1158 $product =
new Product($this->db);
1159 $result = $product->fetch($fk_product);
1160 $product_type = $product->type;
1163 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet_rec SET ";
1164 $sql .=
"fk_facture = ".((int) $facid);
1165 $sql .=
", label=".(!empty($label) ?
"'".$this->db->escape($label).
"'" :
"null");
1166 $sql .=
", description='".$this->db->escape($desc).
"'";
1167 $sql .=
", price=".price2num($pu_ht);
1168 $sql .=
", qty=".price2num($qty);
1169 $sql .=
", tva_tx=".price2num($txtva);
1170 $sql .=
", vat_src_code='".$this->db->escape($vat_src_code).
"'";
1171 $sql .=
", localtax1_tx=".((float) $txlocaltax1);
1172 $sql .=
", localtax1_type='".$this->db->escape($localtaxes_type[0]).
"'";
1173 $sql .=
", localtax2_tx=".((float) $txlocaltax2);
1174 $sql .=
", localtax2_type='".$this->db->escape($localtaxes_type[2]).
"'";
1175 $sql .=
", fk_product=".(!empty($fk_product) ?
"'".$this->db->escape($fk_product).
"'" :
"null");
1176 $sql .=
", product_type=".((int) $product_type);
1177 $sql .=
", remise_percent='".price2num($remise_percent).
"'";
1178 $sql .=
", subprice='".price2num($pu_ht).
"'";
1179 $sql .=
", total_ht='".price2num($total_ht).
"'";
1180 $sql .=
", total_tva='".price2num($total_tva).
"'";
1181 $sql .=
", total_localtax1='".price2num($total_localtax1).
"'";
1182 $sql .=
", total_localtax2='".price2num($total_localtax2).
"'";
1183 $sql .=
", total_ttc='".price2num($total_ttc).
"'";
1184 $sql .=
", date_start_fill=".((int) $date_start_fill);
1185 $sql .=
", date_end_fill=".((int) $date_end_fill);
1186 $sql .=
", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice :
'null');
1187 $sql .=
", buy_price_ht=".($pa_ht ?
price2num($pa_ht) : 0);
1188 $sql .=
", info_bits=".((int) $info_bits);
1189 $sql .=
", rang=".((int) $rang);
1190 $sql .=
", special_code=".((int) $special_code);
1191 $sql .=
", fk_unit=".($fk_unit ?
"'".$this->db->escape($fk_unit).
"'" :
"null");
1192 $sql .=
', multicurrency_subprice = '.price2num($pu_ht_devise);
1193 $sql .=
', multicurrency_total_ht = '.price2num($multicurrency_total_ht);
1194 $sql .=
', multicurrency_total_tva = '.price2num($multicurrency_total_tva);
1195 $sql .=
', multicurrency_total_ttc = '.price2num($multicurrency_total_ttc);
1196 $sql .=
" WHERE rowid = ".((int) $rowid);
1198 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
1199 if ($this->db->query($sql)) {
1204 $this->error = $this->db->lasterror();
1219 if (empty($this->date_when)) {
1233 if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) {
1248 return ($this->
isMaxNbGenReached() ?
'<strike>' :
'').$ret.($this->isMaxNbGenReached() ?
'</strike>' :
'');
1264 global $conf, $langs, $db, $user, $hookmanager;
1270 $langs->loadLangs(array(
"main",
"bills"));
1274 $today =
dol_mktime(23, 59, 59, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year']);
1276 $this->output =
null;
1278 dol_syslog(
"createRecurringInvoices restrictioninvoiceid=".$restrictioninvoiceid.
" forcevalidation=".$forcevalidation);
1280 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'facture_rec';
1281 $sql .=
' WHERE frequency > 0';
1282 $sql .=
" AND (date_when IS NULL OR date_when <= '".$this->db->idate($today).
"')";
1283 $sql .=
' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
1284 $sql .=
' AND suspended = 0';
1285 $sql .=
' AND entity = '.$conf->entity;
1286 if ($restrictioninvoiceid > 0) {
1287 $sql .=
' AND rowid = '.((int) $restrictioninvoiceid);
1289 $sql .= $this->db->order(
'entity',
'ASC');
1291 $parameters = array(
1292 'restrictioninvoiceid' => $restrictioninvoiceid,
1293 'forcevalidation' => $forcevalidation,
1295 $reshook = $hookmanager->executeHooks(
'beforeCreationOfRecurringInvoices', $parameters, $sql);
1297 $resql = $this->db->query($sql);
1300 $num = $this->db->num_rows($resql);
1303 $this->output .= $langs->trans(
"FoundXQualifiedRecurringInvoiceTemplate", $num).
"\n";
1305 $this->output .= $langs->trans(
"NoQualifiedRecurringInvoiceTemplateFound");
1308 $saventity = $conf->entity;
1311 $line = $this->db->fetch_object($resql);
1315 $invoiceidgenerated = 0;
1319 $facturerec->fetch($line->rowid);
1321 if ($facturerec->id > 0) {
1323 $conf->entity = $facturerec->entity;
1325 dol_syslog(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref.
", entity=".$facturerec->entity);
1327 $facture =
new Facture($this->db);
1328 $facture->fac_rec = $facturerec->id;
1329 $facture->fk_fac_rec_source = $facturerec->id;
1332 $facture->brouillon = 1;
1335 $facture->date = (empty($facturerec->date_when) ? $now : $facturerec->date_when);
1336 $facture->socid = $facturerec->socid;
1337 if (!empty($facturerec->fk_multicurrency)) {
1338 $facture->fk_multicurrency = $facturerec->fk_multicurrency;
1339 $facture->multicurrency_code = $facturerec->multicurrency_code;
1340 $facture->multicurrency_tx = $facturerec->multicurrency_tx;
1343 if (isset($facture->array_options) && isset($facturerec->array_options)) {
1344 foreach ($facturerec->array_options as $key => $value) {
1345 if (isset($facture->array_options[$key])) {
1346 $facture->array_options[$key] = $value;
1351 $invoiceidgenerated = $facture->create($user);
1352 if ($invoiceidgenerated <= 0) {
1353 $this->errors = $facture->errors;
1354 $this->error = $facture->error;
1359 if (!$error && ($facturerec->auto_validate || $forcevalidation)) {
1360 $result = $facture->validate($user);
1362 $this->errors = $facture->errors;
1363 $this->error = $facture->error;
1367 if (!$error && $facturerec->generate_pdf) {
1369 $facture->fetch($facture->id);
1370 $result = $facture->generateDocument($facturerec->model_pdf, $langs);
1372 $this->errors = $facture->errors;
1373 $this->error = $facture->error;
1377 if (!$error && !$notrigger) {
1379 $result = $facturerec->call_trigger(
'BILLREC_CREATEBILL', $user);
1381 $this->errors = $facturerec->errors;
1382 $this->error = $facturerec->error;
1389 $this->error =
"Failed to load invoice template with id=".$line->rowid.
", entity=".$conf->entity.
"\n";
1390 $this->errors[] =
"Failed to load invoice template with id=".$line->rowid.
", entity=".$conf->entity;
1391 dol_syslog(
"createRecurringInvoices Failed to load invoice template with id=".$line->rowid.
", entity=".$conf->entity);
1394 if (!$error && $invoiceidgenerated >= 0) {
1395 $this->db->commit(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref);
1396 dol_syslog(
"createRecurringInvoices Process invoice template ".$facturerec->ref.
" is finished with a success generation");
1398 $this->output .= $langs->trans(
"InvoiceGeneratedFromTemplate", $facture->ref, $facturerec->ref).
"\n";
1400 $this->db->rollback(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref);
1403 $parameters = array(
1406 'errorCount' => $error,
1407 'invoiceidgenerated' => $invoiceidgenerated,
1408 'facturerec' => $facturerec,
1411 $reshook = $hookmanager->executeHooks(
'afterCreationOfRecurringInvoice', $parameters, $facture);
1416 $conf->entity = $saventity;
1421 $this->output = trim($this->output);
1423 return $error ? $error : 0;
1438 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'', $notooltip =
'', $save_lastsearch_value = -1)
1440 global $langs, $hookmanager;
1444 $label =
'<u>'.$langs->trans(
"RepeatableInvoice").
'</u>';
1445 if (!empty($this->
ref)) {
1446 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1448 if ($this->frequency > 0) {
1449 $label .=
'<br><b>'.$langs->trans(
'Frequency').
':</b> '.$langs->trans(
'FrequencyPer_'.$this->unit_frequency, $this->frequency);
1451 if (!empty($this->date_last_gen)) {
1452 $label .=
'<br><b>'.$langs->trans(
'DateLastGeneration').
':</b> '.
dol_print_date($this->date_last_gen,
'dayhour');
1454 if ($this->frequency > 0) {
1455 if (!empty($this->date_when)) {
1456 $label .=
'<br><b>'.$langs->trans(
'NextDateToExecution').
':</b> ';
1457 $label .= (empty($this->suspended) ?
'' :
'<strike>').
dol_print_date($this->date_when,
'day').(empty($this->suspended) ?
'' :
'</strike>');
1458 if (!empty($this->suspended)) {
1459 $label .=
' ('.$langs->trans(
"Disabled").
')';
1464 $url = DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$this->id;
1470 if ($option !=
'nolink') {
1472 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1473 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1474 $add_save_lastsearch_values = 1;
1476 if ($add_save_lastsearch_values) {
1477 $url .=
'&save_lastsearch_values=1';
1481 $linkstart =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
1484 $result .= $linkstart;
1486 $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);
1488 if ($withpicto != 2) {
1489 $result .= $this->ref;
1491 $result .= $linkend;
1493 $hookmanager->initHooks(array($this->element .
'dao'));
1494 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1495 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1497 $result = $hookmanager->resPrint;
1499 $result .= $hookmanager->resPrint;
1513 return $this->
LibStatut($this->frequency ? 1 : 0, $this->suspended, $mode, $alreadypaid, empty($this->
type) ? 0 : $this->type);
1527 public function LibStatut($recur, $status, $mode = 0, $alreadypaid = -1, $type = 0)
1531 $langs->load(
'bills');
1533 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1534 $statusType =
'status0';
1539 if ($status == self::STATUS_SUSPENDED) {
1540 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1542 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1545 if ($status == self::STATUS_SUSPENDED) {
1546 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1548 $labelStatus = $langs->transnoentitiesnoconv(
"Draft");
1551 } elseif ($mode == 1) {
1554 if ($status == self::STATUS_SUSPENDED) {
1555 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1557 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1560 if ($status == self::STATUS_SUSPENDED) {
1561 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1563 $labelStatus = $langs->transnoentitiesnoconv(
"Draft");
1566 } elseif ($mode == 2) {
1568 if ($status == self::STATUS_SUSPENDED) {
1569 $statusType =
'status6';
1570 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1572 $statusType =
'status4';
1573 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1576 if ($status == self::STATUS_SUSPENDED) {
1577 $statusType =
'status6';
1578 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1580 $statusType =
'status0';
1581 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1584 } elseif ($mode == 3) {
1587 if ($status == self::STATUS_SUSPENDED) {
1588 $statusType =
'status6';
1589 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1591 $statusType =
'status4';
1592 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1595 if ($status == self::STATUS_SUSPENDED) {
1596 $statusType =
'status6';
1597 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1599 $statusType =
'status0';
1600 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1603 } elseif ($mode == 4) {
1606 if ($status == self::STATUS_SUSPENDED) {
1607 $statusType =
'status6';
1608 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1610 $statusType =
'status4';
1611 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1614 if ($status == self::STATUS_SUSPENDED) {
1615 $statusType =
'status6';
1616 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1618 $statusType =
'status0';
1619 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1622 } elseif ($mode == 5 || $mode == 6) {
1628 if ($status == self::STATUS_SUSPENDED) {
1629 $statusType =
'status6';
1630 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1632 $statusType =
'status4';
1633 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1636 if ($status == self::STATUS_SUSPENDED) {
1637 $statusType =
'status6';
1638 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1640 $statusType =
'status0';
1641 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1646 $labelStatusShort = $labelStatus;
1648 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1661 global $user, $langs, $conf;
1665 $nownotime =
dol_mktime(0, 0, 0, $arraynow[
'mon'], $arraynow[
'mday'], $arraynow[
'year']);
1671 $sql =
"SELECT rowid";
1672 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
1673 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
1674 $sql .= $this->db->plimit(100);
1676 $resql = $this->db->query($sql);
1678 $num_prods = $this->db->num_rows($resql);
1680 while ($i < $num_prods) {
1682 $row = $this->db->fetch_row($resql);
1683 $prodids[$i] = $row[0];
1689 $this->
ref =
'SPECIMEN';
1690 $this->title =
'SPECIMEN';
1691 $this->specimen = 1;
1693 $this->date = $nownotime;
1694 $this->date_lim_reglement = $nownotime + 3600 * 24 * 30;
1695 $this->cond_reglement_id = 1;
1696 $this->cond_reglement_code =
'RECEP';
1698 $this->mode_reglement_id = 0;
1699 $this->mode_reglement_code =
'';
1700 $this->note_public =
'This is a comment (public)';
1701 $this->note_private =
'This is a comment (private)';
1702 $this->note =
'This is a comment (private)';
1703 $this->fk_incoterms = 0;
1704 $this->location_incoterms =
'';
1706 if (empty($option) || $option !=
'nolines') {
1710 while ($xnbp < $nbp) {
1712 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1714 $line->subprice = 100;
1715 $line->tva_tx = 19.6;
1716 $line->localtax1_tx = 0;
1717 $line->localtax2_tx = 0;
1718 $line->remise_percent = 0;
1720 $prodid = mt_rand(1, $num_prods);
1721 $line->fk_product = $prodids[$prodid];
1723 $line->total_ht = -100;
1724 $line->total_ttc = -119.6;
1725 $line->total_tva = -19.6;
1726 } elseif ($xnbp == 2) {
1727 $line->subprice = -100;
1728 $line->total_ht = -100;
1729 $line->total_ttc = -119.6;
1730 $line->total_tva = -19.6;
1731 $line->remise_percent = 0;
1732 } elseif ($xnbp == 3) {
1733 $prodid = mt_rand(1, $num_prods);
1734 $line->fk_product = $prodids[$prodid];
1735 $line->total_ht = 50;
1736 $line->total_ttc = 59.8;
1737 $line->total_tva = 9.8;
1738 $line->remise_percent = 50;
1741 $prodid = mt_rand(1, $num_prods);
1742 $line->fk_product = $prodids[$prodid];
1743 $line->total_ht = 100;
1744 $line->total_ttc = 119.6;
1745 $line->total_tva = 19.6;
1746 $line->remise_percent = 00;
1749 $this->lines[$xnbp] = $line;
1752 $this->total_ht += $line->total_ht;
1753 $this->total_tva += $line->total_tva;
1754 $this->total_ttc += $line->total_ttc;
1756 $this->revenuestamp = 0;
1760 $line->desc = $langs->trans(
"Description").
" (offered line)";
1762 $line->subprice = 100;
1763 $line->tva_tx = 19.6;
1764 $line->localtax1_tx = 0;
1765 $line->localtax2_tx = 0;
1766 $line->remise_percent = 100;
1767 $line->total_ht = 0;
1768 $line->total_ttc = 0;
1769 $line->total_tva = 0;
1770 $prodid = mt_rand(1, $num_prods);
1771 $line->fk_product = $prodids[$prodid];
1773 $this->lines[$xnbp] = $line;
1777 $this->usenewprice = 0;
1826 if (!$this->table_element) {
1827 dol_syslog(get_class($this).
"::setFrequencyAndUnit was called on objet with property table_element not defined", LOG_ERR);
1831 if (!empty($frequency) && empty($unit)) {
1832 dol_syslog(get_class($this).
"::setFrequencyAndUnit was called on objet with params frequency defined but unit not defined", LOG_ERR);
1836 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1837 $sql .=
' SET frequency = '.($frequency ? $this->db->escape($frequency) :
'null');
1838 if (!empty($unit)) {
1839 $sql .=
', unit_frequency = \''.$this->db->escape($unit).
'\'';
1841 $sql .=
" WHERE rowid = ".((int) $this->
id);
1843 dol_syslog(get_class($this).
"::setFrequencyAndUnit", LOG_DEBUG);
1844 if ($this->db->query($sql)) {
1845 $this->frequency = $frequency;
1846 if (!empty($unit)) {
1847 $this->unit_frequency = $unit;
1852 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
1874 public function setNextDate($date, $increment_nb_gen_done = 0, $notrigger = 0)
1879 if (!$this->table_element) {
1880 dol_syslog(get_class($this).
"::setNextDate was called on objet with property table_element not defined", LOG_ERR);
1883 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1884 $sql .=
" SET date_when = ".($date ?
"'".$this->db->idate($date).
"'" :
"null");
1885 if ($increment_nb_gen_done > 0) {
1886 $sql .=
', nb_gen_done = nb_gen_done + 1';
1888 $sql .=
" WHERE rowid = ".((int) $this->
id);
1890 dol_syslog(get_class($this).
"::setNextDate", LOG_DEBUG);
1891 if ($this->db->query($sql)) {
1892 $this->date_when = $date;
1893 if ($increment_nb_gen_done > 0) {
1894 $this->nb_gen_done++;
1899 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
1924 if (!$this->table_element) {
1925 dol_syslog(get_class($this).
"::setMaxPeriod was called on objet with property table_element not defined", LOG_ERR);
1933 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1934 $sql .=
' SET nb_gen_max = '.((int) $nb);
1935 $sql .=
" WHERE rowid = ".((int) $this->
id);
1937 dol_syslog(get_class($this).
"::setMaxPeriod", LOG_DEBUG);
1938 if ($this->db->query($sql)) {
1939 $this->nb_gen_max = $nb;
1943 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
1968 if (!$this->table_element) {
1969 dol_syslog(get_class($this).
"::setAutoValidate was called on objet with property table_element not defined", LOG_ERR);
1973 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1974 $sql .=
' SET auto_validate = '.((int) $validate);
1975 $sql .=
" WHERE rowid = ".((int) $this->
id);
1977 dol_syslog(get_class($this).
"::setAutoValidate", LOG_DEBUG);
1978 if ($this->db->query($sql)) {
1979 $this->auto_validate = $validate;
1983 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2008 if (!$this->table_element) {
2009 dol_syslog(get_class($this).
"::setGeneratePdf was called on objet with property table_element not defined", LOG_ERR);
2013 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2014 $sql .=
' SET generate_pdf = '.((int) $validate);
2015 $sql .=
" WHERE rowid = ".((int) $this->
id);
2017 dol_syslog(get_class($this).
"::setGeneratePdf", LOG_DEBUG);
2018 if ($this->db->query($sql)) {
2019 $this->generate_pdf = $validate;
2023 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2047 if (!$this->table_element) {
2048 dol_syslog(get_class($this).
"::setModelPdf was called on objet with property table_element not defined", LOG_ERR);
2052 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2053 $sql .=
" SET modelpdf = '".$this->db->escape($model).
"'";
2054 $sql .=
" WHERE rowid = ".((int) $this->
id);
2056 dol_syslog(get_class($this).
"::setModelPdf", LOG_DEBUG);
2057 if ($this->db->query($sql)) {
2058 $this->model_pdf = $model;
2062 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2088 public $element =
'facturedetrec';
2093 public $table_element =
'facturedet_rec';
2096 public $fk_product_fournisseur_price;
2097 public $fk_fournprice;
2103 public $description;
2105 public $fk_product_type;
2107 public $fk_contract_line;
2117 public function delete(
User $user, $notrigger =
false)
2126 $result = $this->
call_trigger(
'LINEBILLREC_DELETE', $user);
2142 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
' WHERE rowid='.((int) $this->
id);
2144 $res = $this->db->query($sql);
2147 $this->errors[] = $this->db->lasterror();
2153 $this->db->rollback();
2156 $this->db->commit();
2170 $sql =
'SELECT l.rowid, l.fk_facture ,l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx,';
2171 $sql .=
' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
2172 $sql .=
' l.date_start_fill, l.date_end_fill, l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
2173 $sql .=
' l.rang, l.special_code,';
2174 $sql .=
' l.fk_unit, l.fk_contract_line,';
2175 $sql .=
' l.import_key, l.fk_multicurrency,';
2176 $sql .=
' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
2177 $sql .=
' l.buy_price_ht, l.fk_product_fournisseur_price,';
2178 $sql .=
' l.fk_user_author, l.fk_user_modif,';
2179 $sql .=
' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
2180 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facturedet_rec as l';
2181 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
2182 $sql .=
' WHERE l.rowid = '.((int) $rowid);
2183 $sql .=
' ORDER BY l.rang';
2186 $result = $this->db->query($sql);
2188 $objp = $this->db->fetch_object($result);
2190 $this->
id = $objp->rowid;
2191 $this->label = $objp->custom_label;
2192 $this->desc = $objp->description;
2194 $this->product_type = $objp->product_type;
2195 $this->
ref = $objp->product_ref;
2196 $this->product_ref = $objp->product_ref;
2197 $this->libelle = $objp->product_label;
2198 $this->product_label = $objp->product_label;
2199 $this->product_desc = $objp->product_desc;
2200 $this->fk_product_type = $objp->fk_product_type;
2201 $this->qty = $objp->qty;
2202 $this->
price = $objp->price;
2203 $this->subprice = $objp->subprice;
2204 $this->fk_facture = $objp->fk_facture;
2205 $this->vat_src_code = $objp->vat_src_code;
2206 $this->tva_tx = $objp->tva_tx;
2207 $this->localtax1_tx = $objp->localtax1_tx;
2208 $this->localtax2_tx = $objp->localtax2_tx;
2209 $this->localtax1_type = $objp->localtax1_type;
2210 $this->localtax2_type = $objp->localtax2_type;
2211 $this->remise_percent = $objp->remise_percent;
2213 $this->fk_product = $objp->fk_product;
2214 $this->date_start_fill = $objp->date_start_fill;
2215 $this->date_end_fill = $objp->date_end_fill;
2216 $this->info_bits = $objp->info_bits;
2217 $this->total_ht = $objp->total_ht;
2218 $this->total_tva = $objp->total_tva;
2219 $this->total_ttc = $objp->total_ttc;
2221 $this->rang = $objp->rang;
2222 $this->special_code = $objp->special_code;
2223 $this->fk_unit = $objp->fk_unit;
2224 $this->fk_contract_line = $objp->fk_contract_line;
2225 $this->import_key = $objp->import_key;
2226 $this->fk_multicurrency = $objp->fk_multicurrency;
2227 $this->multicurrency_code = $objp->multicurrency_code;
2228 $this->multicurrency_subprice = $objp->multicurrency_subprice;
2229 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
2230 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
2231 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2233 $this->buy_price_ht = $objp->buy_price_ht;
2235 $this->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
2236 $this->fk_user_author = $objp->fk_user_author;
2237 $this->fk_user_modif = $objp->fk_user_modif;
2239 $this->db->free($result);
2242 $this->error = $this->db->lasterror();
2261 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2263 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet_rec SET";
2264 $sql .=
" fk_facture = ".((int) $this->fk_facture);
2265 $sql .=
", label=".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null");
2266 $sql .=
", description='".$this->db->escape($this->desc).
"'";
2267 $sql .=
", price=".price2num($this->
price);
2268 $sql .=
", qty=".price2num($this->qty);
2269 $sql .=
", tva_tx=".price2num($this->tva_tx);
2270 $sql .=
", vat_src_code='".$this->db->escape($this->vat_src_code).
"'";
2271 $sql .=
", localtax1_tx=".price2num($this->localtax1_tx);
2272 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
2273 $sql .=
", localtax2_tx=".price2num($this->localtax2_tx);
2274 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
2275 $sql .=
", fk_product=".($this->fk_product > 0 ? $this->fk_product :
"null");
2276 $sql .=
", product_type=".((int) $this->product_type);
2277 $sql .=
", remise_percent=".price2num($this->remise_percent);
2278 $sql .=
", subprice=".price2num($this->subprice);
2279 $sql .=
", info_bits=".price2num($this->info_bits);
2280 $sql .=
", date_start_fill=".(int) $this->date_start_fill;
2281 $sql .=
", date_end_fill=".(int) $this->date_end_fill;
2282 if (empty($this->skip_update_total)) {
2283 $sql .=
", total_ht=".price2num($this->total_ht);
2284 $sql .=
", total_tva=".price2num($this->total_tva);
2285 $sql .=
", total_localtax1=".price2num($this->total_localtax1);
2286 $sql .=
", total_localtax2=".price2num($this->total_localtax2);
2287 $sql .=
", total_ttc=".price2num($this->total_ttc);
2289 $sql .=
", rang=".((int) $this->rang);
2290 $sql .=
", special_code=".((int) $this->special_code);
2291 $sql .=
", fk_unit=".($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
"null");
2292 $sql .=
", fk_contract_line=".($this->fk_contract_line ? $this->fk_contract_line :
"null");
2293 $sql .=
" WHERE rowid = ".((int) $this->
id);
2297 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
2299 $resql = $this->db->query($sql);
2308 if (!$error && !$notrigger) {
2310 $result = $this->
call_trigger(
'LINEBILLREC_MODIFY', $user);
2318 $this->db->rollback();
2321 $this->db->commit();
2325 $this->error = $this->db->lasterror();
2326 $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='', $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.
fetch($rowid)
Get line of template invoice.
update(User $user, $notrigger=0)
Update a line to invoice_rec.
Class to manage invoice templates.
create($user, $facid, $notrigger=0)
Create a predefined invoice.
setFrequencyAndUnit($frequency, $unit, $notrigger=0)
Update frequency and unit.
getLibStatut($mode=0, $alreadypaid=-1)
Return label of object status.
LibStatut($recur, $status, $mode=0, $alreadypaid=-1, $type=0)
Return label of a status.
fetch_lines()
Get lines of template invoices into this->lines.
addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise=0, $date_start_fill=0, $date_end_fill=0, $fk_fournprice=null, $pa_ht=0)
Add a line to invoice.
getLinesArray()
Create an array of invoice lines.
updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise=0, $notrigger=0, $date_start_fill=0, $date_end_fill=0, $fk_fournprice=null, $pa_ht=0)
Update a line to invoice.
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='', $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.
__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.
fetch($rowid, $ref='', $ref_ext='')
Load object and lines.
strikeIfMaxNbGenReached($ret)
Format string to output with by striking the string if max number of generation was reached.
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.
print $langs trans("Ref").' m m m statut
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 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