Lines 1337-1343
sub CanBookBeIssued {
Link Here
|
1337 |
|
1337 |
|
1338 |
=head2 CanBookBeReturned |
1338 |
=head2 CanBookBeReturned |
1339 |
|
1339 |
|
1340 |
($returnallowed, $message) = CanBookBeReturned($item, $branch) |
1340 |
($returnallowed, $message) = CanBookBeReturned($item, $branch, [$transferbranch]) |
1341 |
|
1341 |
|
1342 |
Check whether the item can be returned to the provided branch |
1342 |
Check whether the item can be returned to the provided branch |
1343 |
|
1343 |
|
Lines 1362-1406
Returns:
Link Here
|
1362 |
=cut |
1362 |
=cut |
1363 |
|
1363 |
|
1364 |
sub CanBookBeReturned { |
1364 |
sub CanBookBeReturned { |
1365 |
my ($item, $branch) = @_; |
1365 |
my ($item, $returnbranch, $transferbranch) = @_; |
1366 |
my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere'; |
1366 |
my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere'; |
1367 |
|
1367 |
|
1368 |
# assume return is allowed to start |
1368 |
# assume return is allowed to start |
1369 |
my $allowed = 1; |
1369 |
my $allowed = 1; |
1370 |
my $to_branch = $branch; |
|
|
1371 |
my $message; |
1370 |
my $message; |
1372 |
|
1371 |
|
1373 |
# identify all cases where return is forbidden |
1372 |
# identify all cases where return is forbidden |
1374 |
if ($allowreturntobranch eq 'homebranch' && $branch ne $item->homebranch) { |
1373 |
if ($allowreturntobranch eq 'homebranch' && $returnbranch ne $item->homebranch) { |
1375 |
$allowed = 0; |
1374 |
$allowed = 0; |
1376 |
$message = $to_branch = $item->homebranch; |
1375 |
$message = $item->homebranch; |
1377 |
} elsif ($allowreturntobranch eq 'holdingbranch' && $branch ne $item->holdingbranch) { |
1376 |
} elsif ($allowreturntobranch eq 'holdingbranch' && $returnbranch ne $item->holdingbranch) { |
1378 |
$allowed = 0; |
1377 |
$allowed = 0; |
1379 |
$message = $to_branch = $item->holdingbranch; |
1378 |
$message = $item->holdingbranch; |
1380 |
} elsif ($allowreturntobranch eq 'homeorholdingbranch' && $branch ne $item->homebranch && $branch ne $item->holdingbranch) { |
1379 |
} elsif ($allowreturntobranch eq 'homeorholdingbranch' && $returnbranch ne $item->homebranch && $returnbranch ne $item->holdingbranch) { |
1381 |
$allowed = 0; |
1380 |
$allowed = 0; |
1382 |
$message = $to_branch = $item->homebranch; # FIXME: choice of homebranch is arbitrary |
1381 |
$message = $item->homebranch; # FIXME: choice of homebranch is arbitrary |
1383 |
} |
1382 |
} |
1384 |
|
1383 |
|
1385 |
return ($allowed, $message) unless $allowed; |
1384 |
# identify cases where transfer rules prohibit return |
1386 |
|
1385 |
if ( defined($transferbranch) && $allowed ) { |
1387 |
# Make sure there are no branch transfer limits between item's current |
1386 |
my $from_library = Koha::Libraries->find($returnbranch); |
1388 |
# branch (holdinbranch) and the return branch |
1387 |
my $to_library = Koha::Libraries->find($transferbranch); |
1389 |
my $return_library = Koha::Libraries->find($to_branch); |
1388 |
if ( !$item->can_be_transferred({ from => $from_library, to => $to_library }) ) { |
1390 |
if (!$item->can_be_transferred({ to => $return_library })) { |
1389 |
$allowed = 0; |
1391 |
return (0, $item->homebranch); |
1390 |
$message = $transferbranch; |
1392 |
} |
1391 |
} |
1393 |
|
|
|
1394 |
# Make sure there are no branch transfer limits between |
1395 |
# either homebranch and holdinbranch and the return branch |
1396 |
my $home_library = Koha::Libraries->find($item->homebranch); |
1397 |
my $holding_library = Koha::Libraries->find($item->holdingbranch); |
1398 |
if ($item->can_be_transferred({ from => $return_library , to => $holding_library }) or |
1399 |
$item->can_be_transferred({ from => $return_library , to => $home_library })) { |
1400 |
return (1, undef); |
1401 |
} |
1392 |
} |
1402 |
|
1393 |
|
1403 |
return (0, $item->homebranch); |
1394 |
return ($allowed, $message); |
1404 |
} |
1395 |
} |
1405 |
|
1396 |
|
1406 |
=head2 CheckHighHolds |
1397 |
=head2 CheckHighHolds |
Lines 2265-2271
sub AddReturn {
Link Here
|
2265 |
} |
2256 |
} |
2266 |
|
2257 |
|
2267 |
# check if the return is allowed at this branch |
2258 |
# check if the return is allowed at this branch |
2268 |
my ($returnallowed, $message) = CanBookBeReturned($item, $branch); |
2259 |
my ($returnallowed, $message) = CanBookBeReturned($item, $branch, $returnbranch); |
2269 |
|
2260 |
|
2270 |
unless ($returnallowed){ |
2261 |
unless ($returnallowed){ |
2271 |
$messages->{'Wrongbranch'} = { |
2262 |
$messages->{'Wrongbranch'} = { |
2272 |
- |
|
|