forked from Wavyzz/dolibarr
Debug v17, on supplier, default vat rate is sale if no price found
This commit is contained in:
@@ -168,12 +168,14 @@ class box_produits extends ModeleBoxes
|
|||||||
$price = '';
|
$price = '';
|
||||||
$price_base_type = '';
|
$price_base_type = '';
|
||||||
if ($usercancreadprice) {
|
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_base_type = $langs->trans($objp->price_base_type);
|
||||||
$price = ($objp->price_base_type == 'HT') ?price($objp->price) : $price = price($objp->price_ttc);
|
$price = ($objp->price_base_type == 'HT') ?price($objp->price) : $price = price($objp->price_ttc);
|
||||||
} else {
|
} else {
|
||||||
//Parse the dynamic price
|
//Parse the dynamic price
|
||||||
$productstatic->fetch($objp->rowid, '', '', 1);
|
$productstatic->fetch($objp->rowid, '', '', 1);
|
||||||
|
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
|
||||||
$priceparser = new PriceParser($this->db);
|
$priceparser = new PriceParser($this->db);
|
||||||
$price_result = $priceparser->parseProduct($productstatic);
|
$price_result = $priceparser->parseProduct($productstatic);
|
||||||
if ($price_result >= 0) {
|
if ($price_result >= 0) {
|
||||||
|
|||||||
@@ -167,12 +167,13 @@ class box_produits_alerte_stock extends ModeleBoxes
|
|||||||
'text' => $objp->label,
|
'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_base_type = $langs->trans($objp->price_base_type);
|
||||||
$price = ($objp->price_base_type == 'HT') ?price($objp->price) : $price = price($objp->price_ttc);
|
$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);
|
$productstatic->fetch($objp->rowid, '', '', 1);
|
||||||
|
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
|
||||||
$priceparser = new PriceParser($this->db);
|
$priceparser = new PriceParser($this->db);
|
||||||
$price_result = $priceparser->parseProduct($productstatic);
|
$price_result = $priceparser->parseProduct($productstatic);
|
||||||
if ($price_result >= 0) {
|
if ($price_result >= 0) {
|
||||||
|
|||||||
@@ -2828,6 +2828,8 @@ class Form
|
|||||||
if (isModEnabled('dynamicprices') && !empty($objp->fk_price_expression)) {
|
if (isModEnabled('dynamicprices') && !empty($objp->fk_price_expression)) {
|
||||||
$price_product = new Product($this->db);
|
$price_product = new Product($this->db);
|
||||||
$price_product->fetch($objp->rowid, '', '', 1);
|
$price_product->fetch($objp->rowid, '', '', 1);
|
||||||
|
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
|
||||||
$priceparser = new PriceParser($this->db);
|
$priceparser = new PriceParser($this->db);
|
||||||
$price_result = $priceparser->parseProduct($price_product);
|
$price_result = $priceparser->parseProduct($price_product);
|
||||||
if ($price_result >= 0) {
|
if ($price_result >= 0) {
|
||||||
@@ -3463,6 +3465,8 @@ class Form
|
|||||||
$prod_supplier->fourn_qty = $objp->quantity;
|
$prod_supplier->fourn_qty = $objp->quantity;
|
||||||
$prod_supplier->fourn_tva_tx = $objp->tva_tx;
|
$prod_supplier->fourn_tva_tx = $objp->tva_tx;
|
||||||
$prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
|
$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);
|
$priceparser = new PriceParser($this->db);
|
||||||
$price_result = $priceparser->parseProductSupplier($prod_supplier);
|
$price_result = $priceparser->parseProductSupplier($prod_supplier);
|
||||||
if ($price_result >= 0) {
|
if ($price_result >= 0) {
|
||||||
@@ -3717,6 +3721,8 @@ class Form
|
|||||||
$prod_supplier->fourn_qty = $objp->quantity;
|
$prod_supplier->fourn_qty = $objp->quantity;
|
||||||
$prod_supplier->fourn_tva_tx = $objp->tva_tx;
|
$prod_supplier->fourn_tva_tx = $objp->tva_tx;
|
||||||
$prod_supplier->fk_supplier_price_expression = $objp->fk_supplier_price_expression;
|
$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);
|
$priceparser = new PriceParser($this->db);
|
||||||
$price_result = $priceparser->parseProductSupplier($prod_supplier);
|
$price_result = $priceparser->parseProductSupplier($prod_supplier);
|
||||||
if ($price_result >= 0) {
|
if ($price_result >= 0) {
|
||||||
|
|||||||
@@ -6316,20 +6316,25 @@ function get_product_vat_for_country($idprod, $thirdpartytouse, $idprodfournpric
|
|||||||
$product = new Product($db);
|
$product = new Product($db);
|
||||||
$product->fetch($idprod);
|
$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
|
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;
|
$ret = $product->vatrate_supplier;
|
||||||
if ($product->default_vat_code) {
|
if ($product->default_vat_code_supplier) {
|
||||||
$ret .= ' ('.$product->default_vat_code.')';
|
$ret .= ' ('.$product->default_vat_code_supplier.')';
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$ret = $product->tva_tx; // Default vat of product we defined
|
|
||||||
if ($product->default_vat_code) {
|
|
||||||
$ret .= ' ('.$product->default_vat_code.')';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$found = 1;
|
$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 {
|
} else {
|
||||||
// TODO Read default product vat according to product and another countrycode.
|
// 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.
|
// Vat for couple anothercountrycode/product is data that is not managed and store yet, so we will fallback on next rule.
|
||||||
@@ -6359,7 +6364,9 @@ function get_product_vat_for_country($idprod, $thirdpartytouse, $idprodfournpric
|
|||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
} else {
|
} 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 = '';
|
$defaulttx = '';
|
||||||
if ($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS != 'none') {
|
if ($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS != 'none') {
|
||||||
$defaulttx = $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;
|
$defaulttx = $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;
|
||||||
|
|||||||
@@ -35,11 +35,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/class/commonorder.class.php';
|
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')) {
|
if (isModEnabled('productbatch')) {
|
||||||
require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
|
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
|
* Class to manage predefined suppliers products
|
||||||
@@ -1820,10 +1821,10 @@ class CommandeFournisseur extends CommonOrder
|
|||||||
$label = ''; // deprecated
|
$label = ''; // deprecated
|
||||||
|
|
||||||
if ($fk_product > 0) {
|
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
|
// 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);
|
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) {
|
if ($prod->fetch($fk_product) > 0) {
|
||||||
$product_type = $prod->type;
|
$product_type = $prod->type;
|
||||||
$label = $prod->label;
|
$label = $prod->label;
|
||||||
@@ -1882,7 +1883,7 @@ class CommandeFournisseur extends CommonOrder
|
|||||||
if (!empty($prod->packaging) && ($qty % $prod->packaging) > 0) {
|
if (!empty($prod->packaging) && ($qty % $prod->packaging) > 0) {
|
||||||
$coeff = intval($qty / $prod->packaging) + 1;
|
$coeff = intval($qty / $prod->packaging) + 1;
|
||||||
$qty = $prod->packaging * $coeff;
|
$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);
|
$localtaxes_type = getLocalTaxesFromRate($txtva, 0, $mysoc, $this->thirdparty);
|
||||||
|
|
||||||
// Clean vat code
|
// Clean vat code
|
||||||
|
$reg = array();
|
||||||
$vat_src_code = '';
|
$vat_src_code = '';
|
||||||
if (preg_match('/\((.*)\)/', $txtva, $reg)) {
|
if (preg_match('/\((.*)\)/', $txtva, $reg)) {
|
||||||
$vat_src_code = $reg[1];
|
$vat_src_code = $reg[1];
|
||||||
|
|||||||
@@ -38,12 +38,10 @@
|
|||||||
include_once DOL_DOCUMENT_ROOT.'/core/class/commoninvoice.class.php';
|
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.'/core/class/commonobjectline.class.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.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')) {
|
if (isModEnabled('accounting')) {
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
|
||||||
}
|
|
||||||
if (isModEnabled('accounting')) {
|
|
||||||
require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
|
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)) {
|
if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) {
|
||||||
// Check quantity is enough
|
// Check quantity is enough
|
||||||
dol_syslog(get_class($this)."::addline we check supplier prices fk_product=".$fk_product." qty=".$qty." ref_supplier=".$ref_supplier);
|
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) {
|
if ($prod->fetch($fk_product) > 0) {
|
||||||
$product_type = $prod->type;
|
$product_type = $prod->type;
|
||||||
$label = $prod->label;
|
$label = $prod->label;
|
||||||
|
|||||||
@@ -31,7 +31,6 @@
|
|||||||
|
|
||||||
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
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.'/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';
|
require_once DOL_DOCUMENT_ROOT.'/product/class/productfournisseurprice.class.php';
|
||||||
|
|
||||||
|
|
||||||
@@ -638,7 +637,8 @@ class ProductFournisseur extends Product
|
|||||||
}
|
}
|
||||||
$this->packaging = $obj->packaging;
|
$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);
|
$priceparser = new PriceParser($this->db);
|
||||||
$price_result = $priceparser->parseProductSupplier($this);
|
$price_result = $priceparser->parseProductSupplier($this);
|
||||||
if ($price_result >= 0) {
|
if ($price_result >= 0) {
|
||||||
@@ -748,6 +748,7 @@ class ProductFournisseur extends Product
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isModEnabled('dynamicprices') && !empty($prodfourn->fk_supplier_price_expression)) {
|
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);
|
$priceparser = new PriceParser($this->db);
|
||||||
$price_result = $priceparser->parseProductSupplier($prodfourn);
|
$price_result = $priceparser->parseProductSupplier($prodfourn);
|
||||||
if ($price_result >= 0) {
|
if ($price_result >= 0) {
|
||||||
@@ -860,6 +861,8 @@ class ProductFournisseur extends Product
|
|||||||
$prod_supplier->fourn_qty = $record["quantity"];
|
$prod_supplier->fourn_qty = $record["quantity"];
|
||||||
$prod_supplier->fourn_tva_tx = $record["tva_tx"];
|
$prod_supplier->fourn_tva_tx = $record["tva_tx"];
|
||||||
$prod_supplier->fk_supplier_price_expression = $record["fk_supplier_price_expression"];
|
$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);
|
$priceparser = new PriceParser($this->db);
|
||||||
$price_result = $priceparser->parseProductSupplier($prod_supplier);
|
$price_result = $priceparser->parseProductSupplier($prod_supplier);
|
||||||
if ($price_result >= 0) {
|
if ($price_result >= 0) {
|
||||||
|
|||||||
@@ -191,12 +191,28 @@ class Product extends CommonObject
|
|||||||
//! French VAT NPR (0 or 1)
|
//! French VAT NPR (0 or 1)
|
||||||
public $tva_npr = 0;
|
public $tva_npr = 0;
|
||||||
|
|
||||||
|
//! Default discount percent
|
||||||
|
public $remise_percent;
|
||||||
|
|
||||||
//! Other local taxes
|
//! Other local taxes
|
||||||
public $localtax1_tx;
|
public $localtax1_tx;
|
||||||
public $localtax2_tx;
|
public $localtax2_tx;
|
||||||
public $localtax1_type;
|
public $localtax1_type;
|
||||||
public $localtax2_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 $lifetime;
|
||||||
|
|
||||||
public $qc_frequency;
|
public $qc_frequency;
|
||||||
@@ -415,6 +431,7 @@ class Product extends CommonObject
|
|||||||
public $fk_price_expression;
|
public $fk_price_expression;
|
||||||
|
|
||||||
/* To store supplier price found */
|
/* To store supplier price found */
|
||||||
|
public $fourn_qty;
|
||||||
public $fourn_pu;
|
public $fourn_pu;
|
||||||
public $fourn_price_base_type;
|
public $fourn_price_base_type;
|
||||||
public $fourn_socid;
|
public $fourn_socid;
|
||||||
@@ -1955,9 +1972,8 @@ class Product extends CommonObject
|
|||||||
$result = 0;
|
$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)
|
// 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 = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pfp.remise_percent, pfp.fk_soc,";
|
||||||
$sql .= " pfp.fk_product, pfp.ref_fourn, pfp.desc_fourn, pfp.fk_soc, pfp.tva_tx, pfp.fk_supplier_price_expression,";
|
$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.default_vat_code,";
|
|
||||||
$sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,";
|
$sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,";
|
||||||
$sql .= " pfp.packaging";
|
$sql .= " pfp.packaging";
|
||||||
$sql .= " FROM ".$this->db->prefix()."product_fournisseur_price as pfp";
|
$sql .= " FROM ".$this->db->prefix()."product_fournisseur_price as pfp";
|
||||||
@@ -1972,14 +1988,15 @@ class Product extends CommonObject
|
|||||||
if ($resql) {
|
if ($resql) {
|
||||||
$obj = $this->db->fetch_object($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 ($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)) {
|
if (isModEnabled('dynamicprices') && !empty($obj->fk_supplier_price_expression)) {
|
||||||
include_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
|
|
||||||
$prod_supplier = new ProductFournisseur($this->db);
|
$prod_supplier = new ProductFournisseur($this->db);
|
||||||
$prod_supplier->product_fourn_price_id = $obj->rowid;
|
$prod_supplier->product_fourn_price_id = $obj->rowid;
|
||||||
$prod_supplier->id = $obj->fk_product;
|
$prod_supplier->id = $obj->fk_product;
|
||||||
$prod_supplier->fourn_qty = $obj->quantity;
|
$prod_supplier->fourn_qty = $obj->quantity;
|
||||||
$prod_supplier->fourn_tva_tx = $obj->tva_tx;
|
$prod_supplier->fourn_tva_tx = $obj->tva_tx;
|
||||||
$prod_supplier->fk_supplier_price_expression = $obj->fk_supplier_price_expression;
|
$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);
|
$priceparser = new PriceParser($this->db);
|
||||||
$price_result = $priceparser->parseProductSupplier($prod_supplier);
|
$price_result = $priceparser->parseProductSupplier($prod_supplier);
|
||||||
if ($price_result >= 0) {
|
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_pu = $obj->price / $obj->quantity; // Unit price of product of supplier
|
||||||
$this->fourn_price_base_type = 'HT'; // Price base type
|
$this->fourn_price_base_type = 'HT'; // Price base type
|
||||||
$this->fourn_socid = $obj->fk_soc; // Company that offer this price
|
$this->fourn_socid = $obj->fk_soc; // Company that offer this price
|
||||||
$this->ref_fourn = $obj->ref_fourn; // deprecated
|
$this->ref_fourn = $obj->ref_supplier; // deprecated
|
||||||
$this->ref_supplier = $obj->ref_fourn; // Ref supplier
|
$this->ref_supplier = $obj->ref_supplier; // Ref supplier
|
||||||
$this->desc_supplier = $obj->desc_fourn; // desc supplier
|
$this->desc_supplier = $obj->desc_supplier; // desc supplier
|
||||||
$this->remise_percent = $obj->remise_percent; // remise percent if present and not typed
|
$this->remise_percent = $obj->remise_percent; // remise percent if present and not typed
|
||||||
$this->vatrate_supplier = $obj->tva_tx; // Vat ref supplier
|
$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_price = $obj->multicurrency_price;
|
||||||
$this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
|
$this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
|
||||||
$this->fourn_multicurrency_tx = $obj->multicurrency_tx;
|
$this->fourn_multicurrency_tx = $obj->multicurrency_tx;
|
||||||
@@ -2010,8 +2027,7 @@ class Product extends CommonObject
|
|||||||
} else { // If not found
|
} 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.
|
// 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 = "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.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.default_vat_code,";
|
|
||||||
$sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,";
|
$sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,";
|
||||||
$sql .= " pfp.packaging";
|
$sql .= " pfp.packaging";
|
||||||
$sql .= " FROM ".$this->db->prefix()."product_fournisseur_price as pfp";
|
$sql .= " FROM ".$this->db->prefix()."product_fournisseur_price as pfp";
|
||||||
@@ -2036,14 +2052,15 @@ class Product extends CommonObject
|
|||||||
if ($resql) {
|
if ($resql) {
|
||||||
$obj = $this->db->fetch_object($resql);
|
$obj = $this->db->fetch_object($resql);
|
||||||
if ($obj && $obj->quantity > 0) { // If found
|
if ($obj && $obj->quantity > 0) { // If found
|
||||||
if (!empty($conf->dynamicprices->enabled) && !empty($obj->fk_supplier_price_expression)) {
|
if (isModEnabled('dynamicprices') && !empty($obj->fk_supplier_price_expression)) {
|
||||||
include_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
|
|
||||||
$prod_supplier = new ProductFournisseur($this->db);
|
$prod_supplier = new ProductFournisseur($this->db);
|
||||||
$prod_supplier->product_fourn_price_id = $obj->rowid;
|
$prod_supplier->product_fourn_price_id = $obj->rowid;
|
||||||
$prod_supplier->id = $obj->fk_product;
|
$prod_supplier->id = $obj->fk_product;
|
||||||
$prod_supplier->fourn_qty = $obj->quantity;
|
$prod_supplier->fourn_qty = $obj->quantity;
|
||||||
$prod_supplier->fourn_tva_tx = $obj->tva_tx;
|
$prod_supplier->fourn_tva_tx = $obj->tva_tx;
|
||||||
$prod_supplier->fk_supplier_price_expression = $obj->fk_supplier_price_expression;
|
$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);
|
$priceparser = new PriceParser($this->db);
|
||||||
$price_result = $priceparser->parseProductSupplier($prod_supplier);
|
$price_result = $priceparser->parseProductSupplier($prod_supplier);
|
||||||
if ($result >= 0) {
|
if ($result >= 0) {
|
||||||
@@ -2061,7 +2078,7 @@ class Product extends CommonObject
|
|||||||
$this->desc_supplier = $obj->desc_supplier; // desc supplier
|
$this->desc_supplier = $obj->desc_supplier; // desc supplier
|
||||||
$this->remise_percent = $obj->remise_percent; // remise percent if present and not typed
|
$this->remise_percent = $obj->remise_percent; // remise percent if present and not typed
|
||||||
$this->vatrate_supplier = $obj->tva_tx; // Vat ref supplier
|
$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_price = $obj->multicurrency_price;
|
||||||
$this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
|
$this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
|
||||||
$this->fourn_multicurrency_tx = $obj->multicurrency_tx;
|
$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';
|
include_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
|
||||||
$priceparser = new PriceParser($this->db);
|
$priceparser = new PriceParser($this->db);
|
||||||
$price_result = $priceparser->parseProduct($this);
|
$price_result = $priceparser->parseProduct($this);
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ if ($action == 'add') {
|
|||||||
$result = $price_expression->find_title($title);
|
$result = $price_expression->find_title($title);
|
||||||
if ($result == 0) { //No existing entry found with title, ok
|
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);
|
$priceparser = new PriceParser($db);
|
||||||
$price_result = $priceparser->testExpression($id, $expression);
|
$price_result = $priceparser->testExpression($id, $expression);
|
||||||
if ($price_result < 0) { //Expression is not valid
|
if ($price_result < 0) { //Expression is not valid
|
||||||
@@ -96,6 +97,7 @@ if ($action == 'update') {
|
|||||||
$result = $price_expression->find_title($title);
|
$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
|
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);
|
$priceparser = new PriceParser($db);
|
||||||
$price_result = $priceparser->testExpression($id, $expression);
|
$price_result = $priceparser->testExpression($id, $expression);
|
||||||
if ($price_result < 0) { //Expression is not valid
|
if ($price_result < 0) { //Expression is not valid
|
||||||
|
|||||||
@@ -318,6 +318,7 @@ if (empty($reshook)) {
|
|||||||
} else {
|
} else {
|
||||||
if (isModEnabled('dynamicprices') && $price_expression !== '') {
|
if (isModEnabled('dynamicprices') && $price_expression !== '') {
|
||||||
//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);
|
$priceparser = new PriceParser($db);
|
||||||
$object->fk_supplier_price_expression = $price_expression;
|
$object->fk_supplier_price_expression = $price_expression;
|
||||||
$price_result = $priceparser->parseProductSupplier($object);
|
$price_result = $priceparser->parseProductSupplier($object);
|
||||||
|
|||||||
@@ -373,9 +373,11 @@ if ((isModEnabled("product") || isModEnabled("service")) && ($user->hasRight("pr
|
|||||||
print "</td>";
|
print "</td>";
|
||||||
// Sell price
|
// Sell price
|
||||||
if (empty($conf->global->PRODUIT_MULTIPRICES)) {
|
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 = new Product($db);
|
||||||
$product->fetch($objp->rowid);
|
$product->fetch($objp->rowid);
|
||||||
|
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
|
||||||
$priceparser = new PriceParser($db);
|
$priceparser = new PriceParser($db);
|
||||||
$price_result = $priceparser->parseProduct($product);
|
$price_result = $priceparser->parseProduct($product);
|
||||||
if ($price_result >= 0) {
|
if ($price_result >= 0) {
|
||||||
|
|||||||
@@ -258,11 +258,12 @@ if (empty($reshook)) {
|
|||||||
$psq = empty($newpsq) ? 0 : $newpsq;
|
$psq = empty($newpsq) ? 0 : $newpsq;
|
||||||
$maxpricesupplier = $object->min_recommended_price();
|
$maxpricesupplier = $object->min_recommended_price();
|
||||||
|
|
||||||
if (!empty($conf->dynamicprices->enabled)) {
|
if (isModEnabled('dynamicprices')) {
|
||||||
$object->fk_price_expression = empty($eid) ? 0 : $eid; //0 discards expression
|
$object->fk_price_expression = empty($eid) ? 0 : $eid; //0 discards expression
|
||||||
|
|
||||||
if ($object->fk_price_expression != 0) {
|
if ($object->fk_price_expression != 0) {
|
||||||
//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);
|
$priceparser = new PriceParser($db);
|
||||||
|
|
||||||
if ($priceparser->parseProduct($object) < 0) {
|
if ($priceparser->parseProduct($object) < 0) {
|
||||||
|
|||||||
@@ -452,49 +452,49 @@ class SupplierProposal extends CommonObject
|
|||||||
if (!empty($conf->global->SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY)) {
|
if (!empty($conf->global->SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY)) {
|
||||||
// Check quantity is enough
|
// 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);
|
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);
|
$productsupplier = new ProductFournisseur($this->db);
|
||||||
if ($prod->fetch($fk_product) > 0) {
|
if ($productsupplier->fetch($fk_product) > 0) {
|
||||||
$product_type = $prod->type;
|
$product_type = $productsupplier->type;
|
||||||
$label = $prod->label;
|
$label = $productsupplier->label;
|
||||||
$fk_prod_fourn_price = $fk_fournprice;
|
$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.
|
// 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.
|
// 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) {
|
if ($result > 0) {
|
||||||
$pu = $prod->fourn_pu; // Unit price supplier price set by get_buyprice
|
$pu = $productsupplier->fourn_pu; // Unit price supplier price set by get_buyprice
|
||||||
$ref_supplier = $prod->ref_supplier; // Ref 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
|
// is remise percent not keyed but present for the product we add it
|
||||||
if ($remise_percent == 0 && $prod->remise_percent != 0) {
|
if ($remise_percent == 0 && $productsupplier->remise_percent != 0) {
|
||||||
$remise_percent = $prod->remise_percent;
|
$remise_percent = $productsupplier->remise_percent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($result == 0) { // If result == 0, we failed to found the supplier reference price
|
if ($result == 0) { // If result == 0, we failed to found the supplier reference price
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
$this->error = "Ref ".$prod->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier");
|
$this->error = "Ref ".$productsupplier->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier");
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
dol_syslog(get_class($this)."::addline we did not found supplier price, so we can't guess unit price");
|
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
|
//$pu = $productsupplier->fourn_pu; // We do not overwrite unit price
|
||||||
//$ref = $prod->ref_fourn; // We do not overwrite ref supplier price
|
//$ref = $productsupplier_fourn; // We do not overwrite ref supplier price
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ($result == -1) {
|
if ($result == -1) {
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
$this->error = "Ref ".$prod->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier");
|
$this->error = "Ref ".$productsupplier->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier");
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
dol_syslog(get_class($this)."::addline result=".$result." - ".$this->error, LOG_DEBUG);
|
dol_syslog(get_class($this)."::addline result=".$result." - ".$this->error, LOG_DEBUG);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ($result < -1) {
|
if ($result < -1) {
|
||||||
$this->error = $prod->error;
|
$this->error = $productsupplier->error;
|
||||||
$this->errors = $prod->errors;
|
$this->errors = $productsupplier->errors;
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
dol_syslog(get_class($this)."::addline result=".$result." - ".$this->error, LOG_ERR);
|
dol_syslog(get_class($this)."::addline result=".$result." - ".$this->error, LOG_ERR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->error = $prod->error;
|
$this->error = $productsupplier->error;
|
||||||
$this->errors = $prod->errors;
|
$this->errors = $productsupplier->errors;
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user