diff --git a/application/controllers/mockup/process/resultentry-v23/Re_px.php b/application/controllers/mockup/process/resultentry-v23/Re_px.php index 2552eb8b..258fae44 100644 --- a/application/controllers/mockup/process/resultentry-v23/Re_px.php +++ b/application/controllers/mockup/process/resultentry-v23/Re_px.php @@ -170,8 +170,8 @@ class Re_px extends MY_Controller exit; } } - function fix_sample_serum($headerID) - { + function fix_sample_serum($headerID) + { //cari t_ordersample yg belum worklist receive dengan code 017% $sql = "select T_OrderSampleID from t_ordersample @@ -213,14 +213,118 @@ class Re_px extends MY_Controller //print_r($rcv_rows); $rcv_T_OrderSampleID = $rcv_rows[0]["T_OrderSampleID"]; //ada yg belum di receive - foreach ($rows as $r) { - $T_OrderSampleID = $r["T_OrderSampleID"]; - $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); - } - } - public function search() - { - $prm = $this->sys_input; + foreach ($rows as $r) { + $T_OrderSampleID = $r["T_OrderSampleID"]; + $this->update_order_sample($T_OrderSampleID, $rcv_T_OrderSampleID); + } + } + private function get_order_detail_id_input() + { + $prm = $this->sys_input; + if (isset($prm['order_detail_id'])) return intval($prm['order_detail_id']); + if (isset($prm['T_OrderDetailID'])) return intval($prm['T_OrderDetailID']); + if (isset($prm['id'])) return intval($prm['id']); + return 0; + } + private function call_multi_result_procedure($sql) + { + $dbc = $this->db_smartone->conn_id; + $result_sets = array(); + + if (!mysqli_multi_query($dbc, $sql)) { + return array( + "ok" => false, + "message" => mysqli_error($dbc), + "result_sets" => array() + ); + } + + do { + $result = mysqli_store_result($dbc); + if ($result instanceof mysqli_result) { + $result_sets[] = $result->fetch_all(MYSQLI_ASSOC); + mysqli_free_result($result); + } + } while (mysqli_more_results($dbc) && mysqli_next_result($dbc)); + + if (mysqli_errno($dbc)) { + $message = mysqli_error($dbc); + $this->clean_mysqli_connection($dbc); + return array( + "ok" => false, + "message" => $message, + "result_sets" => $result_sets + ); + } + + $this->clean_mysqli_connection($dbc); + return array( + "ok" => true, + "message" => "", + "result_sets" => $result_sets + ); + } + public function check_normal_setting() + { + $order_detail_id = $this->get_order_detail_id_input(); + if ($order_detail_id <= 0) { + $this->sys_error("order_detail_id wajib diisi"); + return; + } + + $call = $this->call_multi_result_procedure("CALL sp_sampling_check_normal_setting({$order_detail_id})"); + if (!$call["ok"]) { + $this->sys_error($call["message"]); + return; + } + + $result_sets = $call["result_sets"]; + $summary = isset($result_sets[0][0]) ? $result_sets[0][0] : array(); + $checks = isset($result_sets[1]) ? $result_sets[1] : array(); + $branches = isset($result_sets[2]) ? $result_sets[2] : array(); + $candidates = isset($result_sets[3]) ? $result_sets[3] : array(); + + $this->sys_ok(array( + "order_detail_id" => $order_detail_id, + "summary" => $summary, + "checks" => $checks, + "branches" => $branches, + "candidates" => $candidates, + "needs_fix" => ( + isset($summary["FnSamplingGetNormalResult"]) && + intval($summary["FnSamplingGetNormalResult"]) <= 0 + ), + "result_sets" => $result_sets + )); + } + public function fix_normal_setting() + { + $order_detail_id = $this->get_order_detail_id_input(); + if ($order_detail_id <= 0) { + $this->sys_error("order_detail_id wajib diisi"); + return; + } + + $call = $this->call_multi_result_procedure("CALL sp_sampling_fix_normal_by_orderdetail({$order_detail_id})"); + if (!$call["ok"]) { + $this->sys_error($call["message"]); + return; + } + + $result_sets = $call["result_sets"]; + $result = isset($result_sets[0][0]) ? $result_sets[0][0] : array(); + $order_detail = isset($result_sets[1][0]) ? $result_sets[1][0] : array(); + + $this->sys_ok(array( + "order_detail_id" => $order_detail_id, + "result" => $result, + "order_detail" => $order_detail, + "result_sets" => $result_sets + )); + } + public function search() + { + $prm = $this->sys_input; $max_rst = 99; $id = $prm["order_id"];