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

(-)a/C4/Circulation.pm (-10 / +10 lines)
Lines 2659-2674 sub CanBookBeRenewed { Link Here
2659
            # can be filled with available items. We can get the union of the sets simply
2659
            # can be filled with available items. We can get the union of the sets simply
2660
            # by pushing all the elements onto an array and removing the duplicates.
2660
            # by pushing all the elements onto an array and removing the duplicates.
2661
            my @reservable;
2661
            my @reservable;
2662
            my %borrowers;
2662
            my %patrons;
2663
            ITEM: foreach my $i (@itemnumbers) {
2663
            ITEM: foreach my $itemnumber (@itemnumbers) {
2664
                my $item = GetItem($i);
2664
                my $item = Koha::Items->find( $itemnumber );
2665
                next if IsItemOnHoldAndFound($i);
2665
                next if IsItemOnHoldAndFound( $itemnumber );
2666
                for my $b (@borrowernumbers) {
2666
                for my $borrowernumber (@borrowernumbers) {
2667
                    my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed;
2667
                    my $patron = $patrons{$borrowernumber} //= Koha::Patrons->find( $borrowernumber );
2668
                    next unless IsAvailableForItemLevelRequest($item, $borr);
2668
                    next unless IsAvailableForItemLevelRequest($item, $patron);
2669
                    next unless CanItemBeReserved($b,$i);
2669
                    next unless CanItemBeReserved($b,$itemnumber);
2670
2670
2671
                    push @reservable, $i;
2671
                    push @reservable, $itemnumber;
2672
                    if (@reservable >= @borrowernumbers) {
2672
                    if (@reservable >= @borrowernumbers) {
2673
                        $resfound = 0;
2673
                        $resfound = 0;
2674
                        last ITEM;
2674
                        last ITEM;
(-)a/C4/ILSDI/Services.pm (-5 / +6 lines)
Lines 38-43 use Koha::DateUtils; Link Here
38
38
39
use Koha::Biblios;
39
use Koha::Biblios;
40
use Koha::Checkouts;
40
use Koha::Checkouts;
41
use Koha::Items;
41
use Koha::Libraries;
42
use Koha::Libraries;
42
use Koha::Patrons;
43
use Koha::Patrons;
43
44
Lines 514-530 sub GetServices { Link Here
514
    my $borrower = $patron->unblessed;
515
    my $borrower = $patron->unblessed;
515
    # Get the item, or return an error code if not found
516
    # Get the item, or return an error code if not found
516
    my $itemnumber = $cgi->param('item_id');
517
    my $itemnumber = $cgi->param('item_id');
517
    my $item = GetItem( $itemnumber );
518
    my $item = Koha::Items->find( $itemnumber );
518
    return { code => 'RecordNotFound' } unless $$item{itemnumber};
519
    return { code => 'RecordNotFound' } unless $item;
519
520
520
    my @availablefor;
521
    my @availablefor;
521
522
522
    # Reserve level management
523
    # Reserve level management
523
    my $biblionumber = $item->{'biblionumber'};
524
    my $biblionumber = $item->biblionumber;
524
    my $canbookbereserved = CanBookBeReserved( $borrower, $biblionumber );
525
    my $canbookbereserved = CanBookBeReserved( $borrower, $biblionumber );
525
    if ($canbookbereserved eq 'OK') {
526
    if ($canbookbereserved eq 'OK') {
526
        push @availablefor, 'title level hold';
527
        push @availablefor, 'title level hold';
527
        my $canitembereserved = IsAvailableForItemLevelRequest($item, $borrower);
528
        my $canitembereserved = IsAvailableForItemLevelRequest($item, $patron);
528
        if ($canitembereserved) {
529
        if ($canitembereserved) {
529
            push @availablefor, 'item level hold';
530
            push @availablefor, 'item level hold';
530
        }
531
        }
Lines 547-553 sub GetServices { Link Here
547
    }
548
    }
548
549
549
    # Issuing management
550
    # Issuing management
550
    my $barcode = $item->{'barcode'} || '';
551
    my $barcode = $item->barcode || '';
551
    $barcode = barcodedecode($barcode) if ( $barcode && C4::Context->preference('itemBarcodeInputFilter') );
552
    $barcode = barcodedecode($barcode) if ( $barcode && C4::Context->preference('itemBarcodeInputFilter') );
552
    if ($barcode) {
553
    if ($barcode) {
553
        my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $borrower, $barcode );
554
        my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $borrower, $barcode );
(-)a/C4/Reserves.pm (-12 / +9 lines)
Lines 1091-1125 and canreservefromotherbranches. Link Here
1091
=cut
1091
=cut
1092
1092
1093
sub IsAvailableForItemLevelRequest {
1093
sub IsAvailableForItemLevelRequest {
1094
    my $item = shift;
1094
    my ( $item, $patron ) = @_;
1095
    my $borrower = shift;
1096
1095
1097
    my $dbh = C4::Context->dbh;
1096
    my $dbh = C4::Context->dbh;
1098
    # must check the notforloan setting of the itemtype
1097
    # must check the notforloan setting of the itemtype
1099
    # FIXME - a lot of places in the code do this
1098
    # FIXME - a lot of places in the code do this
1100
    #         or something similar - need to be
1099
    #         or something similar - need to be
1101
    #         consolidated
1100
    #         consolidated
1102
    my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
1101
    my $itemtype = $item->effective_itemtype;
1103
    my $item_object = Koha::Items->find( $item->{itemnumber } );
1104
    my $itemtype = $item_object->effective_itemtype;
1105
    my $notforloan_per_itemtype
1102
    my $notforloan_per_itemtype
1106
      = $dbh->selectrow_array("SELECT notforloan FROM itemtypes WHERE itemtype = ?",
1103
      = $dbh->selectrow_array("SELECT notforloan FROM itemtypes WHERE itemtype = ?",
1107
                              undef, $itemtype);
1104
                              undef, $itemtype);
1108
1105
1109
    return 0 if
1106
    return 0 if
1110
        $notforloan_per_itemtype ||
1107
        $notforloan_per_itemtype ||
1111
        $item->{itemlost}        ||
1108
        $item->itemlost        ||
1112
        $item->{notforloan} > 0  ||
1109
        $item->notforloan > 0  ||
1113
        $item->{withdrawn}        ||
1110
        $item->withdrawn        ||
1114
        ($item->{damaged} && !C4::Context->preference('AllowHoldsOnDamagedItems'));
1111
        ($item->damaged && !C4::Context->preference('AllowHoldsOnDamagedItems'));
1115
1112
1116
    my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item_object, patron => $patron } );
1113
    my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } );
1117
1114
1118
    if ( $on_shelf_holds == 1 ) {
1115
    if ( $on_shelf_holds == 1 ) {
1119
        return 1;
1116
        return 1;
1120
    } elsif ( $on_shelf_holds == 2 ) {
1117
    } elsif ( $on_shelf_holds == 2 ) {
1121
        my @items =
1118
        my @items =
1122
          Koha::Items->search( { biblionumber => $item->{biblionumber} } );
1119
          Koha::Items->search( { biblionumber => $item->biblionumber } );
1123
1120
1124
        my $any_available = 0;
1121
        my $any_available = 0;
1125
1122
Lines 1138-1144 sub IsAvailableForItemLevelRequest { Link Here
1138
        return $any_available ? 0 : 1;
1135
        return $any_available ? 0 : 1;
1139
    }
1136
    }
1140
1137
1141
    return $item->{onloan} || GetReserveStatus($item->{itemnumber}) eq "Waiting";
1138
    return $item->onloan || GetReserveStatus( $item->itemnumber ) eq "Waiting";
1142
}
1139
}
1143
1140
1144
sub _get_itype {
1141
sub _get_itype {
(-)a/opac/opac-reserve.pl (-1 / +1 lines)
Lines 536-542 foreach my $biblioNum (@biblionumbers) { Link Here
536
536
537
        my $policy_holdallowed = !$itemLoopIter->{already_reserved};
537
        my $policy_holdallowed = !$itemLoopIter->{already_reserved};
538
        $policy_holdallowed &&=
538
        $policy_holdallowed &&=
539
            IsAvailableForItemLevelRequest($itemInfo,$patron_unblessed) &&
539
            IsAvailableForItemLevelRequest($item, $patron) &&
540
            CanItemBeReserved($borrowernumber,$itemNum) eq 'OK';
540
            CanItemBeReserved($borrowernumber,$itemNum) eq 'OK';
541
541
542
        if ($policy_holdallowed) {
542
        if ($policy_holdallowed) {
(-)a/reserve/request.pl (-1 / +1 lines)
Lines 475-481 foreach my $biblionumber (@biblionumbers) { Link Here
475
                if (
475
                if (
476
                       !$item->{cantreserve}
476
                       !$item->{cantreserve}
477
                    && !$exceeded_maxreserves
477
                    && !$exceeded_maxreserves
478
                    && IsAvailableForItemLevelRequest($item, $patron_unblessed)
478
                    && IsAvailableForItemLevelRequest($item_object, $patron)
479
                    && $can_item_be_reserved eq 'OK'
479
                    && $can_item_be_reserved eq 'OK'
480
                  )
480
                  )
481
                {
481
                {
(-)a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t (-31 / +12 lines)
Lines 6-11 use C4::Context; Link Here
6
use C4::Items;
6
use C4::Items;
7
use C4::Circulation;
7
use C4::Circulation;
8
use Koha::IssuingRule;
8
use Koha::IssuingRule;
9
use Koha::Items;
9
10
10
use Test::More tests => 4;
11
use Test::More tests => 4;
11
12
Lines 31-46 C4::Context->set_userenv(0,0,0,'firstname','surname', $library1->{branchcode}, ' Link Here
31
32
32
my $bib_title = "Test Title";
33
my $bib_title = "Test Title";
33
34
34
my $borrower1 = $builder->build({
35
my $patron1 = $builder->build_object({
35
    source => 'Borrower',
36
    class => 'Koha::Patrons',
36
    value => {
37
    value => {
37
        branchcode => $library1->{branchcode},
38
        branchcode => $library1->{branchcode},
38
        dateexpiry => '3000-01-01',
39
        dateexpiry => '3000-01-01',
39
    }
40
    }
40
});
41
});
41
42
42
my $borrower2 = $builder->build({
43
my $patron2 = $builder->build_object({
43
    source => 'Borrower',
44
    class => 'Koha::Patrons',
44
    value => {
45
    value => {
45
        branchcode => $library1->{branchcode},
46
        branchcode => $library1->{branchcode},
46
        dateexpiry => '3000-01-01',
47
        dateexpiry => '3000-01-01',
Lines 49-56 my $borrower2 = $builder->build({ Link Here
49
50
50
# Test hold_fulfillment_policy
51
# Test hold_fulfillment_policy
51
my ( $itemtype ) = @{ $dbh->selectrow_arrayref("SELECT itemtype FROM itemtypes LIMIT 1") };
52
my ( $itemtype ) = @{ $dbh->selectrow_arrayref("SELECT itemtype FROM itemtypes LIMIT 1") };
52
my $borrowernumber1 = $borrower1->{borrowernumber};
53
my $borrowernumber2 = $borrower2->{borrowernumber};
54
my $library_A = $library1->{branchcode};
53
my $library_A = $library1->{branchcode};
55
54
56
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$bib_title', '2011-02-01')");
55
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$bib_title', '2011-02-01')");
Lines 64-90 my $biblioitemnumber = Link Here
64
  $dbh->selectrow_array("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber = $biblionumber")
63
  $dbh->selectrow_array("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber = $biblionumber")
65
  or BAIL_OUT("Cannot find newly created biblioitems record");
64
  or BAIL_OUT("Cannot find newly created biblioitems record");
66
65
67
$dbh->do("
66
my $item1 = $builder->build_object({ class => 'Koha::Items', value => { barcode => 'AllowHoldIf1', biblionumber => $biblionumber, biblioitemnumber => $biblioitemnumber, homebranch => $library_A, holdingbranch => $library_A, notforloan => 0, damaged => 0, itemlost => 0, withdrawn => 0, onloan => undef, itype => $itemtype } });
68
    INSERT INTO items (barcode, biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
69
    VALUES ('AllowHoldIf1', $biblionumber, $biblioitemnumber, '$library_A', '$library_A', 0, 0, 0, 0, NULL, '$itemtype')
70
");
71
67
72
my $itemnumber1 =
68
my $item2 = $builder->build_object({ class => 'Koha::Items', value => { barcode => 'AllowHoldIf2', biblionumber => $biblionumber, biblioitemnumber => $biblioitemnumber, homebranch => $library_A, holdingbranch => $library_A, notforloan => 0, damaged => 0, itemlost => 0, withdrawn => 0, onloan => undef, itype => $itemtype } });
73
  $dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber")
74
  or BAIL_OUT("Cannot find newly created item");
75
76
my $item1 = GetItem( $itemnumber1 );
77
78
$dbh->do("
79
    INSERT INTO items (barcode, biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
80
    VALUES ('AllowHoldIf2', $biblionumber, $biblioitemnumber, '$library_A', '$library_A', 0, 0, 0, 0, NULL, '$itemtype')
81
");
82
83
my $itemnumber2 =
84
  $dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber ORDER BY itemnumber DESC")
85
  or BAIL_OUT("Cannot find newly created item");
86
87
my $item2 = GetItem( $itemnumber2 );
88
69
89
$dbh->do("DELETE FROM issuingrules");
70
$dbh->do("DELETE FROM issuingrules");
90
my $rule = Koha::IssuingRule->new(
71
my $rule = Koha::IssuingRule->new(
Lines 101-117 my $rule = Koha::IssuingRule->new( Link Here
101
);
82
);
102
$rule->store();
83
$rule->store();
103
84
104
my $is = IsAvailableForItemLevelRequest( $item1, $borrower1);
85
my $is = IsAvailableForItemLevelRequest( $item1, $patron1);
105
is( $is, 0, "Item cannot be held, 2 items available" );
86
is( $is, 0, "Item cannot be held, 2 items available" );
106
87
107
AddIssue( $borrower2, $item1->{barcode} );
88
AddIssue( $patron2, $item1->barcode );
108
89
109
$is = IsAvailableForItemLevelRequest( $item1, $borrower1);
90
$is = IsAvailableForItemLevelRequest( $item1, $patron1);
110
is( $is, 0, "Item cannot be held, 1 item available" );
91
is( $is, 0, "Item cannot be held, 1 item available" );
111
92
112
AddIssue( $borrower2, $item2->{barcode} );
93
AddIssue( $patron2, $item2->barcode );
113
94
114
$is = IsAvailableForItemLevelRequest( $item1, $borrower1);
95
$is = IsAvailableForItemLevelRequest( $item1, $patron1);
115
is( $is, 1, "Item can be held, no items available" );
96
is( $is, 1, "Item can be held, no items available" );
116
97
117
# Cleanup
98
# Cleanup
(-)a/t/db_dependent/Reserves.t (-4 / +4 lines)
Lines 118-124 my %data = ( Link Here
118
);
118
);
119
Koha::Patron::Categories->find($category_1)->set({ enrolmentfee => 0})->store;
119
Koha::Patron::Categories->find($category_1)->set({ enrolmentfee => 0})->store;
120
my $borrowernumber = AddMember(%data);
120
my $borrowernumber = AddMember(%data);
121
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
121
my $patron = Koha::Patrons->find( $borrowernumber );
122
my $borrower = $patron->unblessed;
122
my $biblionumber   = $bibnum;
123
my $biblionumber   = $bibnum;
123
my $barcode        = $testbarcode;
124
my $barcode        = $testbarcode;
124
125
Lines 536-544 is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'OK', "Res Link Here
536
####### EO Bug 13113 <<<
537
####### EO Bug 13113 <<<
537
       ####
538
       ####
538
539
539
$item = GetItem($itemnumber);
540
$item = Koha::Items->find($itemnumber);
540
541
541
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a book on item level" );
542
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $patron), "Reserving a book on item level" );
542
543
543
# tests for MoveReserve in relation to ConfirmFutureHolds (BZ 14526)
544
# tests for MoveReserve in relation to ConfirmFutureHolds (BZ 14526)
544
#   hold from A pos 1, today, no fut holds: MoveReserve should fill it
545
#   hold from A pos 1, today, no fut holds: MoveReserve should fill it
545
- 

Return to bug 19302