]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0889.data.acq-cancel-display.sql
LP#1564079 Checkout history skips nonexistent items
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0889.data.acq-cancel-display.sql
1 BEGIN;
2
3 -- check whether patch can be applied
4 SELECT evergreen.upgrade_deps_block_check('0889', :eg_version);
5
6 -- Update ACQ cancel reason names, but only those that 
7 -- have not already been locally modified from stock values.
8
9 UPDATE acq.cancel_reason 
10     SET label = oils_i18n_gettext(1,'Canceled: Invalid ISBN', 'acqcr', 'label')
11     WHERE id = 1 AND label = 'invalid_isbn';
12
13 UPDATE acq.cancel_reason 
14     SET label = oils_i18n_gettext(1,'Canceled: Postpone', 'acqcr', 'label')
15     WHERE id = 2 AND label = 'postpone';
16
17 UPDATE acq.cancel_reason 
18     SET label = oils_i18n_gettext(1,'Delayed: Delivered but Lost', 'acqcr', 'label')
19     WHERE id = 3 AND label = 'delivered_but_lost';
20
21 UPDATE acq.cancel_reason 
22     SET label = oils_i18n_gettext(1,'Canceled: Deleted', 'acqcr', 'label')
23     WHERE id = 1002 AND label = 'Deleted';
24
25 UPDATE acq.cancel_reason 
26     SET label = oils_i18n_gettext(1,'Delayed: Changed', 'acqcr', 'label')
27     WHERE id = 1003 AND label = 'Changed';
28
29 UPDATE acq.cancel_reason 
30     SET label = oils_i18n_gettext(1,'Delayed: No Action', 'acqcr', 'label')
31     WHERE id = 1004 AND label = 'No action';
32
33 UPDATE acq.cancel_reason 
34     SET label = oils_i18n_gettext(1,'Delayed: Accepted without amendment', 'acqcr', 'label')
35     WHERE id = 1005 AND label = 'Accepted without amendment';
36
37 UPDATE acq.cancel_reason 
38     SET label = oils_i18n_gettext(1,'Canceled: Not Accepted', 'acqcr', 'label')
39     WHERE id = 1007 AND label = 'Not accepted';
40
41 UPDATE acq.cancel_reason 
42     SET label = oils_i18n_gettext(1,'Canceled: Not Found', 'acqcr', 'label')
43     WHERE id = 1010 AND label = 'Not found';
44
45 UPDATE acq.cancel_reason 
46     SET label = oils_i18n_gettext(1,'Delayed: Accepted with amendment', 'acqcr', 'label')
47     WHERE id = 1024 AND label = 'Accepted with amendment, no confirmation required';
48
49 UPDATE acq.cancel_reason 
50     SET label = oils_i18n_gettext(1,'Delayed: Split Quantity', 'acqcr', 'label')
51     WHERE id = 1211 AND label = 'Split quantity';
52
53 UPDATE acq.cancel_reason 
54     SET label = oils_i18n_gettext(1,'Delayed: Ordered Quantity', 'acqcr', 'label')
55     WHERE id = 1221 AND label = 'Ordered quantity';
56
57 UPDATE acq.cancel_reason 
58     SET label = oils_i18n_gettext(1,'Delayed: Pieces Delivered', 'acqcr', 'label')
59     WHERE id = 1246 AND label = 'Pieces delivered';
60
61 UPDATE acq.cancel_reason 
62     SET label = oils_i18n_gettext(1,'Delayed: Backorder', 'acqcr', 'label')
63     WHERE id = 1283 AND label = 'Backorder quantity';
64
65 -- action/trigger additions
66 -- All following changes are only applied where the source data matches
67 -- the stock data.  IOW, if a template has been locally modified, 
68 -- it's left unchanged.
69
70 DO $$
71 BEGIN
72     -- avoid collisions by testing for the presence of the 
73     -- desired environment addition.
74
75     PERFORM 1 FROM action_trigger.environment
76         WHERE event_def = 4 AND path = 'lineitems.cancel_reason';
77     IF NOT FOUND THEN 
78         INSERT INTO action_trigger.environment (event_def, path) 
79             VALUES (4, 'lineitems.cancel_reason');
80     END IF;
81
82     PERFORM 1 FROM action_trigger.environment
83         WHERE event_def = 14 AND path = 'cancel_reason';
84     IF NOT FOUND THEN 
85         INSERT INTO action_trigger.environment (event_def, path) 
86             VALUES ( 14, 'cancel_reason' );
87     END IF;
88
89     PERFORM 1 FROM action_trigger.environment
90         WHERE event_def = 14 AND path = 'lineitem_details.cancel_reason';
91     IF NOT FOUND THEN 
92         INSERT INTO action_trigger.environment (event_def, path) 
93             VALUES ( 14, 'lineitem_details.cancel_reason' );
94     END IF;
95 END $$;
96
97 UPDATE action_trigger.event_definition SET template = 
98 $$
99 [%- USE date -%]
100 [%-
101     # find a lineitem attribute by name and optional type
102     BLOCK get_li_attr;
103         FOR attr IN li.attributes;
104             IF attr.attr_name == attr_name;
105                 IF !attr_type OR attr_type == attr.attr_type;
106                     attr.attr_value;
107                     LAST;
108                 END;
109             END;
110         END;
111     END
112 -%]
113
114 <h2>Purchase Order: [% target.name %] ([% target.id %])</h2>
115 <br/>
116 date <b>[% date.format(date.now, '%Y%m%d') %]</b>
117 <br/>
118
119 <style>
120     table td { padding:5px; border:1px solid #aaa;}
121     table { width:95%; border-collapse:collapse; }
122     #vendor-notes { padding:5px; border:1px solid #aaa; }
123 </style>
124 <table id='vendor-table'>
125   <tr>
126     <td valign='top'>Vendor</td>
127     <td>
128       <div>[% target.provider.name %]</div>
129       <div>[% target.provider.addresses.0.street1 %]</div>
130       <div>[% target.provider.addresses.0.street2 %]</div>
131       <div>[% target.provider.addresses.0.city %]</div>
132       <div>[% target.provider.addresses.0.state %]</div>
133       <div>[% target.provider.addresses.0.country %]</div>
134       <div>[% target.provider.addresses.0.post_code %]</div>
135     </td>
136     <td valign='top'>Ship to / Bill to</td>
137     <td>
138       <div>[% target.ordering_agency.name %]</div>
139       <div>[% target.ordering_agency.billing_address.street1 %]</div>
140       <div>[% target.ordering_agency.billing_address.street2 %]</div>
141       <div>[% target.ordering_agency.billing_address.city %]</div>
142       <div>[% target.ordering_agency.billing_address.state %]</div>
143       <div>[% target.ordering_agency.billing_address.country %]</div>
144       <div>[% target.ordering_agency.billing_address.post_code %]</div>
145     </td>
146   </tr>
147 </table>
148
149 <br/><br/>
150 <fieldset id='vendor-notes'>
151     <legend>Notes to the Vendor</legend>
152     <ul>
153     [% FOR note IN target.notes %]
154         [% IF note.vendor_public == 't' %]
155             <li>[% note.value %]</li>
156         [% END %]
157     [% END %]
158     </ul>
159 </fieldset>
160 <br/><br/>
161
162 <table>
163   <thead>
164     <tr>
165       <th>PO#</th>
166       <th>ISBN or Item #</th>
167       <th>Title</th>
168       <th>Quantity</th>
169       <th>Unit Price</th>
170       <th>Line Total</th>
171       <th>Delayed / Canceled</th>
172       <th>Notes</th>
173     </tr>
174   </thead>
175   <tbody>
176
177   [% subtotal = 0 %]
178   [% FOR li IN target.lineitems %]
179
180   <tr>
181     [% count = li.lineitem_details.size %]
182     [% price = li.estimated_unit_price %]
183     [% litotal = (price * count) %]
184     [% subtotal = subtotal + litotal %]
185     [% 
186         ident_attr = helpers.get_li_order_ident(li.attributes);
187         SET ident_value = ident_attr.attr_value IF ident_attr;
188     %]
189     <td>[% target.id %]</td>
190     <td>[% ident_value %]</td>
191     <td>[% PROCESS get_li_attr attr_name = 'title' %]</td>
192     <td>[% count %]</td>
193     <td>[% price %]</td>
194     <td>[% litotal %]</td>
195     <td>[% li.cancel_reason.label %]</td>
196     <td>
197         <ul>
198         [% FOR note IN li.lineitem_notes %]
199             [% IF note.vendor_public == 't' %]
200                 <li>[% note.value %]</li>
201             [% END %]
202         [% END %]
203         </ul>
204     </td>
205   </tr>
206   [% END %]
207   <tr>
208     <td/><td/><td/><td/>
209     <td>Subtotal</td>
210     <td>[% subtotal %]</td>
211   </tr>
212   </tbody>
213 </table>
214
215 <br/>
216
217 Total Line Item Count: [% target.lineitems.size %]
218 $$
219 WHERE id = 4 AND template = 
220 $$
221 [%- USE date -%]
222 [%-
223     # find a lineitem attribute by name and optional type
224     BLOCK get_li_attr;
225         FOR attr IN li.attributes;
226             IF attr.attr_name == attr_name;
227                 IF !attr_type OR attr_type == attr.attr_type;
228                     attr.attr_value;
229                     LAST;
230                 END;
231             END;
232         END;
233     END
234 -%]
235
236 <h2>Purchase Order: [% target.name %] ([% target.id %])</h2>
237 <br/>
238 date <b>[% date.format(date.now, '%Y%m%d') %]</b>
239 <br/>
240
241 <style>
242     table td { padding:5px; border:1px solid #aaa;}
243     table { width:95%; border-collapse:collapse; }
244     #vendor-notes { padding:5px; border:1px solid #aaa; }
245 </style>
246 <table id='vendor-table'>
247   <tr>
248     <td valign='top'>Vendor</td>
249     <td>
250       <div>[% target.provider.name %]</div>
251       <div>[% target.provider.addresses.0.street1 %]</div>
252       <div>[% target.provider.addresses.0.street2 %]</div>
253       <div>[% target.provider.addresses.0.city %]</div>
254       <div>[% target.provider.addresses.0.state %]</div>
255       <div>[% target.provider.addresses.0.country %]</div>
256       <div>[% target.provider.addresses.0.post_code %]</div>
257     </td>
258     <td valign='top'>Ship to / Bill to</td>
259     <td>
260       <div>[% target.ordering_agency.name %]</div>
261       <div>[% target.ordering_agency.billing_address.street1 %]</div>
262       <div>[% target.ordering_agency.billing_address.street2 %]</div>
263       <div>[% target.ordering_agency.billing_address.city %]</div>
264       <div>[% target.ordering_agency.billing_address.state %]</div>
265       <div>[% target.ordering_agency.billing_address.country %]</div>
266       <div>[% target.ordering_agency.billing_address.post_code %]</div>
267     </td>
268   </tr>
269 </table>
270
271 <br/><br/>
272 <fieldset id='vendor-notes'>
273     <legend>Notes to the Vendor</legend>
274     <ul>
275     [% FOR note IN target.notes %]
276         [% IF note.vendor_public == 't' %]
277             <li>[% note.value %]</li>
278         [% END %]
279     [% END %]
280     </ul>
281 </fieldset>
282 <br/><br/>
283
284 <table>
285   <thead>
286     <tr>
287       <th>PO#</th>
288       <th>ISBN or Item #</th>
289       <th>Title</th>
290       <th>Quantity</th>
291       <th>Unit Price</th>
292       <th>Line Total</th>
293       <th>Notes</th>
294     </tr>
295   </thead>
296   <tbody>
297
298   [% subtotal = 0 %]
299   [% FOR li IN target.lineitems %]
300
301   <tr>
302     [% count = li.lineitem_details.size %]
303     [% price = li.estimated_unit_price %]
304     [% litotal = (price * count) %]
305     [% subtotal = subtotal + litotal %]
306     [% 
307         ident_attr = helpers.get_li_order_ident(li.attributes);
308         SET ident_value = ident_attr.attr_value IF ident_attr;
309     %]
310     <td>[% target.id %]</td>
311     <td>[% ident_value %]</td>
312     <td>[% PROCESS get_li_attr attr_name = 'title' %]</td>
313     <td>[% count %]</td>
314     <td>[% price %]</td>
315     <td>[% litotal %]</td>
316     <td>
317         <ul>
318         [% FOR note IN li.lineitem_notes %]
319             [% IF note.vendor_public == 't' %]
320                 <li>[% note.value %]</li>
321             [% END %]
322         [% END %]
323         </ul>
324     </td>
325   </tr>
326   [% END %]
327   <tr>
328     <td/><td/><td/><td/>
329     <td>Subtotal</td>
330     <td>[% subtotal %]</td>
331   </tr>
332   </tbody>
333 </table>
334
335 <br/>
336
337 Total Line Item Count: [% target.lineitems.size %]
338 $$;
339
340 -- lineitem worksheet
341 UPDATE action_trigger.event_definition SET template =
342 $$
343 [%- USE date -%]
344 [%- SET li = target; -%]
345 <div class="wrapper">
346     <div class="summary" style='font-size:110%; font-weight:bold;'>
347
348         <div>Title: [% helpers.get_li_attr("title", "", li.attributes) %]</div>
349         <div>Author: [% helpers.get_li_attr("author", "", li.attributes) %]</div>
350         <div class="count">Item Count: [% li.lineitem_details.size %]</div>
351         <div class="lineid">Lineitem ID: [% li.id %]</div>
352         <div>Open Holds: [% helpers.bre_open_hold_count(li.eg_bib_id) %]</div>
353         [% IF li.cancel_reason.label %]
354         <div>[% li.cancel_reason.label %]</div>
355         [% END %]
356
357         [% IF li.distribution_formulas.size > 0 %]
358             [% SET forms = [] %]
359             [% FOREACH form IN li.distribution_formulas; forms.push(form.formula.name); END %]
360             <div>Distribution Formulas: [% forms.join(',') %]</div>
361         [% END %]
362
363         [% IF li.lineitem_notes.size > 0 %]
364             Lineitem Notes:
365             <ul>
366                 [%- FOR note IN li.lineitem_notes -%]
367                     <li>
368                     [% IF note.alert_text %]
369                         [% note.alert_text.code -%] 
370                         [% IF note.value -%]
371                             : [% note.value %]
372                         [% END %]
373                     [% ELSE %]
374                         [% note.value -%] 
375                     [% END %]
376                     </li>
377                 [% END %]
378             </ul>
379         [% END %]
380     </div>
381     <br/>
382     <table>
383         <thead>
384             <tr>
385                 <th>Branch</th>
386                 <th>Barcode</th>
387                 <th>Call Number</th>
388                 <th>Fund</th>
389                 <th>Shelving Location</th>
390                 <th>Recd.</th>
391                 <th>Notes</th>
392                 <th>Delayed / Canceled</th>
393             </tr>
394         </thead>
395         <tbody>
396         <!-- set detail.owning_lib from fm object to org name -->
397         [% FOREACH detail IN li.lineitem_details %]
398             [% detail.owning_lib = detail.owning_lib.shortname %]
399         [% END %]
400
401         [% FOREACH detail IN li.lineitem_details.sort('owning_lib') %]
402             [% 
403                 IF detail.eg_copy_id;
404                     SET copy = detail.eg_copy_id;
405                     SET cn_label = copy.call_number.label;
406                 ELSE; 
407                     SET copy = detail; 
408                     SET cn_label = detail.cn_label;
409                 END 
410             %]
411             <tr>
412                 <!-- acq.lineitem_detail.id = [%- detail.id -%] -->
413                 <td style='padding:5px;'>[% detail.owning_lib %]</td>
414                 <td style='padding:5px;'>[% IF copy.barcode   %]<span class="barcode"  >[% detail.barcode   %]</span>[% END %]</td>
415                 <td style='padding:5px;'>[% IF cn_label %]<span class="cn_label" >[% cn_label  %]</span>[% END %]</td>
416                 <td style='padding:5px;'>[% IF detail.fund %]<span class="fund">[% detail.fund.code %] ([% detail.fund.year %])</span>[% END %]</td>
417                 <td style='padding:5px;'>[% copy.location.name %]</td>
418                 <td style='padding:5px;'>[% IF detail.recv_time %]<span class="recv_time">[% detail.recv_time %]</span>[% END %]</td>
419                 <td style='padding:5px;'>[% detail.note %]</td>
420                 <td style='padding:5px;'>[% detail.cancel_reason.label %]</td>
421             </tr>
422         [% END %]
423         </tbody>
424     </table>
425 </div>
426 $$
427 WHERE id = 14 AND template = 
428 $$
429 [%- USE date -%]
430 [%- SET li = target; -%]
431 <div class="wrapper">
432     <div class="summary" style='font-size:110%; font-weight:bold;'>
433
434         <div>Title: [% helpers.get_li_attr("title", "", li.attributes) %]</div>
435         <div>Author: [% helpers.get_li_attr("author", "", li.attributes) %]</div>
436         <div class="count">Item Count: [% li.lineitem_details.size %]</div>
437         <div class="lineid">Lineitem ID: [% li.id %]</div>
438         <div>Open Holds: [% helpers.bre_open_hold_count(li.eg_bib_id) %]</div>
439
440         [% IF li.distribution_formulas.size > 0 %]
441             [% SET forms = [] %]
442             [% FOREACH form IN li.distribution_formulas; forms.push(form.formula.name); END %]
443             <div>Distribution Formulas: [% forms.join(',') %]</div>
444         [% END %]
445
446         [% IF li.lineitem_notes.size > 0 %]
447             Lineitem Notes:
448             <ul>
449                 [%- FOR note IN li.lineitem_notes -%]
450                     <li>
451                     [% IF note.alert_text %]
452                         [% note.alert_text.code -%] 
453                         [% IF note.value -%]
454                             : [% note.value %]
455                         [% END %]
456                     [% ELSE %]
457                         [% note.value -%] 
458                     [% END %]
459                     </li>
460                 [% END %]
461             </ul>
462         [% END %]
463     </div>
464     <br/>
465     <table>
466         <thead>
467             <tr>
468                 <th>Branch</th>
469                 <th>Barcode</th>
470                 <th>Call Number</th>
471                 <th>Fund</th>
472                 <th>Shelving Location</th>
473                 <th>Recd.</th>
474                 <th>Notes</th>
475             </tr>
476         </thead>
477         <tbody>
478         <!-- set detail.owning_lib from fm object to org name -->
479         [% FOREACH detail IN li.lineitem_details %]
480             [% detail.owning_lib = detail.owning_lib.shortname %]
481         [% END %]
482
483         [% FOREACH detail IN li.lineitem_details.sort('owning_lib') %]
484             [% 
485                 IF detail.eg_copy_id;
486                     SET copy = detail.eg_copy_id;
487                     SET cn_label = copy.call_number.label;
488                 ELSE; 
489                     SET copy = detail; 
490                     SET cn_label = detail.cn_label;
491                 END 
492             %]
493             <tr>
494                 <!-- acq.lineitem_detail.id = [%- detail.id -%] -->
495                 <td style='padding:5px;'>[% detail.owning_lib %]</td>
496                 <td style='padding:5px;'>[% IF copy.barcode   %]<span class="barcode"  >[% detail.barcode   %]</span>[% END %]</td>
497                 <td style='padding:5px;'>[% IF cn_label %]<span class="cn_label" >[% cn_label  %]</span>[% END %]</td>
498                 <td style='padding:5px;'>[% IF detail.fund %]<span class="fund">[% detail.fund.code %] ([% detail.fund.year %])</span>[% END %]</td>
499                 <td style='padding:5px;'>[% copy.location.name %]</td>
500                 <td style='padding:5px;'>[% IF detail.recv_time %]<span class="recv_time">[% detail.recv_time %]</span>[% END %]</td>
501                 <td style='padding:5px;'>[% detail.note %]</td>
502             </tr>
503         [% END %]
504         </tbody>
505     </table>
506 </div>
507 $$;
508
509
510 COMMIT;