ocean_order.class.php 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  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. /*
  28. * index page
  29. */
  30. if (empty($operate)) {
  31. //search
  32. //栏位信息
  33. $column = column::getInstance()->getDisplayColumn('Ocean_Search');
  34. $BookingTableColumns = column::getInstance()->tableColumns('Ocean_Search',$column);
  35. $data['TrackingTableColumns'] = $BookingTableColumns;
  36. common::echo_json_encode(200,$data);
  37. exit();
  38. }
  39. /*
  40. * ocean order search
  41. */
  42. if ($operate == "search") {
  43. $this->_ocean_search();
  44. }
  45. /*
  46. * ocean order detail
  47. */
  48. if ($operate == "detail") {
  49. $this->_ocean_detail();
  50. }
  51. if ($operate == "ams_isf_log"){
  52. $this->_ams_isf_log();
  53. }
  54. /*
  55. * export ocean order to excel
  56. */
  57. if ($operate == "excel") {
  58. $this->_ocean_excel();
  59. }
  60. if ($operate == 'setting_ocean_order_display') {
  61. column::getInstance()->settingDisplay('Ocean_Search', 'main_new_version.php?action=ocean_order');
  62. }
  63. /*
  64. * download document
  65. */
  66. if ($operate == "download") {
  67. $this->_download();
  68. }
  69. if ($operate == "save_communication") {
  70. try {
  71. $content = $_POST["content"];
  72. $content = common::check_input($content);
  73. $text = $_POST["text"];
  74. $content = urldecode($content);
  75. $web_content = urldecode($text);
  76. $communication_cc = $_POST["communication_cc"];
  77. $serial_no = common::uuid();
  78. $email_uuid = $_POST["serial_no"];
  79. $add_by = _getLoginName();
  80. $refer_id = 0;
  81. $email = $this->getEmail($email_uuid);
  82. $from_email = "US.KApex.Online@kerryapex.com";
  83. $to_email = $email["email"];
  84. $cc_email = $_SESSION['ONLINE_USER']['email'] . ";ApexOnlineCommunication@apexshipping.com";
  85. $communication_cc = trim($communication_cc);
  86. if (!empty($communication_cc)) {
  87. $communication_cc = common::check_input($communication_cc);
  88. $cc_email .= ";" . $communication_cc;
  89. }
  90. $user_from = _getLoginName();
  91. $user_to = $email["name"];
  92. $user_cc = $_SESSION['ONLINE_USER']['first_name'];
  93. if (empty($user_cc)) {
  94. $user_cc = _getLoginName();
  95. }
  96. $user_cc .= ";ApexOnlineCommunication";
  97. //邮件发送
  98. $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>@@";
  99. $emailSql = "select encode(public.pgp_sym_encrypt('" . $serial_no . "','pom_key'), 'base64')::text;";
  100. $key = common::excuteOneSql($emailSql);
  101. $historyEmails = "";
  102. $title = "Communication from " . _getLoginName() . ", HBOL: " . $email["h_bol"] . ", Consignee: " . $email["consignee"];
  103. $emailContent = $content . $poKey . $key . ";" . "@@<br>For your convenience weblink: https://ra.kerryapex.com/<br><br>" . $historyEmails;
  104. 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());");
  105. $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)
  106. VALUES ('$serial_no', '$email_uuid', '$emailContent','$web_content', '$user_from', '$to_email', '$cc_email', $refer_id, '$add_by', now(), '$communication_cc');");
  107. $emailRecords = $this->getCommunicationNew($email_uuid);
  108. common::echo_json_encode(200,array("msg" => "Sent Successfully", "emailRecords" => $emailRecords));
  109. exit();
  110. } catch (Exception $e) {
  111. common::echo_json_encode(500,array("msg" => "Sent Error."));
  112. exit();
  113. }
  114. }
  115. if ($operate == "ocean_vgm") {
  116. if (!_canEdiVgm()) {
  117. $data = array("msg" =>"Vgm Permission Error");
  118. common::echo_json_encode(200, $data);
  119. exit();
  120. }
  121. $serial_no = common::deCode(($_GET["a"]), 'D');
  122. $sqlWhere = " and o.serial_no='" . $serial_no . "'";
  123. $column = "*";
  124. $schemas = $_GET["_schemas"];
  125. if (empty($schemas)) {
  126. $schemas = "public";
  127. }
  128. $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 "
  129. . "$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;
  130. $ocean_info = common::excuteObjectSql($ocean_info_sql);
  131. $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 "
  132. . "$schemas.oc_container o left join $schemas.ocean oc on o.serial_no=oc.serial_no "
  133. . " left join $schemas.ocean_vgm ov on oc.serial_no=ov.serial_no or oc.master_base_number=ov.master_base_number "
  134. . " left join $schemas.ocean_vgm_container v on ov.serial_no=v.serial_no and o.ctnr=v.ctnr "
  135. . " 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"] . "'";
  136. $rs = common::excuteListSql($rs_sql);
  137. $ocean_info["is_send"] = (empty($ocean_info["is_send"]) ? "f" : $ocean_info["is_send"]);
  138. if (empty($ocean_info["id"])) {
  139. $ocean_info["is_send"] = "t";
  140. }
  141. $err_msg = "";
  142. if (empty($ocean_info["carrier_booking"])) {
  143. $err_msg = "Carrier Booking is empty.";
  144. }
  145. if ($schemas <> "public") {
  146. $err_msg .= "This hbol do not support.";
  147. }
  148. foreach ($rs as $cv) {
  149. if (empty($cv["ctnr"])) {
  150. $err_msg .= "Container# is empty.";
  151. }
  152. if (substr($cv["service"], 0, 3) == "CFS") {
  153. $err_msg .= "CFS cannot support update.";
  154. }
  155. }
  156. if (!empty($err_msg)) {
  157. $err_msg = "You cant't add this VGM, (" . $err_msg . ")";
  158. }
  159. $serial_no = common::deCode($serial_no, "E");
  160. //default
  161. if (empty($rs["id"])) {
  162. $default = common::excuteObjectSql("select * from ocean_vgm_setting where login_name ilike '" . _getLoginName() . "'");
  163. }
  164. $log = common::excuteListSql("select * from ocean_vermas where from_serial_no ilike '" . $ocean_info["master_base_number"] . "'");
  165. //detail information
  166. $detail_information_column = array();
  167. $detail_information_column[] = array("title" =>"SN","field" =>"sn","formatter" =>"","type" =>"normal");
  168. $detail_information_column[] = array("title" =>"Carrier Booking No.","field" =>"carrier_booking_no","formatter" =>"","type" =>"normal");
  169. $detail_information_column[] = array("title" =>"Container No","field" =>"ctnr","formatter" =>"","type" =>"normal");
  170. $detail_information_column[] = array("title" =>"VGM Weight","field" =>"vgm_weight","formatter" =>"","type" =>"normal");
  171. $detail_information_column[] = array("title" =>"VGM Unit","field" =>"unit","formatter" =>"","type" =>"normal");
  172. $detail_information_column[] = array("title" =>"VGM Time","field" =>"vgm_time","formatter" =>"","type" =>"normal");
  173. $detail_information_column[] = array("title" =>"VGM Method","field" =>"vgm_method","formatter" =>"","type" =>"normal");
  174. foreach($rs as $rk => $rv){
  175. $log[$rk]['sn'] = $rk +1;
  176. }
  177. $detail_information =array("detail_information_column" =>$detail_information_column,
  178. "detail_information_data" =>$rs);
  179. $data = array("msg" =>$err_msg);
  180. $Submitter = $ocean_info["authorized_company"];
  181. if(empty($ocean_info["id"])){
  182. $Submitter = $default["submitter"];
  183. }
  184. $signature = $ocean_info["signature"];
  185. if(empty($ocean_info["id"])){
  186. $signature = $default["signature"];
  187. }
  188. $authorized_email = $ocean_info["authorized_email"];
  189. if(empty($ocean_info["id"])){
  190. $authorized_email = $default["authorized_email"];
  191. }
  192. $authorized_tel = $ocean_info["authorized_tel"];
  193. if(empty($ocean_info["id"])){
  194. $authorized_tel = $default["authorized_tel"];
  195. }
  196. $data["general_information"] = array("HBL No."=>$ocean_info["o_h_bol"],
  197. "Carrier Booking No."=>$ocean_info["carrier_booking"],
  198. "Vessel"=>$ocean_info["m_vessel"],"Voyage"=>$ocean_info["m_voyage"],
  199. "ETD"=>$ocean_info["f_etd"],"ETA"=>$ocean_info["m_eta"],
  200. "Last updated User"=>$ocean_info["modify_user"],"Last updated Time"=>$ocean_info["modify_time"],
  201. "Submitter" =>$Submitter,"$signature" =>$signature,"authorized_email" =>$authorized_email,"authorized_tel" =>$authorized_tel,"is_send" =>$ocean_info['is_send']);
  202. $data["detail_information"] = $detail_information;
  203. $data["schemas"] = $schemas;
  204. $data["serial_no"] = $serial_no;
  205. common::echo_json_encode(200, $data);
  206. exit();
  207. }
  208. if ($operate == "save_ocean_vgm") {
  209. if (!_canEdiVgm()) {
  210. $data = array("msg" =>"Vgm Permission Error");
  211. common::echo_json_encode(200, $data);
  212. exit();
  213. }
  214. $msg = $this->save_vgm();
  215. $data = array("msg" =>$msg);
  216. common::echo_json_encode(200, $data);
  217. exit();
  218. }
  219. }
  220. /*
  221. * ocean order search
  222. */
  223. private function _ocean_search() {
  224. $cp = common::check_input($_POST ['cp']); //current_page
  225. $ps = common::check_input($_POST ['ps']); //ps
  226. if (empty($ps))
  227. $ps = 50;
  228. $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  229. $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
  230. //查询tag
  231. // IFFBCF;Booking Confirmation
  232. // IFFREC;Cargo Arrived at Origin
  233. // IFFDEP;Departure
  234. // IFFARR;Arrived at Final Destination Port
  235. // IFFAFD;Arrived at Final Destination
  236. if (!empty($_POST["filterTag"])) {
  237. if (count($_POST['filterTag']) == 1){
  238. $filterTag = $_POST['filterTag'][0];
  239. }else{
  240. $filterTag = implode(",", $_POST['filterTag']);
  241. }
  242. $_sqlwhere = "1<>1";
  243. if (stripos($filterTag, "Booked") !== FALSE) {
  244. $_sqlwhere .= " or (dd.status = 'Booked')";
  245. }
  246. if (stripos($filterTag, "Cargo Received") !== FALSE) {
  247. $_sqlwhere .= " or (dd.status = 'Cargo Received')";
  248. }
  249. if (stripos($filterTag, "Departed") !== FALSE) {
  250. $_sqlwhere .= " or (dd.status = 'Departed')";
  251. }
  252. if (stripos($filterTag, "Arrived") !== FALSE) {
  253. $_sqlwhere .= " or (dd.status = 'Arrived')";
  254. }
  255. if (stripos($filterTag, "Completed") !== FALSE) {
  256. $_sqlwhere .= " or (dd.status = 'Completed')";
  257. }
  258. if(strtolower($filterTag) <> "all" && !empty($filterTag)){
  259. $sqlWhere .= " and ($_sqlwhere)";
  260. }
  261. }
  262. if (!empty($_POST["_textSearch"])) {
  263. $sqlWhere .= " and text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))";
  264. }
  265. $rc = $_POST ['rc'];
  266. //这里都要查询,除非多传几个参数回来
  267. if ($rc == - 1 || true) {
  268. $sql = "select count(1) from online_ocean
  269. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  270. when a.description='Cargo Pickup' then 'Cargo Received'
  271. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  272. when a.description='Departure' then 'Departed'
  273. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  274. when a.description='Arrived at Final Destination' then 'Completed'
  275. else 'Booked' END as status
  276. from ocean_milestone a
  277. where a.serial_no=online_ocean.serial_no
  278. and a.description in (
  279. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  280. order by id desc limit 1) dd on true" . $sqlWhere;
  281. $rc = common::excuteOneSql($sql);
  282. //Booked
  283. $sql = $this->getOcanOrderSearchSql("Booked",$sqlWhere);
  284. $Booked = common::excuteOneSql($sql);
  285. //Cargo Received
  286. $sql = $this->getOcanOrderSearchSql("Cargo Received",$sqlWhere);
  287. $Cargo_Received = common::excuteOneSql($sql);
  288. //Departed
  289. $sql = $this->getOcanOrderSearchSql("Departed",$sqlWhere);
  290. $Departed = common::excuteOneSql($sql);
  291. //Arrived
  292. $sql = $this->getOcanOrderSearchSql("Arrived",$sqlWhere);
  293. $Arrived = common::excuteOneSql($sql);
  294. //Completed
  295. $sql = $this->getOcanOrderSearchSql("Completed",$sqlWhere);
  296. $Completed = common::excuteOneSql($sql);
  297. if (!empty($_POST["filterTag"])) {
  298. $tagsList = array(array("name"=>"All","number"=>$rc,"type"=>"all","checked"=>in_array('All', $_POST["filterTag"])? true : false),
  299. array("name"=>"Booked","number"=>$Booked,"type"=>"booked","checked"=>in_array('Booked', $_POST["filterTag"])? true : false),
  300. array("name"=>"Cargo Received","number"=>$Cargo_Received,"type"=>"cargo_received","checked"=>in_array('Cargo Received', $_POST["filterTag"])? true : false),
  301. array("name"=>"Departure","number"=>$Departed,"type"=>"departure","checked"=>in_array('Departure', $_POST["filterTag"])? true : false),
  302. array("name"=>"Arrived","number"=>$Arrived,"type"=>"arrived","checked"=>in_array('Arrived', $_POST["filterTag"])? true : false),
  303. array("name"=>"Completed","number"=>$Completed,"type"=>"completed","checked"=>in_array('Completed', $_POST["filterTag"])? true : false));
  304. }else{
  305. //初始,前端有选择着带入选择
  306. $tagsList = array(array("name"=>"All","number"=>$rc,"type"=>"all","checked"=> true ),
  307. array("name"=>"Booked","number"=>$Booked,"type"=>"booked","checked"=> false),
  308. array("name"=>"Cargo Received","number"=>$Cargo_Received,"type"=>"cargo_received","checked"=> false),
  309. array("name"=>"Departure","number"=>$Departed,"type"=>"departure","checked"=> false),
  310. array("name"=>"Arrived","number"=>$Arrived,"type"=>"arrived","checked"=> false),
  311. array("name"=>"Completed","number"=>$Completed,"type"=>"completed","checked"=>false));
  312. }
  313. $TransportList = array(
  314. array("name"=>"Ocean Freight","number"=>$rc,"checked"=>false,"icon"=>"#icon-icon_ocean_b"));
  315. //现在下载交给前端,后台预先只返回全部字段的列,
  316. $allColumn = column::getInstance()->getDisplayColumnAllReomveDefault('Ocean_Search');
  317. $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
  318. }
  319. $tp = ceil($rc / $ps);
  320. $order_by = " etd desc NULLS LAST, id";
  321. if (_isCustomerLogin()) {
  322. $order_by = " eta desc NULLS LAST, id";
  323. }
  324. if ($rc > 0) {
  325. $ocean_ref_sql = " LEFT JOIN LATERAL ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no
  326. FROM public.ocean_reference temp WHERE temp.serial_no = online_ocean.serial_no) aa ON true ";
  327. $ocean_status_sql = " LEFT JOIN LATERAL ( select case when a.description='Booking Confirmation' then 'Booked'
  328. when a.description='Cargo Pickup' then 'Cargo Received'
  329. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  330. when a.description='Departure' then 'Departed'
  331. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  332. when a.description='Arrived at Final Destination' then 'Completed'
  333. else 'Booked' END as new_status
  334. from ocean_milestone a
  335. where a.serial_no=online_ocean.serial_no
  336. and a.description in (
  337. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  338. order by id desc limit 1) dd ON true ";
  339. $sql = "SELECT order_from as _schemas,serial_no as __serial_no, serial_no,
  340. h_bol as _hbol, isf_bol as _isfbol,
  341. CASE
  342. WHEN dd.new_status is null THEN 'Booked'::text
  343. ELSE dd.new_status::text
  344. END AS new_status, ".
  345. column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.online_ocean $ocean_ref_sql $ocean_status_sql" . $sqlWhere .
  346. " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;
  347. $rs = common::excuteListSql($sql);
  348. error_log($sql);
  349. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  350. foreach($rs as $index => $val) {
  351. //返回加密serial_no
  352. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  353. $rs[$index]["mode"] = "Ocean Frieght";
  354. $rs[$index]["status"] = $rs[$index]["new_status"];
  355. }
  356. $arrTmp = array('searchData' => $rs,
  357. 'tagsList' => array(),
  358. 'TransportList' => $TransportList,
  359. 'allColums' => $allBookingColumns,
  360. 'canEdiVgm' => _canEdiVgm(),
  361. 'rc' => $rc,
  362. 'ps' => $ps,
  363. 'cp' => $cp,
  364. 'tp' => $tp,
  365. 'tmp_search' => common::deCode($sql, 'E'),
  366. 'type' => common::check_input($_POST ['_ntype']));
  367. } else {
  368. $arrTmp = array('searchData' => array(),
  369. 'tagsList' => array(),
  370. 'TransportList' => $TransportList,
  371. 'allColums' => $allBookingColumns,
  372. 'allColcanEdiVgmums' => _canEdiVgm(),
  373. 'rc' => $rc,
  374. 'ps' => $ps,
  375. 'cp' => $cp,
  376. 'tp' => $tp,
  377. 'tmp_search' => common::deCode($sql, 'E'),
  378. 'type' => common::check_input($_POST ['_ntype']));
  379. }
  380. common::echo_json_encode(200,$arrTmp);
  381. exit();
  382. }
  383. private function _ocean_detail() {
  384. $serial_no = common::deCode($_GET['a'], 'D');
  385. $status = $_GET['status'];
  386. $sql = "SELECT m_eta as _m_eta, h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
  387. 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,
  388. to_char(final_eta, 'MM/DD/YYYY') as _final_eta,
  389. o.* ,sh.*, cn.* ,aa.*,dd.*
  390. from ocean o
  391. LEFT JOIN LATERAL ( SELECT company as cn_company,
  392. address_1 as cn_address_1,
  393. address_2 as cn_address_2,
  394. address_3 as cn_address_3,
  395. address_4 as cn_address_4,
  396. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  397. phone_1 as cn_phone
  398. FROM contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
  399. LEFT JOIN LATERAL ( SELECT company as sh_company,
  400. address_1 as sh_address_1,
  401. address_2 as sh_address_2,
  402. address_3 as sh_address_3,
  403. address_4 as sh_address_4,
  404. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  405. phone_1 as sh_phone
  406. FROM contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
  407. LEFT JOIN LATERAL ( SELECT company as aa_company,
  408. address_1 as aa_address_1,
  409. address_2 as aa_address_2,
  410. address_3 as aa_address_3,
  411. address_4 as aa_address_4,
  412. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  413. phone_1 as aa_phone
  414. FROM contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
  415. LEFT JOIN LATERAL ( SELECT company as dd_company,
  416. address_1 as dd_address_1,
  417. address_2 as dd_address_2,
  418. address_3 as dd_address_3,
  419. address_4 as dd_address_4,
  420. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  421. phone_1 as dd_phone
  422. FROM contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
  423. where lower(serial_no) = '" . strtolower($serial_no) . "'";
  424. $ocean = common::excuteObjectSql($sql);
  425. if (!empty($ocean)) {
  426. $ocean['_isf_bol'] = $ocean['isf_bol'];
  427. if (empty($ocean['_isf_bol'])) {
  428. $ocean['_isf_bol'] = "AMAW" . $ocean['_h_bol'];
  429. }
  430. $isf_ss = md5(md5($ocean['_isf_bol']));
  431. $isf_ss = substr($isf_ss, 7) . substr($isf_ss, 0, 7);
  432. //ETA Dest的计算逻辑移除
  433. // most update status
  434. $_schemas = $_REQUEST["_schemas"];
  435. $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 "
  436. . ", fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un FROM public.online_ocean "
  437. . "where serial_no= '" . $ocean["serial_no"] . "'";
  438. if (!empty($_schemas)) {
  439. $mostStatusSql .= " and order_from='" . $_schemas . "'";
  440. }
  441. $mostStatus = common::excuteObjectSql($mostStatusSql);
  442. $state = -1;
  443. if (!empty($mostStatus["last_status_315_code"])) {
  444. $desc = $mostStatus["last_status_315_code"] . "(" . common::getStatusDesc($mostStatus["last_status_315_code"]) . "): " . $mostStatus["last_status_315_date"];
  445. $mostStatus = $desc;
  446. $state = common::getStatusStage($mostStatus["last_status_315_code"]);
  447. }
  448. //请求地图是需要的参数
  449. $uncode = "'";
  450. if ($mostStatus["place_of_receipt_un"] != $mostStatus["fport_of_loading_un"]) {
  451. $uncode .= $mostStatus["place_of_receipt_un"];
  452. }
  453. $uncode .= "'|'" . $mostStatus["fport_of_loading_un"] . "'|'" . $mostStatus["mport_of_discharge_un"] . "'|'";
  454. if ($mostStatus["mport_of_discharge_un"] != $mostStatus["place_of_delivery_un"]) {
  455. $uncode .= $mostStatus["place_of_delivery_un"];
  456. }
  457. $uncode .= "'";
  458. }
  459. //处理shipment data暂时写死
  460. $simplexData = array();
  461. $simplexData[] = array("index" =>1,"label" =>"Place of Receipt",
  462. "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt'],"isArrival" =>$state == 1 ? true : false);
  463. $simplexData[] = array("index" =>2,"label" =>"Port of Loading",
  464. "path" =>$ocean['fport_of_loading_exp_exp']."/".$ocean['fport_of_loading_exp'],"isArrival" =>$state == 2 ? true : false,
  465. "children" =>array(array("label" =>"Cargo arrival at Origin","date" =>"2024-02-01"),
  466. array("label" =>"'Departure","date" =>"2024-02-01")));
  467. $simplexData[] = array("index" =>3,"label" =>"Port of Discharge",
  468. "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge'],"isArrival" =>$state == 3 ? true : false,
  469. "children" =>array(array("label" =>"ETA","date" =>"2024-02-01")));
  470. $simplexData[] = array("index" =>4,"label" =>"Place of Delivery",
  471. "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery'],"isArrival" =>$state == 4 ? true : false);
  472. //处理transportInfo信息数据
  473. $transportInfo = array("Tracking No." =>$ocean['tracking_no'],"status"=>$status,"mode" => "Ocean Frieght",
  474. "origin" =>$ocean['origin_station'],"destination" =>$ocean['destination_station'],
  475. "etd" =>$ocean['f_etd'],"atd" =>"","eta" =>$ocean['m_eta'],"ata" =>"");
  476. //处理basicInfo信息数据
  477. $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
  478. $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
  479. $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['carrier_booking'],
  480. "PO_NO" =>$ocean['po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  481. "Incoterm" =>$ocean['terms'],"Service_Type" =>$ocean['service']);
  482. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  483. $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  484. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  485. $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  486. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  487. $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  488. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  489. $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  490. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  491. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  492. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  493. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  494. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  495. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  496. //处理routes 转船可能有多个情况
  497. $routes = array(array("mode" =>"Sea", "origin" =>$ocean['origin_station'],
  498. "destination" => $ocean['destination_station'], "etd" => $ocean['f_etd'],"atd" => "",
  499. "eta" =>$ocean['m_eta'],"ata" =>"","vessel" =>$vessel,"voyageNo" =>$voyage));
  500. //处理ocean_reference
  501. $ref_no = array();
  502. $ref_arr = common::excuteListSql("select * from ocean_reference where lower(serial_no) = '" . strtolower($serial_no) . "'");
  503. if(!empty($ref_arr)){
  504. foreach($ref_arr as $ref) {
  505. $ref_no[] = array("label"=>$ref["ref_code"],"value"=>$ref["ref_value"]);
  506. }
  507. }
  508. //处理marksAndDescription
  509. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description']);
  510. //配置Ocean_Container字段 UI 需要的字段有:Container.no Packing,quantity,Gross weight(kg),Gross weight(LB),CBM,seal#,size.service
  511. //处理Container
  512. $ocean_container_column = array();
  513. $container_column = column::getInstance()->getDisplayColumnAll('Ocean_Container');
  514. foreach($container_column as $cc){
  515. $ocean_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],"formatter" =>"","type" =>"normal");
  516. }
  517. $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . " from oc_container where lower(serial_no) = '" . strtolower($serial_no) . "'";
  518. $rss = common::excuteListSql($sql);
  519. $quantity_tolal = 0;
  520. $packages = "CTN";
  521. $g_weight_tolal = 0;
  522. $ch_weight_tolal = 0;
  523. $cbm_tolal = 0;
  524. foreach ($rss as $key => $rs) {
  525. $quantity_tolal += $rs['qty'];
  526. $g_weight_tolal += $rs['grs_kgs'];
  527. $ch_weight_tolal += $rs['grs_lbs'];
  528. $cbm_tolal += $rs['cbm'];
  529. $packages = " ".$rs['unit'];
  530. //特殊处理weight
  531. if(!empty($rss[$key]['grs_kgs'])){
  532. $rss[$key]['grs_kgs'] = $rs['grs_kgs']."KG";
  533. }
  534. if(!empty($rss[$key]['grs_lbs'])){
  535. $rss[$key]['grs_lbs'] = $rs['grs_lbs']."LB";
  536. }
  537. }
  538. $containers = array("container_column"=>$ocean_container_column,"container_data" =>$rss);
  539. //Packing 不确定信息
  540. $packing = array("Quantity/Unit"=>$quantity_tolal.$packages,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $ch_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
  541. /* Container Status */
  542. //数据库里配置好
  543. $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container_Status') . " from oc_container_v where lower(serial_no) = '" . strtolower($serial_no) . "'";
  544. $rss = common::excuteListSql($sql);
  545. $containerStatusData = array();
  546. if (!empty($rss)) {
  547. //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
  548. $container_status_column = array("EE","I","AE","VD","VA");
  549. foreach ($rss as $rsk => $rs) {
  550. $containerStatusDataTemp = array();
  551. $content = array();
  552. //新UI 还有站点取值,但不清楚取的什么值,CN,SHK 暂时写死
  553. foreach($container_status_column as $status){
  554. $dec = common::excuteOneSql("select description from ra_online_edi_event where ra_name = '" . $status . "'");
  555. $status = strtolower($status);
  556. $content[] = array("title" =>$dec,"date"=>common::date2usdate($rs[$status]),"country"=>"CN,SHK");
  557. }
  558. $containerStatusDataTemp['label'] = $rs['ctnr']." / ".$rs['size'];
  559. $containerStatusDataTemp['content'] = $content;
  560. $containerStatusData[] = $containerStatusDataTemp;
  561. }
  562. }
  563. //Milestones info 列名固定
  564. $Milestones_column = array();
  565. $Milestones_column[] = array("title" =>"Milestones","field" =>"milestones","formatter" =>"","type" =>"normal");
  566. $Milestones_column[] = array("title" =>"Date Time","field" =>"date_time","formatter" =>"","type" =>"normal");
  567. $Milestones_column[] = array("title" =>"Locations","field" =>"locations","formatter" =>"","type" =>"normal");
  568. $Milestones_column[] = array("title" =>"Remarks","field" =>"remarks","formatter" =>"","type" =>"normal");
  569. //Milestones 数据信息待定
  570. $Milestones_data = array();
  571. $Milestones_data_arr = common::excuteListSql("select description,act_date||act_time as date_time, remark from ocean_milestone a
  572. where a.serial_no='".$ocean["serial_no"]."' order by id");
  573. foreach($Milestones_data_arr as $mda){
  574. $Milestones_data[] = array("milestones"=>$mda['description'],"date_time"=>$mda['date_time'],"locations" => "", "remarks" =>$mda['remark']);
  575. }
  576. $Milestones = array("Milestones_column"=>$Milestones_column,"Milestones_data" =>$Milestones_data);
  577. //页面固定写死的信息
  578. $document_column = array();
  579. $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
  580. $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
  581. $document_data = array();
  582. $document = _getViewDocType($_REQUEST["_schemas"]);
  583. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  584. $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'])."'");
  585. if (!empty($document)) {
  586. foreach ($document as $v) {
  587. $file_type = $v['display_name'];
  588. $file_arr = $this->getFileByHbol($ocean['_m_bol'], $ocean['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE,$ocean['_job_bol']) ;
  589. $tar = json_decode($ocean_can_view_file,true);
  590. if(!empty($tar[$v['display_name']])){
  591. foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
  592. switch ($v['display_name']) {
  593. case 'HBL':
  594. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  595. from ra_online_doc_upload
  596. 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']."'
  597. order by id desc";
  598. break;
  599. case 'MBL':
  600. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  601. from ra_online_doc_upload
  602. 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']."'
  603. order by id desc";
  604. break;
  605. case 'Others':
  606. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  607. from ra_online_doc_upload
  608. 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']."'
  609. order by id desc";
  610. break;
  611. default:
  612. $sql = "";
  613. break;
  614. }
  615. if (!empty($sql)) {
  616. $rss = common::excuteListSql($sql);
  617. foreach ($rss as $rs) {
  618. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  619. $file_arr[] = array("url"=>$OutFileURL."/download.php?_schemas=&a=".base64_encode(base64_encode($rs['serial_no'])),
  620. "file_name" => $rs['file_name'],
  621. "detail"=>$rs['upload_date'],
  622. "can_delete"=>_getLoginName() == $rs['upload_by']);
  623. }else{
  624. $file_arr[] = array("url"=>"main_new_version?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  625. "file_name" => $rs['file_name'],
  626. "detail"=>$rs['upload_date'],
  627. "can_delete"=>_getLoginName() == $rs['upload_by']);
  628. }
  629. }
  630. }
  631. }
  632. }
  633. //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
  634. //按现在的逻辑,有值才会显示
  635. foreach($file_arr as $f){
  636. $document_data[] = array("file_type"=>$file_type,"file"=>$f);
  637. }
  638. }
  639. }
  640. $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
  641. $emailRecords = $this->getCommunicationNew($ocean["serial_no"]);
  642. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $ocean["serial_no"] . "' order by id desc limit 1");
  643. $email = $this->getEmail($ocean["serial_no"]);
  644. $email['cc_email'] = $cc_email;
  645. $email['emailRecords'] = $emailRecords;
  646. global $_COPYRIGHT;
  647. $data = array('transportInfo' => $transportInfo,
  648. 'basicInfo' => $basicInfo,
  649. 'businessPartners' => $businessPartners,
  650. 'ref_no' => $ref_no,
  651. 'packing' => $packing,
  652. 'marksAndDescription' => $marksAndDescription,
  653. 'containers' => $containers,
  654. 'simplexData' =>$simplexData,
  655. 'containerStatusData' => $containerStatusData,
  656. 'document_info' => $document_info,
  657. 'containers' => $containers,
  658. 'Milestones' => $Milestones,
  659. 'routes' => $routes,
  660. 'email' => $email,
  661. 'ams_ss' => md5(md5($ocean['serial_no'])),
  662. 'isf_ss' => $isf_ss,
  663. '_schemas' =>$_schemas,
  664. 'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
  665. 'canEdiVgm' => _canEdiVgm(),
  666. 'copyright' =>$_COPYRIGHT);
  667. common::echo_json_encode(200,$data);
  668. exit();
  669. }
  670. private function _ocean_excel() {
  671. //现在下载交给前端,后台最后只返回全部字段的列,
  672. $allColumn = column::getInstance()->getDisplayColumnAll('Ocean_Search');
  673. $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
  674. common::echo_json_encode(200,array("msg"=>"success","allColums" => $allBookingColumns));
  675. exit;
  676. }
  677. private function _ams_isf_log(){
  678. global $cbpdb;
  679. $ams_ss = $_POST['ams_ss'];
  680. $isf_ss = $_POST['isf_ss'];
  681. $amsLog = array();
  682. //页面固定写死的信息
  683. $amsLog_column = array();
  684. $amsLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"normal");
  685. $amsLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  686. $amsLog_column[] = array("title" =>"Name","field" =>"isams_submit","formatter" =>"","type" =>"normal");
  687. $amsLog_column[] = array("title" =>"Description","field" =>"amslog","formatter" =>"","type" =>"normal");
  688. $amsLog["amsLog_column"] = $amsLog_column;
  689. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  690. $amsLog["data"] = array();
  691. if (_canViewAMSLog()) {
  692. $s = $ams_ss;
  693. //$s = "PDLA200127H";
  694. if (!empty($s)) {
  695. //$cc = $cbpdb->GetAll("select distinct h_bol from ams_information where md5(md5(from_serial_no)) = '" . pg_escape_string($s) . "'");
  696. $cc = $cbpdb->GetAll("select distinct h_bol from ams_information where h_bol = '" . pg_escape_string($s) . "'");
  697. foreach ($cc as $v){
  698. $amses[] = $cbpdb->GetAll("select * from ams_info where h_bol = '" . pg_escape_string($v['h_bol']) . "'");
  699. }
  700. //考虑一个情况
  701. if (count($amses) > 0) {
  702. $ams = $amses[0];
  703. $carrier_hbol = substr($ams[0]['m_bol'], 4);
  704. $carrier_scac = substr($ams[0]['m_bol'], 0, 4);
  705. if (empty($ams[0]['h_bol'])){
  706. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  707. $amsLog["data"] = array();
  708. }else{
  709. $log = $cbpdb->GetAll("select cbpreplytime as atime, amslog, cbperrorcode, isams_submit
  710. from v_e_amslog where hbol = '" . pg_escape_string($ams[0]['h_bol']) . "'
  711. and split_part(stationname, ',', 1) = split_part('" . pg_escape_string($ams[0]['station_name']) . "', ',', 1)
  712. order by cbpreplytime desc, substr(cbperrorcode, 2, 1) desc");
  713. $amsLog["msg"] = "";
  714. $amsLog["data"] = $log;
  715. }
  716. }
  717. }
  718. }
  719. $isfLog = array();
  720. //页面固定写死的信息
  721. $isfLog_column = array();
  722. $isfLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"normal");
  723. $isfLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  724. $isfLog_column[] = array("title" =>"Name","field" =>"isfsubmit","formatter" =>"","type" =>"normal");
  725. $isfLog_column[] = array("title" =>"Description","field" =>"isflog","formatter" =>"","type" =>"normal");
  726. $isfLog["isfLog_column"] = $isfLog_column;
  727. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  728. $isfLog["data"] = array();
  729. if (_canViewISFLog()) {
  730. if (!empty($isf_ss)) {
  731. $ss = $isf_ss;
  732. $len = strlen($ss);
  733. $b = substr($ss, $len - 7) . substr($ss, 0, $len - 7);
  734. if (empty($b)){
  735. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  736. $isfLog["data"] = array();
  737. }else{
  738. $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");
  739. }
  740. if (!empty($isf)) {
  741. if (!empty($isf['dob'])){
  742. $isf['dob'] = date("m/d/Y", strtotime($isf['dob']));
  743. }
  744. $msg = $cbpdb->GetAll("select cbpreplytime as atime, isflog, cbperrorcode, isfsubmit, hbol
  745. from v_e_isflog where (case when coalesce(isf_no, '')<>''
  746. then isf_no = '" . pg_escape_string($isf["isf_no"]) . "' else hbol = '" . pg_escape_string($isf["bol"]) . "'
  747. and stationname = '" . pg_escape_string($isf["station_name"]) . "' end)
  748. order by cbpreplytime desc, rowid desc");
  749. $isfLog["msg"] = "";
  750. $isfLog["data"] = $msg;
  751. }else{
  752. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  753. $isfLog["data"] = array();
  754. }
  755. }
  756. }
  757. $data =array("msg"=>"success",
  758. "canViewAMSLog" => _canViewAMSLog(),
  759. "canViewISFLog" => _canViewISFLog(),
  760. "amsLog" =>$amsLog,
  761. "isfLog" =>$isfLog);
  762. common::echo_json_encode(200,$data);
  763. exit;
  764. }
  765. private function getEmail($serial_no) {
  766. return utils::getEmail($serial_no);
  767. }
  768. private function getCommunicationNew($serial_no) {
  769. $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");
  770. $emialRecords =array();
  771. foreach ($list as $k => $v) {
  772. $msg =array();
  773. $msg["name"] = $v["add_by"];
  774. $msg["creatTime"] = $v["add_times"];
  775. $msg["content"] = urldecode($v["web_content"]);
  776. $emialRecords[] = $msg;
  777. }
  778. return $emialRecords;
  779. }
  780. /*
  781. * get file by hbol/destination
  782. * H:HBL
  783. * M: MBL
  784. * F: FL
  785. * I: C/I & Packing list
  786. */
  787. private function getFileByHbol($m_bol, $h_bol, $types, $m_bs, $display, $detail = FALSE,$job_no="") {
  788. $types = strtolower($types);
  789. $types = explode(";", $types);
  790. $m_bs = explode(";", $m_bs);
  791. $otheres = NULL;
  792. $filefilter = " ('TELEX') ";//过滤掉类型,单独配置 3537
  793. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  794. $file = array();
  795. foreach ($types as $k => $type) {
  796. $m_b = $m_bs[$k];
  797. if (strtolower($m_b) == 'm')
  798. $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";
  799. if (strtolower($m_b) == 'h')
  800. $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";
  801. if (strtolower($m_b) == 'a')
  802. $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";
  803. if (!empty($sql)) {
  804. $rss = common::excuteListSql($sql);
  805. foreach ($rss as $rs) {
  806. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  807. $file[] = array("url"=>$OutFileURL.'/download.php?_schemas=&a='.base64_encode(base64_encode($rs['serial_no'])),
  808. "file_name" => $rs['file_name'],
  809. "detail"=>$rs['upload_date'],
  810. "can_delete"=>_getLoginName() == $rs['upload_by']);
  811. }else {
  812. $file[] = array("url"=>"main_new_version?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  813. "file_name" => $rs['file_name'],
  814. "detail"=>$rs['upload_date'],
  815. "can_delete"=>_getLoginName() == $rs['upload_by']);
  816. }
  817. }
  818. }
  819. }
  820. return $file;
  821. }
  822. /*
  823. * download file
  824. */
  825. private function _download() {
  826. $url = common::deCode($_GET['url'], 'D');
  827. common::download_file($url);
  828. }
  829. private function getOcanOrderSearchSql($type,$sqlWhere) {
  830. if($type == "Booked"){
  831. $Booked_sqlWhere = " and (1<>1 or dd.status ='Booked')";
  832. return "select count(1) from online_ocean
  833. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  834. when a.description='Cargo Pickup' then 'Cargo Received'
  835. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  836. when a.description='Departure' then 'Departed'
  837. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  838. when a.description='Arrived at Final Destination' then 'Completed'
  839. else 'Booked' END as status
  840. from ocean_milestone a
  841. where a.serial_no=online_ocean.serial_no
  842. and a.description in (
  843. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  844. order by id desc limit 1) dd on true" . $sqlWhere.$Booked_sqlWhere;
  845. }
  846. if($type == "Cargo Received"){
  847. $Cargo_Received_sqlWhere = " and (1<>1 or dd.status ='Cargo Received')";
  848. return "select count(1) from online_ocean
  849. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  850. when a.description='Cargo Pickup' then 'Cargo Received'
  851. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  852. when a.description='Departure' then 'Departed'
  853. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  854. when a.description='Arrived at Final Destination' then 'Completed'
  855. else 'Booked' END as status
  856. from ocean_milestone a
  857. where a.serial_no=online_ocean.serial_no
  858. and a.description in (
  859. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  860. order by id desc limit 1) dd on true" . $sqlWhere.$Cargo_Received_sqlWhere;
  861. }
  862. if($type == "Departed"){
  863. $Departed_sqlWhere = " and (1<>1 or dd.status ='Departed')";
  864. return "select count(1) from online_ocean
  865. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  866. when a.description='Cargo Pickup' then 'Cargo Received'
  867. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  868. when a.description='Departure' then 'Departed'
  869. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  870. when a.description='Arrived at Final Destination' then 'Completed'
  871. else 'Booked' END as status
  872. from ocean_milestone a
  873. where a.serial_no=online_ocean.serial_no
  874. and a.description in (
  875. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  876. order by id desc limit 1) dd on true" . $sqlWhere.$Departed_sqlWhere;
  877. }
  878. if($type == "Arrived"){
  879. $Arrived_sqlWhere = " and (1<>1 or dd.status ='Arrived')";
  880. return "select count(1) from online_ocean
  881. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  882. when a.description='Cargo Pickup' then 'Cargo Received'
  883. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  884. when a.description='Departure' then 'Departed'
  885. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  886. when a.description='Arrived at Final Destination' then 'Completed'
  887. else 'Booked' END as status
  888. from ocean_milestone a
  889. where a.serial_no=online_ocean.serial_no
  890. and a.description in (
  891. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  892. order by id desc limit 1) dd on true" . $sqlWhere.$Arrived_sqlWhere;
  893. }
  894. if($type == "Completed"){
  895. $Completed_sqlWhere = " and (1<>1 or dd.status ='Completed')";
  896. return "select count(1) from online_ocean
  897. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  898. when a.description='Cargo Pickup' then 'Cargo Received'
  899. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  900. when a.description='Departure' then 'Departed'
  901. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  902. when a.description='Arrived at Final Destination' then 'Completed'
  903. else 'Booked' END as status
  904. from ocean_milestone a
  905. where a.serial_no=online_ocean.serial_no
  906. and a.description in (
  907. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  908. order by id desc limit 1) dd on true" . $sqlWhere.$Completed_sqlWhere;
  909. }
  910. }
  911. private function save_vgm() {
  912. $schemas = $_POST["schemas"];
  913. $serial_no = common::deCode($_POST["serial_no"], 'D');
  914. $ocean = common::excuteObjectSql("select m_bol, master_base_number, from_station, h_bol from $schemas.ocean where serial_no='" . common::check_input($serial_no) . "'");
  915. $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"] . "'");
  916. $address = $contact["address_1"];
  917. if (!empty($address)) {
  918. $address .= "\r\n";
  919. }
  920. $address .= $contact["address_2"];
  921. if (!empty($address)) {
  922. $address .= "\r\n";
  923. }
  924. $address .= $contact["address_3"];
  925. if (!empty($address)) {
  926. $address .= "\r\n";
  927. }
  928. $address .= $contact["address_4"];
  929. $exists = common::excuteOneSql("select serial_no from $schemas.ocean_vgm_masterbasenumber where master_base_number ilike '" . $ocean["master_base_number"] . "'");
  930. global $db;
  931. $db->StartTrans();
  932. if (empty($_POST["is_send"])) {
  933. $_POST["is_send"] = 'f';
  934. }
  935. if (empty($exists)) {
  936. $db->Execute("insert into ocean_vgm_masterbasenumber (master_base_number, serial_no) values ('" . $ocean["master_base_number"] . "', '$serial_no');");
  937. $value["serial_no"] = $serial_no;
  938. $value["carrier_booking_no"] = $_POST["all_carrier_booking"];
  939. $value["modify_user"] = _getLoginName();
  940. $value["modify_time"] = "now()";
  941. $value["authorized_email"] = !empty($_POST["authorized_email"]) ? $_POST["authorized_email"] : "";
  942. $value["authorized_tel"] = !empty($_POST["authorized_tel"]) ? $_POST["authorized_tel"] : "";
  943. $value["authorized_company"] = !empty($_POST["submitter"]) ? $_POST["submitter"] : "";
  944. $value["signature"] = !empty($_POST["signature"]) ? $_POST["signature"] : "";
  945. $value["is_send"] = $_POST["is_send"];
  946. $value["action"] = "New";
  947. $value["type"] = "Shipper";
  948. $value["m_bol"] = $ocean["m_bol"];
  949. $value["master_base_number"] = $ocean["master_base_number"];
  950. $value["shipper_id"] = $ocean["from_station"];
  951. $value["shipper"] = $contact["company"];
  952. $value["shipper_address"] = $address;
  953. $value["shipper_contactname"] = $contact["contactname_1"];
  954. $value["shipper_email"] = $contact["email_1"];
  955. $value["shipper_fax"] = $contact["fax"];
  956. $value["shipper_telephone"] = $contact["phone_1"];
  957. $value["update_uuid"] = utils::uuid();
  958. $value["h_bol"] = $ocean["h_bol"];
  959. $value["from_station"] = $ocean["from_station"];
  960. $sql = common::getInsertSqlNull("$schemas .ocean_vgm", $value);
  961. $db->Execute($sql);
  962. } else {
  963. $serial_no = $exists;
  964. $db->Execute("update ocean_vgm_masterbasenumber set id=id where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  965. $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(),"
  966. . "authorized_email='" . $_POST["authorized_email"] . "', authorized_tel='" . $_POST["authorized_tel"] . "', authorized_company='" . $_POST["submitter"] . "', signature='" . $_POST["signature"] . "', send_time=null "
  967. . ", update_uuid='" . utils::uuid() . "' where master_base_number ilike '" . $ocean["master_base_number"] . "';");
  968. }
  969. $db->Execute("delete from ocean_vgm_container where serial_no ilike '" . $serial_no . "';");
  970. foreach ($_POST["container_no"] as $i => $cv) {
  971. $value1["serial_no"] = $serial_no;
  972. $value1["carrier_booking_no"] = !empty($_POST["carrier_booking_no"][$i]) ? $_POST["carrier_booking_no"][$i] : "";
  973. $value1["ctnr"] = !empty($_POST["container_no"][$i]) ? $_POST["container_no"][$i] : "";
  974. $value1["size"] = !empty($_POST["size"][$i]) ? $_POST["size"][$i] : "";
  975. $value1["vgm_weight"] = !empty($_POST["vgm_weight"][$i]) ? $_POST["vgm_weight"][$i] : "";
  976. $value1["unit"] = !empty($_POST["vgm_kg_lg"][$i]) ? $_POST["vgm_kg_lg"][$i] : "";
  977. $value1["vgm_time"] = !empty($_POST["vgm_date"][$i]) ? $_POST["vgm_date"][$i] : "";
  978. $value1["cargo_weight_kgs"] = !empty($_POST["cargo_weight_kg"][$i]) ? $_POST["cargo_weight_kg"][$i] : "";
  979. $value1["cargo_weight_lbs"] = !empty($_POST["cargo_weight_lb"][$i]) ? $_POST["cargo_weight_lb"][$i] : "";
  980. $value1["vgm_method"] = !empty($_POST["vgm_method"][$i]) ? $_POST["vgm_method"][$i] : "";
  981. $value1["master_base_number"] = $ocean["master_base_number"];
  982. $sql = common::getInsertSqlNull("$schemas.ocean_vgm_container", $value1);
  983. $db->Execute($sql);
  984. }
  985. if ($db->CompleteTrans() === FALSE) {
  986. return "error";
  987. } else {
  988. return "success";
  989. }
  990. }
  991. }
  992. ?>