From 89dd347ff4cd60cb4308ec362f157d36d3990e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Sat, 21 Mar 2026 17:34:41 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[bending]=20STOCK=20=EC=9E=91=EC=97=85?= =?UTF-8?q?=EC=A7=80=EC=8B=9C=20bending=5Finfo=20DB=20=EC=98=81=EA=B5=AC?= =?UTF-8?q?=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - show() 동적 생성 후 saveQuietly()로 DB 영구 저장 - index() worker_screen 모드에서도 누락된 bending_info 자동 보충 - fillStockBendingInfo() 공통 메서드로 추출 - 기존 작업지시 194~196 bending_info 백필 완료 --- app/Services/WorkOrderService.php | 56 ++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/app/Services/WorkOrderService.php b/app/Services/WorkOrderService.php index ed6842e2..7f0806a5 100644 --- a/app/Services/WorkOrderService.php +++ b/app/Services/WorkOrderService.php @@ -169,6 +169,7 @@ public function index(array $params) // 작업자 화면: BENDING 카테고리 품목에 전개도 폭(bending_width) 추가 if ($workerScreen) { $this->appendBendingWidths($result); + $this->fillMissingStockBendingInfo($result); } return $result; @@ -197,6 +198,44 @@ private function appendBendingWidths($paginator): void } } + /** + * STOCK 작업지시에 bending_info가 없으면 수주의 bending_lot에서 생성 후 DB 영구 저장 + */ + private function fillStockBendingInfo(WorkOrder $workOrder): void + { + $orderOptions = $workOrder->salesOrder->options ?? []; + $bendingLot = $orderOptions['bending_lot'] ?? null; + if (! $bendingLot || ($workOrder->salesOrder->order_type_code ?? '') !== 'STOCK') { + return; + } + + $stockBendingInfo = app(\App\Services\OrderService::class) + ->buildStockBendingInfoStatic( + $bendingLot, + (int) ($orderOptions['target_stock_qty'] ?? $workOrder->salesOrder->quantity ?? 1) + ); + + if ($stockBendingInfo) { + $opts = $workOrder->options ?? []; + $opts['bending_info'] = $stockBendingInfo; + $workOrder->options = $opts; + $workOrder->saveQuietly(); + } + } + + /** + * 목록 결과에서 STOCK 작업지시의 누락된 bending_info를 보충 후 DB 영구 저장 + */ + private function fillMissingStockBendingInfo($paginator): void + { + foreach ($paginator->items() as $workOrder) { + if (! empty($workOrder->options['bending_info']) || ! $workOrder->salesOrder) { + continue; + } + $this->fillStockBendingInfo($workOrder); + } + } + /** * 통계 조회 */ @@ -273,22 +312,9 @@ public function show(int $id) throw new NotFoundHttpException(__('error.not_found')); } - // STOCK(재고생산) 작업지시: bending_info 없으면 수주의 bending_lot에서 동적 생성 + // STOCK(재고생산) 작업지시: bending_info 없으면 수주의 bending_lot에서 생성 후 DB 영구 저장 if (empty($workOrder->options['bending_info']) && $workOrder->salesOrder) { - $orderOptions = $workOrder->salesOrder->options ?? []; - $bendingLot = $orderOptions['bending_lot'] ?? null; - if ($bendingLot && ($workOrder->salesOrder->order_type_code ?? '') === 'STOCK') { - $stockBendingInfo = app(\App\Services\OrderService::class) - ->buildStockBendingInfoStatic( - $bendingLot, - (int) ($orderOptions['target_stock_qty'] ?? $workOrder->salesOrder->quantity ?? 1) - ); - if ($stockBendingInfo) { - $opts = $workOrder->options ?? []; - $opts['bending_info'] = $stockBendingInfo; - $workOrder->options = $opts; - } - } + $this->fillStockBendingInfo($workOrder); } return $workOrder;