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_Weee_Model_Total_Invoice_Weee extends Mage_Sales_Model_Order_Invoice_Total_Abstract
00029 {
00030 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
00031 {
00032 $store = $invoice->getStore();
00033
00034 $totalTax = 0;
00035 $baseTotalTax = 0;
00036
00037 foreach ($invoice->getAllItems() as $item) {
00038 $orderItem = $item->getOrderItem();
00039 $orderItemQty = $orderItem->getQtyOrdered();
00040
00041 if ($orderItemQty) {
00042 if ($orderItem->isDummy()) {
00043 continue;
00044 }
00045
00046 $weeeTaxAmount = $item->getWeeeTaxAppliedAmount()*$item->getQty();
00047 $baseWeeeTaxAmount = $item->getBaseWeeeTaxAppliedAmount()*$item->getQty();
00048
00049 $item->setWeeeTaxAppliedRowAmount($weeeTaxAmount);
00050 $item->setBaseWeeeTaxAppliedRowAmount($baseWeeeTaxAmount);
00051 $newApplied = array();
00052 $applied = Mage::helper('weee')->getApplied($item);
00053 foreach ($applied as $one) {
00054 $one['base_row_amount'] = $one['base_amount']*$item->getQty();
00055 $one['row_amount'] = $one['amount']*$item->getQty();
00056 $one['base_row_amount_incl_tax'] = $one['base_amount_incl_tax']*$item->getQty();
00057 $one['row_amount_incl_tax'] = $one['amount_incl_tax']*$item->getQty();
00058
00059 $newApplied[] = $one;
00060 }
00061 Mage::helper('weee')->setApplied($item, $newApplied);
00062
00063 $item->setWeeeTaxRowDisposition($item->getWeeeTaxDisposition()*$item->getQty());
00064 $item->setBaseWeeeTaxRowDisposition($item->getBaseWeeeTaxDisposition()*$item->getQty());
00065
00066 $totalTax += $weeeTaxAmount;
00067 $baseTotalTax += $baseWeeeTaxAmount;
00068 }
00069 }
00070 if (Mage::helper('weee')->includeInSubtotal($store)) {
00071 $invoice->setSubtotal($invoice->getSubtotal() + $totalTax);
00072 $invoice->setBaseSubtotal($invoice->getBaseSubtotal() + $baseTotalTax);
00073 } else {
00074 $invoice->setTaxAmount($invoice->getTaxAmount() + $totalTax);
00075 $invoice->setBaseTaxAmount($invoice->getBaseTaxAmount() + $baseTotalTax);
00076 }
00077
00078 $invoice->setGrandTotal($invoice->getGrandTotal() + $totalTax);
00079 $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalTax);
00080
00081 return $this;
00082 }
00083 }