ocean_order.class.php 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  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. if (empty($operate)) {
  28. //search
  29. //栏位信息
  30. $column = column::getInstance()->getDisplayColumn('Ocean_Search');
  31. $BookingTableColumns = column::getInstance()->tableColumns('Ocean_Search',$column);
  32. $data['TrackingTableColumns'] = $BookingTableColumns;
  33. common::echo_json_encode(200,$data);
  34. exit();
  35. }
  36. if ($operate == "search") {
  37. $this->_ocean_search();
  38. }
  39. if ($operate == "detail") {
  40. $this->_ocean_detail();
  41. }
  42. if ($operate == "ams_isf_log"){
  43. $this->_ams_isf_log();
  44. }
  45. /*
  46. * export ocean order to excel
  47. */
  48. if ($operate == "excel") {
  49. $this->_ocean_excel();
  50. }
  51. if ($operate == 'setting_ocean_order_display') {
  52. column::getInstance()->settingDisplay('Ocean_Search', 'main_new_version.php?action=ocean_order');
  53. }
  54. /*
  55. * download document
  56. */
  57. if ($operate == "download") {
  58. $this->_download();
  59. }
  60. if ($operate == "save_communication") {
  61. try {
  62. $content = $_POST["content"];
  63. $content = common::check_input($content);
  64. $text = $_POST["text"];
  65. $content = urldecode($content);
  66. $web_content = urldecode($text);
  67. $communication_cc = $_POST["communication_cc"];
  68. $serial_no = common::uuid();
  69. $email_uuid = $_POST["serial_no"];
  70. $add_by = _getLoginName();
  71. $refer_id = 0;
  72. $email = $this->getEmail($email_uuid);
  73. $from_email = "US.KApex.Online@kerryapex.com";
  74. $to_email = $email["email"];
  75. $cc_email = $_SESSION['ONLINE_USER']['email'] . ";ApexOnlineCommunication@apexshipping.com";
  76. $communication_cc = trim($communication_cc);
  77. if (!empty($communication_cc)) {
  78. $communication_cc = common::check_input($communication_cc);
  79. $cc_email .= ";" . $communication_cc;
  80. }
  81. $user_from = _getLoginName();
  82. $user_to = $email["name"];
  83. $user_cc = $_SESSION['ONLINE_USER']['first_name'];
  84. if (empty($user_cc)) {
  85. $user_cc = _getLoginName();
  86. }
  87. $user_cc .= ";ApexOnlineCommunication";
  88. //邮件发送
  89. $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>@@";
  90. $emailSql = "select encode(public.pgp_sym_encrypt('" . $serial_no . "','pom_key'), 'base64')::text;";
  91. $key = common::excuteOneSql($emailSql);
  92. $historyEmails = "";
  93. $title = "Communication from " . _getLoginName() . ", HBOL: " . $email["h_bol"] . ", Consignee: " . $email["consignee"];
  94. $emailContent = $content . $poKey . $key . ";" . "@@<br>For your convenience weblink: https://ra.kerryapex.com/<br><br>" . $historyEmails;
  95. 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());");
  96. $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)
  97. VALUES ('$serial_no', '$email_uuid', '$emailContent','$web_content', '$user_from', '$to_email', '$cc_email', $refer_id, '$add_by', now(), '$communication_cc');");
  98. $emailRecords = $this->getCommunicationNew($email_uuid);
  99. common::echo_json_encode(200,array("msg" => "Sent Successfully", "emailRecords" => $emailRecords));
  100. exit();
  101. } catch (Exception $e) {
  102. common::echo_json_encode(500,array("msg" => "Sent Error."));
  103. exit();
  104. }
  105. }
  106. if ($operate == "ocean_vgm") {
  107. if (!_canEdiVgm()) {
  108. $data = array("msg" =>"Vgm Permission Error");
  109. common::echo_json_encode(400, $data);
  110. exit();
  111. }
  112. $serial_no = common::deCode(($_GET["a"]), 'D');
  113. $sqlWhere = " and o.serial_no='" . $serial_no . "'";
  114. $column = "*";
  115. $schemas = $_GET["_schemas"];
  116. if (empty($schemas)) {
  117. $schemas = "public";
  118. }
  119. $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 "
  120. . "$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;
  121. $ocean_info = common::excuteObjectSql($ocean_info_sql);
  122. $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 "
  123. . "$schemas.oc_container o left join $schemas.ocean oc on o.serial_no=oc.serial_no "
  124. . " left join $schemas.ocean_vgm ov on oc.serial_no=ov.serial_no or oc.master_base_number=ov.master_base_number "
  125. . " left join $schemas.ocean_vgm_container v on ov.serial_no=v.serial_no and o.ctnr=v.ctnr "
  126. . " 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"] . "'";
  127. $rs = common::excuteListSql($rs_sql);
  128. $ocean_info["is_send"] = (empty($ocean_info["is_send"]) ? "f" : $ocean_info["is_send"]);
  129. if (empty($ocean_info["id"])) {
  130. $ocean_info["is_send"] = "t";
  131. }
  132. $err_msg = "";
  133. if (empty($ocean_info["carrier_booking"])) {
  134. $err_msg = "Carrier Booking is empty.";
  135. }
  136. if ($schemas <> "public") {
  137. $err_msg .= "This hbol do not support.";
  138. }
  139. foreach ($rs as $cv) {
  140. if (empty($cv["ctnr"])) {
  141. $err_msg .= "Container# is empty.";
  142. }
  143. if (substr($cv["service"], 0, 3) == "CFS") {
  144. $err_msg .= "CFS cannot support update.";
  145. }
  146. }
  147. if (!empty($err_msg)) {
  148. $err_msg = "You cant't add this VGM, (" . $err_msg . ")";
  149. }
  150. $serial_no = common::deCode($serial_no, "E");
  151. //default
  152. if (empty($rs["id"])) {
  153. $default = common::excuteObjectSql("select * from ocean_vgm_setting where login_name ilike '" . _getLoginName() . "'");
  154. }
  155. $log = common::excuteListSql("select * from ocean_vermas where from_serial_no ilike '" . $ocean_info["master_base_number"] . "'");
  156. //detail information
  157. $detail_information_column = array();
  158. $detail_information_column[] = array("title" =>"SN","field" =>"sn","formatter" =>"","edit_type" =>"normal",);
  159. $detail_information_column[] = array("title" =>"Carrier Booking No.","field" =>"carrier_booking_no","formatter" =>"","edit_type" =>"normal");
  160. $detail_information_column[] = array("title" =>"Container No","field" =>"container_no","formatter" =>"","edit_type" =>"normal");
  161. $detail_information_column[] = array("title" =>"VGM Weight","field" =>"vgm_weight","formatter" =>"","edit_type" =>"number");
  162. $detail_information_column[] = array("title" =>"VGM Unit","field" =>"vgm_kg_lg","formatter" =>"","edit_type" =>"select");
  163. $detail_information_column[] = array("title" =>"VGM Time","field" =>"vgm_date","formatter" =>"","edit_type" =>"dateTime");
  164. $detail_information_column[] = array("title" =>"VGM Method","field" =>"vgm_method","formatter" =>"","edit_type" =>"input");
  165. foreach($rs as $rk => $rv){
  166. $rs[$rk]['sn'] = $rk +1;
  167. $rs[$rk]['container_no'] = $rv['ctnr'];
  168. $rs[$rk]['vgm_kg_lg'] = $rv['unit'];
  169. $rs[$rk]['vgm_date'] = $rv['vgm_time'];
  170. }
  171. $detail_information =array("detail_information_column" =>$detail_information_column,
  172. "detail_information_data" =>$rs);
  173. $data = array("msg" =>$err_msg);
  174. $Submitter = $ocean_info["authorized_company"];
  175. if(empty($ocean_info["id"])){
  176. $Submitter = $default["submitter"];
  177. }
  178. $signature = $ocean_info["signature"];
  179. if(empty($ocean_info["id"])){
  180. $signature = $default["signature"];
  181. }
  182. $authorized_email = $ocean_info["authorized_email"];
  183. if(empty($ocean_info["id"])){
  184. $authorized_email = $default["authorized_email"];
  185. }
  186. $authorized_tel = $ocean_info["authorized_tel"];
  187. if(empty($ocean_info["id"])){
  188. $authorized_tel = $default["authorized_tel"];
  189. }
  190. $data["general_information"] = array("HBL No."=>$ocean_info["o_h_bol"],
  191. "Carrier Booking No."=>$ocean_info["carrier_booking"],
  192. "Vessel"=>$ocean_info["m_vessel"],"Voyage"=>$ocean_info["m_voyage"],
  193. "ETD"=>$ocean_info["f_etd"],"ETA"=>$ocean_info["m_eta"],
  194. "Last updated User"=>$ocean_info["modify_user"],"Last updated Time"=>$ocean_info["modify_time"],
  195. "Submitter" =>$Submitter,"signature" =>$signature,"authorized_email" =>$authorized_email,"authorized_tel" =>$authorized_tel,"is_send" =>$ocean_info['is_send']);
  196. $data["detail_information"] = $detail_information;
  197. $data["schemas"] = $schemas;
  198. $data["serial_no"] = $serial_no;
  199. common::echo_json_encode(200, $data);
  200. exit();
  201. }
  202. if ($operate == "save_ocean_vgm") {
  203. if (!_canEdiVgm()) {
  204. $data = array("msg" =>"Vgm Permission Error");
  205. common::echo_json_encode(400, $data);
  206. exit();
  207. }
  208. $msg = $this->save_vgm();
  209. if ($msg == "success"){
  210. $data = array("msg" =>$msg);
  211. common::echo_json_encode(200, $data);
  212. } else {
  213. $data = array("msg" =>$msg);
  214. common::echo_json_encode(500, $data);
  215. }
  216. exit();
  217. }
  218. }
  219. /*
  220. * ocean order search
  221. */
  222. private function _ocean_search() {
  223. $cp = common::check_input($_POST ['cp']); //current_page
  224. $ps = common::check_input($_POST ['ps']); //ps
  225. if (empty($ps))
  226. $ps = 100;
  227. if (empty($cp))
  228. $cp = 1;
  229. $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  230. $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
  231. if (!empty($_REQUEST["_reportRef"])) {
  232. $_reportType = $_REQUEST["_reportType"];
  233. $_reportRef = $_REQUEST["_reportRef"];
  234. if ($_reportType == "r3") {
  235. if ($_reportRef == "Previous 7 Days") {
  236. $sqlWhere .= " and eta>(current_date-interval '7 days') and eta<current_date";
  237. } else if ($_reportRef == "0 Day") {
  238. $sqlWhere .= " and eta=current_date";
  239. } else if ($_reportRef == "1-2 Days") {
  240. $sqlWhere .= " and eta>current_date and eta<=(current_date+interval '2 days')";
  241. } else if ($_reportRef == "3-6 Days") {
  242. $sqlWhere .= " and eta>(current_date+interval '2 days') and eta<=(current_date+interval '6 days')";
  243. } else if ($_reportRef == "7 Days") {
  244. $sqlWhere .= " and eta>(current_date+interval '6 days')";
  245. } else {
  246. $sqlWhere .= " and 1<>1";
  247. }
  248. } else if ($_reportType == "r4") {
  249. if ($_reportRef == "Previous 7 Days") {
  250. $sqlWhere .= " and etd>(current_date-interval '7 days') and etd<current_date";
  251. } else if ($_reportRef == "0 Day") {
  252. $sqlWhere .= " and etd=current_date";
  253. } else if ($_reportRef == "1-2 Days") {
  254. $sqlWhere .= " and etd>current_date and etd<=(current_date+interval '2 days')";
  255. } else if ($_reportRef == "3-6 Days") {
  256. $sqlWhere .= " and etd>(current_date+interval '2 days') and etd<=(current_date+interval '6 days')";
  257. } else if ($_reportRef == "7 Days") {
  258. $sqlWhere .= " and etd>(current_date+interval '6 days')";
  259. } else {
  260. $sqlWhere .= " and 1<>1";
  261. }
  262. } else if ($_reportType == "ata_r3") {
  263. if ($_reportRef == "0 Day") {
  264. $sqlWhere .= " and ata >= etd and (ata-etd) >= 0 and (ata-etd) < 1";
  265. } else if ($_reportRef == "1-2 Days") {
  266. $sqlWhere .= " and ata >= etd and (ata-etd) >= 1 and (ata-etd) < 2";
  267. } else if ($_reportRef == "3-6 Days") {
  268. $sqlWhere .= " and ata >= etd and (ata-etd) >= 2 and (ata-etd) < 6";
  269. } else if ($_reportRef == "7 Days") {
  270. $sqlWhere .= " and ata >= etd and (ata-etd) >= 6";
  271. } else {
  272. $sqlWhere .= " and 1<>1";
  273. }
  274. } else if ($_reportType == "atd_r4") {
  275. if ($_reportRef == "0 Day") {
  276. $sqlWhere .= " and atd >= etd and (atd-etd) >= 0 and (atd-etd) < 1";
  277. } else if ($_reportRef == "1-2 Days") {
  278. $sqlWhere .= " and atd >= etd and (atd-etd) >= 1 and (atd-etd) < 2";
  279. } else if ($_reportRef == "3-6 Days") {
  280. $sqlWhere .= " and atd >= etd and (atd-etd) >= 2 and (atd-etd) < 6";
  281. } else if ($_reportRef == "7 Days") {
  282. $sqlWhere .= " and atd >= etd and (atd-etd) >= 6 ";
  283. } else {
  284. $sqlWhere .= " and 1<>1";
  285. }
  286. } else if ($_reportType == "top") {
  287. if (!empty($_reportRef)) {
  288. $_reportStationType = $_REQUEST["_reportStationType"];
  289. if($_reportStationType == 'shippr_uncode'){
  290. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  291. }
  292. if($_reportStationType == 'fport_of_loading_un'){
  293. $sqlWhere .= " and fport_of_loading_un = '$_reportRef'";
  294. }
  295. if($_reportStationType == 'consignee_uncode'){
  296. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  297. }
  298. if($_reportStationType == 'mport_of_discharge_un'){
  299. $sqlWhere .= " and mport_of_discharge_un = '$_reportRef'";
  300. }
  301. } else {
  302. $sqlWhere .= " and 1<>1";
  303. }
  304. } else if ($_reportType == "co2e") {
  305. $_reportDataType = $_REQUEST["_reportDataType"];
  306. //查询sea 其他的为空
  307. if (!empty($_reportRef) && $_reportDataType == "sea") {
  308. $_reportStationType = $_REQUEST["_reportStationType"];
  309. if($_reportStationType == 'origin'){
  310. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  311. }else{
  312. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  313. }
  314. } else {
  315. $sqlWhere .= " and 1<>1";
  316. }
  317. } else {
  318. $_reportRef = explode("-", $_REQUEST["_reportRef"]);
  319. $_reportRefb_date = $_REQUEST["_reportRefb_date"];
  320. $bdate = common::excuteOneSql("select to_date('$_reportRefb_date','mm/YYYY')");
  321. $_reportRefe_date = $_REQUEST["_reportRefe_date"];
  322. $edate = common::excuteOneSql("select to_date('$_reportRefe_date','mm/YYYY') + interval '1 month' - interval '1 day'");
  323. //$sqlWhere .= " and eta>='$bdate' and eta<='$edate'";
  324. if ($_REQUEST["_reportRef"] == "Over 80 Days") {
  325. $sqlWhere .= " and (eta-etd)>80";
  326. } else {
  327. $sqlWhere .= " and (eta-etd)>" . $_reportRef[0] . " and (eta-etd)<=" . substr($_reportRef[1], 0, 2);
  328. }
  329. }
  330. }
  331. //取消全文检索
  332. // if (!empty($_POST["_textSearch"])) {
  333. // $sqlWhere .= " and text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))";
  334. // }
  335. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  336. if (!empty($_POST["_textSearch"])) {
  337. $textSearch_arr = $_POST['_textSearch'];
  338. if(!is_array($textSearch_arr)){
  339. $textSearch_arr = array($textSearch_arr);
  340. }
  341. $more_sql = "1<>1";
  342. foreach($textSearch_arr as $tsv){
  343. $more_sql .= " or booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  344. $more_sql .= " or h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
  345. $more_sql .= " or po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  346. $more_sql .= " or carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
  347. }
  348. if ($more_sql <> "1<>1"){
  349. $sqlWhere .= " and ($more_sql)";
  350. }
  351. }
  352. //移除filterTag
  353. $sqlWhere_befrom_filterTag = $sqlWhere;
  354. //查询tag
  355. // IFFBCF Booking Confirmation Created
  356. // IFFCPU Cargo Pickup Cargo Received
  357. // IFFREC Cargo Arrived at Origin Cargo Received
  358. // IFFDEP Departure Departed
  359. // IFFARR Arrived at Final Destination Port Arrived
  360. // IFFAFD Arrived at Final Destination Completed
  361. $filterTag_param = "";
  362. if (!empty($_POST["filterTag"])) {
  363. if (utils::count($_POST['filterTag']) == 1){
  364. $filterTag = $_POST['filterTag'][0];
  365. }else{
  366. $filterTag = utils::implode(",", $_POST['filterTag']);
  367. }
  368. $_sqlwhere = "1<>1";
  369. $filterTag_param = "1<>1";
  370. if (stripos($filterTag, "Created") !== FALSE) {
  371. $_sqlwhere .= " or (m_iffbcf is not null and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null)";
  372. $filterTag_param .= " or (m_iffbcf is not null and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null)";
  373. }
  374. if (stripos($filterTag, "Cargo Received") !== FALSE) {
  375. $_sqlwhere .= " or ((m_iffcpu is not null or m_iffrec is not null) and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null)";
  376. $filterTag_param .= " or ((m_iffcpu is not null or m_iffrec is not null) and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null)";
  377. }
  378. if (stripos($filterTag, "Departure") !== FALSE) {
  379. $_sqlwhere .= "or (m_iffdep is not null and m_iffarr is null and m_iffafd is null)";
  380. $filterTag_param .= "or (m_iffdep is not null and m_iffarr is null and m_iffafd is null)";
  381. }
  382. if (stripos($filterTag, "Arrived") !== FALSE) {
  383. $_sqlwhere .= " or (m_iffarr is not null and m_iffafd is null)";
  384. $filterTag_param .= " or (m_iffarr is not null and m_iffafd is null)";
  385. }
  386. if (stripos($filterTag, "Completed") !== FALSE) {
  387. $_sqlwhere .= " or (m_iffafd is not null)";
  388. $filterTag_param .= " or (m_iffafd is not null)";
  389. }
  390. if(strtolower($filterTag) <> "all" && !empty($filterTag)){
  391. $sqlWhere .= " and ($_sqlwhere)";
  392. $filterTag_param = " ($filterTag_param)";
  393. }
  394. }
  395. if(empty($filterTag_param)){
  396. $filterTag_param = "1=1";
  397. }
  398. $rc = $_POST ['rc'];
  399. //这里都要查询,除非多传几个参数回来
  400. if ($rc == - 1 || true) {
  401. $sql = "select count(1) as rc,
  402. sum(case when $filterTag_param then 1 else 0 end) as seach_rc,
  403. sum(case when (m_iffbcf is not null and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null)
  404. then 1 else 0 end)
  405. as created,
  406. sum(case when ((m_iffcpu is not null or m_iffrec is not null) and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null)
  407. then 1 else 0 end)
  408. as cargo_received,
  409. sum(case when (m_iffdep is not null and m_iffarr is null and m_iffafd is null) then 1 else 0 end) as departed,
  410. sum(case when (m_iffarr is not null and m_iffafd is null) then 1 else 0 end) as arrived,
  411. sum(case when (m_iffafd is not null) then 1 else 0 end) as completed,
  412. string_agg(distinct incoterms, '<$>') as incoterm_str,
  413. string_agg(distinct service, '<$>') as service_str
  414. from online_ocean". $sqlWhere_befrom_filterTag;
  415. error_log("online_ocean_search_All_Status: ".$sql);
  416. $sql_all_status_data = common::excuteObjectSql($sql);
  417. $incoterms = explode("<$>", $sql_all_status_data['incoterm_str']);
  418. $IncotermsList = array();
  419. foreach($incoterms as $terms){
  420. if(!empty($terms['incoterms'])){
  421. $IncotermsList[] = array("name"=>$terms['incoterms'],"checked"=>false);
  422. }
  423. }
  424. $service = explode("<$>", $sql_all_status_data['service_str']);
  425. $ServiceList = array();
  426. foreach($service as $_service){
  427. if(!empty($_service['service'])){
  428. $ServiceList[] = array("name"=>$_service['service'],"checked"=>false);
  429. }
  430. }
  431. $rc = $sql_all_status_data['rc'];
  432. $search_rc = $sql_all_status_data['seach_rc'];
  433. $Created = $sql_all_status_data['created'];
  434. $Cargo_Received = $sql_all_status_data['cargo_received'];
  435. $Departed = $sql_all_status_data['departed'];
  436. $Arrived = $sql_all_status_data['arrived'];
  437. $Completed = $sql_all_status_data['completed'];
  438. if (!empty($_POST["filterTag"])) {
  439. $tagsList = array(array("name"=>"All","number"=>intval($rc),"type"=>"all","checked"=>utils::in_array('All', $_POST["filterTag"])? true : false),
  440. array("name"=>"Created","number"=>intval($Created),"type"=>"created","checked"=>utils::in_array('Created', $_POST["filterTag"])? true : false),
  441. array("name"=>"Cargo Received","number"=>intval($Cargo_Received),"type"=>"cargo_received","checked"=>utils::in_array('Cargo Received', $_POST["filterTag"])? true : false),
  442. array("name"=>"Departure","number"=>intval($Departed),"type"=>"departure","checked"=>utils::in_array('Departure', $_POST["filterTag"])? true : false),
  443. array("name"=>"Arrived","number"=>intval($Arrived),"type"=>"arrived","checked"=>utils::in_array('Arrived', $_POST["filterTag"])? true : false),
  444. array("name"=>"Completed","number"=>intval($Completed),"type"=>"completed","checked"=>utils::in_array('Completed', $_POST["filterTag"])? true : false));
  445. }else{
  446. //初始,前端有选择着带入选择
  447. $tagsList = array(array("name"=>"All","number"=>intval($rc),"type"=>"all","checked"=> true ),
  448. array("name"=>"Created","number"=>intval($Created),"type"=>"created","checked"=> false),
  449. array("name"=>"Cargo Received","number"=>intval($Cargo_Received),"type"=>"cargo_received","checked"=> false),
  450. array("name"=>"Departure","number"=>intval($Departed),"type"=>"departure","checked"=> false),
  451. array("name"=>"Arrived","number"=>intval($Arrived),"type"=>"arrived","checked"=> false),
  452. array("name"=>"Completed","number"=>intval($Completed),"type"=>"completed","checked"=>false));
  453. }
  454. if (!isset($_POST["transport_mode"])){
  455. //代表初始
  456. $TransportList = array(
  457. array("name"=>"Ocean Freight","number"=>intval($rc),"checked"=>false,"icon"=>"#icon-icon_ocean_b"));
  458. }else{
  459. if (strtolower($_POST["transport_mode"]) == "all") {
  460. $TransportList = array(
  461. array("name"=>"Ocean Freight","number"=>intval($rc),"checked"=>true,"icon"=>"#icon-icon_ocean_b"));
  462. } else {
  463. $TransportList = array(
  464. array("name"=>"Ocean Freight","number"=>intval($rc),"checked"=>false,"icon"=>"#icon-icon_ocean_b"));
  465. }
  466. }
  467. //现在下载交给前端,后台预先只返回全部字段的列,
  468. $allColumn = column::getInstance()->getDisplayColumnAllReomveDefault('Ocean_Search');
  469. $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
  470. }
  471. $tp = ceil($rc / $ps);
  472. $order_by = " etd desc NULLS LAST";
  473. if (_isCustomerLogin()) {
  474. $order_by = " eta desc NULLS LAST";
  475. }
  476. if ($rc > 0) {
  477. $ocean_ref_sql = " LEFT JOIN LATERAL ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no
  478. FROM public.ocean_reference temp WHERE temp.serial_no = online_ocean.serial_no) aa ON true ";
  479. $sql = "SELECT order_from as _schemas,serial_no as __serial_no, serial_no,
  480. h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,
  481. CASE
  482. WHEN (m_iffbcf is not null and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Created'::text
  483. WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Cargo Received'::text
  484. WHEN (m_iffdep is not null and m_iffarr is null and m_iffafd is null) THEN 'Departed'::text
  485. WHEN (m_iffarr is not null and m_iffafd is null) THEN 'Arrived'::text
  486. WHEN (m_iffafd is not null) THEN 'Completed'::text
  487. ELSE 'Created'
  488. END AS new_status, ".
  489. column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.online_ocean $ocean_ref_sql " . $sqlWhere .
  490. " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;
  491. $rs = common::excuteListSql($sql);
  492. error_log("online_ocean_search_SQL: ".$sql);
  493. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  494. foreach($rs as $index => $val) {
  495. //返回加密serial_no
  496. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  497. $rs[$index]["mode"] = "Ocean Freight";
  498. //status 改为ocean_milestone里的信息
  499. $rs[$index]["Status"] = $rs[$index]["new_status"];
  500. //以下新增的origin是 shipper和consignee的地址
  501. if(array_key_exists("Origin", $val)){
  502. $rs[$index]["Origin"] = utils::outDisplayForMerge($val['Origin'],$val['_consignee_city']);
  503. }
  504. }
  505. $arrTmp = array('searchData' => $rs,
  506. 'tagsList' => $tagsList,
  507. 'TransportList' => $TransportList,
  508. 'allColums' => $allBookingColumns,
  509. 'IncotermsList' =>$IncotermsList,
  510. 'ServiceList' =>$ServiceList,
  511. 'canEdiVgm' => _canEdiVgm(),
  512. 'rc' => $search_rc,
  513. 'ps' => $ps,
  514. 'cp' => $cp,
  515. 'tp' => $tp,
  516. 'tmp_search' => common::deCode($sql, 'E'),
  517. 'type' => common::check_input($_POST ['_ntype']));
  518. } else {
  519. $arrTmp = array('searchData' => array(),
  520. 'tagsList' => $tagsList,
  521. 'TransportList' => $TransportList,
  522. 'IncotermsList' =>$IncotermsList,
  523. 'ServiceList' =>$ServiceList,
  524. 'allColums' => $allBookingColumns,
  525. 'canEdiVgm' => _canEdiVgm(),
  526. 'rc' => $search_rc,
  527. 'ps' => $ps,
  528. 'cp' => $cp,
  529. 'tp' => $tp,
  530. 'tmp_search' => common::deCode($sql, 'E'),
  531. 'type' => common::check_input($_POST ['_ntype']));
  532. }
  533. common::echo_json_encode(200,$arrTmp);
  534. exit();
  535. }
  536. private function _ocean_detail() {
  537. $serial_no = common::deCode($_GET['a'], 'D');
  538. $sql = $this->getOceanDetail($serial_no);
  539. $ocean = common::excuteObjectSql($sql);
  540. if (!empty($ocean)) {
  541. $ocean['_isf_bol'] = $ocean['isf_bol'];
  542. if (empty($ocean['_isf_bol'])) {
  543. $ocean['_isf_bol'] = "AMAW" . $ocean['_h_bol'];
  544. }
  545. $isf_ss = md5(md5($ocean['_isf_bol']));
  546. $isf_ss = substr($isf_ss, 7) . substr($isf_ss, 0, 7);
  547. //ETA Dest的计算逻辑移除
  548. // most update status
  549. $_schemas = $_REQUEST["_schemas"];
  550. $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 "
  551. . ", fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un FROM public.online_ocean "
  552. . "where serial_no= '" . $ocean["serial_no"] . "'";
  553. if (!empty($_schemas)) {
  554. $mostStatusSql .= " and order_from='" . $_schemas . "'";
  555. }
  556. $mostStatus = common::excuteObjectSql($mostStatusSql);
  557. $state = -1;
  558. if (!empty($mostStatus["last_status_315_code"])) {
  559. //desc 逻辑处理取消
  560. $state = common::getStatusStage($mostStatus["last_status_315_code"]);
  561. }
  562. //请求地图是需要的参数
  563. $uncode = "'";
  564. if ($mostStatus["place_of_receipt_un"] != $mostStatus["fport_of_loading_un"]) {
  565. $uncode .= $mostStatus["place_of_receipt_un"];
  566. }
  567. $uncode .= "'|'" . $mostStatus["fport_of_loading_un"] . "'|'" . $mostStatus["mport_of_discharge_un"] . "'|'";
  568. if ($mostStatus["mport_of_discharge_un"] != $mostStatus["place_of_delivery_un"]) {
  569. $uncode .= $mostStatus["place_of_delivery_un"];
  570. }
  571. $uncode .= "'";
  572. }
  573. $vueData = $this->returnOceanDetailData($ocean,$state);
  574. //处理shipment data暂时写死
  575. $simplexData = $vueData['shipmentData'];
  576. //处理transportInfo信息数据
  577. $transportInfo = $vueData['transportInfo'];
  578. //处理basicInfo信息数据
  579. $basicInfo = $vueData['basicInfo'];
  580. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  581. $businessPartners = $vueData['businessPartners'];
  582. //处理routes 转船可能有多个情况
  583. $routes = $vueData['routes'];
  584. //处理marksAndDescription
  585. $marksAndDescription = $vueData['marksAndDescription'];
  586. //处理ocean_reference
  587. $ref_no = array();
  588. $ref_arr = common::excuteListSql("select * from ocean_reference where lower(serial_no) = '" . strtolower($serial_no) . "'");
  589. if(!empty($ref_arr)){
  590. foreach($ref_arr as $ref) {
  591. $ref_no[] = array("label"=>$ref["ref_code"],"value"=>$ref["ref_value"]);
  592. }
  593. }
  594. //处理Container :配置Ocean_Container字段 UI 需要的字段有:Container.no Packing,quantity,Gross weight(kg),Gross weight(LB),CBM,seal#,size.service
  595. $ocean_container_column = array();
  596. $container_column = column::getInstance()->getDisplayColumnAll('Ocean_Container');
  597. foreach($container_column as $cc){
  598. $ocean_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],"formatter" =>"","type" =>"normal");
  599. }
  600. $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . ",net_lbs from oc_container where lower(serial_no) = '" . strtolower($serial_no) . "'";
  601. $rss = common::excuteListSql($sql);
  602. $quantity_unit = array();
  603. $g_weight_tolal = 0;
  604. $ch_weight_tolal = 0;
  605. $ch_weight_tolal_grs_lbs = 0;
  606. $cbm_tolal = 0;
  607. foreach ($rss as $key => $rs) {
  608. $unit = $rs['unit'];
  609. if (array_key_exists($unit, $quantity_unit)) {
  610. $quantity_unit[$unit] = $quantity_unit[$unit] + $rs['qty'];
  611. } else {
  612. $quantity_unit[$unit] = $rs['qty'];
  613. }
  614. $g_weight_tolal += $rs['grs_kgs'];
  615. $ch_weight_tolal += $rs['net_lbs'];
  616. $ch_weight_tolal_grs_lbs += $rs['grs_lbs'];
  617. $cbm_tolal += $rs['cbm'];
  618. //特殊处理weight
  619. if(!empty($rss[$key]['grs_kgs'])){
  620. $rss[$key]['grs_kgs'] = $rs['grs_kgs']."KG";
  621. }
  622. if(!empty($rss[$key]['grs_lbs'])){
  623. $rss[$key]['grs_lbs'] = $rs['grs_lbs']."LB";
  624. }
  625. }
  626. $quantity_tolal = "";
  627. foreach($quantity_unit as $uk => $uv){
  628. $quantity_tolal.=$uv." ".$uk." ";
  629. }
  630. $ch_weight_tolal = empty($ch_weight_tolal) ? $ch_weight_tolal_grs_lbs : $ch_weight_tolal;
  631. $g_weight_tolal = sprintf("%.3f", $g_weight_tolal);
  632. $ch_weight_tolal = sprintf("%.3f", $ch_weight_tolal);
  633. $cbm_tolal = sprintf("%.4f", $cbm_tolal);
  634. //Containers信息
  635. $containers = array("container_column"=>$ocean_container_column,"container_data" =>$rss);
  636. //Packing信息
  637. $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $ch_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
  638. /* Container Status */
  639. //数据库里配置好
  640. //$sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container_Status') . " from oc_container_v where lower(serial_no) = '" . strtolower($serial_no) . "'";
  641. $ctnr_sql = "SELECT oc.ctnr, oc.serial_no,oc.size FROM oc_container oc LEFT JOIN ocean o ON oc.serial_no = o.serial_no
  642. WHERE o.serial_no='$serial_no'";
  643. $ctnr_data = common::excuteListSql($ctnr_sql);
  644. $containerStatusData = array();
  645. foreach ($ctnr_data as $cd){
  646. $ctnr_status_sql = "select s.source_id, s.event_base as event,
  647. to_char(to_timestamp(s.event_date, 'YYYYMMDD'), 'YYYY-MM-DD') as eventdate,
  648. to_char(to_timestamp(s.event_time, 'HH24MI'), 'HH24:MI') as eventtime,
  649. e.description,s.event_type as eventtype,
  650. s.event_code as eventcode, s.event_city as eventcity
  651. from public.ra_online_container_status_v s
  652. left join ra_online_edi_event e on s.event_base = e.ra_name
  653. where s.serial_no = '" . pg_escape_string($cd['serial_no']) . "'
  654. and s.container_no = '" . pg_escape_string($cd['ctnr']) . "' and is_display = true
  655. order by to_timestamp(s.event_date, 'YYYYMMDD') asc,
  656. to_timestamp(s.event_time, 'HH24MI') asc,
  657. e.ra_order asc";
  658. $ctnr_status = common::excuteListSql($ctnr_status_sql);
  659. //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
  660. $container_status_column = array("EE","I","AE","VD","VA");
  661. $containerStatusDataTemp = array();
  662. $ctnr_uncodes = "";
  663. $content = array();
  664. foreach($container_status_column as $status){
  665. foreach($ctnr_status as $event){
  666. if(strtolower($event['event']) == strtolower($status)){
  667. $eventdate = $event["eventdate"];
  668. if (empty($event["source_id"]) || $event["source_id"]==0) {
  669. $eventdate.= " " . $event["eventtime"];
  670. }
  671. $location_code = $event["eventcode"];
  672. $content[] = array("title" =>$event['description'],"date"=>$eventdate,"country"=>$location_code);
  673. $ctnr_uncodes .=$location_code.";";
  674. }
  675. }
  676. }
  677. //查询全部uncode timezone
  678. $uncode_rs = common::getCityPortsInfo($ctnr_uncodes);
  679. //循环去回填时区
  680. foreach($content as $ck => $cv){
  681. $content[$ck]['timezone'] = $uncode_rs[$cv['country']];
  682. }
  683. $containerStatusDataTemp['label'] = $cd['ctnr']." / ".$cd['size'];
  684. $containerStatusDataTemp['content'] = $content;
  685. $containerStatusData[] = $containerStatusDataTemp;
  686. }
  687. //Milestones info 列名固定
  688. $Milestones = common::getMilestonesInfo($ocean);
  689. //页面固定写死的信息
  690. $document_column = array();
  691. $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
  692. $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
  693. $document_data = array();
  694. $document = _getViewDocType($_REQUEST["_schemas"]);
  695. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  696. $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'])."'");
  697. if (!empty($document)) {
  698. foreach ($document as $v) {
  699. $file_type = $v['display_name'];
  700. $file_arr = $this->getFileByHbol($ocean['_m_bol'], $ocean['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE,$ocean['_job_bol']) ;
  701. $tar = json_decode($ocean_can_view_file,true);
  702. if(!empty($tar[$v['display_name']])){
  703. foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
  704. switch ($v['display_name']) {
  705. case 'HBL':
  706. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  707. from ra_online_doc_upload
  708. 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']."'
  709. order by id desc";
  710. break;
  711. case 'MBL':
  712. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  713. from ra_online_doc_upload
  714. 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']."'
  715. order by id desc";
  716. break;
  717. case 'Others':
  718. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  719. from ra_online_doc_upload
  720. 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']."'
  721. order by id desc";
  722. break;
  723. default:
  724. $sql = "";
  725. break;
  726. }
  727. if (!empty($sql)) {
  728. $rss = common::excuteListSql($sql);
  729. foreach ($rss as $rs) {
  730. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  731. $file_arr[] = array("url"=>$OutFileURL."/download.php?_schemas=&a=".base64_encode(base64_encode($rs['serial_no'])),
  732. "file_name" => $rs['file_name'],
  733. "detail"=>$rs['upload_date'],
  734. "can_delete"=>_getLoginName() == $rs['upload_by'],
  735. "from_system" =>'TOPOCEAN_KSMART');
  736. }else{
  737. $file_arr[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  738. "file_name" => $rs['file_name'],
  739. "detail"=>$rs['upload_date'],
  740. "can_delete"=>_getLoginName() == $rs['upload_by'],
  741. "from_system" =>'');
  742. }
  743. }
  744. }
  745. }
  746. }
  747. //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
  748. //按现在的逻辑,有值才会显示
  749. foreach($file_arr as $f){
  750. $document_data[] = array("file_type"=>$file_type,"file"=>$f);
  751. }
  752. }
  753. }
  754. $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
  755. $emailRecords = $this->getCommunicationNew($ocean["serial_no"]);
  756. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $ocean["serial_no"] . "' order by id desc limit 1");
  757. $email = $this->getEmail($ocean["serial_no"]);
  758. $email['cc_email'] = $cc_email;
  759. $email['emailRecords'] = $emailRecords;
  760. global $_COPYRIGHT;
  761. $data = array('transportInfo' => $transportInfo,
  762. 'basicInfo' => $basicInfo,
  763. 'businessPartners' => $businessPartners,
  764. 'ref_no' => $ref_no,
  765. 'packing' => $packing,
  766. 'marksAndDescription' => $marksAndDescription,
  767. 'containers' => $containers,
  768. 'simplexData' =>$simplexData,
  769. 'containerStatusData' => $containerStatusData,
  770. 'document_info' => $document_info,
  771. 'containers' => $containers,
  772. 'Milestones' => $Milestones,
  773. 'routes' => $routes,
  774. 'email' => $email,
  775. 'ams_ss' => md5(md5($ocean['serial_no'])),
  776. 'isf_ss' => $isf_ss,
  777. '_schemas' =>$_schemas,
  778. 'uncode' =>$uncode,
  779. 'serial_no' =>$serial_no,
  780. 'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
  781. 'canEdiVgm' => _canEdiVgm(),
  782. 'canViewAMSLog'=>_canViewAMSLog(),
  783. 'canViewISFLog'=>_canViewISFLog(),
  784. 'copyright' =>$_COPYRIGHT);
  785. common::echo_json_encode(200,$data);
  786. exit();
  787. }
  788. private function _ocean_excel() {
  789. $sql = common::deCode($_POST ['tmp_search'], 'D');
  790. $sql = substr($sql, 0, strripos($sql, " limit"));
  791. if(!empty($sql)){
  792. $rs = common::excuteListSql($sql);
  793. }
  794. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  795. foreach($rs as $index => $val) {
  796. //返回加密serial_no
  797. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  798. $rs[$index]["mode"] = "Ocean Freight";
  799. //status 改为ocean_milestone里的信息
  800. $rs[$index]["Status"] = $rs[$index]["new_status"];
  801. //以下新增的origin是 shipper和consignee的地址
  802. if(array_key_exists("Origin", $val)){
  803. $rs[$index]["Origin"] = utils::outDisplayForMerge($val['Origin'],$val['_consignee_city']);
  804. }
  805. }
  806. common::echo_json_encode(200,array("msg"=>"success","Data" => $rs));
  807. exit;
  808. }
  809. private function _ams_isf_log(){
  810. global $cbpdb;
  811. $ams_ss = $_POST['ams_ss'];
  812. $isf_ss = $_POST['isf_ss'];
  813. $amsLog = array();
  814. //页面固定写死的信息
  815. $amsLog_column = array();
  816. $amsLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"dateTime");
  817. $amsLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  818. $amsLog_column[] = array("title" =>"Name","field" =>"isams_submit","formatter" =>"","type" =>"normal");
  819. $amsLog_column[] = array("title" =>"Description","field" =>"amslog","formatter" =>"","type" =>"normal");
  820. $amsLog["amsLog_column"] = $amsLog_column;
  821. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  822. $amsLog["data"] = array();
  823. if (_canViewAMSLog()) {
  824. $s = $ams_ss;
  825. //$s = "PDLA200127H";
  826. if (!empty($s)) {
  827. //$cc = $cbpdb->GetAll("select distinct h_bol from ams_information where md5(md5(from_serial_no)) = '" . pg_escape_string($s) . "'");
  828. $cc = $cbpdb->GetAll("select distinct h_bol from ams_information where h_bol = '" . pg_escape_string($s) . "'");
  829. foreach ($cc as $v){
  830. $amses[] = $cbpdb->GetAll("select * from ams_info where h_bol = '" . pg_escape_string($v['h_bol']) . "'");
  831. }
  832. //考虑一个情况
  833. if (utils::count($amses) > 0) {
  834. $ams = $amses[0];
  835. $carrier_hbol = substr($ams[0]['m_bol'], 4);
  836. $carrier_scac = substr($ams[0]['m_bol'], 0, 4);
  837. if (empty($ams[0]['h_bol'])){
  838. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  839. $amsLog["data"] = array();
  840. }else{
  841. $log = $cbpdb->GetAll("select cbpreplytime as atime, amslog, cbperrorcode, isams_submit
  842. from v_e_amslog where hbol = '" . pg_escape_string($ams[0]['h_bol']) . "'
  843. and split_part(stationname, ',', 1) = split_part('" . pg_escape_string($ams[0]['station_name']) . "', ',', 1)
  844. order by cbpreplytime desc, substr(cbperrorcode, 2, 1) desc");
  845. $amsLog["msg"] = "";
  846. $amsLog["data"] = $log;
  847. }
  848. }
  849. }
  850. }
  851. $isfLog = array();
  852. //页面固定写死的信息
  853. $isfLog_column = array();
  854. $isfLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"dateTime");
  855. $isfLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  856. $isfLog_column[] = array("title" =>"Name","field" =>"isfsubmit","formatter" =>"","type" =>"normal");
  857. $isfLog_column[] = array("title" =>"Description","field" =>"isflog","formatter" =>"","type" =>"normal");
  858. $isfLog["isfLog_column"] = $isfLog_column;
  859. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  860. $isfLog["data"] = array();
  861. if (_canViewISFLog()) {
  862. if (!empty($isf_ss)) {
  863. $ss = $isf_ss;
  864. $len = strlen($ss);
  865. $b = substr($ss, $len - 7) . substr($ss, 0, $len - 7);
  866. if (empty($b)){
  867. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  868. $isfLog["data"] = array();
  869. }else{
  870. $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");
  871. }
  872. if (!empty($isf)) {
  873. if (!empty($isf['dob'])){
  874. $isf['dob'] = date("m/d/Y", strtotime($isf['dob']));
  875. }
  876. $msg = $cbpdb->GetAll("select cbpreplytime as atime, isflog, cbperrorcode, isfsubmit, hbol
  877. from v_e_isflog where (case when coalesce(isf_no, '')<>''
  878. then isf_no = '" . pg_escape_string($isf["isf_no"]) . "' else hbol = '" . pg_escape_string($isf["bol"]) . "'
  879. and stationname = '" . pg_escape_string($isf["station_name"]) . "' end)
  880. order by cbpreplytime desc, rowid desc");
  881. $isfLog["msg"] = "";
  882. $isfLog["data"] = $msg;
  883. }else{
  884. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  885. $isfLog["data"] = array();
  886. }
  887. }
  888. }
  889. $data =array("msg"=>"success",
  890. "canViewAMSLog" => _canViewAMSLog(),
  891. "canViewISFLog" => _canViewISFLog(),
  892. "amsLog" =>$amsLog,
  893. "isfLog" =>$isfLog);
  894. common::echo_json_encode(200,$data);
  895. exit;
  896. }
  897. private function getEmail($serial_no) {
  898. return utils::getEmail($serial_no);
  899. }
  900. private function getCommunicationNew($serial_no) {
  901. $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");
  902. $emialRecords =array();
  903. foreach ($list as $k => $v) {
  904. $msg =array();
  905. $msg["name"] = $v["add_by"];
  906. $msg["creatTime"] = $v["add_times"];
  907. $msg["content"] = urldecode($v["web_content"]);
  908. $emialRecords[] = $msg;
  909. }
  910. return $emialRecords;
  911. }
  912. /*
  913. * get file by hbol/destination
  914. * H:HBL
  915. * M: MBL
  916. * F: FL
  917. * I: C/I & Packing list
  918. */
  919. private function getFileByHbol($m_bol, $h_bol, $types, $m_bs, $display, $detail = FALSE,$job_no="") {
  920. $types = strtolower($types);
  921. $types = explode(";", $types);
  922. $m_bs = explode(";", $m_bs);
  923. $otheres = NULL;
  924. $filefilter = " ('TELEX') ";//过滤掉类型,单独配置 3537
  925. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  926. $file = array();
  927. foreach ($types as $k => $type) {
  928. $m_b = $m_bs[$k];
  929. if (strtolower($m_b) == 'm')
  930. $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";
  931. if (strtolower($m_b) == 'h')
  932. $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";
  933. if (strtolower($m_b) == 'a')
  934. $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";
  935. if (!empty($sql)) {
  936. $rss = common::excuteListSql($sql);
  937. foreach ($rss as $rs) {
  938. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  939. $file[] = array("url"=>$OutFileURL.'/download.php?_schemas=&a='.base64_encode(base64_encode($rs['serial_no'])),
  940. "file_name" => $rs['file_name'],
  941. "detail"=>$rs['upload_date'],
  942. "can_delete"=>_getLoginName() == $rs['upload_by'],
  943. "from_system" =>'TOPOCEAN_KSMART');
  944. }else {
  945. $file[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  946. "file_name" => $rs['file_name'],
  947. "detail"=>$rs['upload_date'],
  948. "can_delete"=>_getLoginName() == $rs['upload_by'],
  949. "from_system" =>'');
  950. }
  951. }
  952. }
  953. }
  954. return $file;
  955. }
  956. /*
  957. * download file
  958. */
  959. private function _download() {
  960. $url = common::deCode($_GET['url'], 'D');
  961. common::download_file($url);
  962. }
  963. private function save_vgm() {
  964. $schemas = $_POST["schemas"];
  965. $serial_no = common::deCode($_POST["serial_no"], 'D');
  966. $ocean = common::excuteObjectSql("select m_bol, master_base_number, from_station, h_bol from $schemas.ocean where serial_no='" . common::check_input($serial_no) . "'");
  967. $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"] . "'");
  968. $address = $contact["address_1"];
  969. if (!empty($address)) {
  970. $address .= "\r\n";
  971. }
  972. $address .= $contact["address_2"];
  973. if (!empty($address)) {
  974. $address .= "\r\n";
  975. }
  976. $address .= $contact["address_3"];
  977. if (!empty($address)) {
  978. $address .= "\r\n";
  979. }
  980. $address .= $contact["address_4"];
  981. $exists = common::excuteOneSql("select serial_no from $schemas.ocean_vgm_masterbasenumber where master_base_number ilike '" . $ocean["master_base_number"] . "'");
  982. global $db;
  983. $db->StartTrans();
  984. if (empty($_POST["is_send"])) {
  985. $_POST["is_send"] = 'f';
  986. }
  987. if (empty($exists)) {
  988. $db->Execute("insert into ocean_vgm_masterbasenumber (master_base_number, serial_no) values ('" . $ocean["master_base_number"] . "', '$serial_no');");
  989. $value["serial_no"] = $serial_no;
  990. $value["carrier_booking_no"] = $_POST["all_carrier_booking"];
  991. $value["modify_user"] = _getLoginName();
  992. $value["modify_time"] = "now()";
  993. $value["authorized_email"] = !empty($_POST["authorized_email"]) ? $_POST["authorized_email"] : "";
  994. $value["authorized_tel"] = !empty($_POST["authorized_tel"]) ? $_POST["authorized_tel"] : "";
  995. $value["authorized_company"] = !empty($_POST["submitter"]) ? $_POST["submitter"] : "";
  996. $value["signature"] = !empty($_POST["signature"]) ? $_POST["signature"] : "";
  997. $value["is_send"] = $_POST["is_send"];
  998. $value["action"] = "New";
  999. $value["type"] = "Shipper";
  1000. $value["m_bol"] = $ocean["m_bol"];
  1001. $value["master_base_number"] = $ocean["master_base_number"];
  1002. $value["shipper_id"] = $ocean["from_station"];
  1003. $value["shipper"] = $contact["company"];
  1004. $value["shipper_address"] = $address;
  1005. $value["shipper_contactname"] = $contact["contactname_1"];
  1006. $value["shipper_email"] = $contact["email_1"];
  1007. $value["shipper_fax"] = $contact["fax"];
  1008. $value["shipper_telephone"] = $contact["phone_1"];
  1009. $value["update_uuid"] = utils::uuid();
  1010. $value["h_bol"] = $ocean["h_bol"];
  1011. $value["from_station"] = $ocean["from_station"];
  1012. $sql = common::getInsertSqlNull("$schemas .ocean_vgm", $value);
  1013. $db->Execute($sql);
  1014. } else {
  1015. $serial_no = $exists;
  1016. $db->Execute("update ocean_vgm_masterbasenumber set id=id where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  1017. $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(),"
  1018. . "authorized_email='" . $_POST["authorized_email"] . "', authorized_tel='" . $_POST["authorized_tel"] . "', authorized_company='" . $_POST["submitter"] . "', signature='" . $_POST["signature"] . "', send_time=null "
  1019. . ", update_uuid='" . utils::uuid() . "' where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  1020. }
  1021. $db->Execute("delete from ocean_vgm_container where serial_no ilike '" . $serial_no . "';");
  1022. foreach ($_POST["container_no"] as $i => $cv) {
  1023. $value1["serial_no"] = $serial_no;
  1024. $value1["carrier_booking_no"] = !empty($_POST["carrier_booking_no"][$i]) ? $_POST["carrier_booking_no"][$i] : "";
  1025. $value1["ctnr"] = !empty($_POST["container_no"][$i]) ? $_POST["container_no"][$i] : "";
  1026. $value1["size"] = !empty($_POST["size"][$i]) ? $_POST["size"][$i] : "";
  1027. $value1["vgm_weight"] = !empty($_POST["vgm_weight"][$i]) ? $_POST["vgm_weight"][$i] : "";
  1028. $value1["unit"] = !empty($_POST["vgm_kg_lg"][$i]) ? $_POST["vgm_kg_lg"][$i] : "";
  1029. $value1["vgm_time"] = !empty($_POST["vgm_date"][$i]) ? $_POST["vgm_date"][$i] : "";
  1030. $value1["cargo_weight_kgs"] = !empty($_POST["cargo_weight_kg"][$i]) ? $_POST["cargo_weight_kg"][$i] : "";
  1031. $value1["cargo_weight_lbs"] = !empty($_POST["cargo_weight_lb"][$i]) ? $_POST["cargo_weight_lb"][$i] : "";
  1032. $value1["vgm_method"] = !empty($_POST["vgm_method"][$i]) ? $_POST["vgm_method"][$i] : "";
  1033. $value1["master_base_number"] = $ocean["master_base_number"];
  1034. $sql = common::getInsertSqlNull("$schemas.ocean_vgm_container", $value1);
  1035. $db->Execute($sql);
  1036. }
  1037. if ($db->CompleteTrans() === FALSE) {
  1038. return "error";
  1039. } else {
  1040. return "success";
  1041. }
  1042. }
  1043. private function getOceanDetail($serial_no) {
  1044. $_schemas = $_REQUEST['_schemas'];
  1045. if($_schemas == 'public'){
  1046. $_schemas = "ocean";
  1047. }
  1048. $sql = "SELECT m_eta as _m_eta, h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
  1049. o.* ,sh.*, cn.* ,aa.*,dd.*,oo.*
  1050. from ocean o
  1051. LEFT JOIN LATERAL ( SELECT tracking_no as _tracking_no,shippr_uncode,shipper_city,
  1052. consignee_uncode,consignee_city,incoterms,
  1053. fport_of_loading_un,mport_of_discharge_un,
  1054. place_of_receipt_un,place_of_delivery_un,
  1055. port_of_transshipment_un,
  1056. CASE
  1057. WHEN (m_iffbcf is not null and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Created'::text
  1058. WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Cargo Received'::text
  1059. WHEN (m_iffdep is not null and m_iffarr is null and m_iffafd is null) THEN 'Departed'::text
  1060. WHEN (m_iffarr is not null and m_iffafd is null) THEN 'Arrived'::text
  1061. WHEN (m_iffafd is not null) THEN 'Completed'::text
  1062. ELSE 'Created'::text
  1063. END AS new_status
  1064. FROM public.online_ocean oo WHERE oo.serial_no::text = o.serial_no::text) oo ON true
  1065. LEFT JOIN LATERAL ( SELECT company as cn_company,
  1066. address_1 as cn_address_1,
  1067. address_2 as cn_address_2,
  1068. address_3 as cn_address_3,
  1069. address_4 as cn_address_4,
  1070. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  1071. phone_1 as cn_phone
  1072. FROM $_schemas.contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
  1073. LEFT JOIN LATERAL ( SELECT company as sh_company,
  1074. address_1 as sh_address_1,
  1075. address_2 as sh_address_2,
  1076. address_3 as sh_address_3,
  1077. address_4 as sh_address_4,
  1078. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  1079. phone_1 as sh_phone
  1080. FROM $_schemas.contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
  1081. LEFT JOIN LATERAL ( SELECT company as aa_company,
  1082. address_1 as aa_address_1,
  1083. address_2 as aa_address_2,
  1084. address_3 as aa_address_3,
  1085. address_4 as aa_address_4,
  1086. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  1087. phone_1 as aa_phone
  1088. FROM $_schemas.contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
  1089. LEFT JOIN LATERAL ( SELECT company as dd_company,
  1090. address_1 as dd_address_1,
  1091. address_2 as dd_address_2,
  1092. address_3 as dd_address_3,
  1093. address_4 as dd_address_4,
  1094. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  1095. phone_1 as dd_phone
  1096. FROM $_schemas.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
  1097. where lower(serial_no) = '" . strtolower($serial_no) . "'";
  1098. return $sql;
  1099. }
  1100. private function returnOceanDetailData($ocean,$state){
  1101. $data = array();
  1102. //处理shipment data
  1103. $ocean_milestone_status = common::excuteListSql("select code,
  1104. act_date,est_date,timezone
  1105. from ocean_milestone a
  1106. where a.serial_no='".$ocean["serial_no"]."' and code in('IFFREC','IFFONB','IFFDEP','IFFARR','IFFDEL')
  1107. order by id");
  1108. $ocean_milestone_status_code = array();
  1109. foreach($ocean_milestone_status as $oms){
  1110. $ocean_milestone_status_code[$oms['code']] = $oms;
  1111. }
  1112. if ($state < 1){
  1113. //未发生前
  1114. if(!empty($ocean_milestone_status_code['IFFDEP']['est_date'])){
  1115. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  1116. $ocean['f_etd'] = $ocean_milestone_status_code['IFFDEP']['est_date'];
  1117. }
  1118. } else{
  1119. if(!empty($ocean_milestone_status_code['IFFDEP']['act_date'])){
  1120. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  1121. $ocean['atd'] = $ocean_milestone_status_code['IFFDEP']['act_date'];
  1122. }
  1123. }
  1124. //先处理一下 ATD 和 ATA,在进行后面的取值
  1125. if(empty($ocean['atd'])){
  1126. $ocean['atd'] = $ocean['f_etd'];
  1127. }
  1128. if(empty($ocean['ata'])){
  1129. $ocean['ata'] = $ocean['m_eta'];
  1130. }
  1131. $simplexData = array();
  1132. //place_of_Receipt
  1133. $place_of_Receipt_stauts = array("index" =>1,"label" =>"Place of Receipt",
  1134. "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt_un'],"isArrival" =>$state >= 0 ? true : false);
  1135. $children = array();
  1136. if($state >= 1 && !empty($ocean_milestone_status_code['IFFREC']['act_date'])){
  1137. //发生后,未发生前没有
  1138. $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFREC']['act_date']);
  1139. }
  1140. $place_of_Receipt_stauts["children"] = $children;
  1141. $simplexData[] = $place_of_Receipt_stauts;
  1142. //port_of_Loading
  1143. $port_of_Loading_stauts = array("index" =>2,"label" =>"Port of Loading",
  1144. "path" =>$ocean['fport_of_loading_exp']."/".$ocean['fport_of_loading_un'],"isArrival" =>$state >= 1 ? true : false);
  1145. $children = array();
  1146. if ($state < 1){
  1147. $children[] = array("label" =>"Departure(ETD)","date" =>$ocean['f_etd']);
  1148. } else{
  1149. if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
  1150. $children[] = array("label" =>"On board","date" =>$ocean_milestone_status_code['IFFONB']['act_date']);
  1151. }
  1152. $children[] = array("label" =>"Departure(ATD)","date" =>$ocean['atd']);
  1153. }
  1154. $port_of_Loading_stauts["children"] = $children;
  1155. $simplexData[] = $port_of_Loading_stauts;
  1156. //Port of Discharge
  1157. $port_of_Discharge_status = array("index" =>3,"label" =>"Port of Discharge",
  1158. "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge_un'],"isArrival" =>$state >= 2 ? true : false);
  1159. $children = array();
  1160. // if ($state < 2){
  1161. // //未发生前
  1162. // if(!empty($ocean_milestone_status_code['IFFARR']['est_date'])){
  1163. // $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean_milestone_status_code['IFFARR']['est_date']);
  1164. // }else{
  1165. // //没有,取eta
  1166. // $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['m_eta']);
  1167. // }
  1168. // } else{
  1169. // if(!empty($ocean_milestone_status_code['IFFARR']['act_date'])){
  1170. // $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean_milestone_status_code['IFFARR']['act_date']);
  1171. // }
  1172. // }
  1173. //不需要判断是否发送,根据 milestone 和m_eta 的同步关系,这里m_eta 优先度最高
  1174. if ($state < 2){
  1175. $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['m_eta']);
  1176. }else{
  1177. $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean['ata']);
  1178. }
  1179. $port_of_Discharge_status["children"] = $children;
  1180. $simplexData[] = $port_of_Discharge_status;
  1181. //Place of Delivery
  1182. $place_of_Delivery_status = array("index" =>4,"label" =>"Place of Delivery",
  1183. "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery_un'],"isArrival" =>$state == 3 ? true : false);
  1184. $children = array();
  1185. if ($state < 3){
  1186. //未发生前
  1187. } else{
  1188. if(!empty($ocean_milestone_status_code['IFFDEL']['act_date'])){
  1189. $children[] = array("label" =>"Cargo handover/Delivered","date" =>$ocean_milestone_status_code['IFFDEL']['act_date']);
  1190. }
  1191. }
  1192. $simplexData[] = $place_of_Delivery_status;
  1193. $data['shipmentData'] = $simplexData;
  1194. //获取对应uncode 对应的时间
  1195. $uncodes = $ocean['fport_of_loading_un'].";".$ocean['mport_of_discharge_un'];
  1196. $codeinfo = common::getCityPortsInfo($uncodes);
  1197. //处理transportInfo信息数据
  1198. $transportInfo = array("Tracking No." =>$ocean['_tracking_no'],"status"=>$ocean['new_status'],"mode" => "Ocean Freight",
  1199. "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
  1200. "etd" =>$ocean['f_etd'],"atd" =>$ocean['atd'],
  1201. "etd_timezone" =>$codeinfo[$ocean['fport_of_loading_un']],
  1202. "atd_timezone" =>$codeinfo[$ocean['fport_of_loading_un']],
  1203. "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
  1204. "eta_timezone" =>$codeinfo[$ocean['mport_of_discharge_un']],
  1205. "ata_timezone" =>$codeinfo[$ocean['mport_of_discharge_un']]);
  1206. $data['transportInfo'] = $transportInfo;
  1207. //处理basicInfo信息数据
  1208. $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
  1209. $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
  1210. $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['carrier_booking'],
  1211. "PO_NO" =>$ocean['po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  1212. "Incoterm" =>$ocean['incoterms'],"Service_Type" =>$ocean['service']);
  1213. $data['basicInfo'] = $basicInfo;
  1214. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  1215. $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  1216. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  1217. $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  1218. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  1219. $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  1220. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  1221. $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  1222. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  1223. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  1224. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  1225. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  1226. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  1227. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  1228. $data['businessPartners'] = $businessPartners;
  1229. //处理routes 转船可能有多个情况
  1230. if ($ocean['is_vessel_direct'] <> "t"){
  1231. //不是直航
  1232. $routes = array(array("mode" =>"Ocean Freight","mode_label" =>"Sea", "origin" =>$ocean['shippr_uncode'],
  1233. "destination" => $ocean['port_of_transshipment_un'],
  1234. "etd" => $ocean['f_etd'],"atd" => $ocean['atd'],
  1235. "eta" =>$ocean['f_eta'],"ata" => $ocean['ata'],
  1236. "vessel" =>$ocean['f_vessel'],"voyageNo" =>$ocean['f_voyage']));
  1237. $routes[] = array("mode" =>"Ocean Freight", "mode_label" =>"Sea","origin" =>$ocean['port_of_transshipment_un'],
  1238. "destination" => $ocean['consignee_uncode'],
  1239. "etd" => $ocean['m_etd'],"atd" => $ocean['atd'],
  1240. "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
  1241. "vessel" =>$ocean['m_vessel'],"voyageNo" =>$ocean['m_voyage']);
  1242. }else{
  1243. $routes = array(array("mode" =>"Ocean Freight","mode_label" =>"Sea", "origin" =>$ocean['shippr_uncode'],
  1244. "destination" => $ocean['consignee_uncode'],
  1245. "etd" => $ocean['f_etd'],"atd" => $ocean['atd'],
  1246. "eta" =>$ocean['m_eta'],"ata" => $ocean['ata'],
  1247. "vessel" =>$ocean['f_vessel'],"voyageNo" =>$ocean['f_voyage']));
  1248. }
  1249. $data['routes'] = $routes;
  1250. //处理marksAndDescription
  1251. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description']);
  1252. $data['marksAndDescription'] = $marksAndDescription;
  1253. return $data;
  1254. }
  1255. }
  1256. ?>