]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/version-upgrade/2.9.2-2.9.3-upgrade-db.sql
LP#1772028 Add some FK violation functions just in case they are missing
[Evergreen.git] / Open-ILS / src / sql / Pg / version-upgrade / 2.9.2-2.9.3-upgrade-db.sql
1 --Upgrade Script for 2.9.2 to 2.9.3
2 \set eg_version '''2.9.3'''
3 BEGIN;
4 INSERT INTO config.upgrade_log (version, applied_to) VALUES ('2.9.3', :eg_version);
5
6 SELECT evergreen.upgrade_deps_block_check('0959', :eg_version);
7
8 CREATE OR REPLACE VIEW money.transaction_billing_summary AS
9     SELECT id as xact,
10         last_billing_type,
11         last_billing_note,
12         last_billing_ts,
13         total_owed
14       FROM money.materialized_billable_xact_summary;
15
16
17 SELECT evergreen.upgrade_deps_block_check('0971', :eg_version);
18
19 CREATE OR REPLACE FUNCTION evergreen.protect_reserved_rows_from_delete() RETURNS trigger AS $protect_reserved$
20 BEGIN
21 IF OLD.id < TG_ARGV[0]::INT THEN
22     RAISE EXCEPTION 'Cannot delete row with reserved ID %', OLD.id; 
23 END IF;
24 RETURN OLD;
25 END
26 $protect_reserved$
27 LANGUAGE plpgsql;
28
29
30 SELECT evergreen.upgrade_deps_block_check('0972', :eg_version); -- jstompro/gmcharlt
31
32 -- LP#1550495 - Add Baker&Taylor EDI Quantity Cancel Code
33 -- Insert EDI Cancel Reason 85 (1200 + 85 = 1285) if it doesn't already exist
34 INSERT INTO acq.cancel_reason 
35    (org_unit, keep_debits, id, label, description)
36    SELECT 
37      1, 'f',( 85+1200),
38      oils_i18n_gettext(1285, 'Canceled: By Vendor', 'acqcr', 'label'),
39      oils_i18n_gettext(1285, 'Line item canceled by vendor', 'acqcr', 'description')
40    WHERE NOT EXISTS (
41     SELECT 1 FROM acq.cancel_reason where id=(85+1200)
42    );
43
44
45
46 SELECT evergreen.upgrade_deps_block_check('0973', :eg_version); -- tmccanna/gmcharlt
47
48 UPDATE action_trigger.event_definition SET template = 
49 $$
50 [%- USE date -%]
51 [%- SET user = target -%]
52 <div>
53     <style> li { padding: 8px; margin 5px; }</style>
54     <div>[% date.format %]</div>
55     <br/>   
56         Fines for:<br/>
57     [% user.family_name %], [% user.first_given_name %]
58     <ol>
59     [% FOR xact IN user.open_billable_transactions_summary %]
60         [% IF xact.balance_owed > 0 %]
61             <li>
62                 <div>Details: 
63                     [% IF xact.xact_type == 'circulation' %]
64                         [%- helpers.get_copy_bib_basics(xact.circulation.target_copy).title -%]
65                     [% ELSE %]
66                         [%- xact.last_billing_type -%]
67                     [% END %]
68                 </div>
69                 <div>Total Billed: [% xact.total_owed %]</div>
70                 <div>Total Paid: [% xact.total_paid %]</div>
71                 <div>Balance Owed : [% xact.balance_owed %]</div>
72             </li>
73         [% END %]
74     [% END %]
75     </ol>
76 </div>
77 $$ WHERE id=13
78 AND template = 
79 $$
80 [%- USE date -%]
81 [%- SET user = target -%]
82 <div>
83     <style> li { padding: 8px; margin 5px; }</style>
84     <div>[% date.format %]</div>
85     <br/>
86
87     [% user.family_name %], [% user.first_given_name %]
88     <ol>
89     [% FOR xact IN user.open_billable_transactions_summary %]
90         <li>
91             <div>Details: 
92                 [% IF xact.xact_type == 'circulation' %]
93                     [%- helpers.get_copy_bib_basics(xact.circulation.target_copy).title -%]
94                 [% ELSE %]
95                     [%- xact.last_billing_type -%]
96                 [% END %]
97             </div>
98             <div>Total Billed: [% xact.total_owed %]</div>
99             <div>Total Paid: [% xact.total_paid %]</div>
100             <div>Balance Owed : [% xact.balance_owed %]</div>
101         </li>
102     [% END %]
103     </ol>
104 </div>
105 $$
106 ;
107
108
109 SELECT evergreen.upgrade_deps_block_check('0974', :eg_version); -- tmccanna/gmcharlt
110
111 UPDATE action_trigger.event_definition SET template = 
112 $$
113 [%- USE date -%]
114 [%- SET user = target.0.usr -%]
115 <div>
116     <style> li { padding: 8px; margin 5px; }</style>
117     <div>[% date.format %]</div>
118     <br/>
119     Holds for:<br/>
120         [% user.family_name %], [% user.first_given_name %]
121         
122     <ol>
123     [% FOR hold IN target %]
124         [%-
125             SET idx = loop.count - 1;
126             SET udata =  user_data.$idx;
127         -%]
128         <li>
129             <div>Title: [% udata.item_title %]</div>
130             <div>Author: [% udata.item_author %]</div>
131             <div>Pickup Location: [% udata.pickup_lib %]</b></div>
132             <div>Status: 
133                 [%- IF udata.ready -%]
134                     Ready for pickup
135                 [% ELSE %]
136                     #[% udata.queue_position %] of 
137                       [% udata.potential_copies %] copies.
138                 [% END %]
139             </div>
140         </li>
141     [% END %]
142     </ol>
143 </div>
144
145 $$ WHERE id=12
146 AND template = 
147 $$
148 [%- USE date -%]
149 [%- SET user = target.0.usr -%]
150 <div>
151     <style> li { padding: 8px; margin 5px; }</style>
152     <div>[% date.format %]</div>
153     <br/>
154
155     [% user.family_name %], [% user.first_given_name %]
156     <ol>
157     [% FOR hold IN target %]
158         [%-
159             SET idx = loop.count - 1;
160             SET udata =  user_data.$idx
161         -%]
162         <li>
163             <div>Title: [% hold.bib_rec.bib_record.simple_record.title %]</div>
164             <div>Author: [% hold.bib_rec.bib_record.simple_record.author %]</div>
165             <div>Pickup Location: [% hold.pickup_lib.name %]</div>
166             <div>Status: 
167                 [%- IF udata.ready -%]
168                     Ready for pickup
169                 [% ELSE %]
170                     #[% udata.queue_position %] of [% udata.potential_copies %] copies.
171                 [% END %]
172             </div>
173         </li>
174     [% END %]
175     </ol>
176 </div>
177 $$
178 ;
179
180 COMMIT;