1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Sales
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Sales report refunded collection
30: *
31: * @category Mage
32: * @package Mage_Sales
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Sales_Model_Resource_Report_Refunded_Collection_Order
36: extends Mage_Sales_Model_Resource_Report_Collection_Abstract
37: {
38: /**
39: * Period format
40: *
41: * @var string
42: */
43: protected $_periodFormat;
44:
45: /**
46: * Selected columns
47: *
48: * @var array
49: */
50: protected $_selectedColumns = array();
51:
52: /**
53: * Initialize custom resource model
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/refunded_aggregated_order');
61: $this->setConnection($this->getResource()->getReadConnection());
62: }
63:
64: /**
65: * Retrieve selected columns
66: *
67: * @return array
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()) {
81: $this->_selectedColumns = array(
82: 'period' => $this->_periodFormat,
83: 'orders_count' => 'SUM(orders_count)',
84: 'refunded' => 'SUM(refunded)',
85: 'online_refunded' => 'SUM(online_refunded)',
86: 'offline_refunded' => 'SUM(offline_refunded)'
87: );
88: }
89:
90: if ($this->isTotals()) {
91: $this->_selectedColumns = $this->getAggregatedColumns();
92: }
93:
94: return $this->_selectedColumns;
95: }
96:
97: /**
98: * Add selected data
99: *
100: * @return Mage_Sales_Model_Resource_Report_Refunded_Collection_Order
101: */
102: protected function _initSelect()
103: {
104: $this->getSelect()->from(
105: $this->getResource()->getMainTable() ,
106: $this->_getSelectedColumns()
107: );
108: if (!$this->isTotals()) {
109: $this->getSelect()->group($this->_periodFormat);
110: }
111: return $this;
112: }
113: }
114: