From 64c9236f0d419e09c21e489c354ec95acbf90215 Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Sun, 6 Dec 2026 16:53:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=AF=E6=8C=81=E8=B4=A2=E5=8A=A1?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E9=85=8D=E4=BB=B6=E8=BF=90=E8=B4=B9=E5=85=8D?= =?UTF-8?q?=E6=89=A3=E5=8D=95=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/SupplierAccessoryFreightPageData.php | 10 +++++ tests/Unit/SupplierAccessoryFreightTest.php | 38 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/modules/EcommerceFinance/View/SupplierAccessoryFreightPageData.php b/modules/EcommerceFinance/View/SupplierAccessoryFreightPageData.php index 2352d35da..17a92ec84 100644 --- a/modules/EcommerceFinance/View/SupplierAccessoryFreightPageData.php +++ b/modules/EcommerceFinance/View/SupplierAccessoryFreightPageData.php @@ -2,6 +2,7 @@ namespace Modules\EcommerceFinance\View; +use App\Support\CourierBills\Waybill; use Illuminate\Pagination\LengthAwarePaginator; use Modules\EcommerceFinance\Repositories\SupplierAccessoryFreightRepository; use Modules\EcommerceFinance\Services\SupplierAccessoryFreightMatcher; @@ -42,7 +43,16 @@ class SupplierAccessoryFreightPageData public function rows(array $filters): \Generator { + $excludedWaybills = setting('supplier_accessory_freight.excluded_waybills', []); + $excludedWaybills = is_array($excludedWaybills) ? $excludedWaybills : []; foreach ($this->repository->rows($filters['month']) as $row) { + $waybill = Waybill::normalize((string) ($row['express_no'] ?? '')); + $reason = $waybill === null ? null : ($excludedWaybills[$waybill] ?? null); + if (is_string($reason) && trim($reason) !== '') { + $row['state'] = 'excluded'; + $row['deduction_cents'] = 0; + $row['reason'] = '财务确认不扣款:' . trim($reason); + } foreach (self::TEXT_FILTERS as $key => $label) { if (($filters[$key] ?? '') !== '' && mb_stripos((string) ($row[$key] ?? ''), $filters[$key]) === false) continue 2; } diff --git a/tests/Unit/SupplierAccessoryFreightTest.php b/tests/Unit/SupplierAccessoryFreightTest.php index 51b25e3b5..f311e66d5 100644 --- a/tests/Unit/SupplierAccessoryFreightTest.php +++ b/tests/Unit/SupplierAccessoryFreightTest.php @@ -32,6 +32,7 @@ class SupplierAccessoryFreightTest extends TestCase { $app = new Application(dirname(__DIR__, 2)); $app->instance('config', new Repository(['app' => ['platform_timezone' => 'Asia/Shanghai']])); + $app->instance('setting', new \Akaunting\Setting\Drivers\Memory); $db = new Manager($app); $db->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '']); $db->setEventDispatcher(new \Illuminate\Events\Dispatcher($app)); @@ -314,6 +315,43 @@ class SupplierAccessoryFreightTest extends TestCase $this->assertSame(['DROPSHIP-1', '代发', '0.00', '代发厂家配置匹配「工厂-河北浩浦代发仓」,不扣配件运费'], array_slice(str_getcsv($lines[2]), 3)); } + public function test_finance_exclusions_zero_deductions_in_summary_filters_and_export(): void + { + setting()->set('supplier_accessory_freight.excluded_waybills', [ + 'EXEMPT-100' => '不属于应扣款项', 'EXEMPT-200' => '不属于应扣款项', + ]); + $repository = Mockery::mock(SupplierAccessoryFreightRepository::class); + $repository->shouldReceive('rows')->with('2026-09')->andReturnUsing(function () { + foreach (['EXEMPT-100', " 'exempt-200 ", 'EXEMPT-1000', 'OTHER-300'] as $waybill) { + yield (new SupplierAccessoryFreightMatcher)->match($this->row(['express_no' => $waybill]), + [['name' => '成品', 'supplier_name' => '供应商甲']], [['linkerprovience' => '河北']], [], null, true); + } + }); + $data = new SupplierAccessoryFreightPageData($repository); + app()->instance('request', Request::create('/?month=2026-09&state=ready')); + $page = $data->page(); + $this->assertSame(['all' => 4, 'ready' => 2, 'excluded' => 2, 'pending' => 0, 'amount' => 2470], $page['freightSummary']); + $this->assertSame(['EXEMPT-1000', 'OTHER-300'], array_column($page['freightRows']->items(), 'express_no')); + $controller = new \App\Http\Controllers\Business\SupplierAccessoryFreight; + $response = $controller->export($data); + ob_start(); $response->sendContent(); $csv = ob_get_clean(); + $this->assertSame(3, substr_count($csv, "\n")); + $this->assertStringNotContainsString(',EXEMPT-100,', $csv); + $this->assertStringContainsString('EXEMPT-1000', $csv); + app()->instance('request', Request::create('/?month=2026-09&state=excluded&columns=express_no,deduction,reason')); + $excluded = $data->page(); + $this->assertCount(2, $excluded['freightRows']); + foreach ($excluded['freightRows'] as $row) { + $this->assertSame(0, $row['deduction_cents']); + $this->assertSame(1235, $row['freight_cents']); + $this->assertSame('供应商甲', $row['supplier_name']); + $this->assertSame('财务确认不扣款:不属于应扣款项', $row['reason']); + } + $response = $controller->export($data); + ob_start(); $response->sendContent(); $csv = ob_get_clean(); + $this->assertSame(2, substr_count($csv, ',0.00,财务确认不扣款:不属于应扣款项')); + } + public function test_unready_courier_mirror_does_not_produce_deductions(): void { $registry = Mockery::mock(BusinessMirrorDatasetRegistry::class); -- 2.47.2