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

(-)a/C4/Circulation.pm (-28 / +18 lines)
Lines 1205-1211 sub CanBookBeIssued { Link Here
1205
1205
1206
=head2 CanBookBeReturned
1206
=head2 CanBookBeReturned
1207
1207
1208
  ($returnallowed, $message) = CanBookBeReturned($item, $branch)
1208
  ($returnallowed, $message) = CanBookBeReturned($item, $branch, [$transferbranch])
1209
1209
1210
Check whether the item can be returned to the provided branch
1210
Check whether the item can be returned to the provided branch
1211
1211
Lines 1230-1274 Returns: Link Here
1230
=cut
1230
=cut
1231
1231
1232
sub CanBookBeReturned {
1232
sub CanBookBeReturned {
1233
    my ($item, $branch) = @_;
1233
    my ($item, $returnbranch, $transferbranch) = @_;
1234
    my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere';
1234
    my $allowreturntobranch = C4::Context->preference("AllowReturnToBranch") || 'anywhere';
1235
1235
1236
    # assume return is allowed to start
1236
    # assume return is allowed to start
1237
    my $allowed = 1;
1237
    my $allowed = 1;
1238
    my $to_branch = $branch;
1239
    my $message;
1238
    my $message;
1240
1239
1241
    # identify all cases where return is forbidden
1240
    # identify all cases where return is forbidden
1242
    if ($allowreturntobranch eq 'homebranch' && $branch ne $item->homebranch) {
1241
    if ($allowreturntobranch eq 'homebranch' && $returnbranch ne $item->homebranch) {
1243
        $allowed = 0;
1242
        $allowed = 0;
1244
        $message = $to_branch = $item->homebranch;
1243
        $message = $item->homebranch;
1245
    } elsif ($allowreturntobranch eq 'holdingbranch' && $branch ne $item->holdingbranch) {
1244
    } elsif ($allowreturntobranch eq 'holdingbranch' && $returnbranch ne $item->holdingbranch) {
1246
        $allowed = 0;
1245
        $allowed = 0;
1247
        $message = $to_branch = $item->holdingbranch;
1246
        $message = $item->holdingbranch;
1248
    } elsif ($allowreturntobranch eq 'homeorholdingbranch' && $branch ne $item->homebranch && $branch ne $item->holdingbranch) {
1247
    } elsif ($allowreturntobranch eq 'homeorholdingbranch' && $returnbranch ne $item->homebranch && $returnbranch ne $item->holdingbranch) {
1249
        $allowed = 0;
1248
        $allowed = 0;
1250
        $message = $to_branch = $item->homebranch; # FIXME: choice of homebranch is arbitrary
1249
        $message = $item->homebranch; # FIXME: choice of homebranch is arbitrary
1251
    }
1250
    }
1252
1251
1253
    return ($allowed, $message) unless $allowed;
1252
    # identify cases where transfer rules prohibit return
1254
1253
    if ( defined($transferbranch) && $allowed ) {
1255
    # Make sure there are no branch transfer limits between item's current
1254
        my $from_library = Koha::Libraries->find($returnbranch);
1256
    # branch (holdinbranch) and the return branch
1255
        my $to_library   = Koha::Libraries->find($transferbranch);
1257
    my $return_library = Koha::Libraries->find($to_branch);
1256
        if ( !$item->can_be_transferred({ from => $from_library, to => $to_library }) ) {
1258
    if (!$item->can_be_transferred({ to => $return_library })) {
1257
            $allowed = 0;
1259
        return (0, $item->homebranch);
1258
            $message = $transferbranch;
1260
    }
1259
        }
1261
1262
    # Make sure there are no branch transfer limits between
1263
    # either homebranch and holdinbranch and the return branch
1264
    my $home_library = Koha::Libraries->find($item->homebranch);
1265
    my $holding_library = Koha::Libraries->find($item->holdingbranch);
1266
    if ($item->can_be_transferred({ from => $return_library , to => $holding_library }) or
1267
        $item->can_be_transferred({ from => $return_library , to => $home_library })) {
1268
        return (1, undef);
1269
    }
1260
    }
1270
1261
1271
    return (0, $item->homebranch);
1262
    return ($allowed, $message);
1272
}
1263
}
1273
1264
1274
=head2 CheckHighHolds
1265
=head2 CheckHighHolds
Lines 2056-2062 sub AddReturn { Link Here
2056
    }
2047
    }
2057
2048
2058
    # check if the return is allowed at this branch
2049
    # check if the return is allowed at this branch
2059
    my ($returnallowed, $message) = CanBookBeReturned($item, $branch);
2050
    my ($returnallowed, $message) = CanBookBeReturned($item, $branch, $returnbranch);
2060
2051
2061
    unless ($returnallowed){
2052
    unless ($returnallowed){
2062
        $messages->{'Wrongbranch'} = {
2053
        $messages->{'Wrongbranch'} = {
2063
- 

Return to bug 7376