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