Repair acq.fund_combined_balance for encumbered + spent user/berick/acq-fund-combined-balance-fix
authorBill Erickson <berick@esilibrary.com>
Tue, 13 Sep 2011 20:41:06 +0000 (16:41 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 13 Sep 2011 20:51:55 +0000 (16:51 -0400)
acq.fund_debit_total, which is used by acq.fund_combined_balance, can
return 2 values, the total encumbered and total spent for a fund.  This
patch updates acq.fund_combined_balance to SUM the two so that only 1
row per fund is returned from acq.fund_combined_balance

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/sql/Pg/200.schema.acq.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq.fund-combined-balance.sql.sql [new file with mode: 0644]

index b566ff5..6ab6933 100644 (file)
@@ -2484,9 +2484,9 @@ CREATE OR REPLACE VIEW acq.fund_spent_total AS
 
 CREATE OR REPLACE VIEW acq.fund_combined_balance AS
     SELECT  c.fund,
-            c.amount - COALESCE(d.amount,0.0) AS amount
+            c.amount - SUM( COALESCE(d.amount, 0)) AS amount
       FROM  acq.fund_allocation_total c
-            LEFT JOIN acq.fund_debit_total d USING (fund);
+            LEFT JOIN acq.fund_debit_total d USING (fund) GROUP BY c.fund, c.amount;
 
 CREATE OR REPLACE VIEW acq.fund_spent_balance AS
     SELECT  c.fund,
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq.fund-combined-balance.sql.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq.fund-combined-balance.sql.sql
new file mode 100644 (file)
index 0000000..8dbffab
--- /dev/null
@@ -0,0 +1,18 @@
+-- Evergreen DB patch XXXX.schema.acq.fund-combined-balance.sql.sql
+--
+-- FIXME: insert description of change, if needed
+--
+BEGIN;
+
+-- check whether patch can be applied
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+CREATE OR REPLACE VIEW acq.fund_combined_balance AS
+    SELECT  
+        c.fund,
+        c.amount - SUM( COALESCE(d.amount, 0) ) AS amount
+    FROM  acq.fund_allocation_total c
+        LEFT JOIN acq.fund_debit_total d USING (fund) 
+    GROUP BY c.fund, c.amount;
+
+COMMIT;