diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-11-24 11:16:32 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-11-24 11:16:32 +0000 |
| commit | a8674e6b91fb4d356c311fad0251878de154da53 (patch) | |
| tree | 8bdf91ef99b2628f319df37912ccede1e2f5009c /lib/bidding/service.ts | |
| parent | 68160eba15a2c8408329b6e14b94d5e44fa7e3ab (diff) | |
(최겸) 구매 입찰 수정(폐찰, 낙찰 결재 기능 추가 등)
Diffstat (limited to 'lib/bidding/service.ts')
| -rw-r--r-- | lib/bidding/service.ts | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/lib/bidding/service.ts b/lib/bidding/service.ts index 0261ad57..fe37eaea 100644 --- a/lib/bidding/service.ts +++ b/lib/bidding/service.ts @@ -2363,7 +2363,7 @@ export async function updateBiddingSchedule( .insert(specificationMeetings) .values({ biddingId, - meetingDate: specificationMeeting.meetingDate, + meetingDate: parseDate(specificationMeeting.meetingDate), meetingTime: specificationMeeting.meetingTime || null, location: specificationMeeting.location, address: specificationMeeting.address || null, @@ -2545,6 +2545,39 @@ export async function removeBiddingItem(itemId: number) { } } +// 입찰의 PR 아이템 금액 합산하여 bidding 업데이트 +async function updateBiddingAmounts(biddingId: number) { + try { + // 해당 bidding의 모든 PR 아이템들의 금액 합계 계산 + const amounts = await db + .select({ + totalTargetAmount: sql<number>`COALESCE(SUM(${prItemsForBidding.targetAmount}), 0)`, + totalBudgetAmount: sql<number>`COALESCE(SUM(${prItemsForBidding.budgetAmount}), 0)`, + totalActualAmount: sql<number>`COALESCE(SUM(${prItemsForBidding.actualAmount}), 0)` + }) + .from(prItemsForBidding) + .where(eq(prItemsForBidding.biddingId, biddingId)) + + const { totalTargetAmount, totalBudgetAmount, totalActualAmount } = amounts[0] + + // bidding 테이블 업데이트 + await db + .update(biddings) + .set({ + targetPrice: totalTargetAmount, + budget: totalBudgetAmount, + finalBidPrice: totalActualAmount, + updatedAt: new Date() + }) + .where(eq(biddings.id, biddingId)) + + console.log(`Bidding ${biddingId} amounts updated: target=${totalTargetAmount}, budget=${totalBudgetAmount}, actual=${totalActualAmount}`) + } catch (error) { + console.error('Failed to update bidding amounts:', error) + throw error + } +} + // PR 아이템 추가 (전체 필드 지원) export async function addPRItemForBidding( biddingId: number, @@ -2620,6 +2653,9 @@ export async function addPRItemForBidding( hasSpecDocument: item.hasSpecDocument || false, }).returning() + // PR 아이템 금액 합산하여 bidding 업데이트 + await updateBiddingAmounts(biddingId) + revalidatePath(`/evcp/bid/${biddingId}/info`) revalidatePath(`/evcp/bid/${biddingId}`) @@ -2653,6 +2689,7 @@ export async function getBiddingVendors(biddingId: number) { currency: sql<string>`'KRW'`, invitationStatus: biddingCompanies.invitationStatus, isPriceAdjustmentApplicableQuestion: biddingCompanies.isPriceAdjustmentApplicableQuestion, + businessSize: vendors.businessSize, }) .from(biddingCompanies) .leftJoin(vendors, eq(biddingCompanies.companyId, vendors.id)) @@ -3223,7 +3260,7 @@ export async function searchVendorsForBidding(searchTerm: string = "", biddingId ) ) .orderBy(asc(vendorsWithTypesView.vendorName)); - + return result; } catch (error) { @@ -3232,6 +3269,34 @@ export async function searchVendorsForBidding(searchTerm: string = "", biddingId } } +// 선택된 vendor들의 businessSize 정보를 가져오는 함수 +export async function getVendorsBusinessSize(vendorIds: number[]) { + try { + if (vendorIds.length === 0) { + return {}; + } + + const result = await db + .select({ + id: vendors.id, + businessSize: vendors.businessSize, + }) + .from(vendors) + .where(inArray(vendors.id, vendorIds)); + + // Map 형태로 변환하여 반환 + const businessSizeMap: Record<number, string | null> = {}; + result.forEach(vendor => { + businessSizeMap[vendor.id] = vendor.businessSize; + }); + + return businessSizeMap; + } catch (error) { + console.error('Error getting vendors business size:', error); + return {}; + } +} + // 차수증가 또는 재입찰 함수 export async function increaseRoundOrRebid(biddingId: number, userId: string | undefined, type: 'round_increase' | 'rebidding') { if (!userId) { |
