]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0996.data.email-checkout-receipt.sql
LP#1638299: Stamping upgrade scripts for authority infrastructure work
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0996.data.email-checkout-receipt.sql
1 BEGIN;
2
3 SELECT evergreen.upgrade_deps_block_check('0996', :eg_version);
4
5 INSERT INTO config.usr_setting_type (
6     name,
7     opac_visible,
8     label,
9     description,
10     datatype
11 ) VALUES (
12     'circ.send_email_checkout_receipts',
13     TRUE,
14     oils_i18n_gettext('circ.send_email_checkout_receipts', 'Email checkout receipts by default?', 'cust', 'label'),
15     oils_i18n_gettext('circ.send_email_checkout_receipts', 'Email checkout receipts by default?', 'cust', 'description'),
16     'bool'
17 );
18
19 INSERT INTO action_trigger.hook (key, core_type, description, passive)
20 VALUES (
21     'circ.checkout.batch_notify',
22     'circ',
23     oils_i18n_gettext(
24         'circ.checkout.batch_notify',
25         'Notification of a group of circs',
26         'ath',
27         'description'
28     ),
29     FALSE
30 );
31
32 INSERT INTO action_trigger.hook (key, core_type, description, passive)
33 VALUES (
34     'circ.checkout.batch_notify.session',
35     'circ',
36     oils_i18n_gettext(
37         'circ.checkout.batch_notify.session',
38         'Notification of a group of circs at the end of a checkout session',
39         'ath',
40         'description'
41     ),
42     FALSE
43 );
44
45 INSERT INTO action_trigger.event_definition (
46     active,
47     owner,
48     name,
49     hook,
50     validator,
51     reactor,
52     usr_field,
53     opt_in_setting,
54     group_field,
55     template
56 ) VALUES (
57     TRUE,
58     1,
59     'Email Checkout Receipt',
60     'circ.checkout.batch_notify.session',
61     'NOOP_True',
62     'SendEmail',
63     'usr',
64     'circ.send_email_checkout_receipts',
65     'usr',
66     $$[%- USE date -%]
67 [%- user = target.0.usr -%]
68 To: [%- params.recipient_email || user.email %]
69 From: [%- helpers.get_org_setting(target.0.circ_lib.id, 'org.bounced_emails') || params.sender_email || default_sender %]
70 Subject: Checkout Receipt
71 Auto-Submitted: auto-generated
72
73 You checked out the following items:
74
75 [% FOR circ IN target %]
76     [%- copy_details = helpers.get_copy_bib_basics(circ.target_copy.id) -%]
77     Title: [% copy_details.title %]
78     Author: [% copy_details.author %]
79     Call Number: [% circ.target_copy.call_number.label %]
80     Barcode: [% circ.target_copy.barcode %]
81     Due: [% date.format(helpers.format_date(circ.due_date), '%Y-%m-%d') %]
82     Library: [% circ.circ_lib.name %]
83
84 [% END %]
85 $$);
86
87 INSERT INTO action_trigger.environment (
88     event_def,
89     path
90 ) VALUES (
91     currval('action_trigger.event_definition_id_seq'),
92     'target_copy.call_number'
93 ), (
94     currval('action_trigger.event_definition_id_seq'),
95     'target_copy.location'
96 ), (
97     currval('action_trigger.event_definition_id_seq'),
98     'usr'
99 ), (
100     currval('action_trigger.event_definition_id_seq'),
101     'circ_lib'
102 );
103
104 COMMIT;
105