diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-06-25 05:00:10 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-06-25 05:00:10 +0000 |
| commit | ca6545ad76c548a3202e0deee1e2b1dde51bc413 (patch) | |
| tree | e18ed085c205b602d228b52a289487bea716f442 /lib/techsales-rfq/service.ts | |
| parent | 6824e097d768f724cf439b410ccfb1ab9685ac98 (diff) | |
(최겸) 기술영업 rfq 수정(리비전 오류 및 첨부파일 오류 수정)+스키마 일부 변경
Diffstat (limited to 'lib/techsales-rfq/service.ts')
| -rw-r--r-- | lib/techsales-rfq/service.ts | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/lib/techsales-rfq/service.ts b/lib/techsales-rfq/service.ts index 25e1f379..ffa29acd 100644 --- a/lib/techsales-rfq/service.ts +++ b/lib/techsales-rfq/service.ts @@ -955,27 +955,32 @@ export async function submitTechSalesVendorQuotation(data: { // }); // } - // 항상 revision 저장 (변경사항 여부와 관계없이) - await tx.insert(techSalesVendorQuotationRevisions).values({ - quotationId: data.id, - version: currentQuotation.quotationVersion || 1, - snapshot: { - currency: currentQuotation.currency, - totalPrice: currentQuotation.totalPrice, - validUntil: currentQuotation.validUntil, - remark: currentQuotation.remark, - status: currentQuotation.status, - quotationVersion: currentQuotation.quotationVersion, - submittedAt: currentQuotation.submittedAt, - acceptedAt: currentQuotation.acceptedAt, - updatedAt: currentQuotation.updatedAt, - }, - changeReason: "견적서 제출", - revisedBy: data.updatedBy, - }); + // 첫 제출인지 확인 (quotationVersion이 null인 경우) + const isFirstSubmission = currentQuotation.quotationVersion === null; + + // 첫 제출이 아닌 경우에만 revision 저장 (변경사항 이력 관리) + if (!isFirstSubmission) { + await tx.insert(techSalesVendorQuotationRevisions).values({ + quotationId: data.id, + version: currentQuotation.quotationVersion || 1, + snapshot: { + currency: currentQuotation.currency, + totalPrice: currentQuotation.totalPrice, + validUntil: currentQuotation.validUntil, + remark: currentQuotation.remark, + status: currentQuotation.status, + quotationVersion: currentQuotation.quotationVersion, + submittedAt: currentQuotation.submittedAt, + acceptedAt: currentQuotation.acceptedAt, + updatedAt: currentQuotation.updatedAt, + }, + changeReason: "견적서 제출", + revisedBy: data.updatedBy, + }); + } - // 새로운 버전 번호 계산 (항상 1 증가) - const newRevisionId = (currentQuotation.quotationVersion || 1) + 1; + // 새로운 버전 번호 계산 (첫 제출은 1, 재제출은 1 증가) + const newRevisionId = isFirstSubmission ? 1 : (currentQuotation.quotationVersion || 1) + 1; // 새로운 버전으로 업데이트 const result = await tx @@ -1177,7 +1182,7 @@ export async function getVendorQuotations(input: { }); } - // 조인을 포함한 데이터 조회 + // 조인을 포함한 데이터 조회 (중복 제거를 위해 techSalesAttachments JOIN 제거) const data = await db .select({ id: techSalesVendorQuotations.id, @@ -1211,16 +1216,16 @@ export async function getVendorQuotations(input: { FROM tech_sales_rfq_items WHERE tech_sales_rfq_items.rfq_id = ${techSalesRfqs.id} )`, - // RFQ 첨부파일 개수 + // RFQ 첨부파일 개수 (RFQ_COMMON 타입만 카운트) attachmentCount: sql<number>`( SELECT COUNT(*) FROM tech_sales_attachments WHERE tech_sales_attachments.tech_sales_rfq_id = ${techSalesRfqs.id} + AND tech_sales_attachments.attachment_type = 'RFQ_COMMON' )`, }) .from(techSalesVendorQuotations) .leftJoin(techSalesRfqs, eq(techSalesVendorQuotations.rfqId, techSalesRfqs.id)) - .leftJoin(techSalesAttachments, eq(techSalesRfqs.id, techSalesAttachments.techSalesRfqId)) .leftJoin(biddingProjects, eq(techSalesRfqs.biddingProjectId, biddingProjects.id)) .where(finalWhere) .orderBy(...orderBy) @@ -2727,12 +2732,14 @@ export async function addTechVendorsToTechSalesRfq(input: { } // 🔥 중요: 벤더 추가 시에는 견적서를 생성하지 않고, "Assigned" 상태로만 생성 + // quotation_version은 null로 설정하여 벤더가 실제 견적 제출 시에만 리비전 생성 const [quotation] = await tx .insert(techSalesVendorQuotations) .values({ rfqId: input.rfqId, vendorId: vendorId, status: "Assigned", // Draft가 아닌 Assigned 상태로 생성 + quotationVersion: null, // 리비전은 견적 제출 시에만 생성 createdBy: input.createdBy, updatedBy: input.createdBy, }) |
