summaryrefslogtreecommitdiff
path: root/lib/vendors/table
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-11-11 09:22:58 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-11-11 09:22:58 +0000
commit535de26b9cf3242c04543d6891d78352b9593a60 (patch)
treecfb2a76a3442ad0ec1d2b2b75293658d93a45808 /lib/vendors/table
parent88b737a71372353e47c466553273d88f5bf36834 (diff)
(최겸) 구매 수정사항 개발
Diffstat (limited to 'lib/vendors/table')
-rw-r--r--lib/vendors/table/request-pq-dialog.tsx67
1 files changed, 56 insertions, 11 deletions
diff --git a/lib/vendors/table/request-pq-dialog.tsx b/lib/vendors/table/request-pq-dialog.tsx
index 07057dbe..83eab201 100644
--- a/lib/vendors/table/request-pq-dialog.tsx
+++ b/lib/vendors/table/request-pq-dialog.tsx
@@ -40,7 +40,7 @@ import { Badge } from "@/components/ui/badge"
import { Progress } from "@/components/ui/progress"
import { Vendor } from "@/db/schema/vendors"
import { requestBasicContractInfo, requestPQVendors, sendBasicContractEmail } from "../service"
-import { getProjectsWithPQList } from "@/lib/pq/service"
+import { getProjectsWithPQList, getNonInspectionPQLists } from "@/lib/pq/service"
import type { Project } from "@/lib/pq/service"
import { useSession } from "next-auth/react"
import { DatePicker } from "@/components/ui/date-picker"
@@ -84,12 +84,16 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro
const [agreements, setAgreements] = React.useState<Record<string, boolean>>({})
const [extraNote, setExtraNote] = React.useState<string>("")
const [pqItems, setPqItems] = React.useState<MaterialSearchItem[]>([])
-
+
// PQ 품목 선택 관련 상태는 MaterialGroupSelectorDialogMulti에서 관리됨
const [isLoadingProjects, setIsLoadingProjects] = React.useState(false)
const [basicContractTemplates, setBasicContractTemplates] = React.useState<BasicContractTemplate[]>([])
const [selectedTemplateIds, setSelectedTemplateIds] = React.useState<number[]>([])
const [isLoadingTemplates, setIsLoadingTemplates] = React.useState(false)
+
+ // 미실사 PQ 관련 상태
+ const [activeNonInspectionPQList, setActiveNonInspectionPQList] = React.useState<any>(null)
+ const [isLoadingNonInspectionPQ, setIsLoadingNonInspectionPQ] = React.useState(false)
// 비밀유지 계약서 첨부파일 관련 상태
const [ndaAttachments, setNdaAttachments] = React.useState<File[]>([])
@@ -110,6 +114,19 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro
setIsLoadingProjects(true)
getProjectsWithPQList().then(setProjects).catch(() => toast.error("프로젝트 로딩 실패"))
.finally(() => setIsLoadingProjects(false))
+ } else if (type === "NON_INSPECTION") {
+ setIsLoadingNonInspectionPQ(true)
+ // 활성화된 미실사 PQ 리스트 조회
+ getNonInspectionPQLists().then(result => {
+ if (result.success) {
+ setActiveNonInspectionPQList(result.data)
+ } else {
+ setActiveNonInspectionPQList(null)
+ }
+ }).catch(() => {
+ toast.error("미실사 PQ 리스트 로딩 실패")
+ setActiveNonInspectionPQList(null)
+ }).finally(() => setIsLoadingNonInspectionPQ(false))
}
}, [type])
@@ -221,6 +238,8 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro
setShowProgress(false)
setPqHistory({})
setIsLoadingHistory(false)
+ setActiveNonInspectionPQList(null)
+ setIsLoadingNonInspectionPQ(false)
}
}, [props.open])
@@ -261,6 +280,7 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro
const onApprove = () => {
if (!type) return toast.error("PQ 유형을 선택하세요.")
if (type === "PROJECT" && !selectedProjectId) return toast.error("프로젝트를 선택하세요.")
+ if (type === "NON_INSPECTION" && !activeNonInspectionPQList) return toast.error("활성화된 미실사 PQ 리스트가 없습니다.")
if (!dueDate) return toast.error("마감일을 선택하세요.")
if (pqItems.length === 0) return toast.error("PQ 대상 품목을 선택하세요.")
if (!session?.user?.id) return toast.error("인증 실패")
@@ -639,7 +659,7 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro
})
if (emailResult.success) {
- toast.success(`${templateIds.length}개 템플릿에 대한 기본계약서가 생성되었고, ${vendorIds.length}개 협력업체에 이메일이 발송되었습니다`)
+ toast.success(`${vendorIds.length}개 협력업체에 이메일이 발송되었습니다`)
} else {
toast.warning(`계약서는 생성되었으나 일부 이메일 발송 실패: ${emailResult.error}`)
}
@@ -793,6 +813,31 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro
</div>
)}
+ {type === "NON_INSPECTION" && (
+ <div className="space-y-2">
+ <Label>활성화된 미실사 PQ 리스트</Label>
+ {isLoadingNonInspectionPQ ? (
+ <div className="text-sm text-muted-foreground">로딩 중...</div>
+ ) : activeNonInspectionPQList ? (
+ <div className="p-3 border rounded-md bg-muted/30">
+ <div className="flex items-center gap-2">
+ <Badge variant="secondary">미실사 PQ</Badge>
+ <span className="font-medium">{activeNonInspectionPQList.name}</span>
+ </div>
+ <div className="text-sm text-muted-foreground mt-1">
+ 활성화된 미실사 PQ 리스트를 기준으로 요청합니다.
+ </div>
+ </div>
+ ) : (
+ <div className="p-3 border rounded-md bg-destructive/10 border-destructive/20">
+ <div className="text-sm text-destructive">
+ 활성화된 미실사 PQ 리스트가 없습니다. 먼저 PQ 관리에서 미실사 PQ 리스트를 생성하고 활성화해주세요.
+ </div>
+ </div>
+ )}
+ </div>
+ )}
+
{/* 마감일 입력 */}
<div className="space-y-2">
<Label htmlFor="dueDate">PQ 제출 마감일</Label>
@@ -875,7 +920,7 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro
)}
</div>
)}
- {selectedTemplateIds.length > 0 && (
+ {/* {selectedTemplateIds.length > 0 && (
<div className="text-xs text-muted-foreground">
{selectedTemplateIds.length}개 템플릿이 선택되었습니다.
{vendors.length > 0 && vendors.every(v => v.country !== 'KR') &&
@@ -883,7 +928,7 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro
{vendors.length > 0 && vendors.every(v => v.country === 'KR') &&
" (내자 벤더 - 자동 선택됨)"}
</div>
- )}
+ )} */}
</div>
{/* 비밀유지 계약서 첨부파일 */}
@@ -1013,9 +1058,9 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro
<DialogClose asChild>
<Button variant="outline" disabled={isApprovePending}>취소</Button>
</DialogClose>
- <Button
- onClick={onApprove}
- disabled={isApprovePending || !type || (type === "PROJECT" && !selectedProjectId)}
+ <Button
+ onClick={onApprove}
+ disabled={isApprovePending || !type || (type === "PROJECT" && !selectedProjectId) || (type === "NON_INSPECTION" && !activeNonInspectionPQList)}
>
{isApprovePending && <Loader className="mr-2 size-4 animate-spin" />}
요청하기
@@ -1067,9 +1112,9 @@ export function RequestPQDialog({ vendors, showTrigger = true, onSuccess, ...pro
<DrawerClose asChild>
<Button variant="outline" disabled={isApprovePending} className="flex-1">취소</Button>
</DrawerClose>
- <Button
- onClick={onApprove}
- disabled={isApprovePending || !type || (type === "PROJECT" && !selectedProjectId)}
+ <Button
+ onClick={onApprove}
+ disabled={isApprovePending || !type || (type === "PROJECT" && !selectedProjectId) || (type === "NON_INSPECTION" && !activeNonInspectionPQList)}
className="flex-1"
>
{isApprovePending && <Loader className="mr-2 size-4 animate-spin" />}