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 470-475 foreach my $biblioNum (@biblionumbers) { Link Here
470
        my $item = Koha::Items->find( $itemNum );
491
        my $item = Koha::Items->find( $itemNum );
471
        my $itemLoopIter = {};
492
        my $itemLoopIter = {};
472
493
494
        $itemLoopIter->{item} = $item;
473
        $itemLoopIter->{itemnumber} = $itemNum;
495
        $itemLoopIter->{itemnumber} = $itemNum;
474
        $itemLoopIter->{barcode} = $itemInfo->{barcode};
496
        $itemLoopIter->{barcode} = $itemInfo->{barcode};
475
        $itemLoopIter->{homeBranchName} = $itemInfo->{homebranch};
497
        $itemLoopIter->{homeBranchName} = $itemInfo->{homebranch};
Lines 564-577 foreach my $biblioNum (@biblionumbers) { Link Here
564
                $biblioLoopIter{force_hold} = 1 if $opac_hold_policy eq 'F';
586
                $biblioLoopIter{force_hold} = 1 if $opac_hold_policy eq 'F';
565
            }
587
            }
566
            $numCopiesAvailable++;
588
            $numCopiesAvailable++;
567
568
            unless ( $can_place_hold_if_available_at_pickup ) {
569
                my $items_in_this_library = Koha::Items->search({ biblionumber => $itemInfo->{biblionumber}, holdingbranch => $itemInfo->{holdingbranch} });
570
                my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count;
571
                if ( $items_in_this_library->count > $nb_of_items_issued ) {
572
                    push @not_available_at, $itemInfo->{holdingbranch};
573
                }
574
            }
575
        }
589
        }
576
590
577
        $itemLoopIter->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itemInfo->{itype} }{imageurl} );
591
        $itemLoopIter->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itemInfo->{itype} }{imageurl} );
Lines 587-592 foreach my $biblioNum (@biblionumbers) { Link Here
587
601
588
        push @{$biblioLoopIter{itemLoop}}, $itemLoopIter;
602
        push @{$biblioLoopIter{itemLoop}}, $itemLoopIter;
589
    }
603
    }
604
590
    $template->param(
605
    $template->param(
591
        itemdata_enumchron => $itemdata_enumchron,
606
        itemdata_enumchron => $itemdata_enumchron,
592
        itemdata_ccode     => $itemdata_ccode,
607
        itemdata_ccode     => $itemdata_ccode,
Lines 608-621 foreach my $biblioNum (@biblionumbers) { Link Here
608
    }
623
    }
609
624
610
    if ( $biblioLoopIter{holdable} ) {
625
    if ( $biblioLoopIter{holdable} ) {
611
        @not_available_at = uniq @not_available_at;
626
        unless ($can_place_hold_if_available_at_pickup) {
612
        $biblioLoopIter{not_available_at} = \@not_available_at ;
627
            # Search for libraries where the hold cannot be picked up at
613
    }
628
            my @branchcodes = uniq map { $_->{item}->holdingbranch } @{ $biblioLoopIter{itemLoop} };
629
            for my $branchcode (@branchcodes) {
630
                # The hold avaibility has been calculated before, retrieving the items
631
                my @availables_for_hold_in_this_library = map {
632
                    $_->{item}->holdingbranch eq $branchcode
633
                      && exists $_->{available} && $_->{available}
634
                      ? $_->{item}
635
                      : ()
636
                } @{ $biblioLoopIter{itemLoop} };
637
638
                if ( @availables_for_hold_in_this_library > 0 ) {
639
                    # Searching for items available for hold but that are not checked out
640
                    my $items_in_this_library = Koha::Items->search(
641
                        {
642
                            'me.itemnumber' => {
643
                                -in => [
644
                                    map { $_->itemnumber } @availables_for_hold_in_this_library
645
                                ]
646
                            }
647
                        }
648
                    );
649
                    my $checked_out_items = $items_in_this_library->search(
650
                        { 'issue.itemnumber' => { not => undef } },
651
                        { join               => 'issue' } );
652
                    # If there are not all checked out, the library cannot be used to pickup the hold
653
                    push @not_available_at, $branchcode
654
                        if $items_in_this_library->count > $checked_out_items->count;
655
                }
656
            }
657
        }
614
658
615
    unless ( $can_place_hold_if_available_at_pickup ) {
616
        @not_available_at = uniq @not_available_at;
659
        @not_available_at = uniq @not_available_at;
617
        $biblioLoopIter{not_available_at} = \@not_available_at ;
660
        $biblioLoopIter{not_available_at} = \@not_available_at ;
618
        # The record is not holdable is not available at any of the libraries
661
662
        # The record is not holdable if not available at any of the libraries
619
        if ( Koha::Libraries->search->count == @not_available_at ) {
663
        if ( Koha::Libraries->search->count == @not_available_at ) {
620
            $biblioLoopIter{holdable} = 0;
664
            $biblioLoopIter{holdable} = 0;
621
        }
665
        }
622
- 

Return to bug 24160