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_Tax_Model_Resource_Report_Collection extends Mage_Sales_Model_Resource_Report_Collection_Abstract
36: {
37: 38: 39: 40: 41:
42: protected $_periodFormat;
43:
44: 45: 46: 47: 48:
49: protected $_aggregationTable = 'tax/tax_order_aggregated_created';
50:
51: 52: 53: 54: 55:
56: protected $_selectedColumns = array();
57:
58: 59: 60: 61:
62: public function __construct()
63: {
64: parent::_construct();
65: $this->setModel('adminhtml/report_item');
66: $this->_resource = Mage::getResourceModel('sales/report')->init($this->_aggregationTable);
67: $this->setConnection($this->getResource()->getReadConnection());
68: }
69:
70: 71: 72: 73: 74:
75: protected function _getSelectedColumns()
76: {
77: if ('month' == $this->_period) {
78: $this->_periodFormat = $this->getConnection()->getDateFormatSql('period', '%Y-%m');
79: } elseif ('year' == $this->_period) {
80: $this->_periodFormat = $this->getConnection()->getDateFormatSql('period', '%Y');
81: } else {
82: $this->_periodFormat = $this->getConnection()->getDateFormatSql('period', '%Y-%m-%d');
83: }
84:
85: if (!$this->isTotals() && !$this->isSubTotals()) {
86: $this->_selectedColumns = array(
87: 'period' => $this->_periodFormat,
88: 'code' => 'code',
89: 'percent' => 'percent',
90: 'orders_count' => 'SUM(orders_count)',
91: 'tax_base_amount_sum' => 'SUM(tax_base_amount_sum)'
92: );
93: }
94:
95: if ($this->isTotals()) {
96: $this->_selectedColumns = $this->getAggregatedColumns();
97: }
98:
99: if ($this->isSubTotals()) {
100: $this->_selectedColumns = $this->getAggregatedColumns() + array('period' => $this->_periodFormat);
101: }
102:
103: return $this->_selectedColumns;
104: }
105:
106: 107: 108: 109: 110:
111: protected function _initSelect()
112: {
113: $this->getSelect()->from($this->getResource()->getMainTable() , $this->_getSelectedColumns());
114: if (!$this->isTotals() && !$this->isSubTotals()) {
115: $this->getSelect()->group(array($this->_periodFormat, 'code', 'percent'));
116: }
117:
118: if ($this->isSubTotals()) {
119: $this->getSelect()->group(array(
120: $this->_periodFormat
121: ));
122: }
123:
124: 125: 126:
127: $this->_useAnalyticFunction = true;
128:
129: return $this;
130: }
131: }
132: