|
|
@@ -570,7 +570,6 @@ class ExportFileService extends Service
|
|
|
$sourceData = collect($result);
|
|
|
|
|
|
// 2. 按月份分组,准备多 Sheet 数据
|
|
|
- // 结构:[ '2024-04' => [ 'days' => 30, 'data' => [...] ], ... ]
|
|
|
$monthsData = [];
|
|
|
|
|
|
// 按月分组数据
|
|
|
@@ -578,16 +577,14 @@ class ExportFileService extends Service
|
|
|
return date('Y年m月', strtotime($item['order_date']));
|
|
|
});
|
|
|
|
|
|
- //获取公司基本信息
|
|
|
+ // 获取公司基本信息
|
|
|
$company = EmployeeService::getCompanyDetail($user);
|
|
|
|
|
|
foreach ($groupedByMonth as $monthName => $monthItems) {
|
|
|
- // A. 计算该月总天数
|
|
|
- // 转换 '2024年04月' 为 '2024-04' 获取天数
|
|
|
$formatMonth = str_replace(['年', '月'], ['-', ''], $monthName);
|
|
|
$daysInMonth = date('t', strtotime($formatMonth . '-01'));
|
|
|
|
|
|
- // B. 进一步按 项目+人员 分组,因为一行显示一个项目一个人的全月工时
|
|
|
+ // 按 项目+人员 分组
|
|
|
$groupedByUserItem = $monthItems->groupBy(function ($item) {
|
|
|
return $item['item_code'] . '_' . $item['employee_id'];
|
|
|
});
|
|
|
@@ -601,16 +598,23 @@ class ExportFileService extends Service
|
|
|
$first['employee_name']
|
|
|
];
|
|
|
|
|
|
- // C. 循环 1 号到该月最后一天,填充工时
|
|
|
- // 将该员工该项目在这个月的记录转为 日期 => 工时 的映射
|
|
|
+ // 映射日期 => 记录
|
|
|
$dayMap = $records->keyBy(function($r){
|
|
|
return (int)date('d', strtotime($r['order_date']));
|
|
|
});
|
|
|
|
|
|
for ($d = 1; $d <= $daysInMonth; $d++) {
|
|
|
- $workHour = $dayMap->get($d)['total_work_hours'] ?? '';
|
|
|
- // 如果工时为 0 或空,按你要求的格式传空字符串
|
|
|
- $row[] = ($workHour > 0) ?(float) $workHour : '';
|
|
|
+ $record = $dayMap->get($d);
|
|
|
+
|
|
|
+ // ==================== 【核心改动点】 ====================
|
|
|
+ // 不使用截断后的 $record['total_work_hours']
|
|
|
+ // 直接使用原始分钟数 $record['total_work'] 除以 60,保留高精度浮点数给 Excel
|
|
|
+ if ($record && isset($record['total_work']) && $record['total_work'] > 0) {
|
|
|
+ $row[] = (float)($record['total_work'] / 60);
|
|
|
+ } else {
|
|
|
+ $row[] = '';
|
|
|
+ }
|
|
|
+ // ========================================================
|
|
|
}
|
|
|
|
|
|
$sheetRows[] = $row;
|