|
@@ -226,16 +226,16 @@ class StatisticService extends Service
|
|
|
//查询所有项目人员的工时比例
|
|
//查询所有项目人员的工时比例
|
|
|
//汇总每个人每个月工资
|
|
//汇总每个人每个月工资
|
|
|
$salary_map = [];
|
|
$salary_map = [];
|
|
|
-// $all_salary = [];
|
|
|
|
|
|
|
+ $all_salary = [];
|
|
|
foreach ($month_employee_salary as $val) {
|
|
foreach ($month_employee_salary as $val) {
|
|
|
$month = $monthly_ps_order_key_list[$val['main_id']] ?? '';
|
|
$month = $monthly_ps_order_key_list[$val['main_id']] ?? '';
|
|
|
if ($month) {
|
|
if ($month) {
|
|
|
$salary_map[$val['employee_id'] . '_' . $month] = $val['salary'];
|
|
$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'];
|
|
|
|
|
|
|
+ if(!isset($all_salary[$val['employee_id']])){
|
|
|
|
|
+ $all_salary[$val['employee_id']] = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ $all_salary[$val['employee_id']] += $val['salary'];
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
// 2. 计算每个员工在每个月的全月总工时
|
|
// 2. 计算每个员工在每个月的全月总工时
|
|
@@ -250,6 +250,7 @@ class StatisticService extends Service
|
|
|
|
|
|
|
|
// 3. 计算分摊天数与工资
|
|
// 3. 计算分摊天数与工资
|
|
|
$item_month_list = [];
|
|
$item_month_list = [];
|
|
|
|
|
+ $total_work_min = [];
|
|
|
foreach ($month_employee_list as $item) {
|
|
foreach ($month_employee_list as $item) {
|
|
|
$key = $item['employee_id'] . '_' . $item['order_month'];
|
|
$key = $item['employee_id'] . '_' . $item['order_month'];
|
|
|
$employee_key = $item['order_month'] . '_' . $item['item_id'] . '_' . $item['employee_id'];
|
|
$employee_key = $item['order_month'] . '_' . $item['item_id'] . '_' . $item['employee_id'];
|
|
@@ -277,20 +278,20 @@ class StatisticService extends Service
|
|
|
}
|
|
}
|
|
|
$item_month_list[$employee_key]['allocated_salary'] += $allocated_salary;
|
|
$item_month_list[$employee_key]['allocated_salary'] += $allocated_salary;
|
|
|
$item_month_list[$employee_key]['work_minutes'] += $item['total_work'];
|
|
$item_month_list[$employee_key]['work_minutes'] += $item['total_work'];
|
|
|
|
|
+ if(!isset( $total_work_min[$item['employee_id']])) $total_work_min[$item['employee_id']] = 0;
|
|
|
|
|
+ $total_work_min[$item['employee_id']] += $item['total_work'];
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- foreach ($item_month_list as $k => $v) {
|
|
|
|
|
- $item_month_list[$k]['work_hours'] = round($v['work_minutes'] / 60, 2);
|
|
|
|
|
- $item_month_list[$k]['total_hours'] = round($v['total_min'] / 60);
|
|
|
|
|
- unset($item_month_list[$k]['work_minutes']);
|
|
|
|
|
|
|
+ foreach ($total_work_min as $k=>$v){
|
|
|
|
|
+ $total_work_min[$k] = round($v / 60, 2);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// $collect = collect($item_month_list);
|
|
|
|
|
-// $employee_count = $collect->groupBy('employee_id')
|
|
|
|
|
-// ->map(function ($group) {
|
|
|
|
|
-// return $group->count(); // 统计每个分组里的数量
|
|
|
|
|
-// })
|
|
|
|
|
-// ->toArray();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $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();
|
|
$item_month_list = collect($item_month_list)->sortBy('month')->values()->all();
|
|
|
$items = collect($item_month_list)->pluck('item_id')->unique()->values()->all();
|
|
$items = collect($item_month_list)->pluck('item_id')->unique()->values()->all();
|
|
@@ -303,15 +304,20 @@ class StatisticService extends Service
|
|
|
$employee = Employee::Clear($user, $data);
|
|
$employee = Employee::Clear($user, $data);
|
|
|
$employee_key_list = $employee->wherein('id', $employee_ids)->pluck("title", "id")->toArray();
|
|
$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,&$total_work_min,&$all_salary,&$employee_count) {
|
|
|
$item['item_title'] = $item_title_key_list[$item['item_id']] ?? "未知项目({$item['item_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']})";
|
|
$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['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']];
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ $item['work_hours'] = round($item['work_minutes'] / 60, 2);
|
|
|
|
|
+ $item['total_hours'] = round($item['total_min'] / 60);
|
|
|
|
|
+ if(--$employee_count[$item['employee_id']] > 0){
|
|
|
|
|
+ $all_salary[$item['employee_id']] -= $item['allocated_salary'];
|
|
|
|
|
+ $total_work_min[$item['employee_id']] -= $item['work_hours'];
|
|
|
|
|
+
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $item['allocated_salary'] = $all_salary[$item['employee_id']];
|
|
|
|
|
+ $item['work_hours'] = $total_work_min[$item['employee_id']];
|
|
|
|
|
+ }
|
|
|
return $item;
|
|
return $item;
|
|
|
})->all();
|
|
})->all();
|
|
|
return [true, $item_month_list];
|
|
return [true, $item_month_list];
|