Online Renewal - Add Standing Penalty when Temp Renewal
authorTerran McCanna <tmccanna@georgialibraries.org>
Tue, 22 Nov 2022 18:49:38 +0000 (13:49 -0500)
committerTerran McCanna <tmccanna@georgialibraries.org>
Tue, 22 Nov 2022 18:49:38 +0000 (13:49 -0500)
Signed-off-by: Terran McCanna <tmccanna@georgialibraries.org>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Ecard.pm

index 6564f1b..8805bc8 100644 (file)
@@ -2559,13 +2559,13 @@ sub load_myopac_main {
     my $offset = $self->cgi->param('offset') || 0;
     $self->ctx->{search_ou} = $self->_get_search_lib();
     $self->ctx->{user}->notes(
-        $self->editor->search_actor_usr_note({
+        $self->editor->search_actor_usr_message({
             usr => $self->ctx->{user}->id,
             pub => 't'
         })
     );
 
-    # PINES - need to make sure we're retrieving current info or else changed expire date won't show up
+    # PINES - need to make sure we're retrieving current info
     $self->prepare_extended_user_info;
     # PINES - check whether or not to provide account renewal link
     if ($self->ctx->{user}->billing_address) {
@@ -3480,9 +3480,11 @@ sub has_penalties {
     });
 
     #check for PATRON_TEMP_RENEWAL
+    my $findpenalty = new_editor()->search_config_standing_penalty({name => 'PATRON_TEMP_RENEWAL'})->[0];
+    my $penaltyid = $findpenalty->id;
     my $searchpenalty_temp = new_editor()->search_actor_user_standing_penalty({
         usr => $user->id,
-        standing_penalty => 90,
+        standing_penalty => $penaltyid,
         '-or' => [
             {stop_date => undef},
             {stop_date => {'>' => 'now'}}
@@ -3536,7 +3538,9 @@ sub check_account_exp {
 
     #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.';
+        $ctx->{account_renew_message} = '<div style="border:2px solid green;padding:5px;">Your account could only be temporarily renewed because your
+        address changed. Please visit your nearest PINES library with your current proof of address
+        to complete your account renewal.</div>';
     } 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} = '';
index d52d6a7..3d9b2cd 100644 (file)
@@ -44,7 +44,7 @@ my @api_fields_renew = (
     {name => 'mailing_county', class => 'aua'},
     {name => 'mailing_state', class => 'aua'},
     {name => 'mailing_country', class => 'aua'},
-    {name => 'voter_registration', class => 'asvr'},
+    {name => 'voter_registration', class => 'asvr'}
 );
 
 my @api_fields_register = (
@@ -162,9 +162,6 @@ sub load_ecard_submit {
         $update_type = 'register';
     }
 
-    #TERRAN TEST ECARD CONNECTION
-    $logger->error("TERRAN ACTION TYPE: $update_type");
-
     $self->log_params;
 
     my $testmode = $cgi->param('testmode') || '';
@@ -208,7 +205,8 @@ sub load_ecard_submit {
     } else {
         return $self->compile_response unless $self->update_user;
         return $self->compile_response unless $self->update_addresses;
-        return $self->compile_response unless $self->add_survey_responses;
+# TERRAN - Survey is broken right now
+        #return $self->compile_response unless $self->add_survey_responses;
         return $self->compile_response unless $self->save_user;
         return $self->compile_response if $ctx->{response}->{status};
     }
@@ -218,9 +216,10 @@ sub load_ecard_submit {
     $ctx->{response}->{status} = 'OK';
 
     if ($update_type eq 'renew') {
+        #New expiration date
         $ctx->{response}->{expire_date} = $ctx->{user}->expire_date;
-        # TERRAN - Add code if this is a temp renewal
-        # TERRAN - Add home library code
+        #Mark whether this is a temporary renewal or not
+        # TERRAN - TO DO
     } else {
         $ctx->{response}->{barcode} = $ctx->{user}->card->barcode;
        }
@@ -274,7 +273,7 @@ sub compile_response {
     $logger->info("ECARD responding with " . $ctx->{response});
 
 #TERRAN TEST
-    $logger->error("TERRAN - compiled response is " . $ctx->{response});
+    $logger->error("TERRAN - response being sent to Quipu is: " . $ctx->{response});
 
     return Apache2::Const::OK;
 }
@@ -292,16 +291,12 @@ sub make_user {
     $au->net_access_level(1); # Filtered
     $au->name_keywords($in_house ? 'quipu_inhouse' : 'quipu_remote');
 
-# TERRAN - for testing purposes, hardcoding the home_ou temporarily
-#    my $home_ou = $cgi->param('home_ou');
-    my $home_ou = '4';
+    my $home_ou = $cgi->param('home_ou');
 
-# TERRAN - for testing purposes, hardcoding perm_grp temporarily
-#    my $perm_grp = $U->ou_ancestor_setting_value(
-#        $home_ou,
-#        'lib.ecard_patron_profile'
-#    );
-    my $perm_grp = '2';
+    my $perm_grp = $U->ou_ancestor_setting_value(
+        $home_ou,
+        'lib.ecard_patron_profile'
+    );
 
     $au->profile($perm_grp);
     my $grp = new_editor()->retrieve_permission_grp_tree($perm_grp);
@@ -381,6 +376,8 @@ sub update_user {
             DateTime->now(time_zone => 'local')->add(
                 seconds => interval_to_seconds('30 days'))->iso8601()
         );
+        # Add standing penalty to account
+        $self->apply_temp_renewal_penalty;
     } else {
         my $grp = new_editor()->retrieve_permission_grp_tree($perm_grp);
         $au->expire_date(
@@ -650,9 +647,10 @@ sub add_survey_responses {
     my $answer = $cgi->param('voter_registration');
 
     my $survey_response = Fieldmapper::action::survey_response->new;
+
     $survey_response->id(-1);
     $survey_response->isnew(1);
-    $survey_response->survey(1); # voter registration survey
+    $survey_response->survey(1);
     $survey_response->question(1);
     $survey_response->answer($answer);
 
@@ -725,7 +723,7 @@ sub save_user {
         } else {
             $msg = "Error updating user account: " . $resp->{textcode};
             $logger->error("E-RENEW: $msg");
-            $ctx->{response}->{status} = 'UPDATE_ERR'; # Does this work?
+            $ctx->{response}->{status} = 'UPDATE_ERR';
         }
 
         $ctx->{response}->{messages} = [{msg => $msg, pid => $$}];
@@ -737,5 +735,48 @@ sub save_user {
     return 1;
 }
 
+sub apply_temp_renewal_penalty {
+
+    my $self = shift;
+    my $ctx = $self->ctx;
+    my $cgi = $self->cgi;
+    my $patron_id = $cgi->param('patron_id');
+
+    my $e = new_editor(xact => 1);
+    my $ptype = $e->search_config_standing_penalty({name => 'PATRON_TEMP_RENEWAL'})->[0];
+
+    my $penalty = Fieldmapper::actor::user_standing_penalty->new;
+    $penalty->usr($patron_id);
+    $penalty->org_unit(1);
+    $penalty->standing_penalty($ptype->id);
+
+    my $aum = Fieldmapper::actor::usr_message->new;
+    $aum->create_date('now');
+    $aum->sending_lib(1);
+    $aum->title('Temporary Account Renewal');
+    $aum->usr($penalty->usr);
+    $aum->message('Patron renewed online with an address change so was given a 30-day
+    temporary account renewal. Please archive this message after the address is
+    verified and the renewal date extended.');
+    $aum->pub(0);
+
+    $aum = $e->create_actor_usr_message($aum);
+    unless($aum) {
+        $e->rollback;
+        return 0;
+    }
+
+    $penalty->usr_message($aum->id);
+
+    unless($e->create_actor_user_standing_penalty($penalty)) {
+        $e->rollback;
+        return 0;
+    }
+
+    $e->commit;
+    return 1;
+}
+
+
 1;