ACQ repair reverse exchange rate in fund transfer
authorBill Erickson <berick@esilibrary.com>
Mon, 23 Jul 2012 22:01:50 +0000 (18:01 -0400)
committerMike Rylander <mrylander@gmail.com>
Tue, 24 Jul 2012 14:22:06 +0000 (10:22 -0400)
Updated fund transfer code to use the DB exchange rate stored procedure.
In addition to code consolidation, this allows the fund trasnfer
operation to work if an exchange rate for the two currencies involved is
only defined in one direction.  The existing code required that the rate
be defined in both directions in the database or it would produce an
error in the logs and no visible error in the interface.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm

index 57eb88c..3fff0c3 100644 (file)
@@ -415,23 +415,23 @@ sub transfer_money_between_funds {
     return $e->die_event unless $e->allowed(['ADMIN_FUND','MANAGE_FUND'], $dfund->org, $dfund);
 
     if (!defined $dfund_amount) {
-        my $ratio = 1;
+
         if ($ofund->currency_type ne $dfund->currency_type) {
-            my $exchange_rate = $e->json_query({
-                "select"=>{"acqexr"=>["ratio"]}, 
-                "from"=>"acqexr", 
-                "where"=>{
-                    "from_currency"=>$ofund->currency_type,
-                    "to_currency"=>$dfund->currency_type
-                }
-            });
-            if (scalar(@$exchange_rate)<1) {
-                $logger->error('Unable to find exchange rate for ' . $ofund->currency_type . ' to ' . $dfund->currency_type);
-                return $e->die_event;
-            }
-            $ratio = @{$exchange_rate}[0]->{ratio};
+
+            $dfund_amount = $e->json_query({
+                from => [
+                    'acq.exchange_ratio',
+                    $ofund->currency_type,
+                    $dfund->currency_type,
+                    $ofund_amount
+                ]
+            })->[0]->{'acq.exchange_ratio'};
+
+        } else {
+
+            $dfund_amount = $ofund_amount;
         }
-        $dfund_amount = $ofund_amount * $ratio;
+
     } else {
         return $e->die_event unless $e->allowed("ACQ_XFER_MANUAL_DFUND_AMOUNT");
     }