[open-ils-commits] r15482 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Feb 9 12:21:09 EST 2010
Author: erickson
Date: 2010-02-09 12:21:06 -0500 (Tue, 09 Feb 2010)
New Revision: 15482
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
Log:
consolidate inactive provider test in the po create code. added support for preventing fund debit creation when a fund has or is about to exceed the balance stop percent (if defined)
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm 2010-02-09 14:50:23 UTC (rev 15481)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm 2010-02-09 17:21:06 UTC (rev 15482)
@@ -587,6 +587,29 @@
# ----------------------------------------------------------------------------
sub create_fund_debit {
my($mgr, %args) = @_;
+
+ # Verify the fund is not being spent beyond the hard stop amount
+ my $fund = $mgr->editor->retrieve_acq_fund($args{fund}) or return 0;
+
+ if($fund->balance_stop_percent) {
+
+ my $balance = $mgr->editor->search_acq_fund_combined_balance({fund => $fund->id})->[0];
+ my $allocations = $mgr->editor->search_acq_fund_allocation_total({fund => $fund->id})->[0];
+ $balance = ($balance) ? $balance->amount : 0;
+ $allocations = ($allocations) ? $allocations->amount : 0;
+
+ if(
+ $allocations == 0 || # if no allocations were ever made, assume we have hit the stop percent
+ ( ( ( ($balance - $args{amount}) / $allocations ) * 100 ) < $fund->balance_stop_percent))
+ {
+ $mgr->editor->event(OpenILS::Event->new(
+ 'FUND_EXCEEDS_STOP_PERCENT',
+ payload => {fund => $fund->id, debit_amount => $args{amount}}
+ ));
+ return 0;
+ }
+ }
+
my $debit = Fieldmapper::acq::fund_debit->new;
$debit->debit_type('purchase');
$debit->encumbrance('t');
@@ -678,6 +701,15 @@
sub create_purchase_order {
my($mgr, %args) = @_;
+
+ # verify the chosen provider is still active
+ my $provider = $mgr->editor->retrieve_acq_provider($args{provider}) or return 0;
+ unless($U->is_true($provider->active)) {
+ $logger->error("provider is not active. cannot create PO");
+ $mgr->editor->event(OpenILS::Event->new('ACQ_PROVIDER_INACTIVE'));
+ return 0;
+ }
+
my $po = Fieldmapper::acq::purchase_order->new;
$po->creator($mgr->editor->requestor->id);
$po->editor($mgr->editor->requestor->id);
@@ -979,13 +1011,6 @@
if($create_po) {
- # verify the provider is still active
- unless($U->is_true($provider->active)) {
- $logger->error("provider is not active. cannot create PO");
- $e->rollback;
- return OpenILS::Event->new('ACQ_PROVIDER_INACTIVE');
- }
-
$po = create_purchase_order($mgr,
ordering_agency => $ordering_agency,
provider => $provider->id,
@@ -1298,14 +1323,6 @@
return $e->die_event unless $e->allowed('CREATE_PURCHASE_ORDER', $po->ordering_agency);
my $mgr = OpenILS::Application::Acq::BatchManager->new(editor => $e, conn => $conn);
- # verify the provider is still active
- my $provider = $e->retrieve_acq_provider($po->provider) or return $e->die_event;
- unless($U->is_true($provider->active)) {
- $logger->error("provider is not active. cannot create PO");
- $e->rollback;
- return OpenILS::Event->new('ACQ_PROVIDER_INACTIVE');
- }
-
# create the PO
my %pargs = (ordering_agency => $e->requestor->ws_ou); # default
$pargs{provider} = $po->provider if $po->provider;
More information about the open-ils-commits
mailing list