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

(-)a/C4/Circulation.pm (-23 / +19 lines)
Lines 435-442 sub TooMany { Link Here
435
    my $dbh                    = C4::Context->dbh;
435
    my $dbh                    = C4::Context->dbh;
436
436
437
    # Get which branchcode we need
437
    # Get which branchcode we need
438
    my $branch = _GetCircControlBranch( $item, $patron );
438
    my $branch      = _GetCircControlBranch( $item, $patron );
439
    my $type   = $item->effective_itemtype;
439
    my $type        = $item->effective_itemtype;
440
    my $branch_type = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch';
440
441
441
    my ( $type_object, $parent_type, $parent_maxissueqty_rule );
442
    my ( $type_object, $parent_type, $parent_maxissueqty_rule );
442
    $type_object = Koha::ItemTypes->find($type);
443
    $type_object = Koha::ItemTypes->find($type);
Lines 484-502 sub TooMany { Link Here
484
    if ( defined($maxissueqty_rule) and $maxissueqty_rule->rule_value ne "" ) {
485
    if ( defined($maxissueqty_rule) and $maxissueqty_rule->rule_value ne "" ) {
485
486
486
        my $checkouts;
487
        my $checkouts;
487
        if ( $maxissueqty_rule->branchcode ) {
488
        my $prefetch = { prefetch => 'item' };
488
            if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) {
489
        if ( !$maxissueqty_rule->branchcode ) {    # global level: look at all checkouts
489
                $checkouts = $patron->checkouts->search( { 'me.branchcode' => $maxissueqty_rule->branchcode } );
490
            $checkouts = $patron->checkouts( undef, $prefetch );
490
            } elsif ( C4::Context->preference('CircControl') eq 'PatronLibrary' ) {
491
        } elsif ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) {
491
                $checkouts = $patron->checkouts; # if branch is the patron's home branch, then count all loans by patron
492
            $checkouts = $patron->checkouts->search( { 'me.branchcode' => $branch }, $prefetch );
492
            } else {
493
        } elsif ( C4::Context->preference('CircControl') eq 'PatronLibrary' ) {
493
                my $branch_type = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch';
494
            $checkouts = $patron->checkouts->search( { "item.$branch_type" => $branch }, $prefetch );
494
                $checkouts = $patron->checkouts->search( { "item.$branch_type" => $maxissueqty_rule->branchcode } );
495
        } else {                                   # ItemHomeLibrary
495
            }
496
            $checkouts = $patron->checkouts->search( { "item.$branch_type" => $branch }, $prefetch );
496
        } else {
497
            $checkouts = $patron->checkouts;     # if rule is not branch specific then count all loans by patron
498
        }
497
        }
499
        $checkouts = $checkouts->search( undef, { prefetch => 'item' } );
500
498
501
        my $sum_checkouts;
499
        my $sum_checkouts;
502
        my $rule_itemtype = $maxissueqty_rule->itemtype;
500
        my $rule_itemtype = $maxissueqty_rule->itemtype;
Lines 591-607 sub TooMany { Link Here
591
    if ( defined( $branch_borrower_circ_rule->{patron_maxissueqty} )
589
    if ( defined( $branch_borrower_circ_rule->{patron_maxissueqty} )
592
        and $branch_borrower_circ_rule->{patron_maxissueqty} ne '' )
590
        and $branch_borrower_circ_rule->{patron_maxissueqty} ne '' )
593
    {
591
    {
594
        my $checkouts = $patron->checkouts;
592
        my $checkouts;
593
        my $prefetch = { prefetch => 'item' };
595
        if ( !$branch_borrower_circ_rule->{branchcode} ) {    # global level: look at all checkouts
594
        if ( !$branch_borrower_circ_rule->{branchcode} ) {    # global level: look at all checkouts
596
        } elsif ( C4::Context->preference('CircControl') eq 'PatronLibrary' ) {    # do the same
595
            $checkouts = $patron->checkouts;
597
        } elsif ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) {
596
        } elsif ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) {
598
            $checkouts = $patron->checkouts->search( { 'me.branchcode' => $branch } );
597
            $checkouts = $patron->checkouts->search( { 'me.branchcode' => $branch } );
599
        } else {
598
        } elsif ( C4::Context->preference('CircControl') eq 'PatronLibrary' ) {
600
            my $branch_type = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch';
599
            $checkouts = $patron->checkouts->search( { "item.$branch_type" => $branch }, $prefetch );
601
            $checkouts = $patron->checkouts->search(
600
        } else {                                              # ItemHomeLibrary
602
                { "item.$branch_type" => $branch },
601
            $checkouts = $patron->checkouts->search( { "item.$branch_type" => $branch }, $prefetch );
603
                { prefetch            => 'item' }
604
            );
605
        }
602
        }
606
603
607
        my $checkout_count               = $checkouts->count;
604
        my $checkout_count               = $checkouts->count;
608
- 

Return to bug 41280