LP#1949243: tweak FTX and LIN in EDI messages user/jeffdavis/lp1949243-edi-ftx-lin
authorJeff Davis <jdavis@sitka.bclibraries.ca>
Fri, 29 Oct 2021 23:28:20 +0000 (16:28 -0700)
committerJeff Davis <jdavis@sitka.bclibraries.ca>
Fri, 29 Oct 2021 23:28:20 +0000 (16:28 -0700)
There are a couple of errors in EDIWriter's output:

1. The FTX line is missing a field. We produce FTX+LIN+1+First Nations
but should be producing FTX+LIN+1++First Nations (note the extra +
sign).

2. We are enumerating lineitems using the internal lineitem ID (e.g.
LIN+523964), but they should be enumerated sequentially starting at 1
(e.g. LIN+1).

This commit fixes both errors.

Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIWriter.pm

index b0349ee..38ceb80 100644 (file)
@@ -458,11 +458,14 @@ NAD+SU+$c{provider_id}::92'
 CUX+2:$c{currency_type}:9'
 EDI
 
-    # EDI lineitem segments
-    $edi .= $self->build_lineitem_segments($_) for @lis;
-
     my $li_count = scalar(@lis);
 
+    # EDI lineitem segments
+    for (my $i = 1; $i <= $li_count; $i++) {
+        $lis[$i]->{seq_id} = $i;
+        $edi .= $self->build_lineitem_segments($lis[$i]);
+    }
+
     # Count the number of segments in the EDI message by counting the
     # number of newlines.  Add to count for lines below, not including
     # the UNZ segment.
@@ -502,9 +505,10 @@ sub build_lineitem_segments {
     my $idqual = $li_hash->{idqual};
     my $quantity = $li_hash->{quantity};
     my $price = $li_hash->{estimated_unit_price};
+    my $seq_id = $li_hash->{seq_id};
 
     # Line item identifier segments
-    my $edi = "LIN+$id++$idval:$idqual'\n";
+    my $edi = "LIN+$seq_id++$idval:$idqual'\n";
     $edi .= "PIA+5+$idval:$idqual'\n";
 
     $edi .= $self->IMD('BTI', $li_hash->{title});
@@ -526,7 +530,7 @@ sub build_lineitem_segments {
 
     for my $note (@{$li_hash->{notes}}) {
         if ($note) {
-            $edi .= "FTX+LIN+1+$note'\n"
+            $edi .= "FTX+LIN+1++$note'\n"
         } else {
             $edi .= "FTX+LIN+1'\n"
         }