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');