Public Member Functions | |
collect (Mage_Sales_Model_Order_Creditmemo $creditmemo) |
Definition at line 28 of file Tax.php.
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 }