dolibarr 25.0.0-alpha
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 * Copyright (C) 2026 Lionel Vessiller <lvessiller@open-dsi.fr>
24 *
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 3 of the License, or
28 * (at your option) any later version.
29 *
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
34 *
35 * You should have received a copy of the GNU General Public License
36 * along with this program. If not, see <https://www.gnu.org/licenses/>.
37 */
38
45require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
46require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
47require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
48
53{
57 public $element = 'propaldet';
58
62 public $table_element = 'propaldet';
63
67 public $parent_element = 'propal';
68
72 public $fk_parent_attribute = 'fk_propal';
73
77 public $oldline;
78
79 // From llx_propaldet
83 public $fk_propal;
84
88 public $fk_parent_line;
89
93 public $desc;
94
98 public $fk_product;
99
106 public $fk_product_type;
112 public $product_type = Product::TYPE_PRODUCT;
113
117 public $qty;
118
122 public $tva_tx;
123
127 public $vat_src_code;
128
133 public $subprice;
134
140 public $subprice_ttc = 0;
141
145 public $remise_percent;
146
150 public $fk_remise_except;
151
155 public $rang = 0;
156
160 public $fk_fournprice;
161
165 public $pa_ht;
166
170 public $marge_tx;
171
175 public $marque_tx;
176
184 public $special_code;
185
192 public $info_bits = 0;
193
198 public $total_ht;
199
204 public $total_tva;
205
210 public $total_ttc;
211
217 public $remise;
218
224 public $price;
225
226 // From llx_product
232 public $ref;
233
238 public $product_ref;
239
245 public $libelle;
246
252 public $label;
253
258 public $product_label;
259
264 public $product_desc;
265
270 public $product_tobatch;
271
276 public $product_barcode;
277
281 public $localtax1_tx;
282
286 public $localtax2_tx;
287
291 public $localtax1_type;
292
296 public $localtax2_type;
297
301 public $total_localtax1;
302
306 public $total_localtax2;
307
311 public $date_start;
312
316 public $date_end;
317
321 public $skip_update_total;
322
323 // Multicurrency
327 public $fk_multicurrency;
328
332 public $multicurrency_code;
333
337 public $multicurrency_subprice;
338
342 public $multicurrency_total_ht;
343
347 public $multicurrency_total_tva;
348
352 public $multicurrency_total_ttc;
353
357 public $packaging;
358
364 public function __construct($db)
365 {
366 $this->db = $db;
367 }
368
375 public function fetch($rowid)
376 {
377 $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,';
378 $sql .= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice, pd.subprice_ttc,';
379 $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,';
380 $sql .= ' pd.fk_unit,';
381 $sql .= ' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,';
382 $sql .= ' pd.fk_multicurrency, pd.multicurrency_code, pd.multicurrency_subprice, pd.multicurrency_total_ht, pd.multicurrency_total_tva, pd.multicurrency_total_ttc,';
383 $sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,p.barcode as product_barcode,';
384 $sql .= ' p.weight, p.weight_units, p.volume, p.volume_units,';
385 $sql .= ' p.customcode, p.fk_country as country_id, c.code as country_code,';
386 $sql .= ' p.packaging,';
387 $sql .= ' pd.date_start, pd.date_end, pd.product_type, pd.extraparams';
388 $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pd';
389 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pd.fk_product = p.rowid';
390 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON c.rowid = p.fk_country';
391 $sql .= ' WHERE pd.rowid = '.((int) $rowid);
392
393 $result = $this->db->query($sql);
394 if ($result) {
395 $objp = $this->db->fetch_object($result);
396
397 if ($objp) {
398 $this->id = $objp->rowid;
399 $this->rowid = $objp->rowid; // deprecated
400 $this->fk_propal = $objp->fk_propal;
401 $this->fk_parent_line = $objp->fk_parent_line;
402 $this->label = $objp->custom_label;
403 $this->desc = $objp->description;
404 $this->qty = $objp->qty;
405 $this->price = $objp->price; // deprecated
406 $this->subprice = $objp->subprice;
407 $this->subprice_ttc = $objp->subprice_ttc;
408 $this->vat_src_code = $objp->vat_src_code;
409 $this->tva_tx = $objp->tva_tx;
410 $this->remise = $objp->remise; // deprecated
411 $this->remise_percent = $objp->remise_percent;
412 $this->fk_remise_except = $objp->fk_remise_except;
413 $this->fk_product = $objp->fk_product;
414 $this->info_bits = $objp->info_bits;
415
416 $this->total_ht = $objp->total_ht;
417 $this->total_tva = $objp->total_tva;
418 $this->total_ttc = $objp->total_ttc;
419
420 $this->fk_fournprice = $objp->fk_fournprice;
421
422 $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
423 $this->pa_ht = $marginInfos[0];
424 $this->marge_tx = $marginInfos[1];
425 $this->marque_tx = $marginInfos[2];
426
427 $this->special_code = $objp->special_code;
428 $this->product_type = $objp->product_type;
429 $this->rang = $objp->rang;
430
431 $this->ref = $objp->product_ref; // deprecated
432 $this->product_ref = $objp->product_ref;
433 $this->libelle = $objp->product_label; // deprecated
434 $this->product_label = $objp->product_label;
435 $this->product_desc = $objp->product_desc;
436 $this->product_barcode = $objp->product_barcode;
437 $this->product_custom_code = $objp->customcode;
438 $this->product_custom_country_id = $objp->country_id;
439 $this->product_custom_country_code = $objp->country_code;
440
441 $this->fk_unit = $objp->fk_unit;
442 $this->weight = $objp->weight;
443 $this->weight_units = $objp->weight_units;
444 $this->volume = $objp->volume;
445 $this->volume_units = $objp->volume_units;
446
447 $this->packaging = $objp->packaging;
448
449 $this->date_start = $this->db->jdate($objp->date_start);
450 $this->date_end = $this->db->jdate($objp->date_end);
451
452 $this->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams, true) : array();
453
454 // Multicurrency
455 $this->fk_multicurrency = $objp->fk_multicurrency;
456 $this->multicurrency_code = $objp->multicurrency_code;
457 $this->multicurrency_subprice = $objp->multicurrency_subprice;
458 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
459 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
460 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
461
462 $this->fetch_optionals();
463
464 $this->db->free($result);
465
466 return 1;
467 } else {
468 return 0;
469 }
470 } else {
471 return -1;
472 }
473 }
474
481 public function insert($notrigger = 0)
482 {
483 global $user;
484
485 $error = 0;
486
487 dol_syslog(get_class($this)."::insert rang=".$this->rang);
488
489 $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'.
490 $this->pa_ht = (float) $this->pa_ht; // convert to float after check if empty value
491
492 // Clean parameters
493 if (empty($this->tva_tx)) {
494 $this->tva_tx = 0;
495 }
496 if (empty($this->localtax1_tx)) {
497 $this->localtax1_tx = 0;
498 }
499 if (empty($this->localtax2_tx)) {
500 $this->localtax2_tx = 0;
501 }
502 if (empty($this->localtax1_type)) {
503 $this->localtax1_type = 0;
504 }
505 if (empty($this->localtax2_type)) {
506 $this->localtax2_type = 0;
507 }
508 if (empty($this->total_localtax1)) {
509 $this->total_localtax1 = 0;
510 }
511 if (empty($this->total_localtax2)) {
512 $this->total_localtax2 = 0;
513 }
514 if (empty($this->subprice_ttc)) {
515 $this->subprice_ttc = 0;
516 }
517 if (empty($this->rang)) {
518 $this->rang = 0;
519 }
520 if (empty($this->remise_percent) || !is_numeric($this->remise_percent)) {
521 $this->remise_percent = 0;
522 }
523 if (empty($this->info_bits)) {
524 $this->info_bits = 0;
525 }
526 if (empty($this->special_code)) {
527 $this->special_code = 0;
528 }
529 if (empty($this->fk_parent_line)) {
530 $this->fk_parent_line = 0;
531 }
532 if (empty($this->fk_fournprice)) {
533 $this->fk_fournprice = 0;
534 }
535 if (!is_numeric($this->qty)) {
536 $this->qty = 0;
537 }
538 if (empty($this->multicurrency_subprice)) {
539 $this->multicurrency_subprice = 0;
540 }
541 if (empty($this->multicurrency_total_ht)) {
542 $this->multicurrency_total_ht = 0;
543 }
544 if (empty($this->multicurrency_total_tva)) {
545 $this->multicurrency_total_tva = 0;
546 }
547 if (empty($this->multicurrency_total_ttc)) {
548 $this->multicurrency_total_ttc = 0;
549 }
550
551 // if buy price not defined, define buyprice as configured in margin admin
552 if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
553 if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) {
554 return $result;
555 } else {
556 $this->pa_ht = $result;
557 }
558 }
559
560 // Check parameters
561 if ($this->product_type < 0) {
562 return -1;
563 }
564
565 $this->db->begin();
566
567 // Insert line into database
568 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'propaldet';
569 $sql .= ' (fk_propal, fk_parent_line, label, description, fk_product, product_type,';
570 $sql .= ' fk_remise_except, qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
571 $sql .= ' subprice, subprice_ttc, remise_percent, ';
572 $sql .= ' info_bits, ';
573 $sql .= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,';
574 $sql .= ' fk_unit,';
575 $sql .= ' date_start, date_end';
576 $sql .= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc)';
577 $sql .= " VALUES (".((int) $this->fk_propal).",";
578 $sql .= " ".($this->fk_parent_line > 0 ? "'".$this->db->escape((string) $this->fk_parent_line)."'" : "null").",";
579 $sql .= " ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
580 $sql .= " '".$this->db->escape($this->desc)."',";
581 $sql .= " ".($this->fk_product > 0 ? (int) $this->fk_product : "null").",";
582 $sql .= " ".((int) $this->product_type).",";
583 $sql .= " ".($this->fk_remise_except > 0 ? (int) $this->fk_remise_except : "null").",";
584 $sql .= " ".price2num($this->qty, 'MS').",";
585 $sql .= " ".(empty($this->vat_src_code) ? "''" : "'".$this->db->escape($this->vat_src_code)."'").",";
586 $sql .= " ".price2num($this->tva_tx).",";
587 $sql .= " ".price2num($this->localtax1_tx).",";
588 $sql .= " ".price2num($this->localtax2_tx).",";
589 $sql .= " '".$this->db->escape($this->localtax1_type)."',";
590 $sql .= " '".$this->db->escape($this->localtax2_type)."',";
591 $sql .= " ".(price2num($this->subprice) !== '' ? price2num($this->subprice, 'MU') : "null").",";
592 $sql .= " ".price2num($this->subprice_ttc, 'MU').",";
593 $sql .= " ".price2num($this->remise_percent).",";
594 $sql .= " ".(isset($this->info_bits) ? ((int) $this->info_bits) : "null").",";
595 $sql .= " ".price2num($this->total_ht, 'MT').",";
596 $sql .= " ".price2num($this->total_tva, 'MT').",";
597 $sql .= " ".price2num($this->total_localtax1, 'MT').",";
598 $sql .= " ".price2num($this->total_localtax2, 'MT').",";
599 $sql .= " ".price2num($this->total_ttc, 'MT').",";
600 $sql .= " ".(!empty($this->fk_fournprice) ? "'".$this->db->escape((string) $this->fk_fournprice)."'" : "null").",";
601 $sql .= " ".(isset($this->pa_ht) ? "'".price2num($this->pa_ht)."'" : "null").",";
602 $sql .= ' '.((int) $this->special_code).',';
603 $sql .= ' '.((int) $this->rang).',';
604 $sql .= ' '.(empty($this->fk_unit) ? 'NULL' : ((int) $this->fk_unit)).',';
605 $sql .= " ".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null").',';
606 $sql .= " ".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null");
607 $sql .= ", ".($this->fk_multicurrency > 0 ? ((int) $this->fk_multicurrency) : 'null');
608 $sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
609 $sql .= ", ".price2num($this->multicurrency_subprice, 'CU');
610 $sql .= ", ".price2num($this->multicurrency_total_ht, 'CT');
611 $sql .= ", ".price2num($this->multicurrency_total_tva, 'CT');
612 $sql .= ", ".price2num($this->multicurrency_total_ttc, 'CT');
613 $sql .= ')';
614
615 dol_syslog(get_class($this).'::insert', LOG_DEBUG);
616 $resql = $this->db->query($sql);
617 if ($resql) {
618 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'propaldet');
619 $this->rowid = $this->id;
620 $result = $this->insertExtraFields();
621 if ($result < 0) {
622 $error++;
623 }
624
625 if (!$error && !$notrigger) {
626 // Call trigger
627 $result = $this->call_trigger('LINEPROPAL_INSERT', $user);
628 if ($result < 0) {
629 $this->db->rollback();
630 return -1;
631 }
632 // End call triggers
633 }
634
635 if (!$error) {
636 $this->db->commit();
637 return (int) $this->id;
638 }
639
640 foreach ($this->errors as $errmsg) {
641 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
642 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
643 }
644 $this->db->rollback();
645 return -3;
646 } else {
647 $this->error = $this->db->error()." sql=".$sql;
648 $this->db->rollback();
649 return -2;
650 }
651 }
652
660 public function delete(User $user, $notrigger = 0)
661 {
662 global $conf;
663
664 $error = 0;
665 $this->db->begin();
666
667 if (!$notrigger) {
668 // Call trigger
669 $result = $this->call_trigger('LINEPROPAL_DELETE', $user);
670 if ($result < 0) {
671 $error++;
672 }
673 }
674 // End call triggers
675
676 if (!$error) {
677 $sql = "DELETE FROM " . MAIN_DB_PREFIX . "propaldet WHERE rowid = " . ((int) $this->rowid);
678 dol_syslog("PropaleLigne::delete", LOG_DEBUG);
679 if ($this->db->query($sql)) {
680 // Remove extrafields
681 $this->id = $this->rowid;
682 $result = $this->deleteExtraFields();
683 if ($result < 0) {
684 $error++;
685 dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR);
686 }
687 } else {
688 $this->error = $this->db->error() . " sql=" . $sql;
689 $error++;
690 }
691 }
692
693 if ($error) {
694 $this->db->rollback();
695 return -1;
696 } else {
697 $this->db->commit();
698 return 1;
699 }
700 }
701
708 public function update($notrigger = 0)
709 {
710 global $conf, $user;
711
712 $error = 0;
713
714 $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'.
715
716 if (empty($this->id) && !empty($this->rowid)) {
717 $this->id = $this->rowid;
718 }
719
720 // Clean parameters
721 if (empty($this->tva_tx)) {
722 $this->tva_tx = 0;
723 }
724 if (empty($this->localtax1_tx)) {
725 $this->localtax1_tx = 0;
726 }
727 if (empty($this->localtax2_tx)) {
728 $this->localtax2_tx = 0;
729 }
730 if (empty($this->total_localtax1)) {
731 $this->total_localtax1 = 0;
732 }
733 if (empty($this->total_localtax2)) {
734 $this->total_localtax2 = 0;
735 }
736 if (empty($this->localtax1_type)) {
737 $this->localtax1_type = 0;
738 }
739 if (empty($this->localtax2_type)) {
740 $this->localtax2_type = 0;
741 }
742 if (empty($this->marque_tx)) {
743 $this->marque_tx = 0;
744 }
745 if (empty($this->marge_tx)) {
746 $this->marge_tx = 0;
747 }
748 if (empty($this->price)) {
749 $this->price = 0; // TODO A virer
750 }
751 if (empty($this->remise_percent)) {
752 $this->remise_percent = 0;
753 }
754 if (empty($this->info_bits)) {
755 $this->info_bits = 0;
756 }
757 if (empty($this->special_code)) {
758 $this->special_code = 0;
759 }
760 if (empty($this->fk_parent_line)) {
761 $this->fk_parent_line = 0;
762 }
763 if (empty($this->fk_fournprice)) {
764 $this->fk_fournprice = 0;
765 }
766 if (empty($this->subprice)) {
767 $this->subprice = 0;
768 }
769 if (empty($this->subprice_ttc)) {
770 $this->subprice_ttc = 0;
771 }
772 if (empty($this->pa_ht)) {
773 $this->pa_ht = 0;
774 }
775
776 // if buy price not defined, define buyprice as configured in margin admin
777 if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
778 if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) {
779 return $result;
780 } else {
781 $this->pa_ht = $result;
782 }
783 }
784
785 $this->db->begin();
786
787 // Update line in database
788 $sql = "UPDATE ".MAIN_DB_PREFIX."propaldet SET";
789 $sql .= " description = '".$this->db->escape($this->desc)."'";
790 $sql .= ", label = ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
791 $sql .= ", product_type = ".((int) $this->product_type);
792 $sql .= ", vat_src_code = '".(empty($this->vat_src_code) ? '' : $this->db->escape($this->vat_src_code))."'";
793 $sql .= ", tva_tx='".price2num($this->tva_tx)."'";
794 $sql .= ", localtax1_tx=".price2num($this->localtax1_tx);
795 $sql .= ", localtax2_tx=".price2num($this->localtax2_tx);
796 $sql .= ", localtax1_type='".$this->db->escape($this->localtax1_type)."'";
797 $sql .= ", localtax2_type='".$this->db->escape($this->localtax2_type)."'";
798 $sql .= ", qty = ".((float) price2num($this->qty));
799 $sql .= ", subprice = ".price2num($this->subprice);
800 $sql .= ", subprice_ttc = ".price2num($this->subprice_ttc);
801 $sql .= ", remise_percent = ".price2num($this->remise_percent);
802 $sql .= ", price = ".(float) price2num($this->price); // TODO A virer
803 $sql .= ", remise = ".(float) price2num($this->remise); // TODO A virer
804 $sql .= ", info_bits = '".$this->db->escape((string) $this->info_bits)."'";
805 if (empty($this->skip_update_total)) {
806 $sql .= ", total_ht = ".price2num($this->total_ht);
807 $sql .= ", total_tva = ".price2num($this->total_tva);
808 $sql .= ", total_ttc = ".price2num($this->total_ttc);
809 $sql .= ", total_localtax1 = ".price2num($this->total_localtax1);
810 $sql .= ", total_localtax2 = ".price2num($this->total_localtax2);
811 }
812 $sql .= ", fk_product_fournisseur_price=".(!empty($this->fk_fournprice) ? "'".$this->db->escape((string) $this->fk_fournprice)."'" : "null");
813 $sql .= ", buy_price_ht=".price2num($this->pa_ht);
814 $sql .= ", special_code=".((int) $this->special_code);
815 $sql .= ", fk_parent_line=".($this->fk_parent_line > 0 ? (int) $this->fk_parent_line : "null");
816 if (!empty($this->rang)) {
817 $sql .= ", rang=".((int) $this->rang);
818 }
819 $sql .= ", date_start=".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null");
820 $sql .= ", date_end=".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null");
821 $sql .= ", fk_unit=".(!$this->fk_unit ? 'NULL' : ((int) $this->fk_unit));
822
823 // Multicurrency
824 $sql .= ", multicurrency_subprice=".price2num($this->multicurrency_subprice);
825 $sql .= ", multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
826 $sql .= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
827 $sql .= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
828
829 $sql .= " WHERE rowid = ".((int) $this->id);
830
831 dol_syslog(get_class($this)."::update", LOG_DEBUG);
832 $resql = $this->db->query($sql);
833 if ($resql) {
834 $result = $this->insertExtraFields();
835 if ($result < 0) {
836 $error++;
837 }
838
839 if (!$error && !$notrigger) {
840 // Call trigger
841 $result = $this->call_trigger('LINEPROPAL_MODIFY', $user);
842 if ($result < 0) {
843 $this->db->rollback();
844 return -1;
845 }
846 // End call triggers
847 }
848
849 if (!$error) {
850 $this->db->commit();
851 return 1;
852 }
853
854 foreach ($this->errors as $errmsg) {
855 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
856 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
857 }
858 $this->db->rollback();
859 return -3;
860 } else {
861 $this->error = $this->db->error();
862 $this->db->rollback();
863 return -2;
864 }
865 }
866
867 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
874 public function update_total()
875 {
876 // phpcs:enable
877 $this->db->begin();
878
879 // Update line in database
880 $sql = "UPDATE ".MAIN_DB_PREFIX."propaldet SET";
881 $sql .= " total_ht=".price2num($this->total_ht, 'MT');
882 $sql .= ",total_tva=".price2num($this->total_tva, 'MT');
883 $sql .= ",total_ttc=".price2num($this->total_ttc, 'MT');
884 $sql .= " WHERE rowid = ".((int) $this->rowid);
885
886 dol_syslog("PropaleLigne::update_total", LOG_DEBUG);
887
888 $resql = $this->db->query($sql);
889 if ($resql) {
890 $this->db->commit();
891 return 1;
892 } else {
893 $this->error = $this->db->error();
894 $this->db->rollback();
895 return -2;
896 }
897 }
898}
$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.
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.