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

(-)a/C4/Circulation.pm (-24 / +18 lines)
Lines 45-50 use Koha::DateUtils; Link Here
45
use Koha::Calendar;
45
use Koha::Calendar;
46
use Koha::IssuingRules;
46
use Koha::IssuingRules;
47
use Koha::Items;
47
use Koha::Items;
48
use Koha::Checkouts;
49
use Koha::OldIssues;
48
use Koha::Patrons;
50
use Koha::Patrons;
49
use Koha::Patron::Debarments;
51
use Koha::Patron::Debarments;
50
use Koha::Database;
52
use Koha::Database;
Lines 1929-1949 sub AddReturn { Link Here
1929
        }
1931
        }
1930
1932
1931
        if ($borrowernumber) {
1933
        if ($borrowernumber) {
1932
            if ( ( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'} ) || $return_date ) {
1933
                _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $borrower, return_date => $return_date } );
1934
            }
1935
1936
            eval {
1934
            eval {
1937
                MarkIssueReturned( $borrowernumber, $item->{'itemnumber'},
1935
                MarkIssueReturned( $borrowernumber, $item->{'itemnumber'},
1938
                    $circControlBranch, $return_date, $borrower->{'privacy'} );
1936
                    $circControlBranch, $return_date, $borrower->{'privacy'} );
1939
            };
1937
            };
1940
            if ( $@ ) {
1938
            unless ( $@ ) {
1941
                $messages->{'Wrongbranch'} = {
1939
                if ( ( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'} ) || $return_date ) {
1942
                    Wrongbranch => $branch,
1940
                    _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $borrower, return_date => $return_date } );
1943
                    Rightbranch => $message
1941
                }
1944
                };
1942
            } else {
1945
                carp $@;
1943
                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 );
1946
                return ( 0, { WasReturned => 0 }, $issue, $borrower );
1944
1945
                return ( 0, { WasReturned => 0, DataCorrupted => 1 }, $issue, $borrower );
1947
            }
1946
            }
1948
1947
1949
            # FIXME is the "= 1" right?  This could be the borrower hash.
1948
            # FIXME is the "= 1" right?  This could be the borrower hash.
Lines 2167-2187 sub MarkIssueReturned { Link Here
2167
2166
2168
    # FIXME Improve the return value and handle it from callers
2167
    # FIXME Improve the return value and handle it from callers
2169
    $schema->txn_do(sub {
2168
    $schema->txn_do(sub {
2169
2170
        # Update the returndate
2170
        $dbh->do( $query, undef, @bind );
2171
        $dbh->do( $query, undef, @bind );
2171
2172
2172
        my $id_already_exists = $dbh->selectrow_array(
2173
        # Retrieve the issue
2173
            q|SELECT COUNT(*) FROM old_issues WHERE issue_id = ?|,
2174
        my $issue = Koha::Checkouts->find( $issue_id ); # FIXME should be fetched earlier
2174
            undef, $issue_id
2175
        );
2176
2175
2177
        if ( $id_already_exists ) {
2176
        # Create the old_issues entry
2178
            my $new_issue_id = $dbh->selectrow_array(q|SELECT MAX(issue_id)+1 FROM old_issues|);
2177
        my $old_checkout = Koha::OldIssue->new($issue->unblessed)->store;
2179
            $dbh->do(
2180
                q|UPDATE issues SET issue_id = ? WHERE issue_id = ?|,
2181
                undef, $new_issue_id, $issue_id
2182
            );
2183
            $issue_id = $new_issue_id;
2184
        }
2185
2178
2186
        $dbh->do(q|INSERT INTO old_issues SELECT * FROM issues WHERE issue_id = ?|, undef, $issue_id);
2179
        $dbh->do(q|INSERT INTO old_issues SELECT * FROM issues WHERE issue_id = ?|, undef, $issue_id);
2187
2180
Lines 2190-2196 sub MarkIssueReturned { Link Here
2190
            $dbh->do(q|UPDATE old_issues SET borrowernumber=? WHERE issue_id = ?|, undef, $anonymouspatron, $issue_id);
2183
            $dbh->do(q|UPDATE old_issues SET borrowernumber=? WHERE issue_id = ?|, undef, $anonymouspatron, $issue_id);
2191
        }
2184
        }
2192
2185
2193
        $dbh->do(q|DELETE FROM issues WHERE issue_id = ?|, undef, $issue_id);
2186
        # And finally delete the issue
2187
        $issue->delete;
2194
2188
2195
        ModItem( { 'onloan' => undef }, undef, $itemnumber );
2189
        ModItem( { 'onloan' => undef }, undef, $itemnumber );
2196
2190
(-)a/circ/returns.pl (+3 lines)
Lines 543-548 foreach my $code ( keys %$messages ) { Link Here
543
    elsif ( $code eq 'NotForLoanStatusUpdated' ) {
543
    elsif ( $code eq 'NotForLoanStatusUpdated' ) {
544
        $err{NotForLoanStatusUpdated} = $messages->{NotForLoanStatusUpdated};
544
        $err{NotForLoanStatusUpdated} = $messages->{NotForLoanStatusUpdated};
545
    }
545
    }
546
    elsif ( $code eq 'DataCorrupted' ) {
547
        $err{data_corrupted} = 1;
548
    }
546
    else {
549
    else {
547
        die "Unknown error code $code";    # note we need all the (empty) elsif's above, or we die.
550
        die "Unknown error code $code";    # note we need all the (empty) elsif's above, or we die.
548
        # This forces the issue of staying in sync w/ Circulation.pm
551
        # This forces the issue of staying in sync w/ Circulation.pm
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt (-1 / +5 lines)
Lines 227-232 $(document).ready(function () { Link Here
227
        <p>This item must be checked in at following library: <strong>[% Branches.GetName( rightbranch ) %]</strong></p>
227
        <p>This item must be checked in at following library: <strong>[% Branches.GetName( rightbranch ) %]</strong></p>
228
    </div>
228
    </div>
229
[% END %]
229
[% END %]
230
230
<!-- case of a mistake in transfer loop -->
231
<!-- case of a mistake in transfer loop -->
231
[% IF ( WrongTransfer ) %]
232
[% IF ( WrongTransfer ) %]
232
    <div id="return2" class="dialog message">
233
    <div id="return2" class="dialog message">
Lines 624-630 $(document).ready(function () { Link Here
624
                    [% END %]
625
                    [% END %]
625
626
626
            [% END %]
627
            [% END %]
627
        [% ELSE %]
628
629
            [% IF errmsgloo.data_corrupted %]
630
                <p class="problem">The item has not been checked in due to a configuration issue in your system. You must ask an administrator to take a look at the <a href="/cgi-bin/koha/about.pl#sysinfo">about page</a> and search for the "data problems" section</p>
631
            [% END %]
628
        [% END %]
632
        [% END %]
629
    </div>
633
    </div>
630
634
(-)a/t/db_dependent/Circulation/Returns.t (-7 / +35 lines)
Lines 31-36 use C4::Members; Link Here
31
use Koha::Database;
31
use Koha::Database;
32
use Koha::DateUtils;
32
use Koha::DateUtils;
33
use Koha::Items;
33
use Koha::Items;
34
use Koha::Checkouts;
35
use Koha::OldIssues;
34
36
35
use MARC::Record;
37
use MARC::Record;
36
use MARC::Field;
38
use MARC::Field;
Lines 263-269 subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub { Link Here
263
};
265
};
264
266
265
subtest 'Handle ids duplication' => sub {
267
subtest 'Handle ids duplication' => sub {
266
    plan tests => 1;
268
    plan tests => 6;
269
270
    t::lib::Mocks::mock_preference( 'item-level_itypes', 1 );
271
    t::lib::Mocks::mock_preference( 'CalculateFinesOnReturn', 1 );
272
    t::lib::Mocks::mock_preference( 'finesMode', 'production' );
273
    Koha::IssuingRules->search->update({ chargeperiod => 1, fine => 1, firstremind => 1, });
267
274
268
    my $biblio = $builder->build( { source => 'Biblio' } );
275
    my $biblio = $builder->build( { source => 'Biblio' } );
269
    my $item = $builder->build(
276
    my $item = $builder->build(
Lines 279-291 subtest 'Handle ids duplication' => sub { Link Here
279
        }
286
        }
280
    );
287
    );
281
    my $patron = $builder->build({source => 'Borrower'});
288
    my $patron = $builder->build({source => 'Borrower'});
289
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
290
291
    my $original_checkout = AddIssue( $patron->unblessed, $item->{barcode}, dt_from_string->subtract( days => 50 ) );
292
293
    my $issue_id = $original_checkout->issue_id;
294
    # Create an existing entry in old_issue
295
    $builder->build({ source => 'OldIssue', value => { issue_id => $issue_id } });
296
297
    my $old_checkout = Koha::OldIssues->find( $issue_id );
298
299
    my ($doreturn, $messages, $new_checkout, $borrower);
300
    warning_like {
301
        ( $doreturn, $messages, $new_checkout, $borrower ) =
302
          AddReturn( $item->{barcode}, undef, undef, undef, dt_from_string );
303
    }
304
    [
305
        qr{.*DBD::mysql::st execute failed: Duplicate entry.*},
306
        { carped => qr{The checkin for the following issue failed.*DBIx::Class::Storage::DBI::_dbh_execute.*} }
307
    ],
308
    'DBD should have raised an error about dup primary key';
309
310
    is( $doreturn, 0, 'Return should not have been done' );
311
    is( $messages->{WasReturned}, 0, 'messages should have the WasReturned flag set to 0' );
312
    is( $messages->{DataCorrupted}, 1, 'messages should have the DataCorrupted flag set to 1' );
282
313
283
    my $checkout = AddIssue( $patron, $item->{barcode} );
314
    my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id });
284
    $builder->build({ source => 'OldIssue', value => { issue_id => $checkout->issue_id } });
315
    is( $account_lines->count, 0, 'No account lines should exist for this issue_id, patron should not have been charged' );
285
316
286
    my @a = AddReturn( $item->{barcode} );
317
    is( Koha::Checkouts->find( $issue_id )->issue_id, $issue_id, 'The issues entry should not have been removed' );
287
    my $old_checkout = Koha::OldIssues->find( $checkout->issue_id );
288
    isnt( $old_checkout->itemnumber, $item->{itemnumber}, 'If an item is checked-in, it should be moved to old_issues even if the issue_id already existed in the table' );
289
};
318
};
290
319
291
1;
320
1;
292
- 

Return to bug 18966