feat(API): 작업지시 공정 연동 개선
- WorkOrder 모델에 process_id 추가 - process 관계 추가 (Process 모델) - 공정별 다중 작업지시 생성 지원 - WorkOrderStoreRequest/UpdateRequest 수정 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -398,7 +398,7 @@ public function createFromQuote(int $quoteId, array $data = [])
|
||||
}
|
||||
|
||||
/**
|
||||
* 생산지시 생성
|
||||
* 생산지시 생성 (공정별 작업지시 다중 생성)
|
||||
*/
|
||||
public function createProductionOrder(int $orderId, array $data)
|
||||
{
|
||||
@@ -428,26 +428,43 @@ public function createProductionOrder(int $orderId, array $data)
|
||||
throw new BadRequestHttpException(__('error.order.production_order_already_exists'));
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($order, $data, $tenantId, $userId) {
|
||||
// 작업지시번호 생성
|
||||
$workOrderNo = $this->generateWorkOrderNo($tenantId);
|
||||
// process_ids 배열 또는 단일 process_id 처리
|
||||
$processIds = $data['process_ids'] ?? [];
|
||||
if (empty($processIds) && ! empty($data['process_id'])) {
|
||||
$processIds = [$data['process_id']];
|
||||
}
|
||||
|
||||
// 작업지시 생성
|
||||
$workOrder = WorkOrder::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'work_order_no' => $workOrderNo,
|
||||
'sales_order_id' => $order->id,
|
||||
'project_name' => $order->site_name ?? $order->client_name,
|
||||
'process_type' => $data['process_type'] ?? WorkOrder::PROCESS_SCREEN,
|
||||
'status' => WorkOrder::STATUS_PENDING,
|
||||
'assignee_id' => $data['assignee_id'] ?? null,
|
||||
'team_id' => $data['team_id'] ?? null,
|
||||
'scheduled_date' => $data['scheduled_date'] ?? $order->delivery_date,
|
||||
'memo' => $data['memo'] ?? null,
|
||||
'is_active' => true,
|
||||
'created_by' => $userId,
|
||||
'updated_by' => $userId,
|
||||
]);
|
||||
// 공정이 없으면 null로 하나만 생성
|
||||
if (empty($processIds)) {
|
||||
$processIds = [null];
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($order, $data, $tenantId, $userId, $processIds) {
|
||||
$workOrders = [];
|
||||
|
||||
foreach ($processIds as $processId) {
|
||||
// 작업지시번호 생성
|
||||
$workOrderNo = $this->generateWorkOrderNo($tenantId);
|
||||
|
||||
// 작업지시 생성
|
||||
$workOrder = WorkOrder::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'work_order_no' => $workOrderNo,
|
||||
'sales_order_id' => $order->id,
|
||||
'project_name' => $order->site_name ?? $order->client_name,
|
||||
'process_id' => $processId,
|
||||
'status' => WorkOrder::STATUS_PENDING,
|
||||
'assignee_id' => $data['assignee_id'] ?? null,
|
||||
'team_id' => $data['team_id'] ?? null,
|
||||
'scheduled_date' => $data['scheduled_date'] ?? $order->delivery_date,
|
||||
'memo' => $data['memo'] ?? null,
|
||||
'is_active' => true,
|
||||
'created_by' => $userId,
|
||||
'updated_by' => $userId,
|
||||
]);
|
||||
|
||||
$workOrders[] = $workOrder->load(['assignee:id,name', 'team:id,name', 'process:id,process_name,process_code']);
|
||||
}
|
||||
|
||||
// 수주 상태를 IN_PROGRESS로 변경
|
||||
$order->status_code = Order::STATUS_IN_PROGRESS;
|
||||
@@ -455,7 +472,8 @@ public function createProductionOrder(int $orderId, array $data)
|
||||
$order->save();
|
||||
|
||||
return [
|
||||
'work_order' => $workOrder->load(['assignee:id,name', 'team:id,name']),
|
||||
'work_orders' => $workOrders,
|
||||
'work_order' => $workOrders[0] ?? null, // 하위 호환성
|
||||
'order' => $order->load(['client:id,name', 'items']),
|
||||
];
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user