From: miker Date: Wed, 20 Jun 2007 00:22:36 +0000 (+0000) Subject: adding flattened open transaction view for the reporter; splitting cross-schema views... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a15488d4f05c2bac0fda4127b99220111aa52cea;p=Evergreen.git adding flattened open transaction view for the reporter; splitting cross-schema views out to their own file git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_0@7453 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 644d40495b..eee8720da5 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -609,12 +609,14 @@ + + @@ -2487,6 +2489,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Open-ILS/src/sql/Pg/080.schema.money.sql b/Open-ILS/src/sql/Pg/080.schema.money.sql index fe974c5562..19b8994161 100644 --- a/Open-ILS/src/sql/Pg/080.schema.money.sql +++ b/Open-ILS/src/sql/Pg/080.schema.money.sql @@ -233,47 +233,6 @@ CREATE OR REPLACE VIEW money.billable_xact_summary AS GROUP BY 1,2,3,4,14 ORDER BY MAX(debit.billing_ts), MAX(credit.payment_ts); -CREATE OR REPLACE VIEW money.open_billable_xact_summary AS - SELECT xact.id AS id, - xact.usr AS usr, - xact.xact_start AS xact_start, - xact.xact_finish AS 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) - COALESCE(SUM(credit.amount),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.billing debit ON (xact.id = debit.xact AND debit.voided IS FALSE) - LEFT JOIN money.payment_view credit ON (xact.id = credit.xact AND credit.voided IS FALSE) - WHERE xact.xact_finish IS NULL - GROUP BY 1,2,3,4,14 - ORDER BY MAX(debit.billing_ts), MAX(credit.payment_ts); - - -CREATE OR REPLACE VIEW money.open_usr_summary AS - SELECT usr, - SUM(total_paid) AS total_paid, - SUM(total_owed) AS total_owed, - SUM(balance_owed) AS balance_owed - FROM money.open_billable_xact_summary - GROUP BY 1; - -CREATE OR REPLACE VIEW money.open_usr_circulation_summary AS - SELECT usr, - SUM(total_paid) AS total_paid, - SUM(total_owed) AS total_owed, - SUM(balance_owed) AS balance_owed - FROM money.open_billable_xact_summary - WHERE xact_type = 'circulation' - GROUP BY 1; - CREATE OR REPLACE VIEW money.usr_summary AS SELECT usr, SUM(total_paid) AS total_paid, @@ -323,7 +282,6 @@ CREATE TABLE money.bnm_desk_payment ( ) INHERITS (money.bnm_payment); ALTER TABLE money.bnm_desk_payment ADD PRIMARY KEY (id); - CREATE OR REPLACE VIEW money.desk_payment_view AS SELECT p.*,c.relname AS payment_type FROM money.bnm_desk_payment p diff --git a/Open-ILS/src/sql/Pg/500.view.cross-schema.sql b/Open-ILS/src/sql/Pg/500.view.cross-schema.sql new file mode 100644 index 0000000000..23c2b2c17f --- /dev/null +++ b/Open-ILS/src/sql/Pg/500.view.cross-schema.sql @@ -0,0 +1,68 @@ +BEGIN; + +CREATE OR REPLACE VIEW money.open_billable_xact_summary AS + SELECT xact.id AS id, + xact.usr AS usr, + COALESCE(circ.circ_lib,groc.billing_location) AS billing_location, + xact.xact_start AS xact_start, + xact.xact_finish AS 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) - COALESCE(SUM(credit.amount),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 "action".circulation circ ON (circ.id = xact.id) + LEFT JOIN money.grocery groc ON (groc.id = xact.id) + LEFT JOIN ( + SELECT billing.xact, + billing.voided, + sum(billing.amount) AS amount, + max(billing.billing_ts) AS billing_ts, + last(billing.note) AS note, + last(billing.billing_type) AS billing_type + FROM money.billing + WHERE billing.voided IS FALSE + GROUP BY billing.xact, billing.voided + ) debit ON (xact.id = debit.xact AND debit.voided IS FALSE) + LEFT JOIN ( + SELECT payment_view.xact, + payment_view.voided, + sum(payment_view.amount) AS amount, + max(payment_view.payment_ts) AS payment_ts, + last(payment_view.note) AS note, + last(payment_view.payment_type) AS payment_type + FROM money.payment_view + WHERE payment_view.voided IS FALSE + GROUP BY payment_view.xact, payment_view.voided + ) credit ON (xact.id = credit.xact AND credit.voided IS FALSE) + WHERE xact.xact_finish IS NULL + GROUP BY 1,2,3,4,5,15 + ORDER BY MAX(debit.billing_ts), MAX(credit.payment_ts); + + +CREATE OR REPLACE VIEW money.open_usr_summary AS + SELECT usr, + SUM(total_paid) AS total_paid, + SUM(total_owed) AS total_owed, + SUM(balance_owed) AS balance_owed + FROM money.open_billable_xact_summary + GROUP BY 1; + +CREATE OR REPLACE VIEW money.open_usr_circulation_summary AS + SELECT usr, + SUM(total_paid) AS total_paid, + SUM(total_owed) AS total_owed, + SUM(balance_owed) AS balance_owed + FROM money.open_billable_xact_summary + WHERE xact_type = 'circulation' + GROUP BY 1; + +COMMIT; + diff --git a/Open-ILS/src/sql/Pg/build-db.sh b/Open-ILS/src/sql/Pg/build-db.sh index f52b968cba..b7f5d98007 100755 --- a/Open-ILS/src/sql/Pg/build-db.sh +++ b/Open-ILS/src/sql/Pg/build-db.sh @@ -16,5 +16,7 @@ PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 070.schema.container.sql PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 080.schema.money.sql PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 090.schema.action.sql +PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 500.view.cross-schema.sql + PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 800.fkeys.sql PGUSER=$4 PGHOST=$1 PGPORT=$2 PGDATABASE=$3 psql -f 900.audit-tables.sql diff --git a/Open-ILS/src/sql/Pg/example.reporter-extension.sql b/Open-ILS/src/sql/Pg/example.reporter-extension.sql index 6d1e375c30..88d310e2ac 100644 --- a/Open-ILS/src/sql/Pg/example.reporter-extension.sql +++ b/Open-ILS/src/sql/Pg/example.reporter-extension.sql @@ -118,5 +118,43 @@ SELECT id, WHERE stat_cat = 2; +CREATE OR REPLACE VIEW reporter.classic_current_billing_summary AS +SELECT x.id AS id, + x.usr AS usr, + bl.shortname AS billing_location_shortname, + bl.name AS billing_location_name, + x.billing_location AS billing_location, + c.barcode AS barcode, + u.home_ou AS usr_home_ou, + ul.shortname AS usr_home_ou_shortname, + ul.name AS usr_home_ou_name, + x.xact_start AS xact_start, + x.xact_finish AS xact_finish, + x.xact_type AS xact_type, + x.total_paid AS total_paid, + x.total_owed AS total_owed, + x.balance_owed AS balance_owed, + x.last_payment_ts AS last_payment_ts, + x.last_payment_note AS last_payment_note, + x.last_payment_type AS last_payment_type, + x.last_billing_ts AS last_billing_ts, + x.last_billing_note AS last_billing_note, + x.last_billing_type AS last_billing_type, + paddr.county AS patron_county, + paddr.city AS patron_city, + paddr.post_code AS patron_zip, + g.name AS profile_group, + dem.general_division AS demographic_general_division + FROM money.open_billable_xact_summary x + JOIN actor.org_unit bl ON (x.billing_location = bl.id) + JOIN actor.usr u ON (u.id = x.usr) + JOIN actor.org_unit ul ON (u.home_ou = ul.id) + JOIN actor.card c ON (u.card = c.id) + JOIN permission.grp_tree g ON (u.profile = g.id) + JOIN reporter.demographic dem ON (dem.id = u.id) + JOIN actor.usr_address paddr ON (paddr.id = u.billing_address); + + COMMIT; +