ocean_order.class.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  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. //$search = search::getInstance()->getDisplaySearch("Ocean_Search
  33. //栏位信息
  34. $column = column::getInstance()->getDisplayColumn('Ocean_Search');
  35. $BookingTableColumns = column::getInstance()->tableColumns('Ocean_Search',$column);
  36. $data['TrackingTableColumns'] = $BookingTableColumns;
  37. common::echo_json_encode(200,$data);
  38. exit();
  39. }
  40. /*
  41. * ocean order search
  42. */
  43. if ($operate == "search") {
  44. $this->_ocean_search();
  45. }
  46. /*
  47. * ocean order detail
  48. */
  49. if ($operate == "detail") {
  50. $this->_ocean_detail();
  51. }
  52. if ($operate == "ams_isf_log"){
  53. $this->_ams_isf_log();
  54. }
  55. /*
  56. * export ocean order to excel
  57. */
  58. if ($operate == "excel") {
  59. $this->_ocean_excel();
  60. }
  61. if ($operate == 'setting_ocean_order_display') {
  62. column::getInstance()->settingDisplay('Ocean_Search', 'main_new_version.php?action=ocean_order');
  63. }
  64. /*
  65. * download document
  66. */
  67. if ($operate == "download") {
  68. $this->_download();
  69. }
  70. if ($operate == "save_communication") {
  71. try {
  72. $content = $_POST["content"];
  73. $content = common::check_input($content);
  74. $text = $_POST["text"];
  75. $content = urldecode($content);
  76. $web_content = urldecode($text);
  77. $communication_cc = $_POST["communication_cc"];
  78. $serial_no = common::uuid();
  79. $email_uuid = $_POST["serial_no"];
  80. $add_by = _getLoginName();
  81. $refer_id = 0;
  82. $email = $this->getEmail($email_uuid);
  83. $from_email = "US.KApex.Online@kerryapex.com";
  84. $to_email = $email["email"];
  85. $cc_email = $_SESSION['ONLINE_USER']['email'] . ";ApexOnlineCommunication@apexshipping.com";
  86. $communication_cc = trim($communication_cc);
  87. if (!empty($communication_cc)) {
  88. $communication_cc = common::check_input($communication_cc);
  89. $cc_email .= ";" . $communication_cc;
  90. }
  91. $user_from = _getLoginName();
  92. $user_to = $email["name"];
  93. $user_cc = $_SESSION['ONLINE_USER']['first_name'];
  94. if (empty($user_cc)) {
  95. $user_cc = _getLoginName();
  96. }
  97. $user_cc .= ";ApexOnlineCommunication";
  98. //邮件发送
  99. $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>@@";
  100. $emailSql = "select encode(public.pgp_sym_encrypt('" . $serial_no . "','pom_key'), 'base64')::text;";
  101. $key = common::excuteOneSql($emailSql);
  102. $historyEmails = "";
  103. $title = "Communication from " . _getLoginName() . ", HBOL: " . $email["h_bol"] . ", Consignee: " . $email["consignee"];
  104. $emailContent = $content . $poKey . $key . ";" . "@@<br>For your convenience weblink: https://ra.kerryapex.com/<br><br>" . $historyEmails;
  105. 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());");
  106. $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)
  107. VALUES ('$serial_no', '$email_uuid', '$emailContent','$web_content', '$user_from', '$to_email', '$cc_email', $refer_id, '$add_by', now(), '$communication_cc');");
  108. $emailRecords = $this->getCommunicationNew($email_uuid);
  109. common::echo_json_encode(200,array("msg" => "Sent Successfully", "emailRecords" => $emailRecords));
  110. exit();
  111. } catch (Exception $e) {
  112. common::echo_json_encode(500,array("msg" => "Sent Error."));
  113. exit();
  114. }
  115. }
  116. }
  117. /*
  118. * ocean order search
  119. */
  120. private function _ocean_search() {
  121. $cp = common::check_input($_POST ['cp']); //current_page
  122. $ps = common::check_input($_POST ['ps']); //ps
  123. if (empty($ps))
  124. $ps = 50;
  125. $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  126. $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
  127. //查询tag
  128. // IFFBCF;Booking Confirmation
  129. // IFFREC;Cargo Arrived at Origin
  130. // IFFDEP;Departure
  131. // IFFARR;Arrived at Final Destination Port
  132. // IFFAFD;Arrived at Final Destination
  133. if (!empty($_POST["filterTag"])) {
  134. $tempsql = "1<>1";
  135. foreach($_POST["filterTag"] as $tag){
  136. if ($tag == "All"){
  137. continue;
  138. } elseif ($tag == "Booked"){
  139. //$tempsql .=" or code ";
  140. } elseif ($tag == "Cargo Received"){
  141. } elseif ($tag == "Departure"){
  142. }elseif ($tag == "Arrived"){
  143. }elseif ($tag == "Completed"){
  144. }
  145. }
  146. if ($tempsql <> "1<>1"){
  147. $sqlWhere .= " and (exists(select 1 from public.ocean_milestone where $tempsql))";
  148. }
  149. }
  150. if (!empty($_POST["_textSearch"])) {
  151. $sqlWhere .= " and text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))";
  152. }
  153. $rc = $_POST ['rc'];
  154. if ($rc == - 1) {
  155. $sql = "SELECT count(1) from public.online_ocean" . $sqlWhere;
  156. $rc = common::excuteOneSql($sql);
  157. if (!empty($_POST["filterTag"])) {
  158. $tagsList = array(array("name"=>"All","number"=>$rc,"type"=>"all","checked"=>in_array('All', $_POST["filterTag"])? true : false),
  159. array("name"=>"Booked","number"=>0,"type"=>"booked","checked"=>in_array('Booked', $_POST["filterTag"])? true : false),
  160. array("name"=>"Cargo Received","number"=>0,"type"=>"cargo_received","checked"=>in_array('Cargo Received', $_POST["filterTag"])? true : false),
  161. array("name"=>"Departure","number"=>0,"type"=>"departure","checked"=>in_array('Departure', $_POST["filterTag"])? true : false),
  162. array("name"=>"Arrived","number"=>0,"type"=>"arrived","checked"=>in_array('Arrived', $_POST["filterTag"])? true : false),
  163. array("name"=>"Completed","number"=>0,"type"=>"completed","checked"=>in_array('Completed', $_POST["filterTag"])? true : false));
  164. }else{
  165. //初始,前端有选择着带入选择
  166. $tagsList = array(array("name"=>"All","number"=>$rc,"type"=>"all","checked"=> true ),
  167. array("name"=>"Booked","number"=>0,"type"=>"booked","checked"=> false),
  168. array("name"=>"Cargo Received","number"=>0,"type"=>"cargo_received","checked"=> false),
  169. array("name"=>"Departure","number"=>0,"type"=>"departure","checked"=> false),
  170. array("name"=>"Arrived","number"=>0,"type"=>"arrived","checked"=> false),
  171. array("name"=>"Completed","number"=>0,"type"=>"completed","checked"=>false));
  172. }
  173. $TransportList = array(
  174. array("name"=>"Ocean Freight","number"=>$rc,"checked"=>false,"icon"=>"#icon-icon_ocean_b"));
  175. //现在下载交给前端,后台预先只返回全部字段的列,
  176. $allColumn = column::getInstance()->getDisplayColumnAllReomveDefault('Ocean_Search');
  177. $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
  178. }
  179. $tp = ceil($rc / $ps);
  180. $order_by = " etd desc NULLS LAST, id";
  181. if (_isCustomerLogin()) {
  182. $order_by = " eta desc NULLS LAST, id";
  183. }
  184. if ($rc > 0) {
  185. $ocean_ref_sql = "LEFT JOIN LATERAL ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no
  186. FROM public.ocean_reference temp WHERE temp.serial_no = online_ocean.serial_no) aa ON true ";
  187. if (!empty($_POST["_textSearch"])) {
  188. $sql = "SELECT order_from as _schemas, serial_no as __serial_no,serial_no, h_bol as _hbol, isf_bol as _isfbol, " .
  189. column::getInstance()->getSearchSql('Ocean_Search') . " from public.online_ocean $ocean_ref_sql " . $sqlWhere . " "
  190. . "order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;
  191. } else {
  192. $sql = "SELECT order_from as _schemas,serial_no as __serial_no, serial_no, h_bol as _hbol, isf_bol as _isfbol, " .
  193. column::getInstance()->getSearchSql('Ocean_Search') . " from public.online_ocean $ocean_ref_sql " . $sqlWhere .
  194. " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;
  195. }
  196. $rs = common::excuteListSql($sql);
  197. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  198. foreach($rs as $index => $val) {
  199. //返回加密serial_no
  200. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  201. $rs[$index]["mode"] = "Ocean Frieght";
  202. }
  203. $arrTmp = array('searchData' => $rs,
  204. 'tagsList' => array(),
  205. 'TransportList' => $TransportList,
  206. 'allColums' => $allBookingColumns,
  207. 'rc' => $rc,
  208. 'ps' => $ps,
  209. 'cp' => $cp,
  210. 'tp' => $tp,
  211. 'tmp_search' => common::deCode($sql, 'E'),
  212. 'type' => common::check_input($_POST ['_ntype']));
  213. } else {
  214. $arrTmp = array('searchData' => array(),
  215. 'tagsList' => array(),
  216. 'TransportList' => $TransportList,
  217. 'allColums' => $allBookingColumns,
  218. 'rc' => $rc,
  219. 'ps' => $ps,
  220. 'cp' => $cp,
  221. 'tp' => $tp,
  222. 'tmp_search' => common::deCode($sql, 'E'),
  223. 'type' => common::check_input($_POST ['_ntype']));
  224. }
  225. common::echo_json_encode(200,$arrTmp);
  226. exit();
  227. }
  228. private function _ocean_detail() {
  229. $serial_no = common::deCode($_GET['a'], 'D');
  230. $status = $_GET['status'];
  231. $sql = "SELECT m_eta as _m_eta, h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
  232. 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,
  233. to_char(final_eta, 'MM/DD/YYYY') as _final_eta,o.* ,sh.*, cn.* ,aa.*,dd.*
  234. from ocean o
  235. LEFT JOIN LATERAL ( SELECT company as cn_company,
  236. address_1 as cn_address_1,
  237. address_2 as cn_address_2,
  238. address_3 as cn_address_3,
  239. address_4 as cn_address_4,
  240. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  241. phone_1 as cn_phone
  242. FROM contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
  243. LEFT JOIN LATERAL ( SELECT company as sh_company,
  244. address_1 as sh_address_1,
  245. address_2 as sh_address_2,
  246. address_3 as sh_address_3,
  247. address_4 as sh_address_4,
  248. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  249. phone_1 as sh_phone
  250. FROM contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
  251. LEFT JOIN LATERAL ( SELECT company as aa_company,
  252. address_1 as aa_address_1,
  253. address_2 as aa_address_2,
  254. address_3 as aa_address_3,
  255. address_4 as aa_address_4,
  256. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  257. phone_1 as aa_phone
  258. FROM contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
  259. LEFT JOIN LATERAL ( SELECT company as dd_company,
  260. address_1 as dd_address_1,
  261. address_2 as dd_address_2,
  262. address_3 as dd_address_3,
  263. address_4 as dd_address_4,
  264. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  265. phone_1 as dd_phone
  266. FROM contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
  267. where lower(serial_no) = '" . strtolower($serial_no) . "'";
  268. $ocean = common::excuteObjectSql($sql);
  269. if (!empty($ocean)) {
  270. $ocean['_isf_bol'] = $ocean['isf_bol'];
  271. if (empty($ocean['_isf_bol'])) {
  272. $ocean['_isf_bol'] = "AMAW" . $ocean['_h_bol'];
  273. }
  274. $isf_ss = md5(md5($ocean['_isf_bol']));
  275. $isf_ss = substr($isf_ss, 7) . substr($isf_ss, 0, 7);
  276. if (!empty($ocean['_final_eta'])) {
  277. $ocean['ETA Dest'] = $ocean['_final_eta'];
  278. } else if (!empty($ocean['_eta_dest'])) {
  279. if (strpos($ocean['_eta_dest'], "-") > 0) {
  280. $ocean['ETA Dest'] = substr($ocean['_eta_dest'], 5, 2) . "/" . substr($ocean['_eta_dest'], 8, 2) . "/" . substr($ocean['_eta_dest'], 0, 4);
  281. } elseif (strpos($ocean['_eta_dest'], "/") > 0) {
  282. $ocean['ETA Dest'] = $ocean['_eta_dest'];
  283. } else {
  284. $ocean['ETA Dest'] = substr($ocean['_eta_dest'], 4, 2) . "/" . substr($ocean['_eta_dest'], 6, 2) . "/" . substr($ocean['_eta_dest'], 0, 4);
  285. }
  286. } else {
  287. if (!empty($ocean['_m_eta']))
  288. $ocean['ETA Dest'] = utils::calculate_ETA_Des($serial_no);
  289. }
  290. // most update status
  291. $_schemas = $_REQUEST["_schemas"];
  292. $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 "
  293. . ", fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un FROM public.online_ocean "
  294. . "where serial_no= '" . $ocean["serial_no"] . "'";
  295. if (!empty($_schemas)) {
  296. $mostStatusSql .= " and order_from='" . $_schemas . "'";
  297. }
  298. $mostStatus = common::excuteObjectSql($mostStatusSql);
  299. $state = -1;
  300. if (!empty($mostStatus["last_status_315_code"])) {
  301. $desc = $mostStatus["last_status_315_code"] . "(" . common::getStatusDesc($mostStatus["last_status_315_code"]) . "): " . $mostStatus["last_status_315_date"];
  302. $mostStatus = $desc;
  303. $state = common::getStatusStage($mostStatus["last_status_315_code"]);
  304. }
  305. //请求地图是需要的参数
  306. $uncode = "'";
  307. if ($mostStatus["place_of_receipt_un"] != $mostStatus["fport_of_loading_un"]) {
  308. $uncode .= $mostStatus["place_of_receipt_un"];
  309. }
  310. $uncode .= "'|'" . $mostStatus["fport_of_loading_un"] . "'|'" . $mostStatus["mport_of_discharge_un"] . "'|'";
  311. if ($mostStatus["mport_of_discharge_un"] != $mostStatus["place_of_delivery_un"]) {
  312. $uncode .= $mostStatus["place_of_delivery_un"];
  313. }
  314. $uncode .= "'";
  315. }
  316. //处理shipment data 暂时写死
  317. $simplexData = array();
  318. $simplexData[] = array("index" =>1,"label" =>"Place of Receipt",
  319. "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt'],"isArrival" =>$state == 1 ? true : false);
  320. $simplexData[] = array("index" =>2,"label" =>"Port of Loading",
  321. "path" =>$ocean['fport_of_loading_exp_exp']."/".$ocean['fport_of_loading_exp'],"isArrival" =>$state == 2 ? true : false,
  322. "children" =>array(array("label" =>"Cargo arrival at Origin","date" =>"2024-02-01"),array("label" =>"'Departure","date" =>"2024-02-01")));
  323. $simplexData[] = array("index" =>3,"label" =>"Port of Discharge",
  324. "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge'],"isArrival" =>$state == 3 ? true : false,
  325. "children" =>array(array("label" =>"ETA","date" =>"2024-02-01")));
  326. $simplexData[] = array("index" =>4,"label" =>"Place of Delivery",
  327. "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery'],"isArrival" =>$state == 4 ? true : false);
  328. //处理transportInfo信息数据
  329. $transportInfo = array("Tracking No." =>$ocean['tracking_no'],"status"=>$status,"mode" => "","origin" =>$ocean['origin_station'],"destination" =>$ocean['destination_station'],
  330. "etd" =>$ocean['f_etd'],"atd" =>"","eta" =>$ocean['m_eta'],"ata" =>"");
  331. //处理basicInfo信息数据
  332. $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
  333. $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
  334. $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['carrier_booking'],
  335. "PO_NO" =>$ocean['po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  336. "Incoterm" =>$ocean['terms'],"Service_Type" =>$ocean['service']);
  337. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  338. $shipper_address = $this->retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  339. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  340. $consignee_address = $this->retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  341. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  342. $origin_address = $this->retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  343. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  344. $destination_address = $this->retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  345. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  346. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  347. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  348. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  349. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  350. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  351. //todo 不确定信息
  352. $packing = array("Quantity/Unit"=>"47 CTN","G. Weight" => "480.25 KGS","Ch. Weight" => "689.26 KGS","Volume" => "3.801 CBM");
  353. //处理routes
  354. $routes = array(array("mode" =>"Sea", "origin" =>$ocean['origin_station'],
  355. "destination" => $ocean['destination_station'], "etd" => $ocean['f_etd'],"atd" => "",
  356. "eta" =>$ocean['m_eta'],"ata" =>"","vessel" =>$vessel,"voyageNo" =>$voyage));
  357. //处理ocean_reference
  358. $ref_no = array();
  359. $ref_arr = common::excuteListSql("select * from ocean_reference where lower(serial_no) = '" . strtolower($serial_no) . "'");
  360. if(!empty($ref_arr)){
  361. foreach($ref_arr as $ref) {
  362. $ref_no[] = array("label"=>$ref["ref_code"],"value"=>$ref["ref_value"]);
  363. }
  364. }
  365. //处理marksAndDescription
  366. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description']);
  367. //配置Ocean_Container字段 UI 需要的字段有:Container.no Packing,quantity,Gross weight(kg),Gross weight(LB),CBM,seal#,size.service
  368. //处理Container
  369. $ocean_container_column = array();
  370. $container_column = column::getInstance()->getDisplayColumnAll('Ocean_Container');
  371. foreach($container_column as $cc){
  372. $ocean_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],"formatter" =>"","type" =>"normal");
  373. }
  374. $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . " from oc_container where lower(serial_no) = '" . strtolower($serial_no) . "'";
  375. $rss = common::excuteListSql($sql);
  376. foreach ($rss as $key => $rs) {
  377. //特殊处理weight
  378. if(!empty($rss[$key]['grs_kgs'])){
  379. $rss[$key]['grs_kgs'] = $rs['grs_kgs']."KG";
  380. }
  381. if(!empty($rss[$key]['grs_lbs'])){
  382. $rss[$key]['grs_lbs'] = $rs['grs_lbs']."LB";
  383. }
  384. }
  385. $containers = array("container_column"=>$ocean_container_column,"container_data" =>$rss);
  386. /* Container Status */
  387. //数据库里配置好
  388. $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container_Status') . " from oc_container_v where lower(serial_no) = '" . strtolower($serial_no) . "'";
  389. $rss = common::excuteListSql($sql);
  390. $containerStatusData = array();
  391. if (!empty($rss)) {
  392. //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
  393. $container_status_column = array("EE","I","AE","VD","VA");
  394. foreach ($rss as $rsk => $rs) {
  395. $containerStatusDataTemp = array();
  396. $content = array();
  397. //新UI 还有站点取值,但不清楚取的什么值,CN,SHK 暂时写死
  398. foreach($container_status_column as $status){
  399. $dec = common::excuteOneSql("select description from ra_online_edi_event where ra_name = '" . $status . "'");
  400. $status = strtolower($status);
  401. $content[] = array("title" =>$dec,"date"=>common::date2usdate($rs[$status]),"country"=>"CN,SHK");
  402. }
  403. $containerStatusDataTemp['label'] = $rs['ctnr']." / ".$rs['size'];
  404. $containerStatusDataTemp['content'] = $content;
  405. $containerStatusData[] = $containerStatusDataTemp;
  406. }
  407. }
  408. //Milestones info 列名固定
  409. $Milestones_column = array();
  410. $Milestones_column[] = array("title" =>"Milestones","field" =>"milestones","formatter" =>"","type" =>"normal");
  411. $Milestones_column[] = array("title" =>"Date Time","field" =>"date_time","formatter" =>"","type" =>"normal");
  412. $Milestones_column[] = array("title" =>"Locations","field" =>"locations","formatter" =>"","type" =>"normal");
  413. $Milestones_column[] = array("title" =>"Remarks","field" =>"remarks","formatter" =>"","type" =>"normal");
  414. //假数据
  415. $Milestones_data = array(array("milestones"=>"booking submit","date_time"=>"2024-02-21","locations" => "china", "remarks" =>""));
  416. $Milestones = array("Milestones_column"=>$Milestones_column,"Milestones_data" =>$Milestones_data);
  417. //页面固定写死的信息
  418. $document_column = array();
  419. $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
  420. $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
  421. $document_data = array();
  422. $document = _getViewDocType($_REQUEST["_schemas"]);
  423. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  424. $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'])."'");
  425. if (!empty($document)) {
  426. foreach ($document as $v) {
  427. $file_type = $v['display_name'];
  428. $file_arr = $this->getFileByHbol($ocean['_m_bol'], $ocean['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE,$ocean['_job_bol']) ;
  429. $tar = json_decode($ocean_can_view_file,true);
  430. if(!empty($tar[$v['display_name']])){
  431. foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
  432. switch ($v['display_name']) {
  433. case 'HBL':
  434. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  435. from ra_online_doc_upload
  436. 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']."'
  437. order by id desc";
  438. break;
  439. case 'MBL':
  440. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  441. from ra_online_doc_upload
  442. 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']."'
  443. order by id desc";
  444. break;
  445. case 'Others':
  446. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  447. from ra_online_doc_upload
  448. 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']."'
  449. order by id desc";
  450. break;
  451. default:
  452. $sql = "";
  453. break;
  454. }
  455. if (!empty($sql)) {
  456. $rss = common::excuteListSql($sql);
  457. foreach ($rss as $rs) {
  458. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  459. $file_arr[] = array("url"=>$OutFileURL."/download.php?_schemas=&a=".base64_encode(base64_encode($rs['serial_no'])),
  460. "file_name" => $rs['file_name'],
  461. "detail"=>$rs['upload_date'],
  462. "can_delete"=>_getLoginName() == $rs['upload_by']);
  463. }else{
  464. $file[] = array("url"=>"main_new_version?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  465. "file_name" => $rs['file_name'],
  466. "detail"=>$rs['upload_date'],
  467. "can_delete"=>_getLoginName() == $rs['upload_by']);
  468. }
  469. }
  470. }
  471. }
  472. }
  473. //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
  474. //按现在的逻辑,有值才会显示
  475. foreach($file_arr as $f){
  476. $document_data[] = array("file_type"=>$file_type,"file"=>$f);
  477. }
  478. }
  479. }
  480. $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
  481. $emailRecords = $this->getCommunicationNew($ocean["serial_no"]);
  482. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $ocean["serial_no"] . "' order by id desc limit 1");
  483. $email = $this->getEmail($ocean["serial_no"]);
  484. $email['cc_email'] = $cc_email;
  485. $email['emailRecords'] = $emailRecords;
  486. global $_COPYRIGHT;
  487. $data = array('transportInfo' => $transportInfo,
  488. 'basicInfo' => $basicInfo,
  489. 'businessPartners' => $businessPartners,
  490. 'ref_no' => $ref_no,
  491. 'packing' => $packing,
  492. 'marksAndDescription' => $marksAndDescription,
  493. 'containers' => $containers,
  494. 'simplexData' =>$simplexData,
  495. 'containerStatusData' => $containerStatusData,
  496. 'document_info' => $document_info,
  497. 'containers' => $containers,
  498. 'Milestones' => $Milestones,
  499. 'routes' => $routes,
  500. 'email' => $email,
  501. 'ams_ss' => md5(md5($ocean['serial_no'])),
  502. 'isf_ss' => $isf_ss,
  503. '_schemas' =>$_schemas,
  504. 'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
  505. 'canEdiVgm' => _canEdiVgm(),
  506. 'copyright' =>$_COPYRIGHT);
  507. common::echo_json_encode(200,$data);
  508. exit();
  509. }
  510. private function _ocean_excel() {
  511. //现在下载交给前端,后台最后只返回全部字段的列,
  512. $allColumn = column::getInstance()->getDisplayColumnAll('Ocean_Search');
  513. $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
  514. common::echo_json_encode(200,array("msg"=>"success","allColums" => $allBookingColumns));
  515. exit;
  516. }
  517. private function _ams_isf_log(){
  518. global $cbpdb;
  519. $ams_ss = $_POST['ams_ss'];
  520. $isf_ss = $_POST['isf_ss'];
  521. $amsLog = array();
  522. //页面固定写死的信息
  523. $amsLog_column = array();
  524. $amsLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"normal");
  525. $amsLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  526. $amsLog_column[] = array("title" =>"Name","field" =>"isams_submit","formatter" =>"","type" =>"normal");
  527. $amsLog_column[] = array("title" =>"Description","field" =>"amslog","formatter" =>"","type" =>"normal");
  528. $amsLog["amsLog_column"] = $amsLog_column;
  529. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  530. $amsLog["data"] = array();
  531. if (_canViewAMSLog()) {
  532. $s = $ams_ss;
  533. $s = "PDLA200127H";
  534. if (!empty($s)) {
  535. //$cc = $cbpdb->GetAll("select distinct h_bol from ams_information where md5(md5(from_serial_no)) = '" . pg_escape_string($s) . "'");
  536. $cc = $cbpdb->GetAll("select distinct h_bol from ams_information where h_bol = '" . pg_escape_string($s) . "'");
  537. foreach ($cc as $v){
  538. $amses[] = $cbpdb->GetAll("select * from ams_info where h_bol = '" . pg_escape_string($v['h_bol']) . "'");
  539. }
  540. //考虑一个情况
  541. if (count($amses) > 0) {
  542. $ams = $amses[0];
  543. $carrier_hbol = substr($ams[0]['m_bol'], 4);
  544. $carrier_scac = substr($ams[0]['m_bol'], 0, 4);
  545. if (empty($ams[0]['h_bol'])){
  546. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  547. $amsLog["data"] = array();
  548. }else{
  549. $log = $cbpdb->GetAll("select cbpreplytime as atime, amslog, cbperrorcode, isams_submit
  550. from v_e_amslog where hbol = '" . pg_escape_string($ams[0]['h_bol']) . "'
  551. and split_part(stationname, ',', 1) = split_part('" . pg_escape_string($ams[0]['station_name']) . "', ',', 1)
  552. order by cbpreplytime desc, substr(cbperrorcode, 2, 1) desc");
  553. $amsLog["msg"] = "";
  554. $amsLog["data"] = $log;
  555. }
  556. }
  557. }
  558. }
  559. $isfLog = array();
  560. //页面固定写死的信息
  561. $isfLog_column = array();
  562. $isfLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"normal");
  563. $isfLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  564. $isfLog_column[] = array("title" =>"Name","field" =>"isfsubmit","formatter" =>"","type" =>"normal");
  565. $isfLog_column[] = array("title" =>"Description","field" =>"isflog","formatter" =>"","type" =>"normal");
  566. $isfLog["isfLog_column"] = $isfLog_column;
  567. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  568. $isfLog["data"] = array();
  569. if (_canViewISFLog()) {
  570. if (!empty($isf_ss)) {
  571. $ss = $isf_ss;
  572. $len = strlen($ss);
  573. $b = substr($ss, $len - 7) . substr($ss, 0, $len - 7);
  574. if (empty($b)){
  575. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  576. $isfLog["data"] = array();
  577. }else{
  578. $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");
  579. }
  580. if (!empty($isf)) {
  581. if (!empty($isf['dob'])){
  582. $isf['dob'] = date("m/d/Y", strtotime($isf['dob']));
  583. }
  584. $msg = $cbpdb->GetAll("select cbpreplytime as atime, isflog, cbperrorcode, isfsubmit, hbol
  585. from v_e_isflog where (case when coalesce(isf_no, '')<>''
  586. then isf_no = '" . pg_escape_string($isf["isf_no"]) . "' else hbol = '" . pg_escape_string($isf["bol"]) . "'
  587. and stationname = '" . pg_escape_string($isf["station_name"]) . "' end)
  588. order by cbpreplytime desc, rowid desc");
  589. $isfLog["msg"] = "";
  590. $isfLog["data"] = $msg;
  591. }else{
  592. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  593. $isfLog["data"] = array();
  594. }
  595. }
  596. }
  597. $data =array("msg"=>"success",
  598. "canViewAMSLog" => _canViewAMSLog(),
  599. "canViewISFLog" => _canViewISFLog(),
  600. "amsLog" =>$amsLog,
  601. "isfLog" =>$isfLog);
  602. common::echo_json_encode(200,$data);
  603. exit;
  604. }
  605. private function getEmail($serial_no) {
  606. return utils::getEmail($serial_no);
  607. }
  608. private function getCommunicationNew($serial_no) {
  609. $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");
  610. $emialRecords =array();
  611. foreach ($list as $k => $v) {
  612. $msg =array();
  613. $msg["name"] = $v["add_by"];
  614. $msg["creatTime"] = $v["add_times"];
  615. $msg["content"] = urldecode($v["web_content"]);
  616. $emialRecords[] = $msg;
  617. }
  618. return $emialRecords;
  619. }
  620. private function retStationInfo($address_1,$address_2,$address_3,$address_4,$city,$state,$country,$zipcode){
  621. $stationInfo = "";
  622. if(!empty($address_1)){
  623. $stationInfo .= $address_1;
  624. }
  625. if(!empty($address_2)){
  626. $stationInfo .= " ".$address_2;
  627. }
  628. if(!empty($address_3)){
  629. $stationInfo .= " ".$address_3;
  630. }
  631. if(!empty($address_4)){
  632. $stationInfo .= " ".$address_4;
  633. }
  634. $temp_str = "";
  635. if(!empty($city)){
  636. $temp_str .= $city." ";
  637. }
  638. if(!empty($state)){
  639. $temp_str .= $state." ";
  640. }
  641. if(!empty($zipcode)){
  642. $temp_str .= $zipcode." ";
  643. }
  644. if(!empty($country)){
  645. $temp_str .= $country." ";
  646. }
  647. if(!empty($temp_str)){
  648. return $stationInfo." ".trim($temp_str);
  649. }
  650. return $stationInfo;
  651. }
  652. /*
  653. * get file by hbol/destination
  654. * H:HBL
  655. * M: MBL
  656. * F: FL
  657. * I: C/I & Packing list
  658. */
  659. private function getFileByHbol($m_bol, $h_bol, $types, $m_bs, $display, $detail = FALSE,$job_no="") {
  660. $types = strtolower($types);
  661. $types = explode(";", $types);
  662. $m_bs = explode(";", $m_bs);
  663. $otheres = NULL;
  664. $filefilter = " ('TELEX') ";//过滤掉类型,单独配置 3537
  665. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  666. $file = array();
  667. foreach ($types as $k => $type) {
  668. $m_b = $m_bs[$k];
  669. if (strtolower($m_b) == 'm')
  670. $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";
  671. if (strtolower($m_b) == 'h')
  672. $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";
  673. if (strtolower($m_b) == 'a')
  674. $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";
  675. if (!empty($sql)) {
  676. $rss = common::excuteListSql($sql);
  677. foreach ($rss as $rs) {
  678. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  679. $file[] = array("url"=>$OutFileURL.'/download.php?_schemas=&a='.base64_encode(base64_encode($rs['serial_no'])),
  680. "file_name" => $rs['file_name'],
  681. "detail"=>$rs['upload_date'],
  682. "can_delete"=>_getLoginName() == $rs['upload_by']);
  683. }else {
  684. $file[] = array("url"=>"main_new_version?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  685. "file_name" => $rs['file_name'],
  686. "detail"=>$rs['upload_date'],
  687. "can_delete"=>_getLoginName() == $rs['upload_by']);
  688. }
  689. }
  690. }
  691. }
  692. return $file;
  693. }
  694. /*
  695. * download file
  696. */
  697. private function _download() {
  698. $url = common::deCode($_GET['url'], 'D');
  699. common::download_file($url);
  700. }
  701. }
  702. ?>