Online Renewal - Start of working branch
authorTerran McCanna <tmccanna@georgialibraries.org>
Thu, 5 Aug 2021 22:36:17 +0000 (18:36 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Sun, 30 Oct 2022 17:12:36 +0000 (13:12 -0400)
- 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 <tmccanna@georgialibraries.org>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/templates-bootstrap/opac/myopac/main.tt2
Open-ILS/src/templates-bootstrap/opac/myopac/prefs.tt2

index d2e88d8..03c7090 100644 (file)
@@ -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?
 
index fa36a42..4302845 100644 (file)
@@ -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} = '<span class="light_border"><a class="btn btn-sm btn-action" href="/eg/opac/renew-account"><i class="fas fa-user-cog"></i>Click here to renew your account</a></span>';
+    }
+
+    return;
+}
+
+# PINES - if account is eligible to renew, pass patron data to vendor to populate form
+sub load_renew_account {
+    return;
+}
+
 1;
index 4691639..ea8bab8 100755 (executable)
                 <div style="padding-bottom:10px;">[% l("PINES Account Tips") %]</div>
                 <div class="row">
                     <div class="col-12">
-                     <span [% IF ctx.expired_card %]class="danger"[% END %]>
-                        [% l("Account Expiration Date") %]: 
+                        <span [% IF ctx.expired_card %]class="danger"[% END %]>
+                            [% l("Account Expiration Date") %]:
                             [% date.format(ctx.parse_datetime(ctx.user.expire_date), DATE_FORMAT) %]
                         </span>
                     </div>
-                    <div class="col-12">
-                     [% IF ctx.expired_card %]
-                        <span>
-                            <em>
-                            [% l("<br>Your library card has expired.<br>Please contact a librarian to resolve this issue.", fmt_expire_date) %]
-                            </em>
-                        </span>
-                        [% END %]
+                    <div class="col-12" style="padding-bottom:20px;padding-top:20px;">
+                        [% ctx.account_renew_message %]
                     </div>
-                    <br>
                     <div class="col-12">
                      <a href="[% mkurl(ctx.opac_root _ '/myopac/circs') %]"
                             title="[% l('View My Checked Out Items') %]">
index 763e557..ab88fd7 100755 (executable)
                     [% ELSE %]
                         [% date.format(ctx.parse_datetime(ctx.user.expire_date), DATE_FORMAT) %]
                     [% END %]
+                    <div class="col-12" style="padding:20px 0px 20px 0px;">
+                        [% ctx.account_renew_message %]
+                    </div>
                 </td>
                 <td></td>
             </tr>