Update the views in example.reporter-extension.sql for void payment type.
authorJason Stephenson <jason@sigio.com>
Wed, 30 Oct 2013 23:43:30 +0000 (19:43 -0400)
committerJason Stephenson <jason@sigio.com>
Thu, 7 Nov 2013 22:03:06 +0000 (17:03 -0500)
Signed-off-by: Jason Stephenson <jason@sigio.com>
Open-ILS/src/sql/Pg/example.reporter-extension.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.money.void_payment.sql

index aaf2b23..be153d5 100644 (file)
@@ -250,7 +250,6 @@ CREATE OR REPLACE VIEW money.open_circ_balance_by_owning_lib AS
                JOIN asset.copy cp ON (circ.target_copy = cp.id) 
                JOIN asset.call_number cn ON (cn.id = cp.call_number) 
          WHERE circ.xact_finish IS NULL
-               AND NOT bill.voided
          GROUP BY 1,2,3
          ORDER BY 1,2,3;
 
@@ -276,7 +275,6 @@ CREATE OR REPLACE VIEW money.open_circ_balance_by_circ_and_owning_lib AS
                JOIN asset.copy cp ON (circ.target_copy = cp.id) 
                JOIN asset.call_number cn ON (cn.id = cp.call_number) 
          WHERE circ.xact_finish IS NULL
-               AND NOT bill.voided
          GROUP BY 1,2,3,4
          ORDER BY 1,2,3,4;
 
@@ -304,7 +302,6 @@ CREATE OR REPLACE VIEW money.open_circ_balance_by_usr_home_and_owning_lib AS
                JOIN asset.call_number cn ON (cn.id = cp.call_number) 
                JOIN actor.usr usr ON (circ.usr = usr.id) 
          WHERE circ.xact_finish IS NULL
-               AND NOT bill.voided
          GROUP BY 1,2,3,4
          ORDER BY 1,2,3,4;
 
index 61c3d39..7dfdf9f 100644 (file)
@@ -194,4 +194,68 @@ SET total_paid = xs.payment,
 FROM xact_summary xs
 WHERE xs.xact = id;
 
+-- Replace some other views that use the money.billing table.  These
+-- appear in example.reporter-extension.sql, and therefore may not be
+-- installed at all sites.  For that reason, we wrap the CREATE OR
+-- REPLACE statement in a check to see if they already exist.
+DO $$
+BEGIN
+IF EXISTS(SELECT viewname FROM pg_views WHERE schemaname = 'money' AND viewname = 'open_circ_balance_by_owning_lib')
+THEN
+CREATE OR REPLACE VIEW money.open_circ_balance_by_owning_lib AS
+       SELECT  circ.id,
+               cn.owning_lib,
+               bill.billing_type,
+               SUM(bill.amount) AS billed
+         FROM  action.circulation circ
+               JOIN money.billing bill ON (circ.id = bill.xact) 
+               JOIN asset.copy cp ON (circ.target_copy = cp.id) 
+               JOIN asset.call_number cn ON (cn.id = cp.call_number) 
+         WHERE circ.xact_finish IS NULL
+         GROUP BY 1,2,3
+         ORDER BY 1,2,3;
+END IF;
+END$$;
+
+DO $$
+BEGIN
+IF EXISTS(SELECT viewname FROM pg_views WHERE schemaname = 'money' AND viewname = 'open_circ_balance_by_circ_and_owning_lib')
+THEN
+CREATE OR REPLACE VIEW money.open_circ_balance_by_circ_and_owning_lib AS
+       SELECT  circ.id,
+               circ.circ_lib,
+               cn.owning_lib,
+               bill.billing_type,
+               SUM(bill.amount) AS billed
+         FROM  action.circulation circ
+               JOIN money.billing bill ON (circ.id = bill.xact) 
+               JOIN asset.copy cp ON (circ.target_copy = cp.id) 
+               JOIN asset.call_number cn ON (cn.id = cp.call_number) 
+         WHERE circ.xact_finish IS NULL
+         GROUP BY 1,2,3,4
+         ORDER BY 1,2,3,4;
+END IF;
+END$$;
+
+DO $$
+BEGIN
+IF EXISTS(SELECT viewname FROM pg_views WHERE schemaname = 'money' AND viewname = 'open_circ_balance_by_usr_home_and_owning_lib')
+THEN
+CREATE OR REPLACE VIEW money.open_circ_balance_by_usr_home_and_owning_lib AS
+       SELECT  circ.id,
+               usr.home_ou,
+               cn.owning_lib,
+               bill.billing_type,
+               SUM(bill.amount) AS billed
+         FROM  action.circulation circ
+               JOIN money.billing bill ON (circ.id = bill.xact) 
+               JOIN asset.copy cp ON (circ.target_copy = cp.id) 
+               JOIN asset.call_number cn ON (cn.id = cp.call_number) 
+               JOIN actor.usr usr ON (circ.usr = usr.id) 
+         WHERE circ.xact_finish IS NULL
+         GROUP BY 1,2,3,4
+         ORDER BY 1,2,3,4;
+END IF;
+END$$;
+
 COMMIT;