Lines 1288-1294
sub CanBookBeIssued {
Link Here
|
1288 |
|
1288 |
|
1289 |
=head2 CanBookBeReturned |
1289 |
=head2 CanBookBeReturned |
1290 |
|
1290 |
|
1291 |
($returnallowed, $message) = CanBookBeReturned($item, $branch) |
1291 |
($returnallowed, $message) = CanBookBeReturned($item, $branch, [$transferbranch]) |
1292 |
|
1292 |
|
1293 |
Check whether the item can be returned to the provided branch |
1293 |
Check whether the item can be returned to the provided branch |
1294 |
|
1294 |
|
Lines 1313-1357
Returns:
Link Here
|
1313 |
=cut |
1313 |
=cut |
1314 |
|
1314 |
|
1315 |
sub CanBookBeReturned { |
1315 |
sub CanBookBeReturned { |
1316 |
my ($item, $branch) = @_; |
1316 |
my ($item, $returnbranch, $transferbranch) = @_; |
1317 |
my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere'; |
1317 |
my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere'; |
1318 |
|
1318 |
|
1319 |
# assume return is allowed to start |
1319 |
# assume return is allowed to start |
1320 |
my $allowed = 1; |
1320 |
my $allowed = 1; |
1321 |
my $to_branch = $branch; |
|
|
1322 |
my $message; |
1321 |
my $message; |
1323 |
|
1322 |
|
1324 |
# identify all cases where return is forbidden |
1323 |
# identify all cases where return is forbidden |
1325 |
if ($allowreturntobranch eq 'homebranch' && $branch ne $item->homebranch) { |
1324 |
if ($allowreturntobranch eq 'homebranch' && $returnbranch ne $item->homebranch) { |
1326 |
$allowed = 0; |
1325 |
$allowed = 0; |
1327 |
$message = $to_branch = $item->homebranch; |
1326 |
$message = $item->homebranch; |
1328 |
} elsif ($allowreturntobranch eq 'holdingbranch' && $branch ne $item->holdingbranch) { |
1327 |
} elsif ($allowreturntobranch eq 'holdingbranch' && $returnbranch ne $item->holdingbranch) { |
1329 |
$allowed = 0; |
1328 |
$allowed = 0; |
1330 |
$message = $to_branch = $item->holdingbranch; |
1329 |
$message = $item->holdingbranch; |
1331 |
} elsif ($allowreturntobranch eq 'homeorholdingbranch' && $branch ne $item->homebranch && $branch ne $item->holdingbranch) { |
1330 |
} elsif ($allowreturntobranch eq 'homeorholdingbranch' && $returnbranch ne $item->homebranch && $returnbranch ne $item->holdingbranch) { |
1332 |
$allowed = 0; |
1331 |
$allowed = 0; |
1333 |
$message = $to_branch = $item->homebranch; # FIXME: choice of homebranch is arbitrary |
1332 |
$message = $item->homebranch; # FIXME: choice of homebranch is arbitrary |
1334 |
} |
1333 |
} |
1335 |
|
1334 |
|
1336 |
return ($allowed, $message) unless $allowed; |
1335 |
# identify cases where transfer rules prohibit return |
1337 |
|
1336 |
if ( defined($transferbranch) && $allowed ) { |
1338 |
# Make sure there are no branch transfer limits between item's current |
1337 |
my $from_library = Koha::Libraries->find($returnbranch); |
1339 |
# branch (holdinbranch) and the return branch |
1338 |
my $to_library = Koha::Libraries->find($transferbranch); |
1340 |
my $return_library = Koha::Libraries->find($to_branch); |
1339 |
if ( !$item->can_be_transferred({ from => $from_library, to => $to_library }) ) { |
1341 |
if (!$item->can_be_transferred({ to => $return_library })) { |
1340 |
$allowed = 0; |
1342 |
return (0, $item->homebranch); |
1341 |
$message = $transferbranch; |
1343 |
} |
1342 |
} |
1344 |
|
|
|
1345 |
# Make sure there are no branch transfer limits between |
1346 |
# either homebranch and holdinbranch and the return branch |
1347 |
my $home_library = Koha::Libraries->find($item->homebranch); |
1348 |
my $holding_library = Koha::Libraries->find($item->holdingbranch); |
1349 |
if ($item->can_be_transferred({ from => $return_library , to => $holding_library }) or |
1350 |
$item->can_be_transferred({ from => $return_library , to => $home_library })) { |
1351 |
return (1, undef); |
1352 |
} |
1343 |
} |
1353 |
|
1344 |
|
1354 |
return (0, $item->homebranch); |
1345 |
return ($allowed, $message); |
1355 |
} |
1346 |
} |
1356 |
|
1347 |
|
1357 |
=head2 CheckHighHolds |
1348 |
=head2 CheckHighHolds |
Lines 2177-2183
sub AddReturn {
Link Here
|
2177 |
} |
2168 |
} |
2178 |
|
2169 |
|
2179 |
# check if the return is allowed at this branch |
2170 |
# check if the return is allowed at this branch |
2180 |
my ($returnallowed, $message) = CanBookBeReturned($item, $branch); |
2171 |
my ($returnallowed, $message) = CanBookBeReturned($item, $branch, $returnbranch); |
2181 |
|
2172 |
|
2182 |
unless ($returnallowed){ |
2173 |
unless ($returnallowed){ |
2183 |
$messages->{'Wrongbranch'} = { |
2174 |
$messages->{'Wrongbranch'} = { |
2184 |
- |
|
|