From: Bill Erickson Date: Mon, 23 Jul 2012 22:01:50 +0000 (-0400) Subject: ACQ repair reverse exchange rate in fund transfer X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=aff37795825b477a9b82560fe16ea4685202d201;p=evergreen%2Fpines.git ACQ repair reverse exchange rate in fund transfer 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 Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm index 57eb88cb63..3fff0c33ba 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Financials.pm @@ -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"); }