ocean_order.class.php 78 KB

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