· 5 years ago · Feb 02, 2021, 02:18 AM
1<?php
2 botLog("postion", "nlp ocr");
3 if(getUserVar("QAFOUND")!="TRUE"){
4
5 $msg = strtolower(getUserMessage());
6
7 if(empty($msg)){
8 $msg = strtolower(getUserVar("MSGFORNLP"));
9 }
10
11 $img = getUserImage();
12
13 if($img!=""){
14
15 $no = 1;
16
17 $msg = str_replace("<br>", "-", $msg);
18 $msg = preg_replace("/[^A-Za-z0-9 ]/", "-", $msg);
19 $explodeMsg = explode("-", $msg);
20
21 for($i = 0; $i < sizeof($explodeMsg); $i++){
22 if(strlen($explodeMsg[$i]) == 9){
23 $bl[] = $explodeMsg[$i];
24 }
25 }
26
27 $temparray = []; $i = 0;
28 foreach($bl as $val){
29 $temparray[$val] = [$i];
30 $i++;
31 }
32 foreach($temparray as $key => $val){
33 $bl_uniq[] = $key;
34 }
35
36 // cek di API tracking, kalau bl number ada lalu di simpan
37 foreach($bl_uniq as $valbl_uniq){
38 $url = "https://api.maerskline.com/track/".$valbl_uniq."?operator=mcpu";
39 // botlog("url", $url);
40 $ch = curl_init();
41 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
42 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
43 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
44 curl_setopt($ch, CURLOPT_URL, $url);
45 curl_setopt($ch, CURLOPT_HTTPHEADER,
46 array(
47 "Authorization: Atmosphere atmosphere_app_id=rcewucoc-8DIAwrPS6rI1PoD3y3emWs8P"
48 )
49 );
50 $results = curl_exec($ch);
51 if(curl_error($ch)){
52 botLog("error", curl_error($ch));
53 }
54 curl_close($ch);
55 $result = json_decode($results, true);
56 if($result["tpdoc_num"]!=""){
57 $check_ocr = true;
58 $bl_number[] = $valbl_uniq;
59
60 }
61 }
62 // setelah di cek ada di tracking baru di simpan
63 $no = 0;
64 foreach($bl_number as $bl_number_uniq){
65 setUserVar("BL_OCR".$no, $bl_number_uniq);
66 $no++;
67 }
68
69 $status = "error";
70 $error_msg = $result["error"];
71 $bl_number_1 = $bl_uniq;
72 for($x = 0; $x < sizeof($bl_uniq); $x++){
73 $url = "http://botmaster2.botika.online/server/mcc/API/index.php";
74
75 $tempArr["accessToken"] = "2625d26a-7023-45ea-9a9e-31694a70998d"; //accessToken
76 $tempArr["action"] = "getFreetimeStatusBL"; //actionnya
77 $tempArr["botId"] = "bc1n715x8ea";//bot id nya Myanmar
78 $tempArr["bl"] = strtoupper($bl_number_1);
79
80 $json = json_encode($tempArr);
81
82 //Initiate cURL.
83 $ch = curl_init();
84 //curl_setopt($ch, CURLOPT_HEADER, 1);
85
86 //Tell cURL that we want to send a POST request.
87 curl_setopt($ch, CURLOPT_POST, true);
88 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
89 curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
90 curl_setopt($ch, CURLOPT_TIMEOUT, 400); //timeout in seconds
91 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
92 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
93
94 // set url
95 curl_setopt($ch, CURLOPT_URL, $url);
96 curl_setopt($ch, CURLOPT_HTTPHEADER,
97 array(
98 "Content-Type: application/json",
99 "Accept: application/json",
100 )
101 );
102
103 //Execute the request
104 $result = curl_exec($ch);
105 if(curl_error($ch))
106 {
107 botLog("error", curl_error($ch));
108 }
109 curl_close($ch);
110
111 botLog("json", $json);
112 botLog("result api freetime", $result);
113
114 $results = json_decode($result,true);
115
116 if($results["result"]=="success"){
117
118 if($results["data"][0]["ftd_ft_dem"]!="" && $results["data"][0]["ftd_ft_det"]!=""){
119 $freetime_exp = "Export Freetime: Demurrage ".$results["data"][0]["ftd_ft_dem"]." days & Detention ".$results["data"][0]["ftd_ft_det"]." days <BR>";
120 }
121
122 if($results["data"][0]["ftd_ft"]!=""){
123 $freetime_imp = "Import Freetime: ".$results["data"][0]["ftd_ft"]." days <BR>";
124 }
125
126 // $bl_type = $results["data"][0]["document_group"];
127 // $task_status = $results["data"][0]["task_name"];
128
129 // if((strtolower($bl_type) == "sea waybill" && strtolower($task_status) == "open")){
130 // $bl_status = "No";
131 // }elseif((strtolower($bl_type) == "original" && strtolower($task_status) == "open")){
132 // $bl_status = "No";
133 // }elseif((strtolower($bl_type) == "sea waybill" && strtolower($task_status) == "closed")){
134 // $bl_status = "Yes";
135 // }elseif((strtolower($bl_type) == "original" && strtolower($task_status) == "closed")){
136 // $bl_status = "Yes";
137 // }else{
138 // $bl_status = "No";
139 // }
140 }
141
142 $url = "https://client.botmaster2.botika.online/mcc/API/myanmar.php";
143
144 $tempArr["accessToken"] = "2625d26a-7023-45ea-9a9e-31694a70998d"; //accessToken
145 $tempArr["action"] = "paymentBl"; //actionnya
146 $tempArr["botId"] = "bc1n715x8ea";//bot id nya Myanmar
147 $tempArr["bl"] = strtoupper($bl_uniq[$x]);
148
149 $json = json_encode($tempArr);
150
151 //Initiate cURL.
152 $ch = curl_init();
153 //curl_setopt($ch, CURLOPT_HEADER, 1);
154
155 //Tell cURL that we want to send a POST request.
156 curl_setopt($ch, CURLOPT_POST, true);
157 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
158 curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
159 curl_setopt($ch, CURLOPT_TIMEOUT, 400); //timeout in seconds
160 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
161 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
162
163 // set url
164 curl_setopt($ch, CURLOPT_URL, $url);
165 curl_setopt($ch, CURLOPT_HTTPHEADER,
166 array(
167 "Content-Type: application/json",
168 "Accept: application/json",
169 )
170 );
171
172 //Execute the request
173 $result = curl_exec($ch);
174 if(curl_error($ch))
175 {
176 botLog("error", curl_error($ch));
177 }
178 curl_close($ch);
179
180 botLog("json", $json);
181 botLog("result api payment bl", $result);
182
183 $payment = json_decode($result,true);
184
185 if($payment["isSuccess"]=="true"){
186 $bl_type = $payment["data"][0]["document_group"];
187
188 if(strstr($payment["data"][0]["document_group"], "Not Confirmed Sea Waybill")){
189 $status_group[$x] = "No Telex Release";
190 }elseif(strstr($payment["data"][0]["document_group"], "Confirmed Sea Waybill")){
191 $status_group[$x] = "Telex Release";
192 }elseif(strstr($payment["data"][0]["document_group"], "Not Surrendered")){
193 $status_group[$x] = "Original BL (Not surrendered)";
194 }
195 }
196
197
198 // api tracking
199 $url = "https://api.maerskline.com/track/".strtoupper($bl_uniq[$x])."?operator=mcpu";
200
201 $ch = curl_init();
202
203 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
204 curl_setopt($ch, CURLOPT_TIMEOUT, 400); //timeout in seconds
205 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
206 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
207 curl_setopt($ch, CURLOPT_URL, $url);
208 curl_setopt($ch, CURLOPT_HTTPHEADER, array(
209 "Authorization: Atmosphere atmosphere_app_id=rcewucoc-8DIAwrPS6rI1PoD3y3emWs8P"
210 ));
211
212 $results = curl_exec($ch);
213 if(curl_error($ch)){
214 botLog("error", curl_error($ch));
215 }
216 curl_close($ch);
217 $result = json_decode($results, true);
218
219 $ctr = "";
220 if($result["tpdoc_num"]!="" || !$result["error"]){
221 $tpdoc[$x] = $result["tpdoc_num"];
222
223 $origin[$x] = $result["origin"]["country"];
224 $pod_import[$x] = $result["destination"]["terminal"];
225
226 foreach($result["containers"] as $key => $container){
227 $containerNumber[$x][$key] = $container["container_num"];
228
229 $pod[$x] = $container["latest"]["city"].", ".$container["latest"]["country"];
230
231 $eta[$x] = date("Y-M-d H:i", strtotime($container["eta_final_delivery"]));
232 $etd[$x] = date("Y-M-d H:i", strtotime($container["latest"]["actual_time"]));
233
234 foreach($container["locations"] as $location){
235 foreach($location["events"] as $event){
236 if($event["vessel_name"]!=""){
237 $vesselName[$x] = $event["vessel_name"];
238 }
239
240 if($event["voyage_num"]!=""){
241 $voyageNum[$x] = $event["voyage_num"];
242 }
243
244
245 }
246
247 foreach($location["events"] as $event){
248 $activity[$x] = $event["activity"];
249 if($activity[$x] == "DISCHARG"){
250 $port_of_discharge[$x] = $location["city"].", ".$location["country"];
251 }
252 if($activity[$x] == "LOAD"){
253 $port_of_load[$x] = $location["city"].", ".$location["country"];
254 }
255 }
256 }
257 if(sizeof($containerNumber[$x]) > 1){
258 $ctr .= " - ".$containerNuetmber[$x][$key];
259 }else{
260 $ctr = $containerNumber[$x][$key];
261 }
262
263 }
264
265
266
267 if($origin[$x] == "Myanmar (Burma)"){
268 $chat = "<b>Export</b><BR><BR>".
269
270 $tpdoc[$x]." - ".$ctr."<BR><BR>".
271
272 "Vessel: ".$vesselName[$x]."<BR>".
273 "Voyage Number: ".$voyageNum[$x]."<BR>".
274 "Load Port: ".$port_of_load[$x]."<BR>".
275 "Discharge Port: ".$port_of_discharge[$x]."<BR>".
276 "Departure Date:".$etd[$x]."<BR>".
277 "Arrival Date: ".$eta[$x]."<BR><BR>".
278
279 // $freetime_exp.
280 // $freetime_imp."<BR>".
281
282 "BL Type: ".$bl_type."<BR><BR>".
283
284 "Detail transport plan can be downloaded on Sealand website <BR>".
285 "https://www.sealandmaersk.com<BR><BR>".
286
287 "Disclaimer: <BR>".
288 "- Departure/Arrival Date is subject to actual/estimated depending on vessel actual information availability.<BR>".
289 "- SOB can only be confirmed after container is loaded. All dates and times are given as reasonable estimates only and subject to change with or without prior notice.";
290 }else{
291 $chat = "<b>Import</b><BR><BR>".
292
293 $tpdoc[$x]." - ".$ctr."<BR><BR>".
294
295 "Vessel: ".$vesselName[$x]."<BR>".
296 "Voyage Number: ".$voyageNum[$x]."<BR>".
297 "Load Port: ".$port_of_load[$x]."<BR>".
298 "Discharge Port: ".$port_of_discharge[$x]."<BR>".
299 "Place of Delivery: ".$pod_import[$x]."<BR>".
300 "Estimated Arrival Date: ".$eta[$x]."<BR><BR>".
301
302 $freetime_imp."<BR>".
303
304 "BL Type: ".$bl_type."<BR>".
305 "BL Status: ".$status_group[$x]."<BR><BR>".
306 "Disclaimer: <BR>".
307 "- Departure/Arrival Date is subject to actual/estimated depending on vessel actual information availability.<BR>".
308 "- All dates and times are given as reasonable estimates only and subject to change with or without prior notice. <BR>".
309 "- One-off detention approval will not be reflected in the above information. ";
310 }
311 }else{
312 $chat = "BL Number : ".$bl_uniq[$x]."<BR>Apologize for not able to provide shipment status,<BR>".
313 "please contact our local customer service as per below:<BR>".
314 "Export – email to mm.export@sealandmaersk.com<BR>".
315 "Import – email to mm.import@sealandmaersk.com>";
316 }
317 botSendMessage(["text"=>$chat]);
318 setUserVar("QAFOUND", "TRUE");
319 }
320 }
321 setUserVar("MSGFROMNLP", "");
322 }