@@ -, +, @@ - http://prntscr.com/cz7ch3 - http://prntscr.com/cz7em4 - http://prntscr.com/cz7dj1 http://prntscr.com/cz7g5q --- Koha/Patron.pm | 18 ++++++++++++++++++ circ/circulation.pl | 10 +++------- members/moremember.pl | 16 ++++------------ 3 files changed, 25 insertions(+), 19 deletions(-) --- a/Koha/Patron.pm +++ a/Koha/Patron.pm @@ -568,6 +568,24 @@ sub get_age { return $age; } +=head3 is_category_valid + +my $is_valid = $patron->is_category_valid + +Return 1 if patron's age is between allowed limits, returns 0 if it's not. + +=cut + +sub is_category_valid { + my ($self) = @_; + my $age = $self->get_age; + + my $patroncategory = $self->category; + my ($low,$high) = ($patroncategory->dateofbirthrequired, $patroncategory->upperagelimit); + + return (($high && ($age > $high)) or ($age < $low)) ? 0 : 1; +} + =head3 account my $account = $patron->account --- a/circ/circulation.pl +++ a/circ/circulation.pl @@ -304,14 +304,10 @@ if ($patron) { } # Calculate and display patron's age - my $age = $patron->get_age; - - my $patroncategory = $patron->category; - my ($low,$high) = ($patroncategory->dateofbirthrequired, $patroncategory->upperagelimit); - if (($high && ($age > $high)) or ($age < $low)) { + if ( !$patron->is_category_valid ) { $template->param( age_limitations => 1 ); - $template->param( age_low => $low ); - $template->param( age_high => $high ); + $template->param( age_low => $patron->category->dateofbirthrequired ); + $template->param( age_high => $patron->category->upperagelimit ); } } --- a/members/moremember.pl +++ a/members/moremember.pl @@ -246,20 +246,12 @@ my $overdues_exist = 0; my $totalprice = 0; # Calculate and display patron's age -my $age; -if ( $data->{dateofbirth} ) { - $age = Koha::Patron->new({ dateofbirth => $data->{dateofbirth} })->get_age; - $template->param( age => $age ); -} - -# Check patron's category against age -my $patroncategory = Koha::Patron::Categories->find($data->{ 'categorycode' }); -my ($low,$high) = ($patroncategory->dateofbirthrequired, $patroncategory->upperagelimit); -if (($high && ($age > $high)) or ($age < $low)) { +if ( !$patron->is_category_valid ) { $template->param( age_limitations => 1 ); - $template->param( age_low => $low ); - $template->param( age_high => $high ); + $template->param( age_low => $patron->category->dateofbirthrequired ); + $template->param( age_high => $patron->category->upperagelimit ); } +$template->param( age => $patron->get_age ); ### ############################################################################### --