00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 class Mage_Sales_Model_Order_Invoice_Total_Tax extends Mage_Sales_Model_Order_Invoice_Total_Abstract
00029 {
00030 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
00031 {
00032 $totalTax = 0;
00033 $baseTotalTax = 0;
00034
00035 foreach ($invoice->getAllItems() as $item) {
00036 $orderItem = $item->getOrderItem();
00037 $orderItemTax = $orderItem->getTaxAmount();
00038 $baseOrderItemTax = $orderItem->getBaseTaxAmount();
00039 $orderItemQty = $orderItem->getQtyOrdered();
00040
00041 if ($orderItemTax && $orderItemQty) {
00042 if ($item->getOrderItem()->isDummy()) {
00043 continue;
00044 }
00045
00046
00047
00048 if ($item->isLast()) {
00049 $tax = $orderItemTax - $orderItem->getTaxInvoiced();
00050 $baseTax = $baseOrderItemTax - $orderItem->getBaseTaxInvoiced();
00051 }
00052 else {
00053 $tax = $orderItemTax*$item->getQty()/$orderItemQty;
00054 $baseTax = $baseOrderItemTax*$item->getQty()/$orderItemQty;
00055
00056 $tax = $invoice->getStore()->roundPrice($tax);
00057 $baseTax = $invoice->getStore()->roundPrice($baseTax);
00058 }
00059
00060 $item->setTaxAmount($tax);
00061 $item->setBaseTaxAmount($baseTax);
00062
00063 $totalTax += $tax;
00064 $baseTotalTax += $baseTax;
00065 }
00066 }
00067
00068 $includeShippingTax = true;
00069
00070
00071
00072 foreach ($invoice->getOrder()->getInvoiceCollection() as $previusInvoice) {
00073 if ($previusInvoice->getShippingAmount() && !$previusInvoice->isCanceled()) {
00074 $includeShippingTax = false;
00075 }
00076 }
00077
00078 if ($includeShippingTax) {
00079 $totalTax += $invoice->getOrder()->getShippingTaxAmount();
00080 $baseTotalTax += $invoice->getOrder()->getBaseShippingTaxAmount();
00081 $invoice->setShippingTaxAmount($invoice->getOrder()->getShippingTaxAmount());
00082 $invoice->setBaseShippingTaxAmount($invoice->getOrder()->getBaseShippingTaxAmount());
00083 }
00084
00085
00086 $invoice->setTaxAmount($totalTax);
00087 $invoice->setBaseTaxAmount($baseTotalTax);
00088
00089 $invoice->setGrandTotal($invoice->getGrandTotal() + $totalTax);
00090 $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalTax);
00091
00092 return $this;
00093 }
00094 }