Initial import
This commit is contained in:
213
application/controllers/antrian/AntrianCounterDedicated.php
Normal file
213
application/controllers/antrian/AntrianCounterDedicated.php
Normal file
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
class AntrianCounterDedicated extends MY_Controller
|
||||
{
|
||||
var $db_antrione;
|
||||
var $load;
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_antrione = $this->load->database("antrione", true);
|
||||
}
|
||||
function index()
|
||||
{
|
||||
echo "Api: Training Playground";
|
||||
}
|
||||
|
||||
function list_location()
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT * FROM location WHERE locationIsActive = 'Y'";
|
||||
$qry = $this->db_antrione->query($sql);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qry) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
$result = array(
|
||||
"records" => $data,
|
||||
"qry" => $last_qry
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function list_counter($branchID)
|
||||
{
|
||||
try {
|
||||
// $prm = $this->sys_input;
|
||||
// $locationID = array();
|
||||
// if (isset($prm['locationID'])) {
|
||||
// $locationID = trim($prm["locationID"]);
|
||||
// }
|
||||
$sql = "SELECT counter.* , locationID, locationName,
|
||||
fn_get_serviceID(counterID,counterIsDedicated) as serviceID
|
||||
FROM counter
|
||||
JOIN location ON counterLocationID = locationID
|
||||
AND locationIsActive = 'Y'
|
||||
WHERE counterIsActive = 'Y'
|
||||
AND counterBranchID = ?;
|
||||
";
|
||||
// $sql = "SELECT *
|
||||
// FROM counter
|
||||
// WHERE counterIsActive = 'Y'
|
||||
// AND counterLocationID = ?";
|
||||
$qry = $this->db_antrione->query($sql, [$branchID]);
|
||||
$last_qry = $this->db_antrione->last_query();
|
||||
if (!$qry) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$data = $qry->result_array();
|
||||
$result = array(
|
||||
"records" => $data,
|
||||
"qry" => $last_qry
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
function get_antrian()
|
||||
{
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
$arrCounter = array();
|
||||
if (isset($prm['arr_counter'])) {
|
||||
array_push($prm['arr_counter'], 0);
|
||||
$arrCounter = implode(",", $prm["arr_counter"]);
|
||||
}
|
||||
$branchID = $prm["branchID"];
|
||||
|
||||
$sqlNotServed = "SELECT queueID,
|
||||
statusID, IFNULL(queueNumber,'') as queueNumber,
|
||||
IFNULL(queueSkipDate, 'NEW') as skipQueue,
|
||||
( CASE
|
||||
WHEN statusID = 1 THEN 1
|
||||
END ) as order_status
|
||||
FROM queue
|
||||
JOIN service
|
||||
ON serviceID = queueServiceID
|
||||
AND serviceIsActive = 'Y'
|
||||
AND serviceIsConsultDoctor = 'N'
|
||||
AND queueBranchID = {$branchID}
|
||||
JOIN status
|
||||
ON statusID = queueStatusID
|
||||
WHERE queueIsActive = 'Y'
|
||||
AND statusID IN (1)
|
||||
AND queueLocationID IN (SELECT GROUP_CONCAT(counterLocationID) FROM counter WHERE counterID IN ($arrCounter))
|
||||
AND queueCounterID IN ($arrCounter)
|
||||
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')
|
||||
ORDER BY IFNULL(queueSkipDate, queueCreated)";
|
||||
$qryNotServed = $this->db_antrione->query($sqlNotServed, []);
|
||||
$last_qry_not = $this->db_antrione->last_query();
|
||||
if (!$qryNotServed) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry_not
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$notServed = $qryNotServed->result_array();
|
||||
|
||||
$sqlCall = "SELECT queueID,
|
||||
statusID, IFNULL(queueNumber,'') as queueNumber,
|
||||
queueCounterID,
|
||||
counterCode,
|
||||
counterID,
|
||||
( CASE
|
||||
WHEN statusID = 2 THEN 1
|
||||
WHEN statusID = 5 THEN 2
|
||||
END ) as order_status
|
||||
FROM queue
|
||||
JOIN service
|
||||
ON serviceID = queueServiceID
|
||||
AND serviceIsActive = 'Y'
|
||||
AND serviceIsConsultDoctor = 'N'
|
||||
AND queueBranchID = {$branchID}
|
||||
JOIN status
|
||||
ON statusID = queueStatusID
|
||||
JOIN counter ON queueCounterID = counterID
|
||||
WHERE queueIsActive = 'Y'
|
||||
AND statusID IN (2, 5)
|
||||
AND queueCounterID IN ($arrCounter)
|
||||
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')
|
||||
ORDER BY order_status, queueCreated asc";
|
||||
$qryCall = $this->db_antrione->query($sqlCall, []);
|
||||
$last_qry_served = $this->db_antrione->last_query();
|
||||
if (!$qryCall) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry_served
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$call = $qryCall->result_array();
|
||||
|
||||
$sqlServed = "SELECT queueID,
|
||||
statusID, IFNULL(queueNumber,'') as queueNumber,
|
||||
queueCounterID,
|
||||
counterCode,
|
||||
counterID,
|
||||
( CASE
|
||||
WHEN statusID = 3 THEN 1
|
||||
END ) as order_status
|
||||
FROM queue
|
||||
JOIN service
|
||||
ON serviceID = queueServiceID
|
||||
AND serviceIsActive = 'Y'
|
||||
AND serviceIsConsultDoctor = 'N'
|
||||
AND queueBranchID = {$branchID}
|
||||
JOIN status
|
||||
ON statusID = queueStatusID
|
||||
JOIN counter ON queueCounterID = counterID
|
||||
WHERE queueIsActive = 'Y'
|
||||
AND statusID IN (3)
|
||||
AND queueCounterID IN ($arrCounter)
|
||||
AND DATE_FORMAT(queueCreated, '%d-%m-%Y') = DATE_FORMAT(NOW(), '%d-%m-%Y')
|
||||
ORDER BY order_status, queueCreated asc";
|
||||
$qryServed = $this->db_antrione->query($sqlServed, []);
|
||||
$last_qry_call = $this->db_antrione->last_query();
|
||||
if (!$qryServed) {
|
||||
$error = array(
|
||||
"message" => $this->db_antrione->error()["message"],
|
||||
"sql" => $last_qry_call
|
||||
);
|
||||
$this->sys_error_db($error);
|
||||
exit;
|
||||
}
|
||||
$served = $qryServed->result_array();
|
||||
$data = [];
|
||||
$data["served"] = $served;
|
||||
$data['not_served'] = $notServed;
|
||||
$data['call'] = $call;
|
||||
$data['qry_call'] = $last_qry_call;
|
||||
$data['qry_not_served'] = $last_qry_not;
|
||||
$data['qry_serve'] = $last_qry_served;
|
||||
$result = array(
|
||||
$data
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user