Files
FloatBackOfffice/application/models/Parsed_item_payment_model.php
dev-chiefworks f76abffdcd first commit
2022-05-31 16:21:53 -04:00

88 lines
2.3 KiB
PHP

<?php
if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class Parsed_item_payment_model extends CI_Model
{
private $read_replica;
public function __construct()
{
parent::__construct();
$this->read_replica = $this->load->database('savvy_replica', TRUE);
}
public function get_parsed_item_payment_record(
$filters = [],
$count_record = true,
$limit = null,
$offset = null) {
$string_array = [
'category' => 'lower(tp.category)',
'email' => 'm.email',
];
$date_array = [
'from_date' => 'DATE(receipt_datetime) >=',
'to_date' => 'DATE(receipt_datetime) <=',
];
$number_array = [
'transport_provider_id' => 'transport_provider_id'
];
if ($count_record) {
$this->read_replica->select([
'count(*) AS all_count'
]);
} else {
$this->read_replica->select([
'pit.member_id',
'm.email',
'tp.name',
'pit.receipt_datetime',
'pit.created',
'pit.amount',
'pit.amount_currency',
'pit.transport_provider_id',
'pit.trackedemail_item_id',
'tp.category'
]);
$this->read_replica->order_by('pit.receipt_datetime','DESC');
}
$this->read_replica
->from('parsedemail_item_payment pit')
->join('transport_providers tp', 'pit.transport_provider_id = tp.id', 'left')
->join('members m', 'm.id = pit.member_id', 'left');
foreach($filters as $key => $val) {
if (array_key_exists($key, $date_array)) {
$this->read_replica->where($date_array[$key], $val);
} else if (array_key_exists($key, $string_array)) {
$this->read_replica->like($string_array[$key], strtolower($val));
} else if (array_key_exists($key, $number_array)) {
$this->read_replica->where($number_array[$key], $val);
}
}
if ($limit) {
$this->read_replica->limit($limit, $offset);
}
return $this->read_replica->get()->result_array();
}
}