Răsfoiți Sursa

封装的报表类方法

gogs 1 lună în urmă
părinte
comite
8077817de9

+ 4 - 1
app/Service/Statistic/StatisticCommonService.php

@@ -311,6 +311,7 @@ class StatisticCommonService extends Service
                 if(!isset($all_salary[$item['order_month']])) $all_salary[$item['order_month']] = 0;
                 $all_salary[$item['order_month']] += $total_salary;
                 $all_key_salary[$key] = 1;
+                $item_month_list[$item_key]['total_salary'] = $total_salary;
 
             }
             $item_month_list[$item_key]['total_min'] += $total_salary;
@@ -403,7 +404,9 @@ class StatisticCommonService extends Service
                 elseif($v['type'] == "money") $current_hours = round($item[$v['key']] / 100, 2);
                 else $current_hours = $item[$v['key']];
                 $item[$v['value']] = $current_hours;
-                $sum[$k][$key] -= $current_hours * 100;
+
+                if($v['type'] == "100b") $sum[$k][$key] -= $current_hours ;
+                else $sum[$k][$key] -= $current_hours * 100;
             } else {
                 if($v['type'] == "day")   $item[$v['value']] = $sum[$k][$key];
                 else $item[$v['value']] = round($sum[$k][$key] / 100, 2);

+ 8 - 5
app/Service/StatisticService.php

@@ -153,8 +153,7 @@ class StatisticService extends StatisticCommonService
         $employee_monthly_total_min = $this->calculateSum($month_employee_list,$keys,"total_work");
         //查询所有项目人员的工时比例
         // 3. 计算分摊比例
-        list($item_month_list,$salary_all) = $this->calculateRatioForMonth($month_employee_list,$employee_monthly_total_min,$salary_map,["employee_id","order_month"],["order_month","item_id","employee_id"]);
-
+        list($item_month_list,) = $this->calculateRatioForMonth($month_employee_list,$employee_monthly_total_min,$salary_map,["employee_id","order_month"],["order_month","item_id","employee_id"]);
         $collect = collect($item_month_list);
         $employee_count = $collect->groupBy(function ($item) {
             // 这里的 $item 是集合中的每一行数据
@@ -179,13 +178,13 @@ class StatisticService extends StatisticCommonService
             // 注意:round 会根据你的精度要求处理小数
             return round($value / 60) * 100;
         })->toArray();
-        $sums =  ["work_hours"=>$month_total_hour,"allocated_salary"=>$salary_all];
+        $sums =  ["work_hours"=>$month_total_hour,"allocated_salary"=>$salary_map];
         $word_keys = [
             "allocated_salary" =>
                 [
                     "key" => "allocated_salary",
                     "value" => "allocated_salary",
-                    "type" => "money",
+                    "type" => "100b",
                 ],
             "work_hours" =>
                 [
@@ -198,11 +197,15 @@ class StatisticService extends StatisticCommonService
         foreach ($word_keys as $k=>$v){
             $counts[$k] = $employee_count;
         }
+//        var_dump($sums['allocated_salary']);
+//        var_dump($item_month_list);
+//        $sums($item_month_list);
         $item_month_list = collect($item_month_list)->transform(function ($item) use ($item_title_key_list, $item_code_key_list, $employee_key_list, &$sums, &$counts,$word_keys) {
             $item['item_title'] = $item_title_key_list[$item['item_id']] ?? "未知项目({$item['item_id']})";
             $item['item_code'] = $item_code_key_list[$item['item_id']] ?? "未知项目({$item['item_id']})";
             $item['employee_title'] = $employee_key_list[$item['employee_id']] ?? "未知人员({$item['employee_id']})";
-            $item['total_hours'] = round($item['total_min'] / 60);
+            $item['total_hours'] = round($item['total_work'] / 60);
+            $item['total_salary'] = round($item['total_salary'] / 100,2);
             $key = $item['employee_id'] . '_' . $item['month'];
 //            // 如果不是最后一条