Adding billing location to the open billable transaction summary view
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 18 Jun 2007 20:35:35 +0000 (20:35 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 18 Jun 2007 20:35:35 +0000 (20:35 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@7444 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/080.schema.money.sql

index beef509..0674721 100644 (file)
                        <field name="xact" oils_obj:array_position="17" oils_persist:virtual="true" reporter:datatype="link"/>
                        <field name="grocery" oils_obj:array_position="18" oils_persist:virtual="true" reporter:datatype="link"/>
                        <field name="circulation" oils_obj:array_position="19" oils_persist:virtual="true" reporter:datatype="link"/>
+                       <field name="billing_location" oils_obj:array_position="20" oils_persist:virtual="true" reporter:datatype="link"/>
                </fields>
                <links>
                        <link field="usr" reltype="has_a" key="id" map="" class="au"/>
index 0ffc891..68dc818 100644 (file)
@@ -236,6 +236,7 @@ CREATE OR REPLACE VIEW money.billable_xact_summary AS
 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,
@@ -250,10 +251,32 @@ CREATE OR REPLACE VIEW money.open_billable_xact_summary AS
                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)
+               LEFT JOIN "action".circulation circ ON (circ.id = xact.id)
+               LEFT JOIN money.grocery groc ON (circ.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,14
+         GROUP BY 1,2,3,4,5,15
          ORDER BY MAX(debit.billing_ts), MAX(credit.payment_ts);