diff --git a/application/controllers/klinik/Registrationv3.php b/application/controllers/klinik/Registrationv3.php index 77b3e5c9..f2a6ab20 100644 --- a/application/controllers/klinik/Registrationv3.php +++ b/application/controllers/klinik/Registrationv3.php @@ -1373,4 +1373,120 @@ class Registrationv3 extends MY_Controller $this->sys_ok(array("records" => $rows)); exit; } + + function search_test() + { + if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } + + $prm = $this->sys_input; + $mouid = intval($prm['mouid'] ?? 0); + + if (!$mouid) { + $this->sys_ok(['total' => 0, 'records' => [], 'total_display' => 0]); + exit; + } + $search = "%{$this->db_onedev->escape_like_str(trim($prm['search'] ?? ''))}%"; + + $sql = "SELECT * FROM ( + SELECT Ss_PriceMouID as ss_price_mou_id, + Ss_PriceMouM_MouID as mouid, + 0 as xid, + Nat_TestID as nat_testid, + nat_test, + is_packet, + packet_id, + px_type as type, + ss_price_mou.T_TestID as pxid, + test.T_TestCode as pxcode, + test.T_TestSasCode as pxsascode, + test.T_TestName as test_name, + CONCAT(test.T_TestSasCode,' ',test.T_TestName) as pxname, + test.T_TestIsResult as isresult, + JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceAmount')) as bruto, + JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceDisc')) as discountpersen, + JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceDiscRp')) as discountrp, + if(JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceDisc')) <> 0, + (((JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceDisc')) / 100) * JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceAmount'))) + JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceDiscRp'))), + JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceDiscRp'))) as discount, + ( JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceAmount')) - ((JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceDisc')) / 100) * JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceAmount'))) - JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceDiscRp')) ) as total, + 'Y' as status, 'N' as active, 'N' as cito, 'N' as cito_before, '' as promise, '' as charge, + child_test + FROM ss_price_mou + JOIN t_test test ON ss_price_mou.T_TestID = test.T_TestID + WHERE CONCAT(test.T_TestSasCode,' ',test.T_TestName) LIKE '{$search}' + AND Ss_PriceMouM_MouID = {$mouid} AND is_packet <> 'Y' AND T_PriceIsCito <> 'Y' + UNION + SELECT Ss_PriceMouID as ss_price_mou_id, + Ss_PriceMouM_MouID as mouid, + 0 as xid, + Nat_TestID as nat_testid, + nat_test, + is_packet, + packet_id, + px_type as type, + test.T_PacketID as pxid, + test.T_PacketSasCode as pxcode, + test.T_PacketSasCode as pxsascode, + test.T_PacketName as test_name, + CONCAT(test.T_PacketSasCode,' ',test.T_PacketName) as pxname, + 'N' as isresult, + IF(px_type <> 'PN',JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceAmount')),T_PriceAmount) as bruto, + IF(px_type <> 'PN',JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceDisc')),T_PriceDisc) as discountpersen, + IF(px_type <> 'PN',JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceDiscRp')),T_PriceDiscRp) as discountrp, + if(IF(px_type <> 'PN',JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceDisc')),T_PriceDisc) <> 0, + (((IF(px_type <> 'PN',JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceDisc')),T_PriceDisc) / 100) * IF(px_type <> 'PN',JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceAmount')),T_PriceAmount)) + IF(px_type <> 'PN',JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceDiscRp')),T_PriceDiscRp)), + IF(px_type <> 'PN',JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceDiscRp')),T_PriceDiscRp)) as discount, + IF(px_type <> 'PN',( JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceAmount')) - ((JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceDisc')) / 100) * JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceAmount'))) - JSON_UNQUOTE(JSON_EXTRACT(one_json_sum(Ss_PriceMouID),'$.T_PriceDiscRp')) ),T_PriceTotal) as total, + 'Y' as status, 'N' as active, 'N' as cito, 'N' as cito_before, '' as promise, '' as charge, + child_test + FROM ss_price_mou + JOIN t_packet test ON test.T_PacketID = T_TestID + WHERE CONCAT(test.T_PacketSasCode,' ',test.T_PacketName) LIKE '{$search}' + AND Ss_PriceMouM_MouID = {$mouid} AND is_packet = 'Y' AND T_PriceIsCito <> 'Y' + ) x LIMIT 50"; + + $query = $this->db_onedev->query($sql); + if (!$query) { $this->sys_error_db("search_test", $this->db_onedev); exit; } + + $rows = $query->result_array(); + foreach ($rows as $k => $v) { + $rows[$k]['status'] = ($v['status'] !== 'N'); + $rows[$k]['cito'] = ($v['cito'] !== 'N'); + $rows[$k]['charge'] = ['value' => 0, 'label' => '0%']; + + if ($v['type'] === 'PXR') { + $nat_test_now = []; + $row_nattest = $this->db_onedev->query( + "SELECT T_TestNat_TestID FROM t_test + WHERE T_TestSasCode LIKE ? AND T_TestID <> ? AND T_TestIsActive = 'Y'", + [$v['pxsascode'] . '%', $v['pxid']] + )->result_array(); + foreach ($row_nattest as $vnat) { + $nat_test_now[] = $vnat['T_TestNat_TestID']; + } + $rows[$k]['nat_test'] = $nat_test_now; + + $child_test = json_decode($v['child_test']); + foreach ($child_test as $kchild => $vchild) { + $child_test[$kchild]->nat_test = json_decode($vchild->nat_test); + $row_test = $this->db_onedev->query( + "SELECT T_TestIsResult, T_TestCode, T_TestSasCode FROM t_test WHERE T_TestID = ? LIMIT 1", + [$vchild->T_TestID] + )->row_array(); + if ($row_test) { + $child_test[$kchild]->isresult = $row_test['T_TestIsResult']; + $child_test[$kchild]->pxcode = $row_test['T_TestCode']; + $child_test[$kchild]->pxsascode = $row_test['T_TestSasCode']; + } + } + $rows[$k]['child_test'] = $child_test; + } else { + $rows[$k]['nat_test'] = json_decode($v['nat_test']); + $rows[$k]['child_test'] = json_decode($v['child_test']); + } + } + + $this->sys_ok(['total' => count($rows), 'records' => $rows, 'total_display' => count($rows)]); + exit; + } }