1: <?php
2: namespace Opencart\Admin\Controller\Extension\Opencart\Report;
3: /**
4: * CLass Sale Coupon
5: *
6: * @package Opencart\Admin\Controller\Extension\Opencart\Report
7: */
8: class SaleCoupon 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/sale_coupon');
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_coupon', 'user_token=' . $this->session->data['user_token'])
34: ];
35:
36: $data['save'] = $this->url->link('extension/opencart/report/sale_coupon.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_coupon_status'] = $this->config->get('report_sale_coupon_status');
40: $data['report_sale_coupon_sort_order'] = $this->config->get('report_sale_coupon_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_coupon_form', $data));
47: }
48:
49: /**
50: * Save
51: *
52: * @return void
53: */
54: public function save(): void {
55: $this->load->language('extension/opencart/report/sale_coupon');
56:
57: $json = [];
58:
59: if (!$this->user->hasPermission('modify', 'extension/opencart/report/sale_coupon')) {
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_coupon', $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/sale_coupon');
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/sale_coupon', $data));
88: }
89:
90: /**
91: * List
92: *
93: * @return void
94: */
95: public function list(): void {
96: $this->load->language('extension/opencart/report/sale_coupon');
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['page'])) {
120: $page = (int)$this->request->get['page'];
121: } else {
122: $page = 1;
123: }
124:
125: $data['coupons'] = [];
126:
127: $filter_data = [
128: 'filter_date_start' => $filter_date_start,
129: 'filter_date_end' => $filter_date_end,
130: 'start' => ($page - 1) * $this->config->get('config_pagination'),
131: 'limit' => $this->config->get('config_pagination')
132: ];
133:
134: $this->load->model('extension/opencart/report/coupon');
135:
136: $coupon_total = $this->model_extension_opencart_report_coupon->getTotalCoupons($filter_data);
137:
138: $results = $this->model_extension_opencart_report_coupon->getCoupons($filter_data);
139:
140: foreach ($results as $result) {
141: $data['coupons'][] = [
142: 'name' => $result['name'],
143: 'code' => $result['code'],
144: 'orders' => $result['orders'],
145: 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')),
146: 'edit' => $this->url->link('marketing/coupon.edit', 'user_token=' . $this->session->data['user_token'] . '&coupon_id=' . $result['coupon_id'])
147: ];
148: }
149:
150: $url = '';
151:
152: if (isset($this->request->get['filter_date_start'])) {
153: $url .= '&filter_date_start=' . $this->request->get['filter_date_start'];
154: }
155:
156: if (isset($this->request->get['filter_date_end'])) {
157: $url .= '&filter_date_end=' . $this->request->get['filter_date_end'];
158: }
159:
160: $data['pagination'] = $this->load->controller('common/pagination', [
161: 'total' => $coupon_total,
162: 'page' => $page,
163: 'limit' => $this->config->get('config_pagination'),
164: 'url' => $this->url->link('extension/opencart/report/sale_coupon.report', 'user_token=' . $this->session->data['user_token'] . '&code=sale_coupon' . $url . '&page={page}')
165: ]);
166:
167: $data['results'] = sprintf($this->language->get('text_pagination'), ($coupon_total) ? (($page - 1) * $this->config->get('config_pagination')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination')) > ($coupon_total - $this->config->get('config_pagination'))) ? $coupon_total : ((($page - 1) * $this->config->get('config_pagination')) + $this->config->get('config_pagination')), $coupon_total, ceil($coupon_total / $this->config->get('config_pagination')));
168:
169: $data['filter_date_start'] = $filter_date_start;
170: $data['filter_date_end'] = $filter_date_end;
171:
172: $data['user_token'] = $this->session->data['user_token'];
173:
174: return $this->load->view('extension/opencart/report/sale_coupon_list', $data);
175: }
176: }
177: