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_Sales_Model_Resource_Report_Order_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 = 'sales/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: $adapter = $this->getConnection();
78: if ('month' == $this->_period) {
79: $this->_periodFormat = $adapter->getDateFormatSql('period', '%Y-%m');
80: } elseif ('year' == $this->_period) {
81: $this->_periodFormat = $adapter->getDateExtractSql('period', Varien_Db_Adapter_Interface::INTERVAL_YEAR);
82: } else {
83: $this->_periodFormat = $adapter->getDateFormatSql('period', '%Y-%m-%d');
84: }
85:
86: if (!$this->isTotals()) {
87: $this->_selectedColumns = array(
88: 'period' => $this->_periodFormat,
89: 'orders_count' => 'SUM(orders_count)',
90: 'total_qty_ordered' => 'SUM(total_qty_ordered)',
91: 'total_qty_invoiced' => 'SUM(total_qty_invoiced)',
92: 'total_income_amount' => 'SUM(total_income_amount)',
93: 'total_revenue_amount' => 'SUM(total_revenue_amount)',
94: 'total_profit_amount' => 'SUM(total_profit_amount)',
95: 'total_invoiced_amount' => 'SUM(total_invoiced_amount)',
96: 'total_canceled_amount' => 'SUM(total_canceled_amount)',
97: 'total_paid_amount' => 'SUM(total_paid_amount)',
98: 'total_refunded_amount' => 'SUM(total_refunded_amount)',
99: 'total_tax_amount' => 'SUM(total_tax_amount)',
100: 'total_tax_amount_actual' => 'SUM(total_tax_amount_actual)',
101: 'total_shipping_amount' => 'SUM(total_shipping_amount)',
102: 'total_shipping_amount_actual' => 'SUM(total_shipping_amount_actual)',
103: 'total_discount_amount' => 'SUM(total_discount_amount)',
104: 'total_discount_amount_actual' => 'SUM(total_discount_amount_actual)',
105: );
106: }
107:
108: if ($this->isTotals()) {
109: $this->_selectedColumns = $this->getAggregatedColumns();
110: }
111:
112: return $this->_selectedColumns;
113: }
114:
115: 116: 117: 118: 119:
120: protected function _initSelect()
121: {
122: $this->getSelect()->from($this->getResource()->getMainTable(), $this->_getSelectedColumns());
123: if (!$this->isTotals()) {
124: $this->getSelect()->group($this->_periodFormat);
125: }
126: return $this;
127: }
128: }
129: