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