From 25b916d040a512cd5248dff319d727ae144d0652 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Mon, 15 Sep 2025 03:24:12 +0000 Subject: (최겸) 구매 PCR 개발(po -> pcr, ecc pcr-confirm test 필) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../table/detail-table/create-pcr-pr-dialog.tsx | 598 +++++++++++++++++++++ 1 file changed, 598 insertions(+) create mode 100644 lib/pcr/table/detail-table/create-pcr-pr-dialog.tsx (limited to 'lib/pcr/table/detail-table/create-pcr-pr-dialog.tsx') diff --git a/lib/pcr/table/detail-table/create-pcr-pr-dialog.tsx b/lib/pcr/table/detail-table/create-pcr-pr-dialog.tsx new file mode 100644 index 00000000..1244d179 --- /dev/null +++ b/lib/pcr/table/detail-table/create-pcr-pr-dialog.tsx @@ -0,0 +1,598 @@ +"use client" + +import * as React from "react" +import { useForm } from "react-hook-form" +import { zodResolver } from "@hookform/resolvers/zod" +import * as z from "zod" +import { Button } from "@/components/ui/button" +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog" +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { Input } from "@/components/ui/input" +import { Textarea } from "@/components/ui/textarea" +import { Calendar } from "@/components/ui/calendar" +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover" +import { CalendarIcon } from "lucide-react" +import { format } from "date-fns" +import { cn } from "@/lib/utils" +import { toast } from "sonner" +import { PcrPoData } from "@/lib/pcr/types" +import { createPcrPrAction } from "@/lib/pcr/actions" + +const pcrPrSchema = z.object({ + materialNumber: z.string().min(1, "자재번호는 필수입니다"), + materialDetails: z.string().optional(), + quantityBefore: z.number().optional(), + quantityAfter: z.number().optional(), + weightBefore: z.number().optional(), + weightAfter: z.number().optional(), + subcontractorWeightBefore: z.number().optional(), + subcontractorWeightAfter: z.number().optional(), + supplierWeightBefore: z.number().optional(), + supplierWeightAfter: z.number().optional(), + specDrawingBefore: z.string().optional(), + specDrawingAfter: z.string().optional(), + initialPoContractDate: z.date().optional(), + specChangeDate: z.date().optional(), + poContractModifiedDate: z.date().optional(), + confirmationDate: z.date().optional(), + designManager: z.string().optional(), +}) + +type PcrPrFormData = z.infer + +interface CreatePcrPrDialogProps { + open: boolean + onOpenChange: (open: boolean) => void + selectedPcrPo: PcrPoData | null + onSuccess: () => void +} + +export function CreatePcrPrDialog({ + open, + onOpenChange, + selectedPcrPo, + onSuccess, +}: CreatePcrPrDialogProps) { + const [isSubmitting, setIsSubmitting] = React.useState(false) + + const form = useForm({ + resolver: zodResolver(pcrPrSchema), + defaultValues: { + materialNumber: "", + materialDetails: "", + quantityBefore: undefined, + quantityAfter: undefined, + weightBefore: undefined, + weightAfter: undefined, + subcontractorWeightBefore: undefined, + subcontractorWeightAfter: undefined, + supplierWeightBefore: undefined, + supplierWeightAfter: undefined, + specDrawingBefore: "", + specDrawingAfter: "", + initialPoContractDate: undefined, + specChangeDate: undefined, + poContractModifiedDate: undefined, + confirmationDate: undefined, + designManager: "", + }, + }) + + const onSubmit = async (data: PcrPrFormData) => { + if (!selectedPcrPo) { + toast.error("선택된 PCR_PO가 없습니다") + return + } + + setIsSubmitting(true) + try { + const result = await createPcrPrAction({ + ...data, + poContractNumber: selectedPcrPo.poContractNumber, + }) + + if (result.success) { + toast.success("PCR_PR이 성공적으로 생성되었습니다") + form.reset() + onOpenChange(false) + onSuccess() + } else { + toast.error(result.error || "PCR_PR 생성에 실패했습니다") + } + } catch (error) { + console.error("PCR_PR 생성 오류:", error) + toast.error("PCR_PR 생성 중 오류가 발생했습니다") + } finally { + setIsSubmitting(false) + } + } + + return ( + + + + PCR_PR 생성 + + PO/계약번호: {selectedPcrPo?.poContractNumber} + + + +
+ + {/* 기본 정보 섹션 */} +
+ ( + + 자재번호 * + + + + + + )} + /> + + ( + + 설계 담당자 + + + + + + )} + /> +
+ + ( + + 자재내역 + +