beginnings of aged billing summary
authorChris Sharp <csharp@georgialibraries.org>
Tue, 11 Feb 2020 18:18:26 +0000 (13:18 -0500)
committerChris Sharp <csharp@georgialibraries.org>
Tue, 11 Feb 2020 18:18:26 +0000 (13:18 -0500)
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/080.schema.money.sql
Open-ILS/src/sql/Pg/090.schema.action.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.money_aged_billing_summary.sql [new file with mode: 0644]

index 75b52a7..906aa8f 100644 (file)
@@ -8449,6 +8449,50 @@ SELECT  usr,
                         -->
                </links>
        </class>
+       <class id="mabs" controller="open-ils.cstore"
+               oils_obj:fieldmapper="money::aged_billing_summary"
+               oils_persist:tablename="money.aged_billing_summary"
+               oils_persist="readonly" reporter:label="Aged Billing Summary">
+               <fields oils_persist:primary="id" oils_persist:sequence="">
+                       <field reporter:label="Balance Owed" name="balance_owed" reporter:datatype="money"/>
+                       <field reporter:label="Transaction ID" name="id" reporter:datatype="id"/>
+                       <field reporter:label="Last Billing Note" name="last_billing_note" reporter:datatype="text"/>
+                       <field reporter:label="Last Billing Timestamp" name="last_billing_ts" reporter:datatype="timestamp"/>
+                       <field reporter:label="Last Billing Type" name="last_billing_type" reporter:datatype="text"/>
+                       <field reporter:label="Last Payment Note" name="last_payment_note" reporter:datatype="text"/>
+                       <field reporter:label="Last Payment Timestamp" name="last_payment_ts" reporter:datatype="timestamp"/>
+                       <field reporter:label="Last Payment Type" name="last_payment_type" reporter:datatype="text"/>
+                       <field reporter:label="Total Owed" name="total_owed" reporter:datatype="money"/>
+                       <field reporter:label="Total Paid" name="total_paid" reporter:datatype="money"/>
+                       <field reporter:label="Transaction Finish Time" name="xact_finish" reporter:datatype="timestamp" />
+                       <field reporter:label="Transaction Start Time" name="xact_start" reporter:datatype="timestamp" />
+                       <field reporter:label="Transaction Type" name="xact_type" reporter:datatype="text"/>
+               </fields>
+               <links>
+               </links>
+       </class>
+       <class id="mallbs" controller="open-ils.cstore"
+               oils_obj:fieldmapper="money::all_billing_summary"
+               oils_persist:tablename="money.all_billing_summary"
+               oils_persist="readonly" reporter:label="Combined Aged and Active Billing Summary">
+               <fields oils_persist:primary="id" oils_persist:sequence="">
+                       <field reporter:label="Balance Owed" name="balance_owed" reporter:datatype="money"/>
+                       <field reporter:label="Transaction ID" name="id" reporter:datatype="id"/>
+                       <field reporter:label="Last Billing Note" name="last_billing_note" reporter:datatype="text"/>
+                       <field reporter:label="Last Billing Timestamp" name="last_billing_ts" reporter:datatype="timestamp"/>
+                       <field reporter:label="Last Billing Type" name="last_billing_type" reporter:datatype="text"/>
+                       <field reporter:label="Last Payment Note" name="last_payment_note" reporter:datatype="text"/>
+                       <field reporter:label="Last Payment Timestamp" name="last_payment_ts" reporter:datatype="timestamp"/>
+                       <field reporter:label="Last Payment Type" name="last_payment_type" reporter:datatype="text"/>
+                       <field reporter:label="Total Owed" name="total_owed" reporter:datatype="money"/>
+                       <field reporter:label="Total Paid" name="total_paid" reporter:datatype="money"/>
+                       <field reporter:label="Transaction Finish Time" name="xact_finish" reporter:datatype="timestamp" />
+                       <field reporter:label="Transaction Start Time" name="xact_start" reporter:datatype="timestamp" />
+                       <field reporter:label="Transaction Type" name="xact_type" reporter:datatype="text"/>
+               </fields>
+               <links>
+               </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" />
index 7d30797..04da84f 100644 (file)
@@ -704,5 +704,38 @@ CREATE OR REPLACE VIEW money.all_billings AS
     UNION ALL
     SELECT * FROM money.aged_billing;
 
+-- Create table to hold aged materialized billable xact summary data
+CREATE TABLE money.aged_billing_summary (
+    id                  BIGINT,
+    xact_start          TIMESTAMP WITH TIME ZONE,
+    xact_finish         TIMESTAMP WITH TIME ZONE,
+    total_paid          NUMERIC,
+    last_payment_ts     TIMESTAMP WITH TIME ZONE,
+    last_payment_note   TEXT,
+    last_payment_type   TEXT,
+    total_owed          NUMERIC,
+    last_billing_ts     TIMESTAMP WITH TIME ZONE,
+    last_billing_note   TEXT,
+    last_billing_type   TEXT,
+    balance_owed        NUMERIC,
+    xact_type           TEXT
+);
+
+ALTER TABLE money.aged_billing_summary ADD PRIMARY KEY (id);
+
+CREATE INDEX money_aged_billing_summary_usr_idx ON money.aged_billing_summary (usr);
+CREATE INDEX money_aged_billing_summary_xact_start_idx ON money.aged_billing_summary (xact_start);
+
+CREATE OR REPLACE VIEW money.all_billing_summary AS
+    SELECT id, xact_start, xact_finish, total_paid, last_payment_ts
+    last_payment_note, last_payment_type, total_owed, last_billing_ts,
+    last_billing_note, last_billing_type, balance_owed, xact_type
+    FROM money.billable_xact_summary
+    UNION ALL
+    SELECT id, xact_start, xact_finish, total_paid, last_payment_ts
+    last_payment_note, last_payment_type, total_owed, last_billing_ts,
+    last_billing_note, last_billing_type, balance_owed, xact_type
+    FROM money.aged_billing_summary;
+
 COMMIT;
 
index 3fb3b4a..3be3216 100644 (file)
@@ -352,6 +352,15 @@ BEGIN
         auto_renewal, auto_renewal_remaining
         FROM action.all_circulation WHERE id = OLD.id;
 
+    -- Archive a copy of materialized_xact_billing_summary (minus usr)
+    INSERT INTO money.aged_billing_summary
+        (id, xact_start, xact_finish, total_paid, last_payment_ts, last_payment_note, last_payment_type,
+        total_owed, last_billing_ts, last_billing_note, last_billing_type, balance_owed, xact_type)
+    SELECT
+        id, xact_start, xact_finish, total_paid, last_payment_ts, last_payment_note, last_payment_type,
+        total_owed, last_billing_ts, last_billing_note, last_billing_type, balance_owed, xact_type
+        FROM money.materialized_billable_xact_summary WHERE id = OLD.id;
+
     -- Migrate billings and payments to aged tables
 
     INSERT INTO money.aged_billing
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.money_aged_billing_summary.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.money_aged_billing_summary.sql
new file mode 100644 (file)
index 0000000..fd05d96
--- /dev/null
@@ -0,0 +1,40 @@
+BEGIN;
+
+--SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+-- Create table to hold aged materialized billable xact summary data
+CREATE TABLE money.aged_billing_summary (
+    id                  BIGINT,
+    xact_start          TIMESTAMP WITH TIME ZONE,
+    xact_finish         TIMESTAMP WITH TIME ZONE,
+    total_paid          NUMERIC,
+    last_payment_ts     TIMESTAMP WITH TIME ZONE,
+    last_payment_note   TEXT,
+    last_payment_type   TEXT,
+    total_owed          NUMERIC,
+    last_billing_ts     TIMESTAMP WITH TIME ZONE,
+    last_billing_note   TEXT,
+    last_billing_type   TEXT,
+    balance_owed        NUMERIC,
+    xact_type           TEXT
+);
+
+ALTER TABLE money.aged_billing_summary ADD PRIMARY KEY (id);
+
+CREATE INDEX money_aged_billing_summary_usr_idx ON money.aged_billing_summary (usr);
+CREATE INDEX money_aged_billing_summary_xact_start_idx ON money.aged_billing_summary (xact_start);
+
+CREATE OR REPLACE VIEW money.all_billing_summary AS
+    SELECT id, xact_start, xact_finish, total_paid, last_payment_ts
+    last_payment_note, last_payment_type, total_owed, last_billing_ts,
+    last_billing_note, last_billing_type, balance_owed, xact_type
+    FROM money.billable_xact_summary
+    UNION ALL
+    SELECT id, xact_start, xact_finish, total_paid, last_payment_ts
+    last_payment_note, last_payment_type, total_owed, last_billing_ts,
+    last_billing_note, last_billing_type, balance_owed, xact_type
+    FROM money.aged_billing_summary;
+
+-- populate the new table with aged billing/payment summary data
+
+COMMIT;