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

(-)a/C4/Circulation.pm (-35 / +51 lines)
Lines 2265-2295 sub AddReturn { Link Here
2265
    my $validTransfer = 1;
2265
    my $validTransfer = 1;
2266
    my $stat_type     = 'return';
2266
    my $stat_type     = 'return';
2267
2267
2268
    # get information on item
2268
    # Get item
2269
    my $item = Koha::Items->find( { barcode => $barcode } );
2269
    my $item = Koha::Items->find( { barcode => $barcode } );
2270
    unless ($item) {
2270
    unless ($item) {
2271
        return ( 0, { BadBarcode => $barcode } );    # no barcode means no item or borrower.  bail out.
2271
        return ( 0, { BadBarcode => $barcode } );    # no barcode means no item or borrower.  bail out.
2272
    }
2272
    }
2273
2273
2274
    # Check availability
2275
    my $availability = $item->checkin_availability( { branch => $branch } );
2276
2277
    # Extract context objects
2278
    my $issue = $availability->context->{checkout};
2279
    $patron = $availability->context->{patron};
2280
2281
    # Set NotIssued message if item not checked out
2282
    if ( !$issue ) {
2283
        $messages->{'NotIssued'} = $barcode;
2284
        $item->onloan(undef)->store( { skip_record_index => 1, skip_holds_queue => 1 } ) if defined $item->onloan;
2285
        $doreturn = 0;
2286
    }
2287
2288
    # Handle blockers
2289
    if ( !$availability->available ) {
2290
        my $blockers = $availability->blockers;
2291
2292
        if ( $blockers->{BlockedWithdrawn} ) {
2293
            $messages->{'withdrawn'} = 1;
2294
2295
            # Record local use even when blocked, if preference is on
2296
            if ( !$issue && C4::Context->preference("RecordLocalUseOnReturn") ) {
2297
                my $localuse_count = $item->localuse || 0;
2298
                $localuse_count++;
2299
                $item->localuse($localuse_count)->store;
2300
                $messages->{'LocalUse'} = 1;
2301
            }
2302
2303
            return ( 0, $messages, $issue, ( $patron ? $patron->unblessed : {} ) );
2304
        }
2305
        if ( $blockers->{BlockedLost} ) {
2306
            $doreturn = 0;
2307
        }
2308
        if ( $blockers->{Wrongbranch} ) {
2309
            $messages->{'Wrongbranch'} = $blockers->{Wrongbranch};
2310
            $doreturn = 0;
2311
            my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
2312
            $indexer->index_records( $item->biblionumber, "specialUpdate", "biblioserver" );
2313
            return ( $doreturn, $messages, $issue, ( $patron ? $patron->unblessed : {} ) );
2314
        }
2315
    }
2316
2274
    my $itemnumber     = $item->itemnumber;
2317
    my $itemnumber     = $item->itemnumber;
2275
    my $itemtype       = $item->effective_itemtype;
2318
    my $itemtype       = $item->effective_itemtype;
2276
    my $localuse_count = $item->localuse || 0;
2319
    my $localuse_count = $item->localuse || 0;
2277
2320
2278
    my $issue = $item->checkout;
2321
    # Data consistency check for issued items
2279
    if ($issue) {
2322
    if ( $issue && !$patron ) {
2280
        $patron = $issue->patron
2323
        die
2281
            or die
2282
            "Data inconsistency: barcode $barcode (itemnumber:$itemnumber) claims to be issued to non-existent borrowernumber '"
2324
            "Data inconsistency: barcode $barcode (itemnumber:$itemnumber) claims to be issued to non-existent borrowernumber '"
2283
            . $issue->borrowernumber . "'\n"
2325
            . $issue->borrowernumber . "'\n"
2284
            . Dumper( $issue->unblessed ) . "\n";
2326
            . Dumper( $issue->unblessed ) . "\n";
2285
    } else {
2327
    }
2286
        $messages->{'NotIssued'} = $barcode;
2287
        $item->onloan(undef)->store( { skip_record_index => 1, skip_holds_queue => 1 } ) if defined $item->onloan;
2288
2328
2289
        # even though item is not on loan, it may still be transferred;  therefore, get current branch info
2329
    # Handle not issued items (continued)
2290
        $doreturn = 0;
2330
    if ( !$issue ) {
2291
2331
2292
        # No issue, no borrowernumber.  ONLY if $doreturn, *might* you have a $borrower later.
2293
        # Record this as a local use, instead of a return, if the RecordLocalUseOnReturn is on
2332
        # Record this as a local use, instead of a return, if the RecordLocalUseOnReturn is on
2294
        if ( C4::Context->preference("RecordLocalUseOnReturn") ) {
2333
        if ( C4::Context->preference("RecordLocalUseOnReturn") ) {
2295
            $localuse_count++;
2334
            $localuse_count++;
Lines 2301-2311 sub AddReturn { Link Here
2301
2340
2302
    if ( $item->withdrawn ) {    # book has been cancelled
2341
    if ( $item->withdrawn ) {    # book has been cancelled
2303
        $messages->{'withdrawn'} = 1;
2342
        $messages->{'withdrawn'} = 1;
2304
2305
        # In the case where we block return of withdrawn, we should completely block the return
2306
        # without updating item statuses, so we exit early
2307
        return ( 0, $messages, $issue, ( $patron ? $patron->unblessed : {} ) )
2308
            if C4::Context->preference("BlockReturnOfWithdrawnItems");
2309
    }
2343
    }
2310
2344
2311
    # full item data, but no borrowernumber or checkout info (no issue)
2345
    # full item data, but no borrowernumber or checkout info (no issue)
Lines 2367-2389 sub AddReturn { Link Here
2367
        }
2401
        }
2368
    }
2402
    }
2369
2403
2370
    # check if the return is allowed at this branch
2371
    my ( $returnallowed, $message ) = CanBookBeReturned( $item->unblessed, $branch );
2372
    unless ($returnallowed) {
2373
        $messages->{'Wrongbranch'} = {
2374
            Wrongbranch => $branch,
2375
            Rightbranch => $message
2376
        };
2377
        $doreturn = 0;
2378
        my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
2379
        $indexer->index_records( $item->biblionumber, "specialUpdate", "biblioserver" );
2380
        return ( $doreturn, $messages, $issue, $patron_unblessed );
2381
    }
2382
2383
    if ( $item->itemlost and C4::Context->preference("BlockReturnOfLostItems") ) {
2384
        $doreturn = 0;
2385
    }
2386
2387
    # case of a return of document (deal with issues and holdingbranch)
2404
    # case of a return of document (deal with issues and holdingbranch)
2388
    if ($doreturn) {
2405
    if ($doreturn) {
2389
        die "The item is not issed and cannot be returned" unless $issue;    # Just in case...
2406
        die "The item is not issed and cannot be returned" unless $issue;    # Just in case...
Lines 3307-3313 sub CanBookBeRenewed { Link Here
3307
                        unless CanItemBeReserved(
3324
                        unless CanItemBeReserved(
3308
                        $patron_with_reserve, $other_item, undef,
3325
                        $patron_with_reserve, $other_item, undef,
3309
                        { ignore_hold_counts => 1 }
3326
                        { ignore_hold_counts => 1 }
3310
                    )->{status} eq 'OK';
3327
                        )->{status} eq 'OK';
3311
3328
3312
                    # NOTE: At checkin we call 'CheckReserves' which checks hold 'policy'
3329
                    # NOTE: At checkin we call 'CheckReserves' which checks hold 'policy'
3313
                    # CanItemBeReserved checks 'rules' and 'policies' which means
3330
                    # CanItemBeReserved checks 'rules' and 'policies' which means
3314
- 

Return to bug 41728