mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
FIX default_vat_code was not returned in some Ajax services of products
This commit is contained in:
parent
ee14aa2597
commit
0dcbd458b8
|
|
@ -2414,7 +2414,7 @@ class Form
|
|||
}
|
||||
}
|
||||
|
||||
$selectFields = " p.rowid, p.ref, p.label, p.description, p.barcode, p.fk_country, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.duration, p.fk_price_expression";
|
||||
$selectFields = " p.rowid, p.ref, p.label, p.description, p.barcode, p.fk_country, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.default_vat_code, p.duration, p.fk_price_expression";
|
||||
if (count($warehouseStatusArray)) {
|
||||
$selectFieldsGrouped = ", sum(".$this->db->ifsql("e.statut IS NULL", "0", "ps.reel").") as stock"; // e.statut is null if there is no record in stock
|
||||
} else {
|
||||
|
|
@ -2436,8 +2436,8 @@ class Form
|
|||
//Price by customer
|
||||
if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
|
||||
$sql .= ', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
|
||||
$sql .= ' pcp.price_base_type as custprice_base_type, pcp.tva_tx as custtva_tx, pcp.ref_customer as custref';
|
||||
$selectFields .= ", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custref";
|
||||
$sql .= ' pcp.price_base_type as custprice_base_type, pcp.tva_tx as custtva_tx, pcp.default_vat_code as custdefault_vat_code, pcp.ref_customer as custref';
|
||||
$selectFields .= ", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref";
|
||||
}
|
||||
// Units
|
||||
if (!empty($conf->global->PRODUCT_USE_UNITS)) {
|
||||
|
|
@ -2658,6 +2658,9 @@ class Form
|
|||
$objp->remise_percent = $objp2->remise_percent;
|
||||
$objp->remise = $objp2->remise;
|
||||
|
||||
//$objp->tva_tx is not overwritten by $objp2 value
|
||||
//$objp->default_vat_code is not overwritten by $objp2 value
|
||||
|
||||
$this->constructProductListOption($objp, $opt, $optJson, 0, $selected, $hidepriceinlabel, $filterkey);
|
||||
|
||||
$j++;
|
||||
|
|
@ -2709,8 +2712,9 @@ class Form
|
|||
}
|
||||
|
||||
/**
|
||||
* constructProductListOption.
|
||||
* Function to forge the string with OPTIONs of SELECT.
|
||||
* This define value for &$opt and &$optJson.
|
||||
* This function is called by select_produits_list().
|
||||
*
|
||||
* @param resource $objp Resultset of fetch
|
||||
* @param string $opt Option (var used for returned value in string option format)
|
||||
|
|
@ -2740,6 +2744,7 @@ class Form
|
|||
$outprice_ttc = '';
|
||||
$outpricebasetype = '';
|
||||
$outtva_tx = '';
|
||||
$outdefault_vat_code = '';
|
||||
$outqty = 1;
|
||||
$outdiscount = 0;
|
||||
|
||||
|
|
@ -2866,9 +2871,9 @@ class Form
|
|||
$found = 0;
|
||||
|
||||
// Multiprice
|
||||
// If we need a particular price level (from 1 to 6)
|
||||
// If we need a particular price level (from 1 to n)
|
||||
if (empty($hidepriceinlabel) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) {
|
||||
$sql = "SELECT price, price_ttc, price_base_type, tva_tx";
|
||||
$sql = "SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."product_price";
|
||||
$sql .= " WHERE fk_product = ".((int) $objp->rowid);
|
||||
$sql .= " AND entity IN (".getEntity('productprice').")";
|
||||
|
|
@ -2892,7 +2897,13 @@ class Form
|
|||
$outprice_ht = price($objp2->price);
|
||||
$outprice_ttc = price($objp2->price_ttc);
|
||||
$outpricebasetype = $objp2->price_base_type;
|
||||
$outtva_tx = $objp2->tva_tx;
|
||||
if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) { // using this option is a bug. kept for backward compatibility
|
||||
$outtva_tx = $objp2->tva_tx; // We use the vat rate on line of multiprice
|
||||
$outdefault_vat_code = $objp2->default_vat_code; // We use the vat code on line of multiprice
|
||||
} else {
|
||||
$outtva_tx = $objp->tva_tx; // We use the vat rate of product, not the one on line of multiprice
|
||||
$outdefault_vat_code = $objp->default_vat_code; // We use the vat code or product, not the one on line of multiprice
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dol_print_error($this->db);
|
||||
|
|
@ -2919,7 +2930,8 @@ class Form
|
|||
$outprice_ht = price($objp->unitprice);
|
||||
$outprice_ttc = price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
|
||||
$outpricebasetype = $objp->price_base_type;
|
||||
$outtva_tx = $objp->tva_tx;
|
||||
$outtva_tx = $objp->tva_tx; // This value is the value on product when constructProductListOption is called by select_produits_list even if other field $objp-> are from table price_by_qty
|
||||
$outdefault_vat_code = $objp->default_vat_code; // This value is the value on product when constructProductListOption is called by select_produits_list even if other field $objp-> are from table price_by_qty
|
||||
}
|
||||
if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
|
||||
$opt .= " (".price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency)."/".$langs->trans("Unit").")"; // Do not use strtolower because it breaks utf8 encoding
|
||||
|
|
@ -2947,6 +2959,7 @@ class Form
|
|||
$outprice_ttc = price($objp->custprice_ttc);
|
||||
$outpricebasetype = $objp->custprice_base_type;
|
||||
$outtva_tx = $objp->custtva_tx;
|
||||
$outdefault_vat_code = $objp->custdefault_vat_code;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2963,6 +2976,7 @@ class Form
|
|||
$outprice_ttc = price($objp->price_ttc);
|
||||
$outpricebasetype = $objp->price_base_type;
|
||||
$outtva_tx = $objp->tva_tx;
|
||||
$outdefault_vat_code = $objp->default_vat_code;
|
||||
}
|
||||
|
||||
if (!empty($conf->stock->enabled) && isset($objp->stock) && ($objp->fk_product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES))) {
|
||||
|
|
@ -3011,7 +3025,9 @@ class Form
|
|||
'price_ht'=>price2num($outprice_ht),
|
||||
'price_ttc'=>price2num($outprice_ttc),
|
||||
'pricebasetype'=>$outpricebasetype,
|
||||
'tva_tx'=>$outtva_tx, 'qty'=>$outqty,
|
||||
'tva_tx'=>$outtva_tx,
|
||||
'default_vat_code'=>$outdefault_vat_code,
|
||||
'qty'=>$outqty,
|
||||
'discount'=>$outdiscount,
|
||||
'duration_value'=>$outdurationvalue,
|
||||
'duration_unit'=>$outdurationunit,
|
||||
|
|
|
|||
|
|
@ -85,10 +85,15 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) {
|
|||
if ($ret > 0) {
|
||||
$outref = $object->ref;
|
||||
$outlabel = $object->label;
|
||||
$outlabel_trans ='';
|
||||
$outlabel_trans = '';
|
||||
$outdesc = $object->description;
|
||||
$outdesc_trans ='';
|
||||
$outdesc_trans = '';
|
||||
$outtype = $object->type;
|
||||
$outprice_ht = null;
|
||||
$outprice_ttc = null;
|
||||
$outpricebasetype = null;
|
||||
$outtva_tx = 0;
|
||||
$outdefault_vat_code = '';
|
||||
$outqty = 1;
|
||||
$outdiscount = 0;
|
||||
$mandatory_period = $object->mandatory_period;
|
||||
|
|
@ -132,17 +137,21 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) {
|
|||
$found = true;
|
||||
$outprice_ht = price($objp->unitprice);
|
||||
$outprice_ttc = price($objp->unitprice * (1 + ($object->tva_tx / 100)));
|
||||
|
||||
$outpricebasetype = $object->price_base_type;
|
||||
$outtva_tx = $object->tva_tx;
|
||||
$outdefault_vat_code = $object->default_vat_code;
|
||||
|
||||
$outqty = $objp->quantity;
|
||||
$outdiscount = $objp->remise_percent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Multiprice
|
||||
// Multiprice (1 price per level)
|
||||
if (!$found && isset($price_level) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) { // If we need a particular price level (from 1 to 6)
|
||||
$sql = "SELECT price, price_ttc, price_base_type, tva_tx";
|
||||
$sql = "SELECT price, price_ttc, price_base_type,";
|
||||
$sql .= " tva_tx, default_vat_code"; // Vat rate and code will be used if PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL is on.
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."product_price ";
|
||||
$sql .= " WHERE fk_product = ".((int) $id);
|
||||
$sql .= " AND entity IN (".getEntity('productprice').")";
|
||||
|
|
@ -158,7 +167,14 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) {
|
|||
$outprice_ht = price($objp->price);
|
||||
$outprice_ttc = price($objp->price_ttc);
|
||||
$outpricebasetype = $objp->price_base_type;
|
||||
$outtva_tx = $objp->tva_tx;
|
||||
if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
|
||||
$outtva_tx = $objp->tva_tx;
|
||||
$outdefault_vat_code = $objp->default_vat_code;
|
||||
} else {
|
||||
// The common and default behaviour.
|
||||
$outtva_tx = $object->tva_tx;
|
||||
$outdefault_vat_code = $object->default_vat_code;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -175,10 +191,11 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) {
|
|||
if ($result) {
|
||||
if (count($prodcustprice->lines) > 0) {
|
||||
$found = true;
|
||||
$outprice_ht = price($prodcustprice->lines [0]->price);
|
||||
$outprice_ttc = price($prodcustprice->lines [0]->price_ttc);
|
||||
$outpricebasetype = $prodcustprice->lines [0]->price_base_type;
|
||||
$outtva_tx = $prodcustprice->lines [0]->tva_tx;
|
||||
$outprice_ht = price($prodcustprice->lines[0]->price);
|
||||
$outprice_ttc = price($prodcustprice->lines[0]->price_ttc);
|
||||
$outpricebasetype = $prodcustprice->lines[0]->price_base_type;
|
||||
$outtva_tx = $prodcustprice->lines[0]->tva_tx;
|
||||
$outdefault_vat_code = $prodcustprice->lines[0]->default_vat_code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -188,6 +205,7 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) {
|
|||
$outprice_ttc = price($object->price_ttc);
|
||||
$outpricebasetype = $object->price_base_type;
|
||||
$outtva_tx = $object->tva_tx;
|
||||
$outdefault_vat_code = $object->default_vat_code;
|
||||
}
|
||||
|
||||
$outjson = array(
|
||||
|
|
@ -201,6 +219,7 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) {
|
|||
'price_ttc' => $outprice_ttc,
|
||||
'pricebasetype' => $outpricebasetype,
|
||||
'tva_tx' => $outtva_tx,
|
||||
'default_vat_code' => $outdefault_vat_code,
|
||||
'qty' => $outqty,
|
||||
'discount' => $outdiscount,
|
||||
'mandatory_period' => $mandatory_period,
|
||||
|
|
|
|||
|
|
@ -2037,7 +2037,7 @@ class Product extends CommonObject
|
|||
|
||||
|
||||
/**
|
||||
* Modify customer price of a product/Service
|
||||
* Modify customer price of a product/Service
|
||||
*
|
||||
* @param double $newprice New price
|
||||
* @param string $newpricebase HT or TTC
|
||||
|
|
|
|||
|
|
@ -392,9 +392,9 @@ class Productcustomerprice extends CommonObject
|
|||
$sql .= " t.import_key,";
|
||||
$sql .= " soc.nom as socname,";
|
||||
$sql .= " prod.ref as prodref";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price as t ";
|
||||
$sql .= " ,".MAIN_DB_PREFIX."product as prod ";
|
||||
$sql .= " ,".MAIN_DB_PREFIX."societe as soc ";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price as t,";
|
||||
$sql .= " ".MAIN_DB_PREFIX."product as prod,";
|
||||
$sql .= " ".MAIN_DB_PREFIX."societe as soc";
|
||||
$sql .= " WHERE soc.rowid=t.fk_soc ";
|
||||
$sql .= " AND prod.rowid=t.fk_product ";
|
||||
$sql .= " AND prod.entity IN (".getEntity('product').")";
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ if (empty($reshook)) {
|
|||
$reg = array();
|
||||
$vatratecode = '';
|
||||
if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
|
||||
$vat_src_code = $reg[1];
|
||||
$vatratecode = $reg[1];
|
||||
$tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate.
|
||||
}
|
||||
|
||||
|
|
@ -172,6 +172,8 @@ if (empty($reshook)) {
|
|||
}
|
||||
|
||||
if ($error) {
|
||||
// Force the update of the price of the product to 0 if error
|
||||
|
||||
//$localtaxarray=array('0'=>$localtax1_type,'1'=>$localtax1,'2'=>$localtax2_type,'3'=>$localtax2);
|
||||
$localtaxarray = array(); // We do not store localtaxes into product, we will use instead the "vat code" to retrieve them.
|
||||
$object->updatePrice(0, $object->price_base_type, $user, $tva_tx, '', 0, $npr, 0, 0, $localtaxarray, $vatratecode);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user