PageRenderTime 22ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/app/code/core/Mage/Adminhtml/Block/Report/Sales/Coupons/Grid.php

https://bitbucket.org/dnejedly/eaparts
PHP | 179 lines | 123 code | 18 blank | 38 comment | 6 complexity | 37ba69dadcc47a65c8d478ccfa569dcc MD5 | raw file
  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_Adminhtml
  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. * Adminhtml coupons report grid block
  28. *
  29. * @category Mage
  30. * @package Mage_Adminhtml
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Adminhtml_Block_Report_Sales_Coupons_Grid extends Mage_Adminhtml_Block_Report_Grid_Abstract
  34. {
  35. protected $_columnGroupBy = 'period';
  36. public function __construct()
  37. {
  38. parent::__construct();
  39. $this->setCountTotals(true);
  40. $this->setCountSubTotals(true);
  41. }
  42. public function getResourceCollectionName()
  43. {
  44. if (($this->getFilterData()->getData('report_type') == 'updated_at_order')) {
  45. return 'salesrule/report_updatedat_collection';
  46. } else {
  47. return 'salesrule/report_collection';
  48. }
  49. }
  50. protected function _prepareColumns()
  51. {
  52. $this->addColumn('period', array(
  53. 'header' => Mage::helper('salesrule')->__('Period'),
  54. 'index' => 'period',
  55. 'width' => 100,
  56. 'sortable' => false,
  57. 'period_type' => $this->getPeriodType(),
  58. 'renderer' => 'adminhtml/report_sales_grid_column_renderer_date',
  59. 'totals_label' => Mage::helper('salesrule')->__('Total'),
  60. 'subtotals_label' => Mage::helper('salesrule')->__('Subtotal'),
  61. 'html_decorators' => array('nobr'),
  62. ));
  63. $this->addColumn('coupon_code', array(
  64. 'header' => Mage::helper('salesrule')->__('Coupon Code'),
  65. 'sortable' => false,
  66. 'index' => 'coupon_code'
  67. ));
  68. $this->addColumn('rule_name', array(
  69. 'header' => Mage::helper('salesrule')->__('Shopping Cart Price Rule'),
  70. 'sortable' => false,
  71. 'index' => 'rule_name'
  72. ));
  73. $this->addColumn('coupon_uses', array(
  74. 'header' => Mage::helper('salesrule')->__('Number of Uses'),
  75. 'sortable' => false,
  76. 'index' => 'coupon_uses',
  77. 'total' => 'sum',
  78. 'type' => 'number'
  79. ));
  80. if ($this->getFilterData()->getStoreIds()) {
  81. $this->setStoreIds(explode(',', $this->getFilterData()->getStoreIds()));
  82. }
  83. $currencyCode = $this->getCurrentCurrencyCode();
  84. $rate = $this->getRate($currencyCode);
  85. $this->addColumn('subtotal_amount', array(
  86. 'header' => Mage::helper('salesrule')->__('Sales Subtotal Amount'),
  87. 'sortable' => false,
  88. 'type' => 'currency',
  89. 'currency_code' => $currencyCode,
  90. 'total' => 'sum',
  91. 'index' => 'subtotal_amount',
  92. 'rate' => $rate,
  93. ));
  94. $this->addColumn('discount_amount', array(
  95. 'header' => Mage::helper('salesrule')->__('Sales Discount Amount'),
  96. 'sortable' => false,
  97. 'type' => 'currency',
  98. 'currency_code' => $currencyCode,
  99. 'total' => 'sum',
  100. 'index' => 'discount_amount',
  101. 'rate' => $rate,
  102. ));
  103. $this->addColumn('total_amount', array(
  104. 'header' => Mage::helper('salesrule')->__('Sales Total Amount'),
  105. 'sortable' => false,
  106. 'type' => 'currency',
  107. 'currency_code' => $currencyCode,
  108. 'total' => 'sum',
  109. 'index' => 'total_amount',
  110. 'rate' => $rate,
  111. ));
  112. $this->addColumn('subtotal_amount_actual', array(
  113. 'header' => Mage::helper('salesrule')->__('Subtotal Amount'),
  114. 'sortable' => false,
  115. 'type' => 'currency',
  116. 'currency_code' => $currencyCode,
  117. 'total' => 'sum',
  118. 'index' => 'subtotal_amount_actual',
  119. 'rate' => $rate,
  120. ));
  121. $this->addColumn('discount_amount_actual', array(
  122. 'header' => Mage::helper('salesrule')->__('Discount Amount'),
  123. 'sortable' => false,
  124. 'type' => 'currency',
  125. 'currency_code' => $currencyCode,
  126. 'total' => 'sum',
  127. 'index' => 'discount_amount_actual',
  128. 'rate' => $rate,
  129. ));
  130. $this->addColumn('total_amount_actual', array(
  131. 'header' => Mage::helper('salesrule')->__('Total Amount'),
  132. 'sortable' => false,
  133. 'type' => 'currency',
  134. 'currency_code' => $currencyCode,
  135. 'total' => 'sum',
  136. 'index' => 'total_amount_actual',
  137. 'rate' => $rate,
  138. ));
  139. $this->addExportType('*/*/exportCouponsCsv', Mage::helper('adminhtml')->__('CSV'));
  140. $this->addExportType('*/*/exportCouponsExcel', Mage::helper('adminhtml')->__('Excel XML'));
  141. return parent::_prepareColumns();
  142. }
  143. /**
  144. * Add price rule filter
  145. *
  146. * @param Mage_Reports_Model_Resource_Report_Collection_Abstract $collection
  147. * @param Varien_Object $filterData
  148. * @return Mage_Adminhtml_Block_Report_Grid_Abstract
  149. */
  150. protected function _addCustomFilter($collection, $filterData)
  151. {
  152. if ($filterData->getPriceRuleType()) {
  153. $rulesList = $filterData->getData('rules_list');
  154. if (isset($rulesList[0])) {
  155. $rulesIds = explode(',', $rulesList[0]);
  156. $collection->addRuleFilter($rulesIds);
  157. }
  158. }
  159. return parent::_addCustomFilter($filterData, $collection);
  160. }
  161. }