CaiWuXiTong/app/Utilities/FinanceLedgerAccountShouldKeep.php

46 lines
1.2 KiB
PHP

<?php
namespace App\Utilities;
class FinanceLedgerAccountShouldKeep
{
public const YES = '是';
public const NO = '否';
public const OPTIONS = [self::YES, self::NO];
public static function normalize(?string $value): string
{
$value = trim((string) $value);
if ($value === '') {
return '';
}
$compact = mb_strtoupper((string) preg_replace('/\s+/u', '', $value));
if (in_array($compact, ['是', '保留', '需要保留', '需要', 'Y', 'YES', 'TRUE', '1'], true)) {
return self::YES;
}
if (in_array($compact, ['否', '不保留', '不需要保留', '不需要', 'N', 'NO', 'FALSE', '0'], true)) {
return self::NO;
}
return $value;
}
public static function display(?string $explicitValue, ?string $companyPlan): string
{
$normalized = self::normalize($explicitValue);
if ($normalized !== '') {
return $normalized;
}
$plan = trim((string) $companyPlan);
if ($plan === '') {
return '';
}
return str_contains($plan, '保留') ? self::YES : self::NO;
}
}