diff options
Diffstat (limited to 'lib/soap/ecc')
| -rw-r--r-- | lib/soap/ecc/mapper/rfq-and-pr-mapper.ts | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/lib/soap/ecc/mapper/rfq-and-pr-mapper.ts b/lib/soap/ecc/mapper/rfq-and-pr-mapper.ts index a517d84c..620cd141 100644 --- a/lib/soap/ecc/mapper/rfq-and-pr-mapper.ts +++ b/lib/soap/ecc/mapper/rfq-and-pr-mapper.ts @@ -151,25 +151,37 @@ export async function mapECCRfqHeaderToRfqLast( const inChargeUserInfo = await findUserInfoByEKGRP(eccHeader.EKGRP || null); const inChargeUserId = inChargeUserInfo?.userId || null; - // 첫번째 PR Item 기반으로 projectId, itemCode, itemName 설정 + // 대표 PR Item 기반으로 projectId, itemCode, itemName 설정 (없으면 첫번째 PR Item 사용) let projectId: number | null = null; let itemCode: string | null = null; let itemName: string | null = null; let prNumber: string | null = null; - + let representativeItem: ECCBidItem | undefined; + if (firstItem) { - // projectId: 첫번째 PR Item의 PSPID와 projects.code 매칭 - const projectInfo = await findProjectInfoByPSPID(firstItem.PSPID || null); + // 대표 PR Item 찾기 (ZCON_NO_PO와 BANFN이 같은 아이템) + representativeItem = eccItems.find(item => + item.ANFNR === eccHeader.ANFNR && + item.ZCON_NO_PO && + item.ZCON_NO_PO.trim() && + item.BANFN === item.ZCON_NO_PO.trim() + ); + + // 대표 PR Item이 없으면 첫번째 PR Item 사용 + const targetItem = representativeItem || firstItem; + + // projectId: 대표 PR Item의 PSPID와 projects.code 매칭 + const projectInfo = await findProjectInfoByPSPID(targetItem.PSPID || null); projectId = projectInfo?.id || null; - - // itemCode: 첫번째 PR Item의 MATKL - itemCode = firstItem.MATKL || null; - - // itemName: 첫번째 PR Item의 MATNR로 MDG에서 ZZNAME 조회 - itemName = await findMaterialNameByMATNR(firstItem.MATNR || null); - - // prNumber: 첫번째 PR의 ZREQ_FN 값 - prNumber = firstItem.ZREQ_FN || null; + + // itemCode: 대표 PR Item의 MATNR + itemCode = targetItem.MATNR || null; + + // itemName: 대표 PR Item의 MATNR로 MDG에서 ZZNAME 조회 + itemName = await findMaterialNameByMATNR(targetItem.MATNR || null); + + // prNumber: 대표 PR의 BANFN 또는 첫번째 PR의 ZREQ_FN 값 + prNumber = representativeItem?.BANFN || firstItem.ZREQ_FN || null; } // 매핑 |
