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: class Mage_Paypal_Adminhtml_Paypal_ReportsController extends Mage_Adminhtml_Controller_Action
35: {
36:
37: 38: 39:
40: public function indexAction()
41: {
42: $this->_initAction()
43: ->_addContent($this->getLayout()->createBlock('paypal/adminhtml_settlement_report'))
44: ->renderLayout();
45: }
46:
47: 48: 49:
50: public function gridAction()
51: {
52: $this->loadLayout();
53: $this->getResponse()->setBody(
54: $this->getLayout()->createBlock('paypal/adminhtml_settlement_report_grid')->toHtml()
55: );
56: }
57:
58: 59: 60:
61: public function detailsAction()
62: {
63: $rowId = $this->getRequest()->getParam('id');
64: $row = Mage::getModel('paypal/report_settlement_row')->load($rowId);
65: if (!$row->getId()) {
66: $this->_redirect('*/*/');
67: return;
68: }
69: Mage::register('current_transaction', $row);
70: $this->_initAction()
71: ->_title($this->__('View Transaction'))
72: ->_addContent($this->getLayout()->createBlock('paypal/adminhtml_settlement_details', 'settlementDetails'))
73: ->renderLayout();
74: }
75:
76: 77: 78:
79: public function fetchAction()
80: {
81: try {
82: $reports = Mage::getModel('paypal/report_settlement');
83:
84: $credentials = $reports->getSftpCredentials();
85: if (empty($credentials)) {
86: Mage::throwException(Mage::helper('paypal')->__('Nothing to fetch because of an empty configuration.'));
87: }
88: foreach ($credentials as $config) {
89: try {
90: $fetched = $reports->fetchAndSave($config);
91: $this->_getSession()->addSuccess(
92: Mage::helper('paypal')->__("Fetched %s report rows from '%s@%s'.", $fetched, $config['username'], $config['hostname'])
93: );
94: } catch (Exception $e) {
95: $this->_getSession()->addError(
96: Mage::helper('paypal')->__("Failed to fetch reports from '%s@%s'.", $config['username'], $config['hostname'])
97: );
98: Mage::logException($e);
99: }
100: }
101: } catch (Mage_Core_Exception $e) {
102: $this->_getSession()->addError($e->getMessage());
103: } catch (Exception $e) {
104: Mage::logException($e);
105: }
106: $this->_redirect('*/*/index');
107: }
108:
109: 110: 111: 112:
113: protected function _initAction()
114: {
115: $this->_title($this->__('Reports'))->_title($this->__('Sales'))->_title($this->__('PayPal Settlement Reports'));
116: $this->loadLayout()
117: ->_setActiveMenu('report/sales')
118: ->_addBreadcrumb(Mage::helper('paypal')->__('Reports'), Mage::helper('paypal')->__('Reports'))
119: ->_addBreadcrumb(Mage::helper('paypal')->__('Sales'), Mage::helper('paypal')->__('Sales'))
120: ->_addBreadcrumb(Mage::helper('paypal')->__('PayPal Settlement Reports'), Mage::helper('paypal')->__('PayPal Settlement Reports'));
121: return $this;
122: }
123:
124: 125: 126: 127:
128: protected function _isAllowed()
129: {
130: switch ($this->getRequest()->getActionName()) {
131: case 'index':
132: case 'details':
133: return Mage::getSingleton('admin/session')->isAllowed('report/salesroot/paypal_settlement_reports/view');
134: break;
135: case 'fetch':
136: return Mage::getSingleton('admin/session')->isAllowed('report/salesroot/paypal_settlement_reports/fetch');
137: break;
138: default:
139: return Mage::getSingleton('admin/session')->isAllowed('report/salesroot/paypal_settlement_reports');
140: break;
141: }
142: }
143: }
144: