diff options
Diffstat (limited to 'lib/bidding/approval-actions.ts')
| -rw-r--r-- | lib/bidding/approval-actions.ts | 67 |
1 files changed, 58 insertions, 9 deletions
diff --git a/lib/bidding/approval-actions.ts b/lib/bidding/approval-actions.ts index 9a37d83b..06f5c206 100644 --- a/lib/bidding/approval-actions.ts +++ b/lib/bidding/approval-actions.ts @@ -188,7 +188,7 @@ export async function requestBiddingInvitationWithApproval(data: { .update(biddings) .set({ status: 'approval_pending', // 결재 진행중 상태 - updatedBy: data.currentUser.epId, + updatedBy: Number(data.currentUser.epId), updatedAt: new Date() }) .where(eq(biddings.id, data.biddingId)); @@ -269,13 +269,20 @@ export async function prepareBiddingClosureApprovalData(data: { // 1. 입찰 정보 조회 (템플릿 변수용) debugLog('[BiddingClosureApproval] 입찰 정보 조회 시작'); const { default: db } = await import('@/db/db'); - const { biddings } = await import('@/db/schema'); + const { biddings, prItemsForBidding, biddingCompanies, vendors } = await import('@/db/schema'); const { eq } = await import('drizzle-orm'); const biddingInfo = await db .select({ id: biddings.id, title: biddings.title, + biddingNumber: biddings.biddingNumber, + projectName: biddings.projectName, + itemName: biddings.itemName, + biddingType: biddings.biddingType, + bidPicName: biddings.bidPicName, + supplyPicName: biddings.supplyPicName, + targetPrice: biddings.targetPrice, }) .from(biddings) .where(eq(biddings.id, data.biddingId)) @@ -286,9 +293,41 @@ export async function prepareBiddingClosureApprovalData(data: { throw new Error('입찰 정보를 찾을 수 없습니다'); } + const bidding = biddingInfo[0]; + + // 입찰 대상 자재 정보 조회 + const biddingItemsInfo = await db + .select({ + id: prItemsForBidding.id, + materialCode: prItemsForBidding.materialNumber, + materialCodeName: prItemsForBidding.materialInfo, + quantity: prItemsForBidding.quantity, + quantityUnit: prItemsForBidding.quantityUnit, + targetUnitPrice: prItemsForBidding.targetUnitPrice, + currency: prItemsForBidding.targetCurrency, + }) + .from(prItemsForBidding) + .where(eq(prItemsForBidding.biddingId, data.biddingId)); + + // 입찰 참여 업체 정보 조회 + const vendorSubmissions = await db + .select({ + vendorId: vendors.id, + vendorName: vendors.vendorName, + vendorCode: vendors.vendorCode, + finalQuoteAmount: biddingCompanies.finalQuoteAmount, + submitted: biddingCompanies.isBiddingParticipated, + targetPrice: biddingCompanies.preQuoteAmount, // 사전견적 금액을 내정가로 사용 + }) + .from(biddingCompanies) + .leftJoin(vendors, eq(biddingCompanies.companyId, vendors.id)) + .where(eq(biddingCompanies.biddingId, data.biddingId)); + debugLog('[BiddingClosureApproval] 입찰 정보 조회 완료', { biddingId: data.biddingId, - title: biddingInfo[0].title, + title: bidding.title, + itemCount: biddingItemsInfo.length, + vendorCount: vendorSubmissions.length, }); // 2. 템플릿 변수 매핑 @@ -296,7 +335,9 @@ export async function prepareBiddingClosureApprovalData(data: { const requestedAt = new Date(); const { mapBiddingClosureToTemplateVariables } = await import('./handlers'); const variables = await mapBiddingClosureToTemplateVariables({ - biddingId: data.biddingId, + bidding, + biddingItems: biddingItemsInfo, + vendorSubmissions, description: data.description, requestedAt, }); @@ -305,7 +346,8 @@ export async function prepareBiddingClosureApprovalData(data: { }); return { - bidding: biddingInfo[0], + bidding, + biddingItems: biddingItemsInfo, variables, }; } @@ -341,12 +383,19 @@ export async function requestBiddingClosureWithApproval(data: { const { eq } = await import('drizzle-orm'); // 유찰상태인지 확인 - const { bidding } = await db + const biddingResult = await db .select() .from(biddings) .where(eq(biddings.id, data.biddingId)) .limit(1); + if (biddingResult.length === 0) { + debugError('[BiddingClosureApproval] 입찰 정보를 찾을 수 없음'); + throw new Error('입찰 정보를 찾을 수 없습니다'); + } + + const bidding = biddingResult[0]; + if (bidding.status !== 'bidding_disposal') { debugError('[BiddingClosureApproval] 유찰 상태가 아닙니다.'); throw new Error('유찰 상태인 입찰만 폐찰할 수 있습니다.'); @@ -359,7 +408,7 @@ export async function requestBiddingClosureWithApproval(data: { .update(biddings) .set({ status: 'approval_pending', // 폐찰 결재 진행중 상태 - updatedBy: data.currentUser.epId, + updatedBy: Number(data.currentUser.id), updatedAt: new Date() }) .where(eq(biddings.id, data.biddingId)); @@ -370,7 +419,7 @@ export async function requestBiddingClosureWithApproval(data: { }); // 3. 결재 데이터 준비 - const { bidding: approvalBidding, variables } = await prepareBiddingClosureApprovalData({ + const { bidding: approvalBidding, biddingItems, variables } = await prepareBiddingClosureApprovalData({ biddingId: data.biddingId, description: data.description, }); @@ -514,7 +563,7 @@ export async function requestBiddingAwardWithApproval(data: { .update(biddings) .set({ status: 'approval_pending', // 낙찰 결재 진행중 상태 - updatedBy: data.currentUser.epId, + updatedBy: Number(data.currentUser.id), updatedAt: new Date() }) .where(eq(biddings.id, data.biddingId)); |
