149 lines
4.7 KiB
PHP
149 lines
4.7 KiB
PHP
<?php
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class Parsed_Receipts extends Admin_Controller {
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
|
|
$this->load->helper('form');
|
|
$this->load->library('form_validation');
|
|
$this->load->library('session');
|
|
$this->load->library('table');
|
|
|
|
$this->load->model('parsed_item_payment_model');
|
|
$this->load->model('combo_model');
|
|
}
|
|
|
|
public function index() {
|
|
|
|
$data['page_title'] = 'Parsed Receipts';
|
|
|
|
$this->table->set_template($this->template);
|
|
$this->table->set_heading([
|
|
'User ID',
|
|
'User Email',
|
|
'Merchant Name',
|
|
'Receipt(Travel) Date',
|
|
'Receipt Parsed Date',
|
|
'Amount',
|
|
'Currency',
|
|
'Transport Provider ID',
|
|
'Tracked Email ID',
|
|
'Category'
|
|
]);
|
|
|
|
$params = $this->getValueOfParsedReceipts();
|
|
|
|
$data['card_transport_provider'] =
|
|
$this
|
|
->combo_model
|
|
->getTransportProvidersCombo(
|
|
'card_transport_provider',
|
|
$params['transport_provider_id']
|
|
);
|
|
|
|
$params = array_filter($params, function($ele) {
|
|
return $ele !== "";
|
|
});
|
|
$errors = $this->validateValueForParsedReceipts($params);
|
|
$params = array_diff_key($params, $errors);
|
|
|
|
$data = array_merge(
|
|
$data,
|
|
$params,
|
|
$this->load_pagination(
|
|
$this
|
|
->parsed_item_payment_model
|
|
->get_parsed_item_payment_record($params)[0]['all_count'],
|
|
$params,
|
|
'index'
|
|
)
|
|
);
|
|
|
|
$records = $this->parsed_item_payment_model->get_parsed_item_payment_record(
|
|
$params, SELF::NONE_COUNT_RECORD, $data['limit'], $data['offset']
|
|
);
|
|
|
|
$data['parsed_item_payment_table'] = $this->table->generate($records);
|
|
|
|
$this->renderParsedReceiptsPage('view_parsed_item_payment', $data);
|
|
}
|
|
|
|
public function getValueOfParsedReceipts() {
|
|
return [
|
|
'from_date' => trim($this->input->get('from_date')),
|
|
'to_date' => trim($this->input->get('to_date')),
|
|
'transport_provider_id' => trim($this->input->get('card_transport_provider'))
|
|
? trim($this->input->get('card_transport_provider'))
|
|
: trim($this->input->get('transport_provider_id')),
|
|
'category' => trim($this->input->get('category')),
|
|
'email' => trim($this->input->get('email')),
|
|
];
|
|
}
|
|
|
|
public function validateValueForParsedReceipts($params) {
|
|
$this->load->library('form_validation');
|
|
$this->form_validation->set_data($params);
|
|
$this->setFormRuleForParsedReceipts();
|
|
|
|
$errors = [];
|
|
if ($this->form_validation->run() === FALSE) {
|
|
$errors = $this->form_validation->error_array();
|
|
}
|
|
return $errors;
|
|
}
|
|
|
|
public function setFormRuleForParsedReceipts() {
|
|
$date_pattern = 'regex_match[/\d{4}-\d{2}-\d{2}/]';
|
|
|
|
$this->form_validation->set_rules('from_date', 'from_date', $date_pattern);
|
|
$this->form_validation->set_rules('to_date', 'to_date', $date_pattern);
|
|
$this->form_validation->set_rules('transport_provider_id', 'transport_provider_id', 'integer');
|
|
}
|
|
|
|
public function load_pagination($total_record, $params, $action) {
|
|
// pagination
|
|
$this->load->library('pagination');
|
|
$config["total_rows"] = $total_record;
|
|
$config["base_url"] = base_url() . '/' . get_class($this) . '/' . $action;
|
|
$config["per_page"] = 10;
|
|
$config["uri_segment"] = 3;
|
|
$config["num_links"] = 5;
|
|
$config["suffix"] = '?'
|
|
. http_build_query($params);
|
|
$config["first_url"] = '/' . get_class($this) . "/{$action}/0?"
|
|
. 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"]
|
|
];
|
|
}
|
|
|
|
protected function renderParsedReceiptsPage($page_name, $data) {
|
|
$this->load->view('admin/view_admin_header', $data);
|
|
$this->load->view('parsed_receipts/' . $page_name, $data);
|
|
$this->load->view('admin/view_admin_footer', $data);
|
|
}
|
|
} |