diff --git a/app/Services/OrderService.php b/app/Services/OrderService.php index c3df77a..3138d18 100644 --- a/app/Services/OrderService.php +++ b/app/Services/OrderService.php @@ -1346,6 +1346,21 @@ public function createProductionOrder(int $orderId, array $data) } } + // team_id 결정: 명시적 전달값 > 공정 담당부서 자동 매핑 + $teamId = $data['team_id'] ?? null; + if (! $teamId && $process && $process->department) { + $teamId = DB::table('departments') + ->where('tenant_id', $tenantId) + ->where('name', $process->department) + ->value('id'); + } + + // priority 결정: 문자열 → 숫자 변환 (urgent=1, high=4, normal=7) + $priorityMap = ['urgent' => 1, 'high' => 4, 'normal' => 7]; + $priority = is_numeric($data['priority'] ?? null) + ? (int) $data['priority'] + : ($priorityMap[$data['priority'] ?? 'normal'] ?? 7); + // 작업지시 생성 $workOrder = WorkOrder::create([ 'tenant_id' => $tenantId, @@ -1353,9 +1368,10 @@ public function createProductionOrder(int $orderId, array $data) 'sales_order_id' => $order->id, 'project_name' => $order->site_name ?? $order->client_name, 'process_id' => $processId, - 'status' => ! empty($assigneeIds) ? WorkOrder::STATUS_PENDING : WorkOrder::STATUS_UNASSIGNED, + 'status' => (! empty($assigneeIds) || $teamId) ? WorkOrder::STATUS_WAITING : WorkOrder::STATUS_UNASSIGNED, + 'priority' => $priority, 'assignee_id' => $primaryAssigneeId, - 'team_id' => $data['team_id'] ?? null, + 'team_id' => $teamId, 'scheduled_date' => $data['scheduled_date'] ?? $order->delivery_date, 'memo' => $data['memo'] ?? null, 'options' => $workOrderOptions,