dolibarr 24.0.0-beta
propaleligne.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 Eric Seigne <eric.seigne@ryxeo.com>
4 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2005 Marc Barilley <marc@ocebo.com>
6 * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
7 * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
8 * Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
9 * Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es>
10 * Copyright (C) 2010-2022 Philippe Grand <philippe.grand@atoo-net.com>
11 * Copyright (C) 2012-2014 Christophe Battarel <christophe.battarel@altairis.fr>
12 * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
13 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
14 * Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
15 * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
16 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
17 * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
18 * Copyright (C) 2022 ATM Consulting <contact@atm-consulting.fr>
19 * Copyright (C) 2022 OpenDSI <support@open-dsi.fr>
20 * Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
21 * Copyright (C) 2023 William Mead <william.mead@manchenumerique.fr>
22 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
23 *
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 3 of the License, or
27 * (at your option) any later version.
28 *
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
33 *
34 * You should have received a copy of the GNU General Public License
35 * along with this program. If not, see <https://www.gnu.org/licenses/>.
36 */
37
44require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
45require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
46require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
47
52{
56 public $element = 'propaldet';
57
61 public $table_element = 'propaldet';
62
66 public $parent_element = 'propal';
67
71 public $fk_parent_attribute = 'fk_propal';
72
76 public $oldline;
77
78 // From llx_propaldet
82 public $fk_propal;
83
87 public $fk_parent_line;
88
92 public $desc;
93
97 public $fk_product;
98
105 public $fk_product_type;
111 public $product_type = Product::TYPE_PRODUCT;
112
116 public $qty;
117
121 public $tva_tx;
122
126 public $vat_src_code;
127
132 public $subprice;
133
139 public $subprice_ttc = 0;
140
144 public $remise_percent;
145
149 public $fk_remise_except;
150
154 public $rang = 0;
155
159 public $fk_fournprice;
160
164 public $pa_ht;
165
169 public $marge_tx;
170
174 public $marque_tx;
175
183 public $special_code;
184
191 public $info_bits = 0;
192
197 public $total_ht;
198
203 public $total_tva;
204
209 public $total_ttc;
210
216 public $remise;
217
223 public $price;
224
225 // From llx_product
231 public $ref;
232
237 public $product_ref;
238
244 public $libelle;
245
251 public $label;
252
257 public $product_label;
258
263 public $product_desc;
264
269 public $product_tobatch;
270
275 public $product_barcode;
276
280 public $localtax1_tx;
281
285 public $localtax2_tx;
286
290 public $localtax1_type;
291
295 public $localtax2_type;
296
300 public $total_localtax1;
301
305 public $total_localtax2;
306
310 public $date_start;
311
315 public $date_end;
316
320 public $skip_update_total;
321
322 // Multicurrency
326 public $fk_multicurrency;
327
331 public $multicurrency_code;
332
336 public $multicurrency_subprice;
337
341 public $multicurrency_total_ht;
342
346 public $multicurrency_total_tva;
347
351 public $multicurrency_total_ttc;
352
356 public $packaging;
357
363 public function __construct($db)
364 {
365 $this->db = $db;
366 }
367
376 public function wasEnteredIncludingTax()
377 {
378 return isset($this->subprice_ttc) && (float) $this->subprice_ttc != 0;
379 }
380
387 public function fetch($rowid)
388 {
389 $sql = 'SELECT pd.rowid, pd.fk_propal, pd.fk_parent_line, pd.fk_product, pd.label as custom_label, pd.description, pd.price, pd.qty, pd.vat_src_code, pd.tva_tx,';
390 $sql .= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice, pd.subprice_ttc,';
391 $sql .= ' pd.info_bits, pd.total_ht, pd.total_tva, pd.total_ttc, pd.fk_product_fournisseur_price as fk_fournprice, pd.buy_price_ht as pa_ht, pd.special_code, pd.rang,';
392 $sql .= ' pd.fk_unit,';
393 $sql .= ' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,';
394 $sql .= ' pd.fk_multicurrency, pd.multicurrency_code, pd.multicurrency_subprice, pd.multicurrency_total_ht, pd.multicurrency_total_tva, pd.multicurrency_total_ttc,';
395 $sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,p.barcode as product_barcode,';
396 $sql .= ' p.weight, p.weight_units, p.volume, p.volume_units,';
397 $sql .= ' p.customcode, p.fk_country as country_id, c.code as country_code,';
398 $sql .= ' p.packaging,';
399 $sql .= ' pd.date_start, pd.date_end, pd.product_type, pd.extraparams';
400 $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pd';
401 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pd.fk_product = p.rowid';
402 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON c.rowid = p.fk_country';
403 $sql .= ' WHERE pd.rowid = '.((int) $rowid);
404
405 $result = $this->db->query($sql);
406 if ($result) {
407 $objp = $this->db->fetch_object($result);
408
409 if ($objp) {
410 $this->id = $objp->rowid;
411 $this->rowid = $objp->rowid; // deprecated
412 $this->fk_propal = $objp->fk_propal;
413 $this->fk_parent_line = $objp->fk_parent_line;
414 $this->label = $objp->custom_label;
415 $this->desc = $objp->description;
416 $this->qty = $objp->qty;
417 $this->price = $objp->price; // deprecated
418 $this->subprice = $objp->subprice;
419 $this->subprice_ttc = $objp->subprice_ttc;
420 $this->vat_src_code = $objp->vat_src_code;
421 $this->tva_tx = $objp->tva_tx;
422 $this->remise = $objp->remise; // deprecated
423 $this->remise_percent = $objp->remise_percent;
424 $this->fk_remise_except = $objp->fk_remise_except;
425 $this->fk_product = $objp->fk_product;
426 $this->info_bits = $objp->info_bits;
427
428 $this->total_ht = $objp->total_ht;
429 $this->total_tva = $objp->total_tva;
430 $this->total_ttc = $objp->total_ttc;
431
432 $this->fk_fournprice = $objp->fk_fournprice;
433
434 $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
435 $this->pa_ht = $marginInfos[0];
436 $this->marge_tx = $marginInfos[1];
437 $this->marque_tx = $marginInfos[2];
438
439 $this->special_code = $objp->special_code;
440 $this->product_type = $objp->product_type;
441 $this->rang = $objp->rang;
442
443 $this->ref = $objp->product_ref; // deprecated
444 $this->product_ref = $objp->product_ref;
445 $this->libelle = $objp->product_label; // deprecated
446 $this->product_label = $objp->product_label;
447 $this->product_desc = $objp->product_desc;
448 $this->product_barcode = $objp->product_barcode;
449 $this->product_custom_code = $objp->customcode;
450 $this->product_custom_country_id = $objp->country_id;
451 $this->product_custom_country_code = $objp->country_code;
452
453 $this->fk_unit = $objp->fk_unit;
454 $this->weight = $objp->weight;
455 $this->weight_units = $objp->weight_units;
456 $this->volume = $objp->volume;
457 $this->volume_units = $objp->volume_units;
458
459 $this->packaging = $objp->packaging;
460
461 $this->date_start = $this->db->jdate($objp->date_start);
462 $this->date_end = $this->db->jdate($objp->date_end);
463
464 $this->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams, true) : array();
465
466 // Multicurrency
467 $this->fk_multicurrency = $objp->fk_multicurrency;
468 $this->multicurrency_code = $objp->multicurrency_code;
469 $this->multicurrency_subprice = $objp->multicurrency_subprice;
470 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
471 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
472 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
473
474 $this->fetch_optionals();
475
476 $this->db->free($result);
477
478 return 1;
479 } else {
480 return 0;
481 }
482 } else {
483 return -1;
484 }
485 }
486
493 public function insert($notrigger = 0)
494 {
495 global $user;
496
497 $error = 0;
498
499 dol_syslog(get_class($this)."::insert rang=".$this->rang);
500
501 $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'.
502 $this->pa_ht = (float) $this->pa_ht; // convert to float after check if empty value
503
504 // Clean parameters
505 if (empty($this->tva_tx)) {
506 $this->tva_tx = 0;
507 }
508 if (empty($this->localtax1_tx)) {
509 $this->localtax1_tx = 0;
510 }
511 if (empty($this->localtax2_tx)) {
512 $this->localtax2_tx = 0;
513 }
514 if (empty($this->localtax1_type)) {
515 $this->localtax1_type = 0;
516 }
517 if (empty($this->localtax2_type)) {
518 $this->localtax2_type = 0;
519 }
520 if (empty($this->total_localtax1)) {
521 $this->total_localtax1 = 0;
522 }
523 if (empty($this->total_localtax2)) {
524 $this->total_localtax2 = 0;
525 }
526 if (empty($this->rang)) {
527 $this->rang = 0;
528 }
529 if (empty($this->remise_percent) || !is_numeric($this->remise_percent)) {
530 $this->remise_percent = 0;
531 }
532 if (empty($this->info_bits)) {
533 $this->info_bits = 0;
534 }
535 if (empty($this->special_code)) {
536 $this->special_code = 0;
537 }
538 if (empty($this->fk_parent_line)) {
539 $this->fk_parent_line = 0;
540 }
541 if (empty($this->fk_fournprice)) {
542 $this->fk_fournprice = 0;
543 }
544 if (!is_numeric($this->qty)) {
545 $this->qty = 0;
546 }
547 if (empty($this->multicurrency_subprice)) {
548 $this->multicurrency_subprice = 0;
549 }
550 if (empty($this->multicurrency_total_ht)) {
551 $this->multicurrency_total_ht = 0;
552 }
553 if (empty($this->multicurrency_total_tva)) {
554 $this->multicurrency_total_tva = 0;
555 }
556 if (empty($this->multicurrency_total_ttc)) {
557 $this->multicurrency_total_ttc = 0;
558 }
559
560 // if buy price not defined, define buyprice as configured in margin admin
561 if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
562 if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) {
563 return $result;
564 } else {
565 $this->pa_ht = $result;
566 }
567 }
568
569 // Check parameters
570 if ($this->product_type < 0) {
571 return -1;
572 }
573
574 $this->db->begin();
575
576 // Insert line into database
577 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'propaldet';
578 $sql .= ' (fk_propal, fk_parent_line, label, description, fk_product, product_type,';
579 $sql .= ' fk_remise_except, qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
580 $sql .= ' subprice, subprice_ttc, remise_percent, ';
581 $sql .= ' info_bits, ';
582 $sql .= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,';
583 $sql .= ' fk_unit,';
584 $sql .= ' date_start, date_end';
585 $sql .= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc)';
586 $sql .= " VALUES (".$this->fk_propal.",";
587 $sql .= " ".($this->fk_parent_line > 0 ? "'".$this->db->escape((string) $this->fk_parent_line)."'" : "null").",";
588 $sql .= " ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
589 $sql .= " '".$this->db->escape($this->desc)."',";
590 $sql .= " ".($this->fk_product > 0 ? (int) $this->fk_product : "null").",";
591 $sql .= " ".((int) $this->product_type).",";
592 $sql .= " ".($this->fk_remise_except > 0 ? (int) $this->fk_remise_except : "null").",";
593 $sql .= " ".price2num($this->qty, 'MS').",";
594 $sql .= " ".(empty($this->vat_src_code) ? "''" : "'".$this->db->escape($this->vat_src_code)."'").",";
595 $sql .= " ".price2num($this->tva_tx).",";
596 $sql .= " ".price2num($this->localtax1_tx).",";
597 $sql .= " ".price2num($this->localtax2_tx).",";
598 $sql .= " '".$this->db->escape($this->localtax1_type)."',";
599 $sql .= " '".$this->db->escape($this->localtax2_type)."',";
600 $sql .= " ".(price2num($this->subprice) !== '' ? price2num($this->subprice, 'MU') : "null").",";
601 $sql .= " ".price2num($this->subprice_ttc, 'MU').",";
602 $sql .= " ".price2num($this->remise_percent).",";
603 $sql .= " ".(isset($this->info_bits) ? ((int) $this->info_bits) : "null").",";
604 $sql .= " ".price2num($this->total_ht, 'MT').",";
605 $sql .= " ".price2num($this->total_tva, 'MT').",";
606 $sql .= " ".price2num($this->total_localtax1, 'MT').",";
607 $sql .= " ".price2num($this->total_localtax2, 'MT').",";
608 $sql .= " ".price2num($this->total_ttc, 'MT').",";
609 $sql .= " ".(!empty($this->fk_fournprice) ? "'".$this->db->escape((string) $this->fk_fournprice)."'" : "null").",";
610 $sql .= " ".(isset($this->pa_ht) ? "'".price2num($this->pa_ht)."'" : "null").",";
611 $sql .= ' '.((int) $this->special_code).',';
612 $sql .= ' '.((int) $this->rang).',';
613 $sql .= ' '.(empty($this->fk_unit) ? 'NULL' : ((int) $this->fk_unit)).',';
614 $sql .= " ".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null").',';
615 $sql .= " ".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null");
616 $sql .= ", ".($this->fk_multicurrency > 0 ? ((int) $this->fk_multicurrency) : 'null');
617 $sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
618 $sql .= ", ".price2num($this->multicurrency_subprice, 'CU');
619 $sql .= ", ".price2num($this->multicurrency_total_ht, 'CT');
620 $sql .= ", ".price2num($this->multicurrency_total_tva, 'CT');
621 $sql .= ", ".price2num($this->multicurrency_total_ttc, 'CT');
622 $sql .= ')';
623
624 dol_syslog(get_class($this).'::insert', LOG_DEBUG);
625 $resql = $this->db->query($sql);
626 if ($resql) {
627 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'propaldet');
628 $this->rowid = $this->id;
629 $result = $this->insertExtraFields();
630 if ($result < 0) {
631 $error++;
632 }
633
634 if (!$error && !$notrigger) {
635 // Call trigger
636 $result = $this->call_trigger('LINEPROPAL_INSERT', $user);
637 if ($result < 0) {
638 $this->db->rollback();
639 return -1;
640 }
641 // End call triggers
642 }
643
644 if (!$error) {
645 $this->db->commit();
646 return (int) $this->id;
647 }
648
649 foreach ($this->errors as $errmsg) {
650 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
651 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
652 }
653 $this->db->rollback();
654 return -3;
655 } else {
656 $this->error = $this->db->error()." sql=".$sql;
657 $this->db->rollback();
658 return -2;
659 }
660 }
661
669 public function delete(User $user, $notrigger = 0)
670 {
671 global $conf;
672
673 $error = 0;
674 $this->db->begin();
675
676 if (!$notrigger) {
677 // Call trigger
678 $result = $this->call_trigger('LINEPROPAL_DELETE', $user);
679 if ($result < 0) {
680 $error++;
681 }
682 }
683 // End call triggers
684
685 if (!$error) {
686 $sql = "DELETE FROM " . MAIN_DB_PREFIX . "propaldet WHERE rowid = " . ((int) $this->rowid);
687 dol_syslog("PropaleLigne::delete", LOG_DEBUG);
688 if ($this->db->query($sql)) {
689 // Remove extrafields
690 $this->id = $this->rowid;
691 $result = $this->deleteExtraFields();
692 if ($result < 0) {
693 $error++;
694 dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR);
695 }
696 } else {
697 $this->error = $this->db->error() . " sql=" . $sql;
698 $error++;
699 }
700 }
701
702 if ($error) {
703 $this->db->rollback();
704 return -1;
705 } else {
706 $this->db->commit();
707 return 1;
708 }
709 }
710
717 public function update($notrigger = 0)
718 {
719 global $conf, $user;
720
721 $error = 0;
722
723 $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'.
724
725 if (empty($this->id) && !empty($this->rowid)) {
726 $this->id = $this->rowid;
727 }
728
729 // Clean parameters
730 if (empty($this->tva_tx)) {
731 $this->tva_tx = 0;
732 }
733 if (empty($this->localtax1_tx)) {
734 $this->localtax1_tx = 0;
735 }
736 if (empty($this->localtax2_tx)) {
737 $this->localtax2_tx = 0;
738 }
739 if (empty($this->total_localtax1)) {
740 $this->total_localtax1 = 0;
741 }
742 if (empty($this->total_localtax2)) {
743 $this->total_localtax2 = 0;
744 }
745 if (empty($this->localtax1_type)) {
746 $this->localtax1_type = 0;
747 }
748 if (empty($this->localtax2_type)) {
749 $this->localtax2_type = 0;
750 }
751 if (empty($this->marque_tx)) {
752 $this->marque_tx = 0;
753 }
754 if (empty($this->marge_tx)) {
755 $this->marge_tx = 0;
756 }
757 if (empty($this->price)) {
758 $this->price = 0; // TODO A virer
759 }
760 if (empty($this->remise_percent)) {
761 $this->remise_percent = 0;
762 }
763 if (empty($this->info_bits)) {
764 $this->info_bits = 0;
765 }
766 if (empty($this->special_code)) {
767 $this->special_code = 0;
768 }
769 if (empty($this->fk_parent_line)) {
770 $this->fk_parent_line = 0;
771 }
772 if (empty($this->fk_fournprice)) {
773 $this->fk_fournprice = 0;
774 }
775 if (empty($this->subprice)) {
776 $this->subprice = 0;
777 }
778 if (empty($this->pa_ht)) {
779 $this->pa_ht = 0;
780 }
781
782 // if buy price not defined, define buyprice as configured in margin admin
783 if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
784 if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) {
785 return $result;
786 } else {
787 $this->pa_ht = $result;
788 }
789 }
790
791 $this->db->begin();
792
793 // Update line in database
794 $sql = "UPDATE ".MAIN_DB_PREFIX."propaldet SET";
795 $sql .= " description = '".$this->db->escape($this->desc)."'";
796 $sql .= ", label = ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
797 $sql .= ", product_type = ".((int) $this->product_type);
798 $sql .= ", vat_src_code = '".(empty($this->vat_src_code) ? '' : $this->vat_src_code)."'";
799 $sql .= ", tva_tx='".price2num($this->tva_tx)."'";
800 $sql .= ", localtax1_tx=".price2num($this->localtax1_tx);
801 $sql .= ", localtax2_tx=".price2num($this->localtax2_tx);
802 $sql .= ", localtax1_type='".$this->db->escape($this->localtax1_type)."'";
803 $sql .= ", localtax2_type='".$this->db->escape($this->localtax2_type)."'";
804 $sql .= ", qty = ".((float) price2num($this->qty));
805 $sql .= ", subprice = ".price2num($this->subprice);
806 $sql .= ", subprice_ttc = ".price2num($this->subprice_ttc);
807 $sql .= ", remise_percent = ".price2num($this->remise_percent);
808 $sql .= ", price = ".(float) price2num($this->price); // TODO A virer
809 $sql .= ", remise = ".(float) price2num($this->remise); // TODO A virer
810 $sql .= ", info_bits = '".$this->db->escape((string) $this->info_bits)."'";
811 if (empty($this->skip_update_total)) {
812 $sql .= ", total_ht = ".price2num($this->total_ht);
813 $sql .= ", total_tva = ".price2num($this->total_tva);
814 $sql .= ", total_ttc = ".price2num($this->total_ttc);
815 $sql .= ", total_localtax1 = ".price2num($this->total_localtax1);
816 $sql .= ", total_localtax2 = ".price2num($this->total_localtax2);
817 }
818 $sql .= ", fk_product_fournisseur_price=".(!empty($this->fk_fournprice) ? "'".$this->db->escape((string) $this->fk_fournprice)."'" : "null");
819 $sql .= ", buy_price_ht=".price2num($this->pa_ht);
820 $sql .= ", special_code=".((int) $this->special_code);
821 $sql .= ", fk_parent_line=".($this->fk_parent_line > 0 ? (int) $this->fk_parent_line : "null");
822 if (!empty($this->rang)) {
823 $sql .= ", rang=".((int) $this->rang);
824 }
825 $sql .= ", date_start=".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null");
826 $sql .= ", date_end=".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null");
827 $sql .= ", fk_unit=".(!$this->fk_unit ? 'NULL' : ((int) $this->fk_unit));
828
829 // Multicurrency
830 $sql .= ", multicurrency_subprice=".price2num($this->multicurrency_subprice);
831 $sql .= ", multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
832 $sql .= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
833 $sql .= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
834
835 $sql .= " WHERE rowid = ".((int) $this->id);
836
837 dol_syslog(get_class($this)."::update", LOG_DEBUG);
838 $resql = $this->db->query($sql);
839 if ($resql) {
840 $result = $this->insertExtraFields();
841 if ($result < 0) {
842 $error++;
843 }
844
845 if (!$error && !$notrigger) {
846 // Call trigger
847 $result = $this->call_trigger('LINEPROPAL_MODIFY', $user);
848 if ($result < 0) {
849 $this->db->rollback();
850 return -1;
851 }
852 // End call triggers
853 }
854
855 if (!$error) {
856 $this->db->commit();
857 return 1;
858 }
859
860 foreach ($this->errors as $errmsg) {
861 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
862 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
863 }
864 $this->db->rollback();
865 return -3;
866 } else {
867 $this->error = $this->db->error();
868 $this->db->rollback();
869 return -2;
870 }
871 }
872
873 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
880 public function update_total()
881 {
882 // phpcs:enable
883 $this->db->begin();
884
885 // Update line in database
886 $sql = "UPDATE ".MAIN_DB_PREFIX."propaldet SET";
887 $sql .= " total_ht=".price2num($this->total_ht, 'MT');
888 $sql .= ",total_tva=".price2num($this->total_tva, 'MT');
889 $sql .= ",total_ttc=".price2num($this->total_ttc, 'MT');
890 $sql .= " WHERE rowid = ".((int) $this->rowid);
891
892 dol_syslog("PropaleLigne::update_total", LOG_DEBUG);
893
894 $resql = $this->db->query($sql);
895 if ($resql) {
896 $this->db->commit();
897 return 1;
898 } else {
899 $this->error = $this->db->error();
900 $this->db->rollback();
901 return -2;
902 }
903 }
904}
$object ref
Definition info.php:90
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...
defineBuyPrice($unitPrice=0.0, $discountPercent=0.0, $fk_product=0)
Get buy price to use for margin calculation.
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 ...
const TYPE_PRODUCT
Regular product.
Class to manage commercial proposal lines.
__construct($db)
Class line Constructor.
update($notrigger=0)
Update propal line object into DB.
fetch($rowid)
Retrieve the propal line object.
insert($notrigger=0)
Insert object line propal in database.
update_total()
Update DB line fields total_xxx Used by migration.
wasEnteredIncludingTax()
Return true if the unit price was originally entered including tax (TTC mode).
Class to manage Dolibarr users.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getMarginInfos($pv_ht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $pa_ht)
Return an array with margins information of a line.