4 -- Template update included here for reference only.
5 -- The stock JEDI template is not updated here (see WHERE clause)
6 -- We do update the environment, though, for easier local template
7 -- updating. No env fields are removed (that aren't otherwise replaced).
12 SELECT evergreen.upgrade_deps_block_check('0733', :eg_version);
14 UPDATE action_trigger.event_definition SET template =
16 [%# start JEDI document
17 # Vendor specific kludges:
18 # BT - vendcode goes to NAD/BY *suffix* w/ 91 qualifier
19 # INGRAM - vendcode goes to NAD/BY *segment* w/ 91 qualifier (separately)
20 # BRODART - vendcode goes to FTX segment (lineitem level)
23 IF target.provider.edi_default.vendcode && target.provider.code == 'BRODART';
24 xtra_ftx = target.provider.edi_default.vendcode;
27 [%- BLOCK big_block -%]
29 "recipient":"[% target.provider.san %]",
30 "sender":"[% target.ordering_agency.mailing_address.san %]",
33 "po_number":[% target.id %],
34 "date":"[% date.format(date.now, '%Y%m%d') %]",
36 [% IF target.provider.edi_default.vendcode && (target.provider.code == 'BT' || target.provider.name.match('(?i)^BAKER & TAYLOR')) -%]
37 {"id-qualifier": 91, "id":"[% target.ordering_agency.mailing_address.san _ ' ' _ target.provider.edi_default.vendcode %]"}
38 [%- ELSIF target.provider.edi_default.vendcode && target.provider.code == 'INGRAM' -%]
39 {"id":"[% target.ordering_agency.mailing_address.san %]"},
40 {"id-qualifier": 91, "id":"[% target.provider.edi_default.vendcode %]"}
42 {"id":"[% target.ordering_agency.mailing_address.san %]"}
46 [%- # target.provider.name (target.provider.id) -%]
47 "[% target.provider.san %]",
48 {"id-qualifier": 92, "id":"[% target.provider.id %]"}
50 "currency":"[% target.provider.currency_type %]",
53 [%- FOR li IN target.lineitems %]
55 "line_index":"[% li.id %]",
56 "identifiers":[ [%-# li.isbns = helpers.get_li_isbns(li.attributes) %]
57 [% FOR isbn IN helpers.get_li_isbns(li.attributes) -%]
58 [% IF isbn.length == 13 -%]
59 {"id-qualifier":"EN","id":"[% isbn %]"},
61 {"id-qualifier":"IB","id":"[% isbn %]"},
64 {"id-qualifier":"IN","id":"[% li.id %]"}
66 "price":[% li.estimated_unit_price || '0.00' %],
68 {"BTI":"[% helpers.get_li_attr_jedi('title', '', li.attributes) %]"},
69 {"BPU":"[% helpers.get_li_attr_jedi('publisher', '', li.attributes) %]"},
70 {"BPD":"[% helpers.get_li_attr_jedi('pubdate', '', li.attributes) %]"},
71 {"BPH":"[% helpers.get_li_attr_jedi('pagination','', li.attributes) %]"}
74 FOR note IN li.lineitem_notes;
75 NEXT UNLESS note.vendor_public == 't';
76 ftx_vals.push(note.value);
78 IF xtra_ftx; ftx_vals.unshift(xtra_ftx); END;
79 IF ftx_vals.size == 0; ftx_vals.unshift(''); END; # BT needs FTX+LIN for every LI, even if it is an empty one
83 [% FOR note IN ftx_vals -%] "[% note %]"[% UNLESS loop.last %], [% END %][% END %]
85 "quantity":[% li.lineitem_details.size %],
88 [%- FOR lid IN li.lineitem_details;
90 item_type = lid.circ_modifier;
91 callnumber = lid.cn_label;
92 owning_lib = lid.owning_lib.shortname;
93 location = lid.location;
95 # when we have real copy data, treat it as authoritative
98 item_type = acp.circ_modifier;
99 callnumber = acp.call_number.label;
100 location = acp.location.name;
102 { [%- IF fund %] "fund" : "[% fund %]",[% END -%]
103 [%- IF callnumber %] "call_number" : "[% callnumber %]", [% END -%]
104 [%- IF item_type %] "item_type" : "[% item_type %]", [% END -%]
105 [%- IF location %] "copy_location" : "[% location %]", [% END -%]
106 [%- IF owning_lib %] "owning_lib" : "[% owning_lib %]", [% END -%]
107 [%- #chomp %]"copy_id" : "[% lid.id %]" }[% ',' UNLESS loop.last %]
111 }[% UNLESS loop.last %],[% END %]
112 [%-# TODO: lineitem details (later) -%]
115 "line_items":[% target.lineitems.size %]
116 }] [%# close ORDERS array %]
117 }] [%# close body array %]
120 [% tempo = PROCESS big_block; helpers.escape_json(tempo) %]
122 WHERE id = 23 AND FALSE; -- DON'T PERFORM THE UPDATE
125 -- add copy-related fields to the environment if they're not already there.
129 FROM action_trigger.environment
132 path = 'lineitems.lineitem_details.owning_lib';
134 INSERT INTO action_trigger.environment (event_def, path)
135 VALUES (23, 'lineitems.lineitem_details.owning_lib');
139 FROM action_trigger.environment
142 path = 'lineitems.lineitem_details.fund';
144 INSERT INTO action_trigger.environment (event_def, path)
145 VALUES (23, 'lineitems.lineitem_details.fund');
149 FROM action_trigger.environment
152 path = 'lineitems.lineitem_details.location';
154 INSERT INTO action_trigger.environment (event_def, path)
155 VALUES (23, 'lineitems.lineitem_details.location');
159 FROM action_trigger.environment
162 path = 'lineitems.lineitem_details.eg_copy_id.location';
164 INSERT INTO action_trigger.environment (event_def, path)
165 VALUES (23, 'lineitems.lineitem_details.eg_copy_id.location');
169 FROM action_trigger.environment
172 path = 'lineitems.lineitem_details.eg_copy_id.call_number';
174 INSERT INTO action_trigger.environment (event_def, path)
175 VALUES (23, 'lineitems.lineitem_details.eg_copy_id.call_number');
180 -- remove redundant entry
181 DELETE FROM action_trigger.environment
182 WHERE event_def = 23 AND path = 'lineitems.lineitem_details';