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