Reports: archived accounts hidden everywhere except the General Ledger

- fetchAllGLLines filters accounts.is_archived=false, covering P&L, Balance
  Sheet, Cash Flow, Movement of Equity and Income Statement in one place
- Trial Balance, Reserve Fund Schedule and Budget vs Actuals account lists
  exclude archived; Banking page hides archived accounts from cards/pickers
- General Ledger report intentionally keeps archived accounts (history)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-12 20:27:18 -04:00
parent 03d3c5ee8d
commit 920def8826
4 changed files with 9 additions and 3 deletions
@@ -139,7 +139,8 @@ export default function AccountingBankingPage() {
queryKey: ["accounts", cid], queryKey: ["accounts", cid],
enabled: !!cid, enabled: !!cid,
queryFn: async () => queryFn: async () =>
(await accounting.from("accounts").select("*").eq("company_id", cid).order("code")).data ?? [], // Archived accounts are hidden from Banking (cards + category pickers)
(await accounting.from("accounts").select("*").eq("company_id", cid).eq("is_archived", false).order("code")).data ?? [],
}); });
const bankAccounts = useMemo(() => (accounts as any[]).filter((a) => a.is_bank), [accounts]); const bankAccounts = useMemo(() => (accounts as any[]).filter((a) => a.is_bank), [accounts]);
@@ -107,6 +107,9 @@ async function fetchAllGLLines(cid: string, to: string, select: string, from?: s
.from("journal_entry_lines") .from("journal_entry_lines")
.select(select) .select(select)
.eq("journal_entries.company_id", cid) .eq("journal_entries.company_id", cid)
// Archived accounts stay off the financial statements (their history
// remains visible in the General Ledger report, which queries directly).
.eq("accounts.is_archived", false)
.lte("journal_entries.date", to); .lte("journal_entries.date", to);
if (from) q = q.gte("journal_entries.date", from); if (from) q = q.gte("journal_entries.date", from);
const { data, error } = await q.order("id", { ascending: true }).range(offset, offset + GL_PAGE - 1); const { data, error } = await q.order("id", { ascending: true }).range(offset, offset + GL_PAGE - 1);
@@ -128,7 +131,7 @@ function useReportData(cid: string, from: string, to: string) {
const [inv, bills, accs, exp, custs, vends, ob, ytdInv, ytdExp, ytdBills, allBills, glRes, glCumRes, allInvRes, companyRes] = await Promise.all([ const [inv, bills, accs, exp, custs, vends, ob, ytdInv, ytdExp, ytdBills, allBills, glRes, glCumRes, allInvRes, companyRes] = await Promise.all([
accounting.from("invoices").select("number,total,paid_amount,status,issue_date,customers(name)").eq("company_id", cid).gte("issue_date", from).lte("issue_date", to), accounting.from("invoices").select("number,total,paid_amount,status,issue_date,customers(name)").eq("company_id", cid).gte("issue_date", from).lte("issue_date", to),
accounting.from("bills").select("number,total,paid_amount,status,issue_date,due_date,vendors(name)").eq("company_id", cid).gte("issue_date", from).lte("issue_date", to), accounting.from("bills").select("number,total,paid_amount,status,issue_date,due_date,vendors(name)").eq("company_id", cid).gte("issue_date", from).lte("issue_date", to),
accounting.from("accounts").select("id,name,code,type,subtype,balance,is_bank").eq("company_id", cid), accounting.from("accounts").select("id,name,code,type,subtype,balance,is_bank").eq("company_id", cid).eq("is_archived", false),
accounting.from("expenses").select("date,category,amount,vendor_name,vendors(name)").eq("company_id", cid).gte("date", from).lte("date", to), accounting.from("expenses").select("date,category,amount,vendor_name,vendors(name)").eq("company_id", cid).gte("date", from).lte("date", to),
accounting.from("customers").select("id,name,balance,email,phone,property_address,lot_number").eq("company_id", cid).order("name"), accounting.from("customers").select("id,name,balance,email,phone,property_address,lot_number").eq("company_id", cid).order("name"),
accounting.from("vendors").select("id,name").eq("company_id", cid), accounting.from("vendors").select("id,name").eq("company_id", cid),
@@ -1794,7 +1797,7 @@ function BudgetVsActuals({ companyId, from, to, currency, companyName, rangeLabe
const { data: accounts = [] } = useQuery({ const { data: accounts = [] } = useQuery({
queryKey: ["accounts", companyId], queryKey: ["accounts", companyId],
enabled: !!companyId, enabled: !!companyId,
queryFn: async () => (await accounting.from("accounts").select("*").eq("company_id", companyId).order("code")).data ?? [], queryFn: async () => (await accounting.from("accounts").select("*").eq("company_id", companyId).eq("is_archived", false).order("code")).data ?? [],
}); });
const { data: entries = [] } = useQuery({ const { data: entries = [] } = useQuery({
@@ -82,6 +82,7 @@ export function ReserveFundReport({
.select("id,name,code,type,is_reserve") .select("id,name,code,type,is_reserve")
.eq("company_id", companyId) .eq("company_id", companyId)
.eq("is_reserve", true) .eq("is_reserve", true)
.eq("is_archived", false) // archived accounts stay off reports
.order("code", { ascending: true }); .order("code", { ascending: true });
return (data ?? []) as ReserveAccount[]; return (data ?? []) as ReserveAccount[];
}, },
@@ -66,6 +66,7 @@ export function TrialBalanceReport({ companyId, companyName, logoUrl }: { compan
.from("accounts") .from("accounts")
.select("id,name,code,type,subtype") .select("id,name,code,type,subtype")
.eq("company_id", companyId) .eq("company_id", companyId)
.eq("is_archived", false) // archived accounts stay off reports (GL report keeps them)
.order("code", { ascending: true }); .order("code", { ascending: true });
return (data ?? []) as Omit<Account, "balance">[]; return (data ?? []) as Omit<Account, "balance">[];
}, },