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

(-)a/C4/Circulation.pm (-34 / +17 lines)
Lines 2871-2877 sub CanBookBeRenewed { Link Here
2871
        }
2871
        }
2872
    }
2872
    }
2873
2873
2874
    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber);
2874
    my ( $resfound, $resrec, $possible_reserves ) = C4::Reserves::CheckReserves($itemnumber);
2875
2875
2876
    # If next hold is non priority, then check if any hold with priority (non_priority = 0) exists for the same biblionumber.
2876
    # If next hold is non priority, then check if any hold with priority (non_priority = 0) exists for the same biblionumber.
2877
    if ( $resfound && $resrec->{non_priority} ) {
2877
    if ( $resfound && $resrec->{non_priority} ) {
Lines 2887-2895 sub CanBookBeRenewed { Link Here
2887
    if ( $resfound
2887
    if ( $resfound
2888
        && C4::Context->preference('AllowRenewalIfOtherItemsAvailable') )
2888
        && C4::Context->preference('AllowRenewalIfOtherItemsAvailable') )
2889
    {
2889
    {
2890
        my $schema = Koha::Database->new()->schema();
2890
        my $item_holds = Koha::Holds->search( { itemnumber => $itemnumber, found => undef } )->count();
2891
2892
        my $item_holds = $schema->resultset('Reserve')->search( { itemnumber => $itemnumber, found => undef } )->count();
2893
        if ($item_holds) {
2891
        if ($item_holds) {
2894
            # There is an item level hold on this item, no other item can fill the hold
2892
            # There is an item level hold on this item, no other item can fill the hold
2895
            $resfound = 1;
2893
            $resfound = 1;
Lines 2897-2925 sub CanBookBeRenewed { Link Here
2897
        else {
2895
        else {
2898
2896
2899
            # Get all other items that could possibly fill reserves
2897
            # Get all other items that could possibly fill reserves
2900
            my @itemnumbers = $schema->resultset('Item')->search(
2898
            my $items = Koha::Items->search({
2901
                {
2899
                biblionumber => $resrec->{biblionumber},
2902
                    biblionumber => $resrec->{biblionumber},
2900
                onloan       => undef,
2903
                    onloan       => undef,
2901
                notforloan   => 0,
2904
                    notforloan   => 0,
2902
                -not         => { itemnumber => $itemnumber }
2905
                    -not         => { itemnumber => $itemnumber }
2903
            });
2906
                },
2907
                { columns => 'itemnumber' }
2908
            )->get_column('itemnumber')->all();
2909
2904
2910
            # Get all other reserves that could have been filled by this item
2905
            # Get all other reserves that could have been filled by this item
2911
            my @borrowernumbers;
2906
            my @borrowernumbers = map { $_->{borrowernumber} } @$possible_reserves;
2912
            while (1) {
2907
            my $patrons = Koha::Patrons->search({
2913
                my ( $reserve_found, $reserve, undef ) =
2908
                borrowernumber => { -in => \@borrowernumbers }
2914
                  C4::Reserves::CheckReserves( $itemnumber, undef, undef, \@borrowernumbers );
2909
            });
2915
2916
                if ($reserve_found) {
2917
                    push( @borrowernumbers, $reserve->{borrowernumber} );
2918
                }
2919
                else {
2920
                    last;
2921
                }
2922
            }
2923
2910
2924
            # If the count of the union of the lists of reservable items for each borrower
2911
            # If the count of the union of the lists of reservable items for each borrower
2925
            # is equal or greater than the number of borrowers, we know that all reserves
2912
            # is equal or greater than the number of borrowers, we know that all reserves
Lines 2927-2941 sub CanBookBeRenewed { Link Here
2927
            # by pushing all the elements onto an array and removing the duplicates.
2914
            # by pushing all the elements onto an array and removing the duplicates.
2928
            my @reservable;
2915
            my @reservable;
2929
            my %patrons;
2916
            my %patrons;
2930
            ITEM: foreach my $itemnumber (@itemnumbers) {
2917
            ITEM: while ( my $item = $items->next ) {
2931
                my $item = Koha::Items->find( $itemnumber );
2918
                next if IsItemOnHoldAndFound( $item->itemnumber );
2932
                next if IsItemOnHoldAndFound( $itemnumber );
2919
                while ( my $patron = $patrons->next ) {
2933
                for my $borrowernumber (@borrowernumbers) {
2934
                    my $patron = $patrons{$borrowernumber} //= Koha::Patrons->find( $borrowernumber );
2935
                    next unless IsAvailableForItemLevelRequest($item, $patron);
2920
                    next unless IsAvailableForItemLevelRequest($item, $patron);
2936
                    next unless CanItemBeReserved($borrowernumber,$itemnumber);
2921
                    next unless CanItemBeReserved($patron->borrowernumber,$item->itemnumber);
2937
2922
                    push @reservable, $item->itemnumber;
2938
                    push @reservable, $itemnumber;
2939
                    if (@reservable >= @borrowernumbers) {
2923
                    if (@reservable >= @borrowernumbers) {
2940
                        $resfound = 0;
2924
                        $resfound = 0;
2941
                        last ITEM;
2925
                        last ITEM;
2942
- 

Return to bug 28013