db = $this->load->database("onedev", true); } function index() { echo "Api: Training Playground"; } function get_note() { try { $sql = "SELECT Other_MBVNoteName as name, Other_MBVNoteDescription as description FROM other_mbvnote"; $qry = $this->db->query($sql, []); if (!$qry) { $error = array( "message" => $this->db->error()["message"], ); $this->sys_error_db($error); exit; } $raw = $qry->result_array(); $result = array("records" => $raw); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function get_doctors() { $prm = $this->sys_input; // $id = $prm["id"]; $sql = " SELECT M_DoctorID as id, CONCAT(M_DoctorPrefix,M_DoctorPrefix2,M_DoctorName,M_DoctorSufix,M_DoctorSufix2,M_DoctorSufix3) as name FROM m_doctorso JOIN m_doctor ON M_DoctorSOM_DoctorID = M_DoctorID AND M_DoctorIsActive = 'Y' WHERE M_DoctorSONat_SubGroupID = 7 AND M_DoctorSOIsActive = 'Y' ORDER BY M_DoctorName ASC"; //echo $sql; $query = $this->db->query($sql); if ($query) { $rows = $query->result_array(); $this->sys_ok(["records" => $rows]); } else { $this->sys_error_db("Rerun rows", $this->db); exit; } } function get_result_mbv() { try { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $id = 0; if (isset($prm['id'])) { $id = $prm['id']; } $sql = "SELECT Other_MBVT_OrderDetailID as detail_id, Other_MBVID as id, Other_MBVSkorNugent as skor_nugent, Other_MBVBahan as bahan, Other_MBVM_DoctorID as doctor_id, Other_MBVDetailsSumLp as sum_lp, Other_MBVDetailsSkor as skor FROM t_orderheader JOIN t_orderdetail ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_OrderDetailIsActive = 'Y' JOIN other_mbv ON T_OrderDetailID = Other_MBVT_OrderDetailID AND Other_MBVIsActive = 'Y' JOIN other_mbvdetails ON Other_MBVID = Other_MBVDetailsOther_MBVID AND Other_MBVDetailsIsActive = 'Y' WHERE T_OrderHeaderID = ? AND T_OrderHeaderIsActive = 'Y'"; $qry = $this->db->query($sql, [$id]); if (!$qry) { $error = array( "message" => $this->db->error()["message"], "etc" => $this->db ); $this->sys_error_db($error); exit; } $result = $qry->result_array(); $this->sys_ok(array("records" => $result)); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function saveresult_mbv() { try { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; // print_r(json_encode($prm['detail'])); // exit; $doctor = 0; if (isset($prm['doctor'])) { $doctor = $prm['doctor']; } $bahan = 0; if (isset($prm['bahan'])) { $bahan = $prm['bahan']; } $data = 0; if (isset($prm['detail'])) { $data = $prm['detail']; } // print_r(json_encode($data)); // exit; $skor_nugent = 0; if (isset($prm['skor_nugent'])) { $skor_nugent = $prm['skor_nugent']; } // print_r(json_encode(array("dktr" => $doctor, "dt" => $data, "bhn" => $bahan, "skr" => $skor_nugent,))); // exit; if ($data == 0 || $doctor == 0) { $this->sys_error("result, doctor & bahan are mandatory"); // print_r(json_encode(array("dktr" => $doctor == 0, "dt" => $data == 0, "bhn" => $bahan == 0, "skr" => $skor_nugent == 0,))); exit; } $this->db->trans_begin(); for ($i = 0; $i < count($data); $i++) { if ($data[$i]["xid"] == "0" && $data[$i]["orderdetail_id"] != "0") { //insert other_fna $sql = "INSERT INTO other_mbv (Other_MBVT_OrderDetailID, Other_MBVSkorNugent, Other_MBVBahan, Other_MBVM_DoctorID, Other_MBVUserID, Other_MBVCreated) VALUES(?,?,?,?,?, NOW())"; $qry = $this->db->query($sql, [ $data[$i]["orderdetail_id"], $skor_nugent, $bahan, $doctor["id"], 3 ]); if (!$qry) { $error = array( "message" => $this->db->error()["message"], "etc" => $this->db ); $this->sys_error_db($error); $this->db->trans_rollback(); exit; } $inserted_id = $this->db->insert_id(); $sql = "INSERT INTO other_mbvdetails( Other_MBVDetailsOther_MBVID, Other_MBVDetailsSumLp, Other_MBVDetailsSkor, Other_MBVDetailsUserID, Other_MBVDetailsCreated) VALUES(?,?,?,?, NOW())"; $qry = $this->db->query($sql, [ $inserted_id, $data[$i]["sum_lp"], $data[$i]["skor"], 3 ]); if (!$qry) { $error = array( "message" => $this->db->error()["message"], "etc" => $this->db ); $this->sys_error_db($error); $this->db->trans_rollback(); exit; } } else { $sql = "UPDATE other_mbv SET Other_MBVSkorNugent =? , Other_MBVBahan = ?, Other_MBVM_DoctorID = ? WHERE Other_MBVID = ? AND Other_MBVIsActive = 'Y'"; $qry = $this->db->query($sql, [ $skor_nugent, $bahan, intval($doctor["id"]), intval($data[$i]["xid"]), ]); if (!$qry) { $error = array( "message" => $this->db->error()["message"], "etc" => $this->db ); $this->sys_error_db($error); $this->db->trans_rollback(); exit; } $sql = "UPDATE other_mbvdetails SET Other_MBVDetailsSumLp = ?, Other_MBVDetailsSkor = ? WHERE Other_MBVDetailsOther_MBVID = ? AND Other_MBVDetailsIsActive = 'Y'"; $qry = $this->db->query($sql, [ $data[$i]["sum_lp"], $data[$i]["skor"], intval($data[$i]["xid"]), ]); if (!$qry) { $error = array( "message" => $this->db->error()["message"], "etc" => $this->db ); $this->sys_error_db($error); $this->db->trans_rollback(); exit; } } } $this->db->trans_commit(); $this->sys_ok("success"); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } }