cqp 6 сар өмнө
parent
commit
328dc819d0

+ 3 - 1
app/Service/ExportFileService.php

@@ -104,7 +104,7 @@ class ExportFileService extends Service
             if($search['page_size'] > 5000) return [false,'请选择导出数据的条数每次最多5000条'];
             $id = $this->getListForSearch($data, $user);
             $data['id'] = $id;
-            if($data['type'] != self::type_twl) unset($data['order_search']);
+            if(! in_array($data['type'],[self::type_eight , self::type_twl])) unset($data['order_search']);
         }
 
         //不超时
@@ -1145,6 +1145,8 @@ class ExportFileService extends Service
 
     public function eight($ergs,$user){
         $id = $ergs['id'];
+        $ergs['count_month'] = $ergs['order_search']['count_month'] ?? "";
+        $ergs['top_depart_id'] = $ergs['order_search']['top_depart_id'] ?? 0;
 
         // 导出数据
         $return = [];

+ 13 - 7
app/Service/StatisticsService.php

@@ -1519,15 +1519,20 @@ class StatisticsService extends Service
 
     //新的进销存统计通用搜索底层抽象
     public function statisticsJcNewCommonOrigin($data,$user,$field = []){
-        $startStamp = strtotime(date("Y-m-01 00:00:00"));
+        if(! empty($data['count_month'])) {
+            $startStamp = $this->changeDateToDate($data['count_month']);
+        }else{
+            $startStamp = strtotime(date("Y-m-01 00:00:00"));
+        }
+        $endTimeStamp = strtotime('first day of next month', $startStamp) - 1;
 
         //-------- 结存数量汇总 ---------- //
         //上月结存
         $last_month_stock = "SUM(CASE WHEN crt_time < $startStamp THEN number ELSE 0 END)";
         //本月入库
-        $this_month_in = "SUM(CASE WHEN crt_time >= $startStamp AND number > 0 THEN number ELSE 0 END)";
+        $this_month_in = "SUM(CASE WHEN crt_time >= $startStamp AND crt_time <= $endTimeStamp AND number > 0 THEN number ELSE 0 END)";
         //本月出库
-        $this_month_out = "SUM(CASE WHEN crt_time >= $startStamp AND number < 0 THEN number ELSE 0 END)";
+        $this_month_out = "SUM(CASE WHEN crt_time >= $startStamp AND crt_time <= $endTimeStamp AND number < 0 THEN number ELSE 0 END)";
         //本月结存
         $this_month_stock = "($last_month_stock + $this_month_in + $this_month_out)";
         //-------- 结存数量汇总 ---------- //
@@ -1548,8 +1553,8 @@ class StatisticsService extends Service
         $this_month_in_m = "ROUND(
                                   SUM(
                                       CASE 
-                                            WHEN crt_time >= $startStamp and number > 0 THEN (number * price)
-                                            WHEN crt_time >= $startStamp and number = 0 and price >= 0 and order_type = '$order_type' THEN price
+                                            WHEN crt_time >= $startStamp and crt_time <= $endTimeStamp and number > 0 THEN (number * price)
+                                            WHEN crt_time >= $startStamp and crt_time <= $endTimeStamp and number = 0 and price >= 0 and order_type = '$order_type' THEN price
                                             ELSE 0 
                                       END
                                  ), 
@@ -1558,8 +1563,8 @@ class StatisticsService extends Service
         $this_month_out_m = "ROUND(
                                   SUM(
                                       CASE 
-                                            WHEN crt_time >= $startStamp and number < 0 THEN (number * price)
-                                            WHEN crt_time >= $startStamp and number = 0 and price < 0 and order_type = '$order_type' THEN price
+                                            WHEN crt_time >= $startStamp and crt_time <= $endTimeStamp and number < 0 THEN (number * price)
+                                            WHEN crt_time >= $startStamp and crt_time <= $endTimeStamp and number = 0 and price < 0 and order_type = '$order_type' THEN price
                                             ELSE 0 
                                       END
                                  ), 
@@ -1608,6 +1613,7 @@ class StatisticsService extends Service
     //新的进销存统计
     public function statisticsJcNew($data,$user){
         $model = $this->statisticsJcNewCommon($data, $user);
+        $model->orderBy('product_id','desc');
         $list = $this->limit($model,'',$data);
         $list = $this->fillDataNew($list);