3 SELECT evergreen.upgrade_deps_block_check('0777', :eg_version);
5 -- Listed here for reference / ease of access. The update
6 -- is not applied here (see the WHERE clause).
7 UPDATE action_trigger.event_definition SET template =
11 # extract some commonly used variables
13 VENDOR_SAN = target.provider.san;
14 VENDCODE = target.provider.edi_default.vendcode;
15 VENDACCT = target.provider.edi_default.vendacct;
16 ORG_UNIT_SAN = target.ordering_agency.mailing_address.san;
18 # set the vendor / provider
20 VENDOR_BT = 0; # Baker & Taylor
23 VENDOR_MW_TAPE = 0; # Midwest Tape
24 VENDOR_RB = 0; # Recorded Books
27 IF VENDOR_SAN == '1556150'; VENDOR_BT = 1;
28 ELSIF VENDOR_SAN == '1697684'; VENDOR_BRODART = 1;
29 ELSIF VENDOR_SAN == '1697978'; VENDOR_INGRAM = 1;
30 ELSIF VENDOR_SAN == '2549913'; VENDOR_MW_TAPE = 1;
31 ELSIF VENDOR_SAN == '1113984'; VENDOR_RB = 1;
32 ELSIF VENDOR_SAN == '1699342'; VENDOR_ULS = 1;
35 # if true, pass the PO name as a secondary identifier
42 # GIR configuration --------------------------------------
44 INC_COPIES = 1; # copies on/off switch
49 INC_COLLECTION_CODE = 1;
64 INC_COLLECTION_CODE = 0;
68 # END GIR configuration ---------------------------------
71 [%- BLOCK big_block -%]
73 "recipient":"[% VENDOR_SAN %]",
74 "sender":"[% ORG_UNIT_SAN %]",
78 "po_number":[% target.id %],
81 "po_name":"[% target.name | replace('\/', ' ') | replace('"', '\"') %]",
84 "date":"[% date.format(date.now, '%Y%m%d') %]",
88 {"id-qualifier": 91, "id":"[% ORG_UNIT_SAN %] [% VENDCODE %]"}
90 {"id":"[% ORG_UNIT_SAN %]"},
91 {"id-qualifier": 91, "id":"[% VENDACCT %]"}
97 {"id-qualifier": 92, "id":"[% target.provider.id %]"}
100 "currency":"[% target.provider.currency_type %]",
103 [%- FOR li IN target.lineitems %]
105 "line_index":"[% li.id %]",
109 idqual = 'EN'; # default ISBN/UPC/EAN-13
110 ident_attr = helpers.get_li_order_ident(li.attributes);
112 idname = ident_attr.attr_name;
113 idval = ident_attr.attr_value;
114 IF idname == 'isbn' AND idval.length != 13;
116 ELSIF idname == 'issn';
123 {"id-qualifier":"[% idqual %]","id":"[% idval %]"}
125 "price":[% li.estimated_unit_price || '0.00' %],
127 {"BTI":"[% helpers.get_li_attr_jedi('title', '', li.attributes) %]"},
128 {"BPU":"[% helpers.get_li_attr_jedi('publisher', '', li.attributes) %]"},
129 {"BPD":"[% helpers.get_li_attr_jedi('pubdate', '', li.attributes) %]"},
131 {"BEN":"[% helpers.get_li_attr_jedi('edition', '', li.attributes) %]"},
132 {"BAU":"[% helpers.get_li_attr_jedi('author', '', li.attributes) %]"}
134 {"BPH":"[% helpers.get_li_attr_jedi('pagination','', li.attributes) %]"}
138 FOR note IN li.lineitem_notes;
139 NEXT UNLESS note.vendor_public == 't';
140 ftx_vals.push(note.value);
142 IF VENDOR_BRODART; # look for copy-level spec code
143 FOR lid IN li.lineitem_details;
145 spec_note = lid.note.match('spec code ([a-zA-Z0-9_])');
146 IF spec_note.0; ftx_vals.push(spec_note.0); END;
150 IF xtra_ftx; ftx_vals.unshift(xtra_ftx); END;
152 # BT & ULS want FTX+LIN for every LI, even if empty
153 IF ((VENDOR_BT OR VENDOR_ULS) AND ftx_vals.size == 0);
154 ftx_vals.unshift('');
159 [% FOR note IN ftx_vals -%] "[% note %]"[% UNLESS loop.last %], [% END %][% END %]
162 "quantity":[% li.lineitem_details.size %],
164 [%- IF INC_COPIES -%]
166 [%- compressed_copies = [];
167 FOR lid IN li.lineitem_details;
168 fund = lid.fund.code;
169 item_type = lid.circ_modifier;
170 callnumber = lid.cn_label;
171 owning_lib = lid.owning_lib.shortname;
172 location = lid.location;
173 collection_code = lid.collection_code;
175 # when we have real copy data, treat it as authoritative for some fields
176 acp = lid.eg_copy_id;
178 item_type = acp.circ_modifier;
179 callnumber = acp.call_number.label;
180 location = acp.location.name;
184 # collapse like copies into groups w/ quantity
187 IF !INC_COPY_ID; # INC_COPY_ID implies 1 copy per GIR
188 FOR copy IN compressed_copies;
189 IF (fund == copy.fund OR (!fund AND !copy.fund)) AND
190 (item_type == copy.item_type OR (!item_type AND !copy.item_type)) AND
191 (callnumber == copy.callnumber OR (!callnumber AND !copy.callnumber)) AND
192 (owning_lib == copy.owning_lib OR (!owning_lib AND !copy.owning_lib)) AND
193 (location == copy.location OR (!location AND !copy.location)) AND
194 (collection_code == copy.collection_code OR (!collection_code AND !copy.collection_code));
196 copy.quantity = copy.quantity + 1;
203 compressed_copies.push({
205 item_type => item_type,
206 callnumber => callnumber,
207 owning_lib => owning_lib,
208 location => location,
209 collection_code => collection_code,
210 copy_id => lid.id, # for INC_COPY_ID
215 FOR copy IN compressed_copies;
217 # If we assume owning_lib is required and set,
218 # it is safe to prepend each following copy field w/ a ","
220 # B&T EDI requires expected GIR fields to be
221 # present regardless of whether a value exists.
222 # some fields are required to have a value in ACQ,
223 # though, so they are not forced into place below.
225 %]{[%- IF INC_OWNING_LIB AND copy.owning_lib %] "owning_lib":"[% copy.owning_lib %]"[% END -%]
226 [%- IF INC_FUND AND copy.fund %],"fund":"[% copy.fund %]"[% END -%]
227 [%- IF INC_CALLNUMBER AND (VENDOR_BT OR copy.callnumber) %],"call_number":"[% copy.callnumber %]"[% END -%]
228 [%- IF INC_ITEM_TYPE AND (VENDOR_BT OR copy.item_type) %],"item_type":"[% copy.item_type %]"[% END -%]
229 [%- IF INC_LOCATION AND copy.location %],"copy_location":"[% copy.location %]"[% END -%]
230 [%- IF INC_COLLECTION_CODE AND (VENDOR_BT OR copy.collection_code) %],"collection_code":"[% copy.collection_code %]"[% END -%]
231 [%- IF INC_QUANTITY %],"quantity":"[% copy.quantity %]"[% END -%]
232 [%- IF INC_COPY_ID %],"copy_id":"[% copy.copy_id %]" [% END %]}[% ',' UNLESS loop.last -%]
233 [%- END -%] [%# FOR compressed_copies -%]
235 [%- END -%] [%# IF INC_COPIES %]
237 }[% UNLESS loop.last %],[% END -%]
239 [% END %] [%# END lineitems %]
241 "line_items":[% target.lineitems.size %]
242 }] [%# close ORDERS array %]
243 }] [%# close body array %]
246 [% tempo = PROCESS big_block; helpers.escape_json(tempo) %]
248 WHERE ID = 23 AND FALSE; -- remove 'AND FALSE' to apply this update
251 -- lineitem worksheet
252 UPDATE action_trigger.event_definition SET template =
256 # find a lineitem attribute by name and optional type
258 FOR attr IN li.attributes;
259 IF attr.attr_name == attr_name;
260 IF !attr_type OR attr_type == attr.attr_type;
269 <h2>Purchase Order [% target.id %]</h2>
271 date <b>[% date.format(date.now, '%Y%m%d') %]</b>
275 table td { padding:5px; border:1px solid #aaa;}
276 table { width:95%; border-collapse:collapse; }
277 #vendor-notes { padding:5px; border:1px solid #aaa; }
279 <table id='vendor-table'>
281 <td valign='top'>Vendor</td>
283 <div>[% target.provider.name %]</div>
284 <div>[% target.provider.addresses.0.street1 %]</div>
285 <div>[% target.provider.addresses.0.street2 %]</div>
286 <div>[% target.provider.addresses.0.city %]</div>
287 <div>[% target.provider.addresses.0.state %]</div>
288 <div>[% target.provider.addresses.0.country %]</div>
289 <div>[% target.provider.addresses.0.post_code %]</div>
291 <td valign='top'>Ship to / Bill to</td>
293 <div>[% target.ordering_agency.name %]</div>
294 <div>[% target.ordering_agency.billing_address.street1 %]</div>
295 <div>[% target.ordering_agency.billing_address.street2 %]</div>
296 <div>[% target.ordering_agency.billing_address.city %]</div>
297 <div>[% target.ordering_agency.billing_address.state %]</div>
298 <div>[% target.ordering_agency.billing_address.country %]</div>
299 <div>[% target.ordering_agency.billing_address.post_code %]</div>
305 <fieldset id='vendor-notes'>
306 <legend>Notes to the Vendor</legend>
308 [% FOR note IN target.notes %]
309 [% IF note.vendor_public == 't' %]
310 <li>[% note.value %]</li>
321 <th>ISBN or Item #</th>
332 [% FOR li IN target.lineitems %]
335 [% count = li.lineitem_details.size %]
336 [% price = li.estimated_unit_price %]
337 [% litotal = (price * count) %]
338 [% subtotal = subtotal + litotal %]
340 ident_attr = helpers.get_li_order_ident(li.attributes);
341 SET ident_value = ident_attr.attr_value IF ident_attr;
343 <td>[% target.id %]</td>
344 <td>[% ident_value %]</td>
345 <td>[% PROCESS get_li_attr attr_name = 'title' %]</td>
348 <td>[% litotal %]</td>
351 [% FOR note IN li.lineitem_notes %]
352 [% IF note.vendor_public == 't' %]
353 <li>[% note.value %]</li>
363 <td>[% subtotal %]</td>
370 Total Line Item Count: [% target.lineitems.size %]
372 WHERE ID = 4; -- PO HTML