ocean_order.class.php 75 KB

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