fix: keep personal-card company plan retained

Personal-card plan and keep status are both fixed to retained.
This commit is contained in:
shanshi 2026-12-01 17:37:34 +08:00
parent 857330d70d
commit c8a3759f91
13 changed files with 68 additions and 27 deletions

View File

@ -109,6 +109,7 @@ class AssignFinanceLedgerCompanyPlans extends Command
$connection->table('fin_accounts')
->whereIn('id', $ids)
->update([
'company_plan' => '保留',
'account_should_keep' => '是',
'updated_at' => $now,
]);

View File

@ -2924,15 +2924,12 @@ class FinanceLedger extends Controller
->where('account_short', $accountShort)
->first(['company_name', 'account_short', 'account_type', 'account_should_keep']);
abort_if($account === null, 422, '账户简称不存在,请刷新账户总表后重试。');
$allowedPlans = $connection->table('fin_accounts')
$allowedPlans = FinanceLedgerAccountShouldKeep::companyPlanOptions($connection->table('fin_accounts')
->whereNotNull('company_plan')
->where('company_plan', '<>', '')
->distinct()
->pluck('company_plan')
->map(static fn (mixed $value): string => trim((string) $value))
->filter()
->values()
->all();
->all());
abort_unless($plan === '' || in_array($plan, $allowedPlans, true), 422, '请选择现有公司规划。');
$overrideType = $connection->table('fin_account_type_overrides')
@ -2941,6 +2938,7 @@ class FinanceLedger extends Controller
$effectiveType = $overrideType !== null
? (string) $overrideType
: (string) ($account->account_type ?? '');
$effectivePlan = $plan;
$accountUpdates = [];
if (FinanceLedgerAccountType::companyPlanDrivesKeep($effectiveType)) {
$accountUpdates = $companyPlans->synchronizeBankAccounts(
@ -2956,6 +2954,8 @@ class FinanceLedger extends Controller
'updated_at' => now(),
];
if (FinanceLedgerAccountType::isAlwaysRetained($effectiveType)) {
$effectivePlan = '保留';
$values['company_plan'] = '保留';
$values['account_should_keep'] = FinanceLedgerAccountShouldKeep::YES;
$account->account_should_keep = FinanceLedgerAccountShouldKeep::YES;
}
@ -2969,8 +2969,8 @@ class FinanceLedger extends Controller
'ok' => true,
'account_short' => $accountShort,
'company_name' => (string) $account->company_name,
'company_plan' => $plan,
'label' => $plan !== '' ? $plan : '未填写',
'company_plan' => $effectivePlan,
'label' => $effectivePlan !== '' ? $effectivePlan : '未填写',
'account_should_keep' => $keep,
'keep_label' => $keep !== '' ? $keep : '未填写',
'account_updates' => $accountUpdates,

View File

@ -14,6 +14,8 @@ class FinanceLedgerAccountShouldKeep
public const OPTIONS = [self::YES, self::TEMPORARY, self::NO];
public const COMPANY_PLAN_OPTIONS = ['保留', '不保留', '待注销'];
public const LABELS = [
self::YES => '保留',
self::TEMPORARY => '暂时保留',
@ -71,6 +73,18 @@ class FinanceLedgerAccountShouldKeep
: self::TEMPORARY;
}
public static function companyPlanOptions(array $existing = []): array
{
$options = [
...self::COMPANY_PLAN_OPTIONS,
...array_map(static fn (mixed $value): string => trim((string) $value), $existing),
];
$options = array_values(array_unique(array_filter($options)));
sort($options, SORT_NATURAL | SORT_FLAG_CASE);
return $options;
}
public static function label(?string $explicitValue, ?string $companyPlan): string
{
return self::LABELS[self::display($explicitValue, $companyPlan)] ?? '';

View File

@ -24,7 +24,9 @@ class FinanceLedgerAccountCreator
$accountShort = $this->text($data['account_short'] ?? '');
$accountNo = $this->text($data['account_no'] ?? '');
$accountType = $this->text($data['account_type'] ?? '');
$companyPlan = $this->text($data['company_plan'] ?? '');
$companyPlan = FinanceLedgerAccountType::isAlwaysRetained($accountType)
? '保留'
: $this->text($data['company_plan'] ?? '');
$companyFields = [
'register_place' => $this->nullableText($data['company_register_place'] ?? null),
'business_type' => $this->nullableText($data['company_business_type'] ?? null),

View File

@ -59,7 +59,9 @@ class FinanceLedgerAccountEditor
$accountType = $this->nullableText($data['account_type'] ?? null);
$accountNo = $this->nullableText($data['account_no'] ?? null);
$status = FinanceLedgerAccountStatus::normalize((string) ($data['status'] ?? ''));
$companyPlan = $this->nullableText($data['company_plan'] ?? null);
$companyPlan = FinanceLedgerAccountType::isAlwaysRetained($accountType)
? '保留'
: $this->nullableText($data['company_plan'] ?? null);
$syncCompanyPlan = array_key_exists('company_plan', $data)
&& FinanceLedgerAccountType::companyPlanDrivesKeep($accountType);
$accountShouldKeep = FinanceLedgerAccountType::isAlwaysRetained($accountType)

View File

@ -129,6 +129,7 @@ class FinanceLedgerBaseImporter
$keepIndex === null ? null : $this->text($row[$keepIndex] ?? null),
);
if (FinanceLedgerAccountType::isAlwaysRetained($accountType)) {
$companyPlan = '保留';
$accountShouldKeep = FinanceLedgerAccountShouldKeep::YES;
} elseif (FinanceLedgerAccountType::companyPlanDrivesKeep($accountType)
&& $companyPlan !== '') {

View File

@ -73,13 +73,14 @@ final class FinanceLedgerCompanyPlanSynchronizer
$currentPlan = trim((string) ($account->company_plan ?? ''));
$currentKeep = trim((string) ($account->account_should_keep ?? ''));
if (FinanceLedgerAccountType::isAlwaysRetained($accountType)) {
if ($currentKeep === FinanceLedgerAccountShouldKeep::YES) {
if ($currentPlan === '保留'
&& $currentKeep === FinanceLedgerAccountShouldKeep::YES) {
continue;
}
$personalCardChanges[] = [
'id' => (int) $account->id,
'account_short' => $accountShort,
'company_plan' => $currentPlan,
'company_plan' => '保留',
'account_should_keep' => FinanceLedgerAccountShouldKeep::YES,
];
@ -121,6 +122,7 @@ final class FinanceLedgerCompanyPlanSynchronizer
$this->connection->table('fin_accounts')
->whereIn('id', array_column($personalCardChanges, 'id'))
->update([
'company_plan' => '保留',
'account_should_keep' => FinanceLedgerAccountShouldKeep::YES,
'updated_at' => $now,
]);

View File

@ -2920,17 +2920,15 @@ class FinanceLedgerPageData
private function accountPlanOptions(): array
{
return FinanceLedgerIndependentAccounts::exclude($this->db()->table('fin_accounts'))
$existing = FinanceLedgerIndependentAccounts::exclude($this->db()->table('fin_accounts'))
->whereNotNull('company_plan')
->where('company_plan', '<>', '')
->distinct()
->orderBy('company_plan')
->pluck('company_plan')
->map(static fn (mixed $value): string => trim((string) $value))
->filter()
->unique()
->values()
->all();
return FinanceLedgerAccountShouldKeep::companyPlanOptions($existing);
}
private function companyOptions(): array

View File

@ -1654,7 +1654,7 @@
<td class="ledger-plan-column">
<span class="ledger-account-readonly" data-account-edit-display data-account-plan-display>{{ $row->company_plan ?: '未填写' }}</span>
@if ($canEditAccountStatus)
<select class="ledger-inline-select ledger-plan-select ledger-account-editor" data-account-editor data-account-plan data-account-short="{{ $row->account_short }}" data-url="{{ route('business.financial-ledger.accounts.plan') }}" aria-label="账户 {{ $row->account_short }} 账户状态" disabled>
<select class="ledger-inline-select ledger-plan-select ledger-account-editor" data-account-editor data-account-plan data-account-short="{{ $row->account_short }}" data-account-plan-locked="{{ ($row->account_keep_mode ?? 'manual') === 'always_retained' ? 'true' : 'false' }}" data-url="{{ route('business.financial-ledger.accounts.plan') }}" aria-label="账户 {{ $row->account_short }} 账户状态" title="{{ ($row->account_keep_mode ?? 'manual') === 'always_retained' ? '个人卡公司规划固定为保留' : '' }}" disabled>
<option value="" @selected(($row->company_plan ?? '') === '')>未填写</option>
@foreach ($accountPlanOptions as $planOption)
<option value="{{ $planOption }}" @selected($row->company_plan === $planOption)>{{ $planOption }}</option>
@ -1765,7 +1765,7 @@
<td class="ledger-plan-column">
<span class="ledger-account-readonly" data-account-edit-display data-account-plan-display>{{ $row->company_plan ?: '未填写' }}</span>
@if ($canEditAccountStatus)
<select class="ledger-inline-select ledger-plan-select ledger-account-editor" data-account-editor data-account-plan data-account-short="{{ $row->account_short }}" data-url="{{ route('business.financial-ledger.accounts.plan') }}" aria-label="账户 {{ $row->account_short }} 公司规划" disabled>
<select class="ledger-inline-select ledger-plan-select ledger-account-editor" data-account-editor data-account-plan data-account-short="{{ $row->account_short }}" data-account-plan-locked="{{ ($row->account_keep_mode ?? 'manual') === 'always_retained' ? 'true' : 'false' }}" data-url="{{ route('business.financial-ledger.accounts.plan') }}" aria-label="账户 {{ $row->account_short }} 公司规划" title="{{ ($row->account_keep_mode ?? 'manual') === 'always_retained' ? '个人卡公司规划固定为保留' : '' }}" disabled>
<option value="" @selected(($row->company_plan ?? '') === '')>未填写</option>
@foreach ($accountPlanOptions as $planOption)
<option value="{{ $planOption }}" @selected($row->company_plan === $planOption)>{{ $planOption }}</option>
@ -5954,7 +5954,11 @@
accountKeepSelect.title = mode === 'always_retained'
? '个人卡固定为保留'
: (mode === 'company_plan' ? '由公司规划自动生成' : '');
if (mode === 'always_retained') accountKeepSelect.value = '是';
if (accountPlanInput) accountPlanInput.readOnly = mode === 'always_retained';
if (mode === 'always_retained') {
if (accountPlanInput) accountPlanInput.value = '保留';
accountKeepSelect.value = '是';
}
if (mode === 'company_plan') {
accountKeepSelect.value = keepForCompanyPlan(accountPlanInput?.value);
}
@ -6005,7 +6009,8 @@
accountPanel?.classList.toggle('is-account-edit-mode', active);
accountPanel?.querySelectorAll('[data-account-editor]').forEach((editor) => {
const keepMode = editor.dataset.accountKeepMode || 'manual';
editor.disabled = !active || keepMode !== 'manual';
const planLocked = editor.dataset.accountPlanLocked === 'true';
editor.disabled = !active || keepMode !== 'manual' || planLocked;
});
accountEditToggle?.setAttribute('aria-checked', active ? 'true' : 'false');
if (accountAddCompanyButton) {
@ -6140,13 +6145,19 @@
const accountEditField = (name) => accountEditForm?.elements.namedItem(name) || null;
const applyAccountEditKeepMode = (mode, companyPlan = '') => {
const keepField = accountEditField('account_should_keep');
const planField = accountEditField('company_plan');
if (!keepField) return;
keepField.disabled = mode !== 'manual';
keepField.title = mode === 'always_retained'
? '个人卡固定为保留'
: (mode === 'company_plan' ? '由公司规划自动生成' : '');
if (mode === 'always_retained') keepField.value = '是';
if (mode === 'company_plan') keepField.value = keepForCompanyPlan(companyPlan);
if (planField) planField.readOnly = mode === 'always_retained';
if (mode === 'always_retained') {
if (planField) planField.value = '保留';
keepField.value = '是';
} else if (mode === 'company_plan') {
keepField.value = keepForCompanyPlan(companyPlan);
}
};
const openAccountEditDialog = async (button) => {
if (!accountEditDialog || !accountEditForm) return;

View File

@ -1088,7 +1088,8 @@ class FinanceLedgerAccountStatusTest extends FeatureTestCase
$this->loginAs()->get($this->pageUrl())
->assertOk()
->assertSee('data-account-keep-mode="company_plan"', false)
->assertSee('data-account-keep-mode="always_retained"', false);
->assertSee('data-account-keep-mode="always_retained"', false)
->assertSee('data-account-plan-locked="true"', false);
$this->loginAs()->postJson($this->planUrl(), [
'account_short' => '联动公户甲',
@ -1106,7 +1107,7 @@ class FinanceLedgerAccountStatusTest extends FeatureTestCase
}
$this->assertDatabaseHas('fin_accounts', [
'account_short' => '联动个人卡',
'company_plan' => '不保留',
'company_plan' => '保留',
'account_should_keep' => '是',
], 'business_mirror');
$this->assertDatabaseHas('fin_accounts', [
@ -1130,7 +1131,7 @@ class FinanceLedgerAccountStatusTest extends FeatureTestCase
}
$this->assertDatabaseHas('fin_accounts', [
'account_short' => '联动个人卡',
'company_plan' => '不保留',
'company_plan' => '保留',
'account_should_keep' => '是',
], 'business_mirror');

View File

@ -89,7 +89,7 @@ class AssignFinanceLedgerCompanyPlansTest extends FeatureTestCase
'暂时公司银行账户' => '不保留/暂时保留',
'保留公司支付宝' => '待注销/否',
'暂时公司网商' => '保留/是',
'暂时公司个人卡' => '不保留/是',
'暂时公司个人卡' => '保留/是',
], $connection->table('fin_accounts')
->orderBy('id')
->get(['company_name', 'account_short', 'company_plan', 'account_should_keep'])
@ -122,7 +122,7 @@ class AssignFinanceLedgerCompanyPlansTest extends FeatureTestCase
], 'business_mirror');
$this->assertDatabaseHas('fin_accounts', [
'account_short' => '暂时公司个人卡',
'company_plan' => '不保留',
'company_plan' => '保留',
'account_should_keep' => '是',
], 'business_mirror');
}

View File

@ -66,6 +66,7 @@ class FinanceLedgerBaseImporterTest extends TestCase
$rows = $this->importer()->parseAccounts($sheet);
$this->assertCount(1, $rows);
$this->assertSame('保留', $rows[0]['company_plan']);
$this->assertSame('是', $rows[0]['account_should_keep']);
$this->assertSame('0001', $rows[0]['account_last4']);
$this->assertSame('10000', $rows[0]['single_limit']);
@ -128,6 +129,7 @@ class FinanceLedgerBaseImporterTest extends TestCase
$rows = $this->importer()->parseAccounts($sheet);
$this->assertCount(1, $rows);
$this->assertSame('保留', $rows[0]['company_plan']);
$this->assertSame('是', $rows[0]['account_should_keep']);
$this->assertSame('0002', $rows[0]['account_last4']);
$this->assertSame('1000', $rows[0]['single_limit']);

View File

@ -50,4 +50,11 @@ class FinanceLedgerAccountShouldKeepTest extends TestCase
);
$this->assertNull(FinanceLedgerAccountShouldKeep::fromCompanyPlan(''));
}
public function test_company_plan_options_keep_fixed_values_available(): void
{
$this->assertContains('保留', FinanceLedgerAccountShouldKeep::companyPlanOptions());
$this->assertContains('不保留', FinanceLedgerAccountShouldKeep::companyPlanOptions());
$this->assertContains('待注销', FinanceLedgerAccountShouldKeep::companyPlanOptions());
}
}