diff --git a/src/pages/accounting/AccountingBankingPage.tsx b/src/pages/accounting/AccountingBankingPage.tsx index 4a40f07..3ccf99e 100644 --- a/src/pages/accounting/AccountingBankingPage.tsx +++ b/src/pages/accounting/AccountingBankingPage.tsx @@ -140,7 +140,7 @@ export default function AccountingBankingPage() { const [selected, setSelected] = useState>(new Set()); const { data: accounts = [] } = useQuery({ - queryKey: ["accounts", cid], + queryKey: ["accounts", cid, "banking"], enabled: !!cid, queryFn: async () => // Archived accounts are hidden from Banking (cards + category pickers) diff --git a/src/pages/accounting/AccountingBillsPage.tsx b/src/pages/accounting/AccountingBillsPage.tsx index 775be71..4c5e26e 100644 --- a/src/pages/accounting/AccountingBillsPage.tsx +++ b/src/pages/accounting/AccountingBillsPage.tsx @@ -85,11 +85,16 @@ export default function AccountingBillsPage() { .or(`association_id.eq.${associationId},association_ids.cs.{${associationId}}`) .order("name")).data ?? [], }); + // Bill line categories: expenses plus asset/equity/liability accounts + // (e.g. prepaid insurance, reserve-funded repairs to an equity component) — + // not just expense accounts. Bank accounts are excluded. const { data: expenseAccounts = [] } = useQuery({ - queryKey: ["expense-accounts", cid], + queryKey: ["bill-category-accounts", cid], enabled: !!cid, queryFn: async () => - (await accounting.from("accounts").select("id,name,code,type").eq("company_id", cid).eq("type", "expense").eq("is_archived", false).order("code")).data ?? [], + (await accounting.from("accounts").select("id,name,code,type") + .eq("company_id", cid).in("type", ["expense", "asset", "equity", "liability"]) + .eq("is_bank", false).eq("is_archived", false).order("type").order("code")).data ?? [], }); const enriched = useMemo( @@ -351,7 +356,7 @@ export default function AccountingBillsPage() { const [paying, setPaying] = useState(false); const { data: bankAccounts = [] } = useQuery({ - queryKey: ["bank-accounts", cid], + queryKey: ["bank-accounts", cid, "bills-payment"], enabled: !!cid, queryFn: async () => // Payment accounts: banks plus equity accounts (e.g. reserve components diff --git a/src/pages/accounting/AccountingBudgetDetailPage.tsx b/src/pages/accounting/AccountingBudgetDetailPage.tsx index 35fc5f3..6174c12 100644 --- a/src/pages/accounting/AccountingBudgetDetailPage.tsx +++ b/src/pages/accounting/AccountingBudgetDetailPage.tsx @@ -50,7 +50,7 @@ export default function AccountingBudgetDetailPage({ basePath = "/dashboard/acco }); const { data: accounts = [] } = useQuery({ - queryKey: ["accounts", cid], + queryKey: ["accounts", cid, "budget"], enabled: !!cid, queryFn: async () => (await accounting.from("accounts").select("*").eq("company_id", cid).eq("is_archived", false).order("code")).data ?? [], diff --git a/src/pages/accounting/AccountingChartOfAccountsPage.tsx b/src/pages/accounting/AccountingChartOfAccountsPage.tsx index 1731357..0eb120c 100644 --- a/src/pages/accounting/AccountingChartOfAccountsPage.tsx +++ b/src/pages/accounting/AccountingChartOfAccountsPage.tsx @@ -79,7 +79,9 @@ export default function AccountingChartOfAccountsPage() { // ── Queries ── const { data: accounts = [] } = useQuery({ - queryKey: ["accounts", cid], + // Distinct key: this is the only list that INCLUDES archived accounts, so + // it must not share a cache with the active-only pickers on other pages. + queryKey: ["accounts", cid, "coa-all"], enabled: !!cid, queryFn: async () => (await accounting.from("accounts").select("*").eq("company_id", cid).order("code", { ascending: true })).data ?? [], diff --git a/src/pages/accounting/AccountingDepositsPage.tsx b/src/pages/accounting/AccountingDepositsPage.tsx index 875ef42..3cc7713 100644 --- a/src/pages/accounting/AccountingDepositsPage.tsx +++ b/src/pages/accounting/AccountingDepositsPage.tsx @@ -46,7 +46,7 @@ export default function AccountingDepositsPage() { }, [cid]); const { data: bankAccounts = [] } = useQuery({ - queryKey: ["bank-accounts", cid], + queryKey: ["bank-accounts", cid, "deposits"], enabled: !!cid, queryFn: async () => (await accounting.from("accounts").select("id,name,code,balance").eq("company_id", cid).eq("is_bank", true).eq("is_archived", false).order("code")).data ?? [], diff --git a/src/pages/accounting/AccountingExpensesPage.tsx b/src/pages/accounting/AccountingExpensesPage.tsx index 7d808aa..21b6e6f 100644 --- a/src/pages/accounting/AccountingExpensesPage.tsx +++ b/src/pages/accounting/AccountingExpensesPage.tsx @@ -68,7 +68,7 @@ export default function AccountingExpensesPage() { }); const { data: accounts = [] } = useQuery({ - queryKey: ["bank-accounts", cid], + queryKey: ["bank-accounts", cid, "expenses-payment"], enabled: !!cid, // Paid-through accounts: banks plus equity accounts; archived hidden. queryFn: async () => (await accounting.from("accounts").select("id,name").eq("company_id", cid).or("is_bank.eq.true,type.eq.equity").eq("is_archived", false).order("name")).data ?? [], diff --git a/src/pages/accounting/AccountingGeneralLedgerPage.tsx b/src/pages/accounting/AccountingGeneralLedgerPage.tsx index ef7b7ad..ae70de1 100644 --- a/src/pages/accounting/AccountingGeneralLedgerPage.tsx +++ b/src/pages/accounting/AccountingGeneralLedgerPage.tsx @@ -54,7 +54,7 @@ export default function AccountingGeneralLedgerPage() { }); const { data: accounts = [] } = useQuery({ - queryKey: ["accounts", cid], + queryKey: ["accounts", cid, "gl"], enabled: !!cid, queryFn: async () => (await accounting.from("accounts").select("id, code, name, type").eq("company_id", cid).order("code")).data ?? [], diff --git a/src/pages/accounting/AccountingInvoicesPage.tsx b/src/pages/accounting/AccountingInvoicesPage.tsx index 2e9731a..ac05f1c 100644 --- a/src/pages/accounting/AccountingInvoicesPage.tsx +++ b/src/pages/accounting/AccountingInvoicesPage.tsx @@ -123,7 +123,7 @@ export default function AccountingInvoicesPage() { const [paying, setPaying] = useState(false); const { data: depositAccounts = [] } = useQuery({ - queryKey: ["deposit-accounts", cid], + queryKey: ["deposit-accounts", cid, "invoices"], enabled: !!cid, queryFn: async () => { const { data } = await accounting.from("accounts") diff --git a/src/pages/accounting/AccountingJournalEntriesPage.tsx b/src/pages/accounting/AccountingJournalEntriesPage.tsx index 1221535..4624427 100644 --- a/src/pages/accounting/AccountingJournalEntriesPage.tsx +++ b/src/pages/accounting/AccountingJournalEntriesPage.tsx @@ -53,7 +53,7 @@ export default function AccountingJournalEntriesPage() { }); const { data: accounts = [] } = useQuery({ - queryKey: ["accounts", cid], + queryKey: ["accounts", cid, "je"], enabled: !!cid, queryFn: async () => (await accounting.from("accounts").select("*").eq("company_id", cid).eq("is_archived", false).order("code")).data ?? [], diff --git a/src/pages/accounting/AccountingOpeningBalancesPage.tsx b/src/pages/accounting/AccountingOpeningBalancesPage.tsx index 18fe2f8..ff17e6e 100644 --- a/src/pages/accounting/AccountingOpeningBalancesPage.tsx +++ b/src/pages/accounting/AccountingOpeningBalancesPage.tsx @@ -35,7 +35,7 @@ export default function AccountingOpeningBalancesPage() { const qc = useQueryClient(); const { data: accounts = [] } = useQuery({ - queryKey: ["accounts", cid], + queryKey: ["accounts", cid, "ob"], enabled: !!cid, queryFn: async () => (await accounting.from("accounts").select("id,name,code,type").eq("company_id", cid).eq("is_archived", false).order("code", { ascending: true })).data ?? [], }); diff --git a/src/pages/accounting/AccountingReceivePaymentsPage.tsx b/src/pages/accounting/AccountingReceivePaymentsPage.tsx index 51e07fc..adbfb02 100644 --- a/src/pages/accounting/AccountingReceivePaymentsPage.tsx +++ b/src/pages/accounting/AccountingReceivePaymentsPage.tsx @@ -39,7 +39,7 @@ export default function AccountingReceivePaymentsPage() { const [initialized, setInitialized] = useState(false); const { data: bankAccounts = [] } = useQuery({ - queryKey: ["bank-accounts", cid], + queryKey: ["bank-accounts", cid, "receive-payments"], enabled: !!cid, queryFn: async () => (await accounting.from("accounts").select("id,name,code,balance").eq("company_id", cid).eq("is_bank", true).eq("is_archived", false).order("name")).data ?? [], diff --git a/src/pages/accounting/AccountingReconcileDetailPage.tsx b/src/pages/accounting/AccountingReconcileDetailPage.tsx index 73c753a..408e00c 100644 --- a/src/pages/accounting/AccountingReconcileDetailPage.tsx +++ b/src/pages/accounting/AccountingReconcileDetailPage.tsx @@ -122,7 +122,7 @@ export default function AccountingReconcileDetailPage() { const priorReconDate: string | null = lastCompleted?.statement_end_date ?? null; const { data: allAccounts = [] } = useQuery({ - queryKey: ["accounts", cid], + queryKey: ["accounts", cid, "recon"], enabled: !!cid, queryFn: async () => (await accounting.from("accounts").select("id,name,type,is_bank").eq("company_id", cid).eq("is_archived", false).order("name")).data ?? [], diff --git a/src/pages/accounting/AccountingReportsPage.tsx b/src/pages/accounting/AccountingReportsPage.tsx index c171ce6..817a53c 100644 --- a/src/pages/accounting/AccountingReportsPage.tsx +++ b/src/pages/accounting/AccountingReportsPage.tsx @@ -1920,7 +1920,7 @@ function BudgetVsActuals({ companyId, from, to, currency, companyName, rangeLabe const actualsLabel = `${actFrom} to ${actTo}`; const { data: accounts = [] } = useQuery({ - queryKey: ["accounts", companyId], + queryKey: ["accounts", companyId, "budget-actuals"], enabled: !!companyId, queryFn: async () => (await accounting.from("accounts").select("*").eq("company_id", companyId).eq("is_archived", false).order("code")).data ?? [], }); diff --git a/src/pages/accounting/AccountingSalesReceiptsPage.tsx b/src/pages/accounting/AccountingSalesReceiptsPage.tsx index e8bc1cb..78b823b 100644 --- a/src/pages/accounting/AccountingSalesReceiptsPage.tsx +++ b/src/pages/accounting/AccountingSalesReceiptsPage.tsx @@ -63,7 +63,7 @@ export default function AccountingSalesReceiptsPage() { }); const { data: depositAccounts = [] } = useQuery({ - queryKey: ["deposit-accounts", cid], + queryKey: ["deposit-accounts", cid, "sales-receipts"], enabled: !!cid, queryFn: async () => { const { data } = await accounting