db_onedev = $this->load->database("onedev", true); $this->staffID = 0; $sql = "select M_UserM_StaffID from m_user where M_UserID = ?"; $qry = $this->db_onedev->query($sql,array($this->sys_user["M_UserID"])); if ($qry) { $rows = $qry->result_array(); if(count($rows) > 0 ) $this->staffID = $rows[0]["M_UserM_StaffID"]; } $this->userID = $this->sys_user["M_UserID"]; } // data yg di upload // status : Arrival , Cancel / Serve , Lokasi // data lain : Catatan tambahan /* drop table if exists address_loc; create table address_loc ( Addres_LocID int not null auto_increment primary key, Address_LocM_PatientID int , Address_LocM_PatientAddressID int, Address_LocLat decimal(12,9), Address_LocLng decimal(12,9), Address_LocM_UserID int, Address_LocCreated datetime default current_timestamp(), Address_LocUpdated datetime default current_timestamp() on update current_timestamp(), Address_LocIsActive varchar(1) default 'Y', key(Address_LocM_PatientID), key(Address_LocM_PatientAddressID), key(Address_LocIsActive), unique(Address_LocM_PatientAddressID) ); */ function upload_order() { $orders = array(); try { $orders= $this->sys_input["orders"]; } catch(Exception $e) { } $updated_no = ""; $this->db_onedev->trans_start(); foreach($orders as $order) { $id = $order["PreOrder_HeaderID"]; $patientID = $order["PreOrder_HeaderM_PatientID"]; $addressID = $order["PreOrder_HeaderM_PatientAdrressID"]; if ($updated_no != "") $updated_no .= ", "; $updated_no .= $order["PreOrder_HeaderNumber"]; $updated_mark = ""; if (isset($order["arrived"]) ) { //update arrival and lat lng if ($updated_mark != "") $updated_mark .= ","; $updated_mark .= "Dtg"; } if (isset($order["note"])) { //add note if ($updated_mark != "") $updated_mark .= ","; $updated_mark .= "Cat"; } if (isset($order["latlng"])) { $lat = $order["latlng"]["lat"]; $lng = $order["latlng"]["lng"]; $sql = "insert into address_loc(Address_LocM_PatientID, Address_LocM_PatientAddressID, Address_LocLat,Address_LocLng, Address_LocM_UserID) values(?,?,?,?,?) on duplicate key update set Address_LocLat = ? , Address_LocLng = ? , Address_LocM_UserID=? where Address_LocM_PatientAddressID = ? "; $this->db_onedev->query($sql, array($patientID, $addressID, $lat, $lng, $this->userID, $lat, $lng, $this->userID, $patientID) ); } if (isset($order["status"])) { $status = $order["status"]; foreach($status as $s) { $statusID = $s["statusID"]; // 6 - ARRIVED , 3 - SERVE , 4 - DONE , 5 - CANCELLED // insert to log if ($status == 4 || $id == 5) { //update status $sql = "update one_preorder_dev.preorder_header set PreOrder_HeaderM_PreOrderStatusID = ? PreOrderM_UserID = ? where PreOrder_HeaderID = ?"; } } //update status serve / cancel if ($updated_mark != "") $updated_mark .= ","; $is_cancel = false; if ($is_cancel) $updated_mark = "Cancel"; $updated_mark .= "Serve"; } } } function mark_order() { $ids = array(); try { $ids= $this->sys_input["ids"]; } catch(Exception $e) { } foreach($ids as $id) { $sql = "update one_preorder_dev.preorder_header set PreOrder_HeaderDownloadedMobile='Y', PreOrder_HeaderM_UserID = ? where PreOrder_HeaderID = ?"; $this->db_onedev->query($sql,array($this->sys_user["M_UserID"],$id)); } echo json_encode( array( "status" => "OK" )); } function download_order() { $date = date("Y-m-d"); try { $date = $this->sys_input["date"]; } catch(Exception $e) { } $sql = "select PreOrder_HeaderID,PreOrder_HeaderNumbering, PreOrder_HeaderDate, PreOrder_HeaderTime, M_PatientAddressDescription,M_PatientAddressLat, M_PatientAddressLng, concat(M_TitleName,' ',M_PatientName) M_PatientName, PreOrder_HeaderPhone,M_KelurahanLat, M_KelurahanLng, concat(M_DoctorPrefix,' ',M_DoctorName,' ',M_DoctorSufix) M_DoctorName, M_KelurahanName,M_DistrictName,M_CityName from one_preorder_dev.preorder_header join m_patientaddress on M_PatientAddressID = PreOrder_HeaderM_PatientAdrressID join m_patient on PreOrder_HeaderM_PatientID = M_PatientID join m_title on M_PatientM_TitleID = M_TitleID join m_doctor on PreOrder_HeaderM_DoctorID = M_DoctorID left join m_kelurahan on PreOrder_HeaderM_KelurahanID = M_KelurahanID left join m_district on M_KelurahanM_DistrictID= M_DistrictID left join m_city on M_DistrictM_CityID = M_CityID where PreOrder_HeaderDate = ? and PreOrder_HeaderM_PreOrderStatusID=2 and PreOrder_HeaderDownloadedMobile = 'N' and PreOrder_HeaderM_StaffID = ?"; $qry = $this->db_onedev->query($sql,array($date,$this->staffID)); $order = array(); if ($qry) { $order = $qry->result_array(); foreach($order as $idx => $o) { $id = $o["PreOrder_HeaderID"]; $order[$idx]["test"] = $this->get_test($id); $order[$idx]["delivery"] = $this->get_delivery($id); } } echo json_encode( array( "status" => "OK", "data" => $order )); } function get_test($id) { $sql = "select PreOrder_TestID, PreOrder_TestT_TestCode, PreOrder_TestT_TestName, PreOrder_TestPrice, PreOrder_TestDisc , PreOrder_TestDiscRp , PreOrder_TestTotal from one_preorder_dev.preorder_test where PreOrder_TestPreOrder_HeaderID = ? and PreOrder_TestIsActive = 'Y'"; $qry = $this->db_onedev->query($sql,array($id)); if ($qry) { return $qry->result_array(); } return array(); } function get_delivery($id) { $sql = "select PreOrder_DeliveryID, M_DeliveryName, PreOrder_DeliveryDestination from one_preorder_dev.preorder_delivery join m_delivery on PreOrder_DeliveryM_DeliveryID = M_DeliveryID where PreOrder_DeliveryPreOrder_HeaderID = ? and PreOrder_DeliveryIsActive = 'Y'"; $qry = $this->db_onedev->query($sql,array($id)); if ($qry) { return $qry->result_array(); } return array(); } }