my $waitingdate;
# If the reserv had the waiting status, we had the value of the resdate
- if ( $found eq 'W' ) {
+ if ( $found && $found eq 'W' ) {
$waitingdate = $resdate;
}
item_level_hold => $checkitem ? 1 : 0,
}
)->store();
- $hold->set_waiting() if $found eq 'W';
+ $hold->set_waiting() if $found && $found eq 'W';
logaction( 'HOLDS', 'CREATE', $hold->id, Dumper($hold->unblessed) )
if C4::Context->preference('HoldsLog');
{ status => ageRestricted }, if the Item is age restricted for this borrower.
{ status => damaged }, if the Item is damaged.
{ status => cannotReserveFromOtherBranches }, if syspref 'canreservefromotherbranches' is OK.
+ { status => branchNotInHoldGroup }, if borrower home library is not in hold group, and holds are only allowed from hold groups.
{ status => tooManyReserves, limit => $limit }, if the borrower has exceeded their maximum reserve amount.
{ status => notReservable }, if holds on this item are not allowed
{ status => libraryNotFound }, if given branchcode is not an existing library
{ status => libraryNotPickupLocation }, if given branchcode is not configured to be a pickup location
{ status => cannotBeTransferred }, if branch transfer limit applies on given item and branchcode
+ { status => pickupNotInHoldGroup }, pickup location is not in hold group, and pickup locations are only allowed from hold groups.
=cut
return { status => 'cannotReserveFromOtherBranches' };
}
+ my $item_library = Koha::Libraries->find( {branchcode => $item->homebranch} );
+ if ( $branchitemrule->{holdallowed} == 3) {
+ if($borrower->{branchcode} ne $item->homebranch && !$item_library->validate_hold_sibling( {branchcode => $borrower->{branchcode}} )) {
+ return { status => 'branchNotInHoldGroup' };
+ }
+ }
+
# If reservecount is ok, we check item branch if IndependentBranches is ON
# and canreservefromotherbranches is OFF
if ( C4::Context->preference('IndependentBranches')
unless ($item->can_be_transferred({ to => $destination })) {
return { status => 'cannotBeTransferred' };
}
+ unless ($branchitemrule->{hold_fulfillment_policy} ne 'holdgroup' || $item_library->validate_hold_sibling( {branchcode => $pickup_branchcode} )) {
+ return { status => 'pickupNotInHoldGroup' };
+ }
+ unless ($branchitemrule->{hold_fulfillment_policy} ne 'patrongroup' || Koha::Libraries->find({branchcode => $borrower->{branchcode}})->validate_hold_sibling({branchcode => $pickup_branchcode})) {
+ return { status => 'pickupNotInHoldGroup' };
+ }
}
return { status => 'OK' };
my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
next if ($branchitemrule->{'holdallowed'} == 0);
next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
+ my $library = Koha::Libraries->find({branchcode=>$item->homebranch});
+ next if (($branchitemrule->{'holdallowed'} == 3) && (!$library->validate_hold_sibling({branchcode => $patron->branchcode}) ));
my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy};
- next
- if $hold_fulfillment_policy ne 'any'
- && (
- $hold_fulfillment_policy eq ''
- || ( $res->{branchcode} ne
- $item->$hold_fulfillment_policy )
- );
+ next if ( ($hold_fulfillment_policy eq 'holdgroup') && (!$library->validate_hold_sibling({branchcode => $res->{branchcode}})) );
+ next if ( ($hold_fulfillment_policy eq 'homebranch') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) );
+ next if ( ($hold_fulfillment_policy eq 'holdingbranch') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) );
next unless $item->can_be_transferred( { to => scalar Koha::Libraries->find( $res->{branchcode} ) } );
$priority = $res->{'priority'};
$highest = $res;
$sth_set->execute( $newstatus, $itemnumber );
my $item = Koha::Items->find($itemnumber);
- if ( ( $item->location eq 'CART' && $item->permanent_location ne 'CART' ) && $newstatus ) {
+ if ( $item->location && $item->location eq 'CART'
+ && ( !$item->permanent_location || $item->permanent_location ne 'CART' )
+ && $newstatus ) {
CartToShelf( $itemnumber );
}
}
_FixPriority( { biblionumber => $biblionumber } );
my $item = Koha::Items->find($itemnumber);
- if ( ( $item->location eq 'CART' && $item->permanent_location ne 'CART' ) ) {
+ if ( $item->location && $item->location eq 'CART'
+ && ( !$item->permanent_location || $item->permanent_location ne 'CART' ) ) {
CartToShelf( $itemnumber );
}
return 0 unless $destination;
return 0 unless $destination->pickup_location;
return 0 unless $item->can_be_transferred( { to => $destination } );
+ my $reserves_control_branch =
+ GetReservesControlBranch( $item->unblessed(), $patron->unblessed() );
+ my $branchitemrule =
+ C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->itype );
+ my $home_library = Koka::Libraries->find( {branchcode => $item->homebranch} );
+ return 0 unless $branchitemrule->{hold_fulfillment_policy} ne 'holdgroup' || $home_library->validate_hold_sibling( {branchcode => $pickup_branchcode} );
}
if ( $on_shelf_holds == 1 ) {
foreach my $i (@items) {
my $reserves_control_branch = GetReservesControlBranch( $i->unblessed(), $patron->unblessed );
my $branchitemrule = C4::Circulation::GetBranchItemRule( $reserves_control_branch, $i->itype );
+ my $item_library = Koha::Libraries->find( {branchcode => $i->homebranch} );
+
$any_available = 1
unless $i->itemlost
|| ( $i->damaged
&& !C4::Context->preference('AllowHoldsOnDamagedItems') )
|| Koha::ItemTypes->find( $i->effective_itemtype() )->notforloan
- || $branchitemrule->{holdallowed} == 1 && $patron->branchcode ne $i->homebranch;
+ || $branchitemrule->{holdallowed} == 1 && $patron->branchcode ne $i->homebranch
+ || $branchitemrule->{holdallowed} == 3 && !$item_library->validate_hold_sibling( {branchcode => $patron->branchcode} );
}
return $any_available ? 0 : 1;
if ( $rank eq "del" ) { # FIXME will crash if called without $hold
$hold->cancel;
}
- elsif ( $rank eq "W" || $rank eq "0" ) {
+ elsif ( $reserve_id && ( $rank eq "W" || $rank eq "0" ) ) {
# make sure priority for waiting or in-transit items is 0
my $query = "
push( @priority, $line );
}
+ # FIXME This whole sub must be rewritten, especially to highlight what is done when reserve_id is not given
# To find the matching index
my $i;
my $key = -1; # to allow for 0 to be a valid result
for ( $i = 0 ; $i < @priority ; $i++ ) {
- if ( $reserve_id == $priority[$i]->{'reserve_id'} ) {
+ if ( $reserve_id && $reserve_id == $priority[$i]->{'reserve_id'} ) {
$key = $i; # save the index
last;
}