# Add a pile of automagic getter/setter methods
# --------------------------------------------------------------------------
my @AUTOLOAD_FIELDS = qw/
+ penalty_request
remote_hold
backdate
copy
}
+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
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
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;
my $GROUP_TREE;
my $ORG_TREE;
my @ORG_LIST;
+my @OU_TYPES;
# -----------------------------------------------------------------------
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)
#}
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;
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;
+ }
+ );
}
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} ) {