From f5b60aab384e5e2ef2985214628b72620d7a33db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Thu, 12 Mar 2026 14:00:49 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[QMS]=20=EB=A1=9C=ED=8A=B8=EC=8B=AC?= =?UTF-8?q?=EC=82=AC=20=EC=84=9C=EB=A5=98=20=EB=AA=A9=EB=A1=9D=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 작업일지/중간검사: 인식 가능한 공정만 표시, 공정별 그룹핑 - 중간검사 detail: PQC Inspection 대신 WorkOrder 기반으로 변경 - 문서 아이템 표시 개선 (공정명, 작업지시번호, 문서번호 추가) - 루트 정보에 거래처(client) 필드 추가 - location에 document 관계 eager loading 추가 Co-Authored-By: Claude Opus 4.6 --- app/Services/QmsLotAuditService.php | 39 ++++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/app/Services/QmsLotAuditService.php b/app/Services/QmsLotAuditService.php index 951be48..c776b01 100644 --- a/app/Services/QmsLotAuditService.php +++ b/app/Services/QmsLotAuditService.php @@ -82,13 +82,14 @@ public function show(int $id): array } /** - * 수주 루트별 8종 서류 목록 (Document[]) + * 수주 로트별 8종 서류 목록 (Document[]) */ public function routeDocuments(int $qualityDocumentOrderId): array { $docOrder = QualityDocumentOrder::with([ 'order.workOrders.process', 'locations.orderItem', + 'locations.document', 'qualityDocument', ])->findOrFail($qualityDocumentOrderId); @@ -118,20 +119,15 @@ public function routeDocuments(int $qualityDocumentOrderId): array // 2. 수주서 $documents[] = $this->formatDocument('order', '수주서', collect([$order])); - // 3. 작업일지 (공정별 1개씩 — 같은 공정의 WO는 그룹핑) - $workOrdersByProcess = $workOrders->groupBy('process_id')->map(fn ($group) => $group->first()); - $documents[] = $this->formatDocumentWithSubType('log', '작업일지', $workOrdersByProcess); + // 3. 작업일지 & 4. 중간검사 성적서 (인식 가능한 공정만 — 공정별 1개씩) + $recognizedWorkOrders = $workOrders->filter(function ($wo) { + $subType = $this->mapProcessToSubType($wo->process?->process_name); - // 4. 중간검사 성적서 (PQC — 공정별 1개씩) - $pqcInspections = Inspection::where('inspection_type', 'PQC') - ->whereIn('work_order_id', $workOrders->pluck('id')) - ->with('workOrder.process') - ->get(); + return $subType !== null; + })->groupBy('process_id')->map(fn ($group) => $group->first()); - // 공정별 그룹핑 (같은 공정의 PQC는 최신 1개만) - $pqcByProcess = $pqcInspections->groupBy(fn ($insp) => $insp->workOrder?->process_id) - ->map(fn ($group) => $group->sortByDesc('inspection_date')->first()); - $documents[] = $this->formatDocumentWithSubType('report', '중간검사 성적서', $pqcByProcess, 'workOrder'); + $documents[] = $this->formatDocumentWithSubType('log', '작업일지', $recognizedWorkOrders); + $documents[] = $this->formatDocumentWithSubType('report', '중간검사 성적서', $recognizedWorkOrders); // 5. 납품확인서 $shipments = $order->shipments()->get(); @@ -161,7 +157,7 @@ public function documentDetail(string $type, int $id): array 'import' => $this->getInspectionDetail($id, 'IQC'), 'order' => $this->getOrderDetail($id), 'log' => $this->getWorkOrderLogDetail($id), - 'report' => $this->getInspectionDetail($id, 'PQC'), + 'report' => $this->getWorkOrderLogDetail($id), 'confirmation', 'shipping' => $this->getShipmentDetail($id), 'product' => $this->getLocationDetail($id), 'quality' => $this->getQualityDocDetail($id), @@ -240,6 +236,7 @@ private function transformRouteToFrontend(QualityDocumentOrder $docOrder, Qualit 'id' => (string) $docOrder->id, 'code' => $docOrder->order->order_no, 'date' => $docOrder->order->received_at?->toDateString(), + 'client' => $docOrder->order->client_name ?? '', 'site' => $docOrder->order->site_name ?? '', 'location_count' => $docOrder->locations->count(), 'sub_items' => $docOrder->locations->values()->map(fn ($loc, $idx) => [ @@ -317,12 +314,18 @@ private function formatDocumentWithSubType(string $type, string $title, $collect private function formatDocumentItem(string $type, $item): array { return match ($type) { - 'import', 'report' => [ + 'import' => [ 'id' => (string) $item->id, 'title' => $item->inspection_no ?? '', 'date' => $item->inspection_date?->toDateString() ?? $item->request_date?->toDateString() ?? '', 'code' => $item->inspection_no ?? '', ], + 'report' => [ + 'id' => (string) $item->id, + 'title' => $item->process?->process_name ?? '중간검사 성적서', + 'date' => $item->created_at?->toDateString() ?? '', + 'code' => $item->work_order_no ?? '', + ], 'order' => [ 'id' => (string) $item->id, 'title' => $item->order_no, @@ -331,9 +334,9 @@ private function formatDocumentItem(string $type, $item): array ], 'log' => [ 'id' => (string) $item->id, - 'title' => $item->project_name ?? '작업일지', + 'title' => $item->process?->process_name ?? '작업일지', 'date' => $item->created_at?->toDateString() ?? '', - 'code' => $item->id, + 'code' => $item->work_order_no ?? '', ], 'confirmation', 'shipping' => [ 'id' => (string) $item->id, @@ -345,7 +348,7 @@ private function formatDocumentItem(string $type, $item): array 'id' => (string) $item->id, 'title' => trim(($item->orderItem?->floor_code ?? '').' '.($item->orderItem?->symbol_code ?? '')) ?: '제품검사 성적서', 'date' => $item->updated_at?->toDateString() ?? '', - 'code' => '', + 'code' => $item->document?->document_no ?? '', ], 'quality' => [ 'id' => (string) $item->id,