dolibarr 23.0.3
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-2025 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
137 public $remise_percent;
138
142 public $fk_remise_except;
143
147 public $rang = 0;
148
152 public $fk_fournprice;
153
157 public $pa_ht;
158
162 public $marge_tx;
163
167 public $marque_tx;
168
176 public $special_code;
177
184 public $info_bits = 0;
185
190 public $total_ht;
191
196 public $total_tva;
197
202 public $total_ttc;
203
209 public $remise;
210
216 public $price;
217
218 // From llx_product
224 public $ref;
225
230 public $product_ref;
231
237 public $libelle;
238
244 public $label;
245
250 public $product_label;
251
256 public $product_desc;
257
262 public $product_tobatch;
263
268 public $product_barcode;
269
273 public $localtax1_tx;
274
278 public $localtax2_tx;
279
283 public $localtax1_type;
284
288 public $localtax2_type;
289
293 public $total_localtax1;
294
298 public $total_localtax2;
299
303 public $date_start;
304
308 public $date_end;
309
313 public $skip_update_total;
314
315 // Multicurrency
319 public $fk_multicurrency;
320
324 public $multicurrency_code;
325
329 public $multicurrency_subprice;
330
334 public $multicurrency_total_ht;
335
339 public $multicurrency_total_tva;
340
344 public $multicurrency_total_ttc;
345
349 public $packaging;
350
356 public function __construct($db)
357 {
358 $this->db = $db;
359 }
360
367 public function fetch($rowid)
368 {
369 $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,';
370 $sql .= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice,';
371 $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,';
372 $sql .= ' pd.fk_unit,';
373 $sql .= ' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,';
374 $sql .= ' pd.fk_multicurrency, pd.multicurrency_code, pd.multicurrency_subprice, pd.multicurrency_total_ht, pd.multicurrency_total_tva, pd.multicurrency_total_ttc,';
375 $sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,p.barcode as product_barcode,';
376 $sql .= ' p.weight, p.weight_units, p.volume, p.volume_units,';
377 $sql .= ' p.customcode, p.fk_country as country_id, c.code as country_code,';
378 $sql .= ' p.packaging,';
379 $sql .= ' pd.date_start, pd.date_end, pd.product_type, pd.extraparams';
380 $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pd';
381 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pd.fk_product = p.rowid';
382 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON c.rowid = p.fk_country';
383 $sql .= ' WHERE pd.rowid = '.((int) $rowid);
384
385 $result = $this->db->query($sql);
386 if ($result) {
387 $objp = $this->db->fetch_object($result);
388
389 if ($objp) {
390 $this->id = $objp->rowid;
391 $this->rowid = $objp->rowid; // deprecated
392 $this->fk_propal = $objp->fk_propal;
393 $this->fk_parent_line = $objp->fk_parent_line;
394 $this->label = $objp->custom_label;
395 $this->desc = $objp->description;
396 $this->qty = $objp->qty;
397 $this->price = $objp->price; // deprecated
398 $this->subprice = $objp->subprice;
399 $this->vat_src_code = $objp->vat_src_code;
400 $this->tva_tx = $objp->tva_tx;
401 $this->remise = $objp->remise; // deprecated
402 $this->remise_percent = $objp->remise_percent;
403 $this->fk_remise_except = $objp->fk_remise_except;
404 $this->fk_product = $objp->fk_product;
405 $this->info_bits = $objp->info_bits;
406
407 $this->total_ht = $objp->total_ht;
408 $this->total_tva = $objp->total_tva;
409 $this->total_ttc = $objp->total_ttc;
410
411 $this->fk_fournprice = $objp->fk_fournprice;
412
413 $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
414 $this->pa_ht = $marginInfos[0];
415 $this->marge_tx = $marginInfos[1];
416 $this->marque_tx = $marginInfos[2];
417
418 $this->special_code = $objp->special_code;
419 $this->product_type = $objp->product_type;
420 $this->rang = $objp->rang;
421
422 $this->ref = $objp->product_ref; // deprecated
423 $this->product_ref = $objp->product_ref;
424 $this->libelle = $objp->product_label; // deprecated
425 $this->product_label = $objp->product_label;
426 $this->product_desc = $objp->product_desc;
427 $this->product_barcode = $objp->product_barcode;
428 $this->product_custom_code = $objp->customcode;
429 $this->product_custom_country_id = $objp->country_id;
430 $this->product_custom_country_code = $objp->country_code;
431
432 $this->fk_unit = $objp->fk_unit;
433 $this->weight = $objp->weight;
434 $this->weight_units = $objp->weight_units;
435 $this->volume = $objp->volume;
436 $this->volume_units = $objp->volume_units;
437
438 $this->packaging = $objp->packaging;
439
440 $this->date_start = $this->db->jdate($objp->date_start);
441 $this->date_end = $this->db->jdate($objp->date_end);
442
443 $this->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams, true) : array();
444
445 // Multicurrency
446 $this->fk_multicurrency = $objp->fk_multicurrency;
447 $this->multicurrency_code = $objp->multicurrency_code;
448 $this->multicurrency_subprice = $objp->multicurrency_subprice;
449 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
450 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
451 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
452
453 $this->fetch_optionals();
454
455 $this->db->free($result);
456
457 return 1;
458 } else {
459 return 0;
460 }
461 } else {
462 return -1;
463 }
464 }
465
472 public function insert($notrigger = 0)
473 {
474 global $user;
475
476 $error = 0;
477
478 dol_syslog(get_class($this)."::insert rang=".$this->rang);
479
480 $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'.
481 $this->pa_ht = (float) $this->pa_ht; // convert to float after check if empty value
482
483 // Clean parameters
484 if (empty($this->tva_tx)) {
485 $this->tva_tx = 0;
486 }
487 if (empty($this->localtax1_tx)) {
488 $this->localtax1_tx = 0;
489 }
490 if (empty($this->localtax2_tx)) {
491 $this->localtax2_tx = 0;
492 }
493 if (empty($this->localtax1_type)) {
494 $this->localtax1_type = 0;
495 }
496 if (empty($this->localtax2_type)) {
497 $this->localtax2_type = 0;
498 }
499 if (empty($this->total_localtax1)) {
500 $this->total_localtax1 = 0;
501 }
502 if (empty($this->total_localtax2)) {
503 $this->total_localtax2 = 0;
504 }
505 if (empty($this->rang)) {
506 $this->rang = 0;
507 }
508 if (empty($this->remise_percent) || !is_numeric($this->remise_percent)) {
509 $this->remise_percent = 0;
510 }
511 if (empty($this->info_bits)) {
512 $this->info_bits = 0;
513 }
514 if (empty($this->special_code)) {
515 $this->special_code = 0;
516 }
517 if (empty($this->fk_parent_line)) {
518 $this->fk_parent_line = 0;
519 }
520 if (empty($this->fk_fournprice)) {
521 $this->fk_fournprice = 0;
522 }
523 if (!is_numeric($this->qty)) {
524 $this->qty = 0;
525 }
526 if (empty($this->multicurrency_subprice)) {
527 $this->multicurrency_subprice = 0;
528 }
529 if (empty($this->multicurrency_total_ht)) {
530 $this->multicurrency_total_ht = 0;
531 }
532 if (empty($this->multicurrency_total_tva)) {
533 $this->multicurrency_total_tva = 0;
534 }
535 if (empty($this->multicurrency_total_ttc)) {
536 $this->multicurrency_total_ttc = 0;
537 }
538
539 // if buy price not defined, define buyprice as configured in margin admin
540 if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
541 if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) {
542 return $result;
543 } else {
544 $this->pa_ht = $result;
545 }
546 }
547
548 // Check parameters
549 if ($this->product_type < 0) {
550 return -1;
551 }
552
553 $this->db->begin();
554
555 // Insert line into database
556 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'propaldet';
557 $sql .= ' (fk_propal, fk_parent_line, label, description, fk_product, product_type,';
558 $sql .= ' fk_remise_except, qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
559 $sql .= ' subprice, remise_percent, ';
560 $sql .= ' info_bits, ';
561 $sql .= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,';
562 $sql .= ' fk_unit,';
563 $sql .= ' date_start, date_end';
564 $sql .= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc)';
565 $sql .= " VALUES (".$this->fk_propal.",";
566 $sql .= " ".($this->fk_parent_line > 0 ? "'".$this->db->escape((string) $this->fk_parent_line)."'" : "null").",";
567 $sql .= " ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
568 $sql .= " '".$this->db->escape($this->desc)."',";
569 $sql .= " ".($this->fk_product > 0 ? (int) $this->fk_product : "null").",";
570 $sql .= " ".((int) $this->product_type).",";
571 $sql .= " ".($this->fk_remise_except > 0 ? (int) $this->fk_remise_except : "null").",";
572 $sql .= " ".price2num($this->qty, 'MS').",";
573 $sql .= " ".(empty($this->vat_src_code) ? "''" : "'".$this->db->escape($this->vat_src_code)."'").",";
574 $sql .= " ".price2num($this->tva_tx).",";
575 $sql .= " ".price2num($this->localtax1_tx).",";
576 $sql .= " ".price2num($this->localtax2_tx).",";
577 $sql .= " '".$this->db->escape($this->localtax1_type)."',";
578 $sql .= " '".$this->db->escape($this->localtax2_type)."',";
579 $sql .= " ".(price2num($this->subprice) !== '' ? price2num($this->subprice, 'MU') : "null").",";
580 $sql .= " ".price2num($this->remise_percent).",";
581 $sql .= " ".(isset($this->info_bits) ? ((int) $this->info_bits) : "null").",";
582 $sql .= " ".price2num($this->total_ht, 'MT').",";
583 $sql .= " ".price2num($this->total_tva, 'MT').",";
584 $sql .= " ".price2num($this->total_localtax1, 'MT').",";
585 $sql .= " ".price2num($this->total_localtax2, 'MT').",";
586 $sql .= " ".price2num($this->total_ttc, 'MT').",";
587 $sql .= " ".(!empty($this->fk_fournprice) ? "'".$this->db->escape((string) $this->fk_fournprice)."'" : "null").",";
588 $sql .= " ".(isset($this->pa_ht) ? "'".price2num($this->pa_ht)."'" : "null").",";
589 $sql .= ' '.((int) $this->special_code).',';
590 $sql .= ' '.((int) $this->rang).',';
591 $sql .= ' '.(empty($this->fk_unit) ? 'NULL' : ((int) $this->fk_unit)).',';
592 $sql .= " ".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null").',';
593 $sql .= " ".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null");
594 $sql .= ", ".($this->fk_multicurrency > 0 ? ((int) $this->fk_multicurrency) : 'null');
595 $sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
596 $sql .= ", ".price2num($this->multicurrency_subprice, 'CU');
597 $sql .= ", ".price2num($this->multicurrency_total_ht, 'CT');
598 $sql .= ", ".price2num($this->multicurrency_total_tva, 'CT');
599 $sql .= ", ".price2num($this->multicurrency_total_ttc, 'CT');
600 $sql .= ')';
601
602 dol_syslog(get_class($this).'::insert', LOG_DEBUG);
603 $resql = $this->db->query($sql);
604 if ($resql) {
605 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'propaldet');
606 $this->rowid = $this->id;
607 $result = $this->insertExtraFields();
608 if ($result < 0) {
609 $error++;
610 }
611
612 if (!$error && !$notrigger) {
613 // Call trigger
614 $result = $this->call_trigger('LINEPROPAL_INSERT', $user);
615 if ($result < 0) {
616 $this->db->rollback();
617 return -1;
618 }
619 // End call triggers
620 }
621
622 if (!$error) {
623 $this->db->commit();
624 return (int) $this->id;
625 }
626
627 foreach ($this->errors as $errmsg) {
628 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
629 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
630 }
631 $this->db->rollback();
632 return -3;
633 } else {
634 $this->error = $this->db->error()." sql=".$sql;
635 $this->db->rollback();
636 return -2;
637 }
638 }
639
647 public function delete(User $user, $notrigger = 0)
648 {
649 global $conf;
650
651 $error = 0;
652 $this->db->begin();
653
654 if (!$notrigger) {
655 // Call trigger
656 $result = $this->call_trigger('LINEPROPAL_DELETE', $user);
657 if ($result < 0) {
658 $error++;
659 }
660 }
661 // End call triggers
662
663 if (!$error) {
664 $sql = "DELETE FROM " . MAIN_DB_PREFIX . "propaldet WHERE rowid = " . ((int) $this->rowid);
665 dol_syslog("PropaleLigne::delete", LOG_DEBUG);
666 if ($this->db->query($sql)) {
667 // Remove extrafields
668 $this->id = $this->rowid;
669 $result = $this->deleteExtraFields();
670 if ($result < 0) {
671 $error++;
672 dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR);
673 }
674 } else {
675 $this->error = $this->db->error() . " sql=" . $sql;
676 $error++;
677 }
678 }
679
680 if ($error) {
681 $this->db->rollback();
682 return -1;
683 } else {
684 $this->db->commit();
685 return 1;
686 }
687 }
688
695 public function update($notrigger = 0)
696 {
697 global $conf, $user;
698
699 $error = 0;
700
701 $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'.
702
703 if (empty($this->id) && !empty($this->rowid)) {
704 $this->id = $this->rowid;
705 }
706
707 // Clean parameters
708 if (empty($this->tva_tx)) {
709 $this->tva_tx = 0;
710 }
711 if (empty($this->localtax1_tx)) {
712 $this->localtax1_tx = 0;
713 }
714 if (empty($this->localtax2_tx)) {
715 $this->localtax2_tx = 0;
716 }
717 if (empty($this->total_localtax1)) {
718 $this->total_localtax1 = 0;
719 }
720 if (empty($this->total_localtax2)) {
721 $this->total_localtax2 = 0;
722 }
723 if (empty($this->localtax1_type)) {
724 $this->localtax1_type = 0;
725 }
726 if (empty($this->localtax2_type)) {
727 $this->localtax2_type = 0;
728 }
729 if (empty($this->marque_tx)) {
730 $this->marque_tx = 0;
731 }
732 if (empty($this->marge_tx)) {
733 $this->marge_tx = 0;
734 }
735 if (empty($this->price)) {
736 $this->price = 0; // TODO A virer
737 }
738 if (empty($this->remise_percent)) {
739 $this->remise_percent = 0;
740 }
741 if (empty($this->info_bits)) {
742 $this->info_bits = 0;
743 }
744 if (empty($this->special_code)) {
745 $this->special_code = 0;
746 }
747 if (empty($this->fk_parent_line)) {
748 $this->fk_parent_line = 0;
749 }
750 if (empty($this->fk_fournprice)) {
751 $this->fk_fournprice = 0;
752 }
753 if (empty($this->subprice)) {
754 $this->subprice = 0;
755 }
756 if (empty($this->pa_ht)) {
757 $this->pa_ht = 0;
758 }
759
760 // if buy price not defined, define buyprice as configured in margin admin
761 if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
762 if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) {
763 return $result;
764 } else {
765 $this->pa_ht = $result;
766 }
767 }
768
769 $this->db->begin();
770
771 // Mise a jour ligne en base
772 $sql = "UPDATE ".MAIN_DB_PREFIX."propaldet SET";
773 $sql .= " description = '".$this->db->escape($this->desc)."'";
774 $sql .= ", label = ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
775 $sql .= ", product_type = ".((int) $this->product_type);
776 $sql .= ", vat_src_code = '".(empty($this->vat_src_code) ? '' : $this->vat_src_code)."'";
777 $sql .= ", tva_tx='".price2num($this->tva_tx)."'";
778 $sql .= ", localtax1_tx=".price2num($this->localtax1_tx);
779 $sql .= ", localtax2_tx=".price2num($this->localtax2_tx);
780 $sql .= ", localtax1_type='".$this->db->escape($this->localtax1_type)."'";
781 $sql .= ", localtax2_type='".$this->db->escape($this->localtax2_type)."'";
782 $sql .= ", qty = ".((float) price2num($this->qty));
783 $sql .= ", subprice = ".price2num($this->subprice);
784 $sql .= ", remise_percent = ".price2num($this->remise_percent);
785 $sql .= ", price = ".(float) price2num($this->price); // TODO A virer
786 $sql .= ", remise = ".(float) price2num($this->remise); // TODO A virer
787 $sql .= ", info_bits = '".$this->db->escape((string) $this->info_bits)."'";
788 if (empty($this->skip_update_total)) {
789 $sql .= ", total_ht = ".price2num($this->total_ht);
790 $sql .= ", total_tva = ".price2num($this->total_tva);
791 $sql .= ", total_ttc = ".price2num($this->total_ttc);
792 $sql .= ", total_localtax1 = ".price2num($this->total_localtax1);
793 $sql .= ", total_localtax2 = ".price2num($this->total_localtax2);
794 }
795 $sql .= ", fk_product_fournisseur_price=".(!empty($this->fk_fournprice) ? "'".$this->db->escape((string) $this->fk_fournprice)."'" : "null");
796 $sql .= ", buy_price_ht=".price2num($this->pa_ht);
797 $sql .= ", special_code=".((int) $this->special_code);
798 $sql .= ", fk_parent_line=".($this->fk_parent_line > 0 ? (int) $this->fk_parent_line : "null");
799 if (!empty($this->rang)) {
800 $sql .= ", rang=".((int) $this->rang);
801 }
802 $sql .= ", date_start=".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null");
803 $sql .= ", date_end=".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null");
804 $sql .= ", fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
805
806 // Multicurrency
807 $sql .= ", multicurrency_subprice=".price2num($this->multicurrency_subprice);
808 $sql .= ", multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
809 $sql .= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
810 $sql .= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
811
812 $sql .= " WHERE rowid = ".((int) $this->id);
813
814 dol_syslog(get_class($this)."::update", LOG_DEBUG);
815 $resql = $this->db->query($sql);
816 if ($resql) {
817 $result = $this->insertExtraFields();
818 if ($result < 0) {
819 $error++;
820 }
821
822 if (!$error && !$notrigger) {
823 // Call trigger
824 $result = $this->call_trigger('LINEPROPAL_MODIFY', $user);
825 if ($result < 0) {
826 $this->db->rollback();
827 return -1;
828 }
829 // End call triggers
830 }
831
832 if (!$error) {
833 $this->db->commit();
834 return 1;
835 }
836
837 foreach ($this->errors as $errmsg) {
838 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
839 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
840 }
841 $this->db->rollback();
842 return -3;
843 } else {
844 $this->error = $this->db->error();
845 $this->db->rollback();
846 return -2;
847 }
848 }
849
850 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
857 public function update_total()
858 {
859 // phpcs:enable
860 $this->db->begin();
861
862 // Mise a jour ligne en base
863 $sql = "UPDATE ".MAIN_DB_PREFIX."propaldet SET";
864 $sql .= " total_ht=".price2num($this->total_ht, 'MT');
865 $sql .= ",total_tva=".price2num($this->total_tva, 'MT');
866 $sql .= ",total_ttc=".price2num($this->total_ttc, 'MT');
867 $sql .= " WHERE rowid = ".((int) $this->rowid);
868
869 dol_syslog("PropaleLigne::update_total", LOG_DEBUG);
870
871 $resql = $this->db->query($sql);
872 if ($resql) {
873 $this->db->commit();
874 return 1;
875 } else {
876 $this->error = $this->db->error();
877 $this->db->rollback();
878 return -2;
879 }
880 }
881}
$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.
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.