[open-ils-commits] [GIT] Evergreen ILS branch master updated. 425bc5e41e99e2eaf1c87f8fc2e94103574316e4

Evergreen Git git at git.evergreen-ils.org
Thu Mar 1 14:07:52 EST 2018


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  425bc5e41e99e2eaf1c87f8fc2e94103574316e4 (commit)
       via  2eb265e1e1c4a64d65c8045da82539633e45b6e8 (commit)
       via  341ac34fd85fb85a2cd050f498925fbe422a3478 (commit)
       via  ec2cb1a293749522772f1bf967d3d2e0acb0920d (commit)
       via  73a8eaaf265b992bc37b7930c1a4c0a5f75e6a57 (commit)
      from  ba4c86439b16126e37b4e3c691afe11b64b028f4 (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 425bc5e41e99e2eaf1c87f8fc2e94103574316e4
Author: Jeff Godin <jgodin at tadl.org>
Date:   Thu Mar 1 14:06:06 2018 -0500

    LP#1748924 Stamping upgrade script
    
    Stamping upgrade script for expanding billing timestamps
    
    Signed-off-by: Jeff Godin <jgodin at tadl.org>

diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index f9a44c1..19972c6 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 ('1105', :eg_version); --cesardv/kmlussier
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1106', :eg_version); --dbwells/jeff
 
 CREATE TABLE config.bib_source (
 	id		SERIAL	PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.expand_billing_timestamps.sql b/Open-ILS/src/sql/Pg/upgrade/1106.data.expand_billing_timestamps.sql
similarity index 96%
rename from Open-ILS/src/sql/Pg/upgrade/XXXX.data.expand_billing_timestamps.sql
rename to Open-ILS/src/sql/Pg/upgrade/1106.data.expand_billing_timestamps.sql
index 2bb7468..0e53acd 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.expand_billing_timestamps.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/1106.data.expand_billing_timestamps.sql
@@ -1,6 +1,6 @@
 BEGIN;
 
---SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+SELECT evergreen.upgrade_deps_block_check('1106', :eg_version);
 
 ALTER TABLE money.billing
 	ADD COLUMN create_date TIMESTAMP WITH TIME ZONE,

commit 2eb265e1e1c4a64d65c8045da82539633e45b6e8
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Thu Mar 1 13:41:06 2018 -0500

    LP#1748924 Disable materialized summary updates in upgrade script
    
    We are not touching billing_ts, so this trigger eats up a lot of
    time for nothing.  Disable it during the upgrade process.
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Jeff Godin <jgodin at tadl.org>

diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.expand_billing_timestamps.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.expand_billing_timestamps.sql
index e88b4cc..2bb7468 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.expand_billing_timestamps.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.expand_billing_timestamps.sql
@@ -7,6 +7,11 @@ ALTER TABLE money.billing
 	ADD COLUMN period_start    TIMESTAMP WITH TIME ZONE,
 	ADD COLUMN period_end  TIMESTAMP WITH TIME ZONE;
 
+--Disable materialized update trigger
+--It takes forever, and doesn't matter yet for what we are doing, as the
+--view definition is unchanged (still using billing_ts)
+ALTER TABLE money.billing DISABLE TRIGGER mat_summary_upd_tgr;
+
 --Limit to btype=1 / 'Overdue Materials'
 --Update day-granular fines first (i.e. 24 hour, 1 day, 2 day, etc., all of which are multiples of 86400 seconds), and simply remove the time portion of timestamp
 UPDATE money.billing mb
@@ -27,6 +32,9 @@ WHERE mb.xact = ac.id
 SET CONSTRAINTS ALL IMMEDIATE;
 UPDATE money.billing SET create_date = COALESCE(period_start, billing_ts);
 
+--Re-enable update trigger
+ALTER TABLE money.billing ENABLE TRIGGER mat_summary_upd_tgr;
+
 ALTER TABLE money.billing ALTER COLUMN create_date SET DEFAULT NOW();
 ALTER TABLE money.billing ALTER COLUMN create_date SET NOT NULL;
 

commit 341ac34fd85fb85a2cd050f498925fbe422a3478
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Fri Nov 6 14:38:37 2015 -0500

    LP#1748924 Add release notes
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Jeff Godin <jgodin at tadl.org>

diff --git a/docs/RELEASE_NOTES_NEXT/Circulation/billing_ts_now_reflect_billing_time.adoc b/docs/RELEASE_NOTES_NEXT/Circulation/billing_ts_now_reflect_billing_time.adoc
new file mode 100644
index 0000000..1a7a356
--- /dev/null
+++ b/docs/RELEASE_NOTES_NEXT/Circulation/billing_ts_now_reflect_billing_time.adoc
@@ -0,0 +1,15 @@
+Enhanced Billing Timestamp Support
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Previously, billings had to make do with a single timestamp attempting
+to fill two different roles.  In the case of an overdue fine, the
+timestamp represented the *end* of the fine period for that billing,
+while for all other fines, the timestamp was merely the time the bill
+was created.  This setup generally worked, but not without confusion,
+and limited our ability to understand and process the data.
+
+Billings will now have up to three timestamps: a create date, and when
+applicable, a fine period start and a fine period end.  This clarifies
+and simplifies things like backdating, retrospective fine generation,
+account balancing for negative balance avoidance, and billing timeline
+views.

commit ec2cb1a293749522772f1bf967d3d2e0acb0920d
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Mon Feb 12 10:48:14 2018 -0500

    LP#1748924 Upgrade script for expanding billing timestamps
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Jeff Godin <jgodin at tadl.org>

diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.expand_billing_timestamps.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.expand_billing_timestamps.sql
new file mode 100644
index 0000000..e88b4cc
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.expand_billing_timestamps.sql
@@ -0,0 +1,45 @@
+BEGIN;
+
+--SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+ALTER TABLE money.billing
+	ADD COLUMN create_date TIMESTAMP WITH TIME ZONE,
+	ADD COLUMN period_start    TIMESTAMP WITH TIME ZONE,
+	ADD COLUMN period_end  TIMESTAMP WITH TIME ZONE;
+
+--Limit to btype=1 / 'Overdue Materials'
+--Update day-granular fines first (i.e. 24 hour, 1 day, 2 day, etc., all of which are multiples of 86400 seconds), and simply remove the time portion of timestamp
+UPDATE money.billing mb
+	SET period_start = date_trunc('day', billing_ts), period_end = date_trunc('day', billing_ts) + (ac.fine_interval - '1 second')
+	FROM action.circulation ac
+WHERE mb.xact = ac.id
+	AND mb.btype = 1
+	AND (EXTRACT(EPOCH FROM ac.fine_interval))::integer % 86400 = 0;
+
+--Update fines for non-day intervals
+UPDATE money.billing mb
+	SET period_start = billing_ts - ac.fine_interval + interval '1 sec', period_end = billing_ts
+	FROM action.circulation ac
+WHERE mb.xact = ac.id
+	AND mb.btype = 1
+	AND (EXTRACT(EPOCH FROM ac.fine_interval))::integer % 86400 > 0;
+
+SET CONSTRAINTS ALL IMMEDIATE;
+UPDATE money.billing SET create_date = COALESCE(period_start, billing_ts);
+
+ALTER TABLE money.billing ALTER COLUMN create_date SET DEFAULT NOW();
+ALTER TABLE money.billing ALTER COLUMN create_date SET NOT NULL;
+
+CREATE INDEX m_b_create_date_idx ON money.billing (create_date);
+CREATE INDEX m_b_period_start_idx ON money.billing (period_start);
+CREATE INDEX m_b_period_end_idx ON money.billing (period_end);
+
+CREATE OR REPLACE FUNCTION money.maintain_billing_ts () RETURNS TRIGGER AS $$
+BEGIN
+	NEW.billing_ts := COALESCE(NEW.period_end, NEW.create_date);
+	RETURN NEW;
+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();
+
+COMMIT;

commit 73a8eaaf265b992bc37b7930c1a4c0a5f75e6a57
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Mon Feb 12 10:11:33 2018 -0500

    LP#1748924 Enhanced Billing Timestamp Support
    
    As discussed at Hack-a-way 2016, rather than continue to try to cram
    multiple meanings into one timestamp, let's create a complete set of
    all the useful timestamps for a typical billing.
    
    In this new config, every billing will have a 'create_date', then most
    (overdues) will also describe when they start and end.
    
    billing_ts is now deprecated, but will continue to exist for backwards
    compatibility.  It will be managed by trigger to approximate its
    current definition; equal to 'period_end' for overdues, equal to
    'create_date' for other billings.
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Jeff Godin <jgodin at tadl.org>

diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml
index ae53496..b272b9f 100644
--- a/Open-ILS/examples/fm_IDL.xml
+++ b/Open-ILS/examples/fm_IDL.xml
@@ -7987,7 +7987,10 @@ SELECT  usr,
 	<class id="mb" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="money::billing" oils_persist:tablename="money.billing" reporter:label="Billing Line Item">
 		<fields oils_persist:primary="id" oils_persist:sequence="money.billing_id_seq">
 			<field reporter:label="Amount" name="amount" reporter:datatype="money" />
-			<field reporter:label="Billing Timestamp" name="billing_ts" reporter:datatype="timestamp"/>
+			<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"/>
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm
index c7caea7..879644f 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm
@@ -199,7 +199,7 @@ sub reopen_xact {
 
 
 sub create_bill {
-    my($class, $e, $amount, $btype, $type, $xactid, $note, $billing_ts) = @_;
+    my($class, $e, $amount, $btype, $type, $xactid, $note, $period_start, $period_end) = @_;
 
     $logger->info("The system is charging $amount [$type] on xact $xactid");
     $note ||= 'SYSTEM GENERATED';
@@ -209,7 +209,8 @@ sub create_bill {
     my $bill = Fieldmapper::money::billing->new;
     $bill->xact($xactid);
     $bill->amount($amount);
-    $bill->billing_ts($billing_ts);
+    $bill->period_start($period_start);
+    $bill->period_end($period_end);
     $bill->billing_type($type); 
     $bill->btype($btype); 
     $bill->note($note);
@@ -579,7 +580,7 @@ sub generate_fines {
             my $tz = $U->ou_ancestor_setting_value(
                 $c->$circ_lib_method, 'lib.timezone') || 'local';
 
-            my ($latest_billing_ts, $latest_amount) = ('',0);
+            my ($latest_period_end, $latest_amount) = ('',0);
             for (my $bill = 1; $bill <= $pending_fine_count; $bill++) {
     
                 if ($current_fine_total >= $max_fine) {
@@ -596,16 +597,17 @@ sub generate_fines {
                 }
                 
                 # Use org time zone (or default to 'local')
-                my $billing_ts = DateTime->from_epoch( epoch => $last_fine, time_zone => $tz );
+                my $period_end = DateTime->from_epoch( epoch => $last_fine, time_zone => $tz );
                 my $current_bill_count = $bill;
                 while ( $current_bill_count ) {
-                    $billing_ts->add( seconds_to_interval_hash( $fine_interval ) );
+                    $period_end->add( seconds_to_interval_hash( $fine_interval ) );
                     $current_bill_count--;
                 }
+                my $period_start = $period_end->clone->subtract( seconds_to_interval_hash( $fine_interval - 1 ) );
 
-                my $timestamptz = $billing_ts->strftime('%FT%T%z');
+                my $timestamptz = $period_end->strftime('%FT%T%z');
                 if (!$skip_closed_check) {
-                    my $dow = $billing_ts->day_of_week_0();
+                    my $dow = $period_end->day_of_week_0();
                     my $dow_open = "dow_${dow}_open";
                     my $dow_close = "dow_${dow}_close";
 
@@ -630,7 +632,7 @@ sub generate_fines {
                 }
                 $current_fine_total += $this_billing_amount;
                 $latest_amount += $this_billing_amount;
-                $latest_billing_ts = $timestamptz;
+                $latest_period_end = $timestamptz;
 
                 my $bill = Fieldmapper::money::billing->new;
                 $bill->xact($c->id);
@@ -638,13 +640,14 @@ sub generate_fines {
                 $bill->billing_type("Overdue materials");
                 $bill->btype(1);
                 $bill->amount(sprintf('%0.2f', $this_billing_amount/100));
-                $bill->billing_ts($timestamptz);
+                $bill->period_start($period_start->strftime('%FT%T%z'));
+                $bill->period_end($timestamptz);
                 $e->create_money_billing($bill);
 
             }
 
-            $conn->respond( "\t\tAdding fines totaling $latest_amount for overdue up to $latest_billing_ts\n" )
-                if ($conn and $latest_billing_ts and $latest_amount);
+            $conn->respond( "\t\tAdding fines totaling $latest_amount for overdue up to $latest_period_end\n" )
+                if ($conn and $latest_period_end and $latest_amount);
 
 
             # Calculate penalties inline
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
index deb9541..3f3d946 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
@@ -4222,7 +4222,8 @@ sub checkin_handle_lost_or_lo_now_found_restore_od {
             $ods->[0]->billing_type(),
             $self->circ->id(),
             "System: $tag RETURNED - OVERDUES REINSTATED",
-            $ods->[0]->billing_ts() # date this restoration the same as the last overdue (for possible subsequent fine generation)
+            $ods->[-1]->period_start(),
+            $ods->[0]->period_end() # date this restoration the same as the last overdue (for possible subsequent fine generation)
         );
     }
 }
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm
index f177e5d..009da40 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm
@@ -978,7 +978,8 @@ sub _rebill_xact {
             $billing->billing_type,
             $xact_id,
             "System: MANUAL ADJUSTMENT, BILLING #".$billing->id." REINSTATED\n(PREV: ".$billing->note.")",
-            $billing->billing_ts()
+            $billing->period_start(),
+            $billing->period_end()
         );
         return $evt if $evt;
         $rebill_amount += $billing->amount;
diff --git a/Open-ILS/src/sql/Pg/080.schema.money.sql b/Open-ILS/src/sql/Pg/080.schema.money.sql
index 6265ae8..b5f3b27 100644
--- a/Open-ILS/src/sql/Pg/080.schema.money.sql
+++ b/Open-ILS/src/sql/Pg/080.schema.money.sql
@@ -51,18 +51,32 @@ CREATE INDEX m_g_usr_idx ON "money".grocery (usr);
 CREATE TABLE money.billing (
 	id		BIGSERIAL			PRIMARY KEY,
 	xact		BIGINT				NOT NULL, -- money.billable_xact.id
-	billing_ts	TIMESTAMP WITH TIME ZONE	NOT NULL DEFAULT NOW(),
+	billing_ts	TIMESTAMP WITH TIME ZONE	NOT NULL, -- DEPRECATED, legacy only
 	voided		BOOL				NOT NULL DEFAULT FALSE,
 	voider		INT,
 	void_time	TIMESTAMP WITH TIME ZONE,
 	amount		NUMERIC(6,2)			NOT NULL,
 	billing_type	TEXT				NOT NULL,
 	btype		INT				NOT NULL REFERENCES config.billing_type (id) ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED,
-	note		TEXT
+	note		TEXT,
+	create_date	TIMESTAMP WITH TIME ZONE	NOT NULL DEFAULT NOW(),
+	period_start	TIMESTAMP WITH TIME ZONE,
+	period_end	TIMESTAMP WITH TIME ZONE
 );
 CREATE INDEX m_b_xact_idx ON money.billing (xact);
 CREATE INDEX m_b_time_idx ON money.billing (billing_ts);
+CREATE INDEX m_b_create_date_idx ON money.billing (create_date);
+CREATE INDEX m_b_period_start_idx ON money.billing (period_start);
+CREATE INDEX m_b_period_end_idx ON money.billing (period_end);
 CREATE INDEX m_b_voider_idx ON money.billing (voider); -- helps user merge function speed
+CREATE OR REPLACE FUNCTION money.maintain_billing_ts () RETURNS TRIGGER AS $$
+BEGIN
+	NEW.billing_ts := COALESCE(NEW.period_end, NEW.create_date);
+	RETURN NEW;
+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,

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

Summary of changes:
 Open-ILS/examples/fm_IDL.xml                       |    5 ++-
 .../lib/OpenILS/Application/Circ/CircCommon.pm     |   25 +++++----
 .../lib/OpenILS/Application/Circ/Circulate.pm      |    3 +-
 .../perlmods/lib/OpenILS/Application/Circ/Money.pm |    3 +-
 Open-ILS/src/sql/Pg/002.schema.config.sql          |    2 +-
 Open-ILS/src/sql/Pg/080.schema.money.sql           |   18 ++++++-
 .../1106.data.expand_billing_timestamps.sql        |   53 ++++++++++++++++++++
 .../billing_ts_now_reflect_billing_time.adoc       |   15 ++++++
 8 files changed, 107 insertions(+), 17 deletions(-)
 create mode 100644 Open-ILS/src/sql/Pg/upgrade/1106.data.expand_billing_timestamps.sql
 create mode 100644 docs/RELEASE_NOTES_NEXT/Circulation/billing_ts_now_reflect_billing_time.adoc


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list