1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: class Mage_Weee_Model_Total_Creditmemo_Weee extends Mage_Sales_Model_Order_Creditmemo_Total_Abstract
29: {
30: public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
31: {
32: $store = $creditmemo->getStore();
33:
34: $totalTax = 0;
35: $baseTotalTax = 0;
36:
37: foreach ($creditmemo->getAllItems() as $item) {
38: if ($item->getOrderItem()->isDummy()) {
39: continue;
40: }
41: $orderItemQty = $item->getOrderItem()->getQtyOrdered();
42:
43: $totalTax += $item->getWeeeTaxAppliedAmount()*$item->getQty();
44: $baseTotalTax += $item->getBaseWeeeTaxAppliedAmount()*$item->getQty();
45:
46: $newApplied = array();
47: $applied = Mage::helper('weee')->getApplied($item);
48: foreach ($applied as $one) {
49: $one['base_row_amount'] = $one['base_amount']*$item->getQty();
50: $one['row_amount'] = $one['amount']*$item->getQty();
51: $one['base_row_amount_incl_tax'] = $one['base_amount_incl_tax']*$item->getQty();
52: $one['row_amount_incl_tax'] = $one['amount_incl_tax']*$item->getQty();
53:
54: $newApplied[] = $one;
55: }
56: Mage::helper('weee')->setApplied($item, $newApplied);
57:
58: $item->setWeeeTaxRowDisposition($item->getWeeeTaxDisposition()*$item->getQty());
59: $item->setBaseWeeeTaxRowDisposition($item->getBaseWeeeTaxDisposition()*$item->getQty());
60: }
61:
62: if (Mage::helper('weee')->includeInSubtotal($store)) {
63: $creditmemo->setSubtotal($creditmemo->getSubtotal() + $totalTax);
64: $creditmemo->setBaseSubtotal($creditmemo->getBaseSubtotal() + $baseTotalTax);
65: } else {
66: $creditmemo->setTaxAmount($creditmemo->getTaxAmount() + $totalTax);
67: $creditmemo->setBaseTaxAmount($creditmemo->getBaseTaxAmount() + $baseTotalTax);
68: }
69:
70: $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $totalTax);
71: $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseTotalTax);
72:
73: return $this;
74: }
75: }
76: