@@ -, +, @@ ->extend_subscription --- C4/Members.pm | 34 ---------------------------------- Koha/Patron.pm | 27 +++++++++++++++++++++++++++ members/setstatus.pl | 5 +++-- 3 files changed, 30 insertions(+), 36 deletions(-) --- a/C4/Members.pm +++ a/C4/Members.pm @@ -113,7 +113,6 @@ BEGIN { &AddMember &AddMember_Opac &MoveMemberToDeleted - &ExtendMemberSubscriptionTo ); #Check data @@ -1577,39 +1576,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); --- a/Koha/Patron.pm +++ a/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 --- a/members/setstatus.pl +++ a/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 ); --