From b0cd721e0b2d41ae300e477aff16d5c36abd39e5 Mon Sep 17 00:00:00 2001 From: shanshi <3316401569@qq.com> Date: Wed, 21 Oct 2026 11:58:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A2=E5=8A=A1=E5=8F=B0=E8=B4=A6=EF=BC=9A?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B4=A6=E6=88=B7=E6=98=AF=E5=90=A6=E4=BF=9D?= =?UTF-8?q?=E7=95=99=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FinanceLedgerAccountShouldKeep.php | 45 +++++ ...dd_account_should_keep_to_fin_accounts.php | 35 ++++ .../Services/FinanceLedgerAccountTemplate.php | 27 ++- .../Services/FinanceLedgerBaseImporter.php | 70 +++++--- .../View/FinanceLedgerPageData.php | 5 + .../pages/financial-ledger/ledger.blade.php | 7 +- .../FinanceLedgerAccountStatusTest.php | 17 ++ .../FinanceLedgerAccountTemplateTest.php | 11 +- .../FinanceLedgerBaseImporterTest.php | 159 ++++++++++++++++++ 9 files changed, 338 insertions(+), 38 deletions(-) create mode 100644 app/Utilities/FinanceLedgerAccountShouldKeep.php create mode 100644 database/migrations/2026_10_21_120000_add_account_should_keep_to_fin_accounts.php create mode 100644 tests/Unit/EcommerceFinance/FinanceLedgerBaseImporterTest.php diff --git a/app/Utilities/FinanceLedgerAccountShouldKeep.php b/app/Utilities/FinanceLedgerAccountShouldKeep.php new file mode 100644 index 00000000..bf928203 --- /dev/null +++ b/app/Utilities/FinanceLedgerAccountShouldKeep.php @@ -0,0 +1,45 @@ +connection()); + if (! $schema->hasTable('fin_accounts') || $schema->hasColumn('fin_accounts', 'account_should_keep')) { + return; + } + + $schema->table('fin_accounts', function (Blueprint $table): void { + $table->string('account_should_keep', 20)->nullable()->after('company_plan'); + }); + } + + public function down(): void + { + $schema = Schema::connection($this->connection()); + if ($schema->hasTable('fin_accounts') && $schema->hasColumn('fin_accounts', 'account_should_keep')) { + $schema->table('fin_accounts', function (Blueprint $table): void { + $table->dropColumn('account_should_keep'); + }); + } + } +}; diff --git a/modules/EcommerceFinance/Services/FinanceLedgerAccountTemplate.php b/modules/EcommerceFinance/Services/FinanceLedgerAccountTemplate.php index 3b059c2e..f5658433 100644 --- a/modules/EcommerceFinance/Services/FinanceLedgerAccountTemplate.php +++ b/modules/EcommerceFinance/Services/FinanceLedgerAccountTemplate.php @@ -3,6 +3,7 @@ namespace Modules\EcommerceFinance\Services; use App\Utilities\FinanceLedgerAccountStatus; +use App\Utilities\FinanceLedgerAccountShouldKeep; use App\Utilities\FinanceLedgerAccountType; use Illuminate\Support\Facades\DB; use PhpOffice\PhpSpreadsheet\Cell\Coordinate; @@ -33,6 +34,7 @@ class FinanceLedgerAccountTemplate '开户行', '开户城市/网点', '公司规划', + '账户是否保留', '后4位', '单笔限额', '日限额', @@ -98,29 +100,35 @@ class FinanceLedgerAccountTemplate $sheet->getStyle("A1:{$lastColumn}{$lastRow}")->getBorders()->getAllBorders() ->setBorderStyle(Border::BORDER_THIN)->getColor()->setARGB('FFD8D2C7'); - $sheet->getStyle("A2:N{$lastRow}")->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT); - $sheet->getStyle("O2:Q{$lastRow}")->getNumberFormat()->setFormatCode('#,##0.00'); - $sheet->getStyle("R2:R{$lastRow}")->getNumberFormat()->setFormatCode('0.00'); - $sheet->getStyle("S2:Y{$lastRow}")->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT); + $sheet->getStyle("A2:O{$lastRow}")->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT); + $sheet->getStyle("P2:R{$lastRow}")->getNumberFormat()->setFormatCode('#,##0.00'); + $sheet->getStyle("S2:S{$lastRow}")->getNumberFormat()->setFormatCode('0.00'); + $sheet->getStyle("T2:Z{$lastRow}")->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT); $options = $spreadsheet->createSheet(); $options->setTitle('选项'); $options->setCellValue('A1', '账户状态'); $options->setCellValue('B1', '账户类型'); + $options->setCellValue('C1', '账户是否保留'); $statuses = array_values(FinanceLedgerAccountStatus::OPTIONS); $types = $this->accountTypes(); + $keepOptions = FinanceLedgerAccountShouldKeep::OPTIONS; foreach ($statuses as $index => $status) { $options->setCellValue('A' . ($index + 2), $status); } foreach ($types as $index => $type) { $options->setCellValue('B' . ($index + 2), $type); } + foreach ($keepOptions as $index => $option) { + $options->setCellValue('C' . ($index + 2), $option); + } $options->setSheetState(Worksheet::SHEETSTATE_HIDDEN); $this->applyListValidation($sheet, 'D', '\'选项\'!$A$2:$A$' . (count($statuses) + 1), '请选择账户状态'); if ($types !== []) { $this->applyListValidation($sheet, 'C', '\'选项\'!$B$2:$B$' . (count($types) + 1), '请选择账户类型'); } + $this->applyListValidation($sheet, 'J', '\'选项\'!$C$2:$C$' . (count($keepOptions) + 1), '请选择账户是否保留'); $notes = $spreadsheet->createSheet(); $notes->setTitle('填写说明'); @@ -130,6 +138,7 @@ class FinanceLedgerAccountTemplate ['必填', '公司名称、账户简称。'], ['账户状态', implode(' / ', $statuses)], ['账户类型', $types !== [] ? implode(' / ', $types) : '留空或按实际填写'], + ['账户是否保留', implode(' / ', $keepOptions)], ['金额', '可用金额、不可用金额、每日可出按数字填写;限额列保留原有组合写法。'], ['提交前', '请核对账户数、余额合计和期初合计,再导入系统。'], ], null, 'A1'); @@ -139,8 +148,8 @@ class FinanceLedgerAccountTemplate $notes->getStyle('A1:B1')->getFill() ->setFillType(Fill::FILL_SOLID) ->getStartColor()->setARGB('FF856632'); - $notes->getStyle('A1:B7')->getAlignment()->setVertical(Alignment::VERTICAL_TOP)->setWrapText(true); - $notes->getStyle('A1:B7')->getBorders()->getAllBorders() + $notes->getStyle('A1:B8')->getAlignment()->setVertical(Alignment::VERTICAL_TOP)->setWrapText(true); + $notes->getStyle('A1:B8')->getBorders()->getAllBorders() ->setBorderStyle(Border::BORDER_THIN)->getColor()->setARGB('FFD8D2C7'); $notes->getRowDimension(1)->setRowHeight(26); @@ -189,9 +198,9 @@ class FinanceLedgerAccountTemplate { return match ($index) { 0, 6 => 30, - 1, 5, 7, 23 => 22, - 2, 3, 4, 8, 17 => 13, - 14, 15, 16 => 16, + 1, 5, 7, 24 => 22, + 2, 3, 4, 8, 9, 18 => 13, + 15, 16, 17 => 16, default => 18, }; } diff --git a/modules/EcommerceFinance/Services/FinanceLedgerBaseImporter.php b/modules/EcommerceFinance/Services/FinanceLedgerBaseImporter.php index e3790ac8..447d57ee 100644 --- a/modules/EcommerceFinance/Services/FinanceLedgerBaseImporter.php +++ b/modules/EcommerceFinance/Services/FinanceLedgerBaseImporter.php @@ -2,7 +2,9 @@ namespace Modules\EcommerceFinance\Services; +use App\Utilities\FinanceLedgerAccountShouldKeep; use Illuminate\Support\Facades\DB; +use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use RuntimeException; @@ -90,45 +92,63 @@ class FinanceLedgerBaseImporter ]; } - private function accounts(?Worksheet $sheet): array + protected function accounts(?Worksheet $sheet): array { if (! $sheet) { throw new RuntimeException('缺少「账户总表」工作表。'); } + $lastColumn = Coordinate::columnIndexFromString($sheet->getHighestDataColumn()); + $headers = $sheet->rangeToArray('A1:' . Coordinate::stringFromColumnIndex($lastColumn) . '1')[0] ?? []; + $headerIndexes = []; + foreach ($headers as $index => $header) { + $key = (string) preg_replace('/\s+/u', '', trim((string) $header)); + if ($key !== '') { + $headerIndexes[$key] = $index; + } + } + $rows = []; - foreach ($this->rows($sheet, 2, 23) as $row) { - $company = $this->text($row[0] ?? null); - $short = $this->text($row[1] ?? null); + foreach ($this->rows($sheet, 2, $lastColumn) as $row) { + $value = static function (string $header, int $legacyIndex) use ($row, $headerIndexes): mixed { + return $row[$headerIndexes[$header] ?? $legacyIndex] ?? null; + }; + + $company = $this->text($value('公司名称', 0)); + $short = $this->text($value('账户简称', 1)); if ($company === '' || $short === '') { continue; } + $keepIndex = $headerIndexes['账户是否保留'] ?? null; $rows[] = [ 'company_name' => $company, 'account_short' => $short, 'region' => null, - 'account_no' => $this->text($row[2] ?? null), - 'bank_name' => $this->text($row[3] ?? null), - 'bank_city_branch' => $this->text($row[4] ?? null), - 'account_type' => $this->text($row[5] ?? null), - 'company_plan' => $this->text($row[6] ?? null), - 'account_last4' => $this->text($row[7] ?? null), - 'single_limit' => $this->text($row[8] ?? null), - 'daily_limit' => $this->text($row[9] ?? null), - 'monthly_limit' => $this->text($row[10] ?? null), - 'yearly_limit' => $this->text($row[11] ?? null), - 'current_balance' => $this->number($row[12] ?? null), - 'blocked_amount' => $this->number($row[13] ?? null), - 'daily_available' => $this->number($row[14] ?? null), - 'clearing_days' => $this->nullableNumber($row[15] ?? null), - 'raise_target' => $this->text($row[16] ?? null), - 'raise_status' => $this->text($row[17] ?? null), - 'raise_actions' => $this->text($row[18] ?? null), - 'done_actions' => $this->text($row[19] ?? null), - 'next_action' => $this->text($row[20] ?? null), - 'remark' => $this->text($row[21] ?? null), - 'owner' => $this->text($row[22] ?? null), + 'account_no' => $this->text($value('账号', 2)), + 'bank_name' => $this->text($value('开户行', 3)), + 'bank_city_branch' => $this->text($value('开户城市/网点', 4)), + 'account_type' => $this->text($value('账户类型', 5)), + 'company_plan' => $this->text($value('公司规划', 6)), + 'account_should_keep' => FinanceLedgerAccountShouldKeep::normalize( + $keepIndex === null ? null : $this->text($row[$keepIndex] ?? null), + ), + 'account_last4' => $this->text($value('后4位', 7)), + 'single_limit' => $this->text($value('单笔限额', 8)), + 'daily_limit' => $this->text($value('日限额', 9)), + 'monthly_limit' => $this->text($value('月限额', 10)), + 'yearly_limit' => $this->text($value('年限额', 11)), + 'current_balance' => $this->number($value('可用金额', 12)), + 'blocked_amount' => $this->number($value('不可用金额', 13)), + 'daily_available' => $this->number($value('每日可出', 14)), + 'clearing_days' => $this->nullableNumber($value('预计出清天数', 15)), + 'raise_target' => $this->text($value('提额目标', 16)), + 'raise_status' => $this->text($value('提额状态', 17)), + 'raise_actions' => $this->text($value('提额动作', 18)), + 'done_actions' => $this->text($value('已做动作', 19)), + 'next_action' => $this->text($value('下一步', 20)), + 'remark' => $this->text($value('备注', 21)), + 'owner' => $this->text($value('责任人', 22)), ]; } diff --git a/modules/EcommerceFinance/View/FinanceLedgerPageData.php b/modules/EcommerceFinance/View/FinanceLedgerPageData.php index e027325b..1d5a9951 100644 --- a/modules/EcommerceFinance/View/FinanceLedgerPageData.php +++ b/modules/EcommerceFinance/View/FinanceLedgerPageData.php @@ -3,6 +3,7 @@ namespace Modules\EcommerceFinance\View; use App\Utilities\FinanceLedgerAccountStatus; +use App\Utilities\FinanceLedgerAccountShouldKeep; use App\Utilities\FinanceLedgerAccountType; use App\Utilities\FinanceLedgerAccess; use Illuminate\Contracts\Pagination\LengthAwarePaginator; @@ -173,6 +174,10 @@ class FinanceLedgerPageData if ($typeOverrides->has($row->account_short)) { $row->account_type = (string) ($typeOverrides->get($row->account_short) ?? ''); } + $row->account_should_keep = FinanceLedgerAccountShouldKeep::display( + $row->account_should_keep ?? null, + $row->company_plan ?? null, + ); return $row; }); diff --git a/resources/views/business/pages/financial-ledger/ledger.blade.php b/resources/views/business/pages/financial-ledger/ledger.blade.php index e1d42910..f85c14e6 100644 --- a/resources/views/business/pages/financial-ledger/ledger.blade.php +++ b/resources/views/business/pages/financial-ledger/ledger.blade.php @@ -88,6 +88,7 @@ .ledger-accounts-table thead th.num { text-align:center; } .ledger-accounts-table { min-width:max-content; } .ledger-accounts-table .is-column-hidden { display:none !important; } + .ledger-keep-column { width:6.5rem; min-width:6.5rem; text-align:center; } .ledger-table td.wrap { white-space:normal; min-width:14rem; max-width:22rem; line-height:1.5; } .ledger-table .muted { color:var(--vip-content-muted, #595959); } .ledger-table .danger { color:var(--vip-danger, #B80000); } @@ -196,7 +197,7 @@
| 公司名称 | 账户简称 | 账户类型 | 账户状态 | 地区 | 账号 | 开户行 | 开户城市/网点 | 公司规划 | 后4位 | 单笔限额 | 日限额 | 月限额 | 年限额 | 可用金额 | 不可用金额 | 每日可出 | 预计出清天数 | 提额目标 | 提额状态 | 提额动作 | 已做动作 | 下一步 | 备注 | 责任人 | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 公司名称 | 账户简称 | 账户类型 | 账户状态 | 地区 | 账号 | 开户行 | 开户城市/网点 | 公司规划 | 账户是否保留 | 后4位 | 单笔限额 | 日限额 | 月限额 | 年限额 | 可用金额 | 不可用金额 | 每日可出 | 预计出清天数 | 提额目标 | 提额状态 | 提额动作 | 已做动作 | 下一步 | 备注 | 责任人 | |||||||||||||
| {{ $row->region }} | {{ $row->account_no }} | {{ $row->bank_name }} | {{ $row->bank_city_branch }} | -{{ $row->company_plan }} | {{ $row->account_last4 }} | {{ $row->single_limit }} | {{ $row->daily_limit }} | {{ $row->monthly_limit }} | {{ $row->yearly_limit }} | {{ $money($row->current_balance) }} | {{ $money($row->blocked_amount) }} | {{ $money($row->daily_available) }} | {{ $row->clearing_days !== null ? number_format((float) $row->clearing_days, 2) : '' }} | {{ $row->raise_target }} | {{ $row->raise_status }} | {{ $row->raise_actions }} | {{ $row->done_actions }} | {{ $row->next_action }} | {{ $row->remark }} | {{ $row->owner }} | +{{ $row->company_plan }} | {{ $row->account_should_keep }} | {{ $row->account_last4 }} | {{ $row->single_limit }} | {{ $row->daily_limit }} | {{ $row->monthly_limit }} | {{ $row->yearly_limit }} | {{ $money($row->current_balance) }} | {{ $money($row->blocked_amount) }} | {{ $money($row->daily_available) }} | {{ $row->clearing_days !== null ? number_format((float) $row->clearing_days, 2) : '' }} | {{ $row->raise_target }} | {{ $row->raise_status }} | {{ $row->raise_actions }} | {{ $row->done_actions }} | {{ $row->next_action }} | {{ $row->remark }} | {{ $row->owner }} |
没有匹配的账户数据。 | ||||||||||||||||||||||||||||||||||||||
没有匹配的账户数据。 | ||||||||||||||||||||||||||||||||||||||