]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/XXXX.30day.expiration.prenotice.sql
LP#1124498 Patron notification via email for card expiration
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / XXXX.30day.expiration.prenotice.sql
1 BEGIN;
2
3 --create hook for actor.usr.expire_date
4 INSERT INTO action_trigger.hook (key, core_type, description, passive)
5     VALUES ('expire', 'au', 'Card is expired', 't');
6         
7         --SQL to create event definition for 30 day card pre-expiration notice
8 --Inactive, owned by top of org tree by default.  Modify to suit needs.
9 --Can set reactor to 'ProcessTemplate' for testing.  Will generate emails in DB, but not actually send.
10
11 INSERT INTO action_trigger.event_definition (active, owner, name, hook, validator, reactor, delay, delay_field, group_field, max_delay, template)
12     VALUES ('t', '1', '30 Day Card Expiration Courtesy Notice', 'expire', 'NOOP_True', 'SendEmail', '-30 days', 'expire_date', 'usr', '-29 days',
13         $$
14 [%- USE date -%]
15 [%- user = target -%]
16 [%- lib = target.home_ou -%]
17 To: [%- params.recipient_email || user.email %]
18 From: [%- helpers.get_org_setting(target.home_ou.id, 'org.bounced_emails') || lib.email || params.sender_email || default_sender %]
19 Reply-To: [%- helpers.get_org_setting(target.home_ou.id, 'org.bounced_emails') || lib.email || params.sender_email || default_sender %]
20 Errors-To: [%- helpers.get_org_setting(target.home_ou.id, 'org.bounced_emails') || lib.email || params.sender_email || default_sender %]
21 Subject: Courtesy Notice - Library Card Expiration in 30 days
22
23 Dear [% user.first_given_name %] [% user.family_name %],
24
25 Our records indicate your library card is due to expire in 30 days.  Please visit your local library at your convenience to renew your card in order to avoid a disruption in access to library service.
26
27 Sincerely,
28 [% lib.name %]
29
30 Contact your library for more information:
31
32 [% lib.name %]
33 [%- SET addr = lib.mailing_address -%]
34 [%- IF !addr -%] [%- SET addr = lib.billing_address -%] [%- END %]
35 [% lib.mailing_address.street1 %] [% lib.mailing_address.street2 %]
36 [% lib.mailing_address.city %], [% lib.mailing_address.state %]
37 [% lib.mailing_address.post_code %]
38 [% lib.phone %]
39
40 $$);
41
42 --get current value in sequence
43 SELECT currval('action_trigger.event_definition_id_seq');
44
45 --send from email address parameter
46 INSERT INTO action_trigger.event_params (event_def, param, value)
47         VALUES (CURRVAL('action_trigger.event_definition_id_seq'), 'sender_email', 'evergreen@example.org');
48         
49 --insert environment values
50 INSERT INTO action_trigger.environment (event_def, path)
51     VALUES (CURRVAL('action_trigger.event_definition_id_seq'), 'home_ou.mailing_address');
52         
53 INSERT INTO action_trigger.environment (event_def, path)
54     VALUES (CURRVAL('action_trigger.event_definition_id_seq'), 'home_ou.billing_address');      
55         
56 COMMIT;