From d47334639bd717aa860563ec1020a29827524fd4 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Fri, 5 Dec 2025 06:29:23 +0000
Subject: (최겸)구매 결재일 기준 공고 수정
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../vendor/components/pr-items-pricing-table.tsx   | 125 +++++++++++++++++++--
 1 file changed, 118 insertions(+), 7 deletions(-)

(limited to 'lib/bidding/vendor/components/pr-items-pricing-table.tsx')

diff --git a/lib/bidding/vendor/components/pr-items-pricing-table.tsx b/lib/bidding/vendor/components/pr-items-pricing-table.tsx
index 5afb2b67..6910e360 100644
--- a/lib/bidding/vendor/components/pr-items-pricing-table.tsx
+++ b/lib/bidding/vendor/components/pr-items-pricing-table.tsx
@@ -4,7 +4,17 @@ import * as React from 'react'
 import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
 import { Input } from '@/components/ui/input'
 import { Label } from '@/components/ui/label'
-
+import { Button } from '@/components/ui/button'
+import { Calendar } from '@/components/ui/calendar'
+import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
+import {
+  Dialog,
+  DialogContent,
+  DialogDescription,
+  DialogFooter,
+  DialogHeader,
+  DialogTitle,
+} from '@/components/ui/dialog'
 import { Badge } from '@/components/ui/badge'
 import {
   Table,
@@ -16,10 +26,12 @@ import {
 } from '@/components/ui/table'
 import {
   Package,
-
   Download,
-  Calculator
+  Calculator,
+  CalendarIcon
 } from 'lucide-react'
+import { format } from 'date-fns'
+import { cn } from '@/lib/utils'
 import { formatDate } from '@/lib/utils'
 import { downloadFile, formatFileSize, getFileInfo } from '@/lib/file-download'
 import { getSpecDocumentsForPrItem } from '../../pre-quote/service'
@@ -186,6 +198,8 @@ export function PrItemsPricingTable({
 }: PrItemsPricingTableProps) {
   const [quotations, setQuotations] = React.useState<PrItemQuotation[]>([])
   const [specDocuments, setSpecDocuments] = React.useState<Record<number, SpecDocument[]>>({})
+  const [showBulkDateDialog, setShowBulkDateDialog] = React.useState(false)
+  const [bulkDeliveryDate, setBulkDeliveryDate] = React.useState<Date | undefined>(undefined)
 
   // 초기 견적 데이터 설정 및 SPEC 문서 로드
   React.useEffect(() => {
@@ -279,6 +293,21 @@ export function PrItemsPricingTable({
     onTotalAmountChange(totalAmount)
   }
 
+  // 일괄 납기일 적용
+  const applyBulkDeliveryDate = () => {
+    if (bulkDeliveryDate && quotations.length > 0) {
+      const formattedDate = format(bulkDeliveryDate, 'yyyy-MM-dd')
+      const updatedQuotations = quotations.map(q => ({
+        ...q,
+        proposedDeliveryDate: formattedDate
+      }))
+      
+      setQuotations(updatedQuotations)
+      onQuotationsChange(updatedQuotations)
+      setShowBulkDateDialog(false)
+      setBulkDeliveryDate(undefined)
+    }
+  }
 
   // 통화 포맷팅
   const formatCurrency = (amount: number) => {
@@ -292,12 +321,26 @@ export function PrItemsPricingTable({
   const totalAmount = quotations.reduce((sum, q) => sum + q.bidAmount, 0)
 
   return (
+    <>
     <Card>
       <CardHeader>
-        <CardTitle className="flex items-center gap-2">
-          <Package className="w-5 h-5" />
-          품목별 입찰 작성
-        </CardTitle>
+        <div className="flex items-center justify-between">
+          <CardTitle className="flex items-center gap-2">
+            <Package className="w-5 h-5" />
+            품목별 입찰 작성
+          </CardTitle>
+          {!readOnly && (
+            <Button
+              type="button"
+              variant="outline"
+              size="sm"
+              onClick={() => setShowBulkDateDialog(true)}
+            >
+              <CalendarIcon className="h-4 w-4 mr-1" />
+              전체 납품예정일 설정
+            </Button>
+          )}
+        </div>
       </CardHeader>
       <CardContent>
         <div className="space-y-4">
@@ -467,5 +510,73 @@ export function PrItemsPricingTable({
         </div>
       </CardContent>
     </Card>
+
+      {/* 일괄 납품예정일 설정 다이얼로그 */}
+      <Dialog open={showBulkDateDialog} onOpenChange={setShowBulkDateDialog}>
+        <DialogContent className="sm:max-w-md">
+          <DialogHeader>
+            <DialogTitle>전체 납품예정일 설정</DialogTitle>
+            <DialogDescription>
+              모든 PR 아이템에 동일한 납품예정일을 적용합니다.
+            </DialogDescription>
+          </DialogHeader>
+
+          <div className="space-y-4">
+            <div className="space-y-2">
+              <Label>납품예정일 선택</Label>
+              <Popover>
+                <PopoverTrigger asChild>
+                  <Button
+                    variant="outline"
+                    className={cn(
+                      "w-full justify-start text-left font-normal",
+                      !bulkDeliveryDate && "text-muted-foreground"
+                    )}
+                  >
+                    <CalendarIcon className="mr-2 h-4 w-4" />
+                    {bulkDeliveryDate ? format(bulkDeliveryDate, "yyyy-MM-dd") : "날짜 선택"}
+                  </Button>
+                </PopoverTrigger>
+                <PopoverContent className="w-auto p-0" align="start">
+                  <Calendar
+                    mode="single"
+                    selected={bulkDeliveryDate}
+                    onSelect={setBulkDeliveryDate}
+                    initialFocus
+                  />
+                </PopoverContent>
+              </Popover>
+            </div>
+
+            <div className="bg-muted/50 rounded-lg p-3">
+              <p className="text-sm text-muted-foreground">
+                선택된 날짜가 <strong>{prItems.length}개</strong>의 모든 PR 아이템에 적용됩니다.
+                기존에 설정된 납품예정일은 모두 교체됩니다.
+              </p>
+            </div>
+          </div>
+
+          <DialogFooter>
+            <Button
+              type="button"
+              variant="outline"
+              onClick={() => {
+                setShowBulkDateDialog(false)
+                setBulkDeliveryDate(undefined)
+              }}
+            >
+              취소
+            </Button>
+            <Button
+              type="button"
+              onClick={applyBulkDeliveryDate}
+              disabled={!bulkDeliveryDate}
+            >
+              전체 적용
+            </Button>
+          </DialogFooter>
+        </DialogContent>
+      </Dialog>
+    </>
   )
 }
-- 
cgit v1.2.3

