ocean_order.class.php 77 KB

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