ocean_order.class.php 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. /**
  6. * Description of ocean
  7. *
  8. * @author Administrator
  9. */
  10. class ocean_order {
  11. private static $_ocean;
  12. function __construct() {
  13. }
  14. public static function getInstance() {
  15. global $memory_limit;
  16. $memory_limit = ini_get("memory_limit");
  17. ini_set("memory_limit", '2048M');
  18. if (!self::$_ocean) {
  19. $c = __CLASS__;
  20. self::$_ocean = new $c;
  21. }
  22. return self::$_ocean;
  23. }
  24. public function ocean_order() {
  25. $operate = utils::_get('operate');
  26. $operate = strtolower($operate);
  27. /*
  28. * index page
  29. */
  30. if (empty($operate)) {
  31. //search
  32. //栏位信息
  33. $column = column::getInstance()->getDisplayColumn('Ocean_Search');
  34. $BookingTableColumns = column::getInstance()->tableColumns('Ocean_Search',$column);
  35. $data['TrackingTableColumns'] = $BookingTableColumns;
  36. common::echo_json_encode(200,$data);
  37. exit();
  38. }
  39. /*
  40. * ocean order search
  41. */
  42. if ($operate == "search") {
  43. $this->_ocean_search();
  44. }
  45. /*
  46. * ocean order detail
  47. */
  48. if ($operate == "detail") {
  49. $this->_ocean_detail();
  50. }
  51. if ($operate == "ams_isf_log"){
  52. $this->_ams_isf_log();
  53. }
  54. /*
  55. * export ocean order to excel
  56. */
  57. if ($operate == "excel") {
  58. $this->_ocean_excel();
  59. }
  60. if ($operate == 'setting_ocean_order_display') {
  61. column::getInstance()->settingDisplay('Ocean_Search', 'main_new_version.php?action=ocean_order');
  62. }
  63. /*
  64. * download document
  65. */
  66. if ($operate == "download") {
  67. $this->_download();
  68. }
  69. if ($operate == "save_communication") {
  70. try {
  71. $content = $_POST["content"];
  72. $content = common::check_input($content);
  73. $text = $_POST["text"];
  74. $content = urldecode($content);
  75. $web_content = urldecode($text);
  76. $communication_cc = $_POST["communication_cc"];
  77. $serial_no = common::uuid();
  78. $email_uuid = $_POST["serial_no"];
  79. $add_by = _getLoginName();
  80. $refer_id = 0;
  81. $email = $this->getEmail($email_uuid);
  82. $from_email = "US.KApex.Online@kerryapex.com";
  83. $to_email = $email["email"];
  84. $cc_email = $_SESSION['ONLINE_USER']['email'] . ";ApexOnlineCommunication@apexshipping.com";
  85. $communication_cc = trim($communication_cc);
  86. if (!empty($communication_cc)) {
  87. $communication_cc = common::check_input($communication_cc);
  88. $cc_email .= ";" . $communication_cc;
  89. }
  90. $user_from = _getLoginName();
  91. $user_to = $email["name"];
  92. $user_cc = $_SESSION['ONLINE_USER']['first_name'];
  93. if (empty($user_cc)) {
  94. $user_cc = _getLoginName();
  95. }
  96. $user_cc .= ";ApexOnlineCommunication";
  97. //邮件发送
  98. $poKey = "<br><br>Important note: when you reply this email, do not remove ApexOnlineCommunication@apexshipping.com<br>Below is system code, do not delete.<br>@@";
  99. $emailSql = "select encode(public.pgp_sym_encrypt('" . $serial_no . "','pom_key'), 'base64')::text;";
  100. $key = common::excuteOneSql($emailSql);
  101. $historyEmails = "";
  102. $title = "Communication from " . _getLoginName() . ", HBOL: " . $email["h_bol"] . ", Consignee: " . $email["consignee"];
  103. $emailContent = $content . $poKey . $key . ";" . "@@<br>For your convenience weblink: https://ra.kerryapex.com/<br><br>" . $historyEmails;
  104. common::excuteUpdateSql("insert into public.email_record (type,title,from_email,to_email,cc_email,content,insert_date)values('Communication','$title','$from_email','$to_email','$cc_email','$emailContent',now());");
  105. $rs = common::excuteUpdateSql("INSERT INTO public.online_ocean_communication(serial_no, email_uuid, content,web_content,user_from, user_to, user_cc, refer_id, add_by, add_time, cc_email)
  106. VALUES ('$serial_no', '$email_uuid', '$emailContent','$web_content', '$user_from', '$to_email', '$cc_email', $refer_id, '$add_by', now(), '$communication_cc');");
  107. $emailRecords = $this->getCommunicationNew($email_uuid);
  108. common::echo_json_encode(200,array("msg" => "Sent Successfully", "emailRecords" => $emailRecords));
  109. exit();
  110. } catch (Exception $e) {
  111. common::echo_json_encode(500,array("msg" => "Sent Error."));
  112. exit();
  113. }
  114. }
  115. if ($operate == "ocean_vgm") {
  116. if (!_canEdiVgm()) {
  117. $data = array("msg" =>"Vgm Permission Error");
  118. common::echo_json_encode(200, $data);
  119. exit();
  120. }
  121. $serial_no = common::deCode(($_GET["a"]), 'D');
  122. $sqlWhere = " and o.serial_no='" . $serial_no . "'";
  123. $column = "*";
  124. $schemas = $_GET["_schemas"];
  125. if (empty($schemas)) {
  126. $schemas = "public";
  127. }
  128. $ocean_info_sql = "select o.from_station as o_from_station, o.h_bol as o_h_bol, o.carrier_booking, o.m_vessel, o.m_voyage, to_char(o.f_etd, 'MM/DD/YYYY') as f_etd, to_char(o.m_eta, 'MM/DD/YYYY') as m_eta, v.*, o.master_base_number from "
  129. . "$schemas.ocean o left join $schemas.ocean_vgm v on o.serial_no=v.serial_no or o.master_base_number=v.master_base_number where 1=1 and o.status::text <> 'Cancelled'::text AND o.bol_type::text <> 'BOOKING'::text AND o.bol_type::text <> 'QUOTE'::text" . $sqlWhere;
  130. $ocean_info = common::excuteObjectSql($ocean_info_sql);
  131. $rs_sql = "select o.service, o.ctnr, v.carrier_booking_no, o.ctnr, o.size, v.vgm_weight, v.unit, v.vgm_time, v.vgm_method, o.grs_kgs, o.grs_lbs, ov.id as ocean_vgm_id, v.id as ocean_vgm_container_id from "
  132. . "$schemas.oc_container o left join $schemas.ocean oc on o.serial_no=oc.serial_no "
  133. . " left join $schemas.ocean_vgm ov on oc.serial_no=ov.serial_no or oc.master_base_number=ov.master_base_number "
  134. . " left join $schemas.ocean_vgm_container v on ov.serial_no=v.serial_no and o.ctnr=v.ctnr "
  135. . " where 1=1 and oc.status::text <> 'Cancelled'::text AND oc.bol_type::text <> 'BOOKING'::text AND oc.bol_type::text <> 'QUOTE'::text and oc.master_base_number='" . $ocean_info["master_base_number"] . "' and oc.from_station='" . $ocean_info["o_from_station"] . "'";
  136. $rs = common::excuteListSql($rs_sql);
  137. $ocean_info["is_send"] = (empty($ocean_info["is_send"]) ? "f" : $ocean_info["is_send"]);
  138. if (empty($ocean_info["id"])) {
  139. $ocean_info["is_send"] = "t";
  140. }
  141. $err_msg = "";
  142. if (empty($ocean_info["carrier_booking"])) {
  143. $err_msg = "Carrier Booking is empty.";
  144. }
  145. if ($schemas <> "public") {
  146. $err_msg .= "This hbol do not support.";
  147. }
  148. foreach ($rs as $cv) {
  149. if (empty($cv["ctnr"])) {
  150. $err_msg .= "Container# is empty.";
  151. }
  152. if (substr($cv["service"], 0, 3) == "CFS") {
  153. $err_msg .= "CFS cannot support update.";
  154. }
  155. }
  156. if (!empty($err_msg)) {
  157. $err_msg = "You cant't add this VGM, (" . $err_msg . ")";
  158. }
  159. $serial_no = common::deCode($serial_no, "E");
  160. //default
  161. if (empty($rs["id"])) {
  162. $default = common::excuteObjectSql("select * from ocean_vgm_setting where login_name ilike '" . _getLoginName() . "'");
  163. }
  164. $log = common::excuteListSql("select * from ocean_vermas where from_serial_no ilike '" . $ocean_info["master_base_number"] . "'");
  165. //detail information
  166. $detail_information_column = array();
  167. $detail_information_column[] = array("title" =>"SN","field" =>"sn","formatter" =>"","type" =>"normal");
  168. $detail_information_column[] = array("title" =>"Carrier Booking No.","field" =>"carrier_booking_no","formatter" =>"","type" =>"normal");
  169. $detail_information_column[] = array("title" =>"Container No","field" =>"ctnr","formatter" =>"","type" =>"normal");
  170. $detail_information_column[] = array("title" =>"VGM Weight","field" =>"vgm_weight","formatter" =>"","type" =>"input");
  171. $detail_information_column[] = array("title" =>"VGM Unit","field" =>"unit","formatter" =>"","type" =>"select");
  172. $detail_information_column[] = array("title" =>"VGM Time","field" =>"vgm_time","formatter" =>"","type" =>"dateTime");
  173. $detail_information_column[] = array("title" =>"VGM Method","field" =>"vgm_method","formatter" =>"","type" =>"input");
  174. foreach($rs as $rk => $rv){
  175. $log[$rk]['sn'] = $rk +1;
  176. }
  177. $detail_information =array("detail_information_column" =>$detail_information_column,
  178. "detail_information_data" =>$rs);
  179. $data = array("msg" =>$err_msg);
  180. $Submitter = $ocean_info["authorized_company"];
  181. if(empty($ocean_info["id"])){
  182. $Submitter = $default["submitter"];
  183. }
  184. $signature = $ocean_info["signature"];
  185. if(empty($ocean_info["id"])){
  186. $signature = $default["signature"];
  187. }
  188. $authorized_email = $ocean_info["authorized_email"];
  189. if(empty($ocean_info["id"])){
  190. $authorized_email = $default["authorized_email"];
  191. }
  192. $authorized_tel = $ocean_info["authorized_tel"];
  193. if(empty($ocean_info["id"])){
  194. $authorized_tel = $default["authorized_tel"];
  195. }
  196. $data["general_information"] = array("HBL No."=>$ocean_info["o_h_bol"],
  197. "Carrier Booking No."=>$ocean_info["carrier_booking"],
  198. "Vessel"=>$ocean_info["m_vessel"],"Voyage"=>$ocean_info["m_voyage"],
  199. "ETD"=>$ocean_info["f_etd"],"ETA"=>$ocean_info["m_eta"],
  200. "Last updated User"=>$ocean_info["modify_user"],"Last updated Time"=>$ocean_info["modify_time"],
  201. "Submitter" =>$Submitter,"signature" =>$signature,"authorized_email" =>$authorized_email,"authorized_tel" =>$authorized_tel,"is_send" =>$ocean_info['is_send']);
  202. $data["detail_information"] = $detail_information;
  203. $data["schemas"] = $schemas;
  204. $data["serial_no"] = $serial_no;
  205. common::echo_json_encode(200, $data);
  206. exit();
  207. }
  208. if ($operate == "save_ocean_vgm") {
  209. if (!_canEdiVgm()) {
  210. $data = array("msg" =>"Vgm Permission Error");
  211. common::echo_json_encode(200, $data);
  212. exit();
  213. }
  214. $msg = $this->save_vgm();
  215. $data = array("msg" =>$msg);
  216. common::echo_json_encode(200, $data);
  217. exit();
  218. }
  219. }
  220. /*
  221. * ocean order search
  222. */
  223. private function _ocean_search() {
  224. $cp = common::check_input($_POST ['cp']); //current_page
  225. $ps = common::check_input($_POST ['ps']); //ps
  226. if (empty($ps))
  227. $ps = 50;
  228. $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  229. $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
  230. //查询tag
  231. // IFFBCF;Booking Confirmation
  232. // IFFREC;Cargo Arrived at Origin
  233. // IFFDEP;Departure
  234. // IFFARR;Arrived at Final Destination Port
  235. // IFFAFD;Arrived at Final Destination
  236. if (!empty($_POST["filterTag"])) {
  237. if (count($_POST['filterTag']) == 1){
  238. $filterTag = $_POST['filterTag'][0];
  239. }else{
  240. $filterTag = implode(",", $_POST['filterTag']);
  241. }
  242. $_sqlwhere = "1<>1";
  243. if (stripos($filterTag, "Booked") !== FALSE) {
  244. $_sqlwhere .= " or (dd.status = 'Booked')";
  245. }
  246. if (stripos($filterTag, "Cargo Received") !== FALSE) {
  247. $_sqlwhere .= " or (dd.status = 'Cargo Received')";
  248. }
  249. if (stripos($filterTag, "Departed") !== FALSE) {
  250. $_sqlwhere .= " or (dd.status = 'Departed')";
  251. }
  252. if (stripos($filterTag, "Arrived") !== FALSE) {
  253. $_sqlwhere .= " or (dd.status = 'Arrived')";
  254. }
  255. if (stripos($filterTag, "Completed") !== FALSE) {
  256. $_sqlwhere .= " or (dd.status = 'Completed')";
  257. }
  258. if(strtolower($filterTag) <> "all" && !empty($filterTag)){
  259. $sqlWhere .= " and ($_sqlwhere)";
  260. }
  261. }
  262. //取消全文检索
  263. // if (!empty($_POST["_textSearch"])) {
  264. // $sqlWhere .= " and text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))";
  265. // }
  266. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  267. if (!empty($_POST["_textSearch"])) {
  268. $textSearch_arr = $_POST['_textSearch'];
  269. if(!is_array($textSearch_arr)){
  270. $textSearch_arr = array($textSearch_arr);
  271. }
  272. $more_sql = "1<>1";
  273. foreach($textSearch_arr as $tsv){
  274. $more_sql .= " or booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  275. $more_sql .= " or h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
  276. $more_sql .= " or po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  277. $more_sql .= " or carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
  278. }
  279. if ($more_sql <> "1<>1"){
  280. $sqlWhere .= " and ($more_sql)";
  281. }
  282. }
  283. $rc = $_POST ['rc'];
  284. //这里都要查询,除非多传几个参数回来
  285. if ($rc == - 1 || true) {
  286. $sql = "select count(1) from online_ocean
  287. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  288. when a.description='Cargo Pickup' then 'Cargo Received'
  289. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  290. when a.description='Departure' then 'Departed'
  291. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  292. when a.description='Arrived at Final Destination' then 'Completed'
  293. else 'Booked' END as status
  294. from ocean_milestone a
  295. where a.serial_no=online_ocean.serial_no
  296. and a.description in (
  297. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  298. order by id desc limit 1) dd on true" . $sqlWhere;
  299. $rc = common::excuteOneSql($sql);
  300. error_log($sql);
  301. //Booked
  302. $sql = $this->getOcanOrderSearchSql("Booked",$sqlWhere);
  303. $Booked = common::excuteOneSql($sql);
  304. //Cargo Received
  305. $sql = $this->getOcanOrderSearchSql("Cargo Received",$sqlWhere);
  306. $Cargo_Received = common::excuteOneSql($sql);
  307. //Departed
  308. $sql = $this->getOcanOrderSearchSql("Departed",$sqlWhere);
  309. $Departed = common::excuteOneSql($sql);
  310. //Arrived
  311. $sql = $this->getOcanOrderSearchSql("Arrived",$sqlWhere);
  312. $Arrived = common::excuteOneSql($sql);
  313. //Completed
  314. $sql = $this->getOcanOrderSearchSql("Completed",$sqlWhere);
  315. $Completed = common::excuteOneSql($sql);
  316. if (!empty($_POST["filterTag"])) {
  317. $tagsList = array(array("name"=>"All","number"=>$rc,"type"=>"all","checked"=>in_array('All', $_POST["filterTag"])? true : false),
  318. array("name"=>"Booked","number"=>$Booked,"type"=>"booked","checked"=>in_array('Booked', $_POST["filterTag"])? true : false),
  319. array("name"=>"Cargo Received","number"=>$Cargo_Received,"type"=>"cargo_received","checked"=>in_array('Cargo Received', $_POST["filterTag"])? true : false),
  320. array("name"=>"Departure","number"=>$Departed,"type"=>"departure","checked"=>in_array('Departure', $_POST["filterTag"])? true : false),
  321. array("name"=>"Arrived","number"=>$Arrived,"type"=>"arrived","checked"=>in_array('Arrived', $_POST["filterTag"])? true : false),
  322. array("name"=>"Completed","number"=>$Completed,"type"=>"completed","checked"=>in_array('Completed', $_POST["filterTag"])? true : false));
  323. }else{
  324. //初始,前端有选择着带入选择
  325. $tagsList = array(array("name"=>"All","number"=>$rc,"type"=>"all","checked"=> true ),
  326. array("name"=>"Booked","number"=>$Booked,"type"=>"booked","checked"=> false),
  327. array("name"=>"Cargo Received","number"=>$Cargo_Received,"type"=>"cargo_received","checked"=> false),
  328. array("name"=>"Departure","number"=>$Departed,"type"=>"departure","checked"=> false),
  329. array("name"=>"Arrived","number"=>$Arrived,"type"=>"arrived","checked"=> false),
  330. array("name"=>"Completed","number"=>$Completed,"type"=>"completed","checked"=>false));
  331. }
  332. $TransportList = array(
  333. array("name"=>"Ocean Freight","number"=>$rc,"checked"=>false,"icon"=>"#icon-icon_ocean_b"));
  334. //现在下载交给前端,后台预先只返回全部字段的列,
  335. $allColumn = column::getInstance()->getDisplayColumnAllReomveDefault('Ocean_Search');
  336. $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
  337. }
  338. $tp = ceil($rc / $ps);
  339. $order_by = " etd desc NULLS LAST, id";
  340. if (_isCustomerLogin()) {
  341. $order_by = " eta desc NULLS LAST, id";
  342. }
  343. if ($rc > 0) {
  344. $ocean_ref_sql = " LEFT JOIN LATERAL ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no
  345. FROM public.ocean_reference temp WHERE temp.serial_no = online_ocean.serial_no) aa ON true ";
  346. $ocean_status_sql = " LEFT JOIN LATERAL ( select case when a.description='Booking Confirmation' then 'Booked'
  347. when a.description='Cargo Pickup' then 'Cargo Received'
  348. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  349. when a.description='Departure' then 'Departed'
  350. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  351. when a.description='Arrived at Final Destination' then 'Completed'
  352. else 'Booked' END as new_status
  353. from ocean_milestone a
  354. where a.serial_no=online_ocean.serial_no
  355. and a.description in (
  356. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  357. order by id desc limit 1) dd ON true ";
  358. $sql = "SELECT order_from as _schemas,serial_no as __serial_no, serial_no,
  359. h_bol as _hbol, isf_bol as _isfbol,
  360. CASE
  361. WHEN dd.new_status is null THEN 'Booked'::text
  362. ELSE dd.new_status::text
  363. END AS new_status, ".
  364. column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.online_ocean $ocean_ref_sql $ocean_status_sql" . $sqlWhere .
  365. " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;
  366. $rs = common::excuteListSql($sql);
  367. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  368. foreach($rs as $index => $val) {
  369. //返回加密serial_no
  370. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  371. $rs[$index]["mode"] = "Ocean Freight";
  372. $rs[$index]["Status"] = $rs[$index]["new_status"];
  373. }
  374. $arrTmp = array('searchData' => $rs,
  375. 'tagsList' => $tagsList,
  376. 'TransportList' => $TransportList,
  377. 'allColums' => $allBookingColumns,
  378. 'canEdiVgm' => _canEdiVgm(),
  379. 'rc' => $rc,
  380. 'ps' => $ps,
  381. 'cp' => $cp,
  382. 'tp' => $tp,
  383. 'tmp_search' => common::deCode($sql, 'E'),
  384. 'type' => common::check_input($_POST ['_ntype']));
  385. } else {
  386. $arrTmp = array('searchData' => array(),
  387. 'tagsList' => $tagsList,
  388. 'TransportList' => $TransportList,
  389. 'allColums' => $allBookingColumns,
  390. 'allColcanEdiVgmums' => _canEdiVgm(),
  391. 'rc' => $rc,
  392. 'ps' => $ps,
  393. 'cp' => $cp,
  394. 'tp' => $tp,
  395. 'tmp_search' => common::deCode($sql, 'E'),
  396. 'type' => common::check_input($_POST ['_ntype']));
  397. }
  398. common::echo_json_encode(200,$arrTmp);
  399. exit();
  400. }
  401. private function _ocean_detail() {
  402. $serial_no = common::deCode($_GET['a'], 'D');
  403. $sql = "SELECT m_eta as _m_eta, h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
  404. public.z_get_eta_dest(o.final_eta::date, o.eta_dest::text, o.service::text, o.m_eta::date, o.place_of_delivery::text, o.mport_of_discharge::text) as _eta_dest,
  405. to_char(final_eta, 'MM/DD/YYYY') as _final_eta,
  406. o.* ,sh.*, cn.* ,aa.*,dd.*,ee.status as new_status
  407. from ocean o
  408. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  409. when a.description='Cargo Pickup' then 'Cargo Received'
  410. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  411. when a.description='Departure' then 'Departed'
  412. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  413. when a.description='Arrived at Final Destination' then 'Completed'
  414. else 'Booked' END as status
  415. from ocean_milestone a
  416. where a.serial_no=online_ocean.serial_no
  417. and a.description in (
  418. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  419. order by id desc limit 1) ee on true
  420. LEFT JOIN LATERAL ( SELECT company as cn_company,
  421. address_1 as cn_address_1,
  422. address_2 as cn_address_2,
  423. address_3 as cn_address_3,
  424. address_4 as cn_address_4,
  425. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  426. phone_1 as cn_phone
  427. FROM contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
  428. LEFT JOIN LATERAL ( SELECT company as sh_company,
  429. address_1 as sh_address_1,
  430. address_2 as sh_address_2,
  431. address_3 as sh_address_3,
  432. address_4 as sh_address_4,
  433. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  434. phone_1 as sh_phone
  435. FROM contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
  436. LEFT JOIN LATERAL ( SELECT company as aa_company,
  437. address_1 as aa_address_1,
  438. address_2 as aa_address_2,
  439. address_3 as aa_address_3,
  440. address_4 as aa_address_4,
  441. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  442. phone_1 as aa_phone
  443. FROM contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
  444. LEFT JOIN LATERAL ( SELECT company as dd_company,
  445. address_1 as dd_address_1,
  446. address_2 as dd_address_2,
  447. address_3 as dd_address_3,
  448. address_4 as dd_address_4,
  449. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  450. phone_1 as dd_phone
  451. FROM contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
  452. where lower(serial_no) = '" . strtolower($serial_no) . "'";
  453. $ocean = common::excuteObjectSql($sql);
  454. if (!empty($ocean)) {
  455. $ocean['_isf_bol'] = $ocean['isf_bol'];
  456. if (empty($ocean['_isf_bol'])) {
  457. $ocean['_isf_bol'] = "AMAW" . $ocean['_h_bol'];
  458. }
  459. $isf_ss = md5(md5($ocean['_isf_bol']));
  460. $isf_ss = substr($isf_ss, 7) . substr($isf_ss, 0, 7);
  461. //ETA Dest的计算逻辑移除
  462. // most update status
  463. $_schemas = $_REQUEST["_schemas"];
  464. $mostStatusSql = "select last_status_loc, last_status_city, to_char(last_status_315_date, 'MM/DD/YYYY') as last_status_315_date,last_status_315_code "
  465. . ", fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un FROM public.online_ocean "
  466. . "where serial_no= '" . $ocean["serial_no"] . "'";
  467. if (!empty($_schemas)) {
  468. $mostStatusSql .= " and order_from='" . $_schemas . "'";
  469. }
  470. $mostStatus = common::excuteObjectSql($mostStatusSql);
  471. $state = -1;
  472. if (!empty($mostStatus["last_status_315_code"])) {
  473. //desc 逻辑处理取消
  474. $state = common::getStatusStage($mostStatus["last_status_315_code"]);
  475. }
  476. //请求地图是需要的参数
  477. $uncode = "'";
  478. if ($mostStatus["place_of_receipt_un"] != $mostStatus["fport_of_loading_un"]) {
  479. $uncode .= $mostStatus["place_of_receipt_un"];
  480. }
  481. $uncode .= "'|'" . $mostStatus["fport_of_loading_un"] . "'|'" . $mostStatus["mport_of_discharge_un"] . "'|'";
  482. if ($mostStatus["mport_of_discharge_un"] != $mostStatus["place_of_delivery_un"]) {
  483. $uncode .= $mostStatus["place_of_delivery_un"];
  484. }
  485. $uncode .= "'";
  486. }
  487. //处理shipment data暂时写死
  488. $simplexData = array();
  489. $simplexData[] = array("index" =>1,"label" =>"Place of Receipt",
  490. "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt'],"isArrival" =>$state == 1 ? true : false);
  491. $simplexData[] = array("index" =>2,"label" =>"Port of Loading",
  492. "path" =>$ocean['fport_of_loading_exp_exp']."/".$ocean['fport_of_loading_exp'],"isArrival" =>$state == 2 ? true : false,
  493. "children" =>array(array("label" =>"Cargo arrival at Origin","date" =>"2024-02-01"),
  494. array("label" =>"'Departure","date" =>"2024-02-01")));
  495. $simplexData[] = array("index" =>3,"label" =>"Port of Discharge",
  496. "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge'],"isArrival" =>$state == 3 ? true : false,
  497. "children" =>array(array("label" =>"ETA","date" =>"2024-02-01")));
  498. $simplexData[] = array("index" =>4,"label" =>"Place of Delivery",
  499. "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery'],"isArrival" =>$state == 4 ? true : false);
  500. //处理transportInfo信息数据
  501. $transportInfo = array("Tracking No." =>$ocean['tracking_no'],"status"=>$ocean['new_status'],"mode" => "Ocean Freight",
  502. "origin" =>$ocean['origin_station'],"destination" =>$ocean['destination_station'],
  503. "etd" =>$ocean['f_etd'],"atd" =>"","eta" =>$ocean['m_eta'],"ata" =>"");
  504. //处理basicInfo信息数据
  505. $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
  506. $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
  507. $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['carrier_booking'],
  508. "PO_NO" =>$ocean['po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  509. "Incoterm" =>$ocean['terms'],"Service_Type" =>$ocean['service']);
  510. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  511. $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  512. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  513. $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  514. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  515. $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  516. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  517. $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  518. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  519. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  520. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  521. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  522. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  523. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  524. //处理routes 转船可能有多个情况
  525. $routes = array(array("mode" =>"Sea", "origin" =>$ocean['origin_station'],
  526. "destination" => $ocean['destination_station'], "etd" => $ocean['f_etd'],"atd" => "",
  527. "eta" =>$ocean['m_eta'],"ata" =>"","vessel" =>$vessel,"voyageNo" =>$voyage));
  528. //处理ocean_reference
  529. $ref_no = array();
  530. $ref_arr = common::excuteListSql("select * from ocean_reference where lower(serial_no) = '" . strtolower($serial_no) . "'");
  531. if(!empty($ref_arr)){
  532. foreach($ref_arr as $ref) {
  533. $ref_no[] = array("label"=>$ref["ref_code"],"value"=>$ref["ref_value"]);
  534. }
  535. }
  536. //处理marksAndDescription
  537. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description']);
  538. //配置Ocean_Container字段 UI 需要的字段有:Container.no Packing,quantity,Gross weight(kg),Gross weight(LB),CBM,seal#,size.service
  539. //处理Container
  540. $ocean_container_column = array();
  541. $container_column = column::getInstance()->getDisplayColumnAll('Ocean_Container');
  542. foreach($container_column as $cc){
  543. $ocean_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],"formatter" =>"","type" =>"normal");
  544. }
  545. $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . " from oc_container where lower(serial_no) = '" . strtolower($serial_no) . "'";
  546. $rss = common::excuteListSql($sql);
  547. $quantity_tolal = 0;
  548. $packages = "CTN";
  549. $g_weight_tolal = 0;
  550. $ch_weight_tolal = 0;
  551. $cbm_tolal = 0;
  552. foreach ($rss as $key => $rs) {
  553. $quantity_tolal += $rs['qty'];
  554. $g_weight_tolal += $rs['grs_kgs'];
  555. $ch_weight_tolal += $rs['grs_lbs'];
  556. $cbm_tolal += $rs['cbm'];
  557. $packages = " ".$rs['unit'];
  558. //特殊处理weight
  559. if(!empty($rss[$key]['grs_kgs'])){
  560. $rss[$key]['grs_kgs'] = $rs['grs_kgs']."KG";
  561. }
  562. if(!empty($rss[$key]['grs_lbs'])){
  563. $rss[$key]['grs_lbs'] = $rs['grs_lbs']."LB";
  564. }
  565. }
  566. $containers = array("container_column"=>$ocean_container_column,"container_data" =>$rss);
  567. //Packing 不确定信息
  568. $packing = array("Quantity/Unit"=>$quantity_tolal.$packages,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $ch_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
  569. /* Container Status */
  570. //数据库里配置好
  571. $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container_Status') . " from oc_container_v where lower(serial_no) = '" . strtolower($serial_no) . "'";
  572. $rss = common::excuteListSql($sql);
  573. $containerStatusData = array();
  574. if (!empty($rss)) {
  575. //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
  576. $container_status_column = array("EE","I","AE","VD","VA");
  577. foreach ($rss as $rsk => $rs) {
  578. $containerStatusDataTemp = array();
  579. $content = array();
  580. //新UI 还有站点取值,但不清楚取的什么值,CN,SHK 暂时写死
  581. foreach($container_status_column as $status){
  582. $dec = common::excuteOneSql("select description from ra_online_edi_event where ra_name = '" . $status . "'");
  583. $status = strtolower($status);
  584. $content[] = array("title" =>$dec,"date"=>common::date2usdate($rs[$status]),"country"=>"CN,SHK");
  585. }
  586. $containerStatusDataTemp['label'] = $rs['ctnr']." / ".$rs['size'];
  587. $containerStatusDataTemp['content'] = $content;
  588. $containerStatusData[] = $containerStatusDataTemp;
  589. }
  590. }
  591. //Milestones info 列名固定
  592. $Milestones_column = array();
  593. $Milestones_column[] = array("title" =>"Milestones","field" =>"milestones","formatter" =>"","type" =>"normal");
  594. $Milestones_column[] = array("title" =>"Date Time","field" =>"date_time","formatter" =>"","type" =>"normal");
  595. $Milestones_column[] = array("title" =>"Locations","field" =>"locations","formatter" =>"","type" =>"normal");
  596. $Milestones_column[] = array("title" =>"Remarks","field" =>"remarks","formatter" =>"","type" =>"normal");
  597. //Milestones 数据信息待定
  598. $Milestones_data = array();
  599. $Milestones_data_arr = common::excuteListSql("select description,act_date||' '||act_time as date_time, remark,timezone from ocean_milestone a
  600. where a.serial_no='".$ocean["serial_no"]."' order by id");
  601. foreach($Milestones_data_arr as $mda){
  602. $Milestones_data[] = array("milestones"=>$mda['description'],"date_time"=>$mda['date_time'],"timezone" =>$mda['timezone'],
  603. "locations" => "", "remarks" =>$mda['remark']);
  604. }
  605. $Milestones = array("Milestones_column"=>$Milestones_column,"Milestones_data" =>$Milestones_data);
  606. //页面固定写死的信息
  607. $document_column = array();
  608. $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
  609. $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
  610. $document_data = array();
  611. $document = _getViewDocType($_REQUEST["_schemas"]);
  612. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  613. $ocean_can_view_file = common::excuteOneSql("select ocean_can_view_file from ra_online_user where lower(user_login)='".strtolower($_SESSION['ONLINE_USER']['user_login'])."'");
  614. if (!empty($document)) {
  615. foreach ($document as $v) {
  616. $file_type = $v['display_name'];
  617. $file_arr = $this->getFileByHbol($ocean['_m_bol'], $ocean['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE,$ocean['_job_bol']) ;
  618. $tar = json_decode($ocean_can_view_file,true);
  619. if(!empty($tar[$v['display_name']])){
  620. foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
  621. switch ($v['display_name']) {
  622. case 'HBL':
  623. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  624. from ra_online_doc_upload
  625. where lower(bol) = lower('".$ocean['_h_bol']."') and lower(format_serailno) in ('".strtolower(str_replace(";","','",$dvalue['value']))."') and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$dvalue['type']."'
  626. order by id desc";
  627. break;
  628. case 'MBL':
  629. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  630. from ra_online_doc_upload
  631. where ( lower(bol) = lower('".strtolower($ocean['_m_bol'])."') or lower(bol) = lower('".strtolower($ocean['_job_bol'])."')) and lower(format_serailno) in ('".strtolower(str_replace(";","','",$dvalue['value']))."') and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$dvalue['type']."'
  632. order by id desc";
  633. break;
  634. case 'Others':
  635. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  636. from ra_online_doc_upload
  637. where (lower(bol) = lower('".strtolower($ocean['_h_bol'])."') or lower(bol) = lower('".strtolower($ocean['_m_bol'])."') or lower(bol) = lower('".strtolower($ocean['_job_bol'])."')) and lower(format_serailno) in ('".strtolower(str_replace(";","','",$dvalue['value']))."') and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$dvalue['type']."'
  638. order by id desc";
  639. break;
  640. default:
  641. $sql = "";
  642. break;
  643. }
  644. if (!empty($sql)) {
  645. $rss = common::excuteListSql($sql);
  646. foreach ($rss as $rs) {
  647. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  648. $file_arr[] = array("url"=>$OutFileURL."/download.php?_schemas=&a=".base64_encode(base64_encode($rs['serial_no'])),
  649. "file_name" => $rs['file_name'],
  650. "detail"=>$rs['upload_date'],
  651. "can_delete"=>_getLoginName() == $rs['upload_by']);
  652. }else{
  653. $file_arr[] = array("url"=>"main_new_version?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  654. "file_name" => $rs['file_name'],
  655. "detail"=>$rs['upload_date'],
  656. "can_delete"=>_getLoginName() == $rs['upload_by']);
  657. }
  658. }
  659. }
  660. }
  661. }
  662. //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
  663. //按现在的逻辑,有值才会显示
  664. foreach($file_arr as $f){
  665. $document_data[] = array("file_type"=>$file_type,"file"=>$f);
  666. }
  667. }
  668. }
  669. $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
  670. $emailRecords = $this->getCommunicationNew($ocean["serial_no"]);
  671. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $ocean["serial_no"] . "' order by id desc limit 1");
  672. $email = $this->getEmail($ocean["serial_no"]);
  673. $email['cc_email'] = $cc_email;
  674. $email['emailRecords'] = $emailRecords;
  675. global $_COPYRIGHT;
  676. $data = array('transportInfo' => $transportInfo,
  677. 'basicInfo' => $basicInfo,
  678. 'businessPartners' => $businessPartners,
  679. 'ref_no' => $ref_no,
  680. 'packing' => $packing,
  681. 'marksAndDescription' => $marksAndDescription,
  682. 'containers' => $containers,
  683. 'simplexData' =>$simplexData,
  684. 'containerStatusData' => $containerStatusData,
  685. 'document_info' => $document_info,
  686. 'containers' => $containers,
  687. 'Milestones' => $Milestones,
  688. 'routes' => $routes,
  689. 'email' => $email,
  690. 'ams_ss' => md5(md5($ocean['serial_no'])),
  691. 'isf_ss' => $isf_ss,
  692. '_schemas' =>$_schemas,
  693. 'uncode' =>$uncode,
  694. 'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
  695. 'canEdiVgm' => _canEdiVgm(),
  696. 'copyright' =>$_COPYRIGHT);
  697. common::echo_json_encode(200,$data);
  698. exit();
  699. }
  700. private function _ocean_excel() {
  701. //现在下载交给前端,后台最后只返回全部字段的列,
  702. $allColumn = column::getInstance()->getDisplayColumnAll('Ocean_Search');
  703. $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
  704. common::echo_json_encode(200,array("msg"=>"success","allColums" => $allBookingColumns));
  705. exit;
  706. }
  707. private function _ams_isf_log(){
  708. global $cbpdb;
  709. $ams_ss = $_POST['ams_ss'];
  710. $isf_ss = $_POST['isf_ss'];
  711. $amsLog = array();
  712. //页面固定写死的信息
  713. $amsLog_column = array();
  714. $amsLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"normal");
  715. $amsLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  716. $amsLog_column[] = array("title" =>"Name","field" =>"isams_submit","formatter" =>"","type" =>"normal");
  717. $amsLog_column[] = array("title" =>"Description","field" =>"amslog","formatter" =>"","type" =>"normal");
  718. $amsLog["amsLog_column"] = $amsLog_column;
  719. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  720. $amsLog["data"] = array();
  721. if (_canViewAMSLog()) {
  722. $s = $ams_ss;
  723. //$s = "PDLA200127H";
  724. if (!empty($s)) {
  725. //$cc = $cbpdb->GetAll("select distinct h_bol from ams_information where md5(md5(from_serial_no)) = '" . pg_escape_string($s) . "'");
  726. $cc = $cbpdb->GetAll("select distinct h_bol from ams_information where h_bol = '" . pg_escape_string($s) . "'");
  727. foreach ($cc as $v){
  728. $amses[] = $cbpdb->GetAll("select * from ams_info where h_bol = '" . pg_escape_string($v['h_bol']) . "'");
  729. }
  730. //考虑一个情况
  731. if (count($amses) > 0) {
  732. $ams = $amses[0];
  733. $carrier_hbol = substr($ams[0]['m_bol'], 4);
  734. $carrier_scac = substr($ams[0]['m_bol'], 0, 4);
  735. if (empty($ams[0]['h_bol'])){
  736. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  737. $amsLog["data"] = array();
  738. }else{
  739. $log = $cbpdb->GetAll("select cbpreplytime as atime, amslog, cbperrorcode, isams_submit
  740. from v_e_amslog where hbol = '" . pg_escape_string($ams[0]['h_bol']) . "'
  741. and split_part(stationname, ',', 1) = split_part('" . pg_escape_string($ams[0]['station_name']) . "', ',', 1)
  742. order by cbpreplytime desc, substr(cbperrorcode, 2, 1) desc");
  743. $amsLog["msg"] = "";
  744. $amsLog["data"] = $log;
  745. }
  746. }
  747. }
  748. }
  749. $isfLog = array();
  750. //页面固定写死的信息
  751. $isfLog_column = array();
  752. $isfLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"normal");
  753. $isfLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  754. $isfLog_column[] = array("title" =>"Name","field" =>"isfsubmit","formatter" =>"","type" =>"normal");
  755. $isfLog_column[] = array("title" =>"Description","field" =>"isflog","formatter" =>"","type" =>"normal");
  756. $isfLog["isfLog_column"] = $isfLog_column;
  757. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  758. $isfLog["data"] = array();
  759. if (_canViewISFLog()) {
  760. if (!empty($isf_ss)) {
  761. $ss = $isf_ss;
  762. $len = strlen($ss);
  763. $b = substr($ss, $len - 7) . substr($ss, 0, $len - 7);
  764. if (empty($b)){
  765. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  766. $isfLog["data"] = array();
  767. }else{
  768. $isf = $cbpdb->GetRow("select * from ocean_isf where md5(md5(bol)) = '" . pg_escape_string($b) . "' or md5(md5(substr(bol, 5))) = '" . pg_escape_string($b) . "' order by id desc limit 1");
  769. }
  770. if (!empty($isf)) {
  771. if (!empty($isf['dob'])){
  772. $isf['dob'] = date("m/d/Y", strtotime($isf['dob']));
  773. }
  774. $msg = $cbpdb->GetAll("select cbpreplytime as atime, isflog, cbperrorcode, isfsubmit, hbol
  775. from v_e_isflog where (case when coalesce(isf_no, '')<>''
  776. then isf_no = '" . pg_escape_string($isf["isf_no"]) . "' else hbol = '" . pg_escape_string($isf["bol"]) . "'
  777. and stationname = '" . pg_escape_string($isf["station_name"]) . "' end)
  778. order by cbpreplytime desc, rowid desc");
  779. $isfLog["msg"] = "";
  780. $isfLog["data"] = $msg;
  781. }else{
  782. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  783. $isfLog["data"] = array();
  784. }
  785. }
  786. }
  787. $data =array("msg"=>"success",
  788. "canViewAMSLog" => _canViewAMSLog(),
  789. "canViewISFLog" => _canViewISFLog(),
  790. "amsLog" =>$amsLog,
  791. "isfLog" =>$isfLog);
  792. common::echo_json_encode(200,$data);
  793. exit;
  794. }
  795. private function getEmail($serial_no) {
  796. return utils::getEmail($serial_no);
  797. }
  798. private function getCommunicationNew($serial_no) {
  799. $list = common::excuteListSql("select to_char(add_time, 'MM/dd/yyyy hh24:MI:ss') as add_times, * from public.online_ocean_communication where email_uuid='$serial_no' and refer_id = 0 order by id");
  800. $emialRecords =array();
  801. foreach ($list as $k => $v) {
  802. $msg =array();
  803. $msg["name"] = $v["add_by"];
  804. $msg["creatTime"] = $v["add_times"];
  805. $msg["content"] = urldecode($v["web_content"]);
  806. $emialRecords[] = $msg;
  807. }
  808. return $emialRecords;
  809. }
  810. /*
  811. * get file by hbol/destination
  812. * H:HBL
  813. * M: MBL
  814. * F: FL
  815. * I: C/I & Packing list
  816. */
  817. private function getFileByHbol($m_bol, $h_bol, $types, $m_bs, $display, $detail = FALSE,$job_no="") {
  818. $types = strtolower($types);
  819. $types = explode(";", $types);
  820. $m_bs = explode(";", $m_bs);
  821. $otheres = NULL;
  822. $filefilter = " ('TELEX') ";//过滤掉类型,单独配置 3537
  823. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  824. $file = array();
  825. foreach ($types as $k => $type) {
  826. $m_b = $m_bs[$k];
  827. if (strtolower($m_b) == 'm')
  828. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date from ra_online_doc_upload where (lower(bol) = '" . strtolower($m_bol) . "' or lower(bol) ='".strtolower($job_no)."' ) and lower(format_serailno) = '$type' and upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter." order by id desc";
  829. if (strtolower($m_b) == 'h')
  830. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date from ra_online_doc_upload where lower(bol) = '" . strtolower($h_bol) . "' and lower(format_serailno) = '$type' and upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter." order by id desc";
  831. if (strtolower($m_b) == 'a')
  832. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date from ra_online_doc_upload where (lower(bol) = '" . strtolower($m_bol) . "' or lower(bol) = '" . strtolower($h_bol) . "' or lower(bol) ='".strtolower($job_no)."') and lower(format_serailno) = '$type' and upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter." order by id desc";
  833. if (!empty($sql)) {
  834. $rss = common::excuteListSql($sql);
  835. foreach ($rss as $rs) {
  836. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  837. $file[] = array("url"=>$OutFileURL.'/download.php?_schemas=&a='.base64_encode(base64_encode($rs['serial_no'])),
  838. "file_name" => $rs['file_name'],
  839. "detail"=>$rs['upload_date'],
  840. "can_delete"=>_getLoginName() == $rs['upload_by']);
  841. }else {
  842. $file[] = array("url"=>"main_new_version?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  843. "file_name" => $rs['file_name'],
  844. "detail"=>$rs['upload_date'],
  845. "can_delete"=>_getLoginName() == $rs['upload_by']);
  846. }
  847. }
  848. }
  849. }
  850. return $file;
  851. }
  852. /*
  853. * download file
  854. */
  855. private function _download() {
  856. $url = common::deCode($_GET['url'], 'D');
  857. common::download_file($url);
  858. }
  859. private function getOcanOrderSearchSql($type,$sqlWhere) {
  860. if($type == "Booked"){
  861. $Booked_sqlWhere = " and (1<>1 or dd.status ='Booked')";
  862. return "select count(1) from online_ocean
  863. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  864. when a.description='Cargo Pickup' then 'Cargo Received'
  865. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  866. when a.description='Departure' then 'Departed'
  867. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  868. when a.description='Arrived at Final Destination' then 'Completed'
  869. else 'Booked' END as status
  870. from ocean_milestone a
  871. where a.serial_no=online_ocean.serial_no
  872. and a.description in (
  873. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  874. order by id desc limit 1) dd on true" . $sqlWhere.$Booked_sqlWhere;
  875. }
  876. if($type == "Cargo Received"){
  877. $Cargo_Received_sqlWhere = " and (1<>1 or dd.status ='Cargo Received')";
  878. return "select count(1) from online_ocean
  879. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  880. when a.description='Cargo Pickup' then 'Cargo Received'
  881. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  882. when a.description='Departure' then 'Departed'
  883. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  884. when a.description='Arrived at Final Destination' then 'Completed'
  885. else 'Booked' END as status
  886. from ocean_milestone a
  887. where a.serial_no=online_ocean.serial_no
  888. and a.description in (
  889. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  890. order by id desc limit 1) dd on true" . $sqlWhere.$Cargo_Received_sqlWhere;
  891. }
  892. if($type == "Departed"){
  893. $Departed_sqlWhere = " and (1<>1 or dd.status ='Departed')";
  894. return "select count(1) from online_ocean
  895. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  896. when a.description='Cargo Pickup' then 'Cargo Received'
  897. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  898. when a.description='Departure' then 'Departed'
  899. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  900. when a.description='Arrived at Final Destination' then 'Completed'
  901. else 'Booked' END as status
  902. from ocean_milestone a
  903. where a.serial_no=online_ocean.serial_no
  904. and a.description in (
  905. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  906. order by id desc limit 1) dd on true" . $sqlWhere.$Departed_sqlWhere;
  907. }
  908. if($type == "Arrived"){
  909. $Arrived_sqlWhere = " and (1<>1 or dd.status ='Arrived')";
  910. return "select count(1) from online_ocean
  911. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  912. when a.description='Cargo Pickup' then 'Cargo Received'
  913. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  914. when a.description='Departure' then 'Departed'
  915. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  916. when a.description='Arrived at Final Destination' then 'Completed'
  917. else 'Booked' END as status
  918. from ocean_milestone a
  919. where a.serial_no=online_ocean.serial_no
  920. and a.description in (
  921. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  922. order by id desc limit 1) dd on true" . $sqlWhere.$Arrived_sqlWhere;
  923. }
  924. if($type == "Completed"){
  925. $Completed_sqlWhere = " and (1<>1 or dd.status ='Completed')";
  926. return "select count(1) from online_ocean
  927. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  928. when a.description='Cargo Pickup' then 'Cargo Received'
  929. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  930. when a.description='Departure' then 'Departed'
  931. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  932. when a.description='Arrived at Final Destination' then 'Completed'
  933. else 'Booked' END as status
  934. from ocean_milestone a
  935. where a.serial_no=online_ocean.serial_no
  936. and a.description in (
  937. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  938. order by id desc limit 1) dd on true" . $sqlWhere.$Completed_sqlWhere;
  939. }
  940. }
  941. private function save_vgm() {
  942. $schemas = $_POST["schemas"];
  943. $serial_no = common::deCode($_POST["serial_no"], 'D');
  944. $ocean = common::excuteObjectSql("select m_bol, master_base_number, from_station, h_bol from $schemas.ocean where serial_no='" . common::check_input($serial_no) . "'");
  945. $contact = common::excuteObjectSql("select company, city, state, zipcode, phone_1, fax, email_1, contactname_1, address_1, address_2, address_3, address_4 from ocean.contacts where contact_id='" . $ocean["from_station"] . "'");
  946. $address = $contact["address_1"];
  947. if (!empty($address)) {
  948. $address .= "\r\n";
  949. }
  950. $address .= $contact["address_2"];
  951. if (!empty($address)) {
  952. $address .= "\r\n";
  953. }
  954. $address .= $contact["address_3"];
  955. if (!empty($address)) {
  956. $address .= "\r\n";
  957. }
  958. $address .= $contact["address_4"];
  959. $exists = common::excuteOneSql("select serial_no from $schemas.ocean_vgm_masterbasenumber where master_base_number ilike '" . $ocean["master_base_number"] . "'");
  960. global $db;
  961. $db->StartTrans();
  962. if (empty($_POST["is_send"])) {
  963. $_POST["is_send"] = 'f';
  964. }
  965. if (empty($exists)) {
  966. $db->Execute("insert into ocean_vgm_masterbasenumber (master_base_number, serial_no) values ('" . $ocean["master_base_number"] . "', '$serial_no');");
  967. $value["serial_no"] = $serial_no;
  968. $value["carrier_booking_no"] = $_POST["all_carrier_booking"];
  969. $value["modify_user"] = _getLoginName();
  970. $value["modify_time"] = "now()";
  971. $value["authorized_email"] = !empty($_POST["authorized_email"]) ? $_POST["authorized_email"] : "";
  972. $value["authorized_tel"] = !empty($_POST["authorized_tel"]) ? $_POST["authorized_tel"] : "";
  973. $value["authorized_company"] = !empty($_POST["submitter"]) ? $_POST["submitter"] : "";
  974. $value["signature"] = !empty($_POST["signature"]) ? $_POST["signature"] : "";
  975. $value["is_send"] = $_POST["is_send"];
  976. $value["action"] = "New";
  977. $value["type"] = "Shipper";
  978. $value["m_bol"] = $ocean["m_bol"];
  979. $value["master_base_number"] = $ocean["master_base_number"];
  980. $value["shipper_id"] = $ocean["from_station"];
  981. $value["shipper"] = $contact["company"];
  982. $value["shipper_address"] = $address;
  983. $value["shipper_contactname"] = $contact["contactname_1"];
  984. $value["shipper_email"] = $contact["email_1"];
  985. $value["shipper_fax"] = $contact["fax"];
  986. $value["shipper_telephone"] = $contact["phone_1"];
  987. $value["update_uuid"] = utils::uuid();
  988. $value["h_bol"] = $ocean["h_bol"];
  989. $value["from_station"] = $ocean["from_station"];
  990. $sql = common::getInsertSqlNull("$schemas .ocean_vgm", $value);
  991. $db->Execute($sql);
  992. } else {
  993. $serial_no = $exists;
  994. $db->Execute("update ocean_vgm_masterbasenumber set id=id where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  995. $db->Execute("update $schemas.ocean_vgm set is_send='" . $_POST["is_send"] . "', carrier_booking_no='" . $_POST["all_carrier_booking"] . "', modify_user='" . _getLoginName() . "', modify_time=now(),"
  996. . "authorized_email='" . $_POST["authorized_email"] . "', authorized_tel='" . $_POST["authorized_tel"] . "', authorized_company='" . $_POST["submitter"] . "', signature='" . $_POST["signature"] . "', send_time=null "
  997. . ", update_uuid='" . utils::uuid() . "' where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  998. }
  999. $db->Execute("delete from ocean_vgm_container where serial_no ilike '" . $serial_no . "';");
  1000. foreach ($_POST["container_no"] as $i => $cv) {
  1001. $value1["serial_no"] = $serial_no;
  1002. $value1["carrier_booking_no"] = !empty($_POST["carrier_booking_no"][$i]) ? $_POST["carrier_booking_no"][$i] : "";
  1003. $value1["ctnr"] = !empty($_POST["container_no"][$i]) ? $_POST["container_no"][$i] : "";
  1004. $value1["size"] = !empty($_POST["size"][$i]) ? $_POST["size"][$i] : "";
  1005. $value1["vgm_weight"] = !empty($_POST["vgm_weight"][$i]) ? $_POST["vgm_weight"][$i] : "";
  1006. $value1["unit"] = !empty($_POST["vgm_kg_lg"][$i]) ? $_POST["vgm_kg_lg"][$i] : "";
  1007. $value1["vgm_time"] = !empty($_POST["vgm_date"][$i]) ? $_POST["vgm_date"][$i] : "";
  1008. $value1["cargo_weight_kgs"] = !empty($_POST["cargo_weight_kg"][$i]) ? $_POST["cargo_weight_kg"][$i] : "";
  1009. $value1["cargo_weight_lbs"] = !empty($_POST["cargo_weight_lb"][$i]) ? $_POST["cargo_weight_lb"][$i] : "";
  1010. $value1["vgm_method"] = !empty($_POST["vgm_method"][$i]) ? $_POST["vgm_method"][$i] : "";
  1011. $value1["master_base_number"] = $ocean["master_base_number"];
  1012. $sql = common::getInsertSqlNull("$schemas.ocean_vgm_container", $value1);
  1013. $db->Execute($sql);
  1014. }
  1015. if ($db->CompleteTrans() === FALSE) {
  1016. return "error";
  1017. } else {
  1018. return "success";
  1019. }
  1020. }
  1021. }
  1022. ?>