ocean_order.class.php 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028
  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. $serial_no = common::deCode($_GET['a'], 'D');
  41. $transport_mode = common::excuteOneSql("SELECT transport_mode FROM public.kln_ocean ob WHERE ob.serial_no = '$serial_no'");
  42. if ($transport_mode == "sea"){
  43. $this->_ocean_detail();
  44. } elseif ($transport_mode == "air"){
  45. $this->_air_ocean_detail();
  46. } else {
  47. $this->_ocean_detail();
  48. }
  49. }
  50. if ($operate == "ams_isf_log"){
  51. $this->_ams_isf_log();
  52. }
  53. /*
  54. * export ocean order to excel
  55. */
  56. if ($operate == "excel") {
  57. $this->_ocean_excel();
  58. }
  59. /*
  60. * download Revenue
  61. */
  62. if ($operate == "revenue") {
  63. $this->_revenue_download();
  64. }
  65. if ($operate == 'setting_ocean_order_display') {
  66. column::getInstance()->settingDisplay('Ocean_Search', 'main_new_version.php?action=ocean_order');
  67. }
  68. /*
  69. * download document
  70. */
  71. if ($operate == "download") {
  72. $this->_download();
  73. }
  74. /*
  75. * document upload
  76. */
  77. if ($operate == "document_upload"){
  78. $transport_mode = $_POST['transport_mode'];
  79. if($transport_mode == 'sea'){
  80. $document = _getViewDocType($_REQUEST["_schemas"]);
  81. }else{
  82. $document = _getAirViewDocType($_REQUEST["_schemas"]);
  83. }
  84. $file_serial_nos = array();
  85. foreach ($document as $v) {
  86. $types = $v['serial_no'];
  87. $types = strtolower($types);
  88. $types = explode(";", $types);
  89. foreach ($types as $k => $type) {
  90. $file_serial_nos[] = $type;
  91. }
  92. }
  93. $file_serial_nos = implode(';',$file_serial_nos);
  94. if($transport_mode == 'sea'){
  95. $sql = "select display_name,format_name as file_type,serial_no,m_h from ra_online_file_format where lower(serial_no) " . common::getInNotInSql($file_serial_nos) . "
  96. and active = true and client_upload = true";
  97. }else{
  98. $sql = "select display_name,format_name as file_type,serial_no,m_h from air_file_format where lower(serial_no) " . common::getInNotInSql($file_serial_nos) . "
  99. and active = true and client_upload = true";
  100. }
  101. $display_name = common::excuteListSql($sql);
  102. $data['File Type'] = $display_name;
  103. common::echo_json_encode(200,$data);
  104. exit();
  105. }
  106. /*
  107. * document upload do
  108. */
  109. if ($operate == "document_upload_do"){
  110. $_schemas = $_REQUEST["_schemas"];
  111. $transport_mode = $_POST['transport_mode'];
  112. $bol = $_POST['h_bol'];
  113. $transport_mode = $_POST['file_type'];
  114. if ($transport_mode == "sea") {
  115. $aaa = common::excuteObjectSql("select from_station, origin_station, destination_station from ocean where lower(h_bol) = '" . strtolower($bol) . "'");
  116. } elseif ($transport_mode == "air") {
  117. $aaa = common::excuteObjectSql("select from_station, origin_station, destination_station from air where lower(hawb) = '" . strtolower($bol) . "'");
  118. }
  119. // try {
  120. // $tmp_name = $_FILES['file']['tmp_name'];
  121. // $file_name = $_FILES['file']["name"];
  122. // $errorMsg = "";
  123. // $sql = "";
  124. // foreach ($file_name as $i => $v) {
  125. // if (empty($v)) {
  126. // continue;
  127. // }
  128. // $size = floor($_FILES ["file"]['size'][$i] / 1024 / 1024);
  129. // if ($size > 2) {
  130. // $errorMsg .= $_FILES['file']["name"][$i] . " larger than 2M.";
  131. // continue;
  132. // }
  133. // if ($_FILES["file"]["error"][$i] > 0) {
  134. // $errorMsg .= "File Upload Error(" . $_FILES ["file"]["error"][$i] . ").";
  135. // continue;
  136. // }
  137. // $file_path = FILE_UPLOAD_PAHT . date("Ymd") . DS;
  138. // if (!is_dir($file_path)) {
  139. // common::mkdirs($file_path);
  140. // }
  141. // $dest_file = $file_path . $path_parts['filename'] . "_" . common::uuid() . "." . $exten;
  142. // move_uploaded_file($tmp_name[$i], $dest_file);
  143. // $sql .= "INSERT INTO public.packing_attachment_list(serial_no, att_type,file_type, created_by, created_time, filename, sourcefilename, notes) VALUES "
  144. // . "('$serial_no', 'EBooking','" . common::check_input($file_type[$i]) . "', '" . _getLoginName() . "', now(), '" . common::check_input($v) . "', '"
  145. // . common::check_input($dest_file) . "', '" . common::check_input($file_note[$i]) . "');";
  146. // }
  147. // if (!empty($errorMsg)) {
  148. // $this->echoJson(array('status' => 'Failed', 'msg' => "Save Booking Failed $errorMsg"));
  149. // }
  150. // common::excuteUpdateSqlThrow($sql);
  151. // exit(json_encode("success"));
  152. // } catch (Exception $e) {
  153. // error_log($e->getTraceAsString());
  154. // $this->echoJson(array('status' => 'Failed', 'msg' => "Save Booking Failed:Upload Filed Failed."));
  155. // }
  156. }
  157. if ($operate == "save_communication") {
  158. try {
  159. $content = $_POST["content"];
  160. $content = common::check_input($content);
  161. $text = $_POST["text"];
  162. $content = urldecode($content);
  163. $web_content = urldecode($text);
  164. $communication_cc = $_POST["communication_cc"];
  165. $serial_no = common::uuid();
  166. $email_uuid = $_POST["serial_no"];
  167. $add_by = _getLoginName();
  168. $refer_id = 0;
  169. $email = $this->getEmail($email_uuid);
  170. $from_email = "US.KApex.Online@kerryapex.com";
  171. $to_email = $email["email"];
  172. $cc_email = $_SESSION['ONLINE_USER']['email'] . ";ApexOnlineCommunication@apexshipping.com";
  173. $communication_cc = trim($communication_cc);
  174. if (!empty($communication_cc)) {
  175. $communication_cc = common::check_input($communication_cc);
  176. $cc_email .= ";" . $communication_cc;
  177. }
  178. $user_from = _getLoginName();
  179. $user_to = $email["name"];
  180. $user_cc = $_SESSION['ONLINE_USER']['first_name'];
  181. if (empty($user_cc)) {
  182. $user_cc = _getLoginName();
  183. }
  184. $user_cc .= ";ApexOnlineCommunication";
  185. //邮件发送
  186. $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>@@";
  187. $emailSql = "select encode(public.pgp_sym_encrypt('" . $serial_no . "','pom_key'), 'base64')::text;";
  188. $key = common::excuteOneSql($emailSql);
  189. $historyEmails = "";
  190. $title = "Communication from " . _getLoginName() . ", HBOL: " . $email["h_bol"] . ", Consignee: " . $email["consignee"];
  191. $emailContent = $content . $poKey . $key . ";" . "@@<br>For your convenience weblink: https://ra.kerryapex.com/<br><br>" . $historyEmails;
  192. 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());");
  193. $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)
  194. VALUES ('$serial_no', '$email_uuid', '$emailContent','$web_content', '$user_from', '$to_email', '$cc_email', $refer_id, '$add_by', now(), '$communication_cc');");
  195. $emailRecords = $this->getCommunicationNew($email_uuid);
  196. common::echo_json_encode(200,array("msg" => "Sent Successfully", "emailRecords" => $emailRecords));
  197. exit();
  198. } catch (Exception $e) {
  199. common::echo_json_encode(500,array("msg" => "Sent Error."));
  200. exit();
  201. }
  202. }
  203. if ($operate == "ocean_vgm") {
  204. if (!_canEdiVgm()) {
  205. $data = array("msg" =>"Vgm Permission Error");
  206. common::echo_json_encode(400, $data);
  207. exit();
  208. }
  209. $serial_no = common::deCode(($_GET["a"]), 'D');
  210. $sqlWhere = " and o.serial_no='" . $serial_no . "'";
  211. $column = "*";
  212. $schemas = $_GET["_schemas"];
  213. if (empty($schemas)) {
  214. $schemas = "public";
  215. }
  216. $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 "
  217. . "$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;
  218. $ocean_info = common::excuteObjectSql($ocean_info_sql);
  219. $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 "
  220. . "$schemas.oc_container o left join $schemas.ocean oc on o.serial_no=oc.serial_no "
  221. . " left join $schemas.ocean_vgm ov on oc.serial_no=ov.serial_no or oc.master_base_number=ov.master_base_number "
  222. . " left join $schemas.ocean_vgm_container v on ov.serial_no=v.serial_no and o.ctnr=v.ctnr "
  223. . " 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"] . "'";
  224. $rs = common::excuteListSql($rs_sql);
  225. $ocean_info["is_send"] = (empty($ocean_info["is_send"]) ? "f" : $ocean_info["is_send"]);
  226. if (empty($ocean_info["id"])) {
  227. $ocean_info["is_send"] = "t";
  228. }
  229. $err_msg = "";
  230. if (empty($ocean_info["carrier_booking"])) {
  231. $err_msg = "Carrier Booking is empty.";
  232. }
  233. if ($schemas <> "public") {
  234. $err_msg .= "This hbol do not support.";
  235. }
  236. $err_msg_ctnr = "";
  237. $err_msg_CFS = "";
  238. foreach ($rs as $cv) {
  239. if (empty($cv["ctnr"])) {
  240. $err_msg_ctnr = "Container# is empty.";
  241. }
  242. if (substr($cv["service"], 0, 3) == "CFS") {
  243. $err_msg_CFS = "CFS cannot support update.";
  244. }
  245. }
  246. if (!empty($err_msg)) {
  247. $err_msg = "You cant't add this VGM, (" . $err_msg ." ". $err_msg_ctnr." ".$err_msg_CFS.")";
  248. }
  249. $serial_no = common::deCode($serial_no, "E");
  250. //default
  251. if (empty($rs["id"])) {
  252. $default = common::excuteObjectSql("select * from ocean_vgm_setting where login_name ilike '" . _getLoginName() . "'");
  253. }
  254. $log = common::excuteListSql("select * from ocean_vermas where from_serial_no ilike '" . $ocean_info["master_base_number"] . "'");
  255. //detail information
  256. $detail_information_column = array();
  257. $detail_information_column[] = array("title" =>"SN","field" =>"sn","formatter" =>"","edit_type" =>"normal",);
  258. $detail_information_column[] = array("title" =>"Carrier Booking No.","field" =>"carrier_booking_no","formatter" =>"","edit_type" =>"normal");
  259. $detail_information_column[] = array("title" =>"Container No","field" =>"container_no","formatter" =>"","edit_type" =>"normal");
  260. $detail_information_column[] = array("title" =>"VGM Weight","field" =>"vgm_weight","formatter" =>"","edit_type" =>"number");
  261. $detail_information_column[] = array("title" =>"VGM Unit","field" =>"vgm_kg_lg","formatter" =>"","edit_type" =>"select");
  262. $detail_information_column[] = array("title" =>"VGM Time","field" =>"vgm_date","formatter" =>"","edit_type" =>"dateTime");
  263. $detail_information_column[] = array("title" =>"VGM Method","field" =>"vgm_method","formatter" =>"","edit_type" =>"input");
  264. foreach($rs as $rk => $rv){
  265. $rs[$rk]['sn'] = $rk +1;
  266. $rs[$rk]['container_no'] = $rv['ctnr'];
  267. $rs[$rk]['vgm_kg_lg'] = $rv['unit'];
  268. $rs[$rk]['vgm_date'] = $rv['vgm_time'];
  269. //这个是前端逻辑,carrier_booking_no为空的话,取carrier_booking
  270. if(empty($rs[$rk]['carrier_booking_no'])){
  271. $rs[$rk]['carrier_booking_no'] = $ocean_info["carrier_booking"];
  272. }
  273. }
  274. $detail_information =array("detail_information_column" =>$detail_information_column,
  275. "detail_information_data" =>$rs);
  276. $data = array("msg" =>$err_msg);
  277. $Submitter = $ocean_info["authorized_company"];
  278. if(empty($ocean_info["id"])){
  279. $Submitter = $default["submitter"];
  280. }
  281. $signature = $ocean_info["signature"];
  282. if(empty($ocean_info["id"])){
  283. $signature = $default["signature"];
  284. }
  285. $authorized_email = $ocean_info["authorized_email"];
  286. if(empty($ocean_info["id"])){
  287. $authorized_email = $default["authorized_email"];
  288. }
  289. $authorized_tel = $ocean_info["authorized_tel"];
  290. if(empty($ocean_info["id"])){
  291. $authorized_tel = $default["authorized_tel"];
  292. }
  293. $data["general_information"] = array("HBL No."=>$ocean_info["o_h_bol"],
  294. "Carrier Booking No."=>$ocean_info["carrier_booking"],
  295. "Vessel"=>$ocean_info["m_vessel"],"Voyage"=>$ocean_info["m_voyage"],
  296. "ETD"=>$ocean_info["f_etd"],"ETA"=>$ocean_info["m_eta"],
  297. "Last updated User"=>$ocean_info["modify_user"],"Last updated Time"=>$ocean_info["modify_time"],
  298. "Submitter" =>$Submitter,"signature" =>$signature,"authorized_email" =>$authorized_email,"authorized_tel" =>$authorized_tel,"is_send" =>$ocean_info['is_send']);
  299. $data["detail_information"] = $detail_information;
  300. $data["schemas"] = $schemas;
  301. $data["serial_no"] = $serial_no;
  302. common::echo_json_encode(200, $data);
  303. exit();
  304. }
  305. if ($operate == "save_ocean_vgm") {
  306. if (!_canEdiVgm()) {
  307. $data = array("msg" =>"Vgm Permission Error");
  308. common::echo_json_encode(400, $data);
  309. exit();
  310. }
  311. $msg = $this->save_vgm();
  312. if ($msg == "success"){
  313. $data = array("msg" =>$msg);
  314. common::echo_json_encode(200, $data);
  315. } else {
  316. $data = array("msg" =>$msg);
  317. common::echo_json_encode(500, $data);
  318. }
  319. exit();
  320. }
  321. /*
  322. * share_shipment 这个提交的意义,是为了留下记录用户信息
  323. */
  324. if ($operate == "share_shipment") {
  325. $data = array("msg" =>"share_shipment");
  326. common::echo_json_encode(200,$data);
  327. exit();
  328. }
  329. }
  330. /*
  331. * ocean order search
  332. */
  333. private function _ocean_search() {
  334. $cp = common::check_input($_POST ['cp']); //current_page
  335. $ps = common::check_input($_POST ['ps']); //ps
  336. if (empty($ps))
  337. $ps = 100;
  338. if (empty($cp))
  339. $cp = 1;
  340. $sqlWhere = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  341. $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
  342. if (!empty($_REQUEST["_reportRef"])) {
  343. $_reportType = $_REQUEST["_reportType"];
  344. $_reportRef = $_REQUEST["_reportRef"];
  345. if ($_reportType == "r3") {
  346. if ($_reportRef == "Previous 7 Days") {
  347. $sqlWhere .= " and eta>(current_date-interval '7 days') and eta<current_date";
  348. } else if ($_reportRef == "≤1 Day") {
  349. $sqlWhere .= " and eta=current_date";
  350. } else if ($_reportRef == "1-2 Days") {
  351. $sqlWhere .= " and eta>current_date and eta<=(current_date+interval '2 days')";
  352. } else if ($_reportRef == "3-6 Days") {
  353. $sqlWhere .= " and eta>(current_date+interval '2 days') and eta<=(current_date+interval '6 days')";
  354. } else if ($_reportRef == "≥7 Days") {
  355. $sqlWhere .= " and eta>(current_date+interval '6 days')";
  356. } else {
  357. $sqlWhere .= " and 1<>1";
  358. }
  359. } else if ($_reportType == "r4") {
  360. if ($_reportRef == "Previous 7 Days") {
  361. $sqlWhere .= " and etd>(current_date-interval '7 days') and etd<current_date";
  362. } else if ($_reportRef == "≤1 Day") {
  363. $sqlWhere .= " and etd=current_date";
  364. } else if ($_reportRef == "1-2 Days") {
  365. $sqlWhere .= " and etd>current_date and etd<=(current_date+interval '2 days')";
  366. } else if ($_reportRef == "3-6 Days") {
  367. $sqlWhere .= " and etd>(current_date+interval '2 days') and etd<=(current_date+interval '6 days')";
  368. } else if ($_reportRef == "≥7 Days") {
  369. $sqlWhere .= " and etd>(current_date+interval '6 days')";
  370. } else {
  371. $sqlWhere .= " and 1<>1";
  372. }
  373. } else if ($_reportType == "ata_r3") {
  374. if ($_reportRef == "≤1 Day") {
  375. $sqlWhere .= " and ata >= etd and (ata-etd) >= 0 and (ata-etd) < 1";
  376. } else if ($_reportRef == "1-2 Days") {
  377. $sqlWhere .= " and ata >= etd and (ata-etd) >= 1 and (ata-etd) < 2";
  378. } else if ($_reportRef == "3-6 Days") {
  379. $sqlWhere .= " and ata >= etd and (ata-etd) >= 2 and (ata-etd) < 6";
  380. } else if ($_reportRef == "≥7 Days") {
  381. $sqlWhere .= " and ata >= etd and (ata-etd) >= 6";
  382. } else {
  383. $sqlWhere .= " and 1<>1";
  384. }
  385. } else if ($_reportType == "atd_r4") {
  386. if ($_reportRef == "≤1 Day") {
  387. $sqlWhere .= " and atd >= etd and (atd-etd) >= 0 and (atd-etd) < 1";
  388. } else if ($_reportRef == "1-2 Days") {
  389. $sqlWhere .= " and atd >= etd and (atd-etd) >= 1 and (atd-etd) < 2";
  390. } else if ($_reportRef == "3-6 Days") {
  391. $sqlWhere .= " and atd >= etd and (atd-etd) >= 2 and (atd-etd) < 6";
  392. } else if ($_reportRef == "≥7 Days") {
  393. $sqlWhere .= " and atd >= etd and (atd-etd) >= 6 ";
  394. } else {
  395. $sqlWhere .= " and 1<>1";
  396. }
  397. } else if ($_reportType == "top") {
  398. if (!empty($_reportRef)) {
  399. $_reportStationType = $_REQUEST["_reportStationType"];
  400. if($_reportStationType == 'shippr_uncode'){
  401. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  402. }
  403. if($_reportStationType == 'fport_of_loading_un'){
  404. $sqlWhere .= " and fport_of_loading_un = '$_reportRef'";
  405. }
  406. if($_reportStationType == 'consignee_uncode'){
  407. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  408. }
  409. if($_reportStationType == 'mport_of_discharge_un'){
  410. $sqlWhere .= " and mport_of_discharge_un = '$_reportRef'";
  411. }
  412. } else {
  413. $sqlWhere .= " and 1<>1";
  414. }
  415. } else if ($_reportType == "co2e") {
  416. $_reportDataType = $_REQUEST["_reportDataType"];
  417. //查询sea 其他的为空
  418. if (!empty($_reportRef) && $_reportDataType == "sea") {
  419. $_reportStationType = $_REQUEST["_reportStationType"];
  420. if($_reportStationType == 'origin'){
  421. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  422. }else{
  423. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  424. }
  425. } else {
  426. $sqlWhere .= " and 1<>1";
  427. }
  428. } else {
  429. $_reportRef = explode("-", $_REQUEST["_reportRef"]);
  430. $_reportRefb_date = $_REQUEST["_reportRefb_date"];
  431. $bdate = common::excuteOneSql("select to_date('$_reportRefb_date','mm/YYYY')");
  432. $_reportRefe_date = $_REQUEST["_reportRefe_date"];
  433. $edate = common::excuteOneSql("select to_date('$_reportRefe_date','mm/YYYY') + interval '1 month' - interval '1 day'");
  434. //$sqlWhere .= " and eta>='$bdate' and eta<='$edate'";
  435. if ($_REQUEST["_reportRef"] == "Over 80 Days") {
  436. $sqlWhere .= " and (eta-etd)>80";
  437. } else {
  438. $sqlWhere .= " and (eta-etd)>" . $_reportRef[0] . " and (eta-etd)<=" . substr($_reportRef[1], 0, 2);
  439. }
  440. }
  441. }
  442. //取消全文检索
  443. // if (!empty($_POST["_textSearch"])) {
  444. // $sqlWhere .= " and text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))";
  445. // }
  446. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  447. if (!empty($_POST["_textSearch"])) {
  448. $textSearch_arr = $_POST['_textSearch'];
  449. if(!is_array($textSearch_arr)){
  450. $textSearch_arr = str_replace(",", ";", $textSearch_arr);
  451. $textSearch_arr = array($textSearch_arr);
  452. }
  453. $more_param = common::getInNotInSqlForSearch(strtolower(implode(';',$textSearch_arr)));
  454. //$sqlWhere .= " and (ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking),lower(tracking_no)],''))";
  455. $sqlWhere .= " and ((ARRAY[$more_param] && array_append(ARRAY[lower(booking_no::text), lower(h_bol::text), lower(m_bol), lower(carrier_booking), lower(quote_no), lower(tracking_no)]||string_to_array(lower(ctnrs),','), ''::text))
  456. or lower(po_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%'
  457. or lower(invoice_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%')";
  458. }
  459. //移除filterTag
  460. $sqlWhere_befrom_filterTag = $sqlWhere;
  461. $mode_param = "";
  462. $transport_mode = empty($_POST["transport_mode"]) ? "all" : $_POST["transport_mode"];
  463. if(!is_array($transport_mode)){
  464. $transport_mode = array($transport_mode);
  465. }
  466. if((count($transport_mode) == 1 && strtolower($transport_mode[0]) == 'all')){
  467. $transport_mode = array("sea","air","road");
  468. }
  469. $transport_mode = implode(";",$transport_mode);
  470. $mode_param = common::getInNotInSqlForSearch($transport_mode);
  471. $sqlWhere .= " and transport_mode in ($mode_param)";
  472. $transport_mode_search = " and transport_mode in ($mode_param)";
  473. //查询tag
  474. // IFFBCF Booking Confirmation Created
  475. // IFFCPU Cargo Pickup Cargo Received
  476. // IFFREC Cargo Arrived at Origin Cargo Received
  477. // IFFDEP Departure Departed
  478. // IFFARR Arrived at Final Destination Port Arrived
  479. // IFFAFD Arrived at Final Destination Completed (remove)
  480. // IFFDEL document turnover/delivered Completed
  481. $filterTag_param = "";
  482. if (!empty($_POST["filterTag"])) {
  483. if (utils::count($_POST['filterTag']) == 1){
  484. $filterTag = $_POST['filterTag'][0];
  485. }else{
  486. $filterTag = utils::implode(",", $_POST['filterTag']);
  487. }
  488. $_sqlwhere = "1<>1";
  489. $filterTag_param = "1<>1";
  490. if(strtolower($filterTag) == "all"){
  491. $filterTag_param = "1=1";
  492. }
  493. if (stripos($filterTag, "Created") !== FALSE) {
  494. $_sqlwhere .= " or ((m_iffbcf is not null or m_iffbcf is null) and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null)";
  495. $filterTag_param .= " or ((m_iffbcf is not null or m_iffbcf is null) and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null)";
  496. }
  497. if (stripos($filterTag, "Cargo Received") !== FALSE) {
  498. $_sqlwhere .= " or ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null)";
  499. $filterTag_param .= " or ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null)";
  500. }
  501. if (stripos($filterTag, "Departure") !== FALSE) {
  502. $_sqlwhere .= "or (m_iffdep is not null and m_iffarr is null and m_iffdel is null)";
  503. $filterTag_param .= "or (m_iffdep is not null and m_iffarr is null and m_iffdel is null)";
  504. }
  505. if (stripos($filterTag, "Arrived") !== FALSE) {
  506. $_sqlwhere .= " or (m_iffarr is not null and m_iffdel is null)";
  507. $filterTag_param .= " or (m_iffarr is not null and m_iffdel is null)";
  508. }
  509. if (stripos($filterTag, "Completed") !== FALSE) {
  510. $_sqlwhere .= " or (m_iffdel is not null)";
  511. $filterTag_param .= " or (m_iffdel is not null)";
  512. }
  513. if(strtolower($filterTag) <> "all" && !empty($filterTag)){
  514. $sqlWhere .= " and ($_sqlwhere)";
  515. $filterTag_param = " ($filterTag_param)";
  516. }
  517. }
  518. if(empty($filterTag_param)){
  519. $filterTag_param = "1=1";
  520. }
  521. $tag_and_mode_param = $filterTag_param.$transport_mode_search;
  522. $rc = $_POST ['rc'];
  523. //这里都要查询,除非多传几个参数回来
  524. if ($rc == - 1 || true) {
  525. $sql = "select count(1) as rc,
  526. sum(case when (1<>1 or (transport_mode='sea')) then 1 else 0 end) as sea_rc,
  527. sum(case when (1<>1 or (transport_mode='air')) then 1 else 0 end) as air_rc,
  528. sum(case when $tag_and_mode_param then 1 else 0 end) as seach_rc,
  529. sum(case when (m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null)
  530. then 1 else 0 end)
  531. as created,
  532. sum(case when ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null)
  533. then 1 else 0 end)
  534. as cargo_received,
  535. sum(case when (m_iffdep is not null and m_iffarr is null and m_iffdel is null) then 1 else 0 end) as departed,
  536. sum(case when (m_iffarr is not null and m_iffdel is null) then 1 else 0 end) as arrived,
  537. sum(case when (m_iffdel is not null) then 1 else 0 end) as completed,
  538. string_agg(distinct incoterms, '<$>') as incoterm_str,
  539. string_agg(distinct service, '<$>') as service_str
  540. from public.kln_ocean". $sqlWhere_befrom_filterTag;
  541. error_log("online_ocean_search_All_Status: ".$sql);
  542. $sql_all_status_data = common::excuteObjectSql($sql);
  543. $incoterms = explode("<$>", $sql_all_status_data['incoterm_str']);
  544. $IncotermsList = array();
  545. foreach($incoterms as $terms){
  546. if(!empty($terms)){
  547. $IncotermsList[] = array("name"=>$terms,"checked"=>false);
  548. }
  549. }
  550. $service = explode("<$>", $sql_all_status_data['service_str']);
  551. $ServiceList = array();
  552. foreach($service as $_service){
  553. if(!empty($_service)){
  554. $ServiceList[] = array("name"=>$_service,"checked"=>false);
  555. }
  556. }
  557. $rc = $sql_all_status_data['rc'];
  558. $search_rc = $sql_all_status_data['seach_rc'];
  559. $sea_rc = $sql_all_status_data['sea_rc'];
  560. $air_rc = $sql_all_status_data['air_rc'];
  561. $Created = $sql_all_status_data['created'];
  562. $Cargo_Received = $sql_all_status_data['cargo_received'];
  563. $Departed = $sql_all_status_data['departed'];
  564. $Arrived = $sql_all_status_data['arrived'];
  565. $Completed = $sql_all_status_data['completed'];
  566. if (!empty($_POST["filterTag"])) {
  567. $tagsList = array(array("name"=>"All","number"=>intval($rc),"type"=>"all","checked"=>utils::in_array('All', $_POST["filterTag"])? true : false),
  568. array("name"=>"Created","number"=>intval($Created),"type"=>"created","checked"=>utils::in_array('Created', $_POST["filterTag"])? true : false),
  569. array("name"=>"Cargo Received","number"=>intval($Cargo_Received),"type"=>"cargo_received","checked"=>utils::in_array('Cargo Received', $_POST["filterTag"])? true : false),
  570. array("name"=>"Departure","number"=>intval($Departed),"type"=>"departure","checked"=>utils::in_array('Departure', $_POST["filterTag"])? true : false),
  571. array("name"=>"Arrived","number"=>intval($Arrived),"type"=>"arrived","checked"=>utils::in_array('Arrived', $_POST["filterTag"])? true : false),
  572. array("name"=>"Completed","number"=>intval($Completed),"type"=>"completed","checked"=>utils::in_array('Completed', $_POST["filterTag"])? true : false));
  573. }else{
  574. //初始,前端有选择着带入选择
  575. $tagsList = array(array("name"=>"All","number"=>intval($rc),"type"=>"all","checked"=> true ),
  576. array("name"=>"Created","number"=>intval($Created),"type"=>"created","checked"=> false),
  577. array("name"=>"Cargo Received","number"=>intval($Cargo_Received),"type"=>"cargo_received","checked"=> false),
  578. array("name"=>"Departure","number"=>intval($Departed),"type"=>"departure","checked"=> false),
  579. array("name"=>"Arrived","number"=>intval($Arrived),"type"=>"arrived","checked"=> false),
  580. array("name"=>"Completed","number"=>intval($Completed),"type"=>"completed","checked"=>false));
  581. }
  582. $TransportList = array(
  583. array("name"=>"Ocean Freight","sname"=>"Sea","number"=>intval($sea_rc),"checked"=>false,"icon"=>"#icon-icon_ocean_b"),
  584. array("name"=>"Air Freight","sname"=>"Air","number"=>intval($air_rc),"checked"=>false,"icon"=>"#icon-icon_airplane_b"));
  585. $transport_mode_arr = explode(";", $transport_mode);
  586. foreach($transport_mode_arr as $mode){
  587. foreach($TransportList as $tkey => $transport){
  588. if(strtolower(trim($mode)) == strtolower($TransportList[$tkey]["sname"])){
  589. $TransportList[$tkey]["checked"] = true;
  590. }
  591. }
  592. }
  593. //现在下载交给前端,后台预先只返回全部字段的列,
  594. $allColumn = column::getInstance()->getDisplayColumnAllReomveDefault('Ocean_Search');
  595. $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
  596. }
  597. $tp = ceil($rc / $ps);
  598. $order_by = " etd desc";
  599. if (_isCustomerLogin()) {
  600. $order_by = " eta desc";
  601. }
  602. if ($rc > 0) {
  603. // $ocean_ref_sql = " LEFT JOIN LATERAL ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no
  604. // FROM public.ocean_reference temp WHERE temp.serial_no = oo.serial_no) aa ON true ";
  605. $sql = "with oo as (SELECT order_from as _schemas,serial_no as __serial_no, serial_no,transport_mode,
  606. h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,
  607. CASE
  608. WHEN (m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Created'::text
  609. WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Cargo Received'::text
  610. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  611. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  612. WHEN (m_iffdel is not null) THEN 'Completed'::text
  613. ELSE 'Created'
  614. END AS new_status, ".
  615. column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.kln_ocean " . $sqlWhere .
  616. " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps.")
  617. select oo.* ,
  618. case when oo.transport_mode ='sea'
  619. then ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no FROM public.ocean_reference temp WHERE temp.serial_no = oo.serial_no)
  620. when oo.transport_mode ='air'
  621. then ''
  622. else ''
  623. end as \"Other refenrence No.\"
  624. from oo";
  625. $tmp_search_without_limit = "with oo as (SELECT order_from as _schemas,serial_no as __serial_no, serial_no,transport_mode,
  626. h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,
  627. CASE
  628. WHEN (m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Created'::text
  629. WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Cargo Received'::text
  630. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  631. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  632. WHEN (m_iffdel is not null) THEN 'Completed'::text
  633. ELSE 'Created'
  634. END AS new_status, ".
  635. column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.kln_ocean " . $sqlWhere .
  636. " order by $order_by)
  637. select oo.* ,
  638. case when oo.transport_mode ='sea'
  639. then ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no FROM public.ocean_reference temp WHERE temp.serial_no = oo.serial_no)
  640. when oo.transport_mode ='air'
  641. then ''
  642. else ''
  643. end as \"Other refenrence No.\"
  644. from oo";
  645. $rs = common::excuteListSql($sql);
  646. error_log("online_ocean_search_SQL: ".$sql);
  647. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  648. foreach($rs as $index => $val) {
  649. //返回加密serial_no
  650. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  651. //$rs[$index]["mode"] = "Ocean Freight";
  652. $rs[$index]["Transportation Mode"] = $val['transport_mode'] == 'sea' ? "Ocean Freight" : ($val['transport_mode'] == 'air' ? "Air Freight": "");
  653. //status 改为ocean_milestone里的信息
  654. $rs[$index]["Status"] = $rs[$index]["new_status"];
  655. }
  656. $arrTmp = array('searchData' => $rs,
  657. 'tagsList' => $tagsList,
  658. 'TransportList' => $TransportList,
  659. 'allColums' => $allBookingColumns,
  660. 'IncotermsList' =>$IncotermsList,
  661. 'ServiceList' =>$ServiceList,
  662. 'canEdiVgm' => _canEdiVgm(),
  663. 'rc' => $search_rc,
  664. 'ps' => $ps,
  665. 'cp' => $cp,
  666. 'tp' => $tp,
  667. 'tmp_search' => common::deCode($tmp_search_without_limit, 'E'),
  668. 'type' => common::check_input($_POST ['_ntype']));
  669. } else {
  670. $arrTmp = array('searchData' => array(),
  671. 'tagsList' => $tagsList,
  672. 'TransportList' => $TransportList,
  673. 'IncotermsList' =>$IncotermsList,
  674. 'ServiceList' =>$ServiceList,
  675. 'allColums' => $allBookingColumns,
  676. 'canEdiVgm' => _canEdiVgm(),
  677. 'rc' => $search_rc,
  678. 'ps' => $ps,
  679. 'cp' => $cp,
  680. 'tp' => $tp,
  681. 'tmp_search' => "",
  682. 'type' => common::check_input($_POST ['_ntype']));
  683. }
  684. common::echo_json_encode(200,$arrTmp);
  685. exit();
  686. }
  687. private function _ocean_detail() {
  688. $serial_no = common::deCode($_GET['a'], 'D');
  689. $sql = $this->getOceanDetail($serial_no);
  690. $ocean = common::excuteObjectSql($sql);
  691. if (!empty($ocean)) {
  692. $ocean['_isf_bol'] = $ocean['isf_bol'];
  693. if (empty($ocean['_isf_bol'])) {
  694. $ocean['_isf_bol'] = "AMAW" . $ocean['_h_bol'];
  695. }
  696. $isf_ss = md5(md5($ocean['_isf_bol']));
  697. $isf_ss = substr($isf_ss, 7) . substr($isf_ss, 0, 7);
  698. //ETA Dest的计算逻辑移除
  699. // most update status
  700. $_schemas = $_REQUEST["_schemas"];
  701. $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 "
  702. . ", fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un FROM public.kln_ocean "
  703. . "where serial_no= '" . $ocean["serial_no"] . "'";
  704. if (!empty($_schemas)) {
  705. $mostStatusSql .= " and order_from='" . $_schemas . "'";
  706. }
  707. $mostStatus = common::excuteObjectSql($mostStatusSql);
  708. $state = -1;
  709. if (!empty($mostStatus["last_status_315_code"])) {
  710. //desc 逻辑处理取消
  711. $state = common::getStatusStage($mostStatus["last_status_315_code"]);
  712. }
  713. //请求地图是需要的参数
  714. $uncode = "'";
  715. if ($mostStatus["place_of_receipt_un"] != $mostStatus["fport_of_loading_un"]) {
  716. $uncode .= $mostStatus["place_of_receipt_un"];
  717. }
  718. $uncode .= "'|'" . $mostStatus["fport_of_loading_un"] . "'|'" . $mostStatus["mport_of_discharge_un"] . "'|'";
  719. if ($mostStatus["mport_of_discharge_un"] != $mostStatus["place_of_delivery_un"]) {
  720. $uncode .= $mostStatus["place_of_delivery_un"];
  721. }
  722. $uncode .= "'";
  723. }
  724. $vueData = $this->returnOceanDetailData($ocean,$state);
  725. //处理shipment data暂时写死
  726. $simplexData = $vueData['shipmentData'];
  727. //处理transportInfo信息数据
  728. $transportInfo = $vueData['transportInfo'];
  729. //处理basicInfo信息数据
  730. $basicInfo = $vueData['basicInfo'];
  731. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  732. $businessPartners = $vueData['businessPartners'];
  733. //处理routes 转船可能有多个情况
  734. $routes = $vueData['routes'];
  735. //处理marksAndDescription
  736. $marksAndDescription = $vueData['marksAndDescription'];
  737. //处理containerStatusData
  738. $containerStatusData = $vueData['containerStatusData'];
  739. //处理ocean_reference
  740. $ref_no = array();
  741. $ref_arr = common::excuteListSql("select * from ocean_reference where lower(serial_no) = '" . strtolower($serial_no) . "'");
  742. if(!empty($ref_arr)){
  743. foreach($ref_arr as $ref) {
  744. $ref_no[] = array("label"=>$ref["ref_code"],"value"=>$ref["ref_value"]);
  745. }
  746. }
  747. //处理Container :配置Ocean_Container字段 UI 需要的字段有:Container.no Packing,quantity,Gross weight(kg),Gross weight(LB),CBM,seal#,size.service
  748. $ocean_container_column = array();
  749. $container_column = column::getInstance()->getDisplayColumnAll('Ocean_Container');
  750. foreach($container_column as $cc){
  751. $ocean_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],"formatter" =>"","type" =>"normal");
  752. }
  753. $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . ",net_lbs from oc_container where lower(serial_no) = '" . strtolower($serial_no) . "'";
  754. $rss = common::excuteListSql($sql);
  755. $quantity_unit = array();
  756. $g_weight_tolal = 0;
  757. $ch_weight_tolal = 0;
  758. $ch_weight_tolal_grs_lbs = 0;
  759. $cbm_tolal = 0;
  760. foreach ($rss as $key => $rs) {
  761. $unit = $rs['unit'];
  762. if (array_key_exists($unit, $quantity_unit)) {
  763. $quantity_unit[$unit] = $quantity_unit[$unit] + $rs['qty'];
  764. } else {
  765. $quantity_unit[$unit] = $rs['qty'];
  766. }
  767. $g_weight_tolal += $rs['grs_kgs'];
  768. $ch_weight_tolal += $rs['net_lbs'];
  769. $ch_weight_tolal_grs_lbs += $rs['grs_lbs'];
  770. $cbm_tolal += $rs['cbm'];
  771. //特殊处理weight
  772. if(!empty($rss[$key]['grs_kgs'])){
  773. $rss[$key]['grs_kgs'] = $rs['grs_kgs']."KGS";
  774. }
  775. if(!empty($rss[$key]['grs_lbs'])){
  776. $rss[$key]['grs_lbs'] = $rs['grs_lbs']."LBS";
  777. }
  778. }
  779. $quantity_tolal = "";
  780. foreach($quantity_unit as $uk => $uv){
  781. // 使用substr()截取第一次出现之前的字符串
  782. $uk = substr($uk, 0, strpos($uk, "-"));
  783. $quantity_tolal.=$uv." ".$uk." ";
  784. }
  785. $ch_weight_tolal = empty($ch_weight_tolal) ? $ch_weight_tolal_grs_lbs : $ch_weight_tolal;
  786. $g_weight_tolal = sprintf("%.3f", $g_weight_tolal);
  787. $ch_weight_tolal = sprintf("%.3f", $ch_weight_tolal);
  788. $cbm_tolal = sprintf("%.4f", $cbm_tolal);
  789. //Containers信息
  790. $containers = array("container_column"=>$ocean_container_column,"container_data" =>$rss);
  791. //Packing信息
  792. $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $ch_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
  793. //Milestones info 列名固定
  794. $Milestones = common::getMilestonesInfo($ocean,"sea",$_schemas,$vueData['EDI315TimeAndLocation']);
  795. //页面固定写死的信息
  796. $document_column = array();
  797. $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
  798. $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
  799. $document_data = array();
  800. $document = _getViewDocType($_REQUEST["_schemas"]);
  801. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  802. $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'])."'");
  803. if (!empty($document)) {
  804. foreach ($document as $v) {
  805. $file_type = $v['display_name'];
  806. $file_arr = $this->getOceanFileByHbol($ocean['_m_bol'], $ocean['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE,$ocean['_job_bol']) ;
  807. $tar = json_decode($ocean_can_view_file,true);
  808. if(!empty($tar[$v['display_name']])){
  809. foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
  810. switch ($v['display_name']) {
  811. case 'HBL':
  812. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  813. from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  814. from ra_online_doc_upload
  815. 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']."'
  816. order by id desc";
  817. break;
  818. case 'MBL':
  819. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  820. from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  821. from ra_online_doc_upload
  822. 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']."'
  823. order by id desc";
  824. break;
  825. case 'Others':
  826. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  827. from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  828. from ra_online_doc_upload
  829. 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']."'
  830. order by id desc";
  831. break;
  832. default:
  833. $sql = "";
  834. break;
  835. }
  836. if (!empty($sql)) {
  837. $rss = common::excuteListSql($sql);
  838. foreach ($rss as $rs) {
  839. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  840. $file_arr[] = array("url"=>$OutFileURL."/download.php?_schemas=&a=".base64_encode(base64_encode($rs['serial_no'])),
  841. "file_name" => $rs['file_name'],
  842. "format_name" => $rs['format_name'],
  843. "detail"=>$rs['upload_date'],
  844. "can_delete"=>_getLoginName() == $rs['upload_by'],
  845. "from_system" =>'TOPOCEAN_KSMART');
  846. }else{
  847. $file_arr[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  848. "file_name" => $rs['file_name'],
  849. "format_name" => $rs['format_name'],
  850. "detail"=>$rs['upload_date'],
  851. "can_delete"=>_getLoginName() == $rs['upload_by'],
  852. "from_system" =>'');
  853. }
  854. }
  855. }
  856. }
  857. }
  858. //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
  859. //按现在的逻辑,有值才会显示
  860. foreach($file_arr as $f){
  861. $document_data[] = array("file_type"=>$f["format_name"],"file"=>$f);
  862. }
  863. }
  864. }
  865. $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
  866. $emailRecords = $this->getCommunicationNew($ocean["serial_no"]);
  867. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $ocean["serial_no"] . "' order by id desc limit 1");
  868. $email = $this->getEmail($ocean["serial_no"]);
  869. $email['cc_email'] = $cc_email;
  870. $email['emailRecords'] = $emailRecords;
  871. global $_COPYRIGHT;
  872. $data = array('transportInfo' => $transportInfo,
  873. 'basicInfo' => $basicInfo,
  874. 'businessPartners' => $businessPartners,
  875. 'ref_no' => $ref_no,
  876. 'packing' => $packing,
  877. 'marksAndDescription' => $marksAndDescription,
  878. 'containers' => $containers,
  879. 'simplexData' =>$simplexData,
  880. 'containerStatusData' => $containerStatusData,
  881. 'document_info' => $document_info,
  882. 'containers' => $containers,
  883. 'Milestones' => $Milestones,
  884. 'routes' => $routes,
  885. 'email' => $email,
  886. 'ams_ss' => md5(md5($ocean['serial_no'])),
  887. 'isf_ss' => $isf_ss,
  888. 'transport_mode' =>"sea",
  889. '_schemas' =>$_schemas,
  890. 'uncode' =>$uncode,
  891. 'serial_no' =>$serial_no,
  892. 'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
  893. 'canEdiVgm' => _canEdiVgm(),
  894. 'canViewAMSLog'=>_canViewAMSLog(),
  895. 'canViewISFLog'=>_canViewISFLog(),
  896. 'copyright' =>$_COPYRIGHT);
  897. common::echo_json_encode(200,$data);
  898. exit();
  899. }
  900. private function _air_ocean_detail(){
  901. $serial_no = common::deCode($_GET['a'], 'D');
  902. $sql = $this->getAirDetail($serial_no);
  903. $air = common::excuteObjectSql($sql);
  904. //根据air_milestone 判断 shipment status的state
  905. $_schemas = $_REQUEST["_schemas"];
  906. $air_milestone_status = common::excuteListSql("select code,
  907. act_date,est_date,timezone
  908. from ocean_milestone a
  909. where a.serial_no='$serial_no' and code in('IFFCPU','IFFREC','IFFONB','IFFARR','IFFDEL')
  910. order by id");
  911. $state = -1;
  912. if (!empty($air_milestone_status)) {
  913. $state_arr = array();
  914. foreach($air_milestone_status as $ms){
  915. if($ms['code'] == "IFFCPU"){
  916. $state_arr[] = 0;
  917. }
  918. if($ms['code'] == "IFFREC" || $ms['code'] == "IFFONB"){
  919. $state_arr[] = 1;
  920. }
  921. if($ms['code'] == "IFFARR"){
  922. $state_arr[] = 2;
  923. }
  924. if($ms['code'] == "IFFDEL"){
  925. $state_arr[] = 3;
  926. }
  927. }
  928. $state = max($state_arr);
  929. }
  930. $vueData = $this->returnAirDetailData($air,$air_milestone_status,$state);
  931. //处理shipment data暂时写死
  932. $simplexData = $vueData['shipmentData'];
  933. //处理transportInfo信息数据
  934. $transportInfo = $vueData['transportInfo'];
  935. //处理basicInfo信息数据
  936. $basicInfo = $vueData['basicInfo'];
  937. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  938. $businessPartners = $vueData['businessPartners'];
  939. //处理routes 转船可能有多个情况
  940. $routes = $vueData['routes'];
  941. //处理marksAndDescription
  942. $marksAndDescription = $vueData['marksAndDescription'];
  943. $quantity_tolal = empty($air['qty']) ? "" : $air['qty'].$air['qty_uom'];
  944. $g_weight_tolal = empty($air['piece_count']) ? "" : sprintf("%.3f", $air['piece_count'])." KGS";
  945. $ch_weight_tolal = empty($air['piece_count']) ? "": sprintf("%.3f", $air['weight'])." KGS";
  946. $cbm_tolal = empty($air['cbm']) ? "" : sprintf("%.4f", $air['cbm'])." CBM";
  947. //Packing信息
  948. $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal,"Ch. Weight" => $ch_weight_tolal,"Volume" => $cbm_tolal);
  949. //Milestones info 列名固定
  950. $Milestones = common::getMilestonesInfo($air,"air",$_schemas);
  951. //页面固定写死的信息
  952. $document_column = array();
  953. $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
  954. $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
  955. $document_data = array();
  956. $document = _getAirViewDocType($_REQUEST["_schemas"]);
  957. $air_can_view_file = common::excuteOneSql("select air_can_view_file from ra_online_user where lower(user_login)='".strtolower($_SESSION['ONLINE_USER']['user_login'])."'");
  958. if (!empty($document)) {
  959. foreach ($document as $v) {
  960. $file_type = $v['display_name'];
  961. $file_arr = $this->getAirFileByHbol($air['_mawb'] . '-' . $air['_mawb_name'], $air['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE);
  962. $tar = json_decode($air_can_view_file,true);
  963. if(!empty($tar[$v['display_name']])){
  964. foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
  965. switch ($v['display_name']) {
  966. case 'HBL':
  967. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  968. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  969. from air_doc_upload
  970. where lower(bol) = lower('".$air['_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']."'
  971. order by id desc";
  972. break;
  973. case 'MBL':
  974. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  975. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  976. from air_doc_upload
  977. where lower(bol) = lower('".strtolower($air['_mawb'] . '-' . $air['_mawb_name'])."') and lower(format_serailno) in ('".strtolower(str_replace(";","','",$dvalue['value']))."') and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$dvalue['type']."'
  978. order by id desc";
  979. break;
  980. case 'Others':
  981. $sql = "SELECT
  982. (SELECT format_name from $_schemas.ra_online_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  983. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  984. from air_doc_upload
  985. where (lower(bol) = lower('".strtolower($air['_h_bol'])."') or lower(bol) = lower('".strtolower($air['_mawb'] . '-' . $air['_mawb_name'])."')) and lower(format_serailno) in ('".strtolower(str_replace(";","','",$dvalue['value']))."') and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$dvalue['type']."'
  986. order by id desc";
  987. break;
  988. default:
  989. $sql = "";
  990. break;
  991. }
  992. if (!empty($sql)) {
  993. $rss = common::excuteListSql($sql);
  994. foreach ($rss as $rs) {
  995. $file_arr[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  996. "file_name" => $rs['file_name'],
  997. "detail"=>$rs['upload_date'],
  998. "can_delete"=>_getLoginName() == $rs['upload_by'],
  999. "from_system" =>'');
  1000. }
  1001. }
  1002. }
  1003. }
  1004. //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
  1005. //按现在的逻辑,有值才会显示
  1006. foreach($file_arr as $f){
  1007. $document_data[] = array("file_type"=>$file_type,"file"=>$f);
  1008. }
  1009. }
  1010. }
  1011. $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
  1012. $emailRecords = $this->getCommunicationNew($air["serial_no"]);
  1013. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $air["serial_no"] . "' order by id desc limit 1");
  1014. $email = $this->getEmail($air["serial_no"]);
  1015. $email['cc_email'] = $cc_email;
  1016. $email['emailRecords'] = $emailRecords;
  1017. global $_COPYRIGHT;
  1018. $data = array('transportInfo' => $transportInfo,
  1019. 'basicInfo' => $basicInfo,
  1020. 'businessPartners' => $businessPartners,
  1021. 'ref_no' => array(),
  1022. 'packing' => $packing,
  1023. 'marksAndDescription' => $marksAndDescription,
  1024. 'containers' => array(),
  1025. 'simplexData' =>$simplexData,
  1026. 'containerStatusData' => array(),
  1027. 'document_info' => $document_info,
  1028. 'containers' => array(),
  1029. 'Milestones' => $Milestones,
  1030. 'routes' => $routes,
  1031. 'email' => $email,
  1032. 'ams_ss' =>"",
  1033. 'isf_ss' => "",
  1034. '_schemas' =>$_schemas,
  1035. 'uncode' =>"",
  1036. 'transport_mode' =>"air",
  1037. 'serial_no' =>$serial_no,
  1038. 'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
  1039. 'canEdiVgm' => _canEdiVgm(),
  1040. 'canViewAMSLog'=>_canViewAMSLog(),
  1041. 'canViewISFLog'=>_canViewISFLog(),
  1042. 'copyright' =>$_COPYRIGHT);
  1043. common::echo_json_encode(200,$data);
  1044. exit();
  1045. }
  1046. private function _ocean_excel() {
  1047. $sql = common::deCode($_POST ['tmp_search'], 'D');
  1048. //$sql = substr($sql, 0, strripos($sql, " limit"));
  1049. if(!empty($sql)){
  1050. $rs = common::excuteListSql($sql);
  1051. }
  1052. //去除null
  1053. foreach($rs as $index => $val) {
  1054. foreach($val as $index_2 => $_val) {
  1055. if(empty($rs[$index][$index_2]) || $rs[$index][$index_2] == null){
  1056. $rs[$index][$index_2] = "";
  1057. }
  1058. }
  1059. }
  1060. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  1061. foreach($rs as $index => $val) {
  1062. //返回加密serial_no
  1063. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  1064. //$rs[$index]["mode"] = "Ocean Freight";
  1065. $rs[$index]["Transportation Mode"] = $val['transport_mode'] == 'sea' ? "Ocean Freight" : ($val['transport_mode'] == 'air' ? "Air Freight": "");
  1066. //status 改为ocean_milestone里的信息
  1067. $rs[$index]["Status"] = $rs[$index]["new_status"];
  1068. }
  1069. common::echo_json_encode(200,array("msg"=>"success","Data" => $rs));
  1070. exit;
  1071. }
  1072. private function _revenue_download(){
  1073. $r2_cloumn = array();
  1074. $r2_cloumn[] = array("title" => "Month","dataIndex"=>"month");
  1075. $r2_cloumn[] = array("title" => "Currency","dataIndex"=>"currency");
  1076. $r2_cloumn[] = array("title" => "Total Amount","dataIndex"=>"invoice_amount");
  1077. $r3_cloumn = array();
  1078. $r3_cloumn[] = array("title" => "Invoice Issue Date","dataIndex"=>"invoice_date");
  1079. $r3_cloumn[] = array("title" => "Invoice Number","dataIndex"=>"invoice_no");
  1080. $r3_cloumn[] = array("title" => "HBL Number","dataIndex"=>"h_bol");
  1081. $r3_cloumn[] = array("title" => "Amount","dataIndex"=>"ivnoice_amount");
  1082. $r3_cloumn[] = array("title" => "Currency","dataIndex"=>"currency");
  1083. $date_from = null;
  1084. $date_to = null;
  1085. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start'])){
  1086. $date_start = common::dateFormatToYM($_REQUEST['date_start']);
  1087. $date_from = $date_start."-01";
  1088. }
  1089. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end'])){
  1090. $date_end = common::dateFormatToYM($_REQUEST['date_end']);
  1091. $date_to = date('Y-m-t', strtotime($date_end."-01"));
  1092. }
  1093. $param = '{"user_login":"'._getLoginName().'","report_type":"ALL","date_from":"'.$date_from.'","date_to":"'.$date_to.'"}';
  1094. //$sql = "SELECT * FROM get_customer_revenue_report('$param');FETCH ALL FROM r2;";
  1095. //$sql = "select * from _test_data_table";
  1096. //$r2_data = common::excuteListSql($sql);
  1097. //只取r3 代码去计总r2 ,避免二次请求数据库
  1098. $sql = "SELECT * FROM get_customer_revenue_report('$param');FETCH ALL FROM r3;";
  1099. //$sql = "select * from _test_data_table_two";
  1100. $r3_data = common::excuteListSql($sql);
  1101. $group_data = array();
  1102. foreach($r3_data as $r3){
  1103. $r3['invoice_date'] = strtoupper(date('M,Y', strtotime($r3['invoice_date'])));
  1104. $group_data[] = $r3;
  1105. }
  1106. //按货币和日期分组
  1107. $groupedItems = array();
  1108. foreach ($group_data as $item) {
  1109. $key = $item['currency']."_".$item['invoice_date'];
  1110. if(array_key_exists($key, $groupedItems)){
  1111. $temp = $groupedItems[$key];
  1112. $temp['invoice_amount'] = $temp['invoice_amount'] + $item['ivnoice_amount'];
  1113. $groupedItems[$key] = $temp;
  1114. }else{
  1115. $groupedItems[$key] = array("month"=>$item['invoice_date'],"currency"=>$item['currency'],"invoice_amount"=>$item['ivnoice_amount']);
  1116. }
  1117. }
  1118. $r2_data = array();
  1119. foreach($groupedItems as $gt){
  1120. $gt['invoice_amount'] = number_format($gt['invoice_amount'], 4, '.', '');
  1121. $r2_data[] = $gt;
  1122. }
  1123. common::echo_json_encode(200,array("msg"=>"success","r2" => $r2_data,"r3"=>$r3_data,"r2_cloumn" => $r2_cloumn,"r3_cloumn" => $r3_cloumn,
  1124. "r2_title"=>"Monthly Summary Data","r3_title"=>"Invoice Detailed Data"));
  1125. exit;
  1126. }
  1127. private function _ams_isf_log(){
  1128. global $cbpdb;
  1129. $ams_ss = $_POST['ams_ss'];
  1130. $isf_ss = $_POST['isf_ss'];
  1131. $amsLog = array();
  1132. //页面固定写死的信息
  1133. $amsLog_column = array();
  1134. $amsLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"dateTime");
  1135. $amsLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  1136. $amsLog_column[] = array("title" =>"Name","field" =>"isams_submit","formatter" =>"","type" =>"normal");
  1137. $amsLog_column[] = array("title" =>"Description","field" =>"amslog","formatter" =>"","type" =>"normal");
  1138. $amsLog["amsLog_column"] = $amsLog_column;
  1139. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  1140. $amsLog["data"] = array();
  1141. if (_canViewAMSLog()) {
  1142. $s = $ams_ss;
  1143. //$s = "PDLA200127H";
  1144. if (!empty($s)) {
  1145. //$cc = $cbpdb->GetAll("select distinct h_bol from ams_information where md5(md5(from_serial_no)) = '" . pg_escape_string($s) . "'");
  1146. $cc = $cbpdb->GetAll("select distinct h_bol from ams_information where h_bol = '" . pg_escape_string($s) . "'");
  1147. foreach ($cc as $v){
  1148. $amses[] = $cbpdb->GetAll("select * from ams_info where h_bol = '" . pg_escape_string($v['h_bol']) . "'");
  1149. }
  1150. //考虑一个情况
  1151. if (utils::count($amses) > 0) {
  1152. $ams = $amses[0];
  1153. $carrier_hbol = substr($ams[0]['m_bol'], 4);
  1154. $carrier_scac = substr($ams[0]['m_bol'], 0, 4);
  1155. if (empty($ams[0]['h_bol'])){
  1156. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  1157. $amsLog["data"] = array();
  1158. }else{
  1159. $log = $cbpdb->GetAll("select cbpreplytime as atime, amslog, cbperrorcode, isams_submit
  1160. from v_e_amslog where hbol = '" . pg_escape_string($ams[0]['h_bol']) . "'
  1161. and split_part(stationname, ',', 1) = split_part('" . pg_escape_string($ams[0]['station_name']) . "', ',', 1)
  1162. order by cbpreplytime desc, substr(cbperrorcode, 2, 1) desc");
  1163. $amsLog["msg"] = "";
  1164. $amsLog["data"] = $log;
  1165. }
  1166. }
  1167. }
  1168. }
  1169. $isfLog = array();
  1170. //页面固定写死的信息
  1171. $isfLog_column = array();
  1172. $isfLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"dateTime");
  1173. $isfLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  1174. $isfLog_column[] = array("title" =>"Name","field" =>"isfsubmit","formatter" =>"","type" =>"normal");
  1175. $isfLog_column[] = array("title" =>"Description","field" =>"isflog","formatter" =>"","type" =>"normal");
  1176. $isfLog["isfLog_column"] = $isfLog_column;
  1177. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  1178. $isfLog["data"] = array();
  1179. if (_canViewISFLog()) {
  1180. if (!empty($isf_ss)) {
  1181. $ss = $isf_ss;
  1182. $len = strlen($ss);
  1183. $b = substr($ss, $len - 7) . substr($ss, 0, $len - 7);
  1184. if (empty($b)){
  1185. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  1186. $isfLog["data"] = array();
  1187. }else{
  1188. $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");
  1189. }
  1190. if (!empty($isf)) {
  1191. if (!empty($isf['dob'])){
  1192. $isf['dob'] = date("m/d/Y", strtotime($isf['dob']));
  1193. }
  1194. $msg = $cbpdb->GetAll("select cbpreplytime as atime, isflog, cbperrorcode, isfsubmit, hbol
  1195. from v_e_isflog where (case when coalesce(isf_no, '')<>''
  1196. then isf_no = '" . pg_escape_string($isf["isf_no"]) . "' else hbol = '" . pg_escape_string($isf["bol"]) . "'
  1197. and stationname = '" . pg_escape_string($isf["station_name"]) . "' end)
  1198. order by cbpreplytime desc, rowid desc");
  1199. $isfLog["msg"] = "";
  1200. $isfLog["data"] = $msg;
  1201. }else{
  1202. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  1203. $isfLog["data"] = array();
  1204. }
  1205. }
  1206. }
  1207. $data =array("msg"=>"success",
  1208. "canViewAMSLog" => _canViewAMSLog(),
  1209. "canViewISFLog" => _canViewISFLog(),
  1210. "amsLog" =>$amsLog,
  1211. "isfLog" =>$isfLog);
  1212. common::echo_json_encode(200,$data);
  1213. exit;
  1214. }
  1215. private function getEmail($serial_no) {
  1216. return utils::getEmail($serial_no);
  1217. }
  1218. private function getCommunicationNew($serial_no) {
  1219. $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");
  1220. $emialRecords =array();
  1221. foreach ($list as $k => $v) {
  1222. $msg =array();
  1223. $msg["name"] = $v["add_by"];
  1224. $msg["creatTime"] = $v["add_times"];
  1225. $msg["content"] = urldecode($v["web_content"]);
  1226. $emialRecords[] = $msg;
  1227. }
  1228. return $emialRecords;
  1229. }
  1230. /*
  1231. * get file by hbol/destination
  1232. * H:HBL
  1233. * M: MBL
  1234. * F: FL
  1235. * I: C/I & Packing list
  1236. */
  1237. private function getOceanFileByHbol($m_bol, $h_bol, $types, $m_bs, $display, $detail = FALSE,$job_no="") {
  1238. $_schemas = $_REQUEST['_schemas'];
  1239. $types = strtolower($types);
  1240. $types = explode(";", $types);
  1241. $m_bs = explode(";", $m_bs);
  1242. $otheres = NULL;
  1243. $filefilter = " ('TELEX') ";//过滤掉类型,单独配置 3537
  1244. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  1245. $file = array();
  1246. foreach ($types as $k => $type) {
  1247. $m_b = $m_bs[$k];
  1248. if (strtolower($m_b) == 'm')
  1249. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1250. 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";
  1251. if (strtolower($m_b) == 'h')
  1252. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1253. 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";
  1254. if (strtolower($m_b) == 'a')
  1255. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = ra_online_doc_upload.format_serailno) as format_name,
  1256. 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";
  1257. if (!empty($sql)) {
  1258. $rss = common::excuteListSql($sql);
  1259. foreach ($rss as $rs) {
  1260. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  1261. $file[] = array("url"=>$OutFileURL.'/download.php?_schemas=&a='.base64_encode(base64_encode($rs['serial_no'])),
  1262. "file_name" => $rs['file_name'],
  1263. "format_name" => $rs['format_name'],
  1264. "detail"=>$rs['upload_date'],
  1265. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1266. "from_system" =>'TOPOCEAN_KSMART');
  1267. }else {
  1268. $file[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  1269. "file_name" => $rs['file_name'],
  1270. "format_name" => $rs['format_name'],
  1271. "detail"=>$rs['upload_date'],
  1272. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1273. "from_system" =>'');
  1274. }
  1275. }
  1276. }
  1277. }
  1278. return $file;
  1279. }
  1280. /*
  1281. * get file by hbol/destination
  1282. * H:HBL
  1283. * M: MBL
  1284. * F: FL
  1285. * I: C/I & Packing list
  1286. */
  1287. private function getAirFileByHbol($m_bol, $h_bol, $types, $m_bs, $display, $detail = FALSE) {
  1288. $_schemas = $_REQUEST['_schemas'];
  1289. $types = explode(";", $types);
  1290. $m_bs = explode(";", $m_bs);
  1291. $filefilter = " ('TELEX') ";//过滤掉类型,单独配置 3537
  1292. $file = array();
  1293. foreach ($types as $k => $type) {
  1294. $m_b = $m_bs[$k];
  1295. if (strtolower($m_b) == 'm')
  1296. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1297. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date from air_doc_upload where lower(bol) = '" . strtolower($m_bol) . "' and lower(format_serailno) " . common::getInNotInSql($type) . " and upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter." order by id desc";
  1298. if (strtolower($m_b) == 'h')
  1299. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1300. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date from air_doc_upload where lower(bol) = '" . strtolower($h_bol) . "' and lower(format_serailno) " . common::getInNotInSql($type) . " and upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter." order by id desc";
  1301. if (strtolower($m_b) == 'a')
  1302. $sql = "SELECT (SELECT format_name from $_schemas.ra_online_file_format where serial_no = air_doc_upload.format_serailno) as format_name,
  1303. file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date from air_doc_upload where (lower(bol) = '" . strtolower($m_bol) . "' or lower(bol) = '" . strtolower($h_bol) . "') and lower(format_serailno) " . common::getInNotInSql($type) . "and upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter." order by id desc";
  1304. if (!empty($sql)) {
  1305. $rss = common::excuteListSql($sql);
  1306. foreach ($rss as $rs) {
  1307. $file[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  1308. "file_name" => $rs['file_name'],
  1309. "format_name" => $rs['format_name'],
  1310. "detail"=>$rs['upload_date'],
  1311. "can_delete"=>_getLoginName() == $rs['upload_by'],
  1312. "from_system" =>'');
  1313. }
  1314. }
  1315. }
  1316. return $file;
  1317. }
  1318. /*
  1319. * download file
  1320. */
  1321. private function _download() {
  1322. $url = common::deCode($_GET['url'], 'D');
  1323. common::download_file($url);
  1324. }
  1325. private function save_vgm() {
  1326. $schemas = $_POST["schemas"];
  1327. $serial_no = common::deCode($_POST["serial_no"], 'D');
  1328. $ocean = common::excuteObjectSql("select m_bol, master_base_number, from_station, h_bol from $schemas.ocean where serial_no='" . common::check_input($serial_no) . "'");
  1329. $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"] . "'");
  1330. $address = $contact["address_1"];
  1331. if (!empty($address)) {
  1332. $address .= "\r\n";
  1333. }
  1334. $address .= $contact["address_2"];
  1335. if (!empty($address)) {
  1336. $address .= "\r\n";
  1337. }
  1338. $address .= $contact["address_3"];
  1339. if (!empty($address)) {
  1340. $address .= "\r\n";
  1341. }
  1342. $address .= $contact["address_4"];
  1343. $exists = common::excuteOneSql("select serial_no from $schemas.ocean_vgm_masterbasenumber where master_base_number ilike '" . $ocean["master_base_number"] . "'");
  1344. global $db;
  1345. $db->StartTrans();
  1346. if (empty($_POST["is_send"])) {
  1347. $_POST["is_send"] = 'f';
  1348. }
  1349. if (empty($exists)) {
  1350. $db->Execute("insert into ocean_vgm_masterbasenumber (master_base_number, serial_no) values ('" . $ocean["master_base_number"] . "', '$serial_no');");
  1351. $value["serial_no"] = $serial_no;
  1352. $value["carrier_booking_no"] = $_POST["all_carrier_booking"];
  1353. $value["modify_user"] = _getLoginName();
  1354. $value["modify_time"] = "now()";
  1355. $value["authorized_email"] = !empty($_POST["authorized_email"]) ? $_POST["authorized_email"] : "";
  1356. $value["authorized_tel"] = !empty($_POST["authorized_tel"]) ? $_POST["authorized_tel"] : "";
  1357. $value["authorized_company"] = !empty($_POST["submitter"]) ? $_POST["submitter"] : "";
  1358. $value["signature"] = !empty($_POST["signature"]) ? $_POST["signature"] : "";
  1359. $value["is_send"] = $_POST["is_send"];
  1360. $value["action"] = "New";
  1361. $value["type"] = "Shipper";
  1362. $value["m_bol"] = $ocean["m_bol"];
  1363. $value["master_base_number"] = $ocean["master_base_number"];
  1364. $value["shipper_id"] = $ocean["from_station"];
  1365. $value["shipper"] = $contact["company"];
  1366. $value["shipper_address"] = $address;
  1367. $value["shipper_contactname"] = $contact["contactname_1"];
  1368. $value["shipper_email"] = $contact["email_1"];
  1369. $value["shipper_fax"] = $contact["fax"];
  1370. $value["shipper_telephone"] = $contact["phone_1"];
  1371. $value["update_uuid"] = utils::uuid();
  1372. $value["h_bol"] = $ocean["h_bol"];
  1373. $value["from_station"] = $ocean["from_station"];
  1374. $sql = common::getInsertSqlNull("$schemas .ocean_vgm", $value);
  1375. $db->Execute($sql);
  1376. } else {
  1377. $serial_no = $exists;
  1378. $db->Execute("update ocean_vgm_masterbasenumber set id=id where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  1379. $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(),"
  1380. . "authorized_email='" . $_POST["authorized_email"] . "', authorized_tel='" . $_POST["authorized_tel"] . "', authorized_company='" . $_POST["submitter"] . "', signature='" . $_POST["signature"] . "', send_time=null "
  1381. . ", update_uuid='" . utils::uuid() . "' where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  1382. }
  1383. $db->Execute("delete from ocean_vgm_container where serial_no ilike '" . $serial_no . "';");
  1384. foreach ($_POST["container_no"] as $i => $cv) {
  1385. $value1["serial_no"] = $serial_no;
  1386. $value1["carrier_booking_no"] = !empty($_POST["carrier_booking_no"][$i]) ? $_POST["carrier_booking_no"][$i] : "";
  1387. $value1["ctnr"] = !empty($_POST["container_no"][$i]) ? $_POST["container_no"][$i] : "";
  1388. $value1["size"] = !empty($_POST["size"][$i]) ? $_POST["size"][$i] : "";
  1389. $value1["vgm_weight"] = !empty($_POST["vgm_weight"][$i]) ? $_POST["vgm_weight"][$i] : "";
  1390. $value1["unit"] = !empty($_POST["vgm_kg_lg"][$i]) ? $_POST["vgm_kg_lg"][$i] : "";
  1391. $value1["vgm_time"] = !empty($_POST["vgm_date"][$i]) ? $_POST["vgm_date"][$i] : "";
  1392. $value1["cargo_weight_kgs"] = !empty($_POST["cargo_weight_kg"][$i]) ? $_POST["cargo_weight_kg"][$i] : "";
  1393. $value1["cargo_weight_lbs"] = !empty($_POST["cargo_weight_lb"][$i]) ? $_POST["cargo_weight_lb"][$i] : "";
  1394. $value1["vgm_method"] = !empty($_POST["vgm_method"][$i]) ? $_POST["vgm_method"][$i] : "";
  1395. $value1["master_base_number"] = $ocean["master_base_number"];
  1396. $sql = common::getInsertSqlNull("$schemas.ocean_vgm_container", $value1);
  1397. $db->Execute($sql);
  1398. }
  1399. if ($db->CompleteTrans() === FALSE) {
  1400. return "error";
  1401. } else {
  1402. return "success";
  1403. }
  1404. }
  1405. private function getOceanDetail($serial_no) {
  1406. $order_from = $_REQUEST['_schemas'];
  1407. $_schemas = $_REQUEST['_schemas'];
  1408. if($_schemas == 'public'){
  1409. $_schemas = "ocean";
  1410. }
  1411. $sql = "with o as(
  1412. SELECT o.* from ocean o where serial_no = '" . $serial_no . "'
  1413. )
  1414. SELECT m_eta as _m_eta, h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
  1415. o.* ,sh.*, cn.* ,aa.*,dd.*,fd.*,oo.*,
  1416. (select uncode from ports where code = o.port_of_transshipment) as port_of_transshipment_un
  1417. from o
  1418. LEFT JOIN LATERAL ( SELECT tracking_no as _tracking_no,shippr_uncode,shipper_city,
  1419. consignee_uncode,consignee_city,incoterms,
  1420. fport_of_loading_un,
  1421. mport_of_discharge_un,
  1422. place_of_receipt_un,
  1423. place_of_delivery_un,
  1424. (select time_zone from public.city_timezone where uncode = oo.fport_of_loading_un limit 1) as pol_timezone,
  1425. (select uncity from public.ports where uncode = oo.fport_of_loading_un limit 1) as pol_uncity,
  1426. (select time_zone from public.city_timezone where uncode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
  1427. (select uncity from public.ports where uncode = oo.mport_of_discharge_un limit 1) as mpod_uncity,
  1428. (select time_zone from public.city_timezone where uncode = oo.place_of_receipt_un limit 1) as por_timezone,
  1429. (select uncity from public.ports where uncode = oo.place_of_receipt_un limit 1) as por_uncity,
  1430. (select time_zone from public.city_timezone where uncode = oo.place_of_delivery_un limit 1) as pod_timezone,
  1431. (select uncity from public.ports where uncode = oo.place_of_delivery_un limit 1) as pod_uncity,
  1432. (select time_zone from public.city_timezone where uncode = oo.final_desination_uncode limit 1) as _fd_timezone,
  1433. (select uncity from public.ports where uncode = oo.final_desination_uncode limit 1) as _pd_uncity,
  1434. po_no as _po_no,
  1435. CASE
  1436. WHEN ((m_iffbcf is not null or m_iffbcf is null) and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Created'::text
  1437. WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Cargo Received'::text
  1438. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  1439. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  1440. WHEN (m_iffdel is not null) THEN 'Completed'::text
  1441. ELSE 'Created'::text
  1442. END AS new_status
  1443. FROM public.kln_ocean oo WHERE oo.serial_no::text = o.serial_no::text and order_from = '$order_from') oo ON true
  1444. LEFT JOIN LATERAL ( SELECT company as cn_company,
  1445. address_1 as cn_address_1,
  1446. address_2 as cn_address_2,
  1447. address_3 as cn_address_3,
  1448. address_4 as cn_address_4,
  1449. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  1450. phone_1 as cn_phone
  1451. FROM $_schemas.contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
  1452. LEFT JOIN LATERAL ( SELECT company as sh_company,
  1453. address_1 as sh_address_1,
  1454. address_2 as sh_address_2,
  1455. address_3 as sh_address_3,
  1456. address_4 as sh_address_4,
  1457. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  1458. phone_1 as sh_phone
  1459. FROM $_schemas.contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
  1460. LEFT JOIN LATERAL ( SELECT company as aa_company,
  1461. address_1 as aa_address_1,
  1462. address_2 as aa_address_2,
  1463. address_3 as aa_address_3,
  1464. address_4 as aa_address_4,
  1465. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  1466. phone_1 as aa_phone,
  1467. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as aa_timezone
  1468. FROM $_schemas.contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
  1469. LEFT JOIN LATERAL ( SELECT company as dd_company,
  1470. address_1 as dd_address_1,
  1471. address_2 as dd_address_2,
  1472. address_3 as dd_address_3,
  1473. address_4 as dd_address_4,
  1474. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  1475. phone_1 as dd_phone,
  1476. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as dd_timezone
  1477. FROM $_schemas.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
  1478. LEFT JOIN LATERAL ( SELECT
  1479. city as fd_city,
  1480. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as fd_timezone
  1481. FROM $_schemas.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true";
  1482. //error_log($sql);
  1483. return $sql;
  1484. }
  1485. private function getAirDetail($serial_no) {
  1486. $order_from = $_REQUEST['_schemas'];
  1487. $_schemas = $_REQUEST['_schemas'];
  1488. if($_schemas == 'public'){
  1489. $_schemas = "ocean";
  1490. }
  1491. $sql = "with o as(
  1492. SELECT oo.*,m_bol as _m_bol, h_bol as _h_bol,
  1493. (select time_zone from public.city_timezone where uncode = oo.fport_of_loading_un limit 1) as pol_timezone,
  1494. (select uncity from public.ports where uncode = oo.fport_of_loading_un limit 1) as pol_uncity,
  1495. (select time_zone from public.city_timezone where uncode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
  1496. (select uncity from public.ports where uncode = oo.mport_of_discharge_un limit 1) as mpod_uncity,
  1497. (select time_zone from public.city_timezone where uncode = oo.place_of_receipt_un limit 1) as por_timezone,
  1498. (select uncity from public.ports where uncode = oo.place_of_receipt_un limit 1) as por_uncity,
  1499. (select time_zone from public.city_timezone where uncode = oo.place_of_delivery_un limit 1) as pod_timezone,
  1500. (select uncity from public.ports where uncode = oo.place_of_delivery_un limit 1) as pod_uncity,
  1501. (select time_zone from public.city_timezone where uncode = oo.final_desination_uncode limit 1) as _fd_timezone,
  1502. (select uncity from public.ports where uncode = oo.final_desination_uncode limit 1) as _pd_uncity,
  1503. CASE
  1504. WHEN ((m_iffbcf is not null or m_iffbcf is null) and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Created'::text
  1505. WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Cargo Received'::text
  1506. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  1507. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  1508. WHEN (m_iffdel is not null) THEN 'Completed'::text
  1509. ELSE 'Created'::text
  1510. END AS new_status
  1511. from public.kln_ocean oo where oo.serial_no = '" . $serial_no . "' and oo.order_from = '$order_from'
  1512. )
  1513. SELECT o.* ,sh.*, cn.*,
  1514. aa.*,dd.*,fd.*,air.*
  1515. from o
  1516. LEFT JOIN LATERAL ( SELECT departure_airport_name as fport_of_loading_exp,
  1517. destination_airport_name as mport_of_discharge_exp,
  1518. mawb as _mawb, mawb_name as _mawb_name, hawb as _hawb
  1519. FROM $order_from.air a WHERE a.serial_no = o.serial_no) air ON true
  1520. LEFT JOIN LATERAL ( SELECT company as cn_company,
  1521. address_1 as cn_address_1,
  1522. address_2 as cn_address_2,
  1523. address_3 as cn_address_3,
  1524. address_4 as cn_address_4,
  1525. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  1526. phone_1 as cn_phone
  1527. FROM $_schemas.contacts c WHERE o.consignee_id::text = c.contact_id::text) cn ON true
  1528. LEFT JOIN LATERAL ( SELECT company as sh_company,
  1529. address_1 as sh_address_1,
  1530. address_2 as sh_address_2,
  1531. address_3 as sh_address_3,
  1532. address_4 as sh_address_4,
  1533. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  1534. phone_1 as sh_phone
  1535. FROM $_schemas.contacts c WHERE o.shipper_id::text = c.contact_id::text) sh ON true
  1536. LEFT JOIN LATERAL ( SELECT company as aa_company,
  1537. address_1 as aa_address_1,
  1538. address_2 as aa_address_2,
  1539. address_3 as aa_address_3,
  1540. address_4 as aa_address_4,
  1541. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  1542. phone_1 as aa_phone,
  1543. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as aa_timezone
  1544. FROM $_schemas.contacts c WHERE o.origin::text = c.contact_id::text) aa ON true
  1545. LEFT JOIN LATERAL ( SELECT company as dd_company,
  1546. address_1 as dd_address_1,
  1547. address_2 as dd_address_2,
  1548. address_3 as dd_address_3,
  1549. address_4 as dd_address_4,
  1550. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  1551. phone_1 as dd_phone,
  1552. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as dd_timezone
  1553. FROM $_schemas.contacts c WHERE o.agent::text = c.contact_id::text) dd ON true
  1554. LEFT JOIN LATERAL ( SELECT
  1555. city as fd_city,
  1556. (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as fd_timezone
  1557. FROM $_schemas.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true";
  1558. //error_log($sql);
  1559. return $sql;
  1560. }
  1561. private function returnOceanDetailData($ocean,$state){
  1562. $data = array();
  1563. //由于这些基础数据还待完善,而且现在提单样式改版也没有显示客户自身的地址数据,所以我们这边的这个取值也要麻烦调整一下:
  1564. //1.Shipment detail顶部的Origin和Destination的取值换成Place of Receipt、Place of Delivery的UNCODE
  1565. //2.Tracking列表页里面字段Origin和Destination先隐藏(客户地址),不做展示
  1566. $ocean['shippr_uncode'] = $ocean['place_of_receipt_un'];
  1567. $ocean['consignee_uncode'] = $ocean['place_of_delivery_un'];
  1568. /* Container Status */
  1569. //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
  1570. //记录所有的信息 EDI315TimeAndLocation
  1571. $EDIDate = common::getEDI315StatusForDetail($ocean["serial_no"]);
  1572. $data['containerStatusData'] = $EDIDate['containerStatusData'];
  1573. $data['EDI315TimeAndLocation'] = $EDIDate['EDI315TimeAndLocation'];
  1574. $VD = $EDIDate['VD'];
  1575. $VA = $EDIDate['VA'];
  1576. //处理shipment data
  1577. $ocean_milestone_status = common::excuteListSql("select code,
  1578. act_date,est_date,timezone
  1579. from ocean_milestone a
  1580. where a.serial_no='".$ocean["serial_no"]."' and code in('IFFREC','IFFONB','IFFDEP','IFFARR','IFFDEL')
  1581. order by id");
  1582. $ocean_milestone_status_code = array();
  1583. foreach($ocean_milestone_status as $oms){
  1584. $ocean_milestone_status_code[$oms['code']] = $oms;
  1585. }
  1586. if ($state < 1){
  1587. //未发生前
  1588. if(!empty($ocean_milestone_status_code['IFFDEP']['est_date'])){
  1589. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  1590. $ocean['f_etd'] = $ocean_milestone_status_code['IFFDEP']['est_date'];
  1591. }
  1592. } else{
  1593. if(!empty($ocean_milestone_status_code['IFFDEP']['act_date'])){
  1594. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  1595. $ocean['atd'] = $ocean_milestone_status_code['IFFDEP']['act_date'];
  1596. }
  1597. }
  1598. //先处理一下 ATD 和 ATA,在进行后面的取值
  1599. if(empty($ocean['atd']) && !empty($VD)){
  1600. $ocean['atd'] = $VD;
  1601. }
  1602. if(empty($ocean['ata']) && !empty($VA)){
  1603. $ocean['ata'] = $VA;
  1604. }
  1605. $simplexData = array();
  1606. //place_of_Receipt
  1607. $place_of_Receipt_stauts = array("index" =>1,"label" =>"Place of Receipt",
  1608. "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt_un'],"isArrival" =>$state >= 0 ? true : false);
  1609. $children = array();
  1610. if($state >= 1 && !empty($ocean_milestone_status_code['IFFREC']['act_date'])){
  1611. //发生后,未发生前没有
  1612. $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFREC']['act_date']);
  1613. }
  1614. $place_of_Receipt_stauts["children"] = $children;
  1615. $simplexData[] = $place_of_Receipt_stauts;
  1616. //port_of_Loading
  1617. $port_of_Loading_stauts = array("index" =>2,"label" =>"Port of Loading",
  1618. "path" =>$ocean['fport_of_loading_exp']."/".$ocean['fport_of_loading_un'],"isArrival" =>$state >= 1 ? true : false);
  1619. $children = array();
  1620. if ($state < 1){
  1621. $children[] = array("label" =>"Departure(ETD)","date" =>$ocean['f_etd']);
  1622. } else{
  1623. if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
  1624. $children[] = array("label" =>"On board","date" =>$ocean_milestone_status_code['IFFONB']['act_date']);
  1625. }
  1626. $children[] = array("label" =>"Departure(ATD)","date" =>$ocean['atd']);
  1627. }
  1628. $port_of_Loading_stauts["children"] = $children;
  1629. $simplexData[] = $port_of_Loading_stauts;
  1630. //Port of Discharge
  1631. $port_of_Discharge_status = array("index" =>3,"label" =>"Port of Discharge",
  1632. "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge_un'],"isArrival" =>$state >= 2 ? true : false);
  1633. $children = array();
  1634. // if ($state < 2){
  1635. // //未发生前
  1636. // if(!empty($ocean_milestone_status_code['IFFARR']['est_date'])){
  1637. // $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean_milestone_status_code['IFFARR']['est_date']);
  1638. // }else{
  1639. // //没有,取eta
  1640. // $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['m_eta']);
  1641. // }
  1642. // } else{
  1643. // if(!empty($ocean_milestone_status_code['IFFARR']['act_date'])){
  1644. // $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean_milestone_status_code['IFFARR']['act_date']);
  1645. // }
  1646. // }
  1647. //不需要判断是否发送,根据 milestone 和m_eta 的同步关系,这里m_eta 优先度最高
  1648. if ($state < 2){
  1649. $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['m_eta']);
  1650. }else{
  1651. $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean['ata']);
  1652. }
  1653. $port_of_Discharge_status["children"] = $children;
  1654. $simplexData[] = $port_of_Discharge_status;
  1655. //Place of Delivery
  1656. $place_of_Delivery_status = array("index" =>4,"label" =>"Place of Delivery",
  1657. "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery_un'],"isArrival" =>$state == 3 ? true : false);
  1658. $children = array();
  1659. if ($state < 3){
  1660. //未发生前
  1661. } else{
  1662. if(!empty($ocean_milestone_status_code['IFFDEL']['act_date'])){
  1663. $children[] = array("label" =>"Cargo handover/Delivered","date" =>$ocean_milestone_status_code['IFFDEL']['act_date']);
  1664. }
  1665. }
  1666. $simplexData[] = $place_of_Delivery_status;
  1667. $data['shipmentData'] = $simplexData;
  1668. //处理transportInfo信息数据(air改过,从KLN_Ocean主表信息 etd 和eta 的取值跟ocean的f_etd,m_eta)
  1669. $transportInfo = array("Tracking No." =>$ocean['_tracking_no'],"status"=>$ocean['new_status'],"mode" => "Ocean Freight",
  1670. "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
  1671. "etd" =>$ocean['f_etd'],"atd" =>$ocean['atd'],
  1672. "etd_timezone" =>$ocean['pol_timezone'],
  1673. "atd_timezone" =>$ocean['pol_timezone'],
  1674. "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
  1675. "eta_timezone" =>$ocean['mpod_timezone'],
  1676. "ata_timezone" =>$ocean['mpod_timezone']);
  1677. $data['transportInfo'] = $transportInfo;
  1678. //处理basicInfo信息数据
  1679. $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
  1680. $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
  1681. $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['booking_no'],
  1682. "PO_NO" =>$ocean['_po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  1683. "Incoterm" =>$ocean['incoterms'],"Service_Type" =>$ocean['service']);
  1684. $data['basicInfo'] = $basicInfo;
  1685. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  1686. $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  1687. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  1688. $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  1689. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  1690. $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  1691. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  1692. $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  1693. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  1694. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  1695. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  1696. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  1697. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  1698. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  1699. $data['businessPartners'] = $businessPartners;
  1700. //处理routes 转船可能有多个情况
  1701. if ($ocean['is_vessel_direct'] <> "t"){
  1702. //不是直航
  1703. $routes = array(array("mode" =>"Ocean Freight","mode_label" =>"Sea", "origin" =>$ocean['shippr_uncode'],
  1704. "destination" => $ocean['port_of_transshipment_un'],
  1705. "etd" => $ocean['f_etd'],"atd" => $ocean['atd'],
  1706. "eta" =>$ocean['f_eta'],"ata" =>"",
  1707. "vessel" =>$ocean['f_vessel'],"voyageNo" =>$ocean['f_voyage']));
  1708. $routes[] = array("mode" =>"Ocean Freight", "mode_label" =>"Sea","origin" =>$ocean['port_of_transshipment_un'],
  1709. "destination" => $ocean['consignee_uncode'],
  1710. "etd" => $ocean['m_etd'],"atd" => "",
  1711. "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
  1712. "vessel" =>$ocean['m_vessel'],"voyageNo" =>$ocean['m_voyage']);
  1713. }else{
  1714. $routes = array(array("mode" =>"Ocean Freight","mode_label" =>"Sea", "origin" =>$ocean['shippr_uncode'],
  1715. "destination" => $ocean['consignee_uncode'],
  1716. "etd" => $ocean['f_etd'],"atd" => $ocean['atd'],
  1717. "eta" =>$ocean['m_eta'],"ata" => $ocean['ata'],
  1718. "vessel" =>$ocean['f_vessel'],"voyageNo" =>$ocean['f_voyage']));
  1719. }
  1720. $data['routes'] = $routes;
  1721. //处理marksAndDescription
  1722. $notes = common::excuteListSql("select notes from station_data.ocean_notes on2 where serial_no='".$ocean["serial_no"]."' and type_code = 'AO'");
  1723. $remark = "";
  1724. foreach($notes as $note){
  1725. if(!empty($note['notes'])){
  1726. $remark.=$note['notes']."\r\n";
  1727. }
  1728. }
  1729. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description'],"remark"=>$remark);
  1730. $data['marksAndDescription'] = $marksAndDescription;
  1731. return $data;
  1732. }
  1733. private function returnAirDetailData($ocean,$ocean_milestone_status,$state){
  1734. $data = array();
  1735. //由于这些基础数据还待完善,而且现在提单样式改版也没有显示客户自身的地址数据,所以我们这边的这个取值也要麻烦调整一下:
  1736. //1.Shipment detail顶部的Origin和Destination的取值换成Place of Receipt、Place of Delivery的UNCODE
  1737. //2.Tracking列表页里面字段Origin和Destination先隐藏(客户地址),不做展示
  1738. //Origin和Destination的展示,能不能Origin of Cargo有值就用Origin of Cargo,Origin of Cargo就放Departure Airport? Destination也一樣?
  1739. $ocean['shippr_uncode'] = !empty($ocean['place_of_receipt_un'])? $ocean['place_of_receipt_un'] : $ocean['fport_of_loading_un'];
  1740. $ocean['consignee_uncode'] = !empty($ocean['place_of_delivery_un']) ? $ocean['place_of_delivery_un'] : $ocean['mport_of_discharge_un'];
  1741. //处理shipment data
  1742. $ocean_milestone_status_code = array();
  1743. foreach($ocean_milestone_status as $oms){
  1744. $ocean_milestone_status_code[$oms['code']] = $oms;
  1745. }
  1746. if ($state < 1){
  1747. //未发生前
  1748. if(!empty($ocean_milestone_status_code['IFFONB']['est_date'])){
  1749. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  1750. $ocean['etd'] = $ocean_milestone_status_code['IFFONB']['est_date'];
  1751. }
  1752. } else{
  1753. if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
  1754. //如果milestone有值,或者与milestone不等,以milestone的优先度最高
  1755. //ATD 取值为IFFONB milestone实际发生的时间
  1756. $ocean['atd'] = $ocean_milestone_status_code['IFFONB']['act_date'];
  1757. }
  1758. }
  1759. $simplexData = array();
  1760. //place_of_Receipt
  1761. $place_of_Receipt_stauts = array("index" =>1,"label" =>"Place of Receipt",
  1762. "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt_un'],"isArrival" =>$state >= 0 ? true : false);
  1763. $children = array();
  1764. if($state >= 1 && !empty($ocean_milestone_status_code['IFFCPU']['act_date'])){
  1765. //发生后,未发生前没有
  1766. $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFCPU']['act_date']);
  1767. }
  1768. $place_of_Receipt_stauts["children"] = $children;
  1769. $simplexData[] = $place_of_Receipt_stauts;
  1770. //port_of_Loading
  1771. $port_of_Loading_stauts = array("index" =>2,"label" =>"Port of Loading",
  1772. "path" =>$ocean['fport_of_loading_exp']."/".$ocean['fport_of_loading_un'],"isArrival" =>$state >= 1 ? true : false);
  1773. $children = array();
  1774. if ($state < 1){
  1775. $children[] = array("label" =>"Departure(ETD)","date" =>$ocean['etd']);
  1776. } else{
  1777. if(!empty($ocean_milestone_status_code['IFFREC']['act_date'])){
  1778. $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFREC']['act_date']);
  1779. }
  1780. if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
  1781. $children[] = array("label" =>"Departure(ATD)","date" =>$ocean_milestone_status_code['IFFONB']['act_date']);
  1782. }
  1783. }
  1784. $port_of_Loading_stauts["children"] = $children;
  1785. $simplexData[] = $port_of_Loading_stauts;
  1786. //Port of Discharge
  1787. $port_of_Discharge_status = array("index" =>3,"label" =>"Port of Discharge",
  1788. "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge_un'],"isArrival" =>$state >= 2 ? true : false);
  1789. $children = array();
  1790. if ($state < 2){
  1791. $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['eta']);
  1792. }else{
  1793. if(!empty($ocean_milestone_status_code['IFFARR']['act_date'])){
  1794. $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean_milestone_status_code['IFFARR']['act_date']);
  1795. $ocean['ata'] = $ocean_milestone_status_code['IFFARR']['act_date'];
  1796. }else{
  1797. //IFFARR 如果同步异常没有值时,去表里的 ata_date AS ata
  1798. $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean['ata']);
  1799. }
  1800. }
  1801. $port_of_Discharge_status["children"] = $children;
  1802. $simplexData[] = $port_of_Discharge_status;
  1803. //Place of Delivery
  1804. $place_of_Delivery_status = array("index" =>4,"label" =>"Place of Delivery",
  1805. "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery_un'],"isArrival" =>$state == 3 ? true : false);
  1806. $children = array();
  1807. if ($state < 3){
  1808. //未发生前
  1809. } else{
  1810. if(!empty($ocean_milestone_status_code['IFFDEL']['act_date'])){
  1811. $children[] = array("label" =>"Cargo handover/Delivered","date" =>$ocean_milestone_status_code['IFFDEL']['act_date']);
  1812. }
  1813. }
  1814. $simplexData[] = $place_of_Delivery_status;
  1815. $data['shipmentData'] = $simplexData;
  1816. //处理transportInfo信息数据(air改过,从KLN_Ocean主表信息 etd 和eta 的取值跟ocean的f_etd,m_eta)
  1817. $transportInfo = array("Tracking No." =>$ocean['tracking_no'],"status"=>$ocean['new_status'],"mode" => "Air Freight",
  1818. "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
  1819. "etd" =>$ocean['etd'],"atd" =>$ocean['atd'],
  1820. "etd_timezone" =>$ocean['pol_timezone'],
  1821. "atd_timezone" =>$ocean['pol_timezone'],
  1822. "eta" =>$ocean['eta'],"ata" =>$ocean['ata'],
  1823. "eta_timezone" =>$ocean['mpod_timezone'],
  1824. "ata_timezone" =>$ocean['mpod_timezone']);
  1825. $data['transportInfo'] = $transportInfo;
  1826. //处理basicInfo信息数据
  1827. $vessel = $ocean['vessel'];
  1828. $voyage = $ocean['voyage'];
  1829. $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['booking_no'],
  1830. "PO_NO" =>$ocean['po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  1831. "Incoterm" =>$ocean['incoterms'],"Service_Type" =>$ocean['service']);
  1832. $data['basicInfo'] = $basicInfo;
  1833. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  1834. $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  1835. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  1836. $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  1837. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  1838. $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  1839. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  1840. $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  1841. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  1842. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  1843. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  1844. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  1845. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  1846. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  1847. $data['businessPartners'] = $businessPartners;
  1848. //处理routes air不存在中转的
  1849. $routes = array(array("mode" =>"Air Freight","mode_label" =>"Air", "origin" =>$ocean['shippr_uncode'],
  1850. "destination" => $ocean['consignee_uncode'],
  1851. "etd" => $ocean['etd'],"atd" => $ocean['atd'],
  1852. "eta" => $ocean['eta'],"ata" => $ocean['ata'],
  1853. "vessel" =>$ocean['vessel'],"voyageNo" =>$ocean['voyage']));
  1854. $data['routes'] = $routes;
  1855. //处理marksAndDescription
  1856. $notes = common::excuteListSql("select notes from station_data.air_notes on2 where serial_no='".$ocean["serial_no"]."' and type_code = 'AO'");
  1857. $remark = "";
  1858. foreach($notes as $note){
  1859. if(!empty($note['notes'])){
  1860. $remark.=$note['notes']."\r\n";
  1861. }
  1862. }
  1863. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description'],"remark"=>$remark);
  1864. $data['marksAndDescription'] = $marksAndDescription;
  1865. return $data;
  1866. }
  1867. }
  1868. ?>