View | Details | Raw Unified | Return to bug 17492
Collapse All | Expand All

(-)a/Koha/Patron.pm (+18 lines)
Lines 977-982 sub get_age { Link Here
977
    return $age;
977
    return $age;
978
}
978
}
979
979
980
=head3 is_category_valid
981
982
my $is_valid = $patron->is_category_valid
983
984
Return 1 if patron's age is between allowed limits, returns 0 if it's not.
985
986
=cut
987
988
sub is_category_valid {
989
    my ($self) = @_;
990
    my $age = $self->get_age;
991
992
    my $patroncategory = $self->category;
993
    my ($low,$high) = ($patroncategory->dateofbirthrequired, $patroncategory->upperagelimit);
994
995
    return (defined($age) && (($high && ($age > $high)) or ($age < $low))) ? 0 : 1;
996
}
997
980
=head3 account
998
=head3 account
981
999
982
my $account = $patron->account
1000
my $account = $patron->account
(-)a/circ/circulation.pl (+7 lines)
Lines 320-325 if ($patron) { Link Here
320
        }
320
        }
321
    }
321
    }
322
322
323
    # Calculate and display patron's age
324
    if ( !$patron->is_category_valid ) {
325
        $template->param( age_limitations => 1 );
326
        $template->param( age_low => $patron->category->dateofbirthrequired );
327
        $template->param( age_high => $patron->category->upperagelimit );
328
    }
329
323
}
330
}
324
331
325
#
332
#
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/category-out-of-age-limit.inc (+4 lines)
Line 0 Link Here
1
    <li>
2
    <span class="circ-hlt">Patron's age is incorrect for their category.</span>
3
    Ages allowed are [% age_low %]-[% age_high %].
4
    <a href="/cgi-bin/koha/members/memberentry.pl?op=modify&amp;borrowernumber=[% borrowernumber %]&amp;step=3" class="btn btn-default btn-xs">Change category</a></li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (+4 lines)
Lines 743-748 Link Here
743
                                        [% INCLUDE 'blocked-fines.inc' fines = chargesamount %]
743
                                        [% INCLUDE 'blocked-fines.inc' fines = chargesamount %]
744
                                    [% END %]
744
                                    [% END %]
745
745
746
                                    [% IF age_limitations %]
747
                                        [% INCLUDE 'category-out-of-age-limit.inc' %]
748
                                    [% END %]
749
746
                                    [% IF ( charges_guarantees ) %]
750
                                    [% IF ( charges_guarantees ) %]
747
                                        <li>
751
                                        <li>
748
                                            <span class="circ-hlt">Fees &amp; Charges:</span> Patron's guarantees collectively owe [% chargesamount_guarantees | $Price %].
752
                                            <span class="circ-hlt">Fees &amp; Charges:</span> Patron's guarantees collectively owe [% chargesamount_guarantees | $Price %].
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt (-2 / +7 lines)
Lines 71-80 Link Here
71
                            </div>
71
                            </div>
72
                        [% END %]
72
                        [% END %]
73
73
74
                        [% IF fines %]
74
                        [% IF fines || age_limitations %]
75
                            <div id="circmessages" class="circmessage attention">
75
                            <div id="circmessages" class="circmessage attention">
76
                                <ul>
76
                                <ul>
77
                                    [% INCLUDE 'blocked-fines.inc' %]
77
                                    [% IF fines %]
78
                                        [% INCLUDE 'blocked-fines.inc' %]
79
                                    [% END %]
80
                                    [% IF age_limitations %]
81
                                        [% INCLUDE 'category-out-of-age-limit.inc' %]
82
                                    [% END %]
78
                                </ul>
83
                                </ul>
79
                            </div>
84
                            </div>
80
                        [% END %]
85
                        [% END %]
(-)a/members/moremember.pl (+8 lines)
Lines 119-124 if ( my $guarantor = $patron->guarantor ) { Link Here
119
my $relatives_issues_count =
119
my $relatives_issues_count =
120
    Koha::Checkouts->count({ borrowernumber => \@relatives });
120
    Koha::Checkouts->count({ borrowernumber => \@relatives });
121
121
122
# Calculate and display patron's age
123
if ( !$patron->is_category_valid ) {
124
    $template->param( age_limitations => 1 );
125
    $template->param( age_low => $patron->category->dateofbirthrequired );
126
    $template->param( age_high => $patron->category->upperagelimit );
127
}
128
$template->param( age => $patron->get_age );
129
122
# Generate CSRF token for upload and delete image buttons
130
# Generate CSRF token for upload and delete image buttons
123
$template->param(
131
$template->param(
124
    csrf_token => Koha::Token->new->generate_csrf({ session_id => $input->cookie('CGISESSID'),}),
132
    csrf_token => Koha::Token->new->generate_csrf({ session_id => $input->cookie('CGISESSID'),}),
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +59 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 39;
22
use Test::More tests => 40;
23
use Test::Warn;
23
use Test::Warn;
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
Lines 639-644 subtest 'get_age' => sub { Link Here
639
    $patron->delete;
639
    $patron->delete;
640
};
640
};
641
641
642
subtest 'is_category_valid' => sub {
643
    plan tests => 10;
644
645
    my $today = dt_from_string;
646
647
    my $category = $builder->build({
648
        source => 'Category',
649
        value => {
650
            categorycode        => 'AGE_5_10',
651
            dateofbirthrequired => 5,
652
            upperagelimit       => 10
653
        }
654
    });
655
    $category = Koha::Patron::Categories->find( $category->{categorycode} );
656
657
    my $patron = $builder->build({
658
        source => 'Borrower',
659
        value => {
660
            categorycode        => 'AGE_5_10'
661
        }
662
    });
663
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
664
665
666
    $patron->dateofbirth( undef );
667
    is( $patron->is_category_valid, 1, 'Patron with no dateofbirth is always valid for any category');
668
669
    $patron->dateofbirth( $today->clone->add( years => -12, months => -6, days => -1 ) );
670
    is( $patron->is_category_valid, 0, 'Patron is 12, so the age is above allowed range 5-10 years');
671
672
    $patron->dateofbirth( $today->clone->add( years => -3, months => -6, days => -1 ) );
673
    is( $patron->is_category_valid, 0, 'Patron is 3, so the age is below allowed range 5-10 years');
674
675
    $patron->dateofbirth( $today->clone->add( years => -7, months => -6, days => -1 ) );
676
    is( $patron->is_category_valid, 1, 'Patron is 7, so the age perfectly suits allowed range 5-10 years');
677
678
    $patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => 0 ) );
679
    is( $patron->is_category_valid, 1, 'Patron celebrates the 5th birthday today, so the age is allowed for this category');
680
681
    $patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => 1 ) );
682
    is( $patron->is_category_valid, 0, 'Patron will celebrate the 5th birthday tomorrow, so the age is NOT allowed for this category');
683
684
    $patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => -1 ) );
685
    is( $patron->is_category_valid, 1, 'Patron celebrated the 5th birthday yesterday, so the age is allowed for this category');
686
687
    $patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => 0 ) );
688
    is( $patron->is_category_valid, 0, 'Patron celebrate the 11th birthday today, so the age is NOT allowed for this category');
689
690
    $patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => 1 ) );
691
    is( $patron->is_category_valid, 1, 'Patron will celebrate the 11th birthday tomorrow, so the age is allowed for this category');
692
693
    $patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => -1 ) );
694
    is( $patron->is_category_valid, 0, 'Patron celebrated the 11th birthday yesterday, so the age is NOT allowed for this category');
695
696
    $patron->delete;
697
    $category->delete;
698
};
699
642
subtest 'account' => sub {
700
subtest 'account' => sub {
643
    plan tests => 1;
701
    plan tests => 1;
644
702
645
- 

Return to bug 17492