From 871a6d46a769cbe9e87146434f4bcb2d6792ab81 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Thu, 30 Oct 2025 10:44:47 +0000
Subject: (최겸) 구매 PQ/실사 재개발(테스트 필요), 정규업체등록 결재 개발, 실사
 의뢰 결재 후처리 등
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 components/pq-input/pq-review-wrapper.tsx | 92 +++++++++++++++++++++++++++----
 1 file changed, 82 insertions(+), 10 deletions(-)

(limited to 'components/pq-input/pq-review-wrapper.tsx')

diff --git a/components/pq-input/pq-review-wrapper.tsx b/components/pq-input/pq-review-wrapper.tsx
index 9b719644..bcb384d9 100644
--- a/components/pq-input/pq-review-wrapper.tsx
+++ b/components/pq-input/pq-review-wrapper.tsx
@@ -23,7 +23,7 @@ import {
 import { useToast } from "@/hooks/use-toast"
 import { CheckCircle, AlertCircle, Paperclip, Square } from "lucide-react"
 import { PQGroupData } from "@/lib/pq/service"
-import { approvePQAction, rejectPQAction, updateSHICommentAction, approveQMReviewAction, rejectQMReviewAction } from "@/lib/pq/service"
+import { approvePQAction, rejectPQAction, updateSHICommentAction, approveQMReviewAction, rejectQMReviewAction, requestPqSupplementAction } from "@/lib/pq/service"
 // import * as ExcelJS from 'exceljs';
 // import { saveAs } from "file-saver";
 
@@ -67,10 +67,13 @@ export function PQReviewWrapper({
   const [showRejectDialog, setShowRejectDialog] = React.useState(false)
   const [showQMApproveDialog, setShowQMApproveDialog] = React.useState(false)
   const [showQMRejectDialog, setShowQMRejectDialog] = React.useState(false)
+  const [showSupplementDialog, setShowSupplementDialog] = React.useState(false)
   const [rejectReason, setRejectReason] = React.useState("")
   const [qmRejectReason, setQmRejectReason] = React.useState("")
+  const [supplementComment, setSupplementComment] = React.useState("")
   const [shiComments, setShiComments] = React.useState<Record<number, string>>({})
   const [isUpdatingComment, setIsUpdatingComment] = React.useState<number | null>(null)
+  const [isSendingSupplement, setIsSendingSupplement] = React.useState(false)
 
   
   // 코드 순서로 정렬하는 함수 (1-1-1, 1-1-2, 1-2-1 순서)
@@ -108,7 +111,7 @@ export function PQReviewWrapper({
     setShiComments(initialComments)
   }, [pqData])
   
-  // PQ 승인 처리 (구매 담당자)
+  // PQ 승인 처리
   const handleApprove = async () => {
     try {
       setIsApproving(true)
@@ -121,10 +124,10 @@ export function PQReviewWrapper({
       if (result.ok) {
         toast({
           title: "PQ 승인 완료",
-          description: "PQ가 QM 검토 단계로 전환되었습니다.",
+          description: "PQ가 성공적으로 승인되었습니다.",
         })
         // 페이지 새로고침
-        router.refresh()
+        router.push(`/evcp/pq_new/`)
       } else {
         toast({
           title: "승인 실패",
@@ -182,6 +185,35 @@ export function PQReviewWrapper({
     }
   }
 
+  // 보완요청 처리
+  const handleRequestSupplement = async () => {
+    if (!supplementComment.trim()) {
+      toast({ title: "보완요청 내용 필요", description: "보완요청 사유를 입력해주세요.", variant: "destructive" })
+      return
+    }
+    try {
+      setIsSendingSupplement(true)
+      const result = await requestPqSupplementAction({
+        pqSubmissionId: pqSubmission.id,
+        vendorId,
+        comment: supplementComment,
+      })
+      if (result.ok) {
+        toast({ title: "보완요청 전송", description: "보완요청 메일을 발송했습니다." })
+        setShowSupplementDialog(false)
+        setSupplementComment("")
+        router.refresh()
+      } else {
+        toast({ title: "전송 실패", description: result.error || "보완요청 전송 중 오류가 발생했습니다.", variant: "destructive" })
+      }
+    } catch (e) {
+      console.error(e)
+      toast({ title: "전송 실패", description: "보완요청 전송 중 오류가 발생했습니다.", variant: "destructive" })
+    } finally {
+      setIsSendingSupplement(false)
+    }
+  }
+
   // QM 거절 처리
   const handleQMReject = async () => {
     if (!qmRejectReason.trim()) {
@@ -426,8 +458,8 @@ export function PQReviewWrapper({
           title: "PQ 거부 완료",
           description: "PQ가 거부되었습니다.",
         })
-        // 페이지 새로고침
-        router.refresh()
+        // 페이지 리다이렉트
+        router.push(`/evcp/pq_new/`)
       } else {
         toast({
           title: "거부 실패",
@@ -745,6 +777,13 @@ export function PQReviewWrapper({
                 >
                   {isRejecting ? "거부 중..." : "거부"}
                 </Button>
+                <Button
+                  variant="secondary"
+                  onClick={() => setShowSupplementDialog(true)}
+                  disabled={isSendingSupplement}
+                >
+                  보완요청
+                </Button>
                 <Button
                   variant="default"
                   onClick={() => setShowApproveDialog(true)}
@@ -756,7 +795,7 @@ export function PQReviewWrapper({
             )}
 
             {/* QM_REVIEWING 상태: QM 승인/거절 */}
-            {pqSubmission.status === "QM_REVIEWING" && (
+            {pqSubmission.status === "APPROVED" && (
               <>
                 <Button
                   variant="outline"
@@ -765,6 +804,13 @@ export function PQReviewWrapper({
                 >
                   {isQMRejecting ? "QM 거절 중..." : "QM 거절"}
                 </Button>
+                <Button
+                  variant="secondary"
+                  onClick={() => setShowSupplementDialog(true)}
+                  disabled={isSendingSupplement}
+                >
+                  보완요청
+                </Button>
                 <Button
                   variant="default"
                   onClick={() => setShowQMApproveDialog(true)}
@@ -802,17 +848,17 @@ export function PQReviewWrapper({
         </div>
 
       
-      {/* 구매 승인 확인 다이얼로그 */}
+      {/* 승인 확인 다이얼로그 */}
       <Dialog open={showApproveDialog} onOpenChange={setShowApproveDialog}>
         <DialogContent>
           <DialogHeader>
-            <DialogTitle>PQ 구매 승인 확인</DialogTitle>
+            <DialogTitle>PQ 승인 확인</DialogTitle>
             <DialogDescription>
               {pqSubmission.vendorName || "알 수 없는 업체"}의 {
                 pqSubmission.type === "GENERAL" ? "일반" : 
                 pqSubmission.type === "PROJECT" ? "프로젝트" : 
                 pqSubmission.type === "NON_INSPECTION" ? "미실사" : "일반"
-              } PQ를 구매 승인하여 QM 검토 단계로 전환하시겠습니까?
+              } PQ를 승인하시겠습니까?
               {pqSubmission.projectId && (
                 <span> 프로젝트: {pqSubmission.projectName}</span>
               )}
@@ -829,6 +875,32 @@ export function PQReviewWrapper({
         </DialogContent>
       </Dialog>
 
+      {/* 보완요청 다이얼로그 */}
+      <Dialog open={showSupplementDialog} onOpenChange={setShowSupplementDialog}>
+        <DialogContent>
+          <DialogHeader>
+            <DialogTitle>PQ 보완요청</DialogTitle>
+            <DialogDescription>
+              {pqSubmission.vendorName || "알 수 없는 업체"}에 보완요청을 전송합니다. 내용(사유)을 입력해주세요.
+            </DialogDescription>
+          </DialogHeader>
+          <Textarea
+            value={supplementComment}
+            onChange={(e) => setSupplementComment(e.target.value)}
+            placeholder="보완요청 사유를 입력하세요"
+            className="min-h-24"
+          />
+          <DialogFooter>
+            <Button variant="outline" onClick={() => setShowSupplementDialog(false)}>
+              취소
+            </Button>
+            <Button onClick={handleRequestSupplement} disabled={isSendingSupplement || !supplementComment.trim()}>
+              {isSendingSupplement ? "전송 중..." : "보완요청 전송"}
+            </Button>
+          </DialogFooter>
+        </DialogContent>
+      </Dialog>
+
       {/* QM 승인 확인 다이얼로그 */}
       <Dialog open={showQMApproveDialog} onOpenChange={setShowQMApproveDialog}>
         <DialogContent>
-- 
cgit v1.2.3

