db_onedev = $this->load->database("onedev", true); } public function search() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $branch = $prm["branch"]; // $branch = 4; $sqlmou = "SELECT M_BranchM_MouID as mouid FROM m_branch WHERE M_BranchID = $branch"; $rstmou = $this->db_onedev->query($sqlmou)->row(); $mouid = $rstmou->mouid; $sql = "SELECT 'N' issave, 0 as id, M_CompanyID, M_MouID, M_BranchID, M_BranchName, CONCAT(M_CompanyName, ' ( ',M_CompanyNumber,')') as companyname, CONCAT(M_MouName, ' ( ',M_MouNumber,')') as mouname, CONCAT('Periode : ', DATE_FORMAT(M_MouStartDate,'%d-%m-%Y'), ' s/d ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as periode, t.T_TestID , t.T_TestName, t.T_TestSasCode, s.T_PriceTotal, t.T_TestID as testparentid, t.T_TestIsParent , fn_get_count_child_test_rujukan(t.T_TestID) as total_child, t.T_TestParentT_TestID FROM ss_price_mou s JOIN t_test t ON t.T_TestID = s.T_TestID AND t.T_TestIsParent = 'Y' AND t.T_TestIsPrice = 'Y' JOIN nat_test n ON n.Nat_TestID = s.Nat_TestID AND n.Nat_TestNat_TestTypeID = 4 JOIN m_mou ON M_MouID = $mouid JOIN m_company ON M_CompanyID = M_MouM_CompanyID JOIN m_branch ON M_BranchID = $branch WHERE Ss_PriceMouM_MouID = $mouid UNION SELECT IF(M_MouRujukanID is null,'N','Y') as issave, IFNULL(M_MouRujukanID,0) as id, M_CompanyID, M_MouID, M_BranchID, M_BranchName, CONCAT(M_CompanyName, ' ( ',M_CompanyNumber,')') as companyname, CONCAT(M_MouName, ' ( ',M_MouNumber,')') as mmouname, CONCAT('Periode : ', DATE_FORMAT(M_MouStartDate,'%d-%m-%Y'), ' s/d ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as periode, b.T_TestID , b.T_TestName, b.T_TestSasCode, IFNULL(M_MouRujukanPrice,T_PriceTotal div total_child) as T_PriceTotal, a.T_TestID as testparentid, b.T_TestIsParent, total_child, b.T_TestParentT_TestID FROM (SELECT t.T_TestID , t.T_TestName, t.T_TestSasCode,s.T_PriceTotal, fn_get_count_child_test_rujukan(t.T_TestID) as total_child FROM ss_price_mou s JOIN t_test t ON t.T_TestID = s.T_TestID AND t.T_TestIsParent = 'Y' AND t.T_TestIsPrice = 'Y' JOIN nat_test n ON n.Nat_TestID = s.Nat_TestID AND n.Nat_TestNat_TestTypeID = 4 WHERE Ss_PriceMouM_MouID = $mouid) a JOIN t_test b ON T_TestParentT_TestID = a.T_TestID AND T_TestIsActive = 'Y' AND T_TestIsPrice = 'N' JOIN m_mou ON M_MouID = $mouid JOIN m_company ON M_CompanyID = M_MouM_CompanyID JOIN m_branch ON M_BranchID = $branch LEFT JOIN m_mou_rujukan ON M_MouRujukanM_BranchID = $branch AND M_MouRujukanM_MouID = $mouid AND M_MouRujukanT_TestID = b.T_TestID AND M_MouRujukanIsActive = 'Y' ORDER BY T_TestSasCode ASC"; $query = $this->db_onedev->query($sql, $sql_param); //echo $this->db_onedev->last_query(); $rows = $query->result_array(); if($rows){ } $result = array("records" => $rows, "sql"=> $this->db_onedev->last_query()); $this->sys_ok($result); exit; } function generateprice(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $branchid = $prm['branchid']; $userid = $this->sys_user["M_UserID"]; foreach($prm['tests'] as $k=>$v){ if(($v['id'] == 0 || $v['id'] == '0') && $v['T_TestIsParent'] == 'N'){ $query = "INSERT INTO m_mou_rujukan ( M_MouRujukanM_BranchID, M_MouRujukanM_MouID, M_MouRujukanT_TestID, M_MouRujukanPrice, M_MouRujukanUserID, M_MouRujukanCreated, M_MouRujukanLastUpdated ) VALUE( ?,?,?,?,?,now(),now() )"; $insert_new_test = $this->db->query($query,array( $branchid, $v['M_MouID'], $v['T_TestID'], $v['T_PriceTotal'], $userid )); } elseif($v['id'] > 0) { $query = "UPDATE m_mou_rujukan SET M_MouRujukanM_MouID = ?, M_MouRujukanT_TestID = ?, M_MouRujukanPrice = ?, M_MouRujukanUserID = ?, M_MouRujukanLastUpdated = now() WHERE M_MouRujukanID = ?"; $update_test = $this->db->query($query,array($v['M_MouID'],$v['T_TestID'],$v['T_PriceTotal'],$userid)); } } $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } function getsexreg(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query =" SELECT * FROM m_branch WHERE M_BranchIsActive = 'Y' "; //echo $query; $rows['branchs'] = $this->db_onedev->query($query)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } }