fix: [생산지시] 보조공정 품목 미배정 문제 수정
- 부자재(감기샤프트, 각파이프 등)가 "재고생산"(보조공정) 매핑으로 미배정 생성되던 문제 - 보조공정(is_auxiliary) 및 미매핑(none) 품목을 메인 공정으로 자동 병합 - 메인 공정 중 품목 수가 가장 많은 공정에 배정
This commit is contained in:
@@ -1533,6 +1533,35 @@ public function createProductionOrder(int $orderId, array $data)
|
||||
}
|
||||
$itemsByProcess[$key]['items'][] = $orderItem;
|
||||
}
|
||||
|
||||
// 보조 공정(재고생산 등) 품목을 메인 공정으로 병합
|
||||
$auxiliaryProcessIds = \App\Models\Process::where('tenant_id', $tenantId)
|
||||
->where('is_active', true)
|
||||
->get()
|
||||
->filter(fn ($p) => ! empty($p->options['is_auxiliary']))
|
||||
->pluck('id')
|
||||
->all();
|
||||
|
||||
$auxiliaryKeys = [];
|
||||
$mainKeys = [];
|
||||
foreach ($itemsByProcess as $key => $group) {
|
||||
if ($key === 'none' || in_array($group['process_id'], $auxiliaryProcessIds, true)) {
|
||||
$auxiliaryKeys[] = $key;
|
||||
} else {
|
||||
$mainKeys[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($auxiliaryKeys) && ! empty($mainKeys)) {
|
||||
// 메인 공정 중 품목 수가 가장 많은 공정에 병합
|
||||
$targetKey = collect($mainKeys)->sortByDesc(fn ($k) => count($itemsByProcess[$k]['items']))->first();
|
||||
foreach ($auxiliaryKeys as $auxKey) {
|
||||
foreach ($itemsByProcess[$auxKey]['items'] as $item) {
|
||||
$itemsByProcess[$targetKey]['items'][] = $item;
|
||||
}
|
||||
unset($itemsByProcess[$auxKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($order, $data, $tenantId, $userId, $itemsByProcess, $nodesBomMap, $isStock) {
|
||||
|
||||
Reference in New Issue
Block a user