db_one = $this->load->database("onedev", true); } function list_instrument() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $search = "%" . $prm["search"] . "%"; try { $sql = "select * from nat_instrument where Nat_InstrumentIsActive='Y' and Nat_InstrumentName like ? ORDER BY Nat_InstrumentCode ASC"; $qry = $this->db_one->query($sql, array($search)); $rows = $qry->result_array(); $tot_count = count($rows); $result = array("total" => $tot_count, "records" => $rows); $this->sys_ok($result); } catch (Exception $e) { $this->sys_error_db("NatInstrument List", $this->db_one); } } function list_test() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $search = "%" . $prm["search"] . "%"; try { $sql = "select * from nat_test where Nat_TestIsResult = 'Y' and Nat_TestIsActive='Y' and Nat_TestName like ?"; $qry = $this->db_one->query($sql, array($search)); $rows = $qry->result_array(); $tot_count = count($rows); $result = array("total" => $tot_count, "records" => $rows); $this->sys_ok($result); } catch (Exception $e) { $this->sys_error_db("NatTest List", $this->db_one); } } function delete_instrument() { $param = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; try { $sql = "update nat_instrument set Nat_InstrumentIsActive = 'N' ,Nat_InstrumentUserID = ? where Nat_InstrumentID= ?"; $id = $param["Nat_InstrumentID"]; $qry = $this->db_one->query($sql, array($userid, $id)); if ($qry) { $result = array("status" => "OK"); $this->sys_ok($result); } else { $this->sys_error_db("Saving Result", $this->db_one); } } catch (Exception $e) { $this->sys_error_db("Nat_Instrument save", $this->db_one); } } function save_instrument() { $param = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; if ($param["Nat_InstrumentID"] == 0) { //add try { $sql = "insert into nat_instrument( Nat_InstrumentCode, Nat_InstrumentName ,Nat_InstrumentUserID) values (?, ?, ? ) "; $code = $param["Nat_InstrumentCode"]; $name = $param["Nat_InstrumentName"]; $qry = $this->db_one->query($sql, array($code, $name, $userid)); if ($qry) { $result = array("status" => "OK"); $this->sys_ok($result); } else { $this->sys_error_db("Saving Result", $this->db_one); } } catch (Exception $e) { $this->sys_error_db("NatMethode List", $this->db_one); } } else { try { $sql = "update nat_instrument set Nat_InstrumentCode = ? ,Nat_InstrumentName = ? ,Nat_InstrumentUserID = ? where Nat_InstrumentID= ?"; $id = $param["Nat_InstrumentID"]; $code = $param["Nat_InstrumentCode"]; $name = $param["Nat_InstrumentName"]; $qry = $this->db_one->query($sql, array( $code, $name, $userid, $id )); if ($qry) { $result = array("status" => "OK"); $this->sys_ok($result); } else { $this->sys_error_db("Saving Result", $this->db_one); } } catch (Exception $e) { $this->sys_error_db("Nat_Instrument save", $this->db_one); } } } function save() { $param = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $userid = $this->sys_user["M_UserID"]; if ($param["M_InstrumentMethodeID"] == 0) { //add try { $sql = "insert into m_instrumentmethode(M_InstrumentMethodeNat_InstrumentID, M_InstrumentMethodeNat_MethodeID, M_InstrumentMethodeNat_TestID, M_InstrumentMethodeResultFormatSF, M_InstrumentMethodeResultFormatAboveSF, M_InstrumentMethodePriority, M_InstrumentMethodeUserID) values (?, ?, ?, ?, ?, ?, ? ) "; $instrumentID = $param["Nat_InstrumentID"]; $methodeID = $param["Nat_MethodeID"]; $testID = $param["Nat_TestID"]; $resultFormatSF = $param["ResultFormatSF"]; $resultFormatAboveSF = $param["ResultFormatAboveSF"]; $priority = $param["Priority"]; $sql_param = array( $instrumentID, $methodeID, $testID, $resultFormatSF, $resultFormatAboveSF, $priority, $userid ); $qry = $this->db_one->query($sql, $sql_param); if ($qry) { $result = array("status" => "OK"); $this->sys_ok($result); } else { $this->sys_error_db("Saving Result", $this->db_one); } } catch (Exception $e) { $this->sys_error_db("NatMethode List", $this->db_one); } } else { try { $sql = "update m_instrumentmethode set M_InstrumentMethodeNat_InstrumentID = ?, M_InstrumentMethodeNat_MethodeID =?, M_InstrumentMethodeNat_TestID =?, M_InstrumentMethodeResultFormatSF = ?,M_InstrumentMethodeResultFormatAboveSF = ? , M_InstrumentMethodePriority = ? , M_InstrumentMethodeUserID = ? where M_InstrumentMethodeID = ? "; $methodePxID = $param["M_InstrumentMethodeID"]; $instrumentID = $param["Nat_InstrumentID"]; $methodeID = $param["Nat_MethodeID"]; $testID = $param["Nat_TestID"]; $resultFormatSF = $param["ResultFormatSF"]; $resultFormatAboveSF = $param["ResultFormatAboveSF"]; $priority = $param["Priority"]; if ($resultFormatSF == "") $resultFormatSF = "0.00"; if ($resultFormatAboveSF == "") $resultFormatAboveSF = "0"; $sql_param = array( $instrumentID, $methodeID, $testID, $resultFormatSF, $resultFormatAboveSF, $priority, $userid, $methodePxID ); $qry = $this->db_one->query($sql, $sql_param); if ($qry) { $result = array("status" => "OK"); $this->sys_ok($result); } else { $this->sys_error_db("Saving Result", $this->db_one); } } catch (Exception $e) { $this->sys_error_db("NatMethode List", $this->db_one); } } } function list_methode() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $search = "%" . $prm["search"] . "%"; try { $sql = "select * from nat_methode where Nat_MethodeIsActive='Y' and Nat_MethodeName like ?"; $qry = $this->db_one->query($sql, array($search)); $rows = $qry->result_array(); $tot_count = count($rows); $result = array("total" => $tot_count, "records" => $rows); $this->sys_ok($result); } catch (Exception $e) { $this->sys_error_db("NatMethode List", $this->db_one); } } function list_methodepx() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $instrumentID = $prm["Nat_InstrumentID"]; try { $sql = "select * , Nat_TestName, Nat_MethodeName from m_instrumentmethode join nat_test on Nat_TestID = M_InstrumentMethodeNat_TestID join nat_methode on Nat_MethodeID = M_InstrumentMethodeNat_MethodeID where M_InstrumentMethodeIsActive='Y' and M_InstrumentMethodeNat_InstrumentID = ?"; $qry = $this->db_one->query($sql, array($instrumentID)); $rows = $qry->result_array(); $tot_count = count($rows); $result = array("total" => $tot_count, "records" => $rows); $this->sys_ok($result); } catch (Exception $e) { $this->sys_error_db("NatMethode List", $this->db_one); } } function get_test_methode() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $id = $prm["Nat_TestID"]; try { $sql = "select * from nat_test where Nat_TestID = ?"; $qry = $this->db_one->query($sql, array($id)); if ($qry) { $rows = $qry->result_array(); if (count($rows) > 0) $test = $rows[0]; $id = $prm["Nat_MethodeID"]; $sql = "select * from nat_methode where Nat_MethodeID= ?"; $qry = $this->db_one->query($sql, array($id)); if ($qry) { $rows = $qry->result_array(); if (count($rows) > 0) $methode = $rows[0]; $result = array( "status" => "OK", "data" => array("test" => $test, "methode" => $methode) ); $this->sys_ok($result); } else { $result = $this->sys_ok(array("status" => "ERR")); } } else { $result = $this->sys_ok(array("status" => "ERR")); } } catch (Exception $e) { $this->sys_error_db("MethodePx delete", $this->db_one); } } function delete_methodepx() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $id = $prm["id"]; try { $sql = "update m_instrumentmethode set M_InstrumentMethodeIsActive = 'N' where M_InstrumentMethodeID = ? "; $qry = $this->db_one->query($sql, array($id)); if ($qry) { $result = array("records" => ""); $this->sys_ok($result); } else { $this->sys_error_db("MethodePx delete", $this->db_one); } } catch (Exception $e) { $this->sys_error_db("MethodePx delete", $this->db_one); } } }