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

(-)a/C4/Circulation.pm (-41 / +47 lines)
Lines 2668-2720 sub CanBookBeRenewed { Link Here
2668
    {
2668
    {
2669
        my $schema = Koha::Database->new()->schema();
2669
        my $schema = Koha::Database->new()->schema();
2670
2670
2671
        # Get all other items that could possibly fill reserves
2671
        my $item_holds = $schema->resultset('Reserve')->search( { itemnumber => $itemnumber, found => undef } )->count();
2672
        my @itemnumbers = $schema->resultset('Item')->search(
2672
        if ($item_holds) {
2673
            {
2673
            # There is an item level hold on this item, no other item can fill the hold
2674
                biblionumber => $resrec->{biblionumber},
2674
            $resfound = 1;
2675
                onloan       => undef,
2676
                -not         => { itemnumber => $itemnumber }
2677
            },
2678
            { columns => 'itemnumber' }
2679
        )->get_column('itemnumber')->all();
2680
2681
        # Get all other reserves that could have been filled by this item
2682
        my @borrowernumbers;
2683
        while (1) {
2684
            my ( $reserve_found, $reserve, undef ) =
2685
              C4::Reserves::CheckReserves( $itemnumber, undef, undef,
2686
                \@borrowernumbers );
2687
2688
            if ($reserve_found) {
2689
                push( @borrowernumbers, $reserve->{borrowernumber} );
2690
            }
2691
            else {
2692
                last;
2693
            }
2694
        }
2675
        }
2676
        else {
2695
2677
2696
        # If the count of the union of the lists of reservable items for each borrower
2678
            # Get all other items that could possibly fill reserves
2697
        # is equal or greater than the number of borrowers, we know that all reserves
2679
            my @itemnumbers = $schema->resultset('Item')->search(
2698
        # can be filled with available items. We can get the union of the sets simply
2699
        # by pushing all the elements onto an array and removing the duplicates.
2700
        my @reservable;
2701
        foreach my $b (@borrowernumbers) {
2702
            my ( $borr ) = C4::Members::GetMemberDetails( $b );
2703
            foreach my $i (@itemnumbers) {
2704
                my $item   = GetItem($i);
2705
                if (   IsAvailableForItemLevelRequest($item, $borr)
2706
                    && CanItemBeReserved( $b, $i )
2707
                    && !IsItemOnHoldAndFound($i) )
2708
                {
2680
                {
2709
                    push( @reservable, $i );
2681
                    biblionumber => $resrec->{biblionumber},
2682
                    onloan       => undef,
2683
                    -not         => { itemnumber => $itemnumber }
2684
                },
2685
                { columns => 'itemnumber' }
2686
            )->get_column('itemnumber')->all();
2687
2688
            # Get all other reserves that could have been filled by this item
2689
            my @borrowernumbers;
2690
            while (1) {
2691
                my ( $reserve_found, $reserve, undef ) =
2692
                  C4::Reserves::CheckReserves( $itemnumber, undef, undef, \@borrowernumbers );
2693
2694
                if ($reserve_found) {
2695
                    push( @borrowernumbers, $reserve->{borrowernumber} );
2696
                }
2697
                else {
2698
                    last;
2699
                }
2700
            }
2701
2702
            # If the count of the union of the lists of reservable items for each borrower
2703
            # is equal or greater than the number of borrowers, we know that all reserves
2704
            # can be filled with available items. We can get the union of the sets simply
2705
            # by pushing all the elements onto an array and removing the duplicates.
2706
            my @reservable;
2707
            foreach my $b (@borrowernumbers) {
2708
                my ($borr) = C4::Members::GetMemberDetails($b);
2709
                foreach my $i (@itemnumbers) {
2710
                    my $item = GetItem($i);
2711
                    if (   IsAvailableForItemLevelRequest( $item, $borr )
2712
                        && CanItemBeReserved( $b, $i )
2713
                        && !IsItemOnHoldAndFound($i) )
2714
                    {
2715
                        push( @reservable, $i );
2716
                    }
2710
                }
2717
                }
2711
            }
2718
            }
2712
        }
2713
2719
2714
        @reservable = uniq(@reservable);
2720
            @reservable = uniq(@reservable);
2715
2721
2716
        if ( @reservable >= @borrowernumbers ) {
2722
            if ( @reservable >= @borrowernumbers ) {
2717
            $resfound = 0;
2723
                $resfound = 0;
2724
            }
2718
        }
2725
        }
2719
    }
2726
    }
2720
2727
2721
- 

Return to bug 13919