Files
BE_CPONE/application/controllers/v1/su/Portserver.php
2026-04-27 10:26:26 +07:00

147 lines
4.8 KiB
PHP

<?php
class Portserver extends MY_Controller
{
public function __construct() {
parent::__construct();
$this->db_one = $this->load->database("onedev", true);
}
function raw() {
$param = $this->sys_input;
try {
$instrumentID = $param["instrumentID"];
$data = $param["data"];
$sql = "insert into itf_raw(itf_RawNat_InstrumentID,itf_RawData)
values(?,?)";
$this->db_one->query($sql, array($instrumentID, base64_decode($data)));
echo json_encode(
array("status" => "OK" , "id" => $this->db_one->insert_id() , "message" => "")
);
} catch(exception $e) {
echo json_encode(
array("status" => "ERR" , "id" => 0, "message" => $e.message() )
);
}
}
function result() {
$param = $this->sys_input;
try {
$instrumentID = $param["instrumentID"];
$rawID = $param["rawID"];
$result= $param["result"];
$noreg = $result["nolab"];
$sql = "insert into itf_result(itf_ResultNat_InstrumentID, itf_ResultItf_RawID,
Itf_ResultNoreg, Itf_ResultInstrumentDate, itf_ResultKode, itf_ResultResult, itf_ResultFlag)
values(?,?,?,?,?,?,?)";
foreach($result["result"] as $r) {
$tgl = $r["date"];
$px = $r["px"];
$result = $r["result"];
$this->db_one->query($sql,
array($instrumentID, $rawID, $noreg, $tgl , $px,
$result,$r["flag"]));
}
if ($instrumentID == 1) {
$sql = "call sp_itf_result_alinity(?)";
} else {
$sql = "call sp_itf_result(?)";
}
$this->db->query($sql, array($rawID));
// auto calc
$s_noreg = substr($noreg,0,10);
$sql = "select T_OrderHeaderID from t_orderheader where T_OrderHeaderLabNumber = ? ";
$qry = $this->db->query($sql,array($s_noreg));
$order_id = 0;
if ($qry) {
$rows = $qry->result_array();
if (count($rows) > 0 ) {
$order_id = $rows[0]["T_OrderHeaderID"];
$this->load->library("Resultcalc");
$this->resultcalc->auto($order_id);
//file_put_contents("/xtmp/re-query.sql",$order_id);
}
}
echo json_encode(
array("status" => "OK" , "message" => "")
);
} catch(exception $e) {
echo json_encode(
array("status" => "ERR" , "message" => $e->message() )
);
}
}
function order() {
$param = $this->sys_input;
$sampleID = $param["sampleID"];
$instrumentID = $param["instrumentID"];
$sql = "call sp_itf_order(?,?)";
try {
$qry = $this->db->query($sql, array($instrumentID,$sampleID));
if (isset($qry->result_id->num_rows)) {
$rows = $qry->result_array();
echo json_encode(
array("status" => "OK" , "order" => $rows)
);
} else {
echo json_encode(
array("status" => "OK" , "order" => array())
);
}
} catch(exception $e) {
echo json_encode(
array("status" => "ERR" , "message" => $e->message() )
);
}
}
function update_order() {
$param = $this->sys_input;
$sampleID = $param["sampleID"];
$instrumentID = $param["instrumentID"];
$status = $param["status"];
$sql = "call sp_itf_order_update(?,?,?)";
try {
$qry = $this->db->query($sql, array($instrumentID,$sampleID,$status));
if ($qry) {
echo json_encode(
array("status" => "OK" , "message" => "")
);
} else {
$msg = print_r($this->db->error(),true);
echo json_encode(
array("status" => "OK" , "message" => $msg )
);
}
} catch(exception $e) {
echo json_encode(
array("status" => "ERR" , "message" => $e->message() )
);
}
}
function reset_order() {
$param = $this->sys_input;
$sampleID = $param["sampleID"];
$instrumentID = $param["instrumentID"];
$status = $param["status"];
$sql = "call sp_itf_order_reset(?,?,?)";
try {
$qry = $this->db->query($sql, array($instrumentID,$sampleID,$status));
if ($qry) {
echo json_encode(
array("status" => "OK" , "message" => "")
);
} else {
$msg = print_r($this->db->error(),true);
echo json_encode(
array("status" => "OK" , "message" => $msg )
);
}
} catch(exception $e) {
echo json_encode(
array("status" => "ERR" , "message" => $e->message() )
);
}
}
}
?>