From: Bill Erickson Date: Tue, 2 Oct 2012 21:10:42 +0000 (-0400) Subject: Capture EDI quantities and their codes X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=30835d9d1ef76974f70868605d9d0f6dda0d9f0e;p=evergreen%2Fequinox.git Capture EDI quantities and their codes Instead of listing all the quantity types by friendly name, capture the bare values and codes so the ML code can continue mapping quantity codes to cancel reason codes. Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm index 4c65996627..c8b58b0727 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm @@ -10,8 +10,8 @@ my %edi_fields = ( message_type => '^UNH\+\d+\+(\S{6}):.*', buyer_san => '^NAD\+BY\+([^:]+).*', vendor_san => '^NAD\+SU\+([^:]+).*', - po_number => '^RFF\+ON:(\S+)', - invoice_ident => '^BGM\+380\+(.*)\+.*', + purchase_order => '^RFF\+ON:(\S+)', + invoiceident2 => '^BGM\+380\+(.*)\+.*', total_billed => '^MOA\+86:(\d+)' ); @@ -19,14 +19,15 @@ my %edi_li_fields = ( id => '^RFF\+LI:\S+\/(\S+)', index => '^LIN\+([^\+]+).*', ident => '^LIN\+\S+\++([^:]+).*', - _ident => '^PIA\+0*5\+([^:]+).*', # ident may live in LIN or PIA - invoice_count => '^QTY\+47:(\d+).*', - order_count => '^QTY\+21:(\d+).*', - dispatch_count => '^QTY\+12:(\d+).*', - backorder_count => '^QTY\+83:(\d+).*', - delivered_count => '^QTY\+46:(\d+).*', + ident2 => '^PIA\+0*5\+([^:]+).*', amount_billed => '^MOA\+203:(\d+)', - unit_price => '^PRI\+AAB:(\d+).*' + unit_price => '^PRI\+AAB:(\d+).*', + expected_date => '^DTM\+44:([^:]+).*' +); + +my %edi_li_quant_fields = ( + quantity => '^QTY\+\d+:(\d+).*', + code => '^QTY\+(\d+):.*', ); my %edi_charge_fields = ( @@ -41,12 +42,21 @@ sub new { sub read_file { my $self = shift; my $file = shift; - my @msgs; open(EDI_FILE, $file) or die "Cannot open $file: $!\n"; my $edi = join('', ); close EDI_FILE; + return $self->read($edi); +} + +# reads an EDI string + +sub read { + my $self = shift; + my $edi = shift or return []; + my @msgs; + $edi =~ s/\n//g; foreach (split(/'/, $edi)) { @@ -84,9 +94,18 @@ sub read_file { if /$edi_li_fields{$field}/; } - # move ident value found at secondary location to 'ident' - $li->{ident} = delete $li->{_ident} - if $li->{_ident} and not $li->{ident}; + + # if no ident value is present, promote ident2 + $li->{ident} = delete $li->{ident2} + if $li->{ident2} and not $li->{ident}; + + if (/$edi_li_quant_fields{quantity}/) { + my $quant = {}; + ($quant->{quantity} = $_) =~ s/$edi_li_quant_fields{quantity}/$1/g; + ($quant->{code} = $_) =~ s/$edi_li_quant_fields{code}/$1/g; + push(@{$li->{quantities}}, $quant); + } + } # - starting a new misc. charge