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

(-)a/C4/Circulation.pm (-40 / +19 lines)
Lines 482-498 sub TooMany { Link Here
482
    # if a rule is found and has a loan limit set, count
482
    # if a rule is found and has a loan limit set, count
483
    # how many loans the patron already has that meet that
483
    # how many loans the patron already has that meet that
484
    # rule
484
    # rule
485
    if ( defined($maxissueqty_rule) and $maxissueqty_rule->rule_value ne "" ) {
485
    if ( defined($maxissueqty_rule) and $maxissueqty_rule->rule_value ne "" ) {    # FIXME Dont forget onsite checkouts
486
486
487
        my $checkouts;
487
        my $checkouts;
488
        my $prefetch = { prefetch => 'item' };
488
        my $prefetch = { prefetch => 'item' };
489
        if ( !$maxissueqty_rule->branchcode ) {    # global level: look at all checkouts
489
        if ( !$maxissueqty_rule->branchcode ) {                                    # global level: look at all checkouts
490
            $checkouts = $patron->checkouts( undef, $prefetch );
490
            $checkouts = $patron->checkouts( undef, $prefetch );
491
        } elsif ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) {
491
        } elsif ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) {
492
            $checkouts = $patron->checkouts->search( { 'me.branchcode' => $branch }, $prefetch );
492
            $checkouts = $patron->checkouts->search( { 'me.branchcode' => $branch }, $prefetch );
493
        } elsif ( C4::Context->preference('CircControl') eq 'PatronLibrary' ) {
493
        } elsif ( C4::Context->preference('CircControl') eq 'PatronLibrary' ) {
494
            $checkouts = $patron->checkouts->search( { "item.$branch_type" => $branch }, $prefetch );
494
            $checkouts = $patron->checkouts->search( { "item.$branch_type" => $branch }, $prefetch );
495
        } else {                                   # ItemHomeLibrary
495
        } else {                                                                   # ItemHomeLibrary
496
            $checkouts = $patron->checkouts->search( { "item.$branch_type" => $branch }, $prefetch );
496
            $checkouts = $patron->checkouts->search( { "item.$branch_type" => $branch }, $prefetch );
497
        }
497
        }
498
498
Lines 543-549 sub TooMany { Link Here
543
            }
543
            }
544
544
545
            $sum_checkouts->{total}++;
545
            $sum_checkouts->{total}++;
546
            $sum_checkouts->{onsite_checkouts}++ if $c->onsite_checkout;
546
            $sum_checkouts->{onsite_checkouts}++ if $c->onsite_checkout;    #FIXME Scope issue?
547
            $sum_checkouts->{itemtype}->{$itemtype}++;
547
            $sum_checkouts->{itemtype}->{$itemtype}++;
548
        }
548
        }
549
549
Lines 586-610 sub TooMany { Link Here
586
586
587
    # Now count total loans against the limit for the branch
587
    # Now count total loans against the limit for the branch
588
    my $branch_borrower_circ_rule = GetBranchBorrowerCircRule( $branch, $cat_borrower );
588
    my $branch_borrower_circ_rule = GetBranchBorrowerCircRule( $branch, $cat_borrower );
589
    if ( defined( $branch_borrower_circ_rule->{patron_maxissueqty} )
589
    my $regular_rule              = $branch_borrower_circ_rule->{patron_maxissueqty};
590
        and $branch_borrower_circ_rule->{patron_maxissueqty} ne '' )
590
    my $onsite_rule               = $branch_borrower_circ_rule->{patron_maxonsiteissueqty};
591
    {
591
    if ( $regular_rule && $regular_rule->rule_value ne '' ) {    # FIXME onsite_rule only or other level?
592
        my $checkouts;
592
        my $checkouts;
593
        my $prefetch = { prefetch => 'item' };
593
        my $prefetch = { prefetch => 'item' };
594
        if ( !$branch_borrower_circ_rule->{branchcode} ) {    # global level: look at all checkouts
594
        if ( !$regular_rule->branchcode ) {                      # global level: look at all checkouts
595
            $checkouts = $patron->checkouts;
595
            $checkouts = $patron->checkouts;
596
        } elsif ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) {
596
        } elsif ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) {
597
            $checkouts = $patron->checkouts->search( { 'me.branchcode' => $branch } );
597
            $checkouts = $patron->checkouts->search( { 'me.branchcode' => $branch } );
598
        } elsif ( C4::Context->preference('CircControl') eq 'PatronLibrary' ) {
598
        } elsif ( C4::Context->preference('CircControl') eq 'PatronLibrary' ) {
599
            $checkouts = $patron->checkouts->search( { "item.$branch_type" => $branch }, $prefetch );
599
            $checkouts = $patron->checkouts->search( { "item.$branch_type" => $branch }, $prefetch );
600
        } else {                                              # ItemHomeLibrary
600
        } else {                                                 # ItemHomeLibrary
601
            $checkouts = $patron->checkouts->search( { "item.$branch_type" => $branch }, $prefetch );
601
            $checkouts = $patron->checkouts->search( { "item.$branch_type" => $branch }, $prefetch );
602
        }
602
        }
603
603
604
        my $checkout_count               = $checkouts->count;
604
        my $checkout_count               = $checkouts->count;
605
        my $onsite_checkout_count        = $checkouts->search( { onsite_checkout => 1 } )->count;
605
        my $onsite_checkout_count        = $checkouts->search( { onsite_checkout => 1 } )->count;
606
        my $max_checkouts_allowed        = $branch_borrower_circ_rule->{patron_maxissueqty};
606
        my $max_checkouts_allowed        = $regular_rule->rule_value;
607
        my $max_onsite_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxonsiteissueqty} || undef;
607
        my $max_onsite_checkouts_allowed = $onsite_rule ? $onsite_rule->rule_value : undef;
608
608
609
        my $qty_over = _check_max_qty(
609
        my $qty_over = _check_max_qty(
610
            {
610
            {
Lines 614-620 sub TooMany { Link Here
614
                max_checkouts_allowed        => $max_checkouts_allowed,
614
                max_checkouts_allowed        => $max_checkouts_allowed,
615
                max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed,
615
                max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed,
616
                switch_onsite_checkout       => $switch_onsite_checkout,
616
                switch_onsite_checkout       => $switch_onsite_checkout,
617
                circulation_rule             => $branch_borrower_circ_rule,
617
                circulation_rule             => $regular_rule,
618
                onsite_circulation_rule      => $onsite_rule,
618
            }
619
            }
619
        );
620
        );
620
        return $qty_over if defined $qty_over;
621
        return $qty_over if defined $qty_over;
Lines 2061-2090 sub GetHardDueDate { Link Here
2061
2062
2062
  my $branch_cat_rule = GetBranchBorrowerCircRule($branchcode, $categorycode);
2063
  my $branch_cat_rule = GetBranchBorrowerCircRule($branchcode, $categorycode);
2063
2064
2064
Retrieves circulation rule attributes that apply to the given
2065
Returns hash with two circulation rules (for patron_maxissueqty and
2065
branch and patron category, regardless of item type.  
2066
patron_maxonsiteissueqty) that apply to the given branch and
2066
The return value is a hashref containing the following key:
2067
patron category, regardless of item type.
2067
2068
patron_maxissueqty - maximum number of loans that a
2069
patron of the given category can have at the given
2070
branch.  If the value is undef, no limit.
2071
2068
2072
patron_maxonsiteissueqty - maximum of on-site checkouts that a
2069
Checks different branch/category combinations in the following order:
2073
patron of the given category can have at the given
2074
branch.  If the value is undef, no limit.
2075
2076
This will check for different branch/category combinations in the following order:
2077
branch and category
2070
branch and category
2078
branch only
2071
branch only
2079
category only
2072
category only
2080
default branch and category
2073
default branch and category
2081
2074
2082
If no rule has been found in the database, it will default to
2083
the built in rule:
2084
2085
patron_maxissueqty - undef
2086
patron_maxonsiteissueqty - undef
2087
2088
C<$branchcode> and C<$categorycode> should contain the
2075
C<$branchcode> and C<$categorycode> should contain the
2089
literal branch code and patron category code, respectively - no
2076
literal branch code and patron category code, respectively - no
2090
wildcards.
2077
wildcards.
Lines 2094-2108 wildcards. Link Here
2094
sub GetBranchBorrowerCircRule {
2081
sub GetBranchBorrowerCircRule {
2095
    my ( $branchcode, $categorycode ) = @_;
2082
    my ( $branchcode, $categorycode ) = @_;
2096
2083
2097
    # Initialize default values
2098
    my $rules = {
2099
        patron_maxissueqty       => undef,
2100
        patron_maxonsiteissueqty => undef,
2101
    };
2102
2103
    # Search for rules!
2084
    # Search for rules!
2085
    my $rules;
2104
    foreach my $rule_name (qw( patron_maxissueqty patron_maxonsiteissueqty )) {
2086
    foreach my $rule_name (qw( patron_maxissueqty patron_maxonsiteissueqty )) {
2105
        my $rule = Koha::CirculationRules->get_effective_rule(
2087
        $rules->{$rule_name} = Koha::CirculationRules->get_effective_rule(
2106
            {
2088
            {
2107
                categorycode => $categorycode,
2089
                categorycode => $categorycode,
2108
                itemtype     => undef,
2090
                itemtype     => undef,
Lines 2110-2117 sub GetBranchBorrowerCircRule { Link Here
2110
                rule_name    => $rule_name,
2092
                rule_name    => $rule_name,
2111
            }
2093
            }
2112
        );
2094
        );
2113
2114
        $rules->{$rule_name} = $rule->rule_value if defined $rule;
2115
    }
2095
    }
2116
2096
2117
    return $rules;
2097
    return $rules;
2118
- 

Return to bug 41280