]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/XXXX.autorenewals_acp_and_circ_duration.sql
LP#1779920 Circ auto-renewal repairs
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / XXXX.autorenewals_acp_and_circ_duration.sql
1 BEGIN;
2     -- SELECT evergreen.upgrade_deps_block_check('xxxx', :eg_version);
3
4     ALTER TABLE config.rule_circ_duration
5     ADD column max_auto_renewals INTEGER;
6
7     ALTER TABLE action.circulation
8     ADD column auto_renewal BOOLEAN;
9
10     ALTER TABLE action.circulation
11     ADD column auto_renewal_remaining INTEGER;
12
13     INSERT INTO action_trigger.validator values('CircIsAutoRenewable', 'Checks whether the circulation is able to be autorenewed.');
14     INSERT INTO action_trigger.reactor values('Circ::AutoRenew', 'Auto-Renews a circulation.');
15     INSERT INTO action_trigger.hook(key, core_type, description) values('autorenewal', 'circ', 'Item was auto-renewed to patron.');
16
17     -- AutoRenewer A/T Def: 
18     INSERT INTO action_trigger.event_definition(active, owner, name, hook, validator, reactor, delay, max_delay, delay_field, group_field)
19         values (false, 1, 'Autorenew', 'checkout.due', 'CircIsOpen', 'Circ::AutoRenew', '-23 hours'::interval,'-1 minute'::interval, 'due_date', 'usr');
20
21     -- AutoRenewal outcome Email notifier A/T Def:
22     INSERT INTO action_trigger.event_definition(active, owner, name, hook, validator, reactor, group_field, template)
23         values (false, 1, 'AutorenewNotify', 'autorenewal', 'NOOP_True', 'SendEmail', 'usr', 
24 $$
25 [%- USE date -%]
26 [%- user = target.0.usr -%]
27 To: [%- params.recipient_email || user.email %]
28 From: [%- params.sender_email || default_sender %]
29 Date: [%- date.format(date.now, '%a, %d %b %Y %T -0000', gmt => 1) %]
30 Subject: Items Out Auto-Renewal Notification 
31 Auto-Submitted: auto-generated
32
33 Dear [% user.family_name %], [% user.first_given_name %]
34 An automatic renewal attempt was made for the following items:
35
36 [% FOR circ IN target %]
37     [%- SET idx = loop.count - 1; SET udata =  user_data.$idx -%]
38     [%- SET cid = circ.target_copy || udata.copy -%]
39     [%- SET copy_details = helpers.get_copy_bib_basics(cid) -%]
40     Item# [% loop.count %]
41     Title: [% copy_details.title %]
42     Author: [% copy_details.author %]
43     [%- IF udata.is_renewed %]
44     Status: Loan Renewed
45     New Due Date: [% date.format(helpers.format_date(udata.new_due_date), '%Y-%m-%d') %]
46     [%- ELSE %]
47     Status: Not Renewed
48     Reason: [% udata.reason %]
49     Due Date: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]
50     [% END %]
51 [% END %]
52 $$
53     );
54
55     INSERT INTO action_trigger.environment (event_def, path ) VALUES
56     ( currval('action_trigger.event_definition_id_seq'), 'usr' ),
57     ( currval('action_trigger.event_definition_id_seq'), 'circ_lib' );
58
59 COMMIT;