From 1dda3c49ddd55c17b58e5daf8b298d03f875a5a6 Mon Sep 17 00:00:00 2001 From: fBrignoli Date: Mon, 9 Jul 2012 09:35:58 +0000 Subject: [PATCH] [-] PDF : Bug Fixed #PSCFV-2735 - Missing tax details in order slip --- classes/order/OrderInvoice.php | 3 +- classes/order/OrderSlip.php | 20 +++-- classes/pdf/HTMLTemplateOrderSlip.php | 102 +++++++++++++++++++++++++- pdf/invoice.tax-tab.tpl | 8 +- pdf/order-slip.tpl | 100 +++++++------------------ 5 files changed, 148 insertions(+), 85 deletions(-) diff --git a/classes/order/OrderInvoice.php b/classes/order/OrderInvoice.php index 5336d6da9..8304a6d56 100644 --- a/classes/order/OrderInvoice.php +++ b/classes/order/OrderInvoice.php @@ -321,7 +321,8 @@ class OrderInvoiceCore extends ObjectModel if ($shipping_tax_amount > 0) $taxes_breakdown[] = array( 'rate' => $order->carrier_tax_rate, - 'total_amount' => $shipping_tax_amount + 'total_amount' => $shipping_tax_amount, + 'total_tax_excl' => $this->total_shipping_tax_excl ); return $taxes_breakdown; diff --git a/classes/order/OrderSlip.php b/classes/order/OrderSlip.php index 2438b038e..cae5dca7c 100644 --- a/classes/order/OrderSlip.php +++ b/classes/order/OrderSlip.php @@ -78,14 +78,21 @@ class OrderSlipCore extends ObjectModel public function addSlipDetail($orderDetailList, $productQtyList) { - foreach ($orderDetailList as $key => $orderDetail) + foreach ($orderDetailList as $key => $id_order_detail) { if ($qty = (int)($productQtyList[$key])) - Db::getInstance()->insert('order_slip_detail', array( - 'id_order_slip' => (int)$this->id, - 'id_order_detail' => (int)$orderDetail, - 'product_quantity' => $qty, - )); + { + $order_detail = new OrderDetail((int)$id_order_detail); + + if (Validate::isLoadedObject($order_detail)) + Db::getInstance()->insert('order_slip_detail', array( + 'id_order_slip' => (int)$this->id, + 'id_order_detail' => (int)$id_order_detail, + 'product_quantity' => $qty, + 'amount_tax_excl' => $order_detail->unit_price_tax_excl * $qty, + 'amount_tax_incl' => $order_detail->unit_price_tax_incl * $qty + )); + } } } @@ -281,6 +288,5 @@ class OrderSlipCore extends ObjectModel Db::getInstance()->insert('order_slip_detail', $insertOrderSlip); } } - } diff --git a/classes/pdf/HTMLTemplateOrderSlip.php b/classes/pdf/HTMLTemplateOrderSlip.php index 1d4731664..08c33d409 100644 --- a/classes/pdf/HTMLTemplateOrderSlip.php +++ b/classes/pdf/HTMLTemplateOrderSlip.php @@ -82,6 +82,7 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice SELECT * FROM `'._DB_PREFIX_.'order_slip_detail` WHERE `id_order_slip` = '.(int)$this->order_slip->id.' AND `id_order_detail` = '.(int)$product['id_order_detail']); + $product['total_price_tax_excl'] = $order_slip_detail['amount_tax_excl']; $product['total_price_tax_incl'] = $order_slip_detail['amount_tax_incl']; } @@ -107,7 +108,7 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice 'delivery_address' => $formatted_delivery_address, 'invoice_address' => $formatted_invoice_address, 'tax_excluded_display' => Group::getPriceDisplayMethod((int)$customer->id_default_group), - 'tax_tab' => '', + 'tax_tab' => $this->getTaxTabContent(), )); return $this->smarty->fetch($this->getTemplate('order-slip')); @@ -130,5 +131,104 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice { return 'order-slip-'.sprintf('%06d', $this->order_slip->id).'.pdf'; } + + /** + * Returns the tax tab content + */ + public function getTaxTabContent() + { + $invoice_address = new Address((int)$this->order->id_address_invoice); + $tax_exempt = Configuration::get('VATNUMBER_MANAGEMENT') + && !empty($invoice_address->vat_number) + && $invoice_address->id_country != Configuration::get('VATNUMBER_COUNTRY'); + + $this->smarty->assign(array( + 'tax_exempt' => $tax_exempt, + 'use_one_after_another_method' => $this->order->useOneAfterAnotherTaxComputationMethod(), + 'product_tax_breakdown' => $this->getProductTaxesBreakdown(), + 'shipping_tax_breakdown' => $this->getShippingTaxesBreakdown(), + 'order' => $this->order, + )); + + return $this->smarty->fetch($this->getTemplate('invoice.tax-tab')); + } + + + public function getProductTaxesBreakdown() + { + $tmp_tax_infos = array(); + foreach ($this->order_slip->getOrdersSlipDetail((int)$this->order_slip->id) as $order_slip_details) + { + $tax_calculator = OrderDetail::getTaxCalculatorStatic((int)$order_slip_details['id_order_detail']); + $tax_amount = $tax_calculator->getTaxesAmount($order_slip_details['amount_tax_excl']); + + if ($this->order->useOneAfterAnotherTaxComputationMethod()) + { + foreach ($tax_amount as $tax_id => $amount) + { + $tax = new Tax((int)$tax_id); + + if (!isset($total_tax_amount[$tax->rate])) + { + $tmp_tax_infos[$tax->rate]['name'] = $tax->name; + $tmp_tax_infos[$tax->rate]['total_price_tax_excl'] = $order_slip_details['amount_tax_excl']; + $tmp_tax_infos[$tax->rate]['total_amount'] = $amount; + } + else + { + + $tmp_tax_infos[$tax->rate]['total_price_tax_excl'] += $order_slip_details['amount_tax_excl']; + $tmp_tax_infos[$tax->rate]['total_amount'] += $amount; + } + } + } else { + $infos = array( + 'total_price_tax_excl' => 0, + 'total_amount' => 0 + ); + + $tax_rate = 0; + + foreach ($tax_amount as $tax_id => $amount) + { + $tax = new Tax((int)$tax_id); + + $tax_rate += $tax->rate; + $infos['total_price_tax_excl'] += $order_slip_details['amount_tax_excl']; + $infos['total_amount'] += $amount; + } + + $tmp_tax_infos[$tax_rate] = $infos; + } + + } + + return $tmp_tax_infos; + } + + public function getShippingTaxesBreakdown() + { + $taxes_breakdown = array(); + $tax = new Tax(); + $tax->rate = $this->order->carrier_tax_rate; + + $tax_calculator = new TaxCalculator(array($tax)); + + $total_tax_excl = $tax_calculator->removeTaxes($this->order_slip->shipping_cost_amount); + $shipping_tax_amount = $this->order_slip->shipping_cost_amount - $total_tax_excl; + + if ($shipping_tax_amount > 0) + $taxes_breakdown[] = array( + 'rate' => $this->order->carrier_tax_rate, + 'total_amount' => $shipping_tax_amount, + 'total_tax_excl' => $total_tax_excl, + ); + + return $taxes_breakdown; + + + return array(); + } } + diff --git a/pdf/invoice.tax-tab.tpl b/pdf/invoice.tax-tab.tpl index 10bec1a8e..a808fc80d 100755 --- a/pdf/invoice.tax-tab.tpl +++ b/pdf/invoice.tax-tab.tpl @@ -41,6 +41,7 @@ {l s='Total Tax' pdf='true'} + {if isset($product_tax_breakdown)} {foreach $product_tax_breakdown as $rate => $product_tax_infos} {l s='Products' pdf='true'} @@ -53,16 +54,20 @@ {displayPrice currency=$order->id_currency price=$product_tax_infos.total_amount} {/foreach} + {/if} + {if isset($shipping_tax_breakdown)} {foreach $shipping_tax_breakdown as $shipping_tax_infos} {l s='Shipping' pdf='true'} {$shipping_tax_infos.rate} % - {displayPrice currency=$order->id_currency price=$order_invoice->total_shipping_tax_excl} + {displayPrice currency=$order->id_currency price=$shipping_tax_infos.total_tax_excl} {displayPrice currency=$order->id_currency price=$shipping_tax_infos.total_amount} {/foreach} + {/if} + {if isset($ecotax_tax_breakdown)} {foreach $ecotax_tax_breakdown as $ecotax_tax_infos} {if $ecotax_tax_infos.ecotax_tax_excl > 0} @@ -73,6 +78,7 @@ {/if} {/foreach} + {/if} {/if} diff --git a/pdf/order-slip.tpl b/pdf/order-slip.tpl index 391713b51..7f770d37d 100755 --- a/pdf/order-slip.tpl +++ b/pdf/order-slip.tpl @@ -86,49 +86,25 @@ - + - {if !$tax_excluded_display} - - {/if} - - - + + {foreach $order_details as $order_detail} {cycle values='#FFF,#DDD' assign=bgcolor} - - - {if !$tax_excluded_display} - - {/if} - - + + - + + {foreach $order_detail.customizedDatas as $customization} @@ -155,66 +131,40 @@
{l s='Product / Reference' pdf='true'}{l s='Product / Reference' pdf='true'} {l s='Unit Price' pdf='true'}
{l s='(Tax Excl.)' pdf='true'}
{l s='Unit Price' pdf='true'}{l s='Discount' pdf='true'} {l s='Qty' pdf='true'}{if $order_slip->partial eq '1'}{l s='Partial refund' pdf='true'}{else}{l s='Total' pdf='true'}{/if}{l s='Price' pdf='true'}
{l s='(Tax Excl.)' pdf='true'}
{l s='Price' pdf='true'}
{l s='(Tax Incl.)' pdf='true'}
{$order_detail.product_name} - {displayPrice currency=$order->id_currency price=$order_detail.unit_price_tax_excl} - - {if $tax_excluded_display} - {displayPrice currency=$order->id_currency price=$order_detail.unit_price_tax_excl} - {else} - {displayPrice currency=$order->id_currency price=$order_detail.unit_price_tax_incl} - {/if} - - {if (isset($order_detail.reduction_amount) && $order_detail.reduction_amount > 0)} - -{displayPrice currency=$order->id_currency price=$order_detail.reduction_amount} - {else if (isset($order_detail.reduction_percent) && $order_detail.reduction_percent > 0)} - -{$order_detail.reduction_percent}% - {else} - -- - {/if} - {$order_detail.product_name}{$order_detail.product_quantity} - {if $tax_excluded_display} - {displayPrice currency=$order->id_currency price=$order_detail.total_price_tax_excl} - {else} - {displayPrice currency=$order->id_currency price=$order_detail.total_price_tax_incl} - {/if} + + + - {displayPrice currency=$order->id_currency price=$order_detail.total_price_tax_excl} + + - {displayPrice currency=$order->id_currency price=$order_detail.total_price_tax_incl}
+ {if $order_slip->shipping_cost_amount} + + + + + {/if} + {if (($order->total_paid_tax_incl - $order->total_paid_tax_excl) > 0)} - + - + {else} - - - {/if} - - {if $order->total_discounts_tax_incl > 0} - - - - - {/if} - - {if $order->total_wrapping_tax_incl > 0} - - - - - {/if} - - {if $order->total_shipping_tax_incl > 0} - - - + {/if} {if ($order->total_paid_tax_incl - $order->total_paid_tax_excl) > 0} - + {/if} - - + +
{l s='Shipping' pdf='true'}- {displayPrice currency=$order->id_currency price=$order_slip->shipping_cost_amount}
{l s='Product Total (Tax Excl.)' pdf='true'}{displayPrice currency=$order->id_currency price=$order->total_products}- {displayPrice currency=$order->id_currency price=$order->total_products}
{l s='Product Total (Tax Incl.)' pdf='true'}{displayPrice currency=$order->id_currency price=$order->total_products_wt}- {displayPrice currency=$order->id_currency price=$order->total_products_wt}
{l s='Product Total' pdf='true'}{displayPrice currency=$order->id_currency price=$order->total_products}
{l s='Total Vouchers' pdf='true'}-{displayPrice currency=$order->id_currency price=$order->total_discounts_tax_incl}
{l s='Wrapping Cost' pdf='true'} - {if $tax_excluded_display} - {displayPrice currency=$order->id_currency price=$order->total_wrapping_tax_excl} - {else} - {displayPrice currency=$order->id_currency price=$order->total_wrapping_tax_incl} - {/if} -
{l s='Shipping Cost' pdf='true'} - {if $tax_excluded_display} - {displayPrice currency=$order->id_currency price=$order->total_shipping_tax_excl} - {else} - {displayPrice currency=$order->id_currency price=$order->total_shipping_tax_incl} - {/if} - - {displayPrice currency=$order->id_currency price=$order->total_products}
{l s='Total Tax' pdf='true'}{displayPrice currency=$order->id_currency price=($order->total_paid_tax_incl - $order->total_paid_tax_excl)}- {displayPrice currency=$order->id_currency price=($order->total_paid_tax_incl - $order->total_paid_tax_excl)}
{l s='Total' pdf='true'}{displayPrice currency=$order->id_currency price=$order->total_paid_tax_incl}{l s='Total ' pdf='true'}- {displayPrice currency=$order->id_currency price=$order->total_paid_tax_incl}