Files
2026-04-15 15:23:57 +07:00

309 lines
10 KiB
PHP

<?php
class Settingv3 extends MY_Controller
{
var $db;
var $load;
var $db_oneklinik;
function __construct()
{
parent::__construct();
$this->db_oneklinik = $this->load->database("onedev", true);
}
function index()
{
// $cek = $this->db->query("select database() as current_db")->result();
// print_r($cek);
echo "Default Setting Klinik";
}
function searchmou()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = "";
$number_limit = 10;
if (isset($prm['search'])) {
$search = trim($prm["search"]);
if ($search != "") {
$search = '%' . $prm['search'] . '%';
} else {
$search = '%%';
}
}
$companyid = "";
if (isset($prm["companyid"])) {
$companyid = trim($prm["companyid"]);
}
$sql = "SELECT M_MouID,
M_MouName
FROM m_mou
JOIN m_company ON M_CompanyID = M_MouM_CompanyID
AND M_CompanyID = ?
ANd M_CompanyIsActive = 'Y'
WHERE M_MouIsActive = 'Y'
AND M_MouIsApproved = 'Y'
AND M_MouStartDate <= date(now()) AND M_MouEndDate >= date(now())
AND M_MouIsReleased = 'Y'
AND (M_MouName LIKE ?)
LIMIT ?";
$qry = $this->db->query($sql, [$companyid, $search, $number_limit]);
// echo $this->db->last_query();
// exit;
if ($qry) {
$rows = $qry->result_array();
} else {
$this->db->trans_rollback();
$this->sys_error_db("mou select error", $this->db);
exit;
}
$result = array(
"total_display" => sizeof($rows),
"records" => $rows
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function savesetting()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$mouid = "";
if (isset($prm["mouid"])) {
$mouid = trim($prm["mouid"]);
}
$price = "";
if (isset($prm["price"])) {
$price = trim($prm["price"]);
}
$stationID = "0";
if (isset($prm["stationid"])) {
$stationID = trim($prm["stationid"]);
}
$locationID = "0";
if (isset($prm["locationid"])) {
$locationID = trim($prm["locationid"]);
}
$sql = "SELECT COUNT(*) as xcount FROM one_klinik.`setting` WHERE SettingIsActive = 'Y'";
$xcount = $this->db_oneklinik->query($sql)->row()->xcount;
// echo $xcount;
if ($xcount == 0) {
$sql = "INSERT INTO one_klinik.`setting`(
settingM_MouID,
settingPriceDefault,
settingIsActive,
settingUserID,
settingCreated,
settingLastUpdated,
settingM_LocationID,
settingT_SampleStationID) VALUES(?,?,'Y',?,NOW(),NOW(),?,?)";
$qry = $this->db_oneklinik->query($sql, array(
$mouid,
$price,
$userid,
$locationID,
$stationID
));
$last_qry = $this->db_oneklinik->last_query();
// echo $last_qry;
if (!$qry) {
$this->db_oneklinik->trans_rollback();
$error = array(
"message" => $this->db_oneklinik->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db_oneklinik);
exit;
}
} else {
$sql = "UPDATE one_klinik.`setting` SET
settingM_MouID = ?,
settingPriceDefault = ?,
settingUserID = ?,
settingLastUpdated = NOW(),
settingT_SampleStationID = ?,
settingM_LocationID = ?
WHERE
settingIsActive = 'Y'";
$qry = $this->db_oneklinik->query($sql, array(
$mouid,
$price,
$userid,
$stationID,
$locationID
));
$last_qry = $this->db_oneklinik->last_query();
if (!$qry) {
$this->db_oneklinik->trans_rollback();
$error = array(
"message" => $this->db_oneklinik->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db_oneklinik);
exit;
}
}
$this->db_oneklinik->trans_commit();
$result = array(
"total" => 1,
"records" => array("xid" => 0)
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function searchcompany()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = "";
$number_limit = 10;
if (isset($prm['search'])) {
$search = trim($prm["search"]);
if ($search != "") {
$search = '%' . $prm['search'] . '%';
} else {
$search = '%%';
}
}
$sql = "SELECT M_CompanyID,
M_CompanyName
FROM m_company
WHERE M_CompanyIsActive = 'Y'
AND M_CompanyName LIKE ?
LIMIT ?";
$qry = $this->db->query($sql, [$search, $number_limit]);
if ($qry) {
$rows = $qry->result_array();
} else {
$this->db->trans_rollback();
$this->sys_error_db("company select error", $this->db);
exit;
}
$result = array(
"total_display" => sizeof($rows),
"records" => $rows
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function get_data()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT setting.*,
M_CompanyID,
M_CompanyName,
M_MouName,
M_LocationName
FROM one_klinik.`setting`
JOIN m_mou ON M_MouID = settingM_MouID
JOIN m_company ON M_MouM_CompanyID = M_CompanyID
LEFT JOIN m_location ON settingM_LocationID = M_LocationID
AND settingT_SampleStationID = M_LocationT_SampleStationID
AND M_LocationIsActive = 'Y'
WHERE settingIsActive = 'Y'";
$qry = $this->db_oneklinik->query($sql);
//echo $this->db_oneklinik->last_query();
if ($qry) {
$rows = $qry->row_array();
} else {
$this->db_oneklinik->trans_rollback();
$this->sys_error_db("setting select error", $this->db);
exit;
}
$result = array(
"records" => $rows
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getLocationList()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT
M_LocationID,
M_LocationT_SampleStationID,
M_LocationName
FROM m_location
JOIN t_samplestation
ON M_LocationT_SampleStationID = T_SampleStationID
AND T_SampleStationIsActive = 'Y'
AND T_SampleStationIsNonLab = 'OTHERS'
WHERE M_LocationIsActive = 'Y'";
$qry = $this->db_oneklinik->query($sql);
//echo $this->db_oneklinik->last_query();
if ($qry) {
$rows = $qry->result_array();
} else {
$this->db_oneklinik->trans_rollback();
$this->sys_error_db("setting select error", $this->db);
exit;
}
$result = array(
"records" => $rows
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}