1: | <?php
2: | namespace Opencart\Admin\Controller\Sale;
3: | /**
4: | * Class Returns
5: | *
6: | * @package Opencart\Admin\Controller\Sale
7: | */
8: | class Returns extends \Opencart\System\Engine\Controller {
9: | /**
10: | * Index
11: | *
12: | * @return void
13: | */
14: | public function index(): void {
15: | $this->load->language('sale/returns');
16: |
17: | $this->document->setTitle($this->language->get('heading_title'));
18: |
19: | if (isset($this->request->get['filter_return_id'])) {
20: | $filter_return_id = (int)$this->request->get['filter_return_id'];
21: | } else {
22: | $filter_return_id = '';
23: | }
24: |
25: | if (isset($this->request->get['filter_order_id'])) {
26: | $filter_order_id = (int)$this->request->get['filter_order_id'];
27: | } else {
28: | $filter_order_id = '';
29: | }
30: |
31: | if (isset($this->request->get['filter_customer'])) {
32: | $filter_customer = $this->request->get['filter_customer'];
33: | } else {
34: | $filter_customer = '';
35: | }
36: |
37: | if (isset($this->request->get['filter_product'])) {
38: | $filter_product = $this->request->get['filter_product'];
39: | } else {
40: | $filter_product = '';
41: | }
42: |
43: | if (isset($this->request->get['filter_model'])) {
44: | $filter_model = $this->request->get['filter_model'];
45: | } else {
46: | $filter_model = '';
47: | }
48: |
49: | if (isset($this->request->get['filter_return_status_id'])) {
50: | $filter_return_status_id = (int)$this->request->get['filter_return_status_id'];
51: | } else {
52: | $filter_return_status_id = '';
53: | }
54: |
55: | if (isset($this->request->get['filter_date_from'])) {
56: | $filter_date_from = $this->request->get['filter_date_from'];
57: | } else {
58: | $filter_date_from = '';
59: | }
60: |
61: | if (isset($this->request->get['filter_date_to'])) {
62: | $filter_date_to = $this->request->get['filter_date_to'];
63: | } else {
64: | $filter_date_to = '';
65: | }
66: |
67: | $url = '';
68: |
69: | if (isset($this->request->get['filter_return_id'])) {
70: | $url .= '&filter_return_id=' . $this->request->get['filter_return_id'];
71: | }
72: |
73: | if (isset($this->request->get['filter_order_id'])) {
74: | $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
75: | }
76: |
77: | if (isset($this->request->get['filter_customer'])) {
78: | $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
79: | }
80: |
81: | if (isset($this->request->get['filter_product'])) {
82: | $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8'));
83: | }
84: |
85: | if (isset($this->request->get['filter_model'])) {
86: | $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
87: | }
88: |
89: | if (isset($this->request->get['filter_return_status_id'])) {
90: | $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id'];
91: | }
92: |
93: | if (isset($this->request->get['filter_date_from'])) {
94: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
95: | }
96: |
97: | if (isset($this->request->get['filter_date_to'])) {
98: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
99: | }
100: |
101: | if (isset($this->request->get['sort'])) {
102: | $url .= '&sort=' . $this->request->get['sort'];
103: | }
104: |
105: | if (isset($this->request->get['order'])) {
106: | $url .= '&order=' . $this->request->get['order'];
107: | }
108: |
109: | if (isset($this->request->get['page'])) {
110: | $url .= '&page=' . $this->request->get['page'];
111: | }
112: |
113: | $data['breadcrumbs'] = [];
114: |
115: | $data['breadcrumbs'][] = [
116: | 'text' => $this->language->get('text_home'),
117: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
118: | ];
119: |
120: | $data['breadcrumbs'][] = [
121: | 'text' => $this->language->get('heading_title'),
122: | 'href' => $this->url->link('sale/returns', 'user_token=' . $this->session->data['user_token'] . $url)
123: | ];
124: |
125: | $data['add'] = $this->url->link('sale/returns.form', 'user_token=' . $this->session->data['user_token'] . $url);
126: | $data['delete'] = $this->url->link('sale/returns.delete', 'user_token=' . $this->session->data['user_token']);
127: |
128: | $data['list'] = $this->getList();
129: |
130: | $this->load->model('localisation/return_status');
131: |
132: | $data['return_statuses'] = $this->model_localisation_return_status->getReturnStatuses();
133: |
134: | $data['filter_return_id'] = $filter_return_id;
135: | $data['filter_order_id'] = $filter_order_id;
136: | $data['filter_customer'] = $filter_customer;
137: | $data['filter_product'] = $filter_product;
138: | $data['filter_model'] = $filter_model;
139: | $data['filter_return_status_id'] = $filter_return_status_id;
140: | $data['filter_date_from'] = $filter_date_from;
141: | $data['filter_date_to'] = $filter_date_to;
142: |
143: | $data['user_token'] = $this->session->data['user_token'];
144: |
145: | $data['header'] = $this->load->controller('common/header');
146: | $data['column_left'] = $this->load->controller('common/column_left');
147: | $data['footer'] = $this->load->controller('common/footer');
148: |
149: | $this->response->setOutput($this->load->view('sale/returns', $data));
150: | }
151: |
152: | /**
153: | * List
154: | *
155: | * @return void
156: | */
157: | public function list(): void {
158: | $this->load->language('sale/returns');
159: |
160: | $this->response->setOutput($this->getList());
161: | }
162: |
163: | /**
164: | * Get List
165: | *
166: | * @return string
167: | */
168: | protected function getList(): string {
169: | if (isset($this->request->get['filter_return_id'])) {
170: | $filter_return_id = (int)$this->request->get['filter_return_id'];
171: | } else {
172: | $filter_return_id = '';
173: | }
174: |
175: | if (isset($this->request->get['filter_order_id'])) {
176: | $filter_order_id = (int)$this->request->get['filter_order_id'];
177: | } else {
178: | $filter_order_id = '';
179: | }
180: |
181: | if (isset($this->request->get['filter_customer'])) {
182: | $filter_customer = $this->request->get['filter_customer'];
183: | } else {
184: | $filter_customer = '';
185: | }
186: |
187: | if (isset($this->request->get['filter_product'])) {
188: | $filter_product = $this->request->get['filter_product'];
189: | } else {
190: | $filter_product = '';
191: | }
192: |
193: | if (isset($this->request->get['filter_model'])) {
194: | $filter_model = $this->request->get['filter_model'];
195: | } else {
196: | $filter_model = '';
197: | }
198: |
199: | if (isset($this->request->get['filter_return_status_id'])) {
200: | $filter_return_status_id = (int)$this->request->get['filter_return_status_id'];
201: | } else {
202: | $filter_return_status_id = '';
203: | }
204: |
205: | if (isset($this->request->get['filter_date_from'])) {
206: | $filter_date_from = $this->request->get['filter_date_from'];
207: | } else {
208: | $filter_date_from = '';
209: | }
210: |
211: | if (isset($this->request->get['filter_date_to'])) {
212: | $filter_date_to = $this->request->get['filter_date_to'];
213: | } else {
214: | $filter_date_to = '';
215: | }
216: |
217: | if (isset($this->request->get['sort'])) {
218: | $sort = (string)$this->request->get['sort'];
219: | } else {
220: | $sort = 'r.return_id';
221: | }
222: |
223: | if (isset($this->request->get['order'])) {
224: | $order = (string)$this->request->get['order'];
225: | } else {
226: | $order = 'DESC';
227: | }
228: |
229: | if (isset($this->request->get['page'])) {
230: | $page = (int)$this->request->get['page'];
231: | } else {
232: | $page = 1;
233: | }
234: |
235: | $url = '';
236: |
237: | if (isset($this->request->get['filter_return_id'])) {
238: | $url .= '&filter_return_id=' . $this->request->get['filter_return_id'];
239: | }
240: |
241: | if (isset($this->request->get['filter_order_id'])) {
242: | $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
243: | }
244: |
245: | if (isset($this->request->get['filter_customer'])) {
246: | $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
247: | }
248: |
249: | if (isset($this->request->get['filter_product'])) {
250: | $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8'));
251: | }
252: |
253: | if (isset($this->request->get['filter_model'])) {
254: | $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
255: | }
256: |
257: | if (isset($this->request->get['filter_return_status_id'])) {
258: | $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id'];
259: | }
260: |
261: | if (isset($this->request->get['filter_date_from'])) {
262: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
263: | }
264: |
265: | if (isset($this->request->get['filter_date_to'])) {
266: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
267: | }
268: |
269: | if (isset($this->request->get['sort'])) {
270: | $url .= '&sort=' . $this->request->get['sort'];
271: | }
272: |
273: | if (isset($this->request->get['order'])) {
274: | $url .= '&order=' . $this->request->get['order'];
275: | }
276: |
277: | if (isset($this->request->get['page'])) {
278: | $url .= '&page=' . $this->request->get['page'];
279: | }
280: |
281: | $data['action'] = $this->url->link('sale/returns.list', 'user_token=' . $this->session->data['user_token'] . $url);
282: |
283: | $data['returns'] = [];
284: |
285: | $filter_data = [
286: | 'filter_return_id' => $filter_return_id,
287: | 'filter_order_id' => $filter_order_id,
288: | 'filter_customer' => $filter_customer,
289: | 'filter_product' => $filter_product,
290: | 'filter_model' => $filter_model,
291: | 'filter_return_status_id' => $filter_return_status_id,
292: | 'filter_date_from' => $filter_date_from,
293: | 'filter_date_to' => $filter_date_to,
294: | 'sort' => $sort,
295: | 'order' => $order,
296: | 'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
297: | 'limit' => $this->config->get('config_pagination_admin')
298: | ];
299: |
300: | $this->load->model('sale/returns');
301: |
302: | $results = $this->model_sale_returns->getReturns($filter_data);
303: |
304: | foreach ($results as $result) {
305: | $data['returns'][] = [
306: | 'return_id' => $result['return_id'],
307: | 'order_id' => $result['order_id'],
308: | 'customer' => $result['customer'],
309: | 'product' => $result['product'],
310: | 'model' => $result['model'],
311: | 'return_status' => $result['return_status'],
312: | 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
313: | 'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])),
314: | 'edit' => $this->url->link('sale/returns.form', 'user_token=' . $this->session->data['user_token'] . '&return_id=' . $result['return_id'] . $url)
315: | ];
316: | }
317: |
318: | $url = '';
319: |
320: | if (isset($this->request->get['filter_return_id'])) {
321: | $url .= '&filter_return_id=' . $this->request->get['filter_return_id'];
322: | }
323: |
324: | if (isset($this->request->get['filter_order_id'])) {
325: | $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
326: | }
327: |
328: | if (isset($this->request->get['filter_customer'])) {
329: | $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
330: | }
331: |
332: | if (isset($this->request->get['filter_product'])) {
333: | $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8'));
334: | }
335: |
336: | if (isset($this->request->get['filter_model'])) {
337: | $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
338: | }
339: |
340: | if (isset($this->request->get['filter_return_status_id'])) {
341: | $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id'];
342: | }
343: |
344: | if (isset($this->request->get['filter_date_from'])) {
345: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
346: | }
347: |
348: | if (isset($this->request->get['filter_date_to'])) {
349: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
350: | }
351: |
352: | if ($order == 'ASC') {
353: | $url .= '&order=DESC';
354: | } else {
355: | $url .= '&order=ASC';
356: | }
357: |
358: | $data['sort_return_id'] = $this->url->link('sale/returns.list', 'user_token=' . $this->session->data['user_token'] . '&sort=r.return_id' . $url);
359: | $data['sort_order_id'] = $this->url->link('sale/returns.list', 'user_token=' . $this->session->data['user_token'] . '&sort=r.order_id' . $url);
360: | $data['sort_customer'] = $this->url->link('sale/returns.list', 'user_token=' . $this->session->data['user_token'] . '&sort=customer' . $url);
361: | $data['sort_product'] = $this->url->link('sale/returns.list', 'user_token=' . $this->session->data['user_token'] . '&sort=r.product' . $url);
362: | $data['sort_model'] = $this->url->link('sale/returns.list', 'user_token=' . $this->session->data['user_token'] . '&sort=r.model' . $url);
363: | $data['sort_status'] = $this->url->link('sale/returns.list', 'user_token=' . $this->session->data['user_token'] . '&sort=return_status' . $url);
364: | $data['sort_date_added'] = $this->url->link('sale/returns.list', 'user_token=' . $this->session->data['user_token'] . '&sort=r.date_added' . $url);
365: | $data['sort_date_modified'] = $this->url->link('sale/returns.list', 'user_token=' . $this->session->data['user_token'] . '&sort=r.date_modified' . $url);
366: |
367: | $url = '';
368: |
369: | if (isset($this->request->get['filter_return_id'])) {
370: | $url .= '&filter_return_id=' . $this->request->get['filter_return_id'];
371: | }
372: |
373: | if (isset($this->request->get['filter_order_id'])) {
374: | $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
375: | }
376: |
377: | if (isset($this->request->get['filter_customer'])) {
378: | $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
379: | }
380: |
381: | if (isset($this->request->get['filter_product'])) {
382: | $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8'));
383: | }
384: |
385: | if (isset($this->request->get['filter_model'])) {
386: | $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
387: | }
388: |
389: | if (isset($this->request->get['filter_return_status_id'])) {
390: | $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id'];
391: | }
392: |
393: | if (isset($this->request->get['filter_date_from'])) {
394: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
395: | }
396: |
397: | if (isset($this->request->get['filter_date_to'])) {
398: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
399: | }
400: |
401: | if (isset($this->request->get['sort'])) {
402: | $url .= '&sort=' . $this->request->get['sort'];
403: | }
404: |
405: | if (isset($this->request->get['order'])) {
406: | $url .= '&order=' . $this->request->get['order'];
407: | }
408: |
409: | $return_total = $this->model_sale_returns->getTotalReturns($filter_data);
410: |
411: | $data['pagination'] = $this->load->controller('common/pagination', [
412: | 'total' => $return_total,
413: | 'page' => $page,
414: | 'limit' => $this->config->get('config_pagination_admin'),
415: | 'url' => $this->url->link('sale/returns.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
416: | ]);
417: |
418: | $data['results'] = sprintf($this->language->get('text_pagination'), ($return_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($return_total - $this->config->get('config_pagination_admin'))) ? $return_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $return_total, ceil($return_total / $this->config->get('config_pagination_admin')));
419: |
420: | $data['sort'] = $sort;
421: | $data['order'] = $order;
422: |
423: | return $this->load->view('sale/returns_list', $data);
424: | }
425: |
426: | /**
427: | * Form
428: | *
429: | * @return void
430: | */
431: | public function form(): void {
432: | $this->load->language('sale/returns');
433: |
434: | $this->document->setTitle($this->language->get('heading_title'));
435: |
436: | $data['text_form'] = !isset($this->request->get['return_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
437: |
438: | $url = '';
439: |
440: | if (isset($this->request->get['filter_return_id'])) {
441: | $url .= '&filter_return_id=' . $this->request->get['filter_return_id'];
442: | }
443: |
444: | if (isset($this->request->get['filter_order_id'])) {
445: | $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
446: | }
447: |
448: | if (isset($this->request->get['filter_customer'])) {
449: | $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
450: | }
451: |
452: | if (isset($this->request->get['filter_product'])) {
453: | $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8'));
454: | }
455: |
456: | if (isset($this->request->get['filter_model'])) {
457: | $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
458: | }
459: |
460: | if (isset($this->request->get['filter_return_status_id'])) {
461: | $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id'];
462: | }
463: |
464: | if (isset($this->request->get['filter_date_from'])) {
465: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
466: | }
467: |
468: | if (isset($this->request->get['filter_date_to'])) {
469: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
470: | }
471: |
472: | if (isset($this->request->get['sort'])) {
473: | $url .= '&sort=' . $this->request->get['sort'];
474: | }
475: |
476: | if (isset($this->request->get['order'])) {
477: | $url .= '&order=' . $this->request->get['order'];
478: | }
479: |
480: | if (isset($this->request->get['page'])) {
481: | $url .= '&page=' . $this->request->get['page'];
482: | }
483: |
484: | $data['breadcrumbs'] = [];
485: |
486: | $data['breadcrumbs'][] = [
487: | 'text' => $this->language->get('text_home'),
488: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
489: | ];
490: |
491: | $data['breadcrumbs'][] = [
492: | 'text' => $this->language->get('heading_title'),
493: | 'href' => $this->url->link('sale/returns', 'user_token=' . $this->session->data['user_token'] . $url)
494: | ];
495: |
496: | $data['save'] = $this->url->link('sale/returns.save', 'user_token=' . $this->session->data['user_token']);
497: | $data['back'] = $this->url->link('sale/returns', 'user_token=' . $this->session->data['user_token'] . $url);
498: |
499: | if (isset($this->request->get['return_id'])) {
500: | $this->load->model('sale/returns');
501: |
502: | $return_info = $this->model_sale_returns->getReturn($this->request->get['return_id']);
503: | }
504: |
505: | if (isset($this->request->get['return_id'])) {
506: | $data['return_id'] = (int)$this->request->get['return_id'];
507: | } else {
508: | $data['return_id'] = 0;
509: | }
510: |
511: | if (!empty($return_info)) {
512: | $data['order_id'] = $return_info['order_id'];
513: | } else {
514: | $data['order_id'] = '';
515: | }
516: |
517: | if (!empty($return_info)) {
518: | $data['date_ordered'] = ($return_info['date_ordered'] != '0000-00-00' ? $return_info['date_ordered'] : '');
519: | } else {
520: | $data['date_ordered'] = '';
521: | }
522: |
523: | if (!empty($return_info)) {
524: | $data['customer'] = $return_info['customer'];
525: | } else {
526: | $data['customer'] = '';
527: | }
528: |
529: | if (!empty($return_info)) {
530: | $data['customer_id'] = $return_info['customer_id'];
531: | } else {
532: | $data['customer_id'] = '';
533: | }
534: |
535: | if (!empty($return_info)) {
536: | $data['firstname'] = $return_info['firstname'];
537: | } else {
538: | $data['firstname'] = '';
539: | }
540: |
541: | if (!empty($return_info)) {
542: | $data['lastname'] = $return_info['lastname'];
543: | } else {
544: | $data['lastname'] = '';
545: | }
546: |
547: | if (!empty($return_info)) {
548: | $data['email'] = $return_info['email'];
549: | } else {
550: | $data['email'] = '';
551: | }
552: |
553: | if (!empty($return_info)) {
554: | $data['telephone'] = $return_info['telephone'];
555: | } else {
556: | $data['telephone'] = '';
557: | }
558: |
559: | if (!empty($return_info)) {
560: | $data['product'] = $return_info['product'];
561: | } else {
562: | $data['product'] = '';
563: | }
564: |
565: | if (!empty($return_info)) {
566: | $data['product_id'] = $return_info['product_id'];
567: | } else {
568: | $data['product_id'] = '';
569: | }
570: |
571: | if (!empty($return_info)) {
572: | $data['model'] = $return_info['model'];
573: | } else {
574: | $data['model'] = '';
575: | }
576: |
577: | if (!empty($return_info)) {
578: | $data['quantity'] = $return_info['quantity'];
579: | } else {
580: | $data['quantity'] = '';
581: | }
582: |
583: | if (!empty($return_info)) {
584: | $data['opened'] = $return_info['opened'];
585: | } else {
586: | $data['opened'] = '';
587: | }
588: |
589: | $this->load->model('localisation/return_reason');
590: |
591: | $data['return_reasons'] = $this->model_localisation_return_reason->getReturnReasons();
592: |
593: | if (!empty($return_info)) {
594: | $data['return_reason_id'] = $return_info['return_reason_id'];
595: | } else {
596: | $data['return_reason_id'] = 0;
597: | }
598: |
599: | $this->load->model('localisation/return_action');
600: |
601: | $data['return_actions'] = $this->model_localisation_return_action->getReturnActions();
602: |
603: | if (!empty($return_info)) {
604: | $data['return_action_id'] = $return_info['return_action_id'];
605: | } else {
606: | $data['return_action_id'] = 0;
607: | }
608: |
609: | if (!empty($return_info)) {
610: | $data['comment'] = $return_info['comment'];
611: | } else {
612: | $data['comment'] = '';
613: | }
614: |
615: | $this->load->model('localisation/return_status');
616: |
617: | $data['return_statuses'] = $this->model_localisation_return_status->getReturnStatuses();
618: |
619: | if (!empty($return_info)) {
620: | $data['return_status_id'] = $return_info['return_status_id'];
621: | } else {
622: | $data['return_status_id'] = '';
623: | }
624: |
625: | $data['history'] = $this->getHistory();
626: |
627: | $data['user_token'] = $this->session->data['user_token'];
628: |
629: | $data['header'] = $this->load->controller('common/header');
630: | $data['column_left'] = $this->load->controller('common/column_left');
631: | $data['footer'] = $this->load->controller('common/footer');
632: |
633: | $this->response->setOutput($this->load->view('sale/returns_form', $data));
634: | }
635: |
636: | /**
637: | * Save
638: | *
639: | * @return void
640: | */
641: | public function save(): void {
642: | $this->load->language('sale/returns');
643: |
644: | $json = [];
645: |
646: | if (!$this->user->hasPermission('modify', 'sale/returns')) {
647: | $json['error']['warning'] = $this->language->get('error_permission');
648: | }
649: |
650: | if (empty($this->request->post['order_id'])) {
651: | $json['error']['order_id'] = $this->language->get('error_order_id');
652: | }
653: |
654: | if (!oc_validate_length($this->request->post['firstname'], 1, 32)) {
655: | $json['error']['firstname'] = $this->language->get('error_firstname');
656: | }
657: |
658: | if (!oc_validate_length($this->request->post['lastname'], 1, 32)) {
659: | $json['error']['lastname'] = $this->language->get('error_lastname');
660: | }
661: |
662: | if ((oc_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) {
663: | $json['error']['email'] = $this->language->get('error_email');
664: | }
665: |
666: | if (!oc_validate_length($this->request->post['telephone'], 3, 32)) {
667: | $json['error']['telephone'] = $this->language->get('error_telephone');
668: | }
669: |
670: | if (!oc_validate_length($this->request->post['product'], 1, 255)) {
671: | $json['error']['product'] = $this->language->get('error_product');
672: | }
673: |
674: | if (!oc_validate_length($this->request->post['model'], 1, 64)) {
675: | $json['error']['model'] = $this->language->get('error_model');
676: | }
677: |
678: | if (empty($this->request->post['return_reason_id'])) {
679: | $json['error']['reason'] = $this->language->get('error_reason');
680: | }
681: |
682: | if (isset($json['error']) && !isset($json['error']['warning'])) {
683: | $json['error']['warning'] = $this->language->get('error_warning');
684: | }
685: |
686: | if (!$json) {
687: | $this->load->model('sale/returns');
688: |
689: | if (!$this->request->post['return_id']) {
690: | $json['return_id'] = $this->model_sale_returns->addReturn($this->request->post);
691: | } else {
692: | $this->model_sale_returns->editReturn($this->request->post['return_id'], $this->request->post);
693: | }
694: |
695: | $json['success'] = $this->language->get('text_success');
696: | }
697: |
698: | $this->response->addHeader('Content-Type: application/json');
699: | $this->response->setOutput(json_encode($json));
700: | }
701: |
702: | /**
703: | * Delete
704: | *
705: | * @return void
706: | */
707: | public function delete(): void {
708: | $this->load->language('sale/returns');
709: |
710: | $json = [];
711: |
712: | if (isset($this->request->post['selected'])) {
713: | $selected = $this->request->post['selected'];
714: | } else {
715: | $selected = [];
716: | }
717: |
718: | if (!$this->user->hasPermission('modify', 'sale/returns')) {
719: | $json['error'] = $this->language->get('error_permission');
720: | }
721: |
722: | if (!$json) {
723: | $this->load->model('sale/returns');
724: |
725: | foreach ($selected as $return_id) {
726: | $this->model_sale_returns->deleteReturn($return_id);
727: | }
728: |
729: | $json['success'] = $this->language->get('text_success');
730: | }
731: |
732: | $this->response->addHeader('Content-Type: application/json');
733: | $this->response->setOutput(json_encode($json));
734: | }
735: |
736: | /**
737: | * History
738: | *
739: | * @return void
740: | */
741: | public function history(): void {
742: | $this->load->language('sale/returns');
743: |
744: | $this->response->setOutput($this->getHistory());
745: | }
746: |
747: | /**
748: | * Get History
749: | *
750: | * @return string
751: | */
752: | public function getHistory(): string {
753: | if (isset($this->request->get['return_id'])) {
754: | $return_id = (int)$this->request->get['return_id'];
755: | } else {
756: | $return_id = 0;
757: | }
758: |
759: | if (isset($this->request->get['page']) && $this->request->get['route'] == 'sale/returns.history') {
760: | $page = (int)$this->request->get['page'];
761: | } else {
762: | $page = 1;
763: | }
764: |
765: | $limit = 10;
766: |
767: | $data['histories'] = [];
768: |
769: | $this->load->model('sale/returns');
770: |
771: | $results = $this->model_sale_returns->getHistories($return_id, ($page - 1) * $limit, $limit);
772: |
773: | foreach ($results as $result) {
774: | $data['histories'][] = [
775: | 'notify' => $result['notify'] ? $this->language->get('text_yes') : $this->language->get('text_no'),
776: | 'status' => $result['status'],
777: | 'comment' => nl2br($result['comment']),
778: | 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
779: | ];
780: | }
781: |
782: | $history_total = $this->model_sale_returns->getTotalHistories($return_id);
783: |
784: | $data['pagination'] = $this->load->controller('common/pagination', [
785: | 'total' => $history_total,
786: | 'page' => $page,
787: | 'limit' => $limit,
788: | 'url' => $this->url->link('sale/returns.history', 'user_token=' . $this->session->data['user_token'] . '&return_id=' . $return_id . '&page={page}')
789: | ]);
790: |
791: | $data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($history_total - $limit)) ? $history_total : ((($page - 1) * $limit) + $limit), $history_total, ceil($history_total / $limit));
792: |
793: | return $this->load->view('sale/returns_history', $data);
794: | }
795: |
796: | /**
797: | * Add History
798: | *
799: | * @return void
800: | */
801: | public function addHistory(): void {
802: | $this->load->language('sale/returns');
803: |
804: | $json = [];
805: |
806: | if (isset($this->request->get['return_id'])) {
807: | $return_id = (int)$this->request->get['return_id'];
808: | } else {
809: | $return_id = 0;
810: | }
811: |
812: | if (!$this->user->hasPermission('modify', 'sale/returns')) {
813: | $json['error'] = $this->language->get('error_permission');
814: | }
815: |
816: | $this->load->model('sale/returns');
817: |
818: | $return_info = $this->model_sale_returns->getReturn($return_id);
819: |
820: | if (!$return_info) {
821: | $json['error'] = $this->language->get('error_return');
822: | }
823: |
824: | if (!$json) {
825: | $this->model_sale_returns->addHistory($return_id, $this->request->post['return_status_id'], $this->request->post['comment'], $this->request->post['notify']);
826: |
827: | $json['success'] = $this->language->get('text_success');
828: | }
829: |
830: | $this->response->addHeader('Content-Type: application/json');
831: | $this->response->setOutput(json_encode($json));
832: | }
833: | }
834: |

OpenCart API API documentation generated by ApiGen dev-master