fix: 补齐OA其他租赁科目映射 #828

Merged
yueyang merged 1 commits from fix/yueyang-oa-other-lease-mapping into main 2026-11-02 17:38:12 +08:00
3 changed files with 90 additions and 3 deletions

View File

@ -0,0 +1,74 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
private function connection(): string
{
return (string) config('upstream_mirrors.connection', 'business_mirror');
}
public function up(): void
{
if (app()->environment('testing')
|| (string) config('system_database.mode', 'bootstrap') === 'bootstrap') {
return;
}
$schema = Schema::connection($this->connection());
if (! $schema->hasTable('oa_process_account_mapping')) {
return;
}
$mapping = json_decode(
(string) file_get_contents(base_path('resources/data/oa_process_account_mapping.json')),
true,
512,
JSON_THROW_ON_ERROR,
);
$codes = array_column($mapping, 'account_code');
if ($mapping === [] || count($codes) !== count(array_unique($codes))) {
throw new \RuntimeException('流程科目映射快照为空或科目编码重复。');
}
$database = $schema->getConnection();
$now = now();
foreach (array_chunk($mapping, 100) as $chunk) {
$database->table('oa_process_account_mapping')->upsert(
array_map(static fn (array $row): array => [
'account_code' => (string) $row['account_code'],
'account_name' => (string) $row['account_name'],
'expense_category' => (string) $row['expense_category'],
'second_level' => $row['second_level']
?? ((string) $row['expense_category'] . '(未细分)'),
'third_level' => $row['third_level'] ?? '未细分',
'in_fee_ratio' => (bool) $row['in_fee_ratio'],
'allocation' => $row['allocation'] ?? null,
'created_at' => $now,
'updated_at' => $now,
], $chunk),
['account_code'],
[
'account_name',
'expense_category',
'second_level',
'third_level',
'in_fee_ratio',
'allocation',
'updated_at',
],
);
}
$database->table('oa_process_account_mapping')
->whereNotIn('account_code', $codes)
->delete();
}
public function down(): void
{
// 已确认的业务映射在回滚时保留。
}
};

View File

@ -1948,5 +1948,15 @@
"in_fee_ratio": false,
"allocation": "分摊",
"source_row": 196
},
{
"account_code": "1123.09.99",
"account_name": "预付账款_租赁费_其他租赁",
"expense_category": "摊销",
"second_level": "摊销",
"third_level": "租赁",
"in_fee_ratio": false,
"allocation": "分摊",
"source_row": 197
}
]

View File

@ -233,10 +233,10 @@ class ManagementExpensesPageDataTest extends TestCase
JSON_THROW_ON_ERROR,
);
$this->assertCount(195, $mapping);
$this->assertCount(195, array_unique(array_column($mapping, 'account_code')));
$this->assertCount(196, $mapping);
$this->assertCount(196, array_unique(array_column($mapping, 'account_code')));
$this->assertSame(37, count(array_filter($mapping, static fn (array $row): bool => $row['in_fee_ratio'])));
$this->assertSame(127, count(array_filter($mapping, static fn (array $row): bool => $row['allocation'] !== null)));
$this->assertSame(128, count(array_filter($mapping, static fn (array $row): bool => $row['allocation'] !== null)));
$mappingByCode = array_column($mapping, null, 'account_code');
$this->assertSame('往来', $mappingByCode['2202.01']['expense_category']);
$this->assertSame('往来', $mappingByCode['2202.01']['second_level']);
@ -248,6 +248,9 @@ class ManagementExpensesPageDataTest extends TestCase
$this->assertTrue($mappingByCode['5601.11.01']['in_fee_ratio']);
$this->assertSame('销售费用', $mappingByCode['1221.07']['expense_category']);
$this->assertSame('推广费用', $mappingByCode['1221.07']['second_level']);
$this->assertSame('摊销', $mappingByCode['1123.09.99']['expense_category']);
$this->assertSame('摊销', $mappingByCode['1123.09.99']['second_level']);
$this->assertSame('租赁', $mappingByCode['1123.09.99']['third_level']);
$this->assertSame('空包费', $mappingByCode['1221.07']['third_level']);
$this->assertTrue($mappingByCode['1221.07']['in_fee_ratio']);
$this->assertSame('管理费用', $mappingByCode['5602.11.03.19']['expense_category']);