Files
sam-api/database/seeders/ItemTypeSeeder.php
hskwon 33010f1916 feat: ItemTypeSeeder에 attributes.source_table 매핑 추가
- common_codes 테이블 item_type 그룹에 source_table 매핑 추가
- FG/PT → products, SM/RM/CS → materials 테이블 매핑
- attributes JSON에 name_en 영문명 추가
2025-12-09 20:27:30 +09:00

96 lines
3.0 KiB
PHP

<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class ItemTypeSeeder extends Seeder
{
/**
* Run the database seeds.
* common_codes 테이블에 item_type 그룹 데이터 시딩
*
* attributes.source_table: 실제 저장 테이블 매핑
* - FG, PT → products 테이블
* - SM, RM, CS → materials 테이블
*/
public function run(): void
{
$tenantId = 1; // 기본 테넌트
// code_group = 'item_type' (컬럼명과 동일하게!)
// attributes.source_table로 물리 테이블 매핑
$itemTypes = [
[
'code_group' => 'item_type',
'code' => 'FG',
'name' => '완제품',
'tenant_id' => $tenantId,
'attributes' => json_encode([
'source_table' => 'products',
'name_en' => 'Finished Goods',
]),
],
[
'code_group' => 'item_type',
'code' => 'PT',
'name' => '부품',
'tenant_id' => $tenantId,
'attributes' => json_encode([
'source_table' => 'products',
'name_en' => 'Parts',
]),
],
[
'code_group' => 'item_type',
'code' => 'SM',
'name' => '부자재',
'tenant_id' => $tenantId,
'attributes' => json_encode([
'source_table' => 'materials',
'name_en' => 'Sub-Materials',
]),
],
[
'code_group' => 'item_type',
'code' => 'RM',
'name' => '원자재',
'tenant_id' => $tenantId,
'attributes' => json_encode([
'source_table' => 'materials',
'name_en' => 'Raw Materials',
]),
],
[
'code_group' => 'item_type',
'code' => 'CS',
'name' => '소모품',
'tenant_id' => $tenantId,
'attributes' => json_encode([
'source_table' => 'materials',
'name_en' => 'Consumables',
]),
],
];
foreach ($itemTypes as $index => $item) {
DB::table('common_codes')->updateOrInsert(
[
'code_group' => $item['code_group'],
'code' => $item['code'],
'tenant_id' => $item['tenant_id'],
],
array_merge($item, [
'sort_order' => $index + 1,
'is_active' => true,
'created_at' => now(),
'updated_at' => now(),
])
);
}
$this->command->info('ItemTypeSeeder: '.count($itemTypes).'개 item_type 코드가 시딩되었습니다.');
}
}