customer_reward.php (6559B)
1 <?php 2 class ControllerExtensionReportCustomerReward extends Controller { 3 public function index() { 4 $this->load->language('extension/report/customer_reward'); 5 6 $this->document->setTitle($this->language->get('heading_title')); 7 8 $this->load->model('setting/setting'); 9 10 if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { 11 $this->model_setting_setting->editSetting('report_customer_reward', $this->request->post); 12 13 $this->session->data['success'] = $this->language->get('text_success'); 14 15 $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); 16 } 17 18 if (isset($this->error['warning'])) { 19 $data['error_warning'] = $this->error['warning']; 20 } else { 21 $data['error_warning'] = ''; 22 } 23 24 $data['breadcrumbs'] = array(); 25 26 $data['breadcrumbs'][] = array( 27 'text' => $this->language->get('text_home'), 28 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) 29 ); 30 31 $data['breadcrumbs'][] = array( 32 'text' => $this->language->get('text_extension'), 33 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) 34 ); 35 36 $data['breadcrumbs'][] = array( 37 'text' => $this->language->get('heading_title'), 38 'href' => $this->url->link('extension/report/customer_reward', 'user_token=' . $this->session->data['user_token'], true) 39 ); 40 41 $data['action'] = $this->url->link('extension/report/customer_reward', 'user_token=' . $this->session->data['user_token'], true); 42 43 $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); 44 45 if (isset($this->request->post['report_customer_reward_status'])) { 46 $data['report_customer_reward_status'] = $this->request->post['report_customer_reward_status']; 47 } else { 48 $data['report_customer_reward_status'] = $this->config->get('report_customer_reward_status'); 49 } 50 51 if (isset($this->request->post['report_customer_reward_sort_order'])) { 52 $data['report_customer_reward_sort_order'] = $this->request->post['report_customer_reward_sort_order']; 53 } else { 54 $data['report_customer_reward_sort_order'] = $this->config->get('report_customer_reward_sort_order'); 55 } 56 57 $data['header'] = $this->load->controller('common/header'); 58 $data['column_left'] = $this->load->controller('common/column_left'); 59 $data['footer'] = $this->load->controller('common/footer'); 60 61 $this->response->setOutput($this->load->view('extension/report/customer_reward_form', $data)); 62 } 63 64 protected function validate() { 65 if (!$this->user->hasPermission('modify', 'extension/report/customer_reward')) { 66 $this->error['warning'] = $this->language->get('error_permission'); 67 } 68 69 return !$this->error; 70 } 71 72 public function report() { 73 $this->load->language('extension/report/customer_reward'); 74 75 if (isset($this->request->get['filter_date_start'])) { 76 $filter_date_start = $this->request->get['filter_date_start']; 77 } else { 78 $filter_date_start = ''; 79 } 80 81 if (isset($this->request->get['filter_date_end'])) { 82 $filter_date_end = $this->request->get['filter_date_end']; 83 } else { 84 $filter_date_end = ''; 85 } 86 87 if (isset($this->request->get['filter_customer'])) { 88 $filter_customer = $this->request->get['filter_customer']; 89 } else { 90 $filter_customer = ''; 91 } 92 93 if (isset($this->request->get['page'])) { 94 $page = $this->request->get['page']; 95 } else { 96 $page = 1; 97 } 98 99 $this->load->model('extension/report/customer'); 100 101 $data['customers'] = array(); 102 103 $filter_data = array( 104 'filter_date_start' => $filter_date_start, 105 'filter_date_end' => $filter_date_end, 106 'filter_customer' => $filter_customer, 107 'start' => ($page - 1) * $this->config->get('config_limit_admin'), 108 'limit' => $this->config->get('config_limit_admin') 109 ); 110 111 $customer_total = $this->model_extension_report_customer->getTotalRewardPoints($filter_data); 112 113 $results = $this->model_extension_report_customer->getRewardPoints($filter_data); 114 115 foreach ($results as $result) { 116 $data['customers'][] = array( 117 'customer' => $result['customer'], 118 'email' => $result['email'], 119 'customer_group' => $result['customer_group'], 120 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), 121 'points' => $result['points'], 122 'orders' => $result['orders'], 123 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')), 124 'edit' => $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'], true) 125 ); 126 } 127 128 $data['user_token'] = $this->session->data['user_token']; 129 130 $url = ''; 131 132 if (isset($this->request->get['filter_date_start'])) { 133 $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; 134 } 135 136 if (isset($this->request->get['filter_date_end'])) { 137 $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; 138 } 139 140 if (isset($this->request->get['filter_customer'])) { 141 $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']); 142 } 143 144 $pagination = new Pagination(); 145 $pagination->total = $customer_total; 146 $pagination->page = $page; 147 $pagination->limit = $this->config->get('config_limit_admin'); 148 $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=customer_reward' . $url . '&page={page}', true); 149 150 $data['pagination'] = $pagination->render(); 151 152 $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($customer_total - $this->config->get('config_limit_admin'))) ? $customer_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $customer_total, ceil($customer_total / $this->config->get('config_limit_admin'))); 153 154 $data['filter_date_start'] = $filter_date_start; 155 $data['filter_date_end'] = $filter_date_end; 156 $data['filter_customer'] = $filter_customer; 157 158 return $this->load->view('extension/report/customer_reward_info', $data); 159 } 160 }