EDI invoice date; invoice paid quantity/amount
authorBill Erickson <berick@esilibrary.com>
Wed, 5 Dec 2012 14:34:00 +0000 (09:34 -0500)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 14 Jan 2013 22:10:31 +0000 (17:10 -0500)
* capture the invoice date in EDIReader
* apply the invoice date to inbound invoices when available instead of
  defaulting to 'now'
* apply the quantity/amount billed to the quantity/amount paid to reduce
  staff data entry needs

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm
Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm

index 09b6ce2..7a6b4f4 100644 (file)
@@ -449,13 +449,8 @@ sub process_parsed_msg {
             next;
         }
 
-        if ($li_hash->{expected_date}) {
-            my ($y, $m, $d) = $li_hash->{expected_date} =~ /^(\d{4})(\d{2})(\d{2})/g;
-            my $recv_time = $y;
-            $recv_time .= "-$m" if $m;
-            $recv_time .= "-$d" if $d;
-            $li->expected_recv_time($recv_time);
-        }
+         $li->expected_recv_time(
+            $class->edi_date_to_iso($li_hash->{expected_date}));
 
         $li->estimated_unit_price($li_hash->{unit_price});
 
@@ -681,6 +676,15 @@ sub cancel_lids {
     return ($cancel_count);
 }
 
+sub edi_date_to_iso {
+    my ($class, $date) = @_;
+    return undef unless $date and $date =~ /\d+/;
+    my ($iso, $m, $d) = $date =~ /^(\d{4})(\d{2})(\d{2})/g;
+    $iso .= "-$m" if $m;
+    $iso .= "-$d" if $d;
+    return $iso;
+}
+
 
 # create_acq_invoice_from_edi() does what it sounds like it does for INVOIC
 # messages.  For similar operation on ORDRSP messages, see the guts of
@@ -704,6 +708,9 @@ sub create_acq_invoice_from_edi {
                                     # distinguish provider and shipper?
     $eg_inv->recv_method("EDI");
 
+    $eg_inv->recv_date(
+        $class->edi_date_to_iso($invoice->{invoice_date}));
+
 
     # some vendors encode the account number as the SAN.
     # starting with the san value, then the account value, 
@@ -793,6 +800,9 @@ sub create_acq_invoice_from_edi {
         my $eg_inv_entry = Fieldmapper::acq::invoice_entry->new;
         $eg_inv_entry->inv_item_count($quantity);
 
+        # amount staff agree to pay for
+        $eg_inv_entry->phys_item_count($quantity);
+
         # XXX Validate by making sure the LI is on-order and belongs to
         # the right provider and ordering agency and all that.
         $eg_inv_entry->lineitem($li_id);
@@ -803,6 +813,9 @@ sub create_acq_invoice_from_edi {
         # This is the total price for all units billed, not per-unit.
         $eg_inv_entry->cost_billed($lineitem_price);
 
+        # amount staff agree to pay
+        $eg_inv_entry->amount_paid($lineitem_price);
+
         push @eg_inv_entries, $eg_inv_entry;
     }
 
index e6c872e..532af2d 100644 (file)
@@ -26,7 +26,8 @@ my %edi_fields = (
     vendor_acct     => qr/^NAD\+SU\+([^:]+)::91/,
     purchase_order  => qr/^RFF\+ON:(\S+)/,
     invoice_ident   => qr/^BGM\+380\+([^\+]+)/,
-    total_billed    => qr/^MOA\+86:(\d+)/
+    total_billed    => qr/^MOA\+86:(\d+)/,
+    invoice_date    => qr/^DTM\+137:([^:]+)/
 );
 
 my %edi_li_fields = (