return $U->ou_ancestor_setting_value($org_id, $setting);
},
+ # This basically greps/maps out ths isbn string values, but also promotes the first isbn-13 to the
+ # front of the line (so that the EDI translator takes it as primary) if there is one.
+ get_li_isbns => sub {
+ my $attrs = shift;
+ my @isbns;
+ my $primary;
+ foreach (@$attrs) {
+ $_->attr_name eq 'isbn' or next;
+ my $val = $_->attr_value;
+ if (! $primary and length($val) == 13) {
+ $primary = $val;
+ } else {
+ push @isbns, $val;
+ }
+ }
+ $primary and unshift @isbns, $primary;
+ $logger->error("get_li_isbns returning isbns: " . join(', ', @isbns));
+ return @isbns;
+ },
+
# helpers.get_li_attr('isbn_13', li.attributes)
# returns matching line item attribute, or undef
get_li_attr => sub {
"items":[
[% FOR li IN target.lineitems %]
{
- "identifiers":[
- {"id-qualifier":"SA","id":"[% li.id %]"},
- {"id-qualifier":"IB","id":"[% helpers.get_li_attr('isbn_13', li.attributes) || helpers.get_li_attr('isbn_10', li.attributes) %]"}
+ "identifiers":[ [%-# li.isbns = helpers.get_li_isbns(li.attributes) %]
+ [% FOR isbn IN helpers.get_li_isbns(li.attributes) -%]
+ [% IF isbn.length == 13 -%]
+ {"id-qualifier":"EN","id":"[% isbn %]"},
+ [% ELSE -%]
+ {"id-qualifier":"IB","id":"[% isbn %]"},
+ [%- END %]
+ [% END %]
+ {"id-qualifier":"SA","id":"[% li.id %]"}
],
"price":[% li.estimated_unit_price || '0.00' %],
"desc":[
--- /dev/null
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0312'); --atz
+
+UPDATE action_trigger.event_definition SET template =
+$$[%- USE date -%]
+[%# start JEDI document -%]
+[%- BLOCK big_block -%]
+{
+ "recipient":"[% target.provider.san %]",
+ "sender":"[% target.ordering_agency.mailing_address.san %]",
+ "body": [{
+ "ORDERS":[ "order", {
+ "po_number":[% target.id %],
+ "date":"[% date.format(date.now, '%Y%m%d') %]",
+ "buyer":[{
+ [%- IF target.provider.edi_default.vendcode -%]
+ "id":"[% target.ordering_agency.mailing_address.san _ ' ' _ target.provider.edi_default.vendcode %]",
+ "id-qualifier": 91
+ [%- ELSE -%]
+ "id":"[% target.ordering_agency.mailing_address.san %]"
+ [%- END -%]
+ }],
+ "vendor":[
+ [%- # target.provider.name (target.provider.id) -%]
+ "[% target.provider.san %]",
+ {"id-qualifier": 92, "id":"[% target.provider.id %]"}
+ ],
+ "currency":"[% target.provider.currency_type %]",
+ "items":[
+ [% FOR li IN target.lineitems %]
+ {
+ "identifiers":[ [%-# li.isbns = helpers.get_li_isbns(li.attributes) %]
+ [% FOR isbn IN helpers.get_li_isbns(li.attributes) -%]
+ [% IF isbn.length == 13 -%]
+ {"id-qualifier":"EN","id":"[% isbn %]"},
+ [% ELSE -%]
+ {"id-qualifier":"IB","id":"[% isbn %]"},
+ [%- END %]
+ [% END %]
+ {"id-qualifier":"SA","id":"[% li.id %]"}
+ ],
+ "price":[% li.estimated_unit_price || '0.00' %],
+ "desc":[
+ {"BTI":"[% helpers.get_li_attr('title', '', li.attributes) %]"},
+ {"BPU":"[% helpers.get_li_attr('publisher', '', li.attributes) %]"},
+ {"BPD":"[% helpers.get_li_attr('pubdate', '', li.attributes) %]"},
+ {"BPH":"[% helpers.get_li_attr('pagination','', li.attributes) %]"}
+ ],
+ "quantity":[% li.lineitem_details.size %]
+ }[% UNLESS loop.last %],[% END %]
+ [%-# TODO: lineitem details (later) -%]
+ [% END %]
+ ],
+ "line_items":[% target.lineitems.size %]
+ }] [% # close ORDERS array %]
+ }] [% # close body array %]
+}
+[% END %]
+[% tempo = PROCESS big_block; helpers.escape_json(tempo) %]
+$$
+WHERE id = 23;
+
+COMMIT;