fix : BOM구성 API - 자재 정보 오류 수정

This commit is contained in:
2025-08-29 17:33:35 +09:00
parent 622c4905fa
commit 41d0afa245

View File

@@ -58,9 +58,17 @@ protected function resolveNodeInfo(string $refType, int $refId): array
$p = Product::query()
->where('tenant_id', $this->tenantId)
->find($refId, ['id','code','name','product_type','category_id']);
if (!$p) return ['id'=>$refId, 'code'=>null, 'name'=>null, 'product_type'=>null, 'category_id'=>null];
if (!$p) {
return [
'id' => $refId,
'code' => null,
'name' => null,
'product_type' => null,
'category_id' => null,
];
}
return [
'id' => $p->id,
'id' => (int) $p->id,
'code' => $p->code,
'name' => $p->name,
'product_type' => $p->product_type,
@@ -68,16 +76,51 @@ protected function resolveNodeInfo(string $refType, int $refId): array
];
}
// MATERIAL 등 다른 타입은 여기서 분기 추가
// if ($refType === 'MATERIAL') {
// $m = DB::table('materials')
// ->where('tenant_id', $this->tenantId)
// ->where('id', $refId)
// ->first(['id','code','name','unit']);
// return $m ? ['id'=>$m->id,'code'=>$m->code,'name'=>$m->name,'unit'=>$m->unit] : ['id'=>$refId,'code'=>null,'name'=>null];
// }
// MATERIAL 분기: materials 테이블 스키마 반영
if ($refType === 'MATERIAL') {
$m = DB::table('materials')
->where('tenant_id', $this->tenantId)
->where('id', $refId)
->whereNull('deleted_at') // 소프트 삭제 고려
->first([
'id',
'material_code', // 코드
'item_name', // 표시명(있으면 우선)
'name', // fallback 표시명
'specification', // 규격
'unit',
'category_id',
]);
return ['id'=>$refId, 'code'=>null, 'name'=>null];
if (!$m) {
return [
'id' => (int) $refId,
'code' => null,
'name' => null,
'unit' => null,
'category_id' => null,
];
}
// item_name 우선, 없으면 name 사용
$displayName = $m->item_name ?: $m->name;
return [
'id' => (int) $m->id,
'code' => $m->material_code, // 표준 코드 필드
'name' => $displayName, // 사용자에게 보일 이름
'unit' => $m->unit,
'spec' => $m->specification, // 있으면 프론트에서 활용 가능
'category_id' => $m->category_id,
];
}
// 알 수 없는 타입 폴백
return [
'id' => $refId,
'code' => null,
'name' => null,
];
}
/**