--- /dev/null
+-- Deploy kcls-evergreen:blanket-po-print-template to pg
+-- requires: student-groups
+
+BEGIN;
+
+DO $$
+BEGIN
+ IF evergreen.insert_on_deploy() THEN
+
+INSERT INTO action_trigger.environment (event_def, path)
+ VALUES (4, 'po_items.inv_item_type');
+
+UPDATE action_trigger.event_definition SET template =
+$TMPL$
+[% USE String %]
+[% USE money=format('%.2f') -%]
+[%-
+ # find a lineitem attribute by name and optional type
+ BLOCK get_li_attr;
+ FOR attr IN li.attributes;
+ IF attr.attr_name == attr_name;
+ IF !attr_type OR attr_type == attr.attr_type;
+ attr.attr_value;
+ LAST;
+ END;
+ END;
+ END;
+ END
+-%]
+<img src="http://www.kcls.org/images/logo.gif" alt="kcls_brandmark" ALIGN=left width=74 height=150>
+<h2 CLASS="centeralign">Purchase Order [% target.id %]</h2>
+<BR CLEAR=LEFT>
+<br/>
+[% newstring = target.order_date | truncate(10,'')%]
+[% newstring2 = "$newstring 00:00:00" %]
+date <b>[% date.format(newstring2, '%m/%d/%Y') %]</b>
+<br/>
+
+<style>
+ table td { padding:5px; border:1px solid #aaa; font-size: 12px}
+ table { width:95%; border-collapse:collapse; font-size: 10px}
+ #vendor-notes { padding:5px; border:1px solid #aaa; font-size: 14px}
+ #vendor-table { padding:5px; border:1px solid #aaa; font-size: 14px}
+ #vendor-table td { padding:5px; border:1px solid #aaa; font-size: 14px}
+p { font-size: 14px }
+.rightalign {text-align:right}
+.centeralign {text-align:center}
+</style>
+<table id='vendor-table'>
+ <tr>
+ <td valign='top'>Vendor</td>
+ <td>
+ <div>[% target.provider.name %]</div>
+ <div>[% target.provider.addresses.0.street1 %]</div>
+ <div>[% target.provider.addresses.0.street2 %]</div>
+ <div>[% target.provider.addresses.0.city %] [% target.provider.addresses.0.state %] [% target.provider.addresses.0.post_code %]</div>
+
+ <div>[% target.provider.addresses.0.country %]</div>
+
+ </td>
+ <td valign='top'>Ship to / Bill to</td>
+ <td>
+ <div>KING COUNTY LIBRARY SYSTEM</div>
+ <div>ATTN: ORDER DEPT</div>
+ <div>960 NEWPORT WAY NW</div>
+ <div>ISSAQUAH WA 98027</div>
+
+ </td>
+ </tr>
+</table>
+
+<br/><br/>
+<fieldset id='vendor-notes'>
+ <legend>Notes to the Vendor</legend>
+ <ul>
+ [% FOR note IN target.notes %]
+ [% IF note.vendor_public == 't' %]
+ <li>[% note.value %]</li>
+ [% END %]
+ [% END %]
+ </ul>
+</fieldset>
+<br/><br/>
+
+<table>
+ <thead>
+ <tr>
+ <th>PO#</th>
+ <th>Line</th>
+ <th>ISBN / Item # / Charge Type</th>
+ <th>Title</th>
+ <th>Author</th>
+ <th>Pub Info</th>
+ <th>Quantity</th>
+ <th>Unit Price</th>
+ <th>Line Total</th>
+ <th>Notes</th>
+ </tr>
+ </thead>
+ <tbody>
+
+ [% subtotal = 0 %]
+ [% FOR li IN target.lineitems %]
+
+ <tr>
+ [% count = li.lineitem_details.size %]
+ [% price = li.estimated_unit_price %]
+ [% litotal = (price * count) %]
+ [% subtotal = subtotal + litotal %]
+ [% isbn = PROCESS get_li_attr attr_name = 'isbn' %]
+ [% ident = PROCESS get_li_attr attr_name = 'identifier' %]
+ [% upc = PROCESS get_li_attr attr_name = 'bupc' %]
+ [% author = PROCESS get_li_attr attr_name = 'author' %]
+ [% publisher = PROCESS get_li_attr attr_name = 'publisher' %]
+ [% pubdate = PROCESS get_li_attr attr_name = 'pubdate' %]
+ [% edition = PROCESS get_li_attr attr_name = 'edition' %]
+ [% vendnum = PROCESS get_li_attr attr_name = 'vendor_num' %]
+[%-
+ idval = '';
+ idqual = 'EN'; # default ISBN/UPC/EAN-13
+ ident_attr = helpers.get_li_order_ident(li.attributes);
+ IF ident_attr;
+ idname = ident_attr.attr_name;
+ idval = ident_attr.attr_value;
+ IF idname == 'isbn' AND idval.length != 13;
+ idqual = 'IB';
+ ELSIF idname == 'issn';
+ idqual = 'IS';
+ END;
+
+ ELSE;
+ idqual = 'IN';
+ idval = '';
+ END -%]
+
+[%- IF vendnum != '';
+ idval = PROCESS get_li_attr attr_name = 'vendor_num';
+ END;
+-%]
+ <td>[% target.id %]</td>
+ <td>[% li.id %]</td>
+ <td>[% idval %]</td>
+ <td>[% PROCESS get_li_attr attr_name = 'title' %] </td>
+ <td>[% author %]</td>
+ <td>[% publisher %] , [% pubdate %]</br>Edition: [% edition %]</td>
+ <td>[% count %]</td>
+ <td>[% price %]</td>
+ <td>[% money(litotal) %]</td>
+ <td>
+ <ul>
+ [% FOR note IN li.lineitem_notes %]
+ [% IF note.vendor_public == 't' %]
+ <li>[% note.value %]</li>
+ [% END %]
+ [% END %]
+ </ul>
+ </td>
+ </tr>
+ [% END %]
+ [% FOR charge IN target.po_items %]
+ [% subtotal = subtotal + charge.estimated_cost;
+ # a blanket charge is considered a single purchase.
+ IF charge.inv_item_type.blanket == 't';
+ total_count = total + 1;
+ END;
+ %]
+ <tr>
+ <td>[% target.id %]</td>
+ <td>[% charge.id %]</td>
+ <td>[% charge.inv_item_type.name %]</td>
+ <td>[% charge.title %]</td>
+ <td>[% charge.author %]</td>
+ <td></td>
+ <td></td>
+ <td>[% money(charge.estimated_cost) %]</td>
+ <td>[% money(charge.estimated_cost) %]</td>
+ [%# po_item.note has no concept of vendor-public,
+ so avoid displaying it by default %]
+ <td></td>
+ </tr>
+ [% END %]
+ <tr>
+ <td/><td/><td/><td/><td> </td><td> </td><td> </td>
+ <td>Sub Total</td>
+ <td>[% money(subtotal) %]</td>
+<td> </td>
+
+ </tr>
+ </tbody>
+</table>
+
+<br/>
+
+Total Line Item Count:[% total_count %]<br/><br/>
+
+<p CLASS="rightalign">
+_____________________________<br/>
+Authorized By
+
+
+
+ Date
+</p>
+
+<p>
+<b>SHIPPING AND BILLING INSTRUCTIONS</b><br/>
+Use our complete Ship To/Bill To address as given above.<br/>
+Report before sending if part of a numbered series, unless series is noted on this order.<br/>
+Do not send if price is substantially above our estimate. Please call for confirmation. 425-369-3368<br/>
+Send invoice in duplicate to address given above.<br/>
+Cite our line item and order number with each item on invoices and/or correspondence.<br/>
+Shipments must be insured or sent at agent's risk.<br/>
+No COD shipments.<br/>
+Questions, call (425) 369-3368<br/>
+</p>
+$TMPL$ WHERE id = 4;
+
+ END IF;
+END $$;
+
+COMMIT;
--- /dev/null
+-- Revert kcls-evergreen:blanket-po-print-template from pg
+
+BEGIN;
+
+DO $$
+BEGIN
+ IF evergreen.insert_on_deploy() THEN
+
+DELETE FROM action_trigger.environment
+ WHERE event_def = 4 AND path = 'po_items.inv_item_type';
+
+UPDATE action_trigger.event_definition SET template =
+$TMPL$
+[% USE String %]
+[% USE money=format('%.2f') -%]
+[%-
+ # find a lineitem attribute by name and optional type
+ BLOCK get_li_attr;
+ FOR attr IN li.attributes;
+ IF attr.attr_name == attr_name;
+ IF !attr_type OR attr_type == attr.attr_type;
+ attr.attr_value;
+ LAST;
+ END;
+ END;
+ END;
+ END
+-%]
+<img src="http://www.kcls.org/images/logo.gif" alt="kcls_brandmark" ALIGN=left width=74 height=150>
+<h2 CLASS="centeralign">Purchase Order [% target.id %]</h2>
+<BR CLEAR=LEFT>
+<br/>
+[% newstring = target.order_date | truncate(10,'')%]
+[% newstring2 = "$newstring 00:00:00" %]
+date <b>[% date.format(newstring2, '%m/%d/%Y') %]</b>
+<br/>
+
+<style>
+ table td { padding:5px; border:1px solid #aaa; font-size: 12px}
+ table { width:95%; border-collapse:collapse; font-size: 10px}
+ #vendor-notes { padding:5px; border:1px solid #aaa; font-size: 14px}
+ #vendor-table { padding:5px; border:1px solid #aaa; font-size: 14px}
+ #vendor-table td { padding:5px; border:1px solid #aaa; font-size: 14px}
+p { font-size: 14px }
+.rightalign {text-align:right}
+.centeralign {text-align:center}
+</style>
+<table id='vendor-table'>
+ <tr>
+ <td valign='top'>Vendor</td>
+ <td>
+ <div>[% target.provider.name %]</div>
+ <div>[% target.provider.addresses.0.street1 %]</div>
+ <div>[% target.provider.addresses.0.street2 %]</div>
+ <div>[% target.provider.addresses.0.city %] [% target.provider.addresses.0.state %] [% target.provider.addresses.0.post_code %]</div>
+
+ <div>[% target.provider.addresses.0.country %]</div>
+
+ </td>
+ <td valign='top'>Ship to / Bill to</td>
+ <td>
+ <div>KING COUNTY LIBRARY SYSTEM</div>
+ <div>ATTN: ORDER DEPT</div>
+ <div>960 NEWPORT WAY NW</div>
+ <div>ISSAQUAH WA 98027</div>
+
+ </td>
+ </tr>
+</table>
+
+<br/><br/>
+<fieldset id='vendor-notes'>
+ <legend>Notes to the Vendor</legend>
+ <ul>
+ [% FOR note IN target.notes %]
+ [% IF note.vendor_public == 't' %]
+ <li>[% note.value %]</li>
+ [% END %]
+ [% END %]
+ </ul>
+</fieldset>
+<br/><br/>
+
+<table>
+ <thead>
+ <tr>
+ <th>PO#</th>
+ <th>Line</th>
+ <th>ISBN or Item #</th>
+ <th>Title</th>
+ <th>Author</th>
+ <th>Pub Info</th>
+ <th>Quantity</th>
+ <th>Unit Price</th>
+ <th>Line Total</th>
+ <th>Notes</th>
+ </tr>
+ </thead>
+ <tbody>
+
+ [% subtotal = 0 %]
+ [% FOR li IN target.lineitems %]
+
+ <tr>
+ [% count = li.lineitem_details.size %]
+ [% price = li.estimated_unit_price %]
+ [% litotal = (price * count) %]
+ [% subtotal = subtotal + litotal %]
+ [% isbn = PROCESS get_li_attr attr_name = 'isbn' %]
+ [% ident = PROCESS get_li_attr attr_name = 'identifier' %]
+ [% upc = PROCESS get_li_attr attr_name = 'bupc' %]
+ [% author = PROCESS get_li_attr attr_name = 'author' %]
+ [% publisher = PROCESS get_li_attr attr_name = 'publisher' %]
+ [% pubdate = PROCESS get_li_attr attr_name = 'pubdate' %]
+ [% edition = PROCESS get_li_attr attr_name = 'edition' %]
+ [% vendnum = PROCESS get_li_attr attr_name = 'vendor_num' %]
+[%-
+ idval = '';
+ idqual = 'EN'; # default ISBN/UPC/EAN-13
+ ident_attr = helpers.get_li_order_ident(li.attributes);
+ IF ident_attr;
+ idname = ident_attr.attr_name;
+ idval = ident_attr.attr_value;
+ IF idname == 'isbn' AND idval.length != 13;
+ idqual = 'IB';
+ ELSIF idname == 'issn';
+ idqual = 'IS';
+ END;
+
+ ELSE;
+ idqual = 'IN';
+ idval = '';
+ END -%]
+
+[%- IF vendnum != '';
+ idval = PROCESS get_li_attr attr_name = 'vendor_num';
+ END;
+-%]
+ <td>[% target.id %]</td>
+ <td>[% li.id %]</td>
+ <td>[% idval %]</td>
+ <td>[% PROCESS get_li_attr attr_name = 'title' %] </td>
+ <td>[% author %]</td>
+ <td>[% publisher %] , [% pubdate %]</br>Edition: [% edition %]</td>
+ <td>[% count %]</td>
+ <td>[% price %]</td>
+ <td>[% money(litotal) %]</td>
+ <td>
+ <ul>
+ [% FOR note IN li.lineitem_notes %]
+ [% IF note.vendor_public == 't' %]
+ <li>[% note.value %]</li>
+ [% END %]
+ [% END %]
+ </ul>
+ </td>
+ </tr>
+ [% END %]
+ <tr>
+ <td/><td/><td/><td/><td> </td><td> </td><td> </td>
+ <td>Sub Total</td>
+ <td>[% money(subtotal) %]</td>
+<td> </td>
+
+ </tr>
+ </tbody>
+</table>
+
+<br/>
+
+
+Total Line Item Count:[% target.lineitems.size %]<br/><br/>
+
+<p CLASS="rightalign">
+_____________________________<br/>
+Authorized By
+
+
+
+ Date
+</p>
+
+<p>
+<b>SHIPPING AND BILLING INSTRUCTIONS</b><br/>
+Use our complete Ship To/Bill To address as given above.<br/>
+Report before sending if part of a numbered series, unless series is noted on this order.<br/>
+Do not send if price is substantially above our estimate. Please call for confirmation. 425-369-3368<br/>
+Send invoice in duplicate to address given above.<br/>
+Cite our line item and order number with each item on invoices and/or correspondence.<br/>
+Shipments must be insured or sent at agent's risk.<br/>
+No COD shipments.<br/>
+Questions, call (425) 369-3368<br/>
+</p>
+$TMPL$ WHERE id = 4;
+
+ END IF;
+END $$;
+
+COMMIT;