fix(银行账单): 显示个人卡账户筛选 (#1724)
个人卡账单账户加入页面下拉与表头筛选,并回显当前选中账户;仅有账单的个人卡进入选项。 验证:BankBillPageTest 32 项通过,293 个断言。
This commit is contained in:
parent
2197444889
commit
632a8407da
@ -99,7 +99,7 @@ final class BankBillPageData
|
||||
}
|
||||
|
||||
if (($column['canonical'] ?? null) === 'account_no') {
|
||||
$options = collect($this->directAccountOptions())
|
||||
$options = collect($this->accountOptions())
|
||||
->map(static fn (array $account): array => [
|
||||
'value' => (string) $account['account_no'],
|
||||
'label' => (string) $account['label'],
|
||||
@ -567,6 +567,42 @@ final class BankBillPageData
|
||||
private function accountOptions(): array
|
||||
{
|
||||
return collect($this->directAccountOptions())
|
||||
->merge($this->personalBillAccountOptions())
|
||||
->unique(static fn (array $row): string => $row['bank_name'] . '|' . $row['account_no'])
|
||||
->sortBy(static fn (array $row): string => $row['label'])
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
private function personalBillAccountOptions(): array
|
||||
{
|
||||
$connection = DB::connection((string) config('upstream_mirrors.connection', 'business_mirror'));
|
||||
$query = $connection->table('fin_accounts as a')
|
||||
->select([
|
||||
'a.company_name',
|
||||
'a.account_short',
|
||||
'a.account_no',
|
||||
'a.bank_name',
|
||||
])
|
||||
->where('a.account_type', '个人卡')
|
||||
->whereNotNull('a.account_no')
|
||||
->where('a.account_no', '<>', '')
|
||||
->whereExists(function (Builder $billQuery): void {
|
||||
$billQuery
|
||||
->selectRaw('1')
|
||||
->from(self::TABLE . ' as b')
|
||||
->whereColumn('b.account_no', 'a.account_no');
|
||||
})
|
||||
->distinct()
|
||||
->orderBy('a.account_short')
|
||||
->orderBy('a.account_no')
|
||||
->get();
|
||||
|
||||
return $query
|
||||
->map(fn (object $row): array => $this->accountOption($row))
|
||||
->filter(static fn (array $row): bool => $row['account_no'] !== '')
|
||||
->unique(static fn (array $row): string => $row['bank_name'] . '|' . $row['account_no'])
|
||||
->sortBy(static fn (array $row): string => $row['label'])
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
@ -617,25 +653,7 @@ final class BankBillPageData
|
||||
->get();
|
||||
|
||||
return $query
|
||||
->map(function (object $row): array {
|
||||
$bank = $this->directAccountBank(
|
||||
(string) ($row->account_short ?? ''),
|
||||
(string) ($row->bank_name ?? ''),
|
||||
);
|
||||
|
||||
return [
|
||||
'bank_name' => $bank,
|
||||
'company_name' => (string) ($row->company_name ?? ''),
|
||||
'account_short' => (string) $row->account_short,
|
||||
'account_no' => preg_replace('/\D+/', '', (string) $row->account_no) ?? '',
|
||||
'label' => trim(implode(' · ', array_filter([
|
||||
$bank,
|
||||
(string) $row->account_short,
|
||||
(string) $row->account_no,
|
||||
(string) ($row->company_name ?? ''),
|
||||
]))),
|
||||
];
|
||||
})
|
||||
->map(fn (object $row): array => $this->accountOption($row))
|
||||
->filter(static fn (array $row): bool => $row['account_no'] !== '')
|
||||
->unique(static fn (array $row): string => $row['bank_name'] . '|' . $row['account_no'])
|
||||
->sortBy(static fn (array $row): string => $row['label'])
|
||||
@ -643,6 +661,27 @@ final class BankBillPageData
|
||||
->all();
|
||||
}
|
||||
|
||||
private function accountOption(object $row): array
|
||||
{
|
||||
$bank = $this->directAccountBank(
|
||||
(string) ($row->account_short ?? ''),
|
||||
(string) ($row->bank_name ?? ''),
|
||||
);
|
||||
|
||||
return [
|
||||
'bank_name' => $bank,
|
||||
'company_name' => (string) ($row->company_name ?? ''),
|
||||
'account_short' => (string) $row->account_short,
|
||||
'account_no' => preg_replace('/\D+/', '', (string) $row->account_no) ?? '',
|
||||
'label' => trim(implode(' · ', array_filter([
|
||||
$bank,
|
||||
(string) $row->account_short,
|
||||
(string) $row->account_no,
|
||||
(string) ($row->company_name ?? ''),
|
||||
]))),
|
||||
];
|
||||
}
|
||||
|
||||
private function directAccountBank(string $accountShort, string $bankName): string
|
||||
{
|
||||
if (str_contains($accountShort, '招行') || str_contains($bankName, '招商银行')) {
|
||||
|
||||
@ -261,6 +261,83 @@ class BankBillPageTest extends FeatureTestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_personal_card_bill_accounts_are_selected_and_available_in_header_filters(): void
|
||||
{
|
||||
$connection = DB::connection('business_mirror');
|
||||
$connection->table('fin_accounts')->insert([
|
||||
'company_name' => '个人测试公司',
|
||||
'account_short' => '华夏个人测试',
|
||||
'account_type' => '个人卡',
|
||||
'bank_name' => '华夏银行',
|
||||
'account_no' => '6222000000000188',
|
||||
'account_should_keep' => '是',
|
||||
'current_balance' => 100,
|
||||
'daily_available' => 100,
|
||||
'blocked_amount' => 0,
|
||||
]);
|
||||
$connection->table('fin_accounts')->insert([
|
||||
'company_name' => '无账单个人测试公司',
|
||||
'account_short' => '华夏无账单个人测试',
|
||||
'account_type' => '个人卡',
|
||||
'bank_name' => '华夏银行',
|
||||
'account_no' => '6222000000000189',
|
||||
'account_should_keep' => '是',
|
||||
'current_balance' => 100,
|
||||
'daily_available' => 100,
|
||||
'blocked_amount' => 0,
|
||||
]);
|
||||
$connection->table('fin_bank_direct_bills')->insert([
|
||||
'bank_name' => '华夏银行',
|
||||
'company_name' => '个人测试公司',
|
||||
'account_short' => '华夏个人测试',
|
||||
'account_no' => '6222000000000188',
|
||||
'txn_date' => '2026-11-22',
|
||||
'txn_at' => '2026-11-22 10:00:00',
|
||||
'record_code' => 'HX-PERSONAL-001',
|
||||
'detail' => '个人卡账单测试',
|
||||
'income' => 100,
|
||||
'expense' => 0,
|
||||
'balance' => 100,
|
||||
'source_file_name' => '华夏个人测试.xls',
|
||||
'source_file_sha256' => str_repeat('e', 64),
|
||||
'row_key' => hash('sha256', 'hx-personal-account-filter'),
|
||||
'imported_at' => '2026-11-24 08:30:00',
|
||||
]);
|
||||
|
||||
$response = $this->loginAs()->get($this->ledgerUrl([
|
||||
'tab' => 'bills',
|
||||
'bills_bank' => '华夏银行',
|
||||
'bills_account_no' => '6222000000000188',
|
||||
'bills_from' => '2026-11-01',
|
||||
'bills_to' => '2026-11-30',
|
||||
]))->assertOk();
|
||||
|
||||
$response
|
||||
->assertSeeText('华夏银行 · 华夏个人测试 · 6222000000000188 · 个人测试公司')
|
||||
->assertSeeText('HX-PERSONAL-001')
|
||||
->assertSeeText('个人卡账单测试');
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/<option\s+value="6222000000000188"[^>]*\bselected\b[^>]*>/s',
|
||||
$response->getContent(),
|
||||
);
|
||||
|
||||
$optionsUrl = route('business.financial-ledger.bank-bills.filter-options', [
|
||||
'company_id' => $this->company->id,
|
||||
'column_key' => 'account_no',
|
||||
'bills_bank' => '华夏银行',
|
||||
'bills_from' => '2026-11-01',
|
||||
'bills_to' => '2026-11-30',
|
||||
]);
|
||||
$this->loginAs()->get($optionsUrl)
|
||||
->assertOk()
|
||||
->assertJsonFragment([
|
||||
'value' => '6222000000000188',
|
||||
'label' => '华夏银行 · 华夏个人测试 · 6222000000000188 · 个人测试公司',
|
||||
'bank' => '华夏银行',
|
||||
])
|
||||
->assertJsonMissing(['value' => '6222000000000189']);
|
||||
}
|
||||
|
||||
public function test_raw_header_filter_applies_to_the_server_query(): void
|
||||
{
|
||||
$connection = DB::connection('business_mirror');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user