From 3add7726166bb75f113130703e24a77b867e9721 Mon Sep 17 00:00:00 2001 From: Terran McCanna Date: Thu, 5 Aug 2021 18:36:17 -0400 Subject: [PATCH] Online Renewal - Start of working branch - Creates placeholders for new English & Spanish pages - Adds ability for those pages to load - Create div on My Account main page & prefs page to hold renewal message or button - Adds code to check whether or not patron is eligible to renew online or not: * patron has not already had one temporary renewal * patron account is still active * patron account expiration date is no more than 30 days in the future * patron account is not barred * patron account does not have a staff-added blocking alert * patron does not owe any fines * patron is not in collections (even if patron pays fines, staff still need to remove collections note) * patron is in one of these perm groups: Patron (2), Friend (14), GLS (56), Homebound (53), Trustee (22), Quipu (64), Digital Only (60) * patron has a valid billing address * patron has a valid day phone NOTE: New standing penalty needs to be created called PATRON_TEMP_RENEWAL. It should display a staff alert and have the label "Patron was given a 30-day temporary account renewal. Please archive this message after the account is fully renewed." It should not create any type of block on its own. The ID of the new standing penalty needs to be updated in the Account.pm file. Signed-off-by: Terran McCanna --- .../src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 3 + .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 141 +++++++++++++++++++++ .../src/templates-bootstrap/opac/myopac/main.tt2 | 15 +-- .../src/templates-bootstrap/opac/myopac/prefs.tt2 | 3 + 4 files changed, 151 insertions(+), 11 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index d2e88d896e..03c7090640 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -191,6 +191,9 @@ sub load { return $self->load_ecard_submit if $path =~ m|opac/ecard/submit|; return $self->load_ecard_verify if $path =~ m|opac/ecard/verify|; + # PINES - online account renewal + return $self->load_renew_account if $path =~ m|opac/renew-account|; + if($path =~ m|opac/login|) { return $self->load_login unless $self->editor->requestor; # already logged in? diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm index fa36a420d3..4302845356 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -119,6 +119,14 @@ sub load_myopac_prefs { $self->prepare_extended_user_info; my $user = $self->ctx->{user}; + # PINES - check whether or not to provide account renewal link + if ($self->ctx->{user}->billing_address) { + $self->ctx->{valid_billing_address} = $self->ctx->{user}->billing_address->valid; + } else { + $self->ctx->{valid_billing_address} = 0; + } + $self->check_account_exp(); + my $lock_usernames = $self->ctx->{get_org_setting}->($e->requestor->home_ou, 'opac.lock_usernames'); if(defined($lock_usernames) and $lock_usernames == 1) { # Policy says no username changes @@ -2644,6 +2652,15 @@ sub load_myopac_main { pub => 't' }) ); + + # PINES - check whether or not to provide account renewal link + if ($self->ctx->{user}->billing_address) { + $self->ctx->{valid_billing_address} = $self->editor->retrieve_actor_user_address($self->ctx->{user}->billing_address)->valid; + } else { + $self->ctx->{valid_billing_address} = 0; + } + $self->check_account_exp(); + return $self->prepare_fines($limit, $offset) || Apache2::Const::OK; } @@ -3501,4 +3518,128 @@ sub load_password_reset { return Apache2::Const::OK; } +# PINES - check whether patron has standing penalties that should block +# online account renewal +sub has_penalties { + my $self = shift; + my $ctx = $self->ctx; + my $user = $self->ctx->{user}; + + #check for INVALID_PATRON_ADDRESS + my $searchpenalty_address = new_editor()->search_actor_user_standing_penalty({ + usr => $user->id, + standing_penalty => 29, + '-or' => [ + {stop_date => undef}, + {stop_date => {'>' => 'now'}} + ] + }); + + #check for INVALID_PATRON_DAY_PHONE + my $searchpenalty_phone = new_editor()->search_actor_user_standing_penalty({ + usr => $user->id, + standing_penalty => 32, + '-or' => [ + {stop_date => undef}, + {stop_date => {'>' => 'now'}} + ] + }); + + #check for PATRON_IN_COLLECTIONS + my $searchpenalty_coll = new_editor()->search_actor_user_standing_penalty({ + usr => $user->id, + standing_penalty => 30, + '-or' => [ + {stop_date => undef}, + {stop_date => {'>' => 'now'}} + ] + }); + + #check for alerting block + my $searchpenalty_alertblock = new_editor()->search_actor_user_standing_penalty({ + usr => $user->id, + standing_penalty => 25, + '-or' => [ + {stop_date => undef}, + {stop_date => {'>' => 'now'}} + ] + }); + + #check for PATRON_TEMP_RENEWAL + ##### THIS WILL BE A DIFFERENT NUMBER ON PRODUCTION ##### + my $searchpenalty_temp = new_editor()->search_actor_user_standing_penalty({ + usr => $user->id, + standing_penalty => 101, + '-or' => [ + {stop_date => undef}, + {stop_date => {'>' => 'now'}} + ] + }); + + if (@$searchpenalty_address || @$searchpenalty_coll || @$searchpenalty_phone || @$searchpenalty_alertblock) { + $ctx->{haspenalty} = 1; + } else { + $ctx->{haspenalty} = 0; + } + + if (@$searchpenalty_temp) { + $ctx->{hastemprenew} = 1; + } else { + $ctx->{hastemprenew} = 0; + } + + return; +} + +# PINES - check whether or not to show account renewal link +sub check_account_exp { + my $self = shift; + my $ctx = $self->ctx; + $self->update_dashboard_stats(); + + #make sure patron is in an eligible perm group for renewal + if ($ctx->{user}->profile eq '2' || $ctx->{user}->profile eq '14' || $ctx->{user}->profile eq '56' || $ctx->{user}->profile eq '53' || $ctx->{user}->profile eq '22' || $ctx->{user}->profile eq '64' || $ctx->{user}->profile eq '60') { + $ctx->{eligible_permgroup} = 1; + } else { + $ctx->{eligible_permgroup} = 0; + } + + #check for various standing penalties that would block an online renewal + $self->has_penalties(); + + #check for other problems that would block an online renewal + if ($ctx->{user}->active ne 't') { #user is no longer active + $ctx->{hasproblem} = 1; + } elsif ($ctx->{haspenalty} eq 1) { #user has a standing penalty block + $ctx->{hasproblem} = 1; + } elsif ($ctx->{user}->barred eq 't') { #user is barred + $ctx->{hasproblem} = 1; + } elsif ($ctx->{valid_billing_address} ne 't') { #user has invalid address + $ctx->{hasproblem} = 1; + } else { + $ctx->{hasproblem} = 0; + } + + #determine which message to show (if any) + if ($ctx->{hastemprenew} eq 1) { #user already has active temp renewal + $ctx->{account_renew_message} = 'Your account was renewed for 30 days. Please visit your nearest PINES library with your current ID and proof of address to complete your account renewal.'; + } elsif (DateTime->today->add(days=>30) lt $ctx->{user}->expire_date) { + #expiration date is too far in future - don't show message + $ctx->{account_renew_message} = ''; + } elsif ($ctx->{hasproblem} eq 1 or $ctx->{eligible_permgroup} eq 0) { #see other problems above + $ctx->{account_renew_message} = 'Your account is due for renewal, but it is not eligible for online renewal. Please visit your nearest PINES library with your current ID and proof of address to renew your account.'; + } elsif ($ctx->{user_stats}->{fines}->{balance_owed} gt 0) { #user has fines + $ctx->{account_renew_message} = 'Your account expiration date is coming up soon. Please pay your outstanding fines in order to renew your account.'; + } else { + $ctx->{account_renew_message} = 'Click here to renew your account'; + } + + return; +} + +# PINES - if account is eligible to renew, pass patron data to vendor to populate form +sub load_renew_account { + return; +} + 1; diff --git a/Open-ILS/src/templates-bootstrap/opac/myopac/main.tt2 b/Open-ILS/src/templates-bootstrap/opac/myopac/main.tt2 index 4691639616..ea8bab8675 100755 --- a/Open-ILS/src/templates-bootstrap/opac/myopac/main.tt2 +++ b/Open-ILS/src/templates-bootstrap/opac/myopac/main.tt2 @@ -16,21 +16,14 @@
[% l("PINES Account Tips") %]
- - [% l("Account Expiration Date") %]: + + [% l("Account Expiration Date") %]: [% date.format(ctx.parse_datetime(ctx.user.expire_date), DATE_FORMAT) %]
-