ocean_order.class.php 74 KB

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