ocean_order.class.php 75 KB

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