dolibarr 25.0.0-alpha
fournisseur.facture.ligne.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
5 * Copyright (C) 2005 Marc Barilley <marc@ocebo.com>
6 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
7 * Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es>
8 * Copyright (C) 2013-2019 Philippe Grand <philippe.grand@atoo-net.com>
9 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
10 * Copyright (C) 2014-2016 Marcos García <marcosgdf@gmail.com>
11 * Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
12 * Copyright (C) 2015-2022 Ferran Marcet <fmarcet@2byte.es>
13 * Copyright (C) 2016-2023 Alexandre Spangaro <aspangaro@open-dsi.fr>
14 * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
15 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
16 * Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
17 * Copyright (C) 2023 Nick Fragoulis
18 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
19 * Copyright (C) 2024 William Mead <william.mead@manchenumerique.fr>
20 *
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 3 of the License, or
24 * (at your option) any later version.
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * You should have received a copy of the GNU General Public License
32 * along with this program. If not, see <https://www.gnu.org/licenses/>.
33 */
34
41require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
42require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
43require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
44
45if (isModEnabled('accounting')) {
46 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
47 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
48}
49
54{
58 public $element = 'facture_fourn_det';
59
63 public $table_element = 'facture_fourn_det';
64
68 public $parent_element = 'facture_fourn';
69
73 public $fk_parent_attribute = 'fk_facture_fourn';
74
78 public $oldline;
79
85 public $ref;
86
91 public $product_ref;
92
98 public $ref_supplier;
99
104 public $product_desc;
105
112 public $pu_ht;
113
118 public $subprice;
119
126 public $pu_ttc;
127
132 public $subprice_ttc;
133
138 public $fk_facture_fourn;
139
145 public $label;
146
152 public $description;
153
157 public $date_start;
158
162 public $date_end;
163
167 public $fk_code_ventilation;
168
172 public $skip_update_total; // Skip update price total for special lines
173
177 public $situation_percent;
178
182 public $fk_prev_id;
183
188 public $vat_src_code;
189
194 public $tva_tx;
195
200 public $localtax1_tx;
201
206 public $localtax2_tx;
207
212 public $qty;
213
218 public $remise_percent;
219
224 public $pa_ht;
225
230 public $total_ht;
231
236 public $total_ttc;
237
242 public $total_tva;
243
248 public $total_localtax1;
249
254 public $total_localtax2;
255
259 public $fk_product;
260
265 public $product_type;
266
271 public $product_label;
272
279 public $info_bits;
280
285 public $fk_remise_except;
286
290 public $fk_parent_line;
291
295 public $special_code;
296
300 public $rang;
301
306 public $localtax1_type;
307
312 public $localtax2_type;
313
314
320 public function __construct($db)
321 {
322 $this->db = $db;
323 }
324
331 public function fetch($rowid)
332 {
333 $sql = 'SELECT f.rowid, f.ref as ref_supplier, f.description as line_desc, f.date_start, f.date_end, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.tva_tx';
334 $sql .= ', f.localtax1_type, f.localtax2_type, f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2, f.fk_remise_except';
335 $sql .= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_facture_fourn, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line, f.fk_unit, f.extraparams';
336 $sql .= ', p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.description as product_desc';
337 $sql .= ', f.multicurrency_subprice, f.multicurrency_total_ht, f.multicurrency_total_tva, multicurrency_total_ttc';
338 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det as f';
339 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON f.fk_product = p.rowid';
340 $sql .= ' WHERE f.rowid = '.((int) $rowid);
341 $sql .= ' ORDER BY f.rang, f.rowid';
342
343 $query = $this->db->query($sql);
344
345 if (!$query) {
346 $this->errors[] = $this->db->error();
347 return -1;
348 }
349
350 if (!$this->db->num_rows($query)) {
351 return 0;
352 }
353
354 $obj = $this->db->fetch_object($query);
355
356 $this->id = $obj->rowid;
357 $this->rowid = $obj->rowid;
358 $this->fk_facture_fourn = $obj->fk_facture_fourn;
359 $this->description = $obj->line_desc;
360 $this->desc = $obj->line_desc;
361 $this->date_start = $obj->date_start;
362 $this->date_end = $obj->date_end;
363 $this->product_ref = $obj->product_ref;
364 $this->ref_supplier = $obj->ref_supplier;
365 $this->product_desc = $obj->product_desc;
366
367 $this->subprice = $obj->pu_ht;
368 $this->pu_ht = $obj->pu_ht;
369 $this->subprice_ttc = $obj->pu_ttc;
370 $this->pu_ttc = $obj->pu_ttc;
371 $this->tva_tx = $obj->tva_tx;
372 $this->localtax1_tx = $obj->localtax1_tx;
373 $this->localtax2_tx = $obj->localtax2_tx;
374 $this->localtax1_type = $obj->localtax1_type;
375 $this->localtax2_type = $obj->localtax2_type;
376
377 $this->qty = $obj->qty;
378 $this->remise_percent = $obj->remise_percent;
379 $this->fk_remise_except = $obj->fk_remise_except;
380 //$this->tva = $obj->total_tva; // deprecated
381 $this->total_ht = $obj->total_ht;
382 $this->total_tva = $obj->total_tva;
383 $this->total_localtax1 = $obj->total_localtax1;
384 $this->total_localtax2 = $obj->total_localtax2;
385 $this->total_ttc = $obj->total_ttc;
386 $this->fk_product = $obj->fk_product;
387 $this->product_type = $obj->product_type;
388 $this->product_label = $obj->product_label;
389 $this->label = $obj->product_label;
390 $this->info_bits = $obj->info_bits;
391 $this->fk_parent_line = $obj->fk_parent_line;
392 $this->special_code = $obj->special_code;
393 $this->rang = $obj->rang;
394 $this->fk_unit = $obj->fk_unit;
395
396 $this->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams, true) : array();
397
398 $this->multicurrency_subprice = $obj->multicurrency_subprice;
399 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
400 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
401 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
402
403 $this->fetch_optionals();
404
405 return 1;
406 }
407
414 public function delete($notrigger = 0)
415 {
416 global $user;
417
418 dol_syslog(get_class($this)."::deleteline rowid=".((int) $this->id), LOG_DEBUG);
419
420 $error = 0;
421
422 $this->db->begin();
423
424 if (!$notrigger) {
425 if ($this->call_trigger('LINEBILL_SUPPLIER_DELETE', $user) < 0) {
426 $error++;
427 }
428 }
429
430 $this->deleteObjectLinked();
431
432 // Remove extrafields
433 if (!$error) {
434 $result = $this->deleteExtraFields();
435 if ($result < 0) {
436 $error++;
437 dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
438 }
439 }
440
441 if (!$error) {
442 // Delete line
443 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn_det ';
444 $sql .= " WHERE rowid = ".((int) $this->id);
445 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
446 $resql = $this->db->query($sql);
447 if (!$resql) {
448 $error++;
449 $this->error = $this->db->lasterror();
450 }
451 }
452
453 if (!$error) {
454 $this->db->commit();
455 return 1;
456 } else {
457 $this->db->rollback();
458 return -1;
459 }
460 }
461
468 public function update($notrigger = 0)
469 {
470 global $user;
471
472 $pu = price2num($this->subprice);
473 $qty = price2num($this->qty);
474
475 // Check parameters
476 if (empty($this->qty)) {
477 $this->qty = 0;
478 }
479
480 if ($this->product_type < 0) {
481 return -1;
482 }
483
484 // Clean parameters
485 if (empty($this->subprice_ttc)) {
486 $this->subprice_ttc = 0;
487 }
488 if (empty($this->remise_percent)) {
489 $this->remise_percent = 0;
490 }
491 if (empty($this->tva_tx)) {
492 $this->tva_tx = 0;
493 }
494 if (empty($this->localtax1_tx)) {
495 $this->localtax1_tx = 0;
496 }
497 if (empty($this->localtax2_tx)) {
498 $this->localtax2_tx = 0;
499 }
500
501 if (empty($this->pa_ht)) {
502 $this->pa_ht = 0;
503 }
504 if (empty($this->multicurrency_subprice)) {
505 $this->multicurrency_subprice = 0;
506 }
507 if (empty($this->multicurrency_total_ht)) {
508 $this->multicurrency_total_ht = 0;
509 }
510 if (empty($this->multicurrency_total_tva)) {
511 $this->multicurrency_total_tva = 0;
512 }
513 if (empty($this->multicurrency_total_ttc)) {
514 $this->multicurrency_total_ttc = 0;
515 }
516
517 $fk_product = (int) $this->fk_product;
518 $fk_unit = (int) $this->fk_unit;
519
520 $this->db->begin();
521
522 $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_det SET";
523 $sql .= " description = '".$this->db->escape(empty($this->description) ? $this->desc : $this->description)."'";
524 $sql .= ", ref = '".$this->db->escape($this->ref_supplier ? $this->ref_supplier : $this->ref)."'";
525 $sql .= ", date_start = ".($this->date_start != '' ? "'".$this->db->idate($this->date_start)."'" : "null");
526 $sql .= ", date_end = ".($this->date_end != '' ? "'".$this->db->idate($this->date_end)."'" : "null");
527 $sql .= ", pu_ht = ".price2num($this->subprice);
528 $sql .= ", pu_ttc = ".price2num($this->subprice_ttc);
529 $sql .= ", qty = ".price2num($this->qty);
530 $sql .= ", remise_percent = ".price2num($this->remise_percent);
531 if ($this->fk_remise_except > 0) {
532 $sql .= ", fk_remise_except=".((int) $this->fk_remise_except);
533 } else {
534 $sql .= ", fk_remise_except=null";
535 }
536 $sql .= ", vat_src_code = '".$this->db->escape(empty($this->vat_src_code) ? '' : $this->vat_src_code)."'";
537 $sql .= ", tva_tx = ".price2num($this->tva_tx);
538 $sql .= ", localtax1_tx = ".price2num($this->localtax1_tx);
539 $sql .= ", localtax2_tx = ".price2num($this->localtax2_tx);
540 $sql .= ", localtax1_type = '".$this->db->escape((string) $this->localtax1_type)."'";
541 $sql .= ", localtax2_type = '".$this->db->escape((string) $this->localtax2_type)."'";
542 $sql .= ", total_ht = ".price2num($this->total_ht);
543 $sql .= ", tva= ".price2num($this->total_tva);
544 $sql .= ", total_localtax1= ".price2num($this->total_localtax1);
545 $sql .= ", total_localtax2= ".price2num($this->total_localtax2);
546 $sql .= ", total_ttc = ".price2num($this->total_ttc);
547 $sql .= ", fk_product = ".($fk_product > 0 ? (int) $fk_product : 'null');
548 $sql .= ", product_type = ".((int) $this->product_type);
549 $sql .= ", info_bits = ".((int) $this->info_bits);
550 $sql .= ", fk_unit = ".($fk_unit > 0 ? (int) $fk_unit : 'null');
551
552 if (!empty($this->rang)) {
553 $sql .= ", rang=".((int) $this->rang);
554 }
555
556 // Multicurrency
557 $sql .= " , multicurrency_subprice=".price2num($this->multicurrency_subprice);
558 $sql .= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
559 $sql .= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
560 $sql .= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
561
562 $sql .= " WHERE rowid = ".((int) $this->id);
563
564 dol_syslog(get_class($this)."::update", LOG_DEBUG);
565 $resql = $this->db->query($sql);
566
567 if (!$resql) {
568 $this->db->rollback();
569 $this->error = $this->db->lasterror();
570 return -1;
571 }
572
573 $this->rowid = $this->id;
574 $error = 0;
575
576 if (!$error) {
577 $result = $this->insertExtraFields();
578 if ($result < 0) {
579 $error++;
580 }
581 }
582
583 if (!$error && !$notrigger) {
584 // Call trigger
585 if ($this->call_trigger('LINEBILL_SUPPLIER_MODIFY', $user) < 0) {
586 $this->db->rollback();
587 return -1;
588 }
589 // End call triggers
590 }
591
592 if ($error) {
593 $this->db->rollback();
594 return -1;
595 }
596
597 $this->db->commit();
598 return 1;
599 }
600
608 public function insert($notrigger = 0, $noerrorifdiscountalreadylinked = 0)
609 {
610 global $user, $langs;
611
612 $error = 0;
613
614 dol_syslog(get_class($this)."::insert rang=".$this->rang, LOG_DEBUG);
615
616 // Clean parameters
617 $this->desc = trim($this->desc);
618 if (empty($this->tva_tx)) {
619 $this->tva_tx = 0;
620 }
621 if (empty($this->localtax1_tx)) {
622 $this->localtax1_tx = 0;
623 }
624 if (empty($this->localtax2_tx)) {
625 $this->localtax2_tx = 0;
626 }
627 if (empty($this->localtax1_type)) {
628 $this->localtax1_type = 0.0;
629 }
630 if (empty($this->localtax2_type)) {
631 $this->localtax2_type = 0.0;
632 }
633 if (empty($this->total_tva)) {
634 $this->total_tva = 0;
635 }
636 if (empty($this->total_localtax1)) {
637 $this->total_localtax1 = 0;
638 }
639 if (empty($this->total_localtax2)) {
640 $this->total_localtax2 = 0;
641 }
642 if (empty($this->rang)) {
643 $this->rang = 0;
644 }
645 if (empty($this->remise_percent)) {
646 $this->remise_percent = 0;
647 }
648 if (empty($this->info_bits)) {
649 $this->info_bits = 0;
650 }
651 if (empty($this->subprice)) {
652 $this->subprice = 0;
653 }
654 if (empty($this->subprice_ttc)) {
655 $this->subprice_ttc = 0;
656 }
657 if (empty($this->special_code)) {
658 $this->special_code = 0;
659 }
660 if (empty($this->fk_parent_line)) {
661 $this->fk_parent_line = 0;
662 }
663 if (!isset($this->situation_percent) || $this->situation_percent > 100 || (string) $this->situation_percent == '') {
664 $this->situation_percent = 100;
665 }
666
667 if (empty($this->pa_ht)) {
668 $this->pa_ht = 0;
669 }
670 if (empty($this->multicurrency_subprice)) {
671 $this->multicurrency_subprice = 0;
672 }
673 if (empty($this->multicurrency_total_ht)) {
674 $this->multicurrency_total_ht = 0;
675 }
676 if (empty($this->multicurrency_total_tva)) {
677 $this->multicurrency_total_tva = 0;
678 }
679 if (empty($this->multicurrency_total_ttc)) {
680 $this->multicurrency_total_ttc = 0;
681 }
682
683
684 // Check parameters
685 if ($this->product_type < 0) {
686 $this->error = 'ErrorProductTypeMustBe0orMore';
687 return -1;
688 }
689 if (!empty($this->fk_product) && $this->fk_product > 0) {
690 // Check product exists
691 $result = Product::isExistingObject('product', $this->fk_product);
692 if ($result <= 0) {
693 $this->error = 'ErrorProductIdDoesNotExists';
694 return -1;
695 }
696 }
697
698 $this->db->begin();
699
700 // Insert line into database
701 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element;
702 $sql .= ' (fk_facture_fourn, fk_parent_line, label, description, ref, qty,';
703 $sql .= ' vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
704 $sql .= ' fk_product, product_type, remise_percent, fk_remise_except, pu_ht, pu_ttc,';
705 $sql .= ' date_start, date_end, fk_code_ventilation, rang, special_code,';
706 $sql .= ' info_bits, total_ht, tva, total_ttc, total_localtax1, total_localtax2, fk_unit';
707 $sql .= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
708 $sql .= ')';
709 $sql .= " VALUES (".((int) $this->fk_facture_fourn).",";
710 $sql .= " ".($this->fk_parent_line > 0 ? "'".$this->db->escape((string) $this->fk_parent_line)."'" : "null").",";
711 $product_label
712 = !empty($this->product_label)
713 ? $this->product_label :
714 (!empty($this->label) ? $this->label : null);
715 $sql .= " ".(!empty($product_label) ? "'".$this->db->escape($product_label)."'" : "null").",";
716 $sql .= " '".$this->db->escape($this->desc ? $this->desc : $this->description)."',";
717 $sql .= " '".$this->db->escape($this->ref_supplier)."',";
718 $sql .= " ".price2num($this->qty).",";
719
720 $sql .= " ".(empty($this->vat_src_code) ? "''" : "'".$this->db->escape($this->vat_src_code)."'").",";
721 $sql .= " ".price2num($this->tva_tx).",";
722 $sql .= " ".price2num($this->localtax1_tx).",";
723 $sql .= " ".price2num($this->localtax2_tx).",";
724 $sql .= " '".$this->db->escape((string) $this->localtax1_type)."',";
725 $sql .= " '".$this->db->escape((string) $this->localtax2_type)."',";
726 $sql .= ' '.((!empty($this->fk_product) && $this->fk_product > 0) ? ((int) $this->fk_product) : "null").',';
727 $sql .= " ".((int) $this->product_type).",";
728 $sql .= " ".price2num($this->remise_percent).",";
729 $sql .= ' '.(!empty($this->fk_remise_except) ? ((int) $this->fk_remise_except) : "null").',';
730 $sql .= " ".price2num($this->subprice).",";
731 // pu_ttc holds the TTC entry mode: the typed TTC unit price when entered including tax, 0 otherwise (like update()).
732 $sql .= " ".price2num($this->subprice_ttc).",";
733 $sql .= " ".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null").",";
734 $sql .= " ".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null").",";
735 $sql .= ' '.(!empty($this->fk_code_ventilation) ? ((int) $this->fk_code_ventilation) : 0).',';
736 $sql .= ' '.((int) $this->rang).',';
737 $sql .= ' '.((int) $this->special_code).',';
738 $sql .= " ".((int) $this->info_bits).",";
739 $sql .= " ".price2num($this->total_ht).",";
740 $sql .= " ".price2num($this->total_tva).",";
741 $sql .= " ".price2num($this->total_ttc).",";
742 $sql .= " ".price2num($this->total_localtax1).",";
743 $sql .= " ".price2num($this->total_localtax2);
744 $sql .= ", ".(!$this->fk_unit ? 'NULL' : ((int) $this->fk_unit));
745 $sql .= ", ".(int) $this->fk_multicurrency;
746 $sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
747 $sql .= ", ".price2num($this->multicurrency_subprice);
748 $sql .= ", ".price2num($this->multicurrency_total_ht);
749 $sql .= ", ".price2num($this->multicurrency_total_tva);
750 $sql .= ", ".price2num($this->multicurrency_total_ttc);
751 $sql .= ')';
752
753 $resql = $this->db->query($sql);
754 if ($resql) {
755 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
756 $this->rowid = $this->id; // backward compatibility
757
758 if (!$error) {
759 $result = $this->insertExtraFields();
760 if ($result < 0) {
761 $error++;
762 }
763 }
764
765 // Si fk_remise_except defini, on lie la remise a la facture
766 // ce qui la flague comme "consommee".
767 if ($this->fk_remise_except) {
768 $discount = new DiscountAbsolute($this->db);
769 $result = $discount->fetch($this->fk_remise_except);
770 if ($result >= 0) {
771 // Check if discount was found
772 if ($result > 0) {
773 // Check if discount not already affected to another invoice
774 if ($discount->fk_facture_line > 0) {
775 if (empty($noerrorifdiscountalreadylinked)) {
776 $this->error = $langs->trans("ErrorDiscountAlreadyUsed", $discount->id);
777 dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR);
778 $this->db->rollback();
779 return -3;
780 }
781 } else {
782 $result = $discount->link_to_invoice($this->id, 0);
783 if ($result < 0) {
784 $this->error = $discount->error;
785 dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR);
786 $this->db->rollback();
787 return -3;
788 }
789 }
790 } else {
791 $this->error = $langs->trans("ErrorADiscountThatHasBeenRemovedIsIncluded");
792 dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR);
793 $this->db->rollback();
794 return -3;
795 }
796 } else {
797 $this->error = $discount->error;
798 dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR);
799 $this->db->rollback();
800 return -3;
801 }
802 }
803
804 if (!$error && !$notrigger) {
805 // Call trigger
806 $result = $this->call_trigger('LINEBILL_SUPPLIER_CREATE', $user);
807 if ($result < 0) {
808 $this->db->rollback();
809 return -2;
810 }
811 // End call triggers
812 }
813
814 if (!$error) {
815 $this->db->commit();
816 return $this->id;
817 }
818
819 foreach ($this->errors as $errmsg) {
820 dol_syslog(get_class($this)."::insert ".$errmsg, LOG_ERR);
821 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
822 }
823
824 $this->db->rollback();
825 return -3;
826 } else {
827 $this->error = $this->db->error();
828 $this->db->rollback();
829 return -2;
830 }
831 }
832
833 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
839 public function update_total()
840 {
841 // phpcs:enable
842 $this->db->begin();
843
844 // Update line in database
845 $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_det SET";
846 $sql .= " total_ht = ".price2num($this->total_ht);
847 $sql .= ", tva= ".price2num($this->total_tva);
848 $sql .= ", total_localtax1 = ".price2num($this->total_localtax1);
849 $sql .= ", total_localtax2 = ".price2num($this->total_localtax2);
850 $sql .= ", total_ttc = ".price2num($this->total_ttc);
851 $sql .= " WHERE rowid = ".((int) $this->id);
852
853 dol_syslog("FactureFournisseurLigne.class.php::update_total", LOG_DEBUG);
854
855 $resql = $this->db->query($sql);
856 if ($resql) {
857 $this->db->commit();
858 return 1;
859 } else {
860 $this->error = $this->db->error();
861 $this->db->rollback();
862 return -2;
863 }
864 }
865}
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...
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
static isExistingObject($element, $id, $ref='', $ref_ext='')
Check if an object id or ref exists If you don't need or want to instantiate the object and just need...
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage absolute discounts.
Class to manage line invoices.
fetch($rowid)
Retrieves a supplier invoice line.
update($notrigger=0)
Update a supplier invoice line.
insert($notrigger=0, $noerrorifdiscountalreadylinked=0)
Insert line into database.
update_total()
Update invoice supplier line into database.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.