ocean_order.class.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  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. }
  116. /*
  117. * ocean order search
  118. */
  119. private function _ocean_search() {
  120. $cp = common::check_input($_POST ['cp']); //current_page
  121. $ps = common::check_input($_POST ['ps']); //ps
  122. if (empty($ps))
  123. $ps = 50;
  124. $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  125. $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
  126. //查询tag
  127. // IFFBCF;Booking Confirmation
  128. // IFFREC;Cargo Arrived at Origin
  129. // IFFDEP;Departure
  130. // IFFARR;Arrived at Final Destination Port
  131. // IFFAFD;Arrived at Final Destination
  132. if (!empty($_POST["filterTag"])) {
  133. if (count($_POST['filterTag']) == 1){
  134. $filterTag = $_POST['filterTag'][0];
  135. }else{
  136. $filterTag = implode(",", $_POST['filterTag']);
  137. }
  138. $_sqlwhere = "1<>1";
  139. if (stripos($filterTag, "Booked") !== FALSE) {
  140. $_sqlwhere .= " or (dd.status = 'Booked')";
  141. }
  142. if (stripos($filterTag, "Cargo Received") !== FALSE) {
  143. $_sqlwhere .= " or (dd.status = 'Cargo Received')";
  144. }
  145. if (stripos($filterTag, "Departed") !== FALSE) {
  146. $_sqlwhere .= " or (dd.status = 'Departed')";
  147. }
  148. if (stripos($filterTag, "Arrived") !== FALSE) {
  149. $_sqlwhere .= " or (dd.status = 'Arrived')";
  150. }
  151. if (stripos($filterTag, "Completed") !== FALSE) {
  152. $_sqlwhere .= " or (dd.status = 'Completed')";
  153. }
  154. if(strtolower($filterTag) <> "all" && !empty($filterTag)){
  155. $sqlWhere .= " and ($_sqlwhere)";
  156. }
  157. }
  158. if (!empty($_POST["_textSearch"])) {
  159. $sqlWhere .= " and text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))";
  160. }
  161. $rc = $_POST ['rc'];
  162. //这里都要查询,除非多传几个参数回来
  163. if ($rc == - 1 || true) {
  164. $sql = "select count(1) from online_ocean
  165. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  166. when a.description='Cargo Pickup' then 'Cargo Received'
  167. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  168. when a.description='Departure' then 'Departed'
  169. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  170. when a.description='Arrived at Final Destination' then 'Completed'
  171. else 'Booked' END as status
  172. from ocean_milestone a
  173. where a.serial_no=online_ocean.serial_no
  174. and a.description in (
  175. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  176. order by id desc limit 1) dd on true" . $sqlWhere;
  177. $rc = common::excuteOneSql($sql);
  178. //Booked
  179. $sql = $this->getOcanOrderSearchSql("Booked",$sqlWhere);
  180. $Booked = common::excuteOneSql($sql);
  181. //Cargo Received
  182. $sql = $this->getOcanOrderSearchSql("Cargo Received",$sqlWhere);
  183. $Cargo_Received = common::excuteOneSql($sql);
  184. //Departed
  185. $sql = $this->getOcanOrderSearchSql("Departed",$sqlWhere);
  186. $Departed = common::excuteOneSql($sql);
  187. //Arrived
  188. $sql = $this->getOcanOrderSearchSql("Arrived",$sqlWhere);
  189. $Arrived = common::excuteOneSql($sql);
  190. //Completed
  191. $sql = $this->getOcanOrderSearchSql("Completed",$sqlWhere);
  192. $Completed = common::excuteOneSql($sql);
  193. if (!empty($_POST["filterTag"])) {
  194. $tagsList = array(array("name"=>"All","number"=>$rc,"type"=>"all","checked"=>in_array('All', $_POST["filterTag"])? true : false),
  195. array("name"=>"Booked","number"=>$Booked,"type"=>"booked","checked"=>in_array('Booked', $_POST["filterTag"])? true : false),
  196. array("name"=>"Cargo Received","number"=>$Cargo_Received,"type"=>"cargo_received","checked"=>in_array('Cargo Received', $_POST["filterTag"])? true : false),
  197. array("name"=>"Departure","number"=>$Departed,"type"=>"departure","checked"=>in_array('Departure', $_POST["filterTag"])? true : false),
  198. array("name"=>"Arrived","number"=>$Arrived,"type"=>"arrived","checked"=>in_array('Arrived', $_POST["filterTag"])? true : false),
  199. array("name"=>"Completed","number"=>$Completed,"type"=>"completed","checked"=>in_array('Completed', $_POST["filterTag"])? true : false));
  200. }else{
  201. //初始,前端有选择着带入选择
  202. $tagsList = array(array("name"=>"All","number"=>$rc,"type"=>"all","checked"=> true ),
  203. array("name"=>"Booked","number"=>$Booked,"type"=>"booked","checked"=> false),
  204. array("name"=>"Cargo Received","number"=>$Cargo_Received,"type"=>"cargo_received","checked"=> false),
  205. array("name"=>"Departure","number"=>$Departed,"type"=>"departure","checked"=> false),
  206. array("name"=>"Arrived","number"=>$Arrived,"type"=>"arrived","checked"=> false),
  207. array("name"=>"Completed","number"=>$Completed,"type"=>"completed","checked"=>false));
  208. }
  209. $TransportList = array(
  210. array("name"=>"Ocean Freight","number"=>$rc,"checked"=>false,"icon"=>"#icon-icon_ocean_b"));
  211. //现在下载交给前端,后台预先只返回全部字段的列,
  212. $allColumn = column::getInstance()->getDisplayColumnAllReomveDefault('Ocean_Search');
  213. $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
  214. }
  215. $tp = ceil($rc / $ps);
  216. $order_by = " etd desc NULLS LAST, id";
  217. if (_isCustomerLogin()) {
  218. $order_by = " eta desc NULLS LAST, id";
  219. }
  220. if ($rc > 0) {
  221. $ocean_ref_sql = " LEFT JOIN LATERAL ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no
  222. FROM public.ocean_reference temp WHERE temp.serial_no = online_ocean.serial_no) aa ON true ";
  223. $ocean_status_sql = " LEFT JOIN LATERAL ( select case when a.description='Booking Confirmation' then 'Booked'
  224. when a.description='Cargo Pickup' then 'Cargo Received'
  225. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  226. when a.description='Departure' then 'Departed'
  227. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  228. when a.description='Arrived at Final Destination' then 'Completed'
  229. else 'Booked' END as new_status
  230. from ocean_milestone a
  231. where a.serial_no=online_ocean.serial_no
  232. and a.description in (
  233. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  234. order by id desc limit 1) dd ON true ";
  235. $sql = "SELECT order_from as _schemas,serial_no as __serial_no, serial_no,
  236. h_bol as _hbol, isf_bol as _isfbol,
  237. CASE
  238. WHEN dd.new_status is null THEN 'Booked'::text
  239. ELSE dd.new_status::text
  240. END AS new_status, ".
  241. column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.online_ocean $ocean_ref_sql $ocean_status_sql" . $sqlWhere .
  242. " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;
  243. $rs = common::excuteListSql($sql);
  244. error_log($sql);
  245. //对查询的结果做特殊处理,比如要拼接某个值,合并值等
  246. foreach($rs as $index => $val) {
  247. //返回加密serial_no
  248. $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
  249. $rs[$index]["mode"] = "Ocean Frieght";
  250. $rs[$index]["status"] = $rs[$index]["new_status"];
  251. }
  252. $arrTmp = array('searchData' => $rs,
  253. 'tagsList' => array(),
  254. 'TransportList' => $TransportList,
  255. 'allColums' => $allBookingColumns,
  256. 'rc' => $rc,
  257. 'ps' => $ps,
  258. 'cp' => $cp,
  259. 'tp' => $tp,
  260. 'tmp_search' => common::deCode($sql, 'E'),
  261. 'type' => common::check_input($_POST ['_ntype']));
  262. } else {
  263. $arrTmp = array('searchData' => array(),
  264. 'tagsList' => array(),
  265. 'TransportList' => $TransportList,
  266. 'allColums' => $allBookingColumns,
  267. 'rc' => $rc,
  268. 'ps' => $ps,
  269. 'cp' => $cp,
  270. 'tp' => $tp,
  271. 'tmp_search' => common::deCode($sql, 'E'),
  272. 'type' => common::check_input($_POST ['_ntype']));
  273. }
  274. common::echo_json_encode(200,$arrTmp);
  275. exit();
  276. }
  277. private function _ocean_detail() {
  278. $serial_no = common::deCode($_GET['a'], 'D');
  279. $status = $_GET['status'];
  280. $sql = "SELECT m_eta as _m_eta, h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
  281. 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,
  282. to_char(final_eta, 'MM/DD/YYYY') as _final_eta,
  283. o.* ,sh.*, cn.* ,aa.*,dd.*
  284. from ocean o
  285. LEFT JOIN LATERAL ( SELECT company as cn_company,
  286. address_1 as cn_address_1,
  287. address_2 as cn_address_2,
  288. address_3 as cn_address_3,
  289. address_4 as cn_address_4,
  290. city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
  291. phone_1 as cn_phone
  292. FROM contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
  293. LEFT JOIN LATERAL ( SELECT company as sh_company,
  294. address_1 as sh_address_1,
  295. address_2 as sh_address_2,
  296. address_3 as sh_address_3,
  297. address_4 as sh_address_4,
  298. city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
  299. phone_1 as sh_phone
  300. FROM contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
  301. LEFT JOIN LATERAL ( SELECT company as aa_company,
  302. address_1 as aa_address_1,
  303. address_2 as aa_address_2,
  304. address_3 as aa_address_3,
  305. address_4 as aa_address_4,
  306. city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
  307. phone_1 as aa_phone
  308. FROM contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
  309. LEFT JOIN LATERAL ( SELECT company as dd_company,
  310. address_1 as dd_address_1,
  311. address_2 as dd_address_2,
  312. address_3 as dd_address_3,
  313. address_4 as dd_address_4,
  314. city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
  315. phone_1 as dd_phone
  316. FROM contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
  317. where lower(serial_no) = '" . strtolower($serial_no) . "'";
  318. $ocean = common::excuteObjectSql($sql);
  319. if (!empty($ocean)) {
  320. $ocean['_isf_bol'] = $ocean['isf_bol'];
  321. if (empty($ocean['_isf_bol'])) {
  322. $ocean['_isf_bol'] = "AMAW" . $ocean['_h_bol'];
  323. }
  324. $isf_ss = md5(md5($ocean['_isf_bol']));
  325. $isf_ss = substr($isf_ss, 7) . substr($isf_ss, 0, 7);
  326. //ETA Dest的计算逻辑移除
  327. // most update status
  328. $_schemas = $_REQUEST["_schemas"];
  329. $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 "
  330. . ", fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un FROM public.online_ocean "
  331. . "where serial_no= '" . $ocean["serial_no"] . "'";
  332. if (!empty($_schemas)) {
  333. $mostStatusSql .= " and order_from='" . $_schemas . "'";
  334. }
  335. $mostStatus = common::excuteObjectSql($mostStatusSql);
  336. $state = -1;
  337. if (!empty($mostStatus["last_status_315_code"])) {
  338. $desc = $mostStatus["last_status_315_code"] . "(" . common::getStatusDesc($mostStatus["last_status_315_code"]) . "): " . $mostStatus["last_status_315_date"];
  339. $mostStatus = $desc;
  340. $state = common::getStatusStage($mostStatus["last_status_315_code"]);
  341. }
  342. //请求地图是需要的参数
  343. $uncode = "'";
  344. if ($mostStatus["place_of_receipt_un"] != $mostStatus["fport_of_loading_un"]) {
  345. $uncode .= $mostStatus["place_of_receipt_un"];
  346. }
  347. $uncode .= "'|'" . $mostStatus["fport_of_loading_un"] . "'|'" . $mostStatus["mport_of_discharge_un"] . "'|'";
  348. if ($mostStatus["mport_of_discharge_un"] != $mostStatus["place_of_delivery_un"]) {
  349. $uncode .= $mostStatus["place_of_delivery_un"];
  350. }
  351. $uncode .= "'";
  352. }
  353. //处理shipment data暂时写死
  354. $simplexData = array();
  355. $simplexData[] = array("index" =>1,"label" =>"Place of Receipt",
  356. "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt'],"isArrival" =>$state == 1 ? true : false);
  357. $simplexData[] = array("index" =>2,"label" =>"Port of Loading",
  358. "path" =>$ocean['fport_of_loading_exp_exp']."/".$ocean['fport_of_loading_exp'],"isArrival" =>$state == 2 ? true : false,
  359. "children" =>array(array("label" =>"Cargo arrival at Origin","date" =>"2024-02-01"),
  360. array("label" =>"'Departure","date" =>"2024-02-01")));
  361. $simplexData[] = array("index" =>3,"label" =>"Port of Discharge",
  362. "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge'],"isArrival" =>$state == 3 ? true : false,
  363. "children" =>array(array("label" =>"ETA","date" =>"2024-02-01")));
  364. $simplexData[] = array("index" =>4,"label" =>"Place of Delivery",
  365. "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery'],"isArrival" =>$state == 4 ? true : false);
  366. //处理transportInfo信息数据
  367. $transportInfo = array("Tracking No." =>$ocean['tracking_no'],"status"=>$status,"mode" => "Ocean Frieght",
  368. "origin" =>$ocean['origin_station'],"destination" =>$ocean['destination_station'],
  369. "etd" =>$ocean['f_etd'],"atd" =>"","eta" =>$ocean['m_eta'],"ata" =>"");
  370. //处理basicInfo信息数据
  371. $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
  372. $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
  373. $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['carrier_booking'],
  374. "PO_NO" =>$ocean['po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
  375. "Incoterm" =>$ocean['terms'],"Service_Type" =>$ocean['service']);
  376. //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
  377. $shipper_address = $this->retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
  378. $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
  379. $consignee_address = $this->retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
  380. $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
  381. $origin_address = $this->retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
  382. $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
  383. $destination_address = $this->retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
  384. $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
  385. $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
  386. $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
  387. $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
  388. $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
  389. $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
  390. //处理routes 转船可能有多个情况
  391. $routes = array(array("mode" =>"Sea", "origin" =>$ocean['origin_station'],
  392. "destination" => $ocean['destination_station'], "etd" => $ocean['f_etd'],"atd" => "",
  393. "eta" =>$ocean['m_eta'],"ata" =>"","vessel" =>$vessel,"voyageNo" =>$voyage));
  394. //处理ocean_reference
  395. $ref_no = array();
  396. $ref_arr = common::excuteListSql("select * from ocean_reference where lower(serial_no) = '" . strtolower($serial_no) . "'");
  397. if(!empty($ref_arr)){
  398. foreach($ref_arr as $ref) {
  399. $ref_no[] = array("label"=>$ref["ref_code"],"value"=>$ref["ref_value"]);
  400. }
  401. }
  402. //处理marksAndDescription
  403. $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description']);
  404. //配置Ocean_Container字段 UI 需要的字段有:Container.no Packing,quantity,Gross weight(kg),Gross weight(LB),CBM,seal#,size.service
  405. //处理Container
  406. $ocean_container_column = array();
  407. $container_column = column::getInstance()->getDisplayColumnAll('Ocean_Container');
  408. foreach($container_column as $cc){
  409. $ocean_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],"formatter" =>"","type" =>"normal");
  410. }
  411. $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . " from oc_container where lower(serial_no) = '" . strtolower($serial_no) . "'";
  412. $rss = common::excuteListSql($sql);
  413. $quantity_tolal = 0;
  414. $packages = "CTN";
  415. $g_weight_tolal = 0;
  416. $ch_weight_tolal = 0;
  417. $cbm_tolal = 0;
  418. foreach ($rss as $key => $rs) {
  419. $quantity_tolal += $rs['qty'];
  420. $g_weight_tolal += $rs['grs_kgs'];
  421. $ch_weight_tolal += $rs['grs_lbs'];
  422. $cbm_tolal += $rs['cbm'];
  423. $packages = " ".$rs['unit'];
  424. //特殊处理weight
  425. if(!empty($rss[$key]['grs_kgs'])){
  426. $rss[$key]['grs_kgs'] = $rs['grs_kgs']."KG";
  427. }
  428. if(!empty($rss[$key]['grs_lbs'])){
  429. $rss[$key]['grs_lbs'] = $rs['grs_lbs']."LB";
  430. }
  431. }
  432. $containers = array("container_column"=>$ocean_container_column,"container_data" =>$rss);
  433. //Packing 不确定信息
  434. $packing = array("Quantity/Unit"=>$quantity_tolal.$packages,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $ch_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
  435. /* Container Status */
  436. //数据库里配置好
  437. $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container_Status') . " from oc_container_v where lower(serial_no) = '" . strtolower($serial_no) . "'";
  438. $rss = common::excuteListSql($sql);
  439. $containerStatusData = array();
  440. if (!empty($rss)) {
  441. //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
  442. $container_status_column = array("EE","I","AE","VD","VA");
  443. foreach ($rss as $rsk => $rs) {
  444. $containerStatusDataTemp = array();
  445. $content = array();
  446. //新UI 还有站点取值,但不清楚取的什么值,CN,SHK 暂时写死
  447. foreach($container_status_column as $status){
  448. $dec = common::excuteOneSql("select description from ra_online_edi_event where ra_name = '" . $status . "'");
  449. $status = strtolower($status);
  450. $content[] = array("title" =>$dec,"date"=>common::date2usdate($rs[$status]),"country"=>"CN,SHK");
  451. }
  452. $containerStatusDataTemp['label'] = $rs['ctnr']." / ".$rs['size'];
  453. $containerStatusDataTemp['content'] = $content;
  454. $containerStatusData[] = $containerStatusDataTemp;
  455. }
  456. }
  457. //Milestones info 列名固定
  458. $Milestones_column = array();
  459. $Milestones_column[] = array("title" =>"Milestones","field" =>"milestones","formatter" =>"","type" =>"normal");
  460. $Milestones_column[] = array("title" =>"Date Time","field" =>"date_time","formatter" =>"","type" =>"normal");
  461. $Milestones_column[] = array("title" =>"Locations","field" =>"locations","formatter" =>"","type" =>"normal");
  462. $Milestones_column[] = array("title" =>"Remarks","field" =>"remarks","formatter" =>"","type" =>"normal");
  463. //假数据
  464. $Milestones_data = array(array("milestones"=>"booking submit","date_time"=>"2024-02-21","locations" => "china", "remarks" =>""));
  465. $Milestones = array("Milestones_column"=>$Milestones_column,"Milestones_data" =>$Milestones_data);
  466. //页面固定写死的信息
  467. $document_column = array();
  468. $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
  469. $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
  470. $document_data = array();
  471. $document = _getViewDocType($_REQUEST["_schemas"]);
  472. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  473. $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'])."'");
  474. if (!empty($document)) {
  475. foreach ($document as $v) {
  476. $file_type = $v['display_name'];
  477. $file_arr = $this->getFileByHbol($ocean['_m_bol'], $ocean['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE,$ocean['_job_bol']) ;
  478. $tar = json_decode($ocean_can_view_file,true);
  479. if(!empty($tar[$v['display_name']])){
  480. foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
  481. switch ($v['display_name']) {
  482. case 'HBL':
  483. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  484. from ra_online_doc_upload
  485. 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']."'
  486. order by id desc";
  487. break;
  488. case 'MBL':
  489. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  490. from ra_online_doc_upload
  491. 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']."'
  492. order by id desc";
  493. break;
  494. case 'Others':
  495. $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
  496. from ra_online_doc_upload
  497. 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']."'
  498. order by id desc";
  499. break;
  500. default:
  501. $sql = "";
  502. break;
  503. }
  504. if (!empty($sql)) {
  505. $rss = common::excuteListSql($sql);
  506. foreach ($rss as $rs) {
  507. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  508. $file_arr[] = array("url"=>$OutFileURL."/download.php?_schemas=&a=".base64_encode(base64_encode($rs['serial_no'])),
  509. "file_name" => $rs['file_name'],
  510. "detail"=>$rs['upload_date'],
  511. "can_delete"=>_getLoginName() == $rs['upload_by']);
  512. }else{
  513. $file_arr[] = array("url"=>"main_new_version?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  514. "file_name" => $rs['file_name'],
  515. "detail"=>$rs['upload_date'],
  516. "can_delete"=>_getLoginName() == $rs['upload_by']);
  517. }
  518. }
  519. }
  520. }
  521. }
  522. //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
  523. //按现在的逻辑,有值才会显示
  524. foreach($file_arr as $f){
  525. $document_data[] = array("file_type"=>$file_type,"file"=>$f);
  526. }
  527. }
  528. }
  529. $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
  530. $emailRecords = $this->getCommunicationNew($ocean["serial_no"]);
  531. $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $ocean["serial_no"] . "' order by id desc limit 1");
  532. $email = $this->getEmail($ocean["serial_no"]);
  533. $email['cc_email'] = $cc_email;
  534. $email['emailRecords'] = $emailRecords;
  535. global $_COPYRIGHT;
  536. $data = array('transportInfo' => $transportInfo,
  537. 'basicInfo' => $basicInfo,
  538. 'businessPartners' => $businessPartners,
  539. 'ref_no' => $ref_no,
  540. 'packing' => $packing,
  541. 'marksAndDescription' => $marksAndDescription,
  542. 'containers' => $containers,
  543. 'simplexData' =>$simplexData,
  544. 'containerStatusData' => $containerStatusData,
  545. 'document_info' => $document_info,
  546. 'containers' => $containers,
  547. 'Milestones' => $Milestones,
  548. 'routes' => $routes,
  549. 'email' => $email,
  550. 'ams_ss' => md5(md5($ocean['serial_no'])),
  551. 'isf_ss' => $isf_ss,
  552. '_schemas' =>$_schemas,
  553. 'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
  554. 'canEdiVgm' => _canEdiVgm(),
  555. 'copyright' =>$_COPYRIGHT);
  556. common::echo_json_encode(200,$data);
  557. exit();
  558. }
  559. private function _ocean_excel() {
  560. //现在下载交给前端,后台最后只返回全部字段的列,
  561. $allColumn = column::getInstance()->getDisplayColumnAll('Ocean_Search');
  562. $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
  563. common::echo_json_encode(200,array("msg"=>"success","allColums" => $allBookingColumns));
  564. exit;
  565. }
  566. private function _ams_isf_log(){
  567. global $cbpdb;
  568. $ams_ss = $_POST['ams_ss'];
  569. $isf_ss = $_POST['isf_ss'];
  570. $amsLog = array();
  571. //页面固定写死的信息
  572. $amsLog_column = array();
  573. $amsLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"normal");
  574. $amsLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  575. $amsLog_column[] = array("title" =>"Name","field" =>"isams_submit","formatter" =>"","type" =>"normal");
  576. $amsLog_column[] = array("title" =>"Description","field" =>"amslog","formatter" =>"","type" =>"normal");
  577. $amsLog["amsLog_column"] = $amsLog_column;
  578. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  579. $amsLog["data"] = array();
  580. if (_canViewAMSLog()) {
  581. $s = $ams_ss;
  582. //$s = "PDLA200127H";
  583. if (!empty($s)) {
  584. //$cc = $cbpdb->GetAll("select distinct h_bol from ams_information where md5(md5(from_serial_no)) = '" . pg_escape_string($s) . "'");
  585. $cc = $cbpdb->GetAll("select distinct h_bol from ams_information where h_bol = '" . pg_escape_string($s) . "'");
  586. foreach ($cc as $v){
  587. $amses[] = $cbpdb->GetAll("select * from ams_info where h_bol = '" . pg_escape_string($v['h_bol']) . "'");
  588. }
  589. //考虑一个情况
  590. if (count($amses) > 0) {
  591. $ams = $amses[0];
  592. $carrier_hbol = substr($ams[0]['m_bol'], 4);
  593. $carrier_scac = substr($ams[0]['m_bol'], 0, 4);
  594. if (empty($ams[0]['h_bol'])){
  595. $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
  596. $amsLog["data"] = array();
  597. }else{
  598. $log = $cbpdb->GetAll("select cbpreplytime as atime, amslog, cbperrorcode, isams_submit
  599. from v_e_amslog where hbol = '" . pg_escape_string($ams[0]['h_bol']) . "'
  600. and split_part(stationname, ',', 1) = split_part('" . pg_escape_string($ams[0]['station_name']) . "', ',', 1)
  601. order by cbpreplytime desc, substr(cbperrorcode, 2, 1) desc");
  602. $amsLog["msg"] = "";
  603. $amsLog["data"] = $log;
  604. }
  605. }
  606. }
  607. }
  608. $isfLog = array();
  609. //页面固定写死的信息
  610. $isfLog_column = array();
  611. $isfLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"normal");
  612. $isfLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
  613. $isfLog_column[] = array("title" =>"Name","field" =>"isfsubmit","formatter" =>"","type" =>"normal");
  614. $isfLog_column[] = array("title" =>"Description","field" =>"isflog","formatter" =>"","type" =>"normal");
  615. $isfLog["isfLog_column"] = $isfLog_column;
  616. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  617. $isfLog["data"] = array();
  618. if (_canViewISFLog()) {
  619. if (!empty($isf_ss)) {
  620. $ss = $isf_ss;
  621. $len = strlen($ss);
  622. $b = substr($ss, $len - 7) . substr($ss, 0, $len - 7);
  623. if (empty($b)){
  624. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  625. $isfLog["data"] = array();
  626. }else{
  627. $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");
  628. }
  629. if (!empty($isf)) {
  630. if (!empty($isf['dob'])){
  631. $isf['dob'] = date("m/d/Y", strtotime($isf['dob']));
  632. }
  633. $msg = $cbpdb->GetAll("select cbpreplytime as atime, isflog, cbperrorcode, isfsubmit, hbol
  634. from v_e_isflog where (case when coalesce(isf_no, '')<>''
  635. then isf_no = '" . pg_escape_string($isf["isf_no"]) . "' else hbol = '" . pg_escape_string($isf["bol"]) . "'
  636. and stationname = '" . pg_escape_string($isf["station_name"]) . "' end)
  637. order by cbpreplytime desc, rowid desc");
  638. $isfLog["msg"] = "";
  639. $isfLog["data"] = $msg;
  640. }else{
  641. $isfLog["msg"] = "Origin have not filed ISF, no data found";
  642. $isfLog["data"] = array();
  643. }
  644. }
  645. }
  646. $data =array("msg"=>"success",
  647. "canViewAMSLog" => _canViewAMSLog(),
  648. "canViewISFLog" => _canViewISFLog(),
  649. "amsLog" =>$amsLog,
  650. "isfLog" =>$isfLog);
  651. common::echo_json_encode(200,$data);
  652. exit;
  653. }
  654. private function getEmail($serial_no) {
  655. return utils::getEmail($serial_no);
  656. }
  657. private function getCommunicationNew($serial_no) {
  658. $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");
  659. $emialRecords =array();
  660. foreach ($list as $k => $v) {
  661. $msg =array();
  662. $msg["name"] = $v["add_by"];
  663. $msg["creatTime"] = $v["add_times"];
  664. $msg["content"] = urldecode($v["web_content"]);
  665. $emialRecords[] = $msg;
  666. }
  667. return $emialRecords;
  668. }
  669. private function retStationInfo($address_1,$address_2,$address_3,$address_4,$city,$state,$country,$zipcode){
  670. $stationInfo = "";
  671. if(!empty($address_1)){
  672. $stationInfo .= $address_1;
  673. }
  674. if(!empty($address_2)){
  675. $stationInfo .= " ".$address_2;
  676. }
  677. if(!empty($address_3)){
  678. $stationInfo .= " ".$address_3;
  679. }
  680. if(!empty($address_4)){
  681. $stationInfo .= " ".$address_4;
  682. }
  683. $temp_str = "";
  684. if(!empty($city)){
  685. $temp_str .= $city." ";
  686. }
  687. if(!empty($state)){
  688. $temp_str .= $state." ";
  689. }
  690. if(!empty($zipcode)){
  691. $temp_str .= $zipcode." ";
  692. }
  693. if(!empty($country)){
  694. $temp_str .= $country." ";
  695. }
  696. if(!empty($temp_str)){
  697. return $stationInfo." ".trim($temp_str);
  698. }
  699. return $stationInfo;
  700. }
  701. /*
  702. * get file by hbol/destination
  703. * H:HBL
  704. * M: MBL
  705. * F: FL
  706. * I: C/I & Packing list
  707. */
  708. private function getFileByHbol($m_bol, $h_bol, $types, $m_bs, $display, $detail = FALSE,$job_no="") {
  709. $types = strtolower($types);
  710. $types = explode(";", $types);
  711. $m_bs = explode(";", $m_bs);
  712. $otheres = NULL;
  713. $filefilter = " ('TELEX') ";//过滤掉类型,单独配置 3537
  714. $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
  715. $file = array();
  716. foreach ($types as $k => $type) {
  717. $m_b = $m_bs[$k];
  718. if (strtolower($m_b) == 'm')
  719. $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";
  720. if (strtolower($m_b) == 'h')
  721. $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";
  722. if (strtolower($m_b) == 'a')
  723. $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";
  724. if (!empty($sql)) {
  725. $rss = common::excuteListSql($sql);
  726. foreach ($rss as $rs) {
  727. if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
  728. $file[] = array("url"=>$OutFileURL.'/download.php?_schemas=&a='.base64_encode(base64_encode($rs['serial_no'])),
  729. "file_name" => $rs['file_name'],
  730. "detail"=>$rs['upload_date'],
  731. "can_delete"=>_getLoginName() == $rs['upload_by']);
  732. }else {
  733. $file[] = array("url"=>"main_new_version?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
  734. "file_name" => $rs['file_name'],
  735. "detail"=>$rs['upload_date'],
  736. "can_delete"=>_getLoginName() == $rs['upload_by']);
  737. }
  738. }
  739. }
  740. }
  741. return $file;
  742. }
  743. /*
  744. * download file
  745. */
  746. private function _download() {
  747. $url = common::deCode($_GET['url'], 'D');
  748. common::download_file($url);
  749. }
  750. private function getOcanOrderSearchSql($type,$sqlWhere) {
  751. if($type == "Booked"){
  752. $Booked_sqlWhere = " and (1<>1 or dd.status ='Booked')";
  753. return "select count(1) from online_ocean
  754. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  755. when a.description='Cargo Pickup' then 'Cargo Received'
  756. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  757. when a.description='Departure' then 'Departed'
  758. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  759. when a.description='Arrived at Final Destination' then 'Completed'
  760. else 'Booked' END as status
  761. from ocean_milestone a
  762. where a.serial_no=online_ocean.serial_no
  763. and a.description in (
  764. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  765. order by id desc limit 1) dd on true" . $sqlWhere.$Booked_sqlWhere;
  766. }
  767. if($type == "Cargo Received"){
  768. $Cargo_Received_sqlWhere = " and (1<>1 or dd.status ='Cargo Received')";
  769. return "select count(1) from online_ocean
  770. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  771. when a.description='Cargo Pickup' then 'Cargo Received'
  772. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  773. when a.description='Departure' then 'Departed'
  774. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  775. when a.description='Arrived at Final Destination' then 'Completed'
  776. else 'Booked' END as status
  777. from ocean_milestone a
  778. where a.serial_no=online_ocean.serial_no
  779. and a.description in (
  780. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  781. order by id desc limit 1) dd on true" . $sqlWhere.$Cargo_Received_sqlWhere;
  782. }
  783. if($type == "Departed"){
  784. $Departed_sqlWhere = " and (1<>1 or dd.status ='Departed')";
  785. return "select count(1) from online_ocean
  786. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  787. when a.description='Cargo Pickup' then 'Cargo Received'
  788. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  789. when a.description='Departure' then 'Departed'
  790. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  791. when a.description='Arrived at Final Destination' then 'Completed'
  792. else 'Booked' END as status
  793. from ocean_milestone a
  794. where a.serial_no=online_ocean.serial_no
  795. and a.description in (
  796. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  797. order by id desc limit 1) dd on true" . $sqlWhere.$Departed_sqlWhere;
  798. }
  799. if($type == "Arrived"){
  800. $Arrived_sqlWhere = " and (1<>1 or dd.status ='Arrived')";
  801. return "select count(1) from online_ocean
  802. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  803. when a.description='Cargo Pickup' then 'Cargo Received'
  804. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  805. when a.description='Departure' then 'Departed'
  806. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  807. when a.description='Arrived at Final Destination' then 'Completed'
  808. else 'Booked' END as status
  809. from ocean_milestone a
  810. where a.serial_no=online_ocean.serial_no
  811. and a.description in (
  812. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  813. order by id desc limit 1) dd on true" . $sqlWhere.$Arrived_sqlWhere;
  814. }
  815. if($type == "Completed"){
  816. $Completed_sqlWhere = " and (1<>1 or dd.status ='Completed')";
  817. return "select count(1) from online_ocean
  818. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  819. when a.description='Cargo Pickup' then 'Cargo Received'
  820. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  821. when a.description='Departure' then 'Departed'
  822. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  823. when a.description='Arrived at Final Destination' then 'Completed'
  824. else 'Booked' END as status
  825. from ocean_milestone a
  826. where a.serial_no=online_ocean.serial_no
  827. and a.description in (
  828. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  829. order by id desc limit 1) dd on true" . $sqlWhere.$Completed_sqlWhere;
  830. }
  831. }
  832. }
  833. ?>