cqp vor 2 Wochen
Ursprung
Commit
2f367bac6d
1 geänderte Dateien mit 12 neuen und 4 gelöschten Zeilen
  1. 12 4
      app/Exports/ResearchExpenseSummarySheetExport.php

+ 12 - 4
app/Exports/ResearchExpenseSummarySheetExport.php

@@ -76,7 +76,7 @@ class ResearchExpenseSummarySheetExport implements WithEvents, WithTitle
                         $sheet->setCellValue("{$col}{$currentRow}", $item['values'][$idx] ?? 0);
                     }
 
-                    // 固定数值列
+                    // 固定数值列(听你的!全量直接由传来数据赋值,不乱动了)
                     $sheet->setCellValue("{$col_7_1}{$currentRow}", $item['val7_1'] ?? 0);
                     $sheet->setCellValue("{$col_7_2}{$currentRow}", $item['val7_2'] ?? 0);
                     $sheet->setCellValue("{$col_8_1}{$currentRow}", $item['val8_1'] ?? 0);
@@ -86,11 +86,19 @@ class ResearchExpenseSummarySheetExport implements WithEvents, WithTitle
                     $firstDetailCol = Coordinate::stringFromColumnIndex($startDetailIdx);
                     $lastDetailCol = Coordinate::stringFromColumnIndex($startDetailIdx + $totalDynamic - 1);
 
+                    // F列:前n项之和不变
                     $sheet->setCellValue("{$col_6}{$currentRow}", "=SUM({$firstDetailCol}{$currentRow}:{$lastDetailCol}{$currentRow})");
-//                    $sheet->setCellValue("{$col_7_2}{$currentRow}", "={$col_7_1}{$currentRow}");
+
+                    // 委托研发保持八折
                     $sheet->setCellValue("{$col_8_2}{$currentRow}", "={$col_8_1}{$currentRow}*0.8");
                     $sheet->setCellValue("{$col_8_4}{$currentRow}", "={$col_8_3}{$currentRow}*0.8");
-                    $sheet->setCellValue("{$col_E}{$currentRow}", "={$col_6}{$currentRow}+{$col_7_2}{$currentRow}+{$col_8_2}{$currentRow}+{$col_8_4}{$currentRow}");
+
+                    // ⭐【核心修改】只改 E 列的公式逻辑
+                    // 严格按照:IF((前n项小计+其他合计7.1)*0.1 < 其他合计7.1, (前n项小计+其他合计7.1)*0.1 + 前n项小计, 其他合计7.1 + 前n项小计) + 委托境内8.2 + 委托境外8.4
+                    $sheet->setCellValue(
+                        "{$col_E}{$currentRow}",
+                        "=IF(({$col_6}{$currentRow}+{$col_7_1}{$currentRow})*0.1 < {$col_7_1}{$currentRow}, ({$col_6}{$currentRow}+{$col_7_1}{$currentRow})*0.1 + {$col_6}{$currentRow}, {$col_7_1}{$currentRow} + {$col_6}{$currentRow}) + {$col_8_2}{$currentRow} + {$col_8_4}{$currentRow}"
+                    );
 
                     // 严格清洗类型字符串进行归集
                     $cleanType = preg_replace('/[\s\v\t\r\n]+/u', '', (string)$item['type']);
@@ -102,7 +110,7 @@ class ResearchExpenseSummarySheetExport implements WithEvents, WithTitle
                     $currentRow++;
                 }
 
-                // 5. 应用合计逻辑
+                // 5. 应用合计逻辑(底部的统筹汇总逻辑不受明细行E列公式影响)
                 $this->applyDynamicSummaryLogic($sheet, $currentRow, $capRows, $expRows, $startDetailIdx, $totalDynamic, $col_E, $col_6, $col_7_1, $col_7_2, $col_8_1, $col_8_2, $col_8_3, $col_8_4);
 
                 // 6. 最终样式