Flatten mockup repo
This commit is contained in:
269
application/controllers/mockup/receivesample/Receivesample.php
Normal file
269
application/controllers/mockup/receivesample/Receivesample.php
Normal file
@@ -0,0 +1,269 @@
|
||||
<?php
|
||||
class Receivesample extends MY_Controller
|
||||
{
|
||||
var $db;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// $cek = $this->db->query("select database() as current_db")->result();
|
||||
// print_r($cek);
|
||||
echo "RECEIVE SAMPLE API";
|
||||
}
|
||||
|
||||
public function search()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$date = $prm["date"];
|
||||
$search = "";
|
||||
if (isset($prm['search'])) {
|
||||
$search = trim($prm["search"]);
|
||||
if ($search != "") {
|
||||
$search = '%' . $prm['search'] . '%';
|
||||
} else {
|
||||
$search = '%%';
|
||||
}
|
||||
}
|
||||
|
||||
$number_offset = 0;
|
||||
$number_limit = 20;
|
||||
if ($prm["current_page"] > 0) {
|
||||
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
||||
}
|
||||
|
||||
$sql_tot = "SELECT count(*) as total
|
||||
FROM spk_home_service_order
|
||||
JOIN t_orderheader ON SpkHomeServiceOrderT_OrderHeaderID = T_OrderHeaderID
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
JOIN spk_home_service ON SpkHomeServiceOrderSpkHomeServiceID = SpkHomeServiceID
|
||||
AND SpkHomeServiceIsActive = 'Y'
|
||||
AND SpkHomeServiceStatus = 'R'
|
||||
AND DATE(SpkHomeServiceDate) = ?
|
||||
JOIN preregister_online ON SpkHomeServiceOrderPreregisterOnlineID = PreregisterOnlineID
|
||||
AND PreregisterOnlineIsActive = 'Y'
|
||||
JOIN m_patient ON PreregisterOnlineM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
WHERE SpkHomeServiceOrderIsActive = 'Y'
|
||||
AND (T_OrderHeaderLabNumber LIKE ? OR SpkHomeServiceNumber LIKE ?)
|
||||
";
|
||||
$qry_tot = $this->db->query($sql_tot, [
|
||||
$date,
|
||||
$search,
|
||||
$search
|
||||
]);
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($qry_tot) {
|
||||
$tot_count = $qry_tot->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count / $number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("Error spk home service order count", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT SpkHomeServiceOrderID,
|
||||
SpkHomeServiceOrderSpkHomeServiceID,
|
||||
SpkHomeServiceOrderT_OrderHeaderID,
|
||||
SpkHomeServiceOrderBranchCode,
|
||||
SpkHomeServiceOrderPreregisterOnlineID,
|
||||
SpkHomeServiceOrderIsActive,
|
||||
SpkHomeServiceID,
|
||||
SpkHomeServiceNumber,
|
||||
DATE_FORMAT(SpkHomeServiceDate, '%d-%m-%Y') as SpkHomeServiceDate,
|
||||
SpkHomeServiceStatus,
|
||||
M_PatientID,
|
||||
M_PatientNoReg,
|
||||
M_PatientName,
|
||||
T_OrderHeaderID,
|
||||
T_OrderHeaderLabNumber,
|
||||
T_OrderHeaderDate
|
||||
FROM spk_home_service_order
|
||||
JOIN t_orderheader ON SpkHomeServiceOrderT_OrderHeaderID = T_OrderHeaderID
|
||||
AND T_OrderHeaderIsActive = 'Y'
|
||||
JOIN spk_home_service ON SpkHomeServiceOrderSpkHomeServiceID = SpkHomeServiceID
|
||||
AND SpkHomeServiceIsActive = 'Y'
|
||||
AND SpkHomeServiceStatus = 'R'
|
||||
AND DATE(SpkHomeServiceDate) = ?
|
||||
JOIN preregister_online ON SpkHomeServiceOrderPreregisterOnlineID = PreregisterOnlineID
|
||||
AND PreregisterOnlineIsActive = 'Y'
|
||||
JOIN m_patient ON PreregisterOnlineM_PatientID = M_PatientID
|
||||
AND M_PatientIsActive = 'Y'
|
||||
WHERE SpkHomeServiceOrderIsActive = 'Y'
|
||||
AND (T_OrderHeaderLabNumber LIKE ? OR SpkHomeServiceNumber LIKE ?)
|
||||
LIMIT ? OFFSET ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$date,
|
||||
$search,
|
||||
$search,
|
||||
$number_limit,
|
||||
$number_offset
|
||||
]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("Error lookup spk home service order", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"total" => $tot_page,
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getsample()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$orderheaderID = $prm["orderheaderID"];
|
||||
$sql = "SELECT T_OrderSampleID,
|
||||
T_OrderSampleT_SampleTypeID as sampleTypeID,
|
||||
T_OrderSampleT_BarcodeLabID as barcodeLabID,
|
||||
CONCAT(T_SampleTypeName, ' | ', T_OrderSampleBarcode) as typename_barcode,
|
||||
T_SampleTypeName,
|
||||
T_OrderSampleBarcode,
|
||||
T_OrderSampleSampling,
|
||||
IFNULL(T_OrderSampleSamplingDate,'') as T_OrderSampleSamplingDate,
|
||||
IFNULL(T_OrderSampleSamplingTime,'') as T_OrderSampleSamplingTime,
|
||||
T_OrderSampleReceive,
|
||||
IFNULL(T_OrderSampleReceiveDate,'') as T_OrderSampleReceiveDate,
|
||||
IFNULL(T_OrderSampleReceiveTime,'') as T_OrderSampleReceiveTime,
|
||||
IF(ReceiveSampleSampleID IS NULL, 'N', 'Y') AS ischoose
|
||||
FROM t_ordersample
|
||||
JOIN t_sampletype ON T_OrderSampleT_SampleTypeID = T_SampleTypeID
|
||||
JOIN t_barcodelab ON T_OrderSampleT_BarcodeLabID = T_BarcodeLabID
|
||||
LEFT JOIN receive_sample_sample ON T_OrderSampleID= ReceiveSampleSampleT_OrderSampleID
|
||||
AND ReceiveSampleSampleIsActive = 'Y'
|
||||
WHERE T_OrderSampleIsActive = 'Y'
|
||||
AND T_OrderSampleT_OrderHeaderID = ?";
|
||||
$qry = $this->db->query($sql, [$orderheaderID]);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
} else {
|
||||
$this->sys_error_db("Error get sampel", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
"records" => $rows,
|
||||
"sql" => $this->db->last_query()
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function saveConfirm()
|
||||
{
|
||||
try {
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$this->db->trans_begin();
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
$arrSample = $prm["arrSample"];
|
||||
$spkHomeServiceID = $prm["spkHomeServiceID"];
|
||||
$spkHomeServiceOrderID = $prm["spkHomeServiceOrderID"];
|
||||
|
||||
$sql_sr = "INSERT INTO receive_sample(
|
||||
ReceiveSampleDate,
|
||||
ReceiveSampleSpkHomeServiceID,
|
||||
ReceiveSampleIsActive,
|
||||
ReceiveSampleCreated,
|
||||
ReceiveSampleCreatedUserID
|
||||
) VALUES (NOW(), ?, 'Y', NOW(), ?)";
|
||||
$qry_sr = $this->db->query($sql_sr, [$spkHomeServiceID, $userid]);
|
||||
if (!$qry_sr) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Error insert receive sample", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$lastid_sr = $this->db->insert_id();
|
||||
|
||||
$sql_rso = "INSERT INTO receive_sample_order(
|
||||
ReceiveSampleOrderReceiveSampleID,
|
||||
ReceiveSampleOrderSpkHomeServiceOrderID,
|
||||
ReceiveSampleOrderIsActive,
|
||||
ReceiveSampleOrderCreated,
|
||||
ReceiveSampleOrderCreatedUserID
|
||||
) VALUES(?, ?, 'Y', NOW(), ?)";
|
||||
$qry_rso = $this->db->query($sql_rso, [$lastid_sr, $spkHomeServiceOrderID, $userid]);
|
||||
if (!$qry_rso) {
|
||||
$this->db->trans_rollback();
|
||||
$this->sys_error_db("Error insert receive sample order", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($arrSample as $key => $value) {
|
||||
$sql_sample = "INSERT INTO receive_sample_sample(
|
||||
ReceiveSampleSampleReceiveSampleID,
|
||||
ReceiveSampleSampleT_OrderSampleID,
|
||||
ReceiveSampleSampleIsActive,
|
||||
ReceiveSampleSampleCreated,
|
||||
ReceiveSampleSampleCreatedUserID
|
||||
) VALUES(?, ?, 'Y', NOW(), ?)";
|
||||
$qry_sample = $this->db->query($sql_sample, [
|
||||
$lastid_sr,
|
||||
$value["T_OrderSampleID"],
|
||||
$userid
|
||||
]);
|
||||
if (!$qry_sample) {
|
||||
$this->db->trans_rollbakc();
|
||||
$this->sys_error_db("Error insert receive sample sample", $this->db);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "UPDATE t_ordersample SET
|
||||
T_OrderSampleReceive = 'Y',
|
||||
T_OrderSampleReceiveDate = CURDATE(),
|
||||
T_OrderSampleReceiveTime = CURTIME(),
|
||||
T_OrderSampleReceiveUserID = ?
|
||||
WHERE T_OrderSampleID = ?";
|
||||
$qry = $this->db->query($sql, [
|
||||
$userid,
|
||||
$value["T_OrderSampleID"]
|
||||
]);
|
||||
if (!$qry) {
|
||||
$this->db->trans_rollbakc();
|
||||
$this->sys_error_db("Error update order sample receive", $this->db);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
$result = array(
|
||||
"total" => 1,
|
||||
"records" => ""
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
} catch (Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user