|
|
@@ -120,11 +120,13 @@ class StatisticService extends Service
|
|
|
//查询所有项目人员的工时比例
|
|
|
//汇总每个人每个月工资
|
|
|
$salary_map = [];
|
|
|
+ $all_salary = 0;
|
|
|
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'];
|
|
|
}
|
|
|
+ $all_salary += $val['salary'];
|
|
|
}
|
|
|
// var_dump($salary_map);die;
|
|
|
// 2. 计算每个员工在每个月的全月总工时
|
|
|
@@ -167,16 +169,29 @@ class StatisticService extends Service
|
|
|
|
|
|
foreach ($item_month_list as $k => $v) {
|
|
|
$item_month_list[$k]['days'] = round($v['work_minutes'] / 8 / 60);
|
|
|
- unset($item_month_list[$k]['work_minutes']);
|
|
|
}
|
|
|
+ $collect = collect($item_month_list);
|
|
|
+ $total_day = round($collect->sum('work_minutes')/8/60);
|
|
|
+ $count = $collect->count();
|
|
|
$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);
|
|
|
$item_title_key_list = $item->wherein('id', $items)->pluck("title", "id")->toArray();
|
|
|
$item_code_key_list = $item->wherein('id', $items)->pluck("code", "id")->toArray();
|
|
|
- $item_month_list = collect($item_month_list)->transform(function ($item) use ($item_title_key_list, $item_code_key_list) {
|
|
|
+ $item_month_list = collect($item_month_list)->transform(function ($item,$index) use ($item_title_key_list, $item_code_key_list,&$total_day,&$all_salary,$count) {
|
|
|
$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'],2);
|
|
|
+ // 如果不是最后一条
|
|
|
+ if ($index < $count - 1) {
|
|
|
+ $total_day -= $item['day'];
|
|
|
+ // 关键:递减外部的 $absolute_total_hours
|
|
|
+ $all_salary -= $item['allocated_salary'];
|
|
|
+ } else {
|
|
|
+ // 最后一条:直接拿剩下的“余额”
|
|
|
+ $item['day'] = $total_day;
|
|
|
+ $item['allocated_salary'] = $all_salary;
|
|
|
+ }
|
|
|
return $item;
|
|
|
})->all();
|
|
|
return [true, $item_month_list];
|