Merge remote-tracking branch 'origin/main' into feature/shanshi-bank-bill-date-filter

This commit is contained in:
shanshi 2026-12-03 17:39:14 +08:00
commit ffbb05b63a
4 changed files with 63 additions and 21 deletions

View File

@ -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',

View File

@ -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 @@
<div class="nsm-fund-kpi @if(($fundOverview['opening_missing_accounts'] ?? 0) > 0) nsm-fund-kpi--warning @endif">
<span>期初余额</span>
<strong>{{ $moneyWanOptional($fundOverview['opening_balance']) }}</strong>
<small>
{{ number_format((int) $fundOverview['opening_accounts']) }} /
{{ number_format((int) $fundOverview['total_accounts']) }} 户已锁定月度期初
</small>
</div>
<div class="nsm-fund-kpi">
<span>期末总余额</span>
@ -2053,10 +2041,6 @@
<td class="num">
{{ $moneyWanOptional($distribution['opening_balance']) }}
@if ($distribution['opening_balance'] !== null) 万 @endif
<small class="nsm-table-note">
{{ number_format((int) $distribution['opening_accounts']) }} /
{{ number_format((int) $distribution['count']) }} 户
</small>
</td>
<td class="num">{{ $moneyWan($distribution['current_balance']) }} 万</td>
<td class="num">{{ $moneyWan($distribution['available_balance']) }} 万</td>
@ -2085,10 +2069,6 @@
<td class="num">
{{ $moneyWanOptional($fundOverview['opening_balance']) }}
@if ($fundOverview['opening_balance'] !== null) 万 @endif
<small class="nsm-table-note">
{{ number_format((int) $fundOverview['opening_accounts']) }} /
{{ number_format((int) $fundOverview['total_accounts']) }} 户
</small>
</td>
<td class="num">{{ $moneyWan($fundOverview['current_balance']) }} 万</td>
<td class="num">{{ $moneyWan($fundOverview['available_balance']) }} 万</td>

View File

@ -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']);
}
}

View File

@ -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('<td>银行账户</td>', $html);
$this->assertStringContainsString('<td>支付宝</td>', $html);
$this->assertStringContainsString('data-bank-drilldown-open', $html);