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

(-)a/opac/opac-reserve.pl (-17 / +60 lines)
Lines 295-305 if ( $query->param('place_reserve') ) { Link Here
295
        }
295
        }
296
296
297
        unless ( $can_place_hold_if_available_at_pickup ) {
297
        unless ( $can_place_hold_if_available_at_pickup ) {
298
            # Search for libraries where the hold cannot be picked up at
298
            my $items_in_this_library = Koha::Items->search({ biblionumber => $biblioNum, holdingbranch => $branch });
299
            my $items_in_this_library = Koha::Items->search({ biblionumber => $biblioNum, holdingbranch => $branch });
299
            my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count;
300
            my @availables_for_hold;
300
            my $nb_of_items_unavailable = $items_in_this_library->search({ -or => { lost => { '!=' => 0 }, damaged => { '!=' => 0 }, } });
301
            # The hold avaibility has not been calculated before, we must call CanItemBeReserved here.
301
            if ( $items_in_this_library->count > $nb_of_items_issued + $nb_of_items_unavailable ) {
302
            # Note that the complexity is quite bad here, but until we store the avaibility we will have to calculate it!
303
            while ( my $item = $items_in_this_library->next ) {
304
                push @availables_for_hold, $item
305
                    if CanItemBeReserved( $borrowernumber, $item->itemnumber, $branch )->{status} eq 'OK'
306
            }
307
308
            if ( @availables_for_hold > 0 ) {
309
                my $items = Koha::Items->search(
310
                    {
311
                        'me.itemnumber' => {
312
                            -in =>
313
                              [ map { $_->itemnumber } @availables_for_hold ]
314
                        }
315
                    }
316
                );
317
                my $checked_out_items = $items->search(
318
                    { 'issue.itemnumber' => { not => undef }, },
319
                    { join => 'issue', },
320
                );
321
                # If there are not all checked out, the hold cannot be picked at this library
302
                $canreserve = 0
322
                $canreserve = 0
323
                    if $items->count > $checked_out_items->count;
303
            }
324
            }
304
        }
325
        }
305
326
Lines 461-466 foreach my $biblioNum (@biblionumbers) { Link Here
461
        my $item = Koha::Items->find( $itemNum );
482
        my $item = Koha::Items->find( $itemNum );
462
        my $itemLoopIter = {};
483
        my $itemLoopIter = {};
463
484
485
        $itemLoopIter->{item} = $item;
464
        $itemLoopIter->{itemnumber} = $itemNum;
486
        $itemLoopIter->{itemnumber} = $itemNum;
465
        $itemLoopIter->{barcode} = $itemInfo->{barcode};
487
        $itemLoopIter->{barcode} = $itemInfo->{barcode};
466
        $itemLoopIter->{homeBranchName} = $itemInfo->{homebranch};
488
        $itemLoopIter->{homeBranchName} = $itemInfo->{homebranch};
Lines 555-568 foreach my $biblioNum (@biblionumbers) { Link Here
555
                $biblioLoopIter{force_hold} = 1 if $opac_hold_policy eq 'F';
577
                $biblioLoopIter{force_hold} = 1 if $opac_hold_policy eq 'F';
556
            }
578
            }
557
            $numCopiesAvailable++;
579
            $numCopiesAvailable++;
558
559
            unless ( $can_place_hold_if_available_at_pickup ) {
560
                my $items_in_this_library = Koha::Items->search({ biblionumber => $itemInfo->{biblionumber}, holdingbranch => $itemInfo->{holdingbranch} });
561
                my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count;
562
                if ( $items_in_this_library->count > $nb_of_items_issued ) {
563
                    push @not_available_at, $itemInfo->{holdingbranch};
564
                }
565
            }
566
        }
580
        }
567
581
568
        $itemLoopIter->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itemInfo->{itype} }{imageurl} );
582
        $itemLoopIter->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itemInfo->{itype} }{imageurl} );
Lines 578-583 foreach my $biblioNum (@biblionumbers) { Link Here
578
592
579
        push @{$biblioLoopIter{itemLoop}}, $itemLoopIter;
593
        push @{$biblioLoopIter{itemLoop}}, $itemLoopIter;
580
    }
594
    }
595
581
    $template->param(
596
    $template->param(
582
        itemdata_enumchron => $itemdata_enumchron,
597
        itemdata_enumchron => $itemdata_enumchron,
583
        itemdata_ccode     => $itemdata_ccode,
598
        itemdata_ccode     => $itemdata_ccode,
Lines 599-612 foreach my $biblioNum (@biblionumbers) { Link Here
599
    }
614
    }
600
615
601
    if ( $biblioLoopIter{holdable} ) {
616
    if ( $biblioLoopIter{holdable} ) {
602
        @not_available_at = uniq @not_available_at;
617
        unless ($can_place_hold_if_available_at_pickup) {
603
        $biblioLoopIter{not_available_at} = \@not_available_at ;
618
            # Search for libraries where the hold cannot be picked up at
604
    }
619
            my @branchcodes = uniq map { $_->{item}->holdingbranch } @{ $biblioLoopIter{itemLoop} };
620
            for my $branchcode (@branchcodes) {
621
                # The hold avaibility has been calculated before, retrieving the items
622
                my @availables_for_hold_in_this_library = map {
623
                    $_->{item}->holdingbranch eq $branchcode
624
                      && exists $_->{available} && $_->{available}
625
                      ? $_->{item}
626
                      : ()
627
                } @{ $biblioLoopIter{itemLoop} };
628
629
                if ( @availables_for_hold_in_this_library > 0 ) {
630
                    # Searching for items available for hold but that are not checked out
631
                    my $items_in_this_library = Koha::Items->search(
632
                        {
633
                            'me.itemnumber' => {
634
                                -in => [
635
                                    map { $_->itemnumber } @availables_for_hold_in_this_library
636
                                ]
637
                            }
638
                        }
639
                    );
640
                    my $checked_out_items = $items_in_this_library->search(
641
                        { 'issue.itemnumber' => { not => undef } },
642
                        { join               => 'issue' } );
643
                    # If there are not all checked out, the library cannot be used to pickup the hold
644
                    push @not_available_at, $branchcode
645
                        if $items_in_this_library->count > $checked_out_items->count;
646
                }
647
            }
648
        }
605
649
606
    unless ( $can_place_hold_if_available_at_pickup ) {
607
        @not_available_at = uniq @not_available_at;
650
        @not_available_at = uniq @not_available_at;
608
        $biblioLoopIter{not_available_at} = \@not_available_at ;
651
        $biblioLoopIter{not_available_at} = \@not_available_at ;
609
        # The record is not holdable is not available at any of the libraries
652
653
        # The record is not holdable if not available at any of the libraries
610
        if ( Koha::Libraries->search->count == @not_available_at ) {
654
        if ( Koha::Libraries->search->count == @not_available_at ) {
611
            $biblioLoopIter{holdable} = 0;
655
            $biblioLoopIter{holdable} = 0;
612
        }
656
        }
613
- 

Return to bug 24160