"use client" import { useState } from "react" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Input } from "@/components/ui/input" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { Search, ArrowUpRight, ArrowDownLeft, Calendar } from "lucide-react" interface Transaction { id: string date: string type: "receivable" | "payable" | "payment_received" | "payment_made" entity: string description: string amount: number status: "pending" | "completed" | "overdue" reference?: string } // Mock transaction data const mockTransactions: Transaction[] = [ { id: "1", date: "2024-01-15", type: "receivable", entity: "ABC Electronics", description: "Invoice #INV-001 - Wireless Headphones", amount: 2500, status: "completed", reference: "INV-001", }, { id: "2", date: "2024-01-14", type: "payment_received", entity: "Tech Solutions Inc", description: "Payment received for Invoice #INV-002", amount: 1800, status: "completed", reference: "PAY-001", }, { id: "3", date: "2024-01-13", type: "payable", entity: "Electronics Wholesale Co", description: "Purchase Order #PO-001 - Components", amount: 3200, status: "pending", reference: "PO-001", }, { id: "4", date: "2024-01-12", type: "payment_made", entity: "Global Tech Supplies", description: "Payment for Invoice #SUP-001", amount: 1500, status: "completed", reference: "PAY-002", }, { id: "5", date: "2024-01-11", type: "receivable", entity: "Mobile World", description: "Invoice #INV-003 - Phone Cases", amount: 950, status: "overdue", reference: "INV-003", }, { id: "6", date: "2024-01-10", type: "payable", entity: "Premium Components Ltd", description: "Purchase Order #PO-002 - Premium Parts", amount: 4500, status: "pending", reference: "PO-002", }, ] export function TransactionHistory() { const [searchTerm, setSearchTerm] = useState("") const [typeFilter, setTypeFilter] = useState("all") const [statusFilter, setStatusFilter] = useState("all") const filteredTransactions = mockTransactions.filter((transaction) => { const matchesSearch = transaction.entity.toLowerCase().includes(searchTerm.toLowerCase()) || transaction.description.toLowerCase().includes(searchTerm.toLowerCase()) || (transaction.reference && transaction.reference.toLowerCase().includes(searchTerm.toLowerCase())) const matchesType = typeFilter === "all" || transaction.type === typeFilter const matchesStatus = statusFilter === "all" || transaction.status === statusFilter return matchesSearch && matchesType && matchesStatus }) const getTransactionIcon = (type: string) => { switch (type) { case "receivable": case "payment_received": return case "payable": case "payment_made": return default: return } } const getTransactionColor = (type: string) => { switch (type) { case "receivable": case "payment_received": return "text-green-600" case "payable": case "payment_made": return "text-red-600" default: return "text-foreground" } } const getStatusBadge = (status: string) => { switch (status) { case "completed": return ( Completed ) case "pending": return ( Pending ) case "overdue": return ( Overdue ) default: return ( {status} ) } } return ( Transaction History Complete history of all credit-related transactions {/* Filters */}
setSearchTerm(e.target.value)} className="pl-10" />
{/* Transaction Table */}
Date Type Entity Description Amount Status Reference {filteredTransactions.length === 0 ? ( {searchTerm || typeFilter !== "all" || statusFilter !== "all" ? "No transactions found matching your filters." : "No transactions recorded yet."} ) : ( filteredTransactions.map((transaction) => (
{new Date(transaction.date).toLocaleDateString()}
{getTransactionIcon(transaction.type)} {transaction.type.replace("_", " ")}
{transaction.entity}
{transaction.description}
{transaction.type.includes("receivable") || transaction.type.includes("payment_received") ? "+" : "-"} ${transaction.amount.toLocaleString()}
{getStatusBadge(transaction.status)} {transaction.reference && ( {transaction.reference} )}
)) )}
) }