464 lines
15 KiB
PHP
464 lines
15 KiB
PHP
<?php
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class Points extends Admin_Controller {
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('point_model');
|
|
$this->load->model('combo_model');
|
|
}
|
|
|
|
public function index() {
|
|
$data = array();
|
|
$this->load->helper('url');
|
|
$this->reportpoints();
|
|
}
|
|
|
|
protected function renderPointsPage($page_name, $data) {
|
|
$this->load->view('admin/view_admin_header', $data);
|
|
$this->load->view('points/' . $page_name, $data);
|
|
$this->load->view('admin/view_admin_footer', $data);
|
|
}
|
|
|
|
public function getValueOfPointReport() {
|
|
return [
|
|
'member_id' => trim($this->input->get('member_id') ?? ''),
|
|
'description' => trim($this->input->get('description') ?? ''),
|
|
'id' => trim($this->input->get('id') ?? ''),
|
|
'from_points' => trim($this->input->get('from_points') ?? ''),
|
|
'to_points' => trim($this->input->get('to_points') ?? ''),
|
|
'from_date' => trim($this->input->get('from_date') ?? ''),
|
|
'to_date' => trim($this->input->get('to_date') ?? ''),
|
|
'status' => trim($this->input->get('card_status')
|
|
?? ($this->input->get('status') ?? -1)),
|
|
];
|
|
}
|
|
|
|
public function setOnePastMonth(&$params, $default_date = 'on') {
|
|
|
|
if (strcmp($default_date, 'on') === 0) {
|
|
$params['from_date'] = date("Y-m-d", strtotime("-1 months"));
|
|
$params['to_date'] = date("Y-m-d");
|
|
}
|
|
|
|
}
|
|
|
|
public function setComboForPointReport($params) {
|
|
$this->load->model('combo_model');
|
|
|
|
$combo['card_status'] = $this->combo_model->getStatusComboFromZeroToNine(
|
|
'card_status',
|
|
$params['status']
|
|
);
|
|
|
|
return $combo;
|
|
}
|
|
|
|
public function getValueCombo($val) {
|
|
$status_value = range(0, 9);
|
|
return in_array($val, $status_value)
|
|
? $val
|
|
: '';
|
|
}
|
|
|
|
public function validateValueForPointReport($params) {
|
|
$this->load->library('form_validation');
|
|
$this->form_validation->set_data($params);
|
|
$this->setFormRuleForPointReportForm();
|
|
|
|
$errors = [];
|
|
if ($this->form_validation->run() === FALSE) {
|
|
$errors = $this->form_validation->error_array();
|
|
}
|
|
return $errors;
|
|
}
|
|
|
|
public function setFormRuleForPointReportForm() {
|
|
$status_pattern = 'regex_match[/^(?:[0-9])$/]';
|
|
$date_pattern = 'regex_match[/\d{4}-\d{2}-\d{2}/]';
|
|
|
|
$this->form_validation->set_rules('member_id', 'Member ID', 'numeric');
|
|
$this->form_validation->set_rules('id', 'ID', 'numeric');
|
|
$this->form_validation->set_rules('from_points', 'From Points', 'numeric');
|
|
$this->form_validation->set_rules('to_points', 'To Points', 'numeric');
|
|
$this->form_validation->set_rules('from_date', 'From Added', $date_pattern);
|
|
$this->form_validation->set_rules('to_date', 'To Added', $date_pattern);
|
|
$this->form_validation->set_rules('status', 'Status', $status_pattern);
|
|
}
|
|
|
|
public function load_pagination($all_record, $params, $action) {
|
|
$action_hidden = $this->input->get('action_hidden');
|
|
// pagination
|
|
$this->load->library('pagination');
|
|
$config["total_rows"] = count($all_record);
|
|
$config["base_url"] = base_url() . "/points/" . $action;
|
|
$config["per_page"] = 10;
|
|
$config["uri_segment"] = 3;
|
|
$config["num_links"] = 5;
|
|
$config["suffix"] =
|
|
"?action_hidden=${action_hidden}&"
|
|
. http_build_query($params);
|
|
$config["first_url"] =
|
|
"/points/{$action}/0?action_hidden=${action_hidden}&"
|
|
. http_build_query($params);
|
|
$config['full_tag_open'] = "<ul class='pagination'>";
|
|
$config['full_tag_close'] = "</ul>";
|
|
$config['num_tag_open'] = '<li>';
|
|
$config['num_tag_close'] = '</li>';
|
|
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
|
|
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
|
|
$config['next_tag_open'] = "<li>";
|
|
$config['next_tagl_close'] = "</li>";
|
|
$config['prev_tag_open'] = "<li>";
|
|
$config['prev_tagl_close'] = "</li>";
|
|
$config['first_tag_open'] = "<li>";
|
|
$config['first_tagl_close'] = "</li>";
|
|
$config['last_tag_open'] = "<li>";
|
|
$config['last_tagl_close'] = "</li>";
|
|
|
|
$this->pagination->initialize($config);
|
|
$page = ( $this->uri->segment(3) ) ? $this->uri->segment(3) : 0;
|
|
$offset = is_numeric($page) ? $page : 0;
|
|
|
|
return [
|
|
'link' => $this->pagination->create_links(),
|
|
'offset' => $offset,
|
|
'limit' => $config["per_page"]
|
|
];
|
|
}
|
|
|
|
public function reportpoints() {
|
|
$this->load->model('report_point_model');
|
|
|
|
$this->load->library('table');
|
|
$this->table->set_template($this->template);
|
|
|
|
$this->table->set_heading([
|
|
'FirstName',
|
|
'Lastname',
|
|
'ID',
|
|
'Description',
|
|
'Points',
|
|
'Added',
|
|
'Status',
|
|
]);
|
|
|
|
$params = $this->getValueOfPointReport();
|
|
|
|
$default_date = $this->input->get('default_date');
|
|
if ($this->input->get('action_hidden')) {
|
|
$this->setOnePastMonth($params, $default_date);
|
|
} else {
|
|
$this->setOnePastMonth($params);
|
|
}
|
|
|
|
$data = $this->setComboForPointReport($params);
|
|
$params['status'] = $this->getValueCombo($params['status']);
|
|
|
|
$params = array_filter($params, function($ele) {
|
|
return $ele !== "";
|
|
});
|
|
$errors = $this->validateValueForPointReport($params);
|
|
$params = array_diff_key($params, $errors);
|
|
|
|
$data = array_merge(
|
|
$data,
|
|
$params,
|
|
$this->load_pagination(
|
|
$this->report_point_model->get_report_point_records($params),
|
|
$params,
|
|
'index'
|
|
)
|
|
);
|
|
$data['points_report'] = $this->table->generate(
|
|
$this->report_point_model->get_report_point_records(
|
|
$params,
|
|
$data['limit'],
|
|
$data['offset']
|
|
)
|
|
);
|
|
|
|
if ($this->input->get('action_hidden')) {
|
|
$data['default_date'] = $default_date;
|
|
} else {
|
|
$data['default_date'] = 'on';
|
|
}
|
|
|
|
$data["page_title"] = "Points Redemption";
|
|
$this->renderPointsPage("view_pointsreport", $data);
|
|
}
|
|
|
|
public function getValueOfAssignsReport() {
|
|
return [
|
|
'search_text' => trim($this->input->get('search_text') ?? ''),
|
|
'find_select_value' =>
|
|
trim( ! empty($this->input->get('find_select'))
|
|
? $this->input->get('find_select')
|
|
: $this->input->get('find_select_value')),
|
|
'from_points' => trim($this->input->get('from_points') ?? ''),
|
|
'to_points' => trim($this->input->get('to_points') ?? ''),
|
|
];
|
|
}
|
|
|
|
public function setComboForAssignsReport($params) {
|
|
$this->load->model('combo_model');
|
|
|
|
$combo['find_select'] = $this->combo_model->getfindMemberType(
|
|
'find_select',
|
|
$params['find_select_value']
|
|
);
|
|
$combo['descsion_group'] = $this->combo_model->getDescisionGroupCombo(
|
|
'descsion_group',
|
|
trim($this->input->post('decision_group') ?? '')
|
|
);
|
|
|
|
return $combo;
|
|
}
|
|
|
|
public function validateValueForAssignsReport($params) {
|
|
$this->load->library('form_validation');
|
|
$this->form_validation->set_data($params);
|
|
$this->setFormRuleForAssignsReport();
|
|
|
|
$errors = [];
|
|
if ($this->form_validation->run() === FALSE) {
|
|
$errors = $this->form_validation->error_array();
|
|
}
|
|
return $errors;
|
|
}
|
|
|
|
public function setFormRuleForAssignsReport() {
|
|
$this->form_validation->set_rules(
|
|
'find_select_value',
|
|
'Select Value',
|
|
'in_list[email,firstname,lastname]'
|
|
);
|
|
$this->form_validation->set_rules(
|
|
'from_points',
|
|
'Points',
|
|
'numeric'
|
|
);
|
|
$this->form_validation->set_rules(
|
|
'to_points',
|
|
'Points',
|
|
'numeric'
|
|
);
|
|
}
|
|
|
|
public function assignpoints() {
|
|
|
|
$this->load->model('assigns_point_model');
|
|
|
|
$this->load->library('table');
|
|
$this->table->set_template($this->template);
|
|
|
|
$this->table->set_heading([
|
|
'ID',
|
|
'Username',
|
|
'FirstName',
|
|
'LastName',
|
|
'Points',
|
|
'Act',
|
|
]);
|
|
|
|
$params = $this->getValueOfAssignsReport();
|
|
|
|
$data = $this->setComboForAssignsReport($params);
|
|
|
|
$errors = $this->validateValueForAssignsReport($params);
|
|
$params = array_filter($params, function($ele) {
|
|
return $ele !== "";
|
|
});
|
|
$params = array_diff_key($params, $errors);
|
|
|
|
if (isset($params['search_text'])) {
|
|
// set ['email' => 'test@gmail.com']
|
|
$params[$params['find_select_value']] = $params['search_text'];
|
|
}
|
|
|
|
$data = array_merge(
|
|
$data,
|
|
$params,
|
|
$this->load_pagination(
|
|
$this->assigns_point_model->get_assigns_point_records($params),
|
|
$params,
|
|
'assignpoints'
|
|
)
|
|
);
|
|
$data['points_report'] = $this->table->generate(
|
|
$this->assigns_point_model->get_assigns_point_records(
|
|
$params,
|
|
$data['limit'],
|
|
$data['offset']
|
|
)
|
|
);
|
|
|
|
$data["page_title"] = "Allocate Point";
|
|
$this->renderPointsPage("view_assignpoints", $data);
|
|
}
|
|
|
|
public function viewAssignDetail() {
|
|
|
|
$data = array();
|
|
$this->load->model('combo_model');
|
|
$points_settings_value = '';
|
|
|
|
if ($this->input->get()) {
|
|
|
|
$member_id = $this->input->get('member_id');
|
|
|
|
|
|
if ($member_id != '' && $member_id > 0) {
|
|
|
|
$this->memberPointsItems($member_id, $data);
|
|
$data["points_settings"] = $this->combo_model->getPointsSettingsCombo("points_settings", $points_settings_value);
|
|
$data['member_id'] = $member_id;
|
|
|
|
$mysql = "SELECT * FROM members WHERE id = " . $member_id;
|
|
$query = $this->read_replica->query($mysql);
|
|
$mr = $query->row_array();
|
|
|
|
// print_r($mr);
|
|
|
|
$data["firstname"] = $mr["firstname"];
|
|
$data["lastname"] = $mr["lastname"];
|
|
$data["email"] = $mr["email"];
|
|
|
|
|
|
|
|
|
|
|
|
$this->load->view('points/extra/point_extra', $data);
|
|
}
|
|
/*
|
|
|
|
|
|
/*
|
|
|
|
|
|
$mysql = "SELECT a.*,a.id AS member_id, b.format AS picture_format ";
|
|
$mysql .= " FROM members a LEFT JOIN card_images b ON (b.id=a.profile_picture) WHERE a.id = $member_id";
|
|
$query = $this->db->query($mysql);
|
|
$data = $query->row_array();
|
|
$data["devices"] = [];
|
|
$data['storage'] = $savvyext->cfgReadChar('system.storage_url');
|
|
$data['start_date'] = $this->input->get('start_date');
|
|
$data['end_date'] = $this->input->get('end_date');
|
|
$data['status'] = !is_null($this->input->get('card_status')) ? $this->input->get('card_status') : 1;
|
|
$data['card_status'] = $this->combo_model->getStatusCombo(
|
|
'card_status', $data['status']
|
|
);
|
|
|
|
$q = "SELECT * FROM members_devices WHERE member_id=${member_id}";
|
|
$q .= $this->query_condition_member_detail($data);
|
|
|
|
$r = $this->db->query($q);
|
|
foreach ($r->result() as $row) {
|
|
$data["devices"][] = $row->player_id;
|
|
}
|
|
|
|
$this->load->view('points/extra/point_extra', $data);
|
|
} else {
|
|
echo "Not found - illegal call";
|
|
}
|
|
*/
|
|
}
|
|
}
|
|
|
|
private function memberPointsItems($member_id, &$data) {
|
|
|
|
$this->load->library('table');
|
|
$this->table->set_template($this->template);
|
|
|
|
$data['points_recieved'] = '';
|
|
|
|
$mysql = "SELECT s.point_key,s.name,p.points,p.added::date "
|
|
. " FROM members_points p "
|
|
. " LEFT JOIN points_settings s ON s.point_key=p.point_key "
|
|
. " WHERE p.member_id = " . $member_id . " ORDER BY p.added DESC";
|
|
$query = $this->read_replica->query($mysql);
|
|
$data["points_recieved"] = $this->table->generate($query);
|
|
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function SendMemberPoints() {
|
|
// echo "ameye aaaa olusesan bbbb";
|
|
$data = array();
|
|
$this->load->model('combo_model');
|
|
$points_settings_value = '';
|
|
|
|
|
|
if ($this->input->get()) {
|
|
|
|
$member_id = $this->input->get('member_id');
|
|
$point_key = $this->input->get('point_key');
|
|
|
|
if ($member_id != '' && $member_id > 0) {
|
|
$in = array();
|
|
$in["action"] = SAVVY_BKO_ASSIGN_POINTS;
|
|
|
|
$in['member_id'] = $member_id; // for session testing - not used
|
|
$in['point_key'] = $point_key;
|
|
|
|
$out = array();
|
|
$ret = $this->savvy_api($in, $out);
|
|
|
|
// print_r($out);
|
|
$message = $out["status_message"];
|
|
|
|
// if ($ret == PHP_API_OK) {
|
|
// $message = $out["status_message"];
|
|
// } else {
|
|
// $message = $out["status_message"];
|
|
// }
|
|
|
|
echo $message;
|
|
}
|
|
}
|
|
|
|
// $this->load->view('points/extra/point_extra', $data);
|
|
}
|
|
|
|
/**
|
|
* Systemic Points Summary Report
|
|
*
|
|
* @return view
|
|
*/
|
|
public function systemicPointsSummary() {
|
|
$data_report = $this->point_model->getSystemicPointsSummary();
|
|
$data = [
|
|
'page_title' => 'Systemic Points Summary',
|
|
'data_report' => $data_report,
|
|
'country_filter' => $this->combo_model->getCountriesHasAccount('country_filter', ''),
|
|
'point_key' => $this->combo_model->getPointKeyUsed('point_key', ''),
|
|
'point_value' => $this->combo_model->getPointValueUsed('point_value', ''),
|
|
];
|
|
|
|
$this->renderPointsPage('view_systemic_points_summary', $data);
|
|
}
|
|
|
|
|
|
public function getSystemicPointsDatatables() {
|
|
$data = $this->point_model->getSystemicPointsDatatables($this->input->post(), 'search');
|
|
header('Content-Type: application/json');
|
|
echo json_encode($data);
|
|
}
|
|
|
|
public function systemicPointsReportCSV()
|
|
{
|
|
$this->load->library('session');
|
|
$postData = $this->session->userdata("SPR_PARAM");
|
|
if ($postData) {
|
|
$this->point_model->getSystemicPointsDatatables($postData, 'export_csv');
|
|
} else {
|
|
echo 'Please try again!';
|
|
die();
|
|
}
|
|
}
|
|
}
|