From 08f960e68020ce28cc3843d4e0ec0570223704af Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Sun, 6 Dec 2026 11:14:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=BF=AB=E9=80=92=E5=AF=B9=E8=B4=A6):=20?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E7=A9=BA=E7=99=BD=E9=99=84=E5=8A=A0=E8=B4=B9?= =?UTF-8?q?=E5=8D=A0=E4=BD=8D=E7=B1=BB=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Support/CourierBills/SummaryTemplate.php | 4 ++- .../CourierBillReconciliationTest.php | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/Support/CourierBills/SummaryTemplate.php b/app/Support/CourierBills/SummaryTemplate.php index 7c36ff4e2..08018456f 100644 --- a/app/Support/CourierBills/SummaryTemplate.php +++ b/app/Support/CourierBills/SummaryTemplate.php @@ -74,7 +74,9 @@ final class SummaryTemplate unset($row); } - return [...$rows, ...$extras]; + // 这些费用已由账单附加费归集,不再沿用上月没有金额的占位类目;有实际费用的行仍保留。 + return array_values(array_filter([...$rows, ...$extras], static fn (array $row): bool => + ! $row['blank'] || ! preg_match('/拦截|改地址|超长/u', $row['label']))); } /** 模板里属于附加费的那几行(自算先放 0,可回填)。 @param list $feeLabels @return list */ diff --git a/tests/Feature/Business/CourierBillReconciliationTest.php b/tests/Feature/Business/CourierBillReconciliationTest.php index 5f28eee2a..c29a03218 100644 --- a/tests/Feature/Business/CourierBillReconciliationTest.php +++ b/tests/Feature/Business/CourierBillReconciliationTest.php @@ -999,6 +999,40 @@ final class CourierBillReconciliationTest extends FeatureTestCase ], $labels($november)); } + public function test_unused_surcharge_categories_are_not_carried_into_summaries_or_exports(): void + { + $this->seedShipping(); + $store = app(CourierBillStore::class); + $store->saveGroup(null, ['name' => '河北中通-江三', 'express_names' => ['河北中通-江三']]); + $store->saveSummaryTemplates([['title' => '河北中通-江三10月', + 'labels' => ['运费', '拦截费', '改地址', '超长费', '记账', '附加费']]], '2026-10'); + $path = $this->workbook(['账单' => [['单号', '运费'], ['ZT001', 10]], + '附加费' => [['快递单号', '附加费金额', '附加费类型'], ['ZT001', 30, '改地址']]]); + $fileId = $store->upload([new UploadedFile($path, '河北中通-江三10月.xlsx', null, null, true)], '2026-10', [], 'tester')[0]; + $id = (int) $store->db()->table('courier_bill_files')->where('id', $fileId)->value('statement_id'); + app(CourierBillMatcher::class)->refreshSummary($id); + $items = $store->db()->table('courier_bill_summary_items')->where('statement_id', $id)->orderBy('sort')->get(); + $this->assertSame(['运费', '记账', '附加费'], $items->pluck('label')->all()); + $this->assertEquals(40, $items->sum('bill_amount')); + $this->assertEquals(30, $items->firstWhere('label', '附加费')->bill_amount); + $this->assertEquals(10, $items->sum('self_amount')); + + $out = tempnam(sys_get_temp_dir(), 'summary_export_');$this->temp[] = $out; + $stream = fopen($out, 'wb');app(StatementExporter::class)->export($id, $stream);fclose($stream); + $book = IOFactory::load($out);$summary = $book->getSheetByName('汇总')->toArray(); + $this->assertSame(['运费', '记账', '附加费', '合计'], array_column(array_slice($summary, 1), 0)); + $this->assertEquals(40, $summary[4][1]);$this->assertEquals(10, $summary[4][2]); + $book->disconnectWorksheets(); + + // 独立费用确有来源时仍保留,即使金额为0;不误删其他占位类目。 + $mapped = SummaryTemplate::apply(['拦截费', '改地址费', '超长费', '包裹拦截费用', '违约金'], [ + '拦截费' => ['bill' => 20.0, 'self' => 0.0, 'kind' => 'fee'], + '超长费' => ['bill' => 0.0, 'self' => 0.0, 'kind' => 'fee'], + ], 10); + $this->assertSame(['拦截费', '超长费', '违约金'], array_column($mapped, 'label')); + $this->assertEquals(20, array_sum(array_column($mapped, 'bill'))); + } + public function test_summary_template_command_imports_a_label_list_by_group_name(): void { $store = app(CourierBillStore::class); -- 2.47.2