Files
BE_CPONE/application/controllers/mockup/couriernew/Patient.php
2026-04-27 10:31:17 +07:00

887 lines
29 KiB
PHP

<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function add_verifications_label($orderid){
$query = " SELECT Result_VerificationsID as id,
IFNULL(Result_VerificationsValueID,0) as xid,
IFNULL(Result_VerificationsValueCheck,'N') as chex,
IF(ISNULL(Result_VerificationsValueID),'',Result_VerificationsValueNote) as note,
Result_VerificationsLabel as label
FROM result_verifications
LEFT JOIN result_verifications_value ON Result_VerificationsValueResult_VerificationsID = Result_VerificationsID AND
Result_VerificationsValueSo_ResultEntryID = $orderid
WHERE
Result_VerificationIsActive = 'Y'
GROUP BY Result_VerificationsID
";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
return $rows;
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$spk = $prm['spk'];
$sql = "SELECT DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
M_CompanyName,
T_OrderHeaderLabNumberExt as no_reg,
courier_staff.M_StaffName as staff_name,
IFNULL(spv_staff.M_StaffName,'Belum dikonfirmasi') as spv_name
FROM result_courierspk_detail
JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
JOIN t_orderpromise ON Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID
JOIN t_orderdelivery ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff courier_staff ON M_CourierM_StaffID = courier_staff.M_StaffID
LEFT JOIN m_staff spv_staff ON M_CourierM_StaffID = spv_staff.M_StaffID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
WHERE
Result_CourierSPKDetailResult_CourierSPKID = {$spk} AND
Result_CourierSPKDetailIsActive = 'Y'
ORDER BY T_OrderPromiseDateTime ASC";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['chex'] = false;
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
public function getspk()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT Result_CourierSPKID as id,
CONCAT(Result_CourierSPKNumbering,' ',M_StaffName) as name
FROM result_courierspk
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
WHERE
Result_CourierSPKDate = '{$prm['startdate']}' AND
Result_CourierSPKIsActive = 'Y'";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
$result = array("total" => count($rows), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
public function getcourier()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$nolab = $prm["nolab"];
$nama = $prm["name"];
$status = $prm["status"];
$datepromise = $prm["startdate"];
$filter = " AND Result_SendCourierStatus = '{$status}'";
$having = "HAVING not_ready_count = 0";
if($status == 'X'){
$filter = " AND ISNULL(Result_SendCourierID)";
$having = "HAVING not_ready_count > 0";
}
$sql_where = "WHERE T_OrderDetailIsActive = 'Y' ";
$sql = " SELECT 0 as id, 'Semua' as staff_name, 0 as not_ready_count
UNION
SELECT M_CourierID as id,
M_StaffName as staff_name,
fn_fo_check_status_not_ready_courier(T_OrderHeaderID,T_OrderPromiseID) as not_ready_count
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND
T_OrderDeliveryM_DeliveryTypeID = 2 AND
T_OrderDeliveryIsActive = 'Y'
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseDateTime < '{$datepromise} 23:59:59'
JOIN result_sendcourier ON Result_SendCourierT_OrderHeaderID = T_OrderHeaderID AND
JSON_CONTAINS(Result_SendCourierIds,T_OrderDetailID)
JOIN result_courierspk_detail ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID AND
Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID AND Result_CourierSPKDetailIsActive = 'Y' AND
Result_CourierSPKDetailStatus = 'O'
JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
$sql_where $filter
GROUP BY M_CourierID
$having";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => count($rows), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
public function save()
{
try {
$xprm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$xuserid = $this->sys_user['M_UserID'];
//# ambil parameter input
//print_r($xprm);
$prm = $xprm['patient'];
$xstatus = $xprm['act'];
$fostatusid = 3;
$fologcode = 'FO.VERIFICATION.CONFIRM';
$id = $prm['T_OrderHeaderID'];
echo $xstatus;
if($xstatus == 'N'){
$fostatusid = 4;
$fologcode = 'FO.VERIFICATION.REJECT';
}else{
$this->save_barcode_new($id);
}
//print_r($prm);
$xverificationnote = $prm['verification_note'];
//echo $xverificationnote;
$sql = "update t_orderheader
set
T_OrderHeaderVerificationNote = '{$xverificationnote}'
where
T_OrderHeaderID = $id";
//echo $sql;
$query = $this->db_onedev->query($sql);
/*$xverification_patient = $this->saveverifications($id,$prm['verification_patient'],'PATIENT',$xuserid);
$xverification_doctor = $this->saveverifications($id,$prm['verification_doctor'],'DOCTOR',$xuserid);
$xverification_companymou = $this->saveverifications($id,$prm['verification_companymou'],'COMPANY',$xuserid);
$xverification_payment = $this->saveverifications($id,$prm['verification_payment'],'PAYMENT',$xuserid);
$xverification_info = $this->saveverifications($id,$prm['verification_info'],'INFO',$xuserid);
$xverification_delivery = $this->saveverification_delivery($id,$prm['verification_delivery'],$xuserid);
$xverification_px = $this->saveverification_px($id,$prm['verification_px'],$xuserid);*/
$sql = "insert into fo_status(
Fo_StatusDate,
Fo_StatusT_OrderHeaderID,
Fo_StatusM_StatusID,
Fo_StatusM_UserID,
Fo_StatusCreated,
Fo_StatusUpdated)
values( now(), ?, ?, ?, now(),now())";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$fostatusid,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("fo_status insert");
exit;
}
$data_log = array();
$data_log['orderid'] = $id;
/*$data_log['verification_patient'] = $prm['verification_patient'];
$data_log['verification_doctor'] = $prm['verification_doctor'];
$data_log['verification_companymou'] = $prm['verification_companymou'];
$data_log['verification_payment'] = $prm['verification_payment'];
$data_log['verification_info'] = $prm['verification_info'];
$data_log['verification_px'] = $prm['verification_px'];
$data_log['verification_delivery'] = $prm['verification_delivery'];*/
$json_dt_log = json_encode($data_log);
$sql = "insert into one_log.log_fo(
Log_FoDate,
Log_FoCode,
Log_FoJson,
Log_FoUserID)
values( now(), ?, ?, ?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$fologcode,
$json_dt_log,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("one_log.fo_log insert");
exit;
}
if($xstatus == 'Y'){
$msg = 'Verifikasi berhasil dilakukan';
}
else{
$msg = 'Tolak Verifikasi berhasil dilakukan';
$sql = "INSERT INTO t_ordermessage (
T_OrderMessageT_OrderHeaderID,
T_OrderMessageType,
T_OrderMessageMessage,
T_OrderMessageFromUserID,
T_OrderMessageCreated,
T_OrderMessageLastUpdated
)
VALUES(
{$id},
'FO.VERIFICATION.REJECT',
'{$xverificationnote}',
{$xuserid},
NOW(),
NOW()
)";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("one_log.t_ordermessage insert");
exit;
}
}
$rows = array('message'=>$msg);
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function save_barcode_new($orderid){
$xuserid = $this->sys_user['M_UserID'];
$query =" SELECT T_SampleTypeID as id,
T_SampleTypeName as name,
'' as children
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
WHERE
T_OrderHeaderID = {$orderid}
GROUP BY T_SampleTypeID
";
//echo $query ;
$barcodes = $this->db_onedev->query($query)->result();
foreach($barcodes as $k => $v){
$query = "SELECT T_SampleTypeID as id, IFNULL(T_BarcodeLabID,0) as xid,
IF(ISNULL(T_BarcodeLabID),'Y',T_BarcodeLabIsActive) as chex,
T_TestName as testname,
T_SampleTypeName as samplename,
IF(ISNULL(T_BarcodeLabID),CONCAT(T_OrderHeaderLabNumber,'.',T_SampleTypeID,'.',1),T_BarcodeLabBarcode) as barcodenumber
FROM t_orderdetail
JOIN t_orderheader ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
LEFT JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
T_BarcodeLabT_SampleTypeID = T_TestT_SampleTypeID AND T_BarcodeLabIsActive = 'Y'
WHERE
T_OrderDetailT_OrderHeaderID = {$orderid} AND T_SampleTypeID = {$v->id}
GROUP BY T_BarcodeLabID ";
$v->children = $this->db_onedev->query($query)->result_array();
//$v->children = $barcode_data;
foreach($v->children as $ki => $vi){
if($vi['chex'] == 'N')
$v->children[$ki]['chex'] = false;
else
$v->children[$ki]['chex'] = true;
$sql = "insert into t_barcodelab(
T_BarcodeLabT_OrderHeaderID,
T_BarcodeLabBarcode,
T_BarcodeLabT_SampleTypeID,
T_BarcodeLabCreated,
T_BarcodeLabLastUpdated,
T_BarcodeLabUserID)
values( ?, ?, ?, now(),now(),?)";
$query = $this->db_onedev->query($sql,
array(
$orderid,
$v->children[$ki]['barcodenumber'],
$v->children[$ki]['id'],
$xuserid
)
);
// echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("t_barcodelab insert");
exit;
}
}
}
//insert log
$supplies = array();
$query =" SELECT M_SuppliesID as id,
IFNULL(T_OrderSuppliesID,0) as xid,
IF(ISNULL(T_OrderSuppliesID),'N',T_OrderSuppliesIsActive) as chex,
IFNULL(T_OrderSuppliesQty,1) as qty,
M_SuppliesName as name,
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as lastupdated,
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as tx_lastupdated
FROM m_supplies
JOIN t_ordersupplies ON T_OrderSuppliesT_OrderHeaderID = $orderid AND T_OrderSuppliesM_SuppliesID = M_SuppliesID
WHERE
M_SuppliesIsActive = 'Y'
";
//echo $query ;
$supplies = $this->db_onedev->query($query)->result_array();
foreach($supplies as $k => $v){
if($v['chex'] == 'N')
$supplies[$k]['chex'] = false;
else
$supplies[$k]['chex'] = true;
}
$dt_log = array('orderid'=>$orderid,'supplies'=>$supplies,'barcode'=>$barcodes);
$fologcode = 'FO.Verification.BarcodeSupplies';
$json_dt_log = json_encode($dt_log);
$sql = "insert into one_log.log_supplies_barcode(
Log_SuppliesBarcodeDate,
Log_SuppliesBarcodeCode,
Log_SuppliesBarcodeJson,
Log_SuppliesBarcodeUserID)
values( now(), ?, ?, ?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$fologcode,
$json_dt_log,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("one_log.log_supplies_barcode insert");
exit;
}
}
function saveverifications($id,$verifications,$type,$userid)
{
try {
//$xverificationtypeid = $this->db_onedev->query("SELECT * FROM fo_verificationtype WHERE Fo_VerificationTypeGroup = '{$type}' AND Fo_VerificationTypeIsActive = 'Y'")->row()->Fo_VericationTypeID;
//echo $xverificationtypeid;
//print_r($verifications);
foreach($verifications as $k => $v){
//print_r($v);
if(intval($v['xid']) == 0){
$sql = "insert into fo_verification(
Fo_VerificationT_OrderHeaderID,
Fo_VerificationFo_VericationTypeID,
Fo_VerificationIsOK,
Fo_VerificationReason,
Fo_VerificationCreated,
Fo_VerificationLastUpdated,
Fo_VerificationUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
$this->sys_error_db("fo_verification insert");
exit;
}
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveverification_delivery($id,$deliveries,$userid)
{
try {
foreach($deliveries as $k => $v){
if($v['id'] === 0){
$sql = "insert into fo_verification_delivery_add(
Fo_VerificationDeliveryAddT_OrderHeaderID,
Fo_VerificationDeliveryAddM_DeliveryID,
Fo_VerificationDeliveryAddM_DeliveryTypeID,
Fo_VerificationDeliveryAddDestination,
Fo_VerificationDeliveryAddAddressID,
Fo_VerificationDeliveryAddM_KelurahanID,
Fo_VerificationDeliveryAddOK,
Fo_VerificationDeliveryAddReason,
Fo_VerificationDeliveryAddCreated,
Fo_VerificationDeliveryAddLastUpdated,
Fo_VerificationDeliveryAddUserID)
values( ?, ?, ?, ?,?,?,?,?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['deliveryid'],
$v['typedeliveryid'],
$v['destination'],
$v['addressid'],
$v['vilageid'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
echo $this->db_onedev->last_query();
$this->sys_error_db("fo_verification_delivery_add insert");
exit;
}
}else{
$sql = "insert into fo_verification_delivery(
Fo_VerificationDeliveryT_OrderHeaderID,
Fo_VerificationDeliveryT_OrderDeliveryID,
Fo_VerificationDeliveryIsOK,
Fo_VerificationDeliveryReason,
Fo_VerificationDeliveryCreated,
Fo_VerificationDeliveryLastUpdated,
Fo_VerificationDeliveryUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
echo $this->db_onedev->last_query();
$this->sys_error_db("fo_verification_delivery insert");
exit;
}
//echo $this->db_onedev->last_query();
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookup_barcodes()
{
try {
$prm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT T_BarcodeLabID as id, 'barcode' as type,T_BarcodeLabID,T_BarcodeLabBarcode, T_BarcodeLabCounter, T_SampleTypeName, 'N' as chex
FROM t_barcodelab
JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID
WHERE
T_BarcodeLabT_OrderHeaderID = {$prm['ohid']} AND T_BarcodeLabIsActive = 'Y'
UNION
SELECT T_OrderHeaderID as id, 'formulir' as type, 0,T_OrderHeaderLabNumber as T_BarcodeLabBarcode, 1, 'Formulir' as T_SampleTypeName, 'N' as chex
FROM t_orderheader
WHERE
T_OrderHeaderID = {$prm['ohid']}
";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
if($rows){
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveverification_px($id,$pxs,$userid)
{
try {
foreach($pxs as $k => $v){
if(intval($v['id']) == 0){
$cxh = $v['chex'] == true ?'Y':'N';
$sql = "insert into fo_verification_test_add(
Fo_VerificationTestAddT_OrderHeaderID,
Fo_VerificationTestAddT_TestID,
Fo_VerificationTestAddBruto,
Fo_VerificationTestAddDiscount,
Fo_VerificationTestAddTotal,
Fo_VerificationTestAddIsOK,
Fo_VerificationTestAddIsCito,
Fo_VerificationTestAddCreated,
Fo_VerificationTestAddLastUpdated,
Fo_VerificationTestAddUserID)
values( $id, {$v['pxid']}, {$v['bruto']}, {$v['discount']},{$v['total']},'{$cxh}','{$v['flagcito']}',now(),now(),{$userid})";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("fo_verification_test_add insert");
exit;
}
}else{
$sql = "insert into fo_verification_test(
Fo_VerificationTestT_OrderHeaderID,
Fo_VerificationTestT_OrderDetailID,
Fo_VerificationTestIsOK,
Fo_VerificationTestReason,
Fo_VerificationTestCreated,
Fo_VerificationTestLastUpdated,
Fo_VerificationTestUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("fo_verification_test insert");
exit;
}
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function verify(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$xstatus = $prm['act'];
if($xstatus == 'Y'){
$msg = "Berhasil melakukan verifikasi";
$query =" INSERT INTO result_verifications_value (
Result_VerificationsValueSo_ResultEntryID,
Result_VerificationsValueResult_VerificationsID,
Result_VerificationsValueCheck,
Result_VerificationsValueNote,
Result_VerificationsValueUserID,
Result_VerificationsValueCreated
)
SELECT {$prm['trx_id']},
Result_VerificationsID,
'Y',
'',
{$userid},
NOW()
FROM result_verifications
WHERE
Result_VerificationIsActive = 'Y'
ON DUPLICATE KEY UPDATE
Result_VerificationsValueCheck = 'Y',
Result_VerificationsValueNote = '',
Result_VerificationsValueUserID = {$userid},
Result_VerificationsValueLastUpdated = NOW()
";
//echo $query;
$this->db_onedev->query($query);
$sql = "UPDATE so_resultentry SET So_ResultEntryStatus = 'VAL2' , So_ResultEntryValidation2 = 'Y' WHERE So_ResultEntryID = {$prm['trx_id']}";
$this->db_onedev->query($sql);
}
else{
$msg = "Tolak untuk perbaikan";
$verifications = $prm['verifications'];
foreach($verifications as $k => $v){
$chx = $v['chex'] == true ?'Y':'N';
$query =" INSERT INTO result_verifications_value (
Result_VerificationsValueSo_ResultEntryID,
Result_VerificationsValueResult_VerificationsID,
Result_VerificationsValueCheck,
Result_VerificationsValueNote,
Result_VerificationsValueUserID,
Result_VerificationsValueCreated
)
values( {$prm['trx_id']},
{$v['id']},
'{$chx}',
'{$v['note']}',
{$userid},
NOW()
)
ON DUPLICATE KEY UPDATE
Result_VerificationsValueCheck = '{$chx}',
Result_VerificationsValueNote = '{$v['note']}',
Result_VerificationsValueUserID = {$userid},
Result_VerificationsValueLastUpdated = NOW()
";
//echo $query;
$this->db_onedev->query($query);
}
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>$msg));
$this->sys_ok($result);
}
public function getstatuspergroup()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = array();
$sql =" SELECT Last_StatusPaymentBillTotal as total_bill,
Last_StatusPaymentPaid as paid,
Last_StatusPaymentUnpaid as unpaid,
Last_StatusPaymentIsLunas as status
FROM last_statuspayment
WHERE
Last_StatusPaymentT_OrderHeaderID = {$prm['T_OrderHeaderID']} ";
$rows['info_bill'] = $this->db_onedev->query($sql)->row_array();
$sql =" SELECT T_OrderDeliveryID as id,
IFNULL(Fo_VerificationDeliveryID,0) as xid,
M_DeliveryTypeCode as code,
IF(ISNULL(Fo_VerificationDeliveryID),'N',Fo_VerificationDeliveryIsOK) as chex,
M_DeliveryID as deliveryid,
IFNULL(T_OrderDeliveryNoteValue,'') as note_courier,
M_DeliveryTypeID as typedeliveryid,
T_OrderDeliveryM_KelurahanID as vilageid,
IF(ISNULL(Fo_VerificationDeliveryID),'',Fo_VerificationDeliveryReason) as note,
'reguler' as type,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN M_DeliveryName
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN CONCAT(M_DeliveryName)
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 10 ) THEN CONCAT(M_DeliveryName)
ELSE
CONCAT(M_DeliveryName)
END as label,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN ''
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressDescription
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressDescription
WHEN T_OrderDeliveryM_DeliveryID = 10 THEN M_CompanyAddress
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN M_DoctorHP
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN M_PatientHP
ELSE
T_OrderDeliveryDestination
END as destination,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressID
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressID
ELSE
0
END as addressid
FROM t_orderdelivery
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN m_delivery ON T_OrderDeliveryM_DeliveryID = M_DeliveryID
JOIN m_deliverytype ON T_OrderDeliveryM_DeliveryTypeID = M_DeliveryTypeID
LEFT JOIN m_doctoraddress ON T_OrderDeliveryAddressID = M_DoctorAddressID AND T_OrderDeliveryM_DeliveryID = 4
LEFT JOIN m_patientaddress ON T_OrderDeliveryAddressID = M_PatientAddressID AND T_OrderDeliveryM_DeliveryID = 2
LEFT JOIN fo_verification_delivery ON Fo_VerificationDeliveryT_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID AND Fo_VerificationDeliveryIsActive = 'Y'
LEFT JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 )
LEFT JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 )
LEFT JOIN m_company ON T_OrderDeliveryAddressID = M_CompanyID AND ( T_OrderDeliveryM_DeliveryID = 10 )
LEFT JOIN t_orderdeliverynote ON T_OrderDeliveryNoteT_OrderDeliveryID = T_OrderDeliveryID AND T_OrderDeliveryNoteIsActive = 'Y'
WHERE
T_OrderDeliveryT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_OrderDeliveryID = {$prm['T_OrderDeliveryID']} AND T_OrderDeliveryIsActive = 'Y'
GROUP BY T_OrderDeliveryID
";
//echo $sql ;
$rows['info_deliveries'] = $this->db_onedev->query($sql)->result_array();
$sql = "SELECT Group_ResultID as id, Group_ResultName as name
FROM t_orderdetail
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN group_resultdetail ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID AND
Group_ResultDetailIsActive = 'Y'
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND
Group_ResultFlagPerTest = 'N'
WHERE
T_OrderDetailT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND
T_OrderDetailIsActive = 'Y'
GROUP BY Group_ResultID
UNION
SELECT Group_ResultID as id, Group_ResultName as name
FROM t_orderdetail
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
JOIN group_resultdetail ON T_OrderDetailT_TestID = Group_ResultDetailT_TestID AND
Group_ResultDetailIsActive = 'Y'
JOIN group_result ON Group_ResultDetailGroup_ResultID = Group_ResultID AND
Group_ResultFlagPerTest = 'Y'
WHERE
T_OrderDetailT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND
T_OrderDetailIsActive = 'Y'
GROUP BY T_OrderDetailID
";
$rows['info_test'] = $this->db_onedev->query($sql)->result_array();
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function receivedbycourier(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$datas = $prm['selected'];
foreach($datas as $k => $v){
$sql = "UPDATE result_courierspk_detail SET Result_CourierSPKDetailStatus = 'S', Result_CourierSPKDetailsUserID = {$userid}
WHERE
Result_CourierSPKDetailT_OrderDeliveryID = {$v['T_OrderDeliveryID']} AND
Result_CourierSPKDetailT_OrderPromiseID = {$v['T_OrderPromiseID']} AND
Result_CourierSPKDetailIsActive = 'Y'
";
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>''));
$this->sys_ok($result);
}
function confirmspv(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$datas = $prm['selected'];
foreach($datas as $k => $v){
$sql = "UPDATE result_courierspk_detail SET
Result_CourierSPKDetailStatus = 'O',
Result_CourierSPKDetailConfirmedBy = {$userid},
Result_CourierSPKDetailConfirmedDateTime = NOW(),
Result_CourierSPKDetailsUserID = {$userid}
WHERE
Result_CourierSPKDetailT_OrderDeliveryID = {$v['T_OrderDeliveryID']} AND
Result_CourierSPKDetailT_OrderPromiseID = {$v['T_OrderPromiseID']} AND
Result_CourierSPKDetailIsActive = 'Y'
";
// echo $sql;
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>''));
$this->sys_ok($result);
}
}