main_new_version.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  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'] = common::excuteOneSql("select ra_password from public.ra_online_user where user_login = 'ra.admin'");
  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. case 'main':
  49. //如果在没有登录前,没有登录信息,指定用户
  50. if(!isset($_SESSION['ONLINE_USER'])){
  51. $menuList = array();
  52. $menuList[] = array("index"=>'1',"label"=>"Dashboard","icon"=>"icon_data_fill_b","path"=>"/dashboard");
  53. $menuList[] = array("index"=>'2',"label"=>"Booking","icon"=>"icon_booking__fill_b","path"=>"/booking");
  54. $menuList[] = array("index"=>'3',"label"=>"Tracking","icon"=>"icon_tracking__fill_b","path"=>"/tracking");
  55. } else {
  56. //d登录后,根据配置的权限,是否显示
  57. if (_isAdmin())
  58. $sql = "select f_column, min(menu_id) as menu_id, max(menu_icon_font) as menu_icon_font from public.ra_online_permission where has_new_version=true group by f_column order by min(order_by)";
  59. elseif (_isNewUser())
  60. $sql = "select f_column, min(menu_id) as menu_id, max(menu_icon_font) as menu_icon_font from public.ra_online_permission where has_new_version=true and customer_check = true group by f_column ORDER BY min(order_by)";
  61. else
  62. $sql = "select p.f_column, min(menu_id) as menu_id, max(menu_icon_font) as menu_icon_font from public.ra_online_user_permission up left join public.ra_online_permission p on up.p_id = p.id where has_new_version=true and lower(user_name) = '" . common::check_input(strtolower(_getLoginName())) . "' group by p.f_column ORDER BY min(p.order_by)";
  63. $rs = common::excuteListSql($sql);
  64. if (empty($rs) && _isApexLogin()) {
  65. $sql = "select f_column, min(menu_id) as menu_id, max(menu_icon_font) as menu_icon_font from public.ra_online_permission where has_new_version=true and default_check = true group by f_column ORDER BY min(order_by)";
  66. $rs = common::excuteListSql($sql);
  67. }
  68. $menuSetting = array("Ocean Booking" => array("label"=>"Booking","path"=>"/booking","icon"=>"icon_booking__fill_b"),
  69. "Ocean B/L Info." => array("label"=>"Tracking","path"=>"/tracking","icon"=>"icon_tracking__fill_b"));
  70. $menuList = array();
  71. $menuList[] = array("index"=>'1',"label"=>"Dashboard","icon"=>"icon_data_fill_b","path"=>"/dashboard");
  72. $index = 2;
  73. foreach ($rs as $value) {
  74. if ($value['f_column'] == "Shipment Info."){
  75. if (_isAdmin())
  76. $ll = common::excuteListSql("select s_column, url_action, sub_menu_id from public.ra_online_permission where has_new_version=true and f_column = '" . common::check_input($value['f_column']) . "' ORDER BY order_by");
  77. elseif (_isNewUser())
  78. $ll = common::excuteListSql("select s_column, url_action, sub_menu_id from public.ra_online_permission where has_new_version=true and customer_check = true and f_column = '" . common::check_input($value['f_column']) . "' ORDER BY order_by");
  79. else
  80. $ll = common::excuteListSql("select s_column, url_action, sub_menu_id from public.ra_online_permission p left join public.ra_online_user_permission gp on gp.p_id = p.id where has_new_version=true and f_column = '" . common::check_input($value['f_column']) . "' and lower(gp.user_name) = '" . common::check_input(strtolower(_getLoginName())) . "' ORDER BY p.order_by");
  81. if (empty($ll) && _isApexLogin()) {
  82. $ll = common::excuteListSql("select s_column, url_action, sub_menu_id from public.ra_online_permission where has_new_version=true and f_column = '" . common::check_input($value['f_column']) . "' and default_check = true ORDER BY order_by");
  83. }
  84. //单独拼接URL
  85. foreach ($ll as $v) {
  86. if($v['s_column'] =="Ocean Booking" || $v['s_column'] =="Ocean B/L Info."){
  87. $urlData = $menuSetting[$v['s_column']];
  88. $menuList[] = array("index"=>"$index","label"=>$urlData['label'],"icon"=>$urlData['icon'],"path"=>$urlData['path']);
  89. $index = $index + 1;
  90. }
  91. }
  92. }
  93. }
  94. // $menuList[] = array("index"=>$index,"label"=>"System Management","icon"=>"icon_system__management_fill_b","type"=>"list",
  95. // "children"=>array(array("index" =>$index.'-1',"label" =>"Operation Log","path"=>"/Operationlog")));
  96. $systemManagement = array("index"=>"$index","label"=>"System Management","icon"=>"icon_system__management_fill_b","type"=>"list");
  97. $children = array();
  98. //只有chud的账户可以看日志记录
  99. if(_getLoginName() == "chud" || _getLoginName() == "IT.Andywu" || _getLoginName() == "ra.admin"){
  100. $children[] = array("index" =>$index.'-1',"label" =>"Operation Log","path"=>"/Operationlog");
  101. }
  102. //$children[] = array("index" =>$index.'-2',"label" =>"System Settings","path"=>"/SystemSettings");
  103. $systemManagement["children"] = $children;
  104. if (!empty($children)){
  105. $menuList[] = $systemManagement;
  106. }
  107. }
  108. common::echo_json_encode(200, $menuList);
  109. exit();
  110. break;
  111. case 'main_filter':
  112. $data = common::getManagement();
  113. common::echo_json_encode(200, $data['dashboard_filter']);
  114. exit();
  115. break;
  116. case 'main_report':
  117. //这里只剩下r3,r4的查询
  118. $type = $_REQUEST["r_type"];
  119. $sqlWhere = ' and ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  120. $sqlWhere = " " . $sqlWhere;
  121. $sqlWhere .= common::getDashboardTransportationSqlWhere();
  122. $sqlWhere = common::check_input($sqlWhere);
  123. $list = common::excuteListSql("select * from public.online_order_status_date_kln_pending('$type'::text, '$sqlWhere'::text) "
  124. . "r (c bigint, e integer, b integer, d text)");
  125. $key = "[";
  126. $value = "[";
  127. $totalValue = 0;
  128. foreach ($list as $vv) {
  129. if ($key != "[") {
  130. $key .= ",";
  131. $value .= ",";
  132. }
  133. if ($type == "r2" || $type == "r3" || $type == "r3_1" || $type == "r4" || $type == "r4_1") {
  134. $key .= '"' . $vv["d"] . '"';
  135. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] . '" }';
  136. $totalValue = $totalValue + $vv["c"];
  137. } else {
  138. if ($vv["e"] == -1) {
  139. $key .= '"Over 80 Days"';
  140. $value .= '{"value":"' . $vv["c"] . '","name":"Over 80 Days"}';
  141. } else {
  142. $key .= '"' . $vv["b"] . '-' . $vv["e"] . ' Days"';
  143. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["b"] . '-' . $vv["e"] . ' Days"}';
  144. }
  145. $totalValue = $totalValue + $vv["c"];
  146. }
  147. }
  148. $key .= "]";
  149. $value .= "]";
  150. //处理返回原表数据格式
  151. $data = common::mian_repot_do($value,$type,$totalValue);
  152. common::echo_json_encode(200, $data);
  153. exit();
  154. break;
  155. case 'main_report_etd':
  156. //这里只有r1查询
  157. $type = "r1";
  158. $container_type = "";
  159. $date_type = strtolower($_REQUEST["date_type"]);
  160. if (empty($_REQUEST["date_start"])) {
  161. $bdate = "null";
  162. } else {
  163. $bdate = $_REQUEST["date_start"];
  164. $bdate = "'$bdate'";
  165. }
  166. if (empty($_REQUEST["date_end"])) {
  167. $edate = "null";
  168. } else {
  169. $edate = $_REQUEST["date_end"];
  170. $edate = "'$edate'";
  171. }
  172. $sqlWhere = ' and ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  173. $sqlWhere = " " . $sqlWhere;
  174. $sqlWhere = $sqlWhere . common::getDashboardTransportationSqlWhere();
  175. $sqlWhere = common::check_input($sqlWhere);
  176. $list = common::excuteListSql("select * from public.online_order_status_date_kln_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text,'$date_type'::text) "
  177. . "r (c bigint, e integer, b integer, d text)");
  178. $key = "[";
  179. $value = "[";
  180. $totalValue = 0;
  181. foreach ($list as $vv) {
  182. if ($key != "[") {
  183. $key .= ",";
  184. $value .= ",";
  185. }
  186. if ($type == "r2" || $type == "r3" || $type == "r3_1" || $type == "r4" || $type == "r4_1") {
  187. $key .= '"' . $vv["d"] . '"';
  188. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] . '" }';
  189. $totalValue = $totalValue + $vv["c"];
  190. } else {
  191. if ($vv["e"] == -1) {
  192. $key .= '"Over 80 Days"';
  193. $value .= '{"value":"' . $vv["c"] . '","name":"Over 80 Days"}';
  194. } else {
  195. $key .= '"' . $vv["b"] . '-' . $vv["e"] . ' Days"';
  196. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["b"] . '-' . $vv["e"] . ' Days"}';
  197. }
  198. $totalValue = $totalValue + $vv["c"];
  199. }
  200. }
  201. $key .= "]";
  202. $value .= "]";
  203. //处理返回原表数据格式
  204. $data = common::mian_repot_do($value,$type,$totalValue);
  205. common::echo_json_encode(200, $data);
  206. exit();
  207. break;
  208. case 'main_report_kpi':
  209. $type = $_REQUEST["r_type"];
  210. $sqlWhere = ' and ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  211. $sqlWhere = " " . $sqlWhere;
  212. $sqlWhere = $sqlWhere . common::getDashboardTransportationSqlWhere();
  213. $sqlWhere = common::check_input($sqlWhere);
  214. $date_type = strtolower($_REQUEST["date_type"]);
  215. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start']))
  216. $sqlWhere .= " and $date_type >= ''" . common::usDate2sqlDate($_REQUEST['date_start']) . " 00:00:00''";
  217. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end']))
  218. $sqlWhere .= " and $date_type <= ''" . common::usDate2sqlDate($_REQUEST['date_end']) . " 23:59:59''";
  219. $list = common::excuteListSql("select * from public.online_order_status_date_kln_kpi('$type'::text,'$sqlWhere'::text) "
  220. . "r (c bigint, d text)");
  221. $key = "[";
  222. $value = "[";
  223. $totalValue = 0;
  224. foreach ($list as $vv) {
  225. if ($key != "[") {
  226. $key .= ",";
  227. $value .= ",";
  228. }
  229. if ($type == "ata_r3" || $type == "atd_r4" ) {
  230. $key .= '"' . $vv["d"] .'"';
  231. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] .'"}';
  232. $totalValue = $totalValue + $vv["c"];
  233. }
  234. }
  235. $key .= "]";
  236. $value .= "]";
  237. //处理返回原表数据格式
  238. $ETDList = array();
  239. $value_arr = json_decode($value,true);
  240. foreach($value_arr as $arr){
  241. $color = common::getItemStyle($type,$arr['name']);
  242. if($arr['name'] == "0 Day"){
  243. $arr['name'] = "≤1 Day";
  244. }
  245. if($arr['name'] == "7 Days"){
  246. $arr['name'] = "≥7 Days";
  247. }
  248. $ETDList[] = array("value" =>intval($arr['value']),"name" =>$arr['name'],"itemStyle" =>array("color" =>$color));
  249. }
  250. if($type == 'atd_r4'){
  251. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('30%','50%'),"title1" =>"Departure","title2" =>"(ATD-ETD)","download_name" => "KPI Departure");
  252. }
  253. if($type == 'ata_r3'){
  254. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('30%','50%'),"title1" =>"Arrival","title2" =>"(ATA-ETA)","download_name" => "KPI Arrival");
  255. }
  256. common::echo_json_encode(200, $data);
  257. exit();
  258. break;
  259. case 'main_report_container_bar':
  260. //新UI 要ALL 20 40 45 四份数据同时查询,且是柱状图,所以与r3 r4查询分开
  261. $container_type_arr = array("20","40","45");
  262. $container_type_param = "all";
  263. $ContainerCounSeries = array();
  264. foreach($container_type_arr as $_container_type){
  265. $container_type = $_container_type;
  266. $date_type = strtolower($_REQUEST["date_type"]);
  267. $type = $_REQUEST["r_type"];
  268. if (empty($_REQUEST["date_start"])) {
  269. $bdate = "null";
  270. } else {
  271. $bdate = $_REQUEST["date_start"];
  272. $bdate = "'$bdate'";
  273. }
  274. if (empty($_REQUEST["date_end"])) {
  275. $edate = "null";
  276. } else {
  277. $edate = $_REQUEST["date_end"];
  278. $edate = "'$edate'";
  279. }
  280. $list= array();
  281. //all 查询所有
  282. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  283. $sqlWhere = common::check_input($sqlWhere);
  284. $sqlWhere = " " . $sqlWhere;
  285. //如果页面查询的是ALL 这个20 40 45都查询出来。否则值查询都对应的size,其他的不查询
  286. if(strtolower($container_type_param) == "all"){
  287. $list = common::excuteListSql("select * from public.online_order_status_date_new_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text, '$date_type'::text) "
  288. . "r (c bigint, e integer, b integer, d text)");
  289. }else{
  290. if($container_type_param == $_container_type){
  291. $list = common::excuteListSql("select * from public.online_order_status_date_new_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text, '$date_type'::text) "
  292. . "r (c bigint, e integer, b integer, d text)");
  293. }
  294. }
  295. $key = "[";
  296. $value = "[";
  297. $totalValue = 0;
  298. foreach ($list as $vv) {
  299. if ($key != "[") {
  300. $key .= ",";
  301. $value .= ",";
  302. }
  303. if ($type == "r2" || $type == "r3" || $type == "r3_1" || $type == "r4" || $type == "r4_1") {
  304. $key .= '"' . $vv["d"] . '"';
  305. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] . '" }';
  306. $totalValue = $totalValue + $vv["c"];
  307. } else {
  308. if ($vv["e"] == -1) {
  309. $key .= '"Over 80 Days"';
  310. $value .= '{"value":"' . $vv["c"] . '","name":"Over 80 Days"}';
  311. } else {
  312. $key .= '"' . $vv["b"] . '-' . $vv["e"] . ' Days"';
  313. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["b"] . '-' . $vv["e"] . ' Days"}';
  314. }
  315. $totalValue = $totalValue + $vv["c"];
  316. }
  317. }
  318. $key .= "]";
  319. $value .= "]";
  320. $key_arr = json_decode($key,true);
  321. $value_arr = json_decode($value,true);
  322. $data = array();
  323. //每一个size 的所有月份总计
  324. $total = 0;
  325. //每一个size 对应的最大值
  326. $max = 0;
  327. foreach($value_arr as $arr){
  328. $data[] = intval($arr['value']);
  329. $total = $total + intval($arr['value']);
  330. $max = $max < intval($arr['value']) ? intval($arr['value']) : $max;
  331. }
  332. $ContainerCounSeries[$container_type] = array("data"=>$data,"total"=>$total,"max"=>$max);
  333. }
  334. //处理返回时数据格式
  335. $ContainerCounSeries_return = array();
  336. //横坐标栏位
  337. $ContainerCount_Title = $key_arr;
  338. //所查的所有模式计算总和
  339. $total = 0;
  340. //所有size下的最大值,方便标注计算最长的Y坐标
  341. $max_all = 0;
  342. foreach($ContainerCounSeries as $k =>$v){
  343. //这个type 是页面传过来的。这个固定r2
  344. $color = common::getItemStyle($type,$k);
  345. $total = $total + $v['total'];
  346. $ContainerCounSeries_return[] = array("name"=>strval($k),"type"=>"bar","emphasis" => array("focus" =>"none"),
  347. "stack" =>"总计","data" =>$v['data'],"itemStyle" =>array("color" =>$color));
  348. $max_all = $max_all + $v['max'];
  349. }
  350. //计算Y坐标的间隔
  351. $interval = utils::calculateTicks(0,$max_all,5);
  352. if($interval == 0){
  353. //处理返回默认值
  354. $interval = 2;
  355. }
  356. $returnData = array("ContainerCount_Title"=>"Total: $total","ContainerCountList" =>$ContainerCount_Title,"ContainerCounSeries" =>$ContainerCounSeries_return,
  357. "min" => 0,"Max" =>$interval*5,"interval" =>$interval,"download_name" => "Container Count");
  358. //demo
  359. // $json = '{"code":200,"data":{"ContainerCount_Title":"Total: 463518","ContainerCountList":["OCT,23","NOV,23","DEC,23","JAN,24","FEB,24","MAR,24","APR,24","MAY,24","JUN,24","JUL,24","AUG,24","SEP,24","OCT,24"],"ContainerCounSeries":[{"name":"20","type":"bar","emphasis":{"focus":"none"},"stack":"\u603b\u8ba1","data":[4400,8600,8804,9271,8961,8793,8534,9476,9530,10277,10081,8997,5784],"itemStyle":{"color":"#FF7500"}},{"name":"40","type":"bar","emphasis":{"focus":"none"},"stack":"\u603b\u8ba1","data":[13652,28021,30422,30136,26320,27035,23979,26494,28406,33318,32318,30962,16369],"itemStyle":{"color":"#FFAC66"}},{"name":"45","type":"bar","emphasis":{"focus":"none"},"stack":"\u603b\u8ba1","data":[189,337,415,437,439,321,250,320,324,603,328,415,200],"itemStyle":{"color":"#FFE3CC"}}],"min":0,"Max":45000,"interval":9000}}';
  360. // $returnData = json_decode($json,true);
  361. // echo json_encode($returnData);
  362. // exit();
  363. common::echo_json_encode(200, $returnData);
  364. exit();
  365. break;
  366. case 'main_report_co2e_bar':
  367. $returnData = common::getCo2eBar();
  368. common::echo_json_encode(200, $returnData);
  369. exit();
  370. break;
  371. case 'main_report_top10_bar':
  372. $returnData = common::getTopBar();
  373. common::echo_json_encode(200, $returnData);
  374. exit();
  375. break;
  376. case 'main_report_revenue':
  377. $returnData = common::getRevenue();
  378. common::echo_json_encode(200, $returnData);
  379. exit();
  380. break;
  381. case 'main_map':
  382. $uncode = $_POST["uncode"];
  383. $serial_no = $_POST["serial_no"];
  384. $unall = explode("|", $uncode);
  385. $sql = "";
  386. if (!empty($unall[0]) && $unall[0] != "''") {
  387. $sql .= "select lon as lng, lat as lat, uncode, 'Place of receipt: '||name1 as location_namewo, 'por' as type from vessel.vt_unlocode where "
  388. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  389. . "($unall[0])";
  390. }
  391. if (!empty($unall[1]) && $unall[1] != "''") {
  392. if (!empty($sql)) {
  393. $sql .= " union ";
  394. }
  395. $sql .= "select lon as lng, lat as lat, uncode, 'POL: '||name1 as location_namewo, 'pol' as type from vessel.vt_unlocode where "
  396. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  397. . "($unall[1])";
  398. }
  399. if (!empty($unall[2]) && $unall[2] != "''") {
  400. if (!empty($sql)) {
  401. $sql .= " union ";
  402. }
  403. $sql .= "select lon as lng, lat as lat, uncode, 'POD: '||name1 as location_namewo, 'pod' as type from vessel.vt_unlocode where "
  404. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  405. . "($unall[2])";
  406. }
  407. if (!empty($unall[3]) && $unall[3] != "''") {
  408. if (!empty($sql)) {
  409. $sql .= " union ";
  410. }
  411. $sql .= "select lon as lng, lat as lat, uncode, 'Place of delivery: '||name1 as location_namewo, 'poe' as type from vessel.vt_unlocode where "
  412. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  413. . "($unall[3])";
  414. }
  415. $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,
  416. to_char(tl.upload_time, 'MM/DD/YYYY HH24:MI:SS') as utime
  417. from public.tk_general g, public.tk_commodity c left join public.tk_location tl on c.serial_no=tl.serial_no
  418. 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");
  419. foreach ($tkStatus as $vv) {
  420. $ll = explode(",", $vv["location"]);
  421. if ($vv["by_pickup"] == "t") {
  422. $pf = explode("\r\n", $vv["pickup_from_exp"]);
  423. $pf = common::check_input($pf[0]) . "(" . $vv["ctnr"] . ")";
  424. $dt = explode("\r\n", $vv["consignee_exp"]);
  425. $dt = common::check_input($dt[0]) . "(" . $vv["ctnr"] . ")";
  426. } else {
  427. $pf = explode("\r\n", $vv["consignee_exp"]);
  428. $pf = common::check_input($pf[0]) . "(" . $vv["ctnr"] . ")";
  429. $dt = explode("\r\n", $vv["deliveryto_exp"]);
  430. $dt = common::check_input($dt[0]) . "(" . $vv["ctnr"] . ")";
  431. }
  432. if ($vv["type"] == "26" && !empty($ll[1])) {
  433. if (!empty($sql)) {
  434. $sql .= " union ";
  435. }
  436. $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";
  437. } elseif ($vv["type"] == "25" && !empty($ll[1])) {
  438. if (!empty($sql)) {
  439. $sql .= " union ";
  440. }
  441. $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";
  442. }
  443. }
  444. if (!empty($sql)) {
  445. $gps = common::excuteListSql($sql . "");
  446. }
  447. if (!empty($serial_no)) {
  448. $all = explode(",", $serial_no);
  449. foreach ($all as $a) {
  450. $rs = common::excuteOneSql("select public.get_vessel_position('$a'::text)");
  451. if (!empty($rs)) {
  452. $rss = explode("|", $rs);
  453. $lng_lat = explode(",", $rss[1]);
  454. $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" => "");
  455. }
  456. }
  457. }
  458. $data = array("gps" => $gps);
  459. common::echo_json_encode("200", $data);
  460. exit();
  461. break;
  462. case 'main_map_new':
  463. include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
  464. //修改添加port_of_transshipment 和port_of_transshipment_name的坐标获取(有为空的可能)
  465. $serial_no = $_REQUEST["serial_no"];
  466. $_schemas = $_REQUEST['_schemas'];
  467. if(empty($_schemas)){
  468. $_schemas ="public";
  469. }
  470. //$serial_no = "F41E6016-1A97-4C93-8198-53D8B3B26220";
  471. $transport_mode = common::excuteOneSql("SELECT transport_mode FROM public.kln_ocean ko
  472. WHERE ko.serial_no = '$serial_no' and order_from = '$_schemas'");
  473. if($transport_mode == "sea"){
  474. $sql = "with ss as (select '$serial_no' as sn)
  475. , aa as (
  476. 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,dd.*
  477. from public.kln_ocean oo
  478. left join LATERAL (
  479. select (select uncode from ports where code = o.port_of_transshipment) as port_of_transshipment_un,
  480. port_of_transshipment_name
  481. from $_schemas.ocean o where o.serial_no=oo.serial_no order by id desc limit 1
  482. ) dd on true
  483. where serial_no=(select sn from ss) limit 1
  484. )
  485. , rr as (
  486. select lon as lng, lat as lat, 'Origin' as label, port_of_loading as infor, 1 as sort, null::timestamp without time zone as stime, 'pol'::text as ptype
  487. from vessel.vt_unlocode, aa where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=fport_of_loading_un
  488. union all
  489. select lon as lng, lat as lat, 'Destination' as label, port_of_discharge as infor, 2 as sort, null::timestamp without time zone as stime, 'pod'::text as ptype
  490. from vessel.vt_unlocode, aa where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=mport_of_discharge_un
  491. union all
  492. select lon as lng, lat as lat, 'Transfer' as label, port_of_transshipment_name as infor, 3 as sort, null::timestamp without time zone as stime, 'poe'::text as ptype
  493. from vessel.vt_unlocode, aa where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=port_of_transshipment_un
  494. )
  495. select * from rr order by sort, stime";
  496. } elseif ($transport_mode == "air"){
  497. $sql = "with ss as (select '$serial_no' as sn)
  498. , aa as (
  499. 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
  500. from public.kln_ocean oo
  501. where serial_no=(select sn from ss) limit 1
  502. )
  503. , rr as (
  504. select lon as lng, lat as lat, 'Origin' as label, port_of_loading as infor, 1 as sort, null::timestamp without time zone as stime, 'pol'::text as ptype
  505. from vessel.vt_unlocode, aa where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=fport_of_loading_un
  506. union all
  507. select lon as lng, lat as lat, 'Destination' as label, port_of_discharge as infor, 2 as sort, null::timestamp without time zone as stime, 'pod'::text as ptype
  508. from vessel.vt_unlocode, aa where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=mport_of_discharge_un
  509. )
  510. select * from rr order by sort, stime";
  511. }
  512. $rss = common::excuteListSql($sql);
  513. //$rss = $mapdb->GetAll($sql);
  514. //先固定死
  515. // $json = '[{"lng":"100.78594000","lat":"13.68521000","label":"Origin","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"},
  516. // {"lng":"100.88333333","lat":"13.08333333","label":"Destination","infor":"LAEM CHABANG PORT,THAILAND","sort":"1","stime":null,"ptype":"pol"},
  517. // {"lng":"-122.28640000","lat":"37.79784000","label":"Transfer","infor":"OAKLAND, CA, USA","sort":"2","stime":null,"ptype":"pod"}]';
  518. //$rss = json_decode($json,true);
  519. global $mapdb;
  520. //查询线(包含所有的线) 空运不查询航线
  521. if ($transport_mode == "air"){
  522. $Line =array();
  523. }else{
  524. error_log("select * from get_track_data('$serial_no',true)");
  525. $map_sql = "select * from get_track_data('$serial_no',true)";
  526. $Line = $mapdb->GetAll($map_sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $map_sql), 0));
  527. }
  528. $solidLine = array();
  529. $dottedLine = array();
  530. $rangePoint = array();
  531. foreach($Line as $line){
  532. if($line['tp'] == "1"){
  533. $solidLine[] = $line;
  534. }elseif($line['tp'] == "0"){
  535. $dottedLine[] = $line;
  536. }else{
  537. $rangePoint[] = $line;
  538. }
  539. }
  540. //如果没有虚线,这这个范围点也是异常的,不需要显示
  541. if(empty($dottedLine)){
  542. $rangePoint = array();
  543. }
  544. $data = array("point"=>$rss,"solidLine"=>$solidLine,"dottedLine"=>$dottedLine,"rangePoint"=>$rangePoint);
  545. common::echo_json_encode(200, $data);
  546. //common::echo_json_encode(200, $rss);
  547. exit();
  548. break;
  549. case 'main_welcome':
  550. $cp = common::check_input($_POST ['cp']); //current_page
  551. $ps = common::check_input($_POST ['ps']); //ps
  552. if (empty($ps))
  553. $ps = 10;
  554. $sqlWhere = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  555. $sqlWhere .= common::getDashboardTransportationSqlWhere();
  556. // test dome
  557. // $_POST['is_default'] = "no";
  558. // $_POST['date_start'] =null;
  559. // $_POST['date_end'] = null;
  560. //默认初始条件:ALL& ETD& Current Month 当前月的1号到最后一天 这个默认条件已经废除,前端不会这样传参数
  561. if (isset($_POST['is_default']) && strtolower($_POST['is_default']) == "yes" && false){
  562. $sqlWhere .= "and etd>='" . date("Y-m") . "-01' and etd<='" . date("Y-m") . "-01'::date + interval '1 month'";
  563. } else {
  564. $date_type = strtolower(common::check_input($_POST ['date_type']));
  565. if (isset($_POST['date_start']) && !empty($_POST['date_start']))
  566. $sqlWhere .= " and $date_type >= '" . common::usDate2sqlDate($_POST['date_start']) . " 00:00:00'";
  567. if (isset($_POST['date_end']) && !empty($_POST['date_end']))
  568. $sqlWhere .= " and $date_type <= '" . common::usDate2sqlDate($_POST['date_end']) . " 23:59:59'";
  569. }
  570. if (isset($_POST['customer']) && !empty($_POST['customer'])){
  571. $sqlWhere .= " and (shipper ilike '%".common::check_input($_POST['customer'])."%' or shipper_id ilike '%".common::check_input($_POST['customer'])."%'
  572. or consignee ilike '%".common::check_input($_POST['customer'])."%' or consignee_id ilike '%".common::check_input($_POST['customer'])."%')";
  573. }
  574. $rc = $_POST ['rc'];
  575. if ($rc == - 1) {
  576. $sql = "SELECT count(1) from public.kln_ocean" . $sqlWhere;
  577. $rc = common::excuteOneSql($sql);
  578. }
  579. $tp = ceil($rc / $ps);
  580. if ($rc > 0) {
  581. $sql = "SELECT order_from as _schemas,serial_no, consignee, shipper, h_bol,final_desination_uncode, transport_mode,
  582. to_char(etd, 'MM/DD/YYYY'::text) as etd,
  583. to_char(eta, 'MM/DD/YYYY'::text) AS eta,
  584. fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un, booking_no,
  585. f_vessel,f_voyage,origin,
  586. CASE
  587. WHEN ((m_iffbcf is not null or m_iffbcf is null) and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Created'::text
  588. WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Cargo Received'::text
  589. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  590. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  591. WHEN (m_iffdel is not null) THEN 'Completed'::text
  592. ELSE 'Created'::text
  593. END AS new_status
  594. FROM public.kln_ocean $sqlWhere";
  595. //$sqlWhere and last_status_315_update_time is not null";
  596. $sql .= " ORDER BY eta DESC limit " . $ps . " offset " . ($cp - 1) * $ps;
  597. //$sql .= " ORDER BY last_status_315_update_time DESC limit " . $ps . " offset " . ($cp - 1) * $ps;
  598. $rss = common::excuteListSql($sql);
  599. //RecentStatusList
  600. $RecentStatusList = array();
  601. foreach ($rss as $key => $value) {
  602. $serial_no = $value["serial_no"];
  603. $_schemas_bk = $value['_schemas'];
  604. $_schemas = $value['_schemas'];
  605. if($_schemas == "public"){
  606. $_schemas = "ocean";
  607. }
  608. //单独取查询milestone信息
  609. if ($value['transport_mode'] == "sea"){
  610. $milestone_sql = "select a.act_date,a.act_time,sn.description,a.timezone,
  611. a.code as dd_code
  612. from public.ocean_milestone a
  613. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'sea'
  614. where a.serial_no='$serial_no'
  615. and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFDEL', ','))
  616. and a.act_date is not null
  617. order by sn.sno desc limit 1";
  618. } elseif ($value['transport_mode'] == "air"){
  619. //air milestone 的Departed实际描述要替换: IFFDEP =》 IFFONB
  620. $milestone_sql = "select a.act_date,a.act_time,sn.description,a.timezone,
  621. case when a.code = 'IFFONB' then 'IFFDEP'
  622. else a.code
  623. end as dd_code
  624. from $_schemas_bk.air_milestone a
  625. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  626. where a.serial_no='$serial_no'
  627. and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFONB,IFFARR,IFFDEL', ','))
  628. and a.act_date is not null
  629. order by sn.sno desc limit 1";
  630. }
  631. $milestone = common::excuteObjectSql($milestone_sql);
  632. $value["act_date"] = $milestone["act_date"];
  633. $value["act_time"] = $milestone["act_time"];
  634. $value["description"] = $milestone["description"];
  635. $value["timezone"] = $milestone["timezone"];
  636. $value["dd_code"] = $milestone["dd_code"];
  637. $timezone = "";
  638. //按照最新execl Timezone From 来自于origin
  639. if($value['dd_code'] == "IFFBCF" || $value['dd_code'] == "IFFCPU"){
  640. $sql = "SELECT (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'')) as timezone
  641. FROM $_schemas.contacts c WHERE c.contact_id = '".$value['origin']."'";
  642. $timezone = common::excuteOneSql($sql);
  643. }
  644. //按照最新execl Timezone From 来自于final_destination
  645. if($value['dd_code'] == "IFFDEL"){
  646. $sql = "select time_zone from public.city_timezone where uncode = '".$value['final_desination_uncode']."'";
  647. $timezone = common::excuteOneSql($sql);
  648. }
  649. if($value['dd_code'] == "IFFREC" || $value['dd_code'] == "IFFDEP" || $value['dd_code'] == "IFFARR"){
  650. $EDI315Time = array();
  651. if ($value['transport_mode'] == "sea"){
  652. //Timezone From 来自于EDI315
  653. $EDI315Time = common::getEDI315Time($serial_no,$value['_schemas']);
  654. }
  655. if($value['dd_code'] == "IFFREC" || $value['dd_code'] == "IFFDEP"){
  656. //先以EDI315 时区为准,如果没有这代表数据是手动输入,或者没有同步情况
  657. $timezone = $EDI315Time[$value['dd_code']]['timezone'];
  658. if(empty($timezone)){
  659. if($value['dd_code'] == "IFFREC"){
  660. $sql = "select time_zone from public.city_timezone where uncode = '".$value['place_of_receipt_un']."'";
  661. }else{
  662. $sql = "select time_zone from public.city_timezone where uncode = '".$value['fport_of_loading_un']."'";
  663. }
  664. $timezone = common::excuteOneSql($sql);
  665. }
  666. }
  667. if($value['dd_code'] == "IFFARR"){
  668. $timezone = $EDI315Time[$value['dd_code']]['timezone'];
  669. if(empty($timezone)){
  670. $sql = "select time_zone from public.city_timezone where uncode = '".$value['mport_of_discharge_un']."'";
  671. $timezone = common::excuteOneSql($sql);
  672. }
  673. }
  674. // 根据IFFDEL这个milestone来判断是否转变为completed
  675. // if($value['dd_code'] == "IFFAFD"){
  676. // $timezone = $EDI315Time[$value['dd_code']]['timezone'];
  677. // if(empty($timezone)){
  678. // $sql = "select time_zone from public.city_timezone where uncode = '".$value['place_of_delivery_un']."'";
  679. // $timezone = common::excuteOneSql($sql);
  680. // }
  681. // }
  682. }
  683. $Arrived = $value['description'];
  684. $RecentStatusList[] = array("Title"=>$value['h_bol'],
  685. "name"=>utils::outDisplayForMerge($value['f_vessel'],$value['f_voyage']),
  686. "bookingNumber" =>$value['booking_no'],
  687. "IsSubscribe" =>false,
  688. "shipperName"=>$value['shipper'],
  689. "consigneeName" =>$value['consignee'],
  690. "startStation"=>$value['fport_of_loading_un'],
  691. "endStation"=>$value['mport_of_discharge_un'],
  692. "ETD"=>$value['etd'],
  693. "ETA"=>$value['eta'],
  694. "type"=>$value['new_status'],
  695. "Arrived"=>$Arrived,
  696. "Time"=>$value["act_date"],
  697. "act_time" =>$value["act_time"],
  698. "timezone"=>$timezone,
  699. "_schemas"=>$value["_schemas"],
  700. "transport_mode"=>$value["transport_mode"],
  701. 'is_subscribe' =>common::checkedSubscribe($value['serial_no']),
  702. "a" =>common::deCode($value['serial_no'], 'E'));
  703. }
  704. $data = common::getManagement();
  705. $arrTmp = array('searchData' => $RecentStatusList,
  706. 'Management' => $data['Management'],
  707. 'dashboard_filter' => $data['dashboard_filter'],
  708. 'is_customer' =>_isCustomerLogin(),
  709. 'rc' => $rc,
  710. 'ps' => $ps,
  711. 'cp' => $cp,
  712. 'tp' => $tp);
  713. } else {
  714. $data = common::getManagement();
  715. $arrTmp = array('searchData' => array(),
  716. 'Management' => $data['Management'],
  717. 'dashboard_filter' => $data['dashboard_filter']);
  718. }
  719. common::echo_json_encode(200,$arrTmp);
  720. exit();
  721. break;
  722. case 'save_layout':
  723. $management = json_encode($_POST["management"]);
  724. $dashboard_filter = json_encode($_POST["dashboardObj"]);
  725. $_param = "";
  726. if(!empty($_POST["management"])){
  727. $_param .= " management = '$management' ";
  728. }
  729. if(!empty($dashboard_filter)){
  730. $_param .= ",dashboard_filter = '$dashboard_filter' ";
  731. }
  732. if(!empty($_param)){
  733. common::excuteUpdateSql("update public.ra_online_user set $_param where lower(user_login) = '" . strtolower(_getLoginName()) . "'");
  734. }
  735. $returnData = array("msg" => "success");
  736. common::echo_json_encode(200, $returnData);
  737. exit();
  738. break;
  739. case 'password':
  740. tools::getInstance()->updatePassword();
  741. break;
  742. case 'tools':
  743. tools::getInstance()->markSystem();
  744. break;
  745. case 'system_setting':
  746. tools::getInstance()->user_system_setting();
  747. break;
  748. case 'monitoring_setting':
  749. tools::getInstance()->user_monitoring_setting();
  750. break;
  751. case 'notifications_rules':
  752. tools::getInstance()->notifications_rules();
  753. break;
  754. case 'user_guide':
  755. $rootPath = realpath(dirname(__FILE__)) . DS;
  756. //common::download_file($rootPath."images\ACE-M1_ISF_ACI_User_Guide\ACE-M1_ISF_ACI_User_Guide.pdf", "ACE-M1_ISF_ACI_User_Guide_V2.0.pdf");
  757. // PDF文件在服务器上的位置
  758. $filename = $rootPath."userFile". DS."KLN_Online_User_Guide_24.11.26.pdf";
  759. $display_name = "KLN_Online_User_Guide_24_11_26.pdf";
  760. // Header content type
  761. header("Content-type: application/pdf");
  762. header("Content-Length: " . filesize($filename));
  763. header("Content-Disposition:attachment;filename=\"" . $display_name . "\"");
  764. // 将文件发送到浏览器。
  765. readfile($filename);
  766. break;
  767. default:
  768. $data = array(
  769. 'msg' => 'Page not found',
  770. );
  771. common::echo_json_encode(500, $data);
  772. }
  773. $db->Close();
  774. $db = null;
  775. if ($max_ec > 0)
  776. ini_set('max_execution_time', $max_ec); //recover old value
  777. if (!empty($memory_limit))
  778. ini_set('memory_limit', $memory_limit);
  779. ?>