summaryrefslogtreecommitdiff
path: root/lib/vendors
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-10-01 09:48:03 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-10-01 09:48:03 +0000
commit33e8452331c301430191b3506825ebaf3edac93a (patch)
tree6d92d754dbd30cafe0f3f920a14d6d6031c624b8 /lib/vendors
parent8ac4e8d9faa6e86ca6c7ab475efd7462d76fc9b6 (diff)
(최겸) 구매 PQ 리스트 기능 수정, 견적 첨부파일 리비전 액션 추가, 기타 등
Diffstat (limited to 'lib/vendors')
-rw-r--r--lib/vendors/service.ts40
-rw-r--r--lib/vendors/table/request-pq-dialog.tsx14
2 files changed, 40 insertions, 14 deletions
diff --git a/lib/vendors/service.ts b/lib/vendors/service.ts
index de88ae72..98c72349 100644
--- a/lib/vendors/service.ts
+++ b/lib/vendors/service.ts
@@ -2,7 +2,7 @@
import { revalidatePath, revalidateTag, unstable_noStore } from "next/cache";
import db from "@/db/db";
-import { vendorAttachments, VendorContact, vendorContacts, vendorDetailView, vendorItemsView, vendorMaterialsView, vendorPossibleItems, vendorPossibleMaterials, vendors, vendorsWithTypesView, vendorsWithTypesAndMaterialsView, vendorTypes, type Vendor } from "@/db/schema";
+import { vendorAttachments, VendorContact, vendorContacts, vendorDetailView, vendorItemsView, vendorMaterialsView, vendorPossibleItems, vendorPossibleMaterials, vendors, vendorsWithTypesView, vendorsWithTypesAndMaterialsView, vendorTypes, type Vendor, pqLists } from "@/db/schema";
import logger from '@/lib/logger';
import * as z from "zod"
import crypto from 'crypto';
@@ -2952,6 +2952,44 @@ export async function requestPQVendors(input: ApproveVendorsInput & {
}
}
+ // PQ 리스트 정보 조회 및 문항 검사
+ const pqType = input.type || "GENERAL";
+ const pqListConditions = [
+ eq(pqLists.type, pqType),
+ eq(pqLists.isDeleted, false)
+ ];
+
+ if (input.projectId) {
+ pqListConditions.push(eq(pqLists.projectId, input.projectId));
+ } else {
+ pqListConditions.push(isNull(pqLists.projectId));
+ }
+
+ const pqList = await db
+ .select()
+ .from(pqLists)
+ .where(and(...pqListConditions))
+ .limit(1)
+ .then(rows => rows[0]);
+
+ // PQ 리스트가 존재하지 않으면 요청 불가
+ if (!pqList) {
+ return {
+ success: false,
+ error: input.projectId ? "프로젝트 PQ 리스트를 찾을 수 없습니다" : "일반 PQ 리스트를 찾을 수 없습니다"
+ };
+ }
+
+ // PQ 리스트에 문항이 있는지 확인
+ const { getPqListCriteriaCount } = await import("@/lib/pq/service");
+ const criteriaCount = await getPqListCriteriaCount(pqList.id);
+ if (criteriaCount === 0) {
+ return {
+ success: false,
+ error: "PQ 리스트에 문항이 없습니다. 문항을 추가한 후 요청해주세요"
+ };
+ }
+
const result = await db.transaction(async (tx) => {
const vendorsBeforeUpdate = await tx
.select({ id: vendors.id, status: vendors.status })
diff --git a/lib/vendors/table/request-pq-dialog.tsx b/lib/vendors/table/request-pq-dialog.tsx
index fd6da145..b5e3b8a8 100644
--- a/lib/vendors/table/request-pq-dialog.tsx
+++ b/lib/vendors/table/request-pq-dialog.tsx
@@ -709,27 +709,15 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro
date={dueDate ? new Date(dueDate) : undefined}
onSelect={(date?: Date) => {
if (date) {
- // 현재 날짜 기준으로 이전 날짜는 선택 불가능
- const today = new Date()
- today.setHours(0, 0, 0, 0) // 오늘 날짜의 시작 시간으로 설정
-
- const selectedDate = new Date(date)
- selectedDate.setHours(0, 0, 0, 0) // 선택된 날짜의 시작 시간으로 설정
-
- if (selectedDate < today) {
- toast.error("마감일은 오늘 날짜 이후로 선택해주세요.")
- return
- } else {
-
// 한국 시간대로 날짜 변환 (UTC 변환으로 인한 날짜 변경 방지)
const kstDate = new Date(date.getTime() - date.getTimezoneOffset() * 60000)
setDueDate(kstDate.toISOString().slice(0, 10))
- }
} else {
setDueDate("")
}
}}
placeholder="마감일 선택"
+ minDate={new Date()}
/>
</div>