[open-ils-commits] r15497 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq (phasefx)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Feb 10 16:38:49 EST 2010


Author: phasefx
Date: 2010-02-10 16:38:43 -0500 (Wed, 10 Feb 2010)
New Revision: 15497

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm
Log:
Method for transfering money between funds

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm	2010-02-10 20:47:44 UTC (rev 15496)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm	2010-02-10 21:38:43 UTC (rev 15497)
@@ -381,7 +381,66 @@
     };
 }
 
+__PACKAGE__->register_method(
+	method => 'transfer_money_between_funds',
+	api_name	=> 'open-ils.acq.funds.transfer_money',
+	signature => {
+        desc => 'Method for transfering money between funds',
+        params => [
+            {desc => 'Authentication token', type => 'string'},
+            {desc => 'Originating fund ID', type => 'number'},
+            {desc => 'Amount of money to transfer away from the originating fund, in the same currency as said fund', type => 'number'},
+            {desc => 'Destination fund ID', type => 'number'},
+            {desc => 'Amount of money to transfer to the destination fund, in the same currency as said fund.  If null, uses the same amount specified with the Originating Fund, and attempts a currency conversion if appropriate.', type => 'number'},
+            {desc => 'Transfer Note', type => 'string'}
+        ],
+        return => {desc => '1 on success, Event on failure'}
+    }
+);
 
+sub transfer_money_between_funds {
+    my($self, $conn, $auth, $ofund_id, $ofund_amount, $dfund_id, $dfund_amount, $note) = @_;
+    my $e = new_editor(xact=>1, authtoken=>$auth);
+    return $e->die_event unless $e->checkauth;
+    my $ofund = $e->retrieve_acq_fund($ofund_id) or return $e->event;
+    return $e->die_event unless $e->allowed(['ADMIN_FUND','MANAGE_FUND'], $ofund->org, $ofund);
+    my $dfund = $e->retrieve_acq_fund($dfund_id) or return $e->event;
+    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 = $ofund_amount * $ratio;
+    }
+
+    $e->json_query({
+        from => [
+            'acq.transfer_fund',
+            $ofund_id, $ofund_amount, $dfund_id, $dfund_amount, $e->requestor->id, $note
+        ]
+    });
+
+    $e->commit;
+
+    return 1;
+}
+
+
+
 # ---------------------------------------------------------------
 # fund Allocations
 # ---------------------------------------------------------------



More information about the open-ils-commits mailing list