]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0957.data.drop_cc_cols.sql
LP#1474051 Stamping upgrade script for drop-cc-data
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0957.data.drop_cc_cols.sql
1
2 BEGIN;
3
4 SELECT evergreen.upgrade_deps_block_check('0957', :eg_version);
5
6 -- Remove references to dropped CC payment columns in the print/email 
7 -- payment receipt templates, but only if the in-db template matches 
8 -- the stock template.
9 -- The actual diff here is only about 8 lines.
10
11 UPDATE action_trigger.event_definition SET template = 
12 $$
13 [%- USE date -%]
14 [%- SET user = target.0.xact.usr -%]
15 To: [%- params.recipient_email || user.email %]
16 From: [%- params.sender_email || default_sender %]
17 Subject: Payment Receipt
18
19 [% date.format -%]
20 [%- SET xact_mp_hash = {} -%]
21 [%- FOR mp IN target %][%# Template is hooked around payments, but let us make the receipt focused on transactions -%]
22     [%- SET xact_id = mp.xact.id -%]
23     [%- IF ! xact_mp_hash.defined( xact_id ) -%][%- xact_mp_hash.$xact_id = { 'xact' => mp.xact, 'payments' => [] } -%][%- END -%]
24     [%- xact_mp_hash.$xact_id.payments.push(mp) -%]
25 [%- END -%]
26 [%- FOR xact_id IN xact_mp_hash.keys.sort -%]
27     [%- SET xact = xact_mp_hash.$xact_id.xact %]
28 Transaction ID: [% xact_id %]
29     [% IF xact.circulation %][% helpers.get_copy_bib_basics(xact.circulation.target_copy).title %]
30     [% ELSE %]Miscellaneous
31     [% END %]
32     Line item billings:
33         [%- SET mb_type_hash = {} -%]
34         [%- FOR mb IN xact.billings %][%# Group billings by their btype -%]
35             [%- IF mb.voided == 'f' -%]
36                 [%- SET mb_type = mb.btype.id -%]
37                 [%- IF ! mb_type_hash.defined( mb_type ) -%][%- mb_type_hash.$mb_type = { 'sum' => 0.00, 'billings' => [] } -%][%- END -%]
38                 [%- IF ! mb_type_hash.$mb_type.defined( 'first_ts' ) -%][%- mb_type_hash.$mb_type.first_ts = mb.billing_ts -%][%- END -%]
39                 [%- mb_type_hash.$mb_type.last_ts = mb.billing_ts -%]
40                 [%- mb_type_hash.$mb_type.sum = mb_type_hash.$mb_type.sum + mb.amount -%]
41                 [%- mb_type_hash.$mb_type.billings.push( mb ) -%]
42             [%- END -%]
43         [%- END -%]
44         [%- FOR mb_type IN mb_type_hash.keys.sort -%]
45             [%- IF mb_type == 1 %][%-# Consolidated view of overdue billings -%]
46                 $[% mb_type_hash.$mb_type.sum %] for [% mb_type_hash.$mb_type.billings.0.btype.name %] 
47                     on [% mb_type_hash.$mb_type.first_ts %] through [% mb_type_hash.$mb_type.last_ts %]
48             [%- ELSE -%][%# all other billings show individually %]
49                 [% FOR mb IN mb_type_hash.$mb_type.billings %]
50                     $[% mb.amount %] for [% mb.btype.name %] on [% mb.billing_ts %] [% mb.note %]
51                 [% END %]
52             [% END %]
53         [% END %]
54     Line item payments:
55         [% FOR mp IN xact_mp_hash.$xact_id.payments %]
56             Payment ID: [% mp.id %]
57                 Paid [% mp.amount %] via [% SWITCH mp.payment_type -%]
58                     [% CASE "cash_payment" %]cash
59                     [% CASE "check_payment" %]check
60                     [% CASE "credit_card_payment" %]credit card
61                     [%- IF mp.credit_card_payment.cc_number %] ([% mp.credit_card_payment.cc_number %])[% END %]
62                     [% CASE "credit_payment" %]credit
63                     [% CASE "forgive_payment" %]forgiveness
64                     [% CASE "goods_payment" %]goods
65                     [% CASE "work_payment" %]work
66                 [%- END %] on [% mp.payment_ts %] [% mp.note %]
67         [% END %]
68 [% END %]
69 $$
70
71 WHERE id = 29 AND template =
72
73 $$
74 [%- USE date -%]
75 [%- SET user = target.0.xact.usr -%]
76 To: [%- params.recipient_email || user.email %]
77 From: [%- params.sender_email || default_sender %]
78 Subject: Payment Receipt
79
80 [% date.format -%]
81 [%- SET xact_mp_hash = {} -%]
82 [%- FOR mp IN target %][%# Template is hooked around payments, but let us make the receipt focused on transactions -%]
83     [%- SET xact_id = mp.xact.id -%]
84     [%- IF ! xact_mp_hash.defined( xact_id ) -%][%- xact_mp_hash.$xact_id = { 'xact' => mp.xact, 'payments' => [] } -%][%- END -%]
85     [%- xact_mp_hash.$xact_id.payments.push(mp) -%]
86 [%- END -%]
87 [%- FOR xact_id IN xact_mp_hash.keys.sort -%]
88     [%- SET xact = xact_mp_hash.$xact_id.xact %]
89 Transaction ID: [% xact_id %]
90     [% IF xact.circulation %][% helpers.get_copy_bib_basics(xact.circulation.target_copy).title %]
91     [% ELSE %]Miscellaneous
92     [% END %]
93     Line item billings:
94         [%- SET mb_type_hash = {} -%]
95         [%- FOR mb IN xact.billings %][%# Group billings by their btype -%]
96             [%- IF mb.voided == 'f' -%]
97                 [%- SET mb_type = mb.btype.id -%]
98                 [%- IF ! mb_type_hash.defined( mb_type ) -%][%- mb_type_hash.$mb_type = { 'sum' => 0.00, 'billings' => [] } -%][%- END -%]
99                 [%- IF ! mb_type_hash.$mb_type.defined( 'first_ts' ) -%][%- mb_type_hash.$mb_type.first_ts = mb.billing_ts -%][%- END -%]
100                 [%- mb_type_hash.$mb_type.last_ts = mb.billing_ts -%]
101                 [%- mb_type_hash.$mb_type.sum = mb_type_hash.$mb_type.sum + mb.amount -%]
102                 [%- mb_type_hash.$mb_type.billings.push( mb ) -%]
103             [%- END -%]
104         [%- END -%]
105         [%- FOR mb_type IN mb_type_hash.keys.sort -%]
106             [%- IF mb_type == 1 %][%-# Consolidated view of overdue billings -%]
107                 $[% mb_type_hash.$mb_type.sum %] for [% mb_type_hash.$mb_type.billings.0.btype.name %] 
108                     on [% mb_type_hash.$mb_type.first_ts %] through [% mb_type_hash.$mb_type.last_ts %]
109             [%- ELSE -%][%# all other billings show individually %]
110                 [% FOR mb IN mb_type_hash.$mb_type.billings %]
111                     $[% mb.amount %] for [% mb.btype.name %] on [% mb.billing_ts %] [% mb.note %]
112                 [% END %]
113             [% END %]
114         [% END %]
115     Line item payments:
116         [% FOR mp IN xact_mp_hash.$xact_id.payments %]
117             Payment ID: [% mp.id %]
118                 Paid [% mp.amount %] via [% SWITCH mp.payment_type -%]
119                     [% CASE "cash_payment" %]cash
120                     [% CASE "check_payment" %]check
121                     [% CASE "credit_card_payment" %]credit card (
122                         [%- SET cc_chunks = mp.credit_card_payment.cc_number.replace(' ','').chunk(4); -%]
123                         [%- cc_chunks.slice(0, -1+cc_chunks.max).join.replace('\S','X') -%] 
124                         [% cc_chunks.last -%]
125                         exp [% mp.credit_card_payment.expire_month %]/[% mp.credit_card_payment.expire_year -%]
126                     )
127                     [% CASE "credit_payment" %]credit
128                     [% CASE "forgive_payment" %]forgiveness
129                     [% CASE "goods_payment" %]goods
130                     [% CASE "work_payment" %]work
131                 [%- END %] on [% mp.payment_ts %] [% mp.note %]
132         [% END %]
133 [% END %]
134 $$;
135
136
137 UPDATE action_trigger.event_definition SET template = 
138 $$
139 [%- USE date -%][%- SET user = target.0.xact.usr -%]
140 <div style="li { padding: 8px; margin 5px; }">
141     <div>[% date.format %]</div><br/>
142     <ol>
143     [% SET xact_mp_hash = {} %]
144     [% FOR mp IN target %][%# Template is hooked around payments, but let us make the receipt focused on transactions %]
145         [% SET xact_id = mp.xact.id %]
146         [% IF ! xact_mp_hash.defined( xact_id ) %][% xact_mp_hash.$xact_id = { 'xact' => mp.xact, 'payments' => [] } %][% END %]
147         [% xact_mp_hash.$xact_id.payments.push(mp) %]
148     [% END %]
149     [% FOR xact_id IN xact_mp_hash.keys.sort %]
150         [% SET xact = xact_mp_hash.$xact_id.xact %]
151         <li>Transaction ID: [% xact_id %]
152             [% IF xact.circulation %][% helpers.get_copy_bib_basics(xact.circulation.target_copy).title %]
153             [% ELSE %]Miscellaneous
154             [% END %]
155             Line item billings:<ol>
156                 [% SET mb_type_hash = {} %]
157                 [% FOR mb IN xact.billings %][%# Group billings by their btype %]
158                     [% IF mb.voided == 'f' %]
159                         [% SET mb_type = mb.btype.id %]
160                         [% IF ! mb_type_hash.defined( mb_type ) %][% mb_type_hash.$mb_type = { 'sum' => 0.00, 'billings' => [] } %][% END %]
161                         [% IF ! mb_type_hash.$mb_type.defined( 'first_ts' ) %][% mb_type_hash.$mb_type.first_ts = mb.billing_ts %][% END %]
162                         [% mb_type_hash.$mb_type.last_ts = mb.billing_ts %]
163                         [% mb_type_hash.$mb_type.sum = mb_type_hash.$mb_type.sum + mb.amount %]
164                         [% mb_type_hash.$mb_type.billings.push( mb ) %]
165                     [% END %]
166                 [% END %]
167                 [% FOR mb_type IN mb_type_hash.keys.sort %]
168                     <li>[% IF mb_type == 1 %][%# Consolidated view of overdue billings %]
169                         $[% mb_type_hash.$mb_type.sum %] for [% mb_type_hash.$mb_type.billings.0.btype.name %] 
170                             on [% mb_type_hash.$mb_type.first_ts %] through [% mb_type_hash.$mb_type.last_ts %]
171                     [% ELSE %][%# all other billings show individually %]
172                         [% FOR mb IN mb_type_hash.$mb_type.billings %]
173                             $[% mb.amount %] for [% mb.btype.name %] on [% mb.billing_ts %] [% mb.note %]
174                         [% END %]
175                     [% END %]</li>
176                 [% END %]
177             </ol>
178             Line item payments:<ol>
179                 [% FOR mp IN xact_mp_hash.$xact_id.payments %]
180                     <li>Payment ID: [% mp.id %]
181                         Paid [% mp.amount %] via [% SWITCH mp.payment_type -%]
182                             [% CASE "cash_payment" %]cash
183                             [% CASE "check_payment" %]check
184                             [% CASE "credit_card_payment" %]credit card
185                             [%- IF mp.credit_card_payment.cc_number %] ([% mp.credit_card_payment.cc_number %])[% END %]
186                             [% CASE "credit_payment" %]credit
187                             [% CASE "forgive_payment" %]forgiveness
188                             [% CASE "goods_payment" %]goods
189                             [% CASE "work_payment" %]work
190                         [%- END %] on [% mp.payment_ts %] [% mp.note %]
191                     </li>
192                 [% END %]
193             </ol>
194         </li>
195     [% END %]
196     </ol>
197 </div>
198 $$
199
200 WHERE id = 30 AND template =
201
202 $$
203 [%- USE date -%][%- SET user = target.0.xact.usr -%]
204 <div style="li { padding: 8px; margin 5px; }">
205     <div>[% date.format %]</div><br/>
206     <ol>
207     [% SET xact_mp_hash = {} %]
208     [% FOR mp IN target %][%# Template is hooked around payments, but let us make the receipt focused on transactions %]
209         [% SET xact_id = mp.xact.id %]
210         [% IF ! xact_mp_hash.defined( xact_id ) %][% xact_mp_hash.$xact_id = { 'xact' => mp.xact, 'payments' => [] } %][% END %]
211         [% xact_mp_hash.$xact_id.payments.push(mp) %]
212     [% END %]
213     [% FOR xact_id IN xact_mp_hash.keys.sort %]
214         [% SET xact = xact_mp_hash.$xact_id.xact %]
215         <li>Transaction ID: [% xact_id %]
216             [% IF xact.circulation %][% helpers.get_copy_bib_basics(xact.circulation.target_copy).title %]
217             [% ELSE %]Miscellaneous
218             [% END %]
219             Line item billings:<ol>
220                 [% SET mb_type_hash = {} %]
221                 [% FOR mb IN xact.billings %][%# Group billings by their btype %]
222                     [% IF mb.voided == 'f' %]
223                         [% SET mb_type = mb.btype.id %]
224                         [% IF ! mb_type_hash.defined( mb_type ) %][% mb_type_hash.$mb_type = { 'sum' => 0.00, 'billings' => [] } %][% END %]
225                         [% IF ! mb_type_hash.$mb_type.defined( 'first_ts' ) %][% mb_type_hash.$mb_type.first_ts = mb.billing_ts %][% END %]
226                         [% mb_type_hash.$mb_type.last_ts = mb.billing_ts %]
227                         [% mb_type_hash.$mb_type.sum = mb_type_hash.$mb_type.sum + mb.amount %]
228                         [% mb_type_hash.$mb_type.billings.push( mb ) %]
229                     [% END %]
230                 [% END %]
231                 [% FOR mb_type IN mb_type_hash.keys.sort %]
232                     <li>[% IF mb_type == 1 %][%# Consolidated view of overdue billings %]
233                         $[% mb_type_hash.$mb_type.sum %] for [% mb_type_hash.$mb_type.billings.0.btype.name %] 
234                             on [% mb_type_hash.$mb_type.first_ts %] through [% mb_type_hash.$mb_type.last_ts %]
235                     [% ELSE %][%# all other billings show individually %]
236                         [% FOR mb IN mb_type_hash.$mb_type.billings %]
237                             $[% mb.amount %] for [% mb.btype.name %] on [% mb.billing_ts %] [% mb.note %]
238                         [% END %]
239                     [% END %]</li>
240                 [% END %]
241             </ol>
242             Line item payments:<ol>
243                 [% FOR mp IN xact_mp_hash.$xact_id.payments %]
244                     <li>Payment ID: [% mp.id %]
245                         Paid [% mp.amount %] via [% SWITCH mp.payment_type -%]
246                             [% CASE "cash_payment" %]cash
247                             [% CASE "check_payment" %]check
248                             [% CASE "credit_card_payment" %]credit card (
249                                 [%- SET cc_chunks = mp.credit_card_payment.cc_number.replace(' ','').chunk(4); -%]
250                                 [%- cc_chunks.slice(0, -1+cc_chunks.max).join.replace('\S','X') -%] 
251                                 [% cc_chunks.last -%]
252                                 exp [% mp.credit_card_payment.expire_month %]/[% mp.credit_card_payment.expire_year -%]
253                             )
254                             [% CASE "credit_payment" %]credit
255                             [% CASE "forgive_payment" %]forgiveness
256                             [% CASE "goods_payment" %]goods
257                             [% CASE "work_payment" %]work
258                         [%- END %] on [% mp.payment_ts %] [% mp.note %]
259                     </li>
260                 [% END %]
261             </ol>
262         </li>
263     [% END %]
264     </ol>
265 </div>
266 $$;
267
268
269 --ROLLBACK;
270 COMMIT;