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

(-)a/C4/Circulation.pm (-26 / +40 lines)
Lines 963-969 sub CanBookBeIssued { Link Here
963
963
964
        my $patron = Koha::Patrons->find( $issue->borrowernumber );
964
        my $patron = Koha::Patrons->find( $issue->borrowernumber );
965
965
966
        my ( $can_be_returned, $message ) = CanBookBeReturned( $item_unblessed, C4::Context->userenv->{branch} );
966
        my ( $can_be_returned, $message ) = CanBookBeReturned( $item_object, C4::Context->userenv->{branch} );
967
967
968
        unless ( $can_be_returned ) {
968
        unless ( $can_be_returned ) {
969
            $issuingimpossible{RETURN_IMPOSSIBLE} = 1;
969
            $issuingimpossible{RETURN_IMPOSSIBLE} = 1;
Lines 1237-1243 Check whether the item can be returned to the provided branch Link Here
1237
1237
1238
=over 4
1238
=over 4
1239
1239
1240
=item C<$item> is a hash of item information as returned Koha::Items->find->unblessed (Temporary, should be a Koha::Item instead)
1240
=item C<$item> is a Koha::Item object
1241
1241
1242
=item C<$branch> is the branchcode where the return is taking place
1242
=item C<$branch> is the branchcode where the return is taking place
1243
1243
Lines 1256-1281 Returns: Link Here
1256
=cut
1256
=cut
1257
1257
1258
sub CanBookBeReturned {
1258
sub CanBookBeReturned {
1259
  my ($item, $branch) = @_;
1259
    my ($item, $branch) = @_;
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 $message;
1264
    my $to_branch = $branch;
1265
1265
    my $message;
1266
  # identify all cases where return is forbidden
1266
1267
  if ($allowreturntobranch eq 'homebranch' && $branch ne $item->{'homebranch'}) {
1267
    # identify all cases where return is forbidden
1268
     $allowed = 0;
1268
    if ($allowreturntobranch eq 'homebranch' && $branch ne $item->homebranch) {
1269
     $message = $item->{'homebranch'};
1269
        $allowed = 0;
1270
  } elsif ($allowreturntobranch eq 'holdingbranch' && $branch ne $item->{'holdingbranch'}) {
1270
        $message = $to_branch = $item->homebranch;
1271
     $allowed = 0;
1271
    } elsif ($allowreturntobranch eq 'holdingbranch' && $branch ne $item->holdingbranch) {
1272
     $message = $item->{'holdingbranch'};
1272
        $allowed = 0;
1273
  } elsif ($allowreturntobranch eq 'homeorholdingbranch' && $branch ne $item->{'homebranch'} && $branch ne $item->{'holdingbranch'}) {
1273
        $message = $to_branch = $item->holdingbranch;
1274
     $allowed = 0;
1274
    } elsif ($allowreturntobranch eq 'homeorholdingbranch' && $branch ne $item->homebranch && $branch ne $item->holdingbranch) {
1275
     $message = $item->{'homebranch'}; # FIXME: choice of homebranch is arbitrary
1275
        $allowed = 0;
1276
  }
1276
        $message = $to_branch = $item->homebranch; # FIXME: choice of homebranch is arbitrary
1277
1277
    }
1278
  return ($allowed, $message);
1278
1279
    # Make sure there are no branch transfer limits between item's current
1280
    # branch (holdinbranch) and the return branch
1281
    my $to_library = Koha::Libraries->find($to_branch);
1282
    if (!$item->can_be_transferred({ to => $to_library })) {
1283
        $allowed = 0;
1284
        $message = $item->homebranch;
1285
    }
1286
1287
    return ($allowed, $message);
1279
}
1288
}
1280
1289
1281
=head2 CheckHighHolds
1290
=head2 CheckHighHolds
Lines 1499-1505 sub AddIssue { Link Here
1499
            if ( $actualissue and not $switch_onsite_checkout ) {
1508
            if ( $actualissue and not $switch_onsite_checkout ) {
1500
                # This book is currently on loan, but not to the person
1509
                # This book is currently on loan, but not to the person
1501
                # who wants to borrow it now. mark it returned before issuing to the new borrower
1510
                # who wants to borrow it now. mark it returned before issuing to the new borrower
1502
                my ( $allowed, $message ) = CanBookBeReturned( $item_unblessed, C4::Context->userenv->{branch} );
1511
                my ( $allowed, $message ) = CanBookBeReturned( $item_object, C4::Context->userenv->{branch} );
1503
                return unless $allowed;
1512
                return unless $allowed;
1504
                AddReturn( $item_object->barcode, C4::Context->userenv->{'branch'} );
1513
                AddReturn( $item_object->barcode, C4::Context->userenv->{'branch'} );
1505
                # AddReturn certainly has side-effects, like onloan => undef
1514
                # AddReturn certainly has side-effects, like onloan => undef
Lines 1939-1944 This book has was returned to the wrong branch. The value is a hashref Link Here
1939
so that C<$messages->{Wrongbranch}->{Wrongbranch}> and C<$messages->{Wrongbranch}->{Rightbranch}>
1948
so that C<$messages->{Wrongbranch}->{Wrongbranch}> and C<$messages->{Wrongbranch}->{Rightbranch}>
1940
contain the branchcode of the incorrect and correct return library, respectively.
1949
contain the branchcode of the incorrect and correct return library, respectively.
1941
1950
1951
=item C<Transferlimit>
1952
1953
A transfer limit exists between item's holding branch and the return branch.
1954
1942
=item C<ResFound>
1955
=item C<ResFound>
1943
1956
1944
The item was reserved. The value is a reference-to-hash whose keys are
1957
The item was reserved. The value is a reference-to-hash whose keys are
Lines 2062-2073 sub AddReturn { Link Here
2062
    }
2075
    }
2063
2076
2064
    # check if the return is allowed at this branch
2077
    # check if the return is allowed at this branch
2065
    my ($returnallowed, $message) = CanBookBeReturned($item->unblessed, $branch);
2078
    my ($returnallowed, $message) = CanBookBeReturned($item, $branch);
2079
2066
    unless ($returnallowed){
2080
    unless ($returnallowed){
2067
        $messages->{'Wrongbranch'} = {
2081
        $messages->{'Wrongbranch'} = {
2068
            Wrongbranch => $branch,
2082
            Wrongbranch => $branch,
2069
            Rightbranch => $message
2083
            Rightbranch => $message
2070
        };
2084
        } if $message;
2085
2071
        $doreturn = 0;
2086
        $doreturn = 0;
2072
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
2087
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
2073
        $indexer->index_records( $item->biblionumber, "specialUpdate", "biblioserver" );
2088
        $indexer->index_records( $item->biblionumber, "specialUpdate", "biblioserver" );
2074
- 

Return to bug 7376