|
|
@@ -884,7 +884,7 @@ class ExportFileService extends Service
|
|
|
$year = date("Y", strtotime($raw_list[0]['voucher_date']));
|
|
|
$company = Depart::where('id', $user['top_depart_id'])->value('title');
|
|
|
|
|
|
- // ================== 【核心修改 1:重构与排序所有金额列】 ==================
|
|
|
+ // ================== 【核心修复 1:精准使用 $feeItem['id'] 参与排序与映射】 ==================
|
|
|
// 1. 定义固定的人员和折旧列配置并赋予 sort
|
|
|
$amountColumnsConfig = [
|
|
|
[
|
|
|
@@ -899,11 +899,12 @@ class ExportFileService extends Service
|
|
|
]
|
|
|
];
|
|
|
|
|
|
- // 2. 将动态费用类型塞入同一个配置池中
|
|
|
- foreach ($fee_type_list as $feeId => $feeItem) {
|
|
|
+ // 2. 将动态费用类型塞入同一个配置池中(【修复点】:从 $feeItem['id'] 读出真实的 55, 56 等真实ID)
|
|
|
+ foreach ($fee_type_list as $feeItem) {
|
|
|
+ $realFeeId = $feeItem['id'] ?? 0;
|
|
|
$amountColumnsConfig[] = [
|
|
|
- 'type_key' => 'fee_' . $feeId, // 对应原逻辑 type == 3 && fee_id == $feeId
|
|
|
- 'fee_id' => $feeId,
|
|
|
+ 'type_key' => 'fee_' . $realFeeId,
|
|
|
+ 'fee_id' => $realFeeId, // 显式留存住真实的数据库 ID,不再受数组索引干扰
|
|
|
'title' => $feeItem['title'] ?? '',
|
|
|
'sort' => (int)($feeItem['sort'] ?? 0),
|
|
|
];
|
|
|
@@ -915,12 +916,8 @@ class ExportFileService extends Service
|
|
|
// 4. 提取出最终的动态表头名称供 Excel 使用
|
|
|
$dynamicHeaderTitles = array_column($sortedAmountColumns, 'title');
|
|
|
|
|
|
- // 5. 计算总列数:
|
|
|
- // 前面基础4列(日期、凭证种类、凭证号、摘要)
|
|
|
- // 加上 2列(记账凭证金额、本期归集金额)
|
|
|
- // 加上 排序后的所有科目列数
|
|
|
- // 加上 2列(委托境内、委托境外)
|
|
|
- $baseColCount = 6; // 前面基础共6列金额及非金额列
|
|
|
+ // 5. 计算总列数
|
|
|
+ $baseColCount = 6;
|
|
|
$sortedColCount = count($sortedAmountColumns);
|
|
|
$totalColCount = $baseColCount + $sortedColCount + 2;
|
|
|
// =========================================================================
|
|
|
@@ -954,7 +951,7 @@ class ExportFileService extends Service
|
|
|
(float)($row['aggregation_amount'] ?? 0),
|
|
|
];
|
|
|
|
|
|
- // ================== 【核心修改 2:依照排序配置填充科目金额】 ==================
|
|
|
+ // ================== 【核心修复 2:依照正确的真实 fee_id 填充科目金额】 ==================
|
|
|
foreach ($sortedAmountColumns as $col) {
|
|
|
$colValue = 0.0;
|
|
|
|
|
|
@@ -965,7 +962,7 @@ class ExportFileService extends Service
|
|
|
// 折旧费用
|
|
|
$colValue = ($row['type'] == 2 ? (float)$row['total_amount'] : 0);
|
|
|
} else {
|
|
|
- // 动态费用科目
|
|
|
+ // 动态费用科目(【修复点】:此时的 $col['fee_id'] 已经能够完美匹配 $row['fee_id'])
|
|
|
$colValue = ($row['type'] == 3 && $row['fee_id'] == $col['fee_id']) ? (float)$row['total_amount'] : 0;
|
|
|
}
|
|
|
|
|
|
@@ -990,7 +987,7 @@ class ExportFileService extends Service
|
|
|
unset($group['totals']); // 释放内存
|
|
|
}
|
|
|
|
|
|
- // 8. 导出逻辑保持不变
|
|
|
+ // 8. 导出逻辑
|
|
|
$file_name = "年度研发支出辅助账汇总统计表_" . date("Y-m-d") . "_". rand(1000,9999);
|
|
|
$filename = $file_name . '.xlsx';
|
|
|
|