Files
BE_IBL/application/controllers/antrian/Service.php
2026-04-15 15:23:57 +07:00

350 lines
12 KiB
PHP

<?php
class Service extends MY_Controller
{
var $db_antrione;
var $load;
function __construct()
{
parent::__construct();
$this->db_antrione = $this->load->database("antrione", true);
}
function index()
{
echo ('API SERVICE');
}
function search()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
// print_r($prm);
// exit;
$search = "%%";
if (isset($prm['search'])) {
$search = trim($prm["search"]);
$search = '%' . $prm['search'] . '%';
}
$order_by = "serviceCode";
if (isset($prm['order_by'])) {
$order_by = trim($prm["order_by"]);
}
$order = "asc";
if (isset($prm['order'])) {
$order = trim($prm["order"]);
}
$sort = "order by " . $order_by . " " . $order;
$page = $prm["page"];
$ROW_PER_PAGE = 10;
$start_offset = 0;
if (isset($prm["page"])) {
if (
is_numeric($prm["page"]) && $prm["page"] > 0
) {
$start_offset = ($page - 1) * $ROW_PER_PAGE;
}
}
$total_count = 0;
$total_page = 0;
$sqlCount = "SELECT COUNT(*) AS total FROM service
WHERE serviceIsActive = 'Y'
AND ( serviceCode LIKE ? OR serviceName LIKE ?)
ORDER BY serviceCode";
$qryCount = $this->db_antrione->query($sqlCount, [$search, $search]);
$last_qry = $this->db_antrione->last_query();
if (!$qryCount) {
$error = array(
"message" => $this->db_antrione->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error);
exit;
}
$sql = "SELECT * FROM service
WHERE serviceIsActive = 'Y'
AND ( serviceCode LIKE ? OR serviceName LIKE ?)
$sort
LIMIT 10 OFFSET ?";
$qry = $this->db_antrione->query($sql, [$search, $search, $start_offset]);
$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;
}
$total = $qryCount->row_array();
$total_count = $total['total'];
$total_page = ceil($total_count / $ROW_PER_PAGE);
$data = $qry->result_array();
$result = array(
"total_filter" => $total_count,
"total" => $total_page,
"records" => $data,
"qry" => $last_qry
);
$this->sys_ok($result);
exit;
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function add()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$code = "";
if (isset($prm['code'])) {
$code = trim($prm["code"]);
}
$name = "";
if (isset($prm['name'])) {
$name = trim($prm["name"]);
}
$priority = "";
if (isset($prm['priority'])) {
$priority = trim($prm["priority"]);
}
$foOrder = "";
if (isset($prm['foOrder'])) {
$foOrder = trim($prm["foOrder"]);
}
$isConsultDoctor = "";
if (isset($prm['isConsultDoctor'])) {
$isConsultDoctor = trim($prm["isConsultDoctor"]);
}
$nameDoctor = "";
if (isset($prm['nameDoctor'])) {
$nameDoctor = trim($prm["nameDoctor"]);
}
if ($isConsultDoctor == 'Y') {
if ($code == "" || $name == "" || $priority == "" || $foOrder == "" || $nameDoctor == "") {
$this->sys_error("code, name, priority, fo order, nama dokter is mandatory");
exit;
}
} else {
if ($code == "" || $name == "" || $priority == "" || $foOrder == "") {
$this->sys_error("code, name, priority, fo order is mandatory");
exit;
}
}
$this->db_antrione->trans_begin();
$sql = "INSERT INTO service
(serviceCode,
serviceName,
servicePriority,
serviceIsFoOrder,
serviceIsConsultDoctor,
serviceDoctorName
)
VALUES(?, ?, ?, ?, ?, ?)";
$qry = $this->db_antrione->query($sql, [$code, $name, $priority, $foOrder, $isConsultDoctor, $nameDoctor]);
$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;
}
$insertedId = $this->db_antrione->insert_id();
$sqlNumbering = "INSERT INTO numbering
(numberingServiceID,
numberingPrefix,
numberingDigit,
numberingReset)
VALUES(? ,? , 4, 'D')";
$qryNumbering = $this->db_antrione->query($sqlNumbering, [$insertedId, $insertedId]);
if (!$qryNumbering) {
$error = array(
"message" => $this->db_antrione->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error);
exit;
}
$this->db_antrione->trans_complete();
$result = array(
"qry" => $last_qry
);
$this->sys_ok($result);
exit;
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function update()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$code = "";
if (isset($prm['code'])) {
$code = trim($prm["code"]);
}
$id = "";
if (isset($prm['id'])) {
$id = trim($prm["id"]);
}
$name = "";
if (isset($prm['name'])) {
$name = trim($prm["name"]);
}
$priority = "";
if (isset($prm['priority'])) {
$priority = trim($prm["priority"]);
}
$foOrder = "";
if (isset($prm['foOrder'])) {
$foOrder = trim($prm["foOrder"]);
}
$isConsultDoctor = "";
if (isset($prm['isConsultDoctor'])) {
$isConsultDoctor = trim($prm["isConsultDoctor"]);
}
$nameDoctor = "";
if (isset($prm['nameDoctor'])) {
$nameDoctor = trim($prm["nameDoctor"]);
}
if ($isConsultDoctor == 'Y') {
if ($code == "" || $name == "" || $priority == "" || $foOrder == "" || $nameDoctor == "") {
$this->sys_error("code, name, priority, fo order, nama dokter is mandatory");
exit;
}
} else {
if ($code == "" || $name == "" || $priority == "" || $foOrder == "") {
$this->sys_error("code, name, priority, fo order is mandatory");
exit;
}
}
$sql = "UPDATE service SET serviceCode = ?,
serviceName = ?,
servicePriority = ?,
serviceIsFoOrder = ?,
serviceIsConsultDoctor = ?,
serviceDoctorName = ?
WHERE serviceID = ?";
$qry = $this->db_antrione->query($sql, [$code, $name, $priority, $foOrder, $isConsultDoctor, $nameDoctor, $id]);
$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;
}
$result = array(
"qry" => $last_qry
);
$this->sys_ok($result);
exit;
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function delete()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = "";
if (isset($prm['id'])) {
$id = trim($prm["id"]);
}
$this->db_antrione->trans_begin();
$sql = "UPDATE service SET
serviceIsActive = 'N'
WHERE serviceID = ?";
$qry = $this->db_antrione->query($sql, [intval($id)]);
$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;
}
$sqlNumbering = "UPDATE numbering SET
numberingIsActive = 'N'
WHERE numberingServiceID = ?";
$qryNumbering = $this->db_antrione->query($sqlNumbering, [intval($id)]);
$last_qry = $this->db_antrione->last_query();
if (!$qryNumbering) {
$error = array(
"message" => $this->db_antrione->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error);
exit;
}
$this->db_antrione->trans_complete();
$result = array(
"qry" => $last_qry
);
$this->sys_ok($result);
exit;
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function listService()
{
try {
$sql = "SELECT * FROM service WHERE serviceIsActive = '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);
}
}
}