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).
10 UPDATE action_trigger.event_definition SET template =
12 [%# start JEDI document
13 # Vendor specific kludges:
14 # BT - vendcode goes to NAD/BY *suffix* w/ 91 qualifier
15 # INGRAM - vendcode goes to NAD/BY *segment* w/ 91 qualifier (separately)
16 # BRODART - vendcode goes to FTX segment (lineitem level)
19 IF target.provider.edi_default.vendcode && target.provider.code == 'BRODART';
20 xtra_ftx = target.provider.edi_default.vendcode;
23 [%- BLOCK big_block -%]
25 "recipient":"[% target.provider.san %]",
26 "sender":"[% target.ordering_agency.mailing_address.san %]",
29 "po_number":[% target.id %],
30 "date":"[% date.format(date.now, '%Y%m%d') %]",
32 [% IF target.provider.edi_default.vendcode && (target.provider.code == 'BT' || target.provider.name.match('(?i)^BAKER & TAYLOR')) -%]
33 {"id-qualifier": 91, "id":"[% target.ordering_agency.mailing_address.san _ ' ' _ target.provider.edi_default.vendcode %]"}
34 [%- ELSIF target.provider.edi_default.vendcode && target.provider.code == 'INGRAM' -%]
35 {"id":"[% target.ordering_agency.mailing_address.san %]"},
36 {"id-qualifier": 91, "id":"[% target.provider.edi_default.vendcode %]"}
38 {"id":"[% target.ordering_agency.mailing_address.san %]"}
42 [%- # target.provider.name (target.provider.id) -%]
43 "[% target.provider.san %]",
44 {"id-qualifier": 92, "id":"[% target.provider.id %]"}
46 "currency":"[% target.provider.currency_type %]",
49 [%- FOR li IN target.lineitems %]
51 "line_index":"[% li.id %]",
52 "identifiers":[ [%-# li.isbns = helpers.get_li_isbns(li.attributes) %]
53 [% FOR isbn IN helpers.get_li_isbns(li.attributes) -%]
54 [% IF isbn.length == 13 -%]
55 {"id-qualifier":"EN","id":"[% isbn %]"},
57 {"id-qualifier":"IB","id":"[% isbn %]"},
60 {"id-qualifier":"IN","id":"[% li.id %]"}
62 "price":[% li.estimated_unit_price || '0.00' %],
64 {"BTI":"[% helpers.get_li_attr_jedi('title', '', li.attributes) %]"},
65 {"BPU":"[% helpers.get_li_attr_jedi('publisher', '', li.attributes) %]"},
66 {"BPD":"[% helpers.get_li_attr_jedi('pubdate', '', li.attributes) %]"},
67 {"BPH":"[% helpers.get_li_attr_jedi('pagination','', li.attributes) %]"}
70 FOR note IN li.lineitem_notes;
71 NEXT UNLESS note.vendor_public == 't';
72 ftx_vals.push(note.value);
74 IF xtra_ftx; ftx_vals.unshift(xtra_ftx); END;
75 IF ftx_vals.size == 0; ftx_vals.unshift(''); END; # BT needs FTX+LIN for every LI, even if it is an empty one
79 [% FOR note IN ftx_vals -%] "[% note %]"[% UNLESS loop.last %], [% END %][% END %]
81 "quantity":[% li.lineitem_details.size %],
84 [%- FOR lid IN li.lineitem_details;
86 item_type = lid.circ_modifier;
87 callnumber = lid.cn_label;
88 owning_lib = lid.owning_lib.shortname;
89 location = lid.location;
91 # when we have real copy data, treat it as authoritative
94 item_type = acp.circ_modifier;
95 callnumber = acp.call_number.label;
96 location = acp.location.name;
98 { [%- IF fund %] "fund" : "[% fund %]",[% END -%]
99 [%- IF callnumber %] "call_number" : "[% callnumber %]", [% END -%]
100 [%- IF item_type %] "item_type" : "[% item_type %]", [% END -%]
101 [%- IF location %] "copy_location" : "[% location %]", [% END -%]
102 [%- IF owning_lib %] "owning_lib" : "[% owning_lib %]", [% END -%]
103 [%- #chomp %]"copy_id" : "[% lid.id %]" }[% ',' UNLESS loop.last %]
107 }[% UNLESS loop.last %],[% END %]
108 [%-# TODO: lineitem details (later) -%]
111 "line_items":[% target.lineitems.size %]
112 }] [%# close ORDERS array %]
113 }] [%# close body array %]
116 [% tempo = PROCESS big_block; helpers.escape_json(tempo) %]
118 WHERE id = 23 AND FALSE; -- DON'T PERFORM THE UPDATE
121 -- add copy-related fields to the environment if they're not already there.
125 FROM action_trigger.environment
128 path = 'lineitems.lineitem_details.owning_lib';
130 INSERT INTO action_trigger.environment (event_def, path)
131 VALUES (23, 'lineitems.lineitem_details.owning_lib');
135 FROM action_trigger.environment
138 path = 'lineitems.lineitem_details.fund';
140 INSERT INTO action_trigger.environment (event_def, path)
141 VALUES (23, 'lineitems.lineitem_details.fund');
145 FROM action_trigger.environment
148 path = 'lineitems.lineitem_details.location';
150 INSERT INTO action_trigger.environment (event_def, path)
151 VALUES (23, 'lineitems.lineitem_details.location');
155 FROM action_trigger.environment
158 path = 'lineitems.lineitem_details.eg_copy_id.location';
160 INSERT INTO action_trigger.environment (event_def, path)
161 VALUES (23, 'lineitems.lineitem_details.eg_copy_id.location');
165 FROM action_trigger.environment
168 path = 'lineitems.lineitem_details.eg_copy_id.call_number';
170 INSERT INTO action_trigger.environment (event_def, path)
171 VALUES (23, 'lineitems.lineitem_details.eg_copy_id.call_number');
176 -- remove redundant entry
177 DELETE FROM action_trigger.environment
178 WHERE event_def = 23 AND path = 'lineitems.lineitem_details';