1: | <?php
2: | namespace Opencart\Admin\Controller\Extension\Opencart\Report;
3: | /**
4: | * Class Subscription
5: | *
6: | * @package Opencart\Admin\Controller\Extension\Opencart\Report
7: | */
8: | class Subscription 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/subscription');
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/subscription', 'user_token=' . $this->session->data['user_token'])
34: | ];
35: |
36: | $data['save'] = $this->url->link('extension/opencart/report/subscription.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_subscription_status'] = $this->config->get('report_subscription_status');
40: | $data['report_subscription_sort_order'] = $this->config->get('report_subscription_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/subscription_form', $data));
47: | }
48: |
49: | /**
50: | * Save
51: | *
52: | * @return void
53: | */
54: | public function save(): void {
55: | $this->load->language('extension/opencart/report/subscription');
56: |
57: | $json = [];
58: |
59: | if (!$this->user->hasPermission('modify', 'extension/opencart/report/subscription')) {
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_subscription', $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/subscription');
82: |
83: | $data['list'] = $this->getReport();
84: |
85: | $this->load->model('localisation/subscription_status');
86: |
87: | $data['subscription_statuses'] = $this->model_localisation_subscription_status->getSubscriptionStatuses();
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/subscription', $data));
114: | }
115: |
116: | /**
117: | * List
118: | *
119: | * @return void
120: | */
121: | public function list(): void {
122: | $this->load->language('extension/opencart/report/subscription');
123: |
124: | $this->response->setOutput($this->getReport());
125: | }
126: |
127: | /**
128: | * Get Report
129: | *
130: | * @return string
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 = date('Y-m-d', strtotime(date('Y') . '-' . date('m') . '-01'));
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 = date('Y-m-d');
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_subscription_status_id'])) {
152: | $filter_subscription_status_id = (int)$this->request->get['filter_subscription_status_id'];
153: | } else {
154: | $filter_subscription_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['subscriptions'] = [];
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_subscription_status_id' => $filter_subscription_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/subscription');
175: |
176: | $subscription_total = $this->model_extension_opencart_report_subscription->getTotalSubscriptions($filter_data);
177: |
178: | $results = $this->model_extension_opencart_report_subscription->getSubscriptions($filter_data);
179: |
180: | foreach ($results as $result) {
181: | $data['subscriptions'][] = [
182: | 'date_start' => date($this->language->get('date_format_short'), strtotime($result['date_start'])),
183: | 'date_end' => date($this->language->get('date_format_short'), strtotime($result['date_end'])),
184: | 'subscriptions' => $result['subscriptions'],
185: | 'products' => $result['products'],
186: | 'tax' => $this->currency->format((float)$result['tax'], $this->config->get('config_currency')),
187: | 'total' => $this->currency->format((float)$result['total'], $this->config->get('config_currency'))
188: | ];
189: | }
190: |
191: | $url = '';
192: |
193: | if (isset($this->request->get['filter_date_start'])) {
194: | $url .= '&filter_date_start=' . $this->request->get['filter_date_start'];
195: | }
196: |
197: | if (isset($this->request->get['filter_date_end'])) {
198: | $url .= '&filter_date_end=' . $this->request->get['filter_date_end'];
199: | }
200: |
201: | if (isset($this->request->get['filter_group'])) {
202: | $url .= '&filter_group=' . $this->request->get['filter_group'];
203: | }
204: |
205: | if (isset($this->request->get['filter_subscription_status_id'])) {
206: | $url .= '&filter_subscription_status_id=' . $this->request->get['filter_subscription_status_id'];
207: | }
208: |
209: | $data['pagination'] = $this->load->controller('common/pagination', [
210: | 'total' => $subscription_total,
211: | 'page' => $page,
212: | 'limit' => $this->config->get('config_pagination'),
213: | 'url' => $this->url->link('extension/opencart/report/subscription', 'user_token=' . $this->session->data['user_token'] . '&code=subscription' . $url . '&page={page}')
214: | ]);
215: |
216: | $data['results'] = sprintf($this->language->get('text_pagination'), ($subscription_total) ? (($page - 1) * $this->config->get('config_pagination')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination')) > ($subscription_total - $this->config->get('config_pagination'))) ? $subscription_total : ((($page - 1) * $this->config->get('config_pagination')) + $this->config->get('config_pagination')), $subscription_total, ceil($subscription_total / $this->config->get('config_pagination')));
217: |
218: | $data['filter_date_start'] = $filter_date_start;
219: | $data['filter_date_end'] = $filter_date_end;
220: | $data['filter_group'] = $filter_group;
221: | $data['filter_subscription_status_id'] = $filter_subscription_status_id;
222: |
223: | $data['user_token'] = $this->session->data['user_token'];
224: |
225: | return $this->load->view('extension/opencart/report/subscription_list', $data);
226: | }
227: | }
228: |

OpenCart API API documentation generated by ApiGen dev-master