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:
35: class Mage_Reports_Model_Resource_Refunded_Collection extends Mage_Sales_Model_Entity_Order_Collection
36: {
37: 38: 39: 40: 41: 42: 43:
44: public function setDateRange($from, $to)
45: {
46: $this->_reset()
47: ->addAttributeToSelect('*')
48: ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to))
49: ->addExpressionAttributeToSelect('orders', 'COUNT({{total_refunded}})', array('total_refunded'));
50:
51: $this->getSelect()
52: ->where('base_total_refunded > ?', 0)
53: ->group('("*")')
54: ->having('orders > ?', 0);
55:
56: return $this;
57: }
58:
59: 60: 61: 62: 63: 64:
65: public function setStoreIds($storeIds)
66: {
67: if ($storeIds) {
68: $this->addAttributeToFilter('store_id', array('in' => (array)$storeIds))
69: ->addExpressionAttributeToSelect(
70: 'refunded',
71: 'SUM({{base_total_refunded}})',
72: array('base_total_refunded'))
73: ->addExpressionAttributeToSelect(
74: 'online_refunded',
75: 'SUM({{base_total_online_refunded}})',
76: array('base_total_online_refunded'))
77: ->addExpressionAttributeToSelect(
78: 'offline_refunded',
79: 'SUM({{base_total_offline_refunded}})',
80: array('base_total_offline_refunded'));
81: } else {
82: $this->addExpressionAttributeToSelect(
83: 'refunded',
84: 'SUM({{base_total_refunded}}*{{base_to_global_rate}})',
85: array('base_total_refunded', 'base_to_global_rate'))
86: ->addExpressionAttributeToSelect(
87: 'online_refunded',
88: 'SUM({{base_total_online_refunded}}*{{base_to_global_rate}})',
89: array('base_total_online_refunded', 'base_to_global_rate'))
90: ->addExpressionAttributeToSelect(
91: 'offline_refunded',
92: 'SUM({{base_total_offline_refunded}}*{{base_to_global_rate}})',
93: array('base_total_offline_refunded', 'base_to_global_rate'));
94: }
95:
96: return $this;
97: }
98:
99: 100: 101: 102: 103:
104: public function getSelectCountSql()
105: {
106: $countSelect = clone $this->getSelect();
107: $countSelect->reset(Zend_Db_Select::ORDER);
108: $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
109: $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
110: $countSelect->reset(Zend_Db_Select::COLUMNS);
111: $countSelect->reset(Zend_Db_Select::GROUP);
112: $countSelect->reset(Zend_Db_Select::HAVING);
113: $countSelect->columns('COUNT(*)');
114:
115: return $countSelect;
116: }
117: }
118: