From b1ca67eebcabcc11c37512423f34914c08488edb 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. --- C4/Members.pm | 34 ---------------------------------- Koha/Patron.pm | 28 ++++++++++++++++++++++++++++ members/setstatus.pl | 5 +++-- 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 628eb15..964acb2 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -116,7 +116,6 @@ BEGIN { &AddMember &AddMember_Opac &MoveMemberToDeleted - &ExtendMemberSubscriptionTo ); #Check data @@ -1682,39 +1681,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 GetTitles (OUEST-PROVENCE) ($borrowertitle)= &GetTitles(); diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 5ba5efc..aaff883 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -23,7 +23,9 @@ use Modern::Perl; use Carp; use C4::Context; +use C4::Log; use Koha::Database; +use Koha::DateUtils; use Koha::Issues; use Koha::OldIssues; use Koha::Patron::Categories; @@ -168,6 +170,32 @@ sub do_check_for_previous_checkout { return $old_issues->count; # 0 || N } +=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 69849aa..e607e50 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.8.1