invoice regex repairs
authorBill Erickson <berick@esilibrary.com>
Fri, 28 Sep 2012 15:32:28 +0000 (11:32 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 28 Sep 2012 15:32:28 +0000 (11:32 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/support-scripts/test-scripts/edi_parser.pl

index 9639cc6..82b4bcc 100644 (file)
@@ -16,12 +16,12 @@ my $PO_NUM_RE           = '^RFF\+ON:(\S+)';
 my $BUYER_SAN_RE        = '^NAD\+BY\+([^:]+).*';
 my $VENDOR_SAN_RE       = '^NAD\+SU\+([^:]+).*';
 my $LIN_INDEX_RE        = '^LIN\+([^\+]+).*';    
-my $LIN_IDENT_RE        = '^LIN\+\S+\++(.*)'; # e.g. ISBN
-my $LIN_QUANTITY_RE     = '^QTY\+47:(\d+)';
+my $LIN_IDENT_RE        = '^LIN\+\S+\++([^:]+).*'; # e.g. ISBN
+my $LIN_QUANTITY_RE     = '^QTY\+47:(\d+).*';
 my $LIN_AMOUNT_RE       = '^MOA\+203:(\d+)';
 my $LIN_ID_RE           = '^RFF\+LI:\S+\/(\S+)';
 my $TOTAL_BILLED_RE     = '^MOA\+86:(\d+)';
-my $MISC_CHARGE_TYPE_RE = '^ALC\+C\++(\S+)';
+my $MISC_CHARGE_TYPE_RE = '^ALC\+C\++([^\+]+).*';
 my $MISC_CHARGE_AMT_RE  = '^MOA\+(8|131):(\d+)';
 
 my @msgs;
@@ -29,7 +29,7 @@ my @msgs;
 foreach (split(/'/, $edi)) {
     my $msg = $msgs[-1];
 
-    if ($_ =~ /^UNH/) { # header.  start a new message.
+    if ($_ =~ /^UNH/) { # starting a new message.
 
         $msg = {lineitems => [], misc_charges => []};
         ($msg->{msg_type} = $_) =~ s/$MSG_TYPE_RE/$1/;
@@ -37,19 +37,19 @@ foreach (split(/'/, $edi)) {
         push(@msgs, $msg);
     }
 
+    ($msg->{buyer_san} = $_) =~ s/$BUYER_SAN_RE/$1/g if /$BUYER_SAN_RE/;
+    ($msg->{vendor_san} = $_) =~ s/$VENDOR_SAN_RE/$1/g if /$VENDOR_SAN_RE/;
+
     if ($msg and $msg->{msg_type} eq 'INVOIC') {
 
         ($msg->{inv_ident} = $_) =~ s/$INV_IDENT_RE/$1/g if /$INV_IDENT_RE/;
         ($msg->{po_number} = $_) =~ s/$PO_NUM_RE/$1/g if /$PO_NUM_RE/;
-        ($msg->{buyer_san} = $_) =~ s/$BUYER_SAN_RE/$1/g if /$BUYER_SAN_RE/;
-        ($msg->{vendor_san} = $_) =~ s/$VENDOR_SAN_RE/$1/g if /$VENDOR_SAN_RE/;
 
-        if ($_ =~ /^LIN\+/) {
-            # starting a new lineitem
+        if ($_ =~ /^LIN\+/) { # starting a new lineitem
 
             $msg->{_current_li} = {};
             ($msg->{_current_li}->{index} = $_) =~ s/$LIN_INDEX_RE/$1/g;
-            ($msg->{_current_li}->{ident} = $_) =~ s/$LIN_IDENT_RE/$1/g;
+            ($msg->{_current_li}->{ident} = $_) =~ s/$LIN_IDENT_RE/$1/g if /$LIN_IDENT_RE/;
 
             push(@{$msg->{lineitems}}, $msg->{_current_li});
         }