ShuanghongS 10 月之前
父節點
當前提交
415c4a93ae
共有 9 個文件被更改,包括 1238 次插入999 次删除
  1. 103 75
      include.ini.php
  2. 148 286
      main_new_version.php
  3. 41 48
      service/ajax.class.php
  4. 120 184
      service/login.class.php
  5. 187 53
      service/ocean_booking.class.php
  6. 453 40
      service/ocean_order.class.php
  7. 19 8
      service/search.class.php
  8. 134 295
      utils/common.class.php
  9. 33 10
      utils/utils.class.php

+ 103 - 75
include.ini.php

@@ -98,10 +98,6 @@ function _isDocAdmin($username) {
     || strtolower($username) == "doc.leah" || strtolower($username) == "doc.yuki" || strtolower($username) == "doc.yoyo";
 }
 
-function _isCustomerLoginHandNew($user) {
-    return strtolower($user["user_type"]) == 'customer';
-}
-
 function _customerFilerSearchHandNew($user, $schemas = "public", $p = 'place_of_delivery', $s = 'shipper_id', $c = 'consignee_id', $b = 'billto_id', $n = 'notify_party_id', $d = 'port_of_discharge_code') {
     $tt = $user['customer_search_type'];
     $sales = $user['ocean_sales'];
@@ -173,77 +169,6 @@ function _customerFilerSearchHandNew($user, $schemas = "public", $p = 'place_of_
     return $sqlWhere1;
 }
 
-//新增手机customer查询空运函数。
-function _customerFilerSearchHandNew_Air($user, $schemas = "public", $p = 'place_of_delivery', $s = 'shipper_id', $c = 'consignee_id', $b = 'billto_id', $n = 'notify_party_id', $d = 'port_of_discharge_code') {
-    $tt = $user['air_customer_search_type'];
-    $sales = $user['air_sales'];
-    if (empty($tt)) {
-        return "1<>1";
-    }
-    //error_log("_customerFilerSearchHandNew -- " . $schemas);
-    $_contact_id = _getContactIDHandNew_Air($user, $schemas);
-    if (empty($_contact_id)) {
-        return "1<>1";
-    }
-    $sqlWhere1 = "";
-    if (utils::checkExist($tt, 's') && !empty($s)) {
-        if (empty($sqlWhere1)) {
-            $sqlWhere1 = " lower($s) " . common::getInNotInSql($_contact_id);
-        } else {
-            $sqlWhere1 .= " or lower($s) " . common::getInNotInSql($_contact_id);
-        }
-    }
-    if (utils::checkExist($tt, 'c') && !empty($c)) {
-        if (empty($sqlWhere1)) {
-            $sqlWhere1 = " lower($c) " . common::getInNotInSql($_contact_id);
-        } else {
-            $sqlWhere1 .= " or lower($c) " . common::getInNotInSql($_contact_id);
-        }
-    }
-    if (utils::checkExist($tt, 'b') && !empty($b)) {
-        if (empty($sqlWhere1)) {
-            $sqlWhere1 = " lower($b) " . common::getInNotInSql($_contact_id);
-        } else {
-            $sqlWhere1 .= " or lower($b) " . common::getInNotInSql($_contact_id);
-        }
-    }
-    if (utils::checkExist($tt, 'n') && !empty($n)) {
-        if (empty($sqlWhere1)) {
-            $sqlWhere1 = " lower($n) " . common::getInNotInSql($_contact_id);
-        } else {
-            $sqlWhere1 .= " or lower($n) " . common::getInNotInSql($_contact_id);
-        }
-    }
-    if (empty($sqlWhere1))
-        return "1<>1";
-    $sqlWhere1 = "(" . $sqlWhere1 . ")";
-
-    if (!empty($user['customer_destination']) && !empty($p)) {
-        $sqlWhere1 .= " and lower($p) " . common::getInNotInSql($user['customer_destination']);
-    }
-
-    if (!empty($user['customer_discharge']) && !empty($d)) {
-        $sqlWhere1 .= " and lower($d) " . common::getInNotInSql($user['customer_discharge']);
-    }
-
-    if (strtolower($sales) == 'all' || empty($sales)) {
-        
-    } else {
-        if (utils::checkExist($sales, ";")) {
-            $sql = "1!=1";
-            $tt = explode(";", $sales);
-            foreach ($tt as $t) {
-                $t = trim($t);
-                if (!empty($t))
-                    $sql .= " or sales_rep ilike '" . $t . "%'";
-            }
-            $sqlWhere1 .= " and ($sql)";
-        } else
-            $sqlWhere1 .= " and sales_rep ilike '" . $sales . "%'";
-    }
-    return $sqlWhere1;
-}
-
 function _getContactIDHandNew_Air($user, $schemas = "public") {
     $contact_id_user = _getCompanyContactHandNew_Air($user);
     $id = "";
@@ -335,6 +260,14 @@ function _getViewDocType($schemas = "public") {
     }
 }
 
+function _getAirViewDocType($schemas = "public") {
+    if ($schemas == "public") {
+        return $_SESSION['ONLINE_USER']['view_air_doc_type'];
+    } else {
+        return $_SESSION[$schemas . '_ONLINE_USER']['view_air_doc_type'];
+    }
+}
+
 function _canEdiVgm($schemas = "public") {
     if ($schemas == "public") {
         return strtolower($_SESSION['ONLINE_USER']['can_edi_vgm']) == 't' || _isAdmin();
@@ -342,4 +275,99 @@ function _canEdiVgm($schemas = "public") {
         return strtolower($_SESSION[$schemas . '_ONLINE_USER']['can_edi_vgm']) == 't' || _isAdmin();
     }
 }
+function _getAirStation($schemas = "public") {
+    if ($schemas == "public") {
+        return $_SESSION['ONLINE_USER']['air_station'];
+    } else {
+        return $_SESSION[$schemas . '_ONLINE_USER']['air_station'];
+    }
+}
+
+function _getAirStationOr($schemas = "public") {
+    if ($schemas == "public") {
+        return $_SESSION['ONLINE_USER']['air_station_or'];
+    } else {
+        return $_SESSION[$schemas . '_ONLINE_USER']['air_station_or'];
+    }
+}
+
+function _getAirSales($schemas = "public") {
+    if ($schemas == "public") {
+        return $_SESSION['ONLINE_USER']['air_sales'];
+    } else {
+        return $_SESSION[$schemas . '_ONLINE_USER']['air_sales'];
+    }
+}
+
+function _getAirSalesOr($schemas = "public") {
+    if ($schemas == "public") {
+        return $_SESSION['ONLINE_USER']['air_sales_or'];
+    } else {
+        return $_SESSION[$schemas . '_ONLINE_USER']['air_sales_or'];
+    }
+}
+
+function _customerAirSearchType($schemas = "public") {
+    if ($schemas == "public") {
+        return $_SESSION['ONLINE_USER']['air_customer_search_type'];
+    } else {
+        return $_SESSION[$schemas . '_ONLINE_USER']['air_customer_search_type'];
+    }
+}
+
+function _getAirContactID($schemas = "public") {
+    if ($schemas == "public") {
+        return $_SESSION['ONLINE_USER']['air_customers'];
+    } else {
+        return $_SESSION[$schemas . '_ONLINE_USER']['air_customers'];
+    }
+}
+
+function _customerAirFilerSearch($schemas = "public", $s = 'shipper_id', $c = 'consignee_id', $b = 'billto_id', $n = 'notify_party_id') {
+    $tt = _customerAirSearchType($schemas);
+    if (empty($tt))
+        return "1<>1";
+    $_contact_id = _getAirContactID($schemas);
+    if (empty($_contact_id)) {
+        return "1<>1";
+    }
+    $sqlWhere1 = "";
+    if (utils::checkExist($tt, 's') && !empty($s)) {
+        if (empty($sqlWhere1)) {
+            $sqlWhere1 = " lower($s) " . common::getInNotInSql($_contact_id);
+        } else {
+            $sqlWhere1 .= " or lower($s) " . common::getInNotInSql($_contact_id);
+        }
+    }
+    if (utils::checkExist($tt, 'c') && !empty($c)) {
+        if (empty($sqlWhere1)) {
+            $sqlWhere1 = " lower($c) " . common::getInNotInSql($_contact_id);
+        } else {
+            $sqlWhere1 .= " or lower($c) " . common::getInNotInSql($_contact_id);
+        }
+    }
+    if (utils::checkExist($tt, 'b') && !empty($b)) {
+        if (empty($sqlWhere1)) {
+            $sqlWhere1 = " lower($b) " . common::getInNotInSql($_contact_id);
+        } else {
+            $sqlWhere1 .= " or lower($b) " . common::getInNotInSql($_contact_id);
+        }
+    }
+    if (utils::checkExist($tt, 'n') && !empty($n)) {
+        if (empty($sqlWhere1)) {
+            $sqlWhere1 = " lower($n) " . common::getInNotInSql($_contact_id);
+        } else {
+            $sqlWhere1 .= " or lower($n) " . common::getInNotInSql($_contact_id);
+        }
+    }
+    if (empty($sqlWhere1))
+        return "1<>1";
+    $sqlWhere1 = "(" . $sqlWhere1 . ")";
+
+    return $sqlWhere1;
+}
+
+function _isCustomerLoginHandNew($user) {
+    return strtolower($user["user_type"]) == 'customer';
+}
 ?>

+ 148 - 286
main_new_version.php

@@ -109,81 +109,17 @@ switch ($action) {
         exit();
         break;    
     case 'main_report':
+        //这里只剩下r3,r4的查询
         $type = $_REQUEST["r_type"];
-        $container_type = $_REQUEST["container_type"];
-        if (empty($_REQUEST["b_date"])) {
-            $bdate = "null";
-        } else {
-            $bdate = $_REQUEST["b_date"];
-            $bdate = "'$bdate'";
-        }
-        if (empty($_REQUEST["e_date"])) {
-            $edate = "null";
-        } else {
-            $edate = $_REQUEST["e_date"];
-            $edate = "'$edate'";
-        }
-        //Demo测试数据 日期全为空 :前端是由日期过来来的
-        // $edate = "null";
-        // $bdate = "null";
-
-        $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
-        $sqlWhere = common::check_input($sqlWhere);
+       
+        $sqlWhere = ' and ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
         $sqlWhere = " " . $sqlWhere;
+        $sqlWhere .= common::getDashboardTransportationSqlWhere();
+        $sqlWhere = common::check_input($sqlWhere);
 
-        $transportation = $_REQUEST["transportation"];
-        if(!is_array($transportation)){
-            $transportation = array($transportation);
-        }
-
-        $list = array();
-        if(count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
-            $transportation = array("Sea","Air","Road");         
-        }
-        foreach($transportation as $mode){
-            if($mode == 'Sea'){
-                $Sealist = common::excuteListSql("select * from public.online_order_status_date('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
+        $list = common::excuteListSql("select * from public.online_order_status_date_kln_pending('$type'::text, '$sqlWhere'::text) "
                     . "r (c bigint, e integer, b integer, d text)");
-                //拼接数据     
-                if(empty($list)){
-                    $list = $Sealist;
-                }else{
-                    foreach($list as $lk =>$lv){
-                        $list[$lk]['c'] = $list[$lk]['c'] + $Sealist[$lk]['c'];
-                    }
-                }  
-            }
-            if($mode == 'Air'){
-                //暂时查询空数据 
-                $sqlWhere_air = $sqlWhere ." and 1<>1 ";
-                $Airlist = common::excuteListSql("select * from public.online_order_status_date('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere_air'::text, '$container_type'::text) "
-                    . "r (c bigint, e integer, b integer, d text)");
-                //拼接数据     
-                if(empty($list)){
-                    $list = $Airlist;
-                }else{
-                    foreach($list as $lk =>$lv){
-                        $list[$lk]['c'] = $list[$lk]['c'] + $Airlist[$lk]['c'];
-                    }
-                }       
-            }
-            if($mode == 'Road'){
-                $sqlWhere_road = $sqlWhere ." and 1<>1 ";
-                $roadlist = common::excuteListSql("select * from public.online_order_status_date('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere_road'::text, '$container_type'::text) "
-                    . "r (c bigint, e integer, b integer, d text)");  
-                //拼接数据     
-                if(empty($list)){
-                    $list = $roadlist;
-                }else{
-                    foreach($list as $lk =>$lv){
-                        $list[$lk]['c'] = $list[$lk]['c'] + $Airlist[$lk]['c'];
-                    }
-                }      
-            }
-        }
-        //online_order_status_date_new 与本地的区分,发布上去这去掉new
-        // $list = common::excuteListSql("select * from public.online_order_status_date('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
-        //                 . "r (c bigint, e integer, b integer, d text)");               
+   
         $key = "[";
         $value = "[";
         $totalValue = 0;
@@ -231,61 +167,13 @@ switch ($action) {
             $edate = $_REQUEST["date_end"];
             $edate = "'$edate'";
         }
-        $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
-        $sqlWhere = common::check_input($sqlWhere);
+        $sqlWhere = ' and ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
         $sqlWhere = " " . $sqlWhere;
+        $sqlWhere = $sqlWhere . common::getDashboardTransportationSqlWhere();
+        $sqlWhere = common::check_input($sqlWhere);
 
-        $transportation = $_REQUEST["transportation"];
-        if(!is_array($transportation)){
-            $transportation = array($transportation);
-        }
-        $list = array();
-        if(count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
-            $transportation = array("Sea","Air","Road");         
-        }
-        foreach($transportation as $mode){
-            if($mode == 'Sea'){
-                $Sealist = 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) "
-                    . "r (c bigint, e integer, b integer, d text)");
-                //拼接数据     
-                if(empty($list)){
-                    $list = $Sealist;
-                }else{
-                    foreach($list as $lk =>$lv){
-                        $list[$lk]['c'] = $list[$lk]['c'] + $Sealist[$lk]['c'];
-                    }
-                }  
-            }
-            if($mode == 'Air'){
-                //暂时查询空数据 
-                $sqlWhere_air = $sqlWhere ." and 1<>1 ";
-                $Airlist = common::excuteListSql("select * from public.online_order_status_date_new_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere_air'::text, '$container_type'::text,'$date_type'::text) "
-                    . "r (c bigint, e integer, b integer, d text)");
-                //拼接数据     
-                if(empty($list)){
-                    $list = $Airlist;
-                }else{
-                    foreach($list as $lk =>$lv){
-                        $list[$lk]['c'] = $list[$lk]['c'] + $Airlist[$lk]['c'];
-                    }
-                }       
-            }
-            if($mode == 'Road'){
-                $sqlWhere_road = $sqlWhere ." and 1<>1 ";
-                $roadlist = common::excuteListSql("select * from public.online_order_status_date_new_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere_road'::text, '$container_type'::text,'$date_type'::text) "
-                    . "r (c bigint, e integer, b integer, d text)");  
-                //拼接数据     
-                if(empty($list)){
-                    $list = $roadlist;
-                }else{
-                    foreach($list as $lk =>$lv){
-                        $list[$lk]['c'] = $list[$lk]['c'] + $roadlist[$lk]['c'];
-                    }
-                }      
-            }
-        }
-        // $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) "
-        //                     . "r (c bigint, e integer, b integer, d text)");               
+        $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) "
+                             . "r (c bigint, e integer, b integer, d text)");               
         $key = "[";
         $value = "[";
         $totalValue = 0;
@@ -318,9 +206,10 @@ switch ($action) {
         break;    
     case 'main_report_kpi':
         $type = $_REQUEST["r_type"];
-        $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
-        $sqlWhere = common::check_input($sqlWhere);
+        $sqlWhere = ' and ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
         $sqlWhere = " " . $sqlWhere;
+        $sqlWhere = $sqlWhere . common::getDashboardTransportationSqlWhere();
+        $sqlWhere = common::check_input($sqlWhere);
         
         $date_type = strtolower($_REQUEST["date_type"]);
         if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start']))
@@ -328,67 +217,9 @@ switch ($action) {
         if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end']))
             $sqlWhere .= " and $date_type <= ''" . common::usDate2sqlDate($_REQUEST['date_end']) . " 23:59:59''";
         
-        $transportation = $_REQUEST["transportation"];
-        if(!is_array($transportation)){
-            $transportation = array($transportation);
-        }
-
-        $list = array();
-        if(count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
-            $transportation = array("Sea","Air","Road");         
-        }
-        foreach($transportation as $mode){
-            if($mode == 'Sea'){
-                $Sealist = common::excuteListSql("select * from public.online_order_status_date_kpi_new('$type'::text,'$sqlWhere'::text) "
-                    . "r (c bigint, d text)");
-                //拼接数据     
-                if(empty($list)){
-                    $list = $Sealist;
-                }else{
-                    foreach($list as $lk =>$lv){
-                        $list[$lk]['c'] = $list[$lk]['c'] + $Sealist[$lk]['c'];
-                    }
-                }     
-            }
-            if($mode == 'Air'){
-                //暂时查询空数据
-                $sqlWhere_air = $sqlWhere ." and 1<>1 ";
-                //拼接的date_start数据
-                //todo 根据权限信息获取一共air查询的总表的整合,因为air信息是分别存在public 和sfs 两个模式中的
-                // $air_view = "";
-                // $air_sql = common::getAirSql($air_view,$type,$sql_where);
-                // $Airlist = common::excuteListSql("select count as c, distext as d from ($air_sql) aa ");
-                $Airlist = common::excuteListSql("select * from public.online_order_status_date_kpi_new('$type'::text,'$sqlWhere_air'::text) "
-                    . "r (c bigint, d text)");
-                //拼接数据     
-                if(empty($list)){
-                    $list = $Airlist;
-                }else{
-                    foreach($list as $lk =>$lv){
-                        $list[$lk]['c'] = $list[$lk]['c'] + $Airlist[$lk]['c'];
-                    }
-                }       
-            }
-            if($mode == 'Road'){
-                $sqlWhere_road = $sqlWhere ." and 1<>1 ";
-                //拼接的date_start数据  road 没有数据  可以置为1<>1
-                //todo 根据权限信息获取一共air查询的总表的整合,因为air信息是分别存在sspublic 和sfs 两个模式中的
-                // $air_view = "";
-                // $air_sql = common::getAirSql($air_view,$type,$sql_where);
-                // $Airlist = common::excuteListSql("select count as c, distext as d from ($air_sql) aa ");
-                $roadlist = common::excuteListSql("select * from public.online_order_status_date_kpi_new('$type'::text,'$sqlWhere_road'::text) "
-                 . "r (c bigint, d text)");  
-                //拼接数据     
-                if(empty($list)){
-                    $list = $roadlist;
-                }else{
-                    foreach($list as $lk =>$lv){
-                        $list[$lk]['c'] = $list[$lk]['c'] + $roadlist[$lk]['c'];
-                    }
-                }       
-            }
-        }
-         
+        $list = common::excuteListSql("select * from public.online_order_status_date_kln_kpi('$type'::text,'$sqlWhere'::text) "
+                . "r (c bigint, d text)");
+    
         $key = "[";
         $value = "[";
         $totalValue = 0;
@@ -640,32 +471,56 @@ switch ($action) {
         exit();
         break;
     case 'main_map_new':
-        //include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
+        include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
         //修改添加port_of_transshipment 和port_of_transshipment_name的坐标获取(有为空的可能)
         $serial_no = $_REQUEST["serial_no"];
+        $_schemas = $_REQUEST['_schemas'];
+        if(empty($_schemas)){
+            $_schemas ="public";
+        }
         //$serial_no = "F41E6016-1A97-4C93-8198-53D8B3B26220";
-        $sql = "with ss as (select '$serial_no' as sn)
-                , aa as (
-                    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.*
-                        from public.online_ocean oo 
-                        left join LATERAL (
-                            select (select uncode from ports where  code = o.port_of_transshipment) as port_of_transshipment_un,
-                                    port_of_transshipment_name
-                                from  ocean o where o.serial_no=oo.serial_no order by id desc limit 1
-                        ) dd on true
-                        where serial_no=(select sn from ss) limit 1
+        $transport_mode = common::excuteOneSql("SELECT transport_mode FROM public.kln_ocean ko 
+                    WHERE ko.serial_no = '$serial_no' and order_from = '$_schemas'");
+        if($transport_mode == "sea"){
+            $sql = "with ss as (select '$serial_no' as sn)
+            , aa as (
+                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.*
+                    from public.online_ocean oo 
+                    left join LATERAL (
+                        select (select uncode from ports where  code = o.port_of_transshipment) as port_of_transshipment_un,
+                                port_of_transshipment_name
+                            from  $_schemas.ocean o where o.serial_no=oo.serial_no order by id desc limit 1
+                    ) dd on true
+                    where serial_no=(select sn from ss) limit 1
+            )
+            , rr as (
+                    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 
+                        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
+                    union all
+                    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 
+                        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
+                    union all
+                    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 
+                        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
+                )
+            select * from rr order by sort, stime";
+        } elseif ($transport_mode == "air"){
+            $sql = "with ss as (select '$serial_no' as sn)
+            , aa as (
+                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
+            )
+            , rr as (
+                    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 
+                        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
+                    union all
+                    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 
+                        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
                 )
-                , rr as (
-                        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 
-                            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
-                        union all
-                        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 
-                            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
-                        union all
-                        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 
-                            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
-                    )
             select * from rr order by sort, stime";
+        }
+        
         $rss = common::excuteListSql($sql);
         //$rss = $mapdb->GetAll($sql);
         //先固定死
@@ -673,31 +528,31 @@ switch ($action) {
         //           {"lng":"100.88333333","lat":"13.08333333","label":"Destination","infor":"LAEM CHABANG PORT,THAILAND","sort":"1","stime":null,"ptype":"pol"},
         //           {"lng":"-122.28640000","lat":"37.79784000","label":"Transfer","infor":"OAKLAND, CA, USA","sort":"2","stime":null,"ptype":"pod"}]';
         //$rss = json_decode($json,true);
-        // global $mapdb;
-        // //查询线(包含所有的线)
-        // error_log("select * from get_track_data('$serial_no',true)");
-        // $map_sql = "select * from get_track_data('$serial_no',true)";
-        // $Line = $mapdb->GetAll($map_sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $map_sql), 0));
+        global $mapdb;
+        //查询线(包含所有的线)
+        error_log("select * from get_track_data('$serial_no',true)");
+        $map_sql = "select * from get_track_data('$serial_no',true)";
+        $Line = $mapdb->GetAll($map_sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $map_sql), 0));
 
-        // $solidLine = array();
-        // $dottedLine = array();
-        // $rangePoint = array();
-        // foreach($Line as $line){
-        //     if($line['tp'] == "1"){
-        //         $solidLine[] = $line;
-        //     }elseif($line['tp'] == "0"){
-        //         $dottedLine[] = $line;
-        //     }else{
-        //         $rangePoint[] = $line;
-        //     }
-        // }
-        // //如果没有虚线,这这个范围点也是异常的,不需要显示
-        // if(empty($dottedLine)){
-        //     $rangePoint = array();
-        // }
-        // $data = array("point"=>$rss,"solidLine"=>$solidLine,"dottedLine"=>$dottedLine,"rangePoint"=>$rangePoint);
-        // common::echo_json_encode(200, $data);
-        common::echo_json_encode(200, $rss);
+        $solidLine = array();
+        $dottedLine = array();
+        $rangePoint = array();
+        foreach($Line as $line){
+            if($line['tp'] == "1"){
+                $solidLine[] = $line;
+            }elseif($line['tp'] == "0"){
+                $dottedLine[] = $line;
+            }else{
+                $rangePoint[] = $line;
+            }
+        }
+        //如果没有虚线,这这个范围点也是异常的,不需要显示
+        if(empty($dottedLine)){
+            $rangePoint = array();
+        }
+        $data = array("point"=>$rss,"solidLine"=>$solidLine,"dottedLine"=>$dottedLine,"rangePoint"=>$rangePoint);
+        common::echo_json_encode(200, $data);
+        //common::echo_json_encode(200, $rss);
         exit();
         break;
     case 'main_welcome':
@@ -706,20 +561,9 @@ switch ($action) {
         if (empty($ps))
             $ps = 10;
 
-        $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
-        $transportation = $_REQUEST["transportation"];
-        if(!is_array($transportation)){
-            $transportation = array($transportation);
-        }
-
-        $list = array();
-        if(count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
-            $transportation = array("Sea","Air","Road");         
-        }else{
-            if(!in_array("Sea",$transportation)){
-                $sqlWhere .= " and 1<>1 ";
-            }
-        }
+        $sqlWhere = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
+        $sqlWhere .= common::getDashboardTransportationSqlWhere();
+        
         // test dome 
         // $_POST['is_default'] = "no";
         // $_POST['date_start'] =null;
@@ -741,58 +585,73 @@ switch ($action) {
 
         $rc = $_POST ['rc'];
         if ($rc == - 1) {
-            $sql = "SELECT count(1) from public.online_ocean" . $sqlWhere ." and last_status_315_update_time is not null";
+            $sql = "SELECT count(1) from public.kln_ocean" . $sqlWhere;
             $rc = common::excuteOneSql($sql);
-            //error_log($sql);
         }
         $tp = ceil($rc / $ps);
         if ($rc > 0) {
-            $sql = "SELECT order_from as _schemas,serial_no,last_status_city, consignee, shipper, h_bol,final_desination_uncode, 
-                    to_char(etd, 'MM/DD/YYYY'::text) as etd, to_char(eta, 'MM/DD/YYYY'::text) AS eta, 
-                    fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un, ctnrs, count_cntr, last_status_ctnr,booking_no,
-                    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,
-                    f_vessel,f_voyage,
-                    CASE
-	    	            WHEN dd.status is null THEN 'Created'::text
-	    	            ELSE dd.status::text
-		            END AS new_status,
-                    dd.act_date,dd.act_time,dd.description,
-                    dd.timezone,dd.code as dd_code
-                    FROM public.online_ocean
-                    left join LATERAL (select case when a.code='IFFBCF' then 'Created'
-                                    when a.code='IFFCPU' then 'Cargo Received'
-                                    when a.code='IFFREC' then 'Cargo Received'
-                                    when a.code='IFFDEP' then 'Departure'
-                                    when a.code='IFFARR' then 'Arrived'
-                                    when a.code='IFFDEL' then 'Completed'
-                                    else 'Created' END as status,
-                                    act_date,act_time,
-                                    _dd.description as description,
-                                    timezone,code
-                            from  public.ocean_milestone a 
-                                left join LATERAL (select sno,description  from  milestone where code=a.code and project_no = '*'  order by sno limit 1) _dd on true
-                    where a.serial_no=online_ocean.serial_no 
-                        and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFDEL', ','))
-                        and a.act_date is not null
-                    order by id desc limit 1) dd on true 
-                    $sqlWhere  and last_status_315_update_time is not null";
-            if (_isDemo()) {
-                $sql .= " ORDER BY eta DESC limit " . $ps . " offset " . ($cp - 1) * $ps;
-            } else {
-                $sql .= " ORDER BY last_status_315_update_time DESC limit " . $ps . " offset " . ($cp - 1) * $ps;
-            }
+            $sql = "SELECT order_from as _schemas,serial_no, consignee, shipper, h_bol,final_desination_uncode, transport_mode,
+                        to_char(etd, 'MM/DD/YYYY'::text) as etd,
+                        to_char(eta, 'MM/DD/YYYY'::text) AS eta, 
+                        fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un, booking_no,
+                        f_vessel,f_voyage,origin,
+                        CASE
+                            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
+                            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
+                            WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
+                            WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
+                            WHEN (m_iffdel is not null) THEN 'Completed'::text
+                            ELSE 'Created'::text
+                        END AS new_status
+                    FROM public.kln_ocean $sqlWhere";
+            //$sqlWhere  and last_status_315_update_time is not null";
+            $sql .= " ORDER BY eta DESC limit " . $ps . " offset " . ($cp - 1) * $ps;
+            //$sql .= " ORDER BY last_status_315_update_time DESC limit " . $ps . " offset " . ($cp - 1) * $ps;
             $rss = common::excuteListSql($sql);
             //RecentStatusList
             $RecentStatusList = array();
             foreach ($rss as $key => $value) {
+                $serial_no = $value["serial_no"];
+                $_schemas_bk = $value['_schemas'];
                 $_schemas = $value['_schemas'];
                 if($_schemas == "public"){
                     $_schemas = "ocean";
                 }
+
+                //单独取查询milestone信息
+                if ($value['transport_mode'] == "sea"){
+                    $milestone_sql = "select a.act_date,a.act_time,sn.description,a.timezone,
+                                a.code as dd_code
+                            from  public.ocean_milestone a 
+                                inner join public.customer_service_milestone_sno sn on sn.code=a.code
+                        where a.serial_no='$serial_no' 
+                            and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFDEL', ','))
+                            and a.act_date is not null
+                        order by sn.sno desc limit 1";
+                } elseif ($value['transport_mode'] == "air"){
+                    //air milestone 的Departed实际描述要替换: IFFDEP =》 IFFONB 
+                    $milestone_sql = "select a.act_date,a.act_time,sn.description,a.timezone,
+                            case when a.code = 'IFFONB' then 'IFFDEP'
+                                 else  a.code 
+                            end as dd_code
+                        from  $_schemas_bk.air_milestone a 
+                            inner join public.customer_service_milestone_sno sn on sn.code=a.code
+                    where a.serial_no='$serial_no' 
+                        and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFONB,IFFARR,IFFDEL', ','))
+                        and a.act_date is not null
+                    order by sn.sno desc limit 1";
+                }
+                $milestone = common::excuteObjectSql($milestone_sql);
+                $value["act_date"] = $milestone["act_date"];
+                $value["act_time"] = $milestone["act_time"];
+                $value["description"] = $milestone["description"];
+                $value["timezone"] = $milestone["timezone"];
+                $value["dd_code"] = $milestone["dd_code"];
+
                 $timezone = "";
                 //按照最新execl Timezone From 来自于origin 
                 if($value['dd_code'] == "IFFBCF" || $value['dd_code'] == "IFFCPU"){
-                    $sql = "SELECT (select time_zone from public.city_timezone where uncode = LEFT(country, 2) || COALESCE(city_code,'')) as timezone
+                    $sql = "SELECT (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'')) as timezone
                          FROM $_schemas.contacts c WHERE  c.contact_id = '".$value['origin']."'";
                     $timezone = common::excuteOneSql($sql);     
                 }
@@ -803,9 +662,11 @@ switch ($action) {
                 }
 
                 if($value['dd_code'] == "IFFREC" || $value['dd_code'] == "IFFDEP" || $value['dd_code'] == "IFFARR"){
-                    //Timezone From 来自于EDI315
-                    $serial_no = $value["serial_no"];
-                    $EDI315Time = common::getEDI315Time($serial_no,$value['_schemas']);
+                    $EDI315Time = array();
+                    if ($value['transport_mode'] == "sea"){
+                        //Timezone From 来自于EDI315
+                        $EDI315Time = common::getEDI315Time($serial_no,$value['_schemas']);
+                    }
 
                     if($value['dd_code'] == "IFFREC" || $value['dd_code'] == "IFFDEP"){
                         //先以EDI315 时区为准,如果没有这代表数据是手动输入,或者没有同步情况
@@ -854,6 +715,7 @@ switch ($action) {
                     "act_time" =>$value["act_time"],
                     "timezone"=>$timezone,
                     "_schemas"=>$value["_schemas"],
+                    "transport_mode"=>$value["transport_mode"],
                     "a" =>common::deCode($value['serial_no'], 'E'));
             }
             $data  = common::getManagement();

+ 41 - 48
service/ajax.class.php

@@ -114,7 +114,7 @@ class ajax {
             $str = $search_field_mapping[$_search_field];
             $sql_where = $sql_where_mapping[$_search_field];
 
-            $table = $search_mode == "tracking" ? "public.online_ocean " : "public.online_booking ";
+            $table = $search_mode == "tracking" ? "public.kln_ocean " : "public.kln_booking ";
 
             if($search_mode == "booking"){
                 $order_by = " f_etd desc NULLS LAST";
@@ -317,7 +317,7 @@ class ajax {
     }
 
     public function getTrackingSearchWhere(){
-        $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
+        $sqlWhere = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
         $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
         
         if (!empty($_REQUEST["_reportRef"])) {
@@ -422,47 +422,40 @@ class ajax {
                 }
             }
         }
-                //处理reference类型的组合查询  Search booking No./HBL No./PO No./Carrier Booking No.
+        //处理reference类型的组合查询  Search booking No./HBL No./PO No./Carrier Booking No.
         if (!empty($_POST["_textSearch"])) {
             $textSearch_arr = $_POST['_textSearch'];
             if(!is_array($textSearch_arr)){
+                $textSearch_arr = str_replace(",", ";", $textSearch_arr);
                 $textSearch_arr = array($textSearch_arr);
             }
-            $more_sql = "1<>1";
-            foreach($textSearch_arr as $tsv){
-                $more_sql .= " or  booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
-                $more_sql .= " or  h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
-                $more_sql .= " or  po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
-                $more_sql .= " or  carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
-            }
-            if ($more_sql <> "1<>1"){
-                $sqlWhere .= " and ($more_sql)";
-            } 
+            $more_param = common::getInNotInSqlForSearch(strtolower(implode(';',$textSearch_arr)));
+            //$sqlWhere .= " and (ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking),lower(tracking_no)],''))";
+            $sqlWhere .= " and ((ARRAY[$more_param] && array_append(ARRAY[lower(booking_no::text), lower(h_bol::text), lower(m_bol), lower(carrier_booking), lower(quote_no), lower(tracking_no)]||string_to_array(lower(ctnrs),','), ''::text))
+                or lower(po_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%'
+                or lower(invoice_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%')";
         }
         return $sqlWhere;
     }
 
     public function getBookingSearchWhere(){
-        $sqlWhere = ' where ' . common::searchExtendHandNew("booking", $_SESSION["ONLINE_USER"]);
+        $sqlWhere = ' where ' . common::searchExtendHand_KLN("booking", $_SESSION["ONLINE_USER"]);
         $sqlWhere .= search::getInstance()->getSearchSQL("Booking_Search");
-        //新版要排除type2情况,总数才会对的上
-        $sqlWhere .= " and (not(bol_type != 'BOOKING' and booking_no is not null and booking_no <> ''))";
+
+        //移除掉全文检索 但保留代码
+        // if (!empty($_POST["_textSearch"])) {
+        //     $sqlWhere .= " and text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))";
+        // }
         //处理reference类型的组合查询  Search booking No./HBL No./PO No./Carrier Booking No.
         if (!empty($_POST["_textSearch"])) {
             $textSearch_arr = $_POST['_textSearch'];
             if(!is_array($textSearch_arr)){
+                $textSearch_arr = str_replace(",", ";", $textSearch_arr);
                 $textSearch_arr = array($textSearch_arr);
             }
-            $more_sql = "1<>1";
-            foreach($textSearch_arr as $tsv){
-                $more_sql .= " or  booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
-                $more_sql .= " or  h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
-                $more_sql .= " or  po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
-                $more_sql .= " or  carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
-            }
-            if ($more_sql <> "1<>1"){
-                $sqlWhere .= " and ($more_sql)";
-            } 
+            $more_param = common::getInNotInSqlForSearch(strtolower(implode(';',$textSearch_arr)));
+            $sqlWhere .= " and ((ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking)],''))
+                or lower(po_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%')"; 
         } 
         return $sqlWhere;
     }
@@ -472,13 +465,13 @@ class ajax {
         if($search_field == "Origin" && $search_mode == "booking"){
             $sqlWhere = $this->getBookingSearchWhere();
             $count_sql = "select COUNT(DISTINCT shipper_city)
-                from public.online_booking $sqlWhere 
+                from public.kln_booking $sqlWhere 
                     and COALESCE(shippr_uncode,'')<>''
                     and  (shipper_city ilike '%" . common::check_input($term) . "%' 
                     or shippr_uncode ilike '%" . common::check_input($term) . "%') ";
 
             $sql = "select left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode 
-                from public.online_booking $sqlWhere 
+                from public.kln_booking $sqlWhere 
                     and COALESCE(shippr_uncode,'')<>''
                     and  (shipper_city ilike '%" . common::check_input($term) . "%' 
                     or shippr_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc NULLS LAST";
@@ -488,13 +481,13 @@ class ajax {
         if($search_field == "Destination" && $search_mode == "booking"){
             $sqlWhere = $this->getBookingSearchWhere();
             $count_sql = "select count(DISTINCT consignee_city)
-                from public.online_booking $sqlWhere
+                from public.kln_booking $sqlWhere
                     and COALESCE(consignee_uncode,'')<>'' 
                     and  (consignee_city ilike '%" . common::check_input($term) . "%' 
                     or consignee_uncode ilike '%" . common::check_input($term) . "%') ";
 
             $sql = "select left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode 
-                from public.online_booking $sqlWhere
+                from public.kln_booking $sqlWhere
                     and COALESCE(consignee_uncode,'')<>'' 
                     and  (consignee_city ilike '%" . common::check_input($term) . "%' 
                     or consignee_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc NULLS LAST";
@@ -504,13 +497,13 @@ class ajax {
         if($search_field == "Place of Receipt" && $search_mode == "booking"){
             $sqlWhere = $this->getBookingSearchWhere();
             $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
-                from public.online_booking $sqlWhere
+                from public.kln_booking $sqlWhere
                     and COALESCE(place_of_receipt_uncode,'')<>'' 
                     and  (place_of_receipt_exp ilike '%" . common::check_input($term) . "%' 
                     or place_of_receipt_uncode ilike '%" . common::check_input($term) . "%')";
 
             $sql = "select left(place_of_receipt_uncode, 2) as country,place_of_receipt_exp as city, place_of_receipt_uncode as uncode 
-                from public.online_booking $sqlWhere
+                from public.kln_booking $sqlWhere
                     and COALESCE(place_of_receipt_uncode,'')<>'' 
                     and  (place_of_receipt_exp ilike '%" . common::check_input($term) . "%' 
                     or place_of_receipt_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc NULLS LAST";
@@ -520,13 +513,13 @@ class ajax {
         if($search_field == "Port of Loading" && $search_mode == "booking"){
             $sqlWhere = $this->getBookingSearchWhere();
             $count_sql = "select COUNT(DISTINCT fport_of_loading_exp)
-                from public.online_booking $sqlWhere
+                from public.kln_booking $sqlWhere
                     and COALESCE(fport_of_loading_uncode,'')<>''  
                     and  (fport_of_loading_exp ilike '%" . common::check_input($term) . "%' 
                     or fport_of_loading_uncode ilike '%" . common::check_input($term) . "%')";
             
             $sql = "select left(fport_of_loading_uncode, 2) as country,fport_of_loading_exp as city, fport_of_loading_uncode as uncode 
-                from public.online_booking $sqlWhere
+                from public.kln_booking $sqlWhere
                     and COALESCE(fport_of_loading_uncode,'')<>'' 
                     and  (fport_of_loading_exp ilike '%" . common::check_input($term) . "%' 
                     or fport_of_loading_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc NULLS LAST";
@@ -536,13 +529,13 @@ class ajax {
         if($search_field == "Place of delivery" && $search_mode == "booking"){
             $sqlWhere = $this->getBookingSearchWhere();
             $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
-                from public.online_booking $sqlWhere
+                from public.kln_booking $sqlWhere
                     and COALESCE(place_of_delivery_uncode,'')<>'' 
                     and  (place_of_delivery_exp ilike '%" . common::check_input($term) . "%' 
                     or place_of_delivery_uncode ilike '%" . common::check_input($term) . "%')";
 
             $sql = "select left(place_of_delivery_uncode, 2) as country,place_of_delivery_exp as city, place_of_delivery_uncode as uncode
-                from public.online_booking $sqlWhere
+                from public.kln_booking $sqlWhere
                     and COALESCE(place_of_delivery_uncode,'')<>'' 
                     and  (place_of_delivery_exp ilike '%" . common::check_input($term) . "%' 
                     or place_of_delivery_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc NULLS LAST";
@@ -558,13 +551,13 @@ class ajax {
         if($search_field == "Origin" && $search_mode == "tracking"){
             $sqlWhere = $this->getTrackingSearchWhere();
             $count_sql = "select COUNT(DISTINCT shipper_city)
-                from public.online_ocean $sqlWhere
+                from public.kln_ocean $sqlWhere
                     and COALESCE(shippr_uncode,'')<>'' 
                     and  (shipper_city ilike '%" . common::check_input($term) . "%' 
                     or shippr_uncode ilike '%" . common::check_input($term) . "%')";
 
             $sql = "select left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
-                from public.online_ocean $sqlWhere
+                from public.kln_ocean $sqlWhere
                     and COALESCE(shippr_uncode,'')<>'' 
                     and  (shipper_city ilike '%" . common::check_input($term) . "%' 
                     or shippr_uncode ilike '%" . common::check_input($term) . "%') order by $order_by";
@@ -574,13 +567,13 @@ class ajax {
         if($search_field == "Destination" && $search_mode == "tracking"){
             $sqlWhere = $this->getTrackingSearchWhere();
             $count_sql = "select COUNT(DISTINCT consignee_city)
-                from public.online_ocean $sqlWhere
+                from public.kln_ocean $sqlWhere
                     and COALESCE(consignee_uncode,'')<>'' 
                     and  (consignee_city ilike '%" . common::check_input($term) . "%' 
                     or consignee_uncode ilike '%" . common::check_input($term) . "%')";
 
             $sql = "select left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
-                from public.online_ocean $sqlWhere
+                from public.kln_ocean $sqlWhere
                     and COALESCE(consignee_uncode,'')<>'' 
                     and  (consignee_city ilike '%" . common::check_input($term) . "%' 
                     or consignee_uncode ilike '%" . common::check_input($term) . "%') order by $order_by";
@@ -590,13 +583,13 @@ class ajax {
         if($search_field == "Place of Receipt" && $search_mode == "tracking"){
             $sqlWhere = $this->getTrackingSearchWhere();
             $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
-                from public.online_ocean $sqlWhere
+                from public.kln_ocean $sqlWhere
                     and COALESCE(place_of_receipt_un,'')<>'' 
                     and  (place_of_receipt_exp ilike '%" . common::check_input($term) . "%' 
                     or place_of_receipt_un ilike '%" . common::check_input($term) . "%')";
 
             $sql = "select left(place_of_receipt_un, 2) as country,place_of_receipt_exp as city, place_of_receipt_un as uncode
-                from public.online_ocean $sqlWhere
+                from public.kln_ocean $sqlWhere
                     and COALESCE(place_of_receipt_un,'')<>'' 
                     and  (place_of_receipt_exp ilike '%" . common::check_input($term) . "%' 
                     or place_of_receipt_un ilike '%" . common::check_input($term) . "%') order by $order_by";
@@ -606,13 +599,13 @@ class ajax {
         if($search_field == "Port of Loading" && $search_mode == "tracking"){
             $sqlWhere = $this->getTrackingSearchWhere();
             $count_sql = "select COUNT(DISTINCT port_of_loading)
-                from public.online_ocean $sqlWhere 
+                from public.kln_ocean $sqlWhere 
                     and COALESCE(fport_of_loading_un,'')<>''
                     and  (port_of_loading ilike '%" . common::check_input($term) . "%' 
                     or fport_of_loading_un ilike '%" . common::check_input($term) . "%')";
 
             $sql = "select left(fport_of_loading_un, 2) as country,port_of_loading as city, fport_of_loading_un as uncode
-                from public.online_ocean $sqlWhere
+                from public.kln_ocean $sqlWhere
                     and COALESCE(fport_of_loading_un,'')<>'' 
                     and  (port_of_loading ilike '%" . common::check_input($term) . "%' 
                     or fport_of_loading_un ilike '%" . common::check_input($term) . "%') order by $order_by";
@@ -622,13 +615,13 @@ class ajax {
         if($search_field == "Place of Discharge" && $search_mode == "tracking"){
             $sqlWhere = $this->getTrackingSearchWhere();
             $count_sql = "select COUNT(DISTINCT port_of_discharge)
-                from public.online_ocean $sqlWhere
+                from public.kln_ocean $sqlWhere
                     and COALESCE(mport_of_discharge_un,'')<>'' 
                     and  (port_of_discharge ilike '%" . common::check_input($term) . "%' 
                     or mport_of_discharge_un ilike '%" . common::check_input($term) . "%')";
 
             $sql = "select  left(mport_of_discharge_un, 2) as country,port_of_discharge as city, mport_of_discharge_un as uncode
-                from public.online_ocean $sqlWhere 
+                from public.kln_ocean $sqlWhere 
                     and COALESCE(mport_of_discharge_un,'')<>''
                     and  (port_of_discharge ilike '%" . common::check_input($term) . "%' 
                     or mport_of_discharge_un ilike '%" . common::check_input($term) . "%') order by $order_by";
@@ -638,13 +631,13 @@ class ajax {
         if($search_field == "Place of delivery" && $search_mode == "tracking"){
             $sqlWhere = $this->getTrackingSearchWhere();
             $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
-                from public.online_ocean $sqlWhere
+                from public.kln_ocean $sqlWhere
                     and COALESCE(place_of_delivery_un,'')<>'' 
                     and  (place_of_delivery_exp ilike '%" . common::check_input($term) . "%' 
                     or place_of_delivery_un ilike '%" . common::check_input($term) . "%')";
 
             $sql = "select left(place_of_delivery_un, 2) as country,place_of_delivery_exp as city, place_of_delivery_un as uncode
-                from public.online_ocean $sqlWhere
+                from public.kln_ocean $sqlWhere
                     and COALESCE(place_of_delivery_un,'')<>'' 
                     and  (place_of_delivery_exp ilike '%" . common::check_input($term) . "%' 
                     or place_of_delivery_un ilike '%" . common::check_input($term) . "%') order by $order_by";

+ 120 - 184
service/login.class.php

@@ -1158,7 +1158,7 @@ class login {
             exit();
         }else{
             $reference_number_lower = strtolower($reference_number);
-            $online_ocean_sql = "select serial_no,order_from from online_ocean 
+            $online_ocean_sql = "select serial_no,order_from from kln_ocean 
                 where ((ARRAY['$reference_number_lower'] && array_append(ARRAY[lower(booking_no::text), lower(h_bol::text), lower(m_bol), lower(carrier_booking), lower(quote_no), lower(tracking_no)]||string_to_array(lower(ctnrs),','), ''::text))
                     or lower(po_no) like '%$reference_number_lower%'
                     or lower(invoice_no) like '%$reference_number_lower%')";
@@ -1168,7 +1168,7 @@ class login {
             }elseif(!empty($online_ocean_arr) && count($online_ocean_arr) > 1){
                 $data = array("msg" =>"Multiple results");
             }else{
-                $data =  $this->getTrackingInfo($online_ocean_arr[0]["serial_no"],$online_ocean_arr[0]["order_from"]);
+                $data =  $this->getTrackingInfo($online_ocean_arr[0]["serial_no"],$online_ocean_arr[0]["order_from"]);  
             }
             common::echo_json_encode(200, $data);
             //记录查询log情况
@@ -1236,26 +1236,28 @@ class login {
         }
 
         $ocean = $ocean_arr[0];
-        //获取对应uncode 对应的时间
-        $uncodes = $ocean['fport_of_loading_un'].";".$ocean['mport_of_discharge_un'];
-        $codeinfo = common::getCityPortsInfo($uncodes);
-
         //处理transportInfo信息数据
-        $transportInfo = array("Tracking No." =>$ocean['_tracking_no'],"status"=>$ocean['new_status'],"mode" => "Ocean Freight",
+        $transportInfo = array("Tracking No." =>$ocean['tracking_no'],"status"=>$ocean['new_status'],
+            "mode" => $ocean['transport_mode'] == 'sea' ? "Ocean Freight" : ($ocean['transport_mode'] == 'air' ? "Air Freight": ""),
             "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
-            "etd" =>$ocean['f_etd'],"atd" =>$ocean['atd'],
-            "etd_timezone" =>$codeinfo[$ocean['fport_of_loading_un']],
-            "atd_timezone" =>$codeinfo[$ocean['fport_of_loading_un']],
-            "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
-            "eta_timezone" =>$codeinfo[$ocean['mport_of_discharge_un']],
-            "ata_timezone" =>$codeinfo[$ocean['mport_of_discharge_un']]);
+            "etd" =>$ocean['etd'],"atd" =>$ocean['atd'],
+            "etd_timezone" =>$ocean['pol_timezone'],
+            "atd_timezone" =>$ocean['pol_timezone'],
+            "eta" =>$ocean['eta'],"ata" =>$ocean['ata'],
+            "eta_timezone" =>$ocean['mpod_timezone'],
+            "ata_timezone" =>$ocean['mpod_timezone']);
         $data['transportInfo'] = $transportInfo;
 
         //处理basicInfo信息数据
-        $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
-        $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
+        if($ocean['transport_mode'] == "sea"){
+            $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
+            $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
+        } elseif ($ocean['transport_mode'] == "air"){
+            $vessel = $ocean['vessel'];
+            $voyage = $ocean['voyage'];
+        }
         $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['booking_no'],
-            "PO_NO" =>$ocean['_po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
+            "PO_NO" =>$ocean['po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
             "Incoterm" =>$ocean['incoterms'],"Service_Type" =>$ocean['service']);
 
         //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
@@ -1277,89 +1279,100 @@ class login {
         //处理marksAndDescription
         $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description']);
         
-        $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . " ,net_lbs from oc_container where lower(serial_no) = '" . strtolower($ocean['serial_no']) . "'";
-        $rss = common::excuteListSql($sql);
-
-        $quantity_unit = array();
-        $g_weight_tolal = 0;
-        $ch_weight_tolal = 0;
-        $ch_weight_tolal_grs_lbs = 0;
-        $cbm_tolal = 0;
-        foreach ($rss as $key => $rs) {
-            $unit = $rs['unit'];
-            if (array_key_exists($unit, $quantity_unit)) {
-                $quantity_unit[$unit] = $quantity_unit[$unit] + $rs['qty'];
-            } else {
-                $quantity_unit[$unit] =  $rs['qty'];
+        if($ocean['transport_mode'] == "sea"){
+            $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . " ,net_lbs from oc_container where lower(serial_no) = '" . strtolower($ocean['serial_no']) . "'";
+            $rss = common::excuteListSql($sql);
+
+            $quantity_unit = array();
+            $g_weight_tolal = 0;
+            $ch_weight_tolal = 0;
+            $ch_weight_tolal_grs_lbs = 0;
+            $cbm_tolal = 0;
+            foreach ($rss as $key => $rs) {
+                $unit = $rs['unit'];
+                if (array_key_exists($unit, $quantity_unit)) {
+                    $quantity_unit[$unit] = $quantity_unit[$unit] + $rs['qty'];
+                } else {
+                    $quantity_unit[$unit] =  $rs['qty'];
+                }
+                $g_weight_tolal += $rs['grs_kgs'];
+                $ch_weight_tolal += $rs['net_lbs'];
+                $ch_weight_tolal_grs_lbs += $rs['grs_lbs'];
+                $cbm_tolal += $rs['cbm'];
             }
-            $g_weight_tolal += $rs['grs_kgs'];
-            $ch_weight_tolal += $rs['net_lbs'];
-            $ch_weight_tolal_grs_lbs += $rs['grs_lbs'];
-            $cbm_tolal += $rs['cbm'];
-        }
-        $quantity_tolal = "";
-        foreach($quantity_unit as $uk => $uv){
-            $quantity_tolal.=$uv." ".$uk." ";
+            $quantity_tolal = "";
+            foreach($quantity_unit as $uk => $uv){
+                $quantity_tolal.=$uv." ".$uk." ";
+            }
+            $ch_weight_tolal = empty($ch_weight_tolal) ? $ch_weight_tolal_grs_lbs : $ch_weight_tolal;
+            //Packing 不确定信息
+            $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $ch_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
+        } elseif ($ocean['transport_mode'] == "air"){
+            $quantity_tolal = empty($ocean['qty']) ? "" : $ocean['qty'].$ocean['qty_uom'];
+            $g_weight_tolal = empty($ocean['piece_count']) ? "" : sprintf("%.3f", $ocean['piece_count'])." KGS";
+            $ch_weight_tolal = empty($ocean['piece_count']) ? "": sprintf("%.3f", $ocean['weight'])." KGS";
+            $cbm_tolal = empty($ocean['cbm']) ? "" : sprintf("%.4f", $ocean['cbm'])." CBM";
+            //Packing信息
+            $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal,"Ch. Weight" => $ch_weight_tolal,"Volume" => $cbm_tolal);
         }
-        $ch_weight_tolal = empty($ch_weight_tolal) ? $ch_weight_tolal_grs_lbs : $ch_weight_tolal;
-        //Packing 不确定信息
-        $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $ch_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
 
         /* Container Status */
-        //数据库里配置好
-        //$sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container_Status') . " from oc_container_v where lower(serial_no) = '" . strtolower($serial_no) . "'";
-        $serial_no = $ocean["serial_no"];
-        $ctnr_sql = "SELECT oc.ctnr, oc.serial_no,oc.size FROM oc_container oc LEFT JOIN ocean o ON oc.serial_no = o.serial_no 
-                WHERE o.serial_no='$serial_no'";
-        $ctnr_data = common::excuteListSql($ctnr_sql); 
-        foreach ($ctnr_data as $cd){
-            //存在柜号为空的数据情况
-            if(empty($cd['ctnr'])){
-                continue;
-            }
-            $ctnr_status_sql = "select s.source_id, s.event_base as event,
-                    to_char(to_timestamp(s.event_date, 'YYYYMMDD'), 'YYYY-MM-DD') as eventdate,
-                    to_char(to_timestamp(s.event_time, 'HH24MI'), 'HH24:MI') as eventtime,
-                    e.description,s.event_type as eventtype, 
-                    s.event_code as eventcode, s.event_city as eventcity,
-                    (select time_zone from public.city_timezone where uncode = s.event_code) as timezone,
-                    (select uncity from public.ports where uncode = s.event_code) as uncity,
-                    case when event ='I'  then 'IFFREC'::text
-                        when event ='AE'  then 'IFFONB'::text
-                        when event ='VD'  then 'IFFDEP'::text
-                        when event ='EB' or event ='VA' then 'IFFARR'::text
-                        when event ='UV'  then 'IFFUND'::text
-                        when event ='VA'  then 'IFFAFD'::text
-                        when event ='AV'  then 'IFFCTA'::text
-                        when event ='CT'  then 'IFFICC'::text
-                        when event ='OA' or event ='D'  then 'IFFPPD'::text
-                        when event ='EE'  then 'IFFECP'::text
-                        else '' ::text
-                    end as milestone_code  
-                from public.ra_online_container_status_v s 
-                    left join ra_online_edi_event e on s.event_base = e.ra_name 
-                where s.serial_no = '" . pg_escape_string($cd['serial_no']) . "' 
-                    and s.container_no = '" . pg_escape_string($cd['ctnr']) . "' and is_display = true 
-                order by to_timestamp(s.event_date, 'YYYYMMDD') asc,
-                    to_timestamp(s.event_time, 'HH24MI') asc,e.ra_order asc";
-            $ctnr_status = common::excuteListSql($ctnr_status_sql);       
-            //记录所有的信息
-            $EDI315TimeAndLocation = array();
-            foreach($ctnr_status as $event){
-                if(!empty($EDI315TimeAndLocation['IFFARR']) && $EDI315TimeAndLocation['IFFARR']['code'] == "EB"){
-                    //如果存在EB 的EB 的优先级最高
+        //sea 才有EDI315
+        if($ocean['transport_mode'] == "sea"){
+            $serial_no = $ocean["serial_no"];
+            $ctnr_sql = "SELECT oc.ctnr, oc.serial_no,oc.size FROM oc_container oc LEFT JOIN ocean o ON oc.serial_no = o.serial_no 
+                    WHERE o.serial_no='$serial_no'";
+            $ctnr_data = common::excuteListSql($ctnr_sql); 
+            foreach ($ctnr_data as $cd){
+                //存在柜号为空的数据情况
+                if(empty($cd['ctnr'])){
                     continue;
                 }
-                if(!empty($EDI315TimeAndLocation['IFFPPD']) && $EDI315TimeAndLocation['IFFARR']['code'] == "OA"){
-                    //如果存在OA 的OA 的优先级最高
-                    continue;
+                $ctnr_status_sql = "select s.source_id, s.event_base as event,
+                        to_char(to_timestamp(s.event_date, 'YYYYMMDD'), 'YYYY-MM-DD') as eventdate,
+                        to_char(to_timestamp(s.event_time, 'HH24MI'), 'HH24:MI') as eventtime,
+                        e.description,s.event_type as eventtype, 
+                        s.event_code as eventcode, s.event_city as eventcity,
+                        (select time_zone from public.city_timezone where uncode = s.event_code) as timezone,
+                        (select uncity from public.ports where uncode = s.event_code) as uncity,
+                        case when event ='I'  then 'IFFREC'::text
+                            when event ='AE'  then 'IFFONB'::text
+                            when event ='VD'  then 'IFFDEP'::text
+                            when event ='EB' or event ='VA' then 'IFFARR'::text
+                            when event ='UV'  then 'IFFUND'::text
+                            when event ='VA'  then 'IFFAFD'::text
+                            when event ='AV'  then 'IFFCTA'::text
+                            when event ='CT'  then 'IFFICC'::text
+                            when event ='OA' or event ='D'  then 'IFFPPD'::text
+                            when event ='EE'  then 'IFFECP'::text
+                            else '' ::text
+                        end as milestone_code  
+                    from public.ra_online_container_status_v s 
+                        left join ra_online_edi_event e on s.event_base = e.ra_name 
+                    where s.serial_no = '" . pg_escape_string($cd['serial_no']) . "' 
+                        and s.container_no = '" . pg_escape_string($cd['ctnr']) . "' and is_display = true 
+                    order by to_timestamp(s.event_date, 'YYYYMMDD') asc,
+                        to_timestamp(s.event_time, 'HH24MI') asc,e.ra_order asc";
+                $ctnr_status = common::excuteListSql($ctnr_status_sql);       
+                //记录所有的信息
+                $EDI315TimeAndLocation = array();
+                foreach($ctnr_status as $event){
+                    if(!empty($EDI315TimeAndLocation['IFFARR']) && $EDI315TimeAndLocation['IFFARR']['code'] == "EB"){
+                        //如果存在EB 的EB 的优先级最高
+                        continue;
+                    }
+                    if(!empty($EDI315TimeAndLocation['IFFPPD']) && $EDI315TimeAndLocation['IFFARR']['code'] == "OA"){
+                        //如果存在OA 的OA 的优先级最高
+                        continue;
+                    }
+                    $EDI315TimeAndLocation[$event['milestone_code']] = array("code"=>$event['event'],"timezone"=>$event['timezone'],"location"=>$event['uncity']);
                 }
-                $EDI315TimeAndLocation[$event['milestone_code']] = array("code"=>$event['event'],"timezone"=>$event['timezone'],"location"=>$event['uncity']);
             }
+        }else if ($ocean['transport_mode'] == "air"){
+            $EDI315TimeAndLocation = array();
         }
-
         //Milestones 数据信息待定
-        $Milestones = common::getMilestonesInfo($ocean,$EDI315TimeAndLocation);
+        $Milestones = common::getMilestonesInfo($ocean,$ocean['transport_mode'],$order_from,$EDI315TimeAndLocation);
 
         global $_COPYRIGHT;
         $data = array('transportInfo' => $transportInfo, 
@@ -1373,19 +1386,12 @@ class login {
     }
 
     private function trackingSql($serial_no,$order_from){
-        $public_sql = "with o as(
-            SELECT  o.* from public.ocean o where o.serial_no = '$serial_no'
-        )
-        SELECT m_eta as _m_eta,  h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
-                o.* ,sh.*, cn.* ,aa.*,dd.*,fd.*,oo.*,
-                (select uncode from ports where  code = o.port_of_transshipment) as port_of_transshipment_un
-            from o 
-            LEFT JOIN LATERAL ( SELECT tracking_no as _tracking_no,shippr_uncode,shipper_city,
-                    consignee_uncode,consignee_city,incoterms,
-                    fport_of_loading_un,
-                    mport_of_discharge_un,
-                    place_of_receipt_un,
-                    place_of_delivery_un,
+        $_schemas = $order_from;
+        if($_schemas == 'public'){
+            $_schemas = "ocean";
+        }
+        $sql = "with o as(
+            SELECT  oo.*,m_bol as _m_bol, h_bol as _h_bol,
                     (select time_zone from public.city_timezone where uncode = oo.fport_of_loading_un limit 1) as pol_timezone,
                     (select uncity from public.ports where uncode = oo.fport_of_loading_un limit 1) as pol_uncity,
                     (select time_zone from public.city_timezone where uncode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
@@ -1394,7 +1400,8 @@ class login {
                     (select uncity from public.ports where uncode = oo.place_of_receipt_un limit 1) as por_uncity,
                     (select time_zone from public.city_timezone where uncode = oo.place_of_delivery_un limit 1) as pod_timezone,
                     (select uncity from public.ports where uncode = oo.place_of_delivery_un limit 1) as pod_uncity,
-                    po_no as _po_no,
+                    (select time_zone from public.city_timezone where uncode = oo.final_desination_uncode limit 1) as _fd_timezone,
+                    (select uncity from public.ports where uncode = oo.final_desination_uncode limit 1) as _pd_uncity, 
                     CASE
                         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
                         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
@@ -1403,77 +1410,10 @@ class login {
                         WHEN (m_iffdel is not null) THEN 'Completed'::text
                         ELSE 'Created'::text
                     END AS new_status
-                FROM  public.online_ocean oo WHERE oo.serial_no::text = o.serial_no::text) oo ON true
-            LEFT JOIN LATERAL ( SELECT company as cn_company,
-                address_1 as cn_address_1,
-                address_2 as cn_address_2,
-                address_3 as cn_address_3,
-                address_4 as cn_address_4,
-                city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
-                phone_1 as cn_phone
-            FROM ocean.contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
-            LEFT JOIN LATERAL ( SELECT company as sh_company,
-                address_1 as sh_address_1,
-                address_2 as sh_address_2,
-                address_3 as sh_address_3,
-                address_4 as sh_address_4,
-                city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
-                phone_1 as sh_phone
-            FROM ocean.contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
-            LEFT JOIN LATERAL ( SELECT company as aa_company,
-                address_1 as aa_address_1,
-                address_2 as aa_address_2,
-                address_3 as aa_address_3,
-                address_4 as aa_address_4,
-                city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
-                phone_1 as aa_phone,
-                (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as aa_timezone
-            FROM ocean.contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
-            LEFT JOIN LATERAL ( SELECT company as dd_company,
-                address_1 as dd_address_1,
-                address_2 as dd_address_2,
-                address_3 as dd_address_3,
-                address_4 as dd_address_4,
-                city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
-                phone_1 as dd_phone,
-                (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as dd_timezone
-            FROM ocean.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
-            LEFT JOIN LATERAL ( SELECT 
-                city as fd_city,
-                (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as fd_timezone
-            FROM ocean.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true";
-
-        $sfs_sql = "with o as(
-                SELECT  o.* from sfs.ocean o where o.serial_no = '$serial_no'
+            from public.kln_ocean oo where oo.serial_no = '" . $serial_no . "' and oo.order_from = '$order_from'
         )
-        SELECT m_eta as _m_eta,  h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
-                o.* ,sh.*, cn.* ,aa.*,dd.*,fd.*,oo.*,
-                (select uncode from ports where  code = o.port_of_transshipment) as port_of_transshipment_un
-            from o
-            LEFT JOIN LATERAL ( SELECT tracking_no as _tracking_no,shippr_uncode,shipper_city,
-                    consignee_uncode,consignee_city,incoterms,
-                    fport_of_loading_un,
-                    mport_of_discharge_un,
-                    place_of_receipt_un,
-                    place_of_delivery_un,
-                    (select time_zone from public.city_timezone where uncode = oo.fport_of_loading_un limit 1) as pol_timezone,
-                    (select uncity from public.ports where uncode = oo.fport_of_loading_un limit 1) as pol_uncity,
-                    (select time_zone from public.city_timezone where uncode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
-                    (select uncity from public.ports where uncode = oo.mport_of_discharge_un limit 1) as mpod_uncity,
-                    (select time_zone from public.city_timezone where uncode = oo.place_of_receipt_un limit 1) as por_timezone,
-                    (select uncity from public.ports where uncode = oo.place_of_receipt_un limit 1) as por_uncity,
-                    (select time_zone from public.city_timezone where uncode = oo.place_of_delivery_un limit 1) as pod_timezone,
-                    (select uncity from public.ports where uncode = oo.place_of_delivery_un limit 1) as pod_uncity,
-                    po_no as _po_no,
-                    CASE
-                        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
-                        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
-                        WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
-                        WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
-                        WHEN (m_iffdel is not null) THEN 'Completed'::text
-                        ELSE 'Created'::text
-                    END AS new_status
-                FROM  public.online_ocean oo WHERE oo.serial_no::text = o.serial_no::text) oo ON true
+        SELECT  o.* ,sh.*, cn.*,aa.*,dd.*,fd.*
+        from o
             LEFT JOIN LATERAL ( SELECT company as cn_company,
                 address_1 as cn_address_1,
                 address_2 as cn_address_2,
@@ -1481,7 +1421,7 @@ class login {
                 address_4 as cn_address_4,
                 city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
                 phone_1 as cn_phone
-            FROM sfs.contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
+            FROM $_schemas.contacts c WHERE o.consignee_id::text = c.contact_id::text) cn ON true
             LEFT JOIN LATERAL ( SELECT company as sh_company,
                 address_1 as sh_address_1,
                 address_2 as sh_address_2,
@@ -1489,7 +1429,7 @@ class login {
                 address_4 as sh_address_4,
                 city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
                 phone_1 as sh_phone
-            FROM sfs.contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
+            FROM $_schemas.contacts c WHERE o.shipper_id::text = c.contact_id::text) sh ON true
             LEFT JOIN LATERAL ( SELECT company as aa_company,
                 address_1 as aa_address_1,
                 address_2 as aa_address_2,
@@ -1498,7 +1438,7 @@ class login {
                 city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
                 phone_1 as aa_phone,
                 (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as aa_timezone
-            FROM sfs.contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
+            FROM $_schemas.contacts c WHERE o.origin::text = c.contact_id::text) aa ON true
             LEFT JOIN LATERAL ( SELECT company as dd_company,
                 address_1 as dd_address_1,
                 address_2 as dd_address_2,
@@ -1507,18 +1447,14 @@ class login {
                 city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
                 phone_1 as dd_phone,
                 (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as dd_timezone
-            FROM sfs.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
+            FROM $_schemas.contacts c WHERE o.agent::text = c.contact_id::text) dd ON true
             LEFT JOIN LATERAL ( SELECT 
                 city as fd_city,
                 (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as fd_timezone
-            FROM sfs.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true";
-        if(strtolower($order_from) == "public"){
-            return $public_sql;
-        }else{
-            return $sfs_sql;
-        }    
+            FROM $_schemas.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true";
+        return $sql;
     }
-
+    
     private function AES_encrypted($encrypted_string,$isbase64_encode = true){
         $key = 'fT5!R1k$7Mv@4Q9X'; // 16 bytes key
         $iv = '1234567890123456'; // 16 bytes IV

+ 187 - 53
service/ocean_booking.class.php

@@ -57,7 +57,15 @@ class ocean_booking {
             column::getInstance()->settingDisplay('Booking_Search', 'main_new_version.php?action=ocean_booking');
         }
         if ($operate == "detail") {
-            $this->_booking_detail();
+            $serial_no = common::deCode($_GET['a'], 'D');
+            $transport_mode = common::excuteOneSql("SELECT transport_mode FROM public.kln_booking ob WHERE  ob.serial_no = '$serial_no'");
+            if ($transport_mode == "sea"){
+                $this->_booking_detail();
+            } elseif ($transport_mode == "air"){
+                $this->_air_booking_detail();
+            } else {
+                $this->_booking_detail();
+            }
         }
         if ($operate == "excel") {
             $this->_booking_excel();
@@ -126,7 +134,7 @@ class ocean_booking {
         if (empty($ps)){
             $ps = 100;
         }
-        $sqlWhere = ' where ' . common::searchExtendHandNew("booking", $_SESSION["ONLINE_USER"]);
+        $sqlWhere = ' where ' . common::searchExtendHand_KLN("booking", $_SESSION["ONLINE_USER"]);
         $sqlWhere .= search::getInstance()->getSearchSQL("Booking_Search");
 
         //移除掉全文检索 但保留代码
@@ -140,18 +148,7 @@ class ocean_booking {
                 $textSearch_arr = str_replace(",", ";", $textSearch_arr);
                 $textSearch_arr = array($textSearch_arr);
             }
-            // $more_sql = "1<>1";
-            // foreach($textSearch_arr as $tsv){
-            //     $more_sql .= " or  booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
-            //     $more_sql .= " or  h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
-            //     $more_sql .= " or  po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
-            //     $more_sql .= " or  carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
-            // }
-            // if ($more_sql <> "1<>1"){
-            //     $sqlWhere .= " and ($more_sql)";
-            // }
             $more_param = common::getInNotInSqlForSearch(strtolower(implode(';',$textSearch_arr)));
-            //$sqlWhere .= " and (ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking)],''))"; 
             $sqlWhere .= " and ((ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking)],''))
                 or lower(po_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%')"; 
         } 
@@ -159,6 +156,21 @@ class ocean_booking {
         $sqlWhere_befrom_filterTag  = $sqlWhere;
 
         $filterTag_param = "";
+        $mode_param = "";
+        if(!isset($_POST["transport_mode"]) || empty($_POST["transport_mode"])){
+            $_POST["transport_mode"] = "all";
+        }
+        if (strtolower($_POST["transport_mode"]) == "all") {
+            $mode_param = "'sea','air'";
+        } else {
+            $transport_mode = str_replace(",", ";", $_POST["transport_mode"]);
+            //替换transport_mode对应的value
+            $transport_mode = str_replace("Ocean Freight", "sea", $transport_mode);
+            $transport_mode = str_replace("Air Freight", "air", $transport_mode);
+            $mode_param = common::getInNotInSqlForSearch($transport_mode);
+        }
+        $sqlWhere .= " and transport_mode in ($mode_param)";
+        $transport_mode_search = " and transport_mode in ($mode_param)";
         //前端提交是数组
         if (!empty($_POST['filterTag']) && utils::count($_POST['filterTag']) < 4) {
             if (utils::count($_POST['filterTag']) == 1){
@@ -191,20 +203,27 @@ class ocean_booking {
         if(empty($filterTag_param)){
             $filterTag_param = "1=1";
         }
+        $tag_and_mode_param = $filterTag_param.$transport_mode_search;
 
         $rc = $_POST ['rc'];
         //这里都要查询,除非多传几个参数回来
         if ($rc == - 1 || true) {
             $sql_all_status = "SELECT count(1) as rc,
-                sum(case when $filterTag_param then 1 else 0 end) as seach_rc,
+                sum(case when (1<>1 or (transport_mode='sea')) then 1 else 0 end) as sea_rc,
+                sum(case when (1<>1 or (transport_mode='air')) then 1 else 0 end) as air_rc,
+                sum(case when $tag_and_mode_param then 1 else 0 end) as seach_rc,
                 sum(case when (1<>1 or (bol_type = 'BOOKING' and status!='Cancelled')) then 1 else 0 end) as creatd,
                 sum(case when (1<>1 or (bol_type != 'BOOKING')) then 1 else 0 end) as confirmed,
                 sum(case when (1<>1 or (status='Cancelled')) then 1 else 0 end) as concelled
-            from public.online_booking" . $sqlWhere_befrom_filterTag;
+            from public.kln_booking" . $sqlWhere_befrom_filterTag;
+
+            error_log($sql_all_status );
 
             $sql_all_status_data = common::excuteObjectSql($sql_all_status);
             $seach_rc = $sql_all_status_data['seach_rc'];
             $rc = $sql_all_status_data['rc'];
+            $sea_rc = $sql_all_status_data['sea_rc'];
+            $air_rc = $sql_all_status_data['air_rc'];
             $Creatd = $sql_all_status_data['creatd'];
             $Confirmed = $sql_all_status_data['confirmed'];
             $Concelled = $sql_all_status_data['concelled'];
@@ -223,20 +242,25 @@ class ocean_booking {
                 array("name"=>"Cancelled","number"=>intval($Concelled),"type"=>"cancelled","checked"=>false));
             }
 
-            if (!isset($_POST["transport_mode"])){
-                //代表初始
-                $TransportList = array(
-                    array("name"=>"Ocean Freight","number"=>intval($rc),"checked"=>false,"icon"=>"#icon-icon_ocean_b"));
-            }else{
-                if (strtolower($_POST["transport_mode"]) == "all") {
-                    $TransportList = array(
-                        array("name"=>"Ocean Freight","number"=>intval($rc),"checked"=>true,"icon"=>"#icon-icon_ocean_b"));
-                } else {
-                    $TransportList = array(
-                        array("name"=>"Ocean Freight","number"=>intval($rc),"checked"=>false,"icon"=>"#icon-icon_ocean_b"));
+            $TransportList = array(
+                array("name"=>"Ocean Freight","number"=>intval($sea_rc),"checked"=>false,"icon"=>"#icon-icon_ocean_b"),
+                array("name"=>"Air Freight","number"=>intval($air_rc),"checked"=>false,"icon"=>"#icon-icon_airplane_b"));
+            
+            if (strtolower($_POST["transport_mode"]) == "all") {
+                foreach($TransportList as $tkey => $transport){
+                    $TransportList[$tkey]["checked"] = true;
+                }
+            } else {
+                $transport_mode_arr = explode(",", $_POST["transport_mode"]);
+                foreach($transport_mode_arr as $mode){
+                    foreach($TransportList as $tkey => $transport){
+                        if(trim($mode) == $TransportList[$tkey]["name"]){
+                            $TransportList[$tkey]["checked"] = true;
+                        }
+                    }
                 }
             }
-
+            
             //现在下载交给前端,后台预先只返回全部字段的列,
             $allColumn = column::getInstance()->getDisplayColumnAllReomveDefault('Booking_Search');
             $allBookingColumns = column::getInstance()->tableColumns('Booking_Search',$allColumn);
@@ -247,9 +271,9 @@ class ocean_booking {
             //TopOcean的不用考虑
             $ocean_dest_sql = "";
             //合并显示两个特殊字段 voyage_m_voyage/vessel_m_vessel
-            $sql = "SELECT order_from as _schemas, serial_no as __serial_no, created_time as __created_time, color, 
-                        f_voyage as __f_voyage, m_voyage as __m_voyage,f_vessel as __f_vessel, m_vessel as __m_vessel," .
-                        column::getInstance()->getSearchSqlForDisplay('Booking_Search') . " from public.online_booking $ocean_dest_sql " . $sqlWhere . " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;
+            $sql = "SELECT order_from as _schemas, serial_no as __serial_no, 
+                        color,transport_mode, bol_type, m_voyage as _m_voyage, m_vessel as _m_vessel," .
+                        column::getInstance()->getSearchSqlForDisplay('Booking_Search') . " from public.kln_booking $ocean_dest_sql " . $sqlWhere . " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;
             
             $rs = common::excuteListSql($sql);
             error_log("online_booking_search_SQL: ".$sql);
@@ -258,25 +282,36 @@ class ocean_booking {
             foreach($rs as $index => $val) {
                 //合并显示 vessel
                 if(array_key_exists("f_vessel", $val)){
-                    $rs[$index]["f_vessel"] = utils::outDisplayForMerge($val['f_vessel'],$val['__m_vessel']);
+                    $rs[$index]["f_vessel"] = utils::outDisplayForMerge($val['f_vessel'],$val['_m_vessel']);
                 }
                 //合并显示 voyage
                 if(array_key_exists("f_voyage", $val)){
-                    $rs[$index]["f_voyage"] = utils::outDisplayForMerge($val['f_voyage'],$val['__m_voyage']);
+                    $rs[$index]["f_voyage"] = utils::outDisplayForMerge($val['f_voyage'],$val['_m_voyage']);
                 }
                 //返回加密serial_no
                 $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
 
                 //按新逻辑处理status,现在是管理员权限,客户权限少了一种状态,先设置默认值防止出错
-                $status = "Created";
-                if ($val['color'] == "FF00FF00" || $val['color'] == "FF0000FF"){
+                // $status = "Created";
+                // if ($val['color'] == "FF00FF00" || $val['color'] == "FF0000FF"){
+                //     $status = "Confirmed";
+                // }
+                // if ($val['color'] == "FFFF0000"){
+                //     $status = "Cancelled";
+                // }
+                // $rs[$index]["Status"] = $status;
+                if($val['bol_type'] == 'BOOKING' and $val['Status']!='Cancelled'){
+                    $status = "Created";
+                }
+                if ($val['bol_type'] != 'BOOKING'){
                     $status = "Confirmed";
                 }
-                if ($val['color'] == "FFFF0000"){
+                if ($val['Status']=='Cancelled'){
                     $status = "Cancelled";
                 }
                 $rs[$index]["Status"] = $status;
-                $rs[$index]["Transportation Mode"] = "Ocean Freight";
+
+                $rs[$index]["Transportation Mode"] = $val['transport_mode'] == 'sea' ? "Ocean Freight" : ($val['transport_mode'] == 'air' ? "Air Freight": "");
             }
             
             $arrTmp = array('searchData' => $rs, 
@@ -313,14 +348,17 @@ class ocean_booking {
         if($_schemas == 'public'){
             $_schemas = "ocean";
         }
-        $sql = "SELECT o.booking_no as _booking_no,
-            o.* ,sh.*, cn.* ,aa.*,dd.*,ob.* 
-        from ocean o
+        $sql = "with o as(
+            SELECT  o.*,'' as incoterms from ocean o where lower(serial_no) = '" . strtolower($serial_no) . "''
+        )
+        SELECT o.booking_no as _booking_no,
+            o.* ,sh.*, cn.* ,aa.*,dd.*,ob.* ,
+        from o
             LEFT JOIN LATERAL ( SELECT shippr_uncode,shipper_city,
                 consignee_uncode,consignee_city,
                 place_of_receipt_uncode,place_of_delivery_uncode,
-                fport_of_loading_uncode,mport_of_discharge_uncode,po_no as _po_no
-            FROM public.online_booking ob WHERE o.serial_no::text = ob.serial_no::text) ob ON true
+                fport_of_loading_uncode,mport_of_discharge_uncode,po_no as _po_no,transport_mode
+            FROM public.kln_booking ob WHERE o.serial_no::text = ob.serial_no::text) ob ON true
             LEFT JOIN LATERAL ( SELECT company as cn_company,
                 address_1 as cn_address_1,
                 address_2 as cn_address_2,
@@ -352,8 +390,7 @@ class ocean_booking {
                 address_4 as dd_address_4,
                 city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
                 phone_1 as dd_phone
-            FROM $_schemas.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
-        where lower(serial_no) = '" . strtolower($serial_no) . "'";
+            FROM $_schemas.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true";
         $ocean = common::excuteObjectSql($sql);
 
         $vueData = $this->returnBookingDetailData($ocean,$status);
@@ -445,6 +482,104 @@ class ocean_booking {
         exit(); 
     }
 
+    /**
+     * 信息从kln_booking表里获取(查询全部数据),信息不够在从对应模式里的air_booking取部分数据。 
+    */
+    private function _air_booking_detail(){
+        $serial_no = common::deCode($_GET['a'], 'D');
+        $status = $_GET['status'];
+        $_schemas = $_GET['_schemas'];
+        if($_schemas == 'public'){
+            $_schemas = "ocean";
+        }
+        //air要关联ata_date as ata, atd没有对应字段
+        $sql = "with o as(
+            SELECT  o.* from kln_booking o where serial_no = '" . $serial_no . "'
+        )
+        SELECT *, po_no as _po_no,'' as incoterms,null as atd
+            sh.*, cn.*, aa.*, dd.*
+        from o
+            LEFT JOIN LATERAL ( SELECT company as cn_company,
+                address_1 as cn_address_1,
+                address_2 as cn_address_2,
+                address_3 as cn_address_3,
+                address_4 as cn_address_4,
+                city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
+                phone_1 as cn_phone
+            FROM $_schemas.contacts c WHERE o.consignee_id::text = c.contact_id::text) cn ON true
+            LEFT JOIN LATERAL ( SELECT company as sh_company,
+                address_1 as sh_address_1,
+                address_2 as sh_address_2,
+                address_3 as sh_address_3,
+                address_4 as sh_address_4,
+                city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
+                phone_1 as sh_phone
+            FROM $_schemas.contacts c WHERE o.shipper_id::text = c.contact_id::text) sh ON true
+            LEFT JOIN LATERAL ( SELECT company as aa_company,
+                address_1 as aa_address_1,
+                address_2 as aa_address_2,
+                address_3 as aa_address_3,
+                address_4 as aa_address_4,
+                city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
+                phone_1 as aa_phone
+            FROM $_schemas.contacts c WHERE o.origin::text = c.contact_id::text) aa ON true
+            LEFT JOIN LATERAL ( SELECT company as dd_company,
+                address_1 as dd_address_1,
+                address_2 as dd_address_2,
+                address_3 as dd_address_3,
+                address_4 as dd_address_4,
+                city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
+                phone_1 as dd_phone
+            FROM $_schemas.contacts c WHERE o.agent::text = c.contact_id::text) dd ON true
+        where lower(o.serial_no) = '" . strtolower($serial_no) . "'";
+        $ocean = common::excuteObjectSql($sql);
+
+        $vueData = $this->returnBookingDetailData($ocean,$status);
+
+        //处理transportInfo信息数据
+        $transportInfo = $vueData["transportInfo"];
+        //处理basicInfo信息数据
+        $basicInfo = $vueData["basicInfo"];
+        //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
+        $businessPartners = $vueData["businessPartners"];
+        $marksAndDescription = $vueData["marksAndDescription"];
+        //处理ocean_reference: air没有这个信息
+        $ref_no = array();
+        
+        //处理返回booking的 Container 信息数据
+        $containers = array();
+        //packing
+        //$packing = array("Quantity/Unit"=>"47 CTN","G. Weight" => "480.25 KGS","Ch. Weight" => "689.26 KGS","Volume" => "3.801 CBM");
+        $quantity_tolal = empty($ocean['qty']) ? "" : $ocean['qty'].$ocean['qty_uom'];
+        $g_weight_tolal = empty($ocean['piece_count']) ? "" : sprintf("%.3f", $ocean['piece_count'])." KGS";
+        $ch_weight_tolal = empty($ocean['piece_count']) ? "": sprintf("%.3f", $ocean['weight'])." KGS";
+        $cbm_tolal = empty($ocean['cbm']) ? "" : sprintf("%.4f", $ocean['cbm'])." CBM";
+        $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal,"Ch. Weight" => $ch_weight_tolal,"Volume" => $cbm_tolal);
+        
+        //处理邮件信息返回
+        $emailRecords = $this->getCommunicationNew($ocean["serial_no"]);
+        $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $ocean["serial_no"] . "' order by id desc limit 1");
+        $email = $this->getEmail($ocean["serial_no"]);
+        $email['cc_email'] = $cc_email;
+        $email['emailRecords'] = $emailRecords;
+
+        global $_COPYRIGHT;
+        $data = array('transportInfo' => $transportInfo, 
+                        'basicInfo' => $basicInfo,
+                        'businessPartners' => $businessPartners,
+                        'ref_no' => $ref_no,
+                        'packing' => $packing,
+                        'marksAndDescription' => $marksAndDescription,
+                        'containers' => $containers,
+                        'email' => $email,
+                        'serial_no' => $serial_no,
+                        '_schemas' => $_GET['_schemas'],
+                        '__serial_no' => common::deCode($ocean['serial_no'], 'E'),
+                        'copyright' =>$_COPYRIGHT);
+        common::echo_json_encode(200,$data);                
+        exit(); 
+    }
+
     private function _booking_excel() {  
         $sql = common::deCode($_POST ['tmp_search'], 'D');
         $sql = substr($sql, 0, strripos($sql, " limit"));
@@ -462,28 +597,27 @@ class ocean_booking {
         foreach($rs as $index => $val) {
             //合并显示 vessel
             if(array_key_exists("f_vessel", $val)){
-                $rs[$index]["f_vessel"] = utils::outDisplayForMerge($val['f_vessel'],$val['__m_vessel']);
+                $rs[$index]["f_vessel"] = utils::outDisplayForMerge($val['f_vessel'],$val['_m_vessel']);
             }
             //合并显示 voyage
             if(array_key_exists("f_voyage", $val)){
-                $rs[$index]["f_voyage"] = utils::outDisplayForMerge($val['f_voyage'],$val['__m_voyage']);
+                $rs[$index]["f_voyage"] = utils::outDisplayForMerge($val['f_voyage'],$val['_m_voyage']);
             }
             //返回加密serial_no
             $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
 
             //按新逻辑处理status,现在是管理员权限,客户权限少了一种状态,先设置默认值防止出错
-            $status = "Created";
-            if(!($val['color'] == "FFFF0000" || $val['color'] == "FF00FF00" || $val['color'] == "FF0000FF")){
-                $status = "Confirmed";
-            }
-            if ($val['color'] == "FF0000FF"){
+            if($val['bol_type'] == 'BOOKING' and $val['Status']!='Cancelled'){
                 $status = "Created";
             }
-            if ($val['color'] == "FFFF0000"){
+            if ($val['bol_type'] != 'BOOKING'){
+                $status = "Confirmed";
+            }
+            if ($val['Status']=='Cancelled'){
                 $status = "Cancelled";
             }
             $rs[$index]["Status"] = $status;
-            $rs[$index]["Transportation Mode"] = "Ocean Freight";
+            $rs[$index]["Transportation Mode"] = $val['transport_mode'] == 'sea' ? "Ocean Freight" : ($val['transport_mode'] == 'air' ? "Air Freight": "");
         }
         common::echo_json_encode(200,array("msg"=>"success","Data" => $rs));
         exit;
@@ -552,7 +686,7 @@ class ocean_booking {
         $uncodes = $ocean['fport_of_loading_uncode'].";".$ocean['mport_of_discharge_uncode'];
         $codeinfo = common::getCityPortsInfo($uncodes);
         //处理transportInfo信息数据
-        $transportInfo = array("bookingNo." =>$ocean['booking_no'],"status"=>$status,"mode" => "Ocean Freight",
+        $transportInfo = array("bookingNo." =>$ocean['booking_no'],"status"=>$status,"mode" => $ocean['transport_mode'] == 'sea' ? "Ocean Freight" : ($ocean['transport_mode'] == 'air' ? "Air Freight": ""),
             "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
             "etd" =>$ocean['f_etd'],"atd" =>$ocean['atd'],
             "etd_timezone" =>$codeinfo[$ocean['fport_of_loading_uncode']],

+ 453 - 40
service/ocean_order.class.php

@@ -47,7 +47,15 @@ class ocean_order {
         }
 
         if ($operate == "detail") {
-            $this->_ocean_detail();
+            $serial_no = common::deCode($_GET['a'], 'D');
+            $transport_mode = common::excuteOneSql("SELECT transport_mode FROM public.kln_ocean ob WHERE  ob.serial_no = '$serial_no'");
+            if ($transport_mode == "sea"){
+                $this->_ocean_detail();
+            } elseif ($transport_mode == "air"){
+                $this->_air_ocean_detail();
+            } else {
+                $this->_ocean_detail();
+            }
         }
 
         if ($operate == "ams_isf_log"){
@@ -268,6 +276,15 @@ class ocean_order {
             }
             exit();
         }
+        
+        /*
+         * share_shipment 这个提交的意义,是为了留下记录用户信息
+        */
+        if ($operate == "share_shipment") {
+            $data = array("msg" =>"share_shipment");
+            common::echo_json_encode(200,$data);
+            exit();
+        }
     }
 
     /*
@@ -281,7 +298,7 @@ class ocean_order {
         if (empty($cp))
             $cp = 1;
 
-        $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
+        $sqlWhere = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
         $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
 
         if (!empty($_REQUEST["_reportRef"])) {
@@ -398,18 +415,7 @@ class ocean_order {
                 $textSearch_arr = str_replace(",", ";", $textSearch_arr);
                 $textSearch_arr = array($textSearch_arr);
             }
-            // $more_sql = "1<>1";
-            // foreach($textSearch_arr as $tsv){
-            //     $more_sql .= " or  booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
-            //     $more_sql .= " or  h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
-            //     $more_sql .= " or  po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
-            //     $more_sql .= " or  carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
-            // }
-            // if ($more_sql <> "1<>1"){
-            //     $sqlWhere .= " and ($more_sql)";
-            // }
             $more_param = common::getInNotInSqlForSearch(strtolower(implode(';',$textSearch_arr)));
-            // or text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))
             //$sqlWhere .= " and (ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking),lower(tracking_no)],''))";
             $sqlWhere .= " and ((ARRAY[$more_param] && array_append(ARRAY[lower(booking_no::text), lower(h_bol::text), lower(m_bol), lower(carrier_booking), lower(quote_no), lower(tracking_no)]||string_to_array(lower(ctnrs),','), ''::text))
                 or lower(po_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%'
@@ -417,6 +423,22 @@ class ocean_order {
         }
         //移除filterTag
         $sqlWhere_befrom_filterTag  = $sqlWhere;
+
+        $mode_param = "";
+        if(!isset($_POST["transport_mode"]) || empty($_POST["transport_mode"])){
+            $_POST["transport_mode"] = "all";
+        }
+        if (strtolower($_POST["transport_mode"]) == "all") {
+            $mode_param = "'sea','air'";
+        } else {
+            $transport_mode = str_replace(",", ";", $_POST["transport_mode"]);
+            //替换transport_mode对应的value
+            $transport_mode = str_replace("Ocean Freight", "sea", $transport_mode);
+            $transport_mode = str_replace("Air Freight", "air", $transport_mode);
+            $mode_param = common::getInNotInSqlForSearch($transport_mode);
+        }
+        $sqlWhere .= " and transport_mode in ($mode_param)";
+        $transport_mode_search = " and transport_mode in ($mode_param)";
         
         //查询tag
         // IFFBCF  Booking Confirmation                      Created
@@ -468,12 +490,15 @@ class ocean_order {
         if(empty($filterTag_param)){
             $filterTag_param = "1=1";
         }
+        $tag_and_mode_param = $filterTag_param.$transport_mode_search;
 
         $rc = $_POST ['rc'];
         //这里都要查询,除非多传几个参数回来
         if ($rc == - 1 || true) {
             $sql = "select count(1) as rc,
-                sum(case when $filterTag_param then 1 else 0 end) as seach_rc, 
+                sum(case when (1<>1 or (transport_mode='sea')) then 1 else 0 end) as sea_rc, 
+                sum(case when (1<>1 or (transport_mode='air')) then 1 else 0 end) as air_rc, 
+                sum(case when $tag_and_mode_param then 1 else 0 end) as seach_rc, 
                 sum(case when (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 1 else 0 end) 
                 as created, 
@@ -485,7 +510,7 @@ class ocean_order {
                 sum(case when (m_iffdel is not null) then 1 else 0 end) as completed,
                 string_agg(distinct incoterms, '<$>') as incoterm_str,
                 string_agg(distinct service, '<$>') as service_str 
-            from online_ocean". $sqlWhere_befrom_filterTag;
+            from kln_ocean". $sqlWhere_befrom_filterTag;
             error_log("online_ocean_search_All_Status: ".$sql);
 
             $sql_all_status_data = common::excuteObjectSql($sql);
@@ -505,6 +530,8 @@ class ocean_order {
             }
             $rc = $sql_all_status_data['rc'];
             $search_rc = $sql_all_status_data['seach_rc'];
+            $sea_rc = $sql_all_status_data['sea_rc'];
+            $air_rc = $sql_all_status_data['air_rc'];
             $Created = $sql_all_status_data['created'];
             $Cargo_Received = $sql_all_status_data['cargo_received'];
             $Departed = $sql_all_status_data['departed'];
@@ -528,17 +555,22 @@ class ocean_order {
                 array("name"=>"Completed","number"=>intval($Completed),"type"=>"completed","checked"=>false));
             }
 
-            if (!isset($_POST["transport_mode"])){
-                //代表初始
-                $TransportList = array(
-                    array("name"=>"Ocean Freight","number"=>intval($rc),"checked"=>false,"icon"=>"#icon-icon_ocean_b"));
-            }else{
-                if (strtolower($_POST["transport_mode"]) == "all") {
-                    $TransportList = array(
-                        array("name"=>"Ocean Freight","number"=>intval($rc),"checked"=>true,"icon"=>"#icon-icon_ocean_b"));
-                } else {
-                    $TransportList = array(
-                        array("name"=>"Ocean Freight","number"=>intval($rc),"checked"=>false,"icon"=>"#icon-icon_ocean_b"));
+            $TransportList = array(
+                array("name"=>"Ocean Freight","number"=>intval($sea_rc),"checked"=>false,"icon"=>"#icon-icon_ocean_b"),
+                array("name"=>"Air Freight","number"=>intval($air_rc),"checked"=>false,"icon"=>"#icon-icon_airplane_b"));
+
+            if (strtolower($_POST["transport_mode"]) == "all") {
+                foreach($TransportList as $tkey => $transport){
+                    $TransportList[$tkey]["checked"] = true;
+                }
+            } else {
+                $transport_mode_arr = explode(",", $_POST["transport_mode"]);
+                foreach($transport_mode_arr as $mode){
+                    foreach($TransportList as $tkey => $transport){
+                        if(trim($mode) == $TransportList[$tkey]["name"]){
+                            $TransportList[$tkey]["checked"] = true;
+                        }
+                    }
                 }
             }
 
@@ -552,10 +584,10 @@ class ocean_order {
             $order_by = " eta desc";
         }
         if ($rc > 0) {
-            $ocean_ref_sql = " LEFT JOIN LATERAL ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no
-                            FROM public.ocean_reference temp WHERE temp.serial_no = oo.serial_no) aa ON true ";
+            // $ocean_ref_sql = " LEFT JOIN LATERAL ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no
+            //                 FROM public.ocean_reference temp WHERE temp.serial_no = oo.serial_no) aa ON true ";
 
-            $sql = "with oo  as (SELECT order_from as _schemas,serial_no as __serial_no, serial_no,
+            $sql = "with oo  as (SELECT order_from as _schemas,serial_no as __serial_no, serial_no,transport_mode,
                     h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,
                     CASE
 	    	            WHEN (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
@@ -565,11 +597,18 @@ class ocean_order {
                         WHEN (m_iffdel is not null) THEN 'Completed'::text
 	    	            ELSE 'Created'
 		            END AS new_status, ".
-                    column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.online_ocean " . $sqlWhere . 
+                    column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.kln_ocean " . $sqlWhere . 
                 " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps.") 
-            select oo.* ,aa.other_refenrence_no as \"Other refenrence No.\" from oo $ocean_ref_sql";
-
-            $tmp_search_without_limit = "with oo  as (SELECT order_from as _schemas,serial_no as __serial_no, serial_no,
+            select oo.* ,
+                case when oo.transport_mode ='sea' 
+                        then ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no FROM public.ocean_reference temp WHERE temp.serial_no = oo.serial_no)
+                    when oo.transport_mode ='air' 
+                        then ''
+                    else '' 
+                end as \"Other refenrence No.\"
+            from oo";
+
+            $tmp_search_without_limit = "with oo  as (SELECT order_from as _schemas,serial_no as __serial_no, serial_no,transport_mode,
                     h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,
                     CASE
 	    	            WHEN (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
@@ -579,9 +618,16 @@ class ocean_order {
                         WHEN (m_iffdel is not null) THEN 'Completed'::text
 	    	            ELSE 'Created'
 		            END AS new_status, ".
-                    column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.online_ocean " . $sqlWhere . 
+                    column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.kln_ocean " . $sqlWhere . 
                 " order by $order_by) 
-            select oo.* ,aa.other_refenrence_no as \"Other refenrence No.\" from oo $ocean_ref_sql";
+           select oo.* ,
+                case when oo.transport_mode ='sea' 
+                        then ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no FROM public.ocean_reference temp WHERE temp.serial_no = oo.serial_no)
+                    when oo.transport_mode ='air' 
+                        then ''
+                    else '' 
+                end as \"Other refenrence No.\"
+            from oo";
             
             $rs = common::excuteListSql($sql);
             error_log("online_ocean_search_SQL: ".$sql);
@@ -590,7 +636,8 @@ class ocean_order {
             foreach($rs as $index => $val) {
                 //返回加密serial_no
                 $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
-                $rs[$index]["mode"] = "Ocean Freight";
+                //$rs[$index]["mode"] = "Ocean Freight";
+                $rs[$index]["Transportation Mode"] = $val['transport_mode'] == 'sea' ? "Ocean Freight" : ($val['transport_mode'] == 'air' ? "Air Freight": "");
                 //status 改为ocean_milestone里的信息
                 $rs[$index]["Status"] = $rs[$index]["new_status"];
             }
@@ -743,7 +790,7 @@ class ocean_order {
         $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $ch_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
         
         //Milestones info  列名固定
-        $Milestones = common::getMilestonesInfo($ocean,$vueData['EDI315TimeAndLocation']);
+        $Milestones = common::getMilestonesInfo($ocean,"sea",$_schemas,$vueData['EDI315TimeAndLocation']);
 
         //页面固定写死的信息
         $document_column = array();
@@ -841,6 +888,7 @@ class ocean_order {
                         'email' => $email,
                         'ams_ss' =>  md5(md5($ocean['serial_no'])),
                         'isf_ss' => $isf_ss,
+                        'transport_mode' =>"sea",
                         '_schemas' =>$_schemas,
                         'uncode' =>$uncode,
                         'serial_no' =>$serial_no,
@@ -853,6 +901,159 @@ class ocean_order {
         exit(); 
     }
 
+    private function _air_ocean_detail(){
+        $serial_no = common::deCode($_GET['a'], 'D');
+        $sql = $this->getAirDetail($serial_no);
+        $air = common::excuteObjectSql($sql);
+        
+        //根据air_milestone 判断 shipment status的state
+        $_schemas = $_REQUEST["_schemas"];
+        $air_milestone_status = common::excuteListSql("select code,
+                act_date,est_date,timezone 
+            from  ocean_milestone a 
+		 		where a.serial_no='$serial_no' and code in('IFFCPU','IFFREC','IFFONB','IFFARR','IFFDEL')
+            order by id");
+        $state = -1;
+        if (!empty($air_milestone_status)) {
+            $state_arr = array();
+            foreach($air_milestone_status as $ms){
+                if($ms['code'] == "IFFCPU"){
+                    $state_arr[] = 0;
+                }
+                if($ms['code'] == "IFFREC" || $ms['code'] == "IFFONB"){
+                    $state_arr[] = 1;
+                }
+                if($ms['code'] == "IFFARR"){
+                    $state_arr[] = 2;
+                }
+                if($ms['code'] == "IFFDEL"){
+                    $state_arr[] = 3;
+                }
+            }
+            $state = max($state_arr);
+        }        
+        $vueData = $this->returnAirDetailData($air,$air_milestone_status,$state);
+
+        //处理shipment data暂时写死
+        $simplexData = $vueData['shipmentData'];
+        //处理transportInfo信息数据
+        $transportInfo = $vueData['transportInfo'];
+        //处理basicInfo信息数据
+        $basicInfo = $vueData['basicInfo'];
+        //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
+        $businessPartners = $vueData['businessPartners'];
+        //处理routes 转船可能有多个情况
+        $routes = $vueData['routes']; 
+        //处理marksAndDescription
+        $marksAndDescription = $vueData['marksAndDescription'];
+        
+        $quantity_tolal = empty($air['qty']) ? "" : $air['qty'].$air['qty_uom'];
+        $g_weight_tolal = empty($air['piece_count']) ? "" : sprintf("%.3f", $air['piece_count'])." KGS";
+        $ch_weight_tolal = empty($air['piece_count']) ? "": sprintf("%.3f", $air['weight'])." KGS";
+        $cbm_tolal = empty($air['cbm']) ? "" : sprintf("%.4f", $air['cbm'])." CBM";
+        //Packing信息
+        $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal,"Ch. Weight" => $ch_weight_tolal,"Volume" => $cbm_tolal);
+        
+        //Milestones info  列名固定
+        $Milestones = common::getMilestonesInfo($air,"air",$_schemas);
+
+        //页面固定写死的信息
+        $document_column = array();
+        $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
+        $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
+
+        $document_data = array();
+
+        $document = _getAirViewDocType($_REQUEST["_schemas"]);
+        $air_can_view_file = common::excuteOneSql("select air_can_view_file from ra_online_user where lower(user_login)='".strtolower($_SESSION['ONLINE_USER']['user_login'])."'");
+        if (!empty($document)) {
+            foreach ($document as $v) {
+                $file_type = $v['display_name'];
+                $file_arr =  $this->getFileByHbol($air['_m_bol'], $air['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE);
+
+                $tar = json_decode($air_can_view_file,true);
+                if(!empty($tar[$v['display_name']])){
+                    foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
+                        switch ($v['display_name']) {
+                            case 'HBL':
+                                $sql = "SELECT file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
+                                        from air_doc_upload
+                                        where lower(bol) = lower('".$air['_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']."'
+                                        order by id desc";
+                                break;
+                            case 'MBL':
+                                $sql = "SELECT file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
+                                        from air_doc_upload
+                                        where lower(bol) = lower('".strtolower($air['_m_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']."'
+                                        order by id desc";
+                                break;
+                            case 'Others':
+                                $sql = "SELECT file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
+                                        from air_doc_upload
+                                        where (lower(bol) = lower('".strtolower($air['_h_bol'])."') or lower(bol) = lower('".strtolower($air['_m_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']."'
+                                        order by id desc";
+                                break;
+                            default:
+                                $sql = "";
+                                break;
+                        }
+                        if (!empty($sql)) {
+                            $rss = common::excuteListSql($sql);
+                            foreach ($rss as $rs) {
+                                $file_arr[] = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
+                                        "file_name" => $rs['file_name'],
+                                        "detail"=>$rs['upload_date'],
+                                        "can_delete"=>_getLoginName() == $rs['upload_by'],
+                                        "from_system" =>'');
+                            }
+                        }
+                    }
+                }
+                //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
+                //按现在的逻辑,有值才会显示
+                foreach($file_arr as $f){
+                    $document_data[] = array("file_type"=>$file_type,"file"=>$f);
+                }
+            }
+        }
+        $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
+
+        $emailRecords = $this->getCommunicationNew($air["serial_no"]);
+        $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $air["serial_no"] . "' order by id desc limit 1");
+        $email = $this->getEmail($air["serial_no"]);
+        $email['cc_email'] = $cc_email;
+        $email['emailRecords'] = $emailRecords;
+
+        global $_COPYRIGHT;
+        $data = array('transportInfo' => $transportInfo, 
+                        'basicInfo' => $basicInfo,
+                        'businessPartners' => $businessPartners,
+                        'ref_no' => array(),
+                        'packing' => $packing,
+                        'marksAndDescription' => $marksAndDescription,
+                        'containers' => array(),
+                        'simplexData' =>$simplexData,
+                        'containerStatusData' => array(),
+                        'document_info' => $document_info,
+                        'containers' => array(),
+                        'Milestones' => $Milestones,
+                        'routes' => $routes,
+                        'email' => $email,
+                        'ams_ss' =>"",
+                        'isf_ss' => "",
+                        '_schemas' =>$_schemas,
+                        'uncode' =>"",
+                        'transport_mode' =>"air",
+                        'serial_no' =>$serial_no,
+                        'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
+                        'canEdiVgm' => _canEdiVgm(),
+                        'canViewAMSLog'=>_canViewAMSLog(),
+                        'canViewISFLog'=>_canViewISFLog(),
+                        'copyright' =>$_COPYRIGHT);
+        common::echo_json_encode(200,$data);                
+        exit(); 
+    }
+
     private function _ocean_excel() {
         $sql = common::deCode($_POST ['tmp_search'], 'D');
         //$sql = substr($sql, 0, strripos($sql, " limit"));
@@ -871,7 +1072,8 @@ class ocean_order {
         foreach($rs as $index => $val) {
             //返回加密serial_no
             $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
-            $rs[$index]["mode"] = "Ocean Freight";
+            //$rs[$index]["mode"] = "Ocean Freight";
+            $rs[$index]["Transportation Mode"] = $val['transport_mode'] == 'sea' ? "Ocean Freight" : ($val['transport_mode'] == 'air' ? "Air Freight": "");
             //status 改为ocean_milestone里的信息
             $rs[$index]["Status"] = $rs[$index]["new_status"];
         }
@@ -1277,6 +1479,79 @@ class ocean_order {
         return $sql;
     }
 
+    private function getAirDetail($serial_no) {
+        $order_from = $_REQUEST['_schemas'];
+        $_schemas = $_REQUEST['_schemas'];
+        if($_schemas == 'public'){
+            $_schemas = "ocean";
+        }
+        $sql = "with o as(
+            SELECT  oo.*,m_bol as _m_bol, h_bol as _h_bol,
+                    (select time_zone from public.city_timezone where uncode = oo.fport_of_loading_un limit 1) as pol_timezone,
+                    (select uncity from public.ports where uncode = oo.fport_of_loading_un limit 1) as pol_uncity,
+                    (select time_zone from public.city_timezone where uncode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
+                    (select uncity from public.ports where uncode = oo.mport_of_discharge_un limit 1) as mpod_uncity,
+                    (select time_zone from public.city_timezone where uncode = oo.place_of_receipt_un limit 1) as por_timezone,
+                    (select uncity from public.ports where uncode = oo.place_of_receipt_un limit 1) as por_uncity,
+                    (select time_zone from public.city_timezone where uncode = oo.place_of_delivery_un limit 1) as pod_timezone,
+                    (select uncity from public.ports where uncode = oo.place_of_delivery_un limit 1) as pod_uncity,
+                    (select time_zone from public.city_timezone where uncode = oo.final_desination_uncode limit 1) as _fd_timezone,
+                    (select uncity from public.ports where uncode = oo.final_desination_uncode limit 1) as _pd_uncity, 
+                    CASE
+                        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
+                        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
+                        WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
+                        WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
+                        WHEN (m_iffdel is not null) THEN 'Completed'::text
+                        ELSE 'Created'::text
+                    END AS new_status
+            from public.kln_ocean oo where oo.serial_no = '" . $serial_no . "' and oo.order_from = '$order_from'
+        )
+        SELECT  o.* ,sh.*, cn.*,
+                aa.*,dd.*,fd.*
+        from o 
+            LEFT JOIN LATERAL ( SELECT company as cn_company,
+                address_1 as cn_address_1,
+                address_2 as cn_address_2,
+                address_3 as cn_address_3,
+                address_4 as cn_address_4,
+                city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
+                phone_1 as cn_phone
+            FROM $_schemas.contacts c WHERE o.consignee_id::text = c.contact_id::text) cn ON true
+            LEFT JOIN LATERAL ( SELECT company as sh_company,
+                address_1 as sh_address_1,
+                address_2 as sh_address_2,
+                address_3 as sh_address_3,
+                address_4 as sh_address_4,
+                city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
+                phone_1 as sh_phone
+            FROM $_schemas.contacts c WHERE o.shipper_id::text = c.contact_id::text) sh ON true
+            LEFT JOIN LATERAL ( SELECT company as aa_company,
+                address_1 as aa_address_1,
+                address_2 as aa_address_2,
+                address_3 as aa_address_3,
+                address_4 as aa_address_4,
+                city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
+                phone_1 as aa_phone,
+                (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as aa_timezone
+            FROM $_schemas.contacts c WHERE o.origin::text = c.contact_id::text) aa ON true
+            LEFT JOIN LATERAL ( SELECT company as dd_company,
+                address_1 as dd_address_1,
+                address_2 as dd_address_2,
+                address_3 as dd_address_3,
+                address_4 as dd_address_4,
+                city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
+                phone_1 as dd_phone,
+                (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as dd_timezone
+            FROM $_schemas.contacts c WHERE o.agent::text = c.contact_id::text) dd ON true
+            LEFT JOIN LATERAL ( SELECT 
+                city as fd_city,
+                (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'') limit 1) as fd_timezone
+            FROM $_schemas.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true";
+        //error_log($sql);
+        return $sql;
+    }
+
     private function returnOceanDetailData($ocean,$state){
         $data = array();
         //由于这些基础数据还待完善,而且现在提单样式改版也没有显示客户自身的地址数据,所以我们这边的这个取值也要麻烦调整一下:
@@ -1392,7 +1667,7 @@ class ocean_order {
         $simplexData[] = $place_of_Delivery_status;
         $data['shipmentData'] = $simplexData;
 
-        //处理transportInfo信息数据
+        //处理transportInfo信息数据(air改过,从KLN_Ocean主表信息 etd 和eta 的取值跟ocean的f_etd,m_eta)
         $transportInfo = array("Tracking No." =>$ocean['_tracking_no'],"status"=>$ocean['new_status'],"mode" => "Ocean Freight",
             "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
             "etd" =>$ocean['f_etd'],"atd" =>$ocean['atd'],
@@ -1451,10 +1726,148 @@ class ocean_order {
         $data['routes'] = $routes;
         
         //处理marksAndDescription
-        $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description']);
+        $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description'],"remark"=>$ocean['remark']);
         $data['marksAndDescription'] = $marksAndDescription;
 
         return $data;    
     }
+
+    private function returnAirDetailData($ocean,$ocean_milestone_status,$state){
+        $data = array();
+        //由于这些基础数据还待完善,而且现在提单样式改版也没有显示客户自身的地址数据,所以我们这边的这个取值也要麻烦调整一下:
+        //1.Shipment detail顶部的Origin和Destination的取值换成Place of Receipt、Place of Delivery的UNCODE
+        //2.Tracking列表页里面字段Origin和Destination先隐藏(客户地址),不做展示
+        $ocean['shippr_uncode'] = $ocean['place_of_receipt_un'];
+        $ocean['consignee_uncode'] = $ocean['place_of_delivery_un'];
+
+        //处理shipment data
+        $ocean_milestone_status_code = array();
+        foreach($ocean_milestone_status as $oms){
+            $ocean_milestone_status_code[$oms['code']] = $oms;
+        }
+        if ($state < 1){
+            //未发生前
+            if(!empty($ocean_milestone_status_code['IFFONB']['est_date'])){
+                //如果milestone有值,或者与milestone不等,以milestone的优先度最高
+                $ocean['etd'] = $ocean_milestone_status_code['IFFONB']['est_date'];
+            } 
+        } else{
+            if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
+                //如果milestone有值,或者与milestone不等,以milestone的优先度最高
+                //ATD 取值为IFFONB milestone实际发生的时间
+                $ocean['atd'] = $ocean_milestone_status_code['IFFONB']['act_date'];
+            }
+        }
+
+        $simplexData = array();
+        //place_of_Receipt
+        $place_of_Receipt_stauts =  array("index" =>1,"label" =>"Place of Receipt",
+            "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt_un'],"isArrival" =>$state >= 0 ? true : false);
+        $children = array();  
+        if($state >= 1 && !empty($ocean_milestone_status_code['IFFCPU']['act_date'])){
+            //发生后,未发生前没有
+            $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFCPU']['act_date']);
+        }
+        $place_of_Receipt_stauts["children"] = $children;
+        $simplexData[] = $place_of_Receipt_stauts;
+
+        //port_of_Loading
+        $port_of_Loading_stauts = array("index" =>2,"label" =>"Port of Loading",
+            "path" =>$ocean['fport_of_loading_exp']."/".$ocean['fport_of_loading_un'],"isArrival" =>$state >= 1 ? true : false);
+        $children = array();  
+        if ($state < 1){
+            $children[] = array("label" =>"Departure(ETD)","date" =>$ocean['etd']);
+        } else{
+            if(!empty($ocean_milestone_status_code['IFFREC']['act_date'])){
+                $children[] = array("label" =>"Cargo Received","date" =>$ocean_milestone_status_code['IFFREC']['act_date']);
+            }
+            if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
+                $children[] = array("label" =>"Departure(ATD)","date" =>$ocean_milestone_status_code['IFFONB']['act_date']);
+            }
+        }                 
+        $port_of_Loading_stauts["children"] = $children;        
+        $simplexData[] = $port_of_Loading_stauts;
+
+        //Port of Discharge
+        $port_of_Discharge_status = array("index" =>3,"label" =>"Port of Discharge",
+            "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge_un'],"isArrival" =>$state >= 2 ? true : false);
+        $children = array(); 
+        if ($state < 2){
+            $children[] = array("label" =>"Arrival(ETA)","date" =>$ocean['eta']);
+        }else{
+            if(!empty($ocean_milestone_status_code['IFFARR']['act_date'])){
+                $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean_milestone_status_code['IFFARR']['act_date']);
+                $ocean['ata'] = $ocean_milestone_status_code['IFFARR']['act_date'];
+            }else{
+                //IFFARR 如果同步异常没有值时,去表里的 ata_date AS ata
+                $children[] = array("label" =>"Arrival(ATA)","date" =>$ocean['ata']);
+            }
+        }             
+        $port_of_Discharge_status["children"] = $children;     
+        $simplexData[] = $port_of_Discharge_status;
+
+        //Place of Delivery
+        $place_of_Delivery_status = array("index" =>4,"label" =>"Place of Delivery",
+            "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery_un'],"isArrival" =>$state == 3 ? true : false);
+        $children = array(); 
+        if ($state < 3){
+            //未发生前
+        } else{
+            if(!empty($ocean_milestone_status_code['IFFDEL']['act_date'])){
+                $children[] = array("label" =>"Cargo handover/Delivered","date" =>$ocean_milestone_status_code['IFFDEL']['act_date']);
+            }
+        }                 
+        $simplexData[] = $place_of_Delivery_status;
+        $data['shipmentData'] = $simplexData;
+
+        //处理transportInfo信息数据(air改过,从KLN_Ocean主表信息 etd 和eta 的取值跟ocean的f_etd,m_eta)
+        $transportInfo = array("Tracking No." =>$ocean['tracking_no'],"status"=>$ocean['new_status'],"mode" => "Air Freight",
+            "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
+            "etd" =>$ocean['etd'],"atd" =>$ocean['atd'],
+            "etd_timezone" =>$ocean['pol_timezone'],
+            "atd_timezone" =>$ocean['pol_timezone'],
+            "eta" =>$ocean['eta'],"ata" =>$ocean['ata'],
+            "eta_timezone" =>$ocean['mpod_timezone'],
+            "ata_timezone" =>$ocean['mpod_timezone']);
+        $data['transportInfo'] = $transportInfo;
+
+        //处理basicInfo信息数据
+        $vessel = $ocean['vessel'];
+        $voyage = $ocean['voyage'];
+        $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['booking_no'],
+            "PO_NO" =>$ocean['po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
+            "Incoterm" =>$ocean['incoterms'],"Service_Type" =>$ocean['service']);
+        $data['basicInfo'] = $basicInfo;    
+
+        //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
+        $shipper_address = common::retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'], 
+            $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
+        $consignee_address = common::retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'], 
+            $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
+        $origin_address = common::retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'], 
+            $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']); 
+        $destination_address = common::retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'], 
+            $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);    
+
+        $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
+        $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
+        $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
+        $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
+        $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
+        $data['businessPartners'] = $businessPartners;  
+    
+        //处理routes air不存在中转的
+        $routes = array(array("mode" =>"Air Freight","mode_label" =>"Air", "origin" =>$ocean['shippr_uncode'],
+                "destination" => $ocean['consignee_uncode'],
+                "etd" => $ocean['etd'],"atd" => $ocean['atd'],
+                "eta" => $ocean['eta'],"ata" => $ocean['ata'],
+                "vessel" =>$ocean['vessel'],"voyageNo" =>$ocean['voyage']));
+        $data['routes'] = $routes;
+        
+        //处理marksAndDescription
+        $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description'],"remark"=>$ocean['remark']);
+        $data['marksAndDescription'] = $marksAndDescription;
+        return $data;    
+    }
 }
 ?>

+ 19 - 8
service/search.class.php

@@ -102,16 +102,27 @@ class search {
         $result = " and 1=1";
         $sql = $this->_getSql($rs, "value_name, search_condition, is_int");
         $rss = common::excuteListSql($sql);
+        //因为正式服务器保持不变的前提下,手动的添加transport_mode
+        if(strtolower($model_name) == "booking_search" || strtolower($model_name) == "ocean_search"){
+            $rss[] = array("value_name"=>"transport_mode","search_condition"=>"like","is_int"=>false);
+        }
         foreach ($rss as $v) {
             if ((isset($_POST[$v['value_name']]) && !empty($_POST[$v['value_name']])) || (isset($_POST[$v['value_name'] . '_start']) && !empty($_POST[$v['value_name'] . '_start'])) || (isset($_POST[$v['value_name'] . '_end']) && !empty($_POST[$v['value_name'] . '_end']))) {
-                if (strtolower($model_name) == "booking_search" && (strtolower($v['value_name']) == "transport_mode")) {
-                    //transport_mode todo
-                    
-                } elseif (strtolower($model_name) == "ocean_search" 
-                    && (strtolower($v['value_name']) == "transport_mode" 
-                        || strtolower($v['value_name']) == "incoterms"
-                        || strtolower($v['value_name']) == "service")){
-                    //transport_mode todo  
+                //transport_mode 查询统一处理
+                if ((strtolower($model_name) == "booking_search" || strtolower($model_name) == "ocean_search") && strtolower($v['value_name']) == "transport_mode") {
+                    //需要被拿出来,以不影响计总的数量计算
+                    // $mode_param = "";
+                    // if (strtolower($_POST["transport_mode"]) == "all") {
+                    //     $mode_param = "'sea','air'";
+                    // } else {
+                    //     $transport_mode = str_replace(",", ";", $_POST["transport_mode"]);
+                    //     //替换transport_mode对应的value
+                    //     $transport_mode = str_replace("Ocean Freight", "sea", $transport_mode);
+                    //     $transport_mode = str_replace("Air Freight", "air", $transport_mode);
+                    //     $mode_param = common::getInNotInSqlForSearch($transport_mode);
+                    // }
+                    // $result .= " and transport_mode in ($mode_param)";
+                } elseif (strtolower($model_name) == "ocean_search"  && (strtolower($v['value_name']) == "incoterms"|| strtolower($v['value_name']) == "service")){
                     //incoterms 和 service特殊处理
                     if(!empty($_POST[$v['value_name']])){
                         //前台这个字段,All是字符串,其他值的提交过来的是数组

+ 134 - 295
utils/common.class.php

@@ -195,21 +195,34 @@ class common {
         }
     }
 
+    public static function searchExtendHand_KLN($type, $user, $company_name = "station_name") {
+        $sqlWhere = " 1=1";
+        if($type == "booking"){
+            $ocean_booking_sqlWhere = self::searchExtendHandNew("booking",$user, $company_name);
+            $air_booking_sqlWhere = self::searchExtendHandNew("air_booking",$user, $company_name);
+            $sqlWhere = "((transport_mode ='sea' and ".$ocean_booking_sqlWhere.") or (transport_mode ='air' and ".$air_booking_sqlWhere."))";
+        }
+        if($type == "ocean"){
+            $ocean_booking_sqlWhere = self::searchExtendHandNew("ocean",$user, $company_name);
+            $air_booking_sqlWhere = self::searchExtendHandNew("air",$user, $company_name);
+            $sqlWhere = "((transport_mode ='sea' and ".$ocean_booking_sqlWhere.") or (transport_mode ='air' and ".$air_booking_sqlWhere."))";
+        }
+        return $sqlWhere;
+    }
+
     public static function searchExtendHandNew($type, $user, $company_name = "station_name") {
         if (_isAdminHandNew($user)) {
-            if(strtolower($type) == "air_booking" ) //|| strtolower($type) == "air"
+            if(strtolower($type) == "air_booking" )
             {
                 return "1=1";
             }
-            //return " (schem_not_display is null or schem_not_display=false)";
             return " (COALESCE(schem_not_display,false) = false)";
         }
         if (_isDocAdmin($user["user_login"])) {
-            if(strtolower($type) == "air_booking" ) //|| strtolower($type) == "air"
+            if(strtolower($type) == "air_booking" )
             {
                 return "1=1";
             }
-            //return ' (schem_not_display is null or schem_not_display=false)';
             return ' (COALESCE(schem_not_display,false) = false)';
         }
         if (strtolower($type) != "ocean" && strtolower($type) != "booking" && strtolower($type) != "air_booking"&& strtolower($type) != "air") {
@@ -223,7 +236,6 @@ class common {
         if ($user["is_kerry_shipment"] == "t") {
             $sqlWhere = " is_kerry_shipment is not null and is_kerry_shipment=true";
         } else if ($user["is_kerry_shipment"] == "f") {
-            //$sqlWhere = " (is_kerry_shipment is null or is_kerry_shipment=false)";
             $sqlWhere = " (COALESCE(is_kerry_shipment,false) = false)";
         } else {
             $sqlWhere = " 1=1";
@@ -263,31 +275,17 @@ class common {
                 $sqlWhere .= self::_bookingHandNew($user, $schames);
             }
             if (strtolower($type) == "air_booking") {
-                $sqlWhere .= self::_airHandNew($user, $schames);
+                $sqlWhere .= self::_air($schames);
             }
             
             if (strtolower($type) == "air") {
-                $sqlWhere .= self::_airHandNew($user, $schames);
-                if ($company_name == "doc") {
-                    if (empty($user["view_file_format"])) {
-                        if (strtolower($user["user_type"]) == "customer") {
-                            $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true and client_display = true)";
-                        } else {
-                            $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true)";
-                        }
-                    } else {
-                        $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
-                    }
-                }
+                $sqlWhere .= self::_air($schames);
             }
 
         } elseif (count($schemas_list) == 2) {
-            if(strtolower($type) == "air_booking" )//|| strtolower($type) == "air"
-            {
-                // $sqlWhere .= " and 1=1";
-            }
-            else{
-                //$sqlWhere .= " and (schem_not_display is null or schem_not_display=false)";
+            if(strtolower($type) == "air_booking" ){
+                
+            }else{
                 $sqlWhere .= " and (COALESCE(schem_not_display,false) = false)";
             }
             if (strtolower($type) == "ocean") {
@@ -335,48 +333,24 @@ class common {
             }
             if (strtolower($type) == "air_booking") {
                 $sqlWhere .= " and ((order_from='public' ";
-                $sqlWhere .= self::_airHandNew($user, "public");
+                $sqlWhere .= self::_air("public");
                 $sqlWhere .= ") or (order_from='sfs' ";
                 if (empty($user["sfs_ONLINE_USER"])) {
                     $user = $_SESSION["sfs_ONLINE_USER"];
                 }
-                $sqlWhere .= self::_airHandNew($user, "sfs");
+                $sqlWhere .= self::_air("sfs");
                 $sqlWhere .= "))";
-
-                // $sqlWhere .= self::_airHandNew($user, $schames);
             }
             
             if (strtolower($type) == "air") {
                 $sqlWhere .= " and ((order_from='public' ";
-                $sqlWhere .= self::_airHandNew($user, "public");
-                if ($company_name == "doc") {
-                    if (empty($user["view_file_format"])) {
-                        if (strtolower($user["user_type"]) == "customer") {
-                            $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true and client_display = true)";
-                        } else {
-                            $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true)";
-                        }
-                    } else {
-                        $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
-                    }
-                }
+                $sqlWhere .= self::_air($user, "public");
                 $sqlWhere .= ") or (order_from='sfs' ";
 
                 if (empty($user["sfs_ONLINE_USER"])) {
                     $user = $_SESSION["sfs_ONLINE_USER"];
                 }
-                $sqlWhere .= self::_airHandNew($user, "sfs");
-                if ($company_name == "doc") {
-                    if (empty($user["view_file_format"])) {
-                        if (strtolower($user["user_type"]) == "customer") {
-                            $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true and client_display = true)";
-                        } else {
-                            $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true)";
-                        }
-                    } else {
-                        $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
-                    }
-                }
+                $sqlWhere .= self::_air($user, "sfs");
                 $sqlWhere .= ") )";
             }
         } else {
@@ -591,7 +565,9 @@ class common {
         exit();
     }
 
-
+    /**
+     * _bookingHandNew 和 _oceanHandNew逻辑完全一样,只是ocean 多一个dest_op字段,在booking里没有的
+    */
     private static function _oceanHandNew($user, $schemas = "public") {
         $o = $user['ocean_station'];
         $o_or = $user['ocean_station_or'];
@@ -609,7 +585,6 @@ class common {
         }
         $sqlWhere = "";
         if (_isCustomerLoginHandNew($user)) {
-            //error_log("_oceanHandNew".$schemas);
             $sqlWhere .= " and " . _customerFilerSearchHandNew($user, $schemas);
         } else {
             if (empty($o) && empty($d) && empty($sales) && empty($op) && empty($follow)) {
@@ -712,10 +687,10 @@ class common {
         return $sqlWhere;
     }
 
+    /**
+     * _bookingHandNew 和 _oceanHandNew逻辑完全一样,只是ocean 多一个dest_op字段,在booking里没有的
+    */
     private static function _bookingHandNew($user, $schames) {
-        //        if (_isDemo())
-        //            return " serial_no = 'D4DD1D79-83F4-4E65-9773-CF5277D72738'";
-        
                 $o = $user['ocean_station'];
                 $o_or = $user['ocean_station_or'];
                 $d = $user['ocean_agent'];
@@ -730,25 +705,7 @@ class common {
                 if (strtolower($o_or) == "all" || strtolower($d_or) == "all" || strtolower($sales_or) == "all") {
                     return " and 1=1";
                 }
-        //        $sc_list = $user['schemas_list'];
-        //        if (empty($sc_list)) {
-        //            $sc_list = $_SESSION["schemas_list"];
-        //        }
-        //        if (empty($sc_list)) {
-        //            return " and 1<>1";
-        //        }
-        //        $sqlWhere = " and 1=1";
-        //        if ($user["is_kerry_shipment"] == "t") {
-        //            $sqlWhere = " and and is_kerry_shipment is not null and is_kerry_shipment=true";
-        //        } else if ($user["is_kerry_shipment"] == "f") {
-        //            $sqlWhere = " and (is_kerry_shipment is null or is_kerry_shipment=false)";
-        //        }
-        //        if (count($sc_list) == 1) {
-        //            $sch = $sc_list[0]['schemas_name'];
-        //            $sqlWhere .= " and order_from='$sch'";
-        //        } else {
-        //            $sqlWhere .= " and (schem_not_display is null or schem_not_display=false)";
-        //        }
+
                 $sqlWhere = "";
                 if (_isCustomerLoginHandNew($user)) {
                     $sqlWhere .= " and " . _customerFilerSearchHandNew($user, $schames);
@@ -842,115 +799,46 @@ class common {
                 return $sqlWhere;
     }
 
-    private static function _airHandNew($user, $schemas = "public") 
-    {
-        if($schemas=="public")
-        {
-            $station = $user['air_station'];
-            $station_or = $user['air_station_or'];
-     
-            $sales = $user['air_sales'];
-            $sales_or = $user['air_sales_or'];
-        }
-        else
-        {
-            $station = $user[$schemas."_ONLINE_USER"]['air_station'];
-            $station_or = $user[$schemas."_ONLINE_USER"]['air_station_or'];
-     
-            $sales = $user[$schemas."_ONLINE_USER"]['air_sales'];
-            $sales_or = $user[$schemas."_ONLINE_USER"]['air_sales_or'];
-        }
-
- 
+    /**
+     * online air
+     */
+    private static function _air($schemas = "public") {
+        $station = _getAirStation($schemas);
+        $station_or = _getAirStationOr($schemas);
+        $sales = _getAirSales($schemas);
+        $sales_or = _getAirSalesOr($schemas);
 
-        if (strtolower($station_or) == "all"  || strtolower($sales_or) == "all" ) //|| strtolower($d_or) == "all"|| strtolower($op_or) == "all"|| strtolower($follow_or) == "all"
-        {
-            return " and 1=1";
-        }
-        $sqlWhere = "";
-        if (_isCustomerLoginHandNew($user)) {
-            //error_log("_oceanHandNew".$schemas);
-            $sqlWhere .= " and " . _customerFilerSearchHandNew_Air($user, $schemas);
-        } 
-        else 
-        {
-            if (empty($station)  && empty($sales) ) //&& empty($d)&& empty($op) && empty($follow)
-            {
-                return " and 1<>1";
+        $sqlWhere = " 1=1";
+        if (_isCustomerLogin()) {
+            $sqlWhere .= " and " . _customerAirFilerSearch($schemas);
+        } else {
+            if (empty($station) && empty($sales)) {
+                return " 1<>1";
             }
-            if ((strtolower($station) == 'all' || empty($station)) ) //&& (strtolower($d) == "all" || empty($d))
-            {
-                
-            } 
-            else 
-            {
-                $sql = "1=1";
-                if (!empty($station) && strtolower($station) != 'all') {
-                    $sql .= " and (lower(origin)";
-                    $sql .= utils::getInSql($station);
-                    $sql .= " or lower(destination_station)";
-                    $sql .= utils::getInSql($station);
-                    $sql .= ")";
-                }
-                $sqlWhere .= " and (" . $sql . ")";
+            if (strtolower($station_or) == "all" || strtolower($sales_or) == "all")
+                        return $sqlWhere;
+        
+            if (strtolower($station) == 'all' || empty($station)) {
+                        
+            } else {
+                $sqlWhere .= " and (lower(origin)";
+                $sqlWhere .= utils::getInSql($station);
+                $sqlWhere .= " or lower(agent)";
+                $sqlWhere .= utils::getInSql($station);
+                $sqlWhere .= ")";
             }
             if (strtolower($sales) == 'all' || empty($sales)) {
-                
-            } else 
-            {
-                if (utils::checkExist($sales, ";")) {
-                    $sql = "1!=1";
-                    $tt = explode(";", $sales);
-                    foreach ($tt as $t) {
-                        $t = trim($t);
-                        if (!empty($t))
-                        {
-                            $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
-                            $sql .= " or lower(following_sales)='" . strtolower($t) . "'";
-
-                        }
-                    }
-                    $sqlWhere .= " and ($sql)";
-                } else
-                {
-                    $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales) . "'";
-                    $sqlWhere .= " or lower(following_sales)='" . strtolower($sales) . "'";
-                }
-
-            }
-
-           
-            $sqlWhere = " (1=1 $sqlWhere)";
-            if (!empty($station_or)) {
-                $sqlWhere .= " or lower(origin)";
-                $sqlWhere .= utils::getInSql($station_or);
-                $sqlWhere .= " or lower(destination_station)";
-                $sqlWhere .= utils::getInSql($station_or);
-            }
-            if (!empty($sales_or)) {
-                if (utils::checkExist($sales_or, ";")) {
-                    $sql = "1!=1";
-                    $tt = explode(";", $sales_or);
-                    foreach ($tt as $t) {
-                        $t = trim($t);
-                        if (!empty($t))
-                        {
-                            $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
-                            $sql .= " or lower(following_sales)='" . strtolower($t) . "'";
-                        }
-                    }
-                    $sqlWhere .= " or ($sql)";
-                } else
-                {
-                    $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "'";
-                    $sqlWhere .= " or lower(following_sales)='" . strtolower($sales_or) . "'";
-
-                }
+                        
+            } else {
+                $sqlWhere .= " and (lower(sales_rep) " . utils::getInSql($sales) . " or lower(following_sales) " . utils::getInSql($sales) . ")";
             }
-            $sqlWhere = " and ($sqlWhere)";
+            $sqlWhere = " ($sqlWhere)";
+            if (!empty($station_or))
+                $sqlWhere = "$sqlWhere or lower(origin)" . utils::getInSql($station_or) . " or lower(agent)" . utils::getInSql($station_or);
+            if (!empty($sales_or))
+                $sqlWhere = "$sqlWhere or lower(sales_rep)" . utils::getInSql($sales_or) . " or lower(following_sales)" . utils::getInSql($sales_or);
         }
-
-        return $sqlWhere;
+        return "($sqlWhere)";
     }
 
     public static function isNewVersion() {
@@ -1291,9 +1179,8 @@ class common {
     public static function getCo2eBar(){
         //新UI air sea road 目前只有sea
         $type = $_REQUEST["r_type"];
-        $shipment_mode_arr = array("air","sea","road");
 
-        $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
+        $sqlWhere = ' and ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
         $sqlWhere = " " . $sqlWhere;
 
         $date_type = strtolower($_REQUEST["date_type"]);
@@ -1301,18 +1188,31 @@ class common {
             $sqlWhere .= " and $date_type >= '" . common::usDate2sqlDate($_REQUEST['date_start']) . " 00:00:00'";
         if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end']))
             $sqlWhere .= " and $date_type <= '" . common::usDate2sqlDate($_REQUEST['date_end']) . " 23:59:59'";
+
+        $transportation = $_REQUEST["transportation"];
+        if(!is_array($transportation)){
+            $transportation = array($transportation);
+        }
+        $mode_param = "";
+        if(count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
+            $mode_param = "'sea','air','road'";         
+        }else{
+            $transport_mode = implode(';', $transportation);
+            $mode_param = common::getInNotInSqlForSearch($transport_mode);
+        }
+        $sqlWhere .= " and transport_mode in ($mode_param)";
          
         $ContainerCount_Title = array();
         //先查询总的排放量sea air road,确定排名后,在分别查询对应的sea air road 
         //这里的问题跟 top 一样 。总的排放量查询有问题。目前是总的排放量 暂时等于 sea的排放量
         if ($type == "co2e_orgin"){
             $co2e_shippr_sql = "select SUM(COALESCE(carbon_emission,0)) as catnum ,
-                shippr_uncode as station from online_ocean  where 1=1 and COALESCE(shippr_uncode,'')<>'' and carbon_emission is not null  $sqlWhere group by shippr_uncode order by catnum desc limit 10";
+                shippr_uncode as station from kln_ocean  where 1=1 and COALESCE(shippr_uncode,'')<>'' and carbon_emission is not null  $sqlWhere group by shippr_uncode order by catnum desc limit 10";
             $co2e_aLL = common::excuteListSql($co2e_shippr_sql);
         }
         if ($type == "co2e_destination"){
             $co2e_consignee_sql = "select SUM(COALESCE(carbon_emission,0)) as catnum ,
-                consignee_uncode as station from online_ocean  where 1=1 and COALESCE(consignee_uncode,'')<>'' and carbon_emission is not null $sqlWhere group by consignee_uncode order by catnum desc limit 10";
+                consignee_uncode as station from kln_ocean  where 1=1 and COALESCE(consignee_uncode,'')<>'' and carbon_emission is not null $sqlWhere group by consignee_uncode order by catnum desc limit 10";
             $co2e_aLL = common::excuteListSql($co2e_consignee_sql);
         }
         //最大Y值
@@ -1328,6 +1228,7 @@ class common {
         $station_str = utils::implode(',',$stations);
 
         $ContainerCounSeries = array();
+        $shipment_mode_arr = array("air","sea","road");
         foreach($shipment_mode_arr as $_shipment_mode){
             //类型有 sea air road,目前之类只查询sea的,其他为空
             $shipment_mode = $_shipment_mode;
@@ -1355,21 +1256,6 @@ class common {
                 $total = $total + $val['catnum'];
                 $max = $max < $val['catnum'] ? $val['catnum'] : $max;
             }
-
-            $transportation = $_REQUEST["transportation"];
-            if(!is_array($transportation)){
-                $transportation = array($transportation);
-            }
-            if(count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
-
-            }else{
-                //这里不用处理,只有sea的数据
-                if (!in_array("Sea", $transportation)){
-                    $data = array_fill_keys(array_keys($data), 0);
-                    $total = 0;
-                    $max = 0;
-                }
-            }
             $ContainerCounSeries[$shipment_mode] = array("data"=>$data,"total"=>$total,"max"=>$max);
         }
         
@@ -1394,7 +1280,7 @@ class common {
     }
 
     public static function getTopBar(){
-        $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
+        $sqlWhere = ' and ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
         $sqlWhere = " " . $sqlWhere;
 
         $date_type = strtolower($_REQUEST["date_type"]);
@@ -1402,10 +1288,23 @@ class common {
             $sqlWhere .= " and $date_type >= '" . common::usDate2sqlDate($_REQUEST['date_start']) . " 00:00:00'";
         if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end']))
             $sqlWhere .= " and $date_type <= '" . common::usDate2sqlDate($_REQUEST['date_end']) . " 23:59:59'";
+
+        $transportation = $_REQUEST["transportation"];
+        if(!is_array($transportation)){
+            $transportation = array($transportation);
+        }
+        $mode_param = "";
+        if(count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
+            $mode_param = "'sea','air','road'";         
+        }else{
+            $transport_mode = implode(';', $transportation);
+            $mode_param = common::getInNotInSqlForSearch($transport_mode);
+        }
+        $sqlWhere .= " and transport_mode in ($mode_param)";    
          
         $toporiginType = "shippr_uncode";
         $shippr_uncode_10_sql ="with aa as  (select count(shippr_uncode) as num,shippr_uncode,
-                                (array_agg(shipper_city))[1] AS shipper_city from online_ocean  
+                                (array_agg(shipper_city))[1] AS shipper_city from kln_ocean  
                         where 1=1 and COALESCE(shippr_uncode,'')<>'' $sqlWhere group by shippr_uncode order by num desc limit 10)
             select   aa.*,dd.* from  aa  
             left join LATERAL ( select lon as lng, lat as lat,
@@ -1419,7 +1318,7 @@ class common {
         if(count($shippr_uncode_10) == 1 && empty($shippr_uncode_10[0]["shippr_uncode"])){
             $toporiginType = "fport_of_loading_un";
             $shippr_uncode_10_sql = "with aa as  (select count(fport_of_loading_un) as num,fport_of_loading_un as shippr_uncode 
-                    from online_ocean where 1=1 and COALESCE(fport_of_loading_un,'')<>'' $sqlWhere group by fport_of_loading_un order by num desc limit 10)
+                    from kln_ocean where 1=1 and COALESCE(fport_of_loading_un,'')<>'' $sqlWhere group by fport_of_loading_un order by num desc limit 10)
                     select   aa.*,dd.* from  aa  
                         left join LATERAL ( select lon as lng, lat as lat,
                             '' as label, '' as infor, 3 as sort,
@@ -1432,7 +1331,7 @@ class common {
         $topdestinationinType = "consignee_uncode";
         $consignee_uncode_10_sql = "with aa as  (select count(consignee_uncode) as num,consignee_uncode,
                     (array_agg(consignee_city))[1] AS consignee_city 
-                from online_ocean  where 1=1  and COALESCE(consignee_uncode,'')<>''  $sqlWhere group by consignee_uncode order by num desc limit 10)
+                from kln_ocean  where 1=1  and COALESCE(consignee_uncode,'')<>''  $sqlWhere group by consignee_uncode order by num desc limit 10)
         select   aa.*,dd.* from  aa  
         left join LATERAL ( select lon as lng, lat as lat,
             '' as label, '' as infor, 3 as sort,
@@ -1443,7 +1342,7 @@ class common {
         //如果值没有:客户地址-->站点地址-->Port地址(POL/POD) 
         if(count($consignee_uncode_10) == 1 && empty($consignee_uncode_10[0]["consignee_uncode"])){
             $topdestinationinType = "mport_of_discharge_un";
-            $consignee_uncode_10_sql = "with aa as  (select count(mport_of_discharge_un) as num,mport_of_discharge_un as consignee_uncode from online_ocean where 1=1 and COALESCE(mport_of_discharge_un,'')<>'' $sqlWhere group by mport_of_discharge_un order by num desc limit 10)
+            $consignee_uncode_10_sql = "with aa as  (select count(mport_of_discharge_un) as num,mport_of_discharge_un as consignee_uncode from kln_ocean where 1=1 and COALESCE(mport_of_discharge_un,'')<>'' $sqlWhere group by mport_of_discharge_un order by num desc limit 10)
                 select   aa.*,dd.* from  aa  
                 left join LATERAL ( select lon as lng, lat as lat,
                     '' as label, '' as infor, 3 as sort,
@@ -1452,22 +1351,6 @@ class common {
             $consignee_uncode_10 = common::excuteListSql($consignee_uncode_10_sql);
         }
 
-        //Top查询有点问题,暂时这样查询: 理论上查询air sea road 所有数据的top 10,在更加这个top的站点,分别去查询对于mode的数据计总。
-        //但是目前只有sea, 所有模式计总 = sea计总(以后这里是要改的)
-        $transportation = $_REQUEST["transportation"];
-        if(!is_array($transportation)){
-            $transportation = array($transportation);
-        }
-        if(count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
-
-        }else{
-            //这里不用处理,只有sea的数据
-            if (!in_array("Sea", $transportation)){
-                $shippr_uncode_10 = array();
-                $consignee_uncode_10 = array();
-            }
-        }
-
         $toporigin = array();
         $toporiginMap = array();
         $i = 0;
@@ -1550,7 +1433,7 @@ class common {
     }
 
     public static function getRevenue(){
-        $data = '{"bar_title":"Total: 0","barList":["DEC,23","JAN,24","FEB,24","MAR,24","APR,24","MAY,24","JUN,24","JUL,24","AUG,24","SEP,24","OCT,24","NOV,24"],"barSeries":[{"name":"USD","type":"bar","data":[1,1,1,1,1,1,1,1,1,1,1,1],"emphasis":{"disabled":true,"focus":"none"},"itemStyle":{"color":"#FF7500","borderRadius":6},"label":{"show":false,"color":"#646A73","position":"top","fontFamily":"Lato-Light","hideWhenMouseLeave":false}},{"name":"THB","type":"bar","data":[2,2,2,2,2,2,2,2,2,2,2,2],"emphasis":{"disabled":true,"focus":"none"},"itemStyle":{"color":"#FFAC66","borderRadius":6},"label":{"show":false,"color":"#646A73","position":"top","fontFamily":"Lato-Light","hideWhenMouseLeave":false}},{"name":"SGD","type":"bar","data":[3,3,3,3,3,3,3,3,3,3,3,3],"emphasis":{"disabled":true,"focus":"none"},"itemStyle":{"color":"#FFE3CC","borderRadius":6},"label":{"show":false,"color":"#646A73","position":"top","fontFamily":"Lato-Light","hideWhenMouseLeave":false}}],"Max":5,"interval":1,"download_name":"Rvenue","isShowTooltips":true}';   
+        //$data = '{"bar_title":"Total: 0","barList":["DEC,23","JAN,24","FEB,24","MAR,24","APR,24","MAY,24","JUN,24","JUL,24","AUG,24","SEP,24","OCT,24","NOV,24"],"barSeries":[{"name":"USD","type":"bar","data":[1,1,1,1,1,1,1,1,1,1,1,1],"emphasis":{"disabled":true,"focus":"none"},"itemStyle":{"color":"#FF7500","borderRadius":6},"label":{"show":false,"color":"#646A73","position":"top","fontFamily":"Lato-Light","hideWhenMouseLeave":false}},{"name":"THB","type":"bar","data":[2,2,2,2,2,2,2,2,2,2,2,2],"emphasis":{"disabled":true,"focus":"none"},"itemStyle":{"color":"#FFAC66","borderRadius":6},"label":{"show":false,"color":"#646A73","position":"top","fontFamily":"Lato-Light","hideWhenMouseLeave":false}},{"name":"SGD","type":"bar","data":[3,3,3,3,3,3,3,3,3,3,3,3],"emphasis":{"disabled":true,"focus":"none"},"itemStyle":{"color":"#FFE3CC","borderRadius":6},"label":{"show":false,"color":"#646A73","position":"top","fontFamily":"Lato-Light","hideWhenMouseLeave":false}}],"Max":5,"interval":1,"download_name":"Rvenue","isShowTooltips":true}';   
         //return json_decode($data,true);
         $date_from = null;
         $date_to = null;
@@ -1666,12 +1549,12 @@ class common {
             "title"=>"Container Count",
             "switchValue"=>true,
             "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
-        // if(_isRevenueDisplay()){    
-        //     $Management[] = array("id"=>5 ,
-        //         "title"=>"Revenue Spent",
-        //         "switchValue"=>true,
-        //         "text"=>"Revenue data for the past 12 months."); 
-        // }   
+        if(_isRevenueDisplay()){    
+            $Management[] = array("id"=>5 ,
+                "title"=>"Revenue Spent",
+                "switchValue"=>true,
+                "text"=>"Revenue data for the past 12 months."); 
+        }   
         $Management[] = array("id"=>6 ,
             "title"=>"Top 10 Origin/Destination",
             "switchValue"=>true,
@@ -1807,7 +1690,7 @@ class common {
         return $str;
     }
 
-    public static function getMilestonesInfo($ocean,$EDI315TimeAndLocation){
+    public static function getMilestonesInfo($ocean,$transport_mode,$_schemas,$EDI315TimeAndLocation=array()){
         //Milestones info列名固定
         $Milestones_column = array();
         $Milestones_column[] = array("title" =>"Milestones","field" =>"milestones","formatter" =>"normal","type" =>"normal");
@@ -1820,13 +1703,22 @@ class common {
     
         //Milestones 数据信息待定
         $Milestones_data = array();
-        $Milestones_data_arr = common::excuteListSql("select  sn.description,act_date||' '||COALESCE(act_time,'') as date_time,
-            remark,timezone,a.code
-        from  public.ocean_milestone a  
-            inner join public.customer_service_milestone_sno sn on sn.code=a.code
-        where a.serial_no='".$ocean["serial_no"]."' and act_date is not null  order by sn.sno asc");           
+        if($transport_mode == 'sea'){
+            $Milestones_data_arr = common::excuteListSql("select  sn.description,act_date||' '||COALESCE(act_time,'') as date_time,
+                    remark,timezone,a.code
+                from  public.ocean_milestone a  
+                    inner join public.customer_service_milestone_sno sn on sn.code=a.code
+                where a.serial_no='".$ocean["serial_no"]."' and act_date is not null  order by sn.sno asc");  
+        }else{
+            $Milestones_data_arr = common::excuteListSql("select  sn.description,act_date||' '||COALESCE(act_time,'') as date_time,
+                    remark,timezone,a.code
+                from  $_schemas.air_milestone a  
+                    inner join public.customer_service_milestone_sno sn on sn.code=a.code
+                where a.serial_no='".$ocean["serial_no"]."' and act_date is not null  order by sn.sno asc");  
+        }         
         foreach($Milestones_data_arr as $mda){
             $timezone = "";
+            $IFFICC_locations ="";
             if(!empty($EDI315TimeAndLocation[$mda['code']])){
                 $edi315Info = $EDI315TimeAndLocation[$mda['code']];
                 if(!empty($edi315Info)){
@@ -2061,74 +1953,21 @@ class common {
         return $EDI315TimeAndLocation;
     }
 
-    public static function getAirSql($air_view,$type,$sql_where){
-        $r3_r4_sql = "";
-        if($type == 'ata_r3'){
-            $r3_r4_sql = "select count(1) as count, '0 Day' as distext
-                from ($air_view) aa where 1=1 $sql_where and  ata >= etd and (ata-etd) >= 0 and (ata-etd) < 1
-                union all 
-                select count(1) as count, '1-2 Days' as distext
-                from ($air_view) aa where 1=1 $sql_where and ata >= etd and (ata-etd) >= 1 and (ata-etd) < 2
-                union all 
-                select count(1) as count, '3-6 Days' as distext
-                from ($air_view) aa where 1=1 $sql_where and ata >= etd and (ata-etd) >= 2 and (ata-etd) < 6
-                union all 
-                select count(1) as count, '7 Days' as distext
-                from ($air_view) aa where 1=1 $sql_where and ata >= etd and (ata-etd) >= 6";
-        }
-        if($type == 'atd_r4'){
-        $r3_r4_sql ="select count(1) as count, ''0 Day'' as distext
-			from ($air_view) aa where 1=1 $sql_where and  atd >= etd and (atd-etd) >= 0 and (atd-etd) < 1
-			union all 
-			select count(1) as count, ''1-2 Days'' as distext
-			from ($air_view) aa where 1=1 $sql_where and atd >= etd and (atd-etd) >= 1 and (atd-etd) < 2
-			union all 
-			select count(1) as count, ''3-6 Days'' as distext
-			from ($air_view) aa where 1=1 $sql_where and atd >= etd and (atd-etd) >= 2 and (atd-etd) < 6
-			union all 
-			select count(1) as count, ''7 Days'' as distext
-			from ($air_view) aa where 1=1 $sql_where and and atd >= etd and (atd-etd) >= 6";
-        }
-        return $r3_r4_sql;
-    }
-
-    public static function getTopBarSQL($toporiginType,$transportation,$sqlWhere,$air_v){
+    public static function getDashboardTransportationSqlWhere(){
+        $transportation = $_REQUEST["transportation"];
         if(!is_array($transportation)){
             $transportation = array($transportation);
         }
+        $mode_param = "";
         if(count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
-            $transportation = array("Ocean","Air","Road");
-        }
-        //处理生成TopBarSQL
-        $_tmp_table = "";
-        foreach($transportation as $mode){
-            if($mode == "Ocean"){
-                if(empty($_tmp_table)){
-                    $_tmp_table .= "select shippr_uncode,shipper_city from online_ocean where 1=1 and COALESCE(shippr_uncode,'')<>'' $sqlWhere";
-                }else{
-                    $_tmp_table .= "union all select shippr_uncode,shipper_city from online_ocean where 1=1 and COALESCE(shippr_uncode,'')<>'' $sqlWhere";
-                }
-            }
-            if($mode == "Air"){
-                if(empty($_tmp_table)){
-                    $_tmp_table .= "select shippr_uncode,shipper_city from $air_v where 1=1 and COALESCE(shippr_uncode,'')<>'' $sqlWhere";
-                }else{
-                    $_tmp_table .= "union all select shippr_uncode,shipper_city from $air_v where 1=1 and COALESCE(shippr_uncode,'')<>'' $sqlWhere";
-                }
-            }
-            if($mode == "Road"){
-                
-            }
+            $mode_param = "'sea','air','road'";         
+        }else{
+            $transport_mode = implode(';', $transportation);
+            $mode_param = common::getInNotInSqlForSearch($transport_mode);
         }
-        //虽然air 没有地图信息,但是坐标查询为空的过滤掉
-        $TopBarSQL =  "with aa as  (select count(shippr_uncode) as num,shippr_uncode,
-                                (array_agg(shipper_city))[1] AS shipper_city from ($_tmp_table) as _tmp  group by shippr_uncode order by num desc limit 10)
-            select   aa.*,dd.* from  aa  
-            left join LATERAL ( select lon as lng, lat as lat,
-                '' as label, '' as infor, 3 as sort,
-                null::timestamp without time zone as stime,''::text as ptype 
-            from vessel.vt_unlocode where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=aa.shippr_uncode ) dd on true";
-        return  $TopBarSQL;
+        return " and transport_mode in ($mode_param)";
     }
+
+
 }
 ?>

+ 33 - 10
utils/utils.class.php

@@ -374,8 +374,8 @@ class utils {
         if(!isset($_SESSION['ONLINE_USER'])){
             $user_type = common::excuteOneSql("select user_type from public.ra_online_user u where lower(user_login) = '" . strtolower($user_name) . "'");
         }
-
-        $operateInfo = utils::getPageByAction($_REQUEST["action"],$_REQUEST["operate"],$_REQUEST["model_name"]);
+        
+        $operateInfo = utils::getPageByAction($_REQUEST["action"],$_REQUEST["operate"]);
         $page = $operateInfo["page"];
         $operation = $operateInfo["operate"];
         $operation_detail = utils::analyzeOperationDetail($_REQUEST["action"],$_REQUEST["operate"]);
@@ -396,7 +396,7 @@ class utils {
         }
     }
 
-    public static function getPageByAction($action,$operate,$model_name){
+    public static function getPageByAction($action,$operate){
         //取消
         $operationConvertName = array(
             "login=do_login" => array("page" =>"Login","operate"=>"Login"),
@@ -405,6 +405,8 @@ class utils {
             "login=update_pwd_expires" => array("page" =>"Login","operate"=>"Reset password"),
             "ocean_booking=search" => array("page" =>"Booking","operate"=>"Search"),
             "Booking_Search=save_setting_display" => array("page" =>"Booking","operate"=>"Customize Coulumns"),
+            "booking=autody" => array("page" =>"Booking","operate"=>"More Filter"),
+            "booking=autoport" => array("page" =>"Booking","operate"=>"More Filter"),
             "ocean_booking=detail" => array("page" =>"Booking","operate"=>"Open Detailed Page"),
             "ocean_booking=excel" => array("page" =>"Booking","operate"=>"Download"),
             "ocean_booking=save_communication" => array("page" =>"Booking","operate"=>"Send Email"),
@@ -413,14 +415,25 @@ class utils {
             "login=tracking_checked" => array("page" =>"Tracking","operate"=>"Public tracking"),
             "ocean_order=search" => array("page" =>"Tracking","operate"=>"Search"),
             "Ocean_Search=save_setting_display" => array("page" =>"Tracking","operate"=>"Customize Coulumns"),
+            "tracking=autody" => array("page" =>"Tracking","operate"=>"More Filter"),
+            "tracking=autoport" => array("page" =>"Tracking","operate"=>"More Filter"),
             "ocean_order=detail" => array("page" =>"Tracking","operate"=>"Open Detailed Page"),
             "ocean_order=excel" => array("page" =>"Tracking","operate"=>"Download"),
-            "ocean_booking=save_communication" => array("page" =>"Tracking","operate"=>"Send Email"),
-            "ocean_booking=ams_isf_log" => array("page" =>"Tracking","operate"=>"AMS/ISF"),
+            "ocean_order=download" => array("page" =>"Tracking","operate"=>"Download"),
+            "ocean_order=save_communication" => array("page" =>"Booking","operate"=>"Send Email"),
+            "ocean_order=ams_isf_log" => array("page" =>"Tracking","operate"=>"AMS/ISF"),
+            "ocean_order=ocean_vgm" => array("page" =>"Tracking","operate"=>"Enter VGM"),
+            "ocean_order=save_ocean_vgm" => array("page" =>"Tracking","operate"=>"Save VGM"),
+            "ocean_order=share_shipment" => array("page" =>"Tracking","operate"=>"Share shipment"),
 
             "tools=mark_save" => array("page" =>"Tools","operate"=>"Mark_Save"),
             "password=" => array("page" =>"Profile","operate"=>"Change password"));
         if($action == "ajax" && $operate == "save_setting_display"){
+            $model_name = $_REQUEST['model_name'];
+            return $operationConvertName[$model_name."=".$operate];
+        }
+        if($action == "ajax" && ($operate == "autody" || $operate == "autoport")){
+            $model_name = $_REQUEST['search_mode'];
             return $operationConvertName[$model_name."=".$operate];
         }    
         return $operationConvertName[$action."=".$operate];
@@ -512,11 +525,23 @@ class utils {
             $detail = urldecode($text);  
         }
         if(($action == "ocean_order") && $operate == "ams_isf_log"){
-            $detail = "AMS/ISF";  
+            $detail = "Enter AMS/ISF Page";  
         }
         if(($action == "ocean_booking" || $action == "ocean_order") && $operate == "excel"){
             $detail = "Filter_condition:" . $_REQUEST['excel_filter_condition']." Selected Fields:". $_REQUEST['selected_fields'];
         }
+        //Tracking詳情頁download的file(顯示file名稱)
+        if(($action == "ocean_order") && $operate == "download"){
+            $filename = common::deCode($_GET['url'], 'D');
+            $filename = str_replace("/", DIRECTORY_SEPARATOR, $filename);
+            $filename = str_replace("\\", DIRECTORY_SEPARATOR, $filename);
+            $display_name = basename($filename);
+            if (!file_exists($filename)){
+                $detail = "Tracking Detail Attachment Download But File Not Exist : $display_name";
+            }else{
+                $detail = "Tracking Detail Attachment Download: $display_name";
+            }
+        }
         return $detail;
 
     }
@@ -589,14 +614,12 @@ class utils {
 
         $shipment_mode_where = " 1=1 ";
         //这里处理为空,目前没有数据
-        if($shipment_mode == "air" || $shipment_mode == "road"){
-            $shipment_mode_where = " 1<>1 ";
-        }
+        $shipment_mode_where = " transport_mode = '$shipment_mode' ";
         $shipment_mode_where .= $sqlWhere;
         foreach ($ids_arr as $value) {
             if (!empty($value)) {
                 if (empty($sql)) {
-                    $sql .= "SELECT $str FROM online_ocean  where $shipment_mode_where  and $filed = '$value'";
+                    $sql .= "SELECT $str FROM kln_ocean  where $shipment_mode_where  and $filed = '$value'";
                 } else {
                     $sql .= " union all SELECT $str from online_ocean  where $shipment_mode_where and $filed = '$value'";
                 }