148 lines
5.5 KiB
PHP
148 lines
5.5 KiB
PHP
<?php
|
|
class Antrian extends MY_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
function getAntrian()
|
|
{
|
|
try {
|
|
$prm = $this->sys_input;
|
|
$service_id = "service_id";
|
|
if (isset($prm['service_id'])) {
|
|
$service_id = trim($prm["service_id"]);
|
|
}
|
|
$service_code = "service_code";
|
|
if (isset($prm['service_code'])) {
|
|
$service_code = trim($prm["service_code"]);
|
|
}
|
|
$date = date("Y-m-d");
|
|
// PERCOBAAN
|
|
$this->db->trans_begin();
|
|
$sql = "SELECT MAX(Q_QueueNumber ) as queueNumb
|
|
FROM q_queue WHERE Q_QueueQ_ServiceID = ?
|
|
AND DATE(Q_QueueCreated) = DATE(NOW()) FOR UPDATE";
|
|
$qry = $this->db->query($sql, array($service_id));
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
$inserted_id = 0;
|
|
$rows = $qry->row_array();
|
|
|
|
$sql_log = "INSERT INTO q_queuelog(
|
|
Q_QueueLogDate,
|
|
Q_QueueLogQ_StatusID,
|
|
Q_QueueLogQ_CounterID,
|
|
Q_QueueLogIsActive)
|
|
VALUES (NOW(), 1, 0,'Y')";
|
|
$qry_log = $this->db->query($sql_log, array());
|
|
$last_qry = $this->db->last_query();
|
|
$inserted_id_log = $this->db->insert_id();
|
|
if ($rows['queueNumb'] != NULL) {
|
|
$number = $rows['queueNumb'];
|
|
$code = $number[0];
|
|
$cd = str_split($number);
|
|
|
|
$count = "";
|
|
for ($i = 1; $i < count($cd); $i++) {
|
|
$count = $count . $cd[$i];
|
|
}
|
|
|
|
$count = $count + 1;
|
|
$count = str_pad($count, 3, "0", STR_PAD_LEFT);
|
|
|
|
$newNumber = $code . $count;
|
|
$sql = "INSERT INTO q_queue (
|
|
Q_QueueNumber,
|
|
Q_QueueStatusID,
|
|
Q_QueueQ_QueueLogID,
|
|
Q_QueueQ_CounterID,
|
|
Q_QueueQ_ServiceID,
|
|
Q_QueueCreated,
|
|
Q_QueueLastUpdated)
|
|
VALUES(
|
|
?, 1, ?, 0,?,NOW(), NOW())
|
|
";
|
|
$qry = $this->db->query($sql, array($newNumber, $inserted_id_log, $service_id));
|
|
$last_qry = $this->db->last_query();
|
|
$inserted_id = $this->db->insert_id();
|
|
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
} else {
|
|
$count = 0;
|
|
$count = str_pad($count, 3, "0", STR_PAD_LEFT);
|
|
$newNumber = $service_code . $count;
|
|
$sql = "INSERT INTO q_queue (
|
|
Q_QueueNumber,
|
|
Q_QueueStatusID,
|
|
Q_QueueQ_QueueLogID,
|
|
Q_QueueQ_CounterID,
|
|
Q_QueueQ_ServiceID,
|
|
Q_QueueCreated,
|
|
Q_QueueLastUpdated)
|
|
VALUES(
|
|
?, 1, ?, 0,?,NOW(), NOW())
|
|
";
|
|
$qry = $this->db->query($sql, array($newNumber, $inserted_id_log, $service_id));
|
|
$last_qry = $this->db->last_query();
|
|
$inserted_id = $this->db->insert_id();
|
|
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$sql_val = "SELECT Q_QueueNumber AS number
|
|
FROM q_queue
|
|
WHERE Q_QueueID = ?";
|
|
$qry_val = $this->db->query($sql_val, array($inserted_id));
|
|
$last_qry = $this->db->last_query();
|
|
$value = $qry_val->row_array();
|
|
|
|
if ($this->db->trans_status() === FALSE) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error);
|
|
} else {
|
|
|
|
$this->db->trans_commit();
|
|
$result = array(
|
|
"inserted_id" => $inserted_id,
|
|
"number" => $value['number'],
|
|
);
|
|
$this->sys_ok($result);
|
|
}
|
|
// END PERCOBAAN
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|