ShuanghongS 1 år sedan
förälder
incheckning
533f5aacb0

+ 8 - 20
main_new_version.php

@@ -460,27 +460,15 @@ switch ($action) {
                     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 status,
+	    	            WHEN (m_iffbcf is not null and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Created'::text
+                        WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Cargo Received'::text
+                        WHEN (m_iffdep is not null and m_iffarr is null and m_iffafd is null) THEN 'Departed'::text
+                        WHEN (m_iffarr is not null and m_iffafd is null) THEN 'Arrived'::text
+                        WHEN (m_iffafd is not null) THEN 'Completed'::text
+	    	            ELSE 'Created'
+		            END AS new_status,
                     dd.act_date,dd.description,dd.timezone,dd.act_time
                     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 'Departed'
-                                    when a.code='IFFARR' then 'Arrived'
-                                    when a.code='IFFAFD' then 'Completed'
-                                    else 'Created' END as status,
-                                    act_date,act_time,
-                                    case when a.code = 'IFFECP' then 'Empty Container Pickup' else _dd.description end as description,
-                                    timezone
-                            from  ocean_milestone a 
-                                    left join LATERAL (select sno,description  from  milestone where code=a.code and project_no = '*' 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,IFFAFD', ','))
-                        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;
@@ -502,7 +490,7 @@ switch ($action) {
                     "endStation"=>$value['mport_of_discharge_un'],
                     "ETD"=>$value['etd'],
                     "ETA"=>$value['eta'],
-                    "type"=>$value['status'],
+                    "type"=>$value['new_status'],
                     "Arrived"=>$Arrived,
                     "Time"=>$value["act_date"],
                     "act_time" =>$value["act_time"],

+ 43 - 19
service/ajax.class.php

@@ -461,11 +461,13 @@ class ajax {
             $sqlWhere = $this->getBookingSearchWhere();
             $count_sql = "select COUNT(DISTINCT shipper_city)
                 from public.online_booking $sqlWhere 
+                    and COALESCE(shippr_uncode)<>''
                     and  (shipper_city ilike '" . common::check_input($term) . "%' 
                     or shippr_uncode ilike '" . common::check_input($term) . "%') ";
 
             $sql = "select DISTINCT ON (shipper_city) left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode 
                 from public.online_booking $sqlWhere 
+                    and COALESCE(shippr_uncode)<>''
                     and  (shipper_city ilike '" . common::check_input($term) . "%' 
                     or shippr_uncode ilike '" . common::check_input($term) . "%') ";
             return  array("count_sql"=>$count_sql,"sql"=>$sql);      
@@ -474,12 +476,14 @@ 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.online_booking $sqlWhere
+                    and COALESCE(consignee_uncode)<>'' 
                     and  (consignee_city ilike '" . common::check_input($term) . "%' 
                     or consignee_uncode ilike '" . common::check_input($term) . "%') ";
 
             $sql = "select DISTINCT ON (consignee_city) left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode 
-                from public.online_booking $sqlWhere 
+                from public.online_booking $sqlWhere
+                    and COALESCE(consignee_uncode)<>'' 
                     and  (consignee_city ilike '" . common::check_input($term) . "%' 
                     or consignee_uncode ilike '" . common::check_input($term) . "%')";
             return  array("count_sql"=>$count_sql,"sql"=>$sql);
@@ -488,12 +492,14 @@ 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.online_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 DISTINCT ON (place_of_receipt_exp) 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.online_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) . "%')";
             return  array("count_sql"=>$count_sql,"sql"=>$sql);
@@ -502,12 +508,14 @@ 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.online_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 DISTINCT ON (fport_of_loading_exp) 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.online_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) . "%')";
             return  array("count_sql"=>$count_sql,"sql"=>$sql);
@@ -516,12 +524,14 @@ 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.online_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 DISTINCT ON (place_of_delivery_exp) 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.online_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) . "%')";
 
@@ -534,21 +544,25 @@ class ajax {
           
             $count_sql = "select COUNT(DISTINCT city) from (select left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
                 from public.online_ocean $sqlWhere 
+                    and COALESCE(shippr_uncode)<>''
                     and  (shipper_city ilike '" . common::check_input($term) . "%' 
                     or shippr_uncode ilike '" . common::check_input($term) . "%') 
                 union
                     select left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
-                from public.online_ocean $sqlWhere 
+                from public.online_ocean $sqlWhere
+                    and COALESCE(consignee_uncode)<>'' 
                     and  (consignee_city ilike '" . common::check_input($term) . "%' 
                     or consignee_uncode ilike '" . common::check_input($term) . "%')) as temp";
 
             $sql = "select * from(select DISTINCT ON (shipper_city)  left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
-                from public.online_ocean $sqlWhere 
+                from public.online_ocean $sqlWhere
+                    and COALESCE(shippr_uncode)<>'' 
                     and  (shipper_city ilike '" . common::check_input($term) . "%' 
                     or shippr_uncode ilike '" . common::check_input($term) . "%') 
                 union
                     select DISTINCT ON (consignee_city) left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
-                from public.online_ocean $sqlWhere 
+                from public.online_ocean $sqlWhere
+                    and COALESCE(consignee_uncode)<>''  
                     and  (consignee_city ilike '" . common::check_input($term) . "%' 
                     or consignee_uncode ilike '" . common::check_input($term) . "%')) as temp";
             return  array("count_sql"=>$count_sql,"sql"=>$sql);        
@@ -557,12 +571,14 @@ class ajax {
         if($search_field == "Destination" && $search_mode == "tracking"){
             $sqlWhere = $this->getTrackingSearchWhere();
             $count_sql = "select COUNT(DISTINCT final_desination_exp)
-                from public.online_ocean $sqlWhere 
+                from public.online_ocean $sqlWhere
+                    and COALESCE(final_desination_uncode)<>'' 
                     and  (final_desination_exp ilike '" . common::check_input($term) . "%' 
                     or final_desination_uncode ilike '" . common::check_input($term) . "%')";
 
             $sql = "select DISTINCT ON (final_desination_exp) left(final_desination_uncode, 2) as country,final_desination_exp as city, final_desination_uncode as uncode
-                from public.online_ocean $sqlWhere 
+                from public.online_ocean $sqlWhere
+                    and COALESCE(final_desination_uncode)<>'' 
                     and  (final_desination_exp ilike '" . common::check_input($term) . "%' 
                     or final_desination_uncode ilike '" . common::check_input($term) . "%')";
             return  array("count_sql"=>$count_sql,"sql"=>$sql);             
@@ -571,12 +587,14 @@ 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.online_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 DISTINCT ON (place_of_receipt_exp) 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.online_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) . "%')";
             return  array("count_sql"=>$count_sql,"sql"=>$sql);          
@@ -586,11 +604,13 @@ class ajax {
             $sqlWhere = $this->getTrackingSearchWhere();
             $count_sql = "select COUNT(DISTINCT port_of_loading)
                 from public.online_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 DISTINCT ON (port_of_loading) 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.online_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) . "%')";
             return  array("count_sql"=>$count_sql,"sql"=>$sql);
@@ -599,12 +619,14 @@ 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.online_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 DISTINCT ON (port_of_discharge) left(mport_of_discharge_un, 2) as country,port_of_discharge as city, mport_of_discharge_un as uncode
                 from public.online_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) . "%')";
             return  array("count_sql"=>$count_sql,"sql"=>$sql);        
@@ -613,12 +635,14 @@ 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.online_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 DISTINCT ON (place_of_delivery_exp) 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.online_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) . "%')";
             return  array("count_sql"=>$count_sql,"sql"=>$sql);        

+ 2 - 2
service/column.class.php

@@ -20,8 +20,8 @@ class column {
         $data = array();
         //判断是否重置
         if(!empty($_REQUEST['reset']) && $_REQUEST['reset'] == "yes"){
-            common::excuteUpdateSql("update ra_online_search_display_config_cso set ids = '' 
-                 where lower(login_name)='" . strtolower(_getLoginName()) . "' and lower(model_name) = '" . strtolower($model_name) . "'");
+            // common::excuteUpdateSql("update ra_online_search_display_config_cso set ids = '' 
+            //      where lower(login_name)='" . strtolower(_getLoginName()) . "' and lower(model_name) = '" . strtolower($model_name) . "'");
         }
         if (empty($type)) {
             $allData = $this->getDisplayColumnAllReomveDefault($model_name);

+ 28 - 36
service/login.class.php

@@ -1161,25 +1161,19 @@ class login {
     private function getTrackingInfo($reference_number){
         $sql = "SELECT o.* ,sh.*, cn.* ,aa.*,dd.*,
                 oo.*,
-                CASE
-	    	        WHEN cc.status is null THEN 'Created'::text
-	    	        ELSE cc.status::text
-		        END AS new_status
                 from public.ocean o 
-                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 'Departed'
-                                when a.code='IFFARR' then 'Arrived'
-                                when a.code='IFFAFD' then 'Completed'
-                                else 'Created' END as status
-                        from  ocean_milestone a 
-                where a.serial_no=o.serial_no 
-                    and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
-                    and a.act_date is not null
-                order by id desc limit 1) cc on true
-                LEFT JOIN LATERAL ( SELECT incoterms as incoterms,shippr_uncode,shipper_city,
-                    consignee_uncode,consignee_city,fport_of_loading_un,mport_of_discharge_un
+                LEFT JOIN LATERAL ( SELECT incoterms as incoterms,tracking_no as _tracking_no,
+                    shippr_uncode,shipper_city,
+                    consignee_uncode,consignee_city,
+                    fport_of_loading_un,mport_of_discharge_un,
+                    CASE
+                        WHEN (m_iffbcf is not null and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Created'::text
+                        WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Cargo Received'::text
+                        WHEN (m_iffdep is not null and m_iffarr is null and m_iffafd is null) THEN 'Departed'::text
+                        WHEN (m_iffarr is not null and m_iffafd is null) THEN 'Arrived'::text
+                        WHEN (m_iffafd is not null) THEN 'Completed'::text
+                        ELSE 'Created'::text
+                    END AS new_status
                 FROM online_ocean  WHERE online_ocean.serial_no = o.serial_no) oo ON true
                 LEFT JOIN LATERAL ( SELECT company as cn_company,
                     address_1 as cn_address_1,
@@ -1242,8 +1236,8 @@ class login {
         $codeinfo = common::getCityPortsInfo($uncodes);
 
         //处理transportInfo信息数据
-        $transportInfo = array("Tracking No." =>$ocean['tracking_no'],"status"=>$ocean['new_status'],"mode" => "Ocean Freight",
-            "origin" =>$ocean['origin_station'],"destination" =>$ocean['destination_station'],
+        $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'],
             "etd_timezone" =>$codeinfo[$ocean['fport_of_loading_un']],
             "atd_timezone" =>$codeinfo[$ocean['fport_of_loading_un']],
@@ -1321,23 +1315,21 @@ class login {
     }
 
     private function trackingSfsSql($reference_number){
-        $sql = "SELECT o.* ,sh.*, cn.* ,aa.*,dd.* ,
-                CASE
-	    	        WHEN cc.status is null THEN 'Created'::text
-	    	        ELSE cc.status::text
-		        END AS new_status
+        $sql = "SELECT o.* ,sh.*, cn.* ,aa.*,dd.*,oo.*
             from sfs.ocean o 
-            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 'Departed'
-                            when a.code='IFFARR' then 'Arrived'
-                            when a.code='IFFAFD' then 'Completed'
-                            else 'Created' END as status
-                    from  ocean_milestone a 
-            where a.serial_no=o.serial_no 
-                and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
-            order by id desc limit 1) cc on true
+            LEFT JOIN LATERAL ( SELECT incoterms as incoterms,tracking_no as _tracking_no,
+                    shippr_uncode,shipper_city,
+                    consignee_uncode,consignee_city,
+                    fport_of_loading_un,mport_of_discharge_un,
+                    CASE
+                        WHEN (m_iffbcf is not null and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Created'::text
+                        WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Cargo Received'::text
+                        WHEN (m_iffdep is not null and m_iffarr is null and m_iffafd is null) THEN 'Departed'::text
+                        WHEN (m_iffarr is not null and m_iffafd is null) THEN 'Arrived'::text
+                        WHEN (m_iffafd is not null) THEN 'Completed'::text
+	    	        ELSE 'Created'::text
+		        END AS new_status
+                FROM online_ocean  WHERE online_ocean.serial_no = o.serial_no) oo ON true
             LEFT JOIN LATERAL ( SELECT company as cn_company,
                 address_1 as cn_address_1,
                 address_2 as cn_address_2,

+ 61 - 33
service/ocean_booking.class.php

@@ -152,7 +152,10 @@ class ocean_booking {
                 $sqlWhere .= " and ($more_sql)";
             } 
         } 
+        //为了移除filterTag条件
         $sqlWhere_befrom_filterTag  = $sqlWhere;
+
+        $filterTag_param = "";
         //前端提交是数组
         if (!empty($_POST['filterTag']) && utils::count($_POST['filterTag']) < 4) {
             if (utils::count($_POST['filterTag']) == 1){
@@ -161,55 +164,48 @@ class ocean_booking {
                 $filterTag = utils::implode(",", $_POST['filterTag']);
             }
             $_sqlwhere = "1<>1";
+            $filterTag_param = "1<>1";
             if (stripos($filterTag, "Confirmed") !== FALSE) {
                 $_sqlwhere .= " or (bol_type = 'BOOKING' and status!='Cancelled')";
+                $filterTag_param .= " or (bol_type = 'BOOKING' and status!='Cancelled')";
             }
             if (stripos($filterTag, "type2") !== FALSE) {
                 $_sqlwhere .= " or (bol_type != 'BOOKING' and booking_no is not null and booking_no <> '')";
+                $filterTag_param .= " or (bol_type != 'BOOKING' and booking_no is not null and booking_no <> '')";
             }
             if (stripos($filterTag, "Cancelled") !== FALSE) {
                 $_sqlwhere .= " or (status='Cancelled')";
+                $filterTag_param .= " or (status='Cancelled')";
             }
             if (stripos($filterTag, "Created") !== FALSE) {
                 $_sqlwhere .= " or (bol_type != 'BOOKING' and (booking_no is null or booking_no = ''))";
+                $filterTag_param .= " or (bol_type != 'BOOKING' and (booking_no is null or booking_no = ''))";
             }
             if(strtolower($filterTag) <> "all" && !empty($filterTag)){
                 $sqlWhere .= " and ($_sqlwhere)";
+                $filterTag_param = " ($filterTag_param)";
             }
         }
+        if(empty($filterTag_param)){
+            $filterTag_param = "1=1";
+        }
+
         $rc = $_POST ['rc'];
         //这里都要查询,除非多传几个参数回来
         if ($rc == - 1 || true) {
-            //查询 earch ALL
-            $sql = "SELECT count(1) from public.online_booking" . $sqlWhere;
-            $seach_rc = common::excuteOneSql($sql);
-            error_log("online_booking_count_ALL_SQL: ".$sql);
-
-            //移除filterTag
-            $sqlWhere_bk = $sqlWhere_befrom_filterTag;
-
-            //查询 ALL
-            $sql = "SELECT count(1) from public.online_booking" . $sqlWhere_bk;
-            $rc = common::excuteOneSql($sql);
-            error_log("online_booking_count_ALL_SQL: ".$sql);
-            
-            //查询Creatd
-            $Creatd_sqlWhere = " and (1<>1 or (bol_type != 'BOOKING' and (booking_no is null or booking_no = '')))";
-            $Creatd_sql = "SELECT count(1) from public.online_booking" . $sqlWhere_bk.$Creatd_sqlWhere;
-            $Creatd = common::excuteOneSql($Creatd_sql);
-            error_log("online_booking_count_Creatd_SQL: ".$sql);
-
-            //查询Confirmed
-            $Confirmed_sqlWhere = " and (1<>1 or (bol_type = 'BOOKING' and status!='Cancelled'))";
-            $Confirmed_sql = "SELECT count(1) from public.online_booking" . $sqlWhere_bk.$Confirmed_sqlWhere;
-            $Confirmed = common::excuteOneSql($Confirmed_sql);
-            error_log("online_booking_count_Confirmed_SQL: ".$sql);
-
-            //查询Concelled
-            $Concelled_sqlWhere = " and (1<>1 or (status='Cancelled'))";
-            $Concelled_sql = "SELECT count(1) from public.online_booking" . $sqlWhere_bk.$Concelled_sqlWhere;
-            $Concelled = common::excuteOneSql($Concelled_sql);
-            error_log("online_booking_count_Concelled_SQL: ".$sql);
+            $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 (bol_type != 'BOOKING' and (booking_no is null or booking_no = ''))) then 1 else 0 end) as creatd,
+                sum(case when (1<>1 or (bol_type = 'BOOKING' and status!='Cancelled')) 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;
+
+            $sql_all_status_data = common::excuteObjectSql($sql_all_status);
+            $seach_rc = $sql_all_status_data['seach_rc'];
+            $rc = $sql_all_status_data['rc'];
+            $Creatd = $sql_all_status_data['creatd'];
+            $Confirmed = $sql_all_status_data['confirmed'];
+            $Concelled = $sql_all_status_data['concelled'];
 
             //前端数据返回,不管有无数据
             if (!empty($_POST["filterTag"])) {
@@ -417,6 +413,12 @@ class ocean_booking {
         }
 
         //$packing = array("Quantity/Unit"=>"47 CTN","G. Weight" => "480.25 KGS","Ch. Weight" => "689.26 KGS","Volume" => "3.801 CBM");
+        $g_weight_tolal = sprintf("%.3f", $g_weight_tolal);
+        if (!empty($ocean['_booking_no'])) {
+            $cbm_tolal = sprintf("%.3f", $cbm_tolal);
+        }else{
+            $cbm_tolal = sprintf("%.4f", $cbm_tolal);
+        }
         $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $g_weight_tolal." KGS","Volume" => $cbm_tolal." CBM");
         
         //处理邮件信息返回
@@ -447,9 +449,35 @@ class ocean_booking {
         $sql = common::deCode($_POST ['tmp_search'], 'D');
         $sql = substr($sql, 0, strripos($sql, " limit"));
         if(!empty($sql)){
-            $rss = common::excuteListSql($sql);
+            $rs = common::excuteListSql($sql);
+        }
+        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']);
+            }
+            //合并显示 voyage
+            if(array_key_exists("f_voyage", $val)){
+                $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"){
+                $status = "Created";
+            }
+            if ($val['color'] == "FFFF0000"){
+                $status = "Cancelled";
+            }
+            $rs[$index]["Status"] = $status;
+            $rs[$index]["Transportation Mode"] = "Ocean Freight";
         }
-        common::echo_json_encode(200,array("msg"=>"success","Data" => $rss));
+        common::echo_json_encode(200,array("msg"=>"success","Data" => $rs));
         exit;
     }
 
@@ -512,7 +540,7 @@ class ocean_booking {
         $codeinfo = common::getCityPortsInfo($uncodes);
         //处理transportInfo信息数据
         $transportInfo = array("bookingNo." =>$ocean['booking_no'],"status"=>$status,"mode" => "Ocean Freight",
-            "origin" =>$ocean['origin_station'],"destination" =>$ocean['destination_station'],
+            "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
             "etd" =>$ocean['f_etd'],"atd" =>$ocean['atd'],
             "etd_timezone" =>$codeinfo[$ocean['fport_of_loading_uncode']],
             "atd_timezone" =>$codeinfo[$ocean['fport_of_loading_uncode']],

+ 90 - 194
service/ocean_order.class.php

@@ -395,6 +395,7 @@ class ocean_order {
                 $sqlWhere .= " and ($more_sql)";
             } 
         }
+        //移除filterTag
         $sqlWhere_befrom_filterTag  = $sqlWhere;
         
         //查询tag
@@ -404,6 +405,7 @@ class ocean_order {
         // IFFDEP  Departure                                 Departed
         // IFFARR  Arrived at Final Destination Port         Arrived
         // IFFAFD  Arrived at Final Destination              Completed
+        $filterTag_param = "";
         if (!empty($_POST["filterTag"])) {
             if (utils::count($_POST['filterTag']) == 1){
                 $filterTag = $_POST['filterTag'][0];
@@ -412,84 +414,77 @@ class ocean_order {
             }
 
             $_sqlwhere = "1<>1";
+            $filterTag_param = "1<>1";
             if (stripos($filterTag, "Created") !== FALSE) {
-                $_sqlwhere .= " or (dd.new_status = 'Created' or dd.new_status is null)";
+                $_sqlwhere .= " or (m_iffbcf is not null and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null)";
+                $filterTag_param .= " or (m_iffbcf is not null and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null)";
             }
             if (stripos($filterTag, "Cargo Received") !== FALSE) {
-                $_sqlwhere .= " or (dd.new_status = 'Cargo Received')";
+                $_sqlwhere .= " or ((m_iffcpu is not null or m_iffrec is not null) and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null)";
+                $filterTag_param .= " or ((m_iffcpu is not null or m_iffrec is not null) and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null)";
             }
             if (stripos($filterTag, "Departure") !== FALSE) {
-                $_sqlwhere .= " or (dd.new_status = 'Departed')";
+                $_sqlwhere .= "or (m_iffdep is not null and m_iffarr is null and m_iffafd is null)";
+                $filterTag_param .= "or (m_iffdep is not null and m_iffarr is null and m_iffafd is null)";
             }
             if (stripos($filterTag, "Arrived") !== FALSE) {
-                $_sqlwhere .= " or (dd.new_status = 'Arrived')";
+                $_sqlwhere .= " or (m_iffarr is not null and m_iffafd is null)";
+                $filterTag_param .= " or (m_iffarr is not null and m_iffafd is null)";
             }
             if (stripos($filterTag, "Completed") !== FALSE) {
-                $_sqlwhere .= " or (dd.new_status = 'Completed')";
+                $_sqlwhere .= " or (m_iffafd is not null)";
+                $filterTag_param .= " or (m_iffafd is not null)";
             }
             if(strtolower($filterTag) <> "all" && !empty($filterTag)){
                 $sqlWhere .= " and ($_sqlwhere)";
+                $filterTag_param = " ($filterTag_param)";
             }
         }
+        if(empty($filterTag_param)){
+            $filterTag_param = "1=1";
+        }
 
         $rc = $_POST ['rc'];
         //这里都要查询,除非多传几个参数回来
         if ($rc == - 1 || true) {
-            $sql = $this->getOcanOrderSearchSql("All",$sqlWhere);    
-            $search_rc = common::excuteOneSql($sql);
-            error_log("online_ocean_count_ALL_Search_SQL:".$sql);
-
-            //移除filterTag
-            $sqlWhere_bk = $sqlWhere_befrom_filterTag;
-
-            //后端带入Incoterms/Service
-            $incoterms_sql = "select DISTINCT incoterms from online_ocean" . $sqlWhere_bk; 
-            $incoterms = common::excuteListSql($incoterms_sql);
+            $sql = "select count(1) as rc,
+                sum(case when $filterTag_param then 1 else 0 end) as seach_rc, 
+                sum(case when (m_iffbcf is not null and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null)
+                     then 1 else 0 end) 
+                as created, 
+                sum(case when ((m_iffcpu is not null or m_iffrec is not null) and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null)
+                     then 1 else 0 end) 
+                as cargo_received,
+                sum(case when (m_iffdep is not null and m_iffarr is null and m_iffafd is null) then 1 else 0 end) as departed,
+                sum(case when (m_iffarr is not null and m_iffafd is null) then 1 else 0 end) as arrived,
+                sum(case when (m_iffafd 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;
+            error_log("online_ocean_search_All_Status: ".$sql);
+
+            $sql_all_status_data = common::excuteObjectSql($sql);
+            $incoterms = explode("<$>", $sql_all_status_data['incoterm_str']);
             $IncotermsList = array();
             foreach($incoterms as $terms){
                 if(!empty($terms['incoterms'])){
                     $IncotermsList[] = array("name"=>$terms['incoterms'],"checked"=>false);
                 }
             }
-
-            $service_sql = "select DISTINCT service from online_ocean" . $sqlWhere_bk; 
-            $service = common::excuteListSql($service_sql);
+            $service = explode("<$>", $sql_all_status_data['service_str']);
             $ServiceList = array();
             foreach($service as $_service){
                 if(!empty($_service['service'])){
                     $ServiceList[] = array("name"=>$_service['service'],"checked"=>false);
                 }
             }
-
-
-            $sql = $this->getOcanOrderSearchSql("All",$sqlWhere_bk);    
-            $rc = common::excuteOneSql($sql);
-            error_log("online_ocean_count_ALL_SQL:".$sql);
-
-            //Created
-            $sql = $this->getOcanOrderSearchSql("Created",$sqlWhere_bk);
-            $Created = common::excuteOneSql($sql);
-            error_log("online_ocean_count_Created_SQL: ".$sql);
-
-            //Cargo Received
-            $sql = $this->getOcanOrderSearchSql("Cargo Received",$sqlWhere_bk);
-            $Cargo_Received = common::excuteOneSql($sql);
-            error_log("online_ocean_count_Cargo_Received_SQL: ".$sql);
-
-            //Departed
-            $sql = $this->getOcanOrderSearchSql("Departed",$sqlWhere_bk);
-            $Departed = common::excuteOneSql($sql);
-            error_log("online_ocean_count_Departed_SQL: ".$sql);
-
-            //Arrived
-            $sql = $this->getOcanOrderSearchSql("Arrived",$sqlWhere_bk);
-            $Arrived = common::excuteOneSql($sql);
-            error_log("online_ocean_count_Arrived_SQL: ".$sql);
-
-            //Completed
-            $sql = $this->getOcanOrderSearchSql("Completed",$sqlWhere_bk);
-            $Completed = common::excuteOneSql($sql);
-            error_log("online_ocean_count_Completed_SQL: ".$sql);
+            $rc = $sql_all_status_data['rc'];
+            $search_rc = $sql_all_status_data['seach_rc'];
+            $Created = $sql_all_status_data['created'];
+            $Cargo_Received = $sql_all_status_data['cargo_received'];
+            $Departed = $sql_all_status_data['departed'];
+            $Arrived = $sql_all_status_data['arrived'];
+            $Completed = $sql_all_status_data['completed'];
             
             if (!empty($_POST["filterTag"])) {
                 $tagsList = array(array("name"=>"All","number"=>intval($rc),"type"=>"all","checked"=>utils::in_array('All', $_POST["filterTag"])? true : false),
@@ -535,26 +530,17 @@ class ocean_order {
             $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 = online_ocean.serial_no) aa ON true ";
 
-            $ocean_status_sql = " 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 'Departed'
-                                    when a.code='IFFARR' then 'Arrived'
-                                    when a.code='IFFAFD' then 'Completed'
-                                    else 'Created' END as new_status
-                            from  ocean_milestone a 
-                    where a.serial_no=online_ocean.serial_no 
-                        and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
-                        and a.act_date is not null
-                    order by id desc limit 1) dd ON true ";
-
             $sql = "SELECT order_from as _schemas,serial_no as __serial_no, serial_no,
                     h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,
                     CASE
-	    	            WHEN dd.new_status is null THEN 'Created'::text
-	    	            ELSE dd.new_status::text
+	    	            WHEN (m_iffbcf is not null and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Created'::text
+                        WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Cargo Received'::text
+                        WHEN (m_iffdep is not null and m_iffarr is null and m_iffafd is null) THEN 'Departed'::text
+                        WHEN (m_iffarr is not null and m_iffafd is null) THEN 'Arrived'::text
+                        WHEN (m_iffafd is not null) THEN 'Completed'::text
+	    	            ELSE 'Created'
 		            END AS new_status, ".
-                    column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.online_ocean $ocean_ref_sql $ocean_status_sql" . $sqlWhere . 
+                    column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.online_ocean $ocean_ref_sql " . $sqlWhere . 
                 " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;
             $rs = common::excuteListSql($sql);
             error_log("online_ocean_search_SQL: ".$sql);
@@ -704,6 +690,10 @@ class ocean_order {
             $quantity_tolal.=$uv." ".$uk." ";
         }
         $ch_weight_tolal = empty($ch_weight_tolal) ? $ch_weight_tolal_grs_lbs : $ch_weight_tolal;
+
+        $g_weight_tolal = sprintf("%.3f", $g_weight_tolal);
+        $ch_weight_tolal = sprintf("%.3f", $ch_weight_tolal);
+        $cbm_tolal = sprintf("%.4f", $cbm_tolal);
         //Containers信息
         $containers = array("container_column"=>$ocean_container_column,"container_data" =>$rss);
         //Packing信息
@@ -877,9 +867,21 @@ class ocean_order {
         $sql = common::deCode($_POST ['tmp_search'], 'D');
         $sql = substr($sql, 0, strripos($sql, " limit"));
         if(!empty($sql)){
-            $rss = common::excuteListSql($sql);
+            $rs = common::excuteListSql($sql);
+        }
+        //对查询的结果做特殊处理,比如要拼接某个值,合并值等
+        foreach($rs as $index => $val) {
+            //返回加密serial_no
+            $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
+            $rs[$index]["mode"] = "Ocean Freight";
+            //status 改为ocean_milestone里的信息
+            $rs[$index]["Status"] = $rs[$index]["new_status"];
+            //以下新增的origin是 shipper和consignee的地址
+            if(array_key_exists("Origin", $val)){
+                $rs[$index]["Origin"] = utils::outDisplayForMerge($val['Origin'],$val['_consignee_city']);
+            }
         }
-        common::echo_json_encode(200,array("msg"=>"success","Data" => $rss));
+        common::echo_json_encode(200,array("msg"=>"success","Data" => $rs));
         exit;
     }
     
@@ -1051,104 +1053,6 @@ class ocean_order {
         common::download_file($url);
     }
     
-    private function getOcanOrderSearchSql($type,$sqlWhere) {
-        if($type == "All"){
-            return "select count(1) from 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 'Departed'
-                                when a.code='IFFARR' then 'Arrived'
-                                when a.code='IFFAFD' then 'Completed'
-                                else 'Created' END as new_status
-                        from  ocean_milestone a 
-                where a.serial_no=online_ocean.serial_no 
-                    and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
-                    and a.act_date is not null
-                order by id desc limit 1) dd on true" . $sqlWhere;
-        }
-        if($type == "Created"){
-            $Created_sqlWhere = " and (1<>1 or dd.new_status ='Created' or dd.new_status is null)";
-            return "select count(1) from 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 'Departed'
-                                when a.code='IFFARR' then 'Arrived'
-                                when a.code='IFFAFD' then 'Completed'
-                                else 'Created' END as new_status
-                        from  ocean_milestone a 
-                where a.serial_no=online_ocean.serial_no 
-                    and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
-                    and a.act_date is not null
-                order by id desc limit 1) dd on true" . $sqlWhere.$Created_sqlWhere;
-        }
-        if($type == "Cargo Received"){
-            $Cargo_Received_sqlWhere = " and (1<>1 or dd.new_status ='Cargo Received')";
-            return "select count(1) from 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 'Departed'
-                                when a.code='IFFARR' then 'Arrived'
-                                when a.code='IFFAFD' then 'Completed'
-                                else 'Created' END as new_status
-                        from  ocean_milestone a 
-                where a.serial_no=online_ocean.serial_no 
-                    and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
-                    and a.act_date is not null
-                order by id desc limit 1) dd on true" . $sqlWhere.$Cargo_Received_sqlWhere;
-        }
-        if($type == "Departed"){
-            $Departed_sqlWhere = " and (1<>1 or dd.new_status ='Departed')";
-            return "select count(1) from 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 'Departed'
-                                when a.code='IFFARR' then 'Arrived'
-                                when a.code='IFFAFD' then 'Completed'
-                                else 'Created' END as new_status
-                        from  ocean_milestone a 
-                where a.serial_no=online_ocean.serial_no 
-                    and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
-                    and a.act_date is not null
-                order by id desc limit 1) dd on true" . $sqlWhere.$Departed_sqlWhere;
-        }
-        if($type == "Arrived"){
-            $Arrived_sqlWhere = " and (1<>1 or dd.new_status ='Arrived')";
-            return "select count(1) from 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 'Departed'
-                                when a.code='IFFARR' then 'Arrived'
-                                when a.code='IFFAFD' then 'Completed'
-                                else 'Created' END as new_status
-                        from  ocean_milestone a 
-                where a.serial_no=online_ocean.serial_no 
-                    and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
-                    and a.act_date is not null
-                order by id desc limit 1) dd on true" . $sqlWhere.$Arrived_sqlWhere;
-        }
-        if($type == "Completed"){
-            $Completed_sqlWhere = " and (1<>1 or dd.new_status ='Completed')";
-            return "select count(1) from 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 'Departed'
-                                when a.code='IFFARR' then 'Arrived'
-                                when a.code='IFFAFD' then 'Completed'
-                                else 'Created' END as new_status
-                        from  ocean_milestone a 
-                where a.serial_no=online_ocean.serial_no 
-                    and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
-                    and a.act_date is not null
-                order by id desc limit 1) dd on true" . $sqlWhere.$Completed_sqlWhere;
-        }
-    }
-
     private function save_vgm() {
         $schemas = $_POST["schemas"];
         $serial_no = common::deCode($_POST["serial_no"], 'D');
@@ -1244,30 +1148,22 @@ class ocean_order {
             $_schemas = "ocean";
         }
         $sql = "SELECT m_eta as _m_eta,  h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
-                (select incoterms from online_ocean where online_ocean.serial_no = o.serial_no limit 1) as incoterms,
-                public.z_get_eta_dest(o.final_eta::date, o.eta_dest::text, o.service::text, o.m_eta::date, o.place_of_delivery::text, o.mport_of_discharge::text) as _eta_dest, 
-                to_char(final_eta, 'MM/DD/YYYY') as _final_eta,
-                o.* ,sh.*, cn.* ,aa.*,dd.*,oo.*,
-                CASE
-	    	        WHEN ee.status is null THEN 'Created'::text
-	    	        ELSE ee.status::text
-		        END AS new_status
+                o.* ,sh.*, cn.* ,aa.*,dd.*,oo.*
             from ocean o 
-            LEFT JOIN LATERAL ( SELECT shippr_uncode,shipper_city,
-                    consignee_uncode,consignee_city,fport_of_loading_un,mport_of_discharge_un,place_of_receipt_un,place_of_delivery_un
+            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,
+                    port_of_transshipment_un,
+                    CASE
+                        WHEN (m_iffbcf is not null and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Created'::text
+                        WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Cargo Received'::text
+                        WHEN (m_iffdep is not null and m_iffarr is null and m_iffafd is null) THEN 'Departed'::text
+                        WHEN (m_iffarr is not null and m_iffafd is null) THEN 'Arrived'::text
+                        WHEN (m_iffafd 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 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 'Departed'
-                                when a.code='IFFARR' then 'Arrived'
-                                when a.code='IFFAFD' then 'Completed'
-                                else 'Created' END as status
-                        from  ocean_milestone a 
-                where a.serial_no=o.serial_no 
-                    and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
-                    and a.act_date is not null
-                order by id desc limit 1) ee on true
             LEFT JOIN LATERAL ( SELECT company as cn_company,
                 address_1 as cn_address_1,
                 address_2 as cn_address_2,
@@ -1409,8 +1305,8 @@ class ocean_order {
         $codeinfo = common::getCityPortsInfo($uncodes);
 
         //处理transportInfo信息数据
-        $transportInfo = array("Tracking No." =>$ocean['tracking_no'],"status"=>$ocean['new_status'],"mode" => "Ocean Freight",
-            "origin" =>$ocean['origin_station'],"destination" =>$ocean['destination_station'],
+        $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'],
             "etd_timezone" =>$codeinfo[$ocean['fport_of_loading_un']],
             "atd_timezone" =>$codeinfo[$ocean['fport_of_loading_un']],
@@ -1447,19 +1343,19 @@ class ocean_order {
         //处理routes 转船可能有多个情况
         if ($ocean['is_vessel_direct'] <> "t"){
             //不是直航
-            $routes = array(array("mode" =>"Ocean Freight","mode_label" =>"Sea", "origin" =>$ocean['fport_of_loading'],
-                "destination" => $ocean['fport_of_discharge'],
+            $routes = array(array("mode" =>"Ocean Freight","mode_label" =>"Sea", "origin" =>$ocean['shippr_uncode'],
+                "destination" => $ocean['port_of_transshipment_un'],
                 "etd" => $ocean['f_etd'],"atd" => $ocean['atd'],
                 "eta" =>$ocean['f_eta'],"ata" => $ocean['ata'],
                 "vessel" =>$ocean['f_vessel'],"voyageNo" =>$ocean['f_voyage']));
-            $routes[] = array("mode" =>"Ocean Freight", "mode_label" =>"Sea","origin" =>$ocean['mport_of_loading'],
-                "destination" => $ocean['mport_of_discharge'],
+            $routes[] = array("mode" =>"Ocean Freight", "mode_label" =>"Sea","origin" =>$ocean['port_of_transshipment_un'],
+                "destination" => $ocean['consignee_uncode'],
                 "etd" => $ocean['m_etd'],"atd" => $ocean['atd'],
                 "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
                 "vessel" =>$ocean['m_vessel'],"voyageNo" =>$ocean['m_voyage']);
         }else{
-            $routes = array(array("mode" =>"Ocean Freight","mode_label" =>"Sea", "origin" =>$ocean['fport_of_loading'],
-                "destination" => $ocean['fport_of_discharge'],
+            $routes = array(array("mode" =>"Ocean Freight","mode_label" =>"Sea", "origin" =>$ocean['shippr_uncode'],
+                "destination" => $ocean['consignee_uncode'],
                 "etd" => $ocean['f_etd'],"atd" => $ocean['atd'],
                 "eta" =>$ocean['m_eta'],"ata" => $ocean['ata'],
                 "vessel" =>$ocean['f_vessel'],"voyageNo" =>$ocean['f_voyage']));

+ 26 - 1
service/operation_log.class.php

@@ -47,6 +47,16 @@ class operation_log{
         if ($operate == "search") {
             $this->_operation_search();
         }
+
+        if ($operate == "excel") {
+            $sql = common::deCode($_POST ['tmp_search'], 'D');
+            $sql = substr($sql, 0, strripos($sql, " limit"));
+            if(!empty($sql)){
+                $rss = common::excuteListSql($sql);
+            }
+            common::echo_json_encode(200,array("msg"=>"success","Data" => $rss));
+            exit;
+        }
     }
 
     /*
@@ -81,6 +91,14 @@ class operation_log{
         if (isset($_POST['operation_date_end']) && !empty($_POST['operation_date_end']))
             $sqlWhere .= " and operation_time <= '" . common::usDate2sqlDate($_POST['operation_date_end']) . " 23:59:59'";
 
+        // $allLogColumns = array();
+        // $allLogColumns[] = array("title" =>"User Type","field" =>"user_type","formatter" =>"normal","type" =>"normal");
+        // $allLogColumns[] = array("title" =>"User Name","field" =>"user_name","formatter" =>"normal","type" =>"normal");
+        // $allLogColumns[] = array("title" =>"Page","field" =>"page","formatter" =>"normal","type" =>"normal");
+        // $allLogColumns[] = array("title" =>"Operation","field" =>"operation","formatter" =>"normal","type" =>"normal");
+        // $allLogColumns[] = array("title" =>"Operation Details","field" =>"operation_detail","formatter" =>"normal","type" =>"normal");
+        // $allLogColumns[] = array("title" =>"Operation Time","field" =>"operation_time","formatter" =>"normal","type" =>"normal");
+
         $rc = $_POST ['rc'];
         if ($rc == - 1) {
             $sql = "SELECT count(1) from public.customer_service_operation_log" . $sqlWhere;
@@ -89,6 +107,7 @@ class operation_log{
         }
         $tp = ceil($rc / $ps);
         $order_by = " id desc";
+    
         if ($rc > 0) {
             $sql = "SELECT ".column::getInstance()->getSearchSqlForDisplay('Operation_Search')." from public.customer_service_operation_log " . $sqlWhere . 
                         " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;
@@ -108,12 +127,18 @@ class operation_log{
             }
 
             $arrTmp = array('searchData' => $rs, 
+               'tmp_search' => common::deCode($sql, 'E'),
                'rc' => $rc,
                'ps' => $ps,
                'cp' => $cp,
                'tp' => $tp);
         } else {
-           $arrTmp = array('searchData' => array());
+           $arrTmp = array('searchData' => array(), 
+            'tmp_search' => common::deCode($sql, 'E'),
+            'rc' => $rc,
+            'ps' => $ps,
+            'cp' => $cp,
+            'tp' => $tp);
         }
         common::echo_json_encode(200,$arrTmp);
         exit();

+ 12 - 12
utils/common.class.php

@@ -1201,12 +1201,12 @@ class common {
         //先查询总的排放量sea air road,确定排名后,在分别查询对应的sea air road
         if ($type == "co2e_orgin"){
             $co2e_shippr_sql = "select SUM(COALESCE(carbon_emission,0)::numeric(12,10)) as catnum ,
-                shippr_uncode as station from online_ocean  where 1=1 $sqlWhere group by shippr_uncode order by catnum desc limit 10";
+                shippr_uncode as station from online_ocean  where 1=1 and COALESCE(shippr_uncode)<>'' $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)::numeric(12,10)) as catnum,
-                consignee_uncode as station from online_ocean  where 1=1 $sqlWhere group by consignee_uncode order by catnum desc limit 10";
+                consignee_uncode as station from online_ocean  where 1=1 and COALESCE(consignee_uncode)<>'' $sqlWhere group by consignee_uncode order by catnum desc limit 10";
             $co2e_aLL = common::excuteListSql($co2e_consignee_sql);
         }
         //最大Y值
@@ -1277,12 +1277,12 @@ class common {
         $toporiginType = "shippr_uncode";
         $shippr_uncode_10_sql = "select count(shippr_uncode) as num,shippr_uncode,
             (array_agg(shipper_city))[1] AS shipper_city from online_ocean  
-        where 1=1 $sqlWhere group by shippr_uncode order by num desc limit 10";
+        where 1=1 and COALESCE(shippr_uncode)<>'' $sqlWhere group by shippr_uncode order by num desc limit 10";
         $shippr_uncode_10 = common::excuteListSql($shippr_uncode_10_sql);
         //如果值没有:客户地址-->站点地址-->Port地址(POL/POD) 
         if(count($shippr_uncode_10) == 1 && empty($shippr_uncode_10[0]["shippr_uncode"])){
             $toporiginType = "fport_of_loading_un";
-            $shippr_uncode_10_sql = "select count(fport_of_loading_un) as num,fport_of_loading_un as shippr_uncode from online_ocean where 1=1 $sqlWhere group by fport_of_loading_un order by num desc limit 10";
+            $shippr_uncode_10_sql = "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";
             $shippr_uncode_10 = common::excuteListSql($shippr_uncode_10_sql);
         }
         //$toporiginType = "fport_of_loading_un";
@@ -1290,12 +1290,12 @@ class common {
         $topdestinationinType = "consignee_uncode";
         $consignee_uncode_10_sql = "select count(consignee_uncode) as num,consignee_uncode,
         (array_agg(consignee_city))[1] AS consignee_city 
-        from online_ocean  where 1=1 $sqlWhere group by consignee_uncode order by num desc limit 10";
+        from online_ocean  where 1=1  and COALESCE(consignee_uncode)<>''  $sqlWhere group by consignee_uncode order by num desc limit 10";
         $consignee_uncode_10 = common::excuteListSql($consignee_uncode_10_sql);
         //如果值没有:客户地址-->站点地址-->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 = "select count(mport_of_discharge_un) as num,mport_of_discharge_un as consignee_uncode from online_ocean where 1=1 $sqlWhere group by mport_of_discharge_un order by num desc limit 10";
+            $consignee_uncode_10_sql = "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 = common::excuteListSql($consignee_uncode_10_sql);
         }
 
@@ -1564,12 +1564,12 @@ class common {
         
         //Milestones 数据信息待定
         $Milestones_data = array();
-        $Milestones_data_arr = common::excuteListSql("select 
-            case when code = 'IFFECP' then 'Empty Container Pickup' else dd.description end as description,
-	        act_date||' '||act_time as date_time, remark,timezone,code,create_by, '' as act_update_by
-            from  ocean_milestone a 
-                left join LATERAL (select sno,description  from  milestone where code=a.code and project_no = '*' limit 1) dd on true
-            where a.serial_no='".$ocean["serial_no"]."' and act_date is not null  order by dd.sno asc, id asc");           
+        $Milestones_data_arr = common::excuteListSql("select  sn.description,
+            act_date||' '||COALESCE(act_time,'') as date_time,
+            remark,timezone,a.code,create_by, '' as act_update_by
+        from  ocean_milestone a  
+            inner join 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){
             $locations = "";
             if(!empty($Mapping_location[$mda['code']])){