db = $this->load->database('regional', true); } function create($mouID) { $sql = "select * from m_mou where M_MouID = ?"; $qry = $this->db->query($sql, array($mouID)); if (! $qry ) { echo 'Err : ' . print_r($this->db->error(),true). '\n'; exit; } $rows = $qry->result_array(); if (count($rows) == 0 ) { echo "Err : No Mou Found!"; exit; } $mouName = $rows[0]["M_MouName"]; //Test kecuali Profile $sql = "select T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID, T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID, T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal, T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id, 'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite, Nat_TestNat_TestTypeID, T_TestSasCode from t_price join t_test on T_PriceT_TestID = T_TestID and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y' and T_TestIsPrice = 'Y' join nat_test on T_TestNat_TestID = Nat_TestID and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5 where T_PriceM_MouID = ? and length(T_TestSasCode) = 8 "; $qry = $this->db->query($sql, array($mouID)); if (! $qry ) { echo 'Err : ' . print_r($this->db->error(),true). '\n'; exit; } $rows = $qry->result_array(); $flag_error = false; foreach($rows as $idx => $r) { $nat_testType = $r["Nat_TestNat_TestTypeID"]; switch($nat_testType) { case 1: //Single $rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']'; break; case 3: //Multi case 4: //Panel $sasCode = $r["T_TestSasCode"] . '%'; $sql = "select T_TestNat_TestID from t_test where T_TestIsResult = 'Y' and T_TestSasCode like ? and T_TestIsActive = 'Y'"; $qry = $this->db->query($sql,array($sasCode)); if (!$qry ) { echo "Err : " . print_r($this->db->error(),true) . "\n"; $flag_error = true; } $nt_rows = $qry->result_array(); $t_rows = array(); foreach($nt_rows as $nr) { $t_rows[] = $nr["T_TestNat_TestID"]; } $rows[$idx]['nat_test'] = "[" . join($t_rows) . "]"; break; } } //print_r($rows); //Test Profile $sql = "select T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID, T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID, T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal, T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id, 'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite, Nat_TestNat_TestTypeID, T_TestSasCode from t_price join t_test on T_PriceT_TestID = T_TestID and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y' join nat_test on T_TestNat_TestID = Nat_TestID and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5 where T_PriceM_MouID = ? and length(T_TestSasCode) = 8 "; $qry = $this->db->query($sql, array($mouID)); if (! $qry ) { echo 'Err : ' . print_r($this->db->error(),true). '\n'; exit; } $rows = $qry->result_array(); $flag_error = false; foreach($rows as $idx => $r) { $sasCode = $r["T_TestSasCode"] . '%'; $sql = "select T_TestNat_TestID from t_test where T_TestIsResult = 'Y' and T_TestSasCode like ? and T_TestIsActive = 'Y'"; $qry = $this->db->query($sql,array($sasCode)); if (!$qry ) { echo "Err : " . print_r($this->db->error(),true) . "\n"; $flag_error = true; } $nt_rows = $qry->result_array(); $t_rows = array(); foreach($nt_rows as $nr) { $t_rows[] = $nr["T_TestNat_TestID"]; } $rows[$idx]['nat_test'] = "[" . join($t_rows) . "]"; } } function upload($prm_date) { $sql = "select * from ssr_mr03 where date(SsrMr03T_OrderHeaderDate) = ? and SsrMr03IsSent = 'N' and SsrMr03Retry < 10"; $qry = $this->db->query($sql,array($prm_date)); if (! $qry) { echo "Err : " . print_r($this->db->error(),true); exit; } $rows = $qry->result_array(); $data = json_encode($rows); $md5 = md5($data); $param = array("data" => $data, "md5" => $md5); $jparam = json_encode($param); $url = "http://bandungraya.aplikasi.web.id/one-api/tools/marketing/r_mr03"; $url = "http://devbandungraya.aplikasi.web.id/one-api/tools/marketing/r_mr03"; echo "Uploading : $prm_date, total " . count($rows) . " records\n"; $j_result = $this->post($url,$jparam); $result = json_decode($j_result,true); $sql = "update ssr_mr03 set SsrMr03Retry = SsrMr03Retry + 1 where date(SsrMr03T_OrderHeaderDate) = ?"; $this->db->query($sql,array($prm_date)); if ($result["status"] == "OK") { $sql = "update ssr_mr03 set SsrMr03IsSent = 'Y' where SsrMr03ID = ?"; foreach($result["SsrMr03ID"] as $id ) { $this->db->query($sql, array($id)); } echo $result["status"] . ", total " . count($result["SsrMr03ID"]) . "\n"; exit; } echo "ERR : " . $result["message"] . "\n"; } function post($url,$data) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data)) ); $result = curl_exec($ch); return $result; } }