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

(-)a/C4/Circulation.pm (+54 lines)
Lines 48-54 use Data::Dumper; Link Here
48
use Koha::DateUtils;
48
use Koha::DateUtils;
49
use Koha::Calendar;
49
use Koha::Calendar;
50
use Koha::Borrower::Debarments;
50
use Koha::Borrower::Debarments;
51
use Koha::Database;
51
use Carp;
52
use Carp;
53
use List::MoreUtils qw( uniq );
52
use Date::Calc qw(
54
use Date::Calc qw(
53
  Today
55
  Today
54
  Today_and_Now
56
  Today_and_Now
Lines 2632-2637 sub CanBookBeRenewed { Link Here
2632
2634
2633
    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber);
2635
    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber);
2634
2636
2637
    # This item can fill one or more unfilled reserve, can those unfilled reserves
2638
    # all be filled by other available items?
2639
    if ( $resfound
2640
        && C4::Context->preference('AllowRenewalIfOtherItemsAvailable') )
2641
    {
2642
        my $schema = Koha::Database->new()->schema();
2643
2644
        # Get all other items that could possibly fill reserves
2645
        my @itemnumbers = $schema->resultset('Item')->search(
2646
            {
2647
                biblionumber => $resrec->{biblionumber},
2648
                onloan       => undef,
2649
                -not         => { itemnumber => $itemnumber }
2650
            },
2651
            { columns => 'itemnumber' }
2652
        )->get_column('itemnumber')->all();
2653
2654
        # Get all other reserves that could have been filled by this item
2655
        my @borrowernumbers;
2656
        while (1) {
2657
            my ( $reserve_found, $reserve, undef ) =
2658
              C4::Reserves::CheckReserves( $itemnumber, undef, undef,
2659
                \@borrowernumbers );
2660
2661
            if ($reserve_found) {
2662
                push( @borrowernumbers, $reserve->{borrowernumber} );
2663
            }
2664
            else {
2665
                last;
2666
            }
2667
        }
2668
2669
        # If the count of the union of the lists of reservable items for each borrower
2670
        # is equal or greater than the number of borrowers, we know that all reserves
2671
        # can be filled with available items. We can get the union of the sets simply
2672
        # by pushing all the elements onto an array and removing the duplicates.
2673
        my @reservable;
2674
        foreach my $b (@borrowernumbers) {
2675
            foreach my $i (@itemnumbers) {
2676
                if ( CanItemBeReserved( $b, $i ) ) {
2677
                    push( @reservable, $i );
2678
                }
2679
            }
2680
        }
2681
2682
        @reservable = uniq(@reservable);
2683
2684
        if ( @reservable >= @borrowernumbers ) {
2685
            $resfound = 0;
2686
        }
2687
    }
2688
2635
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2689
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2636
2690
2637
    return ( 1, undef ) if $override_limit;
2691
    return ( 1, undef ) if $override_limit;
(-)a/C4/Reserves.pm (-8 / +11 lines)
Lines 41-47 use Koha::DateUtils; Link Here
41
use Koha::Calendar;
41
use Koha::Calendar;
42
use Koha::Database;
42
use Koha::Database;
43
43
44
use List::MoreUtils qw( firstidx );
44
use List::MoreUtils qw( firstidx any );
45
45
46
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
46
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
47
47
Lines 879-885 table in the Koha database. Link Here
879
=cut
879
=cut
880
880
881
sub CheckReserves {
881
sub CheckReserves {
882
    my ( $item, $barcode, $lookahead_days) = @_;
882
    my ( $item, $barcode, $lookahead_days, $ignore_borrowers) = @_;
883
    my $dbh = C4::Context->dbh;
883
    my $dbh = C4::Context->dbh;
884
    my $sth;
884
    my $sth;
885
    my $select;
885
    my $select;
Lines 930-936 sub CheckReserves { Link Here
930
    return if  ( $notforloan_per_item > 0 ) or $notforloan_per_itemtype;
930
    return if  ( $notforloan_per_item > 0 ) or $notforloan_per_itemtype;
931
931
932
    # Find this item in the reserves
932
    # Find this item in the reserves
933
    my @reserves = _Findgroupreserve( $bibitem, $biblio, $itemnumber, $lookahead_days);
933
    my @reserves = _Findgroupreserve( $bibitem, $biblio, $itemnumber, $lookahead_days, $ignore_borrowers);
934
934
935
    # $priority and $highest are used to find the most important item
935
    # $priority and $highest are used to find the most important item
936
    # in the list returned by &_Findgroupreserve. (The lower $priority,
936
    # in the list returned by &_Findgroupreserve. (The lower $priority,
Lines 1785-1791 sub _FixPriority { Link Here
1785
1785
1786
=head2 _Findgroupreserve
1786
=head2 _Findgroupreserve
1787
1787
1788
  @results = &_Findgroupreserve($biblioitemnumber, $biblionumber, $itemnumber, $lookahead);
1788
  @results = &_Findgroupreserve($biblioitemnumber, $biblionumber, $itemnumber, $lookahead, $ignore_borrowers);
1789
1789
1790
Looks for an item-specific match first, then for a title-level match, returning the
1790
Looks for an item-specific match first, then for a title-level match, returning the
1791
first match found.  If neither, then we look for a 3rd kind of match based on
1791
first match found.  If neither, then we look for a 3rd kind of match based on
Lines 1802-1808 C<biblioitemnumber>. Link Here
1802
=cut
1802
=cut
1803
1803
1804
sub _Findgroupreserve {
1804
sub _Findgroupreserve {
1805
    my ( $bibitem, $biblio, $itemnumber, $lookahead) = @_;
1805
    my ( $bibitem, $biblio, $itemnumber, $lookahead, $ignore_borrowers) = @_;
1806
    my $dbh   = C4::Context->dbh;
1806
    my $dbh   = C4::Context->dbh;
1807
1807
1808
    # TODO: consolidate at least the SELECT portion of the first 2 queries to a common $select var.
1808
    # TODO: consolidate at least the SELECT portion of the first 2 queries to a common $select var.
Lines 1834-1840 sub _Findgroupreserve { Link Here
1834
    $sth->execute($itemnumber, $lookahead||0);
1834
    $sth->execute($itemnumber, $lookahead||0);
1835
    my @results;
1835
    my @results;
1836
    if ( my $data = $sth->fetchrow_hashref ) {
1836
    if ( my $data = $sth->fetchrow_hashref ) {
1837
        push( @results, $data );
1837
        push( @results, $data )
1838
          unless any{ $data->{borrowernumber} eq $_ } @$ignore_borrowers ;
1838
    }
1839
    }
1839
    return @results if @results;
1840
    return @results if @results;
1840
    
1841
    
Lines 1866-1872 sub _Findgroupreserve { Link Here
1866
    $sth->execute($itemnumber, $lookahead||0);
1867
    $sth->execute($itemnumber, $lookahead||0);
1867
    @results = ();
1868
    @results = ();
1868
    if ( my $data = $sth->fetchrow_hashref ) {
1869
    if ( my $data = $sth->fetchrow_hashref ) {
1869
        push( @results, $data );
1870
        push( @results, $data )
1871
          unless any{ $data->{borrowernumber} eq $_ } @$ignore_borrowers ;
1870
    }
1872
    }
1871
    return @results if @results;
1873
    return @results if @results;
1872
1874
Lines 1899-1905 sub _Findgroupreserve { Link Here
1899
    $sth->execute( $biblio, $bibitem, $itemnumber, $lookahead||0);
1901
    $sth->execute( $biblio, $bibitem, $itemnumber, $lookahead||0);
1900
    @results = ();
1902
    @results = ();
1901
    while ( my $data = $sth->fetchrow_hashref ) {
1903
    while ( my $data = $sth->fetchrow_hashref ) {
1902
        push( @results, $data );
1904
        push( @results, $data )
1905
          unless any{ $data->{borrowernumber} eq $_ } @$ignore_borrowers ;
1903
    }
1906
    }
1904
    return @results;
1907
    return @results;
1905
}
1908
}
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 28-33 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
28
('AllowOnShelfHolds','0','','Allow hold requests to be placed on items that are not on loan','YesNo'),
28
('AllowOnShelfHolds','0','','Allow hold requests to be placed on items that are not on loan','YesNo'),
29
('AllowPKIAuth','None','None|Common Name|emailAddress','Use the field from a client-side SSL certificate to look a user in the Koha database','Choice'),
29
('AllowPKIAuth','None','None|Common Name|emailAddress','Use the field from a client-side SSL certificate to look a user in the Koha database','Choice'),
30
('AllowPurchaseSuggestionBranchChoice','0','1','Allow user to choose branch when making a purchase suggestion','YesNo'),
30
('AllowPurchaseSuggestionBranchChoice','0','1','Allow user to choose branch when making a purchase suggestion','YesNo'),
31
('AllowRenewalIfOtherItemsAvailable','0',NULL,'If enabled, allow a patron to renew an item with unfilled holds if other available items can fill that hold.','YesNo'),
31
('AllowRenewalLimitOverride','0',NULL,'if ON, allows renewal limits to be overridden on the circulation screen','YesNo'),
32
('AllowRenewalLimitOverride','0',NULL,'if ON, allows renewal limits to be overridden on the circulation screen','YesNo'),
32
('AllowReturnToBranch','anywhere','anywhere|homebranch|holdingbranch|homeorholdingbranch','Where an item may be returned','Choice'),
33
('AllowReturnToBranch','anywhere','anywhere|homebranch|holdingbranch|homeorholdingbranch','Where an item may be returned','Choice'),
33
('AllowSelfCheckReturns','0','','If enabled, patrons may return items through the Web-based Self Checkout','YesNo'),
34
('AllowSelfCheckReturns','0','','If enabled, patrons may return items through the Web-based Self Checkout','YesNo'),
(-)a/installer/data/mysql/updatedatabase.pl (+10 lines)
Lines 8776-8781 if ( CheckVersion($DBversion) ) { Link Here
8776
    SetVersion($DBversion);
8776
    SetVersion($DBversion);
8777
}
8777
}
8778
8778
8779
$DBversion = "3.17.00.XXX";
8780
if (CheckVersion($DBversion)) {
8781
    $dbh->do(q{
8782
        INSERT INTO systempreferences ( variable, value, options, explanation, type ) VALUES
8783
        ('AllowRenewalIfOtherItemsAvailable','0',NULL,'If enabled, allow a patron to renew an item with unfilled holds if other available items can fill that hold.','YesNo')
8784
    });
8785
    print "Upgrade to $DBversion done (Bug 11634 - Allow renewal of item with unfilled holds if other available items can fill those holds)\n";
8786
    SetVersion($DBversion);
8787
}
8788
8779
=head1 FUNCTIONS
8789
=head1 FUNCTIONS
8780
8790
8781
=head2 TableExists($table)
8791
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (-1 / +6 lines)
Lines 385-390 Circulation: Link Here
385
            - Each pair of values should be on a separate line.
385
            - Each pair of values should be on a separate line.
386
    Holds Policy:
386
    Holds Policy:
387
        -
387
        -
388
            - pref: AllowRenewalIfOtherItemsAvailable
389
              choices:
390
                  yes: Allow
391
                  no: "Don't allow"
392
            - a patron to renew an item with unfilled holds if other available items can fill that hold.
393
        -
388
            - pref: AllowHoldPolicyOverride
394
            - pref: AllowHoldPolicyOverride
389
              choices:
395
              choices:
390
                  yes: Allow
396
                  yes: Allow
391
- 

Return to bug 11634