[open-ils-commits] [GIT] Evergreen ILS branch master updated. 4d3fe7d66eb2c7ab50302f6f5feb5aa6d6853938

Evergreen Git git at git.evergreen-ils.org
Fri Sep 6 17:39:48 EDT 2019


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  4d3fe7d66eb2c7ab50302f6f5feb5aa6d6853938 (commit)
       via  1f5a6e138988e6fb24e9897882e814f1ee1fa7ee (commit)
       via  41e90694a7e973fef2e1a3176cc95cd692a00f0d (commit)
       via  38a5f67ae3a84ebd85465c1372699a920e2d251f (commit)
       via  e4084e896c7bb256106b26efb9f5046034aac636 (commit)
       via  7d264985517d85986fbe00bee6a947bd36241530 (commit)
       via  522888735197d6a9579e2fba2922cde002bc3426 (commit)
       via  33c46ab6c830b58932b4fa7b707f95edcf698db2 (commit)
      from  46c8e3a876bdf34222429dc9d98954ff84ef20c1 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 4d3fe7d66eb2c7ab50302f6f5feb5aa6d6853938
Author: Galen Charlton <gmc at equinoxinitiative.org>
Date:   Fri Sep 6 17:38:02 2019 -0400

    LP#1793802: stamp database update
    
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>

diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index 977003f998..79af8ae0ba 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -92,7 +92,7 @@ CREATE TRIGGER no_overlapping_deps
     BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
     FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
 
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1180', :eg_version); -- jeffdavis/gmcharlt
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1181', :eg_version); -- berick/csharp/gmcharlt
 
 CREATE TABLE config.bib_source (
 	id		SERIAL	PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql b/Open-ILS/src/sql/Pg/upgrade/1181.schema.aged-billing-payment.sql
similarity index 98%
rename from Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql
rename to Open-ILS/src/sql/Pg/upgrade/1181.schema.aged-billing-payment.sql
index ab8128f008..5fbfd69788 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/1181.schema.aged-billing-payment.sql
@@ -1,7 +1,7 @@
 
 BEGIN;
 
---SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+SELECT evergreen.upgrade_deps_block_check('1181', :eg_version);
 
 \qecho Migrating aged billing and payment data.  This might take a while.
 

commit 1f5a6e138988e6fb24e9897882e814f1ee1fa7ee
Author: Chris Sharp <csharp at georgialibraries.org>
Date:   Tue May 21 06:53:53 2019 -0400

    LP#1793802 - Add new aged/all billing/payment sources to aged/all circ sources.
    
    The new aged/all billing/payment sources need to be included
    in the aged/all circulations reporting sources.
    
    Signed-off-by: Chris Sharp <csharp at georgialibraries.org>
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>

diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml
index d1027b179d..aea0037d60 100644
--- a/Open-ILS/examples/fm_IDL.xml
+++ b/Open-ILS/examples/fm_IDL.xml
@@ -4767,8 +4767,8 @@ SELECT  usr,
 			<link field="target_copy" reltype="has_a" key="id" map="" class="acp"/>
 			<link field="checkin_staff" reltype="has_a" key="id" map="" class="au"/>
 			<link field="circ_lib" reltype="has_a" key="id" map="" class="aou"/>
-			<link field="payments" reltype="has_many" key="xact" map="" class="mp"/>
-			<link field="billings" reltype="has_many" key="xact" map="" class="mb"/>
+			<link field="payments" reltype="has_many" key="xact" map="" class="mallp"/>
+			<link field="billings" reltype="has_many" key="xact" map="" class="mallb"/>
 			<link field="duration_rule" reltype="has_a" key="name" map="" class="crcd"/>
 			<link field="max_fine_rule" reltype="has_a" key="name" map="" class="crmf"/>
 			<link field="recurring_fine_rule" reltype="has_a" key="name" map="" class="crrf"/>
@@ -4850,8 +4850,8 @@ SELECT  usr,
 			<link field="target_copy" reltype="has_a" key="id" map="" class="acp"/>
 			<link field="checkin_staff" reltype="has_a" key="id" map="" class="au"/>
 			<link field="circ_lib" reltype="has_a" key="id" map="" class="aou"/>
-			<link field="payments" reltype="has_many" key="xact" map="" class="mp"/>
-			<link field="billings" reltype="has_many" key="xact" map="" class="mb"/>
+			<link field="payments" reltype="has_many" key="xact" map="" class="mallp"/>
+			<link field="billings" reltype="has_many" key="xact" map="" class="mallb"/>
 			<link field="duration_rule" reltype="has_a" key="name" map="" class="crcd"/>
 			<link field="max_fine_rule" reltype="has_a" key="name" map="" class="crmf"/>
 			<link field="recurring_fine_rule" reltype="has_a" key="name" map="" class="crrf"/>
@@ -4936,8 +4936,8 @@ SELECT  usr,
 			<link field="target_copy" reltype="has_a" key="id" map="" class="acp"/>
 			<link field="checkin_staff" reltype="has_a" key="id" map="" class="au"/>
 			<link field="circ_lib" reltype="has_a" key="id" map="" class="aou"/>
-			<link field="payments" reltype="has_many" key="xact" map="" class="mp"/>
-			<link field="billings" reltype="has_many" key="xact" map="" class="mb"/>
+			<link field="payments" reltype="has_many" key="xact" map="" class="map"/>
+			<link field="billings" reltype="has_many" key="xact" map="" class="mab"/>
 			<link field="duration_rule" reltype="has_a" key="name" map="" class="crcd"/>
 			<link field="max_fine_rule" reltype="has_a" key="name" map="" class="crmf"/>
 			<link field="recurring_fine_rule" reltype="has_a" key="name" map="" class="crrf"/>

commit 41e90694a7e973fef2e1a3176cc95cd692a00f0d
Author: Bill Erickson <berickxx at gmail.com>
Date:   Sat Oct 20 08:11:46 2018 -0400

    LP#1793802 Age circ ages payments before billings
    
    When aging a circulation, payments must be deleted before billings,
    since account_adjustements (payment) reference billings.
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Chris Sharp <csharp at georgialibraries.org>
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>

diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql
index fe3c78a6cc..83e48bf8cf 100644
--- a/Open-ILS/src/sql/Pg/090.schema.action.sql
+++ b/Open-ILS/src/sql/Pg/090.schema.action.sql
@@ -358,8 +358,8 @@ BEGIN
     INSERT INTO money.aged_payment 
         SELECT * FROM money.payment_view WHERE xact = OLD.id;
 
-    DELETE FROM money.billing WHERE xact = OLD.id;
     DELETE FROM money.payment WHERE xact = OLD.id;
+    DELETE FROM money.billing WHERE xact = OLD.id;
 
     RETURN OLD;
 END;
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql
index a88bdd28f3..ab8128f008 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql
@@ -71,8 +71,8 @@ BEGIN
     INSERT INTO money.aged_payment 
         SELECT * FROM money.payment_view WHERE xact = OLD.id;
 
-    DELETE FROM money.billing WHERE xact = OLD.id;
     DELETE FROM money.payment WHERE xact = OLD.id;
+    DELETE FROM money.billing WHERE xact = OLD.id;
 
     RETURN OLD;
 END;
@@ -91,10 +91,7 @@ ALTER TABLE money.forgive_payment DISABLE TRIGGER mat_summary_del_tgr;
 ALTER TABLE money.credit_payment DISABLE TRIGGER mat_summary_del_tgr;
 ALTER TABLE money.goods_payment DISABLE TRIGGER mat_summary_del_tgr;
 
-DELETE FROM money.payment WHERE id IN (
-    SELECT mp.id FROM money.payment mp
-    JOIN money.aged_payment USING (id)
-);
+DELETE FROM money.payment WHERE id IN (SELECT id FROM money.aged_payment);
 
 ALTER TABLE money.payment ENABLE TRIGGER mat_summary_del_tgr;
 ALTER TABLE money.cash_payment ENABLE TRIGGER mat_summary_del_tgr;

commit 38a5f67ae3a84ebd85465c1372699a920e2d251f
Author: Bill Erickson <berickxx at gmail.com>
Date:   Wed Sep 26 17:22:11 2018 -0400

    LP#1793802 Billing/payment purge improvements
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Chris Sharp <csharp at georgialibraries.org>
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>

diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql
index 204e95df5c..a88bdd28f3 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql
@@ -18,16 +18,6 @@ INSERT INTO money.aged_billing
     SELECT mb.* FROM money.billing mb
     JOIN action.aged_circulation circ ON (circ.id = mb.xact);
 
-DELETE FROM money.payment WHERE id IN (
-    SELECT mp.id FROM money.payment mp
-    JOIN action.aged_circulation circ ON (circ.id = mp.xact)
-);
-
-DELETE FROM money.billing WHERE id IN (
-    SELECT mb.id FROM money.billing mb
-    JOIN action.aged_circulation circ ON (circ.id = mb.xact)
-);
-
 CREATE OR REPLACE VIEW money.all_payments AS
     SELECT * FROM money.payment_view 
     UNION ALL
@@ -88,5 +78,61 @@ BEGIN
 END;
 $$ LANGUAGE 'plpgsql';
 
+-- NOTE you could COMMIT here then start a new TRANSACTION if desired.
+
+\qecho Deleting aged payments and billings from active payment/billing
+\qecho tables.  This may take a while...
+
+ALTER TABLE money.payment DISABLE TRIGGER mat_summary_del_tgr;
+ALTER TABLE money.cash_payment DISABLE TRIGGER mat_summary_del_tgr;
+ALTER TABLE money.check_payment DISABLE TRIGGER mat_summary_del_tgr;
+ALTER TABLE money.credit_card_payment DISABLE TRIGGER mat_summary_del_tgr;
+ALTER TABLE money.forgive_payment DISABLE TRIGGER mat_summary_del_tgr;
+ALTER TABLE money.credit_payment DISABLE TRIGGER mat_summary_del_tgr;
+ALTER TABLE money.goods_payment DISABLE TRIGGER mat_summary_del_tgr;
+
+DELETE FROM money.payment WHERE id IN (
+    SELECT mp.id FROM money.payment mp
+    JOIN money.aged_payment USING (id)
+);
+
+ALTER TABLE money.payment ENABLE TRIGGER mat_summary_del_tgr;
+ALTER TABLE money.cash_payment ENABLE TRIGGER mat_summary_del_tgr;
+ALTER TABLE money.check_payment ENABLE TRIGGER mat_summary_del_tgr;
+ALTER TABLE money.credit_card_payment ENABLE TRIGGER mat_summary_del_tgr;
+ALTER TABLE money.forgive_payment ENABLE TRIGGER mat_summary_del_tgr;
+ALTER TABLE money.credit_payment ENABLE TRIGGER mat_summary_del_tgr;
+ALTER TABLE money.goods_payment ENABLE TRIGGER mat_summary_del_tgr;
+
+-- TODO: This approach assumes most of the money.billing rows have been
+-- copied to money.aged_billing.  If that is not the case, which would
+-- happen if circ anonymization is not enabled, it will be faster to
+-- perform a simple delete instead of a truncate/rebuild.
+
+-- Copy all money.billing rows that are not represented in money.aged_billing
+CREATE TEMPORARY TABLE tmp_money_billing ON COMMIT DROP AS
+    SELECT mb.* FROM money.billing mb
+    LEFT JOIN money.aged_billing mab USING (id)
+    WHERE mab.id IS NULL;
+
+ALTER TABLE money.billing DISABLE TRIGGER ALL;
+
+-- temporarily remove the foreign key constraint to money.billing on
+-- account adjusment.  Needed for money.billing truncate.
+ALTER TABLE money.account_adjustment 
+    DROP CONSTRAINT account_adjustment_billing_fkey;
+
+TRUNCATE money.billing;
+
+INSERT INTO money.billing SELECT * FROM tmp_money_billing;
+
+ALTER TABLE money.billing ENABLE TRIGGER ALL;
+ALTER TABLE money.account_adjustment 
+    ADD CONSTRAINT account_adjustment_billing_fkey 
+    FOREIGN KEY (billing) REFERENCES money.billing (id);
+
 COMMIT;
 
+-- Good to run after truncating -- OK to run after COMMIT.
+ANALYZE money.billing;
+

commit e4084e896c7bb256106b26efb9f5046034aac636
Author: Bill Erickson <berickxx at gmail.com>
Date:   Fri Sep 21 15:56:25 2018 -0400

    LP#1793802 Aged billings/payments release notes
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Chris Sharp <csharp at georgialibraries.org>
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>

diff --git a/docs/RELEASE_NOTES_NEXT/Administration/aged-bills-and-payments.adoc b/docs/RELEASE_NOTES_NEXT/Administration/aged-bills-and-payments.adoc
new file mode 100644
index 0000000000..6181761b29
--- /dev/null
+++ b/docs/RELEASE_NOTES_NEXT/Administration/aged-bills-and-payments.adoc
@@ -0,0 +1,15 @@
+Aged Billings and Payments
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Two new database tables are added for tracking aged billings and payments:
+money.aged_billing and money.aged_payment.
+
+Two new database views are added, money.all_billings and money.all_payments
+for aggregating data across the active and aged tables.
+
+When a circulation is aged, billings and payments linked to the circulation
+are migrated from the active billing and payment tables to the new aged 
+tables.
+
+The new tables are accessible to the reporter.
+

commit 7d264985517d85986fbe00bee6a947bd36241530
Author: Bill Erickson <berickxx at gmail.com>
Date:   Fri Sep 21 15:53:23 2018 -0400

    LP#1793802 Aged billings/payments PGTAP tests
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Chris Sharp <csharp at georgialibraries.org>
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>

diff --git a/Open-ILS/src/sql/Pg/live_t/lp1793802-aged-billings-payments.pg b/Open-ILS/src/sql/Pg/live_t/lp1793802-aged-billings-payments.pg
new file mode 100644
index 0000000000..cce5ce1abf
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/live_t/lp1793802-aged-billings-payments.pg
@@ -0,0 +1,47 @@
+-- Load the TAP functions.
+BEGIN;
+
+-- Plan the tests.
+SELECT plan(8);
+
+SELECT is(
+    (SELECT COUNT(*) FROM money.billing WHERE xact = 9),
+    1::BIGINT, 'Confirm billing for xact exists'
+);
+
+SELECT is(
+    (SELECT COUNT(*) FROM money.payment WHERE xact = 9),
+    1::BIGINT, 'Confirm payment for xact exists'
+);
+
+PREPARE age_circ AS DELETE FROM action.circulation WHERE id = 9;
+SELECT lives_ok('age_circ', 'Age circulation without errors');
+
+SELECT is(
+    (SELECT COUNT(*) FROM action.aged_circulation WHERE id = 9),
+    1::BIGINT, 'Confirm circ aged'
+);
+
+SELECT is(
+    (SELECT COUNT(*) FROM money.aged_billing WHERE xact = 9),
+    1::BIGINT, 'Confirm aged billing created'
+);
+
+SELECT is(
+    (SELECT COUNT(*) FROM money.aged_payment WHERE xact = 9),
+    1::BIGINT, 'Confirm aged payment created'
+);
+
+SELECT is(
+    (SELECT COUNT(*) FROM money.billing WHERE xact = 9),
+    0::BIGINT, 'Confirm source billing deleted'
+);
+
+SELECT is(
+    (SELECT COUNT(*) FROM money.payment WHERE xact = 9),
+    0::BIGINT, 'Confirm source payment deleted'
+);
+
+-- Finish the tests and clean up.
+SELECT * FROM finish();
+ROLLBACK;

commit 522888735197d6a9579e2fba2922cde002bc3426
Author: Bill Erickson <berickxx at gmail.com>
Date:   Mon Sep 24 10:33:13 2018 -0400

    LP#1793802 Add money.all_[payments|billings] views
    
    Similar to money.all_circulation_slim, add views to collect data from
    both active and aged versions of the payment and billing tables.
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Chris Sharp <csharp at georgialibraries.org>
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>

diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml
index 19e65a9f85..d1027b179d 100644
--- a/Open-ILS/examples/fm_IDL.xml
+++ b/Open-ILS/examples/fm_IDL.xml
@@ -8070,7 +8070,7 @@ SELECT  usr,
 		oils_obj:fieldmapper="money::aged_payment" 
 		oils_persist:tablename="money.aged_payment" 
 		reporter:label="Payments: Aged">
-		<fields oils_persist:primary="id" oils_persist:sequence="">
+		<fields oils_persist:primary="id" oils_persist:sequence="money.payment_id_seq">
 			<field reporter:label="Amount" name="amount" reporter:datatype="money" />
 			<field reporter:label="Payment ID" name="id" reporter:datatype="id" />
 			<field reporter:label="Note" name="note" reporter:datatype="text"/>
@@ -8090,6 +8090,26 @@ SELECT  usr,
 			</actions>
 		</permacrud>
 	</class>
+	<class id="mallp" controller="open-ils.cstore" 
+		oils_obj:fieldmapper="money::all_payments" 
+		oils_persist:tablename="money.all_payments" 
+		oils_persist="readonly" reporter:label="All Payments">
+		<fields oils_persist:primary="id" oils_persist:sequence="money.payment_id_seq">
+			<field reporter:label="Amount" name="amount" reporter:datatype="money" />
+			<field reporter:label="Payment ID" name="id" reporter:datatype="id" />
+			<field reporter:label="Note" name="note" reporter:datatype="text"/>
+			<field reporter:label="Payment Date/Time" name="payment_ts" reporter:datatype="timestamp"/>
+			<field reporter:label="Payment Type" name="payment_type" reporter:datatype="text"/>
+			<field reporter:label="Aged Circulation" name="xact" reporter:datatype="link"/>
+			<field reporter:label="Voided?" name="voided" reporter:datatype="bool"/>
+		</fields>
+		<links>
+			<!-- 
+				'xact' may link to a money.billabl_xact or to a money.aged_circulation.
+			 -->
+		</links>
+	</class>
+
 	<class id="mbp" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="money::bnm_payment" oils_persist:tablename="money.bnm_payment_view" reporter:core="true" reporter:label="Payments: Brick-and-mortar">
 		<fields oils_persist:primary="id" oils_persist:sequence="">
 			<field reporter:label="Amount" name="amount" reporter:datatype="money" />
@@ -8366,7 +8386,7 @@ SELECT  usr,
 		oils_obj:fieldmapper="money::aged_billing" 
 		oils_persist:tablename="money.aged_billing" 
 		reporter:label="Aged Billing Line Item">
-		<fields oils_persist:primary="id" oils_persist:sequence="">
+		<fields oils_persist:primary="id" oils_persist:sequence="money.billing_id_seq">
 			<field reporter:label="Amount" name="amount" reporter:datatype="money" />
 			<field reporter:label="Create Date" name="create_date" reporter:datatype="timestamp"/>
 			<field reporter:label="Billing Period Start" name="period_start" reporter:datatype="timestamp"/>
@@ -8394,6 +8414,33 @@ SELECT  usr,
 			</actions>
 		</permacrud>
 	</class>
+	<class id="mallb" controller="open-ils.cstore" 
+		oils_obj:fieldmapper="money::all_billings" 
+		oils_persist:tablename="money.all_billings" 
+		oils_persist="readonly" reporter:label="All Billing Line Items">
+		<fields oils_persist:primary="id" oils_persist:sequence="">
+			<field reporter:label="Amount" name="amount" reporter:datatype="money" />
+			<field reporter:label="Create Date" name="create_date" reporter:datatype="timestamp"/>
+			<field reporter:label="Billing Period Start" name="period_start" reporter:datatype="timestamp"/>
+			<field reporter:label="Billing Period End" name="period_end" reporter:datatype="timestamp"/>
+			<field reporter:label="Legacy Billing Timestamp" name="billing_ts" reporter:datatype="timestamp"/>
+			<field reporter:label="Legacy Billing Type" name="billing_type" reporter:datatype="text"/>
+			<field reporter:label="Billing ID" name="id" reporter:datatype="id" />
+			<field reporter:label="Note" name="note" reporter:datatype="text"/>
+			<field reporter:label="Void Timestamp" name="void_time" reporter:datatype="timestamp"/>
+			<field reporter:label="Voided?" name="voided" reporter:datatype="bool"/>
+			<field reporter:label="Voiding Staff Member" name="voider" reporter:datatype="link"/>
+			<field reporter:label="Transaction" name="xact" reporter:datatype="link"/>
+			<field reporter:label="Type" name="btype" reporter:datatype="link"/>
+		</fields>
+		<links>
+			<link field="voider" reltype="has_a" key="id" map="" class="au"/>
+			<link field="btype" reltype="has_a" key="id" map="" class="cbt"/>
+			<!-- 
+				'xact' may link to a money.billabl_xact or to a money.aged_circulation.
+			 -->
+		</links>
+	</class>
 	<class id="pugm" controller="open-ils.cstore" oils_obj:fieldmapper="permission::usr_grp_map" oils_persist:tablename="permission.usr_grp_map" reporter:label="User Group Map">
 		<fields oils_persist:primary="id" oils_persist:sequence="permission.usr_grp_map_id_seq">
 			<field name="grp" />
diff --git a/Open-ILS/src/sql/Pg/080.schema.money.sql b/Open-ILS/src/sql/Pg/080.schema.money.sql
index 85352ab2ab..7d30797b1e 100644
--- a/Open-ILS/src/sql/Pg/080.schema.money.sql
+++ b/Open-ILS/src/sql/Pg/080.schema.money.sql
@@ -691,7 +691,18 @@ CREATE OR REPLACE VIEW money.cashdrawer_payment_view AS
 -- Create 'aged' clones of billing and payment_view tables
 CREATE TABLE money.aged_payment (LIKE money.payment INCLUDING INDEXES);
 ALTER TABLE money.aged_payment ADD COLUMN payment_type TEXT NOT NULL;
+
 CREATE TABLE money.aged_billing (LIKE money.billing INCLUDING INDEXES);
 
+CREATE OR REPLACE VIEW money.all_payments AS
+    SELECT * FROM money.payment_view 
+    UNION ALL
+    SELECT * FROM money.aged_payment;
+
+CREATE OR REPLACE VIEW money.all_billings AS
+    SELECT * FROM money.billing
+    UNION ALL
+    SELECT * FROM money.aged_billing;
+
 COMMIT;
 
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql
index f465411dc9..204e95df5c 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql
@@ -7,6 +7,7 @@ BEGIN;
 
 CREATE TABLE money.aged_payment (LIKE money.payment INCLUDING INDEXES);
 ALTER TABLE money.aged_payment ADD COLUMN payment_type TEXT NOT NULL;
+
 CREATE TABLE money.aged_billing (LIKE money.billing INCLUDING INDEXES);
 
 INSERT INTO money.aged_payment 
@@ -27,6 +28,15 @@ DELETE FROM money.billing WHERE id IN (
     JOIN action.aged_circulation circ ON (circ.id = mb.xact)
 );
 
+CREATE OR REPLACE VIEW money.all_payments AS
+    SELECT * FROM money.payment_view 
+    UNION ALL
+    SELECT * FROM money.aged_payment;
+
+CREATE OR REPLACE VIEW money.all_billings AS
+    SELECT * FROM money.billing
+    UNION ALL
+    SELECT * FROM money.aged_billing;
 
 CREATE OR REPLACE FUNCTION action.age_circ_on_delete () RETURNS TRIGGER AS $$
 DECLARE

commit 33c46ab6c830b58932b4fa7b707f95edcf698db2
Author: Bill Erickson <berickxx at gmail.com>
Date:   Fri Sep 21 14:53:33 2018 -0400

    LP#1793802 Aged billings and payments
    
    Creates tables money.aged_billing and money.aged_payment.  When a
    circulation is aged, billings/payments linked to the circ are migrated
    to the aged_* table.
    
    Upgrade script includes a migration script for migrating existing
    billings and payments.
    
    Includes IDL entries for reporting and pcrud access just in case it's
    needed.  Note the 'xact' column on these new tables links directly to
    the aged circulation instead of the non-existent money.billable_xact.
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Chris Sharp <csharp at georgialibraries.org>
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>

diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml
index 1a8598848b..19e65a9f85 100644
--- a/Open-ILS/examples/fm_IDL.xml
+++ b/Open-ILS/examples/fm_IDL.xml
@@ -8066,6 +8066,30 @@ SELECT  usr,
 			</actions>
 		</permacrud>
 	</class>
+	<class id="map" controller="open-ils.cstore open-ils.pcrud" 
+		oils_obj:fieldmapper="money::aged_payment" 
+		oils_persist:tablename="money.aged_payment" 
+		reporter:label="Payments: Aged">
+		<fields oils_persist:primary="id" oils_persist:sequence="">
+			<field reporter:label="Amount" name="amount" reporter:datatype="money" />
+			<field reporter:label="Payment ID" name="id" reporter:datatype="id" />
+			<field reporter:label="Note" name="note" reporter:datatype="text"/>
+			<field reporter:label="Payment Date/Time" name="payment_ts" reporter:datatype="timestamp"/>
+			<field reporter:label="Payment Type" name="payment_type" reporter:datatype="text"/>
+			<field reporter:label="Aged Circulation" name="xact" reporter:datatype="link"/>
+			<field reporter:label="Voided?" name="voided" reporter:datatype="bool"/>
+		</fields>
+		<links>
+			<link field="xact" reltype="has_a" key="id" map="" class="acirc"/>
+		</links>
+		<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+			<actions>
+				<retrieve permission="VIEW_USER_TRANSACTIONS">
+					<context link="xact" field="usr_home_ou"/>
+				</retrieve>
+			</actions>
+		</permacrud>
+	</class>
 	<class id="mbp" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="money::bnm_payment" oils_persist:tablename="money.bnm_payment_view" reporter:core="true" reporter:label="Payments: Brick-and-mortar">
 		<fields oils_persist:primary="id" oils_persist:sequence="">
 			<field reporter:label="Amount" name="amount" reporter:datatype="money" />
@@ -8338,6 +8362,38 @@ SELECT  usr,
 			</actions>
 		</permacrud>
 	</class>
+	<class id="mab" controller="open-ils.cstore open-ils.pcrud" 
+		oils_obj:fieldmapper="money::aged_billing" 
+		oils_persist:tablename="money.aged_billing" 
+		reporter:label="Aged Billing Line Item">
+		<fields oils_persist:primary="id" oils_persist:sequence="">
+			<field reporter:label="Amount" name="amount" reporter:datatype="money" />
+			<field reporter:label="Create Date" name="create_date" reporter:datatype="timestamp"/>
+			<field reporter:label="Billing Period Start" name="period_start" reporter:datatype="timestamp"/>
+			<field reporter:label="Billing Period End" name="period_end" reporter:datatype="timestamp"/>
+			<field reporter:label="Legacy Billing Timestamp" name="billing_ts" reporter:datatype="timestamp"/>
+			<field reporter:label="Legacy Billing Type" name="billing_type" reporter:datatype="text"/>
+			<field reporter:label="Billing ID" name="id" reporter:datatype="id" />
+			<field reporter:label="Note" name="note" reporter:datatype="text"/>
+			<field reporter:label="Void Timestamp" name="void_time" reporter:datatype="timestamp"/>
+			<field reporter:label="Voided?" name="voided" reporter:datatype="bool"/>
+			<field reporter:label="Voiding Staff Member" name="voider" reporter:datatype="link"/>
+			<field reporter:label="Transaction" name="xact" reporter:datatype="link"/>
+			<field reporter:label="Type" name="btype" reporter:datatype="link"/>
+		</fields>
+		<links>
+			<link field="xact" reltype="has_a" key="id" map="" class="acirc"/>
+			<link field="voider" reltype="has_a" key="id" map="" class="au"/>
+			<link field="btype" reltype="has_a" key="id" map="" class="cbt"/>
+		</links>
+		<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+			<actions>
+				<retrieve permission="VIEW_USER_TRANSACTIONS">
+					<context link="xact" field="usr_home_ou"/>
+				</retrieve>
+			</actions>
+		</permacrud>
+	</class>
 	<class id="pugm" controller="open-ils.cstore" oils_obj:fieldmapper="permission::usr_grp_map" oils_persist:tablename="permission.usr_grp_map" reporter:label="User Group Map">
 		<fields oils_persist:primary="id" oils_persist:sequence="permission.usr_grp_map_id_seq">
 			<field name="grp" />
diff --git a/Open-ILS/src/sql/Pg/080.schema.money.sql b/Open-ILS/src/sql/Pg/080.schema.money.sql
index b5f3b27241..85352ab2ab 100644
--- a/Open-ILS/src/sql/Pg/080.schema.money.sql
+++ b/Open-ILS/src/sql/Pg/080.schema.money.sql
@@ -77,7 +77,6 @@ END;
 $$ LANGUAGE PLPGSQL;
 CREATE TRIGGER maintain_billing_ts_tgr BEFORE INSERT OR UPDATE ON money.billing FOR EACH ROW EXECUTE PROCEDURE money.maintain_billing_ts();
 
-
 CREATE TABLE money.payment (
 	id		BIGSERIAL			PRIMARY KEY,
 	xact		BIGINT				NOT NULL, -- money.billable_xact.id
@@ -689,5 +688,10 @@ CREATE OR REPLACE VIEW money.cashdrawer_payment_view AS
 		LEFT JOIN money.payment_view t ON (p.id = t.id);
 
 
+-- Create 'aged' clones of billing and payment_view tables
+CREATE TABLE money.aged_payment (LIKE money.payment INCLUDING INDEXES);
+ALTER TABLE money.aged_payment ADD COLUMN payment_type TEXT NOT NULL;
+CREATE TABLE money.aged_billing (LIKE money.billing INCLUDING INDEXES);
+
 COMMIT;
 
diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql
index 900c1b36d3..fe3c78a6cc 100644
--- a/Open-ILS/src/sql/Pg/090.schema.action.sql
+++ b/Open-ILS/src/sql/Pg/090.schema.action.sql
@@ -350,6 +350,17 @@ BEGIN
         max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ
         FROM action.all_circulation WHERE id = OLD.id;
 
+    -- Migrate billings and payments to aged tables
+
+    INSERT INTO money.aged_billing
+        SELECT * FROM money.billing WHERE xact = OLD.id;
+
+    INSERT INTO money.aged_payment 
+        SELECT * FROM money.payment_view WHERE xact = OLD.id;
+
+    DELETE FROM money.billing WHERE xact = OLD.id;
+    DELETE FROM money.payment WHERE xact = OLD.id;
+
     RETURN OLD;
 END;
 $$ LANGUAGE 'plpgsql';
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql
new file mode 100644
index 0000000000..f465411dc9
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.aged-billing-payment.sql
@@ -0,0 +1,82 @@
+
+BEGIN;
+
+--SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+\qecho Migrating aged billing and payment data.  This might take a while.
+
+CREATE TABLE money.aged_payment (LIKE money.payment INCLUDING INDEXES);
+ALTER TABLE money.aged_payment ADD COLUMN payment_type TEXT NOT NULL;
+CREATE TABLE money.aged_billing (LIKE money.billing INCLUDING INDEXES);
+
+INSERT INTO money.aged_payment 
+    SELECT  mp.* FROM money.payment_view mp
+    JOIN action.aged_circulation circ ON (circ.id = mp.xact);
+
+INSERT INTO money.aged_billing
+    SELECT mb.* FROM money.billing mb
+    JOIN action.aged_circulation circ ON (circ.id = mb.xact);
+
+DELETE FROM money.payment WHERE id IN (
+    SELECT mp.id FROM money.payment mp
+    JOIN action.aged_circulation circ ON (circ.id = mp.xact)
+);
+
+DELETE FROM money.billing WHERE id IN (
+    SELECT mb.id FROM money.billing mb
+    JOIN action.aged_circulation circ ON (circ.id = mb.xact)
+);
+
+
+CREATE OR REPLACE FUNCTION action.age_circ_on_delete () RETURNS TRIGGER AS $$
+DECLARE
+found char := 'N';
+BEGIN
+
+    -- If there are any renewals for this circulation, don't archive or delete
+    -- it yet.   We'll do so later, when we archive and delete the renewals.
+
+    SELECT 'Y' INTO found
+    FROM action.circulation
+    WHERE parent_circ = OLD.id
+    LIMIT 1;
+
+    IF found = 'Y' THEN
+        RETURN NULL;  -- don't delete
+	END IF;
+
+    -- Archive a copy of the old row to action.aged_circulation
+
+    INSERT INTO action.aged_circulation
+        (id,usr_post_code, usr_home_ou, usr_profile, usr_birth_year, copy_call_number, copy_location,
+        copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy,
+        circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, grace_period, due_date,
+        stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine,
+        max_fine, phone_renewal, desk_renewal, opac_renewal, duration_rule, recurring_fine_rule,
+        max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ)
+      SELECT
+        id,usr_post_code, usr_home_ou, usr_profile, usr_birth_year, copy_call_number, copy_location,
+        copy_owning_lib, copy_circ_lib, copy_bib_record, xact_start, xact_finish, target_copy,
+        circ_lib, circ_staff, checkin_staff, checkin_lib, renewal_remaining, grace_period, due_date,
+        stop_fines_time, checkin_time, create_time, duration, fine_interval, recurring_fine,
+        max_fine, phone_renewal, desk_renewal, opac_renewal, duration_rule, recurring_fine_rule,
+        max_fine_rule, stop_fines, workstation, checkin_workstation, checkin_scan_time, parent_circ
+        FROM action.all_circulation WHERE id = OLD.id;
+
+    -- Migrate billings and payments to aged tables
+
+    INSERT INTO money.aged_billing
+        SELECT * FROM money.billing WHERE xact = OLD.id;
+
+    INSERT INTO money.aged_payment 
+        SELECT * FROM money.payment_view WHERE xact = OLD.id;
+
+    DELETE FROM money.billing WHERE xact = OLD.id;
+    DELETE FROM money.payment WHERE xact = OLD.id;
+
+    RETURN OLD;
+END;
+$$ LANGUAGE 'plpgsql';
+
+COMMIT;
+

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/examples/fm_IDL.xml                       | 115 +++++++++++++++++-
 Open-ILS/src/sql/Pg/002.schema.config.sql          |   2 +-
 Open-ILS/src/sql/Pg/080.schema.money.sql           |  17 ++-
 Open-ILS/src/sql/Pg/090.schema.action.sql          |  11 ++
 .../Pg/live_t/lp1793802-aged-billings-payments.pg  |  47 +++++++
 .../upgrade/1181.schema.aged-billing-payment.sql   | 135 +++++++++++++++++++++
 .../Administration/aged-bills-and-payments.adoc    |  15 +++
 7 files changed, 334 insertions(+), 8 deletions(-)
 create mode 100644 Open-ILS/src/sql/Pg/live_t/lp1793802-aged-billings-payments.pg
 create mode 100644 Open-ILS/src/sql/Pg/upgrade/1181.schema.aged-billing-payment.sql
 create mode 100644 docs/RELEASE_NOTES_NEXT/Administration/aged-bills-and-payments.adoc


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list