Acq: EDI Invoices have fees defined in more places than we were looking collab/senator/acq-invoice-other-charges
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Fri, 28 Sep 2012 21:56:19 +0000 (17:56 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Fri, 28 Sep 2012 21:56:19 +0000 (17:56 -0400)
So look a little harder.

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

index 6e9ce69..01c41df 100644 (file)
@@ -809,6 +809,44 @@ sub create_acq_invoice_from_edi {
         # move on
     };
 
+    # Look here for surcharges and taxes as well.
+    try {
+        # XXX i18n?  How do we even?
+        my %usable_sg51_alc = (
+            'TX' => ['TAX', 'Tax from electronic invoice'],
+            'CA' => ['PRO', 'Possible cataloging services'], # for B&T, anyway
+            'DL' => ['SHP', 'Delivery']
+        );
+
+        if ($invoice->{SG51}) {
+            foreach my $sg51 (@{ $invoice->{SG51} }) {
+                if ($sg51->{ALC} and $sg51->{MOA}) {
+                    my $amount = $sg51->{MOA}[0]{C516}{5004};
+                    my $what = $sg51->{ALC}[0]{C214}{7161};
+
+                    my ($type, $note);
+                    if (not $usable_sg51_alc{$what}) {
+                        $type = 'PRO';   # We have to choose something.
+                        $note = "Unknown charge type '$what'";  # XXX i18n?
+                    } else {
+                        $type = $usable_sg51_alc{$what}->[0];
+                        $note = $usable_sg51_alc{$what}->[1];
+                    }
+
+                    my $eg_inv_item = Fieldmapper::acq::invoice_item->new;
+
+                    $eg_inv_item->inv_item_type($type);
+                    $eg_inv_item->note($note);
+                    $eg_inv_item->cost_billed($amount);
+
+                    push @eg_inv_items, $eg_inv_item;
+                }
+            }
+        }
+    } catch Error with {
+        # move on
+    };
+
     $e->xact_begin;
 
     # save changes to acq.edi_message row