From fccb00d15466cd0b2d861163663a5070c768ff77 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Tue, 2 Sep 2025 09:52:21 +0000
Subject: (대표님) OCR 박진석프로 요청 대응, rfq 변경된 요구사항 구현
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/rfq-last/table/rfq-table-toolbar-actions.tsx | 163 +++++++++++++++++++++++
 1 file changed, 163 insertions(+)
 create mode 100644 lib/rfq-last/table/rfq-table-toolbar-actions.tsx

(limited to 'lib/rfq-last/table/rfq-table-toolbar-actions.tsx')

diff --git a/lib/rfq-last/table/rfq-table-toolbar-actions.tsx b/lib/rfq-last/table/rfq-table-toolbar-actions.tsx
new file mode 100644
index 00000000..1f60da36
--- /dev/null
+++ b/lib/rfq-last/table/rfq-table-toolbar-actions.tsx
@@ -0,0 +1,163 @@
+"use client";
+
+import * as React from "react";
+import { type Table } from "@tanstack/react-table";
+import { Download, RefreshCw, Plus } from "lucide-react";
+
+import { Button } from "@/components/ui/button";
+import {
+  DropdownMenu,
+  DropdownMenuContent,
+  DropdownMenuItem,
+  DropdownMenuSeparator,
+  DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu";
+import { RfqsLastView } from "@/db/schema";
+
+interface RfqTableToolbarActionsProps {
+  table: Table<RfqsLastView>;
+  onRefresh?: () => void;
+}
+
+export function RfqTableToolbarActions({
+  table,
+  onRefresh,
+}: RfqTableToolbarActionsProps) {
+  const [isExporting, setIsExporting] = React.useState(false);
+
+  const handleExportCSV = React.useCallback(async () => {
+    setIsExporting(true);
+    try {
+      const data = table.getFilteredRowModel().rows.map((row) => {
+        const original = row.original;
+        return {
+          "RFQ 코드": original.rfqCode || "",
+          "상태": original.status || "",
+          "프로젝트 코드": original.projectCode || "",
+          "프로젝트명": original.projectName || "",
+          "자재코드": original.itemCode || "",
+          "자재명": original.itemName || "",
+          "패키지 번호": original.packageNo || "",
+          "패키지명": original.packageName || "",
+          "구매담당자": original.picUserName || original.picName || "",
+          "엔지니어링 담당": original.engPicName || "",
+          "발송일": original.rfqSendDate ? new Date(original.rfqSendDate).toLocaleDateString("ko-KR") : "",
+          "마감일": original.dueDate ? new Date(original.dueDate).toLocaleDateString("ko-KR") : "",
+          "업체수": original.vendorCount || 0,
+          "Short List": original.shortListedVendorCount || 0,
+          "견적접수": original.quotationReceivedCount || 0,
+          "PR Items": original.prItemsCount || 0,
+          "주요 Items": original.majorItemsCount || 0,
+          "시리즈": original.series || "",
+          "견적 유형": original.rfqType || "",
+          "견적 제목": original.rfqTitle || "",
+          "프로젝트 회사": original.projectCompany || "",
+          "프로젝트 사이트": original.projectSite || "",
+          "SM 코드": original.smCode || "",
+          "PR 번호": original.prNumber || "",
+          "PR 발행일": original.prIssueDate ? new Date(original.prIssueDate).toLocaleDateString("ko-KR") : "",
+          "생성자": original.createdByUserName || "",
+          "생성일": original.createdAt ? new Date(original.createdAt).toLocaleDateString("ko-KR") : "",
+          "수정자": original.updatedByUserName || "",
+          "수정일": original.updatedAt ? new Date(original.updatedAt).toLocaleDateString("ko-KR") : "",
+        };
+      });
+
+      const fileName = `RFQ_목록_${new Date().toISOString().split("T")[0]}.csv`;
+      exportTableToCSV({ data, filename: fileName });
+    } catch (error) {
+      console.error("Export failed:", error);
+    } finally {
+      setIsExporting(false);
+    }
+  }, [table]);
+
+  const handleExportSelected = React.useCallback(async () => {
+    setIsExporting(true);
+    try {
+      const selectedRows = table.getFilteredSelectedRowModel().rows;
+      if (selectedRows.length === 0) {
+        alert("선택된 항목이 없습니다.");
+        return;
+      }
+
+      const data = selectedRows.map((row) => {
+        const original = row.original;
+        return {
+          "RFQ 코드": original.rfqCode || "",
+          "상태": original.status || "",
+          "프로젝트 코드": original.projectCode || "",
+          "프로젝트명": original.projectName || "",
+          "자재코드": original.itemCode || "",
+          "자재명": original.itemName || "",
+          "패키지 번호": original.packageNo || "",
+          "패키지명": original.packageName || "",
+          "구매담당자": original.picUserName || original.picName || "",
+          "엔지니어링 담당": original.engPicName || "",
+          "발송일": original.rfqSendDate ? new Date(original.rfqSendDate).toLocaleDateString("ko-KR") : "",
+          "마감일": original.dueDate ? new Date(original.dueDate).toLocaleDateString("ko-KR") : "",
+          "업체수": original.vendorCount || 0,
+          "Short List": original.shortListedVendorCount || 0,
+          "견적접수": original.quotationReceivedCount || 0,
+        };
+      });
+
+      const fileName = `RFQ_선택항목_${new Date().toISOString().split("T")[0]}.csv`;
+      exportTableToCSV({ data, filename: fileName });
+    } catch (error) {
+      console.error("Export failed:", error);
+    } finally {
+      setIsExporting(false);
+    }
+  }, [table]);
+
+  return (
+    <div className="flex items-center gap-2">
+      {onRefresh && (
+        <Button
+          variant="outline"
+          size="sm"
+          onClick={onRefresh}
+          className="h-8 px-2 lg:px-3"
+        >
+          <RefreshCw className="mr-2 h-4 w-4" />
+          새로고침
+        </Button>
+      )}
+
+      <DropdownMenu>
+        <DropdownMenuTrigger asChild>
+          <Button
+            variant="outline"
+            size="sm"
+            className="h-8 px-2 lg:px-3"
+            disabled={isExporting}
+          >
+            <Download className="mr-2 h-4 w-4" />
+            {isExporting ? "내보내는 중..." : "내보내기"}
+          </Button>
+        </DropdownMenuTrigger>
+        <DropdownMenuContent align="end">
+          <DropdownMenuItem onClick={handleExportCSV}>
+            전체 데이터 내보내기
+          </DropdownMenuItem>
+          <DropdownMenuItem 
+            onClick={handleExportSelected}
+            disabled={table.getFilteredSelectedRowModel().rows.length === 0}
+          >
+            선택한 항목 내보내기 ({table.getFilteredSelectedRowModel().rows.length}개)
+          </DropdownMenuItem>
+        </DropdownMenuContent>
+      </DropdownMenu>
+
+      <Button
+        variant="samsung"
+        size="sm"
+        className="h-8 px-2 lg:px-3"
+      >
+        <Plus className="mr-2 h-4 w-4" />
+        RFQ 생성
+      </Button>
+    </div>
+  );
+}
\ No newline at end of file
-- 
cgit v1.2.3

