diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-11-20 10:25:41 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-11-20 10:25:41 +0000 |
| commit | b75b1cd920efd61923f7b2dbc4c49987b7b0c4e1 (patch) | |
| tree | 9e4195e697df6df21b5896b0d33acc97d698b4a7 /lib/bidding/pre-quote/service.ts | |
| parent | 4df8d72b79140919c14df103b45bbc8b1afa37c2 (diff) | |
(최겸) 구매 입찰 수정
Diffstat (limited to 'lib/bidding/pre-quote/service.ts')
| -rw-r--r-- | lib/bidding/pre-quote/service.ts | 78 |
1 files changed, 54 insertions, 24 deletions
diff --git a/lib/bidding/pre-quote/service.ts b/lib/bidding/pre-quote/service.ts index 19b418ae..81daf506 100644 --- a/lib/bidding/pre-quote/service.ts +++ b/lib/bidding/pre-quote/service.ts @@ -1,7 +1,7 @@ 'use server'
import db from '@/db/db'
-import { biddingCompanies, companyConditionResponses, biddings, prItemsForBidding, biddingDocuments, companyPrItemBids, priceAdjustmentForms } from '@/db/schema/bidding'
+import { biddingCompanies, biddingCompaniesContacts, companyConditionResponses, biddings, prItemsForBidding, biddingDocuments, companyPrItemBids, priceAdjustmentForms } from '@/db/schema/bidding'
import { basicContractTemplates } from '@/db/schema'
import { vendors } from '@/db/schema/vendors'
import { users } from '@/db/schema'
@@ -1565,10 +1565,11 @@ export async function getExistingBasicContractsForBidding(biddingId: number) { }
}
-// 선정된 업체들 조회 (서버 액션)
+// 입찰 참여 업체들 조회 (벤더와 담당자 정보 포함)
export async function getSelectedVendorsForBidding(biddingId: number) {
try {
- const selectedCompanies = await db
+ // 1. 입찰에 참여하는 모든 업체 조회
+ const companies = await db
.select({
id: biddingCompanies.id,
companyId: biddingCompanies.companyId,
@@ -1579,37 +1580,66 @@ export async function getSelectedVendorsForBidding(biddingId: number) { contactPerson: biddingCompanies.contactPerson,
contactEmail: biddingCompanies.contactEmail,
biddingId: biddingCompanies.biddingId,
+ isPreQuoteSelected: biddingCompanies.isPreQuoteSelected,
})
.from(biddingCompanies)
.leftJoin(vendors, eq(biddingCompanies.companyId, vendors.id))
- .where(and(
- eq(biddingCompanies.biddingId, biddingId),
- eq(biddingCompanies.isPreQuoteSelected, true)
- ))
+ .where(eq(biddingCompanies.biddingId, biddingId))
+
+ // 2. 각 업체의 담당자 정보 조회
+ const vendorsWithContacts = await Promise.all(
+ companies.map(async (company) => {
+ let contacts: any[] = []
+
+ if (company.companyId) {
+ // biddingCompaniesContacts에서 담당자 조회
+ const contactsResult = await db
+ .select({
+ id: biddingCompaniesContacts.id,
+ contactName: biddingCompaniesContacts.contactName,
+ contactEmail: biddingCompaniesContacts.contactEmail,
+ contactNumber: biddingCompaniesContacts.contactNumber,
+ })
+ .from(biddingCompaniesContacts)
+ .where(
+ and(
+ eq(biddingCompaniesContacts.biddingId, biddingId),
+ eq(biddingCompaniesContacts.vendorId, company.companyId)
+ )
+ )
+
+ contacts = contactsResult
+ }
+
+ return {
+ vendorId: company.companyId,
+ vendorName: company.companyName || '',
+ vendorCode: company.companyCode,
+ vendorEmail: company.companyEmail,
+ vendorCountry: company.companyCountry || '대한민국',
+ contactPerson: company.contactPerson,
+ contactEmail: company.contactEmail,
+ biddingCompanyId: company.id,
+ biddingId: company.biddingId,
+ isPreQuoteSelected: company.isPreQuoteSelected,
+ ndaYn: true,
+ generalGtcYn: true,
+ projectGtcYn: true,
+ agreementYn: true,
+ contacts: contacts // 담당자 목록 추가
+ }
+ })
+ )
return {
success: true,
- vendors: selectedCompanies.map(company => ({
- vendorId: company.companyId, // 실제 vendor ID
- vendorName: company.companyName || '',
- vendorCode: company.companyCode,
- vendorEmail: company.companyEmail,
- vendorCountry: company.companyCountry || '대한민국',
- contactPerson: company.contactPerson,
- contactEmail: company.contactEmail,
- biddingCompanyId: company.id, // biddingCompany ID
- biddingId: company.biddingId,
- ndaYn: true, // 모든 계약 타입을 활성화 (필요에 따라 조정)
- generalGtcYn: true,
- projectGtcYn: true,
- agreementYn: true
- }))
+ vendors: vendorsWithContacts
}
} catch (error) {
- console.error('선정된 업체 조회 실패:', error)
+ console.error('입찰 참여 업체 조회 실패:', error)
return {
success: false,
- error: '선정된 업체 조회에 실패했습니다.',
+ error: '입찰 참여 업체 조회에 실패했습니다.',
vendors: []
}
}
|
