diff options
Diffstat (limited to 'lib/vendors')
| -rw-r--r-- | lib/vendors/service.ts | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/lib/vendors/service.ts b/lib/vendors/service.ts index 2328752b..853b3701 100644 --- a/lib/vendors/service.ts +++ b/lib/vendors/service.ts @@ -2584,4 +2584,125 @@ export async function searchVendors(searchTerm: string = "", limit: number = 100 console.error("벤더 검색 오류:", error); return []; } +} + +/** + * 벤더 기본정보 조회 (Basic Info 페이지용) + * vendorsWithTypesView를 사용하여 기본 정보 + contacts + attachments 조회 + */ +export async function getVendorBasicInfo(vendorId: number) { + unstable_noStore(); + + try { + return await db.transaction(async (tx) => { + // 1. 기본 벤더 정보 조회 (vendorsWithTypesView 사용) + const vendor = await tx + .select() + .from(vendorsWithTypesView) + .where(eq(vendorsWithTypesView.id, vendorId)) + .limit(1) + .then(rows => rows[0] || null); + + if (!vendor) { + return null; + } + + // 2. 연락처 정보 조회 + const contacts = await tx + .select() + .from(vendorContacts) + .where(eq(vendorContacts.vendorId, vendorId)) + .orderBy(desc(vendorContacts.isPrimary), asc(vendorContacts.contactName)); + + // 3. 첨부파일 정보 조회 + const attachments = await tx + .select() + .from(vendorAttachments) + .where(eq(vendorAttachments.vendorId, vendorId)) + .orderBy(asc(vendorAttachments.createdAt)); + + // 4. 타입 변환하여 반환 (추후 확장 가능하도록 구조화) + return { + // 기본 벤더 정보 + id: vendor.id, + vendorName: vendor.vendorName, + vendorCode: vendor.vendorCode, + taxId: vendor.taxId, + address: vendor.address, + businessSize: vendor.businessSize || "", // vendorsWithTypesView에 businessSize 필드가 없을 경우 대비 + country: vendor.country, + phone: vendor.phone, + fax: vendor.fax || null, // vendorsWithTypesView에 fax 필드가 없을 경우 대비 + email: vendor.email, + website: vendor.website, + status: vendor.status, + representativeName: vendor.representativeName, + representativeBirth: vendor.representativeBirth, + representativeEmail: vendor.representativeEmail, + representativePhone: vendor.representativePhone, + representativeWorkExperience: vendor.representativeWorkExperience ?? false, // vendorsWithTypesView에 해당 필드가 없을 경우 false로 기본값 + corporateRegistrationNumber: vendor.corporateRegistrationNumber, + creditAgency: vendor.creditAgency, + creditRating: vendor.creditRating, + cashFlowRating: vendor.cashFlowRating, + createdAt: vendor.createdAt, + updatedAt: vendor.updatedAt, + + // 연락처 정보 + contacts: contacts.map(contact => ({ + id: contact.id, + contactName: contact.contactName, + contactPosition: contact.contactPosition, + contactEmail: contact.contactEmail, + contactPhone: contact.contactPhone, + isPrimary: contact.isPrimary, + })), + + // 첨부파일 정보 + attachments: attachments.map(attachment => ({ + id: attachment.id, + fileName: attachment.fileName, + filePath: attachment.filePath, + attachmentType: attachment.attachmentType, + createdAt: attachment.createdAt, + })), + + // 추가 정보는 임시로 null (나중에 실제 데이터로 교체) + additionalInfo: { + businessType: vendor.vendorTypeId ? `Type ${vendor.vendorTypeId}` : null, + employeeCount: 0, // 실제 데이터가 있을 수 있으므로 유지 + mainBusiness: null, + }, + + // 매출 정보 (구현 예정 - 나중에 실제 테이블 연결) + salesInfo: null, // 구현 시 { "2023": { totalSales: "1000", totalDebt: "500", ... }, "2022": { ... } } 형태로 연도별 키 사용 + + // 추가 정보들 (구현 예정 - 나중에 실제 테이블 연결) + organization: null, + + factoryInfo: null, + + inspectionInfo: null, + + evaluationInfo: null, + + classificationInfo: { + vendorClassification: null, + groupCompany: null, + preferredLanguage: "한국어", // 기본값으로 유지 + industryType: "제조업", // 기본값으로 유지 + isoCertification: null, + }, + + contractDetails: null, + + capacityInfo: null, + + calculatedMetrics: null, // 구현 시 { "20231231": { debtRatio: 0, ... }, "20221231": { ... } } 형태로 YYYYMMDD 키 사용 + }; + }); + } catch (error) { + console.error("Error fetching vendor basic info:", error); + return null; + } }
\ No newline at end of file |
