import React from "react"; import { useExpenseTransactions } from "../../hooks/useExpense"; import Error from "../common/Error"; import { formatUTCToLocalTime } from "../../utils/dateUtils"; const AdvancePaymentList = ({ employeeId }) => { const { data, isError, isLoading, error } = useExpenseTransactions(employeeId); const records = data?.json || []; let currentBalance = 0; const rowsWithBalance = data?.map((r) => { const isCredit = r.amount > 0; const credit = isCredit ? r.amount : 0; const debit = !isCredit ? Math.abs(r.amount) : 0; currentBalance += credit - debit; return { id: r.id, description: r.title, projectName: r.project?.name, createdAt: r.createdAt, credit, debit, balance: currentBalance, }; }); const columns = [ { key: "description", label: "Description", align: "text-start" }, { key: "credit", label: ( Credit () ), align: "text-end", }, { key: "debit", label: ( Debit () ), align: "text-end", }, { key: "balance", label: ( Balance ), align: "text-end fw-bold", }, ]; if (isLoading) return
Loading...
; if (isError){ return
{error.status === 404 ? "No advance payment transactions found." : }
}; return (
{employeeId ? ( {columns.map((col) => ( ))} {rowsWithBalance?.map((row) => ( {columns.map((col) => ( ))} ))}
{col.label}
{["balance", "credit", "debit"].includes(col.key) ? ( row[col.key].toLocaleString("en-IN", { style: "currency", currency: "INR", }) ) : (
{formatUTCToLocalTime(row.createdAt)} {row.projectName} {row.description}
)}
Final Balance {currentBalance.toLocaleString("en-IN", { style: "currency", currency: "INR", })}
):(

Please Select Employee

)}
); }; export default AdvancePaymentList;