From 2e90450af9da38302475ec9df595851e420d9986 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 8 Jun 2006 19:28:56 +0000 Subject: [PATCH] more circ events, patched up penalty and circ scripts git-svn-id: svn://svn.open-ils.org/ILS/trunk@4550 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/extras/ils_events.xml | 3 ++ .../backend/penalty/patron_penalty.js | 29 +++++++++++------- .../OpenILS/Application/Circ/Circulate.pm | 7 ++--- .../perlmods/OpenILS/Application/Penalty.pm | 30 ++++++++++++++----- 4 files changed, 48 insertions(+), 21 deletions(-) diff --git a/Open-ILS/src/extras/ils_events.xml b/Open-ILS/src/extras/ils_events.xml index 6ca17cf1ad..feecd30d4b 100644 --- a/Open-ILS/src/extras/ils_events.xml +++ b/Open-ILS/src/extras/ils_events.xml @@ -486,6 +486,9 @@ The attempt to write to the DB failed + + The attempt to query to the DB failed + Permission Denied diff --git a/Open-ILS/src/javascript/backend/penalty/patron_penalty.js b/Open-ILS/src/javascript/backend/penalty/patron_penalty.js index 9a6cf34ea0..3fa1a92aec 100644 --- a/Open-ILS/src/javascript/backend/penalty/patron_penalty.js +++ b/Open-ILS/src/javascript/backend/penalty/patron_penalty.js @@ -7,18 +7,17 @@ load_lib('../circ/circ_lib.js'); /* collect some useful variables */ var patron = environment.patron; var patronProfile = patron.profile.name.toLowerCase(); -var patronItemsOut = environment.patronItemsOut; var patronFines = environment.patronFines; var patronOverdueCount = environment.patronOverdueCount; -log_debug('circ_permit_patron: permit circ on ' + +log_debug('Patron penalty script: ' + ', Patron:' + patron.id + ', Patron Username:' + patron.usrname + ', Patron Profile: ' + patronProfile + - ', Patron copies: ' + patronItemsOut + ', Patron Library: ' + patron.home_ou.name + ', Patron fines: ' + patronFines + + ', Patron overdue: ' + patronOverdueCount + ''); @@ -34,6 +33,10 @@ var PROFILES = { class : { fineLimit : 10, overdueLimit : 10, + }, + 'local system administrator' : { + fineLimit : -1, + overdueLimit : -1, } /* Add profiles as necessary ... */ @@ -41,21 +44,27 @@ var PROFILES = { -/** Find the patron's profile and check the fine and overdue limits */ -log_info(patronProfile); - var profile = PROFILES[patronProfile]; + if( profile ) { - if( patronFines >= profile.fineLimit ) - result.events.push('PATRON_EXCEEDS_FINES'); - if( patronOverdueCount > profile.overdueLimit ) - result.events.puth('PATRON_EXCEEDS_OVERDUE_COUNT'); + + /* check the fine limit */ + if( profile.fineLimit > 0 && patronFines >= profile.fineLimit ) + result.fatalEvents.push('PATRON_EXCEEDS_FINES'); + + /* check the overdue limit */ + if( profile.overdueLimit > 0 && patronOverdueCount > profile.overdueLimit ) + result.fatalEvents.puth('PATRON_EXCEEDS_OVERDUE_COUNT'); + +} else { + log_warn("profile has no configured information: " + patronProfile); } + } go(); diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm index 93a723161f..0f050fd2ba 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm @@ -329,10 +329,9 @@ sub _build_circ_script_runner { $runner->insert('environment.isNonCat', undef); } -# if(ref($ctx->{patron_circ_summary})) { -# $runner->insert( 'environment.patronItemsOut', $ctx->{patron_circ_summary}->[0], 1 ); -# $runner->insert( 'environment.patronFines', $ctx->{patron_circ_summary}->[1], 1 ); -# } + if(ref($ctx->{patron_circ_summary})) { + $runner->insert( 'environment.patronItemsOut', $ctx->{patron_circ_summary}->[0], 1 ); + } $ctx->{runner} = $runner; return $runner; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Penalty.pm b/Open-ILS/src/perlmods/OpenILS/Application/Penalty.pm index b149220a23..e38dd4d514 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Penalty.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Penalty.pm @@ -10,6 +10,8 @@ use OpenSRF::Utils::SettingsClient; use OpenILS::Application::AppUtils; use OpenSRF::Utils::Logger qw(:logger); use base 'OpenSRF::Application'; +use OpenILS::Utils::Editor q/:funcs/; +use OpenILS::Application::Actor; my $U = "OpenILS::Application::AppUtils"; my $script; @@ -49,7 +51,8 @@ sub build_runner { my %args = @_; my $patron = $args{patron}; - my $patron_summary = $args{patron_summary}; + my $fines = $args{fines}; + my $circ_counts = $args{circ_counts}; my $pgroup = find_profile($patron); $patron->profile( $pgroup ); @@ -65,8 +68,8 @@ sub build_runner { $runner->insert( 'environment.patron', $patron, 1); $runner->insert( $fatal_key, [] ); $runner->insert( $info_key, [] ); - $runner->insert( 'environment.patronItemsOut', $patron_summary->[0] ); - $runner->insert( 'environment.patronFines', $patron_summary->[1] ); + $runner->insert( 'environment.patronOverdueCount', $circ_counts->{overdue}); + $runner->insert( 'environment.patronFines', $fines ); return $runner; } @@ -117,23 +120,36 @@ sub patron_penalty { my( $patron, $evt ); $conn->respond_complete(1) if $$args{background}; + + my $e = new_editor(xact => 1); if( $patron = $$args{patron} ) { # - unflesh if necessary $patron->home_ou( $patron->home_ou->id ) if ref($patron->home_ou); $patron->profile( $patron->profile->id ) if ref($patron->profile); } else { - ( $patron, $evt ) = $U->fetch_user($$args{patronid}); - return $evt if $evt; + $patron = $e->retrieve_actor_user($$args{patronid}) + or return $e->event; } # - fetch the circulation summary info for the user my $summary = $U->fetch_patron_circ_summary($patron->id); + # Note, that this ignores any negative balances + my $fxacts = $e->search_money_open_billable_transaction_summary( + { usr => $patron->id, balance_owed => { ">" => 0 } }); + my $fines = 0; + $fines += $_->balance_owed for @$fxacts; + + # - retrieve the number of open circulations the user has by type + # - we have to call this method directly because we don't have an auth session + my $circ_counts = OpenILS::Application::Actor::_checked_out(1, $e, $patron->id); + # - build the script runner my $runner = build_runner( - patron => $patron, - patron_summary => $summary + patron => $patron, + fines => $fines, + circ_counts => $circ_counts, ); # - Load up the script and run it -- 2.43.2