cqp преди 1 седмица
родител
ревизия
93e28794d3
променени са 3 файла, в които са добавени 50 реда и са изтрити 27 реда
  1. 46 27
      app/Exports/ResearchExpenseSummarySheetExport.php
  2. 2 0
      app/Service/ExportFileService.php
  3. 2 0
      app/Service/StatisticService.php

+ 46 - 27
app/Exports/ResearchExpenseSummarySheetExport.php

@@ -34,11 +34,11 @@ class ResearchExpenseSummarySheetExport implements WithEvents, WithTitle
             AfterSheet::class => function (AfterSheet $event) {
                 $sheet = $event->sheet->getDelegate();
 
-                // 1. 计算列索引
+                // 1. 计算列索引(因插入了开始和结束时间,核心列整体右移 2 列)
                 $totalDynamic = count($this->dynamicHeaders);
-                $startDetailIdx = 6; // F列
+                $startDetailIdx = 8; // 动态科目从第 8 列(H列)开始
 
-                $col_E = 'E';
+                $col_G = 'G'; // 允许加计扣除金额合计列(右移至 G 列)
                 $col_6 = Coordinate::stringFromColumnIndex($startDetailIdx + $totalDynamic);
                 $col_7_1 = Coordinate::stringFromColumnIndex($startDetailIdx + $totalDynamic + 1);
                 $col_7_2 = Coordinate::stringFromColumnIndex($startDetailIdx + $totalDynamic + 2);
@@ -51,14 +51,19 @@ class ResearchExpenseSummarySheetExport implements WithEvents, WithTitle
 
                 // 2. 设置布局
                 $sheet->getColumnDimension('B')->setWidth(40);
+                $sheet->getColumnDimension('D')->setWidth(15); // 开始时间列宽
+                $sheet->getColumnDimension('E')->setWidth(15); // 结束时间列宽
+
                 $lastColNum = Coordinate::columnIndexFromString($highestColumn);
                 for ($i = 1; $i <= $lastColNum; $i++) {
                     $col = Coordinate::stringFromColumnIndex($i);
-                    if ($col != 'B') $sheet->getColumnDimension($col)->setWidth(13);
+                    if (!in_array($col, ['B', 'D', 'E'])) {
+                        $sheet->getColumnDimension($col)->setWidth(13);
+                    }
                 }
 
                 // 3. 绘制表头
-                $this->drawDynamicHeader($sheet, $col_E, $col_6, $col_7_1, $col_8_1, $highestColumn);
+                $this->drawDynamicHeader($sheet, $col_G, $col_6, $col_7_1, $col_8_1, $highestColumn);
 
                 // 4. 填充明细
                 $currentRow = 8;
@@ -68,15 +73,20 @@ class ResearchExpenseSummarySheetExport implements WithEvents, WithTitle
                     $sheet->setCellValue("A{$currentRow}", $item['no']);
                     $sheet->setCellValue("B{$currentRow}", $item['name']);
                     $sheet->setCellValue("C{$currentRow}", $item['status'] == 3 ? '已完成' : '进行中');
-                    $sheet->setCellValue("D{$currentRow}", $item['type']);
 
-                    // 动态明细
+                    // 新增的时间列注入
+                    $sheet->setCellValue("D{$currentRow}", $item['start_time'] ?? '');
+                    $sheet->setCellValue("E{$currentRow}", $item['end_time'] ?? '');
+
+                    $sheet->setCellValue("F{$currentRow}", $item['type']);
+
+                    // 动态明细从第 8 列(H列)向右填充
                     foreach ($this->dynamicHeaders as $idx => $header) {
                         $col = Coordinate::stringFromColumnIndex($startDetailIdx + $idx);
                         $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,17 +96,16 @@ class ResearchExpenseSummarySheetExport implements WithEvents, WithTitle
                     $firstDetailCol = Coordinate::stringFromColumnIndex($startDetailIdx);
                     $lastDetailCol = Coordinate::stringFromColumnIndex($startDetailIdx + $totalDynamic - 1);
 
-                    // F列:前n项之和不变
+                    // 前n项之和公式
                     $sheet->setCellValue("{$col_6}{$currentRow}", "=SUM({$firstDetailCol}{$currentRow}:{$lastDetailCol}{$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");
 
-                    // ⭐【核心修改】只改 E 列的公式逻辑
-                    // 严格按照:IF((前n项小计+其他合计7.1)*0.1 < 其他合计7.1, (前n项小计+其他合计7.1)*0.1 + 前n项小计, 其他合计7.1 + 前n项小计)
+                    // ⭐ 只改 G 列(原E列)的公式逻辑,严格匹配原判断逻辑
                     $sheet->setCellValue(
-                        "{$col_E}{$currentRow}",
+                        "{$col_G}{$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})"
                     );
 
@@ -110,29 +119,29 @@ class ResearchExpenseSummarySheetExport implements WithEvents, WithTitle
                     $currentRow++;
                 }
 
-                // 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);
+                // 5. 应用底部合计逻辑
+                $this->applyDynamicSummaryLogic($sheet, $currentRow, $capRows, $expRows, $startDetailIdx, $totalDynamic, $col_G, $col_6, $col_7_1, $col_7_2, $col_8_1, $col_8_2, $col_8_3, $col_8_4);
 
-                // 6. 最终样式
+                // 6. 最终样式区域调整
                 $lastDataRow = $currentRow + 3;
                 $sheet->getStyle("A5:{$highestColumn}{$lastDataRow}")->applyFromArray(['borders' => ['allBorders' => ['borderStyle' => Border::BORDER_THIN]]]);
-                $sheet->getStyle("E8:{$highestColumn}{$lastDataRow}")->getNumberFormat()->setFormatCode('#,##0.00');
+                $sheet->getStyle("G8:{$highestColumn}{$lastDataRow}")->getNumberFormat()->setFormatCode('#,##0.00'); // 从G列开始应用财务数字格式
                 $sheet->getStyle("A5:{$highestColumn}7")->getAlignment()->setWrapText(true)->setHorizontal('center')->setVertical('center');
             },
         ];
     }
 
-    private function drawDynamicHeader($sheet, $col_E, $col_6, $col_7_1, $col_8_1, $highestColumn)
+    private function drawDynamicHeader($sheet, $col_G, $col_6, $col_7_1, $col_8_1, $highestColumn)
     {
         $sheet->mergeCells("A2:{$highestColumn}2");
         $sheet->setCellValue('A2', '研发支出辅助账汇总表');
         $sheet->getStyle('A2')->applyFromArray(['font' => ['size' => 16, 'bold' => true], 'alignment' => ['horizontal' => Alignment::HORIZONTAL_CENTER]]);
 
-        // 第3行布局修复
+        // 第3行企业基本信息布局
         $totalCols = Coordinate::columnIndexFromString($highestColumn);
         $sheet->setCellValue('A3', '纳税人识别号(统一社会信用代码):' . $this->taxId);
 
-        $nameCol = Coordinate::stringFromColumnIndex(max(7, floor($totalCols * 0.55)));
+        $nameCol = Coordinate::stringFromColumnIndex(max(9, floor($totalCols * 0.55)));
         $sheet->setCellValue($nameCol . '3', '纳税人名称:' . $this->companyName);
 
         $periodCol = Coordinate::stringFromColumnIndex($totalCols - 3);
@@ -141,14 +150,22 @@ class ResearchExpenseSummarySheetExport implements WithEvents, WithTitle
         $sheet->setCellValue($highestColumn . '3', '单位:元');
         $sheet->getStyle($highestColumn . '3')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
 
-        // 表头 5-7 行
-        $vHeaders = ['A'=>'项目编号', 'B'=>'项目名称', 'C'=>'完成情况', 'D'=>'支出类型', 'E'=>"允许加计\n扣除金额合计"];
+        // 表头 5-7 行(重排并插入了时间列)
+        $vHeaders = [
+            'A' => '项目编号',
+            'B' => '项目名称',
+            'C' => '完成情况',
+            'D' => "开始时间",
+            'E' => "结束时间",
+            'F' => '支出类型',
+            'G' => "允许加计\n扣除金额合计"
+        ];
         foreach ($vHeaders as $col => $text) {
             $sheet->mergeCells("{$col}5:{$col}7");
             $sheet->setCellValue("{$col}5", $text);
         }
 
-        $startIdx = 6;
+        $startIdx = 8; // 动态科目调整至 H列(第8列)开始
         foreach ($this->dynamicHeaders as $idx => $text) {
             $col = Coordinate::stringFromColumnIndex($startIdx + $idx);
             $sheet->mergeCells("{$col}5:{$col}6");
@@ -169,7 +186,7 @@ class ResearchExpenseSummarySheetExport implements WithEvents, WithTitle
         $sheet->mergeCells("{$col_8_1}5:{$highestColumn}5");
         $sheet->setCellValue("{$col_8_1}5", '委托研发费用及限额');
         $sIdx = Coordinate::columnIndexFromString($col_8_1);
-        $subs = ['委托境内机构或个人进行研发活动所发生的费用', '允许加计扣除的委托境内机构或个人进行研发活动所发生的费用', '委托境外机构进行研发活动所发生的费用', '经限额调整后的委托境外机构进行研发活动所发生的费用'];
+        $subs = ['委托境内机构或个人进行研发 activity 所发生的费用', '允许加计扣除的委托境内机构或个人进行研发活动所发生的费用', '委托境外机构进行研发活动所发生的费用', '经限额调整后的委托境外机构进行研发活动所发生的费用'];
         $nums = ['8.1','8.2','8.3','8.4'];
         for($i=0;$i<4;$i++) {
             $c = Coordinate::stringFromColumnIndex($sIdx + $i);
@@ -178,12 +195,13 @@ class ResearchExpenseSummarySheetExport implements WithEvents, WithTitle
         }
     }
 
-    private function applyDynamicSummaryLogic($sheet, $r, $capRows, $expRows, $startIdx, $dynamicCount, $col_E, $col_6, $col_7_1, $col_7_2, $col_8_1, $col_8_2, $col_8_3, $col_8_4)
+    private function applyDynamicSummaryLogic($sheet, $r, $capRows, $expRows, $startIdx, $dynamicCount, $col_G, $col_6, $col_7_1, $col_7_2, $col_8_1, $col_8_2, $col_8_3, $col_8_4)
     {
         $r_cap = $r; $r_exp = $r + 1; $r_oth = $r + 2; $r_all = $r + 3;
         $labels = ['资本化金额小计', '费用化金额小计', '其中:其他事项', '全额合计'];
         foreach ($labels as $i => $label) {
-            $sheet->mergeCells("A" . ($r+$i) . ":D" . ($r+$i));
+            // 合计行的左侧文本合并范围同步扩展到 A-F 列(第1到第6列)
+            $sheet->mergeCells("A" . ($r+$i) . ":F" . ($r+$i));
             $sheet->setCellValue("A" . ($r+$i), $label);
         }
 
@@ -215,7 +233,8 @@ class ResearchExpenseSummarySheetExport implements WithEvents, WithTitle
             } else {
                 $sheet->setCellValue("{$col_8_4}{$row}", "=IF({$col_8_3}{$r_all}>0, ({$col_8_4}{$r_all}/{$col_8_3}{$r_all})*{$col_8_3}{$row}, 0)");
             }
-            $sheet->setCellValue("{$col_E}{$row}", "={$col_6}{$row}+{$col_7_2}{$row}+{$col_8_2}{$row}+{$col_8_4}{$row}");
+            // 底部小计求和联动更新为新的 $col_G
+            $sheet->setCellValue("{$col_G}{$row}", "={$col_6}{$row}+{$col_7_2}{$row}+{$col_8_2}{$row}+{$col_8_4}{$row}");
         }
     }
 }

+ 2 - 0
app/Service/ExportFileService.php

@@ -1183,6 +1183,8 @@ class ExportFileService extends Service
                 'no'     => $v['code'] ?? '',
                 'name'   => $v['title'] ?? '',
                 'status' => (($v['state'] ?? '') == "完结" ? 3 : 2),
+                'start_time' => $v['start_time'],
+                'end_time' => $v['end_time'],
                 'type'   => $v['expense_type'] ?? '费用化支出',
                 'values' => $rowValues,
                 'val7_1' => $v['other_amount'],

+ 2 - 0
app/Service/StatisticService.php

@@ -411,6 +411,8 @@ class StatisticService extends StatisticCommonService
                 "other_amount" => $other_amount,
                 "jj_other_amount" => $jj_other_amount,
                 "jj_total_amount" => round($jj_amount+$jj_total_amount,2),
+                "start_time" => date('Y-m-d', $v['start_time']),
+                "end_time" => date('Y-m-d', $v['end_time']),
             ];
             $return[] = $item_value;
         }