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 <aleishaamohia@hotmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2016-07-11 23:28:19 +01:00 committed by Kyle M Hall
parent 076ef1e22e
commit e4e90ea0da
3 changed files with 30 additions and 36 deletions

View File

@ -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(<<EOF);
UPDATE borrowers
SET dateexpiry='$date'
WHERE borrowernumber='$borrowerid'
EOF
AddEnrolmentFeeIfNeeded( $borrower->{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);

View File

@ -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

View File

@ -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 );