377 lines
14 KiB
PHP
377 lines
14 KiB
PHP
<?php
|
|
class Update extends MY_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
function index()
|
|
{
|
|
echo "Api: Ini Buat Fungsi Update";
|
|
}
|
|
|
|
function add_update_qc()
|
|
{
|
|
//begin transaction
|
|
$this->db->trans_begin();
|
|
|
|
$param = $this->sys_input;
|
|
|
|
// mandatory
|
|
$id = trim($param['id']);
|
|
$type = strtoupper(trim($param['type']));
|
|
$isskip = trim($param['isskip']);
|
|
$qcid = trim($param['qcid']);
|
|
|
|
// format yyyy-mm-dd
|
|
$sdate_trim = trim($param['sdate']);
|
|
$sdate = date($sdate_trim, strtotime('yyyy-mm-dd'));
|
|
|
|
$qcvalue = trim($param['qcvalue']);
|
|
$note = trim($param['note']);
|
|
|
|
$userid = $this->sys_user['M_UserID'];
|
|
// $userid = 1;
|
|
|
|
|
|
// FITRI : untuk mendapat IP cabang default
|
|
$sql = $this->db->query("SELECT M_BranchIPAddress as branch_ip_address FROM m_branch WHERE M_BranchIsDefault = 'Y'")->row();
|
|
$branch_ip_address = $sql->branch_ip_address;
|
|
|
|
// untuk kondisi type "N"
|
|
if($type == "N")
|
|
{
|
|
// insert m_qc_result
|
|
$sql_insert_m_qc_result = "INSERT INTO m_qc_result(
|
|
M_QcResultM_QcID,
|
|
M_QcResultDate,
|
|
M_QcResultValue,
|
|
M_QcResultIsSkipMeanSd,
|
|
M_QcResultType,
|
|
M_QcResultNote,
|
|
M_QcResultUserID)
|
|
VALUES(?,?,?,?,?,?,?)";
|
|
$qry_insert_m_qc_result = $this->db->query($sql_insert_m_qc_result, array(
|
|
$qcid,
|
|
$sdate,
|
|
$qcvalue,
|
|
$isskip,
|
|
$type,
|
|
$note,
|
|
$userid
|
|
));
|
|
|
|
// echo $this->db->last_query();
|
|
// gagal insert m_qc_result
|
|
if (!$qry_insert_m_qc_result) {
|
|
$this->db->trans_rollback();
|
|
echo json_encode(array(
|
|
"status" => "ERR",
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query()
|
|
));
|
|
exit;
|
|
}
|
|
else{
|
|
$insert_id = $this->db->insert_id();
|
|
|
|
|
|
|
|
$sql_insert_m_qc_result_log = "INSERT INTO m_qc_result_log(
|
|
M_QcResultLogM_QcResultID,
|
|
M_QcResultLogM_QcID,
|
|
M_QcResultLogDate,
|
|
M_QcResultLogValue,
|
|
M_QcResultLogNat_QcRuleID,
|
|
M_QcResultLogIsSkipMeanSd,
|
|
M_QcResultLogType,
|
|
M_QcResultLogNote,
|
|
M_QcResultLogUserID)
|
|
SELECT
|
|
?,
|
|
M_QcResultM_QcID,
|
|
M_QcResultDate,
|
|
M_QcResultValue,
|
|
M_QcResultNat_QcRuleID,
|
|
M_QcResultIsSkipMeanSd,
|
|
M_QcResultType,
|
|
M_QcResultNote,
|
|
?
|
|
FROM m_qc_result
|
|
WHERE M_QcResultID = ?";
|
|
|
|
$qry_insert_m_qc_result_log = $this->db->query($sql_insert_m_qc_result_log,
|
|
array(
|
|
$insert_id,
|
|
$userid,
|
|
$insert_id
|
|
));
|
|
|
|
// gagal insert m_qc_result_log
|
|
if (!$qry_insert_m_qc_result_log) {
|
|
$this->db->trans_rollback();
|
|
echo json_encode(array(
|
|
"status" => "ERR",
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query(),
|
|
"data"=>array(
|
|
"total"=>1,
|
|
"records"=>array(
|
|
"xid"=>$insert_id
|
|
)
|
|
)
|
|
));
|
|
exit;
|
|
}
|
|
else{
|
|
// sukses
|
|
$this->db->trans_commit();
|
|
echo json_encode(array(
|
|
"status" => "OK",
|
|
"data"=>array(
|
|
"total"=>1,
|
|
"records"=>array(
|
|
"xid"=>$insert_id
|
|
)
|
|
)
|
|
));
|
|
|
|
|
|
// FITRI : untuk post ke API process calc
|
|
$url = "http://$branch_ip_address/one-api/qc-v2/process/calc/?qcresultid=".$insert_id;
|
|
$post_rst = $this->post($url);
|
|
//echo "to $url \nresponse : $post_rst\n";
|
|
$post_rst = json_decode($post_rst,true);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
// untuk kondisi type "U"
|
|
if($type == "U"){
|
|
$sql_update_m_qc_result = "UPDATE m_qc_result
|
|
SET M_QcResultValue = ?,
|
|
M_QcResultIsSkipMeanSd = ?,
|
|
M_QcResultType = ?,
|
|
M_QcResultNote = ?,
|
|
M_QcResultUserID = ?
|
|
WHERE M_QcResultID = ?";
|
|
|
|
$qry_update_m_qc_result = $this->db->query($sql_update_m_qc_result, array(
|
|
$qcvalue,
|
|
$isskip,
|
|
$type,
|
|
$note,
|
|
$userid,
|
|
$id
|
|
));
|
|
//echo $this->db->last_query();
|
|
// gagal update m_qc_result
|
|
if (!$qry_update_m_qc_result) {
|
|
$this->db->trans_rollback();
|
|
echo json_encode(array(
|
|
"status" => "ERR",
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query(),
|
|
"data"=>array(
|
|
"total"=>1,
|
|
"records"=>array(
|
|
"xid"=>$id
|
|
)
|
|
)
|
|
));
|
|
exit;
|
|
}
|
|
else
|
|
{
|
|
// insert m_qc_result_log
|
|
$sql_insert_m_qc_result_log = "INSERT INTO m_qc_result_log(
|
|
M_QcResultLogM_QcResultID,
|
|
M_QcResultLogM_QcID,
|
|
M_QcResultLogDate,
|
|
M_QcResultLogValue,
|
|
M_QcResultLogNat_QcRuleID,
|
|
M_QcResultLogIsSkipMeanSd,
|
|
M_QcResultLogType,
|
|
M_QcResultLogNote,
|
|
M_QcResultLogUserID
|
|
)
|
|
SELECT
|
|
?,
|
|
M_QcResultM_QcID,
|
|
M_QcResultDate,
|
|
M_QcResultValue,
|
|
M_QcResultNat_QcRuleID,
|
|
M_QcResultIsSkipMeanSd,
|
|
M_QcResultType,
|
|
M_QcResultNote,
|
|
?
|
|
FROM m_qc_result
|
|
WHERE M_QcResultID = ?";
|
|
|
|
$qry_insert_m_qc_result_log = $this->db->query($sql_insert_m_qc_result_log,
|
|
array(
|
|
$id,
|
|
$userid,
|
|
$id
|
|
));
|
|
|
|
// gagal insert m_qc_result_log
|
|
if (!$qry_insert_m_qc_result_log) {
|
|
$this->db->trans_rollback();
|
|
echo json_encode(array(
|
|
"status" => "ERR",
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query(),
|
|
"data"=>array(
|
|
"total"=>1,
|
|
"records"=>array(
|
|
"xid"=>$id
|
|
)
|
|
)
|
|
));
|
|
exit;
|
|
}
|
|
|
|
// FITRI : untuk post ke API process calc
|
|
$url = "http://$branch_ip_address/one-api/qc-v2/process/calc/?qcresultid=".$id;
|
|
$post_rst = $this->post($url);
|
|
//echo "to $url \nresponse : $post_rst\n";
|
|
$post_rst = json_decode($post_rst,true);
|
|
|
|
|
|
|
|
// sukses
|
|
$this->db->trans_commit();
|
|
echo json_encode(array(
|
|
"status" => "OK",
|
|
"data"=>array(
|
|
"total"=>1,
|
|
"records"=>array(
|
|
"xid"=>$id
|
|
)
|
|
)
|
|
));
|
|
}
|
|
}
|
|
|
|
else{
|
|
// untuk kondisi type "O"
|
|
if($type == "O"){
|
|
$sql_update_m_qc_result = "UPDATE m_qc_result SET
|
|
M_QcResultType = ?,
|
|
M_QcResultNote = ?,
|
|
M_QcResultUserID = ?
|
|
WHERE M_QcResultID = ?";
|
|
|
|
$qry_update_m_qc_result = $this->db->query($sql_update_m_qc_result, array(
|
|
$type,
|
|
$note,
|
|
$userid,
|
|
$id
|
|
));
|
|
|
|
// gagal update m_qc_result
|
|
if (!$qry_update_m_qc_result) {
|
|
$this->db->trans_rollback();
|
|
echo json_encode(array(
|
|
"status" => "ERR",
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query(),
|
|
"data"=>array(
|
|
"total"=>1,
|
|
"records"=>array(
|
|
"xid"=>$id
|
|
)
|
|
)
|
|
));
|
|
exit;
|
|
}
|
|
|
|
else{
|
|
// insert m_qc_result_log
|
|
$sql_insert_m_qc_result_log = "INSERT INTO m_qc_result_log(
|
|
M_QcResultLogM_QcResultID,
|
|
M_QcResultLogM_QcID,
|
|
M_QcResultLogDate,
|
|
M_QcResultLogValue,
|
|
M_QcResultLogNat_QcRuleID,
|
|
M_QcResultLogIsSkipMeanSd,
|
|
M_QcResultLogType,
|
|
M_QcResultLogNote,
|
|
M_QcResultLogUserID
|
|
)
|
|
SELECT
|
|
?,
|
|
M_QcResultM_QcID,
|
|
M_QcResultDate,
|
|
M_QcResultValue,
|
|
M_QcResultNat_QcRuleID,
|
|
M_QcResultIsSkipMeanSd,
|
|
M_QcResultType,
|
|
M_QcResultNote,
|
|
?
|
|
FROM m_qc_result
|
|
WHERE M_QcResultID = ?";
|
|
|
|
$qry_insert_m_qc_result_log = $this->db->query($sql_insert_m_qc_result_log, array(
|
|
$id,
|
|
$userid,
|
|
$id
|
|
));
|
|
|
|
// gagal insert m_qc_result_log
|
|
if (!$qry_insert_m_qc_result_log) {
|
|
$this->db->trans_rollback();
|
|
echo json_encode(array(
|
|
"status" => "ERR",
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $this->db->last_query(),
|
|
"data"=>array(
|
|
"total"=>1,
|
|
"records"=>array(
|
|
"xid"=>$id
|
|
)
|
|
)
|
|
));
|
|
exit;
|
|
}
|
|
|
|
// sukses
|
|
$this->db->trans_commit();
|
|
echo json_encode(array(
|
|
"status" => "OK",
|
|
"data"=>array(
|
|
"total"=>1,
|
|
"records"=>array(
|
|
"xid"=>$id
|
|
)
|
|
)
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function post($url) {
|
|
//$data = $data;
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 12);
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
|
|
|
|
$result = curl_exec($ch);
|
|
//echo "RST : $result ";
|
|
return $result;
|
|
}
|
|
|
|
}
|
|
?>
|