From ec21c9bc54b644f1bf5a1971bdd3b224a2d31a9c Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 15 Jun 2006 14:48:20 +0000 Subject: [PATCH] allowing all-voided bills to show there last billing... even though it was voided git-svn-id: svn://svn.open-ils.org/ILS/trunk@4627 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../Application/Storage/Driver/Pg/dbi.pm | 2 +- Open-ILS/src/sql/Pg/080.schema.money.sql | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm index f9cf0f160e..cbd062172e 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm @@ -115,7 +115,7 @@ #--------------------------------------------------------------------- package money::billable_transaction_summary; - money::billable_transaction_summary->table( 'money.billable_xact_summary' ); + money::billable_transaction_summary->table( 'money.billable_xact_with_void_summary' ); #--------------------------------------------------------------------- package money::open_user_summary; diff --git a/Open-ILS/src/sql/Pg/080.schema.money.sql b/Open-ILS/src/sql/Pg/080.schema.money.sql index d3458ff9e9..60f3a12c6b 100644 --- a/Open-ILS/src/sql/Pg/080.schema.money.sql +++ b/Open-ILS/src/sql/Pg/080.schema.money.sql @@ -78,6 +78,26 @@ CREATE OR REPLACE VIEW money.transaction_payment_summary AS GROUP BY xact ORDER BY MAX(payment_ts); +CREATE OR REPLACE VIEW money.transaction_billing_with_void_summary AS + SELECT xact, + LAST(billing_type) AS last_billing_type, + LAST(note) AS last_billing_note, + MAX(billing_ts) AS last_billing_ts, + SUM(CASE WHEN voided THEN 0 ELSE COALESCE(amount,0) END) AS total_owed + FROM money.billing + GROUP BY xact + ORDER BY MAX(billing_ts); + +CREATE OR REPLACE VIEW money.transaction_payment_with_void_summary AS + SELECT xact, + LAST(payment_type) AS last_payment_type, + LAST(note) AS last_payment_note, + MAX(payment_ts) as last_payment_ts, + SUM(CASE WHEN voided THEN 0 ELSE COALESCE(amount,0) END) AS total_paid + FROM money.payment_view + GROUP BY xact + ORDER BY MAX(payment_ts); + CREATE OR REPLACE VIEW money.open_transaction_billing_type_summary AS SELECT xact, billing_type AS last_billing_type, @@ -111,6 +131,26 @@ CREATE OR REPLACE VIEW money.open_transaction_payment_summary AS GROUP BY xact ORDER BY MAX(payment_ts); +CREATE OR REPLACE VIEW money.billable_xact_with_void_summary AS + SELECT xact.id AS id, + xact.usr AS usr, + xact.xact_start AS xact_start, + xact.xact_finish AS xact_finish, + credit.total_paid, + credit.last_payment_ts, + credit.last_payment_note, + credit.last_payment_type, + debit.total_owed, + debit.last_billing_ts, + debit.last_billing_note, + debit.last_billing_type, + COALESCE(debit.total_owed,0) - COALESCE(credit.total_paid,0) 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.transaction_billing_with_void_summary debit ON (xact.id = debit.xact) + LEFT JOIN money.transaction_payment_with_void_summary credit ON (xact.id = credit.xact); + CREATE OR REPLACE VIEW money.billable_xact_summary AS SELECT xact.id AS id, xact.usr AS usr, -- 2.43.2