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_Tax_Block_Adminhtml_Frontend_Region_Updater
  • Mage_Tax_Block_Checkout_Discount
  • Mage_Tax_Block_Checkout_Grandtotal
  • Mage_Tax_Block_Checkout_Shipping
  • Mage_Tax_Block_Checkout_Subtotal
  • Mage_Tax_Block_Checkout_Tax
  • Mage_Tax_Block_Sales_Order_Tax
  • Mage_Tax_Helper_Data
  • Mage_Tax_Model_Calculation
  • Mage_Tax_Model_Calculation_Rate
  • Mage_Tax_Model_Calculation_Rate_Title
  • Mage_Tax_Model_Calculation_Rule
  • Mage_Tax_Model_Class
  • Mage_Tax_Model_Class_Source_Customer
  • Mage_Tax_Model_Class_Source_Product
  • Mage_Tax_Model_Config
  • Mage_Tax_Model_Config_Price_Include
  • Mage_Tax_Model_Mysql4_Calculation
  • Mage_Tax_Model_Mysql4_Calculation_Collection
  • Mage_Tax_Model_Mysql4_Calculation_Rate
  • Mage_Tax_Model_Mysql4_Calculation_Rate_Collection
  • Mage_Tax_Model_Mysql4_Calculation_Rate_Title
  • Mage_Tax_Model_Mysql4_Calculation_Rate_Title_Collection
  • Mage_Tax_Model_Mysql4_Calculation_Rule
  • Mage_Tax_Model_Mysql4_Calculation_Rule_Collection
  • Mage_Tax_Model_Mysql4_Class
  • Mage_Tax_Model_Mysql4_Class_Collection
  • Mage_Tax_Model_Mysql4_Report_Collection
  • Mage_Tax_Model_Mysql4_Report_Tax
  • Mage_Tax_Model_Mysql4_Report_Updatedat_Collection
  • Mage_Tax_Model_Mysql4_Sales_Order_Tax
  • Mage_Tax_Model_Mysql4_Sales_Order_Tax_Collection
  • Mage_Tax_Model_Mysql4_Setup
  • Mage_Tax_Model_Observer
  • Mage_Tax_Model_Resource_Calculation
  • Mage_Tax_Model_Resource_Calculation_Collection
  • Mage_Tax_Model_Resource_Calculation_Rate
  • Mage_Tax_Model_Resource_Calculation_Rate_Collection
  • Mage_Tax_Model_Resource_Calculation_Rate_Title
  • Mage_Tax_Model_Resource_Calculation_Rate_Title_Collection
  • Mage_Tax_Model_Resource_Calculation_Rule
  • Mage_Tax_Model_Resource_Calculation_Rule_Collection
  • Mage_Tax_Model_Resource_Class
  • Mage_Tax_Model_Resource_Class_Collection
  • Mage_Tax_Model_Resource_Report_Collection
  • Mage_Tax_Model_Resource_Report_Tax
  • Mage_Tax_Model_Resource_Report_Tax_Createdat
  • Mage_Tax_Model_Resource_Report_Tax_Updatedat
  • Mage_Tax_Model_Resource_Report_Updatedat_Collection
  • Mage_Tax_Model_Resource_Sales_Order_Tax
  • Mage_Tax_Model_Resource_Sales_Order_Tax_Collection
  • Mage_Tax_Model_Resource_Sales_Order_Tax_Item
  • Mage_Tax_Model_Resource_Sales_Order_Tax_Item_Collection
  • Mage_Tax_Model_Resource_Setup
  • Mage_Tax_Model_Sales_Order_Tax
  • Mage_Tax_Model_Sales_Order_Tax_Item
  • Mage_Tax_Model_Sales_Pdf_Grandtotal
  • Mage_Tax_Model_Sales_Pdf_Shipping
  • Mage_Tax_Model_Sales_Pdf_Subtotal
  • Mage_Tax_Model_Sales_Pdf_Tax
  • Mage_Tax_Model_Sales_Total_Quote_Discount
  • Mage_Tax_Model_Sales_Total_Quote_Nominal_Subtotal
  • Mage_Tax_Model_Sales_Total_Quote_Nominal_Tax
  • Mage_Tax_Model_Sales_Total_Quote_Shipping
  • Mage_Tax_Model_Sales_Total_Quote_Subtotal
  • Mage_Tax_Model_Sales_Total_Quote_Tax
  • Mage_Tax_Model_System_Config_Source_Algorithm
  • Mage_Tax_Model_System_Config_Source_Apply
  • Mage_Tax_Model_System_Config_Source_PriceType
  • Mage_Tax_Model_System_Config_Source_Tax_Country
  • Mage_Tax_Model_System_Config_Source_Tax_Display_Type
  • Mage_Tax_Model_System_Config_Source_Tax_Region

Exceptions

  • Mage_Tax_Exception
  • 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_Tax
 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: /**
 29:  * Tax report resource model with aggregation by created at
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Tax
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Tax_Model_Resource_Report_Tax_Createdat extends Mage_Reports_Model_Resource_Report_Abstract
 36: {
 37:     /**
 38:      * Resource initialization
 39:      */
 40:     protected function _construct()
 41:     {
 42:         $this->_init('tax/tax_order_aggregated_created', 'id');
 43:     }
 44: 
 45:     /**
 46:      * Aggregate Tax data by order created at
 47:      *
 48:      * @param mixed $from
 49:      * @param mixed $to
 50:      * @return Mage_Tax_Model_Resource_Report_Tax_Createdat
 51:      */
 52:     public function aggregate($from = null, $to = null)
 53:     {
 54:         return $this->_aggregateByOrder('created_at', $from, $to);
 55:     }
 56: 
 57:     /**
 58:      * Aggregate Tax data by orders
 59:      *
 60:      * @throws Exception
 61:      * @param string $aggregationField
 62:      * @param mixed $from
 63:      * @param mixed $to
 64:      * @return Mage_Tax_Model_Resource_Report_Tax_Createdat
 65:      */
 66:     protected function _aggregateByOrder($aggregationField, $from, $to)
 67:     {
 68:         // convert input dates to UTC to be comparable with DATETIME fields in DB
 69:         $from = $this->_dateToUtc($from);
 70:         $to = $this->_dateToUtc($to);
 71: 
 72:         $this->_checkDates($from, $to);
 73:         $writeAdapter = $this->_getWriteAdapter();
 74:         $writeAdapter->beginTransaction();
 75: 
 76:         try {
 77:             if ($from !== null || $to !== null) {
 78:                 $subSelect = $this->_getTableDateRangeSelect(
 79:                     $this->getTable('sales/order'),
 80:                     'created_at', 'updated_at', $from, $to
 81:                 );
 82:             } else {
 83:                 $subSelect = null;
 84:             }
 85: 
 86:             $this->_clearTableByDateRange($this->getMainTable(), $from, $to, $subSelect);
 87:             // convert dates from UTC to current admin timezone
 88:             $periodExpr = $writeAdapter->getDatePartSql(
 89:                 $this->getStoreTZOffsetQuery(
 90:                     array('e' => $this->getTable('sales/order')),
 91:                     'e.' . $aggregationField,
 92:                     $from, $to
 93:                 )
 94:             );
 95: 
 96:             $columns = array(
 97:                 'period'                => $periodExpr,
 98:                 'store_id'              => 'e.store_id',
 99:                 'code'                  => 'tax.code',
100:                 'order_status'          => 'e.status',
101:                 'percent'               => 'MAX(tax.' . $writeAdapter->quoteIdentifier('percent') .')',
102:                 'orders_count'          => 'COUNT(DISTINCT e.entity_id)',
103:                 'tax_base_amount_sum'   => 'SUM(tax.base_amount * e.base_to_global_rate)'
104:             );
105: 
106:             $select = $writeAdapter->select();
107:             $select->from(array('tax' => $this->getTable('tax/sales_order_tax')), $columns)
108:                 ->joinInner(array('e' => $this->getTable('sales/order')), 'e.entity_id = tax.order_id', array())
109:                 ->useStraightJoin();
110: 
111:             $select->where('e.state NOT IN (?)', array(
112:                 Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
113:                 Mage_Sales_Model_Order::STATE_NEW
114:             ));
115: 
116:             if ($subSelect !== null) {
117:                 $select->having($this->_makeConditionFromDateRangeSelect($subSelect, 'period'));
118:             }
119: 
120:             $select->group(array($periodExpr, 'e.store_id', 'code', 'tax.percent', 'e.status'));
121: 
122:             $insertQuery = $writeAdapter->insertFromSelect($select, $this->getMainTable(), array_keys($columns));
123:             $writeAdapter->query($insertQuery);
124: 
125:             $select->reset();
126: 
127:             $columns = array(
128:                 'period'                => 'period',
129:                 'store_id'              => new Zend_Db_Expr(Mage_Core_Model_App::ADMIN_STORE_ID),
130:                 'code'                  => 'code',
131:                 'order_status'          => 'order_status',
132:                 'percent'               => 'MAX(' . $writeAdapter->quoteIdentifier('percent') . ')',
133:                 'orders_count'          => 'SUM(orders_count)',
134:                 'tax_base_amount_sum'   => 'SUM(tax_base_amount_sum)'
135:             );
136: 
137:             $select
138:                 ->from($this->getMainTable(), $columns)
139:                 ->where('store_id <> ?', 0);
140: 
141:             if ($subSelect !== null) {
142:                 $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period'));
143:             }
144: 
145:             $select->group(array('period', 'code', 'percent', 'order_status'));
146:             $insertQuery = $writeAdapter->insertFromSelect($select, $this->getMainTable(), array_keys($columns));
147:             $writeAdapter->query($insertQuery);
148:             $writeAdapter->commit();
149:         } catch (Exception $e) {
150:             $writeAdapter->rollBack();
151:             throw $e;
152:         }
153: 
154:         return $this;
155:     }
156: }
157: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0