diff options
Diffstat (limited to 'public/admin/controller/sale')
-rw-r--r-- | public/admin/controller/sale/order.php | 1844 | ||||
-rw-r--r-- | public/admin/controller/sale/recurring.php | 432 | ||||
-rw-r--r-- | public/admin/controller/sale/return.php | 919 | ||||
-rw-r--r-- | public/admin/controller/sale/voucher.php | 679 | ||||
-rw-r--r-- | public/admin/controller/sale/voucher_theme.php | 381 |
5 files changed, 4255 insertions, 0 deletions
diff --git a/public/admin/controller/sale/order.php b/public/admin/controller/sale/order.php new file mode 100644 index 0000000..cc56abc --- /dev/null +++ b/public/admin/controller/sale/order.php @@ -0,0 +1,1844 @@ +<?php +class ControllerSaleOrder extends Controller { + private $error = array(); + + public function index() { + $this->load->language('sale/order'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/order'); + + $this->getList(); + } + + public function add() { + $this->load->language('sale/order'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/order'); + + $this->getForm(); + } + + public function edit() { + $this->load->language('sale/order'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/order'); + + $this->getForm(); + } + + public function delete() { + $this->load->language('sale/order'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_order_status'])) { + $url .= '&filter_order_status=' . $this->request->get['filter_order_status']; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + if (isset($this->request->get['filter_total'])) { + $url .= '&filter_total=' . $this->request->get['filter_total']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['filter_date_modified'])) { + $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + protected function getList() { + if (isset($this->request->get['filter_order_id'])) { + $filter_order_id = $this->request->get['filter_order_id']; + } else { + $filter_order_id = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['filter_order_status'])) { + $filter_order_status = $this->request->get['filter_order_status']; + } else { + $filter_order_status = ''; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $filter_order_status_id = $this->request->get['filter_order_status_id']; + } else { + $filter_order_status_id = ''; + } + + if (isset($this->request->get['filter_total'])) { + $filter_total = $this->request->get['filter_total']; + } else { + $filter_total = ''; + } + + if (isset($this->request->get['filter_date_added'])) { + $filter_date_added = $this->request->get['filter_date_added']; + } else { + $filter_date_added = ''; + } + + if (isset($this->request->get['filter_date_modified'])) { + $filter_date_modified = $this->request->get['filter_date_modified']; + } else { + $filter_date_modified = ''; + } + + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'o.order_id'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'DESC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_order_status'])) { + $url .= '&filter_order_status=' . $this->request->get['filter_order_status']; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + if (isset($this->request->get['filter_total'])) { + $url .= '&filter_total=' . $this->request->get['filter_total']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['filter_date_modified'])) { + $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['invoice'] = $this->url->link('sale/order/invoice', 'user_token=' . $this->session->data['user_token'], true); + $data['shipping'] = $this->url->link('sale/order/shipping', 'user_token=' . $this->session->data['user_token'], true); + $data['add'] = $this->url->link('sale/order/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = str_replace('&', '&', $this->url->link('sale/order/delete', 'user_token=' . $this->session->data['user_token'] . $url, true)); + + $data['orders'] = array(); + + $filter_data = array( + 'filter_order_id' => $filter_order_id, + 'filter_customer' => $filter_customer, + 'filter_order_status' => $filter_order_status, + 'filter_order_status_id' => $filter_order_status_id, + 'filter_total' => $filter_total, + 'filter_date_added' => $filter_date_added, + 'filter_date_modified' => $filter_date_modified, + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $order_total = $this->model_sale_order->getTotalOrders($filter_data); + + $results = $this->model_sale_order->getOrders($filter_data); + + foreach ($results as $result) { + $data['orders'][] = array( + 'order_id' => $result['order_id'], + 'customer' => $result['customer'], + 'order_status' => $result['order_status'] ? $result['order_status'] : $this->language->get('text_missing'), + 'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']), + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])), + 'shipping_code' => $result['shipping_code'], + 'view' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $result['order_id'] . $url, true), + 'edit' => $this->url->link('sale/order/edit', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $result['order_id'] . $url, true) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + if (isset($this->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_order_status'])) { + $url .= '&filter_order_status=' . $this->request->get['filter_order_status']; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + if (isset($this->request->get['filter_total'])) { + $url .= '&filter_total=' . $this->request->get['filter_total']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['filter_date_modified'])) { + $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified']; + } + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_order'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . '&sort=o.order_id' . $url, true); + $data['sort_customer'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . '&sort=customer' . $url, true); + $data['sort_status'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . '&sort=order_status' . $url, true); + $data['sort_total'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . '&sort=o.total' . $url, true); + $data['sort_date_added'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . '&sort=o.date_added' . $url, true); + $data['sort_date_modified'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . '&sort=o.date_modified' . $url, true); + + $url = ''; + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_order_status'])) { + $url .= '&filter_order_status=' . $this->request->get['filter_order_status']; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + if (isset($this->request->get['filter_total'])) { + $url .= '&filter_total=' . $this->request->get['filter_total']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['filter_date_modified'])) { + $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $order_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($order_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($order_total - $this->config->get('config_limit_admin'))) ? $order_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $order_total, ceil($order_total / $this->config->get('config_limit_admin'))); + + $data['filter_order_id'] = $filter_order_id; + $data['filter_customer'] = $filter_customer; + $data['filter_order_status'] = $filter_order_status; + $data['filter_order_status_id'] = $filter_order_status_id; + $data['filter_total'] = $filter_total; + $data['filter_date_added'] = $filter_date_added; + $data['filter_date_modified'] = $filter_date_modified; + + $data['sort'] = $sort; + $data['order'] = $order; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + // API login + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/order_list', $data)); + } + + public function getForm() { + $data['text_form'] = !isset($this->request->get['order_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + $url = ''; + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_order_status'])) { + $url .= '&filter_order_status=' . $this->request->get['filter_order_status']; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + if (isset($this->request->get['filter_total'])) { + $url .= '&filter_total=' . $this->request->get['filter_total']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['filter_date_modified'])) { + $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['cancel'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->get['order_id'])) { + $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']); + } + + if (!empty($order_info)) { + $data['order_id'] = $this->request->get['order_id']; + $data['store_id'] = $order_info['store_id']; + $data['store_url'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + $data['customer'] = $order_info['customer']; + $data['customer_id'] = $order_info['customer_id']; + $data['customer_group_id'] = $order_info['customer_group_id']; + $data['firstname'] = $order_info['firstname']; + $data['lastname'] = $order_info['lastname']; + $data['email'] = $order_info['email']; + $data['telephone'] = $order_info['telephone']; + $data['account_custom_field'] = $order_info['custom_field']; + + $this->load->model('customer/customer'); + + $data['addresses'] = $this->model_customer_customer->getAddresses($order_info['customer_id']); + + $data['payment_firstname'] = $order_info['payment_firstname']; + $data['payment_lastname'] = $order_info['payment_lastname']; + $data['payment_company'] = $order_info['payment_company']; + $data['payment_address_1'] = $order_info['payment_address_1']; + $data['payment_address_2'] = $order_info['payment_address_2']; + $data['payment_city'] = $order_info['payment_city']; + $data['payment_postcode'] = $order_info['payment_postcode']; + $data['payment_country_id'] = $order_info['payment_country_id']; + $data['payment_zone_id'] = $order_info['payment_zone_id']; + $data['payment_custom_field'] = $order_info['payment_custom_field']; + $data['payment_method'] = $order_info['payment_method']; + $data['payment_code'] = $order_info['payment_code']; + + $data['shipping_firstname'] = $order_info['shipping_firstname']; + $data['shipping_lastname'] = $order_info['shipping_lastname']; + $data['shipping_company'] = $order_info['shipping_company']; + $data['shipping_address_1'] = $order_info['shipping_address_1']; + $data['shipping_address_2'] = $order_info['shipping_address_2']; + $data['shipping_city'] = $order_info['shipping_city']; + $data['shipping_postcode'] = $order_info['shipping_postcode']; + $data['shipping_country_id'] = $order_info['shipping_country_id']; + $data['shipping_zone_id'] = $order_info['shipping_zone_id']; + $data['shipping_custom_field'] = $order_info['shipping_custom_field']; + $data['shipping_method'] = $order_info['shipping_method']; + $data['shipping_code'] = $order_info['shipping_code']; + + // Products + $data['order_products'] = array(); + + $products = $this->model_sale_order->getOrderProducts($this->request->get['order_id']); + + foreach ($products as $product) { + $data['order_products'][] = array( + 'product_id' => $product['product_id'], + 'name' => $product['name'], + 'model' => $product['model'], + 'option' => $this->model_sale_order->getOrderOptions($this->request->get['order_id'], $product['order_product_id']), + 'quantity' => $product['quantity'], + 'price' => $product['price'], + 'total' => $product['total'], + 'reward' => $product['reward'] + ); + } + + // Vouchers + $data['order_vouchers'] = $this->model_sale_order->getOrderVouchers($this->request->get['order_id']); + + $data['coupon'] = ''; + $data['voucher'] = ''; + $data['reward'] = ''; + + $data['order_totals'] = array(); + + $order_totals = $this->model_sale_order->getOrderTotals($this->request->get['order_id']); + + foreach ($order_totals as $order_total) { + // If coupon, voucher or reward points + $start = strpos($order_total['title'], '(') + 1; + $end = strrpos($order_total['title'], ')'); + + if ($start && $end) { + $data[$order_total['code']] = substr($order_total['title'], $start, $end - $start); + } + } + + $data['order_status_id'] = $order_info['order_status_id']; + $data['comment'] = $order_info['comment']; + $data['affiliate_id'] = $order_info['affiliate_id']; + $data['affiliate'] = $order_info['affiliate_firstname'] . ' ' . $order_info['affiliate_lastname']; + $data['currency_code'] = $order_info['currency_code']; + } else { + $data['order_id'] = 0; + $data['store_id'] = 0; + $data['store_url'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + $data['customer'] = ''; + $data['customer_id'] = ''; + $data['customer_group_id'] = $this->config->get('config_customer_group_id'); + $data['firstname'] = ''; + $data['lastname'] = ''; + $data['email'] = ''; + $data['telephone'] = ''; + $data['customer_custom_field'] = array(); + + $data['addresses'] = array(); + + $data['payment_firstname'] = ''; + $data['payment_lastname'] = ''; + $data['payment_company'] = ''; + $data['payment_address_1'] = ''; + $data['payment_address_2'] = ''; + $data['payment_city'] = ''; + $data['payment_postcode'] = ''; + $data['payment_country_id'] = ''; + $data['payment_zone_id'] = ''; + $data['payment_custom_field'] = array(); + $data['payment_method'] = ''; + $data['payment_code'] = ''; + + $data['shipping_firstname'] = ''; + $data['shipping_lastname'] = ''; + $data['shipping_company'] = ''; + $data['shipping_address_1'] = ''; + $data['shipping_address_2'] = ''; + $data['shipping_city'] = ''; + $data['shipping_postcode'] = ''; + $data['shipping_country_id'] = ''; + $data['shipping_zone_id'] = ''; + $data['shipping_custom_field'] = array(); + $data['shipping_method'] = ''; + $data['shipping_code'] = ''; + + $data['order_products'] = array(); + $data['order_vouchers'] = array(); + $data['order_totals'] = array(); + + $data['order_status_id'] = $this->config->get('config_order_status_id'); + $data['comment'] = ''; + $data['affiliate_id'] = ''; + $data['affiliate'] = ''; + $data['currency_code'] = $this->config->get('config_currency'); + + $data['coupon'] = ''; + $data['voucher'] = ''; + $data['reward'] = ''; + } + + // Stores + $this->load->model('setting/store'); + + $data['stores'] = array(); + + $data['stores'][] = array( + 'store_id' => 0, + 'name' => $this->language->get('text_default') + ); + + $results = $this->model_setting_store->getStores(); + + foreach ($results as $result) { + $data['stores'][] = array( + 'store_id' => $result['store_id'], + 'name' => $result['name'] + ); + } + + // Customer Groups + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + // Custom Fields + $this->load->model('customer/custom_field'); + + $data['custom_fields'] = array(); + + $filter_data = array( + 'sort' => 'cf.sort_order', + 'order' => 'ASC' + ); + + $custom_fields = $this->model_customer_custom_field->getCustomFields($filter_data); + + foreach ($custom_fields as $custom_field) { + $data['custom_fields'][] = array( + 'custom_field_id' => $custom_field['custom_field_id'], + 'custom_field_value' => $this->model_customer_custom_field->getCustomFieldValues($custom_field['custom_field_id']), + 'name' => $custom_field['name'], + 'value' => $custom_field['value'], + 'type' => $custom_field['type'], + 'location' => $custom_field['location'], + 'sort_order' => $custom_field['sort_order'] + ); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $this->load->model('localisation/country'); + + $data['countries'] = $this->model_localisation_country->getCountries(); + + $this->load->model('localisation/currency'); + + $data['currencies'] = $this->model_localisation_currency->getCurrencies(); + + $data['voucher_min'] = $this->config->get('config_voucher_min'); + + $this->load->model('sale/voucher_theme'); + + $data['voucher_themes'] = $this->model_sale_voucher_theme->getVoucherThemes(); + + // API login + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/order_form', $data)); + } + + public function info() { + $this->load->model('sale/order'); + + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $order_info = $this->model_sale_order->getOrder($order_id); + + if ($order_info) { + $this->load->language('sale/order'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['text_ip_add'] = sprintf($this->language->get('text_ip_add'), $this->request->server['REMOTE_ADDR']); + $data['text_order'] = sprintf($this->language->get('text_order'), $this->request->get['order_id']); + + $url = ''; + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_order_status'])) { + $url .= '&filter_order_status=' . $this->request->get['filter_order_status']; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + if (isset($this->request->get['filter_total'])) { + $url .= '&filter_total=' . $this->request->get['filter_total']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['filter_date_modified'])) { + $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['shipping'] = $this->url->link('sale/order/shipping', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . (int)$this->request->get['order_id'], true); + $data['invoice'] = $this->url->link('sale/order/invoice', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . (int)$this->request->get['order_id'], true); + $data['edit'] = $this->url->link('sale/order/edit', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . (int)$this->request->get['order_id'], true); + $data['cancel'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['user_token'] = $this->session->data['user_token']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['store_id'] = $order_info['store_id']; + $data['store_name'] = $order_info['store_name']; + + if ($order_info['store_id'] == 0) { + $data['store_url'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + } else { + $data['store_url'] = $order_info['store_url']; + } + + if ($order_info['invoice_no']) { + $data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no']; + } else { + $data['invoice_no'] = ''; + } + + $data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added'])); + + $data['firstname'] = $order_info['firstname']; + $data['lastname'] = $order_info['lastname']; + + if ($order_info['customer_id']) { + $data['customer'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $order_info['customer_id'], true); + } else { + $data['customer'] = ''; + } + + $this->load->model('customer/customer_group'); + + $customer_group_info = $this->model_customer_customer_group->getCustomerGroup($order_info['customer_group_id']); + + if ($customer_group_info) { + $data['customer_group'] = $customer_group_info['name']; + } else { + $data['customer_group'] = ''; + } + + $data['email'] = $order_info['email']; + $data['telephone'] = $order_info['telephone']; + + $data['shipping_method'] = $order_info['shipping_method']; + $data['payment_method'] = $order_info['payment_method']; + + // Payment Address + if ($order_info['payment_address_format']) { + $format = $order_info['payment_address_format']; + } else { + $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}'; + } + + $find = array( + '{firstname}', + '{lastname}', + '{company}', + '{address_1}', + '{address_2}', + '{city}', + '{postcode}', + '{zone}', + '{zone_code}', + '{country}' + ); + + $replace = array( + 'firstname' => $order_info['payment_firstname'], + 'lastname' => $order_info['payment_lastname'], + 'company' => $order_info['payment_company'], + 'address_1' => $order_info['payment_address_1'], + 'address_2' => $order_info['payment_address_2'], + 'city' => $order_info['payment_city'], + 'postcode' => $order_info['payment_postcode'], + 'zone' => $order_info['payment_zone'], + 'zone_code' => $order_info['payment_zone_code'], + 'country' => $order_info['payment_country'] + ); + + $data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); + + // Shipping Address + if ($order_info['shipping_address_format']) { + $format = $order_info['shipping_address_format']; + } else { + $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}'; + } + + $find = array( + '{firstname}', + '{lastname}', + '{company}', + '{address_1}', + '{address_2}', + '{city}', + '{postcode}', + '{zone}', + '{zone_code}', + '{country}' + ); + + $replace = array( + 'firstname' => $order_info['shipping_firstname'], + 'lastname' => $order_info['shipping_lastname'], + 'company' => $order_info['shipping_company'], + 'address_1' => $order_info['shipping_address_1'], + 'address_2' => $order_info['shipping_address_2'], + 'city' => $order_info['shipping_city'], + 'postcode' => $order_info['shipping_postcode'], + 'zone' => $order_info['shipping_zone'], + 'zone_code' => $order_info['shipping_zone_code'], + 'country' => $order_info['shipping_country'] + ); + + $data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); + + // Uploaded files + $this->load->model('tool/upload'); + + $data['products'] = array(); + + $products = $this->model_sale_order->getOrderProducts($this->request->get['order_id']); + + foreach ($products as $product) { + $option_data = array(); + + $options = $this->model_sale_order->getOrderOptions($this->request->get['order_id'], $product['order_product_id']); + + foreach ($options as $option) { + if ($option['type'] != 'file') { + $option_data[] = array( + 'name' => $option['name'], + 'value' => $option['value'], + 'type' => $option['type'] + ); + } else { + $upload_info = $this->model_tool_upload->getUploadByCode($option['value']); + + if ($upload_info) { + $option_data[] = array( + 'name' => $option['name'], + 'value' => $upload_info['name'], + 'type' => $option['type'], + 'href' => $this->url->link('tool/upload/download', 'user_token=' . $this->session->data['user_token'] . '&code=' . $upload_info['code'], true) + ); + } + } + } + + $data['products'][] = array( + 'order_product_id' => $product['order_product_id'], + 'product_id' => $product['product_id'], + 'name' => $product['name'], + 'model' => $product['model'], + 'option' => $option_data, + 'quantity' => $product['quantity'], + 'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']), + 'total' => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value']), + 'href' => $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product['product_id'], true) + ); + } + + $data['vouchers'] = array(); + + $vouchers = $this->model_sale_order->getOrderVouchers($this->request->get['order_id']); + + foreach ($vouchers as $voucher) { + $data['vouchers'][] = array( + 'description' => $voucher['description'], + 'amount' => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value']), + 'href' => $this->url->link('sale/voucher/edit', 'user_token=' . $this->session->data['user_token'] . '&voucher_id=' . $voucher['voucher_id'], true) + ); + } + + $data['totals'] = array(); + + $totals = $this->model_sale_order->getOrderTotals($this->request->get['order_id']); + + foreach ($totals as $total) { + $data['totals'][] = array( + 'title' => $total['title'], + 'text' => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']) + ); + } + + $data['comment'] = nl2br($order_info['comment']); + + $this->load->model('customer/customer'); + + $data['reward'] = $order_info['reward']; + + $data['reward_total'] = $this->model_customer_customer->getTotalCustomerRewardsByOrderId($this->request->get['order_id']); + + $data['affiliate_firstname'] = $order_info['affiliate_firstname']; + $data['affiliate_lastname'] = $order_info['affiliate_lastname']; + + if ($order_info['affiliate_id']) { + $data['affiliate'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $order_info['affiliate_id'], true); + } else { + $data['affiliate'] = ''; + } + + $data['commission'] = $this->currency->format($order_info['commission'], $order_info['currency_code'], $order_info['currency_value']); + + $this->load->model('customer/customer'); + + $data['commission_total'] = $this->model_customer_customer->getTotalTransactionsByOrderId($this->request->get['order_id']); + + $this->load->model('localisation/order_status'); + + $order_status_info = $this->model_localisation_order_status->getOrderStatus($order_info['order_status_id']); + + if ($order_status_info) { + $data['order_status'] = $order_status_info['name']; + } else { + $data['order_status'] = ''; + } + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['order_status_id'] = $order_info['order_status_id']; + + $data['account_custom_field'] = $order_info['custom_field']; + + // Custom Fields + $this->load->model('customer/custom_field'); + + $data['account_custom_fields'] = array(); + + $filter_data = array( + 'sort' => 'cf.sort_order', + 'order' => 'ASC' + ); + + $custom_fields = $this->model_customer_custom_field->getCustomFields($filter_data); + + foreach ($custom_fields as $custom_field) { + if ($custom_field['location'] == 'account' && isset($order_info['custom_field'][$custom_field['custom_field_id']])) { + if ($custom_field['type'] == 'select' || $custom_field['type'] == 'radio') { + $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($order_info['custom_field'][$custom_field['custom_field_id']]); + + if ($custom_field_value_info) { + $data['account_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $custom_field_value_info['name'] + ); + } + } + + if ($custom_field['type'] == 'checkbox' && is_array($order_info['custom_field'][$custom_field['custom_field_id']])) { + foreach ($order_info['custom_field'][$custom_field['custom_field_id']] as $custom_field_value_id) { + $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($custom_field_value_id); + + if ($custom_field_value_info) { + $data['account_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $custom_field_value_info['name'] + ); + } + } + } + + if ($custom_field['type'] == 'text' || $custom_field['type'] == 'textarea' || $custom_field['type'] == 'file' || $custom_field['type'] == 'date' || $custom_field['type'] == 'datetime' || $custom_field['type'] == 'time') { + $data['account_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $order_info['custom_field'][$custom_field['custom_field_id']] + ); + } + + if ($custom_field['type'] == 'file') { + $upload_info = $this->model_tool_upload->getUploadByCode($order_info['custom_field'][$custom_field['custom_field_id']]); + + if ($upload_info) { + $data['account_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $upload_info['name'] + ); + } + } + } + } + + // Custom fields + $data['payment_custom_fields'] = array(); + + foreach ($custom_fields as $custom_field) { + if ($custom_field['location'] == 'address' && isset($order_info['payment_custom_field'][$custom_field['custom_field_id']])) { + if ($custom_field['type'] == 'select' || $custom_field['type'] == 'radio') { + $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($order_info['payment_custom_field'][$custom_field['custom_field_id']]); + + if ($custom_field_value_info) { + $data['payment_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $custom_field_value_info['name'], + 'sort_order' => $custom_field['sort_order'] + ); + } + } + + if ($custom_field['type'] == 'checkbox' && is_array($order_info['payment_custom_field'][$custom_field['custom_field_id']])) { + foreach ($order_info['payment_custom_field'][$custom_field['custom_field_id']] as $custom_field_value_id) { + $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($custom_field_value_id); + + if ($custom_field_value_info) { + $data['payment_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $custom_field_value_info['name'], + 'sort_order' => $custom_field['sort_order'] + ); + } + } + } + + if ($custom_field['type'] == 'text' || $custom_field['type'] == 'textarea' || $custom_field['type'] == 'file' || $custom_field['type'] == 'date' || $custom_field['type'] == 'datetime' || $custom_field['type'] == 'time') { + $data['payment_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $order_info['payment_custom_field'][$custom_field['custom_field_id']], + 'sort_order' => $custom_field['sort_order'] + ); + } + + if ($custom_field['type'] == 'file') { + $upload_info = $this->model_tool_upload->getUploadByCode($order_info['payment_custom_field'][$custom_field['custom_field_id']]); + + if ($upload_info) { + $data['payment_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $upload_info['name'], + 'sort_order' => $custom_field['sort_order'] + ); + } + } + } + } + + // Shipping + $data['shipping_custom_fields'] = array(); + + foreach ($custom_fields as $custom_field) { + if ($custom_field['location'] == 'address' && isset($order_info['shipping_custom_field'][$custom_field['custom_field_id']])) { + if ($custom_field['type'] == 'select' || $custom_field['type'] == 'radio') { + $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($order_info['shipping_custom_field'][$custom_field['custom_field_id']]); + + if ($custom_field_value_info) { + $data['shipping_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $custom_field_value_info['name'], + 'sort_order' => $custom_field['sort_order'] + ); + } + } + + if ($custom_field['type'] == 'checkbox' && is_array($order_info['shipping_custom_field'][$custom_field['custom_field_id']])) { + foreach ($order_info['shipping_custom_field'][$custom_field['custom_field_id']] as $custom_field_value_id) { + $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($custom_field_value_id); + + if ($custom_field_value_info) { + $data['shipping_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $custom_field_value_info['name'], + 'sort_order' => $custom_field['sort_order'] + ); + } + } + } + + if ($custom_field['type'] == 'text' || $custom_field['type'] == 'textarea' || $custom_field['type'] == 'file' || $custom_field['type'] == 'date' || $custom_field['type'] == 'datetime' || $custom_field['type'] == 'time') { + $data['shipping_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $order_info['shipping_custom_field'][$custom_field['custom_field_id']], + 'sort_order' => $custom_field['sort_order'] + ); + } + + if ($custom_field['type'] == 'file') { + $upload_info = $this->model_tool_upload->getUploadByCode($order_info['shipping_custom_field'][$custom_field['custom_field_id']]); + + if ($upload_info) { + $data['shipping_custom_fields'][] = array( + 'name' => $custom_field['name'], + 'value' => $upload_info['name'], + 'sort_order' => $custom_field['sort_order'] + ); + } + } + } + } + + $data['ip'] = $order_info['ip']; + $data['forwarded_ip'] = $order_info['forwarded_ip']; + $data['user_agent'] = $order_info['user_agent']; + $data['accept_language'] = $order_info['accept_language']; + + // Additional Tabs + $data['tabs'] = array(); + + if ($this->user->hasPermission('access', 'extension/payment/' . $order_info['payment_code'])) { + if (is_file(DIR_CATALOG . 'controller/extension/payment/' . $order_info['payment_code'] . '.php')) { + $content = $this->load->controller('extension/payment/' . $order_info['payment_code'] . '/order'); + } else { + $content = ''; + } + + if ($content) { + $this->load->language('extension/payment/' . $order_info['payment_code']); + + $data['tabs'][] = array( + 'code' => $order_info['payment_code'], + 'title' => $this->language->get('heading_title'), + 'content' => $content + ); + } + } + + $this->load->model('setting/extension'); + + $extensions = $this->model_setting_extension->getInstalled('fraud'); + + foreach ($extensions as $extension) { + if ($this->config->get('fraud_' . $extension . '_status')) { + $this->load->language('extension/fraud/' . $extension, 'extension'); + + $content = $this->load->controller('extension/fraud/' . $extension . '/order'); + + if ($content) { + $data['tabs'][] = array( + 'code' => $extension, + 'title' => $this->language->get('extension')->get('heading_title'), + 'content' => $content + ); + } + } + } + + // The URL we send API requests to + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/order_info', $data)); + } else { + return new Action('error/not_found'); + } + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'sale/order')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function createInvoiceNo() { + $this->load->language('sale/order'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'sale/order')) { + $json['error'] = $this->language->get('error_permission'); + } elseif (isset($this->request->get['order_id'])) { + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $this->load->model('sale/order'); + + $invoice_no = $this->model_sale_order->createInvoiceNo($order_id); + + if ($invoice_no) { + $json['invoice_no'] = $invoice_no; + } else { + $json['error'] = $this->language->get('error_action'); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function addReward() { + $this->load->language('sale/order'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'sale/order')) { + $json['error'] = $this->language->get('error_permission'); + } else { + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $this->load->model('sale/order'); + + $order_info = $this->model_sale_order->getOrder($order_id); + + if ($order_info && $order_info['customer_id'] && ($order_info['reward'] > 0)) { + $this->load->model('customer/customer'); + + $reward_total = $this->model_customer_customer->getTotalCustomerRewardsByOrderId($order_id); + + if (!$reward_total) { + $this->model_customer_customer->addReward($order_info['customer_id'], $this->language->get('text_order_id') . ' #' . $order_id, $order_info['reward'], $order_id); + } + } + + $json['success'] = $this->language->get('text_reward_added'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function removeReward() { + $this->load->language('sale/order'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'sale/order')) { + $json['error'] = $this->language->get('error_permission'); + } else { + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $this->load->model('sale/order'); + + $order_info = $this->model_sale_order->getOrder($order_id); + + if ($order_info) { + $this->load->model('customer/customer'); + + $this->model_customer_customer->deleteReward($order_id); + } + + $json['success'] = $this->language->get('text_reward_removed'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function addCommission() { + $this->load->language('sale/order'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'sale/order')) { + $json['error'] = $this->language->get('error_permission'); + } else { + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $this->load->model('sale/order'); + + $order_info = $this->model_sale_order->getOrder($order_id); + + if ($order_info) { + $this->load->model('customer/customer'); + + $affiliate_total = $this->model_customer_customer->getTotalTransactionsByOrderId($order_id); + + if (!$affiliate_total) { + $this->model_customer_customer->addTransaction($order_info['affiliate_id'], $this->language->get('text_order_id') . ' #' . $order_id, $order_info['commission'], $order_id); + } + } + + $json['success'] = $this->language->get('text_commission_added'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function removeCommission() { + $this->load->language('sale/order'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'sale/order')) { + $json['error'] = $this->language->get('error_permission'); + } else { + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $this->load->model('sale/order'); + + $order_info = $this->model_sale_order->getOrder($order_id); + + if ($order_info) { + $this->load->model('customer/customer'); + + $this->model_customer_customer->deleteTransactionByOrderId($order_id); + } + + $json['success'] = $this->language->get('text_commission_removed'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function history() { + $this->load->language('sale/order'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['histories'] = array(); + + $this->load->model('sale/order'); + + $results = $this->model_sale_order->getOrderHistories($this->request->get['order_id'], ($page - 1) * 10, 10); + + foreach ($results as $result) { + $data['histories'][] = array( + 'notify' => $result['notify'] ? $this->language->get('text_yes') : $this->language->get('text_no'), + 'status' => $result['status'], + 'comment' => nl2br($result['comment']), + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])) + ); + } + + $history_total = $this->model_sale_order->getTotalOrderHistories($this->request->get['order_id']); + + $pagination = new Pagination(); + $pagination->total = $history_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('sale/order/history', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $this->request->get['order_id'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($history_total - 10)) ? $history_total : ((($page - 1) * 10) + 10), $history_total, ceil($history_total / 10)); + + $this->response->setOutput($this->load->view('sale/order_history', $data)); + } + + public function invoice() { + $this->load->language('sale/order'); + + $data['title'] = $this->language->get('text_invoice'); + + if ($this->request->server['HTTPS']) { + $data['base'] = HTTPS_SERVER; + } else { + $data['base'] = HTTP_SERVER; + } + + $data['direction'] = $this->language->get('direction'); + $data['lang'] = $this->language->get('code'); + + $this->load->model('sale/order'); + + $this->load->model('setting/setting'); + + $data['orders'] = array(); + + $orders = array(); + + if (isset($this->request->post['selected'])) { + $orders = $this->request->post['selected']; + } elseif (isset($this->request->get['order_id'])) { + $orders[] = $this->request->get['order_id']; + } + + foreach ($orders as $order_id) { + $order_info = $this->model_sale_order->getOrder($order_id); + + if ($order_info) { + $store_info = $this->model_setting_setting->getSetting('config', $order_info['store_id']); + + if ($store_info) { + $store_address = $store_info['config_address']; + $store_email = $store_info['config_email']; + $store_telephone = $store_info['config_telephone']; + $store_fax = $store_info['config_fax']; + } else { + $store_address = $this->config->get('config_address'); + $store_email = $this->config->get('config_email'); + $store_telephone = $this->config->get('config_telephone'); + $store_fax = $this->config->get('config_fax'); + } + + if ($order_info['invoice_no']) { + $invoice_no = $order_info['invoice_prefix'] . $order_info['invoice_no']; + } else { + $invoice_no = ''; + } + + if ($order_info['payment_address_format']) { + $format = $order_info['payment_address_format']; + } else { + $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}'; + } + + $find = array( + '{firstname}', + '{lastname}', + '{company}', + '{address_1}', + '{address_2}', + '{city}', + '{postcode}', + '{zone}', + '{zone_code}', + '{country}' + ); + + $replace = array( + 'firstname' => $order_info['payment_firstname'], + 'lastname' => $order_info['payment_lastname'], + 'company' => $order_info['payment_company'], + 'address_1' => $order_info['payment_address_1'], + 'address_2' => $order_info['payment_address_2'], + 'city' => $order_info['payment_city'], + 'postcode' => $order_info['payment_postcode'], + 'zone' => $order_info['payment_zone'], + 'zone_code' => $order_info['payment_zone_code'], + 'country' => $order_info['payment_country'] + ); + + $payment_address = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); + + if ($order_info['shipping_address_format']) { + $format = $order_info['shipping_address_format']; + } else { + $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}'; + } + + $find = array( + '{firstname}', + '{lastname}', + '{company}', + '{address_1}', + '{address_2}', + '{city}', + '{postcode}', + '{zone}', + '{zone_code}', + '{country}' + ); + + $replace = array( + 'firstname' => $order_info['shipping_firstname'], + 'lastname' => $order_info['shipping_lastname'], + 'company' => $order_info['shipping_company'], + 'address_1' => $order_info['shipping_address_1'], + 'address_2' => $order_info['shipping_address_2'], + 'city' => $order_info['shipping_city'], + 'postcode' => $order_info['shipping_postcode'], + 'zone' => $order_info['shipping_zone'], + 'zone_code' => $order_info['shipping_zone_code'], + 'country' => $order_info['shipping_country'] + ); + + $shipping_address = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); + + $this->load->model('tool/upload'); + + $product_data = array(); + + $products = $this->model_sale_order->getOrderProducts($order_id); + + foreach ($products as $product) { + $option_data = array(); + + $options = $this->model_sale_order->getOrderOptions($order_id, $product['order_product_id']); + + foreach ($options as $option) { + if ($option['type'] != 'file') { + $value = $option['value']; + } else { + $upload_info = $this->model_tool_upload->getUploadByCode($option['value']); + + if ($upload_info) { + $value = $upload_info['name']; + } else { + $value = ''; + } + } + + $option_data[] = array( + 'name' => $option['name'], + 'value' => $value + ); + } + + $product_data[] = array( + 'name' => $product['name'], + 'model' => $product['model'], + 'option' => $option_data, + 'quantity' => $product['quantity'], + 'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']), + 'total' => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value']) + ); + } + + $voucher_data = array(); + + $vouchers = $this->model_sale_order->getOrderVouchers($order_id); + + foreach ($vouchers as $voucher) { + $voucher_data[] = array( + 'description' => $voucher['description'], + 'amount' => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value']) + ); + } + + $total_data = array(); + + $totals = $this->model_sale_order->getOrderTotals($order_id); + + foreach ($totals as $total) { + $total_data[] = array( + 'title' => $total['title'], + 'text' => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']) + ); + } + + $data['orders'][] = array( + 'order_id' => $order_id, + 'invoice_no' => $invoice_no, + 'date_added' => date($this->language->get('date_format_short'), strtotime($order_info['date_added'])), + 'store_name' => $order_info['store_name'], + 'store_url' => rtrim($order_info['store_url'], '/'), + 'store_address' => nl2br($store_address), + 'store_email' => $store_email, + 'store_telephone' => $store_telephone, + 'store_fax' => $store_fax, + 'email' => $order_info['email'], + 'telephone' => $order_info['telephone'], + 'shipping_address' => $shipping_address, + 'shipping_method' => $order_info['shipping_method'], + 'payment_address' => $payment_address, + 'payment_method' => $order_info['payment_method'], + 'product' => $product_data, + 'voucher' => $voucher_data, + 'total' => $total_data, + 'comment' => nl2br($order_info['comment']) + ); + } + } + + $this->response->setOutput($this->load->view('sale/order_invoice', $data)); + } + + public function shipping() { + $this->load->language('sale/order'); + + $data['title'] = $this->language->get('text_shipping'); + + if ($this->request->server['HTTPS']) { + $data['base'] = HTTPS_SERVER; + } else { + $data['base'] = HTTP_SERVER; + } + + $data['direction'] = $this->language->get('direction'); + $data['lang'] = $this->language->get('code'); + + $this->load->model('sale/order'); + + $this->load->model('catalog/product'); + + $this->load->model('setting/setting'); + + $data['orders'] = array(); + + $orders = array(); + + if (isset($this->request->post['selected'])) { + $orders = $this->request->post['selected']; + } elseif (isset($this->request->get['order_id'])) { + $orders[] = $this->request->get['order_id']; + } + + foreach ($orders as $order_id) { + $order_info = $this->model_sale_order->getOrder($order_id); + + // Make sure there is a shipping method + if ($order_info && $order_info['shipping_code']) { + $store_info = $this->model_setting_setting->getSetting('config', $order_info['store_id']); + + if ($store_info) { + $store_address = $store_info['config_address']; + $store_email = $store_info['config_email']; + $store_telephone = $store_info['config_telephone']; + } else { + $store_address = $this->config->get('config_address'); + $store_email = $this->config->get('config_email'); + $store_telephone = $this->config->get('config_telephone'); + } + + if ($order_info['invoice_no']) { + $invoice_no = $order_info['invoice_prefix'] . $order_info['invoice_no']; + } else { + $invoice_no = ''; + } + + if ($order_info['shipping_address_format']) { + $format = $order_info['shipping_address_format']; + } else { + $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}'; + } + + $find = array( + '{firstname}', + '{lastname}', + '{company}', + '{address_1}', + '{address_2}', + '{city}', + '{postcode}', + '{zone}', + '{zone_code}', + '{country}' + ); + + $replace = array( + 'firstname' => $order_info['shipping_firstname'], + 'lastname' => $order_info['shipping_lastname'], + 'company' => $order_info['shipping_company'], + 'address_1' => $order_info['shipping_address_1'], + 'address_2' => $order_info['shipping_address_2'], + 'city' => $order_info['shipping_city'], + 'postcode' => $order_info['shipping_postcode'], + 'zone' => $order_info['shipping_zone'], + 'zone_code' => $order_info['shipping_zone_code'], + 'country' => $order_info['shipping_country'] + ); + + $shipping_address = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); + + $this->load->model('tool/upload'); + + $product_data = array(); + + $products = $this->model_sale_order->getOrderProducts($order_id); + + foreach ($products as $product) { + $option_weight = ''; + + $product_info = $this->model_catalog_product->getProduct($product['product_id']); + + if ($product_info) { + $option_data = array(); + + $options = $this->model_sale_order->getOrderOptions($order_id, $product['order_product_id']); + + foreach ($options as $option) { + if ($option['type'] != 'file') { + $value = $option['value']; + } else { + $upload_info = $this->model_tool_upload->getUploadByCode($option['value']); + + if ($upload_info) { + $value = $upload_info['name']; + } else { + $value = ''; + } + } + + $option_data[] = array( + 'name' => $option['name'], + 'value' => $value + ); + + $product_option_value_info = $this->model_catalog_product->getProductOptionValue($product['product_id'], $option['product_option_value_id']); + + if ($product_option_value_info) { + if ($product_option_value_info['weight_prefix'] == '+') { + $option_weight += $product_option_value_info['weight']; + } elseif ($product_option_value_info['weight_prefix'] == '-') { + $option_weight -= $product_option_value_info['weight']; + } + } + } + + $product_data[] = array( + 'name' => $product_info['name'], + 'model' => $product_info['model'], + 'option' => $option_data, + 'quantity' => $product['quantity'], + 'location' => $product_info['location'], + 'sku' => $product_info['sku'], + 'upc' => $product_info['upc'], + 'ean' => $product_info['ean'], + 'jan' => $product_info['jan'], + 'isbn' => $product_info['isbn'], + 'mpn' => $product_info['mpn'], + 'weight' => $this->weight->format(($product_info['weight'] + (float)$option_weight) * $product['quantity'], $product_info['weight_class_id'], $this->language->get('decimal_point'), $this->language->get('thousand_point')) + ); + } + } + + $data['orders'][] = array( + 'order_id' => $order_id, + 'invoice_no' => $invoice_no, + 'date_added' => date($this->language->get('date_format_short'), strtotime($order_info['date_added'])), + 'store_name' => $order_info['store_name'], + 'store_url' => rtrim($order_info['store_url'], '/'), + 'store_address' => nl2br($store_address), + 'store_email' => $store_email, + 'store_telephone' => $store_telephone, + 'email' => $order_info['email'], + 'telephone' => $order_info['telephone'], + 'shipping_address' => $shipping_address, + 'shipping_method' => $order_info['shipping_method'], + 'product' => $product_data, + 'comment' => nl2br($order_info['comment']) + ); + } + } + + $this->response->setOutput($this->load->view('sale/order_shipping', $data)); + } +} diff --git a/public/admin/controller/sale/recurring.php b/public/admin/controller/sale/recurring.php new file mode 100644 index 0000000..b54a633 --- /dev/null +++ b/public/admin/controller/sale/recurring.php @@ -0,0 +1,432 @@ +<?php +class ControllerSaleRecurring extends Controller { + private $error = array(); + + public function index() { + $this->load->language('sale/recurring'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/recurring'); + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['filter_order_recurring_id'])) { + $filter_order_recurring_id = $this->request->get['filter_order_recurring_id']; + } else { + $filter_order_recurring_id = ''; + } + + if (isset($this->request->get['filter_order_id'])) { + $filter_order_id = $this->request->get['filter_order_id']; + } else { + $filter_order_id = ''; + } + + if (isset($this->request->get['filter_reference'])) { + $filter_reference = $this->request->get['filter_reference']; + } else { + $filter_reference = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['filter_status'])) { + $filter_status = $this->request->get['filter_status']; + } else { + $filter_status = 0; + } + + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'order_recurring_id'; + } + + if (isset($this->request->get['filter_date_added'])) { + $filter_date_added = $this->request->get['filter_date_added']; + } else { + $filter_date_added = ''; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'DESC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['filter_order_recurring_id'])) { + $url .= '&filter_order_recurring_id=' . $this->request->get['filter_order_recurring_id']; + } + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_reference'])) { + $url .= '&filter_reference=' . $this->request->get['filter_reference']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['recurrings'] = array(); + + $filter_data = array( + 'filter_order_recurring_id' => $filter_order_recurring_id, + 'filter_order_id' => $filter_order_id, + 'filter_reference' => $filter_reference, + 'filter_customer' => $filter_customer, + 'filter_status' => $filter_status, + 'filter_date_added' => $filter_date_added, + 'order' => $order, + 'sort' => $sort, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $recurrings_total = $this->model_sale_recurring->getTotalRecurrings($filter_data); + + $results = $this->model_sale_recurring->getRecurrings($filter_data); + + foreach ($results as $result) { + if ($result['status']) { + $status = $this->language->get('text_status_' . $result['status']); + } else { + $status = ''; + } + + $data['recurrings'][] = array( + 'order_recurring_id' => $result['order_recurring_id'], + 'order_id' => $result['order_id'], + 'reference' => $result['reference'], + 'customer' => $result['customer'], + 'status' => $status, + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'view' => $this->url->link('sale/recurring/info', 'user_token=' . $this->session->data['user_token'] . '&order_recurring_id=' . $result['order_recurring_id'] . $url, true), + 'order' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $result['order_id'], true) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $url = ''; + + if (isset($this->request->get['filter_order_recurring_id'])) { + $url .= '&filter_order_recurring_id=' . $this->request->get['filter_order_recurring_id']; + } + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_reference'])) { + $url .= '&filter_reference=' . urlencode(html_entity_decode($this->request->get['filter_reference'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_order_recurring'] = $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . '&sort=or.order_recurring_id' . $url, true); + $data['sort_order'] = $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . '&sort=or.order_id' . $url, true); + $data['sort_reference'] = $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . '&sort=or.reference' . $url, true); + $data['sort_customer'] = $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . '&sort=customer' . $url, true); + $data['sort_status'] = $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . '&sort=or.status' . $url, true); + $data['sort_date_added'] = $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . '&sort=or.date_added' . $url, true); + + $url = ''; + + if (isset($this->request->get['filter_order_recurring_id'])) { + $url .= '&filter_order_recurring_id=' . $this->request->get['filter_order_recurring_id']; + } + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_reference'])) { + $url .= '&filter_reference=' . urlencode(html_entity_decode($this->request->get['filter_reference'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $recurrings_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->text = $this->language->get('text_pagination'); + $pagination->url = $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . '&page={page}' . $url, true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($recurrings_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($recurrings_total - $this->config->get('config_limit_admin'))) ? $recurrings_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $recurrings_total, ceil($recurrings_total / $this->config->get('config_limit_admin'))); + + $data['filter_order_recurring_id'] = $filter_order_recurring_id; + $data['filter_order_id'] = $filter_order_id; + $data['filter_reference'] = $filter_reference; + $data['filter_customer'] = $filter_customer; + $data['filter_status'] = $filter_status; + $data['filter_date_added'] = $filter_date_added; + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['recurring_statuses'] = array(); + + $data['recurring_statuses'][0] = array( + 'text' => '', + 'value' => 0 + ); + + for ($i = 1; $i <= 6; $i++) { + $data['recurring_statuses'][$i] = array( + 'text' => $this->language->get('text_status_' . $i), + 'value' => 1 + ); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/recurring_list', $data)); + } + + public function info() { + $this->load->model('sale/recurring'); + + if (isset($this->request->get['order_recurring_id'])) { + $order_recurring_id = $this->request->get['order_recurring_id']; + } else { + $order_recurring_id = 0; + } + + $order_recurring_info = $this->model_sale_recurring->getRecurring($order_recurring_id); + + if ($order_recurring_info) { + $this->load->language('sale/recurring'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['user_token'] = $this->request->get['user_token']; + + $url = ''; + + if (isset($this->request->get['filter_order_recurring_id'])) { + $url .= '&filter_order_recurring_id=' . $this->request->get['filter_order_recurring_id']; + } + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_reference'])) { + $url .= '&filter_reference=' . $this->request->get['filter_reference']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['cancel'] = $this->url->link('sale/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true); + + // Recurring + $data['order_recurring_id'] = $order_recurring_info['order_recurring_id']; + $data['reference'] = $order_recurring_info['reference']; + $data['recurring_name'] = $order_recurring_info['recurring_name']; + + if ($order_recurring_info['recurring_id']) { + $data['recurring'] = $this->url->link('catalog/recurring/edit', 'user_token=' . $this->session->data['user_token'] . '&recurring_id=' . $order_recurring_info['recurring_id'], true); + } else { + $data['recurring'] = ''; + } + + $data['recurring_description'] = $order_recurring_info['recurring_description']; + + if ($order_recurring_info['status']) { + $data['recurring_status']= $this->language->get('text_status_' . $order_recurring_info['status']); + } else { + $data['recurring_status'] = ''; + } + + $this->load->model('sale/order'); + + $order_info = $this->model_sale_order->getOrder($order_recurring_info['order_id']); + + $data['payment_method'] = $order_info['payment_method']; + + // Order + $data['order_id'] = $order_info['order_id']; + $data['order'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_info['order_id'], true); + $data['firstname'] = $order_info['firstname']; + $data['lastname'] = $order_info['lastname']; + + if ($order_info['customer_id']) { + $data['customer'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $order_info['customer_id'], true); + } else { + $data['customer'] = ''; + } + + $data['email'] = $order_info['email']; + $data['order_status'] = $order_info['order_status']; + $data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added'])); + + // Product + $data['product'] = $order_recurring_info['product_name']; + $data['quantity'] = $order_recurring_info['product_quantity']; + + // Transactions + $data['transactions'] = array(); + + $transactions = $this->model_sale_recurring->getRecurringTransactions($order_recurring_info['order_recurring_id']); + + foreach ($transactions as $transaction) { + $data['transactions'][] = array( + 'date_added' => $transaction['date_added'], + 'type' => $transaction['type'], + 'amount' => $this->currency->format($transaction['amount'], $order_info['currency_code'], $order_info['currency_value']) + ); + } + + $data['buttons'] = $this->load->controller('extension/payment/' . $order_info['payment_code'] . '/recurringButtons'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/recurring_info', $data)); + } else { + return new Action('error/not_found'); + } + } +}
\ No newline at end of file diff --git a/public/admin/controller/sale/return.php b/public/admin/controller/sale/return.php new file mode 100644 index 0000000..80b48f5 --- /dev/null +++ b/public/admin/controller/sale/return.php @@ -0,0 +1,919 @@ +<?php +class ControllerSaleReturn extends Controller { + private $error = array(); + + public function index() { + $this->load->language('sale/return'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/return'); + + $this->getList(); + } + + public function add() { + $this->load->language('sale/return'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/return'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_sale_return->addReturn($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_return_id'])) { + $url .= '&filter_return_id=' . $this->request->get['filter_return_id']; + } + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_return_status_id'])) { + $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['filter_date_modified'])) { + $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('sale/return'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/return'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_sale_return->editReturn($this->request->get['return_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_return_id'])) { + $url .= '&filter_return_id=' . $this->request->get['filter_return_id']; + } + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_return_status_id'])) { + $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['filter_date_modified'])) { + $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('sale/return'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/return'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $return_id) { + $this->model_sale_return->deleteReturn($return_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_return_id'])) { + $url .= '&filter_return_id=' . $this->request->get['filter_return_id']; + } + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_return_status_id'])) { + $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['filter_date_modified'])) { + $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['filter_return_id'])) { + $filter_return_id = $this->request->get['filter_return_id']; + } else { + $filter_return_id = ''; + } + + if (isset($this->request->get['filter_order_id'])) { + $filter_order_id = $this->request->get['filter_order_id']; + } else { + $filter_order_id = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['filter_product'])) { + $filter_product = $this->request->get['filter_product']; + } else { + $filter_product = ''; + } + + if (isset($this->request->get['filter_model'])) { + $filter_model = $this->request->get['filter_model']; + } else { + $filter_model = ''; + } + + if (isset($this->request->get['filter_return_status_id'])) { + $filter_return_status_id = $this->request->get['filter_return_status_id']; + } else { + $filter_return_status_id = ''; + } + + if (isset($this->request->get['filter_date_added'])) { + $filter_date_added = $this->request->get['filter_date_added']; + } else { + $filter_date_added = ''; + } + + if (isset($this->request->get['filter_date_modified'])) { + $filter_date_modified = $this->request->get['filter_date_modified']; + } else { + $filter_date_modified = ''; + } + + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'r.return_id'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'DESC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['filter_return_id'])) { + $url .= '&filter_return_id=' . $this->request->get['filter_return_id']; + } + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_return_status_id'])) { + $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['filter_date_modified'])) { + $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('sale/return/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('sale/return/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['returns'] = array(); + + $filter_data = array( + 'filter_return_id' => $filter_return_id, + 'filter_order_id' => $filter_order_id, + 'filter_customer' => $filter_customer, + 'filter_product' => $filter_product, + 'filter_model' => $filter_model, + 'filter_return_status_id' => $filter_return_status_id, + 'filter_date_added' => $filter_date_added, + 'filter_date_modified' => $filter_date_modified, + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $return_total = $this->model_sale_return->getTotalReturns($filter_data); + + $results = $this->model_sale_return->getReturns($filter_data); + + foreach ($results as $result) { + $data['returns'][] = array( + 'return_id' => $result['return_id'], + 'order_id' => $result['order_id'], + 'customer' => $result['customer'], + 'product' => $result['product'], + 'model' => $result['model'], + 'return_status' => $result['return_status'], + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])), + 'edit' => $this->url->link('sale/return/edit', 'user_token=' . $this->session->data['user_token'] . '&return_id=' . $result['return_id'] . $url, true) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + + unset($this->session->data['error']); + } elseif (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + if (isset($this->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if (isset($this->request->get['filter_return_id'])) { + $url .= '&filter_return_id=' . $this->request->get['filter_return_id']; + } + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_return_status_id'])) { + $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['filter_date_modified'])) { + $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified']; + } + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_return_id'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . '&sort=r.return_id' . $url, true); + $data['sort_order_id'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . '&sort=r.order_id' . $url, true); + $data['sort_customer'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . '&sort=customer' . $url, true); + $data['sort_product'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . '&sort=r.product' . $url, true); + $data['sort_model'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . '&sort=r.model' . $url, true); + $data['sort_status'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $url, true); + $data['sort_date_added'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . '&sort=r.date_added' . $url, true); + $data['sort_date_modified'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . '&sort=r.date_modified' . $url, true); + + $url = ''; + + if (isset($this->request->get['filter_return_id'])) { + $url .= '&filter_return_id=' . $this->request->get['filter_return_id']; + } + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_return_status_id'])) { + $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['filter_date_modified'])) { + $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $return_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($return_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($return_total - $this->config->get('config_limit_admin'))) ? $return_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $return_total, ceil($return_total / $this->config->get('config_limit_admin'))); + + $data['filter_return_id'] = $filter_return_id; + $data['filter_order_id'] = $filter_order_id; + $data['filter_customer'] = $filter_customer; + $data['filter_product'] = $filter_product; + $data['filter_model'] = $filter_model; + $data['filter_return_status_id'] = $filter_return_status_id; + $data['filter_date_added'] = $filter_date_added; + $data['filter_date_modified'] = $filter_date_modified; + + $this->load->model('localisation/return_status'); + + $data['return_statuses'] = $this->model_localisation_return_status->getReturnStatuses(); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/return_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['return_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->get['return_id'])) { + $data['return_id'] = $this->request->get['return_id']; + } else { + $data['return_id'] = 0; + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['order_id'])) { + $data['error_order_id'] = $this->error['order_id']; + } else { + $data['error_order_id'] = ''; + } + + if (isset($this->error['firstname'])) { + $data['error_firstname'] = $this->error['firstname']; + } else { + $data['error_firstname'] = ''; + } + + if (isset($this->error['lastname'])) { + $data['error_lastname'] = $this->error['lastname']; + } else { + $data['error_lastname'] = ''; + } + + if (isset($this->error['email'])) { + $data['error_email'] = $this->error['email']; + } else { + $data['error_email'] = ''; + } + + if (isset($this->error['telephone'])) { + $data['error_telephone'] = $this->error['telephone']; + } else { + $data['error_telephone'] = ''; + } + + if (isset($this->error['product'])) { + $data['error_product'] = $this->error['product']; + } else { + $data['error_product'] = ''; + } + + if (isset($this->error['model'])) { + $data['error_model'] = $this->error['model']; + } else { + $data['error_model'] = ''; + } + + $url = ''; + + if (isset($this->request->get['filter_return_id'])) { + $url .= '&filter_return_id=' . $this->request->get['filter_return_id']; + } + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_product'])) { + $url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_return_status_id'])) { + $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['filter_date_modified'])) { + $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['return_id'])) { + $data['action'] = $this->url->link('sale/return/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('sale/return/edit', 'user_token=' . $this->session->data['user_token'] . '&return_id=' . $this->request->get['return_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('sale/return', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['return_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $return_info = $this->model_sale_return->getReturn($this->request->get['return_id']); + } + + if (isset($this->request->post['order_id'])) { + $data['order_id'] = $this->request->post['order_id']; + } elseif (!empty($return_info)) { + $data['order_id'] = $return_info['order_id']; + } else { + $data['order_id'] = ''; + } + + if (isset($this->request->post['date_ordered'])) { + $data['date_ordered'] = $this->request->post['date_ordered']; + } elseif (!empty($return_info)) { + $data['date_ordered'] = ($return_info['date_ordered'] != '0000-00-00' ? $return_info['date_ordered'] : ''); + } else { + $data['date_ordered'] = ''; + } + + if (isset($this->request->post['customer'])) { + $data['customer'] = $this->request->post['customer']; + } elseif (!empty($return_info)) { + $data['customer'] = $return_info['customer']; + } else { + $data['customer'] = ''; + } + + if (isset($this->request->post['customer_id'])) { + $data['customer_id'] = $this->request->post['customer_id']; + } elseif (!empty($return_info)) { + $data['customer_id'] = $return_info['customer_id']; + } else { + $data['customer_id'] = ''; + } + + if (isset($this->request->post['firstname'])) { + $data['firstname'] = $this->request->post['firstname']; + } elseif (!empty($return_info)) { + $data['firstname'] = $return_info['firstname']; + } else { + $data['firstname'] = ''; + } + + if (isset($this->request->post['lastname'])) { + $data['lastname'] = $this->request->post['lastname']; + } elseif (!empty($return_info)) { + $data['lastname'] = $return_info['lastname']; + } else { + $data['lastname'] = ''; + } + + if (isset($this->request->post['email'])) { + $data['email'] = $this->request->post['email']; + } elseif (!empty($return_info)) { + $data['email'] = $return_info['email']; + } else { + $data['email'] = ''; + } + + if (isset($this->request->post['telephone'])) { + $data['telephone'] = $this->request->post['telephone']; + } elseif (!empty($return_info)) { + $data['telephone'] = $return_info['telephone']; + } else { + $data['telephone'] = ''; + } + + if (isset($this->request->post['product'])) { + $data['product'] = $this->request->post['product']; + } elseif (!empty($return_info)) { + $data['product'] = $return_info['product']; + } else { + $data['product'] = ''; + } + + if (isset($this->request->post['product_id'])) { + $data['product_id'] = $this->request->post['product_id']; + } elseif (!empty($return_info)) { + $data['product_id'] = $return_info['product_id']; + } else { + $data['product_id'] = ''; + } + + if (isset($this->request->post['model'])) { + $data['model'] = $this->request->post['model']; + } elseif (!empty($return_info)) { + $data['model'] = $return_info['model']; + } else { + $data['model'] = ''; + } + + if (isset($this->request->post['quantity'])) { + $data['quantity'] = $this->request->post['quantity']; + } elseif (!empty($return_info)) { + $data['quantity'] = $return_info['quantity']; + } else { + $data['quantity'] = ''; + } + + if (isset($this->request->post['opened'])) { + $data['opened'] = $this->request->post['opened']; + } elseif (!empty($return_info)) { + $data['opened'] = $return_info['opened']; + } else { + $data['opened'] = ''; + } + + if (isset($this->request->post['return_reason_id'])) { + $data['return_reason_id'] = $this->request->post['return_reason_id']; + } elseif (!empty($return_info)) { + $data['return_reason_id'] = $return_info['return_reason_id']; + } else { + $data['return_reason_id'] = ''; + } + + $this->load->model('localisation/return_reason'); + + $data['return_reasons'] = $this->model_localisation_return_reason->getReturnReasons(); + + if (isset($this->request->post['return_action_id'])) { + $data['return_action_id'] = $this->request->post['return_action_id']; + } elseif (!empty($return_info)) { + $data['return_action_id'] = $return_info['return_action_id']; + } else { + $data['return_action_id'] = ''; + } + + $this->load->model('localisation/return_action'); + + $data['return_actions'] = $this->model_localisation_return_action->getReturnActions(); + + if (isset($this->request->post['comment'])) { + $data['comment'] = $this->request->post['comment']; + } elseif (!empty($return_info)) { + $data['comment'] = $return_info['comment']; + } else { + $data['comment'] = ''; + } + + if (isset($this->request->post['return_status_id'])) { + $data['return_status_id'] = $this->request->post['return_status_id']; + } elseif (!empty($return_info)) { + $data['return_status_id'] = $return_info['return_status_id']; + } else { + $data['return_status_id'] = ''; + } + + $this->load->model('localisation/return_status'); + + $data['return_statuses'] = $this->model_localisation_return_status->getReturnStatuses(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/return_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'sale/return')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (empty($this->request->post['order_id'])) { + $this->error['order_id'] = $this->language->get('error_order_id'); + } + + if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) { + $this->error['firstname'] = $this->language->get('error_firstname'); + } + + if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) { + $this->error['lastname'] = $this->language->get('error_lastname'); + } + + if ((utf8_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) { + $this->error['email'] = $this->language->get('error_email'); + } + + if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) { + $this->error['telephone'] = $this->language->get('error_telephone'); + } + + if ((utf8_strlen($this->request->post['product']) < 1) || (utf8_strlen($this->request->post['product']) > 255)) { + $this->error['product'] = $this->language->get('error_product'); + } + + if ((utf8_strlen($this->request->post['model']) < 1) || (utf8_strlen($this->request->post['model']) > 64)) { + $this->error['model'] = $this->language->get('error_model'); + } + + if (empty($this->request->post['return_reason_id'])) { + $this->error['reason'] = $this->language->get('error_reason'); + } + + if ($this->error && !isset($this->error['warning'])) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'sale/return')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function history() { + $this->load->language('sale/return'); + + $this->load->model('sale/return'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['histories'] = array(); + + $results = $this->model_sale_return->getReturnHistories($this->request->get['return_id'], ($page - 1) * 10, 10); + + foreach ($results as $result) { + $data['histories'][] = array( + 'notify' => $result['notify'] ? $this->language->get('text_yes') : $this->language->get('text_no'), + 'status' => $result['status'], + 'comment' => nl2br($result['comment']), + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])) + ); + } + + $history_total = $this->model_sale_return->getTotalReturnHistories($this->request->get['return_id']); + + $pagination = new Pagination(); + $pagination->total = $history_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('sale/return/history', 'user_token=' . $this->session->data['user_token'] . '&return_id=' . $this->request->get['return_id'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($history_total - 10)) ? $history_total : ((($page - 1) * 10) + 10), $history_total, ceil($history_total / 10)); + + $this->response->setOutput($this->load->view('sale/return_history', $data)); + } + + public function addHistory() { + $this->load->language('sale/return'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'sale/return')) { + $json['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('sale/return'); + + $this->model_sale_return->addReturnHistory($this->request->get['return_id'], $this->request->post['return_status_id'], $this->request->post['comment'], $this->request->post['notify']); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/sale/voucher.php b/public/admin/controller/sale/voucher.php new file mode 100644 index 0000000..8317183 --- /dev/null +++ b/public/admin/controller/sale/voucher.php @@ -0,0 +1,679 @@ +<?php +class ControllerSaleVoucher extends Controller { + private $error = array(); + + public function index() { + $this->load->language('sale/voucher'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/voucher'); + + $this->getList(); + } + + public function add() { + $this->load->language('sale/voucher'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/voucher'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_sale_voucher->addVoucher($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('sale/voucher'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/voucher'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_sale_voucher->editVoucher($this->request->get['voucher_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('sale/voucher'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/voucher'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $voucher_id) { + $this->model_sale_voucher->deleteVoucher($voucher_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'v.date_added'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'DESC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('sale/voucher/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('sale/voucher/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['vouchers'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $voucher_total = $this->model_sale_voucher->getTotalVouchers(); + + $results = $this->model_sale_voucher->getVouchers($filter_data); + + foreach ($results as $result) { + if ($result['order_id']) { + $order_href = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $result['order_id'] . $url, true); + } else { + $order_href = ''; + } + + $data['vouchers'][] = array( + 'voucher_id' => $result['voucher_id'], + 'code' => $result['code'], + 'from' => $result['from_name'], + 'to' => $result['to_name'], + 'theme' => $result['theme'], + 'amount' => $this->currency->format($result['amount'], $this->config->get('config_currency')), + 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'edit' => $this->url->link('sale/voucher/edit', 'user_token=' . $this->session->data['user_token'] . '&voucher_id=' . $result['voucher_id'] . $url, true), + 'order' => $order_href + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + if (isset($this->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_code'] = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . '&sort=v.code' . $url, true); + $data['sort_from'] = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . '&sort=v.from_name' . $url, true); + $data['sort_to'] = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . '&sort=v.to_name' . $url, true); + $data['sort_theme'] = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . '&sort=theme' . $url, true); + $data['sort_amount'] = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . '&sort=v.amount' . $url, true); + $data['sort_status'] = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . '&sort=v.status' . $url, true); + $data['sort_date_added'] = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . '&sort=v.date_added' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $voucher_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($voucher_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($voucher_total - $this->config->get('config_limit_admin'))) ? $voucher_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $voucher_total, ceil($voucher_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/voucher_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['voucher_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->request->get['voucher_id'])) { + $data['voucher_id'] = $this->request->get['voucher_id']; + } else { + $data['voucher_id'] = 0; + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['code'])) { + $data['error_code'] = $this->error['code']; + } else { + $data['error_code'] = ''; + } + + if (isset($this->error['from_name'])) { + $data['error_from_name'] = $this->error['from_name']; + } else { + $data['error_from_name'] = ''; + } + + if (isset($this->error['from_email'])) { + $data['error_from_email'] = $this->error['from_email']; + } else { + $data['error_from_email'] = ''; + } + + if (isset($this->error['to_name'])) { + $data['error_to_name'] = $this->error['to_name']; + } else { + $data['error_to_name'] = ''; + } + + if (isset($this->error['to_email'])) { + $data['error_to_email'] = $this->error['to_email']; + } else { + $data['error_to_email'] = ''; + } + + if (isset($this->error['amount'])) { + $data['error_amount'] = $this->error['amount']; + } else { + $data['error_amount'] = ''; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['voucher_id'])) { + $data['action'] = $this->url->link('sale/voucher/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('sale/voucher/edit', 'user_token=' . $this->session->data['user_token'] . '&voucher_id=' . $this->request->get['voucher_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['voucher_id']) && (!$this->request->server['REQUEST_METHOD'] != 'POST')) { + $voucher_info = $this->model_sale_voucher->getVoucher($this->request->get['voucher_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['code'])) { + $data['code'] = $this->request->post['code']; + } elseif (!empty($voucher_info)) { + $data['code'] = $voucher_info['code']; + } else { + $data['code'] = ''; + } + + if (isset($this->request->post['from_name'])) { + $data['from_name'] = $this->request->post['from_name']; + } elseif (!empty($voucher_info)) { + $data['from_name'] = $voucher_info['from_name']; + } else { + $data['from_name'] = ''; + } + + if (isset($this->request->post['from_email'])) { + $data['from_email'] = $this->request->post['from_email']; + } elseif (!empty($voucher_info)) { + $data['from_email'] = $voucher_info['from_email']; + } else { + $data['from_email'] = ''; + } + + if (isset($this->request->post['to_name'])) { + $data['to_name'] = $this->request->post['to_name']; + } elseif (!empty($voucher_info)) { + $data['to_name'] = $voucher_info['to_name']; + } else { + $data['to_name'] = ''; + } + + if (isset($this->request->post['to_email'])) { + $data['to_email'] = $this->request->post['to_email']; + } elseif (!empty($voucher_info)) { + $data['to_email'] = $voucher_info['to_email']; + } else { + $data['to_email'] = ''; + } + + $this->load->model('sale/voucher_theme'); + + $data['voucher_themes'] = $this->model_sale_voucher_theme->getVoucherThemes(); + + if (isset($this->request->post['voucher_theme_id'])) { + $data['voucher_theme_id'] = $this->request->post['voucher_theme_id']; + } elseif (!empty($voucher_info)) { + $data['voucher_theme_id'] = $voucher_info['voucher_theme_id']; + } else { + $data['voucher_theme_id'] = ''; + } + + if (isset($this->request->post['message'])) { + $data['message'] = $this->request->post['message']; + } elseif (!empty($voucher_info)) { + $data['message'] = $voucher_info['message']; + } else { + $data['message'] = ''; + } + + if (isset($this->request->post['amount'])) { + $data['amount'] = $this->request->post['amount']; + } elseif (!empty($voucher_info)) { + $data['amount'] = $voucher_info['amount']; + } else { + $data['amount'] = ''; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($voucher_info)) { + $data['status'] = $voucher_info['status']; + } else { + $data['status'] = true; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/voucher_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'sale/voucher')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['code']) < 3) || (utf8_strlen($this->request->post['code']) > 10)) { + $this->error['code'] = $this->language->get('error_code'); + } + + $voucher_info = $this->model_sale_voucher->getVoucherByCode($this->request->post['code']); + + if ($voucher_info) { + if (!isset($this->request->get['voucher_id'])) { + $this->error['warning'] = $this->language->get('error_exists'); + } elseif ($voucher_info['voucher_id'] != $this->request->get['voucher_id']) { + $this->error['warning'] = $this->language->get('error_exists'); + } + } + + if ((utf8_strlen($this->request->post['to_name']) < 1) || (utf8_strlen($this->request->post['to_name']) > 64)) { + $this->error['to_name'] = $this->language->get('error_to_name'); + } + + if ((utf8_strlen($this->request->post['to_email']) > 96) || !filter_var($this->request->post['to_email'], FILTER_VALIDATE_EMAIL)) { + $this->error['to_email'] = $this->language->get('error_email'); + } + + if ((utf8_strlen($this->request->post['from_name']) < 1) || (utf8_strlen($this->request->post['from_name']) > 64)) { + $this->error['from_name'] = $this->language->get('error_from_name'); + } + + if ((utf8_strlen($this->request->post['from_email']) > 96) || !filter_var($this->request->post['from_email'], FILTER_VALIDATE_EMAIL)) { + $this->error['from_email'] = $this->language->get('error_email'); + } + + if ($this->request->post['amount'] < 1) { + $this->error['amount'] = $this->language->get('error_amount'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'sale/voucher')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('sale/order'); + + foreach ($this->request->post['selected'] as $voucher_id) { + $order_voucher_info = $this->model_sale_order->getOrderVoucherByVoucherId($voucher_id); + + if ($order_voucher_info) { + $this->error['warning'] = sprintf($this->language->get('error_order'), $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_voucher_info['order_id'], true)); + + break; + } + } + + return !$this->error; + } + + public function history() { + $this->load->language('sale/voucher'); + + $this->load->model('sale/voucher'); + + $data['text_no_results'] = $this->language->get('text_no_results'); + + $data['column_order_id'] = $this->language->get('column_order_id'); + $data['column_customer'] = $this->language->get('column_customer'); + $data['column_amount'] = $this->language->get('column_amount'); + $data['column_date_added'] = $this->language->get('column_date_added'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['histories'] = array(); + + $results = $this->model_sale_voucher->getVoucherHistories($this->request->get['voucher_id'], ($page - 1) * 10, 10); + + foreach ($results as $result) { + $data['histories'][] = array( + 'order_id' => $result['order_id'], + 'customer' => $result['customer'], + 'amount' => $this->currency->format($result['amount'], $this->config->get('config_currency')), + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])) + ); + } + + $history_total = $this->model_sale_voucher->getTotalVoucherHistories($this->request->get['voucher_id']); + + $pagination = new Pagination(); + $pagination->total = $history_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('sale/voucher/history', 'user_token=' . $this->session->data['user_token'] . '&voucher_id=' . $this->request->get['voucher_id'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($history_total - 10)) ? $history_total : ((($page - 1) * 10) + 10), $history_total, ceil($history_total / 10)); + + $this->response->setOutput($this->load->view('sale/voucher_history', $data)); + } + + public function send() { + $this->load->language('mail/voucher'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'sale/voucher')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (!$json) { + $this->load->model('sale/voucher'); + + $vouchers = array(); + + if (isset($this->request->post['selected'])) { + $vouchers = $this->request->post['selected']; + } elseif (isset($this->request->post['voucher_id'])) { + $vouchers[] = $this->request->post['voucher_id']; + } + + if ($vouchers) { + foreach ($vouchers as $voucher_id) { + $voucher_info = $this->model_sale_voucher->getVoucher($voucher_id); + + if ($voucher_info) { + if ($voucher_info['order_id']) { + $order_id = $voucher_info['order_id']; + } else { + $order_id = 0; + } + + $this->load->model('sale/order'); + + $order_info = $this->model_sale_order->getOrder($order_id); + + // If voucher belongs to an order + if ($order_info) { + $this->load->model('localisation/language'); + + $language = new Language($order_info['language_code']); + $language->load($order_info['language_code']); + $language->load('mail/voucher'); + + // HTML Mail + $data['title'] = sprintf($language->get('text_subject'), $voucher_info['from_name']); + + $data['text_greeting'] = sprintf($language->get('text_greeting'), $this->currency->format($voucher_info['amount'], (!empty($order_info['currency_code']) ? $order_info['currency_code'] : $this->config->get('config_currency')), (!empty($order_info['currency_value']) ? $order_info['currency_value'] : $this->currency->getValue($this->config->get('config_currency'))))); + $data['text_from'] = sprintf($language->get('text_from'), $voucher_info['from_name']); + $data['text_message'] = $language->get('text_message'); + $data['text_redeem'] = sprintf($language->get('text_redeem'), $voucher_info['code']); + $data['text_footer'] = $language->get('text_footer'); + + $this->load->model('sale/voucher_theme'); + + $voucher_theme_info = $this->model_sale_voucher_theme->getVoucherTheme($voucher_info['voucher_theme_id']); + + if ($voucher_theme_info && is_file(DIR_IMAGE . $voucher_theme_info['image'])) { + $data['image'] = HTTP_CATALOG . 'image/' . $voucher_theme_info['image']; + } else { + $data['image'] = ''; + } + + $data['store_name'] = $order_info['store_name']; + $data['store_url'] = $order_info['store_url']; + $data['message'] = nl2br($voucher_info['message']); + + $mail = new Mail($this->config->get('config_mail_engine')); + $mail->parameter = $this->config->get('config_mail_parameter'); + $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); + $mail->smtp_username = $this->config->get('config_mail_smtp_username'); + $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); + $mail->smtp_port = $this->config->get('config_mail_smtp_port'); + $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); + + $mail->setTo($voucher_info['to_email']); + $mail->setFrom($this->config->get('config_email')); + $mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8')); + $mail->setSubject(sprintf($language->get('text_subject'), html_entity_decode($voucher_info['from_name'], ENT_QUOTES, 'UTF-8'))); + $mail->setHtml($this->load->view('mail/voucher', $data)); + $mail->send(); + + // If voucher does not belong to an order + } else { + $data['title'] = sprintf($this->language->get('text_subject'), $voucher_info['from_name']); + + $data['text_greeting'] = sprintf($this->language->get('text_greeting'), $this->currency->format($voucher_info['amount'], $this->config->get('config_currency'))); + $data['text_from'] = sprintf($this->language->get('text_from'), $voucher_info['from_name']); + $data['text_message'] = $this->language->get('text_message'); + $data['text_redeem'] = sprintf($this->language->get('text_redeem'), $voucher_info['code']); + $data['text_footer'] = $this->language->get('text_footer'); + + $this->load->model('sale/voucher_theme'); + + $voucher_theme_info = $this->model_sale_voucher_theme->getVoucherTheme($voucher_info['voucher_theme_id']); + + if ($voucher_theme_info && is_file(DIR_IMAGE . $voucher_theme_info['image'])) { + $data['image'] = HTTP_CATALOG . 'image/' . $voucher_theme_info['image']; + } else { + $data['image'] = ''; + } + + $data['store_name'] = $this->config->get('config_name'); + $data['store_url'] = HTTP_CATALOG; + $data['message'] = nl2br($voucher_info['message']); + + $mail = new Mail($this->config->get('config_mail_engine')); + $mail->parameter = $this->config->get('config_mail_parameter'); + $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); + $mail->smtp_username = $this->config->get('config_mail_smtp_username'); + $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); + $mail->smtp_port = $this->config->get('config_mail_smtp_port'); + $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); + + $mail->setTo($voucher_info['to_email']); + $mail->setFrom($this->config->get('config_email')); + $mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8')); + $mail->setSubject(html_entity_decode(sprintf($this->language->get('text_subject'), $voucher_info['from_name']), ENT_QUOTES, 'UTF-8')); + $mail->setHtml($this->load->view('mail/voucher', $data)); + $mail->send(); + } + } + } + + $json['success'] = $this->language->get('text_sent'); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/sale/voucher_theme.php b/public/admin/controller/sale/voucher_theme.php new file mode 100644 index 0000000..e2e4bee --- /dev/null +++ b/public/admin/controller/sale/voucher_theme.php @@ -0,0 +1,381 @@ +<?php +class ControllerSaleVoucherTheme extends Controller { + private $error = array(); + + public function index() { + $this->load->language('sale/voucher_theme'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/voucher_theme'); + + $this->getList(); + } + + public function add() { + $this->load->language('sale/voucher_theme'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/voucher_theme'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_sale_voucher_theme->addVoucherTheme($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('sale/voucher_theme', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('sale/voucher_theme'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/voucher_theme'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_sale_voucher_theme->editVoucherTheme($this->request->get['voucher_theme_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('sale/voucher_theme', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('sale/voucher_theme'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('sale/voucher_theme'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $voucher_theme_id) { + $this->model_sale_voucher_theme->deleteVoucherTheme($voucher_theme_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $this->response->redirect($this->url->link('sale/voucher_theme', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'vtd.name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/voucher_theme', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('sale/voucher_theme/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('sale/voucher_theme/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['voucher_themes'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $voucher_theme_total = $this->model_sale_voucher_theme->getTotalVoucherThemes(); + + $results = $this->model_sale_voucher_theme->getVoucherThemes($filter_data); + + foreach ($results as $result) { + $data['voucher_themes'][] = array( + 'voucher_theme_id' => $result['voucher_theme_id'], + 'name' => $result['name'], + 'edit' => $this->url->link('sale/voucher_theme/edit', 'user_token=' . $this->session->data['user_token'] . '&voucher_theme_id=' . $result['voucher_theme_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + if (isset($this->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('sale/voucher_theme', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $voucher_theme_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('sale/voucher_theme', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($voucher_theme_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($voucher_theme_total - $this->config->get('config_limit_admin'))) ? $voucher_theme_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $voucher_theme_total, ceil($voucher_theme_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/voucher_theme_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['voucher_theme_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = array(); + } + + if (isset($this->error['image'])) { + $data['error_image'] = $this->error['image']; + } else { + $data['error_image'] = ''; + } + + $url = ''; + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('sale/voucher_theme', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['voucher_theme_id'])) { + $data['action'] = $this->url->link('sale/voucher_theme/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('sale/voucher_theme/edit', 'user_token=' . $this->session->data['user_token'] . '&voucher_theme_id=' . $this->request->get['voucher_theme_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('sale/voucher_theme', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['voucher_theme_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $voucher_theme_info = $this->model_sale_voucher_theme->getVoucherTheme($this->request->get['voucher_theme_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['voucher_theme_description'])) { + $data['voucher_theme_description'] = $this->request->post['voucher_theme_description']; + } elseif (isset($this->request->get['voucher_theme_id'])) { + $data['voucher_theme_description'] = $this->model_sale_voucher_theme->getVoucherThemeDescriptions($this->request->get['voucher_theme_id']); + } else { + $data['voucher_theme_description'] = array(); + } + + if (isset($this->request->post['image'])) { + $data['image'] = $this->request->post['image']; + } elseif (!empty($voucher_theme_info)) { + $data['image'] = $voucher_theme_info['image']; + } else { + $data['image'] = ''; + } + + $this->load->model('tool/image'); + + if (isset($this->request->post['image']) && is_file(DIR_IMAGE . $this->request->post['image'])) { + $data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 100, 100); + } elseif (!empty($voucher_theme_info) && is_file(DIR_IMAGE . $voucher_theme_info['image'])) { + $data['thumb'] = $this->model_tool_image->resize($voucher_theme_info['image'], 100, 100); + } else { + $data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('sale/voucher_theme_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'sale/voucher_theme')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + foreach ($this->request->post['voucher_theme_description'] as $language_id => $value) { + if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 32)) { + $this->error['name'][$language_id] = $this->language->get('error_name'); + } + } + + if (!$this->request->post['image']) { + $this->error['image'] = $this->language->get('error_image'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'sale/voucher_theme')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('sale/voucher'); + + foreach ($this->request->post['selected'] as $voucher_theme_id) { + $voucher_total = $this->model_sale_voucher->getTotalVouchersByVoucherThemeId($voucher_theme_id); + + if ($voucher_total) { + $this->error['warning'] = sprintf($this->language->get('error_voucher'), $voucher_total); + } + } + + return !$this->error; + } +}
\ No newline at end of file |