2
0
forked from Wavyzz/dolibarr

Debug v17, on supplier, default vat rate is sale if no price found

This commit is contained in:
Laurent Destailleur
2022-12-13 20:06:56 +01:00
parent b4433ebdf9
commit a673bdba15
13 changed files with 106 additions and 64 deletions

View File

@@ -168,12 +168,14 @@ class box_produits extends ModeleBoxes
$price = '';
$price_base_type = '';
if ($usercancreadprice) {
if (empty($conf->dynamicprices->enabled) || empty($objp->fk_price_expression)) {
if (!isModEnabled('dynamicprices') || empty($objp->fk_price_expression)) {
$price_base_type = $langs->trans($objp->price_base_type);
$price = ($objp->price_base_type == 'HT') ?price($objp->price) : $price = price($objp->price_ttc);
} else {
//Parse the dynamic price
$productstatic->fetch($objp->rowid, '', '', 1);
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parseProduct($productstatic);
if ($price_result >= 0) {

View File

@@ -167,12 +167,13 @@ class box_produits_alerte_stock extends ModeleBoxes
'text' => $objp->label,
);
if (empty($conf->dynamicprices->enabled) || empty($objp->fk_price_expression)) {
if (!isModEnabled('dynamicprices') || empty($objp->fk_price_expression)) {
$price_base_type = $langs->trans($objp->price_base_type);
$price = ($objp->price_base_type == 'HT') ?price($objp->price) : $price = price($objp->price_ttc);
} else //Parse the dynamic price
{
} else { //Parse the dynamic price
$productstatic->fetch($objp->rowid, '', '', 1);
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parseProduct($productstatic);
if ($price_result >= 0) {

View File

@@ -2828,6 +2828,8 @@ class Form
if (isModEnabled('dynamicprices') && !empty($objp->fk_price_expression)) {
$price_product = new Product($this->db);
$price_product->fetch($objp->rowid, '', '', 1);
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parseProduct($price_product);
if ($price_result >= 0) {
@@ -3463,6 +3465,8 @@ class Form
$prod_supplier->fourn_qty = $objp->quantity;
$prod_supplier->fourn_tva_tx = $objp->tva_tx;
$prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parseProductSupplier($prod_supplier);
if ($price_result >= 0) {
@@ -3717,6 +3721,8 @@ class Form
$prod_supplier->fourn_qty = $objp->quantity;
$prod_supplier->fourn_tva_tx = $objp->tva_tx;
$prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parseProductSupplier($prod_supplier);
if ($price_result >= 0) {

View File

@@ -6316,20 +6316,25 @@ function get_product_vat_for_country($idprod, $thirdpartytouse, $idprodfournpric
$product = new Product($db);
$product->fetch($idprod);
if ($mysoc->country_code == $thirdpartytouse->country_code) { // If country to consider is ours
if ($mysoc->country_code == $thirdpartytouse->country_code) {
// If country to consider is ours
if ($idprodfournprice > 0) { // We want vat for product for a "supplier" object
$product->get_buyprice($idprodfournprice, 0, 0, 0);
$result = $product->get_buyprice($idprodfournprice, 0, 0, 0);
if ($result > 0) {
$ret = $product->vatrate_supplier;
if ($product->default_vat_code) {
$ret .= ' ('.$product->default_vat_code.')';
}
} else {
$ret = $product->tva_tx; // Default vat of product we defined
if ($product->default_vat_code) {
$ret .= ' ('.$product->default_vat_code.')';
}
if ($product->default_vat_code_supplier) {
$ret .= ' ('.$product->default_vat_code_supplier.')';
}
$found = 1;
}
}
if (!$found) {
$ret = $product->tva_tx; // Default sales vat of product
if ($product->default_vat_code) {
$ret .= ' ('.$product->default_vat_code.')';
}
$found = 1;
}
} else {
// TODO Read default product vat according to product and another countrycode.
// Vat for couple anothercountrycode/product is data that is not managed and store yet, so we will fallback on next rule.
@@ -6341,7 +6346,7 @@ function get_product_vat_for_country($idprod, $thirdpartytouse, $idprodfournpric
// If vat of product for the country not found or not defined, we return the first rate found (sorting on use_default, then on higher vat of country).
$sql = "SELECT t.taux as vat_rate, t.code as default_vat_code";
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
$sql .= " WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code = '".$db->escape($thirdpartytouse->country_code)."'";
$sql .= " WHERE t.active = 1 AND t.fk_pays = c.rowid AND c.code = '".$db->escape($thirdpartytouse->country_code)."'";
$sql .= " ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
$sql .= $db->plimit(1);
@@ -6359,7 +6364,9 @@ function get_product_vat_for_country($idprod, $thirdpartytouse, $idprodfournpric
dol_print_error($db);
}
} else {
// Forced value if autodetect fails. MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS can be '1.23' or '1.23 (CODE)'
// Forced value if autodetect fails. MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS can be
// '1.23'
// or '1.23 (CODE)'
$defaulttx = '';
if ($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS != 'none') {
$defaulttx = $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;

View File

@@ -35,11 +35,12 @@
*/
require_once DOL_DOCUMENT_ROOT.'/core/class/commonorder.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
if (isModEnabled('productbatch')) {
require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
}
require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
/**
* Class to manage predefined suppliers products
@@ -1820,10 +1821,10 @@ class CommandeFournisseur extends CommonOrder
$label = ''; // deprecated
if ($fk_product > 0) {
if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) {
if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) { // Not the common case
// Check quantity is enough
dol_syslog(get_class($this)."::addline we check supplier prices fk_product=".$fk_product." fk_prod_fourn_price=".$fk_prod_fourn_price." qty=".$qty." ref_supplier=".$ref_supplier);
$prod = new Product($this->db);
$prod = new ProductFournisseur($this->db);
if ($prod->fetch($fk_product) > 0) {
$product_type = $prod->type;
$label = $prod->label;
@@ -1882,7 +1883,7 @@ class CommandeFournisseur extends CommonOrder
if (!empty($prod->packaging) && ($qty % $prod->packaging) > 0) {
$coeff = intval($qty / $prod->packaging) + 1;
$qty = $prod->packaging * $coeff;
setEventMessage($langs->trans('QtyRecalculatedWithPackaging'), 'mesgs');
setEventMessages($langs->trans('QtyRecalculatedWithPackaging'), null, 'mesgs');
}
}
}
@@ -1895,6 +1896,7 @@ class CommandeFournisseur extends CommonOrder
$localtaxes_type = getLocalTaxesFromRate($txtva, 0, $mysoc, $this->thirdparty);
// Clean vat code
$reg = array();
$vat_src_code = '';
if (preg_match('/\((.*)\)/', $txtva, $reg)) {
$vat_src_code = $reg[1];

View File

@@ -38,12 +38,10 @@
include_once DOL_DOCUMENT_ROOT.'/core/class/commoninvoice.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
if (isModEnabled('accounting')) {
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
}
if (isModEnabled('accounting')) {
require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
}
@@ -2073,7 +2071,7 @@ class FactureFournisseur extends CommonInvoice
if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) {
// Check quantity is enough
dol_syslog(get_class($this)."::addline we check supplier prices fk_product=".$fk_product." qty=".$qty." ref_supplier=".$ref_supplier);
$prod = new Product($this->db);
$prod = new ProductFournisseur($this->db);
if ($prod->fetch($fk_product) > 0) {
$product_type = $prod->type;
$label = $prod->label;

View File

@@ -31,7 +31,6 @@
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/productfournisseurprice.class.php';
@@ -638,7 +637,8 @@ class ProductFournisseur extends Product
}
$this->packaging = $obj->packaging;
if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression)) {
if (isModEnabled('dynamicprices') && empty($ignore_expression) && !empty($this->fk_supplier_price_expression)) {
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parseProductSupplier($this);
if ($price_result >= 0) {
@@ -748,6 +748,7 @@ class ProductFournisseur extends Product
}
if (isModEnabled('dynamicprices') && !empty($prodfourn->fk_supplier_price_expression)) {
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parseProductSupplier($prodfourn);
if ($price_result >= 0) {
@@ -860,6 +861,8 @@ class ProductFournisseur extends Product
$prod_supplier->fourn_qty = $record["quantity"];
$prod_supplier->fourn_tva_tx = $record["tva_tx"];
$prod_supplier->fk_supplier_price_expression = $record["fk_supplier_price_expression"];
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parseProductSupplier($prod_supplier);
if ($price_result >= 0) {

View File

@@ -191,12 +191,28 @@ class Product extends CommonObject
//! French VAT NPR (0 or 1)
public $tva_npr = 0;
//! Default discount percent
public $remise_percent;
//! Other local taxes
public $localtax1_tx;
public $localtax2_tx;
public $localtax1_type;
public $localtax2_type;
// Properties set by get_buyprice() for return
public $desc_supplier;
public $vatrate_supplier;
public $default_vat_code_supplier;
public $fourn_multicurrency_price;
public $fourn_multicurrency_unitprice;
public $fourn_multicurrency_tx;
public $fourn_multicurrency_id;
public $fourn_multicurrency_code;
public $packaging;
public $lifetime;
public $qc_frequency;
@@ -415,6 +431,7 @@ class Product extends CommonObject
public $fk_price_expression;
/* To store supplier price found */
public $fourn_qty;
public $fourn_pu;
public $fourn_price_base_type;
public $fourn_socid;
@@ -1955,9 +1972,8 @@ class Product extends CommonObject
$result = 0;
// We do a first search with a select by searching with couple prodfournprice and qty only (later we will search on triplet qty/product_id/fourn_ref)
$sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pfp.remise_percent,";
$sql .= " pfp.fk_product, pfp.ref_fourn, pfp.desc_fourn, pfp.fk_soc, pfp.tva_tx, pfp.fk_supplier_price_expression,";
$sql .= " pfp.default_vat_code,";
$sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pfp.remise_percent, pfp.fk_soc,";
$sql .= " pfp.fk_product, pfp.ref_fourn as ref_supplier, pfp.desc_fourn as desc_supplier, pfp.tva_tx, pfp.default_vat_code, pfp.fk_supplier_price_expression,";
$sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,";
$sql .= " pfp.packaging";
$sql .= " FROM ".$this->db->prefix()."product_fournisseur_price as pfp";
@@ -1972,14 +1988,15 @@ class Product extends CommonObject
if ($resql) {
$obj = $this->db->fetch_object($resql);
if ($obj && $obj->quantity > 0) { // If we found a supplier prices from the id of supplier price
if (!empty($conf->dynamicprices->enabled) && !empty($obj->fk_supplier_price_expression)) {
include_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
if (isModEnabled('dynamicprices') && !empty($obj->fk_supplier_price_expression)) {
$prod_supplier = new ProductFournisseur($this->db);
$prod_supplier->product_fourn_price_id = $obj->rowid;
$prod_supplier->id = $obj->fk_product;
$prod_supplier->fourn_qty = $obj->quantity;
$prod_supplier->fourn_tva_tx = $obj->tva_tx;
$prod_supplier->fk_supplier_price_expression = $obj->fk_supplier_price_expression;
include_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parseProductSupplier($prod_supplier);
if ($price_result >= 0) {
@@ -1991,12 +2008,12 @@ class Product extends CommonObject
$this->fourn_pu = $obj->price / $obj->quantity; // Unit price of product of supplier
$this->fourn_price_base_type = 'HT'; // Price base type
$this->fourn_socid = $obj->fk_soc; // Company that offer this price
$this->ref_fourn = $obj->ref_fourn; // deprecated
$this->ref_supplier = $obj->ref_fourn; // Ref supplier
$this->desc_supplier = $obj->desc_fourn; // desc supplier
$this->ref_fourn = $obj->ref_supplier; // deprecated
$this->ref_supplier = $obj->ref_supplier; // Ref supplier
$this->desc_supplier = $obj->desc_supplier; // desc supplier
$this->remise_percent = $obj->remise_percent; // remise percent if present and not typed
$this->vatrate_supplier = $obj->tva_tx; // Vat ref supplier
$this->default_vat_code = $obj->default_vat_code; // Vat code supplier
$this->default_vat_code_supplier = $obj->default_vat_code; // Vat code supplier
$this->fourn_multicurrency_price = $obj->multicurrency_price;
$this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
$this->fourn_multicurrency_tx = $obj->multicurrency_tx;
@@ -2010,8 +2027,7 @@ class Product extends CommonObject
} else { // If not found
// We do a second search by doing a select again but searching with less reliable criteria: couple qty/id product, and if set fourn_ref or fk_soc.
$sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pfp.remise_percent, pfp.fk_soc,";
$sql .= " pfp.fk_product, pfp.ref_fourn as ref_supplier, pfp.desc_fourn as desc_supplier, pfp.tva_tx, pfp.fk_supplier_price_expression,";
$sql .= " pfp.default_vat_code,";
$sql .= " pfp.fk_product, pfp.ref_fourn as ref_supplier, pfp.desc_fourn as desc_supplier, pfp.tva_tx, pfp.default_vat_code, pfp.fk_supplier_price_expression,";
$sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,";
$sql .= " pfp.packaging";
$sql .= " FROM ".$this->db->prefix()."product_fournisseur_price as pfp";
@@ -2036,14 +2052,15 @@ class Product extends CommonObject
if ($resql) {
$obj = $this->db->fetch_object($resql);
if ($obj && $obj->quantity > 0) { // If found
if (!empty($conf->dynamicprices->enabled) && !empty($obj->fk_supplier_price_expression)) {
include_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
if (isModEnabled('dynamicprices') && !empty($obj->fk_supplier_price_expression)) {
$prod_supplier = new ProductFournisseur($this->db);
$prod_supplier->product_fourn_price_id = $obj->rowid;
$prod_supplier->id = $obj->fk_product;
$prod_supplier->fourn_qty = $obj->quantity;
$prod_supplier->fourn_tva_tx = $obj->tva_tx;
$prod_supplier->fk_supplier_price_expression = $obj->fk_supplier_price_expression;
include_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parseProductSupplier($prod_supplier);
if ($result >= 0) {
@@ -2061,7 +2078,7 @@ class Product extends CommonObject
$this->desc_supplier = $obj->desc_supplier; // desc supplier
$this->remise_percent = $obj->remise_percent; // remise percent if present and not typed
$this->vatrate_supplier = $obj->tva_tx; // Vat ref supplier
$this->default_vat_code = $obj->default_vat_code; // Vat code supplier
$this->default_vat_code_supplier = $obj->default_vat_code; // Vat code supplier
$this->fourn_multicurrency_price = $obj->multicurrency_price;
$this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
$this->fourn_multicurrency_tx = $obj->multicurrency_tx;
@@ -2696,7 +2713,7 @@ class Product extends CommonObject
}
}
if (!empty($conf->dynamicprices->enabled) && !empty($this->fk_price_expression) && empty($ignore_expression)) {
if (isModEnabled('dynamicprices') && !empty($this->fk_price_expression) && empty($ignore_expression)) {
include_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parseProduct($this);

View File

@@ -67,7 +67,8 @@ if ($action == 'add') {
if ($eid == 0) {
$result = $price_expression->find_title($title);
if ($result == 0) { //No existing entry found with title, ok
//Check the expression validity by parsing it
// Check the expression validity by parsing it
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
$priceparser = new PriceParser($db);
$price_result = $priceparser->testExpression($id, $expression);
if ($price_result < 0) { //Expression is not valid
@@ -95,7 +96,8 @@ if ($action == 'update') {
if ($eid != 0) {
$result = $price_expression->find_title($title);
if ($result == 0 || $result == $eid) { //No existing entry found with title or existing one is the current one, ok
//Check the expression validity by parsing it
// Check the expression validity by parsing it
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
$priceparser = new PriceParser($db);
$price_result = $priceparser->testExpression($id, $expression);
if ($price_result < 0) { //Expression is not valid

View File

@@ -318,6 +318,7 @@ if (empty($reshook)) {
} else {
if (isModEnabled('dynamicprices') && $price_expression !== '') {
//Check the expression validity by parsing it
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
$priceparser = new PriceParser($db);
$object->fk_supplier_price_expression = $price_expression;
$price_result = $priceparser->parseProductSupplier($object);

View File

@@ -373,9 +373,11 @@ if ((isModEnabled("product") || isModEnabled("service")) && ($user->hasRight("pr
print "</td>";
// Sell price
if (empty($conf->global->PRODUIT_MULTIPRICES)) {
if (!empty($conf->dynamicprices->enabled) && !empty($objp->fk_price_expression)) {
if (isModEnabled('dynamicprices') && !empty($objp->fk_price_expression)) {
$product = new Product($db);
$product->fetch($objp->rowid);
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
$priceparser = new PriceParser($db);
$price_result = $priceparser->parseProduct($product);
if ($price_result >= 0) {

View File

@@ -258,11 +258,12 @@ if (empty($reshook)) {
$psq = empty($newpsq) ? 0 : $newpsq;
$maxpricesupplier = $object->min_recommended_price();
if (!empty($conf->dynamicprices->enabled)) {
if (isModEnabled('dynamicprices')) {
$object->fk_price_expression = empty($eid) ? 0 : $eid; //0 discards expression
if ($object->fk_price_expression != 0) {
//Check the expression validity by parsing it
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
$priceparser = new PriceParser($db);
if ($priceparser->parseProduct($object) < 0) {

View File

@@ -452,49 +452,49 @@ class SupplierProposal extends CommonObject
if (!empty($conf->global->SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY)) {
// Check quantity is enough
dol_syslog(get_class($this)."::addline we check supplier prices fk_product=".$fk_product." fk_fournprice=".$fk_fournprice." qty=".$qty." ref_supplier=".$ref_supplier);
$prod = new Product($this->db);
if ($prod->fetch($fk_product) > 0) {
$product_type = $prod->type;
$label = $prod->label;
$productsupplier = new ProductFournisseur($this->db);
if ($productsupplier->fetch($fk_product) > 0) {
$product_type = $productsupplier->type;
$label = $productsupplier->label;
$fk_prod_fourn_price = $fk_fournprice;
// We use 'none' instead of $ref_supplier, because fourn_ref may not exists anymore. So we will take the first supplier price ok.
// If we want a dedicated supplier price, we must provide $fk_prod_fourn_price.
$result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product, 'none', ($this->fk_soc ? $this->fk_soc : $this->socid)); // Search on couple $fk_prod_fourn_price/$qty first, then on triplet $qty/$fk_product/$ref_supplier/$this->fk_soc
$result = $productsupplier->get_buyprice($fk_prod_fourn_price, $qty, $fk_product, 'none', ($this->fk_soc ? $this->fk_soc : $this->socid)); // Search on couple $fk_prod_fourn_price/$qty first, then on triplet $qty/$fk_product/$ref_supplier/$this->fk_soc
if ($result > 0) {
$pu = $prod->fourn_pu; // Unit price supplier price set by get_buyprice
$ref_supplier = $prod->ref_supplier; // Ref supplier price set by get_buyprice
$pu = $productsupplier->fourn_pu; // Unit price supplier price set by get_buyprice
$ref_supplier = $productsupplier->ref_supplier; // Ref supplier price set by get_buyprice
// is remise percent not keyed but present for the product we add it
if ($remise_percent == 0 && $prod->remise_percent != 0) {
$remise_percent = $prod->remise_percent;
if ($remise_percent == 0 && $productsupplier->remise_percent != 0) {
$remise_percent = $productsupplier->remise_percent;
}
}
if ($result == 0) { // If result == 0, we failed to found the supplier reference price
$langs->load("errors");
$this->error = "Ref ".$prod->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier");
$this->error = "Ref ".$productsupplier->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier");
$this->db->rollback();
dol_syslog(get_class($this)."::addline we did not found supplier price, so we can't guess unit price");
//$pu = $prod->fourn_pu; // We do not overwrite unit price
//$ref = $prod->ref_fourn; // We do not overwrite ref supplier price
//$pu = $productsupplier->fourn_pu; // We do not overwrite unit price
//$ref = $productsupplier_fourn; // We do not overwrite ref supplier price
return -1;
}
if ($result == -1) {
$langs->load("errors");
$this->error = "Ref ".$prod->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier");
$this->error = "Ref ".$productsupplier->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier");
$this->db->rollback();
dol_syslog(get_class($this)."::addline result=".$result." - ".$this->error, LOG_DEBUG);
return -1;
}
if ($result < -1) {
$this->error = $prod->error;
$this->errors = $prod->errors;
$this->error = $productsupplier->error;
$this->errors = $productsupplier->errors;
$this->db->rollback();
dol_syslog(get_class($this)."::addline result=".$result." - ".$this->error, LOG_ERR);
return -1;
}
} else {
$this->error = $prod->error;
$this->errors = $prod->errors;
$this->error = $productsupplier->error;
$this->errors = $productsupplier->errors;
$this->db->rollback();
return -1;
}