Initial import
This commit is contained in:
134
application/controllers/tools/Inject_lab.php
Normal file
134
application/controllers/tools/Inject_lab.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
class Inject_lab extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// $this->db_antrione = $this->load->database("antrione", true);
|
||||
}
|
||||
|
||||
function loop_regno(){
|
||||
$sql = "SELECT *
|
||||
FROM x_t_orderheader
|
||||
WHERE
|
||||
T_OrderheaderID > 6771";
|
||||
$qry = $this->db->query($sql);
|
||||
//echo $sql;
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Error get get header | " . $this->db->error()["message"]
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$datas = $qry->result_array();
|
||||
foreach ($datas as $key => $value) {
|
||||
$this->update($value['T_OrderHeaderOldLabNumber']);
|
||||
}
|
||||
}
|
||||
|
||||
function update($regno)
|
||||
{
|
||||
if (isset($regno)) {
|
||||
$sql = "SELECT DISTINCT T_OrderHeaderID
|
||||
FROM x_t_orderheader
|
||||
WHERE T_OrderHeaderOldLabNumber = ?
|
||||
";
|
||||
$qry = $this->db->query($sql, [$regno]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Error get x_t_orderheader | " . $this->db->error()["message"]
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rows = $qry->result_array();
|
||||
if(count($rows) != 0 ){
|
||||
$t_orderheaderid = $rows[0]['T_OrderHeaderID'];
|
||||
|
||||
$sql = "SELECT T_OrderDetailT_TestID, name
|
||||
FROM x_t_orderdetail
|
||||
JOIN x_map_lab ON test_id = T_OrderDetailT_TestID
|
||||
WHERE T_OrderDetailT_OrderHeaderID = ?
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
";
|
||||
$qry = $this->db->query($sql, [$t_orderheaderid]);
|
||||
if (!$qry) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Error get x_t_orderdetail | " . $this->db->error()["message"]
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$row_details = $qry->result_array();
|
||||
|
||||
|
||||
if(count($row_details) != 0 ){
|
||||
$arr_map =[];
|
||||
foreach ($row_details as $row_detail) {
|
||||
$testid = $row_detail['T_OrderDetailT_TestID'];
|
||||
$x_name = $row_detail['name'];
|
||||
$arr_map[$x_name] = $testid;
|
||||
}
|
||||
}
|
||||
|
||||
$sql="SELECT * FROM x_adm_rekap_fisik_lab WHERE REG_NO = ? ";
|
||||
$query = $this->db->query($sql, [$regno]);
|
||||
if (!$query) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Error get x_t_orderdetail | " . $this->db->error()["message"]
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
|
||||
if(count($rows) == 0 ){
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Tidak Ada REG_NO yang ditemukan"
|
||||
]);
|
||||
exit;
|
||||
}else{
|
||||
foreach($rows as $r){
|
||||
foreach($r as $key=> $value){
|
||||
$test_id = $arr_map[$key];
|
||||
|
||||
$sql = "UPDATE x_t_orderdetail
|
||||
SET t_orderdetailresult = ?
|
||||
WHERE T_OrderDetailT_OrderHeaderID = ?
|
||||
AND T_OrderDetailT_TestID = ?
|
||||
AND T_OrderDetailIsActive = 'Y'
|
||||
";
|
||||
|
||||
$query = $this->db->query($sql, [$value, $t_orderheaderid, $test_id]);
|
||||
|
||||
if (!$query) {
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Error update x_t_orderdetail | " . $this->db->error()["message"]
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
echo json_encode([
|
||||
"status" => "Success",
|
||||
"message" => "Success Update orderdetailresult"
|
||||
]);
|
||||
}
|
||||
}else{
|
||||
echo json_encode([
|
||||
"status" => "ERR",
|
||||
"message" => "Tidak Ada data"
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user