Mage_Sales_Model_Order_Invoice_Total_Tax Class Reference

Inheritance diagram for Mage_Sales_Model_Order_Invoice_Total_Tax:

Mage_Sales_Model_Order_Invoice_Total_Abstract

List of all members.

Public Member Functions

 collect (Mage_Sales_Model_Order_Invoice $invoice)


Detailed Description

Definition at line 28 of file Tax.php.


Member Function Documentation

collect ( Mage_Sales_Model_Order_Invoice invoice  ) 

Resolve rounding problems

Check shipping amount in previus invoices

Reimplemented from Mage_Sales_Model_Order_Invoice_Total_Abstract.

Definition at line 30 of file Tax.php.

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                  * Resolve rounding problems
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          * Check shipping amount in previus invoices
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     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:47 2009 for Magento by  doxygen 1.5.8