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_Adminhtml_Block_Dashboard_Totals extends Mage_Adminhtml_Block_Dashboard_Bar
36: {
37: protected function _construct()
38: {
39: parent::_construct();
40: $this->setTemplate('dashboard/totalbar.phtml');
41: }
42:
43: protected function _prepareLayout()
44: {
45: if (!Mage::helper('core')->isModuleEnabled('Mage_Reports')) {
46: return $this;
47: }
48: $isFilter = $this->getRequest()->getParam('store') || $this->getRequest()->getParam('website') || $this->getRequest()->getParam('group');
49: $period = $this->getRequest()->getParam('period', '24h');
50:
51:
52: $collection = Mage::getResourceModel('reports/order_collection')
53: ->addCreateAtPeriodFilter($period)
54: ->calculateTotals($isFilter);
55:
56: if ($this->getRequest()->getParam('store')) {
57: $collection->addFieldToFilter('store_id', $this->getRequest()->getParam('store'));
58: } else if ($this->getRequest()->getParam('website')){
59: $storeIds = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getStoreIds();
60: $collection->addFieldToFilter('store_id', array('in' => $storeIds));
61: } else if ($this->getRequest()->getParam('group')){
62: $storeIds = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getStoreIds();
63: $collection->addFieldToFilter('store_id', array('in' => $storeIds));
64: } elseif (!$collection->isLive()) {
65: $collection->addFieldToFilter('store_id',
66: array('eq' => Mage::app()->getStore(Mage_Core_Model_Store::ADMIN_CODE)->getId())
67: );
68: }
69:
70: $collection->load();
71:
72: $totals = $collection->getFirstItem();
73:
74: $this->addTotal($this->__('Revenue'), $totals->getRevenue());
75: $this->addTotal($this->__('Tax'), $totals->getTax());
76: $this->addTotal($this->__('Shipping'), $totals->getShipping());
77: $this->addTotal($this->__('Quantity'), $totals->getQuantity()*1, true);
78: }
79: }
80: