summaryrefslogtreecommitdiff
path: root/lib/bidding/service.ts
diff options
context:
space:
mode:
authorjoonhoekim <26rote@gmail.com>2025-11-24 20:16:56 +0900
committerjoonhoekim <26rote@gmail.com>2025-11-24 20:16:56 +0900
commit6bc4162b19f06ad4f919270ebcd4ef18f31cd490 (patch)
treebe37a152174789d269ef718c2a1f3794531e1c37 /lib/bidding/service.ts
parent775997501ef36bf07d7f1f2e1d4abe7c97505e96 (diff)
parenta8674e6b91fb4d356c311fad0251878de154da53 (diff)
(김준회) 최겸프로 작업사항 병합
Diffstat (limited to 'lib/bidding/service.ts')
-rw-r--r--lib/bidding/service.ts69
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) {