Files
BE_IBL/application/controllers/v1/preorder/home-service/Receive.php
2026-04-15 15:23:57 +07:00

1671 lines
56 KiB
PHP
Executable File

<?php
class Receive extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Receive API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->load->helper(array('form', 'url'));
}
function getpaymenttypes(){
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT M_PaymentTypeID as id,
M_PaymentTypeName as name
FROM m_paymenttype
WHERE
M_PaymentTypeIsActive = 'Y'";
$rows = $this->db_onedev->query($sql)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getssbydate(){
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "SELECT Preorder_SuppliesTrxID as trx_id,
Preorder_SuppliesTrxNumbering as trx_numbering,
M_StaffName as staff_name,
M_StaffID as staff_id
FROM one_preorder_dev.preorder_suppliestrx
JOIN m_staff ON Preorder_SuppliesTrxM_StaffID = M_StaffID
WHERE
Preorder_SuppliesFlagReceiveOffice = 'N' AND Preorder_SuppliesTrxStatus = 'RCV' AND Preorder_SuppliesTrxDate = '{$prm['xdate']}' AND Preorder_SuppliesTrxIsActive = 'Y'";
$rows = $this->db_onedev->query($sql)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getdatabyss(){
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
//print_r($prm);
$id = $prm['ss']['trx_id'];
$rows['dp'] = $this->getdp($id);
$rows['samples'] = $this->getsamples($id);
$rows['uses'] = $this->getuses($id);
$rows['supplies'] = $this->getsuppliesrest(0,$id);
$rows['suppliesbuffer'] = array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getdp($id){
$rows = [];
$sql = "SELECT PreOrder_HeaderID as trx_id,
PreOrder_HeaderNumbering as trx_numbering,
PreOrder_HeaderDate as trx_date,
M_PatientDOB as patient_dob,
DATE_FORMAT(PreOrder_HeaderTime,'%H:%i') as trx_time,
'' as patient_age,
PreOrder_HeaderDP as dp,
M_PatientName as patient_name,
ifnull(M_PaymentTypeName,'Pilih Tipe Bayar') as paymenttype_name,
M_PaymentTypeID as paymenttype_id
FROM one_preorder_dev.preorder_sample
JOIN one_preorder_dev.preorder_header ON Preorder_SamplePreOrder_HeaderID = PreOrder_HeaderID
JOIN m_patient ON PreOrder_HeaderM_PatientID = M_PatientID
LEFT JOIN m_paymenttype ON PreOrder_HeaderM_PaymentTypeID = M_PaymentTypeID
WHERE
Preorder_SamplePreorder_SuppliesTrxID = {$id} AND Preorder_SampleIsActive = 'Y'
GROUP BY PreOrder_HeaderID";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
return $rows;
}
function getsamples($id){
$rows = [];
$sql = "SELECT
Preorder_SampleID as trx_id,
T_SampleTypeName as sampletype_name,
Preorder_SampleQty as qty,
Preorder_SampleFlagReceived as flag_receive,
Preorder_SampleBarcode as barcode,
PreOrder_HeaderNumbering as trx_numbering,
DATE_FORMAT(PreOrder_HeaderTime,'%H:%i') as trx_time,
PreOrder_HeaderDP as dp,
M_PatientName as patient_name
FROM one_preorder_dev.preorder_sample
JOIN t_sampletype ON Preorder_SampleT_SampleTypeID = T_SampleTypeID
JOIN one_preorder_dev.preorder_header ON Preorder_SamplePreOrder_HeaderID = PreOrder_HeaderID
JOIN m_patient ON PreOrder_HeaderM_PatientID = M_PatientID
WHERE
Preorder_SamplePreorder_SuppliesTrxID = {$id} AND Preorder_SampleIsActive = 'Y'";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
return $rows;
}
function getuses($id){
$rows = [];
$sql = "SELECT
Preorder_SuppliesUseID as trx_id,
PreOrder_HeaderNumbering as trx_numbering,
DATE_FORMAT(PreOrder_HeaderTime,'%H:%i') as trx_time,
M_PatientName as patient_name,
M_SuppliesName as supplies_name,
Preorder_SuppliesUseQty as qty
FROM one_preorder_dev.preorder_suppliesuse
JOIN m_supplies ON Preorder_SuppliesUseM_SuppliesID = M_SuppliesID
JOIN one_preorder_dev.preorder_header ON Preorder_SuppliesUsePreOrder_HeaderID = PreOrder_HeaderID
JOIN m_patient ON PreOrder_HeaderM_PatientID = M_PatientID
WHERE
Preorder_SuppliesUsePreorder_SuppliesTrxID = {$id} AND Preorder_SuppliesUseIsActive = 'Y'";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
return $rows;
}
function getsuppliesrest($xid,$id){
$rows = [];
if($xid == 0 || $xid == '0'){
$sql = "SELECT 0 as trx_id,
Preorder_SuppliesM_SuppliesID as supplies_id,
M_SuppliesName as supplies_name,
0 as qty
FROM one_preorder_dev.preorder_supplies
JOIN m_supplies ON Preorder_SuppliesM_SuppliesID = M_SuppliesID
WHERE
Preorder_SuppliesPreorder_SuppliesTrxID = {$id} AND Preorder_SuppliesIsActive = 'Y'
UNION
SELECT 0 as trx_id,
Preorder_SuppliesBufferM_SuppliesID as supplies_id,
M_SuppliesName as supplies_name,
0 as qty
FROM one_preorder_dev.preorder_suppliesbuffer
JOIN m_supplies ON Preorder_SuppliesBufferM_SuppliesID = M_SuppliesID
WHERE
Preorder_SuppliesBufferPreorder_SuppliesTrxID = {$id} AND Preorder_SuppliesBufferIsActive = 'Y'";
}
else{
$sql = "SELECT Preorder_SuppliesRestID as trx_id,
Preorder_SuppliesRestM_SuppliesID as supplies_id,
M_SuppliesName as supplies_name,
Preorder_SuppliesRestQty as qty
FROM one_preorder_dev.preorder_suppliesrest
JOIN m_supplies ON Preorder_SuppliesRestM_SuppliesID = M_SuppliesID
WHERE
Preorder_SuppliesRestPreorder_SuppliesRcvID = {$xid} AND Preorder_SuppliesRestIsActive = 'Y'
";
}
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
return $rows;
}
function getsuppliesbuffer($id){
$rows = [];
$sql = "SELECT
M_SuppliesID as supplies_id,
M_SuppliesName as supplies_name,
Preorder_SuppliesBufferID as trx_id,
Preorder_SuppliesBufferQty as qty,
'Y' as status
FROM one_preorder_dev.preorder_suppliesbuffer
JOIN m_supplies ON Preorder_SuppliesBufferM_SuppliesID = M_SuppliesID
WHERE
Preorder_SuppliesBufferPreorder_SuppliesTrxID = {$id} AND Preorder_SuppliesBufferIsActive = 'Y'";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
return $rows;
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$search = $prm["search"];
$status = $prm["stationid"];
$startdate = $prm["startdate"];
$enddate = $prm["enddate"];
$wherestatus = '';
if($status !== 'PENDING'){
$wherestatus = "Preorder_SuppliesRcvStatus = '{$status}' AND ";
}
else{
$wherestatus = 'Preorder_SuppliesFlagReceiveOffice = "N" AND ';
}
$sql_where = "WHERE $wherestatus ( Preorder_SuppliesTrxDate BETWEEN '{$startdate} 00:00:00' AND '{$enddate} 23:59:59' ) AND Preorder_SuppliesTrxIsActive = 'Y'";
//$sql_param = array();
if ($search != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " ( Preorder_SuppliesTrxNumbering like '%$search%' OR penerima.M_StaffName like '%$search%' ) ";
//$sql_param[] = "%$nama%";
}
$sql = " SELECT count(*) as total
FROM (
SELECT Preorder_SuppliesTrxID
FROM one_preorder_dev.preorder_suppliestrx
LEFT JOIN one_preorder_dev.preorder_suppliesrcv ON Preorder_SuppliesRcvPreorder_SuppliesTrxID = Preorder_SuppliesTrxID AND Preorder_SuppliesRcvIsActive = 'Y'
JOIN m_staff penyampling ON Preorder_SuppliesTrxM_StaffID = penyampling.M_StaffID
LEFT JOIN m_staff penerima ON Preorder_SuppliesRcvM_StaffID = penerima.M_StaffID
$sql_where
GROUP BY Preorder_SuppliesTrxID
) x
";
//echo $sql;
$query = $this->db_onedev->query($sql);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_doctor count", $this->db_onedev);
exit;
}
$sql = "SELECT one_preorder_dev.preorder_suppliestrx.*,
IFNULL(Preorder_SuppliesRcvID,0) as trx_id,
Preorder_SuppliesTrxID as ss_trx_id,
Preorder_SuppliesNote as trx_note,
Preorder_SuppliesTrxNumbering as ss_trx_numbering,
Preorder_SuppliesRcvNumbering as trx_numbering,
Preorder_SuppliesTrxDate as ss_trx_date,
Preorder_SuppliesRcvDate as trx_date,
DATE_FORMAT(Preorder_SuppliesTrxDate ,'%d-%m-%Y') as ss_trx_date_ina,
DATE_FORMAT(Preorder_SuppliesRcvDate ,'%d-%m-%Y') as trx_date_ina,
Preorder_SuppliesRcvStatus as status,
penyampling.M_StaffName as penyampling_name,
IFNULL(penerima.M_StaffName,'-') as penerima_name,
'' as dp,
'' as samples,
'' as supplies,
'' as uses,
CASE
WHEN ISNULL(Preorder_SuppliesRcvID) THEN 'PENDING'
WHEN Preorder_SuppliesRcvStatus = 'NEW' THEN 'BARU'
WHEN Preorder_SuppliesRcvStatus = 'CONFRIM' THEN 'KONFIRMMASI'
END as status_name
FROM one_preorder_dev.preorder_suppliestrx
LEFT JOIN one_preorder_dev.preorder_suppliesrcv ON Preorder_SuppliesRcvPreorder_SuppliesTrxID = Preorder_SuppliesTrxID AND Preorder_SuppliesRcvIsActive = 'Y'
JOIN m_staff penyampling ON Preorder_SuppliesTrxM_StaffID = penyampling.M_StaffID
LEFT JOIN m_staff penerima ON Preorder_SuppliesRcvM_StaffID = penerima.M_StaffID
$sql_where
GROUP BY Preorder_SuppliesTrxID
ORDER BY Preorder_SuppliesTrxID DESC
limit 0,20";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['dp'] = $this->getdp($v['ss_trx_id']);
$rows[$k]['samples'] = $this->getsamples($v['ss_trx_id']);
$rows[$k]['uses'] = $this->getuses($v['ss_trx_id']);
$rows[$k]['supplies'] = $this->getsuppliesrest($v['trx_id'],$v['ss_trx_id']);
//$rows[$k]['buffers'] = $this->getbuffers($v['ss_trx_id']);
}
}
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
/*
function getordersamples(){
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$doctorid = $prm['doctorid'];
$doctoraddressid = $prm['doctoraddressid'];
$sql = "SELECT
0 as idx,
M_SexName,
CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname,
T_SampleTypeName as samplename,
T_OrderHeaderLabNumber as labnumber,
T_OrderHeaderID as orderid,
T_SampleTypeID as sampleid,
'Y' as active,
'N' as flag_image
FROM t_samplingso
JOIN t_orderheader ON T_SamplingSoT_OrderHeaderID = T_OrderHeaderID
JOIN t_sampletype ON T_SamplingSoT_SampleTypeID = T_SampleTypeID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
WHERE
T_SamplingSoM_DoctorID = {$doctorid} AND T_SamplingSoM_DoctorAddressID = {$doctoraddressid} AND T_SamplingSoFlagWL = 'N' AND T_SamplingSoIsActive = 'Y'";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getstation(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT T_SampleStationID as id, T_SampleStationName as name
FROM t_samplestation
WHERE
T_SampleStationIsActive = 'Y'
";
//echo $query;
$rows['stations'] = $this->db_onedev->query($query)->result_array();
//print_r($statuses);
foreach($statuses as $k=>$v){
array_push($rows['statuses'],$v);
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getdoctoraddress(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query =" SELECT M_DoctorAddressID as id, M_DoctorAddressDescription as name
FROM m_doctoraddress
WHERE
M_DoctorAddressM_DoctorID = {$prm['id']} AND M_DoctorAddressIsActive = 'Y'
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
*/
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$xdate = date('Y-m-d',strtotime($prm["trx_date"]));
if($prm['trx_id'] == '0' || $prm['trx_id'] == 0){
$numbering = $this->db_onedev->query("SELECT one_preorder_dev.fn_numbering('RS') as numbering")->row()->numbering;
$query ="INSERT INTO one_preorder_dev.preorder_suppliesrcv (
Preorder_SuppliesRcvNumbering,
Preorder_SuppliesRcvDate,
Preorder_SuppliesRcvPreorder_SuppliesTrxID,
Preorder_SuppliesNote,
Preorder_SuppliesRcvM_StaffID,
Preorder_SuppliesRcvCreated,
Preorder_SuppliesRcvLastUpdated,
Preorder_SuppliesRcvUserID
)
VALUES(
'{$numbering}',
'{$xdate}',
'{$prm['ss']['trx_id']}',
'{$prm['trx_note']}',
'{$prm['staff']['id']}',
NOW(),
NOW(),
'{$userid}'
)
";
//echo $query;
$saveheader = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
}else{
$numbering = $this->db_onedev->query("SELECT Preorder_SuppliesRcvNumbering as numbering FROM one_preorder_dev.preorder_suppliesrcv WHERE Preorder_SuppliesRcvID = {$prm['trx_id']}")->row()->numbering;
$query ="UPDATE one_preorder_dev.preorder_suppliesrcv SET
Preorder_SuppliesNote = '{$prm['trx_note']}',
Preorder_SuppliesRcvLastUpdated = NOW(),
Preorder_SuppliesRcvUserID = '{$userid}'
WHERE
Preorder_SuppliesRcvID = {$prm['trx_id']}
";
//echo $query;
$saveheader = $this->db_onedev->query($query);
$last_id = $prm['trx_id'];
}
if($saveheader){
if($prm['dp']){
foreach($prm['dp'] as $k => $v){
$query ="UPDATE one_preorder_dev.preorder_header SET
PreOrder_HeaderDP = {$v['dp']},
PreOrder_HeaderM_PaymentTypeID = {$v['paymenttype_id']},
PreOrder_HeaderLastUpdated = NOW(),
PreOrder_HeaderUserID = '{$userid}'
WHERE
PreOrder_HeaderID = {$v['trx_id']}
";
//echo $query;
$savedetail = $this->db_onedev->query($query);
}
}
if($prm['samples']){
foreach($prm['samples'] as $k => $v){
$query ="UPDATE one_preorder_dev.preorder_sample SET
Preorder_SampleFlagReceived = '{$v['flag_receive']}',
Preorder_SampleQty = {$v['qty']},
Preorder_SampleLastUpdated = NOW(),
Preorder_SampleUserID = '{$userid}'
WHERE
Preorder_SampleID = {$v['trx_id']}
";
//echo $query;
$savedetail = $this->db_onedev->query($query);
}
}
if($prm['supplies']){
foreach($prm['supplies'] as $k => $v){
if($v['trx_id'] == 0 || $v['trx_id'] == '0'){
$query = "INSERT INTO one_preorder_dev.preorder_suppliesrest (
Preorder_SuppliesRestM_SuppliesID,
Preorder_SuppliesRestQty,
Preorder_SuppliesRestPreorder_SuppliesRcvID,
Preorder_SuppliesRestCreated,
Preorder_SuppliesRestLastUpdated,
Preorder_SuppliesRestUserID
)
VALUES(
{$v['supplies_id']},
{$v['qty']},
{$last_id},
NOW(),
NOW(),
{$userid}
)";
}
else{
$query ="UPDATE one_preorder_dev.preorder_suppliesrest SET
Preorder_SuppliesRestQty = {$v['qty']},
Preorder_SuppliesRestLastUpdated = NOW(),
Preorder_SuppliesRestUserID = '{$userid}'
WHERE
Preorder_SuppliesRestID = {$v['trx_id']}
";
}
//echo $query ;
$savedetail = $this->db_onedev->query($query);
}
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"numbering" => $numbering,
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function deletetrx(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE one_preorder_dev.preorder_suppliesrcv SET
Preorder_SuppliesRcvIsActive = 'N',
Preorder_SuppliesRcvUserID = '{$userid}'
WHERE
Preorder_SuppliesRcvID = {$prm['trx_id']}
";
//echo $query;
$saveheader = $this->db_onedev->query($query);
$r_last = $this->db_onedev->query("SELECT * FROM one_preorder_dev.preorder_suppliesrcv WHERE Preorder_SuppliesRcvID = {$prm['trx_id']}")->row();
$last_id = $prm['trx_id'];
$query = " SELECT *
FROM one_preorder_dev.preorder_sample
WHERE
Preorder_SamplePreorder_SuppliesTrxID = {$r_last->Preorder_SuppliesRcvPreorder_SuppliesTrxID}
GROUP BY Preorder_SamplePreOrder_HeaderID";
//echo $query;
$r_delete = $this->db_onedev->query($query)->result_array();
foreach($r_delete as $k => $v){
$query ="UPDATE one_preorder_dev.preorder_header SET
PreOrder_HeaderDP = 0,
PreOrder_HeaderM_PaymentTypeID = 0,
PreOrder_HeaderUserID = '{$userid}'
WHERE
PreOrder_HeaderID = {$v['Preorder_SamplePreOrder_HeaderID']}
";
//echo $query;
$deletexxx = $this->db_onedev->query($query);
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"numbering" => $prm['trx_numbering'],
"id" => $prm['trx_id']
);
$this->sys_ok($result);
exit;
}
function doaction(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
if($prm['act'] == 'RELEASEC' || $prm['act'] === 'RCVDOC' ){
$sql = "UPDATE so_walklettercourier SET
So_WalkLetterCourierStatus = '{$prm['act']}',
So_WalkLetterCourierNote = '{$prm['trx_note']}',
So_WalkLetterCourierUserID = {$userid}
WHERE
So_WalkLetterCourierID = {$prm['trx']['trx_id']}
";
$this->db_onedev->query($sql);
}
if($prm['act'] === 'DONE'){
$details = $prm['details'];
$count_n = 0;
foreach($details as $k => $v){
if($v['flag_image_receive'] === 'N'){
$count_n++;
}
if($v['flag_result_receive'] === 'N'){
$count_n++;
}
$query ="UPDATE so_walklettercourierdetail SET
So_WalkLetterCourierDetailFlagReceiveImage = '{$v['flag_image_receive']}',
So_WalkLetterCourierDetailFlagReceiveResult = '{$v['flag_result_receive']}',
So_WalkLetterCourierDetailUserID = '{$userid}'
WHERE
So_WalkLetterCourierDetailID = {$v['idx']}
";
//echo $query;
$savedetail = $this->db_onedev->query($query);
}
$status = 'DONE';
if($count_n > 0){
$status = 'PARTDONE';
}
$sql = "UPDATE so_walklettercourier SET
So_WalkLetterCourierStatus = '{$status}',
So_WalkLetterCourierNote = '{$prm['trx_note']}',
So_WalkLetterCourierUserID = {$userid}
WHERE
So_WalkLetterCourierID = {$prm['trx']['trx_id']}
";
$this->db_onedev->query($sql);
}
if($prm['act'] == 'FORCEDONE'){
$sql = "UPDATE so_walklettercourier SET
So_WalkLetterCourierNote = '{$prm['trx_note']}',
So_WalkLetterCourierStatus = 'DONE',
So_WalkLetterCourierUserID = {$userid}
WHERE
So_WalkLetterCourierID = {$prm['trx']['trx_id']}
";
$this->db_onedev->query($sql);
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function doconfirm(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$data_rst = array();
$sql = "UPDATE one_preorder_dev.preorder_suppliesrcv SET Preorder_SuppliesRcvStatus = 'CONFIRM', Preorder_SuppliesRcvUserID = {$userid} WHERE Preorder_SuppliesRcvID = {$prm['trx']['trx_id']}";
//echo $sql;
$this->db_onedev->query($sql);
foreach($prm['dp'] as $k => $v){
$saveorderlab = $this->orderlab($v['trx_id'],$v['patient_age']);
array_push($data_rst,array(
'id'=>$saveorderlab->id,
'number'=>$saveorderlab->number,
'verification_patient'=>array(),
'verification_delivery'=>array(),
'verification_payment'=>array(),
'verification_supplies'=>array(),
'verification_barcode'=>array(),
'verification_companymou'=>array(),
'verification_px'=>array(),
'verification_info'=>array(),
'address_patient'=>array(),
'address_doctor'=>array()
));
if($saveorderlab){
$data_header = $this->db_onedev->query("SELECT * FROM t_orderheader WHERE T_OrderHeaderID = '{$saveorderlab->id}'")->row();
$sql = "INSERT INTO f_payment (
F_PaymentT_OrderHeaderID,
F_PaymentDate,
F_PaymentNote,
F_PaymentTotal,
F_PaymentCreated
)
VALUES(
{$saveorderlab->id},
CURDATE(),
'',
{$data_header->T_OrderHeaderTotal},
NOW()
)";
$r_pay = $this->db_onedev->query($sql);
$last_payment_id = $this->db_onedev->insert_id();
//$last_payment_id = $this->db_onedev->query("SELECT F_PaymentID as id FROM f_payment WHERE F_PaymentT_OrderHeaderID = {$saveorderlab->id} AND F_PaymentIsActive = 'Y' LIMIT 1")->row()->id;
//echo $last_payment_id;
$sql = "INSERT INTO f_paymentdetail (
F_PaymentDetailF_PaymentID,
F_PaymentDetailM_PaymentTypeID,
F_PaymentDetailAmount,
F_PaymentDetailActual,
F_PaymentDetailCreated,
F_PaymentDetailUserID
)
VALUES(
{$last_payment_id},
{$v['paymenttype_id']},
'{$v['dp']}',
'{$v['dp']}',
NOW(),
{$userid}
)";
$this->db_onedev->query($sql);
//insert into barcode
$sql = "SELECT T_OrderHeaderLabNumber as labnumber, T_SampleTypeID as sampletypeid
FROM t_orderdetail
JOIN t_orderheader 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 = {$saveorderlab->id} AND T_OrderDetailIsActive = 'Y'
GROUP BY T_SampleTypeID";
//echo $sql;
$dt_sampletype = $this->db_onedev->query($sql)->result();
foreach($dt_sampletype as $k => $v){
$barcode = $v->labnumber.'.'.$v->sampletypeid.'.1';
$sql = "INSERT INTO t_barcodelab (
T_BarcodeLabT_OrderHeaderID,
T_BarcodeLabBarcode,
T_BarcodeLabT_SampleTypeID,
T_BarcodeLabCreated,
T_BarcodeLabLastUpdated,
T_BarcodeLabUserID
)
VALUES(
{$saveorderlab->id},
'{$barcode}',
{$v->sampletypeid},
NOW(),
NOW(),
{$userid}
)";
//echo $sql;
$savebarcode = $this->db_onedev->query($sql);
if($savebarcode){
$barcodeid = $this->db_onedev->insert_id();
$sql = "SELECT *
FROM t_ordersample
WHERE
T_OrderSampleT_OrderHeaderID = {$saveorderlab->id} AND
T_OrderSampleT_SampleTypeID = {$v->sampletypeid} AND
T_OrderSampleT_BarcodeLabID = {$barcodeid} AND T_OrderSampleIsActive = 'Y'";
$ordersample = $this->db_onedev->query($sql)->row();
$sql = "UPDATE t_ordersample SET
T_OrderSampleSampling = 'Y',
T_OrderSampleSamplingDate = CURDATE(),
T_OrderSampleSamplingTime = CURTIME(),
T_OrderSampleSamplingUserID = {$userid},
T_OrderSampleReceive = 'Y',
T_OrderSampleReceiveDate = CURDATE(),
T_OrderSampleReceiveTime = CURTIME(),
T_OrderSampleReceiveUserID = {$userid},
T_OrderSampleVerification = 'Y',
T_OrderSampleVerificationDate = CURDATE(),
T_OrderSampleVerificationTime = CURTIME(),
T_OrderSampleVerificationUserID = {$userid}
WHERE
T_OrderSampleID = {$ordersample->T_OrderSampleID}";
$this->db_onedev->query($sql);
$sql = "SELECT *
FROM last_statussample
WHERE
Last_StatusSampleT_OrderHeaderID = {$saveorderlab->id} AND
Last_StatusSampleT_SampleTypeID = {$v->sampletypeid} AND
Last_StatusSampleBarcode = '{$ordersample->T_OrderSampleBarcode}' AND Last_StatusSampleIsActive = 'Y'";
$last_statussample = $this->db_onedev->query($sql)->row();
$sql = "UPDATE last_statussample SET
Last_StatusSampleM_StatusSampleID = '15',
Last_StatusSampleUserID = {$userid}
WHERE
Last_StatusSampleID = {$last_statussample->Last_StatusSampleID}";
$this->db_onedev->query($sql);
$sql = "INSERT INTO t_ordersampleaddon (
T_OrderSampleAddonT_OrderSampleID,
T_OrderSampleAddonVerificationSampleType,
T_OrderSampleAddonVerificationQuantity,
T_OrderSampleAddonVerificationQuality
)
VALUES(
{$ordersample->T_OrderSampleID},
'Y',
'Y',
'Y'
)";
$this->db_onedev->query($sql);
$sql = "INSERT INTO helper_order (
Helper_OrderT_OrderHeaderID,
Helper_OrderSamplingVerificationPhoto,
Helper_OrderCreated,
Helper_OrderLastUpdated,
Helper_OrderUserID
)
VALUES(
{$saveorderlab->id},
'Y',
NOW(),
NOW(),
{$userid}
)";
$this->db_onedev->query($sql);
$sql = "SELECT * FROM helper_sst WHERE Helper_SstT_OrderHeaderID = {$saveorderlab->id}";
//echo $sql;
$sample_per_station = $this->db_onedev->query($sql)->result();
foreach($sample_per_station as $k => $v){
$sql = "INSERT INTO t_sampling_queue_last_status(
T_SamplingQueueLastStatusT_SampleStationID,
T_SamplingQueueLastStatusT_OrderHeaderID,
T_SamplingQueueLastStatusT_SamplingQueueStatusID,
T_SamplingQueueLastStatusUserID
)
VALUES(
{$v->Helper_SstT_SampleStationID},
{$v->Helper_SstT_OrderHeaderID},
5,
{$userid}
)";
$ins_queue_sample = $this->db_onedev->query($sql);
$sql = "UPDATE helper_sst SET Helper_SstStatus = 'Y' WHERE Helper_SstID = {$v->Helper_SstID}";
$this->db_onedev->query($sql);
}
}
}
}
}
foreach($data_rst as $k=>$v){
$data_rst[$k]['verification_patient'] = $this->add_verification_patient($v['id']);
$data_rst[$k]['verification_doctor'] = $this->add_verification_doctor($v['id']);
$data_rst[$k]['verification_delivery'] = $this->add_verification_delivery($v['id']);
$data_rst[$k]['verification_payment'] = $this->add_verification_payment($v['id']);
$data_rst[$k]['verification_supplies'] = $this->add_verification_supplies($v['id']);
$data_rst[$k]['verification_barcode'] = $this->add_verification_barcode($v['id']);
$data_rst[$k]['verification_companymou'] = $this->add_verification_companymou($v['id']);
$data_rst[$k]['verification_px'] = $this->add_verification_test($v['id']);
$data_rst[$k]['verification_info'] = $this->add_verification_info($v['id']);
$data_rst[$k]['address_patient'] = $this->add_address_patient($v['id']);
$data_rst[$k]['address_doctor'] = $this->add_address_doctor($v['id']);
$saveverication = $this->savetrxverification($v['id'],$data_rst[$k]);
}
$result = array(
"total" => 1 ,
"records" => $data_rst,
"numbering" => $prm['trx_numbering'],
"id" => $prm['trx_id']
);
$this->sys_ok($result);
exit;
}
function orderlab($order_id,$patientage){
//$order_id = $prm['orderid'];
//$patientage = $prm['patientage'];
$userid = $this->sys_user["M_UserID"];
/***t_orderheader***/
$sql = " SELECT *
FROM one_preorder_dev.preorder_header
LEFT JOIN one_preorder_dev.conf_system ON Conf_SystemIsActive = 'Y'
JOIN one.m_mou ON Conf_SystemMOUID = M_MouID
WHERE
PreOrder_HeaderID = '{$order_id}'";
//echo $query;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("select preorder_header", $this->db_onedev);
exit;
}
$data_order = $query->row_array();
$xheader = array(
'patient_id' => $data_order['PreOrder_HeaderM_PatientID'],
'age' => $patientage,
'company_id' => $data_order['M_MouM_CompanyID'],
'mou_id' => $data_order['Conf_SystemMOUID'],
'lang_id' => $data_order['PreOrder_HeaderM_LangID'],
'sender_address_id' => $data_order['PreOrder_HeaderM_DoctorAddressID'],
'sender_doctor_id' => $data_order['PreOrder_HeaderM_DoctorID'],
'doctor_note' => '',
'fo_note' => '',
'queue' => '',
'received_sample' => 'N',
);
$xdelivery = array();
$query = " SELECT *
FROM one_preorder_dev.preorder_header
JOIN one_preorder_dev.preorder_delivery ON PreOrder_DeliveryPreOrder_HeaderID = '{$order_id}' AND PreOrder_DeliveryIsActive = 'Y'
WHERE
PreOrder_HeaderID = '{$order_id}'";
//echo $query;
$delver = $this->db_onedev->query($query)->result_array();
foreach($delver as $k => $v){
$xdel = array(
'address_id' => $v['PreOrder_DeliveryAddressID'],
'delivery_id' => $v['PreOrder_DeliveryM_DeliveryID'],
'delivery_type_id' => $v['PreOrder_DeliveryM_DeliveryTypeID'],
'note' => $v['PreOrder_DeliveryDestination']
);
array_push($xdelivery,$xdel);
}
//print_r($xdelivery );
$query = " SELECT *
FROM one_preorder_dev.preorder_test
JOIN one.t_test ON PreOrder_TestT_TestID = T_TestID
WHERE
PreOrder_TestPreOrder_HeaderID = '{$order_id}' AND PreOrder_TestIsActive = 'Y'";
$data_order_detail = $this->db_onedev->query($query)->result_array();
$xdetails = array();
foreach($data_order_detail as $k => $v){
$xdet = array(
't_id' => $v['PreOrder_TestT_TestID'],
't_cito' => 'N',
't_price' => $v['PreOrder_TestPrice'],
't_disc' => $v['PreOrder_TestDisc'],
't_discrp' => $v['PreOrder_TestDiscRp'],
't_req' => 'Y',
't_reqnote' => $v['T_TestRequirement']
);
array_push($xdetails,$xdet);
}
$header_json = json_encode($xheader);
$delivery_json = json_encode($xdelivery);
$detail_json = json_encode($xdetails);
$sql = "CALL one.sp_fo_register_save(
0,
'{$header_json}',
'{$delivery_json}',
'{$detail_json}',
'{$userid}'
)";
//echo $sql;
$r = $this->db_onedev->query($sql)->row();
$this->clean_mysqli_connection($this->db_onedev->conn_id);
return json_decode($r->data);
/***t_orderheader***/
}
/***begin-verification***/
function add_address_patient($orderid){
$query =" SELECT M_PatientAddressID as id,
M_PatientAddressNote as note,
M_PatientAddressDescription as description,
M_PatientAddressM_KelurahanID as vilageid
FROM m_patientaddress
JOIN t_orderheader ON M_PatientAddressM_PatientID = T_OrderHeaderM_PatientID
WHERE
T_OrderHeaderID = {$orderid} AND M_PatientAddressIsActive = 'Y'
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if($rows)
return $rows;
else
return array();
}
function add_address_doctor($orderid){
$query =" SELECT M_DoctorAddressID as id,
M_DoctorAddressNote as note,
M_DoctorAddressDescription as description,
M_DoctorAddressM_KelurahanID as vilageid
FROM m_doctoraddress
JOIN t_orderheader ON T_OrderHeaderSenderM_DoctorID = M_DoctorAddressM_DoctorID
WHERE
T_OrderHeaderID = {$orderid} AND M_DoctorAddressIsActive = 'Y'
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if($rows)
return $rows;
else
return array();
}
function add_verification_patient($orderid){
$query =" SELECT Fo_VericationTypeID as id,
0 as xid,
'Y' as chex,
'' as note,
Fo_VerificationTypeLabel as label
FROM fo_verificationtype
LEFT JOIN fo_verification ON Fo_VerificationFo_VericationTypeID = Fo_VericationTypeID AND Fo_VerificationT_OrderHeaderID = $orderid
WHERE
Fo_VerificationTypeGroup = 'PATIENT' AND Fo_VerificationTypeIsActive = 'Y'
GROUP BY Fo_VericationTypeID
";
//echo $query;
$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;
}
function add_verification_doctor($orderid){
$query =" SELECT Fo_VericationTypeID as id,
0 as xid,
'Y' as chex,
'' as note,
Fo_VerificationTypeLabel as label
FROM fo_verificationtype
LEFT JOIN fo_verification ON Fo_VerificationFo_VericationTypeID = Fo_VericationTypeID AND Fo_VerificationT_OrderHeaderID = $orderid
WHERE
Fo_VerificationTypeGroup = 'DOCTOR' AND Fo_VerificationTypeIsActive = 'Y'
GROUP BY Fo_VericationTypeID
";
$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;
}
function add_verification_companymou($orderid){
$query =" SELECT Fo_VericationTypeID as id,
0 as xid,
'Y' as chex,
'' as note,
Fo_VerificationTypeLabel as label
FROM fo_verificationtype
LEFT JOIN fo_verification ON Fo_VerificationFo_VericationTypeID = Fo_VericationTypeID AND Fo_VerificationT_OrderHeaderID = $orderid
WHERE
Fo_VerificationTypeGroup = 'COMPANY' AND Fo_VerificationTypeIsActive = 'Y'
GROUP BY Fo_VericationTypeID
";
$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;
}
function add_verification_payment($orderid){
$query =" SELECT Fo_VericationTypeID as id,
0 as xid,
'Y' as chex,
'' as note,
Fo_VerificationTypeLabel as label,
'reguler' as type
FROM fo_verificationtype
LEFT JOIN fo_verification ON Fo_VerificationFo_VericationTypeID = Fo_VericationTypeID AND Fo_VerificationT_OrderHeaderID = $orderid
WHERE
Fo_VerificationTypeGroup = 'PAYMENT' AND Fo_VerificationTypeIsActive = 'Y'
GROUP BY Fo_VericationTypeID
";
$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;
}
function add_verification_supplies($orderid){
$query =" SELECT M_SuppliesID as id,
0 as xid,
'Y' as chex,
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
LEFT JOIN t_ordersupplies ON T_OrderSuppliesT_OrderHeaderID = $orderid AND T_OrderSuppliesM_SuppliesID = M_SuppliesID
WHERE
M_SuppliesIsActive = 'Y'
";
//echo $query ;
$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;
}
function add_verification_barcode($orderid){
$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 ;
$rows = $this->db_onedev->query($query)->result();
foreach($rows as $k => $v){
$query = "SELECT T_SampleTypeID as id, 0 as xid,
'Y' 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();
foreach($v->children as $ki => $vi){
if($vi['chex'] == 'N')
$v->children[$ki]['chex'] = false;
else
$v->children[$ki]['chex'] = true;
}
}
return $rows;
}
function add_verification_delivery($orderid){
$query =" SELECT T_OrderDeliveryID as id,
0 as xid,
M_DeliveryTypeCode as code,
'Y' as chex,
M_DeliveryID as deliveryid,
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, ' : ', M_DoctorAddressDescription)
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN CONCAT(M_DeliveryName, ' : ', M_PatientAddressDescription)
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN CONCAT(M_DeliveryName, ' : ', M_DoctorHP)
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN CONCAT(M_DeliveryName, ' : ', M_PatientHP)
ELSE
CONCAT(M_DeliveryName,' : ',T_OrderDeliveryDestination)
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 = 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 )
WHERE
T_OrderDeliveryT_OrderHeaderID = {$orderid} AND T_OrderDeliveryIsActive = 'Y'
GROUP BY T_OrderDeliveryID
UNION
SELECT 0 as id,
0 as xid,
M_DeliveryTypeCode as code,
'Y' as chex,
Fo_VerificationDeliveryAddM_DeliveryID as deliveryid,
Fo_VerificationDeliveryAddM_DeliveryTypeID as typedeliveryid,
Fo_VerificationDeliveryAddM_KelurahanID as vilageid,
IF(ISNULL(Fo_VerificationDeliveryAddID),'',Fo_VerificationDeliveryAddReason) as note,
'reguler' as type,
CASE
WHEN Fo_VerificationDeliveryAddM_DeliveryID = 1 THEN M_DeliveryName
WHEN Fo_VerificationDeliveryAddM_DeliveryID = 4 THEN CONCAT(M_DeliveryName, ' : ', M_DoctorAddressDescription)
WHEN Fo_VerificationDeliveryAddM_DeliveryID = 2 THEN CONCAT(M_DeliveryName, ' : ', M_PatientAddressDescription)
WHEN ( Fo_VerificationDeliveryAddM_DeliveryID = 7 OR Fo_VerificationDeliveryAddM_DeliveryID = 9 ) THEN CONCAT(M_DeliveryName, ' : ', M_DoctorHP)
WHEN ( Fo_VerificationDeliveryAddM_DeliveryID = 6 OR Fo_VerificationDeliveryAddM_DeliveryID = 8 ) THEN CONCAT(M_DeliveryName, ' : ', M_PatientHP)
ELSE
CONCAT(M_DeliveryName,' : ',Fo_VerificationDeliveryAddDestination)
END as label,
CASE
WHEN Fo_VerificationDeliveryAddM_DeliveryID = 1 THEN ''
WHEN Fo_VerificationDeliveryAddM_DeliveryID = 4 THEN M_DoctorAddressDescription
WHEN Fo_VerificationDeliveryAddM_DeliveryID = 2 THEN M_PatientAddressDescription
WHEN ( Fo_VerificationDeliveryAddM_DeliveryID = 7 OR Fo_VerificationDeliveryAddM_DeliveryID = 9 ) THEN M_DoctorHP
WHEN ( Fo_VerificationDeliveryAddM_DeliveryID = 6 OR Fo_VerificationDeliveryAddM_DeliveryID = 8 ) THEN M_PatientHP
ELSE
Fo_VerificationDeliveryAddDestination
END as destination,
CASE
WHEN Fo_VerificationDeliveryAddM_DeliveryID = 4 THEN M_DoctorAddressID
WHEN Fo_VerificationDeliveryAddM_DeliveryID = 2 THEN M_PatientAddressID
ELSE
0
END as addressid
FROM fo_verification_delivery_add
JOIN t_orderheader ON Fo_VerificationDeliveryAddT_OrderHeaderID = T_OrderHeaderID
JOIN m_delivery ON Fo_VerificationDeliveryAddM_DeliveryID = M_DeliveryID
JOIN m_deliverytype ON Fo_VerificationDeliveryAddM_DeliveryTypeID = M_DeliveryTypeID
LEFT JOIN m_doctoraddress ON Fo_VerificationDeliveryAddAddressID = M_DoctorAddressID AND Fo_VerificationDeliveryAddM_DeliveryID = 4
LEFT JOIN m_patientaddress ON Fo_VerificationDeliveryAddAddressID = M_PatientAddressID AND Fo_VerificationDeliveryAddM_DeliveryID = 2
LEFT JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND ( Fo_VerificationDeliveryAddM_DeliveryID = 7 OR Fo_VerificationDeliveryAddM_DeliveryID = 9 )
LEFT JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND ( Fo_VerificationDeliveryAddM_DeliveryID = 6 OR Fo_VerificationDeliveryAddM_DeliveryID = 8 )
WHERE
Fo_VerificationDeliveryAddT_OrderHeaderID = {$orderid} AND Fo_VerificationDeliveryAddIsActive = 'Y'
";
//echo $query ;
$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;
}
function add_verification_test($orderid){
$query =" SELECT * FROM (
SELECT T_OrderDetailID as id,
0 as xid,
'Y' as chex,
IF(ISNULL(Fo_VerificationTestID),'',Fo_VerificationTestReason) as note,
T_TestID as pxid,
T_TestName as pxname,
T_OrderDetailIsCito as flagcito,
T_OrderDetailPrice as bruto,
T_OrderDetailDiscTotal as discount,
T_OrderDetailTotal as total,
'N' as addon
FROM t_orderdetail
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsPrice = 'Y'
LEFT JOIN fo_verification_test ON Fo_VerificationTestT_OrderDetailID = T_OrderDetailID
WHERE
T_OrderDetailT_OrderHeaderID = $orderid AND T_OrderDetailIsActive = 'Y'
UNION
SELECT 0 as id,
IFNULL(Fo_VerificationTestAddID,0) as xid,
IF(ISNULL(Fo_VerificationTestAddIsOK),'N',Fo_VerificationTestAddIsOK) as chex,
'' as note,
Fo_VerificationTestAddT_TestID as pxid,
T_TestName as pxname,
Fo_VerificationTestAddIsCito as flagcito,
Fo_VerificationTestAddBruto as bruto,
Fo_VerificationTestAddDiscount as discount,
Fo_VerificationTestAddTotal as total,
'N' as addon
FROM fo_verification_test_add
JOIN t_test ON Fo_VerificationTestAddT_TestID = T_TestID
WHERE
Fo_VerificationTestAddT_OrderHeaderID = $orderid AND Fo_VerificationTestAddIsActive = 'Y' ) x
GROUP BY pxid
";
//echo $query ;
$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;
if($v['addon'] == 'N')
$rows[$k]['addon'] = false;
else
$rows[$k]['addon'] = true;
}
return $rows;
}
function add_verification_info($orderid){
$query =" SELECT Fo_VericationTypeID as id,
0 as xid,
'Y' as chex,
IF(ISNULL(Fo_VerificationID),'',Fo_VerificationReason) as note,
Fo_VerificationTypeLabel as label
FROM fo_verificationtype
LEFT JOIN fo_verification ON Fo_VerificationFo_VericationTypeID = Fo_VericationTypeID AND Fo_VerificationT_OrderHeaderID = $orderid
WHERE
Fo_VerificationTypeGroup = 'INFO' AND Fo_VerificationTypeIsActive = 'Y'
GROUP BY Fo_VericationTypeID
";
//echo $query;
$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 savetrxverification($orderid,$prm)
{
try {
//print_r($prm);
//# 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'];
$fostatusid = 3;
$fologcode = 'FO.VERIFICATION.CONFIRM';
//print_r($prm);
$xverificationnote = $prm['verification_note'];
//echo $xverificationnote;
$id = $orderid;
/*$sql = "update t_orderheader
set
T_OrderHeaderVerificationNote = ''
where
T_OrderHeaderID = $id";
//echo $sql;
$query = $this->db_onedev->query($sql);*/
//print_r($prm['verification_patient']);
$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
)
);
//echo $this->db_onedev->last_query();
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;
}
}
return rows;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
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($v['xid'] === 0 || $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
)
);
//echo $this->db_onedev->last_query();
//echo "///////////////////////";
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 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);
}
}
/***end-verification***/
}