db_onedev = $this->load->database("onedev", true); } function searchheader() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $filter_date = $prm['date']; $search = '%' . $prm['search'] . '%'; $page = $prm["page"]; $ROW_PER_PAGE = 20; $start_offset = 0; // print_r($prm); if (isset($prm["page"])) { if ( is_numeric($prm["page"]) && $prm["page"] > 0 ) { $start_offset = ($page - 1) * $ROW_PER_PAGE; } } $sql = "SELECT count(SampleToBranchID ) as total FROM sample_to_branch WHERE SampleToBranchDate = '{$filter_date}' AND SampleBranchIsActive = 'Y' "; $query = $this->db_onedev->query($sql, []); if (!$query) { $message = $this->db_onedev->error(); $message['qry'] = $this->db_onedev->last_query(); $this->sys_error($message); exit; } $total = $query->row_array()['total']; $sql = "SELECT SampleToBranchID AS headerID, Mgm_McuLabel AS headerName, SampleToBranchM_BranchID AS branch_id, M_BranchName as branch_name, SampleToBranchMgm_McuID AS mgm_mcuid, SampleToBranchNumbering AS headerCode, SampleBranchKurirM_StaffID as kurir_id, kurir.M_StaffName as kurir_name, SampleBranchPetugasM_StaffID as staff_id, staff.M_StaffName as staff_name, SampleToBranchValidation as isvalid, SampleToBranchValidationDate as valid_date, SampleToBranchValidationUserID as valid_user_id, M_UserEmail as valid_email FROM sample_to_branch JOIN m_branch ON SampleToBranchM_BranchID = M_BranchID JOIN m_staff kurir ON SampleBranchKurirM_StaffID = kurir.M_StaffID JOIN m_staff staff ON SampleBranchPetugasM_StaffID = staff.M_StaffID JOIN mgm_mcu ON SampleToBranchMgm_McuID = Mgm_McuID LEFT JOIN m_user ON SampleToBranchValidationUserID = M_UserID WHERE SampleToBranchDate = '{$filter_date}' AND SampleBranchIsActive = 'Y' LIMIT ? OFFSET ? "; $query = $this->db_onedev->query($sql, [$ROW_PER_PAGE, $start_offset]); if (!$query) { $message = $this->db_onedev->error(); $message['qry'] = $this->db_onedev->last_query(); $this->sys_error($message); exit; } $result = [ "total" => ceil($total / $ROW_PER_PAGE), "records" => $query->result_array() ]; $this->sys_ok($result); } function insertpriceheader() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; if (!isset($prm['name'])) { $this->sys_error("Nama harus diisi"); exit; } if (trim($prm['name']) == "") { $this->sys_error("Nama harus diisi"); exit; } if (!isset($prm['sd'])) { $this->sys_error("Tanggal awal harus diisi"); exit; } if (!isset($prm['ed'])) { $this->sys_error("Tanggal akhir harus diisi"); exit; } $name = $prm['name']; $startDate = $prm['sd']; $endDate = $prm['ed']; $nw = strtotime($startDate); $nwe = strtotime($endDate); if ($nw > $nwe) { $this->sys_error("Tanggal akhir tidak boleh lebih besar dari Tanggal awal"); exit; } $sql = "SELECT fn_numbering('PH') as number"; $query = $this->db_onedev->query($sql, []); if (!$query) { $message = $this->db_onedev->error(); $message['qry'] = $this->db_onedev->last_query(); $this->sys_error($message); exit; } $number = $query->row_array()['number']; $sql = "INSERT INTO t_priceheader ( T_PriceHeaderName, T_PriceHeaderStartDate, T_PriceHeaderEndDate, T_PriceHeaderCreated, T_PriceHeaderCraetdUserID, T_PriceHeaderCode) VALUES (?,?,?,NOW(), ?,?)"; $query = $this->db_onedev->query($sql, [$name, $startDate, $endDate, $userid, $number]); if (!$query) { $message = $this->db_onedev->error(); $message['qry'] = $this->db_onedev->last_query(); $this->sys_error($message); exit; } // "total" => ceil($total / $ROW_PER_PAGE), $this->sys_ok("OK"); } function editpriceheader() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; if (!isset($prm['name'])) { $this->sys_error("Nama harus diisi"); exit; } if (trim($prm['name']) == "") { $this->sys_error("Nama harus diisi"); exit; } if (!isset($prm['sd'])) { $this->sys_error("Tanggal awal harus diisi"); exit; } if (!isset($prm['ed'])) { $this->sys_error("Tanggal akhir harus diisi"); exit; } $name = $prm['name']; $startDate = $prm['sd']; $endDate = $prm['ed']; $id = $prm['id']; $nw = strtotime($startDate); $nwe = strtotime($endDate); if ($nw > $nwe) { $this->sys_error("Tanggal akhir tidak boleh lebih besar dari Tanggal awal"); exit; } $sql = "UPDATE t_priceheader SET T_PriceHeaderName = '{$name}', T_PriceHeaderStartDate = '{$startDate}', T_PriceHeaderEndDate = '{$endDate}', T_PriceHeaderLastUpdated = NOW(), T_PriceHeaderLastUpdatedUserID = {$userid} WHERE T_PriceHeaderID = $id"; $query = $this->db_onedev->query($sql, []); if (!$query) { $message = $this->db_onedev->error(); $message['qry'] = $this->db_onedev->last_query(); $this->sys_error($message); exit; } // "total" => ceil($total / $ROW_PER_PAGE), $this->sys_ok("OK"); } function deletepriceheader() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $id = $prm['id']; $sql = "UPDATE sample_to_branch SET SampleBranchIsActive = 'N', SampleBranchDeleted = NOW(), SampleBranchDeletedUserID = {$userid} WHERE SampleToBranchID = $id"; $query = $this->db_onedev->query($sql, []); if (!$query) { $message = $this->db_onedev->error(); $message['qry'] = $this->db_onedev->last_query(); $this->sys_error($message); exit; } // "total" => ceil($total / $ROW_PER_PAGE), $this->sys_ok("OK"); } function getfilterprice() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $sql = "SELECT Nat_SubGroupID AS id, Nat_SubGroupName AS name FROM nat_subgroup WHERE Nat_SubGroupIsActive= 'Y'"; $query = $this->db_onedev->query($sql, []); if (!$query) { $message = $this->db_onedev->error(); $message['qry'] = $this->db_onedev->last_query(); $this->sys_error($message); exit; } $subgroup = $query->result_array(); array_push($subgroup, [ 'id' => '0', 'name' => 'Semua' ]); $status = [[ 'id' => 'A', 'name' => 'Semua' ], [ 'id' => 'Y', 'name' => 'Ya' ], [ 'id' => 'N', 'name' => 'Tidak' ]]; // "total" => ceil($total / $ROW_PER_PAGE), $rst = [ "subgroup" => $subgroup, 'status' => $status, ]; $this->sys_ok($rst); } function searchpricetest() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $search = '%' . $prm['search'] . '%'; //$subgroup = $prm['subgroup']; $headerID = $prm['headerid']; // $status = $prm['status']; $page = $prm["page"]; $ROW_PER_PAGE = 20; $start_offset = 0; // print_r($prm); if (isset($prm["page"])) { if ( is_numeric($prm["page"]) && $prm["page"] > 0 ) { $start_offset = ($page - 1) * $ROW_PER_PAGE; } } $sql = "SELECT COUNT(T_OrderHeaderLabNumber) as total FROM t_orderheader JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientName LIKE CONCAT('%',?,'%') WHERE T_OrderHeaderMgm_McuID = ? AND T_OrderHeaderIsActive = 'Y' "; $query = $this->db_onedev->query($sql, [$search, $prm['mgm_mcuid']]); $qryTotal = $this->db_onedev->last_query(); if (!$query) { $message = $this->db_onedev->error(); $message['qry'] = $this->db_onedev->last_query(); $this->sys_error($message); exit; } $total = $query->row_array()['total']; $sql = "SELECT M_PatientName as patient_name, T_OrderHeaderLabNumber as labno, T_OrderHeaderID as idx, M_PatientNoReg as noreg, '' as samples FROM t_orderheader JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientName LIKE CONCAT('%',?,'%') WHERE T_OrderHeaderMgm_McuID = ? AND T_OrderHeaderIsActive = 'Y' LIMIT ? OFFSET ? "; $query = $this->db_onedev->query($sql, [ $search, $prm['mgm_mcuid'], $ROW_PER_PAGE, $start_offset]); if (!$query) { $message = $this->db_onedev->error(); $message['qry'] = $this->db_onedev->last_query(); $this->sys_error($message); exit; } $data_return = $query->result_array(); if($data_return){ foreach ($data_return as $key => $value) { $sql = "SELECT T_OrderSampleID as order_sample_id, T_OrderSampleT_SampleTypeID as sample_type_id, T_SampleTypeName as sample_type_name, LEFT(T_OrderSampleBarcode,13) as barcode, T_OrderSampleSampling as issampling, IFNULL(T_OrderSampleSamplingDate,'') as sampling_date, IFNULL(T_OrderSampleSamplingTime,'') as sampling_time, T_OrderSampleReceive as isreceive, IFNULL(T_OrderSampleReceiveDate,'') as receive_date, IFNULL(T_OrderSampleReceiveTime,'') as receive_time, IFNULL(SampleToBranchDetailID,0) as detail_id FROM t_ordersample JOIN t_sampletype ON T_OrderSampleT_SampleTypeID = T_SampleTypeID LEFT JOIN sample_to_branch_detail ON SampleToBranchDetailSampleToBranchID = ? AND SampleToBranchDetailT_OrderSampleID = T_OrderSampleID AND SampleToBranchDetailIsActive = 'Y' WHERE T_OrderSampleT_OrderHeaderID = ? AND T_OrderSampleIsActive = 'Y'"; $query = $this->db_onedev->query($sql, [$prm['headerid'],$value['idx']]); //echo $this->db_onedev->last_query(); if (!$query) { $message = $this->db_onedev->error(); $message['qry'] = $this->db_onedev->last_query(); $this->sys_error($message); exit; } $data_return[$key]['samples'] = $query->result_array(); } } $result = [ "total" => ceil($total / $ROW_PER_PAGE), "ttl" => $total, "records" => $data_return ]; $this->sys_ok($result); } function checksample(){ if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $sql = "SELECT count(*) as tot FROM sample_to_branch_detail WHERE SampleToBranchDetailT_OrderSampleID = ? AND SampleToBranchDetailIsActive = 'Y'"; $query = $this->db_onedev->query($sql,array($prm['order_sample_id'])); // echo $sql; if (!$query) { $message = $this->db_onedev->error(); $message['qry'] = $this->db_onedev->last_query(); $this->sys_error($message); exit; } $exist_tot = $query->row()->tot; if($exist_tot == 0){ $sql = "INSERT INTO sample_to_branch_detail ( SampleToBranchDetailSampleToBranchID, SampleToBranchDetailT_OrderSampleID, SampleToBranchDetailCreated, SampleToBranchDetailCreatedUserID ) VALUES(?,?,NOW(),?)"; $query = $this->db_onedev->query($sql,array( $prm['headerid'], $prm['order_sample_id'], $userid )); // echo $sql; if (!$query) { $message = $this->db_onedev->error(); $message['qry'] = $this->db_onedev->last_query(); $this->sys_error($message); exit; } $result = [ "records" => $prm ]; $this->sys_ok($result); }else{ $message = "Sudah di dalam keranjang"; $this->sys_error($message); exit; } } function getsetups() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $branch_id = $prm['branch']['id']; $sql = "SELECT Mgm_McuID AS id, CONCAT(Mgm_McuNumber,' ',Mgm_McuLabel) AS name FROM mgm_mcu WHERE Mgm_McuIsActive = 'Y' AND Mgm_McuM_BranchID = {$branch_id} AND ( CURDATE() BETWEEN Mgm_McuStartDate AND Mgm_McuEndDate )"; $query = $this->db_onedev->query($sql); // echo $sql; if (!$query) { $message = $this->db_onedev->error(); $message['qry'] = $this->db_onedev->last_query(); $this->sys_error($message); exit; } $result = [ "records" => $query->result_array() ]; $this->sys_ok($result); } function getbranchs() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $sql = "SELECT M_BranchID AS id, M_BranchCode AS code, M_BranchName AS name FROM m_branch WHERE M_BranchIsActive = 'Y'"; $query = $this->db_onedev->query($sql); if (!$query) { $message = $this->db_onedev->error(); $message['qry'] = $this->db_onedev->last_query(); $this->sys_error($message); exit; } $result = [ "records" => $query->result_array() ]; $this->sys_ok($result); } function searchstaffs() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $search = '%' . $prm['search'] . '%'; $filter_staff = ""; if(isset($prm['staff_sample'])){ $filter_staff = " AND M_StaffID <> {$prm['staff_sample']['id']} "; } $sql = "SELECT M_StaffID as id, M_StaffName as name FROM m_staff WHERE M_StaffName LIKE '{$search}' AND M_StaffIsActive = 'Y' {$filter_staff} "; $query = $this->db_onedev->query($sql); //echo $sql; if (!$query) { $message = $this->db_onedev->error(); $message['qry'] = $this->db_onedev->last_query(); $this->sys_error($message); exit; } $result = [ "records" => $query->result_array() ]; $this->sys_ok($result); } function saveheader() { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; $sql = "INSERT INTO sample_to_branch ( SampleToBranchNumbering, SampleToBranchDate, SampleToBranchM_BranchID, SampleToBranchMgm_McuID, SampleBranchPetugasM_StaffID, SampleBranchKurirM_StaffID, SampleBranchCreated, SampleBranchCreatedUserID ) VALUES( fn_numbering_cpone('SJS'),?,?,?,?,?,NOW(),? ) "; $query = $this->db_onedev->query($sql,array( $prm['date'], $prm['branch']['id'], $prm['setup']['id'], $prm['staff_sample']['id'], $prm['staff_courier']['id'], $userid )); //echo $this->db_onedev->last_query(); if (!$query) { $message = $this->db_onedev->error(); $message['qry'] = $this->db_onedev->last_query(); $this->sys_error($message); exit; } $last_id = $this->db_onedev->insert_id(); $sql = "SELECT SampleToBranchNumbering as code FROM sample_to_branch WHERE SampleToBranchID = {$last_id}"; $results = $this->db_onedev->query($sql)->row_array(); $this->sys_ok($results); } }