Bug 10481: FIX No enrollment fee when changing patron category.

When a patron changes to a category with enrollment fee, they
are not generated.

Test plan:
- Choose a category without fee (e.g. Kid)
- Add an enrollment fee for another category (e.g. Young adult)
- Choose a kid and change his category to "Young adult".
- Note the warning message "Fees & Charges: Patron has Outstanding fees
  & charges of XX" on the check out page.

This patch also moves all instances of adding the enrollment fee
to a new routine in C4::Members, AddEnrolmentFeeIfNeeded(), so
additional tests include:

- Register a new patron and give it a category that has
  an enrollment fee.  Verify that the fee is charged.
- Renew the patron.  Verify that the additional fee is charged.
- Register a new patron with a child patron category.
- Use the 'update child to adult' menu option to change the
  patron's category to one that is fee-bearing.  Verify that the
  enrollment fee was charged.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
This commit is contained in:
Jonathan Druart 2013-06-17 14:56:22 +02:00 committed by Galen Charlton
parent a4d8144efd
commit f8eb19163b

View file

@ -753,6 +753,7 @@ sub ModMember {
$data{password} = md5_base64($data{password});
}
}
my $old_categorycode = GetBorrowerCategorycode( $data{borrowernumber} );
my $execute_success=UpdateInTable("borrowers",\%data);
if ($execute_success) { # only proceed if the update was a success
# ok if its an adult (type) it may have borrowers that depend on it as a guarantor
@ -763,12 +764,17 @@ sub ModMember {
# is adult check guarantees;
UpdateGuarantees(%data);
}
# If the patron changes to a category with enrollment fee, we add a fee
if ( $data{categorycode} and $data{categorycode} ne $old_categorycode ) {
AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
}
logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "UPDATE (executed w/ arg: $data{'borrowernumber'})") if C4::Context->preference("BorrowersLog");
}
return $execute_success;
}
=head2 AddMember
$borrowernumber = &AddMember(%borrower);
@ -806,18 +812,7 @@ 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");
# check for enrollment fee & add it if needed
my $sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode=?");
$sth->execute($data{'categorycode'});
my ($enrolmentfee) = $sth->fetchrow;
if ($sth->err) {
warn sprintf('Database returned the following error: %s', $sth->errstr);
return;
}
if ($enrolmentfee && $enrolmentfee > 0) {
# insert fee in patron debts
manualinvoice($data{'borrowernumber'}, '', '', 'A', $enrolmentfee);
}
AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
return $data{'borrowernumber'};
}
@ -1877,14 +1872,9 @@ UPDATE borrowers
SET dateexpiry='$date'
WHERE borrowernumber='$borrowerid'
EOF
# add enrolmentfee if needed
$sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode=?");
$sth->execute($borrower->{'categorycode'});
my ($enrolmentfee) = $sth->fetchrow;
if ($enrolmentfee && $enrolmentfee > 0) {
# insert fee in patron debts
manualinvoice($borrower->{'borrowernumber'}, '', '', 'A', $enrolmentfee);
}
AddEnrolmentFeeIfNeeded( $borrower->{categorycode}, $borrower->{borrowernumber} );
logaction("MEMBERS", "RENEW", $borrower->{'borrowernumber'}, "Membership renewed")if C4::Context->preference("BorrowersLog");
return $date if ($sth);
return 0;
@ -2541,6 +2531,35 @@ sub AddMember_Opac {
return ( $borrowernumber, $password );
}
=head2 AddEnroltmenFeeIfNeeded
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 );
}
}
END { } # module clean-up code here (global destructor)
1;