110 lines
3.7 KiB
PHP
110 lines
3.7 KiB
PHP
<?php
|
|
|
|
if (!defined('BASEPATH')) {
|
|
exit('No direct script access allowed');
|
|
}
|
|
|
|
class Booking_model extends CI_Model {
|
|
|
|
public function __constructor() {
|
|
parrent::__constructor();
|
|
}
|
|
|
|
public function getReports($params = null, $page = 0, $limit = 10) {
|
|
$queryString = 'SELECT * FROM booking';
|
|
$countString = 'SELECT COUNT(*) FROM booking';
|
|
$whereString = ' WHERE 1=1';
|
|
$orderByString = ' ORDER BY created DESC';
|
|
$offset = $page * $limit;
|
|
$paginationString = " LIMIT $limit OFFSET $offset";
|
|
|
|
if (isset($params['id']) && !empty($params['id'])) {
|
|
$whereString .= " AND id = '" . pg_escape_string($params['id']) . "' ";
|
|
}
|
|
|
|
if (isset($params['quote_id']) && !empty($params['quote_id'])) {
|
|
$whereString .= " AND quote_id = '" . pg_escape_string($params['quote_id']) . "' ";
|
|
}
|
|
|
|
if (isset($params['member_id']) && !empty($params['member_id'])) {
|
|
$whereString .= " AND member_id = '" . pg_escape_string($params['member_id']) . "' ";
|
|
}
|
|
|
|
if (isset($params['cost']) && $params['cost'] != '') {
|
|
$whereString .= " AND cost = '" . pg_escape_string($params['cost']) . "' ";
|
|
}
|
|
|
|
if (isset($params['provider_booking_ref']) && !empty($params['provider_booking_ref'])) {
|
|
$whereString .= " AND provider_booking_ref ILIKE '%" . pg_escape_string($params['provider_booking_ref']) . "%' ";
|
|
}
|
|
|
|
if (isset($params['message']) && !empty($params['message'])) {
|
|
$whereString .= " AND message ILIKE '%" . pg_escape_string($params['message']) . "%' ";
|
|
}
|
|
|
|
// if (isset($params['details']) && !empty($params['details'])) {
|
|
// // Filter JSON data
|
|
// }
|
|
|
|
if (isset($params['status']) && !empty($params['status'])) {
|
|
switch ($params['status']) {
|
|
case 'pending':
|
|
$whereString .= " AND status = 1 ";
|
|
break;
|
|
case 'cancelled':
|
|
$whereString .= " AND status = 3 ";
|
|
break;
|
|
case 'active':
|
|
$whereString .= " AND status IN (2, 4) ";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (isset($params['created']) && !empty($params['created'])) {
|
|
$created = explode(' - ', $params['created']);
|
|
$whereString .= " AND created BETWEEN '$created[0] 00:00:00' AND '$created[1] 23:59:59.99' ";
|
|
}
|
|
|
|
if (isset($params['updated']) && !empty($params['updated'])) {
|
|
$updated = explode(' - ', $params['updated']);
|
|
$whereString .= " AND updated BETWEEN '$updated[0] 00:00:00' AND '$updated[1] 23:59:59.99' ";
|
|
}
|
|
|
|
if (isset($params['completed']) && !empty($params['completed'])) {
|
|
$completed = explode(' - ', $params['completed']);
|
|
$whereString .= " AND completed BETWEEN '$completed[0] 00:00:00' AND '$completed[1] 23:59:59.99' ";
|
|
}
|
|
|
|
$queryString .= $whereString . $orderByString . $paginationString;
|
|
$countString .= $whereString;
|
|
|
|
$query = $this->db->query($queryString);
|
|
$countQuery = $this->db->query($countString);
|
|
|
|
$data = [
|
|
'result' => $query->result_array(),
|
|
'total' => $countQuery->result_array()[0]['count'],
|
|
'pageSize' => $limit,
|
|
'pageNo' => $page
|
|
];
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function store($data) {
|
|
$this->db->insert('booking', $data);
|
|
}
|
|
|
|
public function update($id, $data) {
|
|
$this->db->update('booking', $data, "id = $id");
|
|
}
|
|
|
|
public function delete($params) {
|
|
$this->db->delete('booking', $params);
|
|
}
|
|
|
|
}
|
|
|
|
?>
|