"
",
'thead_open' => '',
'thead_close' => '',
'heading_row_start' => '',
'heading_row_end' => '
',
'heading_cell_start' => '',
'heading_cell_end' => ' | ',
'tbody_open' => '',
'tbody_close' => '',
'row_start' => '',
'row_end' => '
',
'cell_start' => '',
'cell_end' => ' | ',
'row_alt_start' => '',
'row_alt_end' => '
',
'cell_alt_start' => '',
'cell_alt_end' => ' | ',
'table_close' => '
'
);
public function index() {
$this->load->helper('url');
$data = array();
$this->load->library('table');
$this->table->set_template($this->template);
$data['backoffice_users'] = "";
$mysql = "SELECT c.country, '' AS View FROM subscriptions s LEFT JOIN country c ON c.code =s.country ORDER by s.id ASC";
$query = $this->read_replica->query($mysql);
$this->table->set_heading('Country', array('data' => 'View', 'style' => 'width:50px'));
$data['subscription_country'] = $this->table->generate($query);
$this->renderSubscriptionPage('view_subscription', $data);
// echo 'Ameye Olu';
}
public function viewsubscription() {
$subscription_id = $this->input->get('subscription_id');
if ($subscription_id > 0) {
$this->load->library('table');
$this->table->set_template($this->template);
$mysql = "SELECT 'Title: :'||title||'
Description :'||description||'
Price :'|| price*0.01 AS Subscription FROM subscriptions_detail WHERE subscriptions =" . $subscription_id;
$query = $this->read_replica->query($mysql);
//$this->table->set_heading( 'Country', array('data' => 'View', 'style' => 'width:50px') );
$data['subscription_table'] = $this->table->generate($query);
$this->load->view('admin/common/subscription_detail', $data);
}
}
/*
SELECT mca.*,mc.card_points,mc.card_reciept,mc.title,UPPER(tp.name) AS transporter FROM members_card_assign mca LEFT JOIN main_cards mc ON mc.id =mca.card_id LEFT JOIN transport_providers tp ON tp.id::text =mc.card_reciept WHERE mca.id =2654162;
id | member_id | card_id | status | added | list_order | subscribe | how | card_points | card_reciept | title | transporter
---------+-----------+---------+--------+----------------------------+------------+----------------------------+-----+-------------+--------------+--------------------------------------------------+-------------
2654162 | 74 | 49 | 1 | 2019-11-10 15:13:11.904596 | 0 | 2019-11-11 07:45:15.314858 | | 0 | 3 | Earn points worth $5 on your next ride with Grab | GRAB
(1 row)
*/
public function procSubscription() {
echo "Get Subscription ID
Check Status
Insert The Points
Modify Status
Clean-up - email if needed";
$assign_id = $this->input->get('assign_id'); // this is like the assign ID
echo "
Assign ID = " . $assign_id . "
";
if ($assign_id > 0) {
$mysql = " SELECT tp.name AS card_reciept_name, mca.*,mc.card_points,mc.card_reciept,mc.title,UPPER(tp.name) AS transporter "
. " FROM members_card_assign mca "
. " LEFT JOIN main_cards mc ON mc.id =mca.card_id "
. " LEFT JOIN transport_providers tp ON tp.id::text =mc.card_reciept "
. " WHERE mca.id =" . $assign_id;
// echo $mysql;
$query = $this->read_replica->query($mysql);
if ($query->num_rows() == 1) {
$inx = $query->result_array();
// print_r($inx);
$member_id = $inx[0]['member_id'];
$card_points = $inx[0]['card_points']*50;
$card_reciept_name = $inx[0]['card_reciept_name'];
$out = array();
$inx['action'] = SAVVY_BKO_PROCESS_POINTS;
$inx["assign_id"] = $assign_id;
$ret = $this->savvy_api($inx, $out);
if ($ret == PHP_API_OK) {
// $message = $id > 0 ? 'Updated!' : 'Created!';
$this->pointsNotification($member_id, $assign_id, $card_points,$card_reciept_name );
echo "Points Allocated";
} else {
// $message = 'Failed to ' . ($id > 0 ? 'update' : 'create') . ' card: ' . isset($out["status"]) ? $out["status"] : '';
echo "Points allocation error";
}
}
} else {
echo "The selected sction not found";
}
return 0;
}
/*
* savvy=> SELECT mca.*,mc.card_points,mc.card_reciept,mc.title,UPPER(tp.name) AS transporter FROM members_card_assign mca LEFT JOIN main_cards mc ON mc.id =mca.card_id LEFT JOIN transport_providers tp ON tp.id::text =mc.card_reciept WHERE mca.id =2655337;
id | member_id | card_id | status | added | list_order | subscribe | how | completed | trigger_key | message | cat | reciept_count | updated | card_points | card_reciept | title | transporter
---------+-----------+---------+--------+----------------------------+------------+----------------------------+-----+-----------+-------------+---------+-----+---------------+----------------------------+-------------+--------------+-------------------------------+-------------
2655337 | 251 | 132 | 1 | 2020-04-10 07:47:50.809046 | 0 | 2020-04-10 07:49:00.380875 | | | | | | 0 | 2020-05-14 16:35:03.030581 | 0 | | Get $10 back on Anywheel Bike |
(1 row)
*/
private function pointsNotification($member_id, $assign_id, $points,$card_reciept_name ) {
$outX = array();
$x = [];
$x["mmode"] = "AUTO";
$x["trigger_key"] = "ETRG0019";
$x["action"] = FLOAT_SYSTEM_CREATE_NOTIFICATION;
$x["msg"] = "You've just earned $points float Points for ".$card_reciept_name ;
$x["pid"] = 0;
$x["member_id"] = $member_id;
$x["notice_type"] = "INSTANT";
$ret = $this->savvy_api($x, $outX);
// print_r($x);
return 0;
}
public function load_pagination($all_record, $params, $action, $limit = 10) {
$action_hidden = $this->input->get('action_hidden');
// pagination
$this->load->library('pagination');
$config["total_rows"] = count($all_record);
$config["base_url"] = base_url() . "/subscription/" . $action;
$config["per_page"] = $limit;
$config["uri_segment"] = 3;
$config["num_links"] = 5;
$config["suffix"] = "?action_hidden=${action_hidden}&"
. http_build_query($params);
$config["first_url"] = "/subscription/{$action}/0?action_hidden=${action_hidden}&"
. http_build_query($params);
$config['full_tag_open'] = "";
$config['num_tag_open'] = '';
$config['num_tag_close'] = '';
$config['cur_tag_open'] = "";
$config['cur_tag_close'] = "";
$config['next_tag_open'] = "";
$config['next_tagl_close'] = "";
$config['prev_tag_open'] = "";
$config['prev_tagl_close'] = "";
$config['first_tag_open'] = "";
$config['first_tagl_close'] = "";
$config['last_tag_open'] = "";
$config['last_tagl_close'] = "";
$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 getValueCombo($val) {
$status_value = range(0, 9);
return in_array($val, $status_value) ? $val : '';
}
public function setComboForSubscriptionReport($params) {
$this->load->model('combo_model');
$combo['card_status'] = $this->combo_model->getStatusComboFromZeroToOne(
'card_status', $params['status']
);
$combo['card_ready'] = $this->combo_model->getYesNoComboWithAll(
'card_ready', $params['ready']
);
$combo['card_completed'] = $this->combo_model->getCompletedCombo(
'card_completed', $params['completed']
);
return $combo;
}
/**
* prepare search params
* @param array &$data
* @param array $params
*/
public function subscribed_deals_searching(&$data, &$params) {
// load combo model
$this->load->model('combo_model');
$data['points'] = $this->combo_model->getPointsSubscribedDeals( 'points', isset( $params['points'] ) ? $params['points'] : 0 );
unset( $params['points'] );
}
public function setFormRuleForSubscriptionReportForm() {
$status_pattern = 'regex_match[/^(?:[0-9])$/]';
$date_pattern = 'regex_match[/\d{4}-\d{2}-\d{2}/]';
$this->form_validation->set_rules('reciept_count', 'Reciepts', 'numeric');
$this->form_validation->set_rules('from_date', 'Created date', $date_pattern);
$this->form_validation->set_rules('to_date', 'Created date', $date_pattern);
$this->form_validation->set_rules('status', 'Status', $status_pattern);
}
public function getValueOfSubscriptionReportForm() {
return [
'title' => trim($this->input->get('title') ?? ''),
'card_receipts' => trim($this->input->get('card_receipts') ?? ''),
'reciept_count' => trim($this->input->get('reciept_count') ?? ''),
'from_date' => trim($this->input->get('from_date') ?? ''),
'to_date' => trim($this->input->get('to_date') ?? ''),
'status' => 1,
'ready' => trim($this->input->get('card_ready') ?? ($this->input->get('ready') ?? -1)),
'completed' => trim($this->input->get('card_completed') ?? ($this->input->get('completed') ?? -1)),
'email' => trim($this->input->get('email')),
'id' => trim($this->input->get('id'))
];
}
public function validateValueForSubscriptionReport($params) {
$this->load->library('form_validation');
$this->form_validation->set_data($params);
$this->setFormRuleForSubscriptionReportForm();
$errors = [];
if ($this->form_validation->run() === FALSE) {
$errors = $this->form_validation->error_array();
}
return $errors;
}
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 subscriptionreport() {
$this->load->model('subscription_model');
$this->load->library('table');
$this->table->set_template($this->template);
$this->table->set_heading([
'ID',
'FirstName',
'Lastname',
'Description',
'Date Subscribed',
'Status',
'Card Id',
'Card Reciept',
'Reciepts',
'Ready',
'Action',
'Dt. Completed'
]);
$params = $this->getValueOfSubscriptionReportForm();
$default_date = $this->input->get('default_date');
if ($this->input->get('action_hidden')) {
$this->setOnePastMonth($params, $default_date);
} else {
$this->setOnePastMonth($params);
}
$data = $this->setComboForSubscriptionReport($params);
$data["page_title"] = "Subscription Report";
$params['status'] = $this->getValueCombo($params['status']);
$params = array_filter($params, function($ele) {
return $ele !== "";
});
$errors = $this->validateValueForSubscriptionReport($params);
$params = array_diff_key($params, $errors);
$data = array_merge(
$data, $params, $this->load_pagination(
$this->subscription_model->get_subscription_report_records($params), $params, 'SubscriptionReport'
)
);
$data['subscription_table'] = $this->table->generate(
$this->subscription_model->get_subscription_report_records(
$params, $data['limit'], $data['offset']
)
);
if ($this->input->get('action_hidden')) {
$data['default_date'] = $default_date;
} else {
$data['default_date'] = 'on';
}
$this->renderSubscriptionPage('view_subscriptionreport', $data);
}
/**
* Show Subscribed Deals report
* @return mixed
*/
public function subscribed_deals() {
$this->load->model('summary_report_model');
// load table library
$this->load->library('table');
$this->table->set_template($this->template);
$this->table->set_heading([
'Card ID',
'Deal Name',
'Location',
'Deal Value (Card Points)',
'Total Subscribed in past 24 hours',
'Total Subscribed in past 7 days',
'Total Subscribed in past 14 days',
'Total Subscribed in past 30 days',
'Total Subscribed All Time',
'Deals Redeemed'
]);
$data = array();
$params = $this->input->get();
// total report
$data['page_title'] = 'Subscribed Deals Report';
$data['overall_summary'] = $this->summary_report_model->getSummaryReport( $params );
$data = array_merge(
$data,
$params,
$this->load_pagination(
$data['overall_summary'], $params, 'subscribed_deals', $limit = 20
)
);
// get subscribed summary report
$data['summary_report'] = $this->table->generate(
$this->summary_report_model->getSummaryReport( $params, $data['limit'], $data['offset'] )
);
// prepare filter combo
$this->subscribed_deals_searching( $data, $params );
$this->renderSubscriptionPage( 'view_subscribed_deals', $data );
}
public function validateValueForCarpoolReport($params) {
$this->load->library('form_validation');
$this->form_validation->set_data($params);
$this->setFormRuleForCarpoolReportForm();
$errors = [];
if ($this->form_validation->run() === FALSE) {
$errors = $this->form_validation->error_array();
}
return $errors;
}
public function setFormRuleForCarpoolReportForm() {
$status_pattern = 'regex_match[/^(?:[0-9])$/]';
$date_pattern = 'regex_match[/\d{4}-\d{2}-\d{2}/]';
$this->form_validation->set_rules('card_id', 'Card ID', 'numeric');
$this->form_validation->set_rules('pool', 'Pool', 'numeric');
$this->form_validation->set_rules('from_date', 'Created date', $date_pattern);
$this->form_validation->set_rules('to_date', 'Created date', $date_pattern);
$this->form_validation->set_rules('status', 'Status', 'numeric');
}
public function getValueOfCarpoolReportForm() {
return [
'email' => trim($this->input->get('email') ?? ''),
'title' => trim($this->input->get('title') ?? ''),
'from_date' => trim($this->input->get('from_date') ?? ''),
'to_date' => trim($this->input->get('to_date') ?? ''),
'pool' => trim($this->input->get('pool') ?? ''),
'card_id' => trim($this->input->get('card_id') ?? ''),
'status' => trim($this->input->get('status') ?? '')
];
}
public function carpoolreport() {
$this->load->model('carpool_report_model');
$this->load->library('table');
$this->table->set_template($this->template);
$data["page_title"] = "Carpool Report";
$this->table->set_heading([
'CarPool ID',
'?column?',
'LastName',
'Email',
'Pool',
'Title',
'Card ID',
'Added',
'Updated',
'Status',
'Proc1'
]);
$params = $this->getValueOfCarpoolReportForm();
$default_date = $this->input->get('default_date');
if ($this->input->get('action_hidden')) {
$this->setOnePastMonth($params, $default_date);
} else {
$this->setOnePastMonth($params);
}
$params = array_filter($params, function($ele) {
return $ele !== "";
});
$errors = $this->validateValueForCarpoolReport($params);
$params = array_diff_key($params, $errors);
$data = array_merge(
$data, $params, $this->load_pagination(
$this->carpool_report_model->get_carpool_records($params), $params, 'carpoolreport'
)
);
$data['carpool_table'] = $this->table->generate(
$this->carpool_report_model->get_carpool_records(
$params, $data['limit'], $data['offset']
)
);
if ($this->input->get('action_hidden')) {
$data['default_date'] = $default_date;
} else {
$data['default_date'] = 'on';
}
$this->renderSubscriptionPage('view_carpoolreport', $data);
}
public function setComboForCarPoolFriendReport($params) {
$this->load->model('combo_model');
$combo['card_status'] = $this->combo_model->getStatusComboFromZeroToNine(
'card_status', $params['status']
);
return $combo;
}
public function setFormRuleForCarPoolFriendReportForm() {
$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('carpool_id', 'Carpool ID', 'numeric');
$this->form_validation->set_rules('from_date', 'Created date', $date_pattern);
$this->form_validation->set_rules('to_date', 'Created date', $date_pattern);
$this->form_validation->set_rules('status', 'Status', 'numeric');
}
public function getValueOfCarPoolFriendReportForm() {
return [
'member_id' => trim($this->input->get('member_id') ?? ''),
'carpool_id' => trim($this->input->get('carpool_id') ?? ''),
'from_date' => trim($this->input->get('from_date') ?? ''),
'to_date' => trim($this->input->get('to_date') ?? ''),
'email' => trim($this->input->get('email') ?? ''),
'status' => trim($this->input->get('card_status') ?? ($this->input->get('status') ?? -1)),
];
}
public function validateValueForCarPoolFriendReport($params) {
$this->load->library('form_validation');
$this->form_validation->set_data($params);
$this->setFormRuleForCarPoolFriendReportForm();
$errors = [];
if ($this->form_validation->run() === FALSE) {
$errors = $this->form_validation->error_array();
}
return $errors;
}
public function carpoolfriend() {
$this->load->model('carpool_friend_model');
$this->load->library('table');
$this->table->set_template($this->template);
$data["page_title"] = "Carpool Friend Report";
$this->table->set_heading([
'Proc Status',
'Member',
'Member ID',
'ID',
'Carpool ID',
'FirstName',
'LastName',
'Email',
'Status',
'Accept Status',
'Pool Status',
'Level A',
'Level B',
'Added',
'Last Message',
'Updated',
'Link'
]);
$params = $this->getValueOfCarpoolFriendReportForm();
$default_date = $this->input->get('default_date');
if ($this->input->get('action_hidden')) {
$this->setOnePastMonth($params, $default_date);
} else {
$this->setOnePastMonth($params);
}
$data = $this->setComboForCarpoolFriendReport($params);
$data["page_title"] = "Carpool Friend Report";
$params['status'] = $this->getValueCombo($params['status']);
$params = array_filter($params, function($ele) {
return $ele !== "";
});
$errors = $this->validateValueForCarPoolFriendReport($params);
$params = array_diff_key($params, $errors);
$data = array_merge(
$data, $params, $this->load_pagination(
$this->carpool_friend_model->get_carpool_friend_records($params), $params, 'carpoolfriend'
)
);
$data['carpool_friend_table'] = $this->table->generate(
$this->carpool_friend_model->get_carpool_friend_records(
$params, $data['limit'], $data['offset']
)
);
if ($this->input->get('action_hidden')) {
$data['default_date'] = $default_date;
} else {
$data['default_date'] = 'on';
}
$this->renderSubscriptionPage('view_carpoolfriend', $data);
}
public function setFormRuleForSurveyReportForm() {
$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('from_date', 'Created date', $date_pattern);
$this->form_validation->set_rules('to_date', 'Created date', $date_pattern);
$this->form_validation->set_rules('status', 'Status', $status_pattern);
}
public function getValueOfSurveyReportForm() {
return [
'member_id' => trim($this->input->get('member_id') ?? ''),
'description' => trim($this->input->get('description') ?? ''),
'answer' => trim($this->input->get('answer') ?? ''),
'action' => trim($this->input->get('action') ?? ''),
'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)),
'ready' => trim($this->input->get('card_ready') ?? ($this->input->get('ready') ?? -1)),
'completed' => trim($this->input->get('card_completed') ?? ($this->input->get('completed') ?? -1)),
];
}
public function validateValueForSurveyReport($params) {
$this->load->library('form_validation');
$this->form_validation->set_data($params);
$this->setFormRuleForSurveyReportForm();
$errors = [];
if ($this->form_validation->run() === FALSE) {
$errors = $this->form_validation->error_array();
}
return $errors;
}
public function surveyreport() {
$this->load->model('survey_report_model');
$this->load->library('table');
$this->table->set_template($this->template);
$this->table->set_heading([
'ID:MEMBER_ID',
'FirstName',
'Lastname',
'Description',
'Answer',
'Status',
'Date',
'Action',
]);
$params = $this->getValueOfSurveyReportForm();
$default_date = $this->input->get('default_date');
if ($this->input->get('action_hidden')) {
$this->setOnePastMonth($params, $default_date);
} else {
$this->setOnePastMonth($params);
}
$data = $this->setComboForSubscriptionReport($params);
$data["page_title"] = "Survey Report";
$params['status'] = $this->getValueCombo($params['status']);
$params = array_filter($params, function($ele) {
return $ele !== "";
});
$errors = $this->validateValueForSurveyReport($params);
$params = array_diff_key($params, $errors);
$data = array_merge(
$data, $params, $this->load_pagination(
$this->survey_report_model->get_survey_report_records($params), $params, 'surveyreport'
)
);
$data['subscription_table'] = $this->table->generate(
$this->survey_report_model->get_survey_report_records(
$params, $data['limit'], $data['offset']
)
);
if ($this->input->get('action_hidden')) {
$data['default_date'] = $default_date;
} else {
$data['default_date'] = 'on';
}
$this->renderSubscriptionPage('view_surveyreport', $data);
}
protected function renderSubscriptionPage($page_name, $data) {
$this->load->view('admin/view_admin_header', $data);
$this->load->view('subscription/' . $page_name, $data);
$this->load->view('admin/view_admin_footer', $data);
}
}