db_smartone = $this->load->database("onedev", true); } public function search_company() { $prm = $this->sys_input; $max_rst = 12; // QUERY TOTAL $sql = "select count(*) total from m_company where M_CompanyIsActive = 'Y' and M_CompanyIsLabTo = 'Y' order by M_CompanyName ASC"; $query = $this->db_smartone->query($sql); if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("price company count", $this->db_smartone); exit; } $sql = "select M_CompanyID, M_CompanyName from m_company where M_CompanyIsActive = 'Y' and M_CompanyIsLabTo = 'Y' order by M_CompanyName ASC limit 0, {$max_rst}"; $query = $this->db_smartone->query($sql, [$company, $search]); if ($query) { $rows = $query->result_array(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); $this->sys_ok($result); } else { $this->sys_error_db("price company rows", $this->db_smartone); exit; } } public function search_mou() { $prm = $this->sys_input; $max_rst = 12; $search = '%' . $prm["search"] . '%'; $company = $prm["company_id"]; // QUERY TOTAL $sql = "select count(*) total from m_mou where M_MouIsActive = 'Y' and M_MouM_CompanyID = ? and M_MouName LIKE ? order by M_MouName ASC"; $query = $this->db_smartone->query($sql, [$company, $search]); if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("price mou count", $this->db_smartone); exit; } $sql = "select M_MouID, M_MouName, M_MouStartDate, M_MouEndDate from m_mou where M_MouIsActive = 'Y' and M_MouM_CompanyID = ? and M_MouName LIKE ? order by M_MouName ASC limit 0, {$max_rst}"; $query = $this->db_smartone->query($sql, [$company, $search]); if ($query) { $rows = $query->result_array(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); $this->sys_ok($result); } else { $this->sys_error_db("price mou rows", $this->db_smartone); exit; } } public function search_price() { $prm = $this->sys_input; $max_rst = 12; $search = '%' . $prm["search"] . '%'; $mou = $prm["mou_id"]; // QUERY TOTAL $sql = "select count(*) total from t_priceref join t_test on t_pricereft_testid = t_testid where T_PriceRefIsActive = 'Y' and T_PriceRefM_MouID = ? and T_TestName LIKE ? order by T_TestName ASC"; $query = $this->db_smartone->query($sql, [$mou, $search]); if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("price mou count", $this->db_smartone); exit; } $sql = "select T_PriceRefID, T_TestID, T_TestCode, T_TestName, T_PriceRefM_CompanyID, T_PriceRefM_MouID, T_PriceRefAmount, T_PriceRefStartDate, T_PriceRefEndDate, JSON_OBJECT('T_TestID', T_TestID, 'T_TestCode', T_TestCode, 'T_TestName', T_TestName) px from t_priceref join t_test on t_pricereft_testid = t_testid where T_PriceRefIsActive = 'Y' and T_PriceRefM_MouID = ? and T_TestName LIKE ? order by T_TestName ASC limit 0, {$max_rst}"; $query = $this->db_smartone->query($sql, [$mou, $search]); if ($query) { $rows = $query->result_array(); foreach($rows as $k => $v) $rows[$k]['px'] = json_decode($v['px']); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "q" => $this->db_smartone->last_query()); $this->sys_ok($result); } else { $this->sys_error_db("price mou rows", $this->db_smartone); exit; } } public function save_px() { $prm = $this->sys_input; $max_rst = 50; $data = $prm["data"]; // QUERY $query = $this->db_smartone->query("CALL sp_master_price_ref_save('{$data}', '0')"); if ($query) { $result = $query->row(); $this->sys_ok($result); exit; } else { $this->sys_error_db("price ref new", $this->db_smartone); exit; } } public function del_price() { $prm = $this->sys_input; $id = $prm["id"]; $sql = "update t_priceref set t_pricerefisactive = 'N' where T_PriceRefIsActive = 'Y' and T_PriceRefID = ?"; $query = $this->db_smartone->query($sql, [$id]); if ($query) { $result = array("query"=>$this->db_smartone->last_query(), "id"=>$id); $this->sys_ok($result); } else { $this->sys_error_db("price ref rows", $this->db_smartone); exit; } } } ?>