63 lines
2.2 KiB
PHP
63 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Utilities;
|
|
|
|
use Illuminate\Database\ConnectionInterface;
|
|
|
|
final class FinanceLedgerBankDirectAccounts
|
|
{
|
|
/** @return array<string,true> */
|
|
public static function map(ConnectionInterface $connection): array
|
|
{
|
|
$accounts = $connection->table('fin_accounts')
|
|
->whereNotNull('account_short')
|
|
->where('account_short', '<>', '')
|
|
->orderBy('id')
|
|
->get(['account_short', 'account_type', 'bank_name']);
|
|
if ($accounts->isEmpty()) {
|
|
return [];
|
|
}
|
|
|
|
$accountShorts = $accounts->pluck('account_short')->unique()->values()->all();
|
|
$typeOverrides = $connection->getSchemaBuilder()->hasTable('fin_account_type_overrides')
|
|
? $connection->table('fin_account_type_overrides')
|
|
->whereIn('account_short', $accountShorts)
|
|
->pluck('account_type', 'account_short')
|
|
: collect();
|
|
$sources = $connection->getSchemaBuilder()->hasTable('fin_flow_summary_account_sources')
|
|
? $connection->table('fin_flow_summary_account_sources')
|
|
->whereIn('account_short', $accountShorts)
|
|
->pluck('data_source', 'account_short')
|
|
: collect();
|
|
|
|
$direct = [];
|
|
foreach ($accounts as $account) {
|
|
$accountShort = trim((string) $account->account_short);
|
|
$accountType = trim((string) (
|
|
$typeOverrides[$accountShort]
|
|
?? $account->account_type
|
|
?? ''
|
|
));
|
|
if ($accountShort === '' || $accountType === '个人卡') {
|
|
continue;
|
|
}
|
|
|
|
if (FinanceLedgerFlowSummaryDataSource::normalize($sources[$accountShort] ?? null)
|
|
=== FinanceLedgerFlowSummaryDataSource::DIRECT) {
|
|
$direct[$accountShort] = true;
|
|
continue;
|
|
}
|
|
|
|
$bank = trim((string) ($account->bank_name ?? ''));
|
|
if (str_contains($accountShort, '招商')
|
|
|| str_contains($accountShort, '招行')
|
|
|| str_contains($bank, '招商')
|
|
|| str_contains($bank, '招行')) {
|
|
$direct[$accountShort] = true;
|
|
}
|
|
}
|
|
|
|
return $direct;
|
|
}
|
|
}
|