]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/version-upgrade/2.6.3-2.7.0-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.6.3-2.7.0-upgrade-db.sql
1 --Upgrade Script for 2.6.3 to 2.7.0
2 \set eg_version '''2.7.0'''
3 BEGIN;
4 INSERT INTO config.upgrade_log (version, applied_to) VALUES ('2.7.0', :eg_version);
5 -- check whether patch can be applied
6 SELECT evergreen.upgrade_deps_block_check('0884', :eg_version);
7
8 UPDATE container.biblio_record_entry_bucket_type
9 SET label = oils_i18n_gettext(
10         'bookbag',
11         'Book List',
12         'cbrebt',
13         'label'
14 ) WHERE code = 'bookbag';
15
16 UPDATE container.user_bucket_type
17 SET label = oils_i18n_gettext(
18         'folks:pub_book_bags.view',
19         'List Published Book Lists',
20         'cubt',
21         'label'
22 ) WHERE code = 'folks:pub_book_bags.view';
23
24 UPDATE container.user_bucket_type
25 SET label = oils_i18n_gettext(
26         'folks:pub_book_bags.add',
27         'Add to Published Book Lists',
28         'cubt',
29         'label'
30 ) WHERE code = 'folks:pub_book_bags.add';
31
32 UPDATE action_trigger.hook
33 SET description = oils_i18n_gettext(
34         'container.biblio_record_entry_bucket.csv',
35         'Produce a CSV file representing a book list',
36         'ath',
37         'description'
38 ) WHERE key = 'container.biblio_record_entry_bucket.csv';
39
40 UPDATE action_trigger.reactor
41 SET description = oils_i18n_gettext(
42         'ContainerCSV',
43         'Facilitates producing a CSV file representing a book list by introducing an "items" variable into the TT environment, sorted as dictated according to user params',
44         'atr',
45         'description'
46 )
47 WHERE module = 'ContainerCSV';
48
49 UPDATE action_trigger.event_definition
50 SET template = REPLACE(template, 'bookbag', 'book list'),
51 name = 'Book List CSV'
52 WHERE name = 'Bookbag CSV';
53
54 UPDATE config.org_unit_setting_type
55 SET description = oils_i18n_gettext(
56         'opac.patron.temporary_list_warn',
57         'Present a warning dialog to the patron when a patron adds a book to a temporary book list.',
58         'coust',
59         'description'
60 ) WHERE name = 'opac.patron.temporary_list_warn';
61
62 UPDATE config.usr_setting_type
63 SET label = oils_i18n_gettext(
64         'opac.default_list',
65         'Default list to use when adding to a list',
66         'cust',
67         'label'
68 ),
69 description = oils_i18n_gettext(
70         'opac.default_list',
71         'Default list to use when adding to a list',
72         'cust',
73         'description'
74 ) WHERE name = 'opac.default_list';
75
76
77 SELECT evergreen.upgrade_deps_block_check('0885', :eg_version);
78
79 CREATE OR REPLACE FUNCTION evergreen.ranked_volumes(
80     bibid BIGINT[],
81     ouid INT,
82     depth INT DEFAULT NULL,
83     slimit HSTORE DEFAULT NULL,
84     soffset HSTORE DEFAULT NULL,
85     pref_lib INT DEFAULT NULL,
86     includes TEXT[] DEFAULT NULL::TEXT[]
87 ) RETURNS TABLE(id BIGINT, name TEXT, label_sortkey TEXT, rank BIGINT) AS $$
88     WITH RECURSIVE ou_depth AS (
89         SELECT COALESCE(
90             $3,
91             (
92                 SELECT depth
93                 FROM actor.org_unit_type aout
94                     INNER JOIN actor.org_unit ou ON ou_type = aout.id
95                 WHERE ou.id = $2
96             )
97         ) AS depth
98     ), descendant_depth AS (
99         SELECT  ou.id,
100                 ou.parent_ou,
101                 out.depth
102         FROM  actor.org_unit ou
103                 JOIN actor.org_unit_type out ON (out.id = ou.ou_type)
104                 JOIN anscestor_depth ad ON (ad.id = ou.id),
105                 ou_depth
106         WHERE ad.depth = ou_depth.depth
107             UNION ALL
108         SELECT  ou.id,
109                 ou.parent_ou,
110                 out.depth
111         FROM  actor.org_unit ou
112                 JOIN actor.org_unit_type out ON (out.id = ou.ou_type)
113                 JOIN descendant_depth ot ON (ot.id = ou.parent_ou)
114     ), anscestor_depth AS (
115         SELECT  ou.id,
116                 ou.parent_ou,
117                 out.depth
118         FROM  actor.org_unit ou
119                 JOIN actor.org_unit_type out ON (out.id = ou.ou_type)
120         WHERE ou.id = $2
121             UNION ALL
122         SELECT  ou.id,
123                 ou.parent_ou,
124                 out.depth
125         FROM  actor.org_unit ou
126                 JOIN actor.org_unit_type out ON (out.id = ou.ou_type)
127                 JOIN anscestor_depth ot ON (ot.parent_ou = ou.id)
128     ), descendants as (
129         SELECT ou.* FROM actor.org_unit ou JOIN descendant_depth USING (id)
130     )
131
132     SELECT ua.id, ua.name, ua.label_sortkey, MIN(ua.rank) AS rank FROM (
133         SELECT acn.id, aou.name, acn.label_sortkey,
134             RANK() OVER w
135         FROM asset.call_number acn
136             JOIN asset.copy acp ON (acn.id = acp.call_number)
137             JOIN descendants AS aou ON (acp.circ_lib = aou.id)
138         WHERE acn.record = ANY ($1)
139             AND acn.deleted IS FALSE
140             AND acp.deleted IS FALSE
141             AND CASE WHEN ('exclude_invisible_acn' = ANY($7)) THEN
142                 EXISTS (
143                     SELECT 1
144                     FROM asset.opac_visible_copies
145                     WHERE copy_id = acp.id AND record = acn.record
146                 ) ELSE TRUE END
147         GROUP BY acn.id, acp.status, aou.name, acn.label_sortkey, aou.id
148         WINDOW w AS (
149             ORDER BY
150                 COALESCE(
151                     CASE WHEN aou.id = $2 THEN -20000 END,
152                     CASE WHEN aou.id = $6 THEN -10000 END,
153                     (SELECT distance - 5000
154                         FROM actor.org_unit_descendants_distance($6) as x
155                         WHERE x.id = aou.id AND $6 IN (
156                             SELECT q.id FROM actor.org_unit_descendants($2) as q)),
157                     (SELECT e.distance FROM actor.org_unit_descendants_distance($2) as e WHERE e.id = aou.id),
158                     1000
159                 ),
160                 evergreen.rank_cp_status(acp.status)
161         )
162     ) AS ua
163     GROUP BY ua.id, ua.name, ua.label_sortkey
164     ORDER BY rank, ua.name, ua.label_sortkey
165     LIMIT ($4 -> 'acn')::INT
166     OFFSET ($5 -> 'acn')::INT;
167 $$ LANGUAGE SQL STABLE ROWS 10;
168
169 CREATE OR REPLACE FUNCTION evergreen.ranked_volumes
170     ( bibid BIGINT, ouid INT, depth INT DEFAULT NULL, slimit HSTORE DEFAULT NULL, soffset HSTORE DEFAULT NULL, pref_lib INT DEFAULT NULL, includes TEXT[] DEFAULT NULL::TEXT[] )
171     RETURNS TABLE (id BIGINT, name TEXT, label_sortkey TEXT, rank BIGINT)
172     AS $$ SELECT * FROM evergreen.ranked_volumes(ARRAY[$1],$2,$3,$4,$5,$6,$7) $$ LANGUAGE SQL STABLE;
173
174
175 SELECT evergreen.upgrade_deps_block_check('0886', :eg_version);
176
177 INSERT INTO config.copy_status
178 (id, name, holdable, opac_visible, copy_active, restrict_copy_delete)
179 VALUES (17, 'Lost and Paid', FALSE, FALSE, FALSE, TRUE);
180
181 INSERT INTO config.org_unit_setting_type
182 (name, grp, label, description, datatype)
183 VALUES
184 ('circ.use_lost_paid_copy_status',
185  'circ',
186  oils_i18n_gettext('circ.use_lost_paid_copy_status',
187      'Use Lost and Paid copy status',
188      'coust', 'label'),
189  oils_i18n_gettext('circ.use_lost_paid_copy_status',
190      'Use Lost and Paid copy status when lost or long overdue billing is paid',
191      'coust', 'description'),
192  'bool');
193
194
195 -- check whether patch can be applied
196 SELECT evergreen.upgrade_deps_block_check('0888', :eg_version);
197
198 DROP VIEW acq.lineitem_summary;
199
200 CREATE VIEW acq.lineitem_summary AS
201     SELECT 
202         li.id AS lineitem, 
203         (
204             SELECT COUNT(lid.id) 
205             FROM acq.lineitem_detail lid
206             WHERE lineitem = li.id
207         ) AS item_count,
208         (
209             SELECT COUNT(lid.id) 
210             FROM acq.lineitem_detail lid
211             WHERE recv_time IS NOT NULL AND lineitem = li.id
212         ) AS recv_count,
213         (
214             SELECT COUNT(lid.id) 
215             FROM acq.lineitem_detail lid
216                 JOIN acq.cancel_reason acqcr ON (acqcr.id = lid.cancel_reason)
217             WHERE acqcr.keep_debits IS FALSE AND lineitem = li.id
218         ) AS cancel_count,
219         (
220             SELECT COUNT(lid.id) 
221             FROM acq.lineitem_detail lid
222                 JOIN acq.cancel_reason acqcr ON (acqcr.id = lid.cancel_reason)
223             WHERE acqcr.keep_debits IS TRUE AND lineitem = li.id
224         ) AS delay_count,
225         (
226             SELECT COUNT(lid.id) 
227             FROM acq.lineitem_detail lid
228                 JOIN acq.fund_debit debit ON (lid.fund_debit = debit.id)
229             WHERE NOT debit.encumbrance AND lineitem = li.id
230         ) AS invoice_count,
231         (
232             SELECT COUNT(DISTINCT(lid.id)) 
233             FROM acq.lineitem_detail lid
234                 JOIN acq.claim claim ON (claim.lineitem_detail = lid.id)
235             WHERE lineitem = li.id
236         ) AS claim_count,
237         (
238             SELECT (COUNT(lid.id) * li.estimated_unit_price)::NUMERIC(8,2)
239             FROM acq.lineitem_detail lid
240             WHERE lid.cancel_reason IS NULL AND lineitem = li.id
241         ) AS estimated_amount,
242         (
243             SELECT SUM(debit.amount)::NUMERIC(8,2)
244             FROM acq.lineitem_detail lid
245                 JOIN acq.fund_debit debit ON (lid.fund_debit = debit.id)
246             WHERE debit.encumbrance AND lineitem = li.id
247         ) AS encumbrance_amount,
248         (
249             SELECT SUM(debit.amount)::NUMERIC(8,2)
250             FROM acq.lineitem_detail lid
251                 JOIN acq.fund_debit debit ON (lid.fund_debit = debit.id)
252             WHERE NOT debit.encumbrance AND lineitem = li.id
253         ) AS paid_amount
254
255         FROM acq.lineitem AS li;
256
257
258 -- check whether patch can be applied
259 SELECT evergreen.upgrade_deps_block_check('0889', :eg_version);
260
261 -- Update ACQ cancel reason names, but only those that 
262 -- have not already been locally modified from stock values.
263
264 UPDATE acq.cancel_reason 
265     SET label = oils_i18n_gettext(1,'Canceled: Invalid ISBN', 'acqcr', 'label')
266     WHERE id = 1 AND label = 'invalid_isbn';
267
268 UPDATE acq.cancel_reason 
269     SET label = oils_i18n_gettext(1,'Canceled: Postpone', 'acqcr', 'label')
270     WHERE id = 2 AND label = 'postpone';
271
272 UPDATE acq.cancel_reason 
273     SET label = oils_i18n_gettext(1,'Delayed: Delivered but Lost', 'acqcr', 'label')
274     WHERE id = 3 AND label = 'delivered_but_lost';
275
276 UPDATE acq.cancel_reason 
277     SET label = oils_i18n_gettext(1,'Canceled: Deleted', 'acqcr', 'label')
278     WHERE id = 1002 AND label = 'Deleted';
279
280 UPDATE acq.cancel_reason 
281     SET label = oils_i18n_gettext(1,'Delayed: Changed', 'acqcr', 'label')
282     WHERE id = 1003 AND label = 'Changed';
283
284 UPDATE acq.cancel_reason 
285     SET label = oils_i18n_gettext(1,'Delayed: No Action', 'acqcr', 'label')
286     WHERE id = 1004 AND label = 'No action';
287
288 UPDATE acq.cancel_reason 
289     SET label = oils_i18n_gettext(1,'Delayed: Accepted without amendment', 'acqcr', 'label')
290     WHERE id = 1005 AND label = 'Accepted without amendment';
291
292 UPDATE acq.cancel_reason 
293     SET label = oils_i18n_gettext(1,'Canceled: Not Accepted', 'acqcr', 'label')
294     WHERE id = 1007 AND label = 'Not accepted';
295
296 UPDATE acq.cancel_reason 
297     SET label = oils_i18n_gettext(1,'Canceled: Not Found', 'acqcr', 'label')
298     WHERE id = 1010 AND label = 'Not found';
299
300 UPDATE acq.cancel_reason 
301     SET label = oils_i18n_gettext(1,'Delayed: Accepted with amendment', 'acqcr', 'label')
302     WHERE id = 1024 AND label = 'Accepted with amendment, no confirmation required';
303
304 UPDATE acq.cancel_reason 
305     SET label = oils_i18n_gettext(1,'Delayed: Split Quantity', 'acqcr', 'label')
306     WHERE id = 1211 AND label = 'Split quantity';
307
308 UPDATE acq.cancel_reason 
309     SET label = oils_i18n_gettext(1,'Delayed: Ordered Quantity', 'acqcr', 'label')
310     WHERE id = 1221 AND label = 'Ordered quantity';
311
312 UPDATE acq.cancel_reason 
313     SET label = oils_i18n_gettext(1,'Delayed: Pieces Delivered', 'acqcr', 'label')
314     WHERE id = 1246 AND label = 'Pieces delivered';
315
316 UPDATE acq.cancel_reason 
317     SET label = oils_i18n_gettext(1,'Delayed: Backorder', 'acqcr', 'label')
318     WHERE id = 1283 AND label = 'Backorder quantity';
319
320 -- action/trigger additions
321 -- All following changes are only applied where the source data matches
322 -- the stock data.  IOW, if a template has been locally modified, 
323 -- it's left unchanged.
324
325 DO $$
326 BEGIN
327     -- avoid collisions by testing for the presence of the 
328     -- desired environment addition.
329
330     PERFORM 1 FROM action_trigger.environment
331         WHERE event_def = 4 AND path = 'lineitems.cancel_reason';
332     IF NOT FOUND THEN 
333         INSERT INTO action_trigger.environment (event_def, path) 
334             VALUES (4, 'lineitems.cancel_reason');
335     END IF;
336
337     PERFORM 1 FROM action_trigger.environment
338         WHERE event_def = 14 AND path = 'cancel_reason';
339     IF NOT FOUND THEN 
340         INSERT INTO action_trigger.environment (event_def, path) 
341             VALUES ( 14, 'cancel_reason' );
342     END IF;
343
344     PERFORM 1 FROM action_trigger.environment
345         WHERE event_def = 14 AND path = 'lineitem_details.cancel_reason';
346     IF NOT FOUND THEN 
347         INSERT INTO action_trigger.environment (event_def, path) 
348             VALUES ( 14, 'lineitem_details.cancel_reason' );
349     END IF;
350 END $$;
351
352 UPDATE action_trigger.event_definition SET template = 
353 $$
354 [%- USE date -%]
355 [%-
356     # find a lineitem attribute by name and optional type
357     BLOCK get_li_attr;
358         FOR attr IN li.attributes;
359             IF attr.attr_name == attr_name;
360                 IF !attr_type OR attr_type == attr.attr_type;
361                     attr.attr_value;
362                     LAST;
363                 END;
364             END;
365         END;
366     END
367 -%]
368
369 <h2>Purchase Order: [% target.name %] ([% target.id %])</h2>
370 <br/>
371 date <b>[% date.format(date.now, '%Y%m%d') %]</b>
372 <br/>
373
374 <style>
375     table td { padding:5px; border:1px solid #aaa;}
376     table { width:95%; border-collapse:collapse; }
377     #vendor-notes { padding:5px; border:1px solid #aaa; }
378 </style>
379 <table id='vendor-table'>
380   <tr>
381     <td valign='top'>Vendor</td>
382     <td>
383       <div>[% target.provider.name %]</div>
384       <div>[% target.provider.addresses.0.street1 %]</div>
385       <div>[% target.provider.addresses.0.street2 %]</div>
386       <div>[% target.provider.addresses.0.city %]</div>
387       <div>[% target.provider.addresses.0.state %]</div>
388       <div>[% target.provider.addresses.0.country %]</div>
389       <div>[% target.provider.addresses.0.post_code %]</div>
390     </td>
391     <td valign='top'>Ship to / Bill to</td>
392     <td>
393       <div>[% target.ordering_agency.name %]</div>
394       <div>[% target.ordering_agency.billing_address.street1 %]</div>
395       <div>[% target.ordering_agency.billing_address.street2 %]</div>
396       <div>[% target.ordering_agency.billing_address.city %]</div>
397       <div>[% target.ordering_agency.billing_address.state %]</div>
398       <div>[% target.ordering_agency.billing_address.country %]</div>
399       <div>[% target.ordering_agency.billing_address.post_code %]</div>
400     </td>
401   </tr>
402 </table>
403
404 <br/><br/>
405 <fieldset id='vendor-notes'>
406     <legend>Notes to the Vendor</legend>
407     <ul>
408     [% FOR note IN target.notes %]
409         [% IF note.vendor_public == 't' %]
410             <li>[% note.value %]</li>
411         [% END %]
412     [% END %]
413     </ul>
414 </fieldset>
415 <br/><br/>
416
417 <table>
418   <thead>
419     <tr>
420       <th>PO#</th>
421       <th>ISBN or Item #</th>
422       <th>Title</th>
423       <th>Quantity</th>
424       <th>Unit Price</th>
425       <th>Line Total</th>
426       <th>Delayed / Canceled</th>
427       <th>Notes</th>
428     </tr>
429   </thead>
430   <tbody>
431
432   [% subtotal = 0 %]
433   [% FOR li IN target.lineitems %]
434
435   <tr>
436     [% count = li.lineitem_details.size %]
437     [% price = li.estimated_unit_price %]
438     [% litotal = (price * count) %]
439     [% subtotal = subtotal + litotal %]
440     [% 
441         ident_attr = helpers.get_li_order_ident(li.attributes);
442         SET ident_value = ident_attr.attr_value IF ident_attr;
443     %]
444     <td>[% target.id %]</td>
445     <td>[% ident_value %]</td>
446     <td>[% PROCESS get_li_attr attr_name = 'title' %]</td>
447     <td>[% count %]</td>
448     <td>[% price %]</td>
449     <td>[% litotal %]</td>
450     <td>[% li.cancel_reason.label %]</td>
451     <td>
452         <ul>
453         [% FOR note IN li.lineitem_notes %]
454             [% IF note.vendor_public == 't' %]
455                 <li>[% note.value %]</li>
456             [% END %]
457         [% END %]
458         </ul>
459     </td>
460   </tr>
461   [% END %]
462   <tr>
463     <td/><td/><td/><td/>
464     <td>Subtotal</td>
465     <td>[% subtotal %]</td>
466   </tr>
467   </tbody>
468 </table>
469
470 <br/>
471
472 Total Line Item Count: [% target.lineitems.size %]
473 $$
474 WHERE id = 4 AND template = 
475 $$
476 [%- USE date -%]
477 [%-
478     # find a lineitem attribute by name and optional type
479     BLOCK get_li_attr;
480         FOR attr IN li.attributes;
481             IF attr.attr_name == attr_name;
482                 IF !attr_type OR attr_type == attr.attr_type;
483                     attr.attr_value;
484                     LAST;
485                 END;
486             END;
487         END;
488     END
489 -%]
490
491 <h2>Purchase Order: [% target.name %] ([% target.id %])</h2>
492 <br/>
493 date <b>[% date.format(date.now, '%Y%m%d') %]</b>
494 <br/>
495
496 <style>
497     table td { padding:5px; border:1px solid #aaa;}
498     table { width:95%; border-collapse:collapse; }
499     #vendor-notes { padding:5px; border:1px solid #aaa; }
500 </style>
501 <table id='vendor-table'>
502   <tr>
503     <td valign='top'>Vendor</td>
504     <td>
505       <div>[% target.provider.name %]</div>
506       <div>[% target.provider.addresses.0.street1 %]</div>
507       <div>[% target.provider.addresses.0.street2 %]</div>
508       <div>[% target.provider.addresses.0.city %]</div>
509       <div>[% target.provider.addresses.0.state %]</div>
510       <div>[% target.provider.addresses.0.country %]</div>
511       <div>[% target.provider.addresses.0.post_code %]</div>
512     </td>
513     <td valign='top'>Ship to / Bill to</td>
514     <td>
515       <div>[% target.ordering_agency.name %]</div>
516       <div>[% target.ordering_agency.billing_address.street1 %]</div>
517       <div>[% target.ordering_agency.billing_address.street2 %]</div>
518       <div>[% target.ordering_agency.billing_address.city %]</div>
519       <div>[% target.ordering_agency.billing_address.state %]</div>
520       <div>[% target.ordering_agency.billing_address.country %]</div>
521       <div>[% target.ordering_agency.billing_address.post_code %]</div>
522     </td>
523   </tr>
524 </table>
525
526 <br/><br/>
527 <fieldset id='vendor-notes'>
528     <legend>Notes to the Vendor</legend>
529     <ul>
530     [% FOR note IN target.notes %]
531         [% IF note.vendor_public == 't' %]
532             <li>[% note.value %]</li>
533         [% END %]
534     [% END %]
535     </ul>
536 </fieldset>
537 <br/><br/>
538
539 <table>
540   <thead>
541     <tr>
542       <th>PO#</th>
543       <th>ISBN or Item #</th>
544       <th>Title</th>
545       <th>Quantity</th>
546       <th>Unit Price</th>
547       <th>Line Total</th>
548       <th>Notes</th>
549     </tr>
550   </thead>
551   <tbody>
552
553   [% subtotal = 0 %]
554   [% FOR li IN target.lineitems %]
555
556   <tr>
557     [% count = li.lineitem_details.size %]
558     [% price = li.estimated_unit_price %]
559     [% litotal = (price * count) %]
560     [% subtotal = subtotal + litotal %]
561     [% 
562         ident_attr = helpers.get_li_order_ident(li.attributes);
563         SET ident_value = ident_attr.attr_value IF ident_attr;
564     %]
565     <td>[% target.id %]</td>
566     <td>[% ident_value %]</td>
567     <td>[% PROCESS get_li_attr attr_name = 'title' %]</td>
568     <td>[% count %]</td>
569     <td>[% price %]</td>
570     <td>[% litotal %]</td>
571     <td>
572         <ul>
573         [% FOR note IN li.lineitem_notes %]
574             [% IF note.vendor_public == 't' %]
575                 <li>[% note.value %]</li>
576             [% END %]
577         [% END %]
578         </ul>
579     </td>
580   </tr>
581   [% END %]
582   <tr>
583     <td/><td/><td/><td/>
584     <td>Subtotal</td>
585     <td>[% subtotal %]</td>
586   </tr>
587   </tbody>
588 </table>
589
590 <br/>
591
592 Total Line Item Count: [% target.lineitems.size %]
593 $$;
594
595 -- lineitem worksheet
596 UPDATE action_trigger.event_definition SET template =
597 $$
598 [%- USE date -%]
599 [%- SET li = target; -%]
600 <div class="wrapper">
601     <div class="summary" style='font-size:110%; font-weight:bold;'>
602
603         <div>Title: [% helpers.get_li_attr("title", "", li.attributes) %]</div>
604         <div>Author: [% helpers.get_li_attr("author", "", li.attributes) %]</div>
605         <div class="count">Item Count: [% li.lineitem_details.size %]</div>
606         <div class="lineid">Lineitem ID: [% li.id %]</div>
607         <div>Open Holds: [% helpers.bre_open_hold_count(li.eg_bib_id) %]</div>
608         [% IF li.cancel_reason.label %]
609         <div>[% li.cancel_reason.label %]</div>
610         [% END %]
611
612         [% IF li.distribution_formulas.size > 0 %]
613             [% SET forms = [] %]
614             [% FOREACH form IN li.distribution_formulas; forms.push(form.formula.name); END %]
615             <div>Distribution Formulas: [% forms.join(',') %]</div>
616         [% END %]
617
618         [% IF li.lineitem_notes.size > 0 %]
619             Lineitem Notes:
620             <ul>
621                 [%- FOR note IN li.lineitem_notes -%]
622                     <li>
623                     [% IF note.alert_text %]
624                         [% note.alert_text.code -%] 
625                         [% IF note.value -%]
626                             : [% note.value %]
627                         [% END %]
628                     [% ELSE %]
629                         [% note.value -%] 
630                     [% END %]
631                     </li>
632                 [% END %]
633             </ul>
634         [% END %]
635     </div>
636     <br/>
637     <table>
638         <thead>
639             <tr>
640                 <th>Branch</th>
641                 <th>Barcode</th>
642                 <th>Call Number</th>
643                 <th>Fund</th>
644                 <th>Shelving Location</th>
645                 <th>Recd.</th>
646                 <th>Notes</th>
647                 <th>Delayed / Canceled</th>
648             </tr>
649         </thead>
650         <tbody>
651         <!-- set detail.owning_lib from fm object to org name -->
652         [% FOREACH detail IN li.lineitem_details %]
653             [% detail.owning_lib = detail.owning_lib.shortname %]
654         [% END %]
655
656         [% FOREACH detail IN li.lineitem_details.sort('owning_lib') %]
657             [% 
658                 IF detail.eg_copy_id;
659                     SET copy = detail.eg_copy_id;
660                     SET cn_label = copy.call_number.label;
661                 ELSE; 
662                     SET copy = detail; 
663                     SET cn_label = detail.cn_label;
664                 END 
665             %]
666             <tr>
667                 <!-- acq.lineitem_detail.id = [%- detail.id -%] -->
668                 <td style='padding:5px;'>[% detail.owning_lib %]</td>
669                 <td style='padding:5px;'>[% IF copy.barcode   %]<span class="barcode"  >[% detail.barcode   %]</span>[% END %]</td>
670                 <td style='padding:5px;'>[% IF cn_label %]<span class="cn_label" >[% cn_label  %]</span>[% END %]</td>
671                 <td style='padding:5px;'>[% IF detail.fund %]<span class="fund">[% detail.fund.code %] ([% detail.fund.year %])</span>[% END %]</td>
672                 <td style='padding:5px;'>[% copy.location.name %]</td>
673                 <td style='padding:5px;'>[% IF detail.recv_time %]<span class="recv_time">[% detail.recv_time %]</span>[% END %]</td>
674                 <td style='padding:5px;'>[% detail.note %]</td>
675                 <td style='padding:5px;'>[% detail.cancel_reason.label %]</td>
676             </tr>
677         [% END %]
678         </tbody>
679     </table>
680 </div>
681 $$
682 WHERE id = 14 AND template = 
683 $$
684 [%- USE date -%]
685 [%- SET li = target; -%]
686 <div class="wrapper">
687     <div class="summary" style='font-size:110%; font-weight:bold;'>
688
689         <div>Title: [% helpers.get_li_attr("title", "", li.attributes) %]</div>
690         <div>Author: [% helpers.get_li_attr("author", "", li.attributes) %]</div>
691         <div class="count">Item Count: [% li.lineitem_details.size %]</div>
692         <div class="lineid">Lineitem ID: [% li.id %]</div>
693         <div>Open Holds: [% helpers.bre_open_hold_count(li.eg_bib_id) %]</div>
694
695         [% IF li.distribution_formulas.size > 0 %]
696             [% SET forms = [] %]
697             [% FOREACH form IN li.distribution_formulas; forms.push(form.formula.name); END %]
698             <div>Distribution Formulas: [% forms.join(',') %]</div>
699         [% END %]
700
701         [% IF li.lineitem_notes.size > 0 %]
702             Lineitem Notes:
703             <ul>
704                 [%- FOR note IN li.lineitem_notes -%]
705                     <li>
706                     [% IF note.alert_text %]
707                         [% note.alert_text.code -%] 
708                         [% IF note.value -%]
709                             : [% note.value %]
710                         [% END %]
711                     [% ELSE %]
712                         [% note.value -%] 
713                     [% END %]
714                     </li>
715                 [% END %]
716             </ul>
717         [% END %]
718     </div>
719     <br/>
720     <table>
721         <thead>
722             <tr>
723                 <th>Branch</th>
724                 <th>Barcode</th>
725                 <th>Call Number</th>
726                 <th>Fund</th>
727                 <th>Shelving Location</th>
728                 <th>Recd.</th>
729                 <th>Notes</th>
730             </tr>
731         </thead>
732         <tbody>
733         <!-- set detail.owning_lib from fm object to org name -->
734         [% FOREACH detail IN li.lineitem_details %]
735             [% detail.owning_lib = detail.owning_lib.shortname %]
736         [% END %]
737
738         [% FOREACH detail IN li.lineitem_details.sort('owning_lib') %]
739             [% 
740                 IF detail.eg_copy_id;
741                     SET copy = detail.eg_copy_id;
742                     SET cn_label = copy.call_number.label;
743                 ELSE; 
744                     SET copy = detail; 
745                     SET cn_label = detail.cn_label;
746                 END 
747             %]
748             <tr>
749                 <!-- acq.lineitem_detail.id = [%- detail.id -%] -->
750                 <td style='padding:5px;'>[% detail.owning_lib %]</td>
751                 <td style='padding:5px;'>[% IF copy.barcode   %]<span class="barcode"  >[% detail.barcode   %]</span>[% END %]</td>
752                 <td style='padding:5px;'>[% IF cn_label %]<span class="cn_label" >[% cn_label  %]</span>[% END %]</td>
753                 <td style='padding:5px;'>[% IF detail.fund %]<span class="fund">[% detail.fund.code %] ([% detail.fund.year %])</span>[% END %]</td>
754                 <td style='padding:5px;'>[% copy.location.name %]</td>
755                 <td style='padding:5px;'>[% IF detail.recv_time %]<span class="recv_time">[% detail.recv_time %]</span>[% END %]</td>
756                 <td style='padding:5px;'>[% detail.note %]</td>
757             </tr>
758         [% END %]
759         </tbody>
760     </table>
761 </div>
762 $$;
763
764
765 COMMIT;