dolibarr 21.0.0-alpha
facture-rec.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
7 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2017-2024 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2023 Nick Fragoulis
11 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
33require_once DOL_DOCUMENT_ROOT.'/core/class/commoninvoice.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
35require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
36require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
37require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/factureligne.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
39
40
45{
46 const TRIGGER_PREFIX = 'BILLREC';
50 public $element = 'facturerec';
51
55 public $table_element = 'facture_rec';
56
60 public $table_element_line = 'facturedet_rec';
61
65 public $fk_element = 'fk_facture';
66
70 public $picto = 'bill';
71
75 public $entity;
76
80 protected $table_ref_field = 'titre';
81
85 public $title;
86
91 public $titre;
92
96 public $multicurrency_subprice;
100 public $socid;
104 public $number;
108 public $date;
109 //public $remise;
110 //public $remise_absolue;
111 //public $remise_percent;
112
118 public $total;
119
125 public $tva;
126
130 public $date_last_gen;
134 public $date_when;
138 public $nb_gen_done;
142 public $nb_gen_max;
143
147 public $user_author;
148
152 public $frequency;
153
157 public $unit_frequency;
158
162 public $rang;
163
167 public $special_code;
168
172 public $usenewprice = 0;
173
177 public $date_lim_reglement;
181 public $cond_reglement_code; // Code in llx_c_paiement
185 public $mode_reglement_code; // Code in llx_c_paiement
186
190 public $suspended; // status
191
195 public $auto_validate; // 0 to create in draft, 1 to create and validate the new invoice
199 public $generate_pdf; // 1 to generate PDF on invoice generation (default)
200
201
226 // BEGIN MODULEBUILDER PROPERTIES
230 public $fields = array(
231 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
232 'titre' => array('type' => 'varchar(100)', 'label' => 'Titre', 'enabled' => 1, 'showoncombobox' => 1, 'visible' => -1, 'position' => 15),
233 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 20, 'index' => 1),
234 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => 'isModEnabled("societe")', 'visible' => -1, 'notnull' => 1, 'position' => 25),
235 'subtype' => array('type' => 'smallint(6)', 'label' => 'InvoiceSubtype', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 30),
236 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'position' => 35),
237 'total_tva' => array('type' => 'double(24,8)', 'label' => 'Tva', 'enabled' => 1, 'visible' => -1, 'position' => 55, 'isameasure' => 1),
238 'localtax1' => array('type' => 'double(24,8)', 'label' => 'Localtax1', 'enabled' => 1, 'visible' => -1, 'position' => 60, 'isameasure' => 1),
239 'localtax2' => array('type' => 'double(24,8)', 'label' => 'Localtax2', 'enabled' => 1, 'visible' => -1, 'position' => 65, 'isameasure' => 1),
240 'total_ht' => array('type' => 'double(24,8)', 'label' => 'Total', 'enabled' => 1, 'visible' => -1, 'position' => 70, 'isameasure' => 1),
241 'total_ttc' => array('type' => 'double(24,8)', 'label' => 'Total ttc', 'enabled' => 1, 'visible' => -1, 'position' => 75, 'isameasure' => 1),
242 'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user author', 'enabled' => 1, 'visible' => -1, 'position' => 80),
243 '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),
244 'fk_cond_reglement' => array('type' => 'integer', 'label' => 'Fk cond reglement', 'enabled' => 1, 'visible' => -1, 'position' => 90),
245 'fk_mode_reglement' => array('type' => 'integer', 'label' => 'Fk mode reglement', 'enabled' => 1, 'visible' => -1, 'position' => 95),
246 'date_lim_reglement' => array('type' => 'date', 'label' => 'Date lim reglement', 'enabled' => 1, 'visible' => -1, 'position' => 100),
247 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 105),
248 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 110),
249 'modelpdf' => array('type' => 'varchar(255)', 'label' => 'Modelpdf', 'enabled' => 1, 'visible' => -1, 'position' => 115),
250 'date_when' => array('type' => 'datetime', 'label' => 'Date when', 'enabled' => 1, 'visible' => -1, 'position' => 130),
251 'date_last_gen' => array('type' => 'datetime', 'label' => 'Date last gen', 'enabled' => 1, 'visible' => -1, 'position' => 135),
252 'nb_gen_done' => array('type' => 'integer', 'label' => 'Nb gen done', 'enabled' => 1, 'visible' => -1, 'position' => 140),
253 'nb_gen_max' => array('type' => 'integer', 'label' => 'Nb gen max', 'enabled' => 1, 'visible' => -1, 'position' => 145),
254 'frequency' => array('type' => 'integer', 'label' => 'Frequency', 'enabled' => 1, 'visible' => -1, 'position' => 150),
255 'unit_frequency' => array('type' => 'varchar(2)', 'label' => 'UnitFrequency', 'enabled' => 1, 'visible' => -1, 'position' => 152),
256 'usenewprice' => array('type' => 'integer', 'label' => 'UseNewPrice', 'enabled' => 1, 'visible' => 0, 'position' => 155),
257 'revenuestamp' => array('type' => 'double(24,8)', 'label' => 'RevenueStamp', 'enabled' => 1, 'visible' => -1, 'position' => 160, 'isameasure' => 1),
258 'auto_validate' => array('type' => 'integer', 'label' => 'Auto validate', 'enabled' => 1, 'visible' => -1, 'position' => 165),
259 'generate_pdf' => array('type' => 'integer', 'label' => 'Generate pdf', 'enabled' => 1, 'visible' => -1, 'position' => 170),
260 'fk_account' => array('type' => 'integer', 'label' => 'Fk account', 'enabled' => 'isModEnabled("bank")', 'visible' => -1, 'position' => 175),
261 'fk_multicurrency' => array('type' => 'integer', 'label' => 'Fk multicurrency', 'enabled' => 1, 'visible' => -1, 'position' => 180),
262 'multicurrency_code' => array('type' => 'varchar(255)', 'label' => 'Multicurrency code', 'enabled' => 1, 'visible' => -1, 'position' => 185),
263 'multicurrency_tx' => array('type' => 'double(24,8)', 'label' => 'Multicurrency tx', 'enabled' => 1, 'visible' => -1, 'position' => 190, 'isameasure' => 1),
264 'multicurrency_total_ht' => array('type' => 'double(24,8)', 'label' => 'Multicurrency total ht', 'enabled' => 1, 'visible' => -1, 'position' => 195, 'isameasure' => 1),
265 'multicurrency_total_tva' => array('type' => 'double(24,8)', 'label' => 'Multicurrency total tva', 'enabled' => 1, 'visible' => -1, 'position' => 200, 'isameasure' => 1),
266 'multicurrency_total_ttc' => array('type' => 'double(24,8)', 'label' => 'Multicurrency total ttc', 'enabled' => 1, 'visible' => -1, 'position' => 205, 'isameasure' => 1),
267 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'position' => 210),
268 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 215),
269 'suspended' => array('type' => 'integer', 'label' => 'Suspended', 'enabled' => 1, 'visible' => -1, 'position' => 225),
270 );
271 // END MODULEBUILDER PROPERTIES
272
273 const STATUS_NOTSUSPENDED = 0;
274 const STATUS_SUSPENDED = 1;
275
276
277
283 public function __construct(DoliDB $db)
284 {
285 $this->db = $db;
286 }
287
297 public function create($user, $facid, $notrigger = 0, $onlylines = array())
298 {
299 global $conf;
300
301 $error = 0;
302 $now = dol_now();
303
304 // Clean parameters
305 $this->titre = trim(isset($this->titre) ? $this->titre : $this->title); // deprecated
306 $this->title = trim($this->title);
307 $this->usenewprice = empty($this->usenewprice) ? 0 : $this->usenewprice;
308 if (empty($this->suspended)) {
309 $this->suspended = 0;
310 }
311
312 // No frequency defined then no next date to execution
313 if (empty($this->frequency)) {
314 $this->frequency = 0;
315 $this->date_when = null;
316 }
317
318 $this->frequency = abs($this->frequency);
319 $this->nb_gen_done = 0;
320 $this->nb_gen_max = empty($this->nb_gen_max) ? 0 : $this->nb_gen_max;
321 $this->auto_validate = empty($this->auto_validate) ? 0 : $this->auto_validate;
322 $this->generate_pdf = empty($this->generate_pdf) ? 0 : $this->generate_pdf;
323
324 $this->db->begin();
325
326 // Load invoice template
327 $facsrc = new Facture($this->db);
328 $result = $facsrc->fetch($facid);
329 if ($result > 0) {
330 $this->socid = $facsrc->socid;
331
332 $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec (";
333 $sql .= "titre";
334 $sql .= ", fk_soc";
335 $sql .= ", subtype";
336 $sql .= ", entity";
337 $sql .= ", datec";
338 $sql .= ", amount";
339 //$sql .= ", remise";
340 $sql .= ", note_private";
341 $sql .= ", note_public";
342 $sql .= ", modelpdf";
343 $sql .= ", fk_user_author";
344 $sql .= ", fk_projet";
345 $sql .= ", fk_account";
346 $sql .= ", fk_cond_reglement";
347 $sql .= ", fk_mode_reglement";
348 $sql .= ", usenewprice";
349 $sql .= ", frequency";
350 $sql .= ", unit_frequency";
351 $sql .= ", date_when";
352 $sql .= ", date_last_gen";
353 $sql .= ", nb_gen_done";
354 $sql .= ", nb_gen_max";
355 $sql .= ", auto_validate";
356 $sql .= ", generate_pdf";
357 $sql .= ", fk_multicurrency";
358 $sql .= ", multicurrency_code";
359 $sql .= ", multicurrency_tx";
360 $sql .= ", suspended";
361 $sql .= ") VALUES (";
362 $sql .= "'".$this->db->escape($this->titre ? $this->titre : $this->title)."'";
363 $sql .= ", ".((int) $this->socid);
364 $sql .= ", ".($this->subtype ? "'".$this->db->escape($this->subtype)."'" : "null");
365 $sql .= ", ".((int) $conf->entity);
366 $sql .= ", '".$this->db->idate($now)."'";
367 $sql .= ", ".(!empty($facsrc->total_ttc) ? ((float) $facsrc->total_ttc) : '0');
368 //$sql .= ", ".(!empty($facsrc->remise_absolue) ? ((float) $this->remise_absolue) : '0');
369 $sql .= ", ".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL");
370 $sql .= ", ".(!empty($this->note_public) ? ("'".$this->db->escape($this->note_public)."'") : "NULL");
371 $sql .= ", ".(!empty($this->model_pdf) ? ("'".$this->db->escape($this->model_pdf)."'") : "NULL");
372 $sql .= ", ".((int) $user->id);
373 $sql .= ", ".(!empty($this->fk_project) ? ((int) $this->fk_project) : "null");
374 $sql .= ", ".(!empty($facsrc->fk_account) ? ((int) $facsrc->fk_account) : "null");
375 $sql .= ", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) : "null");
376 $sql .= ", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) : "null");
377 $sql .= ", ".((int) $this->usenewprice);
378 $sql .= ", ".((int) $this->frequency);
379 $sql .= ", '".$this->db->escape($this->unit_frequency)."'";
380 $sql .= ", ".(!empty($this->date_when) ? "'".$this->db->idate($this->date_when)."'" : 'NULL');
381 $sql .= ", ".(!empty($this->date_last_gen) ? "'".$this->db->idate($this->date_last_gen)."'" : 'NULL');
382 $sql .= ", ".((int) $this->nb_gen_done);
383 $sql .= ", ".((int) $this->nb_gen_max);
384 $sql .= ", ".((int) $this->auto_validate);
385 $sql .= ", ".((int) $this->generate_pdf);
386 $sql .= ", ".((int) $facsrc->fk_multicurrency);
387 $sql .= ", '".$this->db->escape($facsrc->multicurrency_code)."'";
388 $sql .= ", ".((float) $facsrc->multicurrency_tx);
389 $sql .= ", ".((int) $this->suspended);
390 $sql .= ")";
391
392 if ($this->db->query($sql)) {
393 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_rec");
394
395 // Fields used into addline later
396 $this->fk_multicurrency = $facsrc->fk_multicurrency;
397 $this->multicurrency_code = $facsrc->multicurrency_code;
398 $this->multicurrency_tx = $facsrc->multicurrency_tx;
399
400 // Add lines
401 $fk_parent_line = 0;
402
403 $num = count($facsrc->lines);
404 for ($i = 0; $i < $num; $i++) {
405 $facline = $facsrc->lines[$i];
406 '@phan-var-force FactureLigneRec $facline';
407 if (!empty($onlylines) && !in_array($facline->id, $onlylines)) {
408 continue; // Skip unselected lines
409 }
410
411 // Reset fk_parent_line for no child products and special product
412 if (($facline->product_type != 9 && empty($facline->fk_parent_line)) || $facline->product_type == 9) {
413 $fk_parent_line = 0;
414 }
415
416 $tva_tx = $facline->tva_tx;
417 if (!empty($facline->vat_src_code) && !preg_match('/\‍(/', (string) $tva_tx)) {
418 $tva_tx .= ' ('.$facline->vat_src_code.')';
419 }
420
421 $default_start_fill = getDolGlobalInt('INVOICEREC_SET_AUTOFILL_DATE_START');
422 $default_end_fill = getDolGlobalInt('INVOICEREC_SET_AUTOFILL_DATE_END');
423
424 $result_insert = $this->addline(
425 $facline->desc,
426 $facline->subprice,
427 $facline->qty,
428 $tva_tx,
429 $facline->localtax1_tx,
430 $facline->localtax2_tx,
431 $facline->fk_product,
432 $facline->remise_percent,
433 'HT',
434 $facline->info_bits,
435 0,
436 0,
437 $facline->product_type,
438 $facline->rang,
439 $facline->special_code,
440 $facline->label,
441 $facline->fk_unit,
442 $facline->multicurrency_subprice,
443 $default_start_fill,
444 $default_end_fill,
445 0,
446 $facline->pa_ht,
447 $fk_parent_line
448 );
449
450 // Defined the new fk_parent_line
451 if ($result_insert > 0 && $facline->product_type == 9) {
452 $fk_parent_line = $result_insert;
453 }
454
455 if ($result_insert < 0) {
456 $error++;
457 } else {
458 $objectline = new FactureLigneRec($this->db);
459
460 $result2 = $objectline->fetch($result_insert);
461 if ($result2 > 0) {
462 // Extrafields
463 if (method_exists($facline, 'fetch_optionals')) {
464 $facline->fetch_optionals($facline->id);
465 $objectline->array_options = $facline->array_options;
466 }
467
468 $result = $objectline->insertExtraFields();
469 if ($result < 0) {
470 $error++;
471 }
472 } elseif ($result2 < 0) {
473 $this->errors[] = $objectline->error;
474 $error++;
475 }
476 }
477 }
478
479 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) { // To use new linkedObjectsIds instead of old linked_objects
480 $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds
481 }
482
483 // Add object linked
484 if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
485 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
486 if (is_array($tmp_origin_id)) { // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
487 foreach ($tmp_origin_id as $origin_id) {
488 $ret = $this->add_object_linked($origin, $origin_id);
489 if (!$ret) {
490 $this->error = $this->db->lasterror();
491 $error++;
492 }
493 }
494 } else { // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1))
495 $origin_id = $tmp_origin_id;
496 $ret = $this->add_object_linked($origin, $origin_id);
497 if (!$ret) {
498 $this->error = $this->db->lasterror();
499 $error++;
500 }
501 }
502 }
503 }
504
505 if (!$error) {
506 $result = $this->insertExtraFields();
507 if ($result < 0) {
508 $error++;
509 }
510 }
511
512 if (!$error && !$notrigger) {
513 // Call trigger
514 $result = $this->call_trigger('BILLREC_CREATE', $user);
515 if ($result < 0) {
516 $this->db->rollback();
517 return -2;
518 }
519 // End call triggers
520 }
521
522 if ($error) {
523 $this->db->rollback();
524 return -3;
525 } else {
526 $this->db->commit();
527 return $this->id;
528 }
529 } else {
530 $this->error = $this->db->lasterror();
531 $this->db->rollback();
532 return -2;
533 }
534 } else {
535 $this->db->rollback();
536 return -1;
537 }
538 }
539
540
548 public function update(User $user, $notrigger = 0)
549 {
550 $error = 0;
551
552 $sql = "UPDATE ".MAIN_DB_PREFIX."facture_rec SET";
553 $sql .= " entity = ".((int) $this->entity).",";
554 $sql .= " titre = '".$this->db->escape($this->title)."',";
555 $sql .= " suspended = ".((int) $this->suspended).",";
556 $sql .= " fk_soc = ".((int) $this->socid).",";
557 $sql .= " total_tva = ".((float) $this->total_tva).",";
558 $sql .= " localtax1 = ".((float) $this->total_localtax1).",";
559 $sql .= " localtax2 = ".((float) $this->total_localtax2).",";
560 $sql .= " total_ht = ".((float) $this->total_ht).",";
561 $sql .= " total_ttc = ".((float) $this->total_ttc);
562 // TODO Add missing fields
563 $sql .= " WHERE rowid = ".((int) $this->id);
564
565 $this->db->begin();
566
567 dol_syslog(get_class($this)."::update", LOG_DEBUG);
568
569 $resql = $this->db->query($sql);
570 if ($resql) {
571 if (!$error) {
572 $result = $this->insertExtraFields();
573 if ($result < 0) {
574 $error++;
575 }
576 }
577
578 if (!$error && !$notrigger) {
579 // Call trigger
580 $result = $this->call_trigger('BILLREC_MODIFY', $user);
581 if ($result < 0) {
582 $this->db->rollback();
583 return -2;
584 }
585 // End call triggers
586 }
587 $this->db->commit();
588 return 1;
589 } else {
590 $this->error = $this->db->lasterror();
591 $this->db->rollback();
592 return -1;
593 }
594 }
595
606 public function fetch($rowid, $ref = '', $ref_ext = '', $noextrafields = 0, $nolines = 0)
607 {
608 dol_syslog('FactureRec::fetch', LOG_DEBUG);
609
610 $sql = 'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc, f.subtype, f.total_tva, f.localtax1, f.localtax2, f.total_ht, f.total_ttc';
611 $sql .= ', f.date_lim_reglement as dlr';
612 $sql .= ', f.note_private, f.note_public, f.fk_user_author';
613 $sql .= ', f.modelpdf as model_pdf';
614 $sql .= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet as fk_project';
615 $sql .= ', f.fk_account';
616 $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';
617 $sql .= ', f.generate_pdf';
618 $sql .= ", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
619 $sql .= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
620 $sql .= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
621 //$sql.= ', el.fk_source';
622 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_rec as f';
623 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
624 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id';
625 //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = f.rowid AND el.targettype = 'facture'";
626 $sql .= ' WHERE f.entity IN ('.getEntity('invoice').')';
627 if ($rowid) {
628 $sql .= ' AND f.rowid = '.((int) $rowid);
629 } elseif ($ref) {
630 $sql .= " AND f.titre = '".$this->db->escape($ref)."'";
631 } else {
632 $sql .= ' AND f.rowid = 0';
633 }
634 /* This field are not used for template invoice
635 if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'";
636 */
637
638 $result = $this->db->query($sql);
639 if ($result) {
640 if ($this->db->num_rows($result)) {
641 $obj = $this->db->fetch_object($result);
642
643 $this->id = $obj->rowid;
644 $this->entity = $obj->entity;
645 $this->titre = $obj->title; // deprecated
646 $this->title = $obj->title;
647 $this->ref = $obj->title;
648 $this->subtype = $obj->subtype;
649 $this->suspended = $obj->suspended;
650 $this->total_ht = $obj->total_ht;
651 $this->total_tva = $obj->total_tva;
652 $this->total_localtax1 = $obj->localtax1;
653 $this->total_localtax2 = $obj->localtax2;
654 $this->total_ttc = $obj->total_ttc;
655 $this->socid = $obj->fk_soc;
656 $this->date_lim_reglement = $this->db->jdate($obj->dlr);
657 $this->mode_reglement_id = $obj->fk_mode_reglement;
658 $this->mode_reglement_code = $obj->mode_reglement_code;
659 $this->mode_reglement = $obj->mode_reglement_libelle;
660 $this->cond_reglement_id = $obj->fk_cond_reglement;
661 $this->cond_reglement_code = $obj->cond_reglement_code;
662 $this->cond_reglement = $obj->cond_reglement_libelle;
663 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
664 $this->fk_project = $obj->fk_project;
665 $this->fk_account = $obj->fk_account;
666 $this->note_private = $obj->note_private;
667 $this->note_public = $obj->note_public;
668 $this->user_author = $obj->fk_user_author; // deprecated
669 $this->user_creation_id = $obj->fk_user_author;
670 $this->model_pdf = $obj->model_pdf;
671 //$this->special_code = $obj->special_code;
672 $this->frequency = $obj->frequency;
673 $this->unit_frequency = $obj->unit_frequency;
674 $this->date_when = $this->db->jdate($obj->date_when);
675 $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
676 $this->nb_gen_done = $obj->nb_gen_done;
677 $this->nb_gen_max = $obj->nb_gen_max;
678 $this->usenewprice = $obj->usenewprice;
679 $this->auto_validate = $obj->auto_validate;
680 $this->generate_pdf = $obj->generate_pdf;
681
682 // Multicurrency
683 $this->fk_multicurrency = $obj->fk_multicurrency;
684 $this->multicurrency_code = $obj->multicurrency_code;
685 $this->multicurrency_tx = $obj->multicurrency_tx;
686 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
687 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
688 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
689
690 // Retrieve all extrafield
691 // fetch optionals attributes and labels
692 if (empty($noextrafields)) {
693 $result = $this->fetch_optionals();
694 if ($result < 0) {
695 $this->error = $this->db->lasterror();
696 return -4;
697 }
698 }
699
700 // Retrieve lines
701 if (empty($nolines)) {
702 $result = $this->fetch_lines();
703 if ($result < 0) {
704 $this->error = $this->db->lasterror();
705 return -3;
706 }
707 }
708
709 return 1;
710 } else {
711 $this->error = 'Bill with id '.$rowid.' or ref '.$ref.' not found';
712 dol_syslog('Facture::Fetch Error '.$this->error, LOG_ERR);
713 return -2;
714 }
715 } else {
716 $this->error = $this->db->error();
717 return -1;
718 }
719 }
720
721
727 public function getLinesArray()
728 {
729 return $this->fetch_lines();
730 }
731
732
733 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
739 public function fetch_lines()
740 {
741 // phpcs:enable
742
743 $this->lines = array();
744
745 dol_syslog('FactureRec::fetch_lines', LOG_DEBUG);
746
747 $sql = 'SELECT l.rowid, l.fk_facture, l.fk_product, l.fk_parent_line, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx, ';
748 $sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
749 $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,';
750 $sql .= ' l.rang, l.special_code,';
751 $sql .= ' l.fk_unit, l.fk_contract_line,';
752 $sql .= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
753 $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
754 $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l';
755 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
756 $sql .= ' WHERE l.fk_facture = '.((int) $this->id);
757 $sql .= ' ORDER BY l.rang';
758
759 $result = $this->db->query($sql);
760 if ($result) {
761 $num = $this->db->num_rows($result);
762 $i = 0;
763 while ($i < $num) {
764 $objp = $this->db->fetch_object($result);
765 $line = new FactureLigneRec($this->db);
766
767 $line->id = $objp->rowid;
768 $line->rowid = $objp->rowid;
769 $line->fk_facture = $objp->fk_facture;
770 $line->fk_parent_line = $objp->fk_parent_line;
771 $line->desc = $objp->description; // Description line
772 $line->description = $objp->description; // Description line
773 $line->ref = $objp->product_ref; // Ref product
774 $line->product_ref = $objp->product_ref; // Ref product
775 $line->libelle = $objp->product_label; // deprecated
776 $line->product_label = $objp->product_label; // Label product
777 $line->product_desc = $objp->product_desc; // Description product
778 $line->product_type = $objp->product_type; // Type of line
779 $line->fk_product_type = $objp->fk_product_type; // Type of product
780 $line->qty = $objp->qty;
781 $line->subprice = $objp->subprice;
782
783 $line->label = $objp->custom_label; // @deprecated
784
785 $line->vat_src_code = $objp->vat_src_code;
786 $line->tva_tx = $objp->tva_tx;
787 $line->localtax1_tx = $objp->localtax1_tx;
788 $line->localtax2_tx = $objp->localtax2_tx;
789 $line->localtax1_type = $objp->localtax1_type;
790 $line->localtax2_type = $objp->localtax2_type;
791 $line->remise_percent = $objp->remise_percent;
792 //$line->fk_remise_except = $objp->fk_remise_except;
793 $line->fk_product = $objp->fk_product;
794 $line->date_start_fill = $objp->date_start_fill;
795 $line->date_end_fill = $objp->date_end_fill;
796 $line->info_bits = $objp->info_bits;
797 $line->total_ht = $objp->total_ht;
798 $line->total_tva = $objp->total_tva;
799 $line->total_ttc = $objp->total_ttc;
800
801 $line->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
802 $line->fk_fournprice = $objp->fk_product_fournisseur_price; // For backward compatibility
803
804 $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $objp->fk_product_fournisseur_price, $objp->pa_ht);
805
806 $line->buyprice = $marginInfos[0];
807 $line->pa_ht = $marginInfos[0]; // For backward compatibility
808 $line->marge_tx = $marginInfos[1];
809 $line->marque_tx = $marginInfos[2];
810 $line->rang = $objp->rang;
811 $line->special_code = $objp->special_code;
812 $line->fk_unit = $objp->fk_unit;
813 $line->fk_contract_line = $objp->fk_contract_line;
814
815 // Ne plus utiliser
816 $line->price = $objp->price;
817 $line->remise = $objp->remise;
818
819 $line->fetch_optionals();
820
821 // Multicurrency
822 $line->fk_multicurrency = $objp->fk_multicurrency;
823 $line->multicurrency_code = $objp->multicurrency_code;
824 $line->multicurrency_subprice = $objp->multicurrency_subprice;
825 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
826 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
827 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
828
829 $this->lines[$i] = $line;
830
831 $i++;
832 }
833
834 $this->db->free($result);
835 return 1;
836 } else {
837 $this->error = $this->db->lasterror();
838 return -3;
839 }
840 }
841
842
851 public function delete(User $user, $notrigger = 0, $idwarehouse = -1)
852 {
853 $rowid = $this->id;
854
855 dol_syslog(get_class($this)."::delete rowid=".((int) $rowid), LOG_DEBUG);
856
857 $error = 0;
858 $this->db->begin();
859
860 $main = MAIN_DB_PREFIX.'facturedet_rec';
861 $ef = $main."_extrafields";
862
863 $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM ".$main." WHERE fk_facture = ".((int) $rowid).")";
864 $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = ".((int) $rowid);
865
866 if ($this->db->query($sqlef) && $this->db->query($sql)) {
867 $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_rec WHERE rowid = ".((int) $rowid);
868 dol_syslog($sql);
869 if ($this->db->query($sql)) {
870 // Delete linked object
871 $res = $this->deleteObjectLinked();
872 if ($res < 0) {
873 $error = -3;
874 }
875 // Delete extrafields
876 $res = $this->deleteExtraFields();
877 if ($res < 0) {
878 $error = -4;
879 }
880 } else {
881 $this->error = $this->db->lasterror();
882 $error = -1;
883 }
884 } else {
885 $this->error = $this->db->lasterror();
886 $error = -2;
887 }
888 if (!$error && !$notrigger) {
889 // Call trigger
890 $result = $this->call_trigger('BILLREC_DELETE', $user);
891 if ($result < 0) {
892 $error++;
893 }
894 // End call triggers
895 }
896 if (!$error) {
897 $this->db->commit();
898 return 1;
899 } else {
900 $this->db->rollback();
901 return $error;
902 }
903 }
904
905
934 public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $fk_product = 0, $remise_percent = 0, $price_base_type = 'HT', $info_bits = 0, $fk_remise_except = 0, $pu_ttc = 0, $type = 0, $rang = -1, $special_code = 0, $label = '', $fk_unit = null, $pu_ht_devise = 0, $date_start_fill = 0, $date_end_fill = 0, $fk_fournprice = null, $pa_ht = 0, $fk_parent_line = 0)
935 {
936 global $mysoc;
937
938 $facid = $this->id;
939
940 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);
941 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
942
943 // Check parameters
944 if ($type < 0) {
945 return -1;
946 }
947
948 $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
949
950 // Clean vat code
951 $reg = array();
952 $vat_src_code = '';
953 if (preg_match('/\‍((.*)\‍)/', (string) $txtva, $reg)) {
954 $vat_src_code = $reg[1];
955 $txtva = preg_replace('/\s*\‍(.*\‍)/', '', (string) $txtva); // Remove code from vatrate.
956 }
957
958
959 // Clean parameters
960 $remise_percent = price2num($remise_percent);
961 if (empty($remise_percent)) {
962 $remise_percent = 0;
963 }
964 $qty = price2num($qty);
965 $pu_ht = price2num($pu_ht);
966 $pu_ttc = price2num($pu_ttc);
967 if (!preg_match('/\‍((.*)\‍)/', $txtva)) {
968 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
969 }
970 $txlocaltax1 = price2num($txlocaltax1);
971 $txlocaltax2 = price2num($txlocaltax2);
972 if (empty($txtva)) {
973 $txtva = 0;
974 }
975 if (empty($txlocaltax1)) {
976 $txlocaltax1 = 0;
977 }
978 if (empty($txlocaltax2)) {
979 $txlocaltax2 = 0;
980 }
981 if (empty($info_bits)) {
982 $info_bits = 0;
983 }
984
985 if ($price_base_type == 'HT') {
986 $pu = $pu_ht;
987 } else {
988 $pu = $pu_ttc;
989 }
990
991 // Calcul du total TTC et de la TVA pour la ligne a partir de
992 // qty, pu, remise_percent et txtva
993 // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
994 // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
995
996 $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);
997 $total_ht = $tabprice[0];
998 $total_tva = $tabprice[1];
999 $total_ttc = $tabprice[2];
1000 $total_localtax1 = $tabprice[9];
1001 $total_localtax2 = $tabprice[10];
1002 $pu_ht = $tabprice[3];
1003
1004 // MultiCurrency
1005 $multicurrency_total_ht = $tabprice[16];
1006 $multicurrency_total_tva = $tabprice[17];
1007 $multicurrency_total_ttc = $tabprice[18];
1008 $pu_ht_devise = $tabprice[19];
1009
1010 $product_type = $type;
1011 if ($fk_product) {
1012 $product = new Product($this->db);
1013 $result = $product->fetch($fk_product);
1014 $product_type = $product->type;
1015 }
1016
1017 if (empty($fk_parent_line) || $fk_parent_line < 0) {
1018 $fk_parent_line = 0;
1019 }
1020
1021 // Rank to use
1022 $ranktouse = $rang;
1023 if ($ranktouse == -1) {
1024 $rangmax = $this->line_max(0);
1025 $ranktouse = $rangmax + 1;
1026 }
1027
1028 $sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (";
1029 $sql .= "fk_facture";
1030 $sql .= ", fk_parent_line";
1031 $sql .= ", label";
1032 $sql .= ", description";
1033 $sql .= ", price";
1034 $sql .= ", qty";
1035 $sql .= ", tva_tx";
1036 $sql .= ", vat_src_code";
1037 $sql .= ", localtax1_tx";
1038 $sql .= ", localtax1_type";
1039 $sql .= ", localtax2_tx";
1040 $sql .= ", localtax2_type";
1041 $sql .= ", fk_product";
1042 $sql .= ", product_type";
1043 $sql .= ", remise_percent";
1044 $sql .= ", subprice";
1045 $sql .= ", remise";
1046 $sql .= ", total_ht";
1047 $sql .= ", total_tva";
1048 $sql .= ", total_localtax1";
1049 $sql .= ", total_localtax2";
1050 $sql .= ", total_ttc";
1051 $sql .= ", date_start_fill";
1052 $sql .= ", date_end_fill";
1053 $sql .= ", fk_product_fournisseur_price";
1054 $sql .= ", buy_price_ht";
1055 $sql .= ", info_bits";
1056 $sql .= ", rang";
1057 $sql .= ", special_code";
1058 $sql .= ", fk_unit";
1059 $sql .= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
1060 $sql .= ") VALUES (";
1061 $sql .= " ".((int) $facid);
1062 $sql .= ", ".($fk_parent_line > 0 ? ((int) $fk_parent_line) : "null");
1063 $sql .= ", ".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
1064 $sql .= ", '".$this->db->escape($desc)."'";
1065 $sql .= ", ".price2num($pu_ht);
1066 $sql .= ", ".price2num($qty);
1067 $sql .= ", ".price2num($txtva);
1068 $sql .= ", '".$this->db->escape($vat_src_code)."'";
1069 $sql .= ", ".price2num($txlocaltax1);
1070 $sql .= ", '".$this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] : '')."'";
1071 $sql .= ", ".price2num($txlocaltax2);
1072 $sql .= ", '".$this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] : '')."'";
1073 $sql .= ", ".(!empty($fk_product) ? "'".$this->db->escape($fk_product)."'" : "null");
1074 $sql .= ", ".((int) $product_type);
1075 $sql .= ", ".price2num($remise_percent);
1076 $sql .= ", ".price2num($pu_ht);
1077 $sql .= ", null";
1078 $sql .= ", ".price2num($total_ht);
1079 $sql .= ", ".price2num($total_tva);
1080 $sql .= ", ".price2num($total_localtax1);
1081 $sql .= ", ".price2num($total_localtax2);
1082 $sql .= ", ".price2num($total_ttc);
1083 $sql .= ", ".(int) $date_start_fill;
1084 $sql .= ", ".(int) $date_end_fill;
1085 $sql .= ", ".($fk_fournprice > 0 ? $fk_fournprice : 'null');
1086 $sql .= ", ".($pa_ht ? price2num($pa_ht) : 0);
1087 $sql .= ", ".((int) $info_bits);
1088 $sql .= ", ".((int) $ranktouse);
1089 $sql .= ", ".((int) $special_code);
1090 $sql .= ", ".($fk_unit ? ((int) $fk_unit) : "null");
1091 $sql .= ", ".(int) $this->fk_multicurrency;
1092 $sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
1093 $sql .= ", ".price2num($pu_ht_devise, 'CU');
1094 $sql .= ", ".price2num($multicurrency_total_ht, 'CT');
1095 $sql .= ", ".price2num($multicurrency_total_tva, 'CT');
1096 $sql .= ", ".price2num($multicurrency_total_ttc, 'CT');
1097 $sql .= ")";
1098
1099 dol_syslog(get_class($this)."::addline", LOG_DEBUG);
1100 if ($this->db->query($sql)) {
1101 $lineId = $this->db->last_insert_id(MAIN_DB_PREFIX."facturedet_rec");
1102 $this->id = $facid;
1103 $this->update_price(1);
1104 return $lineId;
1105 } else {
1106 $this->error = $this->db->lasterror();
1107 return -1;
1108 }
1109 }
1110
1141 public function updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $fk_product = 0, $remise_percent = 0, $price_base_type = 'HT', $info_bits = 0, $fk_remise_except = 0, $pu_ttc = 0, $type = 0, $rang = -1, $special_code = 0, $label = '', $fk_unit = null, $pu_ht_devise = 0, $notrigger = 0, $date_start_fill = 0, $date_end_fill = 0, $fk_fournprice = null, $pa_ht = 0, $fk_parent_line = 0)
1142 {
1143 global $mysoc;
1144
1145 $facid = $this->id;
1146
1147 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);
1148 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
1149
1150 // Clean parameters
1151 if (empty($remise_percent)) {
1152 $remise_percent = 0;
1153 }
1154
1155 // Check parameters
1156 if ($type < 0) {
1157 return -1;
1158 }
1159
1160 // Clean parameters
1161 $remise_percent = price2num($remise_percent);
1162 $qty = price2num($qty);
1163 if (empty($info_bits)) {
1164 $info_bits = 0;
1165 }
1166 $pu_ht = price2num($pu_ht);
1167 $pu_ttc = price2num($pu_ttc);
1168 $pu_ht_devise = price2num($pu_ht_devise);
1169 if (!preg_match('/\‍((.*)\‍)/', (string) $txtva)) {
1170 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
1171 }
1172 $txlocaltax1 = price2num($txlocaltax1);
1173 $txlocaltax2 = price2num($txlocaltax2);
1174 if (empty($txlocaltax1)) {
1175 $txlocaltax1 = 0;
1176 }
1177 if (empty($txlocaltax2)) {
1178 $txlocaltax2 = 0;
1179 }
1180
1181 if (empty($this->multicurrency_subprice)) {
1182 $this->multicurrency_subprice = 0;
1183 }
1184 if (empty($this->multicurrency_total_ht)) {
1185 $this->multicurrency_total_ht = 0;
1186 }
1187 if (empty($this->multicurrency_total_tva)) {
1188 $this->multicurrency_total_tva = 0;
1189 }
1190 if (empty($this->multicurrency_total_ttc)) {
1191 $this->multicurrency_total_ttc = 0;
1192 }
1193
1194 if ($price_base_type == 'HT') {
1195 $pu = $pu_ht;
1196 } else {
1197 $pu = $pu_ttc;
1198 }
1199
1200 // Calculate total with, without tax and tax from qty, pu, remise_percent and txtva
1201 // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
1202 // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
1203
1204 $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
1205
1206 // Clean vat code
1207 $vat_src_code = '';
1208 $reg = array();
1209 if (preg_match('/\‍((.*)\‍)/', $txtva, $reg)) {
1210 $vat_src_code = $reg[1];
1211 $txtva = preg_replace('/\s*\‍(.*\‍)/', '', $txtva); // Remove code into vatrate.
1212 }
1213
1214 $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);
1215
1216 $total_ht = $tabprice[0];
1217 $total_tva = $tabprice[1];
1218 $total_ttc = $tabprice[2];
1219 $total_localtax1 = $tabprice[9];
1220 $total_localtax2 = $tabprice[10];
1221 $pu_ht = $tabprice[3];
1222 $pu_tva = $tabprice[4];
1223 $pu_ttc = $tabprice[5];
1224
1225 // MultiCurrency
1226 $multicurrency_total_ht = $tabprice[16];
1227 $multicurrency_total_tva = $tabprice[17];
1228 $multicurrency_total_ttc = $tabprice[18];
1229 $pu_ht_devise = $tabprice[19];
1230
1231 $product_type = $type;
1232 if ($fk_product) {
1233 $product = new Product($this->db);
1234 $result = $product->fetch($fk_product);
1235 $product_type = $product->type;
1236 }
1237
1238 if (empty($fk_parent_line) || $fk_parent_line < 0) {
1239 $fk_parent_line = 0;
1240 }
1241
1242 $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET ";
1243 $sql .= "fk_facture = ".((int) $facid);
1244 $sql .= ", fk_parent_line = ".($fk_parent_line > 0 ? ((int) $fk_parent_line) : "null");
1245 $sql .= ", label=".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
1246 $sql .= ", description='".$this->db->escape($desc)."'";
1247 $sql .= ", price=".price2num($pu_ht);
1248 $sql .= ", qty=".price2num($qty);
1249 $sql .= ", tva_tx=".price2num($txtva);
1250 $sql .= ", vat_src_code='".$this->db->escape($vat_src_code)."'";
1251 $sql .= ", localtax1_tx=".((float) $txlocaltax1);
1252 $sql .= ", localtax1_type='".$this->db->escape($localtaxes_type[0])."'";
1253 $sql .= ", localtax2_tx=".((float) $txlocaltax2);
1254 $sql .= ", localtax2_type='".$this->db->escape($localtaxes_type[2])."'";
1255 $sql .= ", fk_product=".(!empty($fk_product) ? "'".$this->db->escape($fk_product)."'" : "null");
1256 $sql .= ", product_type=".((int) $product_type);
1257 $sql .= ", remise_percent='".price2num($remise_percent)."'";
1258 $sql .= ", subprice='".price2num($pu_ht)."'";
1259 $sql .= ", total_ht='".price2num($total_ht)."'";
1260 $sql .= ", total_tva='".price2num($total_tva)."'";
1261 $sql .= ", total_localtax1='".price2num($total_localtax1)."'";
1262 $sql .= ", total_localtax2='".price2num($total_localtax2)."'";
1263 $sql .= ", total_ttc='".price2num($total_ttc)."'";
1264 $sql .= ", date_start_fill=".((int) $date_start_fill);
1265 $sql .= ", date_end_fill=".((int) $date_end_fill);
1266 $sql .= ", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice : 'null');
1267 $sql .= ", buy_price_ht=".($pa_ht ? price2num($pa_ht) : 0);
1268 $sql .= ", info_bits=".((int) $info_bits);
1269 $sql .= ", rang=".((int) $rang);
1270 $sql .= ", special_code=".((int) $special_code);
1271 $sql .= ", fk_unit=".($fk_unit ? "'".$this->db->escape($fk_unit)."'" : "null");
1272 $sql .= ', multicurrency_subprice = '.price2num($pu_ht_devise);
1273 $sql .= ', multicurrency_total_ht = '.price2num($multicurrency_total_ht);
1274 $sql .= ', multicurrency_total_tva = '.price2num($multicurrency_total_tva);
1275 $sql .= ', multicurrency_total_ttc = '.price2num($multicurrency_total_ttc);
1276 $sql .= " WHERE rowid = ".((int) $rowid);
1277
1278 dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
1279 if ($this->db->query($sql)) {
1280 $this->id = $facid;
1281 $this->update_price(1);
1282 return 1;
1283 } else {
1284 $this->error = $this->db->lasterror();
1285 return -1;
1286 }
1287 }
1288
1289
1295 public function getNextDate()
1296 {
1297 if (empty($this->date_when)) {
1298 return false;
1299 }
1300 return dol_time_plus_duree($this->date_when, $this->frequency, $this->unit_frequency);
1301 }
1302
1308 public function isMaxNbGenReached()
1309 {
1310 $ret = false;
1311 if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) {
1312 $ret = true;
1313 }
1314 return $ret;
1315 }
1316
1323 public function strikeIfMaxNbGenReached($ret)
1324 {
1325 return $this->isMaxNbGenReached() ? '<strike>'.$ret.'</strike>' : $ret;
1326 }
1327
1339 public function createRecurringInvoices($restrictioninvoiceid = 0, $forcevalidation = 0, $notrigger = 0)
1340 {
1341 global $conf, $langs, $db, $user, $hookmanager;
1342
1343 $error = 0;
1344 $nb_create = 0;
1345
1346 // Load translation files required by the page
1347 $langs->loadLangs(array("main", "bills"));
1348
1349 $now = dol_now();
1350 $tmparray = dol_getdate($now);
1351 $today = dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year']); // Today is last second of current day
1352
1353 $this->output = '';
1354
1355 dol_syslog("createRecurringInvoices restrictioninvoiceid=".$restrictioninvoiceid." forcevalidation=".$forcevalidation);
1356
1357 $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture_rec';
1358 $sql .= ' WHERE frequency > 0'; // A recurring invoice is an invoice with a frequency
1359 $sql .= " AND (date_when IS NULL OR date_when <= '".$this->db->idate($today)."')";
1360 $sql .= ' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
1361 $sql .= ' AND suspended = 0';
1362 $sql .= ' AND entity = '.$conf->entity; // MUST STAY = $conf->entity here
1363 if ($restrictioninvoiceid > 0) {
1364 $sql .= ' AND rowid = '.((int) $restrictioninvoiceid);
1365 }
1366 $sql .= $this->db->order('entity', 'ASC');
1367 //print $sql;exit;
1368 $parameters = array(
1369 'restrictioninvoiceid' => $restrictioninvoiceid,
1370 'forcevalidation' => $forcevalidation,
1371 );
1372 $reshook = $hookmanager->executeHooks('beforeCreationOfRecurringInvoices', $parameters, $sql); // note that $sql might be modified by hooks
1373
1374 $resql = $this->db->query($sql);
1375 if ($resql) {
1376 $i = 0;
1377 $num = $this->db->num_rows($resql);
1378
1379 if ($num) {
1380 $this->output .= $langs->trans("FoundXQualifiedRecurringInvoiceTemplate", $num)."\n";
1381 } else {
1382 $this->output .= $langs->trans("NoQualifiedRecurringInvoiceTemplateFound");
1383 }
1384
1385 $saventity = $conf->entity;
1386
1387 while ($i < $num) { // Loop on each template invoice. If $num = 0, test is false at first pass.
1388 $line = $this->db->fetch_object($resql);
1389
1390 $this->db->begin();
1391
1392 $invoiceidgenerated = 0;
1393
1394 $facture = null;
1395 $facturerec = new FactureRec($this->db);
1396 $facturerec->fetch($line->rowid);
1397
1398 if ($facturerec->id > 0) {
1399 // Set entity context
1400 $conf->entity = $facturerec->entity;
1401
1402 dol_syslog("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref.", entity=".$facturerec->entity);
1403
1404 $facture = new Facture($this->db);
1405 $facture->fac_rec = $facturerec->id; // We will create $facture from this recurring invoice
1406 $facture->fk_fac_rec_source = $facturerec->id; // We will create $facture from this recurring invoice
1407
1408 $facture->type = self::TYPE_STANDARD;
1409 $facture->subtype = $facturerec->subtype;
1410 $facture->statut = self::STATUS_DRAFT; // deprecated
1411 $facture->status = self::STATUS_DRAFT;
1412 $facture->date = (empty($facturerec->date_when) ? $now : $facturerec->date_when); // We could also use dol_now here but we prefer date_when so invoice has real date when we would like even if we generate later.
1413 $facture->socid = $facturerec->socid;
1414 if (!empty($facturerec->fk_multicurrency)) {
1415 $facture->fk_multicurrency = $facturerec->fk_multicurrency;
1416 $facture->multicurrency_code = $facturerec->multicurrency_code;
1417 $facture->multicurrency_tx = $facturerec->multicurrency_tx;
1418 }
1419
1420 if (isset($facture->array_options) && isset($facturerec->array_options)) {
1421 foreach ($facturerec->array_options as $key => $value) {
1422 if (isset($facture->array_options[$key])) {
1423 $facture->array_options[$key] = $value;
1424 }
1425 }
1426 }
1427
1428 $invoiceidgenerated = $facture->create($user);
1429 if ($invoiceidgenerated <= 0) {
1430 $this->errors = $facture->errors;
1431 $this->error = $facture->error;
1432 $error++;
1433 }
1434
1435
1436 if (!$error && ($facturerec->auto_validate || $forcevalidation)) {
1437 $result = $facture->validate($user);
1438 if ($result <= 0) {
1439 $this->errors = $facture->errors;
1440 $this->error = $facture->error;
1441 $error++;
1442 }
1443 }
1444 if (!$error && $facturerec->generate_pdf) {
1445 // We refresh the object in order to have all necessary data (like date_lim_reglement)
1446 $facture->fetch($facture->id);
1447 $result = $facture->generateDocument($facturerec->model_pdf, $langs);
1448 if ($result <= 0) {
1449 $this->errors = $facture->errors;
1450 $this->error = $facture->error;
1451 $error++;
1452 }
1453 }
1454 } else {
1455 $error++;
1456 $this->error = "Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity."\n";
1457 $this->errors[] = "Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity;
1458 dol_syslog("createRecurringInvoices Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity);
1459 }
1460
1461 if (!$error && $invoiceidgenerated >= 0) {
1462 $this->db->commit("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
1463 dol_syslog("createRecurringInvoices Process invoice template ".$facturerec->ref." is finished with a success generation");
1464 $nb_create++;
1465 $this->output .= $langs->trans("InvoiceGeneratedFromTemplate", $facture->ref, $facturerec->ref)."\n";
1466 } else {
1467 $this->db->rollback("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
1468 }
1469
1470 $parameters = array(
1471 'cpt' => $i,
1472 'total' => $num,
1473 'errorCount' => $error,
1474 'invoiceidgenerated' => $invoiceidgenerated,
1475 'facturerec' => $facturerec, // it's an object which PHP passes by "reference", so modifiable by hooks.
1476 'this' => $this, // it's an object which PHP passes by "reference", so modifiable by hooks.
1477 );
1478 $reshook = $hookmanager->executeHooks('afterCreationOfRecurringInvoice', $parameters, $facture); // note: $facture can be modified by hooks (warning: $facture can be null)
1479
1480 $i++;
1481 }
1482
1483 $conf->entity = $saventity; // Restore entity context
1484 } else {
1485 dol_print_error($this->db);
1486 }
1487
1488 $this->output = trim($this->output);
1489
1490 return $error ? $error : 0;
1491 }
1492
1505 public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '', $notooltip = 0, $save_lastsearch_value = -1)
1506 {
1507 global $langs, $hookmanager;
1508
1509 $result = '';
1510
1511 $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("RepeatableInvoice").'</u>';
1512 if (!empty($this->ref)) {
1513 $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1514 }
1515 if ($this->frequency > 0) {
1516 $label .= '<br><b>'.$langs->trans('Frequency').':</b> '.$langs->trans('FrequencyPer_'.$this->unit_frequency, $this->frequency);
1517 }
1518 if (!empty($this->date_last_gen)) {
1519 $label .= '<br><b>'.$langs->trans('DateLastGeneration').':</b> '.dol_print_date($this->date_last_gen, 'dayhour');
1520 }
1521 if ($this->frequency > 0) {
1522 if (!empty($this->date_when)) {
1523 $label .= '<br><b>'.$langs->trans('NextDateToExecution').':</b> ';
1524 $label .= (empty($this->suspended) ? '' : '<strike>').dol_print_date($this->date_when, 'day').(empty($this->suspended) ? '' : '</strike>'); // No hour for this property
1525 if (!empty($this->suspended)) {
1526 $label .= ' ('.$langs->trans("Disabled").')';
1527 }
1528 }
1529 }
1530
1531 $url = DOL_URL_ROOT.'/compta/facture/card-rec.php?facid='.$this->id;
1532
1533 if ($short) {
1534 return $url;
1535 }
1536
1537 if ($option != 'nolink') {
1538 // Add param to save lastsearch_values or not
1539 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1540 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1541 $add_save_lastsearch_values = 1;
1542 }
1543 if ($add_save_lastsearch_values) {
1544 $url .= '&save_lastsearch_values=1';
1545 }
1546 }
1547
1548 $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1549 $linkend = '</a>';
1550
1551 $result .= $linkstart;
1552 if ($withpicto) {
1553 $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);
1554 }
1555 if ($withpicto != 2) {
1556 $result .= dol_trunc($this->ref, $max);
1557 }
1558 $result .= $linkend;
1559 global $action;
1560 $hookmanager->initHooks(array($this->element . 'dao'));
1561 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1562 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1563 if ($reshook > 0) {
1564 $result = $hookmanager->resPrint;
1565 } else {
1566 $result .= $hookmanager->resPrint;
1567 }
1568 return $result;
1569 }
1570
1578 public function getLibStatut($mode = 0, $alreadypaid = -1)
1579 {
1580 return $this->LibStatut($this->frequency ? 1 : 0, $this->suspended, $mode, $alreadypaid, empty($this->type) ? 0 : $this->type);
1581 }
1582
1583 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1594 public function LibStatut($recur, $status, $mode = 0, $alreadypaid = -1, $type = 0)
1595 {
1596 // phpcs:enable
1597 global $langs;
1598 $langs->load('bills');
1599
1600 $labelStatus = $langs->transnoentitiesnoconv('Active');
1601 $statusType = 'status0';
1602
1603 //print "$recur,$status,$mode,$alreadypaid,$type";
1604 if ($mode == 0) {
1605 if ($recur) {
1606 if ($status == self::STATUS_SUSPENDED) {
1607 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1608 } else {
1609 $labelStatus = $langs->transnoentitiesnoconv('Active');
1610 }
1611 } else {
1612 if ($status == self::STATUS_SUSPENDED) {
1613 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1614 } else {
1615 $labelStatus = $langs->transnoentitiesnoconv("Draft");
1616 }
1617 }
1618 } elseif ($mode == 1) {
1619 $prefix = 'Short';
1620 if ($recur) {
1621 if ($status == self::STATUS_SUSPENDED) {
1622 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1623 } else {
1624 $labelStatus = $langs->transnoentitiesnoconv('Active');
1625 }
1626 } else {
1627 if ($status == self::STATUS_SUSPENDED) {
1628 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1629 } else {
1630 $labelStatus = $langs->transnoentitiesnoconv("Draft");
1631 }
1632 }
1633 } elseif ($mode == 2) {
1634 if ($recur) {
1635 if ($status == self::STATUS_SUSPENDED) {
1636 $statusType = 'status6';
1637 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1638 } else {
1639 $statusType = 'status4';
1640 $labelStatus = $langs->transnoentitiesnoconv('Active');
1641 }
1642 } else {
1643 if ($status == self::STATUS_SUSPENDED) {
1644 $statusType = 'status6';
1645 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1646 } else {
1647 $statusType = 'status0';
1648 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1649 }
1650 }
1651 } elseif ($mode == 3) {
1652 if ($recur) {
1653 $prefix = 'Short';
1654 if ($status == self::STATUS_SUSPENDED) {
1655 $statusType = 'status6';
1656 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1657 } else {
1658 $statusType = 'status4';
1659 $labelStatus = $langs->transnoentitiesnoconv('Active');
1660 }
1661 } else {
1662 if ($status == self::STATUS_SUSPENDED) {
1663 $statusType = 'status6';
1664 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1665 } else {
1666 $statusType = 'status0';
1667 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1668 }
1669 }
1670 } elseif ($mode == 4) {
1671 $prefix = '';
1672 if ($recur) {
1673 if ($status == self::STATUS_SUSPENDED) {
1674 $statusType = 'status6';
1675 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1676 } else {
1677 $statusType = 'status4';
1678 $labelStatus = $langs->transnoentitiesnoconv('Active');
1679 }
1680 } else {
1681 if ($status == self::STATUS_SUSPENDED) {
1682 $statusType = 'status6';
1683 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1684 } else {
1685 $statusType = 'status0';
1686 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1687 }
1688 }
1689 } elseif ($mode == 5 || $mode == 6) {
1690 $prefix = '';
1691 if ($mode == 5) {
1692 $prefix = 'Short';
1693 }
1694 if ($recur) {
1695 if ($status == self::STATUS_SUSPENDED) {
1696 $statusType = 'status6';
1697 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1698 } else {
1699 $statusType = 'status4';
1700 $labelStatus = $langs->transnoentitiesnoconv('Active');
1701 }
1702 } else {
1703 if ($status == self::STATUS_SUSPENDED) {
1704 $statusType = 'status6';
1705 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1706 } else {
1707 $statusType = 'status0';
1708 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1709 }
1710 }
1711 }
1712
1713 $labelStatusShort = $labelStatus;
1714
1715 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
1716 }
1717
1725 public function getNextNumRef($soc, $mode = 'next')
1726 {
1727 // Not used for recurring invoices
1728 return '';
1729 }
1730
1737 public function info($id)
1738 {
1739 $sql = 'SELECT c.rowid, datec, tms as datem,';
1740 $sql .= ' fk_user_author, fk_user_modif';
1741 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_rec as c';
1742 $sql .= ' WHERE c.rowid = '.((int) $id);
1743
1744 $result = $this->db->query($sql);
1745 if ($result) {
1746 if ($this->db->num_rows($result)) {
1747 $obj = $this->db->fetch_object($result);
1748
1749 $this->id = $obj->rowid;
1750
1751 $this->user_creation_id = $obj->fk_user_author;
1752 $this->user_modification_id = $obj->fk_user_modif;
1753 $this->date_creation = $this->db->jdate($obj->datec);
1754 $this->date_modification = $this->db->jdate($obj->datem);
1755 }
1756 $this->db->free($result);
1757 } else {
1758 dol_print_error($this->db);
1759 }
1760 }
1761
1770 public function initAsSpecimen($option = '')
1771 {
1772 global $langs;
1773
1774 $now = dol_now();
1775 $arraynow = dol_getdate($now);
1776 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
1777
1778 // Load array of products prodids
1779 $num_prods = 0;
1780 $prodids = array();
1781
1782 $sql = "SELECT rowid";
1783 $sql .= " FROM ".MAIN_DB_PREFIX."product";
1784 $sql .= " WHERE entity IN (".getEntity('product').")";
1785 $sql .= $this->db->plimit(100);
1786
1787 $resql = $this->db->query($sql);
1788 if ($resql) {
1789 $num_prods = $this->db->num_rows($resql);
1790 $i = 0;
1791 while ($i < $num_prods) {
1792 $i++;
1793 $row = $this->db->fetch_row($resql);
1794 $prodids[$i] = $row[0];
1795 }
1796 }
1797
1798 // Initialize parameters
1799 $this->id = 0;
1800 $this->ref = 'SPECIMEN';
1801 $this->title = 'SPECIMEN';
1802 $this->specimen = 1;
1803 $this->socid = 1;
1804 $this->date = $nownotime;
1805 $this->date_lim_reglement = $nownotime + 3600 * 24 * 30;
1806 $this->cond_reglement_id = 1;
1807 $this->cond_reglement_code = 'RECEP';
1808 $this->date_lim_reglement = $this->calculate_date_lim_reglement();
1809 $this->mode_reglement_id = 0; // Not forced to show payment mode CHQ + VIR
1810 $this->mode_reglement_code = ''; // Not forced to show payment mode CHQ + VIR
1811 $this->note_public = 'This is a comment (public)';
1812 $this->note_private = 'This is a comment (private)';
1813 $this->note = 'This is a comment (private)';
1814 $this->fk_incoterms = 0;
1815 $this->location_incoterms = '';
1816
1817 if (empty($option) || $option != 'nolines') {
1818 // Lines
1819 $nbp = 5;
1820 $xnbp = 0;
1821 while ($xnbp < $nbp) {
1822 $line = new FactureLigne($this->db);
1823 $line->desc = $langs->trans("Description")." ".$xnbp;
1824 $line->qty = 1;
1825 $line->subprice = 100;
1826 $line->tva_tx = 19.6;
1827 $line->localtax1_tx = 0;
1828 $line->localtax2_tx = 0;
1829 $line->remise_percent = 0;
1830 if ($xnbp == 1) { // Qty is negative (product line)
1831 $prodid = mt_rand(1, $num_prods);
1832 $line->fk_product = $prodids[$prodid];
1833 $line->qty = -1;
1834 $line->total_ht = -100;
1835 $line->total_ttc = -119.6;
1836 $line->total_tva = -19.6;
1837 } elseif ($xnbp == 2) { // UP is negative (free line)
1838 $line->subprice = -100;
1839 $line->total_ht = -100;
1840 $line->total_ttc = -119.6;
1841 $line->total_tva = -19.6;
1842 $line->remise_percent = 0;
1843 } elseif ($xnbp == 3) { // Discount is 50% (product line)
1844 $prodid = mt_rand(1, $num_prods);
1845 $line->fk_product = $prodids[$prodid];
1846 $line->total_ht = 50;
1847 $line->total_ttc = 59.8;
1848 $line->total_tva = 9.8;
1849 $line->remise_percent = 50;
1850 } else { // (product line)
1851 $prodid = mt_rand(1, $num_prods);
1852 $line->fk_product = $prodids[$prodid];
1853 $line->total_ht = 100;
1854 $line->total_ttc = 119.6;
1855 $line->total_tva = 19.6;
1856 $line->remise_percent = 00;
1857 }
1858
1859 $this->lines[$xnbp] = $line;
1860 $xnbp++;
1861
1862 $this->total_ht += $line->total_ht;
1863 $this->total_tva += $line->total_tva;
1864 $this->total_ttc += $line->total_ttc;
1865 }
1866 $this->revenuestamp = 0;
1867
1868 // Add a line "offered"
1869 $line = new FactureLigne($this->db);
1870 $line->desc = $langs->trans("Description")." (offered line)";
1871 $line->qty = 1;
1872 $line->subprice = 100;
1873 $line->tva_tx = 19.6;
1874 $line->localtax1_tx = 0;
1875 $line->localtax2_tx = 0;
1876 $line->remise_percent = 100;
1877 $line->total_ht = 0;
1878 $line->total_ttc = 0; // 90 * 1.196
1879 $line->total_tva = 0;
1880 $prodid = mt_rand(1, $num_prods);
1881 $line->fk_product = $prodids[$prodid];
1882
1883 $this->lines[$xnbp] = $line;
1884 $xnbp++;
1885 }
1886
1887 $this->usenewprice = 0;
1888
1889 return 1;
1890 }
1891
1900 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1901 {
1902 $tables = array(
1903 'facture_rec'
1904 );
1905
1906 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1907 }
1908
1917 public static function replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
1918 {
1919 $tables = array(
1920 'facturedet_rec'
1921 );
1922
1923 return CommonObject::commonReplaceProduct($dbs, $origin_id, $dest_id, $tables);
1924 }
1925
1934 public function setFrequencyAndUnit($frequency, $unit, $notrigger = 0)
1935 {
1936 global $user;
1937
1938 if (!$this->table_element) {
1939 dol_syslog(get_class($this)."::setFrequencyAndUnit was called on object with property table_element not defined", LOG_ERR);
1940 return -1;
1941 }
1942
1943 if (!empty($frequency) && empty($unit)) {
1944 dol_syslog(get_class($this)."::setFrequencyAndUnit was called on object with params frequency defined but unit not defined", LOG_ERR);
1945 return -2;
1946 }
1947
1948 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1949 $sql .= ' SET frequency = '.($frequency ? $this->db->escape($frequency) : 'null');
1950 if (!empty($unit)) {
1951 $sql .= ', unit_frequency = \''.$this->db->escape($unit).'\'';
1952 }
1953 $sql .= " WHERE rowid = ".((int) $this->id);
1954
1955 dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
1956 if ($this->db->query($sql)) {
1957 $this->frequency = $frequency;
1958 if (!empty($unit)) {
1959 $this->unit_frequency = $unit;
1960 }
1961
1962 if (!$notrigger) {
1963 // Call trigger
1964 $result = $this->call_trigger('BILLREC_MODIFY', $user);
1965 if ($result < 0) {
1966 return $result;
1967 }
1968 // End call triggers
1969 }
1970
1971 return 1;
1972 } else {
1973 dol_print_error($this->db);
1974 return -1;
1975 }
1976 }
1977
1986 public function setNextDate($date, $increment_nb_gen_done = 0, $notrigger = 0)
1987 {
1988 global $user;
1989
1990 if (!$this->table_element) {
1991 dol_syslog(get_class($this)."::setNextDate was called on object with property table_element not defined", LOG_ERR);
1992 return -1;
1993 }
1994 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1995 $sql .= " SET date_when = ".($date ? "'".$this->db->idate($date)."'" : "null");
1996 if ($increment_nb_gen_done > 0) {
1997 $sql .= ', nb_gen_done = nb_gen_done + 1';
1998 }
1999 $sql .= " WHERE rowid = ".((int) $this->id);
2000
2001 dol_syslog(get_class($this)."::setNextDate", LOG_DEBUG);
2002 if ($this->db->query($sql)) {
2003 $this->date_when = $date;
2004 if ($increment_nb_gen_done > 0) {
2005 $this->nb_gen_done++;
2006
2007 if (getDolGlobalInt('MAIN_SUSPEND_FACTURE_REC_ON_MAX_GEN_REACHED') && $this->isMaxNbGenReached()) {
2008 $resSuspend = $this->setValueFrom('suspended', 1);
2009
2010 if ($resSuspend <= 0) {
2011 dol_syslog(__METHOD__ . '::setValueFrom Error : ' . $this->error, LOG_ERR);
2012 return -1;
2013 }
2014 }
2015 }
2016
2017 if (!$notrigger) {
2018 // Call trigger
2019 $result = $this->call_trigger('BILLREC_MODIFY', $user);
2020 if ($result < 0) {
2021 return $result;
2022 }
2023 // End call triggers
2024 }
2025 return 1;
2026 } else {
2027 dol_print_error($this->db);
2028 return -1;
2029 }
2030 }
2031
2039 public function setMaxPeriod($nb, $notrigger = 0)
2040 {
2041 global $user;
2042
2043 if (!$this->table_element) {
2044 dol_syslog(get_class($this)."::setMaxPeriod was called on object with property table_element not defined", LOG_ERR);
2045 return -1;
2046 }
2047
2048 if (empty($nb)) {
2049 $nb = 0;
2050 }
2051
2052 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2053 $sql .= ' SET nb_gen_max = '.((int) $nb);
2054 $sql .= " WHERE rowid = ".((int) $this->id);
2055
2056 dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
2057 if ($this->db->query($sql)) {
2058 $this->nb_gen_max = $nb;
2059
2060 if (!$notrigger) {
2061 // Call trigger
2062 $result = $this->call_trigger('BILLREC_MODIFY', $user);
2063 if ($result < 0) {
2064 return $result;
2065 }
2066 // End call triggers
2067 }
2068
2069 return 1;
2070 } else {
2071 dol_print_error($this->db);
2072 return -1;
2073 }
2074 }
2075
2083 public function setAutoValidate($validate, $notrigger = 0)
2084 {
2085 global $user;
2086
2087 if (!$this->table_element) {
2088 dol_syslog(get_class($this)."::setAutoValidate was called on object with property table_element not defined", LOG_ERR);
2089 return -1;
2090 }
2091
2092 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2093 $sql .= ' SET auto_validate = '.((int) $validate);
2094 $sql .= " WHERE rowid = ".((int) $this->id);
2095
2096 dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
2097 if ($this->db->query($sql)) {
2098 $this->auto_validate = $validate;
2099
2100 if (!$notrigger) {
2101 // Call trigger
2102 $result = $this->call_trigger('BILLREC_MODIFY', $user);
2103 if ($result < 0) {
2104 return $result;
2105 }
2106 // End call triggers
2107 }
2108
2109 return 1;
2110 } else {
2111 dol_print_error($this->db);
2112 return -1;
2113 }
2114 }
2115
2123 public function setGeneratePdf($validate, $notrigger = 0)
2124 {
2125 global $user;
2126
2127 if (!$this->table_element) {
2128 dol_syslog(get_class($this)."::setGeneratePdf was called on object with property table_element not defined", LOG_ERR);
2129 return -1;
2130 }
2131
2132 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2133 $sql .= ' SET generate_pdf = '.((int) $validate);
2134 $sql .= " WHERE rowid = ".((int) $this->id);
2135
2136 dol_syslog(get_class($this)."::setGeneratePdf", LOG_DEBUG);
2137 if ($this->db->query($sql)) {
2138 $this->generate_pdf = $validate;
2139
2140 if (!$notrigger) {
2141 // Call trigger
2142 $result = $this->call_trigger('BILLREC_MODIFY', $user);
2143 if ($result < 0) {
2144 return $result;
2145 }
2146 // End call triggers
2147 }
2148
2149 return 1;
2150 } else {
2151 dol_print_error($this->db);
2152 return -1;
2153 }
2154 }
2155
2163 public function setModelPdf($model, $notrigger = 0)
2164 {
2165 global $user;
2166 if (!$this->table_element) {
2167 dol_syslog(get_class($this)."::setModelPdf was called on object with property table_element not defined", LOG_ERR);
2168 return -1;
2169 }
2170
2171 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2172 $sql .= " SET modelpdf = '".$this->db->escape($model)."'";
2173 $sql .= " WHERE rowid = ".((int) $this->id);
2174
2175 dol_syslog(get_class($this)."::setModelPdf", LOG_DEBUG);
2176 if ($this->db->query($sql)) {
2177 $this->model_pdf = $model;
2178
2179 if (!$notrigger) {
2180 // Call trigger
2181 $result = $this->call_trigger('BILLREC_MODIFY', $user);
2182 if ($result < 0) {
2183 return $result;
2184 }
2185 // End call triggers
2186 }
2187
2188 return 1;
2189 } else {
2190 dol_print_error($this->db);
2191 return -1;
2192 }
2193 }
2194}
2195
2196
2197
2203{
2207 public $element = 'facturedetrec';
2208
2212 public $table_element = 'facturedet_rec';
2213
2217 public $parent_element = 'facturerec';
2218
2222 public $fk_parent_attribute = 'fk_facture';
2223
2225
2228 public $fk_facture;
2232 public $fk_parent_line;
2233
2237 public $fk_product_fournisseur_price;
2242 public $fk_fournprice;
2243
2247 public $rang;
2248 //public $situation_percent; // Not supported on recurring invoice line
2249
2253 public $desc;
2257 public $description;
2258
2263 public $fk_product_type;
2264
2268 public $fk_contract_line;
2269
2270
2278 public function delete(User $user, $notrigger = 0)
2279 {
2280 $error = 0;
2281
2282 $this->db->begin();
2283
2284 if (!$error) {
2285 if (!$notrigger) {
2286 // Call triggers
2287 $result = $this->call_trigger('LINEBILLREC_DELETE', $user);
2288 if ($result < 0) {
2289 $error++;
2290 } // Do also here what you must do to rollback action if trigger fail
2291 // End call triggers
2292 }
2293 }
2294
2295 if (!$error) {
2296 $result = $this->deleteExtraFields();
2297 if ($result < 0) {
2298 $error++;
2299 }
2300 }
2301
2302 if (!$error) {
2303 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.((int) $this->id);
2304
2305 $res = $this->db->query($sql);
2306 if (!$res) {
2307 $error++;
2308 $this->errors[] = $this->db->lasterror();
2309 }
2310 }
2311
2312 // Commit or rollback
2313 if ($error) {
2314 $this->db->rollback();
2315 return -1;
2316 } else {
2317 $this->db->commit();
2318 return 1;
2319 }
2320 }
2321
2322
2329 public function fetch($rowid)
2330 {
2331 $sql = 'SELECT l.rowid, l.fk_facture, l.fk_parent_line, l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx,';
2332 $sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
2333 $sql .= ' l.date_start_fill, l.date_end_fill, l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
2334 $sql .= ' l.rang, l.special_code,';
2335 $sql .= ' l.fk_unit, l.fk_contract_line,';
2336 $sql .= ' l.import_key, l.fk_multicurrency,';
2337 $sql .= ' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
2338 $sql .= ' l.buy_price_ht, l.fk_product_fournisseur_price,';
2339 $sql .= ' l.fk_user_author, l.fk_user_modif,';
2340 $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
2341 $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l';
2342 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
2343 $sql .= ' WHERE l.rowid = '.((int) $rowid);
2344 $sql .= ' ORDER BY l.rang';
2345
2346 dol_syslog('FactureRec::fetch', LOG_DEBUG);
2347 $result = $this->db->query($sql);
2348 if ($result) {
2349 $objp = $this->db->fetch_object($result);
2350
2351 $this->id = $objp->rowid;
2352 $this->fk_facture = $objp->fk_facture;
2353 $this->fk_parent_line = $objp->fk_parent_line;
2354 $this->label = $objp->custom_label; // Label line
2355 $this->desc = $objp->description; // Description line
2356 $this->description = $objp->description; // Description line
2357 $this->product_type = $objp->product_type; // Type of line
2358 $this->ref = $objp->product_ref; // Ref product
2359 $this->product_ref = $objp->product_ref; // Ref product
2360 $this->libelle = $objp->product_label; // deprecated
2361 $this->product_label = $objp->product_label; // Label product
2362 $this->product_desc = $objp->product_desc; // Description product
2363 $this->fk_product_type = $objp->fk_product_type; // Type of product
2364 $this->qty = $objp->qty;
2365 $this->price = $objp->price;
2366 $this->subprice = $objp->subprice;
2367 $this->vat_src_code = $objp->vat_src_code;
2368 $this->tva_tx = $objp->tva_tx;
2369 $this->localtax1_tx = $objp->localtax1_tx;
2370 $this->localtax2_tx = $objp->localtax2_tx;
2371 $this->localtax1_type = $objp->localtax1_type;
2372 $this->localtax2_type = $objp->localtax2_type;
2373 $this->remise_percent = $objp->remise_percent;
2374 //$this->fk_remise_except = $objp->fk_remise_except;
2375 $this->fk_product = $objp->fk_product;
2376 $this->date_start_fill = $objp->date_start_fill;
2377 $this->date_end_fill = $objp->date_end_fill;
2378 $this->info_bits = $objp->info_bits;
2379 $this->total_ht = $objp->total_ht;
2380 $this->total_tva = $objp->total_tva;
2381 $this->total_ttc = $objp->total_ttc;
2382
2383 $this->rang = $objp->rang;
2384 $this->special_code = $objp->special_code;
2385 $this->fk_unit = $objp->fk_unit;
2386 $this->fk_contract_line = $objp->fk_contract_line;
2387 $this->import_key = $objp->import_key;
2388 $this->fk_multicurrency = $objp->fk_multicurrency;
2389 $this->multicurrency_code = $objp->multicurrency_code;
2390 $this->multicurrency_subprice = $objp->multicurrency_subprice;
2391 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
2392 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
2393 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2394
2395 $this->buy_price_ht = $objp->buy_price_ht;
2396
2397 $this->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
2398 $this->fk_user_author = $objp->fk_user_author;
2399 $this->fk_user_modif = $objp->fk_user_modif;
2400
2401 $this->db->free($result);
2402 return 1;
2403 } else {
2404 $this->error = $this->db->lasterror();
2405 return -3;
2406 }
2407 }
2408
2409
2417 public function update(User $user, $notrigger = 0)
2418 {
2419 global $conf;
2420
2421 $error = 0;
2422
2423 // Clean parameters
2424 if (empty($this->fk_parent_line)) {
2425 $this->fk_parent_line = 0;
2426 }
2427
2428 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
2429
2430 $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET";
2431 $sql .= " fk_facture = ".((int) $this->fk_facture);
2432 $sql .= ", fk_parent_line=".($this->fk_parent_line > 0 ? $this->fk_parent_line : "null");
2433 $sql .= ", label=".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
2434 $sql .= ", description='".$this->db->escape($this->desc)."'";
2435 $sql .= ", price=".price2num($this->price);
2436 $sql .= ", qty=".price2num($this->qty);
2437 $sql .= ", tva_tx=".price2num($this->tva_tx);
2438 $sql .= ", vat_src_code='".$this->db->escape($this->vat_src_code)."'";
2439 $sql .= ", localtax1_tx=".price2num($this->localtax1_tx);
2440 $sql .= ", localtax1_type='".$this->db->escape($this->localtax1_type)."'";
2441 $sql .= ", localtax2_tx=".price2num($this->localtax2_tx);
2442 $sql .= ", localtax2_type='".$this->db->escape($this->localtax2_type)."'";
2443 $sql .= ", fk_product=".($this->fk_product > 0 ? $this->fk_product : "null");
2444 $sql .= ", product_type=".((int) $this->product_type);
2445 $sql .= ", remise_percent=".price2num($this->remise_percent);
2446 $sql .= ", subprice=".price2num($this->subprice);
2447 $sql .= ", info_bits=".price2num($this->info_bits);
2448 $sql .= ", date_start_fill=".(int) $this->date_start_fill;
2449 $sql .= ", date_end_fill=".(int) $this->date_end_fill;
2450 if (empty($this->skip_update_total)) {
2451 $sql .= ", total_ht=".price2num($this->total_ht);
2452 $sql .= ", total_tva=".price2num($this->total_tva);
2453 $sql .= ", total_localtax1=".price2num($this->total_localtax1);
2454 $sql .= ", total_localtax2=".price2num($this->total_localtax2);
2455 $sql .= ", total_ttc=".price2num($this->total_ttc);
2456 }
2457 $sql .= ", rang=".((int) $this->rang);
2458 $sql .= ", special_code=".((int) $this->special_code);
2459 $sql .= ", fk_unit=".($this->fk_unit ? "'".$this->db->escape($this->fk_unit)."'" : "null");
2460 $sql .= ", fk_contract_line=".($this->fk_contract_line ? $this->fk_contract_line : "null");
2461 $sql .= " WHERE rowid = ".((int) $this->id);
2462
2463 $this->db->begin();
2464
2465 dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
2466
2467 $resql = $this->db->query($sql);
2468 if ($resql) {
2469 if (!$error) {
2470 $result = $this->insertExtraFields();
2471 if ($result < 0) {
2472 $error++;
2473 }
2474 }
2475
2476 if (!$error && !$notrigger) {
2477 // Call trigger
2478 $result = $this->call_trigger('LINEBILLREC_MODIFY', $user);
2479 if ($result < 0) {
2480 $error++;
2481 }
2482 // End call triggers
2483 }
2484
2485 if ($error) {
2486 $this->db->rollback();
2487 return -2;
2488 } else {
2489 $this->db->commit();
2490 return 1;
2491 }
2492 } else {
2493 $this->error = $this->db->lasterror();
2494 $this->db->rollback();
2495 return -2;
2496 }
2497 }
2498}
$object ref
Definition info.php:79
Superclass for invoice classes.
const TYPE_STANDARD
Standard invoice.
calculate_date_lim_reglement($cond_reglement=0)
Returns an invoice payment deadline based on the invoice settlement conditions and billing date.
const STATUS_DRAFT
Draft status.
Parent class of all other business classes for details of elements (invoices, contracts,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
update_price($exclspec=0, $roundingadjust='auto', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif')
Setter generic.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage invoices.
Class to manage invoice lines.
Class to manage invoice lines of templates.
fetch($rowid)
Get line of template invoice.
update(User $user, $notrigger=0)
Update a line to invoice_rec.
Class to manage invoice templates.
setFrequencyAndUnit($frequency, $unit, $notrigger=0)
Update frequency and unit.
getLibStatut($mode=0, $alreadypaid=-1)
Return label of object status.
addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except=0, $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise=0, $date_start_fill=0, $date_end_fill=0, $fk_fournprice=null, $pa_ht=0, $fk_parent_line=0)
Add a line to invoice.
LibStatut($recur, $status, $mode=0, $alreadypaid=-1, $type=0)
Return label of a status.
updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except=0, $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise=0, $notrigger=0, $date_start_fill=0, $date_end_fill=0, $fk_fournprice=null, $pa_ht=0, $fk_parent_line=0)
Update a line to invoice.
fetch_lines()
Get lines of template invoices into this->lines.
info($id)
Load miscellaneous information for tab "Info".
getLinesArray()
Create an array of invoice lines.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $moretitle='', $notooltip=0, $save_lastsearch_value=-1)
Return clickable name (with picto eventually)
isMaxNbGenReached()
Return if maximum number of generation is reached.
setModelPdf($model, $notrigger=0)
Update the model for documents.
getNextNumRef($soc, $mode='next')
Return next reference of invoice not already used (or last reference)
__construct(DoliDB $db)
Constructor.
setNextDate($date, $increment_nb_gen_done=0, $notrigger=0)
Update the next date of execution.
setAutoValidate($validate, $notrigger=0)
Update the auto validate flag of invoice.
initAsSpecimen($option='')
Initialise an instance with random values.
setMaxPeriod($nb, $notrigger=0)
Update the maximum period.
update(User $user, $notrigger=0)
Update a line invoice_rec.
create($user, $facid, $notrigger=0, $onlylines=array())
Create a predefined invoice.
strikeIfMaxNbGenReached($ret)
Format string to output with by striking the string if max number of generation was reached.
fetch($rowid, $ref='', $ref_ext='', $noextrafields=0, $nolines=0)
Load object and lines.
setGeneratePdf($validate, $notrigger=0)
Update the auto generate documents.
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
getNextDate()
Return the next date of.
createRecurringInvoices($restrictioninvoiceid=0, $forcevalidation=0, $notrigger=0)
Create all recurrents invoices (for all entities if multicompany is used).
Class to manage products or services.
Class to manage Dolibarr users.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
getMarginInfos($pv_ht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $pa_ht)
Return an array with margins information of a line.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
Definition price.lib.php:88
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:137