db_onedev = $this->load->database("onedev", true); } function getkuota(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $idsubcategory = $prm['idsubcategory']; $query = "SELECT COUNT(*) as exist_kuota FROM m_reg_kuota WHERE M_RegKuotaIsActive = 'Y' AND M_RegKuotaT_SubCategoryID = $idsubcategory"; $exist_kuota = $this->db_onedev->query($query)->row()->exist_kuota; if($exist_kuota != 0){ $query =" SELECT IFNULL(M_RegKuotaID,0) as M_RegKuotaID, IFNULL(M_RegKuotaReguler,'') as M_RegKuotaReguler, IFNULL(M_RegKuotaCito,'') as M_RegKuotaCito, IFNULL(M_RegKuotaCito1Day,'') as M_RegKuotaCito1Day, IFNULL(M_RegKuotaCito2Day,'') as M_RegKuotaCito2Day, IFNULL(M_RegKuotaIsWork,'N') as M_RegKuotaIsWork, 'xxx' as regtimes, 'xxx' as regtimesreguler, '' as action FROM m_reg_kuota WHERE M_RegKuotaT_SubCategoryID = $idsubcategory "; //echo $query; $rows = $this->db_onedev->query($query)->result_array(); }else{ $query ="SELECT 0 as M_RegKuotaID, 0 as M_RegKuotaReguler, 0 as M_RegKuotaCito, '' as M_RegKuotaCito1Day, '' as M_RegKuotaCito2Day, 'N' as M_RegKuotaIsWork, 'xxx' as regtimes, 'xxx' as regtimesreguler, '' as action"; $rows = $this->db_onedev->query($query)->result_array(); } if($rows){ foreach($rows as $k => $v){ $rows[$k]['regtimes'] = $this->add_regtime($idsubcategory); $rows[$k]['regtimesreguler'] = $this->add_regtimereguler($idsubcategory); $rows[$k]['action'] = 'delete'; $rows[$k]['action'] .= 'edit'; } }else{ $starDate = new DateTime(date('Y-m-d')); for ($i=0; $i < 15; $i++) { $query = "SELECT COUNT(*) as exist FROM m_reg_kuota_log WHERE M_RegKuotaLogIsActive = 'Y' AND M_RegKuotaLogT_SubCategoryID = $idsubcategory AND M_RegKuotaLogDate = '".date_format($starDate, 'Y-m-d')."'"; $exist_date = $this->db_onedev->query($query)->row()->exist; if($i == 0){ $label = 'Hari Ini'; }else if($i == 1){ $label = 'H+1'; }else if($i == 2){ $label = 'H+2'; }else if($i == 3){ $label = 'H+3'; }else if($i == 4){ $label = 'H+4'; }else if($i == 5){ $label = 'H+5'; }else if($i == 6){ $label = 'H+6'; }else if($i == 7){ $label = 'H+7'; }else if($i == 8){ $label = 'H+8'; }else if($i == 9){ $label = 'H+9'; }else if($i == 10){ $label = 'H+10'; }else if($i == 11){ $label = 'H+11'; }else if($i == 12){ $label = 'H+12'; }else if($i == 13){ $label = 'H+13'; }else if($i == 14){ $label = 'H+14'; } if($exist_date == 0){ $queryinsertlog = "INSERT INTO m_reg_kuota_log (M_RegKuotaLogT_SubCategoryID,M_RegKuotaLogDate,M_RegKuotaLogReguler,M_RegKuotaLogCito,M_RegKuotaLogLabel,M_RegKuotaLogUserID,M_RegKuotaLogCreated,M_RegKuotaLogLastUpdated ) VALUES ($idsubcategory,'".date_format($starDate, 'Y-m-d')."',0,0,'{$label}',3,now(),now());"; $insert_log = $this->db_onedev->query($queryinsertlog); } $starDate = date_add($starDate, date_interval_create_from_date_string('1 days')); } $endDate = date_add($starDate, date_interval_create_from_date_string('14 days')); $rows[$k]['regtimes'] = $this->add_regtime($idsubcategory); } $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function add_regtime($idsubcategory){ $starDate = new DateTime(date('Y-m-d')); for ($i=0; $i < 15; $i++) { $query = "SELECT COUNT(*) as exist FROM m_reg_kuota_log WHERE M_RegKuotaLogIsActive = 'Y' AND M_RegKuotaLogT_SubCategoryID = $idsubcategory AND M_RegKuotaLogDate = '".date_format($starDate, 'Y-m-d')."'"; $exist_date = $this->db_onedev->query($query)->row()->exist; $querycito = "SELECT M_RegKuotaCito as cito FROM m_reg_kuota WHERE M_RegKuotaIsActive = 'Y' AND M_RegKuotaT_SubCategoryID = $idsubcategory"; $cito = $this->db_onedev->query($querycito)->row()->cito; if (is_null($cito)) { $cito = 0; }else { $cito = $this->db_onedev->query($querycito)->row()->cito; } $queryreguler = "SELECT M_RegKuotaReguler as reguler FROM m_reg_kuota WHERE M_RegKuotaIsActive = 'Y' AND M_RegKuotaT_SubCategoryID = $idsubcategory"; $reguler = $this->db_onedev->query($queryreguler)->row()->reguler; if (is_null($reguler)) { $reguler = 0; }else { $reguler = $this->db_onedev->query($queryreguler)->row()->reguler; } $userid = $this->sys_user["M_UserID"]; if($i == 0){ $label = 'Hari Ini'; }else if($i == 1){ $label = 'H+1'; }else if($i == 2){ $label = 'H+2'; }else if($i == 3){ $label = 'H+3'; }else if($i == 4){ $label = 'H+4'; }else if($i == 5){ $label = 'H+5'; }else if($i == 6){ $label = 'H+6'; }else if($i == 7){ $label = 'H+7'; }else if($i == 8){ $label = 'H+8'; }else if($i == 9){ $label = 'H+9'; }else if($i == 10){ $label = 'H+10'; }else if($i == 11){ $label = 'H+11'; }else if($i == 12){ $label = 'H+12'; }else if($i == 13){ $label = 'H+13'; }else if($i == 14){ $label = 'H+14'; }; if($exist_date == 0){ $queryinsertlog = "INSERT INTO m_reg_kuota_log (M_RegKuotaLogT_SubCategoryID,M_RegKuotaLogDate,M_RegKuotaLogReguler,M_RegKuotaLogCito,M_RegKuotaLogLabel,M_RegKuotaLogUserID,M_RegKuotaLogCreated,M_RegKuotaLogLastUpdated ) VALUES ($idsubcategory,'".date_format($starDate, 'Y-m-d')."',$reguler,$cito,'{$label}',3,now(),now());"; $insert_log = $this->db_onedev->query($queryinsertlog); //echo $this->db_onedev->last_query(); }else{ $queryupdate ="UPDATE m_reg_kuota_log SET M_RegKuotaLogLabel = '{$label}', M_RegKuotaLogUserID = '{$userid}', M_RegKuotaLogLastUpdated = now() WHERE M_RegKuotaLogT_SubCategoryID = $idsubcategory AND M_RegKuotaLogDate = '".date_format($starDate, 'Y-m-d')."'"; $update_detail = $this->db_onedev->query($queryupdate); } $starDate = date_add($starDate, date_interval_create_from_date_string('1 days')); } $endDate = date_add($starDate, date_interval_create_from_date_string('14 days')); $query ="SELECT IFNULL(M_RegKuotaLogID,0) as xid, M_RegKuotaLogDate , M_RegKuotaLogCito,M_RegKuotaLogLabel,M_RegKuotaLogT_SubCategoryID FROM m_reg_kuota_log WHERE M_RegKuotaLogIsActive = 'Y' AND M_RegKuotaLogT_SubCategoryID = $idsubcategory AND M_RegKuotaLogDate BETWEEN date(now()) AND date(now()) + INTERVAL 14 DAY GROUP BY M_RegKuotaLogDate"; //echo $query; $rows = $this->db_onedev->query($query)->result_array(); if(!$rows) $rows = array(); return $rows; } function add_regtimereguler($idsubcategory){ $starDate = new DateTime(date('Y-m-d')); for ($i=0; $i < 15; $i++) { $query = "SELECT COUNT(*) as exist FROM m_reg_kuota_log WHERE M_RegKuotaLogIsActive = 'Y' AND M_RegKuotaLogT_SubCategoryID = $idsubcategory AND M_RegKuotaLogDate = '".date_format($starDate, 'Y-m-d')."'"; $exist_date = $this->db_onedev->query($query)->row()->exist; $querycito = "SELECT M_RegKuotaCito as cito FROM m_reg_kuota WHERE M_RegKuotaIsActive = 'Y' AND M_RegKuotaT_SubCategoryID = $idsubcategory"; $cito = $this->db_onedev->query($querycito)->row()->cito; $queryreguler = "SELECT M_RegKuotaReguler as reguler FROM m_reg_kuota WHERE M_RegKuotaIsActive = 'Y' AND M_RegKuotaT_SubCategoryID = $idsubcategory"; $reguler = $this->db_onedev->query($queryreguler)->row()->reguler; $userid = $this->sys_user["M_UserID"]; if($i == 0){ $label = 'Hari Ini'; }else if($i == 1){ $label = 'H+1'; }else if($i == 2){ $label = 'H+2'; }else if($i == 3){ $label = 'H+3'; }else if($i == 4){ $label = 'H+4'; }else if($i == 5){ $label = 'H+5'; }else if($i == 6){ $label = 'H+6'; }else if($i == 7){ $label = 'H+7'; }else if($i == 8){ $label = 'H+8'; }else if($i == 9){ $label = 'H+9'; }else if($i == 10){ $label = 'H+10'; }else if($i == 11){ $label = 'H+11'; }else if($i == 12){ $label = 'H+12'; }else if($i == 13){ $label = 'H+13'; }else if($i == 14){ $label = 'H+14'; } if($exist_date == 0){ $queryinsertlog = "INSERT INTO m_reg_kuota_log (M_RegKuotaLogT_SubCategoryID,M_RegKuotaLogDate,M_RegKuotaLogReguler,M_RegKuotaLogCito,M_RegKuotaLogLabel,M_RegKuotaLogUserID,M_RegKuotaLogCreated,M_RegKuotaLogLastUpdated ) VALUES ($idsubcategory,'".date_format($starDate, 'Y-m-d')."',$reguler,$cito,'{$label}',3,now(),now());"; $insert_log = $this->db_onedev->query($queryinsertlog); }else{ $queryupdate ="UPDATE m_reg_kuota_log SET M_RegKuotaLogLabel = '{$label}', M_RegKuotaLogUserID = '{$userid}', M_RegKuotaLogLastUpdated = now() WHERE M_RegKuotaLogT_SubCategoryID = $idsubcategory AND M_RegKuotaLogDate = '".date_format($starDate, 'Y-m-d')."'"; $update_detail = $this->db_onedev->query($queryupdate); } $starDate = date_add($starDate, date_interval_create_from_date_string('1 days')); } $endDate = date_add($starDate, date_interval_create_from_date_string('14 days')); $query ="SELECT IFNULL(M_RegKuotaLogID,0) as xid, M_RegKuotaLogDate , M_RegKuotaLogReguler,M_RegKuotaLogLabel FROM m_reg_kuota_log WHERE M_RegKuotaLogIsActive = 'Y' AND M_RegKuotaLogT_SubCategoryID = $idsubcategory AND M_RegKuotaLogDate BETWEEN date(now()) AND date(now()) + INTERVAL 14 DAY GROUP BY M_RegKuotaLogDate"; //echo $query; $rows = $this->db_onedev->query($query)->result_array(); if(!$rows) $rows = array(); return $rows; } function getday(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query =" SELECT * FROM m_reg_day WHERE M_RegDayIsActive = 'Y' "; //echo $query; $rows['days'] = $this->db_onedev->query($query)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function getsubcategory(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = []; $query =" SELECT * FROM t_subcategory WHERE T_SubCategoryIsActive = 'Y' AND T_SubCategoryIsKuota = 'Y' "; //echo $query; $rows['subcategorys'] = $this->db_onedev->query($query)->result_array(); $result = array( "total" => count($rows) , "records" => $rows, ); $this->sys_ok($result); exit; } function savenewmethode(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; foreach($prm['orderdays'] as $k=>$v){ $query = "INSERT INTO m_methode_priority ( M_MethodePriorityM_MethodePriorityID, M_MethodePriorityT_TestID, M_MethodePriorityT_TestCode, M_MethodePriorityT_TestName, M_MethodePriorityT_TestPrice, M_MethodePriorityT_TestDisc, M_MethodePriorityT_TestDiscRp, M_MethodePriorityT_TestTotal, M_MethodePriorityUserID, M_MethodePriorityCreated, M_MethodePriorityLastUpdated ) VALUE( ?,?,?,?,?,?,?,?,?, now(),now() )"; $insert_new_test = $this->db_onedev->query($query,array( $orderpatient_id, $v['T_TestID'], $v['T_TestCode'], $v['T_TestName'], $v['T_PriceAmount'], $v['T_PriceDisc'], $v['T_PriceDiscRp'], $v['total'], $userid )); } $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } function saveeditmethode(){ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $M_RegKuotaReguler = $prm['M_RegKuotaReguler']; $M_RegKuotaCito = $prm['M_RegKuotaCito']; $M_RegKuotaCito1Day = $prm['M_RegKuotaCito1Day']; $M_RegKuotaCito2Day = $prm['M_RegKuotaCito2Day']; $M_RegKuotaIsWork = $prm['M_RegKuotaIsWork']; $M_RegKuotaT_SubCategoryID = $prm['M_RegKuotaT_SubCategoryID']; $userid = $this->sys_user["M_UserID"]; $query = "SELECT COUNT(*) as exist_kuota FROM m_reg_kuota WHERE M_RegKuotaIsActive = 'Y' AND M_RegKuotaT_SubCategoryID = $M_RegKuotaT_SubCategoryID"; $exist_kuota = $this->db_onedev->query($query)->row()->exist_kuota; if($exist_kuota != 0){ $queryupdate ="UPDATE m_reg_kuota SET M_RegKuotaT_SubCategoryID = '{$M_RegKuotaT_SubCategoryID}', M_RegKuotaReguler = '{$M_RegKuotaReguler}', M_RegKuotaCito = '{$M_RegKuotaCito}', M_RegKuotaCito1Day = '{$M_RegKuotaCito1Day}', M_RegKuotaCito2Day = '{$M_RegKuotaCito2Day}', M_RegKuotaIsWork = '{$M_RegKuotaIsWork}', M_RegKuotaUserID = '{$userid}', M_RegKuotaLastUpdated = now() WHERE M_RegKuotaID = ?"; $update_header = $this->db_onedev->query($queryupdate,array($prm['xid'])); }else{ $queryupdate ="INSERT m_reg_kuota (M_RegKuotaT_SubCategoryID, M_RegKuotaReguler, M_RegKuotaCito, M_RegKuotaCito1Day, M_RegKuotaCito2Day, M_RegKuotaIsWork, M_RegKuotaUserID, M_RegKuotaCreated) VALUES('{$M_RegKuotaT_SubCategoryID}', '{$M_RegKuotaReguler}', '{$M_RegKuotaCito}', '{$M_RegKuotaCito1Day}', '{$M_RegKuotaCito2Day}', '{$M_RegKuotaIsWork}', '{$userid}', now() )"; $update_header = $this->db_onedev->query($queryupdate); } foreach($prm['orderregtimes'] as $k=>$v){ $tanggal = $v['M_RegKuotaLogDate']; $cito = $v['M_RegKuotaLogCito']; $label = $v['M_RegKuotaLogLabel']; $query = "SELECT COUNT(*) as exist FROM m_reg_kuota_log WHERE M_RegKuotaLogIsActive = 'Y' AND M_RegKuotaLogDate = '{$tanggal}'"; $exist_date = $this->db_onedev->query($query)->row()->exist; if($v['xid'] == 0 && $exist_date == 0 ){ $query = "INSERT INTO m_reg_kuota_log( M_RegKuotaLogT_SubCategoryID, M_RegKuotaLogDate, M_RegKuotaLogCito, M_RegKuotaLogLabel, M_RegKuotaLogUserID, M_RegKuotaLogCreated, M_RegKuotaLogLastUpdated ) VALUES(?,?,?,?,?,now(),now())"; $insert_detail = $this->db_onedev->query($query,array($M_RegKuotaT_SubCategoryID,$tanggal,$cito,$label,$userid)); }else{ $queryupdate ="UPDATE m_reg_kuota_log SET M_RegKuotaLogCito = $cito, M_RegKuotaLogUserID = '{$userid}', M_RegKuotaLogLastUpdated = now() WHERE M_RegKuotaLogID = ?"; $update_detail = $this->db_onedev->query($queryupdate,array($v['xid'])); } } foreach($prm['orderregtimesreguler'] as $k=>$v){ $tanggal = $v['M_RegKuotaLogDate']; $reguler = $v['M_RegKuotaLogReguler']; $label = $v['M_RegKuotaLogLabel']; $query = "SELECT COUNT(*) as exist FROM m_reg_kuota_log WHERE M_RegKuotaLogIsActive = 'Y' AND M_RegKuotaLogDate = '{$tanggal}'"; $exist_date = $this->db_onedev->query($query)->row()->exist; if($v['xid'] == 0 && $exist_date == 0 ){ $query = "INSERT INTO m_reg_kuota_log( M_RegKuotaT_SubCategoryID, M_RegKuotaLogDate, M_RegKuotaLogReguler, M_RegKuotaLogLabel, M_RegKuotaLogUserID, M_RegKuotaLogCreated, M_RegKuotaLogLastUpdated ) VALUES(?,?,?,?,?,now(),now())"; $insert_detail = $this->db_onedev->query($query,array($M_RegKuotaT_SubCategoryID,$tanggal,$reguler,$label,$userid)); }else{ $queryupdate ="UPDATE m_reg_kuota_log SET M_RegKuotaLogReguler = $reguler, M_RegKuotaLogUserID = '{$userid}', M_RegKuotaLogLastUpdated = now() WHERE M_RegKuotaLogID = ?"; $update_detail = $this->db_onedev->query($queryupdate,array($v['xid'])); } } $result = array( "total" => 1 , "records" => array('status'=>'OK') ); $this->sys_ok($result); exit; } function searchtest(){ $prm = $this->sys_input; $max_rst = 12; $tot_count = 0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } $mou_id = $prm['mouid']; // QUERY TOTAL $sql = "SELECT count(*) as total FROM t_test JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}' WHERE T_TestName like ? AND T_TestIsActive = 'Y' ORDER BY T_TestName ASC"; $query = $this->db_onedev->query($sql,$q['search']); //echo $query; if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("test count",$this->db_onedev); exit; } $sql = " SELECT 'Y' as editable, 0 as xid, T_TestID, T_TestCode, T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total, M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP FROM one_lis_dev.t_test JOIN one_lis_dev.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}' JOIN one_lis_dev.m_mou ON M_MouID = '{$mou_id}' JOIN one_lis_dev.m_company ON M_MouM_CompanyID = M_CompanyID WHERE T_TestName like ? AND T_TestIsActive = 'Y' ORDER BY T_TestName ASC "; $query = $this->db_onedev->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); //echo $this->db_onedev->last_query(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("test rows",$this->db_onedev); exit; } } }