ShuanghongS 3 месяцев назад
Родитель
Сommit
2ad9626c46
1 измененных файлов с 35 добавлено и 28 удалено
  1. 35 28
      service/destination_delivery.class.php

+ 35 - 28
service/destination_delivery.class.php

@@ -607,10 +607,11 @@ class destination_delivery {
             $sqlWhere = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
             //兜底规则
             $sqlWhere .= " and eta >= now() - INTERVAL '6 months' and eta <= now() + INTERVAL '6 months'";
-            //代表employee 
+            //代表employee
+            $sqlDeliveryWhere = " 1=1"; 
             if(_isApexLogin()){
                 //$sqlWhere .= " and kln_pic ilike '"._getLoginEamil()."'";
-                $sqlWhere .= "and '".strtolower(_getLoginEamil())."' in (select regexp_split_to_table(lower(kln_pic), ','))";
+                $sqlDeliveryWhere .= " and '".strtolower(_getLoginEamil())."' in (select regexp_split_to_table(lower(kd.kln_pic), ','))";
             }    
 
             //条件带入
@@ -624,20 +625,20 @@ class destination_delivery {
             }
 
             if (isset($_REQUEST['delivery_date_start']) && !empty($_REQUEST['delivery_date_start']))
-                $sqlWhere .= " and delivery_date >= '" . common::usDate2sqlDate($_REQUEST['delivery_date_start']) . " 00:00:00'";
+                $sqlDeliveryWhere .= " and kd.delivery_date >= '" . common::usDate2sqlDate($_REQUEST['delivery_date_start']) . " 00:00:00'";
             if (isset($_REQUEST['delivery_date_end']) && !empty($_REQUEST['delivery_date_end']))
-                $sqlWhere .= " and delivery_date <= '" . common::usDate2sqlDate($_REQUEST['delivery_date_end']) . " 23:59:59'";
+                $sqlDeliveryWhere .= " and kd.delivery_date <= '" . common::usDate2sqlDate($_REQUEST['delivery_date_end']) . " 23:59:59'";
 
             if(!empty($_POST['delivery_mode'])){
-                $sqlWhere .= " and delivery_mode ='". common::check_input($_REQUEST['delivery_mode'])."'";
+                $sqlDeliveryWhere .= " and kd.delivery_mode ='". common::check_input($_REQUEST['delivery_mode'])."'";
             }
             if (isset($_REQUEST['created_time_start']) && !empty($_REQUEST['created_time_start']))
-                $sqlWhere .= " and created_time >= '" . common::usDate2sqlDate($_REQUEST['created_time_start']) . " 00:00:00'";
+                $sqlDeliveryWhere .= " and kd.created_time >= '" . common::usDate2sqlDate($_REQUEST['created_time_start']) . " 00:00:00'";
             if (isset($_REQUEST['created_time_end']) && !empty($_REQUEST['created_time_end']))
-                $sqlWhere .= " and created_time <= '" . common::usDate2sqlDate($_REQUEST['created_time_end']) . " 23:59:59'";
+                $sqlDeliveryWhere .= " and kd.created_time <= '" . common::usDate2sqlDate($_REQUEST['created_time_end']) . " 23:59:59'";
 
             //移除filterTag
-            $sqlWhere_befrom_filterTag  = $sqlWhere;
+            //$sqlWhere_befrom_filterTag  = $sqlWhere;
 
             $filterTag_param = "";
             if (!empty($_POST["filterTag"])) {
@@ -652,16 +653,16 @@ class destination_delivery {
                     $filterTag_param = "1=1";
                 }
                 if (stripos($filterTag, "Pending Approval") !== FALSE) {
-                    $filterTag_param .= " or (status = 'Pending Approval')";
+                    $filterTag_param .= " or (kd.status = 'Pending Approval')";
                 }
                 if (stripos($filterTag, "Approve") !== FALSE) {
-                    $filterTag_param .= " or (status = 'Approve')";
+                    $filterTag_param .= " or (kd.status = 'Approve')";
                 }
                 if (stripos($filterTag, "Reject") !== FALSE) {
-                    $filterTag_param .= " or (status = 'Reject')";
+                    $filterTag_param .= " or (kd.status = 'Reject')";
                 }
                 if (stripos($filterTag, "Cancel") !== FALSE) {
-                    $filterTag_param .= " or (status = 'Cancel')";
+                    $filterTag_param .= " or (kd.status = 'Cancel')";
                 }
                 if(strtolower($filterTag) <> "all" && !empty($filterTag)){
                     $filterTag_param = " ($filterTag_param)";
@@ -677,12 +678,13 @@ class destination_delivery {
             if ($rc == - 1 || true) {
                 $sql = "select count(1) as rc,
                         sum(case when $tag_and_mode_param then 1 else 0 end) as seach_rc, 
-                        sum(case when status ='Pending Approval' then 1 else 0 end) as pending_approval_rc, 
-                        sum(case when status ='Approve' then 1 else 0 end) as approved_rc,
-                        sum(case when status ='Reject' then 1 else 0 end) as rejected_rc,
-                        sum(case when status ='Cancel' then 1 else 0 end) as cancelled_rc
-                    from public.kln_destination_delivery 
-                        where exists(select 1 from public.kln_ocean oo ". $sqlWhere_befrom_filterTag."  and oo.serial_no = any(h_serial_no))";
+                        sum(case when kd.status ='Pending Approval' then 1 else 0 end) as pending_approval_rc, 
+                        sum(case when kd.status ='Approve' then 1 else 0 end) as approved_rc,
+                        sum(case when kd.status ='Reject' then 1 else 0 end) as rejected_rc,
+                        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))";
                 error_log("kln_destination_delivery_count:".$sql);        
                 $statusRc = common::excuteObjectSql($sql);
                 $rc = $statusRc['rc'];
@@ -697,8 +699,9 @@ class destination_delivery {
                 $sql = "select *,to_char((recommended_delivery_window_date_from)::date, 'YYYY-MM-DD') 
                                     || ';' ||
                                     to_char((recommended_delivery_window_date_to)::date, 'YYYY-MM-DD') AS date_range
-                         from public.kln_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))";
                 $sql .= " order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
 
@@ -1134,21 +1137,25 @@ class destination_delivery {
          * Delivery date
         */
         if ($operate == "delivery_date_load"){
-             $sqlWhere = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
+            $sqlWhere = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
             //兜底规则
-            //$sqlWhere .= " and eta >= now() - INTERVAL '6 months' and eta <= now() + INTERVAL '6 months'";
-            //代表employee 
+            $sqlWhere .= " and eta >= now() - INTERVAL '6 months' and eta <= now() + INTERVAL '6 months'";
+
+            $sqlDeliveryWhere = " 1=1"; 
             if(_isApexLogin()){
-                //$sqlWhere .= " and kln_pic = '"._getLoginEamil()."'";
-            }  
-            $sqlWhere_befrom_filterTag = $sqlWhere;
+                //$sqlWhere .= " and kln_pic ilike '"._getLoginEamil()."'";
+                $sqlDeliveryWhere .= " and '".strtolower(_getLoginEamil())."' in (select regexp_split_to_table(lower(kd.kln_pic), ','))";
+            }      
+            //$sqlWhere_befrom_filterTag = $sqlWhere;
             $sql = "select delivery_date::date as delivery_date,
                         sum(case when status ='Pending Approval' then 1 else 0 end) as pending_approval_rc,
                         sum(case when status ='Approve' then 1 else 0 end) as approved_rc
-                    from public.kln_destination_delivery 
-                        where exists(select 1 from public.kln_ocean oo ". $sqlWhere_befrom_filterTag."  and oo.serial_no = any(h_serial_no))
+                    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))
                     group by delivery_date::date  order by delivery_date::date desc";
-            $rs  = common::excuteListSql($sql);        
+            $rs  = common::excuteListSql($sql);
+            error_log("delivery_date_load:".$sql);        
             $dateArr = new stdClass();
             foreach($rs as $val){
                 //$dateArr[] = array($val['delivery_date'] => array("pending"=>$val['pending_approval_rc'],"approved"=>$val['approved_rc']));