JBAS-1306 Lost/paid summary view SQL repair
authorBill Erickson <berickxx@gmail.com>
Tue, 16 Oct 2018 15:21:35 +0000 (11:21 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Avoid use of all_ciculation_slim and all_payments view for active
lookups.  These slow the queries down considerably for the normal use
case of staff accepting payments and printing recteipts.

If the B.O. needs access to payments for anon circs / money down the
road we may can create a separate query.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/sql/schema/deploy/lost-paid-receipts.sql

index 6a11e38..f7a5a90 100644 (file)
@@ -91,20 +91,20 @@ CREATE OR REPLACE VIEW money.refundable_xact_summary AS
         total_refunded.amount::NUMERIC(8,2) AS total_refunded,
         refundable_payment_count.count AS num_refundable_payments
     FROM money.refundable_xact xact
-        JOIN action.all_circulation_slim circ ON (circ.id = xact.xact)
+        JOIN action.circulation circ ON (circ.id = xact.xact)
         JOIN asset.copy acp ON (acp.id = circ.target_copy)
         JOIN asset.call_number acn ON (acn.id = acp.call_number)
         JOIN reporter.materialized_simple_record rsr ON (rsr.id = acn.record)
         JOIN money.materialized_billable_xact_summary summary 
-            ON (summary.id = xact.id)
+            ON (summary.id = xact.xact)
                JOIN (
             SELECT pay.xact, SUM(pay.amount) amount
-            FROM money.all_payments pay WHERE amount > 0 GROUP BY 1
+            FROM money.payment pay WHERE amount > 0 GROUP BY 1
                ) total_paid ON (total_paid.xact = xact.xact)
                JOIN (
                        SELECT mrp.refundable_xact, SUM(pay.amount) AS amount
                        FROM money.refundable_payment mrp
-                       JOIN money.all_payments pay ON (mrp.payment = pay.id)
+                       JOIN money.payment pay ON (mrp.payment = pay.id)
                        GROUP BY 1
                ) refundable_paid ON (refundable_paid.refundable_xact = xact.id)
         LEFT JOIN (
@@ -132,7 +132,7 @@ CREATE OR REPLACE VIEW money.refundable_payment_summary AS
         pay.payment_type,
         aws.name AS workstation
     FROM money.refundable_payment mrp
-        JOIN money.all_payments pay ON (pay.id = mrp.payment)
+        JOIN money.payment_view pay ON (pay.id = mrp.payment)
         JOIN actor.org_unit aou ON (aou.id = mrp.payment_ou)
         LEFT JOIN money.cash_payment cash ON (cash.id = pay.id)
         LEFT JOIN actor.workstation aws ON (aws.id = cash.cash_drawer)