|
|
@@ -602,8 +602,8 @@ class StatisticService extends Service
|
|
|
"code" => $v['code'],
|
|
|
"title" => $v['title'],
|
|
|
"state" => $v['state'] == 3 ? "完结" : "进行中",
|
|
|
- "employee_salary" => $item_employee_list[$v['id']]['salary'] ?? 0,
|
|
|
- "device_depreciation" => $item_device_list[$v['id']]['depreciation'] ?? 0,
|
|
|
+ "employee_salary" => isset($item_employee_list[$v['id']]['salary']) ? round($item_employee_list[$v['id']]['salary']/100,2) : 0,
|
|
|
+ "device_depreciation" => isset($item_device_list[$v['id']]['depreciation']) ? round($item_device_list[$v['id']]['depreciation']/100,2): 0,
|
|
|
"expense_type" => "费用化支出",
|
|
|
"fee_list" => collect($item_fee_list[$v['id']] ?? [])->values()->all(),
|
|
|
];
|
|
|
@@ -663,12 +663,12 @@ class StatisticService extends Service
|
|
|
$item_list = [];
|
|
|
foreach ($month_employee_list as $item) {
|
|
|
$key = $item['employee_id'] . '_' . $item['order_month'];
|
|
|
- $item_key = $item['item_id'];
|
|
|
- if (!isset($item_list[$item_key])) {
|
|
|
- $item_list[$item_key] = [
|
|
|
- "salary" => 0,
|
|
|
- ];
|
|
|
- }
|
|
|
+// $item_key = $item['item_id'].'_'.$item['order_month'];
|
|
|
+// if (!isset($item_list[$item_key])) {
|
|
|
+// $item_list[$item_key] = [
|
|
|
+// "salary" => 0,
|
|
|
+// ];
|
|
|
+// }
|
|
|
$total_salary = $salary_map[$key] ?? 0;
|
|
|
$total_min = $employee_monthly_total_min[$key] ?? 0;
|
|
|
|
|
|
@@ -679,9 +679,39 @@ class StatisticService extends Service
|
|
|
} else {
|
|
|
$allocated_salary = 0;
|
|
|
}
|
|
|
- $item_list[$item_key]['salary'] += $allocated_salary;
|
|
|
+ $item_list[] = [
|
|
|
+ 'employee_id' => $item['employee_id'],
|
|
|
+ 'allocated_salary' => $allocated_salary*100,
|
|
|
+ 'month' => $item['order_month'],
|
|
|
+ 'item_id' => $item['item_id'],
|
|
|
+ ];
|
|
|
}
|
|
|
- return $item_list;
|
|
|
+ $collect = collect($item_list);
|
|
|
+ $employee_count = $collect->groupBy(function ($item) {
|
|
|
+ // 这里的 $item 是集合中的每一行数据
|
|
|
+ return $item['employee_id'] . '_' . $item['month'];
|
|
|
+ })->map(function ($group) {
|
|
|
+ return $group->count();
|
|
|
+ })->toArray();
|
|
|
+
|
|
|
+ $month_employee_list = $collect->transform(function ($item, $index) use (&$employee_count,&$salary_map) {
|
|
|
+
|
|
|
+ // 如果不是最后一条
|
|
|
+ $key = $item['employee_id'] . '_' . $item['month'];
|
|
|
+ if (--$employee_count[$key] > 0) {
|
|
|
+ $salary_map[$key] -= $item['allocated_salary'];
|
|
|
+ } else {
|
|
|
+ $item['allocated_salary'] = $salary_map[$key];
|
|
|
+ }
|
|
|
+ return $item;
|
|
|
+ })->all();
|
|
|
+ $return_item_list = [];
|
|
|
+ foreach ($month_employee_list as $v){
|
|
|
+ $key = $v['item_id'];
|
|
|
+ if(!isset($return_item_list[$key])) $return_item_list[$key]['salary'] = 0;
|
|
|
+ $return_item_list[$key]['salary'] += $v['allocated_salary'];
|
|
|
+ }
|
|
|
+ return $return_item_list;
|
|
|
}
|
|
|
|
|
|
private function getDeviceItemSalary($month_start, $month_end, $data, $user)
|
|
|
@@ -731,14 +761,14 @@ class StatisticService extends Service
|
|
|
$item_list = [];
|
|
|
foreach ($month_device_list as $item) {
|
|
|
$key = $item['device_id'] . '_' . $item['order_month'];
|
|
|
- $device_key = $item['item_id'];
|
|
|
+// $device_key = $item['item_id'];
|
|
|
$total_depreciatio = $depreciatio_map[$key] ?? 0;
|
|
|
$total_min = $device_monthly_total_min[$key] ?? 0;
|
|
|
- if (!isset($item_list[$device_key])) {
|
|
|
- $item_list[$device_key] = [
|
|
|
- "depreciation" => 0,
|
|
|
- ];
|
|
|
- }
|
|
|
+// if (!isset($item_list[$device_key])) {
|
|
|
+// $item_list[$device_key] = [
|
|
|
+// "depreciation" => 0,
|
|
|
+// ];
|
|
|
+// }
|
|
|
// B. 计算工资分摊:(项目工时 / 月总工时) * 月工资
|
|
|
if ($total_min > 0) {
|
|
|
$ratio = round($item['total_work'] / $total_min, 3);
|
|
|
@@ -746,7 +776,37 @@ class StatisticService extends Service
|
|
|
} else {
|
|
|
$allocated_salary = 0;
|
|
|
}
|
|
|
- $item_list[$device_key]['depreciation'] += $allocated_salary;
|
|
|
+ $item_list[] = [
|
|
|
+ 'device_id' => $item['device_id'],
|
|
|
+ 'depreciation' => $allocated_salary*100,
|
|
|
+ 'month' => $item['order_month'],
|
|
|
+ 'item_id' => $item['item_id'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $collect = collect($item_list);
|
|
|
+ $device_count = $collect->groupBy(function ($item) {
|
|
|
+ // 这里的 $item 是集合中的每一行数据
|
|
|
+ return $item['device_id'] . '_' . $item['month'];
|
|
|
+ })->map(function ($group) {
|
|
|
+ return $group->count();
|
|
|
+ })->toArray();
|
|
|
+
|
|
|
+ $month_employee_list = $collect->transform(function ($item, $index) use (&$device_count,&$depreciatio_map) {
|
|
|
+
|
|
|
+ // 如果不是最后一条
|
|
|
+ $key = $item['device_id'] . '_' . $item['month'];
|
|
|
+ if (--$device_count[$key] > 0) {
|
|
|
+ $depreciatio_map[$key] -= $item['depreciation'];
|
|
|
+ } else {
|
|
|
+ $item['depreciation'] = $depreciatio_map[$key];
|
|
|
+ }
|
|
|
+ return $item;
|
|
|
+ })->all();
|
|
|
+ $return_item_list = [];
|
|
|
+ foreach ($month_employee_list as $v){
|
|
|
+ $key = $v['item_id'];
|
|
|
+ if(!isset($return_item_list[$key])) $return_item_list[$key]['depreciation'] = 0;
|
|
|
+ $return_item_list[$key]['depreciation'] += $v['depreciation'];
|
|
|
}
|
|
|
return $item_list;
|
|
|
}
|
|
|
@@ -817,11 +877,11 @@ class StatisticService extends Service
|
|
|
];
|
|
|
}
|
|
|
if ($item['entrust_type'] == 1) {
|
|
|
- $item_key_list[$key][$rootId]['entrust1_amount'] += $item['amount'];
|
|
|
+ $item_key_list[$key][$rootId]['entrust1_amount'] += $item['amount']*100;
|
|
|
} elseif ($item['entrust_type'] == 2) {
|
|
|
- $item_key_list[$key][$rootId]['entrust2_amount'] += $item['amount'];
|
|
|
+ $item_key_list[$key][$rootId]['entrust2_amount'] += $item['amount']*100;
|
|
|
}
|
|
|
- $item_key_list[$key][$rootId]['total_amount'] += $item['amount'];
|
|
|
+ $item_key_list[$key][$rootId]['total_amount'] += $item['amount']*100;
|
|
|
//这边需要拿到头部所有的一级费用类型
|
|
|
if (!isset($type_list[$rootId])) {
|
|
|
$type_list[$rootId] = [
|
|
|
@@ -832,6 +892,20 @@ class StatisticService extends Service
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+// var_dump($item_key_list);die;
|
|
|
+ foreach ($item_key_list as $k=>$v){
|
|
|
+ foreach ($v as $kk=>$vv){
|
|
|
+ $item_key_list[$k][$kk]['entrust1_amount'] = round( $vv['entrust1_amount']/100,2);
|
|
|
+ $item_key_list[$k][$kk]['entrust2_amount'] = round( $vv['entrust2_amount']/100,2);
|
|
|
+ $item_key_list[$k][$kk]['total_amount'] = round( $vv['total_amount']/100,2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+// $item_key_list = collect($item_key_list)->transform(function ($item) {
|
|
|
+// $item['entrust1_amount'] = round( $item['entrust1_amount']/100,2);
|
|
|
+// $item['entrust2_amount'] = round( $item['entrust2_amount']/100,2);
|
|
|
+// $item['total_amount'] = round( $item['total_amount']/100,2);
|
|
|
+// return $item;
|
|
|
+// })->all();
|
|
|
// 使用 values() 丢弃原始键名,重新从 0 开始建立索引
|
|
|
$type_list = collect($type_list)->sortBy('sort')->values()->all();
|
|
|
// 4. 重置数组索引并返回
|