1: | <?php
|
2: | namespace Opencart\Admin\Controller\Extension\Opencart\Report;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class ProductPurchased extends \Opencart\System\Engine\Controller {
|
9: | |
10: | |
11: | |
12: | |
13: |
|
14: | public function index(): void {
|
15: | $this->load->language('extension/opencart/report/product_purchased');
|
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('text_extension'),
|
28: | 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report')
|
29: | ];
|
30: |
|
31: | $data['breadcrumbs'][] = [
|
32: | 'text' => $this->language->get('heading_title'),
|
33: | 'href' => $this->url->link('extension/opencart/report/product_purchased', 'user_token=' . $this->session->data['user_token'])
|
34: | ];
|
35: |
|
36: | $data['save'] = $this->url->link('extension/opencart/report/product_purchased.save', 'user_token=' . $this->session->data['user_token']);
|
37: | $data['back'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report');
|
38: |
|
39: | $data['report_product_purchased_status'] = $this->config->get('report_product_purchased_status');
|
40: | $data['report_product_purchased_sort_order'] = $this->config->get('report_product_purchased_sort_order');
|
41: |
|
42: | $data['header'] = $this->load->controller('common/header');
|
43: | $data['column_left'] = $this->load->controller('common/column_left');
|
44: | $data['footer'] = $this->load->controller('common/footer');
|
45: |
|
46: | $this->response->setOutput($this->load->view('extension/opencart/report/product_purchased_form', $data));
|
47: | }
|
48: |
|
49: | |
50: | |
51: | |
52: | |
53: |
|
54: | public function save(): void {
|
55: | $this->load->language('extension/opencart/report/product_purchased');
|
56: |
|
57: | $json = [];
|
58: |
|
59: | if (!$this->user->hasPermission('modify', 'extension/opencart/report/product_purchased')) {
|
60: | $json['error'] = $this->language->get('error_permission');
|
61: | }
|
62: |
|
63: | if (!$json) {
|
64: | $this->load->model('setting/setting');
|
65: |
|
66: | $this->model_setting_setting->editSetting('report_product_purchased', $this->request->post);
|
67: |
|
68: | $json['success'] = $this->language->get('text_success');
|
69: | }
|
70: |
|
71: | $this->response->addHeader('Content-Type: application/json');
|
72: | $this->response->setOutput(json_encode($json));
|
73: | }
|
74: |
|
75: | |
76: | |
77: | |
78: | |
79: |
|
80: | public function report(): void {
|
81: | $this->load->language('extension/opencart/report/product_purchased');
|
82: |
|
83: | $data['list'] = $this->getReport();
|
84: |
|
85: | $this->load->model('localisation/order_status');
|
86: |
|
87: | $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
|
88: |
|
89: | $data['user_token'] = $this->session->data['user_token'];
|
90: |
|
91: | $this->response->setOutput($this->load->view('extension/opencart/report/product_purchased', $data));
|
92: | }
|
93: |
|
94: | |
95: | |
96: | |
97: | |
98: |
|
99: | public function list(): void {
|
100: | $this->load->language('extension/opencart/report/product_purchased');
|
101: |
|
102: | $this->response->setOutput($this->getReport());
|
103: | }
|
104: |
|
105: | |
106: | |
107: | |
108: | |
109: |
|
110: | public function getReport(): string {
|
111: | if (isset($this->request->get['filter_date_start'])) {
|
112: | $filter_date_start = $this->request->get['filter_date_start'];
|
113: | } else {
|
114: | $filter_date_start = '';
|
115: | }
|
116: |
|
117: | if (isset($this->request->get['filter_date_end'])) {
|
118: | $filter_date_end = $this->request->get['filter_date_end'];
|
119: | } else {
|
120: | $filter_date_end = '';
|
121: | }
|
122: |
|
123: | if (isset($this->request->get['filter_order_status_id'])) {
|
124: | $filter_order_status_id = (int)$this->request->get['filter_order_status_id'];
|
125: | } else {
|
126: | $filter_order_status_id = 0;
|
127: | }
|
128: |
|
129: | if (isset($this->request->get['page'])) {
|
130: | $page = (int)$this->request->get['page'];
|
131: | } else {
|
132: | $page = 1;
|
133: | }
|
134: |
|
135: | $data['products'] = [];
|
136: |
|
137: | $filter_data = [
|
138: | 'filter_date_start' => $filter_date_start,
|
139: | 'filter_date_end' => $filter_date_end,
|
140: | 'filter_order_status_id' => $filter_order_status_id,
|
141: | 'start' => ($page - 1) * $this->config->get('config_pagination'),
|
142: | 'limit' => $this->config->get('config_pagination')
|
143: | ];
|
144: |
|
145: | $this->load->model('extension/opencart/report/product_purchased');
|
146: |
|
147: | $product_total = $this->model_extension_opencart_report_product_purchased->getTotalPurchased($filter_data);
|
148: |
|
149: | $results = $this->model_extension_opencart_report_product_purchased->getPurchased($filter_data);
|
150: |
|
151: | foreach ($results as $result) {
|
152: | $data['products'][] = [
|
153: | 'name' => $result['name'],
|
154: | 'model' => $result['model'],
|
155: | 'quantity' => $result['quantity'],
|
156: | 'total' => $this->currency->format($result['total'], $this->config->get('config_currency'))
|
157: | ];
|
158: | }
|
159: |
|
160: | $url = '';
|
161: |
|
162: | if (isset($this->request->get['filter_date_start'])) {
|
163: | $url .= '&filter_date_start=' . $this->request->get['filter_date_start'];
|
164: | }
|
165: |
|
166: | if (isset($this->request->get['filter_date_end'])) {
|
167: | $url .= '&filter_date_end=' . $this->request->get['filter_date_end'];
|
168: | }
|
169: |
|
170: | if (isset($this->request->get['filter_order_status_id'])) {
|
171: | $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
|
172: | }
|
173: |
|
174: | $data['pagination'] = $this->load->controller('common/pagination', [
|
175: | 'total' => $product_total,
|
176: | 'page' => $page,
|
177: | 'limit' => $this->config->get('config_pagination'),
|
178: | 'url' => $this->url->link('extension/opencart/report/product_purchased.report', 'user_token=' . $this->session->data['user_token'] . '&code=product_purchased' . $url . '&page={page}')
|
179: | ]);
|
180: |
|
181: | $data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_pagination')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination')) > ($product_total - $this->config->get('config_pagination'))) ? $product_total : ((($page - 1) * $this->config->get('config_pagination')) + $this->config->get('config_pagination')), $product_total, ceil($product_total / $this->config->get('config_pagination')));
|
182: |
|
183: | $data['filter_date_start'] = $filter_date_start;
|
184: | $data['filter_date_end'] = $filter_date_end;
|
185: | $data['filter_order_status_id'] = $filter_order_status_id;
|
186: |
|
187: | $data['user_token'] = $this->session->data['user_token'];
|
188: |
|
189: | return $this->load->view('extension/opencart/report/product_purchased_list', $data);
|
190: | }
|
191: | }
|
192: | |