Bugzilla – Attachment 56493 Details for
Bug 16912
Koha::Patrons - Move AddEnrolmentFeeIfNeeded to add_enrolment_fee_if_needed
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16912: Koha::Patrons - Move AddEnrolmentFeeIfNeeded to ->add_enrolment_fee_if_needed
Bug-16912-KohaPatrons---Move-AddEnrolmentFeeIfNeed.patch (text/plain), 5.48 KB, created by
Jonathan Druart
on 2016-10-14 09:25:16 UTC
(
hide
)
Description:
Bug 16912: Koha::Patrons - Move AddEnrolmentFeeIfNeeded to ->add_enrolment_fee_if_needed
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-10-14 09:25:16 UTC
Size:
5.48 KB
patch
obsolete
>From cdfb66708296bf7d45306b26721539d9dc2925be Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 12 Jul 2016 08:30:13 +0100 >Subject: [PATCH] Bug 16912: Koha::Patrons - Move AddEnrolmentFeeIfNeeded to > ->add_enrolment_fee_if_needed > >This patch moves the code of the C4::Members::AddEnrolmentFeeIfNeeded >subroutine to the Koha::Patron->add_enrolment_fee_if_needed method. >The behavior should be unchanged. > >Test plan: >1/ Define enrolment fee for 2 patron categories >2/ Create a patron using the first category >=> The patron should be charged >3/ Change the patron category to the other one >=> The patron should be charged again > >Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com> >--- > C4/Members.pm | 48 +++++++++--------------------------------------- > Koha/Patron.pm | 21 ++++++++++++++++++++- > 2 files changed, 29 insertions(+), 40 deletions(-) > >diff --git a/C4/Members.pm b/C4/Members.pm >index 4f00453..dc81867 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -541,19 +541,19 @@ sub ModMember { > $new_borrower->{dateexpiry} ||= undef if exists $new_borrower->{dateexpiry}; > $new_borrower->{debarred} ||= undef if exists $new_borrower->{debarred}; > $new_borrower->{sms_provider_id} ||= undef if exists $new_borrower->{sms_provider_id}; >+ $new_borrower->{guarantorid} ||= undef if exists $new_borrower->{guarantorid}; > >- my $rs = $schema->resultset('Borrower')->search({ >- borrowernumber => $new_borrower->{borrowernumber}, >- }); >+ my $patron = Koha::Patrons->find( $new_borrower->{borrowernumber} ); > > delete $new_borrower->{userid} if exists $new_borrower->{userid} and not $new_borrower->{userid}; > >- my $execute_success = $rs->update($new_borrower); >- if ($execute_success ne '0E0') { # only proceed if the update was a success >+ my $execute_success = $patron->store if $patron->set($new_borrower); >+ >+ if ($execute_success) { # only proceed if the update was a success > # If the patron changes to a category with enrollment fee, we add a fee > if ( $data{categorycode} and $data{categorycode} ne $old_categorycode ) { > if ( C4::Context->preference('FeeOnChangePatronCategory') ) { >- AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} ); >+ $patron->add_enrolment_fee_if_needed; > } > } > >@@ -641,8 +641,8 @@ sub AddMember { > $new_member->{checkprevcheckout} ||= 'inherit'; > delete $new_member->{borrowernumber}; > >- my $rs = $schema->resultset('Borrower'); >- $data{borrowernumber} = $rs->create($new_member)->id; >+ my $patron = Koha::Patron->new($new_member)->store; >+ $data{borrowernumber} = $patron->id; > > # If NorwegianPatronDBEnable is enabled, we set syncstatus to something that a > # cronjob will use for syncing with NL >@@ -656,10 +656,9 @@ sub AddMember { > }); > } > >- # mysql_insertid is probably bad. not necessarily accurate and mysql-specific at best. > logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog"); > >- AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} ); >+ $patron->add_enrolment_fee_if_needed; > > return $data{borrowernumber}; > } >@@ -1771,35 +1770,6 @@ sub AddMember_Opac { > return ( $borrowernumber, $borrower{'password'} ); > } > >-=head2 AddEnrolmentFeeIfNeeded >- >- AddEnrolmentFeeIfNeeded( $borrower->{categorycode}, $borrower->{borrowernumber} ); >- >-Add enrolment fee for a patron if needed. >- >-=cut >- >-sub AddEnrolmentFeeIfNeeded { >- my ( $categorycode, $borrowernumber ) = @_; >- # check for enrollment fee & add it if needed >- my $dbh = C4::Context->dbh; >- my $sth = $dbh->prepare(q{ >- SELECT enrolmentfee >- FROM categories >- WHERE categorycode=? >- }); >- $sth->execute( $categorycode ); >- if ( $sth->err ) { >- warn sprintf('Database returned the following error: %s', $sth->errstr); >- return; >- } >- my ($enrolmentfee) = $sth->fetchrow; >- if ($enrolmentfee && $enrolmentfee > 0) { >- # insert fee in patron debts >- C4::Accounts::manualinvoice( $borrowernumber, '', '', 'A', $enrolmentfee ); >- } >-} >- > =head2 DeleteExpiredOpacRegistrations > > Delete accounts that haven't been upgraded from the 'temporary' category >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index b5449a3..bbc506e 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -228,7 +228,7 @@ sub renew_account { > > $self->dateexpiry($expiry_date)->store; > >- C4::Members::AddEnrolmentFeeIfNeeded( $self->categorycode, $self->borrowernumber ); >+ $self->add_enrolment_fee_if_needed; > > logaction( "MEMBERS", "RENEW", $self->borrowernumber, "Membership renewed" ) if C4::Context->preference("BorrowersLog"); > return dt_from_string( $expiry_date )->truncate( to => 'day' ); >@@ -267,6 +267,25 @@ sub track_login { > $self->lastseen( dt_from_string() )->store; > } > >+=head3 add_enrolment_fee_if_needed >+ >+my $enrolment_fee = $patron->add_enrolment_fee_if_needed; >+ >+Add enrolment fee for a patron if needed. >+ >+=cut >+ >+sub add_enrolment_fee_if_needed { >+ my ($self) = @_; >+ my $patron_category = Koha::Patron::Categories->find( $self->categorycode ); >+ my $enrolment_fee = $patron_category->enrolmentfee; >+ if ( $enrolment_fee && $enrolment_fee > 0 ) { >+ # insert fee in patron debts >+ C4::Accounts::manualinvoice( $self->borrowernumber, '', '', 'A', $enrolment_fee ); >+ } >+ return $enrolment_fee || 0; >+} >+ > =head3 type > > =cut >-- >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 16912
:
53342
|
53343
|
53519
|
53520
|
54798
|
54804
|
54836
|
54837
|
54838
|
56493
|
56494
|
56495
|
56526
|
56527
|
56528
|
56771
|
56772
|
56773