101 lines
4.2 KiB
PHP
101 lines
4.2 KiB
PHP
<?php
|
|
class Insertorderdetailss extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "insert ke order detail ss";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
$this->load->helper(array('form', 'url'));
|
|
}
|
|
function insertdetailss($id)
|
|
{
|
|
try {
|
|
// if (!$this->isLogin) {
|
|
// $this->sys_error("Invalid Token");
|
|
// exit;
|
|
// }
|
|
if (trim($id) == '' || !is_numeric($id)) {
|
|
$this->sys_error("orederheaderid kosong atau bukan angka");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT * FROM t_orderheader
|
|
WHERE T_OrderHeaderM_PatientID = (SELECT T_OrderHeaderM_PatientID FROM t_orderheader WHERE T_OrderHeaderID = ?)
|
|
AND t_orderheaderID <> ?
|
|
AND T_OrderHeaderIsActive = 'Y'
|
|
ORDER BY T_OrderHeaderDate DESC LIMIT 1";
|
|
$bfr = $this->db_onedev->query($sql, [$id, $id]);
|
|
if (!$bfr) {
|
|
$this->sys_error($this->db_onedev->error()["message"]);
|
|
exit;
|
|
}
|
|
$before = $bfr->row_array();
|
|
|
|
$sql = "SELECT * FROM t_orderheader
|
|
JOIN t_orderdetail ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
|
|
WHERE T_OrderHeaderID = ?
|
|
AND T_OrderDetailT_TestIsResult = 'Y'
|
|
AND T_OrderHeaderIsActive = 'Y'";
|
|
$rows = $this->db_onedev->query($sql, [$id])->result_array();
|
|
$arrDetails = array();
|
|
foreach ($rows as $key => $value) {
|
|
$arrDetails[] = $value['T_OrderDetailID'];
|
|
}
|
|
$detail = implode(',', $arrDetails);
|
|
|
|
$sqlCek = "SELECT GROUP_CONCAT(t_orderDetailSsT_OrderDetailID) as cek FROM t_orderdetail_ss
|
|
WHERE t_orderDetailSsT_OrderHeaderID = ?
|
|
AND t_orderDetailSsT_OrderDetailID IN ($detail)";
|
|
$rowCek = $this->db_onedev->query($sqlCek, [$id])->row_array()['cek'];
|
|
$idInOrderDetailss = explode(',', $rowCek);
|
|
$lst_qry = $this->db_onedev->last_query();
|
|
|
|
foreach ($rows as $key => $value) {
|
|
$detailID = $value['T_OrderDetailID'];
|
|
$testID = $value['T_OrderDetailT_TestID'];
|
|
|
|
if (!in_array($detail, $idInOrderDetailss)) {
|
|
$sqlInsert = "INSERT INTO t_orderdetail_ss
|
|
(t_orderDetailSsT_OrderHeaderID,
|
|
t_orderDetailSsT_OrderDetailID,
|
|
t_orderDetailSsT_TestID,
|
|
t_orderDetailSsH1ID,
|
|
t_orderDetailSsH1Result)
|
|
VALUES(?,?,?,0,'-')";
|
|
$qryInsert = $this->db_onedev->query($sqlInsert, [$id, $detailID, $testID]);
|
|
}
|
|
}
|
|
|
|
$sqlUpdate = "UPDATE t_orderdetail_ss
|
|
JOIN t_orderdetail
|
|
ON T_OrderDetailT_OrderHeaderID = ?
|
|
AND T_OrderDetailIsActive = 'Y'
|
|
AND t_orderDetailSsT_OrderHeaderID =?
|
|
AND t_orderDetailSsT_TestID = T_OrderDetailT_TestID
|
|
SET t_orderDetailSsH1ID = T_OrderDetailID,
|
|
t_orderDetailSsH1Result = T_OrderDetailResult,
|
|
t_orderDetailSsH1Date = ?";
|
|
$qryUpdate = $this->db_onedev->query($sqlUpdate, [$before['T_OrderHeaderID'], $id, $before['T_OrderHeaderDate']]);
|
|
$lst_qry2 = $this->db_onedev->last_query();
|
|
|
|
$result = array(
|
|
"records" => $before,
|
|
"detail" => $detail,
|
|
"idInOrderDetailss" => $idInOrderDetailss,
|
|
"lst qry update" => $lst_qry2
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
} catch (Exception $e) {
|
|
$this->sys_error($e);
|
|
exit;
|
|
}
|
|
}
|
|
}
|