Bugzilla – Attachment 53515 Details for
Bug 16911
Koha::Patrons - Move ExtendMemberSubscriptionTo to ->renew_account
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16911: Koha::Patron::Categories - Move GetExpiryDate to ->get_expiry_date
Bug-16911-KohaPatronCategories---Move-GetExpiryDat.patch (text/plain), 6.99 KB, created by
Jonathan Druart
on 2016-07-20 13:57:26 UTC
(
hide
)
Description:
Bug 16911: Koha::Patron::Categories - Move GetExpiryDate to ->get_expiry_date
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-07-20 13:57:26 UTC
Size:
6.99 KB
patch
obsolete
>From 50819b8fd679f28da87504fb54cbe3861040b6b8 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 11 Jul 2016 23:45:55 +0100 >Subject: [PATCH] Bug 16911: Koha::Patron::Categories - Move GetExpiryDate to > ->get_expiry_date > >This patch moves the code from C4::Members::GetExpiryDate to >Koha::Patron::Categories. >Nothing much exiting, please follow test plan in next patches. >--- > C4/Members.pm | 37 ++++--------------------------------- > Koha/Patron/Category.pm | 11 +++++++++++ > members/memberentry.pl | 7 ++++--- > tools/import_borrowers.pl | 6 +++--- > 4 files changed, 22 insertions(+), 39 deletions(-) > >diff --git a/C4/Members.pm b/C4/Members.pm >index 63e3f36..040d4fd 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -25,7 +25,7 @@ use strict; > use C4::Context; > use String::Random qw( random_string ); > use Scalar::Util qw( looks_like_number ); >-use Date::Calc qw/Today Add_Delta_YM check_date Date_to_Days/; >+use Date::Calc qw/Today check_date Date_to_Days/; > use C4::Log; # logaction > use C4::Overdues; > use C4::Reserves; >@@ -43,6 +43,7 @@ use Koha::Database; > use Koha::Holds; > use Koha::List::Patron; > use Koha::Patrons; >+use Koha::Patron::Categories; > > our (@ISA,@EXPORT,@EXPORT_OK,$debug); > >@@ -88,7 +89,6 @@ BEGIN { > &GetBorrowersWhoHaveNeverBorrowed > &GetBorrowersWithIssuesHistoryOlderThan > >- &GetExpiryDate > &GetUpcomingMembershipExpires > > &IssueSlip >@@ -658,9 +658,7 @@ sub AddMember { > if ( $data{'userid'} eq '' || !Check_Userid( $data{'userid'} ) ); > > # add expiration date if it isn't already there >- unless ( $data{'dateexpiry'} ) { >- $data{'dateexpiry'} = GetExpiryDate( $data{'categorycode'}, output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' } ) ); >- } >+ $data{dateexpiry} ||= Koha::Patron::Categories->find( $data{categorycode} )->get_expiry_date; > > # add enrollment date if it isn't already there > unless ( $data{'dateenrolled'} ) { >@@ -1224,33 +1222,6 @@ sub GetNoticeEmailAddress { > return $data->{'primaryemail'} || ''; > } > >-=head2 GetExpiryDate >- >- $expirydate = GetExpiryDate($categorycode, $dateenrolled); >- >-Calculate expiry date given a categorycode and starting date. Date argument must be in ISO format. >-Return date is also in ISO format. >- >-=cut >- >-sub GetExpiryDate { >- my ( $categorycode, $dateenrolled ) = @_; >- my $enrolments; >- if ($categorycode) { >- my $dbh = C4::Context->dbh; >- my $sth = $dbh->prepare("SELECT enrolmentperiod,enrolmentperioddate FROM categories WHERE categorycode=?"); >- $sth->execute($categorycode); >- $enrolments = $sth->fetchrow_hashref; >- } >- # die "GetExpiryDate: for enrollmentperiod $enrolmentperiod (category '$categorycode') starting $dateenrolled.\n"; >- my @date = split (/-/,$dateenrolled); >- if($enrolments->{enrolmentperiod}){ >- return sprintf("%04d-%02d-%02d", Add_Delta_YM(@date,0,$enrolments->{enrolmentperiod})); >- }else{ >- return $enrolments->{enrolmentperioddate}; >- } >-} >- > =head2 GetUpcomingMembershipExpires > > my $expires = GetUpcomingMembershipExpires({ >@@ -1625,7 +1596,7 @@ sub ExtendMemberSubscriptionTo { > eval { output_pref( { dt => dt_from_string( $borrower->{'dateexpiry'} ), dateonly => 1, dateformat => 'iso' } ); } > : > output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' } ); >- $date = GetExpiryDate( $borrower->{'categorycode'}, $date ); >+ $date = Koha::Patron::Categories->find( $borrower->{categorycode} )->get_expiry_date( $date ); > } > my $sth = $dbh->do(<<EOF); > UPDATE borrowers >diff --git a/Koha/Patron/Category.pm b/Koha/Patron/Category.pm >index 7b17c8c..f85f4d8 100644 >--- a/Koha/Patron/Category.pm >+++ b/Koha/Patron/Category.pm >@@ -22,6 +22,7 @@ use Carp; > use C4::Members::Messaging; > > use Koha::Database; >+use Koha::DateUtils; > > use base qw(Koha::Object); > >@@ -177,6 +178,16 @@ sub _catb_resultset { > return $self->{_catb_resultset}; > } > >+sub get_expiry_date { >+ my ($self, $date ) = @_; >+ if ( $self->enrolmentperiod ) { >+ $date ||= dt_from_string; >+ return $date->add( months => $self->enrolmentperiod ); >+ } else { >+ return $self->enrolmentperioddate; >+ } >+} >+ > =head3 type > > =cut >diff --git a/members/memberentry.pl b/members/memberentry.pl >index 4785691..8b10967 100755 >--- a/members/memberentry.pl >+++ b/members/memberentry.pl >@@ -360,8 +360,8 @@ if ($op eq 'save' || $op eq 'insert'){ > > if ( ($op eq 'modify' || $op eq 'insert' || $op eq 'save'|| $op eq 'duplicate') and ($step == 0 or $step == 3 )){ > unless ($newdata{'dateexpiry'}){ >- my $arg2 = $newdata{'dateenrolled'} || output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); >- $newdata{'dateexpiry'} = GetExpiryDate($newdata{'categorycode'},$arg2); >+ my $patron_category = Koha::Patron::Categories->find( $newdata{categorycode} ); >+ $newdata{'dateexpiry'} = $patron_category->get_expiry_date( $newdata{dateenrolled} ); > } > } > >@@ -630,7 +630,8 @@ if (!defined($data{'dateenrolled'}) or $data{'dateenrolled'} eq ''){ > } > if ( $op eq 'duplicate' ) { > $data{'dateenrolled'} = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); >- $data{'dateexpiry'} = GetExpiryDate( $data{'categorycode'}, $data{'dateenrolled'} ); >+ my $patron_category = Koha::Patron::Categories->find( $data{categorycode} ); >+ $data{dateexpiry} = $patron_category->get_expiry_date( $data{dateenrolled} ); > } > if (C4::Context->preference('uppercasesurnames')) { > $data{'surname'} &&= uc( $data{'surname'} ); >diff --git a/tools/import_borrowers.pl b/tools/import_borrowers.pl >index e1754e6..389c973 100755 >--- a/tools/import_borrowers.pl >+++ b/tools/import_borrowers.pl >@@ -142,7 +142,7 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { > } > > push @feedback, {feedback=>1, name=>'headerrow', value=>join(', ', @csvcolumns)}; >- my $today_iso = output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' }); >+ my $today = output_pref; > my @criticals = qw(surname branchcode categorycode); # there probably should be others > my @bad_dates; # I've had a few. > LINE: while ( my $borrowerline = <$handle> ) { >@@ -218,8 +218,8 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { > push @missing_criticals, {key=>$_, line=>$. , lineraw=>$borrowerline, bad_date=>1}; > } > } >- $borrower{dateenrolled} = $today_iso unless $borrower{dateenrolled}; >- $borrower{dateexpiry} = GetExpiryDate($borrower{categorycode},$borrower{dateenrolled}) unless $borrower{dateexpiry}; >+ $borrower{dateenrolled} ||= $today; >+ $borrower{dateexpiry} ||= Koha::Patron::Categories->find( $borrower{categorycode} )->get_expiry_date( $borrower{dateenrolled} ); > my $borrowernumber; > my $member; > if ( ($matchpoint eq 'cardnumber') && ($borrower{'cardnumber'}) ) { >-- >2.8.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 16911
:
53338
|
53339
|
53340
|
53341
|
53346
|
53514
|
53515
|
53516
|
53517
|
53518
|
53533
|
54752
|
54753
|
54754
|
54755
|
54756
|
54757
|
54789
|
54790
|
54791
|
54792
|
54793
|
54794
|
55191
|
55192
|
55193
|
55194
|
55195
|
55196
|
55197
|
55424
|
55447