31 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
34 require_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';
87 public $remise_absolue;
88 public $remise_percent;
102 public $date_last_gen;
117 public $unit_frequency;
120 public $special_code;
122 public $usenewprice = 0;
124 public $date_lim_reglement;
125 public $cond_reglement_code;
126 public $mode_reglement_code;
130 public $auto_validate;
131 public $generate_pdf;
168 public $fields = array(
169 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
170 'titre' =>array(
'type'=>
'varchar(100)',
'label'=>
'Titre',
'enabled'=>1,
'showoncombobox' => 1,
'visible'=>-1,
'position'=>15),
171 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>20,
'index'=>1),
172 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>
'$conf->societe->enabled',
'visible'=>-1,
'notnull'=>1,
'position'=>25),
173 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>30),
175 'remise' =>array(
'type'=>
'double',
'label'=>
'Remise',
'enabled'=>1,
'visible'=>-1,
'position'=>40),
178 'total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'Tva',
'enabled'=>1,
'visible'=>-1,
'position'=>55,
'isameasure'=>1),
179 'localtax1' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax1',
'enabled'=>1,
'visible'=>-1,
'position'=>60,
'isameasure'=>1),
180 'localtax2' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax2',
'enabled'=>1,
'visible'=>-1,
'position'=>65,
'isameasure'=>1),
181 'total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'Total',
'enabled'=>1,
'visible'=>-1,
'position'=>70,
'isameasure'=>1),
182 'total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'Total ttc',
'enabled'=>1,
'visible'=>-1,
'position'=>75,
'isameasure'=>1),
183 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
184 'fk_projet' =>array(
'type'=>
'integer:Project:projet/class/project.class.php:1:fk_statut=1',
'label'=>
'Fk projet',
'enabled'=>
'$conf->project->enabled',
'visible'=>-1,
'position'=>85),
185 'fk_cond_reglement' =>array(
'type'=>
'integer',
'label'=>
'Fk cond reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
186 'fk_mode_reglement' =>array(
'type'=>
'integer',
'label'=>
'Fk mode reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
187 'date_lim_reglement' =>array(
'type'=>
'date',
'label'=>
'Date lim reglement',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
188 'note_private' =>array(
'type'=>
'text',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>105),
189 'note_public' =>array(
'type'=>
'text',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>110),
190 'modelpdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Modelpdf',
'enabled'=>1,
'visible'=>-1,
'position'=>115),
191 'date_last_gen' =>array(
'type'=>
'varchar(7)',
'label'=>
'Last gen',
'enabled'=>1,
'visible'=>-1,
'position'=>120),
192 'unit_frequency' =>array(
'type'=>
'varchar(2)',
'label'=>
'Unit frequency',
'enabled'=>1,
'visible'=>-1,
'position'=>125),
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 'usenewprice' =>array(
'type'=>
'integer',
'label'=>
'UseNewPrice',
'enabled'=>1,
'visible'=>0,
'position'=>155),
199 'revenuestamp' =>array(
'type'=>
'double(24,8)',
'label'=>
'RevenueStamp',
'enabled'=>1,
'visible'=>-1,
'position'=>160,
'isameasure'=>1),
200 'auto_validate' =>array(
'type'=>
'integer',
'label'=>
'Auto validate',
'enabled'=>1,
'visible'=>-1,
'position'=>165),
201 'generate_pdf' =>array(
'type'=>
'integer',
'label'=>
'Generate pdf',
'enabled'=>1,
'visible'=>-1,
'position'=>170),
202 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'Fk account',
'enabled'=>
'$conf->banque->enabled',
'visible'=>-1,
'position'=>175),
203 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'Fk multicurrency',
'enabled'=>1,
'visible'=>-1,
'position'=>180),
204 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'Multicurrency code',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
205 'multicurrency_tx' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency tx',
'enabled'=>1,
'visible'=>-1,
'position'=>190,
'isameasure'=>1),
206 'multicurrency_total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total ht',
'enabled'=>1,
'visible'=>-1,
'position'=>195,
'isameasure'=>1),
207 'multicurrency_total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total tva',
'enabled'=>1,
'visible'=>-1,
'position'=>200,
'isameasure'=>1),
208 'multicurrency_total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total ttc',
'enabled'=>1,
'visible'=>-1,
'position'=>205,
'isameasure'=>1),
209 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>210),
210 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>215),
211 'suspended' =>array(
'type'=>
'integer',
'label'=>
'Suspended',
'enabled'=>1,
'visible'=>-1,
'position'=>225),
215 const STATUS_NOTSUSPENDED = 0;
216 const STATUS_SUSPENDED = 1;
238 public function create($user, $facid, $notrigger = 0)
246 $this->titre = trim(isset($this->titre) ? $this->titre : $this->title);
247 $this->title = trim($this->title);
248 $this->usenewprice = empty($this->usenewprice) ? 0 : $this->usenewprice;
249 if (empty($this->suspended)) {
250 $this->suspended = 0;
254 if (empty($this->frequency)) {
255 $this->frequency = 0;
256 $this->date_when = null;
259 $this->frequency = abs($this->frequency);
260 $this->nb_gen_done = 0;
261 $this->nb_gen_max = empty($this->nb_gen_max) ? 0 : $this->nb_gen_max;
262 $this->auto_validate = empty($this->auto_validate) ? 0 : $this->auto_validate;
263 $this->generate_pdf = empty($this->generate_pdf) ? 0 : $this->generate_pdf;
269 $result = $facsrc->fetch($facid);
272 $this->brouillon = 1;
273 $this->fk_soc = $facsrc->socid;
275 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facture_rec (";
282 $sql .=
", note_private";
283 $sql .=
", note_public";
284 $sql .=
", modelpdf";
285 $sql .=
", fk_user_author";
286 $sql .=
", fk_projet";
287 $sql .=
", fk_account";
288 $sql .=
", fk_cond_reglement";
289 $sql .=
", fk_mode_reglement";
290 $sql .=
", usenewprice";
291 $sql .=
", frequency";
292 $sql .=
", unit_frequency";
293 $sql .=
", date_when";
294 $sql .=
", date_last_gen";
295 $sql .=
", nb_gen_done";
296 $sql .=
", nb_gen_max";
297 $sql .=
", auto_validate";
298 $sql .=
", generate_pdf";
299 $sql .=
", fk_multicurrency";
300 $sql .=
", multicurrency_code";
301 $sql .=
", multicurrency_tx";
302 $sql .=
", suspended";
303 $sql .=
") VALUES (";
304 $sql .=
"'".$this->db->escape($this->titre ? $this->titre : $this->title).
"'";
305 $sql .=
", ".((int) $this->fk_soc);
306 $sql .=
", ".((int) $conf->entity);
307 $sql .=
", '".$this->db->idate($now).
"'";
308 $sql .=
", ".(!empty($facsrc->total_ttc) ? ((
float) $facsrc->total_ttc) :
'0');
309 $sql .=
", ".(!empty($facsrc->remise_absolue) ? ((
float) $this->remise_absolue) :
'0');
310 $sql .=
", ".(!empty($this->note_private) ? (
"'".$this->db->escape($this->note_private).
"'") :
"NULL");
311 $sql .=
", ".(!empty($this->note_public) ? (
"'".$this->db->escape($this->note_public).
"'") :
"NULL");
312 $sql .=
", ".(!empty($this->model_pdf) ? (
"'".$this->db->escape($this->model_pdf).
"'") :
"NULL");
313 $sql .=
", ".((int) $user->id);
314 $sql .=
", ".(!empty($this->fk_project) ? ((int) $this->fk_project) :
"null");
315 $sql .=
", ".(!empty($facsrc->fk_account) ? ((int) $facsrc->fk_account) :
"null");
316 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
"null");
317 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
"null");
318 $sql .=
", ".((int) $this->usenewprice);
319 $sql .=
", ".((int) $this->frequency);
320 $sql .=
", '".$this->db->escape($this->unit_frequency).
"'";
321 $sql .=
", ".(!empty($this->date_when) ?
"'".$this->db->idate($this->date_when).
"'" :
'NULL');
322 $sql .=
", ".(!empty($this->date_last_gen) ?
"'".$this->db->idate($this->date_last_gen).
"'" :
'NULL');
323 $sql .=
", ".((int) $this->nb_gen_done);
324 $sql .=
", ".((int) $this->nb_gen_max);
325 $sql .=
", ".((int) $this->auto_validate);
326 $sql .=
", ".((int) $this->generate_pdf);
327 $sql .=
", ".((int) $facsrc->fk_multicurrency);
328 $sql .=
", '".$this->db->escape($facsrc->multicurrency_code).
"'";
329 $sql .=
", ".((float) $facsrc->multicurrency_tx);
330 $sql .=
", ".((int) $this->suspended);
333 if ($this->
db->query($sql)) {
334 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"facture_rec");
337 $this->fk_multicurrency = $facsrc->fk_multicurrency;
338 $this->multicurrency_code = $facsrc->multicurrency_code;
339 $this->multicurrency_tx = $facsrc->multicurrency_tx;
342 $num = count($facsrc->lines);
343 for ($i = 0; $i < $num; $i++) {
344 $tva_tx = $facsrc->lines[$i]->tva_tx;
345 if (!empty($facsrc->lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
346 $tva_tx .=
' ('.$facsrc->lines[$i]->vat_src_code.
')';
349 $default_start_fill =
getDolGlobalInt(
'INVOICEREC_SET_AUTOFILL_DATE_START');
350 $default_end_fill =
getDolGlobalInt(
'INVOICEREC_SET_AUTOFILL_DATE_END');
352 $result_insert = $this->
addline(
353 $facsrc->lines[$i]->desc,
354 $facsrc->lines[$i]->subprice,
355 $facsrc->lines[$i]->qty,
357 $facsrc->lines[$i]->localtax1_tx,
358 $facsrc->lines[$i]->localtax2_tx,
359 $facsrc->lines[$i]->fk_product,
360 $facsrc->lines[$i]->remise_percent,
362 $facsrc->lines[$i]->info_bits,
365 $facsrc->lines[$i]->product_type,
366 $facsrc->lines[$i]->rang,
367 $facsrc->lines[$i]->special_code,
368 $facsrc->lines[$i]->label,
369 $facsrc->lines[$i]->fk_unit,
370 $facsrc->lines[$i]->multicurrency_subprice,
374 $facsrc->lines[$i]->pa_ht
377 if ($result_insert < 0) {
382 $result2 = $objectline->fetch($result_insert);
385 if (method_exists($facsrc->lines[$i],
'fetch_optionals')) {
386 $facsrc->lines[$i]->fetch_optionals($facsrc->lines[$i]->id);
387 $objectline->array_options = $facsrc->lines[$i]->array_options;
390 $result = $objectline->insertExtraFields();
394 } elseif ($result2 < 0) {
395 $this->errors[] = $objectline->error;
401 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
402 $this->linked_objects = $this->linkedObjectsIds;
406 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
407 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
408 if (is_array($tmp_origin_id)) {
409 foreach ($tmp_origin_id as $origin_id) {
412 $this->error = $this->
db->lasterror();
418 $origin_id = $tmp_origin_id;
421 $this->error = $this->
db->lasterror();
435 if (!$error && !$notrigger) {
439 $this->
db->rollback();
446 $this->
db->rollback();
453 $this->error = $this->
db->lasterror();
454 $this->
db->rollback();
458 $this->
db->rollback();
477 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture_rec SET";
478 $sql .=
" entity = ".((int) $this->entity).
",";
479 $sql .=
" titre = '".$this->db->escape($this->title).
"',";
480 $sql .=
" suspended = ".((int) $this->suspended).
",";
481 $sql .=
" fk_soc = ".((int) $this->socid).
",";
482 $sql .=
" total_tva = ".((float) $this->total_tva).
",";
483 $sql .=
" localtax1 = ".((float) $this->localtax1).
",";
484 $sql .=
" localtax2 = ".((float) $this->localtax2).
",";
485 $sql .=
" total_ht = ".((float) $this->total_ht).
",";
486 $sql .=
" total_ttc = ".((float) $this->total_ttc).
",";
487 $sql .=
" remise_percent = ".((float) $this->remise_percent);
489 $sql .=
" WHERE rowid = ".((int) $this->
id);
493 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
504 if (!$error && !$notrigger) {
508 $this->
db->rollback();
516 $this->error = $this->
db->lasterror();
517 $this->
db->rollback();
530 public function fetch($rowid, $ref =
'', $ref_ext =
'')
534 $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';
535 $sql .=
', f.remise_percent, f.remise_absolue, f.remise';
536 $sql .=
', f.date_lim_reglement as dlr';
537 $sql .=
', f.note_private, f.note_public, f.fk_user_author';
538 $sql .=
', f.modelpdf as model_pdf';
539 $sql .=
', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet as fk_project';
540 $sql .=
', f.fk_account';
541 $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';
542 $sql .=
', f.generate_pdf';
543 $sql .=
", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
544 $sql .=
', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
545 $sql .=
', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
547 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture_rec as f';
548 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
549 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as p ON f.fk_mode_reglement = p.id';
551 $sql .=
' WHERE f.entity IN ('.getEntity(
'invoice').
')';
553 $sql .=
' AND f.rowid = '.((int) $rowid);
555 $sql .=
" AND f.titre = '".$this->db->escape($ref).
"'";
557 $sql .=
' AND f.rowid = 0';
563 $result = $this->
db->query($sql);
565 if ($this->
db->num_rows($result)) {
566 $obj = $this->
db->fetch_object($result);
568 $this->
id = $obj->rowid;
569 $this->entity = $obj->entity;
570 $this->titre = $obj->title;
571 $this->title = $obj->title;
572 $this->
ref = $obj->title;
573 $this->suspended = $obj->suspended;
574 $this->remise_percent = $obj->remise_percent;
575 $this->remise_absolue = $obj->remise_absolue;
576 $this->remise = $obj->remise;
577 $this->total_ht = $obj->total_ht;
578 $this->total_tva = $obj->total_tva;
579 $this->total_localtax1 = $obj->localtax1;
580 $this->total_localtax2 = $obj->localtax2;
581 $this->total_ttc = $obj->total_ttc;
582 $this->socid = $obj->fk_soc;
583 $this->date_lim_reglement = $this->
db->jdate($obj->dlr);
584 $this->mode_reglement_id = $obj->fk_mode_reglement;
585 $this->mode_reglement_code = $obj->mode_reglement_code;
586 $this->mode_reglement = $obj->mode_reglement_libelle;
587 $this->cond_reglement_id = $obj->fk_cond_reglement;
588 $this->cond_reglement_code = $obj->cond_reglement_code;
589 $this->cond_reglement = $obj->cond_reglement_libelle;
590 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
591 $this->fk_project = $obj->fk_project;
592 $this->fk_account = $obj->fk_account;
593 $this->note_private = $obj->note_private;
594 $this->note_public = $obj->note_public;
595 $this->user_author = $obj->fk_user_author;
596 $this->modelpdf = $obj->model_pdf;
597 $this->model_pdf = $obj->model_pdf;
599 $this->frequency = $obj->frequency;
600 $this->unit_frequency = $obj->unit_frequency;
601 $this->date_when = $this->
db->jdate($obj->date_when);
602 $this->date_last_gen = $this->
db->jdate($obj->date_last_gen);
603 $this->nb_gen_done = $obj->nb_gen_done;
604 $this->nb_gen_max = $obj->nb_gen_max;
605 $this->usenewprice = $obj->usenewprice;
606 $this->auto_validate = $obj->auto_validate;
607 $this->generate_pdf = $obj->generate_pdf;
610 $this->fk_multicurrency = $obj->fk_multicurrency;
611 $this->multicurrency_code = $obj->multicurrency_code;
612 $this->multicurrency_tx = $obj->multicurrency_tx;
613 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
614 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
615 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
617 if ($this->statut == self::STATUS_DRAFT) {
618 $this->brouillon = 1;
630 $this->error = $this->
db->lasterror();
635 $this->error =
'Bill with id '.$rowid.
' or ref '.$ref.
' not found';
636 dol_syslog(
'Facture::Fetch Error '.$this->error, LOG_ERR);
640 $this->error = $this->
db->error();
667 $this->lines = array();
678 dol_syslog(
'FactureRec::fetch_lines', LOG_DEBUG);
680 $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, ';
681 $sql .=
' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
682 $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,';
683 $sql .=
' l.rang, l.special_code,';
684 $sql .=
' l.fk_unit, l.fk_contract_line,';
685 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
686 $sql .=
' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
687 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facturedet_rec as l';
688 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
689 $sql .=
' WHERE l.fk_facture = '.((int) $this->
id);
690 $sql .=
' ORDER BY l.rang';
692 $result = $this->
db->query($sql);
694 $num = $this->
db->num_rows($result);
697 $objp = $this->
db->fetch_object($result);
700 $line->id = $objp->rowid;
701 $line->rowid = $objp->rowid;
702 $line->desc = $objp->description;
703 $line->description = $objp->description;
704 $line->ref = $objp->product_ref;
705 $line->product_ref = $objp->product_ref;
706 $line->libelle = $objp->product_label;
707 $line->product_label = $objp->product_label;
708 $line->product_desc = $objp->product_desc;
709 $line->product_type = $objp->product_type;
710 $line->fk_product_type = $objp->fk_product_type;
711 $line->qty = $objp->qty;
712 $line->subprice = $objp->subprice;
714 $line->label = $objp->custom_label;
716 $line->vat_src_code = $objp->vat_src_code;
717 $line->tva_tx = $objp->tva_tx;
718 $line->localtax1_tx = $objp->localtax1_tx;
719 $line->localtax2_tx = $objp->localtax2_tx;
720 $line->localtax1_type = $objp->localtax1_type;
721 $line->localtax2_type = $objp->localtax2_type;
722 $line->remise_percent = $objp->remise_percent;
724 $line->fk_product = $objp->fk_product;
725 $line->date_start_fill = $objp->date_start_fill;
726 $line->date_end_fill = $objp->date_end_fill;
727 $line->info_bits = $objp->info_bits;
728 $line->total_ht = $objp->total_ht;
729 $line->total_tva = $objp->total_tva;
730 $line->total_ttc = $objp->total_ttc;
734 $line->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
735 $line->fk_fournprice = $objp->fk_product_fournisseur_price;
737 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $objp->fk_product_fournisseur_price, $objp->pa_ht);
739 $line->buyprice = $marginInfos[0];
740 $line->pa_ht = $marginInfos[0];
741 $line->marge_tx = $marginInfos[1];
742 $line->marque_tx = $marginInfos[2];
743 $line->rang = $objp->rang;
744 $line->special_code = $objp->special_code;
745 $line->fk_unit = $objp->fk_unit;
746 $line->fk_contract_line = $objp->fk_contract_line;
749 $line->price = $objp->price;
750 $line->remise = $objp->remise;
752 $line->fetch_optionals();
755 $line->fk_multicurrency = $objp->fk_multicurrency;
756 $line->multicurrency_code = $objp->multicurrency_code;
757 $line->multicurrency_subprice = $objp->multicurrency_subprice;
758 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
759 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
760 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
762 $this->lines[$i] = $line;
767 $this->
db->free($result);
770 $this->error = $this->
db->lasterror();
784 public function delete(
User $user, $notrigger = 0, $idwarehouse = -1)
788 dol_syslog(get_class($this).
"::delete rowid=".((
int) $rowid), LOG_DEBUG);
793 $main = MAIN_DB_PREFIX.
'facturedet_rec';
794 $ef = $main.
"_extrafields";
796 $sqlef =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_facture = ".((int) $rowid).
")";
797 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"facturedet_rec WHERE fk_facture = ".((int) $rowid);
799 if ($this->
db->query($sqlef) && $this->
db->query($sql)) {
800 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"facture_rec WHERE rowid = ".((int) $rowid);
802 if ($this->
db->query($sql)) {
814 $this->error = $this->
db->lasterror();
818 $this->error = $this->
db->lasterror();
821 if (!$error && !$notrigger) {
833 $this->
db->rollback();
866 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)
872 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);
873 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
885 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
886 $vat_src_code = $reg[1];
887 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
890 if ($this->brouillon) {
892 $remise_percent =
price2num($remise_percent);
893 if (empty($remise_percent)) {
899 if (!preg_match(
'/\((.*)\)/', $txtva)) {
907 if (empty($txlocaltax1)) {
910 if (empty($txlocaltax2)) {
913 if (empty($info_bits)) {
917 if ($price_base_type ==
'HT') {
928 $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);
929 $total_ht = $tabprice[0];
930 $total_tva = $tabprice[1];
931 $total_ttc = $tabprice[2];
932 $total_localtax1 = $tabprice[9];
933 $total_localtax2 = $tabprice[10];
934 $pu_ht = $tabprice[3];
937 $multicurrency_total_ht = $tabprice[16];
938 $multicurrency_total_tva = $tabprice[17];
939 $multicurrency_total_ttc = $tabprice[18];
940 $pu_ht_devise = $tabprice[19];
942 $product_type = $type;
945 $result = $product->fetch($fk_product);
946 $product_type = $product->type;
951 if ($ranktouse == -1) {
953 $ranktouse = $rangmax + 1;
956 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"facturedet_rec (";
957 $sql .=
"fk_facture";
959 $sql .=
", description";
963 $sql .=
", vat_src_code";
964 $sql .=
", localtax1_tx";
965 $sql .=
", localtax1_type";
966 $sql .=
", localtax2_tx";
967 $sql .=
", localtax2_type";
968 $sql .=
", fk_product";
969 $sql .=
", product_type";
970 $sql .=
", remise_percent";
971 $sql .=
", subprice";
973 $sql .=
", total_ht";
974 $sql .=
", total_tva";
975 $sql .=
", total_localtax1";
976 $sql .=
", total_localtax2";
977 $sql .=
", total_ttc";
978 $sql .=
", date_start_fill";
979 $sql .=
", date_end_fill";
980 $sql .=
", fk_product_fournisseur_price";
981 $sql .=
", buy_price_ht";
982 $sql .=
", info_bits";
984 $sql .=
", special_code";
986 $sql .=
', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
987 $sql .=
") VALUES (";
988 $sql .=
" ".((int) $facid);
989 $sql .=
", ".(!empty($label) ?
"'".$this->db->escape($label).
"'" :
"null");
990 $sql .=
", '".$this->db->escape($desc).
"'";
991 $sql .=
", ".price2num($pu_ht);
992 $sql .=
", ".price2num($qty);
993 $sql .=
", ".price2num($txtva);
994 $sql .=
", '".$this->db->escape($vat_src_code).
"'";
995 $sql .=
", ".price2num($txlocaltax1);
996 $sql .=
", '".$this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] :
'').
"'";
997 $sql .=
", ".price2num($txlocaltax2);
998 $sql .=
", '".$this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] :
'').
"'";
999 $sql .=
", ".(!empty($fk_product) ?
"'".$this->db->escape($fk_product).
"'" :
"null");
1000 $sql .=
", ".((int) $product_type);
1001 $sql .=
", ".price2num($remise_percent);
1002 $sql .=
", ".price2num($pu_ht);
1004 $sql .=
", ".price2num($total_ht);
1005 $sql .=
", ".price2num($total_tva);
1006 $sql .=
", ".price2num($total_localtax1);
1007 $sql .=
", ".price2num($total_localtax2);
1008 $sql .=
", ".price2num($total_ttc);
1009 $sql .=
", ".(int) $date_start_fill;
1010 $sql .=
", ".(int) $date_end_fill;
1011 $sql .=
", ".($fk_fournprice > 0 ? $fk_fournprice :
'null');
1012 $sql .=
", ".($pa_ht ?
price2num($pa_ht) : 0);
1013 $sql .=
", ".((int) $info_bits);
1014 $sql .=
", ".((int) $ranktouse);
1015 $sql .=
", ".((int) $special_code);
1016 $sql .=
", ".($fk_unit ? ((int) $fk_unit) :
"null");
1017 $sql .=
", ".(int) $this->fk_multicurrency;
1018 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1019 $sql .=
", ".price2num($pu_ht_devise,
'CU');
1020 $sql .=
", ".price2num($multicurrency_total_ht,
'CT');
1021 $sql .=
", ".price2num($multicurrency_total_tva,
'CT');
1022 $sql .=
", ".price2num($multicurrency_total_ttc,
'CT');
1025 dol_syslog(get_class($this).
"::addline", LOG_DEBUG);
1026 if ($this->
db->query($sql)) {
1027 $lineId = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"facturedet_rec");
1032 $this->error = $this->
db->lasterror();
1067 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)
1073 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);
1074 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1077 if (empty($remise_percent)) {
1078 $remise_percent = 0;
1086 if ($this->brouillon) {
1088 $remise_percent =
price2num($remise_percent);
1090 if (empty($info_bits)) {
1095 $pu_ht_devise =
price2num($pu_ht_devise);
1096 if (!preg_match(
'/\((.*)\)/', $txtva)) {
1101 if (empty($txlocaltax1)) {
1104 if (empty($txlocaltax2)) {
1108 if (empty($this->multicurrency_subprice)) {
1109 $this->multicurrency_subprice = 0;
1111 if (empty($this->multicurrency_total_ht)) {
1112 $this->multicurrency_total_ht = 0;
1114 if (empty($this->multicurrency_total_tva)) {
1115 $this->multicurrency_total_tva = 0;
1117 if (empty($this->multicurrency_total_ttc)) {
1118 $this->multicurrency_total_ttc = 0;
1121 if ($price_base_type ==
'HT') {
1136 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
1137 $vat_src_code = $reg[1];
1138 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
1141 $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);
1143 $total_ht = $tabprice[0];
1144 $total_tva = $tabprice[1];
1145 $total_ttc = $tabprice[2];
1146 $total_localtax1 = $tabprice[9];
1147 $total_localtax2 = $tabprice[10];
1148 $pu_ht = $tabprice[3];
1149 $pu_tva = $tabprice[4];
1150 $pu_ttc = $tabprice[5];
1153 $multicurrency_total_ht = $tabprice[16];
1154 $multicurrency_total_tva = $tabprice[17];
1155 $multicurrency_total_ttc = $tabprice[18];
1156 $pu_ht_devise = $tabprice[19];
1158 $product_type = $type;
1161 $result = $product->fetch($fk_product);
1162 $product_type = $product->type;
1165 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet_rec SET ";
1166 $sql .=
"fk_facture = ".((int) $facid);
1167 $sql .=
", label=".(!empty($label) ?
"'".$this->db->escape($label).
"'" :
"null");
1168 $sql .=
", description='".$this->db->escape($desc).
"'";
1169 $sql .=
", price=".price2num($pu_ht);
1170 $sql .=
", qty=".price2num($qty);
1171 $sql .=
", tva_tx=".price2num($txtva);
1172 $sql .=
", vat_src_code='".$this->db->escape($vat_src_code).
"'";
1173 $sql .=
", localtax1_tx=".((float) $txlocaltax1);
1174 $sql .=
", localtax1_type='".$this->db->escape($localtaxes_type[0]).
"'";
1175 $sql .=
", localtax2_tx=".((float) $txlocaltax2);
1176 $sql .=
", localtax2_type='".$this->db->escape($localtaxes_type[2]).
"'";
1177 $sql .=
", fk_product=".(!empty($fk_product) ?
"'".$this->db->escape($fk_product).
"'" :
"null");
1178 $sql .=
", product_type=".((int) $product_type);
1179 $sql .=
", remise_percent='".price2num($remise_percent).
"'";
1180 $sql .=
", subprice='".price2num($pu_ht).
"'";
1181 $sql .=
", total_ht='".price2num($total_ht).
"'";
1182 $sql .=
", total_tva='".price2num($total_tva).
"'";
1183 $sql .=
", total_localtax1='".price2num($total_localtax1).
"'";
1184 $sql .=
", total_localtax2='".price2num($total_localtax2).
"'";
1185 $sql .=
", total_ttc='".price2num($total_ttc).
"'";
1186 $sql .=
", date_start_fill=".((int) $date_start_fill);
1187 $sql .=
", date_end_fill=".((int) $date_end_fill);
1188 $sql .=
", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice :
'null');
1189 $sql .=
", buy_price_ht=".($pa_ht ?
price2num($pa_ht) : 0);
1190 $sql .=
", info_bits=".((int) $info_bits);
1191 $sql .=
", rang=".((int) $rang);
1192 $sql .=
", special_code=".((int) $special_code);
1193 $sql .=
", fk_unit=".($fk_unit ?
"'".$this->db->escape($fk_unit).
"'" :
"null");
1194 $sql .=
', multicurrency_subprice = '.price2num($pu_ht_devise);
1195 $sql .=
', multicurrency_total_ht = '.price2num($multicurrency_total_ht);
1196 $sql .=
', multicurrency_total_tva = '.price2num($multicurrency_total_tva);
1197 $sql .=
', multicurrency_total_ttc = '.price2num($multicurrency_total_ttc);
1198 $sql .=
" WHERE rowid = ".((int) $rowid);
1200 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
1201 if ($this->
db->query($sql)) {
1206 $this->error = $this->
db->lasterror();
1220 if (empty($this->date_when)) {
1234 if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) {
1249 return ($this->
isMaxNbGenReached() ?
'<strike>' :
'').$ret.($this->isMaxNbGenReached() ?
'</strike>' :
'');
1265 global $conf, $langs, $db, $user, $hookmanager;
1271 $langs->loadLangs(array(
"main",
"bills"));
1275 $today =
dol_mktime(23, 59, 59, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year']);
1277 dol_syslog(
"createRecurringInvoices restrictioninvoiceid=".$restrictioninvoiceid.
" forcevalidation=".$forcevalidation);
1279 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'facture_rec';
1280 $sql .=
' WHERE frequency > 0';
1281 $sql .=
" AND (date_when IS NULL OR date_when <= '".$this->db->idate($today).
"')";
1282 $sql .=
' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
1283 $sql .=
' AND suspended = 0';
1284 $sql .=
' AND entity = '.$conf->entity;
1285 if ($restrictioninvoiceid > 0) {
1286 $sql .=
' AND rowid = '.((int) $restrictioninvoiceid);
1288 $sql .= $this->
db->order(
'entity',
'ASC');
1290 $parameters = array(
1291 'restrictioninvoiceid' => $restrictioninvoiceid,
1292 'forcevalidation' => $forcevalidation,
1294 $reshook = $hookmanager->executeHooks(
'beforeCreationOfRecurringInvoices', $parameters, $sql);
1299 $num = $this->
db->num_rows(
$resql);
1302 $this->output .= $langs->trans(
"FoundXQualifiedRecurringInvoiceTemplate", $num).
"\n";
1304 $this->output .= $langs->trans(
"NoQualifiedRecurringInvoiceTemplateFound");
1307 $saventity = $conf->entity;
1310 $line = $this->
db->fetch_object(
$resql);
1314 $invoiceidgenerated = 0;
1318 $facturerec->fetch($line->rowid);
1320 if ($facturerec->id > 0) {
1322 $conf->entity = $facturerec->entity;
1324 dol_syslog(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref.
", entity=".$facturerec->entity);
1327 $facture->fac_rec = $facturerec->id;
1328 $facture->fk_fac_rec_source = $facturerec->id;
1330 $facture->type = self::TYPE_STANDARD;
1331 $facture->brouillon = 1;
1332 $facture->statut = self::STATUS_DRAFT;
1333 $facture->status = self::STATUS_DRAFT;
1334 $facture->date = (empty($facturerec->date_when) ? $now : $facturerec->date_when);
1335 $facture->socid = $facturerec->socid;
1336 if (!empty($facturerec->fk_multicurrency)) {
1337 $facture->fk_multicurrency = $facturerec->fk_multicurrency;
1338 $facture->multicurrency_code = $facturerec->multicurrency_code;
1339 $facture->multicurrency_tx = $facturerec->multicurrency_tx;
1342 $invoiceidgenerated = $facture->create($user);
1343 if ($invoiceidgenerated <= 0) {
1344 $this->errors = $facture->errors;
1345 $this->error = $facture->error;
1350 if (!$error && ($facturerec->auto_validate || $forcevalidation)) {
1351 $result = $facture->validate($user);
1353 $this->errors = $facture->errors;
1354 $this->error = $facture->error;
1358 if (!$error && $facturerec->generate_pdf) {
1360 $facture->fetch($facture->id);
1361 $result = $facture->generateDocument($facturerec->model_pdf, $langs);
1363 $this->errors = $facture->errors;
1364 $this->error = $facture->error;
1368 if (!$error && !$notrigger) {
1370 $result = $facturerec->call_trigger(
'BILLREC_CREATEBILL', $user);
1372 $this->errors = $facturerec->errors;
1373 $this->error = $facturerec->error;
1380 $this->error =
"Failed to load invoice template with id=".$line->rowid.
", entity=".$conf->entity.
"\n";
1381 $this->errors[] =
"Failed to load invoice template with id=".$line->rowid.
", entity=".$conf->entity;
1382 dol_syslog(
"createRecurringInvoices Failed to load invoice template with id=".$line->rowid.
", entity=".$conf->entity);
1385 if (!$error && $invoiceidgenerated >= 0) {
1386 $this->
db->commit(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref);
1387 dol_syslog(
"createRecurringInvoices Process invoice template ".$facturerec->ref.
" is finished with a success generation");
1389 $this->output .= $langs->trans(
"InvoiceGeneratedFromTemplate", $facture->ref, $facturerec->ref).
"\n";
1391 $this->
db->rollback(
"createRecurringInvoices Process invoice template id=".$facturerec->id.
", ref=".$facturerec->ref);
1394 $parameters = array(
1397 'errorCount' => $error,
1398 'invoiceidgenerated' => $invoiceidgenerated,
1399 'facturerec' => $facturerec,
1402 $reshook = $hookmanager->executeHooks(
'afterCreationOfRecurringInvoice', $parameters, $facture);
1407 $conf->entity = $saventity;
1412 $this->output = trim($this->output);
1414 return $error ? $error : 0;
1429 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'', $notooltip =
'', $save_lastsearch_value = -1)
1431 global $langs, $hookmanager;
1435 $label =
'<u>'.$langs->trans(
"RepeatableInvoice").
'</u>';
1436 if (!empty($this->
ref)) {
1437 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1439 if ($this->frequency > 0) {
1440 $label .=
'<br><b>'.$langs->trans(
'Frequency').
':</b> '.$langs->trans(
'FrequencyPer_'.$this->unit_frequency, $this->frequency);
1442 if (!empty($this->date_last_gen)) {
1443 $label .=
'<br><b>'.$langs->trans(
'DateLastGeneration').
':</b> '.
dol_print_date($this->date_last_gen,
'dayhour');
1445 if ($this->frequency > 0) {
1446 if (!empty($this->date_when)) {
1447 $label .=
'<br><b>'.$langs->trans(
'NextDateToExecution').
':</b> ';
1448 $label .= (empty($this->suspended) ?
'' :
'<strike>').
dol_print_date($this->date_when,
'day').(empty($this->suspended) ?
'' :
'</strike>');
1449 if (!empty($this->suspended)) {
1450 $label .=
' ('.$langs->trans(
"Disabled").
')';
1455 $url = DOL_URL_ROOT.
'/compta/facture/card-rec.php?facid='.$this->id;
1461 if ($option !=
'nolink') {
1463 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1464 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1465 $add_save_lastsearch_values = 1;
1467 if ($add_save_lastsearch_values) {
1468 $url .=
'&save_lastsearch_values=1';
1472 $linkstart =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
1475 $result .= $linkstart;
1477 $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);
1479 if ($withpicto != 2) {
1480 $result .= $this->ref;
1482 $result .= $linkend;
1484 $hookmanager->initHooks(array($this->element .
'dao'));
1485 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1486 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1488 $result = $hookmanager->resPrint;
1490 $result .= $hookmanager->resPrint;
1504 return $this->
LibStatut($this->frequency ? 1 : 0, $this->suspended, $mode, $alreadypaid, empty($this->
type) ? 0 : $this->
type);
1518 public function LibStatut($recur, $status, $mode = 0, $alreadypaid = -1, $type = 0)
1522 $langs->load(
'bills');
1524 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1525 $statusType =
'status0';
1530 if ($status == self::STATUS_SUSPENDED) {
1531 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1533 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1536 if ($status == self::STATUS_SUSPENDED) {
1537 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1539 $labelStatus = $langs->transnoentitiesnoconv(
"Draft");
1542 } elseif ($mode == 1) {
1545 if ($status == self::STATUS_SUSPENDED) {
1546 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1548 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1551 if ($status == self::STATUS_SUSPENDED) {
1552 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1554 $labelStatus = $langs->transnoentitiesnoconv(
"Draft");
1557 } elseif ($mode == 2) {
1559 if ($status == self::STATUS_SUSPENDED) {
1560 $statusType =
'status6';
1561 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1563 $statusType =
'status4';
1564 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1567 if ($status == self::STATUS_SUSPENDED) {
1568 $statusType =
'status6';
1569 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1571 $statusType =
'status0';
1572 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1575 } elseif ($mode == 3) {
1578 if ($status == self::STATUS_SUSPENDED) {
1579 $statusType =
'status6';
1580 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1582 $statusType =
'status4';
1583 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1586 if ($status == self::STATUS_SUSPENDED) {
1587 $statusType =
'status6';
1588 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1590 $statusType =
'status0';
1591 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1594 } elseif ($mode == 4) {
1597 if ($status == self::STATUS_SUSPENDED) {
1598 $statusType =
'status6';
1599 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1601 $statusType =
'status4';
1602 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1605 if ($status == self::STATUS_SUSPENDED) {
1606 $statusType =
'status6';
1607 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1609 $statusType =
'status0';
1610 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1613 } elseif ($mode == 5 || $mode == 6) {
1619 if ($status == self::STATUS_SUSPENDED) {
1620 $statusType =
'status6';
1621 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1623 $statusType =
'status4';
1624 $labelStatus = $langs->transnoentitiesnoconv(
'Active');
1627 if ($status == self::STATUS_SUSPENDED) {
1628 $statusType =
'status6';
1629 $labelStatus = $langs->transnoentitiesnoconv(
'Disabled');
1631 $statusType =
'status0';
1632 $labelStatus = $langs->transnoentitiesnoconv(
'Draft');
1637 $labelStatusShort = $labelStatus;
1639 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1652 global $user, $langs, $conf;
1656 $nownotime =
dol_mktime(0, 0, 0, $arraynow[
'mon'], $arraynow[
'mday'], $arraynow[
'year']);
1662 $sql =
"SELECT rowid";
1663 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
1664 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
1665 $sql .= $this->
db->plimit(100);
1669 $num_prods = $this->
db->num_rows(
$resql);
1671 while ($i < $num_prods) {
1673 $row = $this->
db->fetch_row(
$resql);
1674 $prodids[$i] = $row[0];
1680 $this->
ref =
'SPECIMEN';
1681 $this->title =
'SPECIMEN';
1682 $this->specimen = 1;
1684 $this->date = $nownotime;
1685 $this->date_lim_reglement = $nownotime + 3600 * 24 * 30;
1686 $this->cond_reglement_id = 1;
1687 $this->cond_reglement_code =
'RECEP';
1689 $this->mode_reglement_id = 0;
1690 $this->mode_reglement_code =
'';
1691 $this->note_public =
'This is a comment (public)';
1692 $this->note_private =
'This is a comment (private)';
1693 $this->note =
'This is a comment (private)';
1694 $this->fk_incoterms = 0;
1695 $this->location_incoterms =
'';
1697 if (empty($option) || $option !=
'nolines') {
1701 while ($xnbp < $nbp) {
1703 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1705 $line->subprice = 100;
1706 $line->tva_tx = 19.6;
1707 $line->localtax1_tx = 0;
1708 $line->localtax2_tx = 0;
1709 $line->remise_percent = 0;
1711 $prodid = mt_rand(1, $num_prods);
1712 $line->fk_product = $prodids[$prodid];
1714 $line->total_ht = -100;
1715 $line->total_ttc = -119.6;
1716 $line->total_tva = -19.6;
1717 } elseif ($xnbp == 2) {
1718 $line->subprice = -100;
1719 $line->total_ht = -100;
1720 $line->total_ttc = -119.6;
1721 $line->total_tva = -19.6;
1722 $line->remise_percent = 0;
1723 } elseif ($xnbp == 3) {
1724 $prodid = mt_rand(1, $num_prods);
1725 $line->fk_product = $prodids[$prodid];
1726 $line->total_ht = 50;
1727 $line->total_ttc = 59.8;
1728 $line->total_tva = 9.8;
1729 $line->remise_percent = 50;
1732 $prodid = mt_rand(1, $num_prods);
1733 $line->fk_product = $prodids[$prodid];
1734 $line->total_ht = 100;
1735 $line->total_ttc = 119.6;
1736 $line->total_tva = 19.6;
1737 $line->remise_percent = 00;
1740 $this->lines[$xnbp] = $line;
1743 $this->total_ht += $line->total_ht;
1744 $this->total_tva += $line->total_tva;
1745 $this->total_ttc += $line->total_ttc;
1747 $this->revenuestamp = 0;
1751 $line->desc = $langs->trans(
"Description").
" (offered line)";
1753 $line->subprice = 100;
1754 $line->tva_tx = 19.6;
1755 $line->localtax1_tx = 0;
1756 $line->localtax2_tx = 0;
1757 $line->remise_percent = 100;
1758 $line->total_ht = 0;
1759 $line->total_ttc = 0;
1760 $line->total_tva = 0;
1761 $prodid = mt_rand(1, $num_prods);
1762 $line->fk_product = $prodids[$prodid];
1764 $this->lines[$xnbp] = $line;
1768 $this->usenewprice = 0;
1817 if (!$this->table_element) {
1818 dol_syslog(get_class($this).
"::setFrequencyAndUnit was called on objet with property table_element not defined", LOG_ERR);
1822 if (!empty($frequency) && empty($unit)) {
1823 dol_syslog(get_class($this).
"::setFrequencyAndUnit was called on objet with params frequency defined but unit not defined", LOG_ERR);
1827 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1828 $sql .=
' SET frequency = '.($frequency ? $this->
db->escape($frequency) :
'null');
1829 if (!empty($unit)) {
1830 $sql .=
', unit_frequency = \''.$this->db->escape($unit).
'\'';
1832 $sql .=
" WHERE rowid = ".((int) $this->
id);
1834 dol_syslog(get_class($this).
"::setFrequencyAndUnit", LOG_DEBUG);
1835 if ($this->
db->query($sql)) {
1836 $this->frequency = $frequency;
1837 if (!empty($unit)) {
1838 $this->unit_frequency = $unit;
1843 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
1865 public function setNextDate($date, $increment_nb_gen_done = 0, $notrigger = 0)
1870 if (!$this->table_element) {
1871 dol_syslog(get_class($this).
"::setNextDate was called on objet with property table_element not defined", LOG_ERR);
1874 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1875 $sql .=
" SET date_when = ".($date ?
"'".$this->db->idate($date).
"'" :
"null");
1876 if ($increment_nb_gen_done > 0) {
1877 $sql .=
', nb_gen_done = nb_gen_done + 1';
1879 $sql .=
" WHERE rowid = ".((int) $this->
id);
1881 dol_syslog(get_class($this).
"::setNextDate", LOG_DEBUG);
1882 if ($this->
db->query($sql)) {
1883 $this->date_when = $date;
1884 if ($increment_nb_gen_done > 0) {
1885 $this->nb_gen_done++;
1890 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
1915 if (!$this->table_element) {
1916 dol_syslog(get_class($this).
"::setMaxPeriod was called on objet with property table_element not defined", LOG_ERR);
1924 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1925 $sql .=
' SET nb_gen_max = '.((int) $nb);
1926 $sql .=
" WHERE rowid = ".((int) $this->
id);
1928 dol_syslog(get_class($this).
"::setMaxPeriod", LOG_DEBUG);
1929 if ($this->
db->query($sql)) {
1930 $this->nb_gen_max = $nb;
1934 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
1959 if (!$this->table_element) {
1960 dol_syslog(get_class($this).
"::setAutoValidate was called on objet with property table_element not defined", LOG_ERR);
1964 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1965 $sql .=
' SET auto_validate = '.((int) $validate);
1966 $sql .=
" WHERE rowid = ".((int) $this->
id);
1968 dol_syslog(get_class($this).
"::setAutoValidate", LOG_DEBUG);
1969 if ($this->
db->query($sql)) {
1970 $this->auto_validate = $validate;
1974 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
1999 if (!$this->table_element) {
2000 dol_syslog(get_class($this).
"::setGeneratePdf was called on objet with property table_element not defined", LOG_ERR);
2004 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2005 $sql .=
' SET generate_pdf = '.((int) $validate);
2006 $sql .=
" WHERE rowid = ".((int) $this->
id);
2008 dol_syslog(get_class($this).
"::setGeneratePdf", LOG_DEBUG);
2009 if ($this->
db->query($sql)) {
2010 $this->generate_pdf = $validate;
2014 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2038 if (!$this->table_element) {
2039 dol_syslog(get_class($this).
"::setModelPdf was called on objet with property table_element not defined", LOG_ERR);
2043 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2044 $sql .=
" SET modelpdf = '".$this->db->escape($model).
"'";
2045 $sql .=
" WHERE rowid = ".((int) $this->
id);
2047 dol_syslog(get_class($this).
"::setModelPdf", LOG_DEBUG);
2048 if ($this->
db->query($sql)) {
2049 $this->model_pdf = $model;
2053 $result = $this->
call_trigger(
'BILLREC_MODIFY', $user);
2079 public $element =
'facturedetrec';
2084 public $table_element =
'facturedet_rec';
2087 public $fk_product_fournisseur_price;
2088 public $fk_fournprice;
2093 public $description;
2095 public $fk_product_type;
2097 public $fk_contract_line;
2107 public function delete(
User $user, $notrigger =
false)
2116 $result = $this->
call_trigger(
'LINEBILLREC_DELETE', $user);
2132 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
' WHERE rowid='.((int) $this->
id);
2134 $res = $this->
db->query($sql);
2137 $this->errors[] = $this->
db->lasterror();
2143 $this->
db->rollback();
2146 $this->
db->commit();
2160 $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,';
2161 $sql .=
' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
2162 $sql .=
' l.date_start_fill, l.date_end_fill, l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
2163 $sql .=
' l.rang, l.special_code,';
2164 $sql .=
' l.fk_unit, l.fk_contract_line,';
2165 $sql .=
' l.import_key, l.fk_multicurrency,';
2166 $sql .=
' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
2167 $sql .=
' l.buy_price_ht, l.fk_product_fournisseur_price,';
2168 $sql .=
' l.fk_user_author, l.fk_user_modif,';
2169 $sql .=
' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
2170 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facturedet_rec as l';
2171 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
2172 $sql .=
' WHERE l.rowid = '.((int) $rowid);
2173 $sql .=
' ORDER BY l.rang';
2176 $result = $this->
db->query($sql);
2178 $objp = $this->
db->fetch_object($result);
2180 $this->
id = $objp->rowid;
2181 $this->label = $objp->custom_label;
2182 $this->desc = $objp->description;
2184 $this->product_type = $objp->product_type;
2185 $this->
ref = $objp->product_ref;
2186 $this->product_ref = $objp->product_ref;
2187 $this->libelle = $objp->product_label;
2188 $this->product_label = $objp->product_label;
2189 $this->product_desc = $objp->product_desc;
2190 $this->fk_product_type = $objp->fk_product_type;
2191 $this->qty = $objp->qty;
2192 $this->
price = $objp->price;
2193 $this->subprice = $objp->subprice;
2194 $this->fk_facture = $objp->fk_facture;
2195 $this->vat_src_code = $objp->vat_src_code;
2196 $this->tva_tx = $objp->tva_tx;
2197 $this->localtax1_tx = $objp->localtax1_tx;
2198 $this->localtax2_tx = $objp->localtax2_tx;
2199 $this->localtax1_type = $objp->localtax1_type;
2200 $this->localtax2_type = $objp->localtax2_type;
2201 $this->remise_percent = $objp->remise_percent;
2203 $this->fk_product = $objp->fk_product;
2204 $this->date_start_fill = $objp->date_start_fill;
2205 $this->date_end_fill = $objp->date_end_fill;
2206 $this->info_bits = $objp->info_bits;
2207 $this->total_ht = $objp->total_ht;
2208 $this->total_tva = $objp->total_tva;
2209 $this->total_ttc = $objp->total_ttc;
2211 $this->rang = $objp->rang;
2212 $this->special_code = $objp->special_code;
2213 $this->fk_unit = $objp->fk_unit;
2214 $this->fk_contract_line = $objp->fk_contract_line;
2215 $this->import_key = $objp->import_key;
2216 $this->fk_multicurrency = $objp->fk_multicurrency;
2217 $this->multicurrency_code = $objp->multicurrency_code;
2218 $this->multicurrency_subprice = $objp->multicurrency_subprice;
2219 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
2220 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
2221 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2223 $this->buy_price_ht = $objp->buy_price_ht;
2225 $this->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
2226 $this->fk_user_author = $objp->fk_user_author;
2227 $this->fk_user_modif = $objp->fk_user_modif;
2229 $this->
db->free($result);
2232 $this->error = $this->
db->lasterror();
2251 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2253 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facturedet_rec SET";
2254 $sql .=
" fk_facture = ".((int) $this->fk_facture);
2255 $sql .=
", label=".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null");
2256 $sql .=
", description='".$this->db->escape($this->desc).
"'";
2257 $sql .=
", price=".price2num($this->
price);
2258 $sql .=
", qty=".price2num($this->qty);
2259 $sql .=
", tva_tx=".price2num($this->tva_tx);
2260 $sql .=
", vat_src_code='".$this->db->escape($this->vat_src_code).
"'";
2261 $sql .=
", localtax1_tx=".price2num($this->localtax1_tx);
2262 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
2263 $sql .=
", localtax2_tx=".price2num($this->localtax2_tx);
2264 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
2265 $sql .=
", fk_product=".($this->fk_product > 0 ? $this->fk_product :
"null");
2266 $sql .=
", product_type=".((int) $this->product_type);
2267 $sql .=
", remise_percent=".price2num($this->remise_percent);
2268 $sql .=
", subprice=".price2num($this->subprice);
2269 $sql .=
", info_bits=".price2num($this->info_bits);
2270 $sql .=
", date_start_fill=".(int) $this->date_start_fill;
2271 $sql .=
", date_end_fill=".(int) $this->date_end_fill;
2272 if (empty($this->skip_update_total)) {
2273 $sql .=
", total_ht=".price2num($this->total_ht);
2274 $sql .=
", total_tva=".price2num($this->total_tva);
2275 $sql .=
", total_localtax1=".price2num($this->total_localtax1);
2276 $sql .=
", total_localtax2=".price2num($this->total_localtax2);
2277 $sql .=
", total_ttc=".price2num($this->total_ttc);
2279 $sql .=
", rang=".((int) $this->rang);
2280 $sql .=
", special_code=".((int) $this->special_code);
2281 $sql .=
", fk_unit=".($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
"null");
2282 $sql .=
", fk_contract_line=".($this->fk_contract_line ? $this->fk_contract_line :
"null");
2283 $sql .=
" WHERE rowid = ".((int) $this->
id);
2287 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
2298 if (!$error && !$notrigger) {
2300 $result = $this->
call_trigger(
'LINEBILLREC_MODIFY', $user);
2308 $this->
db->rollback();
2311 $this->
db->commit();
2315 $this->error = $this->
db->lasterror();
2316 $this->
db->rollback();
create($user, $facid, $notrigger=0)
Create a predefined invoice.
calculate_date_lim_reglement($cond_reglement=0)
Returns an invoice payment deadline based on the invoice settlement conditions and billing date...
setAutoValidate($validate, $notrigger=0)
Update the auto validate flag of invoice.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Class to manage invoice lines of templates.
setMaxPeriod($nb, $notrigger=0)
Update the maximum period.
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...
getMarginInfos($pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $paht)
Return an array with margins information of a line.
setNextDate($date, $increment_nb_gen_done=0, $notrigger=0)
Update the next date of execution.
getNomUrl($withpicto=0, $option= '', $max=0, $short=0, $moretitle= '', $notooltip= '', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
$conf db
API class for accounts.
initAsSpecimen($option= '')
Initialise an instance with random values.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
deleteObjectLinked($sourceid=null, $sourcetype= '', $targetid=null, $targettype= '', $rowid= '', $f_user=null, $notrigger=0)
Delete all links between an object $this.
Class to manage invoice templates.
static commonReplaceProduct(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
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.
Class to manage Dolibarr users.
Class to manage Dolibarr database access.
getLinesArray()
Create an array of invoice lines.
getNextDate()
Return the next date of.
fetch($rowid, $ref= '', $ref_ext= '')
Load object and lines.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
Parent class of all other business classes for details of elements (invoices, contracts, proposals, orders, ...)
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
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...
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
fetch_lines()
Get lines of template invoices into this->lines.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
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.
update(User $user, $notrigger=0)
Update a line to invoice_rec.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
deleteExtraFields()
Delete all extra fields values for the current object.
setModelPdf($model, $notrigger=0)
Update the model for documents.
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...
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Superclass for invoices classes.
strikeIfMaxNbGenReached($ret)
Format string to output with by striking the string if max number of generation was reached...
fetch($rowid)
Get line of template invoice.
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.
div float
Buy price without taxes.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add objects linked in llx_element_element.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
LibStatut($recur, $status, $mode=0, $alreadypaid=-1, $type=0)
Return label of a status.
__construct(DoliDB $db)
Constructor.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
isMaxNbGenReached()
Return if maximum number of generation is reached.
Class to manage invoices.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
setFrequencyAndUnit($frequency, $unit, $notrigger=0)
Update frequency and unit.
update(User $user, $notrigger=0)
Update a line to invoice_rec.
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)...
setGeneratePdf($validate, $notrigger=0)
Update the auto generate documents.
createRecurringInvoices($restrictioninvoiceid=0, $forcevalidation=0, $notrigger=0)
Create all recurrents invoices (for all entities if multicompany is used).
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
getLibStatut($mode=0, $alreadypaid=-1)
Return label of object status.
Class to manage invoice lines.