feat: 拆分银行账户与非店铺账户汇总视图

This commit is contained in:
shanshi 2026-11-11 14:08:10 +08:00
parent 4e76f76b71
commit ef326c179f
3 changed files with 55 additions and 8 deletions

View File

@ -87,7 +87,10 @@ class FinanceLedgerPageData
$tab = array_key_exists($tab, self::TABS) ? $tab : 'accounts';
$openingDate = (string) config('finance_ledger.opening_date', '2026-10-17');
$transactionView = $this->transactionView();
$flowView = request('flows_view') === 'daily' ? 'daily' : 'summary';
$requestedFlowView = trim((string) request('flows_view', 'summary'));
$flowView = in_array($requestedFlowView, ['summary', 'bank', 'non_store', 'daily'], true)
? $requestedFlowView
: 'summary';
$flowPeriod = $this->dateRange('flows');
$transactionPeriod = $this->dateRange('txns');
$mappingPeriod = $this->dateRange('mapping');
@ -591,7 +594,7 @@ class FinanceLedgerPageData
{
return $view === 'daily'
? $this->dailyFlows($period)
: $this->accountFlowSummary($period);
: $this->accountFlowSummary($period, $view);
}
private function dailyFlows(array $period): array
@ -629,13 +632,29 @@ class FinanceLedgerPageData
];
}
private function accountFlowSummary(array $period): array
private function accountFlowSummary(array $period, string $view = 'summary'): array
{
$customFields = $this->flowSummaryCustomFields();
$accountQuery = FinanceLedgerIndependentAccounts::exclude(
$this->db()->table('fin_accounts as a'),
'a.account_short',
);
if ($view === 'bank') {
$accountQuery->where(function ($scope): void {
$scope->where(function ($account): void {
$account->whereNull('a.account_short')
->orWhere('a.account_short', 'not like', '%支付宝%');
})->where(function ($accountType): void {
$accountType->whereNull('a.account_type')
->orWhere('a.account_type', 'not like', '%支付宝%');
});
});
} elseif ($view === 'non_store') {
$accountQuery->where(function ($scope): void {
$scope->where('a.account_short', 'like', '%支付宝%')
->orWhere('a.account_type', 'like', '%支付宝%');
});
}
foreach (['flows_company' => 'a.company_name', 'flows_account' => 'a.account_short'] as $param => $column) {
$value = trim((string) request($param, ''));
if ($value !== '') {
@ -646,7 +665,7 @@ class FinanceLedgerPageData
$accountRows = $accountQuery
->orderBy('a.company_name')
->orderBy('a.account_short')
->get(['a.company_name', 'a.account_short'])
->get(['a.company_name', 'a.account_short', 'a.account_type'])
->filter(static fn ($account): bool => trim((string) ($account->account_short ?? '')) !== '')
->unique('account_short')
->keyBy('account_short');

View File

@ -71,6 +71,7 @@
$currentMonthEnd = now()->endOfMonth()->toDateString();
$flowPeriod = $ledgerFlowPeriod ?? ['from' => $currentMonthStart, 'to' => $currentMonthEnd];
$flowView = $ledgerFlowView ?? 'summary';
$flowUsesAccountSummary = $flowView !== 'daily';
$flowSummaryCustomFields = $ledgerFlowSummaryCustomFields ?? [];
$transactionPeriod = $ledgerTransactionPeriod ?? ['from' => $currentMonthStart, 'to' => $currentMonthEnd];
$mappingPeriod = $ledgerMappingPeriod ?? ['from' => $currentMonthStart, 'to' => $currentMonthEnd];
@ -1079,10 +1080,12 @@
</form>
<nav class="ledger-subtabbar" aria-label="账户资金汇总视图">
<a class="ledger-subtab {{ $flowView === 'summary' ? 'is-active' : '' }}" href="{{ $flowViewUrl('summary') }}" @if ($flowView === 'summary') aria-current="page" @endif>账户汇总</a>
<a class="ledger-subtab {{ $flowView === 'bank' ? 'is-active' : '' }}" href="{{ $flowViewUrl('bank') }}" @if ($flowView === 'bank') aria-current="page" @endif>银行账户</a>
<a class="ledger-subtab {{ $flowView === 'non_store' ? 'is-active' : '' }}" href="{{ $flowViewUrl('non_store') }}" @if ($flowView === 'non_store') aria-current="page" @endif>非店铺账户</a>
<a class="ledger-subtab {{ $flowView === 'daily' ? 'is-active' : '' }}" href="{{ $flowViewUrl('daily') }}" @if ($flowView === 'daily') aria-current="page" @endif>按日流水</a>
@if ($flowView === 'summary' && $canEditAccounts)
@if ($flowUsesAccountSummary && $canEditAccounts)
<span class="ledger-flow-grid-actions">
<button class="ledger-btn" type="button" title="新增一个账户汇总行" data-ledger-flow-summary-add-row data-return-url="{{ $flowViewUrl('summary') }}"><span class="material-icons-outlined" aria-hidden="true">playlist_add</span>新增行</button>
<button class="ledger-btn" type="button" title="新增一个账户汇总行" data-ledger-flow-summary-add-row data-return-url="{{ $flowViewUrl($flowView) }}"><span class="material-icons-outlined" aria-hidden="true">playlist_add</span>新增行</button>
<button class="ledger-btn" type="button" title="在账户资金汇总末尾新增一个自定义列" data-ledger-flow-summary-add-column><span class="material-icons-outlined" aria-hidden="true">view_column</span>新增列</button>
</span>
@endif
@ -1109,7 +1112,7 @@
])
@endforeach
@foreach ($flowSummaryCustomFields as $customField)
@if ($flowView === 'summary')
@if ($flowUsesAccountSummary)
<th scope="col" class="ledger-custom-column" data-ledger-header-field="summary-custom-{{ $customField['field_key'] }}">
<div class="ledger-custom-column-head">
<strong title="{{ $customField['field_name'] }}">{{ $customField['field_name'] }}</strong>
@ -1125,7 +1128,7 @@
</th>
@endif
@endforeach
@if ($flowView === 'summary')
@if ($flowUsesAccountSummary)
<th scope="col">操作</th>
@endif
</tr></thead>

View File

@ -463,6 +463,31 @@ class FinanceLedgerHeaderControlsTest extends FeatureTestCase
$this->assertStringContainsString('>2026-10-17</td>', $dailyHtml);
}
public function test_account_flow_summary_separates_bank_accounts_and_alipay_only(): void
{
$bankHtml = $this->loginAs()->get($this->pageUrl([
'flows_view' => 'bank',
'flows_from' => '2026-10-01',
'flows_to' => '2026-10-31',
]))->assertOk()->getContent();
$this->assertStringContainsString('>账户汇总</a>', $bankHtml);
$this->assertStringContainsString('>银行账户</a>', $bankHtml);
$this->assertStringContainsString('>非店铺账户</a>', $bankHtml);
$this->assertStringContainsString('>按日流水</a>', $bankHtml);
$this->assertStringContainsString('data-flow-summary-account="账户甲"', $bankHtml);
$this->assertStringNotContainsString('data-flow-summary-account="账户乙"', $bankHtml);
$nonStoreHtml = $this->loginAs()->get($this->pageUrl([
'flows_view' => 'non_store',
'flows_from' => '2026-10-01',
'flows_to' => '2026-10-31',
]))->assertOk()->getContent();
$this->assertStringContainsString('data-flow-summary-account="账户乙"', $nonStoreHtml);
$this->assertStringNotContainsString('data-flow-summary-account="账户甲"', $nonStoreHtml);
}
public function test_account_bank_affiliation_uses_only_the_account_short_suffix(): void
{
$affiliations = [