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 2607-2612 sub CanBookBeRenewed { Link Here
2607
2609
2608
    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves( $itemnumber );
2610
    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves( $itemnumber );
2609
2611
2612
    # This item can fill one or more unfilled reserve, can those unfilled reserves
2613
    # all be filled by other available items?
2614
    if ( $resfound
2615
        && C4::Context->preference('AllowRenewalIfOtherItemsAvailable') )
2616
    {
2617
        my $schema = Koha::Database->new()->schema();
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
                -not         => { itemnumber => $itemnumber }
2625
            },
2626
            { columns => 'itemnumber' }
2627
        )->get_column('itemnumber')->all();
2628
2629
        # Get all other reserves that could have been filled by this item
2630
        my @borrowernumbers;
2631
        while (1) {
2632
            my ( $reserve_found, $reserve, undef ) =
2633
              C4::Reserves::CheckReserves( $itemnumber, undef, undef,
2634
                \@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
        foreach my $b (@borrowernumbers) {
2650
            foreach my $i (@itemnumbers) {
2651
                if ( CanItemBeReserved( $b, $i ) ) {
2652
                    push( @reservable, $i );
2653
                }
2654
            }
2655
        }
2656
2657
        @reservable = uniq(@reservable);
2658
2659
        if ( @reservable >= @borrowernumbers ) {
2660
            $resfound = 0;
2661
        }
2662
    }
2663
2610
    if ( $resfound ) { # '' when no hold was found
2664
    if ( $resfound ) { # '' when no hold was found
2611
        $renewokay = 0;
2665
        $renewokay = 0;
2612
        $error = "on_reserve";
2666
        $error = "on_reserve";
(-)a/C4/Reserves.pm (-8 / +11 lines)
Lines 39-45 use C4::Dates qw( format_date_in_iso ); Link Here
39
39
40
use Koha::DateUtils;
40
use Koha::DateUtils;
41
41
42
use List::MoreUtils qw( firstidx );
42
use List::MoreUtils qw( firstidx any );
43
43
44
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
44
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
45
45
Lines 863-869 table in the Koha database. Link Here
863
=cut
863
=cut
864
864
865
sub CheckReserves {
865
sub CheckReserves {
866
    my ( $item, $barcode, $lookahead_days) = @_;
866
    my ( $item, $barcode, $lookahead_days, $ignore_borrowers) = @_;
867
    my $dbh = C4::Context->dbh;
867
    my $dbh = C4::Context->dbh;
868
    my $sth;
868
    my $sth;
869
    my $select;
869
    my $select;
Lines 914-920 sub CheckReserves { Link Here
914
    return if  ( $notforloan_per_item > 0 ) or $notforloan_per_itemtype;
914
    return if  ( $notforloan_per_item > 0 ) or $notforloan_per_itemtype;
915
915
916
    # Find this item in the reserves
916
    # Find this item in the reserves
917
    my @reserves = _Findgroupreserve( $bibitem, $biblio, $itemnumber, $lookahead_days);
917
    my @reserves = _Findgroupreserve( $bibitem, $biblio, $itemnumber, $lookahead_days, $ignore_borrowers);
918
918
919
    # $priority and $highest are used to find the most important item
919
    # $priority and $highest are used to find the most important item
920
    # in the list returned by &_Findgroupreserve. (The lower $priority,
920
    # in the list returned by &_Findgroupreserve. (The lower $priority,
Lines 1754-1760 sub _FixPriority { Link Here
1754
1754
1755
=head2 _Findgroupreserve
1755
=head2 _Findgroupreserve
1756
1756
1757
  @results = &_Findgroupreserve($biblioitemnumber, $biblionumber, $itemnumber, $lookahead);
1757
  @results = &_Findgroupreserve($biblioitemnumber, $biblionumber, $itemnumber, $lookahead, $ignore_borrowers);
1758
1758
1759
Looks for an item-specific match first, then for a title-level match, returning the
1759
Looks for an item-specific match first, then for a title-level match, returning the
1760
first match found.  If neither, then we look for a 3rd kind of match based on
1760
first match found.  If neither, then we look for a 3rd kind of match based on
Lines 1771-1777 C<biblioitemnumber>. Link Here
1771
=cut
1771
=cut
1772
1772
1773
sub _Findgroupreserve {
1773
sub _Findgroupreserve {
1774
    my ( $bibitem, $biblio, $itemnumber, $lookahead) = @_;
1774
    my ( $bibitem, $biblio, $itemnumber, $lookahead, $ignore_borrowers) = @_;
1775
    my $dbh   = C4::Context->dbh;
1775
    my $dbh   = C4::Context->dbh;
1776
1776
1777
    # TODO: consolidate at least the SELECT portion of the first 2 queries to a common $select var.
1777
    # TODO: consolidate at least the SELECT portion of the first 2 queries to a common $select var.
Lines 1803-1809 sub _Findgroupreserve { Link Here
1803
    $sth->execute($itemnumber, $lookahead||0);
1803
    $sth->execute($itemnumber, $lookahead||0);
1804
    my @results;
1804
    my @results;
1805
    if ( my $data = $sth->fetchrow_hashref ) {
1805
    if ( my $data = $sth->fetchrow_hashref ) {
1806
        push( @results, $data );
1806
        push( @results, $data )
1807
          unless any{ $data->{borrowernumber} eq $_ } @$ignore_borrowers ;
1807
    }
1808
    }
1808
    return @results if @results;
1809
    return @results if @results;
1809
    
1810
    
Lines 1835-1841 sub _Findgroupreserve { Link Here
1835
    $sth->execute($itemnumber, $lookahead||0);
1836
    $sth->execute($itemnumber, $lookahead||0);
1836
    @results = ();
1837
    @results = ();
1837
    if ( my $data = $sth->fetchrow_hashref ) {
1838
    if ( my $data = $sth->fetchrow_hashref ) {
1838
        push( @results, $data );
1839
        push( @results, $data )
1840
          unless any{ $data->{borrowernumber} eq $_ } @$ignore_borrowers ;
1839
    }
1841
    }
1840
    return @results if @results;
1842
    return @results if @results;
1841
1843
Lines 1868-1874 sub _Findgroupreserve { Link Here
1868
    $sth->execute( $biblio, $bibitem, $itemnumber, $lookahead||0);
1870
    $sth->execute( $biblio, $bibitem, $itemnumber, $lookahead||0);
1869
    @results = ();
1871
    @results = ();
1870
    while ( my $data = $sth->fetchrow_hashref ) {
1872
    while ( my $data = $sth->fetchrow_hashref ) {
1871
        push( @results, $data );
1873
        push( @results, $data )
1874
          unless any{ $data->{borrowernumber} eq $_ } @$ignore_borrowers ;
1872
    }
1875
    }
1873
    return @results;
1876
    return @results;
1874
}
1877
}
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 26-31 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
26
('AllowOnShelfHolds','0','','Allow hold requests to be placed on items that are not on loan','YesNo'),
26
('AllowOnShelfHolds','0','','Allow hold requests to be placed on items that are not on loan','YesNo'),
27
('AllowPKIAuth','None','None|Common Name|emailAddress','Use the field from a client-side SSL certificate to look a user in the Koha database','Choice'),
27
('AllowPKIAuth','None','None|Common Name|emailAddress','Use the field from a client-side SSL certificate to look a user in the Koha database','Choice'),
28
('AllowPurchaseSuggestionBranchChoice','0','1','Allow user to choose branch when making a purchase suggestion','YesNo'),
28
('AllowPurchaseSuggestionBranchChoice','0','1','Allow user to choose branch when making a purchase suggestion','YesNo'),
29
('AllowRenewalIfOtherItemsAvailable','0',NULL,'If enabled, allow a patron to renew an item with unfilled holds if other available items can fill that hold.','YesNo'),
29
('AllowRenewalLimitOverride','0',NULL,'if ON, allows renewal limits to be overridden on the circulation screen','YesNo'),
30
('AllowRenewalLimitOverride','0',NULL,'if ON, allows renewal limits to be overridden on the circulation screen','YesNo'),
30
('AllowReturnToBranch','anywhere','anywhere|homebranch|holdingbranch|homeorholdingbranch','Where an item may be returned','Choice'),
31
('AllowReturnToBranch','anywhere','anywhere|homebranch|holdingbranch|homeorholdingbranch','Where an item may be returned','Choice'),
31
('AllowSelfCheckReturns','0','','If enabled, patrons may return items through the Web-based Self Checkout','YesNo'),
32
('AllowSelfCheckReturns','0','','If enabled, patrons may return items through the Web-based Self Checkout','YesNo'),
(-)a/installer/data/mysql/updatedatabase.pl (+10 lines)
Lines 8465-8470 if ( CheckVersion($DBversion) ) { Link Here
8465
    SetVersion($DBversion);
8465
    SetVersion($DBversion);
8466
}
8466
}
8467
8467
8468
$DBversion = "3.15.00.XXX";
8469
if (CheckVersion($DBversion)) {
8470
    $dbh->do(q{
8471
        INSERT INTO systempreferences ( variable, value, options, explanation, type ) VALUES
8472
        ('AllowRenewalIfOtherItemsAvailable','0',NULL,'If enabled, allow a patron to renew an item with unfilled holds if other available items can fill that hold.','YesNo')
8473
    });
8474
    print "Upgrade to $DBversion done (Bug 11634 - Allow renewal of item with unfilled holds if other available items can fill those holds)\n";
8475
    SetVersion($DBversion);
8476
}
8477
8468
=head1 FUNCTIONS
8478
=head1 FUNCTIONS
8469
8479
8470
=head2 TableExists($table)
8480
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (-1 / +6 lines)
Lines 365-370 Circulation: Link Here
365
            - <br /><b>NOTE If you are doing hourly loans then you should have this on.</b>
365
            - <br /><b>NOTE If you are doing hourly loans then you should have this on.</b>
366
    Holds Policy:
366
    Holds Policy:
367
        -
367
        -
368
            - pref: AllowRenewalIfOtherItemsAvailable
369
              choices:
370
                  yes: Allow
371
                  no: "Don't allow"
372
            - a patron to renew an item with unfilled holds if other available items can fill that hold.
373
        -
368
            - pref: AllowHoldPolicyOverride
374
            - pref: AllowHoldPolicyOverride
369
              choices:
375
              choices:
370
                  yes: Allow
376
                  yes: Allow
371
- 

Return to bug 11634