Skip to content

Commit

Permalink
[-] BO : FixBug #PSCSX-3570 - Fix wrong tax calculation with free shi…
Browse files Browse the repository at this point in the history
…pping
  • Loading branch information
jnadaud committed Oct 21, 2014
1 parent 7e99cb1 commit a462165
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 26 deletions.
18 changes: 17 additions & 1 deletion classes/order/OrderInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public function useOneAfterAnotherTaxComputationMethod()
* @since 1.5
* @return array
*/
public function getProductTaxesBreakdown()
public function getProductTaxesBreakdown($order = null)
{
$tmp_tax_infos = array();
if ($this->useOneAfterAnotherTaxComputationMethod())
Expand Down Expand Up @@ -333,6 +333,22 @@ public function getProductTaxesBreakdown()
foreach ($tmp_tax_infos as &$tax)
$tax['total_amount'] = Tools::ps_round($tax['total_amount'], _PS_PRICE_DISPLAY_PRECISION_);

// Add shipping tax amount to tax infos if we have a free shipping cart rule
foreach ($order->getCartRules() as $cart_rule)
if ($cart_rule['free_shipping'])
{
$shipping_tax_amount = $this->total_shipping_tax_incl - $this->total_shipping_tax_excl;

if ($shipping_tax_amount > 0)
{
$tmp_tax_infos[$tax_infos['rate']]['total_amount'] += $shipping_tax_amount;
$tmp_tax_infos[$tax_infos['rate']]['name'] = $tax_infos['name'];
$tmp_tax_infos[$tax_infos['rate']]['total_price_tax_excl'] += $this->total_shipping_tax_excl;
}

break;
}

return $tmp_tax_infos;
}

Expand Down
4 changes: 2 additions & 2 deletions classes/pdf/HTMLTemplateInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ public function getTaxTabContent()
&& !empty($address->vat_number)
&& $address->id_country != Configuration::get('VATNUMBER_COUNTRY');
$carrier = new Carrier($this->order->id_carrier);

$data = array(
'tax_exempt' => $tax_exempt,
'use_one_after_another_method' => $this->order_invoice->useOneAfterAnotherTaxComputationMethod(),
'product_tax_breakdown' => $this->order_invoice->getProductTaxesBreakdown(),
'product_tax_breakdown' => $this->order_invoice->getProductTaxesBreakdown($this->order),
'shipping_tax_breakdown' => $this->order_invoice->getShippingTaxesBreakdown($this->order),
'ecotax_tax_breakdown' => $this->order_invoice->getEcoTaxTaxesBreakdown(),
'wrapping_tax_breakdown' => $this->order_invoice->getWrappingTaxesBreakdown(),
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminPdfController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function initProcess()
else
$this->errors[] = Tools::displayError('You do not have permission to view this.');
}

public function checkCacheFolder()
{
if (!is_dir(_PS_CACHE_DIR_.'tcpdf/'))
Expand Down
6 changes: 3 additions & 3 deletions pdf/invoice.tax-tab.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
<td style="width: 20%; text-align: right;">{if isset($is_order_slip) && $is_order_slip}- {/if}{displayPrice currency=$order->id_currency price=$product_tax_infos.total_amount}</td>
</tr>
{/foreach}
{/if}
{/if}

{if isset($shipping_tax_breakdown)}
{if isset($shipping_tax_breakdown)}
{foreach $shipping_tax_breakdown as $shipping_tax_infos}
<tr style="line-height:6px;background-color:{cycle values='#FFF,#DDD'};">
<td style="width: 30%">
Expand Down Expand Up @@ -100,4 +100,4 @@
</tr>
</table>
<!-- / TAX DETAILS -->
{/if}
{/if}
36 changes: 17 additions & 19 deletions pdf/invoice.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<b>{l s='Carrier:' pdf='true'}</b><br />
{$carrier->name}<br />
<br />
{/if}
{/if}
<!-- / CUSTOMER INFORMATION -->
</td>
<td style="width: 83%; text-align: right">
Expand Down Expand Up @@ -230,36 +230,34 @@
</tr>
{/if}

{if $order_invoice->total_discount_tax_incl > 0}
{if $order_invoice->total_wrapping_tax_incl > 0}
<tr style="line-height:5px;">
<td style="text-align: right; font-weight: bold">{l s='Total Vouchers' pdf='true'}</td>
<td style="width: 17%; text-align: right;">-{displayPrice currency=$order->id_currency price=($order_invoice->total_discount_tax_incl)}</td>
{if $tax_excluded_display}
<td style="text-align: right; font-weight: bold">{l s='Wrapping Cost (Tax Excl.)' pdf='true'}</td>
<td style="width: 17%; text-align: right;">{displayPrice currency=$order->id_currency price=$order_invoice->total_wrapping_tax_excl}</td>
{else}
<td style="text-align: right; font-weight: bold">{l s='Wrapping Cost (Tax Incl.)' pdf='true'}</td>
<td style="width: 17%; text-align: right;">{displayPrice currency=$order->id_currency price=$order_invoice->total_wrapping_tax_incl}</td>
{/if}
</tr>
{/if}

{if $order_invoice->total_wrapping_tax_incl > 0}
{if $order_invoice->total_shipping_tax_incl > 0}
<tr style="line-height:5px;">
<td style="text-align: right; font-weight: bold">{l s='Wrapping Cost' pdf='true'}</td>
<td style="width: 17%; text-align: right;">
{if $tax_excluded_display}
{displayPrice currency=$order->id_currency price=$order_invoice->total_wrapping_tax_excl}
<td style="text-align: right; font-weight: bold">{l s='Shipping Cost (Tax Excl.)' pdf='true'}</td>
<td style="width: 17%; text-align: right;">{displayPrice currency=$order->id_currency price=$order_invoice->total_shipping_tax_excl}</td>
{else}
{displayPrice currency=$order->id_currency price=$order_invoice->total_wrapping_tax_incl}
<td style="text-align: right; font-weight: bold">{l s='Shipping Cost (Tax Incl.)' pdf='true'}</td>
<td style="width: 17%; text-align: right;">{displayPrice currency=$order->id_currency price=$order_invoice->total_shipping_tax_incl}</td>
{/if}
</td>
</tr>
{/if}

{if $order_invoice->total_shipping_tax_incl > 0}
{if $order_invoice->total_discount_tax_incl > 0}
<tr style="line-height:5px;">
<td style="text-align: right; font-weight: bold">{l s='Shipping Cost' pdf='true'}</td>
<td style="width: 17%; text-align: right;">
{if $tax_excluded_display}
{displayPrice currency=$order->id_currency price=$order_invoice->total_shipping_tax_excl}
{else}
{displayPrice currency=$order->id_currency price=$order_invoice->total_shipping_tax_incl}
{/if}
</td>
<td style="text-align: right; font-weight: bold">{l s='Total Vouchers (Tax Incl.)' pdf='true'}</td>
<td style="width: 17%; text-align: right;">-{displayPrice currency=$order->id_currency price=($order_invoice->total_discount_tax_incl)}</td>
</tr>
{/if}

Expand Down

0 comments on commit a462165

Please sign in to comment.