From: Bill Erickson Date: Mon, 12 Nov 2012 14:35:53 +0000 (-0500) Subject: EDIReader : detect SAN vs. account number in buyer/seller X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=7aeee191a3ce0ae2d291191cff5dbca3d769c8f9;p=contrib%2FConifer.git EDIReader : detect SAN vs. account number in buyer/seller NAD+BY+XXXXXXX::31B' -- SAN NAD+BY+YYYYYYY::91' -- Account number For invoices, try the SAN first followed by the account number to determine the receiving org unit. Signed-off-by: Bill Erickson Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm index 1fd06399d4..f41d29cd52 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm @@ -585,31 +585,46 @@ sub create_acq_invoice_from_edi { # distinguish provider and shipper? $eg_inv->recv_method("EDI"); - my $buyer_san = $invoice->{buyer_san}; - if (not $buyer_san) { - $logger->error($log_prefix . "could not find buyer SAN in INVOIC"); - return 0; - } + # some vendors encode the account number as the SAN. + # starting with the san value, then the account value, + # treat each as a san, then an acct number until the first success + for my $buyer ( ($invoice->{buyer_san}, $invoice->{buyer_acct}) ) { + next unless $buyer; - # some vendors encode the SAN as "$SAN $vendcode" - $buyer_san =~ s/\s.*//g; + # some vendors encode the SAN as "$SAN $vendcode" + $buyer =~ s/\s.*//g; - # Find the matching org unit based on SAN via 'aoa' table. - my $addrs = - $e->search_actor_org_address({valid => "t", san => $buyer_san}); + my $addr = $e->search_actor_org_address( + {valid => "t", san => $buyer})->[0]; - if (not $addrs or not @$addrs) { - $logger->error( - $log_prefix . "couldn't find OU unit matching buyer SAN in INVOIC:". - $e->event + if ($addr) { + + $eg_inv->receiver($addr->org_unit); + last; + + } else { + + my $acct = $e->search_acq_edi_account({vendacct => $buyer})->[0]; + + if ($acct) { + $eg_inv->receiver($acct->owner); + last; + } + } + } + + if (!$eg_inv->receiver) { + $logger->error($log_prefix . + sprintf("unable to determine buyer (org unit) in invoice; ". + "buyer_san=%s; buyer_acct=%s", + ($invoice->{buyer_san} || ''), + ($invoice->{buyer_acct} || '') + ) ); return 0; } - # XXX Should we verify that this matches PO ordering agency later? - $eg_inv->receiver($addrs->[0]->org_unit); - $eg_inv->inv_ident($invoice->{invoice_ident}); if (!$eg_inv->inv_ident) { diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm index 18d46ff88e..d3b5697545 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm @@ -20,8 +20,10 @@ my $NEW_LIN_RE = '^LIN'; # starts a new line item my %edi_fields = ( message_type => qr/^UNH\+\d+\+(\S{6})/, - buyer_san => qr/^NAD\+BY\+([^:]+)/, - vendor_san => qr/^NAD\+SU\+([^:]+)/, + buyer_san => qr/^NAD\+BY\+([^:]+)::31B/, + buyer_acct => qr/^NAD\+BY\+([^:]+)::91/, + vendor_san => qr/^NAD\+SU\+([^:]+)::31B/, + vendor_acct => qr/^NAD\+SU\+([^:]+)::91/, purchase_order => qr/^RFF\+ON:(\S+)/, invoice_ident => qr/^BGM\+380\+([^\+]+)/, total_billed => qr/^MOA\+86:(\d+)/