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