From fe74f56d76fdc2bd12435e3e155ebfde08dec414 Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 12 Sep 2006 01:58:47 +0000 Subject: [PATCH] moved scriptbuilder to new storage method for fetching total owed by a patron only fetching total-owed on penaly calls, not circ calls (since circ gets that info from the penalty server) added new JS method to determine if two orgs share an ancestor at a given depth - added hold_permit logic using new method to allow holds of certain items within the region git-svn-id: svn://svn.open-ils.org/ILS/trunk@6069 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/javascript/backend/circ/circ_lib.js | 10 +++ .../backend/circ/circ_permit_hold.js | 15 ++-- .../perlmods/OpenILS/Application/AppUtils.pm | 17 +++++ .../OpenILS/Application/Circ/Circulate.pm | 37 +++++++--- .../OpenILS/Application/Circ/ScriptBuilder.pm | 69 +++++++++++++++---- .../perlmods/OpenILS/Application/Penalty.pm | 1 + 6 files changed, 123 insertions(+), 26 deletions(-) diff --git a/Open-ILS/src/javascript/backend/circ/circ_lib.js b/Open-ILS/src/javascript/backend/circ/circ_lib.js index 739675ba9b..886eb23d78 100644 --- a/Open-ILS/src/javascript/backend/circ/circ_lib.js +++ b/Open-ILS/src/javascript/backend/circ/circ_lib.js @@ -180,6 +180,16 @@ function isOrgDescendent( parentName, childId ) { return false; } +function hasCommonAncestor( org1, org2, depth ) { + var key = scratchKey(); + __OILS_FUNC_hasCommonAncestor(scratchPad(key), org1, org2, depth); + var val = getScratch(key); + if( val == '1' ) return true; + return false; +} + + + /* useful for testing */ function die(msg) { log_error("die(): "+msg); diff --git a/Open-ILS/src/javascript/backend/circ/circ_permit_hold.js b/Open-ILS/src/javascript/backend/circ/circ_permit_hold.js index b78599c81d..5dc9b2cccd 100644 --- a/Open-ILS/src/javascript/backend/circ/circ_permit_hold.js +++ b/Open-ILS/src/javascript/backend/circ/circ_permit_hold.js @@ -23,6 +23,8 @@ if( mod == 'bestsellernh' ) var marcItemType = getMARCItemType(); +var isAnc; + if( ( marcItemType == 'g' || marcItemType == 'i' || marcItemType == 'j' || @@ -32,13 +34,18 @@ if( ( marcItemType == 'g' || mod == 'av' || mod == 'cd' || mod == 'dvd' || - mod == 'video' ) && + mod == 'video' ) ) { - !isOrgDescendent(copy.circ_lib.shortname, patron.home_ou.id) ) { + isAnc = hasCommonAncestor( copy.circ_lib.id, patron.home_ou.id, 1 ); - log_info("This patron may not place a hold on the selected item"); + if( isAnc) { + log_info("patron and copy circ_lib share a common ancestor, hold allowed"); - result.events.push('ITEM_NOT_HOLDABLE'); + } else { + + log_info("patron and copy circ_lib do NOT share a common ancestor, hold on this type of material not allowed"); + result.events.push('ITEM_NOT_HOLDABLE'); + } } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm index c522581587..8eae942959 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm @@ -1092,5 +1092,22 @@ sub is_true { } +sub patron_money_owed { + my( $self, $patronid ) = @_; + my $ses = OpenSRF::AppSession->create('open-ils.storage'); + my $req = $ses->request( + 'open-ils.storage.money.billable_transaction.summary.search', + { usr => $patronid, xact_finish => undef } ); + + my $total = 0; + my $data; + while( $data = $req->recv ) { + $data = $data->content; + $total += $data->balance_owed; + } + return $total; +} + + 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm index bc63fe40f0..65dfaffc1a 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm @@ -283,6 +283,7 @@ sub DESTROY { } # Add a pile of automagic getter/setter methods # -------------------------------------------------------------------------- my @AUTOLOAD_FIELDS = qw/ + penalty_request remote_hold backdate copy @@ -596,6 +597,29 @@ sub do_copy_checks { } +sub send_penalty_request { + my $self = shift; + my $ses = OpenSRF::AppSession->create('open-ils.penalty'); + $self->penalty_request( + $ses->request( + 'open-ils.penalty.patron_penalty.calculate', + { update => 1, + authtoken => $self->editor->authtoken, + patron => $self->patron } ) ); +} + +sub gather_penalty_request { + my $self = shift; + return [] unless $self->penalty_request; + my $data = $self->penalty_request->recv; + if( ref $data ) { + $data = $data->content; + return $data->{fatal_penalties}; + } + $logger->error("circulator: penalty request returned no data"); + return []; +} + # --------------------------------------------------------------------- # This pushes any patron-related events into the list but does not # set bail_out for any events @@ -605,16 +629,7 @@ sub run_patron_permit_scripts { my $runner = $self->script_runner; my $patronid = $self->patron->id; - # --------------------------------------------------------------------- - # Find all of the fatal penalties currently set on the user - # --------------------------------------------------------------------- - my $penalties = $U->update_patron_penalties( - authtoken => $self->editor->authtoken, - patron => $self->patron, - ); - - $penalties = $penalties->{fatal_penalties}; - + $self->send_penalty_request(); # --------------------------------------------------------------------- # Now run the patron permit script @@ -625,6 +640,8 @@ sub run_patron_permit_scripts { my $patron_events = $result->{events}; my @allevents; + + my $penalties = $self->gather_penalty_request(); push( @allevents, OpenILS::Event->new($_)) for (@$penalties, @$patron_events); $logger->info("circulator: permit_patron script returned events: @allevents") if @allevents; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/ScriptBuilder.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/ScriptBuilder.pm index bb0f366f0d..9284a4b6f7 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/ScriptBuilder.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/ScriptBuilder.pm @@ -19,6 +19,7 @@ my %GROUP_SET; my $GROUP_TREE; my $ORG_TREE; my @ORG_LIST; +my @OU_TYPES; # ----------------------------------------------------------------------- @@ -165,7 +166,7 @@ sub fetch_user_data { if( my $copy = $ctx->{copy} ) { my $circs = $e->search_action_circulation( - { target_copy => $copy->id, stop_fines_time => undef }); + { target_copy => $copy->id, checkin_time => undef }); if( my $circ = $circs->[0] ) { $ctx->{patron} = $e->retrieve_actor_user($circ->usr) @@ -229,23 +230,24 @@ sub fetch_user_data { #} if( $ctx->{fetch_patron_circ_info} ) { - my $circ_counts = OpenILS::Application::Actor::_checked_out(1, $e, $patron->id); $ctx->{patronOverdue} = $circ_counts->{overdue} || 0; $ctx->{patronItemsOut} = $ctx->{patronOverdue} + $circ_counts->{out}; + $logger->debug("script_builder: patron overdue count is " . $ctx->{patronOverdue}); + } + if( $ctx->{fetch_patron_money_info} ) { # Grab the fines - my $fxacts = $e->search_money_open_billable_transaction_summary( - { usr => $patron->id, balance_owed => { "!=" => 0 } }); - - my $fines = 0; - $fines += $_->balance_owed for @$fxacts; - $ctx->{patronFines} = $fines; - - $logger->debug("script_builder: patron fines determined to be $fines"); - $logger->debug("script_builder: patron overdue count is " . $ctx->{patronOverdue}); +# my $fxacts = $e->search_money_billable_transaction_summary( +# { usr => $patron->id, balance_owed => { "!=" => 0 }, xact_finish => undef }); +# +# my $fines = 0; +# $fines += $_->balance_owed for @$fxacts; +# $ctx->{patronFines} = $fines; + $ctx->{patronFines} = $U->patron_money_owed($patron->id); + $logger->debug("script_builder: patron fines determined to be ".$ctx->{patronFines}); } return undef; @@ -299,11 +301,20 @@ sub insert_org_methods { my ($child) = grep { $_->id == $id } @ORG_LIST; my $val = is_org_descendent( $parent, $child ); $logger->debug("script_builder: is_org_desc returned val $val, writing to $write_key"); - $r->insert($write_key, $val, 1) if $val; # Needs testing, was dying before + $r->insert($write_key, $val, 1) if $val; return $val; } ); + $r->insert(__OILS_FUNC_hasCommonAncestor => + sub { + my( $write_key, $orgid1, $orgid2, $depth ) = @_; + my $val = has_common_ancestor( $orgid1, $orgid2, $depth ); + $logger->debug("script_builder: has_common_ancestor resturned $val"); + $r->insert($write_key, $val, 1) if $val; + return $val; + } + ); } @@ -318,6 +329,40 @@ sub is_org_descendent { return 0; } +sub has_common_ancestor { + my( $org1, $org2, $depth ) = @_; + return 0 unless $org1 and $org2; + $logger->debug("script_builder: has_common_ancestor checking orgs $org1 : $org2"); + + return 1 if $org1 == $org2; + ($org1) = grep { $_->id == $org1 } @ORG_LIST; + ($org2) = grep { $_->id == $org2 } @ORG_LIST; + + my $p1 = find_parent_at_depth($org1, $depth); + my $p2 = find_parent_at_depth($org2, $depth); + + return 1 if $p1->id == $p2->id; + return 0; +} + + +sub find_parent_at_depth { + my $org = shift; + my $depth = shift; + fetch_ou_types(); + do { + my ($t) = grep { $_->id == $org->ou_type } @OU_TYPES; + return $org if $t->depth == $depth; + } while( ($org) = grep { $_->id == $org->parent_ou } @ORG_LIST ); + return undef; +} + + +sub fetch_ou_types { + return if @OU_TYPES; + @OU_TYPES = @{new_editor()->retrieve_all_actor_org_unit_type()}; +} + sub insert_copy_methods { my( $e, $ctx, $runner ) = @_; if( my $copy = $ctx->{copy} ) { diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Penalty.pm b/Open-ILS/src/perlmods/OpenILS/Application/Penalty.pm index e8d6293860..4df24dc31c 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Penalty.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Penalty.pm @@ -82,6 +82,7 @@ sub patron_penalty { $args->{patron_id} = $args->{patronid}; $args->{fetch_patron_circ_info} = 1; + $args->{fetch_patron_money_info} = 1; $args->{ignore_user_status} = 1; my $runner = OpenILS::Application::Circ::ScriptBuilder->build($args); -- 2.43.2