From 0b5a90456dbcfd6443c0bdf1b22c217506b085ea Mon Sep 17 00:00:00 2001 From: shanshi <3316401569@qq.com> Date: Wed, 25 Nov 2026 13:44:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=B4=A2=E5=8A=A1=E5=8F=B0=E8=B4=A6):=20?= =?UTF-8?q?=E6=97=A0=E7=9C=9F=E5=AE=9E=E6=9C=9F=E5=88=9D=E4=B8=8D=E7=94=9F?= =?UTF-8?q?=E6=88=90=E9=9B=B6=E5=9F=BA=E6=B5=81=E6=B0=B4=20(#1405)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/FinanceLedgerCalculator.php | 5 +--- .../FinanceLedgerCalculatorTest.php | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/modules/EcommerceFinance/Services/FinanceLedgerCalculator.php b/modules/EcommerceFinance/Services/FinanceLedgerCalculator.php index c607bd10..3ad9d8bf 100644 --- a/modules/EcommerceFinance/Services/FinanceLedgerCalculator.php +++ b/modules/EcommerceFinance/Services/FinanceLedgerCalculator.php @@ -124,10 +124,7 @@ class FinanceLedgerCalculator ->sortBy('date') ->values(); if ($accountOpenings->isEmpty()) { - $accountOpenings = collect([[ - 'date' => $openingDate, - 'balance' => 0.0, - ]]); + continue; } $balance = 0.0; diff --git a/tests/Unit/EcommerceFinance/FinanceLedgerCalculatorTest.php b/tests/Unit/EcommerceFinance/FinanceLedgerCalculatorTest.php index 97525b42..cb2543dc 100644 --- a/tests/Unit/EcommerceFinance/FinanceLedgerCalculatorTest.php +++ b/tests/Unit/EcommerceFinance/FinanceLedgerCalculatorTest.php @@ -214,6 +214,36 @@ class FinanceLedgerCalculatorTest extends TestCase ); } + public function test_account_without_actual_opening_does_not_create_zero_based_flows(): void + { + $db = DB::connection('business_mirror'); + $db->table('fin_accounts')->insert([ + 'company_name' => '公司E', + 'account_short' => '无期初账户E', + 'account_type' => '公户', + 'bank_name' => '工商银行', + 'current_balance' => 0, + 'blocked_amount' => 0, + 'daily_available' => 0, + ]); + $db->table('fin_transactions')->insert([ + 'txn_date' => '2026-10-18', + 'account_short' => '无期初账户E', + 'source' => 'manual', + 'source_value' => null, + 'income' => 88.88, + 'expense' => 0, + ]); + + $result = app(FinanceLedgerCalculator::class)->recalculate(); + + $this->assertSame(2, $result['accounts']); + $this->assertSame(3, $result['flows']); + $this->assertSame(0, $db->table('fin_daily_flows') + ->where('account_short', '无期初账户E') + ->count()); + } + public function test_account_opening_date_can_precede_the_global_ledger_opening_date(): void { $db = DB::connection('business_mirror');