ocean_order.class.php 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386
  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 = 50;
  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. $sqlWhere_befrom_filterTag = $sqlWhere;
  353. //查询tag
  354. // IFFBCF Booking Confirmation Created
  355. // IFFCPU Cargo Pickup Cargo Received
  356. // IFFREC Cargo Arrived at Origin Cargo Received
  357. // IFFDEP Departure Departed
  358. // IFFARR Arrived at Final Destination Port Arrived
  359. // IFFAFD Arrived at Final Destination Completed
  360. if (!empty($_POST["filterTag"])) {
  361. if (utils::count($_POST['filterTag']) == 1){
  362. $filterTag = $_POST['filterTag'][0];
  363. }else{
  364. $filterTag = utils::implode(",", $_POST['filterTag']);
  365. }
  366. $_sqlwhere = "1<>1";
  367. if (stripos($filterTag, "Created") !== FALSE) {
  368. $_sqlwhere .= " or (dd.new_status = 'Created' or dd.new_status is null)";
  369. }
  370. if (stripos($filterTag, "Cargo Received") !== FALSE) {
  371. $_sqlwhere .= " or (dd.new_status = 'Cargo Received')";
  372. }
  373. if (stripos($filterTag, "Departure") !== FALSE) {
  374. $_sqlwhere .= " or (dd.new_status = 'Departed')";
  375. }
  376. if (stripos($filterTag, "Arrived") !== FALSE) {
  377. $_sqlwhere .= " or (dd.new_status = 'Arrived')";
  378. }
  379. if (stripos($filterTag, "Completed") !== FALSE) {
  380. $_sqlwhere .= " or (dd.new_status = 'Completed')";
  381. }
  382. if(strtolower($filterTag) <> "all" && !empty($filterTag)){
  383. $sqlWhere .= " and ($_sqlwhere)";
  384. }
  385. }
  386. $rc = $_POST ['rc'];
  387. //这里都要查询,除非多传几个参数回来
  388. if ($rc == - 1 || true) {
  389. $sql = $this->getOcanOrderSearchSql("All",$sqlWhere);
  390. $search_rc = common::excuteOneSql($sql);
  391. error_log("online_ocean_count_ALL_Search_SQL:".$sql);
  392. //移除filterTag
  393. $sqlWhere_bk = $sqlWhere_befrom_filterTag;
  394. $sql = $this->getOcanOrderSearchSql("All",$sqlWhere_bk);
  395. $rc = common::excuteOneSql($sql);
  396. error_log("online_ocean_count_ALL_SQL:".$sql);
  397. //Created
  398. $sql = $this->getOcanOrderSearchSql("Created",$sqlWhere_bk);
  399. $Created = common::excuteOneSql($sql);
  400. error_log("online_ocean_count_Created_SQL: ".$sql);
  401. //Cargo Received
  402. $sql = $this->getOcanOrderSearchSql("Cargo Received",$sqlWhere_bk);
  403. $Cargo_Received = common::excuteOneSql($sql);
  404. error_log("online_ocean_count_Cargo_Received_SQL: ".$sql);
  405. //Departed
  406. $sql = $this->getOcanOrderSearchSql("Departed",$sqlWhere_bk);
  407. $Departed = common::excuteOneSql($sql);
  408. error_log("online_ocean_count_Departed_SQL: ".$sql);
  409. //Arrived
  410. $sql = $this->getOcanOrderSearchSql("Arrived",$sqlWhere_bk);
  411. $Arrived = common::excuteOneSql($sql);
  412. error_log("online_ocean_count_Arrived_SQL: ".$sql);
  413. //Completed
  414. $sql = $this->getOcanOrderSearchSql("Completed",$sqlWhere_bk);
  415. $Completed = common::excuteOneSql($sql);
  416. error_log("online_ocean_count_Completed_SQL: ".$sql);
  417. if (!empty($_POST["filterTag"])) {
  418. $tagsList = array(array("name"=>"All","number"=>intval($rc),"type"=>"all","checked"=>utils::in_array('All', $_POST["filterTag"])? true : false),
  419. array("name"=>"Created","number"=>intval($Created),"type"=>"created","checked"=>utils::in_array('Created', $_POST["filterTag"])? true : false),
  420. array("name"=>"Cargo Received","number"=>intval($Cargo_Received),"type"=>"cargo_received","checked"=>utils::in_array('Cargo Received', $_POST["filterTag"])? true : false),
  421. array("name"=>"Departure","number"=>intval($Departed),"type"=>"departure","checked"=>utils::in_array('Departure', $_POST["filterTag"])? true : false),
  422. array("name"=>"Arrived","number"=>intval($Arrived),"type"=>"arrived","checked"=>utils::in_array('Arrived', $_POST["filterTag"])? true : false),
  423. array("name"=>"Completed","number"=>intval($Completed),"type"=>"completed","checked"=>utils::in_array('Completed', $_POST["filterTag"])? true : false));
  424. }else{
  425. //初始,前端有选择着带入选择
  426. $tagsList = array(array("name"=>"All","number"=>intval($rc),"type"=>"all","checked"=> true ),
  427. array("name"=>"Created","number"=>intval($Created),"type"=>"created","checked"=> false),
  428. array("name"=>"Cargo Received","number"=>intval($Cargo_Received),"type"=>"cargo_received","checked"=> false),
  429. array("name"=>"Departure","number"=>intval($Departed),"type"=>"departure","checked"=> false),
  430. array("name"=>"Arrived","number"=>intval($Arrived),"type"=>"arrived","checked"=> false),
  431. array("name"=>"Completed","number"=>intval($Completed),"type"=>"completed","checked"=>false));
  432. }
  433. $TransportList = array(
  434. array("name"=>"Ocean Freight","number"=>intval($rc),"checked"=>true,"icon"=>"#icon-icon_ocean_b"));
  435. //现在下载交给前端,后台预先只返回全部字段的列,
  436. $allColumn = column::getInstance()->getDisplayColumnAllReomveDefault('Ocean_Search');
  437. $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
  438. }
  439. $tp = ceil($rc / $ps);
  440. $order_by = " etd desc NULLS LAST, id";
  441. if (_isCustomerLogin()) {
  442. $order_by = " eta desc NULLS LAST, id";
  443. }
  444. if ($rc > 0) {
  445. $ocean_ref_sql = " LEFT JOIN LATERAL ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no
  446. FROM public.ocean_reference temp WHERE temp.serial_no = online_ocean.serial_no) aa ON true ";
  447. $ocean_status_sql = " LEFT JOIN LATERAL (select case when a.code='IFFBCF' then 'Created'
  448. when a.code='IFFCPU' then 'Cargo Received'
  449. when a.code='IFFREC' then 'Cargo Received'
  450. when a.code='IFFDEP' then 'Departed'
  451. when a.code='IFFARR' then 'Arrived'
  452. when a.code='IFFAFD' then 'Completed'
  453. else 'Created' END as new_status
  454. from ocean_milestone a
  455. where a.serial_no=online_ocean.serial_no
  456. and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
  457. and a.act_date is not null
  458. order by id desc limit 1) dd ON true ";
  459. $sql = "SELECT order_from as _schemas,serial_no as __serial_no, serial_no,
  460. h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,
  461. CASE
  462. WHEN dd.new_status is null THEN 'Created'::text
  463. ELSE dd.new_status::text
  464. END AS new_status, ".
  465. column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.online_ocean $ocean_ref_sql $ocean_status_sql" . $sqlWhere .
  466. " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;
  467. $rs = common::excuteListSql($sql);
  468. error_log("online_ocean_search_SQL: ".$sql);
  469. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  470. foreach($rs as $index => $val) {
  471. //返回加密serial_no
  472. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  473. $rs[$index]["mode"] = "Ocean Freight";
  474. //status 改为ocean_milestone里的信息
  475. $rs[$index]["Status"] = $rs[$index]["new_status"];
  476. //以下新增的origin是 shipper和consignee的地址
  477. if(array_key_exists("Origin", $val)){
  478. $rs[$index]["Origin"] = utils::outDisplayForMerge($val['Origin'],$val['_consignee_city']);
  479. }
  480. }
  481. $arrTmp = array('searchData' => $rs,
  482. 'tagsList' => $tagsList,
  483. 'TransportList' => $TransportList,
  484. 'allColums' => $allBookingColumns,
  485. 'canEdiVgm' => _canEdiVgm(),
  486. 'rc' => $search_rc,
  487. 'ps' => $ps,
  488. 'cp' => $cp,
  489. 'tp' => $tp,
  490. 'tmp_search' => common::deCode($sql, 'E'),
  491. 'type' => common::check_input($_POST ['_ntype']));
  492. } else {
  493. $arrTmp = array('searchData' => array(),
  494. 'tagsList' => $tagsList,
  495. 'TransportList' => $TransportList,
  496. 'allColums' => $allBookingColumns,
  497. 'canEdiVgm' => _canEdiVgm(),
  498. 'rc' => $rc,
  499. 'ps' => $ps,
  500. 'cp' => $cp,
  501. 'tp' => $tp,
  502. 'tmp_search' => common::deCode($sql, 'E'),
  503. 'type' => common::check_input($_POST ['_ntype']));
  504. }
  505. common::echo_json_encode(200,$arrTmp);
  506. exit();
  507. }
  508. private function _ocean_detail() {
  509. $serial_no = common::deCode($_GET['a'], 'D');
  510. $sql = $this->getOceanDetail($serial_no);
  511. error_log($sql);
  512. $ocean = common::excuteObjectSql($sql);
  513. if (!empty($ocean)) {
  514. $ocean['_isf_bol'] = $ocean['isf_bol'];
  515. if (empty($ocean['_isf_bol'])) {
  516. $ocean['_isf_bol'] = "AMAW" . $ocean['_h_bol'];
  517. }
  518. $isf_ss = md5(md5($ocean['_isf_bol']));
  519. $isf_ss = substr($isf_ss, 7) . substr($isf_ss, 0, 7);
  520. //ETA Dest的计算逻辑移除
  521. // most update status
  522. $_schemas = $_REQUEST["_schemas"];
  523. $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 "
  524. . ", fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un FROM public.online_ocean "
  525. . "where serial_no= '" . $ocean["serial_no"] . "'";
  526. if (!empty($_schemas)) {
  527. $mostStatusSql .= " and order_from='" . $_schemas . "'";
  528. }
  529. $mostStatus = common::excuteObjectSql($mostStatusSql);
  530. $state = -1;
  531. if (!empty($mostStatus["last_status_315_code"])) {
  532. //desc 逻辑处理取消
  533. $state = common::getStatusStage($mostStatus["last_status_315_code"]);
  534. }
  535. //请求地图是需要的参数
  536. $uncode = "'";
  537. if ($mostStatus["place_of_receipt_un"] != $mostStatus["fport_of_loading_un"]) {
  538. $uncode .= $mostStatus["place_of_receipt_un"];
  539. }
  540. $uncode .= "'|'" . $mostStatus["fport_of_loading_un"] . "'|'" . $mostStatus["mport_of_discharge_un"] . "'|'";
  541. if ($mostStatus["mport_of_discharge_un"] != $mostStatus["place_of_delivery_un"]) {
  542. $uncode .= $mostStatus["place_of_delivery_un"];
  543. }
  544. $uncode .= "'";
  545. }
  546. $vueData = $this->returnOceanDetailData($ocean,$state);
  547. //处理shipment data暂时写死
  548. $simplexData = $vueData['shipmentData'];
  549. //处理transportInfo信息数据
  550. $transportInfo = $vueData['transportInfo'];
  551. //处理basicInfo信息数据
  552. $basicInfo = $vueData['basicInfo'];
  553. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  554. $businessPartners = $vueData['businessPartners'];
  555. //处理routes 转船可能有多个情况
  556. $routes = $vueData['routes'];
  557. //处理marksAndDescription
  558. $marksAndDescription = $vueData['marksAndDescription'];
  559. //处理ocean_reference
  560. $ref_no = array();
  561. $ref_arr = common::excuteListSql("select * from ocean_reference where lower(serial_no) = '" . strtolower($serial_no) . "'");
  562. if(!empty($ref_arr)){
  563. foreach($ref_arr as $ref) {
  564. $ref_no[] = array("label"=>$ref["ref_code"],"value"=>$ref["ref_value"]);
  565. }
  566. }
  567. //处理Container :配置Ocean_Container字段 UI 需要的字段有:Container.no Packing,quantity,Gross weight(kg),Gross weight(LB),CBM,seal#,size.service
  568. $ocean_container_column = array();
  569. $container_column = column::getInstance()->getDisplayColumnAll('Ocean_Container');
  570. foreach($container_column as $cc){
  571. $ocean_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],"formatter" =>"","type" =>"normal");
  572. }
  573. $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . " from oc_container where lower(serial_no) = '" . strtolower($serial_no) . "'";
  574. $rss = common::excuteListSql($sql);
  575. $quantity_tolal = 0;
  576. $packages = "CTN";
  577. $g_weight_tolal = 0;
  578. $ch_weight_tolal = 0;
  579. $cbm_tolal = 0;
  580. foreach ($rss as $key => $rs) {
  581. $quantity_tolal += $rs['qty'];
  582. $g_weight_tolal += $rs['grs_kgs'];
  583. $ch_weight_tolal += $rs['grs_lbs'];
  584. $cbm_tolal += $rs['cbm'];
  585. $packages = $rs['unit'];
  586. //特殊处理weight
  587. if(!empty($rss[$key]['grs_kgs'])){
  588. $rss[$key]['grs_kgs'] = $rs['grs_kgs']."KG";
  589. }
  590. if(!empty($rss[$key]['grs_lbs'])){
  591. $rss[$key]['grs_lbs'] = $rs['grs_lbs']."LB";
  592. }
  593. }
  594. //Containers信息
  595. $containers = array("container_column"=>$ocean_container_column,"container_data" =>$rss);
  596. //Packing信息
  597. $packing = array("Quantity/Unit"=>$quantity_tolal." ".$packages,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $ch_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
  598. /* Container Status */
  599. //数据库里配置好
  600. //$sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container_Status') . " from oc_container_v where lower(serial_no) = '" . strtolower($serial_no) . "'";
  601. $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
  602. WHERE o.serial_no='$serial_no'";
  603. $ctnr_data = common::excuteListSql($ctnr_sql);
  604. $containerStatusData = array();
  605. foreach ($ctnr_data as $cd){
  606. $ctnr_status_sql = "select s.source_id, s.event_base as event,
  607. to_char(to_timestamp(s.event_date, 'YYYYMMDD'), 'YYYY-MM-DD') as eventdate,
  608. to_char(to_timestamp(s.event_time, 'HH24MI'), 'HH24:MI') as eventtime,
  609. e.description,s.event_type as eventtype,
  610. s.event_code as eventcode, s.event_city as eventcity
  611. from public.ra_online_container_status_v s
  612. left join ra_online_edi_event e on s.event_base = e.ra_name
  613. where s.serial_no = '" . pg_escape_string($cd['serial_no']) . "'
  614. and s.container_no = '" . pg_escape_string($cd['ctnr']) . "' and is_display = true
  615. order by to_timestamp(s.event_date, 'YYYYMMDD') asc,
  616. to_timestamp(s.event_time, 'HH24MI') asc,
  617. e.ra_order asc";
  618. $ctnr_status = common::excuteListSql($ctnr_status_sql);
  619. //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
  620. $container_status_column = array("EE","I","AE","VD","VA");
  621. $containerStatusDataTemp = array();
  622. $content = array();
  623. foreach($container_status_column as $status){
  624. foreach($ctnr_status as $event){
  625. if(strtolower($event['event']) == strtolower($status)){
  626. $eventdate = $event["eventdate"];
  627. if (empty($event["source_id"]) || $event["source_id"]==0) {
  628. $eventdate.= " " . $event["eventtime"];
  629. }
  630. $location_code = $event["eventtype"] . "," . $event["eventcode"];
  631. $content[] = array("title" =>$event['description'],"date"=>$eventdate,"country"=>$location_code);
  632. }
  633. }
  634. }
  635. $containerStatusDataTemp['label'] = $cd['ctnr']." / ".$cd['size'];
  636. $containerStatusDataTemp['content'] = $content;
  637. $containerStatusData[] = $containerStatusDataTemp;
  638. }
  639. //Milestones info 列名固定
  640. $Milestones = common::getMilestonesInfo($ocean);
  641. //页面固定写死的信息
  642. $document_column = array();
  643. $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
  644. $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
  645. $document_data = array();
  646. $document = _getViewDocType($_REQUEST["_schemas"]);
  647. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  648. $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'])."'");
  649. if (!empty($document)) {
  650. foreach ($document as $v) {
  651. $file_type = $v['display_name'];
  652. $file_arr = $this->getFileByHbol($ocean['_m_bol'], $ocean['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE,$ocean['_job_bol']) ;
  653. $tar = json_decode($ocean_can_view_file,true);
  654. if(!empty($tar[$v['display_name']])){
  655. foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
  656. switch ($v['display_name']) {
  657. case 'HBL':
  658. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  659. from ra_online_doc_upload
  660. 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']."'
  661. order by id desc";
  662. break;
  663. case 'MBL':
  664. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  665. from ra_online_doc_upload
  666. 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']."'
  667. order by id desc";
  668. break;
  669. case 'Others':
  670. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  671. from ra_online_doc_upload
  672. 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']."'
  673. order by id desc";
  674. break;
  675. default:
  676. $sql = "";
  677. break;
  678. }
  679. if (!empty($sql)) {
  680. $rss = common::excuteListSql($sql);
  681. foreach ($rss as $rs) {
  682. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  683. $file_arr[] = array("url"=>$OutFileURL."/download.php?_schemas=&a=".base64_encode(base64_encode($rs['serial_no'])),
  684. "file_name" => $rs['file_name'],
  685. "detail"=>$rs['upload_date'],
  686. "can_delete"=>_getLoginName() == $rs['upload_by'],
  687. "from_system" =>'TOPOCEAN_KSMART');
  688. }else{
  689. $file_arr[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  690. "file_name" => $rs['file_name'],
  691. "detail"=>$rs['upload_date'],
  692. "can_delete"=>_getLoginName() == $rs['upload_by'],
  693. "from_system" =>'');
  694. }
  695. }
  696. }
  697. }
  698. }
  699. //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
  700. //按现在的逻辑,有值才会显示
  701. foreach($file_arr as $f){
  702. $document_data[] = array("file_type"=>$file_type,"file"=>$f);
  703. }
  704. }
  705. }
  706. $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
  707. $emailRecords = $this->getCommunicationNew($ocean["serial_no"]);
  708. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $ocean["serial_no"] . "' order by id desc limit 1");
  709. $email = $this->getEmail($ocean["serial_no"]);
  710. $email['cc_email'] = $cc_email;
  711. $email['emailRecords'] = $emailRecords;
  712. global $_COPYRIGHT;
  713. $data = array('transportInfo' => $transportInfo,
  714. 'basicInfo' => $basicInfo,
  715. 'businessPartners' => $businessPartners,
  716. 'ref_no' => $ref_no,
  717. 'packing' => $packing,
  718. 'marksAndDescription' => $marksAndDescription,
  719. 'containers' => $containers,
  720. 'simplexData' =>$simplexData,
  721. 'containerStatusData' => $containerStatusData,
  722. 'document_info' => $document_info,
  723. 'containers' => $containers,
  724. 'Milestones' => $Milestones,
  725. 'routes' => $routes,
  726. 'email' => $email,
  727. 'ams_ss' => md5(md5($ocean['serial_no'])),
  728. 'isf_ss' => $isf_ss,
  729. '_schemas' =>$_schemas,
  730. 'uncode' =>$uncode,
  731. 'serial_no' =>$serial_no,
  732. 'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
  733. 'canEdiVgm' => _canEdiVgm(),
  734. 'canViewAMSLog'=>_canViewAMSLog(),
  735. 'canViewISFLog'=>_canViewISFLog(),
  736. 'copyright' =>$_COPYRIGHT);
  737. common::echo_json_encode(200,$data);
  738. exit();
  739. }
  740. private function _ocean_excel() {
  741. //现在下载交给前端,后台最后只返回全部字段的列,
  742. $allColumn = column::getInstance()->getDisplayColumnAll('Ocean_Search');
  743. $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
  744. common::echo_json_encode(200,array("msg"=>"success","allColums" => $allBookingColumns));
  745. exit;
  746. }
  747. private function _ams_isf_log(){
  748. global $cbpdb;
  749. $ams_ss = $_POST['ams_ss'];
  750. $isf_ss = $_POST['isf_ss'];
  751. $amsLog = array();
  752. //页面固定写死的信息
  753. $amsLog_column = array();
  754. $amsLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"dateTime");
  755. $amsLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  756. $amsLog_column[] = array("title" =>"Name","field" =>"isams_submit","formatter" =>"","type" =>"normal");
  757. $amsLog_column[] = array("title" =>"Description","field" =>"amslog","formatter" =>"","type" =>"normal");
  758. $amsLog["amsLog_column"] = $amsLog_column;
  759. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  760. $amsLog["data"] = array();
  761. if (_canViewAMSLog()) {
  762. $s = $ams_ss;
  763. //$s = "PDLA200127H";
  764. if (!empty($s)) {
  765. //$cc = $cbpdb->GetAll("select distinct h_bol from ams_information where md5(md5(from_serial_no)) = '" . pg_escape_string($s) . "'");
  766. $cc = $cbpdb->GetAll("select distinct h_bol from ams_information where h_bol = '" . pg_escape_string($s) . "'");
  767. foreach ($cc as $v){
  768. $amses[] = $cbpdb->GetAll("select * from ams_info where h_bol = '" . pg_escape_string($v['h_bol']) . "'");
  769. }
  770. //考虑一个情况
  771. if (utils::count($amses) > 0) {
  772. $ams = $amses[0];
  773. $carrier_hbol = substr($ams[0]['m_bol'], 4);
  774. $carrier_scac = substr($ams[0]['m_bol'], 0, 4);
  775. if (empty($ams[0]['h_bol'])){
  776. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  777. $amsLog["data"] = array();
  778. }else{
  779. $log = $cbpdb->GetAll("select cbpreplytime as atime, amslog, cbperrorcode, isams_submit
  780. from v_e_amslog where hbol = '" . pg_escape_string($ams[0]['h_bol']) . "'
  781. and split_part(stationname, ',', 1) = split_part('" . pg_escape_string($ams[0]['station_name']) . "', ',', 1)
  782. order by cbpreplytime desc, substr(cbperrorcode, 2, 1) desc");
  783. $amsLog["msg"] = "";
  784. $amsLog["data"] = $log;
  785. }
  786. }
  787. }
  788. }
  789. $isfLog = array();
  790. //页面固定写死的信息
  791. $isfLog_column = array();
  792. $isfLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"dateTime");
  793. $isfLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  794. $isfLog_column[] = array("title" =>"Name","field" =>"isfsubmit","formatter" =>"","type" =>"normal");
  795. $isfLog_column[] = array("title" =>"Description","field" =>"isflog","formatter" =>"","type" =>"normal");
  796. $isfLog["isfLog_column"] = $isfLog_column;
  797. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  798. $isfLog["data"] = array();
  799. if (_canViewISFLog()) {
  800. if (!empty($isf_ss)) {
  801. $ss = $isf_ss;
  802. $len = strlen($ss);
  803. $b = substr($ss, $len - 7) . substr($ss, 0, $len - 7);
  804. if (empty($b)){
  805. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  806. $isfLog["data"] = array();
  807. }else{
  808. $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");
  809. }
  810. if (!empty($isf)) {
  811. if (!empty($isf['dob'])){
  812. $isf['dob'] = date("m/d/Y", strtotime($isf['dob']));
  813. }
  814. $msg = $cbpdb->GetAll("select cbpreplytime as atime, isflog, cbperrorcode, isfsubmit, hbol
  815. from v_e_isflog where (case when coalesce(isf_no, '')<>''
  816. then isf_no = '" . pg_escape_string($isf["isf_no"]) . "' else hbol = '" . pg_escape_string($isf["bol"]) . "'
  817. and stationname = '" . pg_escape_string($isf["station_name"]) . "' end)
  818. order by cbpreplytime desc, rowid desc");
  819. $isfLog["msg"] = "";
  820. $isfLog["data"] = $msg;
  821. }else{
  822. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  823. $isfLog["data"] = array();
  824. }
  825. }
  826. }
  827. $data =array("msg"=>"success",
  828. "canViewAMSLog" => _canViewAMSLog(),
  829. "canViewISFLog" => _canViewISFLog(),
  830. "amsLog" =>$amsLog,
  831. "isfLog" =>$isfLog);
  832. common::echo_json_encode(200,$data);
  833. exit;
  834. }
  835. private function getEmail($serial_no) {
  836. return utils::getEmail($serial_no);
  837. }
  838. private function getCommunicationNew($serial_no) {
  839. $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");
  840. $emialRecords =array();
  841. foreach ($list as $k => $v) {
  842. $msg =array();
  843. $msg["name"] = $v["add_by"];
  844. $msg["creatTime"] = $v["add_times"];
  845. $msg["content"] = urldecode($v["web_content"]);
  846. $emialRecords[] = $msg;
  847. }
  848. return $emialRecords;
  849. }
  850. /*
  851. * get file by hbol/destination
  852. * H:HBL
  853. * M: MBL
  854. * F: FL
  855. * I: C/I & Packing list
  856. */
  857. private function getFileByHbol($m_bol, $h_bol, $types, $m_bs, $display, $detail = FALSE,$job_no="") {
  858. $types = strtolower($types);
  859. $types = explode(";", $types);
  860. $m_bs = explode(";", $m_bs);
  861. $otheres = NULL;
  862. $filefilter = " ('TELEX') ";//过滤掉类型,单独配置 3537
  863. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  864. $file = array();
  865. foreach ($types as $k => $type) {
  866. $m_b = $m_bs[$k];
  867. if (strtolower($m_b) == 'm')
  868. $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";
  869. if (strtolower($m_b) == 'h')
  870. $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";
  871. if (strtolower($m_b) == 'a')
  872. $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";
  873. if (!empty($sql)) {
  874. $rss = common::excuteListSql($sql);
  875. foreach ($rss as $rs) {
  876. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  877. $file[] = array("url"=>$OutFileURL.'/download.php?_schemas=&a='.base64_encode(base64_encode($rs['serial_no'])),
  878. "file_name" => $rs['file_name'],
  879. "detail"=>$rs['upload_date'],
  880. "can_delete"=>_getLoginName() == $rs['upload_by'],
  881. "from_system" =>'TOPOCEAN_KSMART');
  882. }else {
  883. $file[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  884. "file_name" => $rs['file_name'],
  885. "detail"=>$rs['upload_date'],
  886. "can_delete"=>_getLoginName() == $rs['upload_by'],
  887. "from_system" =>'');
  888. }
  889. }
  890. }
  891. }
  892. return $file;
  893. }
  894. /*
  895. * download file
  896. */
  897. private function _download() {
  898. $url = common::deCode($_GET['url'], 'D');
  899. common::download_file($url);
  900. }
  901. private function getOcanOrderSearchSql($type,$sqlWhere) {
  902. if($type == "All"){
  903. return "select count(1) from online_ocean
  904. left join LATERAL (select case when a.code='IFFBCF' then 'Created'
  905. when a.code='IFFCPU' then 'Cargo Received'
  906. when a.code='IFFREC' then 'Cargo Received'
  907. when a.code='IFFDEP' then 'Departed'
  908. when a.code='IFFARR' then 'Arrived'
  909. when a.code='IFFAFD' then 'Completed'
  910. else 'Created' END as new_status
  911. from ocean_milestone a
  912. where a.serial_no=online_ocean.serial_no
  913. and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
  914. and a.act_date is not null
  915. order by id desc limit 1) dd on true" . $sqlWhere;
  916. }
  917. if($type == "Created"){
  918. $Created_sqlWhere = " and (1<>1 or dd.new_status ='Created' or dd.new_status is null)";
  919. return "select count(1) from online_ocean
  920. left join LATERAL (select case when a.code='IFFBCF' then 'Created'
  921. when a.code='IFFCPU' then 'Cargo Received'
  922. when a.code='IFFREC' then 'Cargo Received'
  923. when a.code='IFFDEP' then 'Departed'
  924. when a.code='IFFARR' then 'Arrived'
  925. when a.code='IFFAFD' then 'Completed'
  926. else 'Created' END as new_status
  927. from ocean_milestone a
  928. where a.serial_no=online_ocean.serial_no
  929. and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
  930. and a.act_date is not null
  931. order by id desc limit 1) dd on true" . $sqlWhere.$Created_sqlWhere;
  932. }
  933. if($type == "Cargo Received"){
  934. $Cargo_Received_sqlWhere = " and (1<>1 or dd.new_status ='Cargo Received')";
  935. return "select count(1) from online_ocean
  936. left join LATERAL (select case when a.code='IFFBCF' then 'Created'
  937. when a.code='IFFCPU' then 'Cargo Received'
  938. when a.code='IFFREC' then 'Cargo Received'
  939. when a.code='IFFDEP' then 'Departed'
  940. when a.code='IFFARR' then 'Arrived'
  941. when a.code='IFFAFD' then 'Completed'
  942. else 'Created' END as new_status
  943. from ocean_milestone a
  944. where a.serial_no=online_ocean.serial_no
  945. and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
  946. and a.act_date is not null
  947. order by id desc limit 1) dd on true" . $sqlWhere.$Cargo_Received_sqlWhere;
  948. }
  949. if($type == "Departed"){
  950. $Departed_sqlWhere = " and (1<>1 or dd.new_status ='Departed')";
  951. return "select count(1) from online_ocean
  952. left join LATERAL (select case when a.code='IFFBCF' then 'Created'
  953. when a.code='IFFCPU' then 'Cargo Received'
  954. when a.code='IFFREC' then 'Cargo Received'
  955. when a.code='IFFDEP' then 'Departed'
  956. when a.code='IFFARR' then 'Arrived'
  957. when a.code='IFFAFD' then 'Completed'
  958. else 'Created' END as new_status
  959. from ocean_milestone a
  960. where a.serial_no=online_ocean.serial_no
  961. and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
  962. and a.act_date is not null
  963. order by id desc limit 1) dd on true" . $sqlWhere.$Departed_sqlWhere;
  964. }
  965. if($type == "Arrived"){
  966. $Arrived_sqlWhere = " and (1<>1 or dd.new_status ='Arrived')";
  967. return "select count(1) from online_ocean
  968. left join LATERAL (select case when a.code='IFFBCF' then 'Created'
  969. when a.code='IFFCPU' then 'Cargo Received'
  970. when a.code='IFFREC' then 'Cargo Received'
  971. when a.code='IFFDEP' then 'Departed'
  972. when a.code='IFFARR' then 'Arrived'
  973. when a.code='IFFAFD' then 'Completed'
  974. else 'Created' END as new_status
  975. from ocean_milestone a
  976. where a.serial_no=online_ocean.serial_no
  977. and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
  978. and a.act_date is not null
  979. order by id desc limit 1) dd on true" . $sqlWhere.$Arrived_sqlWhere;
  980. }
  981. if($type == "Completed"){
  982. $Completed_sqlWhere = " and (1<>1 or dd.new_status ='Completed')";
  983. return "select count(1) from online_ocean
  984. left join LATERAL (select case when a.code='IFFBCF' then 'Created'
  985. when a.code='IFFCPU' then 'Cargo Received'
  986. when a.code='IFFREC' then 'Cargo Received'
  987. when a.code='IFFDEP' then 'Departed'
  988. when a.code='IFFARR' then 'Arrived'
  989. when a.code='IFFAFD' then 'Completed'
  990. else 'Created' END as new_status
  991. from ocean_milestone a
  992. where a.serial_no=online_ocean.serial_no
  993. and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
  994. and a.act_date is not null
  995. order by id desc limit 1) dd on true" . $sqlWhere.$Completed_sqlWhere;
  996. }
  997. }
  998. private function save_vgm() {
  999. $schemas = $_POST["schemas"];
  1000. $serial_no = common::deCode($_POST["serial_no"], 'D');
  1001. $ocean = common::excuteObjectSql("select m_bol, master_base_number, from_station, h_bol from $schemas.ocean where serial_no='" . common::check_input($serial_no) . "'");
  1002. $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"] . "'");
  1003. $address = $contact["address_1"];
  1004. if (!empty($address)) {
  1005. $address .= "\r\n";
  1006. }
  1007. $address .= $contact["address_2"];
  1008. if (!empty($address)) {
  1009. $address .= "\r\n";
  1010. }
  1011. $address .= $contact["address_3"];
  1012. if (!empty($address)) {
  1013. $address .= "\r\n";
  1014. }
  1015. $address .= $contact["address_4"];
  1016. $exists = common::excuteOneSql("select serial_no from $schemas.ocean_vgm_masterbasenumber where master_base_number ilike '" . $ocean["master_base_number"] . "'");
  1017. global $db;
  1018. $db->StartTrans();
  1019. if (empty($_POST["is_send"])) {
  1020. $_POST["is_send"] = 'f';
  1021. }
  1022. if (empty($exists)) {
  1023. $db->Execute("insert into ocean_vgm_masterbasenumber (master_base_number, serial_no) values ('" . $ocean["master_base_number"] . "', '$serial_no');");
  1024. $value["serial_no"] = $serial_no;
  1025. $value["carrier_booking_no"] = $_POST["all_carrier_booking"];
  1026. $value["modify_user"] = _getLoginName();
  1027. $value["modify_time"] = "now()";
  1028. $value["authorized_email"] = !empty($_POST["authorized_email"]) ? $_POST["authorized_email"] : "";
  1029. $value["authorized_tel"] = !empty($_POST["authorized_tel"]) ? $_POST["authorized_tel"] : "";
  1030. $value["authorized_company"] = !empty($_POST["submitter"]) ? $_POST["submitter"] : "";
  1031. $value["signature"] = !empty($_POST["signature"]) ? $_POST["signature"] : "";
  1032. $value["is_send"] = $_POST["is_send"];
  1033. $value["action"] = "New";
  1034. $value["type"] = "Shipper";
  1035. $value["m_bol"] = $ocean["m_bol"];
  1036. $value["master_base_number"] = $ocean["master_base_number"];
  1037. $value["shipper_id"] = $ocean["from_station"];
  1038. $value["shipper"] = $contact["company"];
  1039. $value["shipper_address"] = $address;
  1040. $value["shipper_contactname"] = $contact["contactname_1"];
  1041. $value["shipper_email"] = $contact["email_1"];
  1042. $value["shipper_fax"] = $contact["fax"];
  1043. $value["shipper_telephone"] = $contact["phone_1"];
  1044. $value["update_uuid"] = utils::uuid();
  1045. $value["h_bol"] = $ocean["h_bol"];
  1046. $value["from_station"] = $ocean["from_station"];
  1047. $sql = common::getInsertSqlNull("$schemas .ocean_vgm", $value);
  1048. $db->Execute($sql);
  1049. } else {
  1050. $serial_no = $exists;
  1051. $db->Execute("update ocean_vgm_masterbasenumber set id=id where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  1052. $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(),"
  1053. . "authorized_email='" . $_POST["authorized_email"] . "', authorized_tel='" . $_POST["authorized_tel"] . "', authorized_company='" . $_POST["submitter"] . "', signature='" . $_POST["signature"] . "', send_time=null "
  1054. . ", update_uuid='" . utils::uuid() . "' where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  1055. }
  1056. $db->Execute("delete from ocean_vgm_container where serial_no ilike '" . $serial_no . "';");
  1057. foreach ($_POST["container_no"] as $i => $cv) {
  1058. $value1["serial_no"] = $serial_no;
  1059. $value1["carrier_booking_no"] = !empty($_POST["carrier_booking_no"][$i]) ? $_POST["carrier_booking_no"][$i] : "";
  1060. $value1["ctnr"] = !empty($_POST["container_no"][$i]) ? $_POST["container_no"][$i] : "";
  1061. $value1["size"] = !empty($_POST["size"][$i]) ? $_POST["size"][$i] : "";
  1062. $value1["vgm_weight"] = !empty($_POST["vgm_weight"][$i]) ? $_POST["vgm_weight"][$i] : "";
  1063. $value1["unit"] = !empty($_POST["vgm_kg_lg"][$i]) ? $_POST["vgm_kg_lg"][$i] : "";
  1064. $value1["vgm_time"] = !empty($_POST["vgm_date"][$i]) ? $_POST["vgm_date"][$i] : "";
  1065. $value1["cargo_weight_kgs"] = !empty($_POST["cargo_weight_kg"][$i]) ? $_POST["cargo_weight_kg"][$i] : "";
  1066. $value1["cargo_weight_lbs"] = !empty($_POST["cargo_weight_lb"][$i]) ? $_POST["cargo_weight_lb"][$i] : "";
  1067. $value1["vgm_method"] = !empty($_POST["vgm_method"][$i]) ? $_POST["vgm_method"][$i] : "";
  1068. $value1["master_base_number"] = $ocean["master_base_number"];
  1069. $sql = common::getInsertSqlNull("$schemas.ocean_vgm_container", $value1);
  1070. $db->Execute($sql);
  1071. }
  1072. if ($db->CompleteTrans() === FALSE) {
  1073. return "error";
  1074. } else {
  1075. return "success";
  1076. }
  1077. }
  1078. private function getOceanDetail($serial_no) {
  1079. $_schemas = $_REQUEST['_schemas'];
  1080. if($_schemas == 'public'){
  1081. $_schemas = "ocean";
  1082. }
  1083. $sql = "SELECT m_eta as _m_eta, h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
  1084. (select incoterms from online_ocean where online_ocean.serial_no = o.serial_no limit 1) as incoterms,
  1085. public.z_get_eta_dest(o.final_eta::date, o.eta_dest::text, o.service::text, o.m_eta::date, o.place_of_delivery::text, o.mport_of_discharge::text) as _eta_dest,
  1086. to_char(final_eta, 'MM/DD/YYYY') as _final_eta,
  1087. o.* ,sh.*, cn.* ,aa.*,dd.*,
  1088. CASE
  1089. WHEN ee.status is null THEN 'Created'::text
  1090. ELSE ee.status::text
  1091. END AS new_status
  1092. from ocean o
  1093. left join LATERAL (select case when a.code='IFFBCF' then 'Created'
  1094. when a.code='IFFCPU' then 'Cargo Received'
  1095. when a.code='IFFREC' then 'Cargo Received'
  1096. when a.code='IFFDEP' then 'Departed'
  1097. when a.code='IFFARR' then 'Arrived'
  1098. when a.code='IFFAFD' then 'Completed'
  1099. else 'Created' END as status
  1100. from ocean_milestone a
  1101. where a.serial_no=o.serial_no
  1102. and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
  1103. and a.act_date is not null
  1104. order by id desc limit 1) ee on true
  1105. LEFT JOIN LATERAL ( SELECT company as cn_company,
  1106. address_1 as cn_address_1,
  1107. address_2 as cn_address_2,
  1108. address_3 as cn_address_3,
  1109. address_4 as cn_address_4,
  1110. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  1111. phone_1 as cn_phone
  1112. FROM $_schemas.contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
  1113. LEFT JOIN LATERAL ( SELECT company as sh_company,
  1114. address_1 as sh_address_1,
  1115. address_2 as sh_address_2,
  1116. address_3 as sh_address_3,
  1117. address_4 as sh_address_4,
  1118. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  1119. phone_1 as sh_phone
  1120. FROM $_schemas.contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
  1121. LEFT JOIN LATERAL ( SELECT company as aa_company,
  1122. address_1 as aa_address_1,
  1123. address_2 as aa_address_2,
  1124. address_3 as aa_address_3,
  1125. address_4 as aa_address_4,
  1126. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  1127. phone_1 as aa_phone
  1128. FROM $_schemas.contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
  1129. LEFT JOIN LATERAL ( SELECT company as dd_company,
  1130. address_1 as dd_address_1,
  1131. address_2 as dd_address_2,
  1132. address_3 as dd_address_3,
  1133. address_4 as dd_address_4,
  1134. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  1135. phone_1 as dd_phone
  1136. FROM $_schemas.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
  1137. where lower(serial_no) = '" . strtolower($serial_no) . "'";
  1138. return $sql;
  1139. }
  1140. private function returnOceanDetailData($ocean,$state){
  1141. $data = array();
  1142. //处理shipment data
  1143. $ocean_milestone_status = common::excuteListSql("select code,
  1144. act_date,est_date,timezone
  1145. from ocean_milestone a
  1146. where a.serial_no='".$ocean["serial_no"]."' and code in('IFFREC','IFFONB','IFFDEP','IFFARR','IFFDEL')
  1147. order by id");
  1148. $ocean_milestone_status_code = array();
  1149. foreach($ocean_milestone_status as $oms){
  1150. $ocean_milestone_status_code[$oms['code']] = $oms;
  1151. }
  1152. $simplexData = array();
  1153. //place_of_Receipt
  1154. $place_of_Receipt_stauts = array("index" =>1,"label" =>"Place of Receipt",
  1155. "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt'],"isArrival" =>$state >= 1 ? true : false);
  1156. $children = array();
  1157. if($state >= 1 && !empty($ocean_milestone_status_code['IFFREC']['act_date'])){
  1158. //发生后,未发生前没有
  1159. $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFREC']['act_date']);
  1160. }
  1161. $place_of_Receipt_stauts["children"] = $children;
  1162. $simplexData[] = $place_of_Receipt_stauts;
  1163. //port_of_Loading
  1164. $port_of_Loading_stauts = array("index" =>2,"label" =>"Port of Loading",
  1165. "path" =>$ocean['fport_of_loading_exp_exp']."/".$ocean['fport_of_loading_exp'],"isArrival" =>$state >= 2 ? true : false);
  1166. $children = array();
  1167. if ($state <= 1){
  1168. //未发生前
  1169. if(!empty($ocean_milestone_status_code['IFFDEP']['est_date'])){
  1170. $children[] = array("label" =>"Departure(ETD)","date" =>$ocean_milestone_status_code['IFFDEP']['est_date']);
  1171. } else {
  1172. //没有,取etd
  1173. $children[] = array("label" =>"Departure(ETD)","date" =>$ocean['f_etd']);
  1174. }
  1175. } else{
  1176. if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
  1177. $children[] = array("label" =>"On board","date" =>$ocean_milestone_status_code['IFFONB']['act_date']);
  1178. }
  1179. if(!empty($ocean_milestone_status_code['IFFDEP']['act_date'])){
  1180. $children[] = array("label" =>"Departure(ATD)","date" =>$ocean_milestone_status_code['IFFDEP']['act_date']);
  1181. }
  1182. }
  1183. $port_of_Loading_stauts["children"] = $children;
  1184. $simplexData[] = $port_of_Loading_stauts;
  1185. //Port of Discharge
  1186. $port_of_Discharge_status = array("index" =>3,"label" =>"Port of Discharge",
  1187. "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge'],"isArrival" =>$state >= 3 ? true : false);
  1188. $children = array();
  1189. if ($state <= 2){
  1190. //未发生前
  1191. if(!empty($ocean_milestone_status_code['IFFARR']['est_date'])){
  1192. $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean_milestone_status_code['IFFARR']['est_date']);
  1193. }else{
  1194. //没有,取eta
  1195. $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['m_eta']);
  1196. }
  1197. } else{
  1198. if(!empty($ocean_milestone_status_code['IFFARR']['act_date'])){
  1199. $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean_milestone_status_code['IFFARR']['act_date']);
  1200. }
  1201. }
  1202. $port_of_Discharge_status["children"] = $children;
  1203. $simplexData[] = $port_of_Discharge_status;
  1204. //Place of Delivery
  1205. $place_of_Delivery_status = array("index" =>4,"label" =>"Place of Delivery",
  1206. "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery'],"isArrival" =>$state == 4 ? true : false);
  1207. $children = array();
  1208. if ($state <= 3){
  1209. //未发生前
  1210. } else{
  1211. if(!empty($ocean_milestone_status_code['IFFDEL']['act_date'])){
  1212. $children[] = array("label" =>"Cargo handover/Delivered","date" =>$ocean_milestone_status_code['IFFDEL']['act_date']);
  1213. }
  1214. }
  1215. $simplexData[] = $place_of_Delivery_status;
  1216. $data['shipmentData'] = $simplexData;
  1217. //处理transportInfo信息数据
  1218. $transportInfo = array("Tracking No." =>$ocean['tracking_no'],"status"=>$ocean['new_status'],"mode" => "Ocean Freight",
  1219. "origin" =>$ocean['origin_station'],"destination" =>$ocean['destination_station'],
  1220. "etd" =>$ocean['f_etd'],"atd" =>"","eta" =>$ocean['m_eta'],"ata" =>"");
  1221. $data['transportInfo'] = $transportInfo;
  1222. //处理basicInfo信息数据
  1223. $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
  1224. $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
  1225. $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['carrier_booking'],
  1226. "PO_NO" =>$ocean['po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  1227. "Incoterm" =>$ocean['incoterms'],"Service_Type" =>$ocean['service']);
  1228. $data['basicInfo'] = $basicInfo;
  1229. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  1230. $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  1231. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  1232. $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  1233. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  1234. $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  1235. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  1236. $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  1237. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  1238. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  1239. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  1240. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  1241. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  1242. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  1243. $data['businessPartners'] = $businessPartners;
  1244. //处理routes 转船可能有多个情况
  1245. $routes = array(array("mode" =>"Ocean Freight","mode_label" =>"Sea", "origin" =>$ocean['fport_of_loading'],
  1246. "destination" => $ocean['fport_of_discharge'],
  1247. "etd" => $ocean['f_etd'],"atd" => "",
  1248. "eta" =>$ocean['f_eta'],"ata" =>"",
  1249. "vessel" =>$ocean['f_vessel'],"voyageNo" =>$ocean['f_voyage']));
  1250. //不是直航
  1251. if ($ocean['is_vessel_direct'] <> "t"){
  1252. $routes[] = array("mode" =>"Ocean Freight", "mode_label" =>"Sea","origin" =>$ocean['mport_of_loading'],
  1253. "destination" => $ocean['mport_of_discharge'],
  1254. "etd" => $ocean['m_etd'],"atd" => "",
  1255. "eta" =>$ocean['m_eta'],"ata" =>"",
  1256. "vessel" =>$ocean['m_vessel'],"voyageNo" =>$ocean['m_voyage']);
  1257. }
  1258. $data['routes'] = $routes;
  1259. //处理marksAndDescription
  1260. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description']);
  1261. $data['marksAndDescription'] = $marksAndDescription;
  1262. return $data;
  1263. }
  1264. }
  1265. ?>