feat: 增加财务台账账户组合筛选
This commit is contained in:
parent
3fd5417c73
commit
76a940fe97
@ -25,6 +25,8 @@ class FinanceLedgerPageData
|
||||
'sources' => ['title' => '数据来源', 'icon' => 'database'],
|
||||
];
|
||||
|
||||
private const ACCOUNT_FILTER_EMPTY = '__empty__';
|
||||
|
||||
public function page(?string $tab = null): array
|
||||
{
|
||||
$tab = (string) (request('tab') ?: $tab);
|
||||
@ -53,6 +55,7 @@ class FinanceLedgerPageData
|
||||
'ledgerSourceSummary' => $this->sourceSummary(),
|
||||
'ledgerMeta' => $this->meta(),
|
||||
'ledgerAccountOptions' => $this->accountOptions(),
|
||||
'ledgerAccountFilterOptions' => $this->accountFilterOptions(),
|
||||
'ledgerAccountStatusOptions' => FinanceLedgerAccountStatus::OPTIONS,
|
||||
'ledgerCanEditMapping' => FinanceLedgerAccess::canEditMapping(user()),
|
||||
'ledgerCanEditAccountStatus' => FinanceLedgerAccess::canEditAccountStatus(user()),
|
||||
@ -71,6 +74,48 @@ class FinanceLedgerPageData
|
||||
});
|
||||
}
|
||||
|
||||
$accountShort = trim((string) request('accounts_short', ''));
|
||||
if ($accountShort !== '') {
|
||||
$query->where('account_short', 'like', '%' . $accountShort . '%');
|
||||
}
|
||||
|
||||
$status = trim((string) request('accounts_status', ''));
|
||||
if ($status !== '' && array_key_exists($status, FinanceLedgerAccountStatus::OPTIONS)) {
|
||||
if ($status === FinanceLedgerAccountStatus::NORMAL) {
|
||||
$nonNormalStatuses = array_values(array_diff(
|
||||
array_keys(FinanceLedgerAccountStatus::OPTIONS),
|
||||
[FinanceLedgerAccountStatus::NORMAL],
|
||||
));
|
||||
$query->whereNotIn(
|
||||
'account_short',
|
||||
$this->db()->table('fin_account_statuses')
|
||||
->select('account_short')
|
||||
->whereIn('status', $nonNormalStatuses),
|
||||
);
|
||||
} else {
|
||||
$query->whereIn(
|
||||
'account_short',
|
||||
$this->db()->table('fin_account_statuses')
|
||||
->select('account_short')
|
||||
->where('status', $status),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (['accounts_region' => 'region', 'accounts_type' => 'account_type'] as $parameter => $column) {
|
||||
$value = trim((string) request($parameter, ''));
|
||||
if ($value === '') {
|
||||
continue;
|
||||
}
|
||||
if ($value === self::ACCOUNT_FILTER_EMPTY) {
|
||||
$query->where(function (Builder $builder) use ($column): void {
|
||||
$builder->whereNull($column)->orWhere($column, '');
|
||||
});
|
||||
} else {
|
||||
$query->where($column, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$summaryQuery = clone $query;
|
||||
$summary = [
|
||||
'count' => (clone $query)->count(),
|
||||
@ -272,6 +317,18 @@ class FinanceLedgerPageData
|
||||
->select('account_short')->distinct()->orderBy('account_short')->pluck('account_short')->all();
|
||||
}
|
||||
|
||||
private function accountFilterOptions(): array
|
||||
{
|
||||
return [
|
||||
'regions' => $this->db()->table('fin_accounts')
|
||||
->whereNotNull('region')->where('region', '<>', '')
|
||||
->distinct()->orderBy('region')->pluck('region')->all(),
|
||||
'types' => $this->db()->table('fin_accounts')
|
||||
->whereNotNull('account_type')->where('account_type', '<>', '')
|
||||
->distinct()->orderBy('account_type')->pluck('account_type')->all(),
|
||||
];
|
||||
}
|
||||
|
||||
private function db()
|
||||
{
|
||||
return DB::connection((string) config('upstream_mirrors.connection', 'business_mirror'));
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
$canEdit = (bool) ($ledgerCanEditMapping ?? false);
|
||||
$canEditAccountStatus = (bool) ($ledgerCanEditAccountStatus ?? false);
|
||||
$accountStatusOptions = $ledgerAccountStatusOptions ?? \App\Utilities\FinanceLedgerAccountStatus::OPTIONS;
|
||||
$accountFilterOptions = $ledgerAccountFilterOptions ?? ['regions' => [], 'types' => []];
|
||||
$money = static fn ($value): string => $value === null || $value === '' ? '' : number_format((float) $value, 2);
|
||||
$date = static fn ($value): string => $value ? \Illuminate\Support\Carbon::parse($value)->format('Y-m-d') : '';
|
||||
$tabUrl = static fn (string $tab): string => route('business.pages.show', ['section' => 'financial-ledger', 'page' => 'ledger', 'tab' => $tab]);
|
||||
@ -119,7 +120,11 @@
|
||||
<section class="ledger-panel" id="ledger-panel-accounts" role="tabpanel" data-ledger-panel="accounts" @if ($activeTab !== 'accounts') hidden @endif>
|
||||
<form class="ledger-toolbar" method="GET" action="{{ $tabUrl('accounts') }}">
|
||||
<input type="hidden" name="tab" value="accounts">
|
||||
<div class="ledger-field"><label for="accounts-q">关键词</label><input id="accounts-q" name="accounts_q" value="{{ request('accounts_q') }}" placeholder="公司、账户简称、账号、责任人"></div>
|
||||
<div class="ledger-field"><label for="accounts-q">关键词</label><input id="accounts-q" name="accounts_q" value="{{ request('accounts_q') }}" placeholder="公司、账号、责任人"></div>
|
||||
<div class="ledger-field" style="min-width:11rem"><label for="accounts-short">账户简称</label><input id="accounts-short" name="accounts_short" list="ledger-account-list" value="{{ request('accounts_short') }}" placeholder="选择或输入"></div>
|
||||
<div class="ledger-field" style="min-width:8rem"><label for="accounts-status">账户状态</label><select id="accounts-status" name="accounts_status"><option value="">全部状态</option>@foreach ($accountStatusOptions as $statusCode => $statusLabel)<option value="{{ $statusCode }}" @selected(request('accounts_status') === $statusCode)>{{ $statusLabel }}</option>@endforeach</select></div>
|
||||
<div class="ledger-field" style="min-width:8rem"><label for="accounts-region">地区</label><select id="accounts-region" name="accounts_region"><option value="">全部地区</option>@foreach (($accountFilterOptions['regions'] ?? []) as $region)<option value="{{ $region }}" @selected(request('accounts_region') === $region)>{{ $region }}</option>@endforeach<option value="__empty__" @selected(request('accounts_region') === '__empty__')>未填写</option></select></div>
|
||||
<div class="ledger-field" style="min-width:8rem"><label for="accounts-type">账户类型</label><select id="accounts-type" name="accounts_type"><option value="">全部类型</option>@foreach (($accountFilterOptions['types'] ?? []) as $type)<option value="{{ $type }}" @selected(request('accounts_type') === $type)>{{ $type }}</option>@endforeach<option value="__empty__" @selected(request('accounts_type') === '__empty__')>未填写</option></select></div>
|
||||
<div class="ledger-actions"><button class="ledger-btn primary" type="submit"><span class="material-icons-outlined">search</span>查询</button><a class="ledger-btn" href="{{ $tabUrl('accounts') }}"><span class="material-icons-outlined">refresh</span>重置</a></div>
|
||||
</form>
|
||||
<div class="ledger-summary">
|
||||
|
||||
@ -50,9 +50,75 @@ class FinanceLedgerAccountStatusTest extends FeatureTestCase
|
||||
->assertSee('网银异常')
|
||||
->assertSee('限额')
|
||||
->assertSee('工商注销')
|
||||
->assertSee('name="accounts_short"', false)
|
||||
->assertSee('name="accounts_status"', false)
|
||||
->assertSee('name="accounts_region"', false)
|
||||
->assertSee('name="accounts_type"', false)
|
||||
->assertSee('未填写')
|
||||
->assertSee('value="normal" selected', false);
|
||||
}
|
||||
|
||||
public function test_account_filters_narrow_by_short_status_region_and_type(): void
|
||||
{
|
||||
$connection = DB::connection('business_mirror');
|
||||
$connection->table('fin_accounts')->insert([
|
||||
[
|
||||
'company_name' => '筛选测试公司甲',
|
||||
'account_short' => '筛选账户甲',
|
||||
'region' => '上海',
|
||||
'account_type' => '公户',
|
||||
],
|
||||
[
|
||||
'company_name' => '筛选测试公司乙',
|
||||
'account_short' => '筛选账户乙',
|
||||
'region' => '杭州',
|
||||
'account_type' => '个人卡',
|
||||
],
|
||||
]);
|
||||
$connection->table('fin_account_statuses')->insert([
|
||||
'account_short' => '筛选账户乙',
|
||||
'status' => 'limited',
|
||||
'updated_by' => 'Test User',
|
||||
]);
|
||||
|
||||
$this->loginAs()->get(route('business.pages.show', [
|
||||
'company_id' => $this->company->id,
|
||||
'section' => 'financial-ledger',
|
||||
'page' => 'ledger',
|
||||
'accounts_short' => '筛选账户',
|
||||
'accounts_status' => 'limited',
|
||||
'accounts_region' => '杭州',
|
||||
'accounts_type' => '个人卡',
|
||||
]))
|
||||
->assertOk()
|
||||
->assertSee('data-account-short="筛选账户乙"', false)
|
||||
->assertDontSee('data-account-short="筛选账户甲"', false)
|
||||
->assertSee('value="limited" selected', false);
|
||||
|
||||
$this->loginAs()->get(route('business.pages.show', [
|
||||
'company_id' => $this->company->id,
|
||||
'section' => 'financial-ledger',
|
||||
'page' => 'ledger',
|
||||
'accounts_short' => '筛选账户',
|
||||
'accounts_status' => 'normal',
|
||||
]))
|
||||
->assertOk()
|
||||
->assertSee('data-account-short="筛选账户甲"', false)
|
||||
->assertDontSee('data-account-short="筛选账户乙"', false);
|
||||
|
||||
$this->loginAs()->get(route('business.pages.show', [
|
||||
'company_id' => $this->company->id,
|
||||
'section' => 'financial-ledger',
|
||||
'page' => 'ledger',
|
||||
'accounts_short' => '测试账户',
|
||||
'accounts_status' => 'normal',
|
||||
'accounts_region' => '__empty__',
|
||||
'accounts_type' => '__empty__',
|
||||
]))
|
||||
->assertOk()
|
||||
->assertSee('data-account-short="测试账户"', false);
|
||||
}
|
||||
|
||||
public function test_account_status_can_be_saved_and_updated_without_duplicate_rows(): void
|
||||
{
|
||||
$payload = [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user