added advance transaction records

This commit is contained in:
pramod.mahajan 2025-11-05 23:04:27 +05:30
parent bac9f25df1
commit 8229a44a74
2 changed files with 69 additions and 35 deletions

View File

@ -2,16 +2,53 @@ import React from "react";
import { useExpenseTransactions } from "../../hooks/useExpense"; import { useExpenseTransactions } from "../../hooks/useExpense";
import Error from "../common/Error"; import Error from "../common/Error";
import { formatUTCToLocalTime } from "../../utils/dateUtils"; import { formatUTCToLocalTime } from "../../utils/dateUtils";
import Loader, { SpinnerLoader } from "../common/Loader";
const AdvancePaymentList = ({ employeeId }) => { const AdvancePaymentList = ({ employeeId }) => {
const { data, isError, isLoading, error } = const { data, isError, isLoading, error, isFetching } =
useExpenseTransactions(employeeId); useExpenseTransactions(employeeId, { enabled: !!employeeId });
const records = data?.json || []; // Handle no employee selected
if (!employeeId) {
return (
<div
className="d-flex justify-content-center align-items-center"
style={{ height: "200px" }}
>
<p className="text-muted m-0">Please select an employee</p>
</div>
);
}
// Handle loading state
if (isLoading || isFetching) {
return (
<div
className="d-flex justify-content-center align-items-center"
style={{ height: "200px" }}
>
<SpinnerLoader/>
</div>
);
}
// Handle error state
if (isError) {
return (
<div className="text-center py-3">
{error?.status === 404 ? (
"No advance payment transactions found."
) : (
<Error error={error} />
)}
</div>
);
}
const records = Array.isArray(data) ? data : [];
let currentBalance = 0; let currentBalance = 0;
const rowsWithBalance = records.map((r) => {
const rowsWithBalance = data?.map((r) => {
const isCredit = r.amount > 0; const isCredit = r.amount > 0;
const credit = isCredit ? r.amount : 0; const credit = isCredit ? r.amount : 0;
const debit = !isCredit ? Math.abs(r.amount) : 0; const debit = !isCredit ? Math.abs(r.amount) : 0;
@ -19,8 +56,8 @@ const AdvancePaymentList = ({ employeeId }) => {
return { return {
id: r.id, id: r.id,
description: r.title, description: r.title || "-",
projectName: r.project?.name, projectName: r.project?.name || "-",
createdAt: r.createdAt, createdAt: r.createdAt,
credit, credit,
debit, debit,
@ -33,41 +70,44 @@ const AdvancePaymentList = ({ employeeId }) => {
{ {
key: "credit", key: "credit",
label: ( label: (
<span> <>
Credit (<i className="bx bx-rupee text-success"></i>) Credit <i className="bx bx-rupee text-success"></i>
</span> </>
), ),
align: "text-end", align: "text-end",
}, },
{ {
key: "debit", key: "debit",
label: ( label: (
<span> <>
Debit (<i className="bx bx-rupee text-danger"></i>) Debit <i className="bx bx-rupee text-danger"></i>
</span> </>
), ),
align: "text-end", align: "text-end",
}, },
{ {
key: "balance", key: "balance",
label: ( label: (
<span> <>
Balance <i className="bi bi-currency-rupee text-primary"></i> Balance <i className="bi bi-currency-rupee text-primary"></i>
</span> </>
), ),
align: "text-end fw-bold", align: "text-end fw-bold",
}, },
]; ];
if (isLoading) return <div>Loading...</div>; // Handle empty records
if (isError){ if (rowsWithBalance.length === 0) {
return <div>{error.status === 404 ? "No advance payment transactions found." : <Error error={error}/>}</div> return (
}; <div className="text-center text-muted py-3">
No advance payment records found.
</div>
);
}
return ( return (
<div className="row "> <div className="table-responsive">
<div className="table-responsive"> <table className="table align-middle">
{employeeId ? ( <table className="table align-middle">
<thead className="table_header_border"> <thead className="table_header_border">
<tr> <tr>
{columns.map((col) => ( {columns.map((col) => (
@ -78,17 +118,16 @@ const AdvancePaymentList = ({ employeeId }) => {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{rowsWithBalance?.map((row) => ( {rowsWithBalance.map((row) => (
<tr key={row.id}> <tr key={row.id}>
{columns.map((col) => ( {columns.map((col) => (
<td key={col.key} className={`${col.align} p-2`}> <td key={col.key} className={`${col.align} p-2`}>
{["balance", "credit", "debit"].includes(col.key) ? ( {["balance", "credit", "debit"].includes(col.key) ? (
row[col.key].toLocaleString("en-IN", { <span>
style: "currency", {row[col.key].toLocaleString("en-IN")}
currency: "INR", </span>
})
) : ( ) : (
<div className="d-flex flex-column text-start "> <div className="d-flex flex-column text-start">
<small className="text-muted"> <small className="text-muted">
{formatUTCToLocalTime(row.createdAt)} {formatUTCToLocalTime(row.createdAt)}
</small> </small>
@ -114,12 +153,7 @@ const AdvancePaymentList = ({ employeeId }) => {
</td> </td>
</tr> </tr>
</tfoot> </tfoot>
</table>):( </table>
<div className="d-flex justify-content-center align-items-center" style={{ height: "200px" }}>
<p className="text-muted m-0">Please Select Employee</p>
</div>
)}
</div>
</div> </div>
); );
}; };

View File

@ -26,7 +26,7 @@ export const SpinnerLoader = ()=>{
<div className="spinner-border text-primary mb-3" role="status"> <div className="spinner-border text-primary mb-3" role="status">
<span className="visually-hidden">Loading...</span> <span className="visually-hidden">Loading...</span>
</div> </div>
<p className="text-secondary mb-0">Loading attendance data...</p> <p className="text-secondary mb-0">Loading data... Please wait</p>
</div> </div>
) )
} }