|
|
@@ -38,22 +38,24 @@ class StatisticService extends StatisticCommonService
|
|
|
$employee_count = $this->calculateCount($day_employee_list,$keys);
|
|
|
$employee_work_count = $this->calculateSumForHour($day_employee_list,$keys,"total_work");
|
|
|
$collection = collect($day_employee_list);
|
|
|
- $month_employee_list = $collection->transform(function ($item) use ($employee_key_list, $item_title_key_list, $item_code_key_list, &$employee_work_count, &$employee_count,$keys) {
|
|
|
+ $sums = ["employee_work_count"=>$employee_work_count];
|
|
|
+ $word_keys = [
|
|
|
+ "employee_work_count" =>
|
|
|
+ [
|
|
|
+ "key" => "total_work",
|
|
|
+ "value" => "total_work_hours",
|
|
|
+ "type" => "hour",
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ $employee_counts = ['employee_work_count' => $employee_count];
|
|
|
+ $month_employee_list = $collection->transform(function ($item) use ($employee_key_list, $item_title_key_list, $item_code_key_list, &$employee_work_count, &$employee_counts,$keys,$word_keys,&$sums) {
|
|
|
$item['employee_name'] = $employee_key_list[$item['employee_id']] ?? "未知员工({$item['employee_id']})";
|
|
|
$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']})";
|
|
|
// 如果不是最后一条
|
|
|
$key = collect($keys)->map(fn($k) => $item[$k] ?? '')->implode('_');
|
|
|
- $sums = ["employee_work_count"=>$employee_work_count];
|
|
|
- $word_keys = [
|
|
|
- "employee_work_count" =>
|
|
|
- [
|
|
|
- "key" => "total_work",
|
|
|
- "value" => "total_work_hours",
|
|
|
- "type" => "hour",
|
|
|
- ]
|
|
|
- ];
|
|
|
- $this->calculateClosure($key,$item,$employee_count,$sums,$word_keys);
|
|
|
+
|
|
|
+ $this->calculateClosure($key,$item,$employee_counts,$sums,$word_keys);
|
|
|
return $item;
|
|
|
})->all();
|
|
|
return [true, $month_employee_list];
|
|
|
@@ -74,8 +76,7 @@ class StatisticService extends StatisticCommonService
|
|
|
$employee_monthly_total_min = $this->calculateSum($month_employee_list,$keys,"total_work");
|
|
|
|
|
|
// 3. 计算分摊比例
|
|
|
- $item_month_list = $this->calculateRatioForMonth($month_employee_list,$employee_monthly_total_min,$salary_map,["employee_id","order_month"],["order_month","item_id"]);
|
|
|
-
|
|
|
+ list($item_month_list,$all_salary) = $this->calculateRatioForMonth($month_employee_list,$employee_monthly_total_min,$salary_map,["employee_id","order_month"],["order_month","item_id"]);
|
|
|
//计算天数
|
|
|
foreach ($item_month_list as $k => $v) {
|
|
|
$item_month_list[$k]['days'] = round($v['work_minutes'] / 8 / 60);
|
|
|
@@ -96,42 +97,43 @@ class StatisticService extends StatisticCommonService
|
|
|
return $group->count();
|
|
|
})->toArray();
|
|
|
$item_day_count = $collect->groupBy(fn($item) => $item['month'])
|
|
|
- ->map(fn($group) => round($group->sum('work_minutes') / 8 / 60))
|
|
|
- ->toArray();
|
|
|
-
|
|
|
- $all_salary = collect($salary_map)
|
|
|
- ->groupBy(function ($value, $key) {
|
|
|
- // 1. 提取下划线后面的内容 (例如: 2024-02)
|
|
|
- return explode('_', $key)[1];
|
|
|
- })
|
|
|
- ->map(function ($group) {
|
|
|
- // 2. 对每个分组内的数值进行求和
|
|
|
- return $group->sum();
|
|
|
- })
|
|
|
+ ->map(fn($group) => round($group->sum('work_minutes') / 8 / 60)*100)
|
|
|
->toArray();
|
|
|
-
|
|
|
- $item_month_list = collect($item_month_list)->transform(function ($item) use ($item_title_key_list, $item_code_key_list, &$all_salary, &$item_day_count, $item_count) {
|
|
|
+// $all_salary = collect($salary_map)
|
|
|
+// ->groupBy(function ($value, $key) {
|
|
|
+// // 1. 提取下划线后面的内容 (例如: 2024-02)
|
|
|
+// return explode('_', $key)[1];
|
|
|
+// })
|
|
|
+// ->map(function ($group) {
|
|
|
+// // 2. 对每个分组内的数值进行求和
|
|
|
+// return $group->sum();
|
|
|
+// })
|
|
|
+// ->toArray();
|
|
|
+ $item_counts = [
|
|
|
+ "all_salary" => $item_count,
|
|
|
+ "item_day_sum" => $item_count,
|
|
|
+ ];
|
|
|
+ $sums = ["item_day_sum"=>$item_day_count,"all_salary"=>$all_salary];
|
|
|
+ $word_keys = [
|
|
|
+ "all_salary" =>
|
|
|
+ [
|
|
|
+ "key" => "allocated_salary",
|
|
|
+ "value" => "allocated_salary",
|
|
|
+ "type" => "money",
|
|
|
+ ],
|
|
|
+ "item_day_sum" =>
|
|
|
+ [
|
|
|
+ "key" => "days",
|
|
|
+ "value" => "days",
|
|
|
+ "type" => "",
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+
|
|
|
+ $item_month_list = collect($item_month_list)->transform(function ($item) use ($item_title_key_list, $item_code_key_list, &$item_counts,&$sums,&$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['allocated_salary'] = round($item['allocated_salary']/100, 2);
|
|
|
$key = $item['month'];
|
|
|
- // 如果不是最后一条
|
|
|
- $sums = ["item_day_sum"=>$item_day_count,"all_salary"=>$all_salary];
|
|
|
- $word_keys = [
|
|
|
- "all_salary" =>
|
|
|
- [
|
|
|
- "key" => "allocated_salary",
|
|
|
- "value" => "allocated_salary",
|
|
|
- "type" => "money",
|
|
|
- ],
|
|
|
- "item_day_sum" =>
|
|
|
- [
|
|
|
- "key" => "days",
|
|
|
- "value" => "days",
|
|
|
- "type" => "",
|
|
|
- ],
|
|
|
- ];
|
|
|
- $this->calculateClosure($key,$item,$item_count,$sums,$word_keys);
|
|
|
+ $this->calculateClosure($key,$item,$item_counts,$sums,$word_keys);
|
|
|
return $item;
|
|
|
})->all();
|
|
|
return [true, $item_month_list];
|
|
|
@@ -151,8 +153,7 @@ class StatisticService extends StatisticCommonService
|
|
|
$employee_monthly_total_min = $this->calculateSum($month_employee_list,$keys,"total_work");
|
|
|
//查询所有项目人员的工时比例
|
|
|
// 3. 计算分摊比例
|
|
|
- $item_month_list = $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 是集合中的每一行数据
|
|
|
@@ -177,30 +178,35 @@ class StatisticService extends StatisticCommonService
|
|
|
// 注意:round 会根据你的精度要求处理小数
|
|
|
return round($value / 60) * 100;
|
|
|
})->toArray();
|
|
|
-
|
|
|
- $item_month_list = collect($item_month_list)->transform(function ($item) use ($item_title_key_list, $item_code_key_list, $employee_key_list, &$month_total_hour, &$salary_map, &$employee_count) {
|
|
|
+ $sums = ["work_hours"=>$month_total_hour,"allocated_salary"=>$salary_map];
|
|
|
+ $word_keys = [
|
|
|
+ "allocated_salary" =>
|
|
|
+ [
|
|
|
+ "key" => "allocated_salary",
|
|
|
+ "value" => "allocated_salary",
|
|
|
+ "type" => "100b",
|
|
|
+ ],
|
|
|
+ "work_hours" =>
|
|
|
+ [
|
|
|
+ "key" => "work_minutes",
|
|
|
+ "value" => "work_hours",
|
|
|
+ "type" => "hour",
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ $counts = [];
|
|
|
+ foreach ($word_keys as $k=>$v){
|
|
|
+ $counts[$k] = $employee_count;
|
|
|
+ }
|
|
|
+ $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['work_minutes'] / 60,2);
|
|
|
+ $item['total_salary'] = round($item['total_salary'] / 100,2);
|
|
|
$key = $item['employee_id'] . '_' . $item['month'];
|
|
|
// // 如果不是最后一条
|
|
|
- $sums = ["work_hours"=>$month_total_hour,"allocated_salary"=>$salary_map];
|
|
|
- $word_keys = [
|
|
|
- "allocated_salary" =>
|
|
|
- [
|
|
|
- "key" => "allocated_salary",
|
|
|
- "value" => "allocated_salary",
|
|
|
- "type" => "money",
|
|
|
- ],
|
|
|
- "work_hours" =>
|
|
|
- [
|
|
|
- "key" => "work_minutes",
|
|
|
- "value" => "work_hours",
|
|
|
- "type" => "hour",
|
|
|
- ],
|
|
|
- ];
|
|
|
- $this->calculateClosure($key,$item,$employee_count,$sums,$word_keys);
|
|
|
+
|
|
|
+ $this->calculateClosure($key,$item,$counts,$sums,$word_keys);
|
|
|
return $item;
|
|
|
})->all();
|
|
|
return [true, $item_month_list];
|
|
|
@@ -234,14 +240,40 @@ class StatisticService extends StatisticCommonService
|
|
|
|
|
|
$collect = collect($item_month_list);
|
|
|
|
|
|
+ $word_keys = [
|
|
|
+ "total_depreciation" =>
|
|
|
+ [
|
|
|
+ "key" => "allocated_depreciation",
|
|
|
+ "value" => "allocated_depreciation",
|
|
|
+ "type" => "money",
|
|
|
+ ],
|
|
|
+ "total_hours" =>
|
|
|
+ [
|
|
|
+ "key" => "hours",
|
|
|
+ "value" => "hours",
|
|
|
+ "type" => "",
|
|
|
+ ],
|
|
|
+ "ratio" =>
|
|
|
+ [
|
|
|
+ "key" => "ratio",
|
|
|
+ "value" => "ratio",
|
|
|
+ "type" => "ratio",
|
|
|
+ ],
|
|
|
+ ];
|
|
|
$device_count = $collect->groupBy(function ($item) {
|
|
|
// 这里的 $item 是集合中的每一行数据
|
|
|
return $item['device_id'] . '_' . $item['month'];
|
|
|
})->map(function ($group) {
|
|
|
return $group->count();
|
|
|
})->toArray();
|
|
|
+ $device_counts = [];
|
|
|
+ foreach ($word_keys as $k=>$v){
|
|
|
+ $device_counts[$k] = $device_count;
|
|
|
+ }
|
|
|
+ $device_total_depreciation['ratio'] = [];
|
|
|
+
|
|
|
// dd($item_month_list);
|
|
|
- $item_month_list = collect($item_month_list)->transform(function ($item) use ($item_title_key_list, $item_code_key_list, $device_key_list, $device_original_value_key_list, &$device_total_depreciation, &$device_count,&$rate_list) {
|
|
|
+ $item_month_list = collect($item_month_list)->transform(function ($item) use ($item_title_key_list, $item_code_key_list, $device_key_list, $device_original_value_key_list, &$device_total_depreciation, &$device_counts,&$rate_list,$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['device_title'] = $device_key_list[$item['device_id']] ?? "未知人员({$item['device_id']})";
|
|
|
@@ -250,29 +282,7 @@ class StatisticService extends StatisticCommonService
|
|
|
$item['total_hours'] = round($item['total_min'] / 60, 1);
|
|
|
|
|
|
$key = $item['device_id'] . '_' . $item['month'];
|
|
|
- $device_total_depreciation['ratio'] = [];
|
|
|
-// // 如果不是最后一条
|
|
|
- $word_keys = [
|
|
|
- "total_depreciation" =>
|
|
|
- [
|
|
|
- "key" => "allocated_depreciation",
|
|
|
- "value" => "allocated_depreciation",
|
|
|
- "type" => "money",
|
|
|
- ],
|
|
|
- "total_hours" =>
|
|
|
- [
|
|
|
- "key" => "hours",
|
|
|
- "value" => "hours",
|
|
|
- "type" => "",
|
|
|
- ],
|
|
|
- "ratio" =>
|
|
|
- [
|
|
|
- "key" => "ratio",
|
|
|
- "value" => "ratio",
|
|
|
- "type" => "ratio",
|
|
|
- ],
|
|
|
- ];
|
|
|
- $this->calculateClosure($key,$item,$device_count,$device_total_depreciation,$word_keys);
|
|
|
+ $this->calculateClosure($key,$item,$device_counts,$device_total_depreciation,$word_keys);
|
|
|
return $item;
|
|
|
})->all();
|
|
|
return [true, $item_month_list];
|
|
|
@@ -332,7 +342,7 @@ class StatisticService extends StatisticCommonService
|
|
|
// 2. 计算每个员工在每个月的全月总工时
|
|
|
$employee_monthly_total_min = $this->calculateSum($month_employee_list,["employee_id","order_month"],"total_work");
|
|
|
// 2. 计算分摊天数与工资
|
|
|
- $item_list = $this->calculateRatioForMonth($month_employee_list,$employee_monthly_total_min,$salary_map,["employee_id","order_month"],["order_month","item_id","employee_id"]);
|
|
|
+ list($item_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_list);
|
|
|
$employee_count = $collect->groupBy(function ($item) {
|
|
|
// 这里的 $item 是集合中的每一行数据
|
|
|
@@ -700,7 +710,7 @@ class StatisticService extends StatisticCommonService
|
|
|
$key = ["employee_id","order_month"];
|
|
|
$employee_monthly_total_min = $this->calculateSum($month_employee_list,$key,"total_work");
|
|
|
// 3. 计算分摊天数与工资
|
|
|
- $item_list = $this->calculateRatioForMonth($month_employee_list,$employee_monthly_total_min,$salary_map,$key,["employee_id","month","item_id"]);
|
|
|
+ list($item_list,) = $this->calculateRatioForMonth($month_employee_list,$employee_monthly_total_min,$salary_map,$key,["employee_id","month","item_id"]);
|
|
|
$collect = collect($item_list);
|
|
|
$employee_count = $collect->groupBy(function ($item) {
|
|
|
// 这里的 $item 是集合中的每一行数据
|