1: | <?php
|
2: | namespace Opencart\Admin\Controller\Extension\Opencart\Report;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class SaleTax extends \Opencart\System\Engine\Controller {
|
9: | |
10: | |
11: | |
12: | |
13: |
|
14: | public function index(): void {
|
15: | $this->load->language('extension/opencart/report/sale_tax');
|
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/sale_tax', 'user_token=' . $this->session->data['user_token'])
|
34: | ];
|
35: |
|
36: | $data['save'] = $this->url->link('extension/opencart/report/sale_tax.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_sale_tax_status'] = $this->config->get('report_sale_tax_status');
|
40: | $data['report_sale_tax_sort_order'] = $this->config->get('report_sale_tax_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/sale_tax_form', $data));
|
47: | }
|
48: |
|
49: | |
50: | |
51: | |
52: | |
53: |
|
54: | public function save(): void {
|
55: | $this->load->language('extension/opencart/report/sale_tax');
|
56: |
|
57: | $json = [];
|
58: |
|
59: | if (!$this->user->hasPermission('modify', 'extension/opencart/report/sale_tax')) {
|
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_sale_tax', $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/sale_tax');
|
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['groups'] = [];
|
90: |
|
91: | $data['groups'][] = [
|
92: | 'text' => $this->language->get('text_year'),
|
93: | 'value' => 'year',
|
94: | ];
|
95: |
|
96: | $data['groups'][] = [
|
97: | 'text' => $this->language->get('text_month'),
|
98: | 'value' => 'month',
|
99: | ];
|
100: |
|
101: | $data['groups'][] = [
|
102: | 'text' => $this->language->get('text_week'),
|
103: | 'value' => 'week',
|
104: | ];
|
105: |
|
106: | $data['groups'][] = [
|
107: | 'text' => $this->language->get('text_day'),
|
108: | 'value' => 'day',
|
109: | ];
|
110: |
|
111: | $data['user_token'] = $this->session->data['user_token'];
|
112: |
|
113: | $this->response->setOutput($this->load->view('extension/opencart/report/sale_tax', $data));
|
114: | }
|
115: |
|
116: | |
117: | |
118: | |
119: | |
120: |
|
121: | public function list(): void {
|
122: | $this->load->language('extension/opencart/report/sale_tax');
|
123: |
|
124: | $this->response->setOutput($this->getReport());
|
125: | }
|
126: |
|
127: | |
128: | |
129: | |
130: | |
131: |
|
132: | public function getReport(): string {
|
133: | if (isset($this->request->get['filter_date_start'])) {
|
134: | $filter_date_start = $this->request->get['filter_date_start'];
|
135: | } else {
|
136: | $filter_date_start = '';
|
137: | }
|
138: |
|
139: | if (isset($this->request->get['filter_date_end'])) {
|
140: | $filter_date_end = $this->request->get['filter_date_end'];
|
141: | } else {
|
142: | $filter_date_end = '';
|
143: | }
|
144: |
|
145: | if (isset($this->request->get['filter_group'])) {
|
146: | $filter_group = $this->request->get['filter_group'];
|
147: | } else {
|
148: | $filter_group = 'week';
|
149: | }
|
150: |
|
151: | if (isset($this->request->get['filter_order_status_id'])) {
|
152: | $filter_order_status_id = (int)$this->request->get['filter_order_status_id'];
|
153: | } else {
|
154: | $filter_order_status_id = 0;
|
155: | }
|
156: |
|
157: | if (isset($this->request->get['page'])) {
|
158: | $page = (int)$this->request->get['page'];
|
159: | } else {
|
160: | $page = 1;
|
161: | }
|
162: |
|
163: | $data['orders'] = [];
|
164: |
|
165: | $filter_data = [
|
166: | 'filter_date_start' => $filter_date_start,
|
167: | 'filter_date_end' => $filter_date_end,
|
168: | 'filter_group' => $filter_group,
|
169: | 'filter_order_status_id' => $filter_order_status_id,
|
170: | 'start' => ($page - 1) * $this->config->get('config_pagination'),
|
171: | 'limit' => $this->config->get('config_pagination')
|
172: | ];
|
173: |
|
174: | $this->load->model('extension/opencart/report/sale');
|
175: |
|
176: | $order_total = $this->model_extension_opencart_report_sale->getTotalTaxes($filter_data);
|
177: |
|
178: | $data['orders'] = [];
|
179: |
|
180: | $results = $this->model_extension_opencart_report_sale->getTaxes($filter_data);
|
181: |
|
182: | foreach ($results as $result) {
|
183: | $data['orders'][] = [
|
184: | 'date_start' => date($this->language->get('date_format_short'), strtotime($result['date_start'])),
|
185: | 'date_end' => date($this->language->get('date_format_short'), strtotime($result['date_end'])),
|
186: | 'title' => $result['title'],
|
187: | 'orders' => $result['orders'],
|
188: | 'total' => $this->currency->format($result['total'], $this->config->get('config_currency'))
|
189: | ];
|
190: | }
|
191: |
|
192: | $url = '';
|
193: |
|
194: | if (isset($this->request->get['filter_date_start'])) {
|
195: | $url .= '&filter_date_start=' . $this->request->get['filter_date_start'];
|
196: | }
|
197: |
|
198: | if (isset($this->request->get['filter_date_end'])) {
|
199: | $url .= '&filter_date_end=' . $this->request->get['filter_date_end'];
|
200: | }
|
201: |
|
202: | if (isset($this->request->get['filter_group'])) {
|
203: | $url .= '&filter_group=' . $this->request->get['filter_group'];
|
204: | }
|
205: |
|
206: | if (isset($this->request->get['filter_order_status_id'])) {
|
207: | $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
|
208: | }
|
209: |
|
210: | $data['pagination'] = $this->load->controller('common/pagination', [
|
211: | 'total' => $order_total,
|
212: | 'page' => $page,
|
213: | 'limit' => $this->config->get('config_pagination'),
|
214: | 'url' => $this->url->link('extension/opencart/report/sale_tax.report', 'user_token=' . $this->session->data['user_token'] . '&code=sale_tax' . $url . '&page={page}')
|
215: | ]);
|
216: |
|
217: | $data['results'] = sprintf($this->language->get('text_pagination'), ($order_total) ? (($page - 1) * $this->config->get('config_pagination')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination')) > ($order_total - $this->config->get('config_pagination'))) ? $order_total : ((($page - 1) * $this->config->get('config_pagination')) + $this->config->get('config_pagination')), $order_total, ceil($order_total / $this->config->get('config_pagination')));
|
218: |
|
219: | $data['filter_date_start'] = $filter_date_start;
|
220: | $data['filter_date_end'] = $filter_date_end;
|
221: | $data['filter_group'] = $filter_group;
|
222: | $data['filter_order_status_id'] = $filter_order_status_id;
|
223: |
|
224: | $data['user_token'] = $this->session->data['user_token'];
|
225: |
|
226: | return $this->load->view('extension/opencart/report/sale_tax_list', $data);
|
227: | }
|
228: | }
|
229: | |