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 452-457 sub apply { Link Here
452
453
453
    my $schema = Koha::Database->new->schema;
454
    my $schema = Koha::Database->new->schema;
454
455
456
    # Item numbers that have had a fine paid where the line has a accounttype
457
    # of OVERDUE and a status of UNRETURNED. We might want to try and renew
458
    # these items.
459
    my $overdue_unreturned = {};
460
455
    $schema->txn_do( sub {
461
    $schema->txn_do( sub {
456
        for my $debit ( @{$debits} ) {
462
        for my $debit ( @{$debits} ) {
457
463
Lines 484-489 sub apply { Link Here
484
            $self->amountoutstanding( $available_credit * -1 )->store;
490
            $self->amountoutstanding( $available_credit * -1 )->store;
485
            $debit->amountoutstanding( $owed - $amount_to_cancel )->store;
491
            $debit->amountoutstanding( $owed - $amount_to_cancel )->store;
486
492
493
            # If we need to make a note of the item associated with this line,
494
            # in order that we can potentially renew it, do so.
495
            # Same logic existing in Koha::Account::pay
496
            if (
497
                $debit->amountoutstanding == 0 &&
498
                $debit->accounttype &&
499
                $debit->accounttype eq 'OVERDUE' &&
500
                $debit->status &&
501
                $debit->status eq 'UNRETURNED'
502
            ) {
503
                $overdue_unreturned->{$debit->itemnumber} = $debit;
504
            }
505
487
            # Same logic exists in Koha::Account::pay
506
            # Same logic exists in Koha::Account::pay
488
            if (   $debit->amountoutstanding == 0
507
            if (   $debit->amountoutstanding == 0
489
                && $debit->itemnumber
508
                && $debit->itemnumber
Lines 496-501 sub apply { Link Here
496
        }
515
        }
497
    });
516
    });
498
517
518
    # If we have overdue unreturned items that have had payments made
519
    # against them, check whether the balance on those items is now zero
520
    # and, if the syspref is set, renew them
521
    # Same logic existing in Koha::Account::pay
522
    if (
523
        C4::Context->preference('RenewAccruingItemWhenPaid') &&
524
        keys %{$overdue_unreturned}
525
    ) {
526
        foreach my $itemnumber (keys %{$overdue_unreturned}) {
527
            # Only do something if this item has no fines left on it
528
            my $fine = C4::Overdues::GetFine( $itemnumber, $self->borrowernumber );
529
            next if $fine && $fine > 0;
530
531
            my ( $renew_ok, $error ) =
532
                C4::Circulation::CanBookBeRenewed(
533
                    $self->borrowernumber, $itemnumber
534
                );
535
            if ( $renew_ok ) {
536
                C4::Circulation::AddRenewal(
537
                    $self->borrowernumber,
538
                    $itemnumber,
539
                    $overdue_unreturned->{$itemnumber}->{branchcode},
540
                    undef,
541
                    undef,
542
                    1
543
                );
544
            }
545
        }
546
    }
547
499
    return $available_credit;
548
    return $available_credit;
500
}
549
}
501
550
502
- 

Return to bug 23051