diff --git a/src/pages/accounting/AccountingCustomerDetailPage.tsx b/src/pages/accounting/AccountingCustomerDetailPage.tsx index a9fd6ce..2ab54b7 100644 --- a/src/pages/accounting/AccountingCustomerDetailPage.tsx +++ b/src/pages/accounting/AccountingCustomerDetailPage.tsx @@ -1,6 +1,6 @@ import { Link, useParams } from "react-router-dom"; import { useQuery, useQueryClient } from "@tanstack/react-query"; -import { useMemo, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import { accounting } from "@/lib/accountingClient"; import { useCompanyId } from "./lib/useCompanyId"; import { Button } from "@/components/ui/button"; @@ -18,9 +18,6 @@ import jsPDF from "jspdf"; import autoTable from "jspdf-autotable"; import { drawReportCoverPage } from "@/lib/reportCover"; -function startOfFY() { - return new Date(new Date().getFullYear(), 0, 1).toISOString().slice(0, 10); -} function today() { return new Date().toLocaleDateString("en-CA", { timeZone: "America/New_York" }); } @@ -44,7 +41,11 @@ export default function AccountingCustomerDetailPage() { const cid = companyId ?? ""; const cur = "USD"; const qc = useQueryClient(); - const [from, setFrom] = useState(startOfFY()); + // Default the ledger/statement to the full history so it matches the main-app + // owner ledger (all-time). Set to the earliest transaction once data loads; + // the user can still narrow the range. "" means "no lower bound" (show all). + const [from, setFrom] = useState(""); + const [fromTouched, setFromTouched] = useState(false); const [to, setTo] = useState(today()); const [drawer, setDrawer] = useState(null); const [editing, setEditing] = useState(false); @@ -140,6 +141,12 @@ export default function AccountingCustomerDetailPage() { return rows; }, [invoices, payments]); + // Default the "From" date to the earliest entry so the full ledger shows + // (matches the main-app owner ledger). Honors a user-chosen range thereafter. + useEffect(() => { + if (!fromTouched && !from && allRows.length) setFrom(allRows[0].date); + }, [allRows, fromTouched, from]); + const openingBalance = useMemo( () => allRows.filter((r) => r.date < from).reduce((s, r) => s + r.debit - r.credit, 0), [allRows, from] @@ -486,7 +493,7 @@ export default function AccountingCustomerDetailPage() { -
setFrom(e.target.value)} className="w-40" />
+
{ setFromTouched(true); setFrom(e.target.value); }} className="w-40" />
setTo(e.target.value)} className="w-40" />