Mage_Sales_Model_Order_Creditmemo_Total_Tax Class Reference

Inheritance diagram for Mage_Sales_Model_Order_Creditmemo_Total_Tax:

Mage_Sales_Model_Order_Creditmemo_Total_Abstract

List of all members.

Public Member Functions

 collect (Mage_Sales_Model_Order_Creditmemo $creditmemo)


Detailed Description

Definition at line 28 of file Tax.php.


Member Function Documentation

collect ( Mage_Sales_Model_Order_Creditmemo creditmemo  ) 

Reimplemented from Mage_Sales_Model_Order_Creditmemo_Total_Abstract.

Definition at line 30 of file Tax.php.

00031     {
00032         $shippingTaxAmount     = 0;
00033         $baseShippingTaxAmount = 0;
00034         $totalTax              = 0;
00035         $baseTotalTax          = 0;
00036 
00037         foreach ($creditmemo->getAllItems() as $item) {
00038             if ($item->getOrderItem()->isDummy()) {
00039                 continue;
00040             }
00041             $orderItemTax     = $item->getOrderItem()->getTaxAmount();
00042             $baseOrderItemTax = $item->getOrderItem()->getBaseTaxAmount();
00043             $orderItemQty = $item->getOrderItem()->getQtyOrdered();
00044 
00045             if ($orderItemTax && $orderItemQty) {
00046                 $tax = $orderItemTax*$item->getQty()/$orderItemQty;
00047                 $baseTax = $baseOrderItemTax*$item->getQty()/$orderItemQty;
00048 
00049                 $tax = $creditmemo->getStore()->roundPrice($tax);
00050                 $baseTax = $creditmemo->getStore()->roundPrice($baseTax);
00051 
00052                 $item->setTaxAmount($tax);
00053                 $item->setBaseTaxAmount($baseTax);
00054 
00055                 $totalTax += $tax;
00056                 $baseTotalTax += $baseTax;
00057             }
00058         }
00059 
00060         if ($invoice = $creditmemo->getInvoice()) {
00061             $totalTax += $invoice->getShippingTaxAmount();
00062             $baseTotalTax += $invoice->getBaseShippingTaxAmount();
00063 
00064             $creditmemo->setShippingTaxAmount($invoice->getShippingTaxAmount());
00065             $creditmemo->setBaseShippingTaxAmount($invoice->getBaseShippingTaxAmount());
00066         } else {
00067             $shippingAmount = $creditmemo->getOrder()->getBaseShippingAmount();
00068             $shippingRefundedAmount = $creditmemo->getOrder()->getBaseShippingRefunded();
00069 
00070             $shippingTaxAmount = 0;
00071             $baseShippingTaxAmount = 0;
00072 
00073             if (($shippingAmount - $shippingRefundedAmount) > $creditmemo->getShippingAmount()) {
00074                 $shippingTaxAmount = $creditmemo->getShippingAmount()*($creditmemo->getOrder()->getShippingTaxAmount()/$shippingAmount);
00075                 $baseShippingTaxAmount = $creditmemo->getBaseShippingAmount()*($creditmemo->getOrder()->getBaseShippingTaxAmount()/$shippingAmount);
00076                 $shippingTaxAmount = $creditmemo->getStore()->roundPrice($shippingTaxAmount);
00077                 $baseShippingTaxAmount = $creditmemo->getStore()->roundPrice($baseShippingTaxAmount);
00078             } elseif (($shippingAmount - $shippingRefundedAmount) == $creditmemo->getShippingAmount()) {
00079                 $shippingTaxAmount = $creditmemo->getOrder()->getShippingTaxAmount() - $creditmemo->getOrder()->getShippingTaxRefunded();
00080                 $baseShippingTaxAmount = $creditmemo->getOrder()->getBaseShippingTaxAmount() - $creditmemo->getOrder()->getBaseShippingTaxRefunded();
00081             }
00082             $totalTax += $shippingTaxAmount;
00083             $baseTotalTax += $baseShippingTaxAmount;
00084         }
00085 
00086         $tmpBaseTotalTax   = $baseTotalTax - ($creditmemo->getOrder()->getBaseTaxRefunded() - $creditmemo->getOrder()->getBaseShippingTaxRefunded());
00087 
00088         if ($tmpBaseTotalTax<0) {
00089             $baseTotalTax = 0;
00090             $totalTax = 0;
00091         }
00092 
00093         $creditmemo->setTaxAmount($totalTax);
00094         $creditmemo->setBaseTaxAmount($baseTotalTax);
00095 
00096         $creditmemo->setShippingTaxAmount($shippingTaxAmount);
00097         $creditmemo->setBaseShippingTaxAmount($baseShippingTaxAmount);
00098 
00099         $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $totalTax);
00100         $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseTotalTax);
00101         return $this;
00102     }


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

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