From 4b28f7f5a7fda4b73810e15a369193ab4de5f2f0 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 14 Jun 2023 13:34:11 +0000 Subject: [PATCH] Bug 28688: Add renew option to membership_expiry.pl Content-Type: text/plain; charset=utf-8 Test plan: [1] Pick an account to expire soon. [2] Choose MembershipExpiryDaysNotice so that it will be selected. (Note: You can extend the selection with -before or -after.) [3] Run misc/cronjobs/membership_expiry.pl -c -v -renew [4] Check new expiry date in the notice. Does it correspond with enrollment period of category and pref BorrowerRenewalPeriodBase? [5] If the patron category has an enrollment fee, check account too. [6] Reset dateexpiry of this patron to original date. [7] Run misc/cronjobs/membership_expiry.pl -c -v [8] Check if you got an expiry notice instead and dateexpiry did not change. Signed-off-by: Marcel de Rooy --- misc/cronjobs/membership_expiry.pl | 36 +++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/misc/cronjobs/membership_expiry.pl b/misc/cronjobs/membership_expiry.pl index e8485663e1..22edc575b0 100755 --- a/misc/cronjobs/membership_expiry.pl +++ b/misc/cronjobs/membership_expiry.pl @@ -41,8 +41,9 @@ Options: --before=X include patrons expiring a number of days BEFORE the date set by the preference --after=X include patrons expiring a number of days AFTER the date set by the preference -l --letter use a specific notice rather than the default - --active=X only send notices to active patrons (active within X months) - --inactive=X only send notices to inactive patrons (inactive within X months) + --active=X only deal with active patrons (active within X months) + --inactive=X only deal with inactive patrons (inactive within X months) + --renew renew patrons and send notice (instead of expiry notice only) =head1 DESCRIPTION @@ -109,7 +110,12 @@ Optional parameter to include active patrons only (active within passed number o =item B<-inactive> Optional parameter to include inactive patrons only (inactive within passed number of months). -This allows you to skip active patrons when you renew them automatically (see bug 28688). +This allows you to e.g. send expiry warnings only to inactive patrons. + +=item B<-renew> + +Optional parameter to automatically renew patrons instead of sending them an expiry notice. +They will be informed by a patron renewal notice. =back @@ -171,6 +177,7 @@ my ( $branch, $letter_type ); my @where; my $active; my $inactive; +my $renew; my $command_line_options = join(" ",@ARGV); @@ -187,6 +194,7 @@ GetOptions( 'where=s' => \@where, 'active:i' => \$active, 'inactive:i' => \$inactive, + 'renew' => \$renew, ) or pod2usage(2); pod2usage( -verbose => 2 ) if $man; @@ -223,7 +231,8 @@ warn 'found ' . $upcoming_mem_expires->count . ' soon expiring members' # main loop $letter_type = 'MEMBERSHIP_EXPIRY' if !$letter_type; -my ( $count_active, $count_inactive, $count_enqueued ) = ( 0, 0, 0 ); +my ( $count_active, $count_inactive, $count_renewed, $count_enqueued ) = ( 0, 0, 0, 0 ); +my $fees = {}; while ( my $recent = $upcoming_mem_expires->next ) { my $patron_active = $recent->is_active({ months => $active // $inactive }); # checked already that only one is defined if( defined($active) && !$patron_active ) { @@ -233,16 +242,29 @@ while ( my $recent = $upcoming_mem_expires->next ) { $count_active++; next; } + + my ($which_notice, $substitute); + if( $renew ) { + $recent->renew_account; + $which_notice = 'MEMBERSHIP_RENEWED'; + $fees->{$recent->branchcode} = $recent->category->enrolmentfee if !exists $fees->{$recent->branchcode}; + $substitute->{enrollment_fee} = $fees->{$recent->branchcode} if $fees->{$recent->branchcode} > 0; + $count_renewed++; + } else { + $which_notice = $letter_type; + } + my $from_address = $recent->library->from_email_address; my $letter = C4::Letters::GetPreparedLetter( module => 'members', - letter_code => $letter_type, + letter_code => $which_notice, branchcode => $recent->branchcode, lang => $recent->lang, tables => { borrowers => $recent->borrowernumber, branches => $recent->branchcode, }, + substitute => $substitute, ); last if !$letter; # Letters.pm already warned, just exit if( $nomail ) { @@ -261,13 +283,14 @@ while ( my $recent = $upcoming_mem_expires->next ) { if ($recent->smsalertnumber) { my $smsletter = C4::Letters::GetPreparedLetter( module => 'members', - letter_code => $letter_type, + letter_code => $which_notice, branchcode => $recent->branchcode, lang => $recent->lang, tables => { borrowers => $recent->borrowernumber, branches => $recent->branchcode, }, + substitute => $substitute, message_transport_type => 'sms', ); if ($smsletter) { @@ -281,6 +304,7 @@ while ( my $recent = $upcoming_mem_expires->next ) { } if( $verbose ) { + print "Membership renewed for $count_renewed patrons\n" if $count_renewed; print "Enqueued notices for $count_enqueued patrons\n"; print "Skipped $count_active active patrons\n" if $count_active; print "Skipped $count_inactive inactive patrons\n" if $count_inactive; -- 2.30.2