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

(-)a/C4/Circulation.pm (-10 / +10 lines)
Lines 2647-2662 sub CanBookBeRenewed { Link Here
2647
            # can be filled with available items. We can get the union of the sets simply
2647
            # can be filled with available items. We can get the union of the sets simply
2648
            # by pushing all the elements onto an array and removing the duplicates.
2648
            # by pushing all the elements onto an array and removing the duplicates.
2649
            my @reservable;
2649
            my @reservable;
2650
            my %borrowers;
2650
            my %patrons;
2651
            ITEM: foreach my $i (@itemnumbers) {
2651
            ITEM: foreach my $itemnumber (@itemnumbers) {
2652
                my $item = GetItem($i);
2652
                my $item = Koha::Items->find( $itemnumber );
2653
                next if IsItemOnHoldAndFound($i);
2653
                next if IsItemOnHoldAndFound( $itemnumber );
2654
                for my $b (@borrowernumbers) {
2654
                for my $borrowernumber (@borrowernumbers) {
2655
                    my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed;
2655
                    my $patron = $patrons{$borrowernumber} //= Koha::Patrons->find( $borrowernumber );
2656
                    next unless IsAvailableForItemLevelRequest($item, $borr);
2656
                    next unless IsAvailableForItemLevelRequest($item, $patron);
2657
                    next unless CanItemBeReserved($b,$i);
2657
                    next unless CanItemBeReserved($borrowernumber,$itemnumber);
2658
2658
2659
                    push @reservable, $i;
2659
                    push @reservable, $itemnumber;
2660
                    if (@reservable >= @borrowernumbers) {
2660
                    if (@reservable >= @borrowernumbers) {
2661
                        $resfound = 0;
2661
                        $resfound = 0;
2662
                        last ITEM;
2662
                        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 1127-1161 and canreservefromotherbranches. Link Here
1127
=cut
1127
=cut
1128
1128
1129
sub IsAvailableForItemLevelRequest {
1129
sub IsAvailableForItemLevelRequest {
1130
    my $item = shift;
1130
    my ( $item, $patron ) = @_;
1131
    my $borrower = shift;
1132
1131
1133
    my $dbh = C4::Context->dbh;
1132
    my $dbh = C4::Context->dbh;
1134
    # must check the notforloan setting of the itemtype
1133
    # must check the notforloan setting of the itemtype
1135
    # FIXME - a lot of places in the code do this
1134
    # FIXME - a lot of places in the code do this
1136
    #         or something similar - need to be
1135
    #         or something similar - need to be
1137
    #         consolidated
1136
    #         consolidated
1138
    my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
1137
    my $itemtype = $item->effective_itemtype;
1139
    my $item_object = Koha::Items->find( $item->{itemnumber } );
1140
    my $itemtype = $item_object->effective_itemtype;
1141
    my $notforloan_per_itemtype
1138
    my $notforloan_per_itemtype
1142
      = $dbh->selectrow_array("SELECT notforloan FROM itemtypes WHERE itemtype = ?",
1139
      = $dbh->selectrow_array("SELECT notforloan FROM itemtypes WHERE itemtype = ?",
1143
                              undef, $itemtype);
1140
                              undef, $itemtype);
1144
1141
1145
    return 0 if
1142
    return 0 if
1146
        $notforloan_per_itemtype ||
1143
        $notforloan_per_itemtype ||
1147
        $item->{itemlost}        ||
1144
        $item->itemlost        ||
1148
        $item->{notforloan} > 0  ||
1145
        $item->notforloan > 0  ||
1149
        $item->{withdrawn}        ||
1146
        $item->withdrawn        ||
1150
        ($item->{damaged} && !C4::Context->preference('AllowHoldsOnDamagedItems'));
1147
        ($item->damaged && !C4::Context->preference('AllowHoldsOnDamagedItems'));
1151
1148
1152
    my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item_object, patron => $patron } );
1149
    my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } );
1153
1150
1154
    if ( $on_shelf_holds == 1 ) {
1151
    if ( $on_shelf_holds == 1 ) {
1155
        return 1;
1152
        return 1;
1156
    } elsif ( $on_shelf_holds == 2 ) {
1153
    } elsif ( $on_shelf_holds == 2 ) {
1157
        my @items =
1154
        my @items =
1158
          Koha::Items->search( { biblionumber => $item->{biblionumber} } );
1155
          Koha::Items->search( { biblionumber => $item->biblionumber } );
1159
1156
1160
        my $any_available = 0;
1157
        my $any_available = 0;
1161
1158
Lines 1174-1180 sub IsAvailableForItemLevelRequest { Link Here
1174
        return $any_available ? 0 : 1;
1171
        return $any_available ? 0 : 1;
1175
    }
1172
    }
1176
1173
1177
    return $item->{onloan} || GetReserveStatus($item->{itemnumber}) eq "Waiting";
1174
    return $item->onloan || GetReserveStatus( $item->itemnumber ) eq "Waiting";
1178
}
1175
}
1179
1176
1180
sub _get_itype {
1177
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 474-480 foreach my $biblionumber (@biblionumbers) { Link Here
474
                if (
474
                if (
475
                       !$item->{cantreserve}
475
                       !$item->{cantreserve}
476
                    && !$exceeded_maxreserves
476
                    && !$exceeded_maxreserves
477
                    && IsAvailableForItemLevelRequest($item, $patron_unblessed)
477
                    && IsAvailableForItemLevelRequest($item_object, $patron)
478
                    && $can_item_be_reserved eq 'OK'
478
                    && $can_item_be_reserved eq 'OK'
479
                  )
479
                  )
480
                {
480
                {
(-)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