|
Lines 2529-2534
sub GetBiblioIssues {
Link Here
|
| 2529 |
return \@issues; |
2529 |
return \@issues; |
| 2530 |
} |
2530 |
} |
| 2531 |
|
2531 |
|
|
|
2532 |
|
| 2533 |
=head2 IsItemAvailableForCheckout |
| 2534 |
|
| 2535 |
$available = ($itemnumber); |
| 2536 |
|
| 2537 |
Find out whether an item doesn't have any holds, item level or more |
| 2538 |
biblio level holds than there are available items. |
| 2539 |
|
| 2540 |
C<$itemnumber> is the number of the item to check the availability for. |
| 2541 |
|
| 2542 |
=cut |
| 2543 |
sub IsItemAvailableForCheckout { |
| 2544 |
my ($itemnumber) = @_; |
| 2545 |
my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber); |
| 2546 |
|
| 2547 |
# This item can fill one or more unfilled reserve, can those unfilled reserves |
| 2548 |
# all be filled by other available items? |
| 2549 |
if ( $resfound ) |
| 2550 |
{ |
| 2551 |
my $schema = Koha::Database->new()->schema(); |
| 2552 |
|
| 2553 |
my $item_holds = $schema->resultset('Reserve')->search( { itemnumber => $itemnumber, found => undef } )->count(); |
| 2554 |
if ($item_holds) { |
| 2555 |
# There is an item level hold on this item, no other item can fill the hold |
| 2556 |
$resfound = 1; |
| 2557 |
} |
| 2558 |
else { |
| 2559 |
|
| 2560 |
# Get all other items that could possibly fill reserves |
| 2561 |
my @itemnumbers = $schema->resultset('Item')->search( |
| 2562 |
{ |
| 2563 |
biblionumber => $resrec->{biblionumber}, |
| 2564 |
onloan => undef, |
| 2565 |
notforloan => 0, |
| 2566 |
-not => { itemnumber => $itemnumber } |
| 2567 |
}, |
| 2568 |
{ columns => 'itemnumber' } |
| 2569 |
)->get_column('itemnumber')->all(); |
| 2570 |
|
| 2571 |
# Get all other reserves that could have been filled by this item |
| 2572 |
my @borrowernumbers; |
| 2573 |
while (1) { |
| 2574 |
my ( $reserve_found, $reserve, undef ) = |
| 2575 |
C4::Reserves::CheckReserves( $itemnumber, undef, undef, \@borrowernumbers ); |
| 2576 |
|
| 2577 |
if ($reserve_found) { |
| 2578 |
push( @borrowernumbers, $reserve->{borrowernumber} ); |
| 2579 |
} |
| 2580 |
else { |
| 2581 |
last; |
| 2582 |
} |
| 2583 |
} |
| 2584 |
|
| 2585 |
# If the count of the union of the lists of reservable items for each borrower |
| 2586 |
# is equal or greater than the number of borrowers, we know that all reserves |
| 2587 |
# can be filled with available items. We can get the union of the sets simply |
| 2588 |
# by pushing all the elements onto an array and removing the duplicates. |
| 2589 |
my @reservable; |
| 2590 |
my %borrowers; |
| 2591 |
ITEM: foreach my $i (@itemnumbers) { |
| 2592 |
my $item = GetItem($i); |
| 2593 |
next if IsItemOnHoldAndFound($i); |
| 2594 |
for my $b (@borrowernumbers) { |
| 2595 |
my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed; |
| 2596 |
next unless IsAvailableForItemLevelRequest($item, $borr); |
| 2597 |
next unless CanItemBeReserved($b,$i); |
| 2598 |
|
| 2599 |
push @reservable, $i; |
| 2600 |
if (@reservable >= @borrowernumbers) { |
| 2601 |
$resfound = 0; |
| 2602 |
last ITEM; |
| 2603 |
} |
| 2604 |
last; |
| 2605 |
} |
| 2606 |
} |
| 2607 |
} |
| 2608 |
} |
| 2609 |
|
| 2610 |
return !$resfound; |
| 2611 |
} |
| 2612 |
|
| 2613 |
|
| 2532 |
=head2 GetUpcomingDueIssues |
2614 |
=head2 GetUpcomingDueIssues |
| 2533 |
|
2615 |
|
| 2534 |
my $upcoming_dues = GetUpcomingDueIssues( { days_in_advance => 4 } ); |
2616 |
my $upcoming_dues = GetUpcomingDueIssues( { days_in_advance => 4 } ); |
|
Lines 2600-2671
sub CanBookBeRenewed {
Link Here
|
| 2600 |
my $patron = Koha::Patrons->find( $borrowernumber ) |
2682 |
my $patron = Koha::Patrons->find( $borrowernumber ) |
| 2601 |
or return; |
2683 |
or return; |
| 2602 |
|
2684 |
|
| 2603 |
my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber); |
2685 |
my ( $resfound, undef, undef ) = C4::Reserves::CheckReserves($itemnumber); |
| 2604 |
|
2686 |
return ( 0, "on_reserve" ) if !C4::Context->preference('AllowRenewalIfOtherItemsAvailable') && $resfound; |
| 2605 |
# This item can fill one or more unfilled reserve, can those unfilled reserves |
2687 |
return ( 0, "on_reserve" ) if !IsItemAvailableForCheckout($itemnumber); |
| 2606 |
# all be filled by other available items? |
|
|
| 2607 |
if ( $resfound |
| 2608 |
&& C4::Context->preference('AllowRenewalIfOtherItemsAvailable') ) |
| 2609 |
{ |
| 2610 |
my $schema = Koha::Database->new()->schema(); |
| 2611 |
|
| 2612 |
my $item_holds = $schema->resultset('Reserve')->search( { itemnumber => $itemnumber, found => undef } )->count(); |
| 2613 |
if ($item_holds) { |
| 2614 |
# There is an item level hold on this item, no other item can fill the hold |
| 2615 |
$resfound = 1; |
| 2616 |
} |
| 2617 |
else { |
| 2618 |
|
| 2619 |
# Get all other items that could possibly fill reserves |
| 2620 |
my @itemnumbers = $schema->resultset('Item')->search( |
| 2621 |
{ |
| 2622 |
biblionumber => $resrec->{biblionumber}, |
| 2623 |
onloan => undef, |
| 2624 |
notforloan => 0, |
| 2625 |
-not => { itemnumber => $itemnumber } |
| 2626 |
}, |
| 2627 |
{ columns => 'itemnumber' } |
| 2628 |
)->get_column('itemnumber')->all(); |
| 2629 |
|
| 2630 |
# Get all other reserves that could have been filled by this item |
| 2631 |
my @borrowernumbers; |
| 2632 |
while (1) { |
| 2633 |
my ( $reserve_found, $reserve, undef ) = |
| 2634 |
C4::Reserves::CheckReserves( $itemnumber, undef, undef, \@borrowernumbers ); |
| 2635 |
|
| 2636 |
if ($reserve_found) { |
| 2637 |
push( @borrowernumbers, $reserve->{borrowernumber} ); |
| 2638 |
} |
| 2639 |
else { |
| 2640 |
last; |
| 2641 |
} |
| 2642 |
} |
| 2643 |
|
| 2644 |
# If the count of the union of the lists of reservable items for each borrower |
| 2645 |
# is equal or greater than the number of borrowers, we know that all reserves |
| 2646 |
# can be filled with available items. We can get the union of the sets simply |
| 2647 |
# by pushing all the elements onto an array and removing the duplicates. |
| 2648 |
my @reservable; |
| 2649 |
my %borrowers; |
| 2650 |
ITEM: foreach my $i (@itemnumbers) { |
| 2651 |
my $item = GetItem($i); |
| 2652 |
next if IsItemOnHoldAndFound($i); |
| 2653 |
for my $b (@borrowernumbers) { |
| 2654 |
my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed; |
| 2655 |
next unless IsAvailableForItemLevelRequest($item, $borr); |
| 2656 |
next unless CanItemBeReserved($b,$i); |
| 2657 |
|
| 2658 |
push @reservable, $i; |
| 2659 |
if (@reservable >= @borrowernumbers) { |
| 2660 |
$resfound = 0; |
| 2661 |
last ITEM; |
| 2662 |
} |
| 2663 |
last; |
| 2664 |
} |
| 2665 |
} |
| 2666 |
} |
| 2667 |
} |
| 2668 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
| 2669 |
|
2688 |
|
| 2670 |
return ( 1, undef ) if $override_limit; |
2689 |
return ( 1, undef ) if $override_limit; |
| 2671 |
|
2690 |
|
| 2672 |
- |
|
|