diff options
Diffstat (limited to 'lib/rfq-last/service.ts')
| -rw-r--r-- | lib/rfq-last/service.ts | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/lib/rfq-last/service.ts b/lib/rfq-last/service.ts index 461a635a..65ead12b 100644 --- a/lib/rfq-last/service.ts +++ b/lib/rfq-last/service.ts @@ -3,7 +3,7 @@ import { revalidatePath, unstable_cache, unstable_noStore } from "next/cache"; import db from "@/db/db"; -import { avlVendorInfo, paymentTerms, incoterms, rfqLastVendorQuotationItems, rfqLastVendorAttachments, rfqLastVendorResponses, RfqsLastView, rfqLastAttachmentRevisions, rfqLastAttachments, rfqsLast, rfqsLastView, users, rfqPrItems, prItemsLastView, vendors, rfqLastDetails, rfqLastVendorResponseHistory, rfqLastDetailsView, vendorContacts, projects, basicContract, basicContractTemplates, rfqLastTbeSessions, rfqLastTbeDocumentReviews, templateDetailView, RfqStatus, purchaseRequests } from "@/db/schema"; +import { avlVendorInfo, paymentTerms, incoterms, rfqLastVendorQuotationItems, rfqLastVendorAttachments, rfqLastVendorResponses, RfqsLastView, rfqLastAttachmentRevisions, rfqLastAttachments, rfqsLast, rfqsLastView, users, rfqPrItems, prItemsLastView, vendors, rfqLastDetails, rfqLastVendorResponseHistory, rfqLastDetailsView, vendorContacts, projects, basicContract, basicContractTemplates, rfqLastTbeSessions, rfqLastTbeDocumentReviews, templateDetailView, RfqStatus, rfqLastPriceAdjustmentForms } from "@/db/schema"; import { sql, and, desc, asc, like, ilike, or, eq, SQL, count, gte, lte, isNotNull, ne, inArray } from "drizzle-orm"; import { filterColumns } from "@/lib/filter-columns"; import { GetRfqLastAttachmentsSchema, GetRfqsSchema } from "./validations"; @@ -1851,13 +1851,41 @@ export async function getRfqVendorResponses(rfqId: number) { .where(eq(rfqLastVendorAttachments.vendorResponseId, response.id)) .orderBy(rfqLastVendorAttachments.attachmentType, rfqLastVendorAttachments.uploadedAt); + // 연동제 폼 조회 + const priceAdjustmentForm = await db + .select({ + id: rfqLastPriceAdjustmentForms.id, + rfqLastVendorResponsesId: rfqLastPriceAdjustmentForms.rfqLastVendorResponsesId, + itemName: rfqLastPriceAdjustmentForms.itemName, + adjustmentReflectionPoint: rfqLastPriceAdjustmentForms.adjustmentReflectionPoint, + majorApplicableRawMaterial: rfqLastPriceAdjustmentForms.majorApplicableRawMaterial, + adjustmentFormula: rfqLastPriceAdjustmentForms.adjustmentFormula, + rawMaterialPriceIndex: rfqLastPriceAdjustmentForms.rawMaterialPriceIndex, + referenceDate: rfqLastPriceAdjustmentForms.referenceDate, + comparisonDate: rfqLastPriceAdjustmentForms.comparisonDate, + adjustmentRatio: rfqLastPriceAdjustmentForms.adjustmentRatio, + notes: rfqLastPriceAdjustmentForms.notes, + adjustmentConditions: rfqLastPriceAdjustmentForms.adjustmentConditions, + majorNonApplicableRawMaterial: rfqLastPriceAdjustmentForms.majorNonApplicableRawMaterial, + adjustmentPeriod: rfqLastPriceAdjustmentForms.adjustmentPeriod, + contractorWriter: rfqLastPriceAdjustmentForms.contractorWriter, + adjustmentDate: rfqLastPriceAdjustmentForms.adjustmentDate, + nonApplicableReason: rfqLastPriceAdjustmentForms.nonApplicableReason, + createdAt: rfqLastPriceAdjustmentForms.createdAt, + updatedAt: rfqLastPriceAdjustmentForms.updatedAt, + }) + .from(rfqLastPriceAdjustmentForms) + .where(eq(rfqLastPriceAdjustmentForms.rfqLastVendorResponsesId, response.id)) + .limit(1); + // 해당 벤더의 총 응답 수 가져오기 const vendorResponseCount = responseCountMap.get(response.vendorId) || 0; return { ...response, - quotationItems, - attachments, + quotationItems: quotationItems || [], + attachments: attachments || [], + priceAdjustmentForm: priceAdjustmentForm && priceAdjustmentForm.length > 0 ? priceAdjustmentForm[0] : null, vendorResponseCount, }; }) @@ -1933,6 +1961,7 @@ export async function getRfqVendorResponses(rfqId: number) { materialPriceRelated: { required: response.vendorMaterialPriceRelatedYn, reason: response.vendorMaterialPriceRelatedReason, + priceAdjustmentForm: response.priceAdjustmentForm || null, }, }, @@ -1958,8 +1987,11 @@ export async function getRfqVendorResponses(rfqId: number) { technical: response.technicalProposal, }, + // 연동제 폼 정보 (최상위 레벨에 추가) + priceAdjustmentForm: response.priceAdjustmentForm || null, + // 견적 아이템 상세 - quotationItems: response.quotationItems.map(item => ({ + quotationItems: (response.quotationItems || []).map(item => ({ id: item.id, rfqPrItemId: item.rfqPrItemId, prNo: item.prNo, @@ -1984,7 +2016,7 @@ export async function getRfqVendorResponses(rfqId: number) { })), // 첨부파일 상세 - attachments: response.attachments.map(file => ({ + attachments: (response.attachments || []).map(file => ({ id: file.id, attachmentType: file.attachmentType, documentNo: file.documentNo, |
