Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Weee_Block_Element_Weee_Tax
  • Mage_Weee_Helper_Data
  • Mage_Weee_Model_Attribute_Backend_Weee_Tax
  • Mage_Weee_Model_Config_Source_Display
  • Mage_Weee_Model_Mysql4_Attribute_Backend_Weee_Tax
  • Mage_Weee_Model_Mysql4_Setup
  • Mage_Weee_Model_Mysql4_Tax
  • Mage_Weee_Model_Observer
  • Mage_Weee_Model_Resource_Attribute_Backend_Weee_Tax
  • Mage_Weee_Model_Resource_Setup
  • Mage_Weee_Model_Resource_Tax
  • Mage_Weee_Model_Tax
  • Mage_Weee_Model_Total_Creditmemo_Weee
  • Mage_Weee_Model_Total_Invoice_Weee
  • Mage_Weee_Model_Total_Quote_Nominal_Weee
  • Mage_Weee_Model_Total_Quote_Weee
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Weee
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: class Mage_Weee_Model_Total_Invoice_Weee extends Mage_Sales_Model_Order_Invoice_Total_Abstract
 29: {
 30:     /**
 31:      * Weee tax collector
 32:      *
 33:      * @param Mage_Sales_Model_Order_Invoice $invoice
 34:      * @return Mage_Weee_Model_Total_Invoice_Weee
 35:      */
 36:     public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 37:     {
 38:         $store = $invoice->getStore();
 39: 
 40:         $totalTax = 0;
 41:         $baseTotalTax = 0;
 42: 
 43:         foreach ($invoice->getAllItems() as $item) {
 44:             $orderItem = $item->getOrderItem();
 45:             $orderItemQty = $orderItem->getQtyOrdered();
 46: 
 47:             if (!$orderItemQty || $orderItem->isDummy()) {
 48:                 continue;
 49:             }
 50: 
 51:             $weeeTaxAmount = $item->getWeeeTaxAppliedAmount() * $item->getQty();
 52:             $baseWeeeTaxAmount = $item->getBaseWeeeTaxAppliedAmount() * $item->getQty();
 53: 
 54:             $item->setWeeeTaxAppliedRowAmount($weeeTaxAmount);
 55:             $item->setBaseWeeeTaxAppliedRowAmount($baseWeeeTaxAmount);
 56:             $newApplied = array();
 57:             $applied = Mage::helper('weee')->getApplied($item);
 58:             foreach ($applied as $one) {
 59:                 $one['base_row_amount'] = $one['base_amount'] * $item->getQty();
 60:                 $one['row_amount'] = $one['amount'] * $item->getQty();
 61:                 $one['base_row_amount_incl_tax'] = $one['base_amount_incl_tax'] * $item->getQty();
 62:                 $one['row_amount_incl_tax'] = $one['amount_incl_tax'] * $item->getQty();
 63: 
 64:                 $newApplied[] = $one;
 65:             }
 66:             Mage::helper('weee')->setApplied($item, $newApplied);
 67: 
 68:             $item->setWeeeTaxRowDisposition($item->getWeeeTaxDisposition() * $item->getQty());
 69:             $item->setBaseWeeeTaxRowDisposition($item->getBaseWeeeTaxDisposition() * $item->getQty());
 70: 
 71:             $totalTax += $weeeTaxAmount;
 72:             $baseTotalTax += $baseWeeeTaxAmount;
 73:         }
 74: 
 75:         /*
 76:          * Add FPT to totals
 77:          * Notice that we check restriction on allowed tax, because
 78:          * a) for last invoice we don't need to collect FPT - it is automatically collected by subtotal/tax collector,
 79:          * that adds whole remaining (not invoiced) subtotal/tax value, so fpt is automatically included into it
 80:          * b) FPT tax is included into order subtotal/tax value, so after multiple invoices with partial item quantities
 81:          * it can happen that other collector will take some FPT value from shared subtotal/tax order value
 82:          */
 83:         $order = $invoice->getOrder();
 84:         if (Mage::helper('weee')->includeInSubtotal($store)) {
 85:             $allowedSubtotal = $order->getSubtotal() - $order->getSubtotalInvoiced() - $invoice->getSubtotal();
 86:             $allowedBaseSubtotal = $order->getBaseSubtotal() - $order->getBaseSubtotalInvoiced()
 87:                 - $invoice->getBaseSubtotal();
 88:             $totalTax = min($allowedSubtotal, $totalTax);
 89:             $baseTotalTax = min($allowedBaseSubtotal, $baseTotalTax);
 90: 
 91:             $invoice->setSubtotal($invoice->getSubtotal() + $totalTax);
 92:             $invoice->setBaseSubtotal($invoice->getBaseSubtotal() + $baseTotalTax);
 93:         } else {
 94:             $allowedTax = $order->getTaxAmount() - $order->getTaxInvoiced() - $invoice->getTaxAmount();
 95:             $allowedBaseTax = $order->getBaseTaxAmount() - $order->getBaseTaxInvoiced() - $invoice->getBaseTaxAmount();
 96:             $totalTax = min($allowedTax, $totalTax);
 97:             $baseTotalTax = min($allowedBaseTax, $baseTotalTax);
 98: 
 99:             $invoice->setTaxAmount($invoice->getTaxAmount() + $totalTax);
100:             $invoice->setBaseTaxAmount($invoice->getBaseTaxAmount() + $baseTotalTax);
101:         }
102: 
103:         $invoice->setGrandTotal($invoice->getGrandTotal() + $totalTax);
104:         $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalTax);
105: 
106:         return $this;
107:     }
108: }
109: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0