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

(-)a/C4/Circulation.pm (-15 / +25 lines)
Lines 58-63 use Koha::Config::SysPrefs; Link Here
58
use Koha::Charges::Fees;
58
use Koha::Charges::Fees;
59
use Koha::Util::SystemPreferences;
59
use Koha::Util::SystemPreferences;
60
use Koha::Checkouts::ReturnClaims;
60
use Koha::Checkouts::ReturnClaims;
61
use Koha::SearchEngine::Indexer;
61
use Carp;
62
use Carp;
62
use List::MoreUtils qw( uniq any );
63
use List::MoreUtils qw( uniq any );
63
use Scalar::Util qw( looks_like_number );
64
use Scalar::Util qw( looks_like_number );
Lines 1898-1904 sub AddReturn { Link Here
1898
                . Dumper($issue->unblessed) . "\n";
1899
                . Dumper($issue->unblessed) . "\n";
1899
    } else {
1900
    } else {
1900
        $messages->{'NotIssued'} = $barcode;
1901
        $messages->{'NotIssued'} = $barcode;
1901
        $item->onloan(undef)->store if defined $item->onloan;
1902
        $item->onloan(undef)->store({skip_record_index=>1}) if defined $item->onloan;
1902
1903
1903
        # even though item is not on loan, it may still be transferred;  therefore, get current branch info
1904
        # even though item is not on loan, it may still be transferred;  therefore, get current branch info
1904
        $doreturn = 0;
1905
        $doreturn = 0;
Lines 1926-1934 sub AddReturn { Link Here
1926
        if (defined $update_loc_rules->{_ALL_}) {
1927
        if (defined $update_loc_rules->{_ALL_}) {
1927
            if ($update_loc_rules->{_ALL_} eq '_PERM_') { $update_loc_rules->{_ALL_} = $item->permanent_location; }
1928
            if ($update_loc_rules->{_ALL_} eq '_PERM_') { $update_loc_rules->{_ALL_} = $item->permanent_location; }
1928
            if ($update_loc_rules->{_ALL_} eq '_BLANK_') { $update_loc_rules->{_ALL_} = ''; }
1929
            if ($update_loc_rules->{_ALL_} eq '_BLANK_') { $update_loc_rules->{_ALL_} = ''; }
1929
            if ( $item->location ne $update_loc_rules->{_ALL_}) {
1930
            if ( defined $item->location && $item->location ne $update_loc_rules->{_ALL_}) {
1930
                $messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{_ALL_} };
1931
                $messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{_ALL_} };
1931
                $item->location($update_loc_rules->{_ALL_})->store;
1932
                $item->location($update_loc_rules->{_ALL_})->store({skip_record_index=>1});
1932
            }
1933
            }
1933
        }
1934
        }
1934
        else {
1935
        else {
Lines 1937-1943 sub AddReturn { Link Here
1937
                if ( $update_loc_rules->{$key} eq '_BLANK_') { $update_loc_rules->{$key} = '' ;}
1938
                if ( $update_loc_rules->{$key} eq '_BLANK_') { $update_loc_rules->{$key} = '' ;}
1938
                if ( ($item->location eq $key && $item->location ne $update_loc_rules->{$key}) || ($key eq '_BLANK_' && $item->location eq '' && $update_loc_rules->{$key} ne '') ) {
1939
                if ( ($item->location eq $key && $item->location ne $update_loc_rules->{$key}) || ($key eq '_BLANK_' && $item->location eq '' && $update_loc_rules->{$key} ne '') ) {
1939
                    $messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{$key} };
1940
                    $messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{$key} };
1940
                    $item->location($update_loc_rules->{$key})->store;
1941
                    $item->location($update_loc_rules->{$key})->store({skip_record_index=>1});
1941
                    last;
1942
                    last;
1942
                }
1943
                }
1943
            }
1944
            }
Lines 1956-1962 sub AddReturn { Link Here
1956
            foreach my $key ( keys %$rules ) {
1957
            foreach my $key ( keys %$rules ) {
1957
                if ( $item->notforloan eq $key ) {
1958
                if ( $item->notforloan eq $key ) {
1958
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$key} };
1959
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$key} };
1959
                    $item->notforloan($rules->{$key})->store({ log_action => 0 });
1960
                    $item->notforloan($rules->{$key})->store({ log_action => 0, skip_record_index => 1 });
1960
                    last;
1961
                    last;
1961
                }
1962
                }
1962
            }
1963
            }
Lines 1970-1976 sub AddReturn { Link Here
1970
            Wrongbranch => $branch,
1971
            Wrongbranch => $branch,
1971
            Rightbranch => $message
1972
            Rightbranch => $message
1972
        };
1973
        };
1973
        $doreturn = 0;
1974
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
1975
        $indexer->index_records( $item->biblionumber, "specialUpdate", "biblioserver" );
1974
        return ( $doreturn, $messages, $issue, $patron_unblessed);
1976
        return ( $doreturn, $messages, $issue, $patron_unblessed);
1975
    }
1977
    }
1976
1978
Lines 1990-1996 sub AddReturn { Link Here
1990
1992
1991
        if ($patron) {
1993
        if ($patron) {
1992
            eval {
1994
            eval {
1993
                MarkIssueReturned( $borrowernumber, $item->itemnumber, $return_date, $patron->privacy );
1995
                MarkIssueReturned( $borrowernumber, $item->itemnumber, $return_date, $patron->privacy, { skip_record_index => 1} );
1994
            };
1996
            };
1995
            unless ( $@ ) {
1997
            unless ( $@ ) {
1996
                if (
1998
                if (
Lines 2006-2031 sub AddReturn { Link Here
2006
            } else {
2008
            } else {
2007
                carp "The checkin for the following issue failed, Please go to the about page, section 'data corrupted' to know how to fix this problem ($@)" . Dumper( $issue->unblessed );
2009
                carp "The checkin for the following issue failed, Please go to the about page, section 'data corrupted' to know how to fix this problem ($@)" . Dumper( $issue->unblessed );
2008
2010
2011
                my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
2012
                $indexer->index_records( $item->biblionumber, "specialUpdate", "biblioserver" );
2013
2009
                return ( 0, { WasReturned => 0, DataCorrupted => 1 }, $issue, $patron_unblessed );
2014
                return ( 0, { WasReturned => 0, DataCorrupted => 1 }, $issue, $patron_unblessed );
2010
            }
2015
            }
2011
2016
2012
            # FIXME is the "= 1" right?  This could be the borrower hash.
2017
            # FIXME is the "= 1" right?  This could be the borrower hash.
2013
            $messages->{'WasReturned'} = 1;
2018
            $messages->{'WasReturned'} = 1;
2014
2019
2020
        } else {
2021
            $item->onloan(undef)->store({ log_action => 0 , skip_record_index => 1 });
2015
        }
2022
        }
2016
2017
        $item->onloan(undef)->store({ log_action => 0 });
2018
    }
2023
    }
2019
2024
2020
    # the holdingbranch is updated if the document is returned to another location.
2025
    # the holdingbranch is updated if the document is returned to another location.
2021
    # this is always done regardless of whether the item was on loan or not
2026
    # this is always done regardless of whether the item was on loan or not
2022
    if ($item->holdingbranch ne $branch) {
2027
    if ($item->holdingbranch ne $branch) {
2023
        $item->holdingbranch($branch)->store;
2028
        $item->holdingbranch($branch)->store({ skip_record_index => 1 });
2024
    }
2029
    }
2025
2030
2026
    my $item_was_lost = $item->itemlost;
2031
    my $item_was_lost = $item->itemlost;
2027
    my $leave_item_lost = C4::Context->preference("BlockReturnOfLostItems") ? 1 : 0;
2032
    my $leave_item_lost = C4::Context->preference("BlockReturnOfLostItems") ? 1 : 0;
2028
    my $updated_item = ModDateLastSeen( $item->itemnumber, $leave_item_lost ); # will unset itemlost if needed
2033
    my $updated_item = ModDateLastSeen( $item->itemnumber, $leave_item_lost, { skip_record_index => 1 } ); # will unset itemlost if needed
2029
2034
2030
    # fix up the accounts.....
2035
    # fix up the accounts.....
2031
    if ( $item_was_lost ) {
2036
    if ( $item_was_lost ) {
Lines 2150-2156 sub AddReturn { Link Here
2150
           )) {
2155
           )) {
2151
            $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s, %s)", $item->itemnumber,$branch, $returnbranch, $transfer_trigger;
2156
            $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s, %s)", $item->itemnumber,$branch, $returnbranch, $transfer_trigger;
2152
            $debug and warn "item: " . Dumper($item->unblessed);
2157
            $debug and warn "item: " . Dumper($item->unblessed);
2153
            ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger);
2158
            ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger, { skip_record_index => 1 });
2154
            $messages->{'WasTransfered'} = 1;
2159
            $messages->{'WasTransfered'} = 1;
2155
        } else {
2160
        } else {
2156
            $messages->{'NeedsTransfer'} = $returnbranch;
2161
            $messages->{'NeedsTransfer'} = $returnbranch;
Lines 2171-2176 sub AddReturn { Link Here
2171
        }
2176
        }
2172
    }
2177
    }
2173
2178
2179
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
2180
    $indexer->index_records( $item->biblionumber, "specialUpdate", "biblioserver" );
2181
2174
    if ( $doreturn and $issue ) {
2182
    if ( $doreturn and $issue ) {
2175
        my $checkin = Koha::Old::Checkouts->find($issue->id);
2183
        my $checkin = Koha::Old::Checkouts->find($issue->id);
2176
2184
Lines 2187-2193 sub AddReturn { Link Here
2187
2195
2188
=head2 MarkIssueReturned
2196
=head2 MarkIssueReturned
2189
2197
2190
  MarkIssueReturned($borrowernumber, $itemnumber, $returndate, $privacy);
2198
  MarkIssueReturned($borrowernumber, $itemnumber, $returndate, $privacy, [$params] );
2191
2199
2192
Unconditionally marks an issue as being returned by
2200
Unconditionally marks an issue as being returned by
2193
moving the C<issues> row to C<old_issues> and
2201
moving the C<issues> row to C<old_issues> and
Lines 2203-2212 Ideally, this function would be internal to C<C4::Circulation>, Link Here
2203
not exported, but it is currently used in misc/cronjobs/longoverdue.pl
2211
not exported, but it is currently used in misc/cronjobs/longoverdue.pl
2204
and offline_circ/process_koc.pl.
2212
and offline_circ/process_koc.pl.
2205
2213
2214
The last optional parameter allos passing skip_record_index to the item store call.
2215
2206
=cut
2216
=cut
2207
2217
2208
sub MarkIssueReturned {
2218
sub MarkIssueReturned {
2209
    my ( $borrowernumber, $itemnumber, $returndate, $privacy ) = @_;
2219
    my ( $borrowernumber, $itemnumber, $returndate, $privacy, $params ) = @_;
2210
2220
2211
    # Retrieve the issue
2221
    # Retrieve the issue
2212
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
2222
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
Lines 2252-2258 sub MarkIssueReturned { Link Here
2252
        # And finally delete the issue
2262
        # And finally delete the issue
2253
        $issue->delete;
2263
        $issue->delete;
2254
2264
2255
        $issue->item->onloan(undef)->store({ log_action => 0 });
2265
        $issue->item->onloan(undef)->store({ log_action => 0, skip_record_index => $params->{skip_record_index} });
2256
2266
2257
        if ( C4::Context->preference('StoreLastBorrower') ) {
2267
        if ( C4::Context->preference('StoreLastBorrower') ) {
2258
            my $item = Koha::Items->find( $itemnumber );
2268
            my $item = Koha::Items->find( $itemnumber );
(-)a/C4/Items.pm (-8 / +11 lines)
Lines 334-347 sub ModItemFromMarc { Link Here
334
334
335
=head2 ModItemTransfer
335
=head2 ModItemTransfer
336
336
337
  ModItemTransfer($itemnumber, $frombranch, $tobranch, $trigger);
337
  ModItemTransfer($itemnumber, $frombranch, $tobranch, $trigger, [$params]);
338
338
339
Marks an item as being transferred from one branch to another and records the trigger.
339
Marks an item as being transferred from one branch to another and records the trigger.
340
340
341
The last optional parameter allows for passing skip_record_index through to the items store call.
342
341
=cut
343
=cut
342
344
343
sub ModItemTransfer {
345
sub ModItemTransfer {
344
    my ( $itemnumber, $frombranch, $tobranch, $trigger ) = @_;
346
    my ( $itemnumber, $frombranch, $tobranch, $trigger, $params ) = @_;
345
347
346
    my $dbh = C4::Context->dbh;
348
    my $dbh = C4::Context->dbh;
347
    my $item = Koha::Items->find( $itemnumber );
349
    my $item = Koha::Items->find( $itemnumber );
Lines 358-387 sub ModItemTransfer { Link Here
358
    $sth->execute($itemnumber, $frombranch, $tobranch, $trigger);
360
    $sth->execute($itemnumber, $frombranch, $tobranch, $trigger);
359
361
360
    # FIXME we are fetching the item twice in the 2 next statements!
362
    # FIXME we are fetching the item twice in the 2 next statements!
361
    Koha::Items->find($itemnumber)->holdingbranch($frombranch)->store({ log_action => 0 });
363
    Koha::Items->find($itemnumber)->holdingbranch($frombranch)->store({ log_action => 0, skip_record_index => $params->{skip_record_index} });
362
    ModDateLastSeen($itemnumber);
364
    ModDateLastSeen($itemnumber, undef, { skip_record_index => $params->{skip_record_index} });
363
    return;
365
    return;
364
}
366
}
365
367
366
=head2 ModDateLastSeen
368
=head2 ModDateLastSeen
367
369
368
ModDateLastSeen( $itemnumber, $leave_item_lost );
370
ModDateLastSeen( $itemnumber, $leave_item_lost, $params );
369
371
370
Mark item as seen. Is called when an item is issued, returned or manually marked during inventory/stocktaking.
372
Mark item as seen. Is called when an item is issued, returned or manually marked during inventory/stocktaking.
371
C<$itemnumber> is the item number
373
C<$itemnumber> is the item number
372
C<$leave_item_lost> determines if a lost item will be found or remain lost
374
C<$leave_item_lost> determines if a lost item will be found or remain lost
373
375
376
The last optional parameter allows for passing skip_record_index through to the items store call.
377
374
=cut
378
=cut
375
379
376
sub ModDateLastSeen {
380
sub ModDateLastSeen {
377
    my ( $itemnumber, $leave_item_lost ) = @_;
381
    my ( $itemnumber, $leave_item_lost, $params ) = @_;
378
382
379
    my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
383
    my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
380
384
381
    my $item = Koha::Items->find($itemnumber);
385
    my $item = Koha::Items->find($itemnumber);
382
    $item->datelastseen($today);
386
    $item->datelastseen($today);
383
    $item->itemlost(0) unless $leave_item_lost;
387
    $item->itemlost(0) unless $leave_item_lost;
384
    $item->store({ log_action => 0 });
388
    $item->store({ log_action => 0, skip_record_index => $params->{skip_record_index} });
385
}
389
}
386
390
387
=head2 CheckItemPreSave
391
=head2 CheckItemPreSave
388
- 

Return to bug 26581