Bug 15407: Koha::Patron::Categories - replace GetBorrowercategory
The purpose of C4::Members::GetBorrowercategory was to return the patron category for a given categorycode. This can be done easily with the Koha::Patron::Categories->find method. Test plan: - Same prerequisite as before - Edit a guarantor and confirm the information will be updated for his/her guarantee(s). - Update a child to adult patron (Note: Should not we hide the patron categories limited to others libraries? If yes, it must be done on another bug report). There is a special behavior if there is only 1 adult category, the user does not need to select a category. So the same as before with only 1 adult patron category. - Import a patron with a category_code which does not exist. You should be warned. - Modify some patron using the batch patron modification tool. The patron category descriptions should correctly be displayed. Note that the overduerules page has already been tested in a previous patch. Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
6ee8dd3a59
commit
a5a23bcebc
|
|
@ -79,7 +79,6 @@ BEGIN {
|
|||
&GetBorNotifyAcctRecord
|
||||
|
||||
&GetborCatFromCatType
|
||||
&GetBorrowercategory
|
||||
GetBorrowerCategorycode
|
||||
&GetBorrowercategoryList
|
||||
|
||||
|
|
@ -1351,34 +1350,6 @@ sub GetborCatFromCatType {
|
|||
return ( \@codes, \%labels );
|
||||
}
|
||||
|
||||
=head2 GetBorrowercategory
|
||||
|
||||
$hashref = &GetBorrowercategory($categorycode);
|
||||
|
||||
Given the borrower's category code, the function returns the corresponding
|
||||
data hashref for a comprehensive information display.
|
||||
|
||||
=cut
|
||||
|
||||
sub GetBorrowercategory {
|
||||
my ($catcode) = @_;
|
||||
my $dbh = C4::Context->dbh;
|
||||
if ($catcode){
|
||||
my $sth =
|
||||
$dbh->prepare(
|
||||
"SELECT description,dateofbirthrequired,upperagelimit,category_type
|
||||
FROM categories
|
||||
WHERE categorycode = ?"
|
||||
);
|
||||
$sth->execute($catcode);
|
||||
my $data =
|
||||
$sth->fetchrow_hashref;
|
||||
return $data;
|
||||
}
|
||||
return;
|
||||
} # sub getborrowercategory
|
||||
|
||||
|
||||
=head2 GetBorrowerCategorycode
|
||||
|
||||
$categorycode = &GetBorrowerCategoryCode( $borrowernumber );
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ use C4::Form::MessagingPreferences;
|
|||
use Koha::Patron::Debarments;
|
||||
use Koha::Cities;
|
||||
use Koha::DateUtils;
|
||||
use Koha::Patron::Categories;
|
||||
use Koha::Token;
|
||||
use Email::Valid;
|
||||
use Module::Load;
|
||||
|
|
@ -153,9 +154,9 @@ $template->param( "checked" => 1 ) if ( defined($nodouble) && $nodouble eq 1 );
|
|||
my $categorycode = $input->param('categorycode') || $borrower_data->{'categorycode'};
|
||||
my $category_type = $input->param('category_type') || '';
|
||||
unless ($category_type or !($categorycode)){
|
||||
my $borrowercategory = GetBorrowercategory($categorycode);
|
||||
$category_type = $borrowercategory->{'category_type'};
|
||||
my $category_name = $borrowercategory->{'description'};
|
||||
my $borrowercategory = Koha::Patron::Categories->find($categorycode);
|
||||
$category_type = $borrowercategory->category_type;
|
||||
my $category_name = $borrowercategory->description;
|
||||
$template->param("categoryname"=>$category_name);
|
||||
}
|
||||
$category_type="A" unless $category_type; # FIXME we should display a error message instead of a 500 error !
|
||||
|
|
@ -303,8 +304,8 @@ if ($op eq 'save' || $op eq 'insert'){
|
|||
|
||||
if ( $newdata{dateofbirth} ) {
|
||||
my $age = GetAge($newdata{dateofbirth});
|
||||
my $borrowercategory=GetBorrowercategory($newdata{'categorycode'});
|
||||
my ($low,$high) = ($borrowercategory->{'dateofbirthrequired'}, $borrowercategory->{'upperagelimit'});
|
||||
my $borrowercategory = Koha::Patron::Categories->find($newdata{categorycode});
|
||||
my ($low,$high) = ($borrowercategory->dateofbirthrequired, $borrowercategory->upperagelimit);
|
||||
if (($high && ($age > $high)) or ($age < $low)) {
|
||||
push @errors, 'ERROR_age_limitations';
|
||||
$template->param( age_low => $low);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ use C4::Context;
|
|||
use C4::Auth;
|
||||
use C4::Output;
|
||||
use C4::Members;
|
||||
use Koha::Patron::Categories;
|
||||
|
||||
# use Smart::Comments;
|
||||
|
||||
|
|
@ -66,8 +67,8 @@ if ( $op eq 'multi' ) {
|
|||
my $row;
|
||||
$row->{catcode} = $k;
|
||||
$row->{catdesc} = $labels->{$k};
|
||||
my $borcat = GetBorrowercategory( $row->{catcode} );
|
||||
$row->{cattype} = $borcat->{'category_type'};
|
||||
my $borcat = Koha::Patron::Categories->find($row->{catcode});
|
||||
$row->{cattype} = $borcat->category_type;
|
||||
push @rows, $row;
|
||||
}
|
||||
$template->param(
|
||||
|
|
@ -83,9 +84,9 @@ elsif ( $op eq 'update' ) {
|
|||
my $member = GetMember('borrowernumber'=>$borrowernumber);
|
||||
$member->{'guarantorid'} = 0;
|
||||
$member->{'categorycode'} = $catcode;
|
||||
my $borcat = GetBorrowercategory($catcode);
|
||||
$member->{'category_type'} = $borcat->{'category_type'};
|
||||
$member->{'description'} = $borcat->{'description'};
|
||||
my $borcat = Koha::Patron::Categories->find($catcode);
|
||||
$member->{'category_type'} = $borcat->category_type;
|
||||
$member->{'description'} = $borcat->description;
|
||||
delete $member->{password};
|
||||
ModMember(%$member);
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ use Koha::Holds;
|
|||
use t::lib::Mocks;
|
||||
|
||||
use Koha::DateUtils;
|
||||
use Koha::Patron::Categories;
|
||||
|
||||
use Data::Dumper;
|
||||
BEGIN {
|
||||
|
|
@ -63,7 +64,7 @@ foreach my $addbra ('CPL', 'FPL', 'RPL') {
|
|||
|
||||
# Add categories if not existing
|
||||
foreach my $addcat ('S', 'PT') {
|
||||
$dbh->do("INSERT INTO categories (categorycode,hidelostitems,category_type) VALUES (?,?,?)",undef,($addcat, 0, $addcat eq 'S'? 'S': 'A')) unless GetBorrowercategory($addcat);
|
||||
$dbh->do("INSERT INTO categories (categorycode,hidelostitems,category_type) VALUES (?,?,?)",undef,($addcat, 0, $addcat eq 'S'? 'S': 'A')) unless Koha::Patron::Categories->find($addcat);
|
||||
}
|
||||
|
||||
# Create a helper biblio
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ use Koha::Patron::Debarments;
|
|||
use Koha::Patrons;
|
||||
use Koha::DateUtils;
|
||||
use Koha::Token;
|
||||
use Koha::Patron::Categories;
|
||||
|
||||
use Text::CSV;
|
||||
# Text::CSV::Unicode, even in binary mode, fails to parse lines with these diacriticals:
|
||||
|
|
@ -188,7 +189,7 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
|
|||
#warn join(':',%borrower);
|
||||
if ($borrower{categorycode}) {
|
||||
push @missing_criticals, {key=>'categorycode', line=>$. , lineraw=>$borrowerline, value=>$borrower{categorycode}, category_map=>1}
|
||||
unless GetBorrowercategory($borrower{categorycode});
|
||||
unless Koha::Patron::Categories->find($borrower{categorycode});
|
||||
} else {
|
||||
push @missing_criticals, {key=>'categorycode', line=>$. , lineraw=>$borrowerline};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ use C4::Output;
|
|||
use List::MoreUtils qw /any uniq/;
|
||||
use Koha::DateUtils qw( dt_from_string );
|
||||
use Koha::List::Patron;
|
||||
use Koha::Patron::Categories;
|
||||
|
||||
my $input = new CGI;
|
||||
my $op = $input->param('op') || 'show_form';
|
||||
|
|
@ -377,7 +378,7 @@ sub GetBorrowerInfos {
|
|||
}
|
||||
$borrower->{$_} = $userdate || '';
|
||||
}
|
||||
$borrower->{category_description} = GetBorrowercategory( $borrower->{categorycode} )->{description};
|
||||
$borrower->{category_description} = Koha::Patron::Categories->find( $borrower->{categorycode} )->{description};
|
||||
my $attr_loop = C4::Members::Attributes::GetBorrowerAttributes( $borrower->{borrowernumber} );
|
||||
$borrower->{patron_attributes} = $attr_loop;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,8 +129,8 @@ if ($op eq 'save') {
|
|||
|
||||
foreach my $bor (keys %temphash){
|
||||
# get category name if we need it for an error message
|
||||
my $bor_category = GetBorrowercategory($bor);
|
||||
my $bor_category_name = defined($bor_category) ? $bor_category->{description} : $bor;
|
||||
my $bor_category = Koha::Patron::Categories->find($bor);
|
||||
my $bor_category_name = $bor_category ? $bor_category->description : $bor;
|
||||
|
||||
# Do some Checking here : delay1 < delay2 <delay3 all of them being numbers
|
||||
# Raise error if not true
|
||||
|
|
|
|||
Loading…
Reference in New Issue