Initial import
This commit is contained in:
304
application/controllers/homeservice/masterdata/Schedule.php
Normal file
304
application/controllers/homeservice/masterdata/Schedule.php
Normal file
@@ -0,0 +1,304 @@
|
||||
<?php
|
||||
class Schedule 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(HS_ScheduleID,0) as HS_ScheduleID,
|
||||
HS_ScheduleM_RegDayID,
|
||||
IFNULL(HS_ScheduleLimit,'') as HS_ScheduleLimit,
|
||||
'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 one_hs.hs_schedule ON HS_ScheduleM_RegDayID = M_RegDayID AND HS_ScheduleIsActive = 'Y'
|
||||
LEFT JOIN one_hs.hs_scheduledetail ON HS_ScheduleDetailHS_ScheduleID = HS_ScheduleID AND HS_ScheduleDetailIsActive = 'Y'
|
||||
LEFT JOIN m_reg_time ON M_RegTimeID = HS_ScheduleDetailM_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(HS_ScheduleDetailID,M_RegTimeID), 'timename', M_RegTimeName,'status', IF(IFNULL(HS_ScheduleDetailID,0) = 0 AND M_RegTimeIsDefault = 'N', 'N','Y')) separator ',' ), ']' )
|
||||
as n FROM
|
||||
(SELECT HS_ScheduleDetailID,M_RegTimeID,M_RegTimeName,M_RegTimeIsDefault
|
||||
FROM m_reg_time
|
||||
JOIN one_hs.hs_schedule ON HS_ScheduleM_RegDayID = $d
|
||||
JOIN one_hs.hs_scheduledetail ON HS_ScheduleDetailM_RegTimeID = M_RegTimeID AND HS_ScheduleDetailHS_ScheduleID = HS_ScheduleID AND HS_ScheduleDetailIsActive = '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']);
|
||||
$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){
|
||||
$query =" SELECT one_hs.hs_scheduledetail.*, m_reg_time.*,IF(HS_ScheduleDetailID IS NULL,'N','Y') as isregtime, IFNULL(HS_ScheduleDetailID,0) as xid
|
||||
FROM m_reg_time
|
||||
LEFT JOIN one_hs.hs_schedule ON HS_ScheduleM_RegDayID = $dayid AND HS_ScheduleIsActive = 'Y'
|
||||
LEFT JOIN one_hs.hs_scheduledetail ON HS_ScheduleDetailM_RegTimeID = M_RegTimeID AND HS_ScheduleDetailHS_ScheduleID = HS_ScheduleID AND HS_ScheduleDetailIsActive = '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 t_subcategory
|
||||
WHERE
|
||||
T_SubCategoryIsActive = 'Y' AND T_SubCategoryIsSchedule = '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['HS_ScheduleT_SubCategoryID'];
|
||||
$dayid = $prm['HS_ScheduleM_RegDayID'];
|
||||
$kuota = $prm['HS_ScheduleLimit'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
if($prm['xid'] == 0 || $prm['xid'] == '0'){
|
||||
$query = "INSERT INTO one_hs.hs_schedule(
|
||||
HS_ScheduleM_RegDayID,
|
||||
HS_ScheduleT_SubCategoryID,
|
||||
HS_ScheduleLimit,
|
||||
HS_ScheduleUserID,
|
||||
HS_ScheduleCreated,
|
||||
HS_ScheduleLastUpdated
|
||||
)
|
||||
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 one_hs.hs_scheduledetail(
|
||||
HS_ScheduleDetailHS_ScheduleID,
|
||||
HS_ScheduleDetailM_RegTimeID,
|
||||
HS_ScheduleDetailUserID,
|
||||
HS_ScheduleDetailCreated,
|
||||
HS_ScheduleDetailLastUpdated
|
||||
)
|
||||
VALUES(?,?,?,now(),now())";
|
||||
$insert_detail = $this->db_onedev->query($query,array($last_id,$xtime,$userid));
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$queryupdate ="UPDATE one_hs.hs_schedule SET
|
||||
HS_ScheduleLimit = '{$kuota}',
|
||||
HS_ScheduleUserID = '{$userid}',
|
||||
HS_ScheduleLastUpdated = now()
|
||||
WHERE
|
||||
HS_ScheduleID = ?";
|
||||
$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 one_hs.hs_scheduledetail(
|
||||
HS_ScheduleDetailHS_ScheduleID,
|
||||
HS_ScheduleDetailM_RegTimeID,
|
||||
HS_ScheduleDetailUserID,
|
||||
HS_ScheduleDetailCreated,
|
||||
HS_ScheduleDetailLastUpdated
|
||||
)
|
||||
VALUES(?,?,?,now(),now())";
|
||||
$insert_detail = $this->db_onedev->query($query,array($prm['xid'],$xtime,$userid));
|
||||
}else if($v['isregtime'] === 'N'){
|
||||
$queryupdate ="UPDATE one_hs.hs_scheduledetail SET
|
||||
HS_ScheduleDetailIsActive = 'N',
|
||||
HS_ScheduleDetailUserID = '{$userid}',
|
||||
HS_ScheduleDetailLastUpdated = now()
|
||||
WHERE
|
||||
HS_ScheduleDetailID = ?";
|
||||
$update_detail = $this->db_onedev->query($queryupdate,array($v['HS_ScheduleDetailID']));
|
||||
}
|
||||
}
|
||||
}
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user