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

(-)a/C4/Circulation.pm (-1 / +7 lines)
Lines 2854-2859 C<$datedue> can be a DateTime object used to set the due date. Link Here
2854
C<$lastreneweddate> is an optional ISO-formatted date used to set issues.lastreneweddate.  If
2854
C<$lastreneweddate> is an optional ISO-formatted date used to set issues.lastreneweddate.  If
2855
this parameter is not supplied, lastreneweddate is set to the current date.
2855
this parameter is not supplied, lastreneweddate is set to the current date.
2856
2856
2857
C<$skipfinecalc> is an optional boolean. There may be circumstances where, even if the
2858
CalculateFinesOnReturn syspref is enabled, we don't want to calculate fines upon renew,
2859
for example, when we're renewing as a result of a fine being paid (see RenewAccruingItemWhenPaid
2860
syspref)
2861
2857
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically
2862
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically
2858
from the book's item type.
2863
from the book's item type.
2859
2864
Lines 2865-2870 sub AddRenewal { Link Here
2865
    my $branch          = shift;
2870
    my $branch          = shift;
2866
    my $datedue         = shift;
2871
    my $datedue         = shift;
2867
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz);
2872
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz);
2873
    my $skipfinecalc    = shift;
2868
2874
2869
    my $item_object   = Koha::Items->find($itemnumber) or return;
2875
    my $item_object   = Koha::Items->find($itemnumber) or return;
2870
    my $biblio = $item_object->biblio;
2876
    my $biblio = $item_object->biblio;
Lines 2890-2896 sub AddRenewal { Link Here
2890
    my $schema = Koha::Database->schema;
2896
    my $schema = Koha::Database->schema;
2891
    $schema->txn_do(sub{
2897
    $schema->txn_do(sub{
2892
2898
2893
        if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
2899
        if ( !skipfinecalc && C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
2894
            _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } );
2900
            _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } );
2895
        }
2901
        }
2896
        _FixOverduesOnReturn( $borrowernumber, $itemnumber, undef, 'RENEWED' );
2902
        _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 95-100 sub pay { Link Here
95
        && !defined($cash_register) );
96
        && !defined($cash_register) );
96
97
97
    my @fines_paid; # List of account lines paid on with this payment
98
    my @fines_paid; # List of account lines paid on with this payment
99
    # Item numbers that have had a fine paid where the line has a accounttype
100
    # of OVERDUE and a status of UNRETURNED. We might want to try and renew
101
    # these items.
102
    my $overdue_unreturned = {};
98
103
99
    my $balance_remaining = $amount; # Set it now so we can adjust the amount if necessary
104
    my $balance_remaining = $amount; # Set it now so we can adjust the amount if necessary
100
    $balance_remaining ||= 0;
105
    $balance_remaining ||= 0;
Lines 113-118 sub pay { Link Here
113
        $fine->amountoutstanding($new_amountoutstanding)->store();
118
        $fine->amountoutstanding($new_amountoutstanding)->store();
114
        $balance_remaining = $balance_remaining - $amount_to_pay;
119
        $balance_remaining = $balance_remaining - $amount_to_pay;
115
120
121
        # If we need to make a note of the item associated with this line,
122
        # in order that we can potentially renew it, do so.
123
        if (
124
            $new_amountoutstanding == 0 &&
125
            $fine->accounttype &&
126
            $fine->accounttype eq 'OVERDUE' &&
127
            $fine->status &&
128
            $fine->status eq 'UNRETURNED'
129
        ) {
130
            $overdue_unreturned->{$fine->itemnumber} = $fine;
131
        }
132
116
        # Same logic exists in Koha::Account::Line::apply
133
        # Same logic exists in Koha::Account::Line::apply
117
        if (   $new_amountoutstanding == 0
134
        if (   $new_amountoutstanding == 0
118
            && $fine->itemnumber
135
            && $fine->itemnumber
Lines 173-178 sub pay { Link Here
173
        $fine->amountoutstanding( $old_amountoutstanding - $amount_to_pay );
190
        $fine->amountoutstanding( $old_amountoutstanding - $amount_to_pay );
174
        $fine->store();
191
        $fine->store();
175
192
193
        # If we need to make a note of the item associated with this line,
194
        # in order that we can potentially renew it, do so.
195
        if (
196
            $old_amountoutstanding - $amount_to_pay == 0 &&
197
            $fine->accounttype &&
198
            $fine->accounttype eq 'OVERDUE' &&
199
            $fine->status &&
200
            $fine->status eq 'UNRETURNED'
201
        ) {
202
            $overdue_unreturned->{$fine->itemnumber} = $fine;
203
        }
204
176
        if (   $fine->amountoutstanding == 0
205
        if (   $fine->amountoutstanding == 0
177
            && $fine->itemnumber
206
            && $fine->itemnumber
178
            && $fine->debit_type_code
207
            && $fine->debit_type_code
Lines 253-258 sub pay { Link Here
253
        }
282
        }
254
    );
283
    );
255
284
285
    # If we have overdue unreturned items that have had payments made
286
    # against them, check whether the balance on those items is now zero
287
    # and, if the syspref is set, renew them
288
    # Same logic exists in Koha::Account::Line::apply
289
    if (
290
        C4::Context->preference('RenewAccruingItemWhenPaid') &&
291
        keys %{$overdue_unreturned}
292
    ) {
293
        foreach my $itemnumber (keys %{$overdue_unreturned}) {
294
            # Only do something if this item has no fines left on it
295
            my $fine = C4::Overdues::GetFine( $itemnumber, $self->{patron_id} );
296
            next if $fine && $fine > 0;
297
298
            my ( $renew_ok, $error ) =
299
                C4::Circulation::CanBookBeRenewed(
300
                    $self->{patron_id}, $itemnumber
301
                );
302
            if ( $renew_ok ) {
303
                C4::Circulation::AddRenewal(
304
                    $self->{patron_id},
305
                    $itemnumber,
306
                    $library_id,
307
                    undef,
308
                    undef,
309
                    1
310
                );
311
            }
312
        }
313
    }
314
256
    if ( C4::Context->preference("FinesLog") ) {
315
    if ( C4::Context->preference("FinesLog") ) {
257
        logaction(
316
        logaction(
258
            "FINES", 'CREATE',
317
            "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::DebitType;
26
use Koha::Account::DebitType;
26
use Koha::Account::Offsets;
27
use Koha::Account::Offsets;
Lines 217-222 sub apply { Link Here
217
218
218
    my $schema = Koha::Database->new->schema;
219
    my $schema = Koha::Database->new->schema;
219
220
221
    # Item numbers that have had a fine paid where the line has a accounttype
222
    # of OVERDUE and a status of UNRETURNED. We might want to try and renew
223
    # these items.
224
    my $overdue_unreturned = {};
225
220
    $schema->txn_do( sub {
226
    $schema->txn_do( sub {
221
        for my $debit ( @{$debits} ) {
227
        for my $debit ( @{$debits} ) {
222
228
Lines 249-254 sub apply { Link Here
249
            $self->amountoutstanding( $available_credit * -1 )->store;
255
            $self->amountoutstanding( $available_credit * -1 )->store;
250
            $debit->amountoutstanding( $owed - $amount_to_cancel )->store;
256
            $debit->amountoutstanding( $owed - $amount_to_cancel )->store;
251
257
258
            # If we need to make a note of the item associated with this line,
259
            # in order that we can potentially renew it, do so.
260
            # Same logic existing in Koha::Account::pay
261
            if (
262
                $debit->amountoutstanding == 0 &&
263
                $debit->accounttype &&
264
                $debit->accounttype eq 'OVERDUE' &&
265
                $debit->status &&
266
                $debit->status eq 'UNRETURNED'
267
            ) {
268
                $overdue_unreturned->{$debit->itemnumber} = $debit;
269
            }
270
252
            # Same logic exists in Koha::Account::pay
271
            # Same logic exists in Koha::Account::pay
253
            if (   $debit->amountoutstanding == 0
272
            if (   $debit->amountoutstanding == 0
254
                && $debit->itemnumber
273
                && $debit->itemnumber
Lines 261-266 sub apply { Link Here
261
        }
280
        }
262
    });
281
    });
263
282
283
    # If we have overdue unreturned items that have had payments made
284
    # against them, check whether the balance on those items is now zero
285
    # and, if the syspref is set, renew them
286
    # Same logic existing in Koha::Account::pay
287
    if (
288
        C4::Context->preference('RenewAccruingItemWhenPaid') &&
289
        keys %{$overdue_unreturned}
290
    ) {
291
        foreach my $itemnumber (keys %{$overdue_unreturned}) {
292
            # Only do something if this item has no fines left on it
293
            my $fine = C4::Overdues::GetFine( $itemnumber, $self->borrowernumber );
294
            next if $fine && $fine > 0;
295
296
            my ( $renew_ok, $error ) =
297
                C4::Circulation::CanBookBeRenewed(
298
                    $self->borrowernumber, $itemnumber
299
                );
300
            if ( $renew_ok ) {
301
                C4::Circulation::AddRenewal(
302
                    $self->borrowernumber,
303
                    $itemnumber,
304
                    $overdue_unreturned->{$itemnumber}->{branchcode},
305
                    undef,
306
                    undef,
307
                    1
308
                );
309
            }
310
        }
311
    }
312
264
    return $available_credit;
313
    return $available_credit;
265
}
314
}
266
315
267
- 

Return to bug 23051