1: <?php
2: namespace Opencart\Admin\Controller\Extension\Opencart\Report;
3: /**
4: * Class Customer Transaction
5: *
6: * @package Opencart\Admin\Controller\Extension\Opencart\Report
7: */
8: class CustomerTransaction extends \Opencart\System\Engine\Controller {
9: /**
10: * Index
11: *
12: * @return void
13: */
14: public function index(): void {
15: $this->load->language('extension/opencart/report/customer_transaction');
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/customer_transaction', 'user_token=' . $this->session->data['user_token'])
34: ];
35:
36: $data['save'] = $this->url->link('extension/opencart/report/customer_transaction.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_customer_transaction_status'] = $this->config->get('report_customer_transaction_status');
40: $data['report_customer_transaction_sort_order'] = $this->config->get('report_customer_transaction_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/customer_transaction_form', $data));
47: }
48:
49: /**
50: * Save
51: *
52: * @return void
53: */
54: public function save(): void {
55: $this->load->language('extension/opencart/report/customer_transaction');
56:
57: $json = [];
58:
59: if (!$this->user->hasPermission('modify', 'extension/opencart/report/customer_transaction')) {
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_customer_transaction', $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: * Report
77: *
78: * @return void
79: */
80: public function report(): void {
81: $this->load->language('extension/opencart/report/customer_transaction');
82:
83: $data['list'] = $this->getReport();
84:
85: $data['user_token'] = $this->session->data['user_token'];
86:
87: $this->response->setOutput($this->load->view('extension/opencart/report/customer_transaction', $data));
88: }
89:
90: /**
91: * List
92: *
93: * @return void
94: */
95: public function list(): void {
96: $this->load->language('extension/opencart/report/customer_transaction');
97:
98: $this->response->setOutput($this->getReport());
99: }
100:
101: /**
102: * Get Report
103: *
104: * @return string
105: */
106: public function getReport(): string {
107: if (isset($this->request->get['filter_date_start'])) {
108: $filter_date_start = $this->request->get['filter_date_start'];
109: } else {
110: $filter_date_start = '';
111: }
112:
113: if (isset($this->request->get['filter_date_end'])) {
114: $filter_date_end = $this->request->get['filter_date_end'];
115: } else {
116: $filter_date_end = '';
117: }
118:
119: if (isset($this->request->get['filter_customer'])) {
120: $filter_customer = $this->request->get['filter_customer'];
121: } else {
122: $filter_customer = '';
123: }
124:
125: if (isset($this->request->get['page'])) {
126: $page = (int)$this->request->get['page'];
127: } else {
128: $page = 1;
129: }
130:
131: $data['customers'] = [];
132:
133: $filter_data = [
134: 'filter_date_start' => $filter_date_start,
135: 'filter_date_end' => $filter_date_end,
136: 'filter_customer' => $filter_customer,
137: 'start' => ($page - 1) * $this->config->get('config_pagination'),
138: 'limit' => $this->config->get('config_pagination')
139: ];
140:
141: $this->load->model('extension/opencart/report/customer_transaction');
142:
143: $customer_total = $this->model_extension_opencart_report_customer_transaction->getTotalTransactions($filter_data);
144:
145: $results = $this->model_extension_opencart_report_customer_transaction->getTransactions($filter_data);
146:
147: foreach ($results as $result) {
148: $data['customers'][] = [
149: 'customer' => $result['customer'],
150: 'email' => $result['email'],
151: 'customer_group' => $result['customer_group'],
152: 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')),
153: 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')),
154: 'edit' => $this->url->link('customer/customer.form', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'])
155: ];
156: }
157:
158: $url = '';
159:
160: if (isset($this->request->get['filter_date_start'])) {
161: $url .= '&filter_date_start=' . $this->request->get['filter_date_start'];
162: }
163:
164: if (isset($this->request->get['filter_date_end'])) {
165: $url .= '&filter_date_end=' . $this->request->get['filter_date_end'];
166: }
167:
168: if (isset($this->request->get['filter_customer'])) {
169: $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']);
170: }
171:
172: $data['pagination'] = $this->load->controller('common/pagination', [
173: 'total' => $customer_total,
174: 'page' => $page,
175: 'limit' => $this->config->get('config_pagination'),
176: 'url' => $this->url->link('extension/opencart/report/customer_transaction.report', 'user_token=' . $this->session->data['user_token'] . '&code=customer_transaction' . $url . '&page={page}')
177: ]);
178:
179: $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_total) ? (($page - 1) * $this->config->get('config_pagination')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination')) > ($customer_total - $this->config->get('config_pagination'))) ? $customer_total : ((($page - 1) * $this->config->get('config_pagination')) + $this->config->get('config_pagination')), $customer_total, ceil($customer_total / $this->config->get('config_pagination')));
180:
181: $data['filter_date_start'] = $filter_date_start;
182: $data['filter_date_end'] = $filter_date_end;
183: $data['filter_customer'] = $filter_customer;
184:
185: $data['user_token'] = $this->session->data['user_token'];
186:
187: return $this->load->view('extension/opencart/report/customer_transaction_list', $data);
188: }
189: }
190: