diff options
Diffstat (limited to 'lib/bidding/pre-quote/service.ts')
| -rw-r--r-- | lib/bidding/pre-quote/service.ts | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/lib/bidding/pre-quote/service.ts b/lib/bidding/pre-quote/service.ts index 7f0a9083..b5b06769 100644 --- a/lib/bidding/pre-quote/service.ts +++ b/lib/bidding/pre-quote/service.ts @@ -127,6 +127,33 @@ export async function updateBiddingCompany(id: number, input: UpdateBiddingCompa } } +// 본입찰 등록 상태 업데이트 (복수 업체 선택 가능) +export async function updatePreQuoteSelection(companyIds: number[], isSelected: boolean, userId: string) { + try { + await db.update(biddingCompanies) + .set({ + isPreQuoteSelected: isSelected, + updatedAt: new Date() + }) + .where(inArray(biddingCompanies.id, companyIds)) + + const message = isSelected + ? `${companyIds.length}개 업체가 본입찰 대상으로 선정되었습니다.` + : `${companyIds.length}개 업체의 본입찰 선정이 취소되었습니다.` + + return { + success: true, + message + } + } catch (error) { + console.error('Failed to update pre-quote selection:', error) + return { + success: false, + error: error instanceof Error ? error.message : '본입찰 선정 상태 업데이트에 실패했습니다.' + } + } +} + // 사전견적용 업체 삭제 export async function deleteBiddingCompany(id: number) { try { @@ -302,6 +329,17 @@ export async function sendPreQuoteInvitations(companyIds: number[]) { } } } + // 3. 입찰 상태를 사전견적 요청으로 변경 (bidding_generated 상태에서만) + await tx + .update(biddings) + .set({ + status: 'request_for_quotation', + updatedAt: new Date() + }) + .where(and( + eq(biddings.id, biddingId), + eq(biddings.status, 'bidding_generated') + )) return { success: true, @@ -556,6 +594,28 @@ export async function submitPreQuoteResponse( await tx.insert(priceAdjustmentForms).values(priceAdjustmentData) } } + + // 5. 입찰 상태를 사전견적 접수로 변경 (request_for_quotation 상태에서만) + // 또한 사전견적 접수일 업데이트 + const biddingCompany = await tx + .select({ biddingId: biddingCompanies.biddingId }) + .from(biddingCompanies) + .where(eq(biddingCompanies.id, biddingCompanyId)) + .limit(1) + + if (biddingCompany.length > 0) { + await tx + .update(biddings) + .set({ + status: 'received_quotation', + preQuoteReceivedAt: new Date(), // 사전견적 접수일 업데이트 + updatedAt: new Date() + }) + .where(and( + eq(biddings.id, biddingCompany[0].biddingId), + eq(biddings.status, 'request_for_quotation') + )) + } }) return { @@ -648,6 +708,8 @@ export async function getPrItemsForBidding(biddingId: number) { materialDescription: prItemsForBidding.materialDescription, quantity: prItemsForBidding.quantity, quantityUnit: prItemsForBidding.quantityUnit, + totalWeight: prItemsForBidding.totalWeight, + weightUnit: prItemsForBidding.weightUnit, currency: prItemsForBidding.currency, requestedDeliveryDate: prItemsForBidding.requestedDeliveryDate, hasSpecDocument: prItemsForBidding.hasSpecDocument @@ -665,7 +727,6 @@ export async function getPrItemsForBidding(biddingId: number) { // SPEC 문서 조회 (PR 아이템에 연결된 문서들) export async function getSpecDocumentsForPrItem(prItemId: number) { try { - console.log('getSpecDocumentsForPrItem called with prItemId:', prItemId) const specDocs = await db .select({ @@ -686,7 +747,6 @@ export async function getSpecDocumentsForPrItem(prItemId: number) { ) ) - console.log('getSpecDocumentsForPrItem result:', specDocs) return specDocs } catch (error) { console.error('Failed to get spec documents for PR item:', error) |
