Online Renewal - Add Standing Penalty when Temp Renewal
authorTerran McCanna <tmccanna@georgialibraries.org>
Tue, 22 Nov 2022 18:49:38 +0000 (13:49 -0500)
committerJason Stephenson <jstephenson@cwmars.org>
Tue, 29 Nov 2022 20:05:42 +0000 (15:05 -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 595d3d3..e60ff87 100644 (file)
@@ -2654,7 +2654,7 @@ sub load_myopac_main {
         })
     );
 
-    # 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) {
@@ -3604,9 +3604,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'}}
@@ -3660,7 +3662,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 300c67c..b8b36e8 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 = (
@@ -315,9 +315,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') || '';
@@ -368,7 +365,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};
     }
@@ -436,7 +434,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;
 }
@@ -454,17 +452,10 @@ sub make_user {
     my $home_ou = $cgi->param('home_ou');
     $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';
-
-# 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);
@@ -542,6 +533,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(
@@ -834,9 +827,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);
 
@@ -947,7 +941,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 => $$}];
@@ -959,4 +953,47 @@ 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;