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');
return { status => 'cannotReserveFromOtherBranches' };
}
- my $branch_control = C4::Context->preference('HomeOrHoldingBranch');
- my $itembranchcode = $branch_control eq 'holdingbranch' ? $item->holdingbranch : $item->homebranch;
- my $item_library = Koha::Libraries->find( {branchcode => $itembranchcode} );
+ my $item_library = Koha::Libraries->find( {branchcode => $item->homebranch} );
if ( $branchitemrule->{holdallowed} == 3) {
- if($borrower->{branchcode} ne $itembranchcode && !$item_library->validate_hold_sibling( {branchcode => $borrower->{branchcode}} )) {
+ if($borrower->{branchcode} ne $item->homebranch && !$item_library->validate_hold_sibling( {branchcode => $borrower->{branchcode}} )) {
return { status => 'branchNotInHoldGroup' };
}
}
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=>$branch});
+ 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 eq 'holdgroup') && (!$library->validate_hold_sibling({branchcode => $res->{branchcode}})) );
$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 );
}
foreach my $i (@items) {
my $reserves_control_branch = GetReservesControlBranch( $i->unblessed(), $patron->unblessed );
my $branchitemrule = C4::Circulation::GetBranchItemRule( $reserves_control_branch, $i->itype );
- my $branch_control = C4::Context->preference('HomeOrHoldingBranch');
- my $itembranchcode = $branch_control eq 'holdingbranch' ? $item->holdingbranch : $item->homebranch;
- my $item_library = Koha::Libraries->find( {branchcode => $itembranchcode} );
+ my $item_library = Koha::Libraries->find( {branchcode => $i->homebranch} );
$any_available = 1
&& !C4::Context->preference('AllowHoldsOnDamagedItems') )
|| Koha::ItemTypes->find( $i->effective_itemtype() )->notforloan
|| $branchitemrule->{holdallowed} == 1 && $patron->branchcode ne $i->homebranch
- || $branchitemrule->{holdallowed} == 3 && !$item_library->validate_hold_sibling( {branchcode => $pickup_branchcode} );
+ || $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;
}