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+)'
);
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 = (
sub read_file {
my $self = shift;
my $file = shift;
- my @msgs;
open(EDI_FILE, $file) or die "Cannot open $file: $!\n";
my $edi = join('', <EDI_FILE>);
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)) {
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