ocean_order.class.php 49 KB

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