90 lines
3.4 KiB
PHP
90 lines
3.4 KiB
PHP
<?php
|
|
class Queue extends MY_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
function log($msg,$pdate)
|
|
{
|
|
echo "$pdate $msg\n";
|
|
}
|
|
function index()
|
|
{
|
|
$prm = $this->sys_input;
|
|
$pdate = date('Y-m-d',strtotime($prm['pdate']));
|
|
|
|
$this->db->trans_begin();
|
|
$sql = "SELECT * FROM antrian_online.queue WHERE queueDate = ? AND queueNewQueueID = 0 ORDER BY queueID ASC";
|
|
$qry = $this->db->query($sql, [$pdate]);
|
|
if (!$qry) {
|
|
$message =
|
|
$this->db->error()["message"] . "|" . $this->db->last_query();
|
|
$this->log($message,$pdate);
|
|
$this->db->trans_rollback();
|
|
exit();
|
|
}
|
|
$rows = $qry->result_array();
|
|
|
|
foreach ($rows as $r) {
|
|
$service = $this->db->query("SELECT serviceID as serviceid FROM antrione.service WHERE serviceIsOnline = 'Y' AND serviceIsActive = 'Y' ORDER BY serviceID ASC LIMIT 1")->row();
|
|
$serviceid = $service->serviceid;
|
|
|
|
$counter = $this->db->query("SELECT counterServiceCounterID as counterid FROM antrione.counter_service WHERE counterServiceServiceID = $serviceid AND counterServiceIsActive = 'Y' ORDER BY counterServiceID ASC LIMIT 1")->row();
|
|
$counterid = $counter->counterid;
|
|
|
|
$location = $this->db->query("SELECT counterLocationID as locationid FROM antrione.counter WHERE counterLocationID = $counterid")->row();
|
|
$locationid = $location->locationid;
|
|
|
|
$number = $this->db->query("SELECT antrione.`fn_get_numbering`($serviceid) as numbering")->row();
|
|
$numbering = $number->numbering;
|
|
|
|
$sql_insert = "insert into antrione.queue(queueNumber,
|
|
queueCounterID,
|
|
queueServiceID,
|
|
queueLocationID,
|
|
queueCreated,
|
|
queueLastUpdated)
|
|
values(?,
|
|
?,
|
|
?,
|
|
?,
|
|
now(),
|
|
now())";
|
|
$qry = $this->db->query($sql_insert, [
|
|
$numbering,
|
|
$counterid,
|
|
$serviceid,
|
|
$locationid
|
|
]);
|
|
$last_id = $this->db->insert_id();
|
|
if (!$qry) {
|
|
$this->log("Error " . $this->db->error()["message"],$pdate);
|
|
$this->db->trans_rollback();
|
|
exit();
|
|
}else{
|
|
$message = "Insert Queue [{$r["queueID"]}] {$r["queueQrCode"]}";
|
|
$this->log($message,$pdate);
|
|
$sql_update = "UPDATE antrian_online.queue SET queueNewQueueID = $last_id WHERE queueID = ?";
|
|
$qry = $this->db->query($sql_update, [
|
|
$r["queueID"]]);
|
|
if (!$qry) {
|
|
$this->log("Error " . $this->db->error()["message"],$pdate);
|
|
$this->db->trans_rollback();
|
|
exit();
|
|
}
|
|
}
|
|
}
|
|
if ($this->db->trans_status === false) {
|
|
$this->db->trans_rollback();
|
|
$this->log(
|
|
"End Queue Insert : Error DB transaction." .
|
|
$this->db->error()["message"], $pdate
|
|
);
|
|
} else {
|
|
$this->db->trans_commit();
|
|
$this->log("End Queue Insert : OK",$pdate);
|
|
}
|
|
}
|
|
}
|