|
|
@@ -226,11 +226,17 @@ class StatisticService extends Service
|
|
|
//查询所有项目人员的工时比例
|
|
|
//汇总每个人每个月工资
|
|
|
$salary_map = [];
|
|
|
+ $all_salary = [];
|
|
|
foreach ($month_employee_salary as $val) {
|
|
|
$month = $monthly_ps_order_key_list[$val['main_id']] ?? '';
|
|
|
if ($month) {
|
|
|
$salary_map[$val['employee_id'] . '_' . $month] = $val['salary'];
|
|
|
}
|
|
|
+ if(!isset( $all_salary[$val['employee_id']])){
|
|
|
+ $all_salary[$val['employee_id']] = 0;
|
|
|
+ }
|
|
|
+ $all_salary[$val['employee_id']] += $val['salary'];
|
|
|
+
|
|
|
}
|
|
|
// 2. 计算每个员工在每个月的全月总工时
|
|
|
$employee_monthly_total_min = [];
|
|
|
@@ -278,6 +284,14 @@ class StatisticService extends Service
|
|
|
$item_month_list[$k]['total_hours'] = round($v['total_min'] / 60);
|
|
|
unset($item_month_list[$k]['work_minutes']);
|
|
|
}
|
|
|
+
|
|
|
+ $collect = collect($item_month_list);
|
|
|
+ $employee_count = $collect->groupBy('employee_id')
|
|
|
+ ->map(function ($group) {
|
|
|
+ return $group->count(); // 统计每个分组里的数量
|
|
|
+ })
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
$item_month_list = collect($item_month_list)->sortBy('month')->values()->all();
|
|
|
$items = collect($item_month_list)->pluck('item_id')->unique()->values()->all();
|
|
|
$item = Item::Clear($user, $data);
|
|
|
@@ -289,10 +303,15 @@ class StatisticService extends Service
|
|
|
$employee = Employee::Clear($user, $data);
|
|
|
$employee_key_list = $employee->wherein('id', $employee_ids)->pluck("title", "id")->toArray();
|
|
|
|
|
|
- $item_month_list = collect($item_month_list)->transform(function ($item) use ($item_title_key_list, $item_code_key_list, $employee_key_list) {
|
|
|
+ $item_month_list = collect($item_month_list)->transform(function ($item,$index) use ($item_title_key_list, $item_code_key_list, $employee_key_list,&$employee_count,&$all_salary) {
|
|
|
$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']})";
|
|
|
+ if(--$employee_count[$item['employee_id']] > 0){
|
|
|
+ $all_salary[$item['employee_id']] -= $item['total_salary'];
|
|
|
+ }else{
|
|
|
+ $item['total_salary'] = $all_salary[$item['employee_id']];
|
|
|
+ }
|
|
|
return $item;
|
|
|
})->all();
|
|
|
return [true, $item_month_list];
|