144 lines
5.3 KiB
PHP
144 lines
5.3 KiB
PHP
<?php
|
|
|
|
|
|
class Perujuk_child extends MY_Controller
|
|
{
|
|
public function index()
|
|
{
|
|
echo "Populate child parameter no rujukan";
|
|
}
|
|
public function xmap($norujukan, $originBranch)
|
|
{
|
|
$sql = "select * from m_branch
|
|
where M_BranchCode=?
|
|
and M_BranchIsActive='Y'";
|
|
$qry = $this->db->query($sql, [$originBranch]);
|
|
|
|
if (!$qry) {
|
|
echo "ERR : " . $this->db->error()["message"] . "|" . $this->db->last_query();
|
|
echo "\n";
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0) {
|
|
echo "$norujukan | from $originBranch not found";
|
|
echo "\n";
|
|
exit;
|
|
}
|
|
$ipAddress = $rows[0]["M_BranchIPAddress"];
|
|
$ipAddress = "demo.aplikasi.web.id";
|
|
$url = "http://$ipAddress/one-api/fix/r_perujuk_child/cek/$norujukan";
|
|
echo $url;
|
|
|
|
$jdata = $this->post($url);
|
|
return json_decode($jdata, true);
|
|
}
|
|
public function post($url)
|
|
{
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
//curl_setopt($ch, CURLOPT_VERBOSE, true);
|
|
$result = curl_exec($ch);
|
|
// echo "RST : $result ";
|
|
return $result;
|
|
}
|
|
public function cek($norujukan, $originBranch)
|
|
{
|
|
$j_map_order = $this->xmap($norujukan, $originBranch);
|
|
$map_order = $j_map_order["data"];
|
|
|
|
$sql = "select * from incoming_ref where incomingRefT_RefDeliveryOrderNumber=?
|
|
and incomingRefOriginM_BranchCode=?";
|
|
$qry = $this->db->query($sql, [$norujukan, $originBranch]);
|
|
if (!$qry) {
|
|
echo "ERR : " . $this->db->error()["message"] . "|" . $this->db->last_query();
|
|
echo "\n";
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0) {
|
|
echo "$norujukan | from $originBranch not found";
|
|
echo "\n";
|
|
exit;
|
|
}
|
|
|
|
$sql = "select incoming_ref_detail.*, T_TestSasCode
|
|
from incoming_ref_detail
|
|
join t_test on incomingRefDetailT_TestID = T_TestID
|
|
where incomingRefDetailincomingRefID=?";
|
|
$qry = $this->db->query($sql, [$rows[0]["incomingRefID"]]);
|
|
$rows = $qry->result_array();
|
|
foreach ($rows as $r) {
|
|
$incomingRefID = $r["incomingRefDetailIncomingRefID"];
|
|
$detailID = $r["incomingRefDetailID"];
|
|
$orderID = $r["incomingRefDetailT_OrderHeaderID"];
|
|
$newOrderID = $r["incomingRefDetailNewT_OrderHeaderID"];
|
|
$testID = $r["incomingRefDetailT_TestID"];
|
|
$sasCode = $r["T_TestSasCode"];
|
|
$sql = "select *
|
|
from t_orderdetail
|
|
where
|
|
T_OrderDetailT_OrderHeaderID = ?
|
|
and T_OrderDetailT_TestSasCode like concat(?,'%')
|
|
and T_OrderDetailT_TestSasCode <> ?";
|
|
$qry = $this->db->query($sql, [$newOrderID, $sasCode, $sasCode]);
|
|
if (!$qry) {
|
|
echo "ERR : " . $this->db->error()["message"] . "|" . $this->db->last_query();
|
|
echo "\n";
|
|
exit;
|
|
}
|
|
$d_rows = $qry->result_array();
|
|
$labNumber = $r["incomingRefDetailT_OrderHeaderLabNumber"];
|
|
echo "Insert untuk $labNumber :\n";
|
|
$arr = array();
|
|
|
|
foreach ($d_rows as $r) {
|
|
$testID = $r["T_OrderDetailT_TestID"];
|
|
$testName = $r["T_OrderDetailT_TestName"];
|
|
$orderDetailID = 0;
|
|
$idx_map = $orderID ."-" . $testID;
|
|
if ($map_order[$idx_map]) {
|
|
$orderDetailID = $map_order[$idx_map];
|
|
}
|
|
$arr[] = array(
|
|
"incomingRefChildIncomingRefID" => $incomingRefID,
|
|
"incomingRefChildT_OrderHeaderID" => $orderID,
|
|
"incomingRefChildNewT_OrderHeaderID" => $newOrderID,
|
|
"incomingRefChildT_TestID" => $testID,
|
|
"incomingRefChildT_TestName" => $testName,
|
|
"incomingRefChildT_OrderDetailID" => $orderDetailID
|
|
);
|
|
$insert_sql = "insert into incoming_ref_child(
|
|
incomingRefChildIncomingRefID,
|
|
incomingRefChildT_OrderHeaderID,
|
|
incomingRefChildNewT_OrderHeaderID,
|
|
incomingRefChildT_TestID,
|
|
incomingRefChildT_TestName,
|
|
incomingRefChildT_OrderDetailID
|
|
)
|
|
values($incomingRefID,
|
|
$orderID,
|
|
$newOrderID,
|
|
$testID,
|
|
$testName,
|
|
$orderDetailID);";
|
|
echo $insert_sql . "\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
incomingRefChildID int(11) NO PRI NULL auto_increment
|
|
incomingRefChildIncomingRefID int(11) YES MUL NULL
|
|
incomingRefChildT_OrderHeaderID int(11) YES MUL NULL
|
|
incomingRefChildNewT_OrderHeaderID int(11) YES MUL NULL
|
|
incomingRefChildT_TestID int(11) YES MUL NULL
|
|
incomingRefChildT_TestName varchar(100) YES NULL
|
|
incomingRefChildT_OrderPromiseDateTime datetime YES NULL
|
|
incomingRefChildT_OrderDetailID int(11) YES NULL
|
|
incomingRefChildCreated datetime YES current_timestamp()
|
|
incomingRefChildLastUpdated
|
|
*/
|