main_new_version.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <?php
  2. $max_ec = ini_get('max_execution_time'); //set max_excution_time
  3. ini_set('max_execution_time', '600');
  4. $memory_limit = "";
  5. $action = "";
  6. if (isset($_GET['action']))
  7. $action = strtolower($_GET['action']);
  8. if (isset($_POST['action']))
  9. $action = strtolower($_POST['action']);
  10. include "include.ini.php";
  11. include 'service/ocean_booking.class.php';
  12. include 'service/ocean_order.class.php';
  13. include 'service/operation_log.class.php';
  14. include 'service/search.class.php';
  15. include 'service/column.class.php';
  16. include 'service/ajax.class.php';
  17. include 'service/login.class.php';
  18. include 'service/tools.class.php';
  19. //为了调用,临时做一个登录动作
  20. $_POST['uname'] = "ra.admin";
  21. $_POST['psw'] = "abc123456789";
  22. //login::getInstance()->do_login_auto();
  23. //验证路由权限
  24. common::securityCheckHandNew($action);
  25. if (_is_only_vgm()) {
  26. Header("Location:main.php?action=main");
  27. }
  28. error_log("--------------前端请求post参数---------------");
  29. error_log(utils::jsonFiltration("null", "\"\"", json_encode($_POST)));
  30. error_log("--------------前端请求get参数---------------");
  31. error_log(utils::jsonFiltration("null", "\"\"", json_encode($_GET)));
  32. //Operation log 日志记录
  33. utils::operation_log_records();
  34. switch ($action) {
  35. case 'ocean_booking':
  36. ocean_booking::getInstance()->ocean_booking();
  37. break;
  38. case 'ocean_order':
  39. include ONLINE_ROOT . 'libs' . DS . 'ams_config.ini.php';
  40. ocean_order::getInstance()->ocean_order();
  41. break;
  42. case 'ajax':
  43. echo ajax::getInstance()->run();
  44. break;
  45. case 'opreation_log':
  46. echo operation_log::getInstance()->operation_log();
  47. break;
  48. /* display index page */
  49. case 'main':
  50. //todo
  51. break;
  52. case 'main_report':
  53. $type = $_REQUEST["r_type"];
  54. $container_type = $_REQUEST["container_type"];
  55. if (empty($_REQUEST["b_date"])) {
  56. $bdate = "null";
  57. } else {
  58. $bdate = $_REQUEST["b_date"];
  59. $bdate = "'$bdate'";
  60. }
  61. if (empty($_REQUEST["e_date"])) {
  62. $edate = "null";
  63. } else {
  64. $edate = $_REQUEST["e_date"];
  65. $edate = "'$edate'";
  66. }
  67. //Demo测试数据 日期全为空
  68. $edate = "null";
  69. $bdate = "null";
  70. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  71. $sqlWhere = common::check_input($sqlWhere);
  72. $sqlWhere = " " . $sqlWhere;
  73. $list = common::excuteListSql("select * from public.online_order_status_date('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
  74. . "r (c bigint, e integer, b integer, d text)");
  75. $key = "[";
  76. $value = "[";
  77. $totalValue = 0;
  78. foreach ($list as $vv) {
  79. if ($key != "[") {
  80. $key .= ",";
  81. $value .= ",";
  82. }
  83. if ($type == "r2" || $type == "r3" || $type == "r3_1" || $type == "r4" || $type == "r4_1") {
  84. $key .= '"' . $vv["d"] . '"';
  85. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] . '" }';
  86. $totalValue = $totalValue + $vv["c"];
  87. } else {
  88. if ($vv["e"] == -1) {
  89. $key .= '"Over 80 Days"';
  90. $value .= '{"value":"' . $vv["c"] . '","name":"Over 80 Days"}';
  91. } else {
  92. $key .= '"' . $vv["b"] . '-' . $vv["e"] . ' Days"';
  93. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["b"] . '-' . $vv["e"] . ' Days"}';
  94. }
  95. $totalValue = $totalValue + $vv["c"];
  96. }
  97. }
  98. $key .= "]";
  99. $value .= "]";
  100. //$data = array($key, $value, $totalValue);
  101. //处理返回原表数据格式
  102. $data = common::mian_repot_do($value,$type,$totalValue);
  103. common::echo_json_encode(200, $data);
  104. exit();
  105. break;
  106. case 'main_report_kpi':
  107. $type = $_REQUEST["r_type"];
  108. $container_type = $_REQUEST["container_type"];
  109. if (empty($_REQUEST["b_date"])) {
  110. $bdate = "null";
  111. } else {
  112. $bdate = $_REQUEST["b_date"];
  113. $bdate = "'$bdate'";
  114. }
  115. if (empty($_REQUEST["e_date"])) {
  116. $edate = "null";
  117. } else {
  118. $edate = $_REQUEST["e_date"];
  119. $edate = "'$edate'";
  120. }
  121. //Demo测试数据 日期全为空
  122. $edate = "null";
  123. $bdate = "null";
  124. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  125. $sqlWhere = common::check_input($sqlWhere);
  126. $sqlWhere = " " . $sqlWhere;
  127. $list = common::excuteListSql("select * from public.online_order_status_date_kpi('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
  128. . "r (c bigint, d text)");
  129. error_log("select * from public.online_order_status_date_kpi('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
  130. . "r (c bigint, d text)");
  131. $key = "[";
  132. $value = "[";
  133. $totalValue = 0;
  134. foreach ($list as $vv) {
  135. if ($key != "[") {
  136. $key .= ",";
  137. $value .= ",";
  138. }
  139. if ($type == "ata_r3" || $type == "atd_r4" ) {
  140. $key .= '"' . $vv["d"] .'"';
  141. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] .'"}';
  142. $totalValue = $totalValue + $vv["c"];
  143. }
  144. }
  145. $key .= "]";
  146. $value .= "]";
  147. //处理返回原表数据格式
  148. $ETDList = array();
  149. $value_arr = json_decode($value,true);
  150. foreach($value_arr as $arr){
  151. $color = common::getItemStyle($type,$arr['name']);
  152. $ETDList[] = array("value" =>intval($arr['value']),"name" =>$arr['name'],"itemStyle" =>array("color" =>$color));
  153. }
  154. if($type == 'atd_r4'){
  155. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('30%','50%'),"title1" =>"Departure","title2" =>"(ATD-ETD)");
  156. }
  157. if($type == 'ata_r3'){
  158. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('30%','50%'),"title1" =>"Arrival","title2" =>"(ATD-ETD)");
  159. }
  160. common::echo_json_encode(200, $data);
  161. exit();
  162. break;
  163. case 'main_report_container_bar':
  164. //新UI 要ALL 20 40 45 四份数据同时查询,且是柱状图,所以与r3 r4查询分开
  165. $container_type_arr = array("20","40","45");
  166. $container_type_param = $_REQUEST["container_type"];
  167. $ContainerCounSeries = array();
  168. foreach($container_type_arr as $_container_type){
  169. $container_type = $_container_type;
  170. $type = $_REQUEST["r_type"];
  171. if (empty($_REQUEST["b_date"])) {
  172. $bdate = "null";
  173. } else {
  174. $bdate = $_REQUEST["b_date"];
  175. $bdate = "'$bdate'";
  176. }
  177. if (empty($_REQUEST["e_date"])) {
  178. $edate = "null";
  179. } else {
  180. $edate = $_REQUEST["e_date"];
  181. $edate = "'$edate'";
  182. }
  183. //Demo测试数据 日期全为空
  184. $edate = "null";
  185. $bdate = "null";
  186. $list= array();
  187. //all 查询所有
  188. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  189. $sqlWhere = common::check_input($sqlWhere);
  190. $sqlWhere = " " . $sqlWhere;
  191. if(strtolower($container_type_param) == "all"){
  192. $list = common::excuteListSql("select * from public.online_order_status_date('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
  193. . "r (c bigint, e integer, b integer, d text)");
  194. }else{
  195. if($container_type_param == $_container_type){
  196. $list = common::excuteListSql("select * from public.online_order_status_date('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
  197. . "r (c bigint, e integer, b integer, d text)");
  198. }
  199. }
  200. $key = "[";
  201. $value = "[";
  202. $totalValue = 0;
  203. foreach ($list as $vv) {
  204. if ($key != "[") {
  205. $key .= ",";
  206. $value .= ",";
  207. }
  208. if ($type == "r2" || $type == "r3" || $type == "r3_1" || $type == "r4" || $type == "r4_1") {
  209. $key .= '"' . $vv["d"] . '"';
  210. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] . '" }';
  211. $totalValue = $totalValue + $vv["c"];
  212. } else {
  213. if ($vv["e"] == -1) {
  214. $key .= '"Over 80 Days"';
  215. $value .= '{"value":"' . $vv["c"] . '","name":"Over 80 Days"}';
  216. } else {
  217. $key .= '"' . $vv["b"] . '-' . $vv["e"] . ' Days"';
  218. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["b"] . '-' . $vv["e"] . ' Days"}';
  219. }
  220. $totalValue = $totalValue + $vv["c"];
  221. }
  222. }
  223. $key .= "]";
  224. $value .= "]";
  225. $key_arr = json_decode($key,true);
  226. $value_arr = json_decode($value,true);
  227. $data = array();
  228. $total = 0;
  229. $max = 0;
  230. foreach($value_arr as $arr){
  231. $data[] = intval($arr['value']);
  232. $total = $total + intval($arr['value']);
  233. $max = $max < intval($arr['value']) ? intval($arr['value']) : $max;
  234. }
  235. $ContainerCounSeries[$container_type] = array("data"=>$data,"total"=>$total,"max"=>$max);
  236. }
  237. //处理返回时数据格式
  238. $ContainerCounSeries_return = array();
  239. $ContainerCount_Title = $key_arr;
  240. $total = 0;
  241. $max_all = 0;
  242. foreach($ContainerCounSeries as $k =>$v){
  243. //这个type 是页面传过来的
  244. $color = common::getItemStyle($type,$k);
  245. $total = $total + $v['total'];
  246. $ContainerCounSeries_return[] = array("name"=>$k,"type"=>"bar","emphasis" => array("focus" =>"none"),
  247. "stack" =>"总计","data" =>$v['data'],"itemStyle" =>array("color" =>$color));
  248. $max_all = $max_all + $v['max'];
  249. }
  250. //处理返回原表数据格式
  251. $interval = utils::calculateTicks(0,$max_all,5);
  252. if($interval == 0){
  253. //处理返回默认值
  254. $interval = 2;
  255. }
  256. $returnData = array("ContainerCount_Title"=>"Total: $total","ContainerCountList" =>$ContainerCount_Title,"ContainerCounSeries" =>$ContainerCounSeries_return,
  257. "min" => 0,"Max" =>$interval*5,"interval" =>$interval);
  258. common::echo_json_encode(200, $returnData);
  259. exit();
  260. break;
  261. case 'main_report_co2e_bar':
  262. $returnData = common::getCo2eBar();
  263. common::echo_json_encode(200, $returnData);
  264. exit();
  265. break;
  266. case 'main_report_top10_bar':
  267. $returnData = common::getTopBar();
  268. common::echo_json_encode(200, $returnData);
  269. exit();
  270. break;
  271. case 'main_map':
  272. $uncode = $_POST["uncode"];
  273. $serial_no = $_POST["serial_no"];
  274. $unall = explode("|", $uncode);
  275. $sql = "";
  276. if (!empty($unall[0]) && $unall[0] != "''") {
  277. $sql .= "select lon as lng, lat as lat, uncode, 'Place of receipt: '||name1 as location_namewo, 'por' as type from vessel.vt_unlocode where "
  278. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  279. . "($unall[0])";
  280. }
  281. if (!empty($unall[1]) && $unall[1] != "''") {
  282. if (!empty($sql)) {
  283. $sql .= " union ";
  284. }
  285. $sql .= "select lon as lng, lat as lat, uncode, 'POL: '||name1 as location_namewo, 'pol' as type from vessel.vt_unlocode where "
  286. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  287. . "($unall[1])";
  288. }
  289. if (!empty($unall[2]) && $unall[2] != "''") {
  290. if (!empty($sql)) {
  291. $sql .= " union ";
  292. }
  293. $sql .= "select lon as lng, lat as lat, uncode, 'POD: '||name1 as location_namewo, 'pod' as type from vessel.vt_unlocode where "
  294. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  295. . "($unall[2])";
  296. }
  297. if (!empty($unall[3]) && $unall[3] != "''") {
  298. if (!empty($sql)) {
  299. $sql .= " union ";
  300. }
  301. $sql .= "select lon as lng, lat as lat, uncode, 'Place of delivery: '||name1 as location_namewo, 'poe' as type from vessel.vt_unlocode where "
  302. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  303. . "($unall[3])";
  304. }
  305. $tkStatus = common::excuteListSql("select tl.by_pickup, g.consignee_exp, g.pickup_from_exp, c.ctnr, g.deliveryto_exp, g.serial_no, tl.location, tl.type, tl.id,
  306. to_char(tl.upload_time, 'MM/DD/YYYY HH24:MI:SS') as utime
  307. from public.tk_general g, public.tk_commodity c left join public.tk_location tl on c.serial_no=tl.serial_no
  308. where g.serial_no=c.serial_no and g.bol=(select m_bol from public.ocean where serial_no='$serial_no') order by tl.order_id");
  309. foreach ($tkStatus as $vv) {
  310. $ll = explode(",", $vv["location"]);
  311. if ($vv["by_pickup"] == "t") {
  312. $pf = explode("\r\n", $vv["pickup_from_exp"]);
  313. $pf = common::check_input($pf[0]) . "(" . $vv["ctnr"] . ")";
  314. $dt = explode("\r\n", $vv["consignee_exp"]);
  315. $dt = common::check_input($dt[0]) . "(" . $vv["ctnr"] . ")";
  316. } else {
  317. $pf = explode("\r\n", $vv["consignee_exp"]);
  318. $pf = common::check_input($pf[0]) . "(" . $vv["ctnr"] . ")";
  319. $dt = explode("\r\n", $vv["deliveryto_exp"]);
  320. $dt = common::check_input($dt[0]) . "(" . $vv["ctnr"] . ")";
  321. }
  322. if ($vv["type"] == "26" && !empty($ll[1])) {
  323. if (!empty($sql)) {
  324. $sql .= " union ";
  325. }
  326. $sql .= "select '" . $ll[1] . "' as lng, '" . $ll[0] . "' as lat, '" . $vv["ctnr"] . "' as uncode, 'Pick up: " . $vv["utime"] . "<br>'||'" . $pf . "' as location_namewo, 'pickup' as type";
  327. } elseif ($vv["type"] == "25" && !empty($ll[1])) {
  328. if (!empty($sql)) {
  329. $sql .= " union ";
  330. }
  331. $sql .= "select '" . $ll[1] . "' as lng, '" . $ll[0] . "' as lat, '" . $vv["ctnr"] . "' as uncode, 'Delivery: " . $vv["utime"] . "<br>'||'" . $dt . "' as location_namewo, 'delivery' as type";
  332. }
  333. }
  334. if (!empty($sql)) {
  335. $gps = common::excuteListSql($sql . "");
  336. }
  337. if (!empty($serial_no)) {
  338. $all = explode(",", $serial_no);
  339. foreach ($all as $a) {
  340. $rs = common::excuteOneSql("select public.get_vessel_position('$a'::text)");
  341. if (!empty($rs)) {
  342. $rss = explode("|", $rs);
  343. $lng_lat = explode(",", $rss[1]);
  344. $gps[] = array("lng" => $lng_lat[0], "lat" => $lng_lat[1], "uncode" => "", "location_namewo" => "", "type" => "vessel", "vessel_name" => $rss[2], "m_shipname" => "", "mmsi" => "", "imo" => "", "m_shipstate" => "", "m_shiptype" => "", "m_dest" => "", "m_newshiparrive" => "", "m_newlasttime" => "", "lasttime" => "", "sub" => "");
  345. }
  346. }
  347. }
  348. $data = array("gps" => $gps);
  349. common::echo_json_encode("200", $data);
  350. exit();
  351. break;
  352. case 'main_map_new':
  353. $serial_no = $_POST["serial_no"];
  354. $sql = "with ss as (select '$serial_no' as sn)
  355. , aa as (
  356. select place_of_receipt_un, place_of_delivery_un, fport_of_loading_un, mport_of_discharge_un, port_of_loading, port_of_discharge, place_of_delivery_exp, place_of_receipt_exp from public.online_ocean oo where serial_no=(select sn from ss) limit 1
  357. )
  358. , v1 as (select public.get_vessel_position(sn::text) bbb from ss)
  359. , t1 as (select tl.upload_time, tl.by_pickup, split_part(g.consignee_exp,'\n',1) as consignee_exp, split_part(g.pickup_from_exp,'\n',1) as pickup_from_exp, c.ctnr, split_part(g.deliveryto_exp,'\n',1) as deliveryto_exp, g.serial_no, tl.location, tl.type, tl.id,
  360. to_char(tl.upload_time, 'MM/DD/YYYY HH24:MI:SS') as utime
  361. from public.tk_general g, public.tk_commodity c left join public.tk_location tl on c.serial_no=tl.serial_no
  362. where g.serial_no=c.serial_no and g.bol=(select m_bol from public.ocean where serial_no=(select sn from ss)) order by tl.order_id)
  363. , vv as (select split_part(split_part(bbb, '|', 2), ',', 1)::numeric as lng, split_part(split_part(bbb, '|', 2), ',', 2)::numeric as lat, 'Vessel: '||split_part(bbb, '|', 3) as infor, 5 as sort, null::timestamp without time zone as stime, 'vessel'::text as ptype from v1 where bbb is not null and bbb<>'')
  364. , tt as (select split_part(location, ',', 2)::numeric as lng, split_part(location, ',', 1)::numeric as lat, (
  365. case when type='26' then ctnr||': Pick up: '||utime||', '||(case when by_pickup=true then pickup_from_exp else consignee_exp end)
  366. else ctnr||': Delivery: '||utime||', '||(case when by_pickup=true then consignee_exp else deliveryto_exp end)
  367. end
  368. ) as infor, 6 as sort, upload_time as stime, case when type='26' then 'pickup'::text else 'delivery'::text end as ptype from t1 where location is not null and location<>'')
  369. , rr as (
  370. select lon as lng, lat as lat, 'Place of receipt: '||place_of_receipt_exp as infor, 0 as sort, null::timestamp without time zone as stime, 'por'::text as ptype from vessel.vt_unlocode, aa where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=place_of_receipt_un
  371. union all
  372. select lon as lng, lat as lat, 'POL: '||port_of_loading as infor, 1 as sort, null::timestamp without time zone as stime, 'pol'::text as ptype from vessel.vt_unlocode, aa where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=fport_of_loading_un
  373. union all
  374. select lon as lng, lat as lat, 'POD: '||port_of_discharge as infor, 2 as sort, null::timestamp without time zone as stime, 'pod'::text as ptype from vessel.vt_unlocode, aa where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=mport_of_discharge_un
  375. union all
  376. select lon as lng, lat as lat, 'Place of delivery: '||place_of_delivery_exp as infor, 3 as sort, null::timestamp without time zone as stime, 'poe'::text as ptype from vessel.vt_unlocode, aa where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=place_of_delivery_un
  377. union all
  378. select * from vv
  379. union all
  380. select * from tt
  381. )
  382. select * from rr order by sort, stime";
  383. $rss = common::excuteListSql($sql);
  384. //先固定死
  385. $json = '[{"lng":"100.78594000","lat":"13.68521000","infor":"Place of receipt: LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"},{"lng":"100.88333333","lat":"13.08333333","infor":"POL: LAEM CHABANG PORT,THAILAND","sort":"1","stime":null,"ptype":"pol"},{"lng":"-122.28640000","lat":"37.79784000","infor":"POD: OAKLAND, CA, USA","sort":"2","stime":null,"ptype":"pod"},{"lng":"93.78333333","lat":"37.68333333","infor":"Place of delivery: STOCKTON, CA, USA","sort":"3","stime":null,"ptype":"poe"}]';
  386. $rss = json_decode($json,true);
  387. common::echo_json_encode("200", $rss);
  388. exit();
  389. break;
  390. case 'main_welcome':
  391. $cp = common::check_input($_POST ['cp']); //current_page
  392. $ps = common::check_input($_POST ['ps']); //ps
  393. if (empty($ps))
  394. $ps = 10;
  395. $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  396. //默认初始条件:ALL& ETD& Current Month 当前月的1号到最后一天
  397. if(isset($_POST['is_default']) && strtolower($_POST['is_default']) == "yes"){
  398. $sqlWhere .= "and etd>='" . date("Y-m") . "-01' and etd<='" . date("Y-m") . "-01'::date + interval '1 month'";
  399. }else{
  400. $date_type = common::check_input($_POST ['date_type']);
  401. if (isset($_POST['date_start']) && !empty($_POST['date_start']))
  402. $sqlWhere .= " and $date_type >= '" . common::usDate2sqlDate($_POST['date_start']) . " 00:00:00'";
  403. if (isset($_POST['date_end']) && !empty($_POST['date_end']))
  404. $sqlWhere .= " and $date_type <= '" . common::usDate2sqlDate($_POST['date_end']) . " 23:59:59'";
  405. }
  406. if (isset($_POST['customer']) && !empty($_POST['customer'])){
  407. $sqlWhere .= " and (shipper ilike '%".common::check_input($_POST['customer'])."%' or shipper_id ilike '%".common::check_input($_POST['customer'])."%'
  408. or consignee ilike '%".common::check_input($_POST['customer'])."%' or consignee_id ilike '%".common::check_input($_POST['customer'])."%')";
  409. }
  410. $rc = $_POST ['rc'];
  411. if ($rc == - 1) {
  412. $sql = "SELECT count(1) from public.online_ocean" . $sqlWhere ." and last_status_315_update_time is not null";
  413. $rc = common::excuteOneSql($sql);
  414. error_log($sql);
  415. }
  416. $tp = ceil($rc / $ps);
  417. if ($rc > 0) {
  418. $sql = "SELECT serial_no,last_status_city, consignee, shipper, h_bol,
  419. to_char(etd, 'MM/DD/YYYY'::text) as etd, to_char(eta, 'MM/DD/YYYY'::text) AS eta,
  420. fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un, ctnrs, count_cntr, last_status_ctnr,booking_no,
  421. to_char(last_status_315_date, 'MM/DD/YYYY'::text) as last_status_315_date,last_status_315_code, last_status_loc, last_status_city, order_from,
  422. dd.status
  423. FROM public.online_ocean
  424. left join LATERAL (select case when a.description='Booking Confirmation' then 'Booked'
  425. when a.description='Cargo Pickup' then 'Cargo Received'
  426. when a.description='Cargo Arrived at Origin' then 'Cargo Received'
  427. when a.description='Departure' then 'Departed'
  428. when a.description='Arrived at Final Destination Port Arrived' then 'Arrived'
  429. when a.description='Arrived at Final Destination' then 'Completed'
  430. else 'Booked' END as status
  431. from ocean_milestone a
  432. where a.serial_no=online_ocean.serial_no
  433. and a.description in (
  434. select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
  435. order by id desc limit 1) dd on true
  436. $sqlWhere and last_status_315_update_time is not null";
  437. if (_isDemo()) {
  438. $sql .= " ORDER BY eta DESC limit " . $ps . " offset " . ($cp - 1) * $ps;
  439. } else {
  440. $sql .= " ORDER BY last_status_315_update_time DESC limit " . $ps . " offset " . ($cp - 1) * $ps;
  441. }
  442. $rss = common::excuteListSql($sql);
  443. //RecentStatusList
  444. $RecentStatusList = array();
  445. foreach ($rss as $key => $value) {
  446. $Arrived = utils::outDisplayForMerge(common::getStatusDesc($value["last_status_315_code"]),common::_toString($value["last_status_loc"]),";");
  447. $RecentStatusList[] = array("Title"=>$value['h_bol'],
  448. "name"=>"MSC SHANVI III / HD433A",
  449. "bookingNumber" =>$value['booking_no'],
  450. "IsSubscribe" =>false,
  451. "shipperName"=>$value['shipper'],
  452. "consigneeName" =>$value['consignee'],
  453. "startStation"=>$value['fport_of_loading_un'],
  454. "endStation"=>$value['mport_of_discharge_un'],
  455. "ETD"=>$value['etd'],
  456. "ETA"=>$value['eta'],
  457. "type"=>$value['status'],
  458. "Arrived"=>$Arrived,
  459. "Time"=>$value["last_status_315_date"],
  460. "a" =>common::deCode($value['serial_no'], 'E'));
  461. }
  462. $arrTmp = array('searchData' => $RecentStatusList,
  463. 'Management' => common::getManagement(),
  464. 'is_customer' =>_isCustomerLogin(),
  465. 'rc' => $rc,
  466. 'ps' => $ps,
  467. 'cp' => $cp,
  468. 'tp' => $tp);
  469. } else {
  470. $arrTmp = array('searchData' => array(),
  471. 'Management' => common::getManagement());
  472. }
  473. common::echo_json_encode(200,$arrTmp);
  474. exit();
  475. break;
  476. case 'save_layout':
  477. $management = json_encode($_POST["management"]);
  478. common::excuteUpdateSql("update public.ra_online_user set management = '$management' where lower(user_login) = '" . strtolower(_getLoginName()) . "'");
  479. $returnData = array("msg" => "success");
  480. common::echo_json_encode(200, $returnData);
  481. exit();
  482. break;
  483. case 'password':
  484. tools::getInstance()->updatePassword();
  485. break;
  486. default:
  487. $data = array(
  488. 'msg' => 'Page not found',
  489. );
  490. common::echo_json_encode(500, $data);
  491. }
  492. $db->Close();
  493. $db = null;
  494. if ($max_ec > 0)
  495. ini_set('max_execution_time', $max_ec); //recover old value
  496. if (!empty($memory_limit))
  497. ini_set('memory_limit', $memory_limit);
  498. ?>