[open-ils-commits] r8366 - branches/acq-experiment/Open-ILS/src/perlmods/OpenILS/Application/Acq

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Jan 9 11:41:54 EST 2008


Author: erickson
Date: 2008-01-09 11:17:20 -0500 (Wed, 09 Jan 2008)
New Revision: 8366

Modified:
   branches/acq-experiment/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm
Log:
added budget CRUD

Modified: branches/acq-experiment/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm
===================================================================
--- branches/acq-experiment/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm	2008-01-09 15:45:28 UTC (rev 8365)
+++ branches/acq-experiment/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm	2008-01-09 16:17:20 UTC (rev 8366)
@@ -13,6 +13,28 @@
 
 my $BAD_PARAMS = OpenILS::Event->new('BAD_PARAMS');
 
+# ---------------------------------------------------------------
+# Returns a list containing the current org id plus the IDs of 
+# any descendents
+# ---------------------------------------------------------------
+sub org_descendants {
+    my($e, $org_id) = @_;
+
+    my $org = $e->retrieve_actor_org_unit(
+        [$org_id, {flesh=>1, flesh_fields=>{aou=>['ou_type']}}]) or return $e->event;
+
+    my $org_list = $U->simplereq(
+        'open-ils.storage',
+        'open-ils.storage.actor.org_unit.descendants.atomic',
+        $org_id, $org->ou_type->depth);
+
+    my $org_ids = [];
+    push(@$org_ids, $_->id) for @$org_list;
+    return $org_ids;
+}
+
+
+
 __PACKAGE__->register_method(
 	method => 'create_fund',
 	api_name	=> 'open-ils.acq.fund.create',
@@ -33,7 +55,29 @@
     return $fund->id;
 }
 
+
 __PACKAGE__->register_method(
+	method => 'delete_fund',
+	api_name	=> 'open-ils.acq.fund.delete',
+	signature => q/
+        Creates a new fund
+		@param auth Authentication token
+		@param fund
+	/
+);
+
+sub delete_fund {
+    my($self, $conn, $auth, $fund_id) = @_;
+    my $e = new_editor(xact=>1, authtoken=>$auth);
+    return $e->die_event unless $e->checkauth;
+    my $fund = $e->retrieve_acq_fund($fund_id) or return $e->die_event;
+    return $e->die_event unless $e->allowed('DELETE_FUND', $fund->owner);
+    $e->delete_acq_fund($fund) or return $e->die_event;
+    $e->commit;
+    return 1;
+}
+
+__PACKAGE__->register_method(
 	method => 'retrieve_fund',
 	api_name	=> 'open-ils.acq.fund.retrieve',
 	signature => q/
@@ -72,24 +116,102 @@
     return $e->event unless $e->allowed('VIEW_FUND', $org_id);
 
     my $search = {owner => $org_id};
+    $search = {owner => org_descendents($e, $org_id)} if $$options{children};
+    my $funds = $e->search_acq_fund($search) or return $e->event;
 
-    if($$options{children}) {
-        # grab the descendent orgs
-        my $org = $e->retrieve_actor_org_unit(
-            [$org_id, {flesh=>1, flesh_fields=>{aou=>['ou_type']}}]) or return $e->event;
-        my $org_list = $U->simplereq(
-            'open-ils.storage',
-            'open-ils.storage.actor.org_unit.descendants.atomic',
-            $org_id, $org->ou_type->depth);
+    return $funds; 
+}
 
-        my $org_ids = [];
-        push(@$org_ids, $_->id) for @$org_list;
-        $search = {owner => $org_ids};
-    }
+# ---------------------------------------------------------------
+# Budgets
+# ---------------------------------------------------------------
 
-    my $funds = $e->search_acq_fund($search) or return $e->event;
-    return $funds; 
+__PACKAGE__->register_method(
+	method => 'create_budget',
+	api_name	=> 'open-ils.acq.budget.create',
+	signature => q/
+        Creates a new budget
+		@param auth Authentication token
+		@param budget
+	/
+);
+
+sub create_budget {
+    my($self, $conn, $auth, $budget) = @_;
+    my $e = new_editor(xact=>1, authtoken=>$auth);
+    return $e->die_event unless $e->checkauth;
+    return $e->die_event unless $e->allowed('CREATE_BUDGET', $budget->org);
+    $e->create_acq_budget($budget) or return $e->die_event;
+    $e->commit;
+    return $budget->id;
 }
 
 
+__PACKAGE__->register_method(
+	method => 'delete_budget',
+	api_name	=> 'open-ils.acq.budget.delete',
+	signature => q/
+        Creates a new budget
+		@param auth Authentication token
+		@param budget
+	/
+);
+
+sub delete_budget {
+    my($self, $conn, $auth, $budget_id) = @_;
+    my $e = new_editor(xact=>1, authtoken=>$auth);
+    return $e->die_event unless $e->checkauth;
+    my $budget = $e->retrieve_acq_budget($budget_id) or return $e->die_event;
+    return $e->die_event unless $e->allowed('DELETE_BUDGET', $budget->org);
+    $e->delete_acq_budget($budget) or return $e->die_event;
+    $e->commit;
+    return 1;
+}
+
+__PACKAGE__->register_method(
+	method => 'retrieve_budget',
+	api_name	=> 'open-ils.acq.budget.retrieve',
+	signature => q/
+        Retrieves a budget by ID
+		@param auth Authentication token
+		@param budget_id
+	/
+);
+
+sub retrieve_budget {
+    my($self, $conn, $auth, $budget_id) = @_;
+    my $e = new_editor(authtoken=>$auth);
+    return $e->event unless $e->checkauth;
+    my $budget = $e->retrieve_acq_budget($budget_id) or return $e->event;
+    return $e->event unless $e->allowed('VIEW_BUDGET', $budget->org);
+    return $budget;
+}
+
+__PACKAGE__->register_method(
+	method => 'retrieve_org_budgets',
+	api_name	=> 'open-ils.acq.budget.org.retrieve',
+	signature => q/
+        Retrieves all the budgets associated with an org unit
+		@param auth Authentication token
+		@param org_id
+        @param options Hash of options.  Options include "children", 
+            which includes the budgets for the requested org and
+            all descendant orgs.
+	/
+);
+
+sub retrieve_org_budgets {
+    my($self, $conn, $auth, $org_id, $options) = @_;
+    my $e = new_editor(authtoken=>$auth);
+    return $e->event unless $e->checkauth;
+    return $e->event unless $e->allowed('VIEW_BUDGET', $org_id);
+
+    my $search = {org => $org_id};
+    $search = {org => org_descendents($e, $org_id)} if $$options{children};
+    my $budgets = $e->search_acq_budget($search) or return $e->event;
+
+    return $budgets; 
+}
+
+
 1;



More information about the open-ils-commits mailing list