ShuanghongS 3 mēneši atpakaļ
vecāks
revīzija
f516983126
2 mainītis faili ar 60 papildinājumiem un 23 dzēšanām
  1. 58 21
      service/destination_delivery.class.php
  2. 2 2
      utils/common.class.php

+ 58 - 21
service/destination_delivery.class.php

@@ -615,18 +615,18 @@ class destination_delivery {
             //代表employee
             $sqlDeliveryWhere = " 1=1"; 
             if(_isApexLogin()){
-                //$sqlWhere .= " and kln_pic ilike '"._getLoginEamil()."'";
-                $sqlDeliveryWhere .= " and '".strtolower(_getLoginEmployeeEamil())."' in (select regexp_split_to_table(lower(kd.kln_pic), ','))";
+                //$sqlDeliveryWhere .=  " and '".strtolower("CATHY.LEE@APEXSHIPPING.COM")."' =  ANY(LOWER(regexp_split_to_array(kd.kln_pic, ',')))";
+                $sqlDeliveryWhere .= " and '".strtolower(_getLoginEmployeeEamil())."' =  ANY(LOWER(regexp_split_to_array(kd.kln_pic, ',')))";
             }    
 
             //条件带入
             $text_search = $_REQUEST['text_search'];
             if (!empty($text_search)){
-                $sqlWhere .= " and (booking_no ilike '%".strtolower($text_search)."%'
-                    or h_bol ilike '%".strtolower($text_search)."%'
-                    or m_bol ilike '%".strtolower($text_search)."%' 
-                    or ctnr ilike '%".strtolower($text_search)."%'
-                    or consignee ilike '%".strtolower($text_search)."%')";
+                $sqlDeliveryWhere .= " and (lower(booking_no) like '%".strtolower($text_search)."%'
+                    or lower(h_bol) like '%".strtolower($text_search)."%'
+                    or lower(m_bol) like '%".strtolower($text_search)."%' 
+                    or lower(ctnr) like '%".strtolower($text_search)."%'
+                    or lower(consignee) like '%".strtolower($text_search)."%')";
             }
 
             if (isset($_REQUEST['delivery_date_start']) && !empty($_REQUEST['delivery_date_start']))
@@ -689,7 +689,7 @@ class destination_delivery {
                         sum(case when kd.status ='Cancel' then 1 else 0 end) as cancelled_rc
                     from public.kln_destination_delivery kd
                         where ".$sqlDeliveryWhere." 
-                            and exists(select 1 from public.kln_ocean oo ". $sqlWhere."  and oo.serial_no = any(kd.h_serial_no))";
+                            and exists(select 1 from public.kln_ocean oo ". $sqlWhere."  and oo.serial_no = any(kd.h_serial_no) limit 1)";
                 error_log("kln_destination_delivery_count:".$sql);        
                 $statusRc = common::excuteObjectSql($sql);
                 $rc = $statusRc['rc'];
@@ -707,7 +707,7 @@ class destination_delivery {
                          from public.kln_destination_delivery kd
                     where ".$tag_and_mode_param." 
                         and ".$sqlDeliveryWhere."
-                        and exists(select 1 from public.kln_ocean oo ". $sqlWhere."  and oo.serial_no = any(h_serial_no))";
+                        and exists(select 1 from public.kln_ocean oo ". $sqlWhere."  and oo.serial_no = any(h_serial_no) limit 1)";
                 $sql .= " order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
 
                 error_log("kln_destination_delivery_search:".$sql);
@@ -1148,8 +1148,8 @@ class destination_delivery {
 
             $sqlDeliveryWhere = " 1=1"; 
             if(_isApexLogin()){
-                //$sqlWhere .= " and kln_pic ilike '"._getLoginEamil()."'";
-                $sqlDeliveryWhere .= " and '".strtolower(_getLoginEmployeeEamil())."' in (select regexp_split_to_table(lower(kd.kln_pic), ','))";
+                //$sqlDeliveryWhere .=  " and '".strtolower("CATHY.LEE@APEXSHIPPING.COM")."' =  ANY(LOWER(regexp_split_to_array(kd.kln_pic, ',')))";
+                $sqlDeliveryWhere .= " and '".strtolower(_getLoginEmployeeEamil())."' =  ANY(LOWER(regexp_split_to_array(kd.kln_pic, ',')))";
             }      
             //$sqlWhere_befrom_filterTag = $sqlWhere;
             $sql = "select delivery_date::date as delivery_date,
@@ -1157,7 +1157,7 @@ class destination_delivery {
                         sum(case when status ='Approve' then 1 else 0 end) as approved_rc
                     from public.kln_destination_delivery kd 
                         where ".$sqlDeliveryWhere."
-                            and exists(select 1 from public.kln_ocean oo ". $sqlWhere."  and oo.serial_no = any(h_serial_no))
+                            and exists(select 1 from public.kln_ocean oo ". $sqlWhere."  and oo.serial_no = any(h_serial_no) limit 1)
                     group by delivery_date::date  order by delivery_date::date desc";
             $rs  = common::excuteListSql($sql);
             error_log("delivery_date_load:".$sql);        
@@ -1213,25 +1213,25 @@ class destination_delivery {
 
         $text_search = $_REQUEST['text_search'];
         if (!empty($text_search)){
-            $sqlWhere .= " and (oo.h_bol ilike '%".strtolower($text_search)."%'
-                or oo.po_no ilike '%".strtolower($text_search)."%'
-                or oo.ctnrs ilike '%".strtolower($text_search)."%')";
+            $sqlWhere .= " and (lower(oo.h_bol) like '%".strtolower($text_search)."%'
+                or lower(oo.po_no) like '%".strtolower($text_search)."%'
+                or lower(oo.ctnrs) like '%".strtolower($text_search)."%')";
         }
 
         //vessel name
         $vessel = $_REQUEST['vessel'];
         if (!empty($vessel)){
-            $sqlWhere .= " and vessel ilike '%".strtolower($vessel)."'%";
+            $sqlWhere .= " and lower(vessel) like '%".strtolower($vessel)."'%";
         }
 
         $consignee = $_REQUEST['consignee'];
         if (!empty($vessel)){
-            $sqlWhere .= " and consignee ilike '%".strtolower($consignee)."'%";
+            $sqlWhere .= " and lower(consignee) like '%".strtolower($consignee)."'%";
         }
 
         $shipper = $_REQUEST['shipper'];
         if (!empty($vessel)){
-            $sqlWhere .= " and shipper ilike '%".strtolower($shipper)."'%";
+            $sqlWhere .= " and lower(shipper) like '%".strtolower($shipper)."'%";
         }
 
         if (isset($_REQUEST['eta_start']) && !empty($_REQUEST['eta_start']))
@@ -1245,16 +1245,53 @@ class destination_delivery {
             $sqlWhere .= " and ata <= '" . common::usDate2sqlDate($_REQUEST['ata_end']) . " 23:59:59'";
 
         $sql = "with oo as(
-                select * from public.kln_ocean oo ". $sqlWhere ."
+                select  oo.serial_no,
+                    oo.h_bol,
+                    oo.m_bol,
+                    oo.service,
+                    oo.po_no,
+                    oo.transport_mode,
+                    oo.qty,
+                    oo.qty_uom,
+                    oo.piece_count,
+                    oo.cbm,
+                    oo.vessel,
+                    oo.voyage,
+                    oo.carrier,
+                    oo.fport_of_loading_un,
+                    oo.mport_of_discharge_un,
+                    oo.eta,
+                    oo.ata,
+                    oo.etd,
+                    oo.atd,
+                    oo.shipper,
+                    oo.consignee_id,
+                    oo.consignee,
+                    oo.booking_no,
+                    oo.agent,
+                    oo.order_from
+                from public.kln_ocean oo ". $sqlWhere ."
+            ),
+            -- 2. 预解析station字段
+            station_list AS (
+                SELECT 
+                    serial_no, 
+                    country, 
+                    kln_pic,
+                    booking_window,
+                    booking_window_date_start,
+                    booking_window_date_end,
+                    unnest(string_to_array(station, ',')) as station_code
+                FROM public.kln_destination_delivery_config
             ),
             ooc as (
                 select oo.*,
                     dc.serial_no as dc_serial_no,
                     dc.country as dc_country,
                     dc.kln_pic as dc_kln_pic
-                from public.kln_destination_delivery_config dc
+                from station_list dc
                     Inner Join oo
-                        on oo.agent in (select regexp_split_to_table(dc.station, ','))
+                        on oo.agent = dc.station_code
                     where  1=1 and 
                         case when dc.booking_window = 'Restrictions_ETD_ATD' and COALESCE(dc.booking_window_date_start,'')<>'' and 	COALESCE(dc.booking_window_date_end,'')<>''
                                 then COALESCE(atd, etd) >= (NOW() - (dc.booking_window_date_start ||' days')::INTERVAL)::date and  COALESCE(atd, etd) <= (NOW() + (dc.booking_window_date_end ||' days')::INTERVAL)::date

+ 2 - 2
utils/common.class.php

@@ -3899,6 +3899,7 @@ class common {
                     continue;
                 }
                 $uniqueAC[] = $_country;
+
                 //如果需要新加的时候 用户固定名称,用作标记   //contact_person,contact_number  '$_contact_person','$_contact_number'
                 $_add_create_user = "Online_D_Address";
                 if ($_contact_type == "Add"){
@@ -3992,8 +3993,7 @@ class common {
                     "contact_number"=>$_contact_number,
                     "contact_id"=>$_contact_id,
                     "sync_key"=>$_sync_key,
-                    "from_station"=>$_from_station,
-                    "contact_type"=>"Unedit");
+                    "from_station"=>$_from_station);
             }
         }
         return $delivery_address;