summaryrefslogtreecommitdiff
path: root/lib/bidding/detail
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-11-28 03:12:57 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-11-28 03:12:57 +0000
commit9cda8482660a87fd98c9ee43f507d75ff75b4e23 (patch)
tree67eb1fc24eec7c4e61d3154f7b09fc5349454672 /lib/bidding/detail
parentf57898bd240d068301ce3ef477f52cff1234e4ee (diff)
(최겸) 구매 입찰 피드백 반영(90%)
Diffstat (limited to 'lib/bidding/detail')
-rw-r--r--lib/bidding/detail/service.ts76
1 files changed, 75 insertions, 1 deletions
diff --git a/lib/bidding/detail/service.ts b/lib/bidding/detail/service.ts
index 0b68eaa7..e425959c 100644
--- a/lib/bidding/detail/service.ts
+++ b/lib/bidding/detail/service.ts
@@ -3,7 +3,7 @@
import db from '@/db/db'
import { biddings, prItemsForBidding, biddingDocuments, biddingCompanies, vendors, companyPrItemBids, companyConditionResponses, vendorSelectionResults, priceAdjustmentForms, users, vendorContacts } from '@/db/schema'
import { specificationMeetings, biddingCompaniesContacts } from '@/db/schema/bidding'
-import { eq, and, sql, desc, ne } from 'drizzle-orm'
+import { eq, and, sql, desc, ne, asc } from 'drizzle-orm'
import { revalidatePath, revalidateTag } from 'next/cache'
import { unstable_cache } from "@/lib/unstable-cache";
import { sendEmail } from '@/lib/mail/sendEmail'
@@ -207,6 +207,80 @@ export async function getBiddingCompaniesData(biddingId: number) {
}
}
+// 입찰 접수 화면용: 모든 초대된 협력사 조회 (필터링 없음, contact 정보 포함)
+export async function getAllBiddingCompanies(biddingId: number) {
+ try {
+ // 1. 기본 협력사 정보 조회
+ const companies = await db
+ .select({
+ id: biddingCompanies.id,
+ biddingId: biddingCompanies.biddingId,
+ companyId: biddingCompanies.companyId,
+ vendorName: vendors.vendorName,
+ vendorCode: vendors.vendorCode,
+ invitationStatus: biddingCompanies.invitationStatus,
+ invitedAt: biddingCompanies.invitedAt,
+ respondedAt: biddingCompanies.respondedAt,
+ preQuoteAmount: biddingCompanies.preQuoteAmount,
+ preQuoteSubmittedAt: biddingCompanies.preQuoteSubmittedAt,
+ isPreQuoteSelected: biddingCompanies.isPreQuoteSelected,
+ finalQuoteAmount: biddingCompanies.finalQuoteAmount,
+ finalQuoteSubmittedAt: biddingCompanies.finalQuoteSubmittedAt,
+ isWinner: biddingCompanies.isWinner,
+ notes: biddingCompanies.notes,
+ createdAt: biddingCompanies.createdAt,
+ updatedAt: biddingCompanies.updatedAt
+ })
+ .from(biddingCompanies)
+ .leftJoin(vendors, eq(biddingCompanies.companyId, vendors.id))
+ .where(eq(biddingCompanies.biddingId, biddingId))
+ .orderBy(biddingCompanies.invitedAt)
+
+ // 2. 각 협력사의 첫 번째 contact 정보 조회
+ const companiesWithContacts = await Promise.all(
+ companies.map(async (company) => {
+ if (!company.companyId) {
+ return {
+ ...company,
+ contactPerson: null,
+ contactEmail: null,
+ contactPhone: null
+ }
+ }
+
+ // biddingCompaniesContacts에서 첫 번째 contact 조회
+ const [firstContact] = await db
+ .select({
+ contactName: biddingCompaniesContacts.contactName,
+ contactEmail: biddingCompaniesContacts.contactEmail,
+ contactNumber: biddingCompaniesContacts.contactNumber,
+ })
+ .from(biddingCompaniesContacts)
+ .where(
+ and(
+ eq(biddingCompaniesContacts.biddingId, biddingId),
+ eq(biddingCompaniesContacts.vendorId, company.companyId)
+ )
+ )
+ .orderBy(asc(biddingCompaniesContacts.id))
+ .limit(1)
+
+ return {
+ ...company,
+ contactPerson: firstContact?.contactName || null,
+ contactEmail: firstContact?.contactEmail || null,
+ contactPhone: firstContact?.contactNumber || null
+ }
+ })
+ )
+
+ return companiesWithContacts
+ } catch (error) {
+ console.error('Failed to get all bidding companies:', error)
+ return []
+ }
+}
+
// prItemsForBidding 테이블에서 품목 정보 조회 (캐시 미적용, always fresh)
export async function getPRItemsForBidding(biddingId: number) {
try {