diff --git a/app/Services/OrderService.php b/app/Services/OrderService.php index 919395db..8d71fe81 100644 --- a/app/Services/OrderService.php +++ b/app/Services/OrderService.php @@ -1614,6 +1614,13 @@ public function createProductionOrder(int $orderId, array $data) $orderOptions['target_stock_qty'] ?? $order->quantity ?? 1 ); if ($stockBendingInfo) { + // STOCK 부품 필터 정보 추가 + $stockBendingInfo['stockPartFilter'] = collect($items)->map(function ($item) { + return [ + 'itemName' => $item->item_name, + 'partKey' => \App\Services\WorkOrderService::parseStockPartKeyStatic($item->item_name), + ]; + })->values()->toArray(); $workOrderOptions = array_merge($workOrderOptions ?? [], ['bending_info' => $stockBendingInfo]); } } @@ -2258,6 +2265,7 @@ private static function buildStockBendingInfoFromLot(array $bendingLot, int $qua 'productCode' => $productCode, 'finishMaterial' => $finishMaterial, 'common' => ['type' => $guideType], + 'isStockProduction' => true, ]; // 가이드레일 (R=벽면, S=측면) diff --git a/app/Services/WorkOrderService.php b/app/Services/WorkOrderService.php index 7f0806a5..6847ebe1 100644 --- a/app/Services/WorkOrderService.php +++ b/app/Services/WorkOrderService.php @@ -216,6 +216,17 @@ private function fillStockBendingInfo(WorkOrder $workOrder): void ); if ($stockBendingInfo) { + // work_order_items에서 부품명 추출하여 필터 정보 추가 + $items = $workOrder->items ?? collect(); + if ($items->isNotEmpty()) { + $stockBendingInfo['stockPartFilter'] = $items->map(function ($item) { + return [ + 'itemName' => $item->item_name, + 'partKey' => self::parseStockPartKey($item->item_name), + ]; + })->values()->toArray(); + } + $opts = $workOrder->options ?? []; $opts['bending_info'] = $stockBendingInfo; $workOrder->options = $opts; @@ -223,6 +234,44 @@ private function fillStockBendingInfo(WorkOrder $workOrder): void } } + /** + * STOCK 품목명에서 부품 키 추출 + * + * "가이드레일(측면) 본체(철재) 2438mm" → "본체" + * "가이드레일(측면) C형 1219mm" → "C형" + */ + public static function parseStockPartKeyStatic(string $itemName): string + { + return self::parseStockPartKey($itemName); + } + + private static function parseStockPartKey(string $itemName): string + { + // "본체", "C형", "D형", "마감재", "별도마감", "BASE" 등 추출 + $patterns = [ + '/본체/' => '본체', + '/C형/' => 'C형', + '/D형/' => 'D형', + '/별도마감/' => '별도마감', + '/마감재/' => '마감재', + '/BASE/i' => 'BASE', + '/하단마감/' => '하단마감재', + '/전면판/' => '전면판', + '/밑면판/' => '밑면판', + '/점검구/' => '점검구', + '/연기차단/' => '연기차단재', + '/케이스/' => '케이스', + ]; + + foreach ($patterns as $pattern => $key) { + if (preg_match($pattern, $itemName)) { + return $key; + } + } + + return $itemName; + } + /** * 목록 결과에서 STOCK 작업지시의 누락된 bending_info를 보충 후 DB 영구 저장 */