"use client" import * as React from "react" import { type ColumnDef } from "@tanstack/react-table" import { Edit, Paperclip, Package, Users } from "lucide-react" import { formatCurrency, formatDate, formatDateTime } from "@/lib/utils" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip" import { TechSalesVendorQuotations, TECH_SALES_QUOTATION_STATUS_CONFIG, TECH_SALES_QUOTATION_STATUSES } from "@/db/schema" import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" interface QuotationWithRfqCode extends TechSalesVendorQuotations { // RFQ 관련 정보 rfqCode?: string; materialCode?: string; dueDate?: Date; rfqStatus?: string; // 아이템 정보 itemName?: string; itemCount?: number; // 프로젝트 정보 projNm?: string; pspid?: string; sector?: string; // RFQ 정보 description?: string; // 벤더 정보 vendorName?: string; vendorCode?: string; // 사용자 정보 createdByName?: string | null; updatedByName?: string | null; // 첨부파일 개수 attachmentCount?: number; } interface GetColumnsProps { router: AppRouterInstance; openAttachmentsSheet: (rfqId: number) => void; openItemsDialog: (rfq: { id: number; rfqCode?: string; status?: string; rfqType?: "SHIP" | "TOP" | "HULL"; }) => void; openContactsDialog: (quotationId: number, vendorName?: string) => void; } export function getColumns({ router, openAttachmentsSheet, openItemsDialog, openContactsDialog }: GetColumnsProps): ColumnDef[] { return [ { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label="모두 선택" className="translate-y-0.5" /> ), cell: ({ row }) => { const isRejected = row.original.status === TECH_SALES_QUOTATION_STATUSES.REJECTED; const isAccepted = row.original.status === TECH_SALES_QUOTATION_STATUSES.ACCEPTED; const isDisabled = isRejected || isAccepted; return ( row.toggleSelected(!!value)} aria-label="행 선택" className="translate-y-0.5" disabled={isDisabled} /> ); }, enableSorting: false, enableHiding: false, }, // { // accessorKey: "id", // header: ({ column }) => ( // // ), // cell: ({ row }) => ( //
// {row.getValue("id")} //
// ), // enableSorting: true, // enableHiding: true, // }, { accessorKey: "rfqCode", header: ({ column }) => ( ), cell: ({ row }) => { const rfqCode = row.getValue("rfqCode") as string; return (
{rfqCode || "N/A"}
); }, enableSorting: true, enableHiding: false, }, // { // accessorKey: "vendorName", // header: ({ column }) => ( // // ), // cell: ({ row }) => { // const vendorName = row.getValue("vendorName") as string; // return ( //
// {vendorName || "N/A"} //
// ); // }, // enableSorting: true, // enableHiding: false, // }, // { // accessorKey: "vendorCode", // header: ({ column }) => ( // // ), // cell: ({ row }) => { // const vendorCode = row.getValue("vendorCode") as string; // return ( //
// {vendorCode || "N/A"} //
// ); // }, // enableSorting: true, // enableHiding: true, // }, // { // accessorKey: "materialCode", // header: ({ column }) => ( // // ), // cell: ({ row }) => { // const materialCode = row.getValue("materialCode") as string; // return ( //
// {materialCode || "N/A"} //
// ); // }, // enableSorting: true, // enableHiding: true, // }, // { // accessorKey: "itemName", // header: ({ column }) => ( // // ), // cell: ({ row }) => { // const itemName = row.getValue("itemName") as string; // return ( //
// // // // // {itemName || "N/A"} // // // //

{itemName || "N/A"}

//
//
//
//
// ); // }, // enableSorting: true, // enableHiding: true, // }, { accessorKey: "description", header: ({ column }) => ( ), cell: ({ row }) => { const description = row.getValue("description") as string; return (
{description || "N/A"}

{description || "N/A"}

); }, enableSorting: true, enableHiding: true, }, { accessorKey: "projNm", header: ({ column }) => ( ), cell: ({ row }) => { const projNm = row.getValue("projNm") as string; return (
{projNm || "N/A"}

{projNm || "N/A"}

); }, enableSorting: true, enableHiding: true, }, // { // accessorKey: "quotationCode", // header: ({ column }) => ( // // ), // cell: ({ row }) => { // const quotationCode = row.getValue("quotationCode") as string; // return ( //
// {quotationCode || "미부여"} //
// ); // }, // enableSorting: true, // enableHiding: true, // }, // { // accessorKey: "quotationVersion", // header: ({ column }) => ( // // ), // cell: ({ row }) => { // const quotationVersion = row.getValue("quotationVersion") as number; // return ( //
// {quotationVersion || 1} //
// ); // }, // enableSorting: true, // enableHiding: true, // }, { id: "items", header: ({ column }) => ( ), cell: ({ row }) => { const quotation = row.original const itemCount = quotation.itemCount || 0 const handleClick = () => { const rfq = { id: quotation.rfqId, rfqCode: quotation.rfqCode, status: quotation.rfqStatus, rfqType: "SHIP" as const, // 기본값 } openItemsDialog(rfq) } return (

{itemCount > 0 ? `${itemCount}개 아이템 보기` : "아이템 없음"}

) }, enableSorting: false, enableHiding: true, }, { id: "attachments", header: ({ column }) => ( ), cell: ({ row }) => { const quotation = row.original const attachmentCount = quotation.attachmentCount || 0 const handleClick = () => { openAttachmentsSheet(quotation.rfqId) } return (

{attachmentCount > 0 ? `${attachmentCount}개 첨부파일 보기` : "첨부파일 없음"}

) }, enableSorting: false, enableHiding: true, }, { accessorKey: "status", header: ({ column }) => ( ), cell: ({ row }) => { const status = row.getValue("status") as string; const statusConfig = TECH_SALES_QUOTATION_STATUS_CONFIG[status as keyof typeof TECH_SALES_QUOTATION_STATUS_CONFIG] || { label: status, variant: "secondary" as const }; return (
{statusConfig.label}
); }, enableSorting: true, enableHiding: false, filterFn: (row, id, value) => { return value.includes(row.getValue(id)); }, }, { accessorKey: "currency", header: ({ column }) => ( ), cell: ({ row }) => { const currency = row.getValue("currency") as string; return (
{currency || "N/A"}
); }, enableSorting: true, enableHiding: true, }, { accessorKey: "totalPrice", header: ({ column }) => ( ), cell: ({ row }) => { const totalPrice = row.getValue("totalPrice") as string; const currency = row.getValue("currency") as string; if (!totalPrice || totalPrice === "0") { return (
미입력
); } return (
{formatCurrency(parseFloat(totalPrice), currency || "USD")}
); }, enableSorting: true, enableHiding: true, }, { accessorKey: "validUntil", header: ({ column }) => ( ), cell: ({ row }) => { const validUntil = row.getValue("validUntil") as Date; return (
{validUntil ? formatDate(validUntil) : "N/A"}
); }, enableSorting: true, enableHiding: true, }, { accessorKey: "submittedAt", header: ({ column }) => ( ), cell: ({ row }) => { const submittedAt = row.getValue("submittedAt") as Date; return (
{submittedAt ? formatDateTime(submittedAt) : "미제출"}
); }, enableSorting: true, enableHiding: true, }, // { // accessorKey: "acceptedAt", // header: ({ column }) => ( // // ), // cell: ({ row }) => { // const acceptedAt = row.getValue("acceptedAt") as Date; // return ( //
// // {acceptedAt ? formatDateTime(acceptedAt) : "미승인"} // //
// ); // }, // enableSorting: true, // enableHiding: true, // }, { accessorKey: "dueDate", header: ({ column }) => ( ), cell: ({ row }) => { const dueDate = row.getValue("dueDate") as Date; const isOverdue = dueDate && new Date() > new Date(dueDate); return (
{dueDate ? formatDate(dueDate) : "N/A"}
); }, enableSorting: true, enableHiding: true, }, // { // accessorKey: "rejectionReason", // header: ({ column }) => ( // // ), // cell: ({ row }) => { // const rejectionReason = row.getValue("rejectionReason") as string; // return ( //
// {rejectionReason ? ( // // // // // {rejectionReason} // // // //

{rejectionReason}

//
//
//
// ) : ( // N/A // )} //
// ); // }, // enableSorting: false, // enableHiding: true, // }, { accessorKey: "createdAt", header: ({ column }) => ( ), cell: ({ row }) => { const createdAt = row.getValue("createdAt") as Date; return (
{createdAt ? formatDateTime(createdAt) : "N/A"}
); }, enableSorting: true, enableHiding: true, }, { accessorKey: "updatedAt", header: ({ column }) => ( ), cell: ({ row }) => { const updatedAt = row.getValue("updatedAt") as Date; return (
{updatedAt ? formatDateTime(updatedAt) : "N/A"}
); }, enableSorting: true, enableHiding: true, }, // { // accessorKey: "createdByName", // header: ({ column }) => ( // // ), // cell: ({ row }) => { // const createdByName = row.getValue("createdByName") as string; // return ( //
// {createdByName || "N/A"} //
// ); // }, // enableSorting: true, // enableHiding: true, // }, // { // accessorKey: "updatedByName", // header: ({ column }) => ( // // ), // cell: ({ row }) => { // const updatedByName = row.getValue("updatedByName") as string; // return ( //
// {updatedByName || "N/A"} //
// ); // }, // enableSorting: true, // enableHiding: true, // }, { id: "actions", header: "작업", cell: ({ row }) => { const quotation = row.original; const rfqCode = quotation.rfqCode || "N/A"; const tooltipText = `${rfqCode} 견적서 작성`; const isRejected = quotation.status === "Rejected"; const isAccepted = quotation.status === "Accepted"; const isDisabled = isRejected || isAccepted; return (

{isRejected ? "거절된 견적서는 편집할 수 없습니다" : isAccepted ? "승인된 견적서는 편집할 수 없습니다" : tooltipText}

); }, enableSorting: false, enableHiding: false, }, { id: "contacts", header: "담당자", cell: ({ row }) => { const quotation = row.original; const handleClick = () => { openContactsDialog(quotation.id, quotation.vendorName); }; return (

RFQ 발송 담당자 보기

); }, enableSorting: false, enableHiding: true, }, ]; }