ShuanghongS 3 săptămâni în urmă
părinte
comite
0f95db3b74
2 a modificat fișierele cu 52 adăugiri și 20 ștergeri
  1. 2 1
      service/report.class.php
  2. 50 19
      utils/common.class.php

+ 2 - 1
service/report.class.php

@@ -1211,7 +1211,8 @@ class report {
                         || $key == "COALESCE(oe.import_po_no,oo.po_no)" 
                         || $key == "oo._voyage" 
                         || $key == "oo._vessel"
-                        || $key == "oo.new_status"){
+                        || $key == "oo.new_status"
+                        || $key == "CONCAT_WS('/', oo._vessel, oo._voyage)"){
                         $ocItemSearchKLN .= $temp_sql_where;
                     } else {
                         $klnOceanSearchKLN .= $temp_sql_where;

+ 50 - 19
utils/common.class.php

@@ -4491,7 +4491,7 @@ class common {
             "oo.carrier" => "carrier",
             "oo._voyage"=>"voyage_flight",    
             "oo._vessel"=>"vessel_airline",
-            "CONCAT_WS(''/'', oo._vessel, oo._voyage)"=>"vslvoy_flight",
+            "CONCAT_WS('/', oo._vessel, oo._voyage)"=>"vslvoy_flight",
             "oo.ams_status" => "ace_m1_status",
             "oo.isisf" => "is_isf",
             "oo.obl_set" => "obl_set",
@@ -4787,9 +4787,10 @@ class common {
         $FIELD_TABLE_MAP = [
         // 主表 oo (kln_ocean)
         'Status'                     => ['oo','new_status'],
-        'Transportation Mode'        => ['oo','new_transport_mode_extend'],
+        'Transportation Mode'        => ['oo'],
         'Voyage/Flight'              => ['oo','_voyage'],
         'Vessel/Airline'             => ['oo','_vessel'],
+        'VSLVOY/FLIGHT'              => ['oo','VSLVOY/FLIGHT'],
         'Container No. (House)'      => ['oo'],
         'Shipment PO No.'            => ['oo', 'oe'], // 可能来自 oe.import_po_no
 
@@ -4830,6 +4831,9 @@ class common {
 
         // 特殊字段:依赖 oc + oe
         'Last Mile Delivery'         => ['oc', 'oe'],
+
+        'Controlling Customer'       => ['oo','Controlling Customer'],
+        'CARRIER TEU'                => ['oe','CARRIER TEU']
         ];
 
         $tables = [];
@@ -4856,10 +4860,13 @@ class common {
         $needCO2           = in_array('co2_r', $requiredTables);
 
         $needNewStatus     = in_array('new_status', $requiredTables);
-        $needMode     = in_array('new_transport_mode_extend', $requiredTables);
         $needVoyage     = in_array('_voyage', $requiredTables);
         $needVessel     = in_array('_vessel', $requiredTables);
 
+        $needVSLVOYFLIGHT     = in_array('VSLVOY/FLIGHT', $requiredTables);
+        $needteu     = in_array('CARRIER TEU', $requiredTables);
+        $needCustomer     = in_array('Controlling Customer', $requiredTables);
+
         //在根据层级分配是否需要字段
         if($level == 'Container Level'){
             $needContainerData = true;
@@ -4880,19 +4887,8 @@ class common {
                     END AS new_status, ";
         }
 
-        $needModeSQL = " ";
-        if ($needMode) {
-            $needModeSQL = "CASE
-                        WHEN transport_mode_extend = 'sea' THEN 'Ocean Freight'::text
-                        WHEN transport_mode_extend = 'air' THEN 'Air Freight'::text
-                        WHEN transport_mode_extend = 'rail' THEN 'Rail Freight'::text
-                        WHEN transport_mode_extend = 'road' THEN 'Road Freight'::text
-                        ELSE ''
-                    END AS new_transport_mode_extend, ";
-        }
-
         $needVoyageSQL = " ";
-        if ($needVoyage) {
+        if ($needVoyage || $needVSLVOYFLIGHT) {
             $needVoyageSQL = "CASE
                         WHEN oo.voyage IS NOT DISTINCT FROM oo.f_voyage THEN oo.voyage
                         WHEN NULLIF(TRIM(oo.voyage), '') IS NOT NULL AND NULLIF(TRIM(oo.f_voyage), '') IS NOT NULL
@@ -4904,7 +4900,7 @@ class common {
         }
 
         $needVesselSQL = " ";
-        if ($needVessel) {
+        if ($needVessel || $needVSLVOYFLIGHT) {
             $needVesselSQL = "CASE
                         WHEN oo.vessel IS NOT DISTINCT FROM oo.f_vessel THEN oo.vessel
                         WHEN NULLIF(TRIM(oo.vessel), '') IS NOT NULL AND NULLIF(TRIM(oo.f_vessel), '') IS NOT NULL
@@ -4915,15 +4911,50 @@ class common {
                     END AS _vessel, ";
         }
 
+        $needCustomerSQL = " ";
+        if($needCustomer){
+            $needCustomerSQL = " case when oo.order_from  ='public' and oo.transport_mode  ='sea' then (select customer_code from public.ocean_extend ex where ex.serial_no = oo.serial_no limit 1)
+                when oo.order_from  ='sfs' and oo.transport_mode  ='sea' then (select customer_code from sfs.ocean_extend ex where ex.serial_no = oo.serial_no limit 1)
+                when oo.order_from  ='public' and oo.transport_mode  ='air' then (select customer_code from public.air_extend ex where ex.serial_no = oo.serial_no limit 1)
+                when oo.order_from  ='sfs' and oo.transport_mode  ='air' then (select customer_code from sfs.air_extend ex where ex.serial_no = oo.serial_no limit 1)
+            else ''::text
+            end as \"Controlling Customer\", ";
+        }
+
+        $needteuSQL = " ";
+        if($needteu){
+            $needteuSQL = " CASE
+                WHEN oe.manifest_type in ('LCL','GPE','CIL','COL') THEN 0::numeric
+                WHEN oe.manifest_type in ('FCL','BCN','CIF','COF','BCL','BCF') and  \"left\"(oc.size::text, 1) = '1'::text THEN 0.5::numeric
+                WHEN oe.manifest_type in ('FCL','BCN','CIF','COF','BCL','BCF') and  \"left\"(oc.size::text, 1) = '2'::text THEN 1::numeric
+                WHEN oe.manifest_type in ('FCL','BCN','CIF','COF','BCL','BCF') and  \"left\"(oc.size::text, 2) = '40'::text THEN 2::numeric
+                WHEN oe.manifest_type in ('FCL','BCN','CIF','COF','BCL','BCF') and  \"left\"(oc.size::text, 2) = '45'::text THEN 2.5::numeric
+                WHEN oe.manifest_type in ('FCL','BCN','CIF','COF','BCL','BCF') and  \"left\"(oc.size::text, 1) = '5'::text THEN 2.65::numeric
+                WHEN oe.manifest_type in ('RORO','BULK','ROR','BLK','CON')  THEN ROUND(COALESCE(oc.grs_kgs,0)/15000.0, 2)::numeric
+            ELSE (CASE
+                    WHEN \"left\"(oc.size::text, 1) = '2'::text THEN 1
+                    ELSE 2::numeric
+                END)
+            END	 AS \"CARRIER TEU\", ";
+        }
+
+        $needVSLVOYFLIGHTSQL = " ";
+        if($needVSLVOYFLIGHT){
+            $needVSLVOYFLIGHTSQL = " CONCAT_WS('/', oo._vessel, oo._voyage) AS \"VSLVOY/FLIGHT\", ";
+        }
+
 
         // --- CTE: oo (主表) ---
         $sql = "
         with oo as (
-            SELECT {$needNewStatusSQL} {$needModeSQL} {$needVoyageSQL} {$needVesselSQL}  * FROM public.kln_ocean oo  <{klnOceanSearchKLN}>
+            SELECT {$needNewStatusSQL} {$needVoyageSQL} {$needVesselSQL} * FROM public.kln_ocean oo  <{klnOceanSearchKLN}>
         )";
 
         // 如果不需要容器/项数据,直接 COUNT
         if (!$needContainerData) {
+            if(!empty($needCustomerSQL) || !empty($needVSLVOYFLIGHTSQL)){
+                return $sql . "\n ,vv as (select {$needCustomerSQL} 1 from oo <{ocItemSearchKLN}>) select count(*)  from vv <{vvSearchKLN}>;";
+            }
             return $sql . "\n select count(*) from oo <{ocItemSearchKLN}> ;";
         }
 
@@ -4989,7 +5020,7 @@ class common {
 
         $sql .= ",
         vv_public AS (
-            SELECT 1
+            SELECT {$needCustomerSQL} {$needteuSQL} {$needVSLVOYFLIGHTSQL} 1
             FROM oo 
             {$joinPublic}
             {$oeLateral}
@@ -4997,7 +5028,7 @@ class common {
             <{ocItemSearchKLN}>
         ),
         vv_sfs AS (
-            SELECT 1
+            SELECT {$needCustomerSQL} {$needteuSQL} {$needVSLVOYFLIGHTSQL} 1
             FROM oo 
             {$joinSfs}
             {$oeLateral}