307 lines
10 KiB
PHP
307 lines
10 KiB
PHP
<?php
|
|
class Quota extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "Schedule API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
}
|
|
|
|
function getschedule(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$idsubcategory = $prm['idsubcategory'];
|
|
$query =" SELECT
|
|
M_RegDayID,
|
|
M_RegDayName,
|
|
IFNULL(SubserviceQuotaID,0) as SubserviceQuotaID,
|
|
SubserviceQuotaM_RegDayID,
|
|
IFNULL(SubserviceQuotaQty,'') as SubserviceQuotaQty,
|
|
subServiceID,
|
|
subServiceName,
|
|
'xxx' as regtimes,
|
|
IFNULL(GROUP_CONCAT(DISTINCT M_RegTimeName ORDER BY M_RegTimeID ASC SEPARATOR ', '),'Belum Ada Settingan Waktu') as M_RegTimeName,
|
|
'' as action
|
|
FROM m_reg_day
|
|
JOIN subservice_kuota ON SubserviceQuotaM_RegDayID = M_RegDayID AND SubserviceQuotasubServiceID = $idsubcategory AND SubserviceQuotaIsActive = 'Y'
|
|
LEFT JOIN subservice ON subServiceID = $idsubcategory
|
|
LEFT JOIN subservice_kuota_detail ON SubserviceKuotaDetailSubserviceQuotaID = SubserviceQuotaID AND SubserviceKuotaDetailIsActive = 'Y'
|
|
LEFT JOIN m_reg_time ON M_RegTimeID = SubserviceKuotaDetailM_RegTimeID AND M_RegTimeIsActive = 'Y'
|
|
WHERE
|
|
M_RegDayIsActive = 'Y'
|
|
GROUP BY M_RegDayID
|
|
ORDER BY M_RegDayID ASC
|
|
";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
if($rows){
|
|
|
|
foreach($rows as $k => $v){
|
|
$d = $v['M_RegDayID'];
|
|
$x = $this->db_onedev->query("select concat( '[', group_concat( json_object('id',IFNULL(SubserviceKuotaDetailID,M_RegTimeID), 'timename', M_RegTimeName,'status', IF(IFNULL(SubserviceKuotaDetailID,0) = 0 AND M_RegTimeIsDefault = 'N', 'N','Y')) separator ',' ), ']' )
|
|
as n FROM
|
|
(SELECT SubserviceKuotaDetailID,M_RegTimeID,M_RegTimeName,M_RegTimeIsDefault
|
|
FROM m_reg_time
|
|
JOIN subservice_kuota ON SubserviceQuotaM_RegDayID = $d AND SubserviceQuotasubServiceID = $idsubcategory
|
|
JOIN subservice_kuota_detail ON SubserviceKuotaDetailM_RegTimeID = M_RegTimeID AND SubserviceKuotaDetailSubserviceQuotaID = SubserviceQuotaID AND SubserviceKuotaDetailIsActive = 'Y'
|
|
WHERE M_RegTimeIsActive = 'Y'
|
|
GROUP BY M_RegTimeID) a")->row();
|
|
$rows[$k]['regtimex'] = json_decode($x->n);
|
|
$rows[$k]['regtimes'] = $this->add_regtime($v['M_RegDayID'],$idsubcategory);
|
|
$rows[$k]['action'] = '<v-icon color="error" @click="deleteAddress(props.item)">delete</v-icon>';
|
|
$rows[$k]['action'] .= '<v-icon color="primary" @click="deleteAddress(props.item)">edit</v-icon>';
|
|
|
|
}
|
|
}
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function add_regtime($dayid,$idsubcategory){
|
|
$query =" SELECT subservice_kuota_detail.*, m_reg_time.*,IF(SubserviceKuotaDetailID IS NULL,'N','Y') as isregtime, IFNULL(SubserviceKuotaDetailID,0) as xid
|
|
FROM m_reg_time
|
|
LEFT JOIN subservice_kuota ON SubserviceQuotaM_RegDayID = $dayid AND SubserviceQuotasubServiceID = $idsubcategory AND SubserviceQuotaIsActive = 'Y'
|
|
LEFT JOIN subservice_kuota_detail ON SubserviceKuotaDetailM_RegTimeID = M_RegTimeID AND SubserviceKuotaDetailSubserviceQuotaID = SubserviceQuotaID AND SubserviceKuotaDetailIsActive = 'Y'
|
|
WHERE M_RegTimeIsActive = 'Y'
|
|
GROUP BY M_RegTimeID";
|
|
//echo $query;
|
|
$rows = $this->db_onedev->query($query)->result_array();
|
|
if(!$rows)
|
|
$rows = array();
|
|
return $rows;
|
|
}
|
|
function getday(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT *
|
|
FROM m_reg_day
|
|
WHERE
|
|
M_RegDayIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['days'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function getsubcategory(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query =" SELECT *
|
|
FROM subservice
|
|
WHERE
|
|
subServiceIsActive = 'Y'
|
|
";
|
|
//echo $query;
|
|
$rows['subcategorys'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function savenewmethode(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
foreach($prm['orderdays'] as $k=>$v){
|
|
$query = "INSERT INTO m_methode_priority (
|
|
M_MethodePriorityM_MethodePriorityID,
|
|
M_MethodePriorityT_TestID,
|
|
M_MethodePriorityT_TestCode,
|
|
M_MethodePriorityT_TestName,
|
|
M_MethodePriorityT_TestPrice,
|
|
M_MethodePriorityT_TestDisc,
|
|
M_MethodePriorityT_TestDiscRp,
|
|
M_MethodePriorityT_TestTotal,
|
|
M_MethodePriorityUserID,
|
|
M_MethodePriorityCreated,
|
|
M_MethodePriorityLastUpdated
|
|
)
|
|
VALUE(
|
|
?,?,?,?,?,?,?,?,?, now(),now()
|
|
)";
|
|
$insert_new_test = $this->db_onedev->query($query,array(
|
|
$orderpatient_id,
|
|
$v['T_TestID'],
|
|
$v['T_TestCode'],
|
|
$v['T_TestName'],
|
|
$v['T_PriceAmount'],
|
|
$v['T_PriceDisc'],
|
|
$v['T_PriceDiscRp'],
|
|
$v['total'],
|
|
$userid
|
|
));
|
|
}
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK')
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
function saveeditmethode(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$subcategoryid = $prm['SubserviceQuotasubServiceID'];
|
|
$dayid = $prm['SubserviceQuotaM_RegDayID'];
|
|
$kuota = $prm['SubserviceQuotaQty'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
if($prm['xid'] == 0 || $prm['xid'] == '0'){
|
|
$query = "INSERT INTO subservice_kuota(
|
|
SubserviceQuotaM_RegDayID,
|
|
SubserviceQuotasubServiceID,
|
|
SubserviceQuotaQty,
|
|
SubserviceQuotaUserID,
|
|
SubserviceQuotaCreated,
|
|
SubserviceQuotaLastUpdated
|
|
)
|
|
VALUES(?,?,?,?,now(),now())";
|
|
$insert_header = $this->db_onedev->query($query,array($dayid,$subcategoryid,$kuota,$userid));
|
|
$last_id = $this->db_onedev->insert_id();
|
|
foreach($prm['orderregtimes'] as $k=>$v){
|
|
if($v['isregtime'] === 'Y'){
|
|
$xtime = $v['M_RegTimeID'];
|
|
$query = "INSERT INTO subservice_kuota_detail(
|
|
SubserviceKuotaDetailSubserviceQuotaID,
|
|
SubserviceKuotaDetailM_RegTimeID,
|
|
SubserviceKuotaDetailUserID,
|
|
SubserviceKuotaDetailCreated,
|
|
SubserviceKuotaDetailLastUpdated
|
|
)
|
|
VALUES(?,?,?,now(),now())";
|
|
$insert_detail = $this->db_onedev->query($query,array($last_id,$xtime,$userid));
|
|
}
|
|
}
|
|
}else{
|
|
$queryupdate ="UPDATE subservice_kuota SET
|
|
SubserviceQuotaQty = '{$kuota}',
|
|
SubserviceQuotaUserID = '{$userid}',
|
|
SubserviceQuotaLastUpdated = now()
|
|
WHERE
|
|
SubserviceQuotaID = ?";
|
|
$update_header = $this->db_onedev->query($queryupdate,array($prm['xid']));
|
|
foreach($prm['orderregtimes'] as $k=>$v){
|
|
if($v['isregtime'] === 'Y' && $v['xid'] == 0){
|
|
$xtime = $v['M_RegTimeID'];
|
|
$query = "INSERT INTO subservice_kuota_detail(
|
|
SubserviceKuotaDetailSubserviceQuotaID,
|
|
SubserviceKuotaDetailM_RegTimeID,
|
|
SubserviceKuotaDetailUserID,
|
|
SubserviceKuotaDetailCreated,
|
|
SubserviceKuotaDetailLastUpdated
|
|
)
|
|
VALUES(?,?,?,now(),now())";
|
|
$insert_detail = $this->db_onedev->query($query,array($prm['xid'],$xtime,$userid));
|
|
}else if($v['isregtime'] === 'N'){
|
|
$queryupdate ="UPDATE subservice_kuota_detail SET
|
|
SubserviceKuotaDetailIsActive = 'N',
|
|
SubserviceKuotaDetailUserID = '{$userid}',
|
|
SubserviceKuotaDetailLastUpdated = now()
|
|
WHERE
|
|
SubserviceKuotaDetailID = ?";
|
|
$update_detail = $this->db_onedev->query($queryupdate,array($v['SubserviceKuotaDetailID']));
|
|
}
|
|
}
|
|
}
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array('status'=>'OK')
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
|
|
function searchtest(){
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count = 0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '')
|
|
{
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
$mou_id = $prm['mouid'];
|
|
// QUERY TOTAL
|
|
$sql = "SELECT count(*) as total
|
|
FROM t_test
|
|
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
|
|
WHERE
|
|
T_TestName like ? AND
|
|
T_TestIsActive = 'Y'
|
|
ORDER BY T_TestName ASC";
|
|
$query = $this->db_onedev->query($sql,$q['search']);
|
|
//echo $query;
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("test count",$this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT 'Y' as editable, 0 as xid, T_TestID, T_TestCode, T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
|
|
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
|
|
FROM one_lis_dev.t_test
|
|
JOIN one_lis_dev.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
|
|
JOIN one_lis_dev.m_mou ON M_MouID = '{$mou_id}'
|
|
JOIN one_lis_dev.m_company ON M_MouM_CompanyID = M_CompanyID
|
|
WHERE
|
|
T_TestName like ? AND
|
|
T_TestIsActive = 'Y'
|
|
ORDER BY T_TestName ASC
|
|
";
|
|
$query = $this->db_onedev->query($sql, array($q['search']));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
}
|
|
else {
|
|
$this->sys_error_db("test rows",$this->db_onedev);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
} |