From e4e90ea0dae0b93978cf450d48a26f9da0be7587 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 11 Jul 2016 23:28:19 +0100 Subject: [PATCH] Bug 16911: Koha::Patrons - Move ExtendMemberSubscriptionTo to ->extend_subscription This patch moves the code from C4::Members::ExtendMemberSubscriptionTo to Koha::Patron->extend_subscription. The expected behavior is: When a new patron is created, the enrolment period defined for the patron category is used unless an enrolment period date is defined. In that case, this date is used. When an account is renewed, the pref BorrowerRenewalPeriodBase is used to determine if the subscription is renewed from today or from the day when his/her account has expired. Test plan: Confirm that the behavior is correct before this patch and that it's still the same after this patchset applied. Signed-off-by: Aleisha Amohia Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall --- C4/Members.pm | 34 ---------------------------------- Koha/Patron.pm | 27 +++++++++++++++++++++++++++ members/setstatus.pl | 5 +++-- 3 files changed, 30 insertions(+), 36 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 3203c9576e..03f0b209e9 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -110,7 +110,6 @@ BEGIN { &AddMember &AddMember_Opac &MoveMemberToDeleted - &ExtendMemberSubscriptionTo ); #Check data @@ -1466,39 +1465,6 @@ sub HandleDelBorrower { #Koha::Virtualshelf->new->delete too. } -=head2 ExtendMemberSubscriptionTo (OUEST-PROVENCE) - - $date = ExtendMemberSubscriptionTo($borrowerid, $date); - -Extending the subscription to a given date or to the expiry date calculated on ISO date. -Returns ISO date. - -=cut - -sub ExtendMemberSubscriptionTo { - my ( $borrowerid,$date) = @_; - my $dbh = C4::Context->dbh; - my $borrower = GetMember('borrowernumber'=>$borrowerid); - unless ($date){ - $date = (C4::Context->preference('BorrowerRenewalPeriodBase') eq 'dateexpiry') ? - eval { output_pref( { dt => dt_from_string( $borrower->{'dateexpiry'} ), dateonly => 1, dateformat => 'iso' } ); } - : - output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' } ); - $date = Koha::Patron::Categories->find( $borrower->{categorycode} )->get_expiry_date( $date ); - } - my $sth = $dbh->do(<{categorycode}, $borrower->{borrowernumber} ); - - logaction("MEMBERS", "RENEW", $borrower->{'borrowernumber'}, "Membership renewed")if C4::Context->preference("BorrowersLog"); - return $date if ($sth); - return 0; -} - =head2 GetHideLostItemsPreference $hidelostitemspref = &GetHideLostItemsPreference($borrowernumber); diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 42b066b60c..ff508a3450 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -23,6 +23,7 @@ use Modern::Perl; use Carp; use C4::Context; +use C4::Members; use C4::Log; use Koha::Database; use Koha::DateUtils; @@ -208,6 +209,32 @@ sub update_password { return 1; } +=head3 extend_subscription + +my $new_expiry_date = $patron->extend_subscription + +Extending the subscription to the expiry date. + +=cut + +sub extend_subscription { + my ($self) = @_; + + my $date = + C4::Context->preference('BorrowerRenewalPeriodBase') eq 'dateexpiry' + ? dt_from_string( $self->dateexpiry ) + : dt_from_string; + my $patron_category = Koha::Patron::Categories->find( $self->categorycode ); # FIXME Should be $self->category + my $expiry_date = $patron_category->get_expiry_date($date); + + $self->dateexpiry($expiry_date)->store; + + C4::Members::AddEnrolmentFeeIfNeeded( $self->categorycode, $self->borrowernumber ); + + logaction( "MEMBERS", "RENEW", $self->borrowernumber, "Membership renewed" ) if C4::Context->preference("BorrowersLog"); + return dt_from_string( $expiry_date )->truncate( to => 'day' ); +} + =head3 type =cut diff --git a/members/setstatus.pl b/members/setstatus.pl index 69849aa07c..e607e50326 100755 --- a/members/setstatus.pl +++ b/members/setstatus.pl @@ -30,6 +30,7 @@ use CGI qw ( -utf8 ); use C4::Context; use C4::Members; use C4::Auth; +use Koha::Patrons; my $input = new CGI; @@ -45,8 +46,8 @@ my $dbh = C4::Context->dbh; my $dateexpiry; if ( $reregistration eq 'y' ) { - # re-reregistration function to automatic calcul of date expiry - $dateexpiry = ExtendMemberSubscriptionTo( $borrowernumber ); + # re-reregistration function to automatic calcul of date expiry + $dateexpiry = Koha::Patrons->find( $borrowernumber )->extend_subscription; } else { my $sth = $dbh->prepare("UPDATE borrowers SET debarred = ?, debarredcomment = '' WHERE borrowernumber = ?"); $sth->execute( $status, $borrowernumber ); -- 2.39.5