diff --git a/modules/EcommerceFinance/Services/FinanceLedgerBankBalanceCurrentCalculator.php b/modules/EcommerceFinance/Services/FinanceLedgerBankBalanceCurrentCalculator.php index 9fbeee23b..202c0f2dc 100644 --- a/modules/EcommerceFinance/Services/FinanceLedgerBankBalanceCurrentCalculator.php +++ b/modules/EcommerceFinance/Services/FinanceLedgerBankBalanceCurrentCalculator.php @@ -67,7 +67,11 @@ final class FinanceLedgerBankBalanceCurrentCalculator continue; } - $details[$accountShort] = $bill !== null + $useBankBillBaseline = $bill !== null + && ($opening === null + || substr((string) $bill['txn_date'], 0, 10) + >= substr((string) $opening->opening_date, 0, 10)); + $details[$accountShort] = $useBankBillBaseline ? [ 'balance' => round((float) $bill['balance'], 2), 'balance_source' => 'bank_bill_plus_transactions', diff --git a/resources/views/business/pages/financial-operations/non-store-accounts.blade.php b/resources/views/business/pages/financial-operations/non-store-accounts.blade.php index 02112c026..cf14eb5fd 100644 --- a/resources/views/business/pages/financial-operations/non-store-accounts.blade.php +++ b/resources/views/business/pages/financial-operations/non-store-accounts.blade.php @@ -227,14 +227,6 @@ color: var(--nsm-warning); } - .nsm-table-note { - display: block; - margin-top: .25rem; - color: var(--nsm-muted); - font-size: .625rem; - font-weight: 400; - } - .nsm-distribution-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); @@ -1970,10 +1962,6 @@
期初余额 {{ $moneyWanOptional($fundOverview['opening_balance']) }} - - {{ number_format((int) $fundOverview['opening_accounts']) }} / - {{ number_format((int) $fundOverview['total_accounts']) }} 户已锁定月度期初 -
期末总余额 @@ -2053,10 +2041,6 @@ {{ $moneyWanOptional($distribution['opening_balance']) }} @if ($distribution['opening_balance'] !== null) 万 @endif - - {{ number_format((int) $distribution['opening_accounts']) }} / - {{ number_format((int) $distribution['count']) }} 户 - {{ $moneyWan($distribution['current_balance']) }} 万 {{ $moneyWan($distribution['available_balance']) }} 万 @@ -2085,10 +2069,6 @@ {{ $moneyWanOptional($fundOverview['opening_balance']) }} @if ($fundOverview['opening_balance'] !== null) 万 @endif - - {{ number_format((int) $fundOverview['opening_accounts']) }} / - {{ number_format((int) $fundOverview['total_accounts']) }} 户 - {{ $moneyWan($fundOverview['current_balance']) }} 万 {{ $moneyWan($fundOverview['available_balance']) }} 万 diff --git a/tests/Feature/Business/FinanceLedgerTransactionBalanceTest.php b/tests/Feature/Business/FinanceLedgerTransactionBalanceTest.php index e626a071a..23c8ace73 100644 --- a/tests/Feature/Business/FinanceLedgerTransactionBalanceTest.php +++ b/tests/Feature/Business/FinanceLedgerTransactionBalanceTest.php @@ -345,4 +345,60 @@ class FinanceLedgerTransactionBalanceTest extends FeatureTestCase $this->assertSame('2026-11-05', $updated['测试阶段账单华夏']['baseline_date']); $this->assertSame(0, $updated['测试阶段账单华夏']['movement_count']); } + + public function test_non_direct_balance_prefers_newer_monthly_opening_over_older_stage_bill(): void + { + $connection = DB::connection('business_mirror'); + $accountId = $connection->table('fin_accounts')->insertGetId([ + 'company_name' => '新旧基准测试公司', + 'account_short' => '测试新期初旧账单工行', + 'account_type' => '公户', + 'bank_name' => '中国工商银行测试支行', + 'account_no' => '1105000000006936', + 'current_balance' => 346101.84, + ]); + $connection->table('fin_account_opening')->insert([ + 'account_short' => '测试新期初旧账单工行', + 'opening_date' => '2026-12-01', + 'opening_balance' => 28764.32, + 'remark' => '期初表导入:2026-11-30 期末余额', + ]); + $connection->table('fin_transactions')->insert([ + 'txn_date' => '2026-12-03', + 'account_short' => '测试新期初旧账单工行', + 'detail' => '唯品会回款', + 'income' => 317337.52, + 'expense' => 0, + 'source' => 'manual', + 'source_value' => null, + 'row_key' => hash('sha256', 'new-opening-old-stage-bill-income'), + ]); + $connection->table('fin_bank_direct_bills')->insert([ + 'bank_name' => '中国工商银行', + 'finance_account_id' => $accountId, + 'company_name' => '新旧基准测试公司', + 'account_short' => '测试新期初旧账单工行', + 'account_no' => '1105000000006936', + 'txn_date' => '2026-11-25', + 'txn_at' => '2026-11-25 17:13:31', + 'record_code' => '000000000', + 'income' => 0, + 'expense' => 0, + 'balance' => 33557.68, + 'source' => 'bank-monthly', + 'row_key' => hash('sha256', 'new-opening-old-stage-bill'), + 'imported_at' => '2026-11-25 10:53:51', + ]); + + $details = app(FinanceLedgerBankBalanceCurrentCalculator::class) + ->balanceDetails(['测试新期初旧账单工行'], '2026-12-03'); + $detail = $details['测试新期初旧账单工行']; + + $this->assertSame(346101.84, $detail['balance']); + $this->assertSame('transactions', $detail['balance_source']); + $this->assertSame('2026-12-01', $detail['baseline_date']); + $this->assertSame(28764.32, $detail['baseline_balance']); + $this->assertSame(317337.52, $detail['post_baseline_income']); + $this->assertSame(1, $detail['movement_count']); + } } diff --git a/tests/Feature/Business/NonStoreAccountMonitorTest.php b/tests/Feature/Business/NonStoreAccountMonitorTest.php index 19d18468d..0a88d2e11 100644 --- a/tests/Feature/Business/NonStoreAccountMonitorTest.php +++ b/tests/Feature/Business/NonStoreAccountMonitorTest.php @@ -767,6 +767,8 @@ class NonStoreAccountMonitorTest extends FeatureTestCase $this->assertStringContainsString('data-retained-fund-distribution', $html); $this->assertStringContainsString('账户平台资金分布', $html); $this->assertStringContainsString('余额占比', $html); + $this->assertStringNotContainsString('nsm-table-note', $html); + $this->assertStringNotContainsString('户已锁定月度期初', $html); $this->assertStringContainsString('银行账户', $html); $this->assertStringContainsString('支付宝', $html); $this->assertStringContainsString('data-bank-drilldown-open', $html);