mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
FIX Default VAT of product added does not take account buyer country
This commit is contained in:
parent
470cbb52f8
commit
04d96f489b
|
|
@ -738,11 +738,11 @@ if (!empty($usemargins) && $user->rights->margins->creer) {
|
|||
if (isNaN(pbq)) { console.log("We use experimental option PRODUIT_CUSTOMER_PRICES_BY_QTY or PRODUIT_CUSTOMER_PRICES_BY_QTY but we could not get the id of pbq from product combo list, so load of price may be 0 if product has differet prices"); }
|
||||
<?php } ?>
|
||||
// Get the price for the product and display it
|
||||
console.log("Load unit price without tax and set it into #price_ht for product id="+$(this).val()+" socid=<?php print $object->socid; ?>");
|
||||
console.log("Load unit price and set it into #price_ht or #price_ttc for product id="+$(this).val()+" socid=<?php print $object->socid; ?>");
|
||||
$.post('<?php echo DOL_URL_ROOT; ?>/product/ajax/products.php?action=fetch',
|
||||
{ 'id': $(this).val(), 'socid': <?php print $object->socid; ?>, 'token': '<?php print currentToken(); ?>' },
|
||||
{ 'id': $(this).val(), 'socid': <?php print $object->socid; ?>, 'token': '<?php print currentToken(); ?>', 'addalsovatforthirdpartyid': 1 },
|
||||
function(data) {
|
||||
console.log("objectline_create.tpl Load unit price end, we got value ht="+data.price_ht+" ttc="+data.price_ttc+" pricebasetype="+data.pricebasetype);
|
||||
console.log("objectline_create.tpl Load unit price ends, we got value ht="+data.price_ht+" ttc="+data.price_ttc+" pricebasetype="+data.pricebasetype);
|
||||
|
||||
$('#date_start').removeAttr('type');
|
||||
$('#date_end').removeAttr('type');
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
/**
|
||||
* \file htdocs/product/ajax/products.php
|
||||
* \brief File to return Ajax response on product list request.
|
||||
* \brief File to return Ajax response on product list request, with default VAT rate.
|
||||
*/
|
||||
|
||||
if (!defined('NOTOKENRENEWAL')) {
|
||||
|
|
@ -35,9 +35,6 @@ if (!defined('NOREQUIREHTML')) {
|
|||
if (!defined('NOREQUIREAJAX')) {
|
||||
define('NOREQUIREAJAX', '1');
|
||||
}
|
||||
if (!defined('NOREQUIRESOC')) {
|
||||
define('NOREQUIRESOC', '1');
|
||||
}
|
||||
if (empty($_GET['keysearch']) && !defined('NOREQUIREHTML')) {
|
||||
define('NOREQUIREHTML', '1');
|
||||
}
|
||||
|
|
@ -225,6 +222,32 @@ if ($action == 'fetch' && !empty($id)) {
|
|||
$outdefault_vat_code = $object->default_vat_code;
|
||||
}
|
||||
|
||||
// VAT to use and default VAT for product are set to same value by default
|
||||
$product_outtva_tx_formated = $outtva_tx_formated;
|
||||
$product_outtva_tx = $outtva_tx;
|
||||
$product_outdefault_vat_code = $outdefault_vat_code;
|
||||
|
||||
// If we ask the price according to buyer, we change it.
|
||||
if (GETPOST('addalsovatforthirdpartyid', 'int')) {
|
||||
$thirdparty_buyer = new Societe($db);
|
||||
$thirdparty_buyer->fetch($socid);
|
||||
|
||||
$tmpvatwithcode = get_default_tva($mysoc, $thirdparty_buyer, $id, 0);
|
||||
|
||||
if (!is_numeric($tmpvatwithcode) || $tmpvatwithcode != -1) {
|
||||
$reg =array();
|
||||
if (preg_match('/(.+)\s\((.+)\)/', $tmpvatwithcode, $reg)) {
|
||||
$outtva_tx = price2num($reg[1]);
|
||||
$outtva_tx_formated = price($outtva_tx);
|
||||
$outdefault_vat_code = $reg[2];
|
||||
} else {
|
||||
$outtva_tx = price2num($tmpvatwithcode);
|
||||
$outtva_tx_formated = price($outtva_tx);
|
||||
$outdefault_vat_code = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$outjson = array(
|
||||
'ref' => $outref,
|
||||
'label' => $outlabel,
|
||||
|
|
@ -235,13 +258,19 @@ if ($action == 'fetch' && !empty($id)) {
|
|||
'price_ht' => $outprice_ht,
|
||||
'price_ttc' => $outprice_ttc,
|
||||
'pricebasetype' => $outpricebasetype,
|
||||
'product_tva_tx_formated' => $product_outtva_tx_formated,
|
||||
'product_tva_tx' => $product_outtva_tx,
|
||||
'product_default_vat_code' => $product_outdefault_vat_code,
|
||||
|
||||
'tva_tx_formated' => $outtva_tx_formated,
|
||||
'tva_tx' => $outtva_tx,
|
||||
'default_vat_code' => $outdefault_vat_code,
|
||||
|
||||
'qty' => $outqty,
|
||||
'discount' => $outdiscount,
|
||||
'mandatory_period' => $mandatory_period,
|
||||
'array_options'=>$object->array_options);
|
||||
'array_options'=>$object->array_options
|
||||
);
|
||||
}
|
||||
|
||||
echo json_encode($outjson);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user