1: | <?php
2: | namespace Opencart\Admin\Controller\Report;
3: | /**
4: | * Class Statistics
5: | *
6: | * @package Opencart\Admin\Controller\Report
7: | */
8: | class Statistics extends \Opencart\System\Engine\Controller {
9: | /**
10: | * Index
11: | *
12: | * @return void
13: | */
14: | public function index(): void {
15: | $this->load->language('report/statistics');
16: |
17: | $this->document->setTitle($this->language->get('heading_title'));
18: |
19: | $data['breadcrumbs'] = [];
20: |
21: | $data['breadcrumbs'][] = [
22: | 'text' => $this->language->get('text_home'),
23: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
24: | ];
25: |
26: | $data['breadcrumbs'][] = [
27: | 'text' => $this->language->get('heading_title'),
28: | 'href' => $this->url->link('report/statistics', 'user_token=' . $this->session->data['user_token'])
29: | ];
30: |
31: | $data['list'] = $this->getList();
32: |
33: | $data['user_token'] = $this->session->data['user_token'];
34: |
35: | $data['header'] = $this->load->controller('common/header');
36: | $data['column_left'] = $this->load->controller('common/column_left');
37: | $data['footer'] = $this->load->controller('common/footer');
38: |
39: | $this->response->setOutput($this->load->view('report/statistics', $data));
40: | }
41: |
42: | /**
43: | * List
44: | *
45: | * @return void
46: | */
47: | public function list(): void {
48: | $this->load->language('report/statistics');
49: |
50: | $this->response->setOutput($this->getList());
51: | }
52: |
53: | /**
54: | * Get List
55: | *
56: | * @return string
57: | */
58: | public function getList(): string {
59: | $data['statistics'] = [];
60: |
61: | $this->load->model('report/statistics');
62: |
63: | $results = $this->model_report_statistics->getStatistics();
64: |
65: | foreach ($results as $result) {
66: | $data['statistics'][] = [
67: | 'name' => $this->language->get('text_' . $result['code']),
68: | 'value' => $result['value'],
69: | 'href' => $this->url->link('report/statistics.' . str_replace('_', '', $result['code']), 'user_token=' . $this->session->data['user_token'])
70: | ];
71: | }
72: |
73: | return $this->load->view('report/statistics_list', $data);
74: | }
75: |
76: | /**
77: | * Order Sale
78: | *
79: | * @return void
80: | */
81: | public function orderSale(): void {
82: | $this->load->language('report/statistics');
83: |
84: | $json = [];
85: |
86: | if (!$this->user->hasPermission('modify', 'report/statistics')) {
87: | $json['error'] = $this->language->get('error_permission');
88: | }
89: |
90: | if (!$json) {
91: | $this->load->model('report/statistics');
92: | $this->load->model('sale/order');
93: |
94: | $this->model_report_statistics->editValue('order_sale', $this->model_sale_order->getTotalSales(['filter_order_status' => implode(',', array_merge($this->config->get('config_complete_status'), $this->config->get('config_processing_status')))]));
95: |
96: | $json['success'] = $this->language->get('text_success');
97: | }
98: |
99: | $this->response->addHeader('Content-Type: application/json');
100: | $this->response->setOutput(json_encode($json));
101: | }
102: |
103: | /**
104: | * Order Processing
105: | *
106: | * @return void
107: | */
108: | public function orderProcessing(): void {
109: | $this->load->language('report/statistics');
110: |
111: | $json = [];
112: |
113: | if (!$this->user->hasPermission('modify', 'report/statistics')) {
114: | $json['error'] = $this->language->get('error_permission');
115: | }
116: |
117: | if (!$json) {
118: | $this->load->model('report/statistics');
119: | $this->load->model('sale/order');
120: |
121: | $this->model_report_statistics->editValue('order_processing', $this->model_sale_order->getTotalOrders(['filter_order_status' => implode(',', $this->config->get('config_processing_status'))]));
122: |
123: | $json['success'] = $this->language->get('text_success');
124: | }
125: |
126: | $this->response->addHeader('Content-Type: application/json');
127: | $this->response->setOutput(json_encode($json));
128: | }
129: |
130: | /**
131: | * Order Complete
132: | *
133: | * @return void
134: | */
135: | public function orderComplete(): void {
136: | $this->load->language('report/statistics');
137: |
138: | $json = [];
139: |
140: | if (!$this->user->hasPermission('modify', 'report/statistics')) {
141: | $json['error'] = $this->language->get('error_permission');
142: | }
143: |
144: | if (!$json) {
145: | $this->load->model('report/statistics');
146: | $this->load->model('sale/order');
147: |
148: | $this->model_report_statistics->editValue('order_complete', $this->model_sale_order->getTotalOrders(['filter_order_status' => implode(',', $this->config->get('config_complete_status'))]));
149: |
150: | $json['success'] = $this->language->get('text_success');
151: | }
152: |
153: | $this->response->addHeader('Content-Type: application/json');
154: | $this->response->setOutput(json_encode($json));
155: | }
156: |
157: | /**
158: | * Order Other
159: | *
160: | * @return void
161: | */
162: | public function orderOther(): void {
163: | $this->load->language('report/statistics');
164: |
165: | $json = [];
166: |
167: | if (!$this->user->hasPermission('modify', 'report/statistics')) {
168: | $json['error'] = $this->language->get('error_permission');
169: | }
170: |
171: | if (!$json) {
172: | $this->load->model('report/statistics');
173: | $this->load->model('localisation/order_status');
174: |
175: | $order_status_data = [];
176: |
177: | $results = $this->model_localisation_order_status->getOrderStatuses();
178: |
179: | foreach ($results as $result) {
180: | if (!in_array($result['order_status_id'], array_merge($this->config->get('config_complete_status'), $this->config->get('config_processing_status')))) {
181: | $order_status_data[] = $result['order_status_id'];
182: | }
183: | }
184: |
185: | $this->load->model('sale/order');
186: |
187: | $this->model_report_statistics->editValue('order_other', $this->model_sale_order->getTotalOrders(['filter_order_status' => implode(',', $order_status_data)]));
188: |
189: | $json['success'] = $this->language->get('text_success');
190: | }
191: |
192: | $this->response->addHeader('Content-Type: application/json');
193: | $this->response->setOutput(json_encode($json));
194: | }
195: |
196: | /**
197: | * Returns
198: | *
199: | * @return void
200: | */
201: | public function returns(): void {
202: | $this->load->language('report/statistics');
203: |
204: | $json = [];
205: |
206: | if (!$this->user->hasPermission('modify', 'report/statistics')) {
207: | $json['error'] = $this->language->get('error_permission');
208: | }
209: |
210: | if (!$json) {
211: | $this->load->model('report/statistics');
212: | $this->load->model('sale/returns');
213: |
214: | $this->model_report_statistics->editValue('return', $this->model_sale_returns->getTotalReturns(['filter_return_status_id' => $this->config->get('config_return_status_id')]));
215: |
216: | $json['success'] = $this->language->get('text_success');
217: | }
218: |
219: | $this->response->addHeader('Content-Type: application/json');
220: | $this->response->setOutput(json_encode($json));
221: | }
222: |
223: | /**
224: | * Product
225: | *
226: | * @return void
227: | */
228: | public function product(): void {
229: | $this->load->language('report/statistics');
230: |
231: | $json = [];
232: |
233: | if (!$this->user->hasPermission('modify', 'report/statistics')) {
234: | $json['error'] = $this->language->get('error_permission');
235: | }
236: |
237: | if (!$json) {
238: | $this->load->model('report/statistics');
239: | $this->load->model('catalog/product');
240: |
241: | $this->model_report_statistics->editValue('product', $this->model_catalog_product->getTotalProducts(['filter_quantity' => 0]));
242: |
243: | $json['success'] = $this->language->get('text_success');
244: | }
245: |
246: | $this->response->addHeader('Content-Type: application/json');
247: | $this->response->setOutput(json_encode($json));
248: | }
249: |
250: | /**
251: | * Review
252: | *
253: | * @return void
254: | */
255: | public function review(): void {
256: | $this->load->language('report/statistics');
257: |
258: | $json = [];
259: |
260: | if (!$this->user->hasPermission('modify', 'report/statistics')) {
261: | $json['error'] = $this->language->get('error_permission');
262: | }
263: |
264: | if (!$json) {
265: | $this->load->model('report/statistics');
266: | $this->load->model('catalog/review');
267: |
268: | $this->model_report_statistics->editValue('review', $this->model_catalog_review->getTotalReviewsAwaitingApproval());
269: |
270: | $json['success'] = $this->language->get('text_success');
271: | }
272: |
273: | $this->response->addHeader('Content-Type: application/json');
274: | $this->response->setOutput(json_encode($json));
275: | }
276: | }
277: |

OpenCart API API documentation generated by ApiGen dev-master