@@ -, +, @@ button to update it - http://prntscr.com/cz7ch3 - http://prntscr.com/cz7em4 - http://prntscr.com/cz7dj1 http://prntscr.com/cz7g5q --- Koha/Patron.pm | 18 +++++++ circ/circulation.pl | 7 +++ .../prog/en/includes/category-out-of-age-limit.inc | 4 ++ .../prog/en/modules/circ/circulation.tt | 4 ++ .../prog/en/modules/members/moremember.tt | 9 +++- members/moremember.pl | 8 +++ t/db_dependent/Koha/Patrons.t | 60 +++++++++++++++++++++- 7 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/category-out-of-age-limit.inc --- a/Koha/Patron.pm +++ a/Koha/Patron.pm @@ -977,6 +977,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 (defined($age) && (($high && ($age > $high)) or ($age < $low))) ? 0 : 1; +} + =head3 account my $account = $patron->account --- a/circ/circulation.pl +++ a/circ/circulation.pl @@ -320,6 +320,13 @@ if ($patron) { } } + # Calculate and display patron's age + if ( !$patron->is_category_valid ) { + $template->param( age_limitations => 1 ); + $template->param( age_low => $patron->category->dateofbirthrequired ); + $template->param( age_high => $patron->category->upperagelimit ); + } + } # --- a/koha-tmpl/intranet-tmpl/prog/en/includes/category-out-of-age-limit.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/category-out-of-age-limit.inc @@ -0,0 +1,4 @@ +
  • + Patron's age is incorrect for their category. + Ages allowed are [% age_low %]-[% age_high %]. + Change category
  • --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -743,6 +743,10 @@ [% INCLUDE 'blocked-fines.inc' fines = chargesamount %] [% END %] + [% IF age_limitations %] + [% INCLUDE 'category-out-of-age-limit.inc' %] + [% END %] + [% IF ( charges_guarantees ) %]
  • Fees & Charges: Patron's guarantees collectively owe [% chargesamount_guarantees | $Price %]. --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -71,10 +71,15 @@ [% END %] - [% IF fines %] + [% IF fines || age_limitations %]
    [% END %] --- a/members/moremember.pl +++ a/members/moremember.pl @@ -119,6 +119,14 @@ if ( my $guarantor = $patron->guarantor ) { my $relatives_issues_count = Koha::Checkouts->count({ borrowernumber => \@relatives }); +# Calculate and display patron's age +if ( !$patron->is_category_valid ) { + $template->param( age_limitations => 1 ); + $template->param( age_low => $patron->category->dateofbirthrequired ); + $template->param( age_high => $patron->category->upperagelimit ); +} +$template->param( age => $patron->get_age ); + # Generate CSRF token for upload and delete image buttons $template->param( csrf_token => Koha::Token->new->generate_csrf({ session_id => $input->cookie('CGISESSID'),}), --- a/t/db_dependent/Koha/Patrons.t +++ a/t/db_dependent/Koha/Patrons.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 39; +use Test::More tests => 40; use Test::Warn; use Test::Exception; use Test::MockModule; @@ -639,6 +639,64 @@ subtest 'get_age' => sub { $patron->delete; }; +subtest 'is_category_valid' => sub { + plan tests => 10; + + my $today = dt_from_string; + + my $category = $builder->build({ + source => 'Category', + value => { + categorycode => 'AGE_5_10', + dateofbirthrequired => 5, + upperagelimit => 10 + } + }); + $category = Koha::Patron::Categories->find( $category->{categorycode} ); + + my $patron = $builder->build({ + source => 'Borrower', + value => { + categorycode => 'AGE_5_10' + } + }); + $patron = Koha::Patrons->find( $patron->{borrowernumber} ); + + + $patron->dateofbirth( undef ); + is( $patron->is_category_valid, 1, 'Patron with no dateofbirth is always valid for any category'); + + $patron->dateofbirth( $today->clone->add( years => -12, months => -6, days => -1 ) ); + is( $patron->is_category_valid, 0, 'Patron is 12, so the age is above allowed range 5-10 years'); + + $patron->dateofbirth( $today->clone->add( years => -3, months => -6, days => -1 ) ); + is( $patron->is_category_valid, 0, 'Patron is 3, so the age is below allowed range 5-10 years'); + + $patron->dateofbirth( $today->clone->add( years => -7, months => -6, days => -1 ) ); + is( $patron->is_category_valid, 1, 'Patron is 7, so the age perfectly suits allowed range 5-10 years'); + + $patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => 0 ) ); + is( $patron->is_category_valid, 1, 'Patron celebrates the 5th birthday today, so the age is allowed for this category'); + + $patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => 1 ) ); + is( $patron->is_category_valid, 0, 'Patron will celebrate the 5th birthday tomorrow, so the age is NOT allowed for this category'); + + $patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => -1 ) ); + is( $patron->is_category_valid, 1, 'Patron celebrated the 5th birthday yesterday, so the age is allowed for this category'); + + $patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => 0 ) ); + is( $patron->is_category_valid, 0, 'Patron celebrate the 11th birthday today, so the age is NOT allowed for this category'); + + $patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => 1 ) ); + is( $patron->is_category_valid, 1, 'Patron will celebrate the 11th birthday tomorrow, so the age is allowed for this category'); + + $patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => -1 ) ); + is( $patron->is_category_valid, 0, 'Patron celebrated the 11th birthday yesterday, so the age is NOT allowed for this category'); + + $patron->delete; + $category->delete; +}; + subtest 'account' => sub { plan tests => 1; --