money.billable_xact_with_void_summary (view)
|
This is a database view, not a base table. It has no triggers, indexes, or FK constraints of its own. Querying this view may be more efficient than joining the underlying tables directly. |
Columns
| Column | Type | Nullable | Notes |
|---|---|---|---|
id |
|
Yes |
|
usr |
|
Yes |
|
xact_start |
|
Yes |
|
xact_finish |
|
Yes |
|
total_paid |
|
Yes |
|
last_payment_ts |
|
Yes |
|
last_payment_note |
|
Yes |
|
last_payment_type |
|
Yes |
|
total_owed |
|
Yes |
|
last_billing_ts |
|
Yes |
|
last_billing_note |
|
Yes |
|
last_billing_type |
|
Yes |
|
balance_owed |
|
Yes |
|
xact_type |
|
Yes |
View Definition
SELECT xact.id,
xact.usr,
xact.xact_start,
xact.xact_finish,
sum(credit.amount) AS total_paid,
max(credit.payment_ts) AS last_payment_ts,
last(credit.note) AS last_payment_note,
last(credit.payment_type) AS last_payment_type,
sum(debit.amount) AS total_owed,
max(debit.billing_ts) AS last_billing_ts,
last(debit.note) AS last_billing_note,
last(debit.billing_type) AS last_billing_type,
COALESCE(sum(debit.amount), 0::numeric) - COALESCE(sum(credit.amount), 0::numeric) AS balance_owed,
p.relname AS xact_type
FROM money.billable_xact xact
JOIN pg_class p ON xact.tableoid = p.oid
LEFT JOIN money.billing debit ON xact.id = debit.xact
LEFT JOIN money.payment_view credit ON xact.id = credit.xact
GROUP BY xact.id, xact.usr, xact.xact_start, xact.xact_finish, p.relname
ORDER BY (max(debit.billing_ts)), (max(credit.payment_ts));