debug = false; } function now() { return Date("Y-m-d H:i:s"); } public function index() { //branch $sql = "select * from m_branch where M_BranchIsActive='Y' and M_BranchIsDefault='Y'"; $qry = $this->db->query($sql); if (!$qry) { echo "{$this->now()} ERR : {$this->db->error()['message']}\n"; exit; } $rows = $qry->result_array(); if (count($rows) == 0) { echo "{$this->now()} ERR : No Default Branch\n"; exit; } $branchID = $rows[0]["M_BranchID"]; $branchName = $rows[0]["M_BranchName"]; //Online Released MOU $sql = "select * from m_mou where M_MouIsReleased='Y' and M_MouIsOnline='Y' order by M_MouID desc"; $qry = $this->db->query($sql); if (!$qry) { echo "{$this->now()} ERR : {$this->db->error()['message']}\n"; exit; } $rows = $qry->result_array(); if (count($rows) == 0) { echo "{$this->now()} ERR : Online Released MOU not found\n"; exit; } $mou = $rows[0]; $mouID = $mou["M_MouID"]; //SsPrice MOU $sql = "select * from ss_price_mou where Ss_PriceMouM_MouID = ?"; $qry = $this->db->query($sql, array($mou["M_MouID"])); if (!$qry) { echo "{$this->now()} ERR : {$this->db->error()['message']}\n"; exit; } $rows = $qry->result_array(); if (count($rows) == 0) { echo "{$this->now()} ERR : Ss Price MOU not found\n"; exit; } $ss_price_mou = $rows; //Working $sql = "select $branchID M_RegPacketWorkM_BranchID, m_reg_packetwork.*, T_PacketName from m_reg_packetwork join t_packet on M_RegPacketWorkT_PacketID = T_PacketID where M_RegPacketWorkIsActive = 'Y' and M_RegPacketWorkM_MouID=?"; $qry = $this->db->query($sql, array($mouID)); if (!$qry) { echo "{$this->now()} ERR : {$this->db->error()['message']}\n"; exit; } $rows = $qry->result_array(); $arr_working = array(); foreach ($rows as $r) { $arr_working[$r["T_PacketName"]] = true; } $sql = "select $branchID M_RegPacketWorkM_BranchID, m_reg_packetwork.* from m_reg_packetwork join t_packet on M_RegPacketWorkT_PacketID = T_PacketID and M_RegPacketWorkM_MouID=?"; $qry = $this->db->query($sql, array($mouID)); if (!$qry) { echo "{$this->now()} ERR : {$this->db->error()['message']}\n"; exit; } $reg_working = $qry->result_array(); //Sale $sql = "select $branchID M_RegPacketSaleM_BranchID, m_reg_packetsale.* , T_PacketName from m_reg_packetsale join t_packet on M_RegPacketSaleT_PacketID = T_PacketID where M_RegPacketSaleIsActive = 'Y' and M_RegPacketSaleM_MouID=?"; $qry = $this->db->query($sql, array($mouID)); if (!$qry) { echo "{$this->now()} ERR : {$this->db->error()['message']}\n"; exit; } $rows = $qry->result_array(); $arr_sell = array(); foreach ($rows as $r) { $arr_sell[$r["T_PacketName"]] = true; } $sql = "select $branchID M_RegPacketSaleM_BranchID, m_reg_packetsale.* from m_reg_packetsale join t_packet on M_RegPacketSaleT_PacketID = T_PacketID and M_RegPacketSaleM_MouID=?"; $qry = $this->db->query($sql, array($mouID)); if (!$qry) { echo "{$this->now()} ERR : {$this->db->error()['message']}\n"; exit; } $reg_sell = $qry->result_array(); $s_packet = "-1"; foreach ($ss_price_mou as $idx => $r) { $ss_price_mou[$idx]["Ss_PriceMouM_BranchID"] = $branchID; $is_sell = "N"; $is_work = "N"; $packetName = $r["T_TestName"]; $packetID = $r["packet_id"]; if ($packetID > 0) { if (isset($arr_working[$packetName])) $is_work = "Y"; if (isset($arr_sell[$packetName])) $is_sell = "Y"; } $ss_price_mou[$idx]["Ss_PriceMouIsSell"] = $is_sell; $ss_price_mou[$idx]["Ss_PriceMouIsWork"] = $is_work; $s_packet .= "," . $packetID; } // echo "Packet Di di $branchName:\n"; // foreach ($ss_price_mou as $r) { // if ($r["is_packet"] == "Y") { // echo $r["T_TestName"]; // echo " , packet : : " . $r["packet_id"] . " , "; // echo " [ Cito : " . $r["T_PriceIsCito"] . "] : "; // echo " IsSell = " . $r["Ss_PriceMouIsSell"]; // echo " , IsWork = " . $r["Ss_PriceMouIsWork"] . " \n"; // } // } // packet $sql = "select $branchID T_PacketM_BranchID, t_packet.* from t_packet where T_PacketID in ( $s_packet) "; $qry = $this->db->query($sql); if (!$qry) { echo "{$this->now()} ERR Packet : {$this->db->error()['message']}\n"; exit; } $packets = $qry->result_array(); $sql = "select $branchID T_PacketDetailM_BranchID, t_packetdetail.* from t_packetdetail where T_PacketDetailT_PacketID in ( $s_packet) and T_PacketDetailIsActive = 'Y'"; $qry = $this->db->query($sql); if (!$qry) { echo "{$this->now()} ERR Packet : {$this->db->error()['message']}\n"; exit; } $packet_details = $qry->result_array(); $data = array( "ss_price_mou" => $ss_price_mou, "packet" => $packets, "working" => $reg_working, "sell" => $reg_sell, "detail" => $packet_details ); $md5 = md5(json_encode($data)); $param = array("md5" => $md5, "data" => $data); $z_param = gzdeflate(json_encode($param), 9); $url = "https://regonline.pramita.co.id/one-api/tools/regonline/r_price"; $resp = $this->post($url, $z_param); print_r($resp); } 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_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/octet-stream', 'Content-Length: ' . strlen($data) )); $result = curl_exec($ch); if (curl_errno($ch) > 0) { return array( "status" => "ERR", "message" => curl_error($ch) ); } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($httpCode != 200) { return array( "status" => "ERR", "message" => "Http Response : $httpCode" ); } $j_result = json_decode($result, true); if (!$j_result) { return array( "status" => "ERR", "message" => "JSON invalid: $result" ); } return $j_result; } }