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

(-)a/C4/Circulation.pm (-28 / +18 lines)
Lines 1231-1237 sub CanBookBeIssued { Link Here
1231
1231
1232
=head2 CanBookBeReturned
1232
=head2 CanBookBeReturned
1233
1233
1234
  ($returnallowed, $message) = CanBookBeReturned($item, $branch)
1234
  ($returnallowed, $message) = CanBookBeReturned($item, $branch, [$transferbranch])
1235
1235
1236
Check whether the item can be returned to the provided branch
1236
Check whether the item can be returned to the provided branch
1237
1237
Lines 1256-1300 Returns: Link Here
1256
=cut
1256
=cut
1257
1257
1258
sub CanBookBeReturned {
1258
sub CanBookBeReturned {
1259
    my ($item, $branch) = @_;
1259
    my ($item, $returnbranch, $transferbranch) = @_;
1260
    my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere';
1260
    my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere';
1261
1261
1262
    # assume return is allowed to start
1262
    # assume return is allowed to start
1263
    my $allowed = 1;
1263
    my $allowed = 1;
1264
    my $to_branch = $branch;
1265
    my $message;
1264
    my $message;
1266
1265
1267
    # identify all cases where return is forbidden
1266
    # identify all cases where return is forbidden
1268
    if ($allowreturntobranch eq 'homebranch' && $branch ne $item->homebranch) {
1267
    if ($allowreturntobranch eq 'homebranch' && $returnbranch ne $item->homebranch) {
1269
        $allowed = 0;
1268
        $allowed = 0;
1270
        $message = $to_branch = $item->homebranch;
1269
        $message = $item->homebranch;
1271
    } elsif ($allowreturntobranch eq 'holdingbranch' && $branch ne $item->holdingbranch) {
1270
    } elsif ($allowreturntobranch eq 'holdingbranch' && $returnbranch ne $item->holdingbranch) {
1272
        $allowed = 0;
1271
        $allowed = 0;
1273
        $message = $to_branch = $item->holdingbranch;
1272
        $message = $item->holdingbranch;
1274
    } elsif ($allowreturntobranch eq 'homeorholdingbranch' && $branch ne $item->homebranch && $branch ne $item->holdingbranch) {
1273
    } elsif ($allowreturntobranch eq 'homeorholdingbranch' && $returnbranch ne $item->homebranch && $returnbranch ne $item->holdingbranch) {
1275
        $allowed = 0;
1274
        $allowed = 0;
1276
        $message = $to_branch = $item->homebranch; # FIXME: choice of homebranch is arbitrary
1275
        $message = $item->homebranch; # FIXME: choice of homebranch is arbitrary
1277
    }
1276
    }
1278
1277
1279
    return ($allowed, $message) unless $allowed;
1278
    # identify cases where transfer rules prohibit return
1280
1279
    if ( defined($transferbranch) && $allowed ) {
1281
    # Make sure there are no branch transfer limits between item's current
1280
        my $from_library = Koha::Libraries->find($returnbranch);
1282
    # branch (holdinbranch) and the return branch
1281
        my $to_library   = Koha::Libraries->find($transferbranch);
1283
    my $return_library = Koha::Libraries->find($to_branch);
1282
        if ( !$item->can_be_transferred({ from => $from_library, to => $to_library }) ) {
1284
    if (!$item->can_be_transferred({ to => $return_library })) {
1283
            $allowed = 0;
1285
        return (0, $item->homebranch);
1284
            $message = $transferbranch;
1286
    }
1285
        }
1287
1288
    # Make sure there are no branch transfer limits between
1289
    # either homebranch and holdinbranch and the return branch
1290
    my $home_library = Koha::Libraries->find($item->homebranch);
1291
    my $holding_library = Koha::Libraries->find($item->holdingbranch);
1292
    if ($item->can_be_transferred({ from => $return_library , to => $holding_library }) or
1293
        $item->can_be_transferred({ from => $return_library , to => $home_library })) {
1294
        return (1, undef);
1295
    }
1286
    }
1296
1287
1297
    return (0, $item->homebranch);
1288
    return ($allowed, $message);
1298
}
1289
}
1299
1290
1300
=head2 CheckHighHolds
1291
=head2 CheckHighHolds
Lines 2085-2091 sub AddReturn { Link Here
2085
    }
2076
    }
2086
2077
2087
    # check if the return is allowed at this branch
2078
    # check if the return is allowed at this branch
2088
    my ($returnallowed, $message) = CanBookBeReturned($item, $branch);
2079
    my ($returnallowed, $message) = CanBookBeReturned($item, $branch, $returnbranch);
2089
2080
2090
    unless ($returnallowed){
2081
    unless ($returnallowed){
2091
        $messages->{'Wrongbranch'} = {
2082
        $messages->{'Wrongbranch'} = {
2092
- 

Return to bug 7376