diff --git a/classes/order/OrderInvoice.php b/classes/order/OrderInvoice.php index 7813dd294..d9fa8d74d 100644 --- a/classes/order/OrderInvoice.php +++ b/classes/order/OrderInvoice.php @@ -67,6 +67,9 @@ class OrderInvoiceCore extends ObjectModel /** @var float */ public $total_shipping_tax_incl; + /** @var int */ + public $shipping_tax_computation_method; + /** @var float */ public $total_wrapping_tax_excl; @@ -101,6 +104,7 @@ class OrderInvoiceCore extends ObjectModel 'total_products_wt' => array('type' => self::TYPE_FLOAT), 'total_shipping_tax_excl' =>array('type' => self::TYPE_FLOAT), 'total_shipping_tax_incl' =>array('type' => self::TYPE_FLOAT), + 'shipping_tax_computation_method' => array('type' => self::TYPE_INT), 'total_wrapping_tax_excl' =>array('type' => self::TYPE_FLOAT), 'total_wrapping_tax_incl' =>array('type' => self::TYPE_FLOAT), 'note' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'size' => 65000), @@ -255,7 +259,7 @@ class OrderInvoiceCore extends ObjectModel { // sum by taxes $taxes_infos = Db::getInstance()->executeS(' - SELECT odt.`id_order_detail`, t.`name`, t.`rate`, SUM(`total_amount`) AS `total_amount` + SELECT odt.`id_order_detail`, t.`rate` AS `name`, t.`rate`, SUM(`total_amount`) AS `total_amount` FROM `'._DB_PREFIX_.'order_detail_tax` odt 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`) @@ -268,9 +272,30 @@ class OrderInvoiceCore extends ObjectModel $tmp_tax_infos = array(); foreach ($taxes_infos as $tax_infos) { - $tmp_tax_infos[$tax_infos['rate']]['total_amount'] = $tax_infos['tax_amount']; + $tmp_tax_infos[$tax_infos['rate']]['total_amount'] = $tax_infos['total_amount']; $tmp_tax_infos[$tax_infos['rate']]['name'] = $tax_infos['name']; } + + $shipping_taxes = Db::getInstance()->executeS(' + SELECT * + FROM `'._DB_PREFIX_.'order_invoice_tax` od + LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = od.`id_tax`) + WHERE `id_order_invoice` = '.(int)$this->id + ); + + foreach ($shipping_taxes as $tax_infos) + { + if (!isset($tmp_tax_infos[$tax_infos['rate']])) + { + $tmp_tax_infos[$tax_infos['rate']]['total_amount'] = 0; + $tmp_tax_infos[$tax_infos['rate']]['name'] = 0; + } + + $tmp_tax_infos[$tax_infos['rate']]['total_amount'] += $tax_infos['amount']; + $tmp_tax_infos[$tax_infos['rate']]['name'] += $tax_infos['rate']; + } + + } else { @@ -305,8 +330,6 @@ class OrderInvoiceCore extends ObjectModel } } - - return $tmp_tax_infos; } @@ -320,6 +343,10 @@ class OrderInvoiceCore extends ObjectModel { $taxes_breakdown = array(); + // shipping cost are added in the product taxes breakdown + if ($this->useOneAfterAnotherTaxComputationMethod()) + return $taxes_breakdown; + $shipping_tax_amount = $this->total_shipping_tax_incl - $this->total_shipping_tax_excl; if ($shipping_tax_amount > 0) @@ -625,4 +652,18 @@ class OrderInvoiceCore extends ObjectModel { return '#'.Configuration::get('PS_INVOICE_PREFIX', $id_lang).sprintf('%06d', $this->number); } + + public function saveCarrierTaxCalculator(array $taxes_amount) + { + $is_correct = true; + foreach ($taxes_amount as $id_tax => $amount) + { + $sql = 'INSERT INTO `'._DB_PREFIX_.'order_invoice_tax` (`id_order_invoice`, `type`, `id_tax`, `amount`) + VALUES ('.(int)$this->id.', \'shipping\', '.(int)$id_tax.', '.(float)$amount.')'; + + $is_correct &= Db::getInstance()->execute($sql); + } + + return $is_correct; + } } \ No newline at end of file