Kaynağa Gözat

改一下bug

gogs 2 ay önce
ebeveyn
işleme
d8ac81caa2
1 değiştirilmiş dosya ile 52 ekleme ve 28 silme
  1. 52 28
      app/Service/StatisticService.php

+ 52 - 28
app/Service/StatisticService.php

@@ -666,8 +666,8 @@ class StatisticService extends Service
         $item = Item::Clear($user, $data);
         $item_list = $item->where('del_time', 0)
             ->where(function ($query) use ($month_start, $month_end) {
-                $query->where('start_time', '>=', $month_start)
-                    ->orWhere('end_time', '<=', $month_end);
+                $query->where('start_time', '<=', $month_start)
+                    ->orWhere('end_time', '>', $month_end);
             })->select("code", "title", "start_time", "end_time", "id", "state")->orderby("start_time","asc")->get()->toArray();
         $item_key_list = [];
         foreach ($item_list as $v) {
@@ -697,32 +697,57 @@ class StatisticService extends Service
                 "fee_id",
                 "type"
             )->get()->toArray();
-
         list($fee_amount,$fee_type_list) =  $this->auxiliaryGroupListByRoot($auxiliary_list,$fee);
-//        dd($item_key_list);
+
+        //找到项目和设备的费用然后进行比例计算
+
         $return = [];
         foreach ($fee_amount as $v){
-            if(!isset($item_key_list[$v['item_id']])) continue;
-            if(!isset($item_salary[$v['item_id']])) continue;
-            if(!isset($device_depreciation[$v['item_id']])) continue;
-            $item_value = $item_key_list[$v['item_id']];
-            $detail = [
-                "code" => $item_value['code'],
-                "title" => $item_value['title'],
-                "state" => $item_value['state'] == 0 ? "进行中":"已完成" ,
-                "voucher_date" => date("Y-m-d",$v['voucher_date']) ,
-                "voucher_type" => $v['voucher_type'] ,
-                "voucher_no" => $v['voucher_no'] ,
-                "voucher_remark" => $v['voucher_remark'] ,
-                "voucher_amount" => $v['voucher_amount'] ,
-                "aggregation_amount" => $v['aggregation_amount'] ,
-                "total_amount" =>  $v['type'] ==  1 ?  $item_salary[$v['item_id']]['allocated_salary'] : ($v['type'] ==  2 ? $device_depreciation[$v['item_id']]['allocated_depreciation'] : $v['total_amount']) ,
-                "fee_id" => $v['fee_id'],
-                "entrust1_amount" => $v['entrust1_amount'],
-                "entrust2_amount" => $v['entrust2_amount'],
-                "type" => $v['type'],
-            ];
-            $return[] = $detail;
+            //人工费用
+            if($v['type'] == 1||$v['type'] == 2){
+                foreach ($item_key_list as $vv){
+                    $detail = [
+                        "code" => $vv['code'],
+                        "title" => $vv['title'],
+                        "state" => $vv['state'] == 3 ? "进行中":"已完成" ,
+                        "voucher_date" => date("Y-m-d",$v['voucher_date']) ,
+                        "voucher_type" => $v['voucher_type'] ,
+                        "voucher_no" => $v['voucher_no'] ,
+                        "voucher_remark" => $v['voucher_remark'] ,
+                        "voucher_amount" => $v['voucher_amount'] ,
+                        "aggregation_amount" => $v['aggregation_amount'] ,
+                        "total_amount" =>   $v['type'] == 1 ? $item_salary[$vv['id']."_".date("Y-m",$v['voucher_date'])]['allocated_salary'] : ($device_depreciation[$vv['id']."_".date("Y-m",$v['voucher_date'])]['allocated_depreciation']??0) ,
+                        "fee_id" => $v['fee_id'],
+                        "entrust1_amount" => $v['entrust1_amount'],
+                        "entrust2_amount" => $v['entrust2_amount'],
+                        "type" => $v['type'],
+                    ];
+                    $return[] = $detail;
+                }
+
+            }else{
+                if(!isset($item_key_list[$v['item_id']])) continue;
+                $item_value = $item_key_list[$v['item_id']];
+                $detail = [
+                    "code" => $item_value['code'],
+                    "title" => $item_value['title'],
+                    "state" => $item_value['state'] == 3 ? "进行中":"已完成" ,
+                    "voucher_date" => date("Y-m-d",$v['voucher_date']) ,
+                    "voucher_type" => $v['voucher_type'] ,
+                    "voucher_no" => $v['voucher_no'] ,
+                    "voucher_remark" => $v['voucher_remark'] ,
+                    "voucher_amount" => $v['voucher_amount'] ,
+                    "aggregation_amount" => $v['aggregation_amount'] ,
+                    "total_amount" =>   $v['total_amount'] ,
+                    "fee_id" => $v['fee_id'],
+                    "entrust1_amount" => $v['entrust1_amount'],
+                    "entrust2_amount" => $v['entrust2_amount'],
+                    "type" => $v['type'],
+                ];
+                $return[] = $detail;
+            }
+
+
         }
 
         return [true,[
@@ -764,7 +789,6 @@ class StatisticService extends Service
         $type_list = [];
         foreach ($list as $k=>$item) {
             if($item['item_id'] == 0||$item['fee_id'] == 0) {
-                unset($list[$k]);
                 continue;
             }
             $feeId = $item['fee_id'];
@@ -843,7 +867,7 @@ class StatisticService extends Service
         $item_year_list = [];
         foreach ($month_employee_list as $item) {
             $key = $item['employee_id'] . '_' . $item['order_month'];
-            $item_key = $item['item_id'];
+            $item_key = $item['item_id'] . '_' . $item['order_month'];
             if (!isset($item_year_list[$item_key])) {
                 $item_year_list[$item_key] = [
                     "allocated_salary" => 0,
@@ -912,7 +936,7 @@ class StatisticService extends Service
         $item_year_list = [];
         foreach ($month_device_list as $item) {
             $key = $item['device_id'] . '_' . $row['order_month'] ;
-            $device_key = $item['item_id'];
+            $device_key = $item['item_id'] . '_' . $item['order_month'];
             $total_depreciatio = $depreciatio_map[$key] ?? 0;
             $total_min = $device_monthly_total_min[$key] ?? 0;
             if (!isset($item_year_list[$device_key])) {