diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/rfq-last/contract-actions.ts | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/rfq-last/contract-actions.ts b/lib/rfq-last/contract-actions.ts index 7d1d0ddc..26b50c3c 100644 --- a/lib/rfq-last/contract-actions.ts +++ b/lib/rfq-last/contract-actions.ts @@ -4,7 +4,7 @@ import db from "@/db/db"; import { rfqsLast, rfqLastDetails,rfqPrItems, prItemsForBidding,biddingConditions,biddingCompanies, projects, biddings,generalContracts ,generalContractItems, vendors, - rfqLastVendorResponses, rfqLastVendorQuotationItems} from "@/db/schema"; + rfqLastVendorResponses, rfqLastVendorQuotationItems, incoterms} from "@/db/schema"; import { eq, and } from "drizzle-orm"; import { revalidatePath } from "next/cache"; import { getServerSession } from "next-auth/next" @@ -30,7 +30,7 @@ export async function createPO(params: CreatePOParams) { if (!session?.user) { throw new Error("인증이 필요합니다."); } - const userId = session.user.id; + const userId = Number(session.user.id); // 1. RFQ 정보 조회 const [rfqData] = await db @@ -127,10 +127,25 @@ export async function createPO(params: CreatePOParams) { } const incotermsCode = detailData.incotermsCode || ''; // 빈 값으로 기본값 설정 - if (!detailData.incotermsDetail) { + // incoterms 테이블에서 description 조회 (INCO2용) + let incotermsDescription = ''; + if (incotermsCode) { + const [incotermsData] = await db + .select({ description: incoterms.description }) + .from(incoterms) + .where(eq(incoterms.code, incotermsCode)) + .limit(1); + + if (incotermsData?.description) { + incotermsDescription = incotermsData.description; + } else { + console.warn(`⚠️ 인코텀즈 코드 '${incotermsCode}'에 대한 설명을 찾을 수 없습니다. - detailData.incotermsDetail을 사용합니다.`); + incotermsDescription = detailData.incotermsDetail || ''; + } + } else { console.warn("⚠️ 인코텀즈 상세 정보(INCO2)가 설정되지 않았습니다. - 빈 값으로 전송합니다."); + incotermsDescription = detailData.incotermsDetail || ''; } - const incotermsDetail = detailData.incotermsDetail || ''; // 빈 값으로 기본값 설정 if (!detailData.taxCode) { console.warn("⚠️ 세금코드(Tax Code)가 설정되지 않았습니다. - 빈 값으로 전송합니다."); @@ -158,7 +173,7 @@ export async function createPO(params: CreatePOParams) { WAERS: currency, ZTERM: paymentTermsCode, INCO1: incotermsCode, - INCO2: incotermsDetail.substring(0, 28), // SAP 최대 28자리 제한 + INCO2: incotermsDescription.substring(0, 28), // SAP 최대 28자리 제한, incoterms 테이블의 description 사용 MWSKZ: taxCode, LANDS: vendorCountryCode, // 벤더 국가 코드 사용 ZRCV_DT: getCurrentSAPDate(), @@ -238,7 +253,7 @@ export async function createPO(params: CreatePOParams) { totalAmount: params.totalAmount, currency: currency, taxCode: taxCode, - incoterms: `${incotermsCode} - ${incotermsDetail}`, + incoterms: `${incotermsCode} - ${incotermsDescription}`, }); // 디버깅: 전송 데이터 전체 로그 (서버 측 로그이므로 모든 정보 포함) |
