Advertisement
andhiirawan

Magento:Advanced Report-Sales Report:Adding Attribute Column

Nov 7th, 2014
876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 33.77 KB | None | 0 0
  1. <?php
  2. //related to the question in Magento StackExchange
  3. //Advanced Report - Sales Report : Adding Attribute Column
  4. //http://magento.stackexchange.com/questions/5860/advanced-report-sales-report-adding-attribute-column
  5. /**
  6. * aheadWorks Co.
  7.  *
  8.  * NOTICE OF LICENSE
  9.  *
  10.  * This source file is subject to the EULA
  11.  * that is bundled with this package in the file LICENSE.txt.
  12.  * It is also available through the world-wide-web at this URL:
  13.  * http://ecommerce.aheadworks.com/AW-LICENSE-COMMUNITY.txt
  14.  *
  15.  * =================================================================
  16.  *                 MAGENTO EDITION USAGE NOTICE
  17.  * =================================================================
  18.  * This package designed for Magento COMMUNITY edition
  19.  * aheadWorks does not guarantee correct work of this extension
  20.  * on any other Magento edition except Magento COMMUNITY edition.
  21.  * aheadWorks does not provide extension support in case of
  22.  * incorrect edition usage.
  23.  * =================================================================
  24.  *
  25.  * @category   AW
  26.  * @package    AW_Advancedreports
  27.  * @version    2.4.0
  28.  * @copyright  Copyright (c) 2010-2012 aheadWorks Co. (http://www.aheadworks.com)
  29.  * @license    http://ecommerce.aheadworks.com/AW-LICENSE-COMMUNITY.txt
  30.  */
  31.  
  32. /**
  33.  * Sales Report Grid
  34.  */
  35. class AW_Advancedreports_Block_Advanced_Sales_Grid extends AW_Advancedreports_Block_Advanced_Grid
  36. {
  37.     const OPTION_SALES_GROUPED_SKU = 'advancedreports_sales_options_skutype';
  38.  
  39.     protected $_routeOption = AW_Advancedreports_Helper_Data::ROUTE_ADVANCED_SALES;
  40.     protected $_optCollection;
  41.     protected $_optCache = array();
  42.  
  43.     /**
  44.      * Cache with addresses for orders
  45.      * @var array
  46.      */
  47.     protected $_addresses = array();
  48.  
  49.     public function __construct()
  50.     {
  51.         parent::__construct();
  52.         $this->setTemplate($this->_helper()->getGridTemplate());
  53.         $this->setExportVisibility(true);
  54.         $this->setStoreSwitcherVisibility(true);
  55.         $this->setUseAjax(true);
  56.         $this->setFilterVisibility(true);
  57.         $this->setId('gridAdvancedSales');
  58.  
  59.         $filterField = $this->_helper()->confOrderDateFilter();
  60.         # Init aggregator
  61.        //$this->getAggregator()->initAggregator($this, AW_Advancedreports_Helper_Tools_Aggregator::TYPE_LIST, $this->getRoute(), $this->_helper()->confOrderDateFilter());
  62.         $this->getAggregator()->initAggregator($this, AW_Advancedreports_Helper_Tools_Aggregator::TYPE_LIST, $this->getRoute(), $filterField);
  63.         $storeIds = $this->getStoreIds();
  64.         if (count($storeIds)) {
  65.             $this->getAggregator()->setStoreFilter($storeIds);
  66.         }      
  67.     }
  68.  
  69.     public function getHideShowBy()
  70.     {
  71.         return true;
  72.     }
  73.  
  74.     /**
  75.      * Retrives initialization array for custom report option
  76.      * @return array
  77.      */
  78.     public function  getCustomOptionsRequired()
  79.     {
  80.         $array = parent::getCustomOptionsRequired();
  81.  
  82.         $include = Mage::getModel('advancedreports/system_config_source_include');
  83.         $skutypes = Mage::getSingleton('advancedreports/system_config_source_skutype')->toOptionArray();
  84.         $addArray = array(
  85.             array(
  86.                 'id' => 'include_refunded',
  87.                 'type' => 'select',
  88.                 'args' => array(
  89.                     'label' => $this->_helper()->__('Include refunded items'),
  90.                     'title' => $this->_helper()->__('Include refunded items'),
  91.                     'name' => 'include_refunded',
  92.                     'values' => $include->toOptionArray(),
  93.                 ),
  94.                 'default' => '1'
  95.             ),
  96.             array(
  97.                 'id' => self::OPTION_SALES_GROUPED_SKU,
  98.                 'type' => 'select',
  99.                 'args' => array(
  100.                     'label' => $this->_helper()->__('SKU usage'),
  101.                     'title' => $this->_helper()->__('SKU usage'),
  102.                     'name' => self::OPTION_SALES_GROUPED_SKU,
  103.                     'class' => '',
  104.                     'required' => true,
  105.                     'values' => $skutypes
  106.                 ),
  107.                 'default' => AW_Advancedreports_Model_System_Config_Source_Skutype::SKUTYPE_SIMPLE
  108.             ),
  109.  
  110.         );
  111.         return array_merge($array, $addArray);
  112.     }
  113.  
  114.  
  115.     protected function _addCustomData($row)
  116.     {
  117.         $this->_customData[] = $row;
  118.         return $this;
  119.     }
  120.  
  121.     /**
  122.      * Prepare array with collected data
  123.      *
  124.      * @param datetime $from
  125.      * @param datetime $to
  126.      * @return array
  127.      */
  128.     public function getPreparedData($from, $to)
  129.     {
  130.         /** @var AW_Advancedreports_Model_Mysql4_Collection_Sales $collection  */
  131.         $collection = Mage::getResourceModel('advancedreports/collection_sales');
  132.         $collection->reInitSelect();
  133.  
  134.         $collection->setDateFilter($from, $to)->setState();
  135.         $storeIds = $this->getStoreIds();
  136.         if (count($storeIds)) {
  137.             $collection->setStoreFilter($storeIds);
  138.         }
  139.  
  140.         $collection->addOrderItems($this->getCustomOption(self::OPTION_SALES_GROUPED_SKU))
  141.             ->addCustomerInfo()
  142.             ->addManufacturer()
  143.             ->addAddress();
  144.  
  145.         if (!$this->getCustomOption('include_refunded')) {
  146.             $collection->excludeRefunded();
  147.         }
  148.  
  149.         //CREATE A JOINING AW POINT SPEND ON ORDER
  150.         $collection->getSelect()->joinLeft( array('awpto' => 'aw_points_transaction_orderspend'),
  151.                 "awpto.order_increment_id = main_table.increment_id",
  152.                 array('points_to_money'=>'COALESCE(awpto.points_to_money,0)/child_soi.total_item'));
  153.        
  154.         //BOF: CREATE A SUBQUERY FOR GETTING A TOTAL ITEM AT ORDER
  155.         $orderTable = Mage::getResourceModel('sales/order_collection')
  156.                             ->addAttributeToSelect('entity_id');
  157.         $orderTable->getSelect()->joinLeft( array('sfoi' => 'sales_flat_order_item'),
  158.                 "sfoi.order_id = main_table.entity_id",
  159.                 array('total_item'=>'count(sfoi.item_id)'));
  160.         $orderTable->getSelect()->group(array("main_table.entity_id"));
  161.  
  162.         $collection->getSelect()->joinLeft( array('child_soi' => new Zend_Db_Expr( '(' . $orderTable->getSelect() . ')')),
  163.                 "child_soi.entity_id = main_table.entity_id",
  164.                 array('total_item'=>'child_soi.total_item'));
  165.         //EOF: CREATE A SUBQUERY FOR GETTING A TOTAL ITEM AT ORDER
  166.        
  167.         //BOF: CREATE A SUBQUERY FOR GETTING A BRAND
  168.         $brandTable = Mage::getModel('catalog/product')->getCollection()
  169.                             ->addAttributeToSelect('entity_id');
  170.         $brandTable->getSelect()->join( array('cpei' => 'catalog_product_entity_int'),
  171.                 "e.entity_id = cpei.entity_id",
  172.                 array());
  173.         $brandTable->getSelect()->join( array('eaov' => 'eav_attribute_option_value'),
  174.                 "cpei.value = eaov.option_id",
  175.                 array('brand' => 'value'));
  176.         $brandTable->getSelect()->join( array('eao' => 'eav_attribute_option'),
  177.                 "eaov.option_id = eao.option_id",
  178.                 array());
  179.         $brandTable->getSelect()->join( array('ea' => 'eav_attribute'),
  180.                 "eao.attribute_id = ea.attribute_id AND ea.attribute_code = 'brand'",
  181.                 array());
  182.  
  183.         $collection->getSelect()->join( array('child_brand' => new Zend_Db_Expr( '(' . $brandTable->getSelect() . ')')),
  184.                 "child_brand.entity_id = _product.entity_id",
  185.                 array('brand'=>'child_brand.brand'));
  186.  
  187.         //EOF: CREATE A SUBQUERY FOR GETTING A BRAND
  188.        
  189.         $collection->getSelect()->joinLeft(
  190.             array ('payment' => 'sales_flat_order_payment'),
  191.             "payment.parent_id = main_table.entity_id",
  192.             array ('method' => 'payment.method')
  193.         )->joinLeft(
  194.             array ('shippment' => 'sales_flat_order'),
  195.             "shippment.entity_id = main_table.entity_id",
  196.             array (
  197.                 'shipping_method' => 'shippment.shipping_method',
  198.                 'shipping_split_amount' => 'COALESCE(shippment.shipping_amount, 0) / child_soi.total_item'
  199.             )
  200.         );
  201.  
  202. //      $collection->getSelect()->join('catalog_product_entity_int', '_product.entity_id = catalog_product_entity_int.entity_id', array());
  203. //      $collection->getSelect()->join('eav_attribute_option_value', 'catalog_product_entity_int.value = eav_attribute_option_value.option_id', array('brand' => 'value'));
  204. //      $collection->getSelect()->join('eav_attribute_option', 'eav_attribute_option_value.option_id = eav_attribute_option.option_id', array());
  205. //      $collection->getSelect()->join('eav_attribute', 'eav_attribute_option.attribute_id = eav_attribute.attribute_id AND eav_attribute.attribute_code = "brand" ', array());
  206.        
  207. //         echo $collection->getSelect();die;
  208.    
  209.         $this->setCollection($collection);
  210.         $this->_prepareData();
  211.        
  212.         return $this->getCustomVarData();
  213.     }
  214.  
  215.     public function _prepareCollection()
  216.     {
  217.         $this
  218.             ->_setUpReportKey()
  219.             ->_setUpFilters();
  220.  
  221.         # Start aggregator
  222.        $date_from = $this->_getMysqlFromFormat($this->getFilter('report_from'));
  223.         $date_to = $this->_getMysqlToFormat($this->getFilter('report_to'));
  224.         $this->getAggregator()->prepareAggregatedCollection($date_from, $date_to);
  225.  
  226.         /** @var AW_Advancedreports_Model_Mysql4_Cache_Collection $collection  */
  227.         $collection = $this->getAggregator()->getAggregatetCollection();
  228.         $this->setCollection($collection);
  229.  
  230.         if ($sort = $this->_getSort()) {
  231.             $collection->addOrder($sort, $this->_getDir());
  232.             $this->getColumn($sort)->setDir($this->_getDir());
  233.         } else {
  234.             $collection->addOrder('order_created_at', 'DESC');
  235.         }
  236.      
  237.         $this->_saveFilters();
  238.         $this->_setColumnFilters();
  239.     }
  240.  
  241.     protected function _addOptionToCache($id, $value)
  242.     {
  243.         $this->_optCache[$id] = $value;
  244.     }
  245.  
  246.     protected function _optionInCache($id)
  247.     {
  248.         if (count($this->_optCache)) {
  249.             foreach ($this->_optCache as $key => $value) {
  250.                 if ($key == $id) {
  251.                     return $value;
  252.                 }
  253.             }
  254.         }
  255.         return null;
  256.     }
  257.  
  258.     protected function _getManufacturer($option_id)
  259.     {
  260.         if (!$this->_optCollection) {
  261.             $this->_optCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
  262.                 ->setStoreFilter(0, false)
  263.                 ->load();
  264.         }
  265.         # seach in quick cache
  266.        if ($val = $this->_optionInCache($option_id)) {
  267.             return $val;
  268.         }
  269.         # search in chached collection
  270.        foreach ($this->_optCollection as $item) {
  271.             if ($option_id == $item->getOptionId()) {
  272.                 $this->_addOptionToCache($option_id, $item->getValue());
  273.                 return $item->getValue();
  274.             }
  275.         }
  276.         return null;
  277.     }
  278.  
  279.     protected function _prepareData()
  280.     {
  281.         foreach ($this->getCollection() as $item) {
  282.             $row = $item->getData();
  283.  
  284.             if (isset($row['order_ship_country_id'])) {
  285.                 $row['order_ship_country'] = $row['order_ship_country_id'];
  286.             }
  287.             if (isset($row['order_bil_country_id'])) {
  288.                 $row['order_bil_country'] = $row['order_bil_country_id'];
  289.             }
  290.  
  291.             # Billing/Shipping logic
  292.            if (isset($row['order_ship_country'])) {
  293.                 $row['order_country'] = $row['order_ship_country'];
  294.             } elseif (isset($row['order_bil_country'])) {
  295.                 $row['order_country'] = $row['order_bil_country'];
  296.             }
  297.             if (isset($row['order_ship_region'])) {
  298.                 $row['order_region'] = $row['order_ship_region'];
  299.             } elseif (isset($row['order_bil_region'])) {
  300.                 $row['order_region'] = $row['order_bil_region'];
  301.             }
  302.             if (isset($row['order_ship_city'])) {
  303.                 $row['order_city'] = $row['order_ship_city'];
  304.             } elseif (isset($row['order_bil_city'])) {
  305.                 $row['order_city'] = $row['order_bil_city'];
  306.             }
  307.             if (isset($row['order_ship_postcode'])) {
  308.                 $row['order_postcode'] = $row['order_ship_postcode'];
  309.             } elseif (isset($row['order_bil_postcode'])) {
  310.                 $row['order_postcode'] = $row['order_bil_postcode'];
  311.             }
  312.             if (is_null($row['customer_email'])) {
  313.                 if (!is_null($row['order_ship_email'])) {
  314.                     $row['customer_email'] = $row['order_ship_email'];
  315.                 } elseif (!is_null($row['order_bil_email'])) {
  316.                     $row['customer_email'] = $row['order_bil_email'];
  317.                 }
  318.             }
  319.            
  320. //             if ((!isset($row['customer_email']) || !($row['customer_email'])) && $this->_helper()->checkExtensionVersion('Mage_Sales', '1.4.0.15', '=')) {
  321. //             if ($this->_helper()->checkExtensionVersion('Mage_Sales', '1.4.0.15', '=')) {
  322.                 /** @var $order Mage_Sales_Model_Order */
  323. //                 $order = Mage::getModel('sales/order')->loadByIncrementId($row['order_increment_id']);
  324. //                 if ($order->getCustomerEmail()) {
  325. //                     $row['customer_email'] = $order->getCustomerEmail();
  326. //                 } elseif ($order->getShippingAddress() && $order->getShippingAddress()->getEmail()) {
  327. //                     $row['customer_email'] = $order->getShippingAddress()->getEmail();
  328. //                 } elseif ($order->getBillingAddress() && $order->getBillingAddress()->getEmail()) {
  329. //                     $row['customer_email'] = $order->getBillingAddress()->getEmail();
  330. //                 }
  331. //             }
  332.  
  333.             if (isset($row['simple_sku'])) {
  334.                 $row['sku'] = $row['simple_sku'];
  335.             }
  336.  
  337.             if (isset($row['sku'])) {
  338.                 $this->_addCustomData($row);
  339.             }
  340.         }
  341.         return $this;
  342.     }
  343.  
  344.     protected function _prepareColumns()
  345.     {
  346.         $def_value = sprintf("%f", 0);
  347.         $def_value = Mage::app()->getLocale()->currency($this->getCurrentCurrencyCode())->toCurrency($def_value);
  348.  
  349.         $this->addColumn('order_increment_id', array(
  350.             'header' => $this->_helper()->__('Order #'),
  351.             'index' => 'order_increment_id',
  352.             'type' => 'text',
  353.             'width' => '80px',
  354.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
  355.             'ddl_size' => 255,
  356.             'ddl_options' => array('nullable' => true),
  357.         ));
  358.  
  359.         $this->addColumn('order_created_at', array(
  360.             'header' => $this->_helper()->__('Order Date'),
  361.             'index' => 'order_created_at',
  362.             'type' => 'datetime',
  363.             'width' => '140px',
  364.             'is_period_key' => true,
  365.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
  366.             'ddl_size' => null,
  367.             'ddl_options' => array('nullable' => false),
  368.         ));
  369.  
  370.         $this->addColumn('xsku', array(
  371.             'header' => $this->_helper()->__('SKU'),
  372.             'width' => '120px',
  373.             'index' => 'xsku',
  374.             'type' => 'text',
  375.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
  376.             'ddl_size' => 255,
  377.             'ddl_options' => array('nullable' => false),
  378.         ));
  379.  
  380.         $this->addColumn('customer_email', array(
  381.             'header' => $this->_helper()->__('Customer Email'),
  382.             'index' => 'customer_email',
  383.             'type' => 'text',
  384.             'width' => '100px',
  385.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
  386.             'ddl_size' => 255,
  387.             'ddl_options' => array('nullable' => true),
  388.         ));
  389.  
  390.         $this->addColumn('customer_group', array(
  391.             'header' => $this->_helper()->__('Customer Group'),
  392.             'index' => 'customer_group',
  393.             'type' => 'text',
  394.             'width' => '100px',
  395.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
  396.             'ddl_size' => 255,
  397.             'ddl_options' => array('nullable' => true),
  398.         ));
  399.  
  400.         $this->addColumn('order_ship_country', array(
  401.             'header' => $this->_helper()->__('Country'),
  402.             'index' => 'order_ship_country',
  403.             'type' => 'country',
  404.             'width' => '100px',
  405.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
  406.             'ddl_size' => 10,
  407.             'ddl_options' => array('nullable' => true),
  408.         ));
  409.  
  410.         $this->addColumn('order_ship_region', array(
  411.             'header' => $this->_helper()->__('Region'),
  412.             'index' => 'order_ship_region',
  413.             'type' => 'text',
  414.             'width' => '100px',
  415.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
  416.             'ddl_size' => 255,
  417.             'ddl_options' => array('nullable' => true),
  418.         ));
  419.  
  420.         $this->addColumn('order_ship_city', array(
  421.             'header' => $this->_helper()->__('City'),
  422.             'index' => 'order_ship_city',
  423.             'type' => 'text',
  424.             'width' => '100px',
  425.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
  426.             'ddl_size' => 255,
  427.             'ddl_options' => array('nullable' => true),
  428.         ));
  429.  
  430.         $this->addColumn('order_ship_postcode', array(
  431.             'header' => $this->_helper()->__('Zip Code'),
  432.             'index' => 'order_ship_postcode',
  433.             'type' => 'text',
  434.             'width' => '60px',
  435.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
  436.             'ddl_size' => 255,
  437.             'ddl_options' => array('nullable' => true),
  438.         ));
  439.  
  440.         $this->addColumn('shipping_method', array (
  441.             'header' => $this->_helper()->__('Shipping Method'),
  442.             'index' => 'shipping_method',
  443.             //'type' => 'text',
  444.             'type' => 'options',
  445.             'options' => $this->getShippingMethods(),
  446.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
  447.             'ddl_size' => 100,
  448.             'ddl_options' => array ('nullable' => true),
  449.         ));
  450.        
  451.         $this->addColumn('method', array (
  452.             'header' => $this->_helper()->__('Payment Method'),
  453.             'index' => 'method',
  454.             'type' => 'options',
  455.             'options' => $this->getPaymentMethods(),
  456.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
  457.             'ddl_size' => 50,
  458.             'ddl_options' => array ('nullable' => true),
  459.         ));
  460.  
  461.         $this->addColumn('name', array(
  462.             'header' => $this->_helper()->__('Product Name'),
  463.             'index' => 'name',
  464.             'type' => 'text',
  465.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
  466.             'ddl_size' => 255,
  467.             'ddl_options' => array('nullable' => true),
  468.         ));
  469.        
  470.         //-------------------------------------------------------Adding column Brand        
  471.         $this->addColumn('brand', array(
  472.             'header' => $this->_helper()->__('Brand'),
  473.             'index' => 'brand',
  474.             'type' => 'text',
  475.             'width' => '100px',
  476.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
  477.             'ddl_size' => 255,
  478.             'ddl_options' => array('nullable' => true),
  479.         ));
  480.  
  481.         $this->addColumn('product_manufacturer', array(
  482.             'header' => $this->_helper()->__('Manufacturer'),
  483.             'index' => 'product_manufacturer',
  484.             'type' => 'text',
  485.             'width' => '100px',
  486.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
  487.             'ddl_size' => 255,
  488.             'ddl_options' => array('nullable' => true),
  489.         ));
  490.  
  491.         $this->addColumn('xqty_ordered', array(
  492.             'header' => $this->_helper()->__('Qty. Ordered'),
  493.             'width' => '60px',
  494.             'index' => 'xqty_ordered',
  495.             'total' => 'sum',
  496.             'type' => 'number',
  497.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  498.             'ddl_size' => '12,4',
  499.             'ddl_options' => array('nullable' => true),
  500.         ));
  501.  
  502.         $this->addColumn('xqty_invoiced', array(
  503.             'header' => $this->_helper()->__('Qty. Invoiced'),
  504.             'width' => '60px',
  505.             'index' => 'xqty_invoiced',
  506.             'total' => 'sum',
  507.             'type' => 'number',
  508.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  509.             'ddl_size' => '12,4',
  510.             'ddl_options' => array('nullable' => true),
  511.  
  512.         ));
  513.  
  514.         $this->addColumn('xqty_shipped', array(
  515.             'header' => $this->_helper()->__('Qty. Shipped'),
  516.             'width' => '60px',
  517.             'index' => 'xqty_shipped',
  518.             'total' => 'sum',
  519.             'type' => 'number',
  520.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  521.             'ddl_size' => '12,4',
  522.             'ddl_options' => array('nullable' => true),
  523.         ));
  524.  
  525.         $this->addColumn('xqty_refunded', array(
  526.             'header' => $this->_helper()->__('Qty. Refunded'),
  527.             'width' => '60px',
  528.             'index' => 'xqty_refunded',
  529.             'total' => 'sum',
  530.             'type' => 'number',
  531.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  532.             'ddl_size' => '12,4',
  533.             'ddl_options' => array('nullable' => true),
  534.         ));
  535.  
  536.  
  537.         $this->addColumn('base_xprice', array(
  538.             'header' => $this->_helper()->__('Price'),
  539.             'width' => '80px',
  540.             'type' => 'currency',
  541.             'currency_code' => $this->getCurrentCurrencyCode(),
  542.             'total' => 'sum',
  543.             'index' => 'base_xprice',
  544.             'column_css_class' => 'nowrap',
  545.             'default' => $def_value,
  546.             'disable_total' => 1,
  547.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  548.             'ddl_size' => '12,4',
  549.             'ddl_options' => array('nullable' => true),
  550.  
  551.         ));
  552.  
  553.         $this->addColumn('base_row_subtotal', array(
  554.             'header' => $this->_helper()->__('Subtotal'),
  555.             'width' => '80px',
  556.             'type' => 'currency',
  557.             'currency_code' => $this->getCurrentCurrencyCode(),
  558.             'total' => 'sum',
  559.             'index' => 'base_row_subtotal',
  560.             'column_css_class' => 'nowrap',
  561.             'default' => $def_value,
  562.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  563.             'ddl_size' => '12,4',
  564.             'ddl_options' => array('nullable' => true),
  565.         ));
  566.  
  567.         $this->addColumn('base_tax_amount', array(
  568.             'header' => $this->_helper()->__('Tax'),
  569.             'width' => '80px',
  570.             'type' => 'currency',
  571.             'currency_code' => $this->getCurrentCurrencyCode(),
  572.             'total' => 'sum',
  573.             'index' => 'base_tax_amount',
  574.             'column_css_class' => 'nowrap',
  575.             'default' => $def_value,
  576.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  577.             'ddl_size' => '12,4',
  578.             'ddl_options' => array('nullable' => true),
  579.         ));
  580.  
  581.         $this->addColumn('base_discount_amount', array(
  582.             'header' => $this->_helper()->__('Discounts'),
  583.             'width' => '80px',
  584.             'type' => 'currency',
  585.             'currency_code' => $this->getCurrentCurrencyCode(),
  586.             'total' => 'sum',
  587.             'index' => 'base_discount_amount',
  588.             'column_css_class' => 'nowrap',
  589.             'default' => $def_value,
  590.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  591.             'ddl_size' => '12,4',
  592.             'ddl_options' => array('nullable' => true),
  593.         ));
  594.  
  595.         $this->addColumn('pointreward', array(
  596.             'header' => $this->_helper()->__('OnlineShop Credit Used'),
  597.             'type' => 'currency',
  598.             'currency_code' => $this->getCurrentCurrencyCode(),
  599.             'index' => 'points_to_money',
  600.             'total' => 'sum',
  601.             'column_css_class' => 'nowrap',
  602.             'default' => $def_value,
  603.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  604.             'ddl_size' => '12,4',
  605.             'ddl_options' => array('nullable' => true),
  606.         ));
  607.  
  608.         $this->addColumn('base_tax_amount', array(
  609.             'header' => $this->_helper()->__('Tax'),
  610.             'width' => '80px',
  611.             'type' => 'currency',
  612.             'currency_code' => $this->getCurrentCurrencyCode(),
  613.             'total' => 'sum',
  614.             'index' => 'base_tax_amount',
  615.             'column_css_class' => 'nowrap',
  616.             'default' => $def_value,
  617.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  618.             'ddl_size' => '12,4',
  619.             'ddl_options' => array('nullable' => true),
  620.         ));
  621.  
  622.  
  623.         $this->addColumn('base_row_xtotal', array(
  624.             'header' => $this->_helper()->__('Total'),
  625.             'width' => '80px',
  626.             'type' => 'currency',
  627.             'currency_code' => $this->getCurrentCurrencyCode(),
  628.             'total' => 'sum',
  629.             'index' => 'base_row_xtotal',
  630.             'column_css_class' => 'nowrap',
  631.             'default' => $def_value,
  632.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  633.             'ddl_size' => '12,4',
  634.             'ddl_options' => array('nullable' => true),
  635.         ));
  636.  
  637.         $this->addColumn('shipping_split_amount', array (
  638.             'header' => $this->_helper()->__('Shipping Amount'),
  639.             'index' => 'shipping_split_amount',
  640.             'type' => 'currency',
  641.             'currency_code' => $this->getCurrentCurrencyCode(),
  642.             'total' => 'sum',
  643.             'column_css_class' => 'nowrap',
  644.             'default' => $def_value,
  645.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  646.             'ddl_size' => '12,4',
  647.             'ddl_options' => array ('nullable' => true)
  648.         ));
  649.        
  650.         $this->addColumn('base_row_xtotal_incl_tax', array(
  651.             'header' => $this->_helper()->__('Total Incl. Tax'),
  652.             'width' => '80px',
  653.             'type' => 'currency',
  654.             'currency_code' => $this->getCurrentCurrencyCode(),
  655.             'total' => 'sum',
  656.             'index' => 'base_row_xtotal_incl_tax',
  657.             'column_css_class' => 'nowrap',
  658.             'default' => $def_value,
  659.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  660.             'ddl_size' => '12,4',
  661.             'ddl_options' => array('nullable' => true),
  662.         ));
  663.  
  664.         $this->addColumn('base_row_xinvoiced', array(
  665.             'header' => $this->_helper()->__('Invoiced'),
  666.             'width' => '80px',
  667.             'type' => 'currency',
  668.             'currency_code' => $this->getCurrentCurrencyCode(),
  669.             'total' => 'sum',
  670.             'index' => 'base_row_xinvoiced',
  671.             'column_css_class' => 'nowrap',
  672.             'default' => $def_value,
  673.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  674.             'ddl_size' => '12,4',
  675.             'ddl_options' => array('nullable' => true),
  676.         ));
  677.  
  678.         $this->addColumn('base_tax_invoiced', array(
  679.             'header' => $this->_helper()->__('Tax Invoiced'),
  680.             'width' => '80px',
  681.             'type' => 'currency',
  682.             'currency_code' => $this->getCurrentCurrencyCode(),
  683.             'total' => 'sum',
  684.             'index' => 'base_tax_invoiced',
  685.             'column_css_class' => 'nowrap',
  686.             'default' => $def_value,
  687.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  688.             'ddl_size' => '12,4',
  689.             'ddl_options' => array('nullable' => true),
  690.         ));
  691.  
  692.         $this->addColumn('base_row_xinvoiced_incl_tax', array(
  693.             'header' => $this->_helper()->__('Invoiced Incl. Tax'),
  694.             'width' => '80px',
  695.             'type' => 'currency',
  696.             'currency_code' => $this->getCurrentCurrencyCode(),
  697.             'total' => 'sum',
  698.             'index' => 'base_row_xinvoiced_incl_tax',
  699.             'column_css_class' => 'nowrap',
  700.             'default' => $def_value,
  701.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  702.             'ddl_size' => '12,4',
  703.             'ddl_options' => array('nullable' => true),
  704.         ));
  705.  
  706.         $this->addColumn('base_row_xrefunded', array(
  707.             'header' => $this->_helper()->__('Refunded'),
  708.             'width' => '80px',
  709.             'type' => 'currency',
  710.             'currency_code' => $this->getCurrentCurrencyCode(),
  711.             'total' => 'sum',
  712.             'index' => 'base_row_xrefunded',
  713.             'column_css_class' => 'nowrap',
  714.             'default' => $def_value,
  715.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  716.             'ddl_size' => '12,4',
  717.             'ddl_options' => array('nullable' => true),
  718.         ));
  719.  
  720.         $this->addColumn('base_tax_xrefunded', array(
  721.             'header' => $this->_helper()->__('Tax Refunded'),
  722.             'width' => '80px',
  723.             'type' => 'currency',
  724.             'currency_code' => $this->getCurrentCurrencyCode(),
  725.             'total' => 'sum',
  726.             'index' => 'base_tax_xrefunded',
  727.             'column_css_class' => 'nowrap',
  728.             'default' => $def_value,
  729.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  730.             'ddl_size' => '12,4',
  731.             'ddl_options' => array('nullable' => true),
  732.         ));
  733.  
  734.         $this->addColumn('base_row_xrefunded_incl_tax', array(
  735.             'header' => $this->_helper()->__('Refunded Incl. Tax'),
  736.             'width' => '80px',
  737.             'type' => 'currency',
  738.             'currency_code' => $this->getCurrentCurrencyCode(),
  739.             'total' => 'sum',
  740.             'index' => 'base_row_xrefunded_incl_tax',
  741.             'column_css_class' => 'nowrap',
  742.             'default' => $def_value,
  743.             'ddl_type' => Varien_Db_Ddl_Table::TYPE_DECIMAL,
  744.             'ddl_size' => '12,4',
  745.             'ddl_options' => array('nullable' => true),
  746.         ));
  747.  
  748.         $this->addColumn('view_order',
  749.             array(
  750.                 'header' => $this->_helper()->__('View Order'),
  751.                 'width' => '70px',
  752.                 'type' => 'action',
  753.                 'align' => 'left',
  754.                 'getter' => 'getOrderId',
  755.                 'actions' => array(
  756.                     array(
  757.                         'caption' => $this->_helper()->__('View'),
  758.                         'url' => array(
  759.                             'base' => 'adminhtml/sales_order/view',
  760.                             'params' => array()
  761.                         ),
  762.                         'field' => 'order_id'
  763.                     )
  764.                 ),
  765.                 'filter' => false,
  766.                 'sortable' => false,
  767.                 'index' => 'order_id',
  768.                 'ddl_type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  769.                 'ddl_size' => null,
  770.                 'ddl_options' => array('nullable' => true, 'unsigned' => true),
  771.             ));
  772.  
  773.         $this->addColumn('view_product',
  774.             array(
  775.                 'header' => $this->_helper()->__('View Product'),
  776.                 'width' => '70px',
  777.                 'type' => 'action',
  778.                 'align' => 'left',
  779.                 'getter' => 'getProductId',
  780.                 'actions' => array(
  781.                     array(
  782.                         'caption' => $this->_helper()->__('View'),
  783.                         'url' => array(
  784.                             'base' => 'adminhtml/catalog_product/edit',
  785.                             'params' => array()
  786.                         ),
  787.                         'field' => 'id'
  788.                     )
  789.                 ),
  790.                 'filter' => false,
  791.                 'sortable' => false,
  792.                 'index' => 'product_id',
  793.                 'ddl_type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
  794.                 'ddl_size' => null,
  795.                 'ddl_options' => array('nullable' => true, 'unsigned' => true),
  796.             ));
  797.  
  798.         $this->addExportType('*/*/exportOrderedCsv', $this->_helper()->__('CSV'));
  799.         $this->addExportType('*/*/exportOrderedExcel', $this->_helper()->__('Excel'));
  800.         return $this;
  801.     }
  802.  
  803.     protected function getShippingMethods() {
  804.         $collections = Mage::getModel('advancedreports/premiumrate')->getCollection();
  805.         $collections->getSelect()
  806.             ->reset(Zend_Db_Select::COLUMNS)
  807.             ->columns('delivery_type');
  808.         $collections->getSelect()->group('main_table.delivery_type');
  809.         $shippingMethods = array ();
  810.        
  811.         foreach ($collections as $collection) {
  812.             $value = $collection->getData('delivery_type');
  813.             $key = $this->getShippingMethodKey($value);
  814.             $shippingMethods[$key] = $value;
  815.         }
  816.        
  817.         return $shippingMethods;
  818.     }
  819.    
  820.     protected function getShippingMethodKey($method) {
  821.         $result = 'premiumrate_' . str_replace(' ', '_', $method);
  822.        
  823.         return $result;
  824.     }
  825.  
  826.     protected function getPaymentMethods() {
  827.         //$payments = Mage::getSingleton('payment/config')->getActiveMethods();
  828.         $payments = Mage::getSingleton('payment/config')->getAllMethods();
  829.         $methods = array ();
  830.        
  831.         foreach ($payments as $paymentCode => $paymentModel) {
  832.             $paymentTitle = Mage::getStoreConfig('payment/' . $paymentCode . '/title');
  833.             $methods[$paymentCode] = $paymentTitle;
  834.         }
  835.        
  836.         return $methods;
  837.     }
  838.  
  839.     public function getChartType()
  840.     {
  841.         return 'none';
  842.     }
  843.  
  844.     public function hasRecords()
  845.     {
  846.         return false;
  847.     }
  848.  
  849.     public function getPeriods()
  850.     {
  851.         return array();
  852.     }
  853.  
  854.     public function getGridUrl()
  855.     {
  856.         $params = Mage::app()->getRequest()->getParams();
  857.         $params['_secure'] = Mage::app()->getStore(true)->isCurrentlySecure();
  858.         return $this->getUrl('*/*/grid', $params);
  859.     }
  860.  
  861.     public function  hasAggregation()
  862.     {
  863.         return true;
  864.     }
  865. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement