From: Bill Erickson Date: Tue, 24 May 2016 16:37:22 +0000 (-0400) Subject: JBAS-1439 Swap Ingram vendcode/vendacct values X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=60b105c3ec5674b77d84beb4ff0521af83da445d;p=working%2FEvergreen.git JBAS-1439 Swap Ingram vendcode/vendacct values Invoicing requires the vendor code and account values on the EDI messages be in the proper location. This also rolls back a change to the EDI order template which swapped them directly within the template. Signed-off-by: Bill Erickson --- diff --git a/KCLS/sql/schema/deploy/ingram-edi-mods.sql b/KCLS/sql/schema/deploy/ingram-edi-mods.sql new file mode 100644 index 0000000000..b24455d9ed --- /dev/null +++ b/KCLS/sql/schema/deploy/ingram-edi-mods.sql @@ -0,0 +1,273 @@ +-- Deploy kcls-evergreen:ingram-edi-mods to pg +-- requires: sip-activity-types + +BEGIN; + +-- Swap vendacct / vendcode for all Ingram EDI accounts +UPDATE acq.edi_account +SET vendcode = vendacct, vendacct = vendcode +WHERE host='ftp://ftp1.ingrambook.com'; + +UPDATE action_trigger.event_definition SET template = +$$ +[%- USE date -%] +[% + # extract some commonly used variables + + VENDOR_SAN = target.provider.san; + VENDCODE = target.provider.edi_default.vendcode; + VENDACCT = target.provider.edi_default.vendacct; + ORG_UNIT_SAN = target.ordering_agency.mailing_address.san; + + # set the vendor / provider + + VENDOR_BT = 0; # Baker & Taylor + VENDOR_INGRAM = 0; + VENDOR_BRODART = 0; + VENDOR_MW_TAPE = 0; # Midwest Tape + VENDOR_RB = 0; # Recorded Books + VENDOR_ULS = 0; # ULS + VENDOR_MLS = 0; # MLS + + IF VENDOR_SAN == '1556150'; VENDOR_BT = 1; + ELSIF VENDOR_SAN == '1697684'; VENDOR_BRODART = 1; + ELSIF VENDOR_SAN == '1697978'; VENDOR_INGRAM = 1; + ELSIF VENDOR_SAN == '2549913'; VENDOR_MW_TAPE = 1; + ELSIF VENDOR_SAN == '1113984'; VENDOR_RB = 1; + ELSIF VENDOR_SAN == '1699342'; VENDOR_ULS = 1; + ELSIF VENDOR_SAN == '1694243'; VENDOR_MLS = 1; + END; + + # if true, pass the PO name as a secondary identifier + # RFF+LI:/li_id + INC_PO_NAME = 0; + IF VENDOR_INGRAM; + INC_PO_NAME = 1; + END; + + # GIR configuration -------------------------------------- + + INC_COPIES = 1; # copies on/off switch + INC_FUND = 0; + INC_CALLNUMBER = 0; + INC_ITEM_TYPE = 1; + INC_LOCATION = 0; + INC_COLLECTION_CODE = 1; + INC_OWNING_LIB = 1; + INC_QUANTITY = 1; + INC_COPY_ID = 0; + + IF VENDOR_BT; + INC_CALLNUMBER = 1; + ORG_UNIT_SAN = '3176061'; + END; + + IF VENDOR_BRODART; + INC_FUND = 1; + ORG_UNIT_SAN = '3176061'; + VENDACCT = VENDCODE; + END; + + IF VENDOR_MW_TAPE; + INC_FUND = 1; + INC_COLLECTION_CODE = 0; + INC_ITEM_TYPE = 0; + END; + IF VENDOR_INGRAM; + # Vendor account and code are now correct in the edi_account. + # No need to swap them in the template. + # VENDACCT = VENDCODE; + ORG_UNIT_SAN = '317606Z'; + END; + + # END GIR configuration --------------------------------- + +-%] +[%- BLOCK big_block -%] +{ + "recipient":"[% VENDOR_SAN %]", + "sender":"[% ORG_UNIT_SAN %]", + "body": [{ + "ORDERS":[ "order", { + + "po_number":[% target.id %], + + [% IF INC_PO_NAME %] + "po_name":"[% target.name | replace('\/', ' ') | replace('"', '\"') %]", + [% END %] + + "date":"[% date.format(date.now, '%Y%m%d') %]", + + "buyer":[ + [% IF VENDOR_BT %] + {"id-qualifier": 91, "id":"[% ORG_UNIT_SAN %] [% VENDCODE %]"} + [% ELSE %] + {"id":"[% ORG_UNIT_SAN %]"}, + {"id-qualifier": 91, "id":"[% VENDACCT %]"} + [% END %] + ], + + "vendor":[ + "[% VENDOR_SAN %]", + {"id-qualifier": 92, "id":"[% target.provider.id %]"} + ], + + "currency":"[% target.provider.currency_type %]", + + "items":[ + [%- FOR li IN target.lineitems %] + { + "line_index":"[% li.id %]", + [% IF (VENDOR_BT) %] + "line_number":"[% li.id %]", + [% END %] + "identifiers":[ + [%- + idval = ''; + vendnum = ''; + 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 = li.id; + END -%] + [%- + IF (VENDOR_BT) && helpers.get_li_attr('vendor_num', '', li.attributes); # USE 938 vendor number if it exists + idval = helpers.get_li_attr('vendor_num', '', li.attributes); + idqual = 'EN'; + END -%] + {"id-qualifier":"[% idqual %]","id":"[% idval %]"} + ], + "price":[% li.estimated_unit_price || '0.00' %], + "desc":[ + {"BTI":"[% helpers.get_li_attr_jedi('title', '', li.attributes) || (VENDOR_MLS ? ' ' : '') %]"}, + {"BPU":"[% helpers.get_li_attr_jedi('publisher', '', li.attributes) || (VENDOR_MLS ? ' ' : '') %]"}, + {"BPD":"[% helpers.get_li_attr_jedi('pubdate', '', li.attributes) || (VENDOR_MLS ? ' ' : '') %]"}, + [% IF VENDOR_ULS OR VENDOR_MLS -%] + {"BEN":"[% helpers.get_li_attr_jedi('edition', '', li.attributes) || (VENDOR_MLS ? ' ' : '') %]"}, + {"BAU":"[% helpers.get_li_attr_jedi('author', '', li.attributes) || (VENDOR_MLS ? ' ' : '') %]"} + [%- ELSE -%] + {"BPH":"[% helpers.get_li_attr_jedi('pagination','', li.attributes) || (VENDOR_MLS ? ' ' : '') %]"} + [%- END %] + ], + [%- ftx_vals = []; + FOR note IN li.lineitem_notes; + NEXT UNLESS note.vendor_public == 't'; + ftx_vals.push(note.value); + END; + IF VENDOR_BRODART; # look for copy-level spec code + FOR lid IN li.lineitem_details; + IF lid.note; + spec_note = lid.note.match('spec code ([a-zA-Z0-9_])'); + IF spec_note.0; ftx_vals.push(spec_note.0); END; + END; + END; + END; + IF xtra_ftx; ftx_vals.unshift(xtra_ftx); END; + + # BT & ULS want FTX+LIN for every LI, even if empty + IF ((VENDOR_BT OR VENDOR_ULS) AND ftx_vals.size == 0); + ftx_vals.unshift(''); + END; + -%] + + "free-text":[ + [% FOR note IN ftx_vals -%] "[% note %]"[% UNLESS loop.last %], [% END %][% END %] + ], + + "quantity":[% li.lineitem_details.size %], + + [%- IF INC_COPIES -%] + "copies" : [ + [%- compressed_copies = []; + FOR lid IN li.lineitem_details; + fund = lid.fund.code; + item_type = lid.circ_modifier; + callnumber = lid.cn_label; + owning_lib = lid.owning_lib.shortname; + location = lid.location; + collection_code = lid.collection_code; + + # when we have real copy data, treat it as authoritative for some fields + acp = lid.eg_copy_id; + IF acp; + item_type = acp.circ_modifier; + callnumber = acp.call_number.label; + location = acp.location.name; + END ; + + + # collapse like copies into groups w/ quantity + + found_match = 0; + IF !INC_COPY_ID; # INC_COPY_ID implies 1 copy per GIR + FOR copy IN compressed_copies; + IF (fund == copy.fund OR (!fund AND !copy.fund)) AND + (item_type == copy.item_type OR (!item_type AND !copy.item_type)) AND + (callnumber == copy.callnumber OR (!callnumber AND !copy.callnumber)) AND + (owning_lib == copy.owning_lib OR (!owning_lib AND !copy.owning_lib)) AND + (location == copy.location OR (!location AND !copy.location)) AND + (collection_code == copy.collection_code OR (!collection_code AND !copy.collection_code)); + + copy.quantity = copy.quantity + 1; + found_match = 1; + END; + END; + END; + + IF !found_match; + compressed_copies.push({ + fund => fund, + item_type => item_type, + callnumber => callnumber, + owning_lib => owning_lib, + location => location, + collection_code => collection_code, + copy_id => lid.id, # for INC_COPY_ID + quantity => 1 + }); + END; + END; + FOR copy IN compressed_copies; + + # If we assume owning_lib is required and set, + # it is safe to prepend each following copy field w/ a "," + + # B&T EDI requires expected GIR fields to be + # present regardless of whether a value exists. + # some fields are required to have a value in ACQ, + # though, so they are not forced into place below. + + %]{[%- IF INC_OWNING_LIB AND copy.owning_lib %] "owning_lib":"[% copy.owning_lib %]"[% END -%] + [%- IF INC_FUND AND copy.fund %],"fund":"[% copy.fund %]"[% END -%] + [%- IF INC_CALLNUMBER AND (VENDOR_BT OR copy.callnumber) %],"call_number":"[% copy.callnumber %]"[% END -%] + [%- IF INC_ITEM_TYPE AND (VENDOR_BT OR copy.item_type) %],"item_type":"[% copy.item_type %]"[% END -%] + [%- IF INC_LOCATION AND copy.location %],"copy_location":"[% copy.location %]"[% END -%] + [%- IF INC_COLLECTION_CODE AND (VENDOR_BT OR copy.collection_code) %],"collection_code":"[% copy.collection_code %]"[% END -%] + [%- IF INC_QUANTITY %],"quantity":"[% copy.quantity %]"[% END -%] + [%- IF INC_COPY_ID %],"copy_id":"[% copy.copy_id %]" [% END %]}[% ',' UNLESS loop.last -%] + [%- END -%] [%# FOR compressed_copies -%] + ] + [%- END -%] [%# IF INC_COPIES %] + + }[% UNLESS loop.last %],[% END -%] + + [% END %] [%# END lineitems %] + ], + "line_items":[% target.lineitems.size %] + }] [%# close ORDERS array %] + }] [%# close body array %] +} +[% END %] +[% tempo = PROCESS big_block; helpers.escape_json(tempo) %] +$$ WHERE id = 23; + +COMMIT; diff --git a/KCLS/sql/schema/revert/ingram-edi-mods.sql b/KCLS/sql/schema/revert/ingram-edi-mods.sql new file mode 100644 index 0000000000..78c8f3e5f3 --- /dev/null +++ b/KCLS/sql/schema/revert/ingram-edi-mods.sql @@ -0,0 +1,271 @@ +-- Revert kcls-evergreen:ingram-edi-mods from pg + +BEGIN; + +UPDATE acq.edi_account +SET vendcode = vendacct, vendacct = vendcode +WHERE host='ftp://ftp1.ingrambook.com'; + +UPDATE action_trigger.event_definition SET template = +$$ +[%- USE date -%] +[% + # extract some commonly used variables + + VENDOR_SAN = target.provider.san; + VENDCODE = target.provider.edi_default.vendcode; + VENDACCT = target.provider.edi_default.vendacct; + ORG_UNIT_SAN = target.ordering_agency.mailing_address.san; + + # set the vendor / provider + + VENDOR_BT = 0; # Baker & Taylor + VENDOR_INGRAM = 0; + VENDOR_BRODART = 0; + VENDOR_MW_TAPE = 0; # Midwest Tape + VENDOR_RB = 0; # Recorded Books + VENDOR_ULS = 0; # ULS + VENDOR_MLS = 0; # MLS + + IF VENDOR_SAN == '1556150'; VENDOR_BT = 1; + ELSIF VENDOR_SAN == '1697684'; VENDOR_BRODART = 1; + ELSIF VENDOR_SAN == '1697978'; VENDOR_INGRAM = 1; + ELSIF VENDOR_SAN == '2549913'; VENDOR_MW_TAPE = 1; + ELSIF VENDOR_SAN == '1113984'; VENDOR_RB = 1; + ELSIF VENDOR_SAN == '1699342'; VENDOR_ULS = 1; + ELSIF VENDOR_SAN == '1694243'; VENDOR_MLS = 1; + END; + + # if true, pass the PO name as a secondary identifier + # RFF+LI:/li_id + INC_PO_NAME = 0; + IF VENDOR_INGRAM; + INC_PO_NAME = 1; + END; + + # GIR configuration -------------------------------------- + + INC_COPIES = 1; # copies on/off switch + INC_FUND = 0; + INC_CALLNUMBER = 0; + INC_ITEM_TYPE = 1; + INC_LOCATION = 0; + INC_COLLECTION_CODE = 1; + INC_OWNING_LIB = 1; + INC_QUANTITY = 1; + INC_COPY_ID = 0; + + IF VENDOR_BT; + INC_CALLNUMBER = 1; + ORG_UNIT_SAN = '3176061'; + END; + + IF VENDOR_BRODART; + INC_FUND = 1; + ORG_UNIT_SAN = '3176061'; + VENDACCT = VENDCODE; + END; + + IF VENDOR_MW_TAPE; + INC_FUND = 1; + INC_COLLECTION_CODE = 0; + INC_ITEM_TYPE = 0; + END; + IF VENDOR_INGRAM; + VENDACCT = VENDCODE; + ORG_UNIT_SAN = '317606Z'; + END; + + # END GIR configuration --------------------------------- + +-%] +[%- BLOCK big_block -%] +{ + "recipient":"[% VENDOR_SAN %]", + "sender":"[% ORG_UNIT_SAN %]", + "body": [{ + "ORDERS":[ "order", { + + "po_number":[% target.id %], + + [% IF INC_PO_NAME %] + "po_name":"[% target.name | replace('\/', ' ') | replace('"', '\"') %]", + [% END %] + + "date":"[% date.format(date.now, '%Y%m%d') %]", + + "buyer":[ + [% IF VENDOR_BT %] + {"id-qualifier": 91, "id":"[% ORG_UNIT_SAN %] [% VENDCODE %]"} + [% ELSE %] + {"id":"[% ORG_UNIT_SAN %]"}, + {"id-qualifier": 91, "id":"[% VENDACCT %]"} + [% END %] + ], + + "vendor":[ + "[% VENDOR_SAN %]", + {"id-qualifier": 92, "id":"[% target.provider.id %]"} + ], + + "currency":"[% target.provider.currency_type %]", + + "items":[ + [%- FOR li IN target.lineitems %] + { + "line_index":"[% li.id %]", + [% IF (VENDOR_BT) %] + "line_number":"[% li.id %]", + [% END %] + "identifiers":[ + [%- + idval = ''; + vendnum = ''; + 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 = li.id; + END -%] + [%- + IF (VENDOR_BT) && helpers.get_li_attr('vendor_num', '', li.attributes); # USE 938 vendor number if it exists + idval = helpers.get_li_attr('vendor_num', '', li.attributes); + idqual = 'EN'; + END -%] + {"id-qualifier":"[% idqual %]","id":"[% idval %]"} + ], + "price":[% li.estimated_unit_price || '0.00' %], + "desc":[ + {"BTI":"[% helpers.get_li_attr_jedi('title', '', li.attributes) || (VENDOR_MLS ? ' ' : '') %]"}, + {"BPU":"[% helpers.get_li_attr_jedi('publisher', '', li.attributes) || (VENDOR_MLS ? ' ' : '') %]"}, + {"BPD":"[% helpers.get_li_attr_jedi('pubdate', '', li.attributes) || (VENDOR_MLS ? ' ' : '') %]"}, + [% IF VENDOR_ULS OR VENDOR_MLS -%] + {"BEN":"[% helpers.get_li_attr_jedi('edition', '', li.attributes) || (VENDOR_MLS ? ' ' : '') %]"}, + {"BAU":"[% helpers.get_li_attr_jedi('author', '', li.attributes) || (VENDOR_MLS ? ' ' : '') %]"} + [%- ELSE -%] + {"BPH":"[% helpers.get_li_attr_jedi('pagination','', li.attributes) || (VENDOR_MLS ? ' ' : '') %]"} + [%- END %] + ], + [%- ftx_vals = []; + FOR note IN li.lineitem_notes; + NEXT UNLESS note.vendor_public == 't'; + ftx_vals.push(note.value); + END; + IF VENDOR_BRODART; # look for copy-level spec code + FOR lid IN li.lineitem_details; + IF lid.note; + spec_note = lid.note.match('spec code ([a-zA-Z0-9_])'); + IF spec_note.0; ftx_vals.push(spec_note.0); END; + END; + END; + END; + IF xtra_ftx; ftx_vals.unshift(xtra_ftx); END; + + # BT & ULS want FTX+LIN for every LI, even if empty + IF ((VENDOR_BT OR VENDOR_ULS) AND ftx_vals.size == 0); + ftx_vals.unshift(''); + END; + -%] + + "free-text":[ + [% FOR note IN ftx_vals -%] "[% note %]"[% UNLESS loop.last %], [% END %][% END %] + ], + + "quantity":[% li.lineitem_details.size %], + + [%- IF INC_COPIES -%] + "copies" : [ + [%- compressed_copies = []; + FOR lid IN li.lineitem_details; + fund = lid.fund.code; + item_type = lid.circ_modifier; + callnumber = lid.cn_label; + owning_lib = lid.owning_lib.shortname; + location = lid.location; + collection_code = lid.collection_code; + + # when we have real copy data, treat it as authoritative for some fields + acp = lid.eg_copy_id; + IF acp; + item_type = acp.circ_modifier; + callnumber = acp.call_number.label; + location = acp.location.name; + END ; + + + # collapse like copies into groups w/ quantity + + found_match = 0; + IF !INC_COPY_ID; # INC_COPY_ID implies 1 copy per GIR + FOR copy IN compressed_copies; + IF (fund == copy.fund OR (!fund AND !copy.fund)) AND + (item_type == copy.item_type OR (!item_type AND !copy.item_type)) AND + (callnumber == copy.callnumber OR (!callnumber AND !copy.callnumber)) AND + (owning_lib == copy.owning_lib OR (!owning_lib AND !copy.owning_lib)) AND + (location == copy.location OR (!location AND !copy.location)) AND + (collection_code == copy.collection_code OR (!collection_code AND !copy.collection_code)); + + copy.quantity = copy.quantity + 1; + found_match = 1; + END; + END; + END; + + IF !found_match; + compressed_copies.push({ + fund => fund, + item_type => item_type, + callnumber => callnumber, + owning_lib => owning_lib, + location => location, + collection_code => collection_code, + copy_id => lid.id, # for INC_COPY_ID + quantity => 1 + }); + END; + END; + FOR copy IN compressed_copies; + + # If we assume owning_lib is required and set, + # it is safe to prepend each following copy field w/ a "," + + # B&T EDI requires expected GIR fields to be + # present regardless of whether a value exists. + # some fields are required to have a value in ACQ, + # though, so they are not forced into place below. + + %]{[%- IF INC_OWNING_LIB AND copy.owning_lib %] "owning_lib":"[% copy.owning_lib %]"[% END -%] + [%- IF INC_FUND AND copy.fund %],"fund":"[% copy.fund %]"[% END -%] + [%- IF INC_CALLNUMBER AND (VENDOR_BT OR copy.callnumber) %],"call_number":"[% copy.callnumber %]"[% END -%] + [%- IF INC_ITEM_TYPE AND (VENDOR_BT OR copy.item_type) %],"item_type":"[% copy.item_type %]"[% END -%] + [%- IF INC_LOCATION AND copy.location %],"copy_location":"[% copy.location %]"[% END -%] + [%- IF INC_COLLECTION_CODE AND (VENDOR_BT OR copy.collection_code) %],"collection_code":"[% copy.collection_code %]"[% END -%] + [%- IF INC_QUANTITY %],"quantity":"[% copy.quantity %]"[% END -%] + [%- IF INC_COPY_ID %],"copy_id":"[% copy.copy_id %]" [% END %]}[% ',' UNLESS loop.last -%] + [%- END -%] [%# FOR compressed_copies -%] + ] + [%- END -%] [%# IF INC_COPIES %] + + }[% UNLESS loop.last %],[% END -%] + + [% END %] [%# END lineitems %] + ], + "line_items":[% target.lineitems.size %] + }] [%# close ORDERS array %] + }] [%# close body array %] +} +[% END %] +[% tempo = PROCESS big_block; helpers.escape_json(tempo) %] +$$ WHERE id = 23; + + + +COMMIT; diff --git a/KCLS/sql/schema/sqitch.plan b/KCLS/sql/schema/sqitch.plan index b8d5badc52..bb735d5d13 100644 --- a/KCLS/sql/schema/sqitch.plan +++ b/KCLS/sql/schema/sqitch.plan @@ -21,3 +21,4 @@ subject-browse-entry-dashes [2.5-to-2.7-upgrade] 2016-02-11T20:12:05Z Bill Erick 2.7-auth-reingest [2.5-to-2.7-upgrade] 2015-12-30T16:25:38Z Bill Erickson # Reingest authority records after 2.7 update patron-self-reg-mods [blanket-po-print-template] 2016-01-13T20:14:00Z Bill Erickson # Patron self-reg customizations sip-activity-types [2.7-auth-reingest] 2016-03-15T21:30:39Z Bill Erickson # User activity types for hoopla/lynda SIP auth +ingram-edi-mods [sip-activity-types] 2016-05-24T16:31:46Z Bill Erickson # Ingram EDI config updates diff --git a/KCLS/sql/schema/verify/ingram-edi-mods.sql b/KCLS/sql/schema/verify/ingram-edi-mods.sql new file mode 100644 index 0000000000..d6c523cf6d --- /dev/null +++ b/KCLS/sql/schema/verify/ingram-edi-mods.sql @@ -0,0 +1,7 @@ +-- Verify kcls-evergreen:ingram-edi-mods on pg + +BEGIN; + +-- XXX Add verifications here. + +ROLLBACK;