From: Jason Etheridge Date: Tue, 1 Oct 2013 20:16:38 +0000 (-0400) Subject: add PatronSumary.pm X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=93bdf13a8c6b40b13c530d67a18a72d32decf09e;p=working%2FEvergreen.git add PatronSumary.pm --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/PatronSummary.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/PatronSummary.pm new file mode 100644 index 0000000000..4e32be681b --- /dev/null +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/PatronSummary.pm @@ -0,0 +1,192 @@ +package OpenILS::WWW::EGCatLoader; +use strict; use warnings; +use Apache2::Const -compile => qw(OK DECLINED FORBIDDEN HTTP_INTERNAL_SERVER_ERROR REDIRECT HTTP_BAD_REQUEST); +use OpenSRF::Utils::Logger qw/$logger/; +use OpenILS::Utils::CStoreEditor qw/:funcs/; +use OpenILS::Utils::Fieldmapper; +use OpenILS::Application::AppUtils; +use OpenILS::Event; +use OpenSRF::Utils::JSON; +use Data::Dumper; +$Data::Dumper::Indent = 0; +use DateTime; +my $U = 'OpenILS::Application::AppUtils'; + +sub isTrue { + my $v = shift; + return 1 if ($v eq 't'); + return 0; +} + +sub load_patron_summary { + my $self = shift; + my $ctx = $self->ctx; + #my $gos = $ctx->{get_org_setting}; + my $e = $self->editor; + my $cgi = $self->cgi; + + $self->_load_user_with_prefs() if($e->checkauth); + + $ctx->{page} = 'patron_summary'; + $ctx->{au_id} = $cgi->param('au_id'); + my @classnames = (); + + # open-ils.actor.user.fleshed.retrieve.authoritative + my $au_resp = $U->simplereq( + 'open-ils.actor', + 'open-ils.actor.user.fleshed.retrieve.authoritative', + $e->authtoken, + $ctx->{au_id}, + [ + 'card', + 'profile', + 'mailing_address', + 'billing_address', + 'open_billable_transactions_summary', + 'standing_penalties', + 'notes', + 'usr_activity', + 'home_ou', + 'ident_type', + 'ident_type2' + ] + ); + + if (ref $au_resp eq 'HASH' && defined $au_resp->{textcode}) { + $ctx->{error} = $au_resp; + return Apache2::Const::OK; + } + + $au_resp->standing_penalties( + grep { + isTrue($_->isdeleted) || $_->stop_date + } @{ $au_resp->standing_penalties } + ); + $ctx->{user} = $au_resp; + + $ctx->{addr} = $au_resp->mailing_address && $au_resp->mailing_address->valid + ? $au_resp->mailing_address + : $au_resp->billing_address && $au_resp->billing_address->valid + ? $au_resp->billing_address + : undef; + + my $classhash = {}; + my $block_list; + foreach my $p ( @{ $au_resp->standing_penalties } ) { + $classhash->{ $p->standing_penalty->name } = 1; + if ($p->standing_penalty->id >= 100) { + $classhash->{'PATRON_HAS_CUSTOM_PENALTY'} = 1; + } + if (isTrue($p->standing_penalty->staff_alert)) { + $classhash->{'PATRON_HAS_STAFF_ALERT'} = 1; + } + $block_list = $p->standing_penalty->block_list; + if ($block_list) { + $classhash->{'PATRON_HAS_BLOCK'} = 1; + if ($block_list =~ 'CIRC') { + $classhash->{'PATRON_HAS_CIRC_BLOCK'} = 1; + } + if ($block_list =~ 'RENEW') { + $classhash->{'PATRON_HAS_RENEW_BLOCK'} = 1; + } + if ($block_list =~ 'HOLD') { + $classhash->{'PATRON_HAS_HOLD_BLOCK'} = 1; + } + if ($block_list =~ 'CAPTURE') { + $classhash->{'PATRON_HAS_CAPTURE_BLOCK'} = 1; + } + if ($block_list =~ 'FULFILL') { + $classhash->{'PATRON_HAS_FULFILL_BLOCK'} = 1; + } + } + } + foreach my $c ( keys %{ $classhash } ) { + push @classnames, $c; + } + if (scalar @{ $au_resp->standing_penalties } == 0) { + push @classnames, 'NO_PENALTIES'; + } + if (scalar @{ $au_resp->standing_penalties } == 1) { + push @classnames, 'ONE_PENALTY'; + } + if (scalar @{ $au_resp->standing_penalties } > 1) { + push @classnames, 'MULTIPLE_PENALTIES'; + } + if ($au_resp->alert_message) { + push @classnames, 'PATRON_HAS_ALERT'; + } + if (isTrue($au_resp->barred)) { + $ctx->{barred} = 1; + push @classnames, 'PATRON_BARRED'; + } + if (isTrue($au_resp->juvenile)) { + push @classnames, 'PATRON_JUVENILE'; + } + if (!isTrue($au_resp->active)) { + push @classnames, 'PATRON_INACTIVE'; + } + if (scalar( @{ $au_resp->notes }) > 0) { + push @classnames, 'PATRON_HAS_NOTES'; + } + push @classnames, 'PATRON_NET_ACCESS_' . $au_resp->net_access_level; + if ( + ($au_resp->mailing_address + && !isTrue($au_resp->mailing_address->valid)) + || ($au_resp->billing_address + && !isTrue($au_resp->billing_address->valid)) + ) { + push @classnames, 'PATRON_HAS_INVALID_ADDRESS'; + } + + my $expire = DateTime::Format::ISO8601->new->parse_datetime( + cleanse_ISO8601($au_resp->expire_date)); + + if( CORE::time > $expire->epoch ) { + push @classnames, 'PATRON_EXPIRED'; + } + + # TODO: PATRON_AGE_IS_ + # TODO: PATRON_AGE_LT_ + # TODO: PATRON_AGE_GE_ + + my $mous_resp = $U->simplereq( + 'open-ils.actor', + 'open-ils.actor.user.fines.summary.authoritative', + $e->authtoken, + $ctx->{au_id} + ); + $ctx->{money_open_user_summary} = $mous_resp; + + if ($mous_resp && $mous_resp->balance_owed > 0) { + push @classnames, 'PATRON_HAS_BILLS'; + } + + my $checked_out_count_resp = $U->simplereq( + 'open-ils.actor', + 'open-ils.actor.user.checked_out.count.authoritative', + $e->authtoken, + $ctx->{au_id} + ); + $ctx->{checked_out_count} = $checked_out_count_resp; + if ($checked_out_count_resp + && ($checked_out_count_resp->{overdue} + + $checked_out_count_resp->{long_overdue} + > 0)) { + push @classnames, 'PATRON_HAS_OVERDUES'; + } + + my $holds_count_resp = $U->simplereq( + 'open-ils.actor', + 'open-ils.actor.user.hold_requests.count.authoritative', + $e->authtoken, + $ctx->{au_id} + ); + $ctx->{holds_count} = $holds_count_resp; + + $ctx->{css_classnames} = join ' ', @classnames; + $ctx->{orig_params} = $cgi->Vars; + + return Apache2::Const::OK; +} + +