db_onedev = $this->load->database("onedev", true); $this->load->helper(array('form', 'url')); } function save() { $prm = $this->sys_input; $userid = $this->sys_user["M_UserID"]; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $rows = array(); $orderID = $prm["orderID"]; $url = $prm["url"]; $type = $prm["type"]; $format = $prm["format"]; if($format == '') $format = 'default-format'; $re_id = $prm["re_id"]; $userid = $this->sys_user["M_UserID"]; $sql = "insert into t_email_nonlab(T_EmailNonLabT_OrderHeaderID,T_EmailNonLabType, T_EmailNonLabFormat, T_EmailNonLabUrl,T_EmailNonLabResultEntryID,T_EmailNonLabUserID) values(?,?,?,?,?,?) on duplicate key update T_EmailNonLabFormat = ? , T_EmailNonLabUrl = ?, T_EmailNonLabResultEntryID = ?, T_EmailNonLabUserID = ? "; $query= $this->db_onedev->query($sql,array($orderID, $type,$format, $url, $re_id,$userid, $format, $url, $re_id,$userid)); if ($query) { $rows = $this->getdeliveries($orderID,$re_id); $this->sys_ok($rows); exit; } $msg = array( "message" => print_r($this->db_onedev->error(), true) , "query" => $this->db_onedev->last_query() ); $this->sys_error($msg); } function getdeliveries($orderid,$re_id){ $query =" SELECT T_OrderDeliveryID as id, IFNULL(Fo_VerificationDeliveryID,0) as xid, M_DeliveryTypeCode as code, IF(ISNULL(Fo_VerificationDeliveryID),'N',Fo_VerificationDeliveryIsOK) as chex, M_DeliveryID as deliveryid, M_DeliveryTypeID as typedeliveryid, T_OrderDeliveryM_KelurahanID as vilageid, IF(ISNULL(Fo_VerificationDeliveryID),'',Fo_VerificationDeliveryReason) as note, 'reguler' as type, CASE WHEN T_OrderDeliveryM_DeliveryID = 1 THEN M_DeliveryName WHEN T_OrderDeliveryM_DeliveryID = 4 THEN CONCAT(M_DeliveryName) WHEN T_OrderDeliveryM_DeliveryID = 2 THEN CONCAT(M_DeliveryName) WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN CONCAT(M_DeliveryName) WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN CONCAT(M_DeliveryName) ELSE CONCAT(M_DeliveryName) END as label, CASE WHEN T_OrderDeliveryM_DeliveryID = 1 THEN '' WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressDescription WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressDescription WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN M_DoctorHP WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN M_PatientHP ELSE T_OrderDeliveryDestination END as destination, CASE WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressID WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressID ELSE 0 END as addressid, 'brown' as color, '' as status_payment, '' as url FROM t_orderdelivery JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID JOIN m_delivery ON T_OrderDeliveryM_DeliveryID = M_DeliveryID JOIN m_deliverytype ON T_OrderDeliveryM_DeliveryTypeID = M_DeliveryTypeID LEFT JOIN m_doctoraddress ON T_OrderDeliveryAddressID = M_DoctorAddressID AND T_OrderDeliveryM_DeliveryID = 4 LEFT JOIN m_patientaddress ON T_OrderDeliveryAddressID = M_PatientAddressID AND T_OrderDeliveryM_DeliveryID = 2 LEFT JOIN fo_verification_delivery ON Fo_VerificationDeliveryT_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID AND Fo_VerificationDeliveryIsActive = 'Y' LEFT JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) LEFT JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) WHERE T_OrderDeliveryT_OrderHeaderID = {$orderid} AND T_OrderDeliveryIsActive = 'Y' GROUP BY T_OrderDeliveryID UNION SELECT 0 as id, IFNULL(Fo_VerificationDeliveryAddID,0) as xid, M_DeliveryTypeCode as code, IF(ISNULL(Fo_VerificationDeliveryAddID),'N',Fo_VerificationDeliveryAddOK) as chex, Fo_VerificationDeliveryAddM_DeliveryID as deliveryid, Fo_VerificationDeliveryAddM_DeliveryTypeID as typedeliveryid, Fo_VerificationDeliveryAddM_KelurahanID as vilageid, IF(ISNULL(Fo_VerificationDeliveryAddID),'',Fo_VerificationDeliveryAddReason) as note, 'reguler' as type, CASE WHEN Fo_VerificationDeliveryAddM_DeliveryID = 1 THEN 'Ambil Sendiri' WHEN Fo_VerificationDeliveryAddM_DeliveryID = 4 THEN CONCAT(M_DeliveryName) WHEN Fo_VerificationDeliveryAddM_DeliveryID = 2 THEN CONCAT(M_DeliveryName) WHEN ( Fo_VerificationDeliveryAddM_DeliveryID = 7 OR Fo_VerificationDeliveryAddM_DeliveryID = 9 ) THEN CONCAT(M_DeliveryName) WHEN ( Fo_VerificationDeliveryAddM_DeliveryID = 6 OR Fo_VerificationDeliveryAddM_DeliveryID = 8 ) THEN CONCAT(M_DeliveryName) ELSE CONCAT(M_DeliveryName) END as label, CASE WHEN Fo_VerificationDeliveryAddM_DeliveryID = 1 THEN '' WHEN Fo_VerificationDeliveryAddM_DeliveryID = 4 THEN M_DoctorAddressDescription WHEN Fo_VerificationDeliveryAddM_DeliveryID = 2 THEN M_PatientAddressDescription WHEN ( Fo_VerificationDeliveryAddM_DeliveryID = 7 OR Fo_VerificationDeliveryAddM_DeliveryID = 9 ) THEN M_DoctorHP WHEN ( Fo_VerificationDeliveryAddM_DeliveryID = 6 OR Fo_VerificationDeliveryAddM_DeliveryID = 8 ) THEN M_PatientHP ELSE Fo_VerificationDeliveryAddDestination END as destination, CASE WHEN Fo_VerificationDeliveryAddM_DeliveryID = 4 THEN M_DoctorAddressID WHEN Fo_VerificationDeliveryAddM_DeliveryID = 2 THEN M_PatientAddressID ELSE 0 END as addressid, 'brown' as color, '' as status_payment, '' as url FROM fo_verification_delivery_add JOIN t_orderheader ON Fo_VerificationDeliveryAddT_OrderHeaderID = T_OrderHeaderID JOIN m_delivery ON Fo_VerificationDeliveryAddM_DeliveryID = M_DeliveryID JOIN m_deliverytype ON Fo_VerificationDeliveryAddM_DeliveryTypeID = M_DeliveryTypeID LEFT JOIN m_doctoraddress ON Fo_VerificationDeliveryAddAddressID = M_DoctorAddressID AND Fo_VerificationDeliveryAddM_DeliveryID = 4 LEFT JOIN m_patientaddress ON Fo_VerificationDeliveryAddAddressID = M_PatientAddressID AND Fo_VerificationDeliveryAddM_DeliveryID = 2 LEFT JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND ( Fo_VerificationDeliveryAddM_DeliveryID = 7 OR Fo_VerificationDeliveryAddM_DeliveryID = 9 ) LEFT JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND ( Fo_VerificationDeliveryAddM_DeliveryID = 6 OR Fo_VerificationDeliveryAddM_DeliveryID = 8 ) WHERE Fo_VerificationDeliveryAddT_OrderHeaderID = {$orderid} AND Fo_VerificationDeliveryAddIsActive = 'Y' "; //echo $query ; $rows = $this->db_onedev->query($query)->result_array(); //echo $this->db_onedev->last_query(); $rst = ''; foreach($rows as $k => $v){ if($rst != ''){ $rst = $rst.' , '.$v['label']; } $rows[$k]['url'] = array(); if($v['typedeliveryid'] == '3' || $v['typedeliveryid'] == '4' || $v['typedeliveryid'] == '5'){ $sql = "SELECT IF(M_MouIsBill = 'Y','Y',Last_StatusPaymentIsLunas) as xpayment FROM last_statuspayment join t_orderheader ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID WHERE Last_StatusPaymentT_OrderHeaderID = {$orderid}"; //echo $sql; $status_payment = $this->db_onedev->query($sql)->row()->xpayment; $rows[$k]['status_payment'] = $status_payment; if($status_payment == 'Y'){ $sql = "SELECT * FROM t_email_nonlab JOIN so_resultentry ON T_EmailNonLabResultEntryID = So_ResultEntryID WHERE T_EmailNonLabT_OrderHeaderID = {$orderid} AND T_EmailNonLabResultEntryID = {$re_id}"; $row_format = $this->db_onedev->query($sql)->row_array(); if($row_format){ $format = array(); $url = array(); $rows[$k]['color'] = 'teal lighten-2'; $rows[$k]['label'] = $v["label"]." : ".$row_format['T_EmailNonLabFormat']; $url = array(array('test'=>'','url'=>$row_format['T_EmailNonLabUrl'])); array_push($format, $row_format['T_EmailNonLabFormat']); if($row_format['So_ResultEntrySo_TemplateOther'] == 'UMUM'){ $url = array(); $ex_url = explode('|^|',$row_format['T_EmailNonLabUrl']); //print_r($ex_url); foreach($ex_url as $k_url => $v_url){ if($k_url == 0) $testname = 'Riwayat'; else $testname = 'Fisik'; $xurl = array('test'=>$testname,'url'=>$v_url); array_push($url, $xurl); } } if($row_format['So_ResultEntrySo_TemplateOther'] == 'UMUM_K3'){ $url = array(); $ex_url = explode('|^|',$row_format['T_EmailNonLabUrl']); //print_r($ex_url); foreach($ex_url as $k_url => $v_url){ if($k_url == 0) $testname = 'Riwayat'; else if($k_url == 1) $testname = 'Fisik'; else $testname = 'Pajanan'; $xurl = array('test'=>$testname,'url'=>$v_url); array_push($url, $xurl); } } $join_format = join(",",$format); $rows[$k]['url'] = $url; $rows[$k]['label'] = $v["label"]." : ".$join_format; } else{ $rows[$k]['label'] = $v["label"]." : Belum Pilih Format"; } } else{ $rows[$k]['color'] = 'orange lighten-2'; $rows[$k]['url'] = ''; } } $rst .= $v['label']; } return $rows; } function get() { $prm = $this->sys_input; if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $orderID = $prm["orderID"]; $type= $prm["type"]; $sql = "select * from t_email_nonlab where T_EmailNonLabT_OrderHeaderID = ? and T_EmailNonLabType=?"; $qry = $this->db_onedev->query($sql, array($orderID,$type)) ; $rows = array(); if ($qry) { $rows = $qry->result_array(); } $this->sys_ok($rows); } }