227 lines
6.1 KiB
PHP
227 lines
6.1 KiB
PHP
<?php
|
||
|
||
class Injectprice extends MY_Controller
|
||
{
|
||
var $db_regional;
|
||
var $load;
|
||
var $db;
|
||
public function __construct()
|
||
{
|
||
parent::__construct();
|
||
$this->db_regional = $this->load->database("regional", true);
|
||
}
|
||
|
||
public function index()
|
||
{
|
||
echo "Inject Patient";
|
||
}
|
||
public function getTest()
|
||
{
|
||
if (!$this->isLogin) {
|
||
$this->sys_error("Invalid Token");
|
||
exit;
|
||
}
|
||
$prm = $this->sys_input;
|
||
$sql = "SELECT T_TestSasCode as TEST_CODE, T_TestName as TEST_NAME, '' as HARGA, 0 as DISKON_PERSEN, 0 as DISKON_RUPIAH, 0 as TOTAL
|
||
FROM t_test
|
||
JOIN nat_test ON T_TestNat_TestID = Nat_TestID
|
||
JOIN nat_testtype ON Nat_TestNat_TestTypeID = Nat_TestTypeID
|
||
WHERE
|
||
T_TestIsActive = 'Y' AND
|
||
T_TestIsPrice = 'Y' AND Nat_TestTypeName <> 'Profile'
|
||
ORDER BY T_TestSasCode ASC";
|
||
$query = $this->db->query($sql);
|
||
if (!$query) {
|
||
$this->sys_error_db("Error get company");
|
||
exit;
|
||
}
|
||
$rst = $query->result_array();
|
||
$this->sys_ok($rst);
|
||
}
|
||
public function getCompany()
|
||
{
|
||
if (!$this->isLogin) {
|
||
$this->sys_error("Invalid Token");
|
||
exit;
|
||
}
|
||
$prm = $this->sys_input;
|
||
$search = '';
|
||
if (isset($prm['search'])) {
|
||
$search = $prm['search'];
|
||
}
|
||
$sql = "SELECT * FROM m_company WHERE M_CompanyIsActive = 'Y'
|
||
AND M_CompanyName LIKE '%$search%' LIMIT 50";
|
||
$query = $this->db->query($sql);
|
||
if (!$query) {
|
||
$this->sys_error_db("Error get company");
|
||
exit;
|
||
}
|
||
$rst = $query->result_array();
|
||
$this->sys_ok($rst);
|
||
}
|
||
public function getMou()
|
||
{
|
||
if (!$this->isLogin) {
|
||
$this->sys_error("Invalid Token");
|
||
exit;
|
||
}
|
||
$prm = $this->sys_input;
|
||
$search = '';
|
||
if (isset($prm['search'])) {
|
||
$search = $prm['search'];
|
||
}
|
||
$companyid = $prm['companyid'];
|
||
$sql = "SELECT * FROM m_mou WHERE M_MouIsActive = 'Y' AND M_MouIsVerified = 'N'
|
||
AND M_MouM_CompanyID = $companyid
|
||
AND M_MouName LIKE '%$search%' LIMIT 50";
|
||
$query = $this->db->query($sql);
|
||
if (!$query) {
|
||
$this->sys_error_db("Error get mou");
|
||
exit;
|
||
}
|
||
$rst = $query->result_array();
|
||
$this->sys_ok($rst);
|
||
}
|
||
public function inject()
|
||
{
|
||
if (!$this->isLogin) {
|
||
$this->sys_error("Invalid Token");
|
||
exit;
|
||
}
|
||
|
||
$prm = $this->sys_input;
|
||
|
||
/** ✅ VALIDASI AGREEMENT (MOU) */
|
||
if (
|
||
!isset($prm['mou']) ||
|
||
empty($prm['mou']) ||
|
||
!isset($prm['mou']['M_MouID']) ||
|
||
empty($prm['mou']['M_MouID'])
|
||
) {
|
||
$this->sys_error("Belum pilih Agreement");
|
||
exit;
|
||
}
|
||
|
||
$userid = $this->sys_user["M_UserID"];
|
||
$company = $prm['company'];
|
||
$mou = $prm['mou'];
|
||
$data = $prm['data'];
|
||
|
||
$companyID = $company['M_CompanyID'];
|
||
$mouID = $mou['M_MouID'];
|
||
|
||
$this->db->trans_begin();
|
||
|
||
/** 1️⃣ Nonaktifkan data lama */
|
||
$sqlUpdate = "
|
||
UPDATE t_price
|
||
SET T_PriceIsActive = 'N'
|
||
WHERE T_PriceM_CompanyID = ?
|
||
AND T_PriceM_MouID = ?
|
||
AND T_PriceIsActive = 'Y'
|
||
";
|
||
|
||
$this->db->query($sqlUpdate, [$companyID, $mouID]);
|
||
|
||
/** 2️⃣ Insert data baru */
|
||
foreach ($data as $row) {
|
||
|
||
$sqlTest = "
|
||
SELECT T_TestID
|
||
FROM t_test
|
||
WHERE T_TestSasCode = ?
|
||
";
|
||
$test = $this->db->query($sqlTest, [$row['TEST_CODE']])->row();
|
||
|
||
if (!$test) {
|
||
$this->db->trans_rollback();
|
||
$this->sys_error("Test code tidak ditemukan : ".$row['TEST_CODE']);
|
||
exit;
|
||
}
|
||
if($row['HARGA'] !== ''){
|
||
$sqlInsert = "
|
||
INSERT INTO t_price (
|
||
T_PriceT_TestID,
|
||
T_PriceIsCito,
|
||
T_PriceM_CompanyID,
|
||
T_PriceM_MouID,
|
||
T_PricePriority,
|
||
T_PriceAmount,
|
||
T_PriceDisc,
|
||
T_PriceDiscRp,
|
||
T_PriceSubTotal,
|
||
T_PriceOther,
|
||
T_PriceTotal,
|
||
T_PriceUserID,
|
||
T_PriceIsActive
|
||
) VALUES (
|
||
?,'N',?,?,'0',?,?,?,?,'0',?,?,'Y'
|
||
)
|
||
";
|
||
|
||
$query = $this->db->query($sqlInsert, [
|
||
$test->T_TestID,
|
||
$companyID,
|
||
$mouID,
|
||
$row['HARGA'],
|
||
$row['DISKON_PERSEN'],
|
||
$row['DISKON_RUPIAH'],
|
||
$row['TOTAL'],
|
||
$row['TOTAL'],
|
||
$userid
|
||
]);
|
||
|
||
if (!$query) {
|
||
$this->db->trans_rollback();
|
||
$this->sys_error_db("Error insert price");
|
||
exit;
|
||
}
|
||
|
||
|
||
$sqlInsertCito = "
|
||
INSERT INTO t_price (
|
||
T_PriceT_TestID,
|
||
T_PriceIsCito,
|
||
T_PriceM_CompanyID,
|
||
T_PriceM_MouID,
|
||
T_PricePriority,
|
||
T_PriceAmount,
|
||
T_PriceDisc,
|
||
T_PriceDiscRp,
|
||
T_PriceSubTotal,
|
||
T_PriceOther,
|
||
T_PriceTotal,
|
||
T_PriceUserID,
|
||
T_PriceIsActive
|
||
) VALUES (
|
||
?,'Y',?,?,'0',?,?,?,?,'0',?,?,'Y'
|
||
)
|
||
";
|
||
|
||
$queryCito = $this->db->query($sqlInsertCito, [
|
||
$test->T_TestID,
|
||
$companyID,
|
||
$mouID,
|
||
$row['HARGA'],
|
||
$row['DISKON_PERSEN'],
|
||
$row['DISKON_RUPIAH'],
|
||
$row['TOTAL'],
|
||
$row['TOTAL'],
|
||
$userid
|
||
]);
|
||
|
||
if (!$queryCito) {
|
||
$this->db->trans_rollback();
|
||
$this->sys_error_db("Error insert price");
|
||
exit;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
$this->db->trans_commit();
|
||
$this->sys_ok("Success");
|
||
}
|
||
|
||
}
|