126 lines
4.9 KiB
PHP
126 lines
4.9 KiB
PHP
<?php
|
|
class Importtestdesc extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
var $load;
|
|
var $kesimpulanfisik;
|
|
|
|
public function index()
|
|
{
|
|
echo "IMPORT DATA";
|
|
}
|
|
public function getTest()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$sql = "SELECT
|
|
Nat_TestCode code,
|
|
Nat_TestName name,
|
|
IFNULL(Nat_TestDescNote, '') description,
|
|
IFNULL(Nat_TestDescID, 0) idCek
|
|
FROM nat_test
|
|
LEFT JOIN nat_test_desc
|
|
ON Nat_TestID = Nat_TestDescNat_TestID
|
|
WHERE Nat_TestIsPrice = 'Y'
|
|
AND Nat_TestIsActive = 'Y'";
|
|
$qry = $this->db_onedev->query($sql, []);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$last_qry = $this->db_onedev->last_query();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$data = $qry->result_array();
|
|
$result = [
|
|
"records" => $data,
|
|
];
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function saveDesc()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$user = $this->sys_user;
|
|
$branchID = $user['M_BranchID'];
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$data = $prm["data"];
|
|
foreach ($data as $key => $value) {
|
|
$desc = "";
|
|
if (array_key_exists('desc', $value)) {
|
|
$desc = $value['desc'];
|
|
} else {
|
|
$desc = ''; // Nilai default jika diperlukan
|
|
}
|
|
$sql = "SELECT
|
|
Nat_TestID as id,
|
|
Nat_TestCode code,
|
|
Nat_TestName name,
|
|
IFNULL(Nat_TestDescNote, '') description,
|
|
IFNULL(Nat_TestDescID, 0) idCek
|
|
FROM nat_test
|
|
LEFT JOIN nat_test_desc
|
|
ON Nat_TestID = Nat_TestDescNat_TestID
|
|
WHERE Nat_TestCode = ?;";
|
|
$qry = $this->db_onedev->query($sql, [$value['code']]);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$last_qry = $this->db_onedev->last_query();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
$cek = $qry->row_array();
|
|
if (!empty($cek)) {
|
|
if (intval($cek['idCek']) == 0) {
|
|
$sql = "INSERT INTO nat_test_desc(
|
|
Nat_TestDescNat_TestID,
|
|
Nat_TestDescNote,
|
|
Nat_TestDescCreated,
|
|
Nat_TestDescCreatedUserID)
|
|
VALUES(?,?,NOW(),?)";
|
|
$qry = $this->db_onedev->query($sql, [$cek['id'], $desc, $userid]);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$last_qry = $this->db_onedev->last_query();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
if (intval($cek['idCek']) > 0 && $cek['description'] != $desc) {
|
|
$sql = "UPDATE nat_test_desc SET
|
|
Nat_TestDescNote = ?,
|
|
Nat_TestDescLastUpdated = NOW(),
|
|
Nat_TestDescLastUpdatedUserID = ?
|
|
WHERE Nat_TestDescID = ?";
|
|
$qry = $this->db_onedev->query($sql, [$desc, $userid, $cek['idCek']]);
|
|
if (!$qry) {
|
|
$message = $this->db_onedev->error();
|
|
$last_qry = $this->db_onedev->last_query();
|
|
$message['last_qry'] = $last_qry;
|
|
$this->sys_error($message);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$this->sys_ok("ok");
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|