Initial import
This commit is contained in:
203
application/controllers/tools/Incomingref.php
Normal file
203
application/controllers/tools/Incomingref.php
Normal file
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
class IncomingRef extends MY_Controller
|
||||
{
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->db = $this->load->database("onedev", true);
|
||||
}
|
||||
function ref_order($incomingRefID) {
|
||||
$sql = "select * from incoming_ref where incomingRefID = ?";
|
||||
$qry = $this->db->query($sql, array($incomingRefID) );
|
||||
$rows = array();
|
||||
$branchID = 0;
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
if ( count($rows) > 0 ) $branchID = $rows[0]["incomingRefM_BranchID"];
|
||||
}
|
||||
$companyID = 0;
|
||||
if ($branchID > 0 ) {
|
||||
$sql = "select *
|
||||
from m_branch where M_BranchID = ?";
|
||||
$qry = $this->db->query($sql, array($branchID) );
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$companyID = $rows[0]["M_BranchM_CompanyID"];
|
||||
$mouID = $rows[0]["M_BranchM_MouID"];
|
||||
$doctorID = $rows[0]["M_BranchM_DoctorID"];
|
||||
$doctorAddressID = $rows[0]["M_BranchM_DoctorAddressID"];
|
||||
}
|
||||
}
|
||||
if ($companyID > 0 ) {
|
||||
|
||||
$sql = "";
|
||||
}
|
||||
}
|
||||
function fo_verify($orderID,$userID) {
|
||||
$sql="INSERT INTO fo_verificationsvalue (
|
||||
Fo_VerificationsValueT_OrderHeaderID,
|
||||
Fo_VerificationsValueFo_VerificationsLabelID,
|
||||
Fo_VerificationsValueCheck,
|
||||
Fo_VerificationsValueNote,
|
||||
Fo_VerificationsValueUserID,
|
||||
Fo_VerificationsValueCreated )
|
||||
SELECT {$orderID},
|
||||
Fo_VerificationsLabelID,
|
||||
'Y',
|
||||
'', {$userID},
|
||||
NOW()
|
||||
FROM fo_verificationslabel
|
||||
WHERE
|
||||
Fo_VerificationsLabelIsActive = 'Y' ";
|
||||
$this->db->query($sql);
|
||||
|
||||
$sql = "call sp_fo_barcode_generate({$orderID})";
|
||||
$this->db->query($sql);
|
||||
|
||||
$fostatusid = 3;
|
||||
$fologcode = 'FO.VERIFICATION.CONFIRM';
|
||||
|
||||
$sql = "insert into fo_status(
|
||||
Fo_StatusDate,
|
||||
Fo_StatusT_OrderHeaderID,
|
||||
Fo_StatusM_StatusID,
|
||||
Fo_StatusM_UserID,
|
||||
Fo_StatusCreated,
|
||||
Fo_StatusUpdated)
|
||||
values( now(), ?, ?, ?, now(),now())";
|
||||
|
||||
$query = $this->db->query($sql,
|
||||
array(
|
||||
$orderID,
|
||||
$fostatusid, $userID
|
||||
)
|
||||
);
|
||||
|
||||
if (!$query) {
|
||||
$this->sys_error_db("fo_status insert");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM fo_verificationsvalue WHERE Fo_VerificationsValueT_OrderHeaderID = {$orderID}";
|
||||
|
||||
$data_log = array();
|
||||
$data_log['orderid'] = $orderID;
|
||||
$data_log['values'] = $this->db->query($sql)->result_array();
|
||||
$data_log['note'] = '';
|
||||
|
||||
$json_dt_log = json_encode($data_log);
|
||||
$sql = "insert into one_log.log_fo(
|
||||
Log_FoDate,
|
||||
Log_FoCode,
|
||||
Log_FoJson,
|
||||
Log_FoUserID)
|
||||
values( now(), ?, ?, ?)";
|
||||
$query = $this->db->query($sql,
|
||||
array(
|
||||
$fologcode,
|
||||
$json_dt_log,
|
||||
$userID
|
||||
)
|
||||
);
|
||||
|
||||
if (!$query) {
|
||||
$this->sys_error_db("one_log.fo_log insert");
|
||||
exit;
|
||||
}
|
||||
|
||||
/* T_OrderSample */
|
||||
$adminUserID = 3;
|
||||
$sql = "update t_ordersample
|
||||
set T_OrderSampleSampling='Y', T_OrderSampleSamplingDate = now(),
|
||||
T_OrderSampleSamplingTime = now(),T_OrderSampleSamplingUserID = $adminUserID,
|
||||
T_OrderSampleReceive='Y', T_OrderSampleReceiveDate = now() , T_OrderSampleReceiveTime = now(),
|
||||
T_OrderSampleReceiveUserID = $adminUserID,
|
||||
T_OrderSampleVerification='Y', T_OrderSampleVerificationDate=now(), T_OrderSampleVerificationTime=now(),
|
||||
T_OrderSampleVerificationUserID = $adminUserID,
|
||||
T_OrderSampleSendHandling = 'Y', T_OrderSampleSendHandlingDate =now(), T_OrderSampleSendHandlingTime=now(),
|
||||
T_OrderSampleSendHandlingUserID = $adminUserID,
|
||||
T_OrderSampleReceiveHandling = 'Y', T_OrderSampleReceiveHandlingDate=now(), T_OrderSampleReceiveHandlingTime=now(),
|
||||
T_OrderSampleReceiveHandlingUserID=$adminUserID,
|
||||
T_OrderSampleHandling='Y', T_OrderSampleHandlingDate=now(), T_OrderSampleHandlingTime=now(),
|
||||
T_OrderSampleHandlingUserID=$adminUserID,
|
||||
T_OrderSampleProcessing='Y', T_OrderSampleReadyToProcessDateTime=now(), T_OrderSampleProcessingDate=now(),
|
||||
T_OrderSampleProcessingTime=now(), T_OrderSampleProcessingUserID=$adminUserID,
|
||||
T_OrderSampleUserID=$adminUserID
|
||||
where T_OrderSampleT_OrderHeaderID = ?";
|
||||
|
||||
|
||||
$qry = $this->db->query($sql, array($orderID) );
|
||||
if (!$qry) {
|
||||
echo $this->db->last_query();
|
||||
$this->sys_error_db("one_log.fo_log insert");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->sys_ok("Verified");
|
||||
$this->broadcast("fo-verification-y");
|
||||
}
|
||||
function receive() {
|
||||
$prm = $this->sys_input;
|
||||
$branchCode = $prm[0]["OriginM_BranchCode"];
|
||||
$sql = "select M_BranchID from m_branch where M_BranchIsActive = 'Y' and
|
||||
M_BranchCode=?";
|
||||
$qry = $this->db->query($sql,array($branchCode));
|
||||
$branchID = 0;
|
||||
if ($qry ) {
|
||||
$rows = $qry->result_array();
|
||||
if (count($rows) > 0 ) $branchID = $rows[0]["M_BranchID"];
|
||||
}
|
||||
$flag_first = true;
|
||||
try
|
||||
{
|
||||
|
||||
$this->db->trans_start();
|
||||
foreach($prm as $p ) {
|
||||
if ($flag_first) {
|
||||
$flag_first = false;
|
||||
$sql_h = "insert into incoming_ref(incomingRefT_RefDeliveryOrderID,
|
||||
incomingRefOriginM_BranchCode,incomingRefM_BranchID, incomingRefT_RefDeliveryOrderDate,
|
||||
incomingRefT_RefDeliveryOrderNumber) values(?,
|
||||
?,?,?,
|
||||
?)";
|
||||
$this->db->query($sql_h,array($p["T_RefDeliveryOrderID"],
|
||||
$p["OriginM_BranchCode"], $branchID, $p["T_RefDeliveryOrderDate"],
|
||||
$p["T_RefDeliveryOrderNumber"]));
|
||||
$orderID = $this->db->insert_id();
|
||||
}
|
||||
//insert detail
|
||||
$sql_d = "insert into incoming_ref_detail(incomingRefDetailIncomingRefID,
|
||||
incomingRefDetailT_OrderHeaderID, incomingRefDetailT_OrderHeaderLabNumber,
|
||||
incomingRefDetailM_PatientName, incomingRefDetailFoNote,
|
||||
incomingRefDetailVefificationNote, incomingRefDetailSamplingNote,
|
||||
incomingRefDetailT_TestID, incomingRefDetailT_TestName,
|
||||
incomingRefDetailT_OrderPromiseDateTime, incomingRefDetailT_OrderDetailID,
|
||||
incomingRefDetailT_BarcodeLabBarcode,incomingRefDetailRequirements,
|
||||
incomingRefDetailPatient)
|
||||
values( ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?)";
|
||||
$patient = json_encode($p["patient"]);
|
||||
$requirements = json_encode($p["requirements"]);
|
||||
foreach($p["test"] as $t ) {
|
||||
$this->db->query($sql_d , array($orderID,
|
||||
$p["T_OrderHeaderID"], $p["T_OrderHeaderLabNumber"],
|
||||
$p["M_PatientName"], $p["FoNote"],
|
||||
$p["VerificationNote"], $p["SamplingNote"],
|
||||
$t["T_TestID"], $p["T_TestName"],
|
||||
$t["T_OrderPromiseDateTime"], $t["T_OrderDetailID"],
|
||||
$t["T_BarcodeLabBarcode"],$requirements, $patient));
|
||||
}
|
||||
}
|
||||
$this->db->trans_complete();
|
||||
$this->sys_ok("Data Inserted");
|
||||
} catch(Exception $e) {
|
||||
$this->sys_error($e->message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user