From 7c4dfc66d51774dd9a6e97b5642235ad4ca3cf73 Mon Sep 17 00:00:00 2001
From: Terran McCanna <tmccanna@georgialibraries.org>
Date: Tue, 5 Mar 2019 16:46:47 -0500
Subject: [PATCH] LP#1818581 Action Trigger for Fine Limit Exceeded

Creates new (optional) email notification that is
sent when a block is applied to a patron's account
due to excess fines.

Signed-off-by: Terran McCanna <tmccanna@georgialibraries.org>
Signed-off-by: Rogan Hamby <rogan.hamby@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
---
 Open-ILS/src/sql/Pg/950.data.seed-values.sql       | 31 ++++++++++++++++++++++
 ...rigger.event_definition.fine_limit_exceeded.sql | 31 ++++++++++++++++++++++
 .../Administration/Fine_Limit_Exceeded.adoc        |  8 ++++++
 3 files changed, 70 insertions(+)
 create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.data.action-trigger.event_definition.fine_limit_exceeded.sql
 create mode 100644 docs/RELEASE_NOTES_NEXT/Administration/Fine_Limit_Exceeded.adoc

diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql
index 36260a4f4c..4e8984b558 100644
--- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql
+++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql
@@ -10355,6 +10355,37 @@ INSERT INTO action_trigger.environment (event_def, path ) VALUES
 
 -- END of autorenwal trigger def stuff
 
+-- Action Trigger for Fine Limit Exceeded--
+
+INSERT INTO action_trigger.event_definition (active, owner, name, hook, validator, reactor, delay, group_field, max_delay, template) 
+    VALUES (false, 1, 'Fine Limit Exceeded', 'penalty.PATRON_EXCEEDS_FINES', 'NOOP_True', 'SendEmail', '00:05:00', 'usr', '1 day', 
+$$
+[%- USE date -%]
+[%- user = target.usr -%]
+
+To: [%- params.recipient_email || user.email %]
+From: [%- params.sender_email || default_sender %]
+Date: [%- date.format(date.now, '%a, %d %b %Y %T -0000', gmt => 1) %]
+Subject: Fine Limit Exceeded
+Auto-Submitted: auto-generated
+
+Dear [% user.first_given_name %] [% user.family_name %],
+
+
+Our records indicate your account has exceeded the fine limit allowed for the use of your library account.
+
+Please visit the library to pay your fines and restore full access to your account.
+[% END %]
+
+$$);
+
+INSERT INTO action_trigger.environment (event_def, path) VALUES
+    (currval('action_trigger.event_definition_id_seq'), 'usr'),
+    (currval('action_trigger.event_definition_id_seq'), 'usr.card');
+
+-- End Action Trigger for Fine Limit Exceeded
+
+
 -- in-db indexing normalizers
 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
 	'NACO Normalize',
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.action-trigger.event_definition.fine_limit_exceeded.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.action-trigger.event_definition.fine_limit_exceeded.sql
new file mode 100644
index 0000000000..c88dd406ce
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.action-trigger.event_definition.fine_limit_exceeded.sql
@@ -0,0 +1,31 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+INSERT INTO action_trigger.event_definition (active, owner, name, hook, validator, reactor, delay, group_field, max_delay, template) 
+    VALUES (false, 1, 'Fine Limit Exceeded', 'penalty.PATRON_EXCEEDS_FINES', 'NOOP_True', 'SendEmail', '00:05:00', 'usr', '1 day', 
+$$
+[%- USE date -%]
+[%- user = target.usr -%]
+
+To: [%- params.recipient_email || user.email %]
+From: [%- params.sender_email || default_sender %]
+Date: [%- date.format(date.now, '%a, %d %b %Y %T -0000', gmt => 1) %]
+Subject: Fine Limit Exceeded
+Auto-Submitted: auto-generated
+
+Dear [% user.first_given_name %] [% user.family_name %],
+
+
+Our records indicate your account has exceeded the fine limit allowed for the use of your library account.
+
+Please visit the library to pay your fines and restore full access to your account.
+[% END %]
+
+$$);
+
+INSERT INTO action_trigger.environment (event_def, path) VALUES
+    (currval('action_trigger.event_definition_id_seq'), 'usr'),
+    (currval('action_trigger.event_definition_id_seq'), 'usr.card');
+
+COMMIT;
\ No newline at end of file
diff --git a/docs/RELEASE_NOTES_NEXT/Administration/Fine_Limit_Exceeded.adoc b/docs/RELEASE_NOTES_NEXT/Administration/Fine_Limit_Exceeded.adoc
new file mode 100644
index 0000000000..3f87964dd5
--- /dev/null
+++ b/docs/RELEASE_NOTES_NEXT/Administration/Fine_Limit_Exceeded.adoc
@@ -0,0 +1,8 @@
+New Action Trigger - Fine Limit Exceeded
+^^^^^^^^^^^^^
+New optional email notification that is sent when a block is applied
+to a patron's account due to excess fines.
+
+(The patron block functionality itself already exists and is based on
+the settings in Local Admin > Standing Penalties (PATRON_EXCEEDS_FINES)
+and Local Administration > Group Penalty Thresholds.)
\ No newline at end of file
-- 
2.11.0