253 lines
8.0 KiB
PHP
253 lines
8.0 KiB
PHP
<?php
|
|
class Setting extends MY_Controller
|
|
{
|
|
var $db;
|
|
var $load;
|
|
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"]);
|
|
}
|
|
|
|
$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) VALUES(?,?,'Y',?,NOW(),NOW())";
|
|
$qry = $this->db_oneklinik->query($sql, array(
|
|
$mouid,
|
|
$price,
|
|
$userid
|
|
));
|
|
$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()
|
|
WHERE
|
|
settingIsActive = 'Y'";
|
|
$qry = $this->db_oneklinik->query($sql, array(
|
|
$mouid,
|
|
$price,
|
|
$userid
|
|
));
|
|
$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
|
|
FROM one_klinik.`setting`
|
|
JOIN m_mou ON M_MouID = settingM_MouID
|
|
JOIN m_company ON M_MouM_CompanyID = M_CompanyID
|
|
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);
|
|
}
|
|
}
|
|
}
|