ocean_order.class.php 77 KB

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