fix(WEB): 수주 등록/수정 옵션 필드 저장 및 담당자 표시 문제 해결

- FormRequest에 options 필드 validation 추가 (StoreOrderRequest, UpdateOrderRequest)
  - shipping_cost_code, receiver, receiver_contact, shipping_address 등
- OrderService.show()에서 client 로드 시 manager_name 필드 추가
- 수주확정/생산지시 되돌리기 기능 추가 (revertOrderConfirmation, revertProductionOrder)
- 견적 calculation_inputs 포함하여 로드

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-01-16 21:58:57 +09:00
parent b86397cbee
commit 090c07605e
14 changed files with 262 additions and 9 deletions

View File

@@ -118,9 +118,9 @@ public function show(int $id)
$order = Order::where('tenant_id', $tenantId)
->with([
'client:id,name,contact_person,phone,email',
'client:id,name,contact_person,phone,email,manager_name',
'items' => fn ($q) => $q->orderBy('sort_order'),
'quote:id,quote_number,site_name',
'quote:id,quote_number,site_name,calculation_inputs',
])
->find($id);
@@ -518,4 +518,101 @@ private function generateWorkOrderNo(int $tenantId): string
return sprintf('%s%s%04d', $prefix, $date, $seq);
}
/**
* 수주확정 되돌리기 (수주등록 상태로 변경)
*/
public function revertOrderConfirmation(int $orderId): array
{
$tenantId = $this->tenantId();
$userId = $this->apiUserId();
// 수주 조회
$order = Order::where('tenant_id', $tenantId)
->find($orderId);
if (! $order) {
throw new NotFoundHttpException(__('error.not_found'));
}
// 수주확정 상태에서만 되돌리기 가능
if ($order->status_code !== Order::STATUS_CONFIRMED) {
throw new BadRequestHttpException(__('error.order.cannot_revert_not_confirmed'));
}
// 상태 변경
$previousStatus = $order->status_code;
$order->status_code = Order::STATUS_DRAFT;
$order->updated_by = $userId;
$order->save();
return [
'order' => $order->load(['client:id,name', 'items']),
'previous_status' => $previousStatus,
];
}
/**
* 생산지시 되돌리기 (작업지시 및 관련 데이터 삭제)
*/
public function revertProductionOrder(int $orderId): array
{
$tenantId = $this->tenantId();
$userId = $this->apiUserId();
// 수주 조회
$order = Order::where('tenant_id', $tenantId)
->find($orderId);
if (! $order) {
throw new NotFoundHttpException(__('error.not_found'));
}
// 완료된 수주는 되돌리기 불가
if ($order->status_code === Order::STATUS_COMPLETED) {
throw new BadRequestHttpException(__('error.order.cannot_revert_completed'));
}
return DB::transaction(function () use ($order, $tenantId, $userId) {
// 관련 작업지시 ID 조회
$workOrderIds = WorkOrder::where('tenant_id', $tenantId)
->where('sales_order_id', $order->id)
->pluck('id')
->toArray();
$deletedCounts = [
'work_results' => 0,
'work_order_items' => 0,
'work_orders' => 0,
];
if (count($workOrderIds) > 0) {
// 1. 작업결과 삭제
$deletedCounts['work_results'] = DB::table('work_results')
->whereIn('work_order_id', $workOrderIds)
->delete();
// 2. 작업지시 품목 삭제
$deletedCounts['work_order_items'] = DB::table('work_order_items')
->whereIn('work_order_id', $workOrderIds)
->delete();
// 3. 작업지시 삭제
$deletedCounts['work_orders'] = WorkOrder::whereIn('id', $workOrderIds)
->delete();
}
// 4. 수주 상태를 CONFIRMED로 되돌리기
$previousStatus = $order->status_code;
$order->status_code = Order::STATUS_CONFIRMED;
$order->updated_by = $userId;
$order->save();
return [
'order' => $order->load(['client:id,name', 'items']),
'deleted_counts' => $deletedCounts,
'previous_status' => $previousStatus,
];
});
}
}