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

(-)a/C4/Circulation.pm (-1 / +7 lines)
Lines 2909-2914 C<$datedue> can be a DateTime object used to set the due date. Link Here
2909
C<$lastreneweddate> is an optional ISO-formatted date used to set issues.lastreneweddate.  If
2909
C<$lastreneweddate> is an optional ISO-formatted date used to set issues.lastreneweddate.  If
2910
this parameter is not supplied, lastreneweddate is set to the current date.
2910
this parameter is not supplied, lastreneweddate is set to the current date.
2911
2911
2912
C<$skipfinecalc> is an optional boolean. There may be circumstances where, even if the
2913
CalculateFinesOnReturn syspref is enabled, we don't want to calculate fines upon renew,
2914
for example, when we're renewing as a result of a fine being paid (see RenewAccruingItemWhenPaid
2915
syspref)
2916
2912
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically
2917
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically
2913
from the book's item type.
2918
from the book's item type.
2914
2919
Lines 2920-2925 sub AddRenewal { Link Here
2920
    my $branch          = shift;
2925
    my $branch          = shift;
2921
    my $datedue         = shift;
2926
    my $datedue         = shift;
2922
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz);
2927
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz);
2928
    my $skipfinecalc    = shift;
2923
2929
2924
    my $item_object   = Koha::Items->find($itemnumber) or return;
2930
    my $item_object   = Koha::Items->find($itemnumber) or return;
2925
    my $biblio = $item_object->biblio;
2931
    my $biblio = $item_object->biblio;
Lines 2945-2951 sub AddRenewal { Link Here
2945
    my $schema = Koha::Database->schema;
2951
    my $schema = Koha::Database->schema;
2946
    $schema->txn_do(sub{
2952
    $schema->txn_do(sub{
2947
2953
2948
        if ( C4::Context->preference('CalculateFinesOnReturn') ) {
2954
        if ( !skipfinecalc && C4::Context->preference('CalculateFinesOnReturn') ) {
2949
            _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } );
2955
            _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } );
2950
        }
2956
        }
2951
        _FixOverduesOnReturn( $borrowernumber, $itemnumber, undef, 'RENEWED' );
2957
        _FixOverduesOnReturn( $borrowernumber, $itemnumber, undef, 'RENEWED' );
(-)a/Koha/Account.pm (-1 / +60 lines)
Lines 24-33 use Data::Dumper; Link Here
24
use List::MoreUtils qw( uniq );
24
use List::MoreUtils qw( uniq );
25
use Try::Tiny;
25
use Try::Tiny;
26
26
27
use C4::Circulation qw( ReturnLostItem );
27
use C4::Circulation qw( ReturnLostItem CanBookBeRenewed AddRenewal );
28
use C4::Letters;
28
use C4::Letters;
29
use C4::Log qw( logaction );
29
use C4::Log qw( logaction );
30
use C4::Stats qw( UpdateStats );
30
use C4::Stats qw( UpdateStats );
31
use C4::Overdues qw(GetFine);
31
32
32
use Koha::Patrons;
33
use Koha::Patrons;
33
use Koha::Account::Lines;
34
use Koha::Account::Lines;
Lines 96-101 sub pay { Link Here
96
        && !defined($cash_register) );
97
        && !defined($cash_register) );
97
98
98
    my @fines_paid; # List of account lines paid on with this payment
99
    my @fines_paid; # List of account lines paid on with this payment
100
    # Item numbers that have had a fine paid where the line has a accounttype
101
    # of OVERDUE and a status of UNRETURNED. We might want to try and renew
102
    # these items.
103
    my $overdue_unreturned = {};
99
104
100
    my $balance_remaining = $amount; # Set it now so we can adjust the amount if necessary
105
    my $balance_remaining = $amount; # Set it now so we can adjust the amount if necessary
101
    $balance_remaining ||= 0;
106
    $balance_remaining ||= 0;
Lines 114-119 sub pay { Link Here
114
        $fine->amountoutstanding($new_amountoutstanding)->store();
119
        $fine->amountoutstanding($new_amountoutstanding)->store();
115
        $balance_remaining = $balance_remaining - $amount_to_pay;
120
        $balance_remaining = $balance_remaining - $amount_to_pay;
116
121
122
        # If we need to make a note of the item associated with this line,
123
        # in order that we can potentially renew it, do so.
124
        if (
125
            $new_amountoutstanding == 0 &&
126
            $fine->accounttype &&
127
            $fine->accounttype eq 'OVERDUE' &&
128
            $fine->status &&
129
            $fine->status eq 'UNRETURNED'
130
        ) {
131
            $overdue_unreturned->{$fine->itemnumber} = $fine;
132
        }
133
117
        # Same logic exists in Koha::Account::Line::apply
134
        # Same logic exists in Koha::Account::Line::apply
118
        if (   $new_amountoutstanding == 0
135
        if (   $new_amountoutstanding == 0
119
            && $fine->itemnumber
136
            && $fine->itemnumber
Lines 174-179 sub pay { Link Here
174
        $fine->amountoutstanding( $old_amountoutstanding - $amount_to_pay );
191
        $fine->amountoutstanding( $old_amountoutstanding - $amount_to_pay );
175
        $fine->store();
192
        $fine->store();
176
193
194
        # If we need to make a note of the item associated with this line,
195
        # in order that we can potentially renew it, do so.
196
        if (
197
            $old_amountoutstanding - $amount_to_pay == 0 &&
198
            $fine->accounttype &&
199
            $fine->accounttype eq 'OVERDUE' &&
200
            $fine->status &&
201
            $fine->status eq 'UNRETURNED'
202
        ) {
203
            $overdue_unreturned->{$fine->itemnumber} = $fine;
204
        }
205
177
        if (   $fine->amountoutstanding == 0
206
        if (   $fine->amountoutstanding == 0
178
            && $fine->itemnumber
207
            && $fine->itemnumber
179
            && $fine->debit_type_code
208
            && $fine->debit_type_code
Lines 254-259 sub pay { Link Here
254
        }
283
        }
255
    );
284
    );
256
285
286
    # If we have overdue unreturned items that have had payments made
287
    # against them, check whether the balance on those items is now zero
288
    # and, if the syspref is set, renew them
289
    # Same logic exists in Koha::Account::Line::apply
290
    if (
291
        C4::Context->preference('RenewAccruingItemWhenPaid') &&
292
        keys %{$overdue_unreturned}
293
    ) {
294
        foreach my $itemnumber (keys %{$overdue_unreturned}) {
295
            # Only do something if this item has no fines left on it
296
            my $fine = C4::Overdues::GetFine( $itemnumber, $self->{patron_id} );
297
            next if $fine && $fine > 0;
298
299
            my ( $renew_ok, $error ) =
300
                C4::Circulation::CanBookBeRenewed(
301
                    $self->{patron_id}, $itemnumber
302
                );
303
            if ( $renew_ok ) {
304
                C4::Circulation::AddRenewal(
305
                    $self->{patron_id},
306
                    $itemnumber,
307
                    $library_id,
308
                    undef,
309
                    undef,
310
                    1
311
                );
312
            }
313
        }
314
    }
315
257
    if ( C4::Context->preference("FinesLog") ) {
316
    if ( C4::Context->preference("FinesLog") ) {
258
        logaction(
317
        logaction(
259
            "FINES", 'CREATE',
318
            "FINES", 'CREATE',
(-)a/Koha/Account/Line.pm (-1 / +49 lines)
Lines 21-26 use Carp; Link Here
21
use Data::Dumper;
21
use Data::Dumper;
22
22
23
use C4::Log qw(logaction);
23
use C4::Log qw(logaction);
24
use C4::Overdues qw(GetFine);
24
25
25
use Koha::Account::CreditType;
26
use Koha::Account::CreditType;
26
use Koha::Account::DebitType;
27
use Koha::Account::DebitType;
Lines 451-456 sub apply { Link Here
451
452
452
    my $schema = Koha::Database->new->schema;
453
    my $schema = Koha::Database->new->schema;
453
454
455
    # Item numbers that have had a fine paid where the line has a accounttype
456
    # of OVERDUE and a status of UNRETURNED. We might want to try and renew
457
    # these items.
458
    my $overdue_unreturned = {};
459
454
    $schema->txn_do( sub {
460
    $schema->txn_do( sub {
455
        for my $debit ( @{$debits} ) {
461
        for my $debit ( @{$debits} ) {
456
462
Lines 483-488 sub apply { Link Here
483
            $self->amountoutstanding( $available_credit * -1 )->store;
489
            $self->amountoutstanding( $available_credit * -1 )->store;
484
            $debit->amountoutstanding( $owed - $amount_to_cancel )->store;
490
            $debit->amountoutstanding( $owed - $amount_to_cancel )->store;
485
491
492
            # If we need to make a note of the item associated with this line,
493
            # in order that we can potentially renew it, do so.
494
            # Same logic existing in Koha::Account::pay
495
            if (
496
                $debit->amountoutstanding == 0 &&
497
                $debit->accounttype &&
498
                $debit->accounttype eq 'OVERDUE' &&
499
                $debit->status &&
500
                $debit->status eq 'UNRETURNED'
501
            ) {
502
                $overdue_unreturned->{$debit->itemnumber} = $debit;
503
            }
504
486
            # Same logic exists in Koha::Account::pay
505
            # Same logic exists in Koha::Account::pay
487
            if (   $debit->amountoutstanding == 0
506
            if (   $debit->amountoutstanding == 0
488
                && $debit->itemnumber
507
                && $debit->itemnumber
Lines 495-500 sub apply { Link Here
495
        }
514
        }
496
    });
515
    });
497
516
517
    # If we have overdue unreturned items that have had payments made
518
    # against them, check whether the balance on those items is now zero
519
    # and, if the syspref is set, renew them
520
    # Same logic existing in Koha::Account::pay
521
    if (
522
        C4::Context->preference('RenewAccruingItemWhenPaid') &&
523
        keys %{$overdue_unreturned}
524
    ) {
525
        foreach my $itemnumber (keys %{$overdue_unreturned}) {
526
            # Only do something if this item has no fines left on it
527
            my $fine = C4::Overdues::GetFine( $itemnumber, $self->borrowernumber );
528
            next if $fine && $fine > 0;
529
530
            my ( $renew_ok, $error ) =
531
                C4::Circulation::CanBookBeRenewed(
532
                    $self->borrowernumber, $itemnumber
533
                );
534
            if ( $renew_ok ) {
535
                C4::Circulation::AddRenewal(
536
                    $self->borrowernumber,
537
                    $itemnumber,
538
                    $overdue_unreturned->{$itemnumber}->{branchcode},
539
                    undef,
540
                    undef,
541
                    1
542
                );
543
            }
544
        }
545
    }
546
498
    return $available_credit;
547
    return $available_credit;
499
}
548
}
500
549
501
- 

Return to bug 23051