From 25b916d040a512cd5248dff319d727ae144d0652 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
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<typeof pcrPrSchema>
+
+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<PcrPrFormData>({
+    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 (
+    <Dialog open={open} onOpenChange={onOpenChange}>
+      <DialogContent className="max-w-4xl max-h-[90vh] overflow-y-auto">
+        <DialogHeader>
+          <DialogTitle>PCR_PR 생성</DialogTitle>
+          <DialogDescription>
+            PO/계약번호: {selectedPcrPo?.poContractNumber}
+          </DialogDescription>
+        </DialogHeader>
+
+        <Form {...form}>
+          <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
+            {/* 기본 정보 섹션 */}
+            <div className="grid grid-cols-2 gap-4">
+              <FormField
+                control={form.control}
+                name="materialNumber"
+                render={({ field }) => (
+                  <FormItem>
+                    <FormLabel>자재번호 *</FormLabel>
+                    <FormControl>
+                      <Input placeholder="자재번호를 입력하세요" {...field} />
+                    </FormControl>
+                    <FormMessage />
+                  </FormItem>
+                )}
+              />
+
+              <FormField
+                control={form.control}
+                name="designManager"
+                render={({ field }) => (
+                  <FormItem>
+                    <FormLabel>설계 담당자</FormLabel>
+                    <FormControl>
+                      <Input placeholder="설계 담당자를 입력하세요" {...field} />
+                    </FormControl>
+                    <FormMessage />
+                  </FormItem>
+                )}
+              />
+            </div>
+
+            <FormField
+              control={form.control}
+              name="materialDetails"
+              render={({ field }) => (
+                <FormItem>
+                  <FormLabel>자재내역</FormLabel>
+                  <FormControl>
+                    <Textarea
+                      placeholder="자재내역을 입력하세요"
+                      className="resize-none"
+                      rows={3}
+                      {...field}
+                    />
+                  </FormControl>
+                  <FormMessage />
+                </FormItem>
+              )}
+            />
+
+            {/* 수량 정보 섹션 */}
+            <div className="space-y-4">
+              <h4 className="text-sm font-medium text-muted-foreground">수량 정보</h4>
+              <div className="grid grid-cols-2 gap-4">
+                <FormField
+                  control={form.control}
+                  name="quantityBefore"
+                  render={({ field }) => (
+                    <FormItem>
+                      <FormLabel>수량 (변경전)</FormLabel>
+                      <FormControl>
+                        <Input
+                          type="number"
+                          step="0.001"
+                          placeholder="0.000"
+                          {...field}
+                          onChange={(e) => field.onChange(e.target.value ? parseFloat(e.target.value) : undefined)}
+                        />
+                      </FormControl>
+                      <FormMessage />
+                    </FormItem>
+                  )}
+                />
+
+                <FormField
+                  control={form.control}
+                  name="quantityAfter"
+                  render={({ field }) => (
+                    <FormItem>
+                      <FormLabel>수량 (변경후)</FormLabel>
+                      <FormControl>
+                        <Input
+                          type="number"
+                          step="0.001"
+                          placeholder="0.000"
+                          {...field}
+                          onChange={(e) => field.onChange(e.target.value ? parseFloat(e.target.value) : undefined)}
+                        />
+                      </FormControl>
+                      <FormMessage />
+                    </FormItem>
+                  )}
+                />
+              </div>
+            </div>
+
+            {/* 중량 정보 섹션 */}
+            <div className="space-y-4">
+              <h4 className="text-sm font-medium text-muted-foreground">중량 정보</h4>
+              <div className="grid grid-cols-2 gap-4">
+                <FormField
+                  control={form.control}
+                  name="weightBefore"
+                  render={({ field }) => (
+                    <FormItem>
+                      <FormLabel>중량 (변경전)</FormLabel>
+                      <FormControl>
+                        <Input
+                          type="number"
+                          step="0.001"
+                          placeholder="0.000"
+                          {...field}
+                          onChange={(e) => field.onChange(e.target.value ? parseFloat(e.target.value) : undefined)}
+                        />
+                      </FormControl>
+                      <FormMessage />
+                    </FormItem>
+                  )}
+                />
+
+                <FormField
+                  control={form.control}
+                  name="weightAfter"
+                  render={({ field }) => (
+                    <FormItem>
+                      <FormLabel>중량 (변경후)</FormLabel>
+                      <FormControl>
+                        <Input
+                          type="number"
+                          step="0.001"
+                          placeholder="0.000"
+                          {...field}
+                          onChange={(e) => field.onChange(e.target.value ? parseFloat(e.target.value) : undefined)}
+                        />
+                      </FormControl>
+                      <FormMessage />
+                    </FormItem>
+                  )}
+                />
+
+                <FormField
+                  control={form.control}
+                  name="subcontractorWeightBefore"
+                  render={({ field }) => (
+                    <FormItem>
+                      <FormLabel>사급중량 (변경전)</FormLabel>
+                      <FormControl>
+                        <Input
+                          type="number"
+                          step="0.001"
+                          placeholder="0.000"
+                          {...field}
+                          onChange={(e) => field.onChange(e.target.value ? parseFloat(e.target.value) : undefined)}
+                        />
+                      </FormControl>
+                      <FormMessage />
+                    </FormItem>
+                  )}
+                />
+
+                <FormField
+                  control={form.control}
+                  name="subcontractorWeightAfter"
+                  render={({ field }) => (
+                    <FormItem>
+                      <FormLabel>사급중량 (변경후)</FormLabel>
+                      <FormControl>
+                        <Input
+                          type="number"
+                          step="0.001"
+                          placeholder="0.000"
+                          {...field}
+                          onChange={(e) => field.onChange(e.target.value ? parseFloat(e.target.value) : undefined)}
+                        />
+                      </FormControl>
+                      <FormMessage />
+                    </FormItem>
+                  )}
+                />
+
+                <FormField
+                  control={form.control}
+                  name="supplierWeightBefore"
+                  render={({ field }) => (
+                    <FormItem>
+                      <FormLabel>도급중량 (변경전)</FormLabel>
+                      <FormControl>
+                        <Input
+                          type="number"
+                          step="0.001"
+                          placeholder="0.000"
+                          {...field}
+                          onChange={(e) => field.onChange(e.target.value ? parseFloat(e.target.value) : undefined)}
+                        />
+                      </FormControl>
+                      <FormMessage />
+                    </FormItem>
+                  )}
+                />
+
+                <FormField
+                  control={form.control}
+                  name="supplierWeightAfter"
+                  render={({ field }) => (
+                    <FormItem>
+                      <FormLabel>도급중량 (변경후)</FormLabel>
+                      <FormControl>
+                        <Input
+                          type="number"
+                          step="0.001"
+                          placeholder="0.000"
+                          {...field}
+                          onChange={(e) => field.onChange(e.target.value ? parseFloat(e.target.value) : undefined)}
+                        />
+                      </FormControl>
+                      <FormMessage />
+                    </FormItem>
+                  )}
+                />
+              </div>
+            </div>
+
+            {/* SPEC 도면 정보 섹션 */}
+            <div className="space-y-4">
+              <h4 className="text-sm font-medium text-muted-foreground">SPEC 도면 정보</h4>
+              <div className="grid grid-cols-2 gap-4">
+                <FormField
+                  control={form.control}
+                  name="specDrawingBefore"
+                  render={({ field }) => (
+                    <FormItem>
+                      <FormLabel>SPEC 도면 (변경전)</FormLabel>
+                      <FormControl>
+                        <Textarea
+                          placeholder="SPEC 도면 정보를 입력하세요"
+                          className="resize-none"
+                          rows={2}
+                          {...field}
+                        />
+                      </FormControl>
+                      <FormMessage />
+                    </FormItem>
+                  )}
+                />
+
+                <FormField
+                  control={form.control}
+                  name="specDrawingAfter"
+                  render={({ field }) => (
+                    <FormItem>
+                      <FormLabel>SPEC 도면 (변경후)</FormLabel>
+                      <FormControl>
+                        <Textarea
+                          placeholder="SPEC 도면 정보를 입력하세요"
+                          className="resize-none"
+                          rows={2}
+                          {...field}
+                        />
+                      </FormControl>
+                      <FormMessage />
+                    </FormItem>
+                  )}
+                />
+              </div>
+            </div>
+
+            {/* 날짜 정보 섹션 */}
+            <div className="space-y-4">
+              <h4 className="text-sm font-medium text-muted-foreground">날짜 정보</h4>
+              <div className="grid grid-cols-2 gap-4">
+                <FormField
+                  control={form.control}
+                  name="initialPoContractDate"
+                  render={({ field }) => (
+                    <FormItem className="flex flex-col">
+                      <FormLabel>최초 PO/계약 일</FormLabel>
+                      <Popover>
+                        <PopoverTrigger asChild>
+                          <FormControl>
+                            <Button
+                              variant="outline"
+                              className={cn(
+                                "w-full pl-3 text-left font-normal",
+                                !field.value && "text-muted-foreground"
+                              )}
+                            >
+                              {field.value ? (
+                                format(field.value, "yyyy년 MM월 dd일")
+                              ) : (
+                                <span>날짜를 선택하세요</span>
+                              )}
+                              <CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
+                            </Button>
+                          </FormControl>
+                        </PopoverTrigger>
+                        <PopoverContent className="w-auto p-0" align="start">
+                          <Calendar
+                            mode="single"
+                            selected={field.value}
+                            onSelect={field.onChange}
+                            disabled={(date) =>
+                              date > new Date() || date < new Date("1900-01-01")
+                            }
+                            initialFocus
+                          />
+                        </PopoverContent>
+                      </Popover>
+                      <FormMessage />
+                    </FormItem>
+                  )}
+                />
+
+                <FormField
+                  control={form.control}
+                  name="specChangeDate"
+                  render={({ field }) => (
+                    <FormItem className="flex flex-col">
+                      <FormLabel>SPEC 변경 일</FormLabel>
+                      <Popover>
+                        <PopoverTrigger asChild>
+                          <FormControl>
+                            <Button
+                              variant="outline"
+                              className={cn(
+                                "w-full pl-3 text-left font-normal",
+                                !field.value && "text-muted-foreground"
+                              )}
+                            >
+                              {field.value ? (
+                                format(field.value, "yyyy년 MM월 dd일")
+                              ) : (
+                                <span>날짜를 선택하세요</span>
+                              )}
+                              <CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
+                            </Button>
+                          </FormControl>
+                        </PopoverTrigger>
+                        <PopoverContent className="w-auto p-0" align="start">
+                          <Calendar
+                            mode="single"
+                            selected={field.value}
+                            onSelect={field.onChange}
+                            disabled={(date) =>
+                              date > new Date() || date < new Date("1900-01-01")
+                            }
+                            initialFocus
+                          />
+                        </PopoverContent>
+                      </Popover>
+                      <FormMessage />
+                    </FormItem>
+                  )}
+                />
+
+                <FormField
+                  control={form.control}
+                  name="poContractModifiedDate"
+                  render={({ field }) => (
+                    <FormItem className="flex flex-col">
+                      <FormLabel>PO/계약 수정 일</FormLabel>
+                      <Popover>
+                        <PopoverTrigger asChild>
+                          <FormControl>
+                            <Button
+                              variant="outline"
+                              className={cn(
+                                "w-full pl-3 text-left font-normal",
+                                !field.value && "text-muted-foreground"
+                              )}
+                            >
+                              {field.value ? (
+                                format(field.value, "yyyy년 MM월 dd일")
+                              ) : (
+                                <span>날짜를 선택하세요</span>
+                              )}
+                              <CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
+                            </Button>
+                          </FormControl>
+                        </PopoverTrigger>
+                        <PopoverContent className="w-auto p-0" align="start">
+                          <Calendar
+                            mode="single"
+                            selected={field.value}
+                            onSelect={field.onChange}
+                            disabled={(date) =>
+                              date > new Date() || date < new Date("1900-01-01")
+                            }
+                            initialFocus
+                          />
+                        </PopoverContent>
+                      </Popover>
+                      <FormMessage />
+                    </FormItem>
+                  )}
+                />
+
+                <FormField
+                  control={form.control}
+                  name="confirmationDate"
+                  render={({ field }) => (
+                    <FormItem className="flex flex-col">
+                      <FormLabel>확인 일</FormLabel>
+                      <Popover>
+                        <PopoverTrigger asChild>
+                          <FormControl>
+                            <Button
+                              variant="outline"
+                              className={cn(
+                                "w-full pl-3 text-left font-normal",
+                                !field.value && "text-muted-foreground"
+                              )}
+                            >
+                              {field.value ? (
+                                format(field.value, "yyyy년 MM월 dd일")
+                              ) : (
+                                <span>날짜를 선택하세요</span>
+                              )}
+                              <CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
+                            </Button>
+                          </FormControl>
+                        </PopoverTrigger>
+                        <PopoverContent className="w-auto p-0" align="start">
+                          <Calendar
+                            mode="single"
+                            selected={field.value}
+                            onSelect={field.onChange}
+                            disabled={(date) =>
+                              date > new Date() || date < new Date("1900-01-01")
+                            }
+                            initialFocus
+                          />
+                        </PopoverContent>
+                      </Popover>
+                      <FormMessage />
+                    </FormItem>
+                  )}
+                />
+              </div>
+            </div>
+
+            <DialogFooter>
+              <Button
+                type="button"
+                variant="outline"
+                onClick={() => onOpenChange(false)}
+                disabled={isSubmitting}
+              >
+                취소
+              </Button>
+              <Button type="submit" disabled={isSubmitting}>
+                {isSubmitting ? "생성 중..." : "생성"}
+              </Button>
+            </DialogFooter>
+          </form>
+        </Form>
+      </DialogContent>
+    </Dialog>
+  )
+}
-- 
cgit v1.2.3

