From a2cf019b3efa134b9559db1d987664d584a69463 Mon Sep 17 00:00:00 2001 From: shanshi <3316401569@qq.com> Date: Wed, 25 Nov 2026 13:53:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=B4=A2=E5=8A=A1=E5=8F=B0=E8=B4=A6):=20?= =?UTF-8?q?=E7=9B=B4=E8=BF=9E=E6=97=A0=E6=B5=81=E6=B0=B4=E6=97=B6=E6=9C=9F?= =?UTF-8?q?=E6=9C=AB=E5=9B=9E=E9=80=80=E9=94=81=E5=AE=9A=E6=9C=9F=E5=88=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/NonStoreAccountMonitorPageData.php | 29 ++++++++++ .../Business/NonStoreAccountMonitorTest.php | 56 +++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/modules/EcommerceFinance/View/NonStoreAccountMonitorPageData.php b/modules/EcommerceFinance/View/NonStoreAccountMonitorPageData.php index 1f6c222b..476afb67 100644 --- a/modules/EcommerceFinance/View/NonStoreAccountMonitorPageData.php +++ b/modules/EcommerceFinance/View/NonStoreAccountMonitorPageData.php @@ -1469,6 +1469,31 @@ final class NonStoreAccountMonitorPageData . (preg_replace('/\D+/', '', (string) $row->account_no) ?? ''); }); + $applyLockedOpeningFallback = static function (array &$row, array &$fixedOpenings): void { + $accountShort = trim((string) ($row['account_short'] ?? '')); + if (! array_key_exists($accountShort, $fixedOpenings)) { + return; + } + + $openingBalance = round((float) $fixedOpenings[$accountShort], 2); + $income = round((float) ($row['bank_bill_period_income'] ?? 0), 2); + $expense = round((float) ($row['bank_bill_period_expense'] ?? 0), 2); + $closingBalance = round($openingBalance + $income - $expense, 2); + $blocked = round( + min(max(0.0, (float) ($row['blocked_balance'] ?? 0)), max(0.0, $closingBalance)), + 2, + ); + $row['opening_balance'] = $openingBalance; + $row['inflow'] = $income; + $row['outflow'] = $expense; + $row['closing_balance'] = $closingBalance; + $row['current_balance'] = $closingBalance; + $row['blocked_balance'] = $blocked; + $row['available_balance'] = round($closingBalance - $blocked, 2); + $row['balance_source'] = 'monthly_opening_fallback'; + $row['monthly_opening_locked'] = true; + }; + foreach ($rows as &$row) { if (! ($row['uses_bank_balance'] ?? false)) { continue; @@ -1477,6 +1502,7 @@ final class NonStoreAccountMonitorPageData $key = (string) ($row['platform_label'] ?? '') . '|' . $accountNo; $accountBills = $bankBills->get($key); if (! $accountBills instanceof Collection || $accountBills->isEmpty()) { + $applyLockedOpeningFallback($row, $fixedOpenings); continue; } @@ -1493,6 +1519,9 @@ final class NonStoreAccountMonitorPageData ); $latestBalance = $balanceRows->last(); if ($latestBalance === null) { + $row['bank_bill_period_income'] = round((float) $inPeriod->sum('income'), 2); + $row['bank_bill_period_expense'] = round((float) $inPeriod->sum('expense'), 2); + $applyLockedOpeningFallback($row, $fixedOpenings); continue; } diff --git a/tests/Feature/Business/NonStoreAccountMonitorTest.php b/tests/Feature/Business/NonStoreAccountMonitorTest.php index f1605ede..cbbafa62 100644 --- a/tests/Feature/Business/NonStoreAccountMonitorTest.php +++ b/tests/Feature/Business/NonStoreAccountMonitorTest.php @@ -453,6 +453,62 @@ class NonStoreAccountMonitorTest extends FeatureTestCase $this->assertStringNotContainsString('-99,999.00', $html); } + public function test_direct_account_without_period_bills_uses_locked_opening_as_closing(): void + { + $connection = DB::connection('business_mirror'); + $connection->table('fin_accounts')->insert([ + 'company_name' => '直连无流水公司', + 'account_short' => '直连无流水招行', + 'account_type' => '公户', + 'bank_name' => '招商银行常州分行', + 'account_no' => '519900000000001', + 'company_plan' => '保留', + 'account_should_keep' => '是', + 'current_balance' => 999, + 'daily_available' => 999, + 'blocked_amount' => 0, + ]); + $connection->table('fin_flow_summary_account_sources')->insert([ + 'account_short' => '直连无流水招行', + 'data_source' => '银企直连', + 'updated_by' => '测试', + ]); + $connection->table('fin_account_opening')->insert([ + 'account_short' => '直连无流水招行', + 'opening_date' => '2026-11-01', + 'opening_balance' => 1234.56, + 'remark' => '系统锁定:2026-10-31 最后一笔实际余额', + ]); + + $this->loginAs()->get($this->pageUrl([ + 'view' => 'accounts', + 'keep' => 'retained', + 'account_category' => 'bank', + 'account_search' => '直连无流水招行', + 'period_from' => '2026-11-01', + 'period_to' => '2026-11-30', + ]))->assertOk(); + + request()->merge([ + 'view' => 'accounts', + 'keep' => 'retained', + 'account_category' => 'bank', + 'account_search' => '直连无流水招行', + 'period_from' => '2026-11-01', + 'period_to' => '2026-11-30', + ]); + $page = app(\Modules\EcommerceFinance\View\NonStoreAccountMonitorPageData::class)->page(); + $row = collect($page['fundOverview']['bank_accounts']) + ->firstWhere('account_short', '直连无流水招行'); + + $this->assertNotNull($row); + $this->assertSame(1234.56, $row['opening_balance']); + $this->assertSame(1234.56, $row['closing_balance']); + $this->assertSame(1234.56, $row['current_balance']); + $this->assertSame('monthly_opening_fallback', $row['balance_source']); + $this->assertTrue($row['monthly_opening_locked']); + } + public function test_missing_monthly_opening_is_not_calculated_from_zero(): void { $connection = DB::connection('business_mirror'); -- 2.47.2