$this->language->load('sale/customer');
$this->load->model('sale/customer');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->user->hasPermission('modify', 'sale/customer')) {
$this->model_sale_customer->addReward($this->request->get['customer_id'], $this->request->post['description'], $this->request->post['points']);
$this->data['success'] = $this->language->get('text_success');
} else {
$this->data['success'] = '';
}
if (($this->request->server['REQUEST_METHOD'] == 'POST') && !$this->user->hasPermission('modify', 'sale/customer')) {
$this->data['error_warning'] = $this->language->get('error_permission');
} else {
$this->data['error_warning'] = '';
}
$this->data['text_no_results'] = $this->language->get('text_no_results');
$this->data['text_balance'] = $this->language->get('text_balance');
$this->data['column_date_added'] = $this->language->get('column_date_added');
$this->data['column_description'] = $this->language->get('column_description');
$this->data['column_points'] = $this->language->get('column_points');
if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
} else {
$page = 1;
}
$this->data['rewards'] = array();
$results = $this->model_sale_customer->getRewards($this->request->get['customer_id'], ($page - 1) * 10, 10);
foreach ($results as $result) {
$this->data['rewards'][] = array(
'points' => $result['points'],
'description' => $result['description'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
);
}
$this->data['balance'] = $this->model_sale_customer->getRewardTotal($this->request->get['customer_id']);
$reward_total = $this->model_sale_customer->getTotalRewards($this->request->get['customer_id']);
$pagination = new Pagination();
$pagination->total = $reward_total;
$pagination->page = $page;
$pagination->limit = 10;
$pagination->text = $this->language->get('text_pagination');
$pagination->url = $this->url->link('sale/customer/reward', 'token=' . $this->session->data['token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page={page}', 'SSL');
$this->data['pagination'] = $pagination->render();
$this->template = 'sale/customer_reward.tpl';
$this->response->setOutput($this->render());