[-] BO: Fix ecotax product backoffice management && rounding issue
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@17804 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var Customer = new Object();
|
var Customer = new Object();
|
||||||
var product_url = '{$link->getAdminLink('AdminProducts', true)}';
|
var product_url = '{$link->getAdminLink('AdminProducts', true)}';
|
||||||
|
var ecotax_tax_excl = parseFloat({$ecotax_tax_excl});
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
Customer = {
|
Customer = {
|
||||||
"hiddenField": jQuery('#id_customer'),
|
"hiddenField": jQuery('#id_customer'),
|
||||||
@@ -405,8 +406,10 @@ $(document).ready(function () {
|
|||||||
<tbody>
|
<tbody>
|
||||||
{$specificPriceModificationForm}
|
{$specificPriceModificationForm}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
calcPriceTI();
|
$(document).ready(function() {
|
||||||
unitPriceWithTax('unit');
|
calcPriceTI();
|
||||||
|
unitPriceWithTax('unit');
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
+39
-25
@@ -1415,32 +1415,46 @@ class CartCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$price = Product::getPriceStatic(
|
if ($with_taxes)
|
||||||
(int)$product['id_product'],
|
$price = Product::getPriceStatic(
|
||||||
true,
|
(int)$product['id_product'],
|
||||||
(int)$product['id_product_attribute'],
|
true,
|
||||||
2,
|
(int)$product['id_product_attribute'],
|
||||||
null,
|
2,
|
||||||
false,
|
null,
|
||||||
true,
|
false,
|
||||||
$product['cart_quantity'],
|
true,
|
||||||
false,
|
$product['cart_quantity'],
|
||||||
((int)$this->id_customer ? (int)$this->id_customer : null),
|
false,
|
||||||
(int)$this->id,
|
((int)$this->id_customer ? (int)$this->id_customer : null),
|
||||||
((int)$address_id ? (int)$address_id : null),
|
(int)$this->id,
|
||||||
$null,
|
((int)$address_id ? (int)$address_id : null),
|
||||||
true,
|
$null,
|
||||||
true,
|
true,
|
||||||
$virtual_context
|
true,
|
||||||
);
|
$virtual_context
|
||||||
|
);
|
||||||
|
else
|
||||||
|
$price = Product::getPriceStatic(
|
||||||
|
(int)$product['id_product'],
|
||||||
|
false,
|
||||||
|
(int)$product['id_product_attribute'],
|
||||||
|
2,
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
$product['cart_quantity'],
|
||||||
|
false,
|
||||||
|
((int)$this->id_customer ? (int)$this->id_customer : null),
|
||||||
|
(int)$this->id,
|
||||||
|
((int)$address_id ? (int)$address_id : null),
|
||||||
|
$null,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
$virtual_context
|
||||||
|
);
|
||||||
|
|
||||||
$total_price = Tools::ps_round($price, 2) * (int)$product['cart_quantity'];
|
$total_price = Tools::ps_round($price * (int)$product['cart_quantity'], 2);
|
||||||
|
|
||||||
if (!$with_taxes)
|
|
||||||
{
|
|
||||||
$product_tax_rate = (float)Tax::getProductTaxRate((int)$product['id_product'], (int)$address_id, $virtual_context);
|
|
||||||
$total_price = Tools::ps_round($total_price / (1 + ($product_tax_rate / 100)), 2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$order_total += $total_price;
|
$order_total += $total_price;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ class OrderInvoiceCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
// sum by order details in order to retrieve real taxes rate
|
// sum by order details in order to retrieve real taxes rate
|
||||||
$taxes_infos = Db::getInstance()->executeS('
|
$taxes_infos = Db::getInstance()->executeS('
|
||||||
SELECT odt.`id_order_detail`, t.`rate` AS `name`, SUM(od.`total_price_tax_excl`) AS total_price_tax_excl, SUM(t.`rate`) AS rate, SUM(`total_amount`) AS `total_amount`, od.`ecotax`, od.`ecotax_tax_rate`
|
SELECT odt.`id_order_detail`, t.`rate` AS `name`, SUM(od.`total_price_tax_excl`) AS total_price_tax_excl, SUM(t.`rate`) AS rate, SUM(`total_amount`) AS `total_amount`, od.`ecotax`, od.`ecotax_tax_rate`, od.`product_quantity`
|
||||||
FROM `'._DB_PREFIX_.'order_detail_tax` odt
|
FROM `'._DB_PREFIX_.'order_detail_tax` odt
|
||||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = odt.`id_tax`)
|
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = odt.`id_tax`)
|
||||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
|
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
|
||||||
@@ -324,9 +324,9 @@ class OrderInvoiceCore extends ObjectModel
|
|||||||
|
|
||||||
$ratio = $tax_infos['total_price_tax_excl'] / $this->total_products;
|
$ratio = $tax_infos['total_price_tax_excl'] / $this->total_products;
|
||||||
$order_reduction_amount = $this->total_discount_tax_excl * $ratio;
|
$order_reduction_amount = $this->total_discount_tax_excl * $ratio;
|
||||||
$tmp_tax_infos[$tax_infos['rate']]['total_amount'] += ($tax_infos['total_amount'] - Tools::ps_round($tax_infos['ecotax'] * $tax_infos['ecotax_tax_rate'] / 100, 2));
|
$tmp_tax_infos[$tax_infos['rate']]['total_amount'] += ($tax_infos['total_amount'] - Tools::ps_round($tax_infos['ecotax'] * $tax_infos['product_quantity'] * $tax_infos['ecotax_tax_rate'] / 100, 2));
|
||||||
$tmp_tax_infos[$tax_infos['rate']]['name'] = $tax_infos['name'];
|
$tmp_tax_infos[$tax_infos['rate']]['name'] = $tax_infos['name'];
|
||||||
$tmp_tax_infos[$tax_infos['rate']]['total_price_tax_excl'] += ($tax_infos['total_price_tax_excl'] - $order_reduction_amount - $tax_infos['ecotax']);
|
$tmp_tax_infos[$tax_infos['rate']]['total_price_tax_excl'] += $tax_infos['total_price_tax_excl'] - $order_reduction_amount - Tools::ps_round($tax_infos['ecotax'] * $tax_infos['product_quantity'], 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,7 +381,7 @@ class OrderInvoiceCore extends ObjectModel
|
|||||||
public function getEcoTaxTaxesBreakdown()
|
public function getEcoTaxTaxesBreakdown()
|
||||||
{
|
{
|
||||||
$res = Db::getInstance()->executeS('
|
$res = Db::getInstance()->executeS('
|
||||||
SELECT `ecotax_tax_rate` as `rate`, SUM(`ecotax`) as `ecotax_tax_excl`, SUM(`ecotax`) as `ecotax_tax_incl`
|
SELECT `ecotax_tax_rate` as `rate`, SUM(`ecotax`) as `ecotax_tax_excl`, SUM(`ecotax`) as `ecotax_tax_incl`, `product_quantity`
|
||||||
FROM `'._DB_PREFIX_.'order_detail`
|
FROM `'._DB_PREFIX_.'order_detail`
|
||||||
WHERE `id_order` = '.(int)$this->id_order.'
|
WHERE `id_order` = '.(int)$this->id_order.'
|
||||||
AND `id_order_invoice` = '.(int)$this->id.'
|
AND `id_order_invoice` = '.(int)$this->id.'
|
||||||
@@ -390,8 +390,10 @@ class OrderInvoiceCore extends ObjectModel
|
|||||||
|
|
||||||
if ($res)
|
if ($res)
|
||||||
foreach ($res as &$row)
|
foreach ($res as &$row)
|
||||||
$row['ecotax_tax_incl'] = Tools::ps_round($row['ecotax_tax_excl'] + ($row['ecotax_tax_excl'] * $row['rate'] / 100), 2);
|
{
|
||||||
|
$row['ecotax_tax_incl'] = Tools::ps_round(($row['ecotax_tax_excl'] * $row['product_quantity']) + ($row['ecotax_tax_excl'] * $row['product_quantity'] * $row['rate'] / 100), 2);
|
||||||
|
$row['ecotax_tax_excl'] = Tools::ps_round($row['ecotax_tax_excl'] * $row['product_quantity'], 2);
|
||||||
|
}
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2781,6 +2781,9 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
$this->context->currency, $shops, $currencies, $countries, $groups)
|
$this->context->currency, $shops, $currencies, $countries, $groups)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$data->assign('ecotax_tax_excl', $obj->ecotax);
|
||||||
|
$this->_applyTaxToEcotax($obj);
|
||||||
|
|
||||||
$data->assign(array(
|
$data->assign(array(
|
||||||
'shops' => $shops,
|
'shops' => $shops,
|
||||||
'admin_one_shop' => count($this->context->employee->getAssociatedShops()) == 1,
|
'admin_one_shop' => count($this->context->employee->getAssociatedShops()) == 1,
|
||||||
@@ -3288,7 +3291,7 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
$data->assign('currency', $currency);
|
$data->assign('currency', $currency);
|
||||||
$this->object = $product;
|
$this->object = $product;
|
||||||
$this->display = 'edit';
|
$this->display = 'edit';
|
||||||
$this->_applyTaxToEcotax($product);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Form for adding a virtual product like software, mp3, etc...
|
* Form for adding a virtual product like software, mp3, etc...
|
||||||
|
|||||||
+5
-4
@@ -35,12 +35,12 @@ function getTax()
|
|||||||
|
|
||||||
function getEcotaxTaxIncluded()
|
function getEcotaxTaxIncluded()
|
||||||
{
|
{
|
||||||
return ($('#ecotax').length && $('#ecotax').val() != '') ? parseFloat($('#ecotax').val()) : 0;
|
return ps_round(ecotax_tax_excl * (1 + ecotaxTaxRate), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEcotaxTaxExcluded()
|
function getEcotaxTaxExcluded()
|
||||||
{
|
{
|
||||||
return getEcotaxTaxIncluded() / (1 + ecotaxTaxRate);
|
return ecotax_tax_excl;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatPrice(price)
|
function formatPrice(price)
|
||||||
@@ -70,12 +70,13 @@ function calcPriceTI()
|
|||||||
document.getElementById('finalPriceWithoutTax').innerHTML = (isNaN(priceTE) == true || priceTE < 0) ? '' :
|
document.getElementById('finalPriceWithoutTax').innerHTML = (isNaN(priceTE) == true || priceTE < 0) ? '' :
|
||||||
(ps_round(priceTE, 2) + getEcotaxTaxExcluded()).toFixed(2);
|
(ps_round(priceTE, 2) + getEcotaxTaxExcluded()).toFixed(2);
|
||||||
calcReduction();
|
calcReduction();
|
||||||
$('#priceTI').value = (parseFloat($('#priceTI').val()) + getEcotaxTaxIncluded()).toFixed(2);
|
$('#priceTI').val((parseFloat($('#priceTI').val()) + getEcotaxTaxIncluded()).toFixed(2));
|
||||||
$('#finalPrice').innerHTML = parseFloat($('#priceTI').val()).toFixed(2);
|
$('#finalPrice').html(parseFloat($('#priceTI').val()).toFixed(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
function calcPriceTE()
|
function calcPriceTE()
|
||||||
{
|
{
|
||||||
|
ecotax_tax_excl = $('#ecotax').val() / (1 + ecotaxTaxRate);
|
||||||
var tax = getTax();
|
var tax = getTax();
|
||||||
var priceTI = parseFloat(document.getElementById('priceTI').value.replace(/,/g, '.'));
|
var priceTI = parseFloat(document.getElementById('priceTI').value.replace(/,/g, '.'));
|
||||||
var newPrice = ps_round(priceTI - getEcotaxTaxIncluded(), 2) / ((tax / 100) + 1);
|
var newPrice = ps_round(priceTI - getEcotaxTaxIncluded(), 2) / ((tax / 100) + 1);
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
<td style="width: 80%">
|
<td style="width: 80%">
|
||||||
{if $tax_exempt}
|
{if $tax_exempt}
|
||||||
{l s='Exempt of VAT according section 259B of the General Tax Code.' pdf='true'}
|
{l s='Exempt of VAT according section 259B of the General Tax Code.' pdf='true'}
|
||||||
{else if (count($shipping_tax_breakdown) + count($product_tax_breakdown) == 0)}
|
{else if (count($shipping_tax_breakdown) + count($product_tax_breakdown) + count($ecotax_tax_breakdown) + count($wrapping_tax_breakdown) == 0)}
|
||||||
{l s='No tax' pdf='true'}
|
{l s='No tax' pdf='true'}
|
||||||
{else}
|
{else}
|
||||||
<table style="width: 70%" >
|
<table style="width: 70%" >
|
||||||
|
|||||||
Reference in New Issue
Block a user