fix(order): 수주 API 500 에러 수정

- show(): clients 테이블 컬럼명 수정 (business_no,representative → contact_person)
- store/update/createFromQuote(): order_items에 tenant_id, serial_no 필드 추가
- index(): quote eager loading 추가

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-12 16:14:09 +09:00
parent f59dd1b9fb
commit 3a40db9444

View File

@@ -29,7 +29,7 @@ public function index(array $params)
$query = Order::query()
->where('tenant_id', $tenantId)
->with(['client:id,name', 'items']);
->with(['client:id,name', 'items', 'quote:id,quote_number']);
// 검색어 (수주번호, 현장명, 거래처명)
if ($q !== '') {
@@ -108,7 +108,7 @@ public function show(int $id)
$order = Order::where('tenant_id', $tenantId)
->with([
'client:id,name,business_no,representative,phone,email',
'client:id,name,contact_person,phone,email',
'items' => fn ($q) => $q->orderBy('sort_order'),
'quote:id,quote_number,site_name',
])
@@ -147,6 +147,8 @@ public function store(array $data)
// 품목 저장
foreach ($items as $index => $item) {
$item['tenant_id'] = $tenantId;
$item['serial_no'] = $index + 1; // 1부터 시작하는 순번
$item['sort_order'] = $index;
$this->calculateItemAmounts($item);
$order->items()->create($item);
@@ -178,7 +180,7 @@ public function update(int $id, array $data)
throw new BadRequestHttpException(__('error.order.cannot_update_completed'));
}
return DB::transaction(function () use ($order, $data, $userId) {
return DB::transaction(function () use ($order, $data, $tenantId, $userId) {
$data['updated_by'] = $userId;
$items = $data['items'] ?? null;
@@ -190,6 +192,8 @@ public function update(int $id, array $data)
if ($items !== null) {
$order->items()->delete();
foreach ($items as $index => $item) {
$item['tenant_id'] = $tenantId;
$item['serial_no'] = $index + 1; // 1부터 시작하는 순번
$item['sort_order'] = $index;
$this->calculateItemAmounts($item);
$order->items()->create($item);
@@ -370,6 +374,8 @@ public function createFromQuote(int $quoteId, array $data = [])
// 견적 품목을 수주 품목으로 변환
foreach ($quote->items as $index => $quoteItem) {
$order->items()->create([
'tenant_id' => $tenantId,
'serial_no' => $index + 1, // 1부터 시작하는 순번
'item_id' => $quoteItem->item_id,
'item_name' => $quoteItem->item_name,
'specification' => $quoteItem->specification,