ocean_order.class.php 76 KB

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