2024-09-05 10:48:31 +00:00
|
|
|
<?php
|
|
|
|
|
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
|
|
|
|
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
|
|
|
|
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
|
|
|
|
* Copyright (C) 2005 Marc Barilley <marc@ocebo.com>
|
|
|
|
|
* Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
|
|
|
|
|
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
|
|
|
|
* Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
|
|
|
|
|
* Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es>
|
|
|
|
|
* Copyright (C) 2010-2022 Philippe Grand <philippe.grand@atoo-net.com>
|
|
|
|
|
* Copyright (C) 2012-2014 Christophe Battarel <christophe.battarel@altairis.fr>
|
|
|
|
|
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
|
|
|
|
|
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
|
|
|
|
* Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
|
|
|
|
|
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
|
2025-08-19 09:24:38 +00:00
|
|
|
* Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
|
2024-09-05 10:48:31 +00:00
|
|
|
* Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
|
|
|
|
|
* Copyright (C) 2022 ATM Consulting <contact@atm-consulting.fr>
|
|
|
|
|
* Copyright (C) 2022 OpenDSI <support@open-dsi.fr>
|
|
|
|
|
* Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
|
|
|
|
|
* Copyright (C) 2023 William Mead <william.mead@manchenumerique.fr>
|
2026-06-11 21:44:12 +00:00
|
|
|
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
|
FIX #37658 - Add unit tests for TTC unit price rounding and add fixes for others objects (proposals, orders, invoices and contracts) (#39055)
* Test: add unit tests for TTC unit price rounding (#37658)
Covers the "unit price entered including tax" workflow (subtotal title, product
line, free line, no-op update, discount on all lines) for sale/purchase objects,
checking totals and that each line keeps its typed TTC value (subprice_ttc).
* Test - Make TTC rounding test portable across versions (guard subtotal step with method_exists)
* Test - Use non-deprecated module names in isModEnabled (order/invoice/contract)
* Fix #37658 Persist TTC unit price entry mode on order/invoice/contract and supplier proposal
A line entered with the unit price including tax keeps its typed value (subprice_ttc) and
computes totals from it, avoiding a 0.01 rounding drift on create, no-op edit and bulk actions.
Moves wasEnteredIncludingTax() to CommonObjectLine.
* Cast unit price to float on supplier proposal updateline (phan)
* FIX #37658 Preserve TTC unit price entry mode on clone (createFromClone)
* Pass socid (not object id) to SupplierProposal::createFromClone in TTC clone test
* Preserve TTC unit price entry mode on origin conversion and credit note
* Fix phan: cast pu_ht to float for Contrat::defineBuyPrice() argument
* Preserve TTC unit price entry mode on supplier order, invoice and proposal (socle, clone, conversion, line edit and bulk actions)
* Fix cast ht to float for CommandeFournisseur::updateline() argument
* Fix cast subprice_ttc to float in ContratLigne::update SQL (phan SqlInjection)
* Add TTC round-of-total stability tests
Cover MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=1 (and _SUPPLIER=1) on fresh
customer and supplier objects with mixed HT/TTC lines: create, no-op,
clone and discount must not drift and must keep the entry mode.
* Preserve TTC entry mode when creating a contract from origin
* Add getPriceBaseType() and preserve TTC entry mode on proposal from origin
---------
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2026-08-11 17:48:40 +00:00
|
|
|
* Copyright (C) 2026 Lionel Vessiller <lvessiller@open-dsi.fr>
|
2024-09-05 10:48:31 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \file htdocs/comm/propal/class/propaleligne.class.php
|
|
|
|
|
* \ingroup propale
|
|
|
|
|
* \brief File of class to manage proposal lines
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class to manage commercial proposal lines
|
|
|
|
|
*/
|
|
|
|
|
class PropaleLigne extends CommonObjectLine
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @var string ID to identify managed object
|
|
|
|
|
*/
|
|
|
|
|
public $element = 'propaldet';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string Name of table without prefix where object is stored
|
|
|
|
|
*/
|
|
|
|
|
public $table_element = 'propaldet';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see CommonObjectLine
|
|
|
|
|
*/
|
|
|
|
|
public $parent_element = 'propal';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see CommonObjectLine
|
|
|
|
|
*/
|
|
|
|
|
public $fk_parent_attribute = 'fk_propal';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var PropaleLigne
|
|
|
|
|
*/
|
|
|
|
|
public $oldline;
|
|
|
|
|
|
|
|
|
|
// From llx_propaldet
|
|
|
|
|
/**
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
|
|
|
|
public $fk_propal;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
|
|
|
|
public $fk_parent_line;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string Line description
|
|
|
|
|
*/
|
|
|
|
|
public $desc;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var int Predefined product Id
|
|
|
|
|
*/
|
|
|
|
|
public $fk_product;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var int
|
|
|
|
|
* @deprecated
|
|
|
|
|
* @see $product_type
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public $fk_product_type;
|
|
|
|
|
/**
|
|
|
|
|
* Product type.
|
|
|
|
|
* @var int
|
|
|
|
|
* @see Product::TYPE_PRODUCT, Product::TYPE_SERVICE
|
|
|
|
|
*/
|
|
|
|
|
public $product_type = Product::TYPE_PRODUCT;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var float Quantity
|
|
|
|
|
*/
|
|
|
|
|
public $qty;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var float|string
|
|
|
|
|
*/
|
|
|
|
|
public $tva_tx;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
public $vat_src_code;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unit price before taxes
|
|
|
|
|
* @var float
|
|
|
|
|
*/
|
|
|
|
|
public $subprice;
|
|
|
|
|
|
2026-06-13 00:34:51 +00:00
|
|
|
/**
|
|
|
|
|
* Unit price including tax — set when the line was entered with price_base_type='TTC', 0 otherwise.
|
|
|
|
|
* Used to preserve the original entry mode on no-op edits (avoids rounding drift).
|
|
|
|
|
* @var float
|
|
|
|
|
*/
|
|
|
|
|
public $subprice_ttc = 0;
|
|
|
|
|
|
2024-09-05 10:48:31 +00:00
|
|
|
/**
|
2024-10-13 14:45:42 +00:00
|
|
|
* @var float|string
|
2024-09-05 10:48:31 +00:00
|
|
|
*/
|
|
|
|
|
public $remise_percent;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var int ID
|
|
|
|
|
*/
|
|
|
|
|
public $fk_remise_except;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var int line rank
|
|
|
|
|
*/
|
|
|
|
|
public $rang = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
|
|
|
|
public $fk_fournprice;
|
|
|
|
|
|
|
|
|
|
/**
|
2025-09-21 21:22:33 +00:00
|
|
|
* @var float|int|''|null
|
2024-09-05 10:48:31 +00:00
|
|
|
*/
|
|
|
|
|
public $pa_ht;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var int|float|string
|
|
|
|
|
*/
|
|
|
|
|
public $marge_tx;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var float|string
|
|
|
|
|
*/
|
|
|
|
|
public $marque_tx;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tag for special lines (exclusive tags)
|
|
|
|
|
* 1: shipping costs
|
|
|
|
|
* 2: ecotaxe
|
|
|
|
|
* 3: option line (when qty = 0)
|
|
|
|
|
* @var int special code
|
|
|
|
|
*/
|
|
|
|
|
public $special_code;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Some other info:
|
|
|
|
|
* Bit 0: 0 si TVA normal - 1 if TVA NPR
|
2026-01-15 15:05:06 +00:00
|
|
|
* Bit 1: 0 if normal line - 1 if line with fixed discount
|
2025-09-21 21:22:33 +00:00
|
|
|
* @var ?int
|
2024-09-05 10:48:31 +00:00
|
|
|
*/
|
|
|
|
|
public $info_bits = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-15 15:05:06 +00:00
|
|
|
* Total amount excluding taxes HT including discounts
|
2024-09-05 10:48:31 +00:00
|
|
|
* @var float
|
|
|
|
|
*/
|
|
|
|
|
public $total_ht;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-15 15:05:06 +00:00
|
|
|
* Total VAT amount
|
2024-09-05 10:48:31 +00:00
|
|
|
* @var float
|
|
|
|
|
*/
|
|
|
|
|
public $total_tva;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-15 15:05:06 +00:00
|
|
|
* Total amount including taxes
|
2024-09-05 10:48:31 +00:00
|
|
|
* @var float
|
|
|
|
|
*/
|
|
|
|
|
public $total_ttc;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var float|string
|
|
|
|
|
* @deprecated
|
|
|
|
|
* @see $remise_percent, $fk_remise_except
|
|
|
|
|
*/
|
|
|
|
|
public $remise;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var float|string
|
|
|
|
|
* @deprecated
|
|
|
|
|
* @see $subprice
|
|
|
|
|
*/
|
|
|
|
|
public $price;
|
|
|
|
|
|
|
|
|
|
// From llx_product
|
|
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
* @deprecated
|
|
|
|
|
* @see $product_ref
|
|
|
|
|
*/
|
|
|
|
|
public $ref;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Product reference
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
public $product_ref;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
* @deprecated
|
|
|
|
|
* @see $product_label
|
|
|
|
|
*/
|
|
|
|
|
public $libelle;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
* @deprecated
|
|
|
|
|
* @see $product_label
|
|
|
|
|
*/
|
|
|
|
|
public $label;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Product label
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
public $product_label;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Product description
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
public $product_desc;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Product use lot
|
2024-10-03 17:40:34 +00:00
|
|
|
* @var int
|
2024-09-05 10:48:31 +00:00
|
|
|
*/
|
|
|
|
|
public $product_tobatch;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Product barcode
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
public $product_barcode;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string|float
|
|
|
|
|
*/
|
|
|
|
|
public $localtax1_tx;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string|float
|
|
|
|
|
*/
|
|
|
|
|
public $localtax2_tx;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var int|string Local tax 1 type
|
|
|
|
|
*/
|
|
|
|
|
public $localtax1_type;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var int|string Local tax 2 type
|
|
|
|
|
*/
|
|
|
|
|
public $localtax2_type;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var float Line total local tax 1
|
|
|
|
|
*/
|
|
|
|
|
public $total_localtax1;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var float Line total local tax 2
|
|
|
|
|
*/
|
|
|
|
|
public $total_localtax2;
|
|
|
|
|
|
|
|
|
|
/**
|
2025-11-12 08:44:39 +00:00
|
|
|
* @var int|''|null
|
2024-09-05 10:48:31 +00:00
|
|
|
*/
|
|
|
|
|
public $date_start;
|
|
|
|
|
|
|
|
|
|
/**
|
2025-11-12 08:44:39 +00:00
|
|
|
* @var int|''|null
|
2024-09-05 10:48:31 +00:00
|
|
|
*/
|
|
|
|
|
public $date_end;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var int Skip update price total for special lines
|
|
|
|
|
*/
|
|
|
|
|
public $skip_update_total;
|
|
|
|
|
|
|
|
|
|
// Multicurrency
|
|
|
|
|
/**
|
|
|
|
|
* @var int multicurrency id
|
|
|
|
|
*/
|
|
|
|
|
public $fk_multicurrency;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string Multicurrency code
|
|
|
|
|
*/
|
|
|
|
|
public $multicurrency_code;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var float Multicurrency subprice
|
|
|
|
|
*/
|
|
|
|
|
public $multicurrency_subprice;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var float Multicurrency total without tax
|
|
|
|
|
*/
|
|
|
|
|
public $multicurrency_total_ht;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var float Multicurrency total vat
|
|
|
|
|
*/
|
|
|
|
|
public $multicurrency_total_tva;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var float Multicurrency total with tax
|
|
|
|
|
*/
|
|
|
|
|
public $multicurrency_total_ttc;
|
|
|
|
|
|
2025-01-28 14:31:08 +00:00
|
|
|
/**
|
2025-01-21 08:43:00 +00:00
|
|
|
* @var float
|
|
|
|
|
*/
|
|
|
|
|
public $packaging;
|
2024-09-05 10:48:31 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class line Constructor
|
|
|
|
|
*
|
|
|
|
|
* @param DoliDB $db Database handler
|
|
|
|
|
*/
|
|
|
|
|
public function __construct($db)
|
|
|
|
|
{
|
|
|
|
|
$this->db = $db;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve the propal line object
|
|
|
|
|
*
|
|
|
|
|
* @param int $rowid Propal line id
|
|
|
|
|
* @return int Return integer <0 if KO, >0 if OK
|
|
|
|
|
*/
|
|
|
|
|
public function fetch($rowid)
|
|
|
|
|
{
|
|
|
|
|
$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,';
|
2026-06-13 00:34:51 +00:00
|
|
|
$sql .= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice, pd.subprice_ttc,';
|
2024-09-05 10:48:31 +00:00
|
|
|
$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,';
|
|
|
|
|
$sql .= ' pd.fk_unit,';
|
|
|
|
|
$sql .= ' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,';
|
|
|
|
|
$sql .= ' pd.fk_multicurrency, pd.multicurrency_code, pd.multicurrency_subprice, pd.multicurrency_total_ht, pd.multicurrency_total_tva, pd.multicurrency_total_ttc,';
|
2025-09-29 19:09:06 +00:00
|
|
|
$sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,p.barcode as product_barcode,';
|
2026-03-15 13:43:53 +00:00
|
|
|
$sql .= ' p.weight, p.weight_units, p.volume, p.volume_units,';
|
2025-09-29 19:09:06 +00:00
|
|
|
$sql .= ' p.customcode, p.fk_country as country_id, c.code as country_code,';
|
2025-01-29 18:15:57 +00:00
|
|
|
$sql .= ' p.packaging,';
|
2025-03-03 11:05:27 +00:00
|
|
|
$sql .= ' pd.date_start, pd.date_end, pd.product_type, pd.extraparams';
|
2024-09-05 10:48:31 +00:00
|
|
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pd';
|
|
|
|
|
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pd.fk_product = p.rowid';
|
2025-09-29 19:09:06 +00:00
|
|
|
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON c.rowid = p.fk_country';
|
2024-09-05 10:48:31 +00:00
|
|
|
$sql .= ' WHERE pd.rowid = '.((int) $rowid);
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
if ($result) {
|
|
|
|
|
$objp = $this->db->fetch_object($result);
|
|
|
|
|
|
|
|
|
|
if ($objp) {
|
|
|
|
|
$this->id = $objp->rowid;
|
2025-09-21 21:22:33 +00:00
|
|
|
$this->rowid = $objp->rowid; // deprecated
|
2024-09-05 10:48:31 +00:00
|
|
|
$this->fk_propal = $objp->fk_propal;
|
|
|
|
|
$this->fk_parent_line = $objp->fk_parent_line;
|
2026-01-15 15:05:06 +00:00
|
|
|
$this->label = $objp->custom_label;
|
|
|
|
|
$this->desc = $objp->description;
|
2024-09-05 10:48:31 +00:00
|
|
|
$this->qty = $objp->qty;
|
2026-01-15 15:05:06 +00:00
|
|
|
$this->price = $objp->price; // deprecated
|
2024-09-05 10:48:31 +00:00
|
|
|
$this->subprice = $objp->subprice;
|
2026-06-13 00:34:51 +00:00
|
|
|
$this->subprice_ttc = $objp->subprice_ttc;
|
2024-09-05 10:48:31 +00:00
|
|
|
$this->vat_src_code = $objp->vat_src_code;
|
|
|
|
|
$this->tva_tx = $objp->tva_tx;
|
|
|
|
|
$this->remise = $objp->remise; // deprecated
|
|
|
|
|
$this->remise_percent = $objp->remise_percent;
|
|
|
|
|
$this->fk_remise_except = $objp->fk_remise_except;
|
|
|
|
|
$this->fk_product = $objp->fk_product;
|
|
|
|
|
$this->info_bits = $objp->info_bits;
|
|
|
|
|
|
|
|
|
|
$this->total_ht = $objp->total_ht;
|
|
|
|
|
$this->total_tva = $objp->total_tva;
|
|
|
|
|
$this->total_ttc = $objp->total_ttc;
|
|
|
|
|
|
|
|
|
|
$this->fk_fournprice = $objp->fk_fournprice;
|
|
|
|
|
|
|
|
|
|
$marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
|
|
|
|
|
$this->pa_ht = $marginInfos[0];
|
|
|
|
|
$this->marge_tx = $marginInfos[1];
|
|
|
|
|
$this->marque_tx = $marginInfos[2];
|
|
|
|
|
|
|
|
|
|
$this->special_code = $objp->special_code;
|
|
|
|
|
$this->product_type = $objp->product_type;
|
|
|
|
|
$this->rang = $objp->rang;
|
|
|
|
|
|
|
|
|
|
$this->ref = $objp->product_ref; // deprecated
|
|
|
|
|
$this->product_ref = $objp->product_ref;
|
|
|
|
|
$this->libelle = $objp->product_label; // deprecated
|
2025-09-29 19:09:06 +00:00
|
|
|
$this->product_label = $objp->product_label;
|
|
|
|
|
$this->product_desc = $objp->product_desc;
|
|
|
|
|
$this->product_barcode = $objp->product_barcode;
|
|
|
|
|
$this->product_custom_code = $objp->customcode;
|
|
|
|
|
$this->product_custom_country_id = $objp->country_id;
|
|
|
|
|
$this->product_custom_country_code = $objp->country_code;
|
2026-03-15 13:43:53 +00:00
|
|
|
|
2024-09-05 10:48:31 +00:00
|
|
|
$this->fk_unit = $objp->fk_unit;
|
2026-03-15 13:43:53 +00:00
|
|
|
$this->weight = $objp->weight;
|
|
|
|
|
$this->weight_units = $objp->weight_units;
|
|
|
|
|
$this->volume = $objp->volume;
|
|
|
|
|
$this->volume_units = $objp->volume_units;
|
2024-09-05 10:48:31 +00:00
|
|
|
|
2025-01-29 18:15:57 +00:00
|
|
|
$this->packaging = $objp->packaging;
|
2025-01-21 08:43:00 +00:00
|
|
|
|
2024-09-05 10:48:31 +00:00
|
|
|
$this->date_start = $this->db->jdate($objp->date_start);
|
|
|
|
|
$this->date_end = $this->db->jdate($objp->date_end);
|
|
|
|
|
|
2025-03-03 11:05:27 +00:00
|
|
|
$this->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams, true) : array();
|
|
|
|
|
|
2024-09-05 10:48:31 +00:00
|
|
|
// Multicurrency
|
|
|
|
|
$this->fk_multicurrency = $objp->fk_multicurrency;
|
|
|
|
|
$this->multicurrency_code = $objp->multicurrency_code;
|
|
|
|
|
$this->multicurrency_subprice = $objp->multicurrency_subprice;
|
|
|
|
|
$this->multicurrency_total_ht = $objp->multicurrency_total_ht;
|
|
|
|
|
$this->multicurrency_total_tva = $objp->multicurrency_total_tva;
|
|
|
|
|
$this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
|
|
|
|
|
|
|
|
|
|
$this->fetch_optionals();
|
|
|
|
|
|
|
|
|
|
$this->db->free($result);
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Insert object line propal in database
|
|
|
|
|
*
|
2024-10-03 17:40:34 +00:00
|
|
|
* @param int<0,1> $notrigger 1=Does not execute triggers, 0= execute triggers
|
2024-09-05 10:48:31 +00:00
|
|
|
* @return int Return integer <0 if KO, >0 if OK
|
|
|
|
|
*/
|
|
|
|
|
public function insert($notrigger = 0)
|
|
|
|
|
{
|
2026-03-15 13:43:53 +00:00
|
|
|
global $user;
|
2024-09-05 10:48:31 +00:00
|
|
|
|
|
|
|
|
$error = 0;
|
|
|
|
|
|
|
|
|
|
dol_syslog(get_class($this)."::insert rang=".$this->rang);
|
|
|
|
|
|
|
|
|
|
$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'.
|
2025-01-06 15:18:42 +00:00
|
|
|
$this->pa_ht = (float) $this->pa_ht; // convert to float after check if empty value
|
2024-09-05 10:48:31 +00:00
|
|
|
|
|
|
|
|
// Clean parameters
|
|
|
|
|
if (empty($this->tva_tx)) {
|
|
|
|
|
$this->tva_tx = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->localtax1_tx)) {
|
|
|
|
|
$this->localtax1_tx = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->localtax2_tx)) {
|
|
|
|
|
$this->localtax2_tx = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->localtax1_type)) {
|
|
|
|
|
$this->localtax1_type = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->localtax2_type)) {
|
|
|
|
|
$this->localtax2_type = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->total_localtax1)) {
|
|
|
|
|
$this->total_localtax1 = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->total_localtax2)) {
|
|
|
|
|
$this->total_localtax2 = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->rang)) {
|
|
|
|
|
$this->rang = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->remise_percent) || !is_numeric($this->remise_percent)) {
|
|
|
|
|
$this->remise_percent = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->info_bits)) {
|
|
|
|
|
$this->info_bits = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->special_code)) {
|
|
|
|
|
$this->special_code = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->fk_parent_line)) {
|
|
|
|
|
$this->fk_parent_line = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->fk_fournprice)) {
|
|
|
|
|
$this->fk_fournprice = 0;
|
|
|
|
|
}
|
|
|
|
|
if (!is_numeric($this->qty)) {
|
|
|
|
|
$this->qty = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->multicurrency_subprice)) {
|
|
|
|
|
$this->multicurrency_subprice = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->multicurrency_total_ht)) {
|
|
|
|
|
$this->multicurrency_total_ht = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->multicurrency_total_tva)) {
|
|
|
|
|
$this->multicurrency_total_tva = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->multicurrency_total_ttc)) {
|
|
|
|
|
$this->multicurrency_total_ttc = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if buy price not defined, define buyprice as configured in margin admin
|
|
|
|
|
if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
|
|
|
|
|
if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) {
|
|
|
|
|
return $result;
|
|
|
|
|
} else {
|
|
|
|
|
$this->pa_ht = $result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check parameters
|
|
|
|
|
if ($this->product_type < 0) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->db->begin();
|
|
|
|
|
|
|
|
|
|
// Insert line into database
|
|
|
|
|
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'propaldet';
|
|
|
|
|
$sql .= ' (fk_propal, fk_parent_line, label, description, fk_product, product_type,';
|
|
|
|
|
$sql .= ' fk_remise_except, qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
|
2026-06-13 00:34:51 +00:00
|
|
|
$sql .= ' subprice, subprice_ttc, remise_percent, ';
|
2024-09-05 10:48:31 +00:00
|
|
|
$sql .= ' info_bits, ';
|
|
|
|
|
$sql .= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,';
|
|
|
|
|
$sql .= ' fk_unit,';
|
|
|
|
|
$sql .= ' date_start, date_end';
|
|
|
|
|
$sql .= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc)';
|
2026-07-23 17:06:39 +00:00
|
|
|
$sql .= " VALUES (".((int) $this->fk_propal).",";
|
2025-03-10 14:47:55 +00:00
|
|
|
$sql .= " ".($this->fk_parent_line > 0 ? "'".$this->db->escape((string) $this->fk_parent_line)."'" : "null").",";
|
2024-09-05 10:48:31 +00:00
|
|
|
$sql .= " ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
|
|
|
|
|
$sql .= " '".$this->db->escape($this->desc)."',";
|
2025-09-12 21:05:15 +00:00
|
|
|
$sql .= " ".($this->fk_product > 0 ? (int) $this->fk_product : "null").",";
|
2025-09-05 23:34:05 +00:00
|
|
|
$sql .= " ".((int) $this->product_type).",";
|
2025-09-12 21:05:15 +00:00
|
|
|
$sql .= " ".($this->fk_remise_except > 0 ? (int) $this->fk_remise_except : "null").",";
|
2024-09-05 10:48:31 +00:00
|
|
|
$sql .= " ".price2num($this->qty, 'MS').",";
|
|
|
|
|
$sql .= " ".(empty($this->vat_src_code) ? "''" : "'".$this->db->escape($this->vat_src_code)."'").",";
|
|
|
|
|
$sql .= " ".price2num($this->tva_tx).",";
|
|
|
|
|
$sql .= " ".price2num($this->localtax1_tx).",";
|
|
|
|
|
$sql .= " ".price2num($this->localtax2_tx).",";
|
|
|
|
|
$sql .= " '".$this->db->escape($this->localtax1_type)."',";
|
|
|
|
|
$sql .= " '".$this->db->escape($this->localtax2_type)."',";
|
|
|
|
|
$sql .= " ".(price2num($this->subprice) !== '' ? price2num($this->subprice, 'MU') : "null").",";
|
2026-06-13 00:34:51 +00:00
|
|
|
$sql .= " ".price2num($this->subprice_ttc, 'MU').",";
|
2024-09-05 10:48:31 +00:00
|
|
|
$sql .= " ".price2num($this->remise_percent).",";
|
|
|
|
|
$sql .= " ".(isset($this->info_bits) ? ((int) $this->info_bits) : "null").",";
|
|
|
|
|
$sql .= " ".price2num($this->total_ht, 'MT').",";
|
|
|
|
|
$sql .= " ".price2num($this->total_tva, 'MT').",";
|
|
|
|
|
$sql .= " ".price2num($this->total_localtax1, 'MT').",";
|
|
|
|
|
$sql .= " ".price2num($this->total_localtax2, 'MT').",";
|
|
|
|
|
$sql .= " ".price2num($this->total_ttc, 'MT').",";
|
2025-03-10 14:47:55 +00:00
|
|
|
$sql .= " ".(!empty($this->fk_fournprice) ? "'".$this->db->escape((string) $this->fk_fournprice)."'" : "null").",";
|
2024-09-05 10:48:31 +00:00
|
|
|
$sql .= " ".(isset($this->pa_ht) ? "'".price2num($this->pa_ht)."'" : "null").",";
|
|
|
|
|
$sql .= ' '.((int) $this->special_code).',';
|
|
|
|
|
$sql .= ' '.((int) $this->rang).',';
|
|
|
|
|
$sql .= ' '.(empty($this->fk_unit) ? 'NULL' : ((int) $this->fk_unit)).',';
|
|
|
|
|
$sql .= " ".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null").',';
|
|
|
|
|
$sql .= " ".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null");
|
|
|
|
|
$sql .= ", ".($this->fk_multicurrency > 0 ? ((int) $this->fk_multicurrency) : 'null');
|
|
|
|
|
$sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
|
|
|
|
|
$sql .= ", ".price2num($this->multicurrency_subprice, 'CU');
|
|
|
|
|
$sql .= ", ".price2num($this->multicurrency_total_ht, 'CT');
|
|
|
|
|
$sql .= ", ".price2num($this->multicurrency_total_tva, 'CT');
|
|
|
|
|
$sql .= ", ".price2num($this->multicurrency_total_ttc, 'CT');
|
|
|
|
|
$sql .= ')';
|
|
|
|
|
|
|
|
|
|
dol_syslog(get_class($this).'::insert', LOG_DEBUG);
|
|
|
|
|
$resql = $this->db->query($sql);
|
|
|
|
|
if ($resql) {
|
2025-09-29 19:09:06 +00:00
|
|
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'propaldet');
|
|
|
|
|
$this->rowid = $this->id;
|
2025-05-22 13:56:56 +00:00
|
|
|
$result = $this->insertExtraFields();
|
|
|
|
|
if ($result < 0) {
|
|
|
|
|
$error++;
|
2024-09-05 10:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$error && !$notrigger) {
|
|
|
|
|
// Call trigger
|
|
|
|
|
$result = $this->call_trigger('LINEPROPAL_INSERT', $user);
|
|
|
|
|
if ($result < 0) {
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
// End call triggers
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-02 12:53:12 +00:00
|
|
|
if (!$error) {
|
|
|
|
|
$this->db->commit();
|
2025-06-02 12:59:18 +00:00
|
|
|
return (int) $this->id;
|
2025-06-02 12:53:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($this->errors as $errmsg) {
|
|
|
|
|
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
|
|
|
|
|
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
|
|
|
|
|
}
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
return -3;
|
2024-09-05 10:48:31 +00:00
|
|
|
} else {
|
|
|
|
|
$this->error = $this->db->error()." sql=".$sql;
|
|
|
|
|
$this->db->rollback();
|
2025-06-02 12:53:12 +00:00
|
|
|
return -2;
|
2024-09-05 10:48:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete line in database
|
|
|
|
|
*
|
|
|
|
|
* @param User $user Object user
|
|
|
|
|
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
|
|
|
|
|
* @return int Return integer <0 if ko, >0 if ok
|
|
|
|
|
*/
|
|
|
|
|
public function delete(User $user, $notrigger = 0)
|
|
|
|
|
{
|
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
|
|
$error = 0;
|
|
|
|
|
$this->db->begin();
|
|
|
|
|
|
|
|
|
|
if (!$notrigger) {
|
|
|
|
|
// Call trigger
|
|
|
|
|
$result = $this->call_trigger('LINEPROPAL_DELETE', $user);
|
|
|
|
|
if ($result < 0) {
|
|
|
|
|
$error++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// End call triggers
|
|
|
|
|
|
|
|
|
|
if (!$error) {
|
|
|
|
|
$sql = "DELETE FROM " . MAIN_DB_PREFIX . "propaldet WHERE rowid = " . ((int) $this->rowid);
|
|
|
|
|
dol_syslog("PropaleLigne::delete", LOG_DEBUG);
|
|
|
|
|
if ($this->db->query($sql)) {
|
|
|
|
|
// Remove extrafields
|
2025-09-21 21:22:33 +00:00
|
|
|
$this->id = $this->rowid;
|
|
|
|
|
$result = $this->deleteExtraFields();
|
|
|
|
|
if ($result < 0) {
|
|
|
|
|
$error++;
|
|
|
|
|
dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR);
|
2024-09-05 10:48:31 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->error = $this->db->error() . " sql=" . $sql;
|
|
|
|
|
$error++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($error) {
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
return -1;
|
|
|
|
|
} else {
|
|
|
|
|
$this->db->commit();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update propal line object into DB
|
|
|
|
|
*
|
|
|
|
|
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
|
|
|
|
|
* @return int Return integer <0 if ko, >0 if ok
|
|
|
|
|
*/
|
|
|
|
|
public function update($notrigger = 0)
|
|
|
|
|
{
|
|
|
|
|
global $conf, $user;
|
|
|
|
|
|
|
|
|
|
$error = 0;
|
|
|
|
|
|
|
|
|
|
$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'.
|
|
|
|
|
|
|
|
|
|
if (empty($this->id) && !empty($this->rowid)) {
|
|
|
|
|
$this->id = $this->rowid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Clean parameters
|
|
|
|
|
if (empty($this->tva_tx)) {
|
|
|
|
|
$this->tva_tx = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->localtax1_tx)) {
|
|
|
|
|
$this->localtax1_tx = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->localtax2_tx)) {
|
|
|
|
|
$this->localtax2_tx = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->total_localtax1)) {
|
|
|
|
|
$this->total_localtax1 = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->total_localtax2)) {
|
|
|
|
|
$this->total_localtax2 = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->localtax1_type)) {
|
|
|
|
|
$this->localtax1_type = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->localtax2_type)) {
|
|
|
|
|
$this->localtax2_type = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->marque_tx)) {
|
|
|
|
|
$this->marque_tx = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->marge_tx)) {
|
|
|
|
|
$this->marge_tx = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->price)) {
|
|
|
|
|
$this->price = 0; // TODO A virer
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->remise_percent)) {
|
|
|
|
|
$this->remise_percent = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->info_bits)) {
|
|
|
|
|
$this->info_bits = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->special_code)) {
|
|
|
|
|
$this->special_code = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->fk_parent_line)) {
|
|
|
|
|
$this->fk_parent_line = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->fk_fournprice)) {
|
|
|
|
|
$this->fk_fournprice = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->subprice)) {
|
|
|
|
|
$this->subprice = 0;
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->pa_ht)) {
|
|
|
|
|
$this->pa_ht = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if buy price not defined, define buyprice as configured in margin admin
|
|
|
|
|
if ($this->pa_ht == 0 && $pa_ht_isemptystring) {
|
|
|
|
|
if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) {
|
|
|
|
|
return $result;
|
|
|
|
|
} else {
|
|
|
|
|
$this->pa_ht = $result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->db->begin();
|
|
|
|
|
|
2026-01-15 15:05:06 +00:00
|
|
|
// Update line in database
|
2024-09-05 10:48:31 +00:00
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propaldet SET";
|
2026-03-23 22:48:30 +00:00
|
|
|
$sql .= " description = '".$this->db->escape($this->desc)."'";
|
|
|
|
|
$sql .= ", label = ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
|
|
|
|
|
$sql .= ", product_type = ".((int) $this->product_type);
|
2026-07-23 17:06:39 +00:00
|
|
|
$sql .= ", vat_src_code = '".(empty($this->vat_src_code) ? '' : $this->db->escape($this->vat_src_code))."'";
|
2024-09-05 10:48:31 +00:00
|
|
|
$sql .= ", tva_tx='".price2num($this->tva_tx)."'";
|
|
|
|
|
$sql .= ", localtax1_tx=".price2num($this->localtax1_tx);
|
|
|
|
|
$sql .= ", localtax2_tx=".price2num($this->localtax2_tx);
|
|
|
|
|
$sql .= ", localtax1_type='".$this->db->escape($this->localtax1_type)."'";
|
|
|
|
|
$sql .= ", localtax2_type='".$this->db->escape($this->localtax2_type)."'";
|
2026-03-23 22:48:30 +00:00
|
|
|
$sql .= ", qty = ".((float) price2num($this->qty));
|
|
|
|
|
$sql .= ", subprice = ".price2num($this->subprice);
|
2026-06-13 00:34:51 +00:00
|
|
|
$sql .= ", subprice_ttc = ".price2num($this->subprice_ttc);
|
2026-03-23 22:48:30 +00:00
|
|
|
$sql .= ", remise_percent = ".price2num($this->remise_percent);
|
|
|
|
|
$sql .= ", price = ".(float) price2num($this->price); // TODO A virer
|
|
|
|
|
$sql .= ", remise = ".(float) price2num($this->remise); // TODO A virer
|
|
|
|
|
$sql .= ", info_bits = '".$this->db->escape((string) $this->info_bits)."'";
|
2024-09-05 10:48:31 +00:00
|
|
|
if (empty($this->skip_update_total)) {
|
2026-03-23 22:48:30 +00:00
|
|
|
$sql .= ", total_ht = ".price2num($this->total_ht);
|
|
|
|
|
$sql .= ", total_tva = ".price2num($this->total_tva);
|
|
|
|
|
$sql .= ", total_ttc = ".price2num($this->total_ttc);
|
|
|
|
|
$sql .= ", total_localtax1 = ".price2num($this->total_localtax1);
|
|
|
|
|
$sql .= ", total_localtax2 = ".price2num($this->total_localtax2);
|
2024-09-05 10:48:31 +00:00
|
|
|
}
|
2025-03-10 14:47:55 +00:00
|
|
|
$sql .= ", fk_product_fournisseur_price=".(!empty($this->fk_fournprice) ? "'".$this->db->escape((string) $this->fk_fournprice)."'" : "null");
|
2024-09-05 10:48:31 +00:00
|
|
|
$sql .= ", buy_price_ht=".price2num($this->pa_ht);
|
|
|
|
|
$sql .= ", special_code=".((int) $this->special_code);
|
|
|
|
|
$sql .= ", fk_parent_line=".($this->fk_parent_line > 0 ? (int) $this->fk_parent_line : "null");
|
|
|
|
|
if (!empty($this->rang)) {
|
|
|
|
|
$sql .= ", rang=".((int) $this->rang);
|
|
|
|
|
}
|
|
|
|
|
$sql .= ", date_start=".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null");
|
|
|
|
|
$sql .= ", date_end=".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null");
|
2026-06-11 21:44:12 +00:00
|
|
|
$sql .= ", fk_unit=".(!$this->fk_unit ? 'NULL' : ((int) $this->fk_unit));
|
2024-09-05 10:48:31 +00:00
|
|
|
|
|
|
|
|
// Multicurrency
|
|
|
|
|
$sql .= ", multicurrency_subprice=".price2num($this->multicurrency_subprice);
|
|
|
|
|
$sql .= ", multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
|
|
|
|
|
$sql .= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
|
|
|
|
|
$sql .= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
|
|
|
|
|
|
|
|
|
|
$sql .= " WHERE rowid = ".((int) $this->id);
|
|
|
|
|
|
|
|
|
|
dol_syslog(get_class($this)."::update", LOG_DEBUG);
|
|
|
|
|
$resql = $this->db->query($sql);
|
|
|
|
|
if ($resql) {
|
2025-09-21 21:22:33 +00:00
|
|
|
$result = $this->insertExtraFields();
|
|
|
|
|
if ($result < 0) {
|
|
|
|
|
$error++;
|
2024-09-05 10:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$error && !$notrigger) {
|
|
|
|
|
// Call trigger
|
|
|
|
|
$result = $this->call_trigger('LINEPROPAL_MODIFY', $user);
|
|
|
|
|
if ($result < 0) {
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
// End call triggers
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-02 12:53:12 +00:00
|
|
|
if (!$error) {
|
|
|
|
|
$this->db->commit();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($this->errors as $errmsg) {
|
|
|
|
|
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
|
|
|
|
|
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
|
|
|
|
|
}
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
return -3;
|
2024-09-05 10:48:31 +00:00
|
|
|
} else {
|
|
|
|
|
$this->error = $this->db->error();
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
return -2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
|
|
|
|
/**
|
|
|
|
|
* Update DB line fields total_xxx
|
|
|
|
|
* Used by migration
|
|
|
|
|
*
|
|
|
|
|
* @return int Return integer <0 if KO, >0 if OK
|
|
|
|
|
*/
|
|
|
|
|
public function update_total()
|
|
|
|
|
{
|
|
|
|
|
// phpcs:enable
|
|
|
|
|
$this->db->begin();
|
|
|
|
|
|
2026-01-15 15:05:06 +00:00
|
|
|
// Update line in database
|
2024-09-05 10:48:31 +00:00
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propaldet SET";
|
|
|
|
|
$sql .= " total_ht=".price2num($this->total_ht, 'MT');
|
|
|
|
|
$sql .= ",total_tva=".price2num($this->total_tva, 'MT');
|
|
|
|
|
$sql .= ",total_ttc=".price2num($this->total_ttc, 'MT');
|
|
|
|
|
$sql .= " WHERE rowid = ".((int) $this->rowid);
|
|
|
|
|
|
|
|
|
|
dol_syslog("PropaleLigne::update_total", LOG_DEBUG);
|
|
|
|
|
|
|
|
|
|
$resql = $this->db->query($sql);
|
|
|
|
|
if ($resql) {
|
|
|
|
|
$this->db->commit();
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
$this->error = $this->db->error();
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
return -2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|