From 5693d7b4511cd7757afb814830725707f22ba7f2 Mon Sep 17 00:00:00 2001 From: Bill Ballou Date: Sun, 22 Feb 2026 18:26:19 -0500 Subject: [PATCH] Add year-end tax report queries for period-specific reporting Adds date-parameterized SQL queries for Income Statement, Expense Detail, Vendor Payment Summary, and General Ledger. These filter TransactionLines by date range instead of using cumulative balances, enabling tax year and other period-specific financial reports. --- references/queries.md | 68 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/references/queries.md b/references/queries.md index 61e77bd..6e268de 100644 --- a/references/queries.md +++ b/references/queries.md @@ -177,6 +177,74 @@ WHERE b.Status IN ('Open', 'Partial') ORDER BY b.DueDate ``` +## Year-End Tax Reports + +Date-parameterized queries for tax year reporting. Replace `{start_date}` and `{end_date}` with Unix timestamps (e.g., 2025: start=1735776000, end=1767312000). + +### Period Income Statement (P&L) + +Sums TransactionLines by Income/Expense account for a date range (Schedule C core data): + +```sql +SELECT a.Code, a.Name, a.Type, + SUM(tl.Debit) as Debits, SUM(tl.Credit) as Credits +FROM TransactionLines tl +JOIN Transactions t ON tl.Transaction = t.id +JOIN Accounts a ON tl.Account = a.id +WHERE a.Type IN ('Income', 'Expense') + AND t.Date >= {start_date} AND t.Date < {end_date} +GROUP BY a.Code, a.Name, a.Type +ORDER BY a.Type DESC, a.Code +``` + +### Period Expense Detail + +All expense transactions with individual line items, grouped by account: + +```sql +SELECT t.Date, a.Code, a.Name, t.Description, t.Reference, tl.Debit, tl.Credit +FROM TransactionLines tl +JOIN Transactions t ON tl.Transaction = t.id +JOIN Accounts a ON tl.Account = a.id +WHERE a.Type = 'Expense' + AND t.Date >= {start_date} AND t.Date < {end_date} +ORDER BY a.Code, t.Date +``` + +### Vendor Payment Summary + +Total payments per vendor for 1099 determination ($600+ threshold): + +```sql +SELECT v.Name as Vendor, COUNT(bp.id) as Payments, SUM(bp.Amount) as TotalPaid +FROM BillPayments bp +JOIN Bills b ON bp.Bill = b.id +JOIN Vendors v ON b.Vendor = v.id +WHERE bp.PaymentDate >= {start_date} AND bp.PaymentDate < {end_date} +GROUP BY v.Name +ORDER BY TotalPaid DESC +``` + +### Period General Ledger + +All transactions in the period with full detail: + +```sql +SELECT t.Date, t.Description, t.Reference, t.Status, + a.Code, a.Name, tl.Debit, tl.Credit, tl.Memo +FROM TransactionLines tl +JOIN Transactions t ON tl.Transaction = t.id +JOIN Accounts a ON tl.Account = a.id +WHERE t.Date >= {start_date} AND t.Date < {end_date} +ORDER BY t.Date, t.id, a.Code +``` + +### Point-in-Time Balance Sheet / Trial Balance + +Use `Accounts.Balance` (cumulative) for businesses that started tracking in Grist during the reporting year. If prior-year data exists, subtract beginning-of-year balances. See the [Financial Reports](#financial-reports) section for balance queries. + +> **Note**: If `tl.Transaction` JOIN fails due to the reserved word issue, fall back to `get_records` on TransactionLines + programmatic joining. + ## Reconciliation Queries ### Cleared Balance for Bank Account