diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-09-24 07:56:53 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-09-24 07:56:53 +0000 |
| commit | ee52c983423fbc63373ce1dacb041d973da502df (patch) | |
| tree | 344bf92c9cef02c9843484235a067e5697bdf39e /lib/bidding/detail/service.ts | |
| parent | 3cde5c2c7d157bb0fe353de5e67e4b35506bb4e2 (diff) | |
(최겸) 구매 입찰 발주비율 로직 수정(이시원 프로)
Diffstat (limited to 'lib/bidding/detail/service.ts')
| -rw-r--r-- | lib/bidding/detail/service.ts | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/bidding/detail/service.ts b/lib/bidding/detail/service.ts index 9fb3d87f..645ebeac 100644 --- a/lib/bidding/detail/service.ts +++ b/lib/bidding/detail/service.ts @@ -1158,6 +1158,23 @@ export async function deleteAwardDocument(documentId: number, biddingId: number, export async function awardBidding(biddingId: number, selectionReason: string, userId: string) { try { const userName = await getUserNameById(userId) + + // 입찰 정보 조회 (contractType 포함) + const biddingInfo = await db + .select({ + contractType: biddings.contractType, + status: biddings.status + }) + .from(biddings) + .where(eq(biddings.id, biddingId)) + .limit(1) + + if (biddingInfo.length === 0) { + return { success: false, error: '입찰 정보를 찾을 수 없습니다.' } + } + + const bidding = biddingInfo[0] + // 낙찰된 업체들 조회 (isWinner가 true인 업체들) const awardedCompanies = await db .select({ @@ -1170,11 +1187,22 @@ export async function awardBidding(biddingId: number, selectionReason: string, u eq(biddingCompanies.biddingId, biddingId), eq(biddingCompanies.isWinner, true) )) - + if (awardedCompanies.length === 0) { return { success: false, error: '낙찰된 업체가 없습니다. 먼저 발주비율을 산정해주세요.' } } + // 일반/매각 입찰의 경우 비율 합계 100% 검증 + const contractType = bidding.contractType + if (contractType === 'general' || contractType === 'sale') { + const totalRatio = awardedCompanies.reduce((sum, company) => + sum + (Number(company.awardRatio) || 0), 0) + + if (totalRatio !== 100) { + return { success: false, error: `일반/매각 입찰의 경우 비율 합계가 100%여야 합니다. 현재 합계: ${totalRatio}%` } + } + } + // 최종입찰가 계산 (낙찰된 업체의 견적금액 * 발주비율의 합) let finalBidPrice = 0 for (const company of awardedCompanies) { |
