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

(-)a/C4/Circulation.pm (-1 / +11 lines)
Lines 2831-2836 C<$datedue> can be a DateTime object used to set the due date. Link Here
2831
C<$lastreneweddate> is an optional ISO-formatted date used to set issues.lastreneweddate.  If
2831
C<$lastreneweddate> is an optional ISO-formatted date used to set issues.lastreneweddate.  If
2832
this parameter is not supplied, lastreneweddate is set to the current date.
2832
this parameter is not supplied, lastreneweddate is set to the current date.
2833
2833
2834
C<$skipfinecalc> is an optional boolean. There may be circumstances where, even if the
2835
CalculateFinesOnReturn syspref is enabled, we don't want to calculate fines upon renew,
2836
for example, when we're renewing as a result of a fine being paid (see RenewAccruingItemWhenPaid
2837
syspref)
2838
2834
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically
2839
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically
2835
from the book's item type.
2840
from the book's item type.
2836
2841
Lines 2842-2847 sub AddRenewal { Link Here
2842
    my $branch          = shift;
2847
    my $branch          = shift;
2843
    my $datedue         = shift;
2848
    my $datedue         = shift;
2844
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz);
2849
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz);
2850
    my $skipfinecalc    = shift;
2845
2851
2846
    my $item_object   = Koha::Items->find($itemnumber) or return;
2852
    my $item_object   = Koha::Items->find($itemnumber) or return;
2847
    my $biblio = $item_object->biblio;
2853
    my $biblio = $item_object->biblio;
Lines 2864-2870 sub AddRenewal { Link Here
2864
2870
2865
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_unblessed, $patron_unblessed) );
2871
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_unblessed, $patron_unblessed) );
2866
2872
2867
    if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
2873
    if (
2874
        !$skipfinecalc &&
2875
        C4::Context->preference('CalculateFinesOnReturn') &&
2876
        $issue->is_overdue
2877
    ) {
2868
        _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } );
2878
        _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } );
2869
    }
2879
    }
2870
    _FixOverduesOnReturn( $borrowernumber, $itemnumber, undef, 'RENEWED' );
2880
    _FixOverduesOnReturn( $borrowernumber, $itemnumber, undef, 'RENEWED' );
(-)a/Koha/Account.pm (-1 / +60 lines)
Lines 23-32 use Carp; Link Here
23
use Data::Dumper;
23
use Data::Dumper;
24
use List::MoreUtils qw( uniq );
24
use List::MoreUtils qw( uniq );
25
25
26
use C4::Circulation qw( ReturnLostItem );
26
use C4::Circulation qw( ReturnLostItem CanBookBeRenewed AddRenewal );
27
use C4::Letters;
27
use C4::Letters;
28
use C4::Log qw( logaction );
28
use C4::Log qw( logaction );
29
use C4::Stats qw( UpdateStats );
29
use C4::Stats qw( UpdateStats );
30
use C4::Overdues qw(GetFine);
30
31
31
use Koha::Patrons;
32
use Koha::Patrons;
32
use Koha::Account::Lines;
33
use Koha::Account::Lines;
Lines 88-93 sub pay { Link Here
88
    my $interface = $params ? ( $params->{interface} || C4::Context->interface ) : C4::Context->interface;
89
    my $interface = $params ? ( $params->{interface} || C4::Context->interface ) : C4::Context->interface;
89
90
90
    my @fines_paid; # List of account lines paid on with this payment
91
    my @fines_paid; # List of account lines paid on with this payment
92
    # Item numbers that have had a fine paid where the line has a accounttype
93
    # of OVERDUE and a status of UNRETURNED. We might want to try and renew
94
    # these items.
95
    my $overdue_unreturned = {};
91
96
92
    my $balance_remaining = $amount; # Set it now so we can adjust the amount if necessary
97
    my $balance_remaining = $amount; # Set it now so we can adjust the amount if necessary
93
    $balance_remaining ||= 0;
98
    $balance_remaining ||= 0;
Lines 106-111 sub pay { Link Here
106
        $fine->amountoutstanding($new_amountoutstanding)->store();
111
        $fine->amountoutstanding($new_amountoutstanding)->store();
107
        $balance_remaining = $balance_remaining - $amount_to_pay;
112
        $balance_remaining = $balance_remaining - $amount_to_pay;
108
113
114
        # If we need to make a note of the item associated with this line,
115
        # in order that we can potentially renew it, do so.
116
        if (
117
            $new_amountoutstanding == 0 &&
118
            $fine->accounttype &&
119
            $fine->accounttype eq 'OVERDUE' &&
120
            $fine->status &&
121
            $fine->status eq 'UNRETURNED'
122
        ) {
123
            $overdue_unreturned->{$fine->itemnumber} = $fine;
124
        }
125
109
        # Same logic exists in Koha::Account::Line::apply
126
        # Same logic exists in Koha::Account::Line::apply
110
        if (   $new_amountoutstanding == 0
127
        if (   $new_amountoutstanding == 0
111
            && $fine->itemnumber
128
            && $fine->itemnumber
Lines 166-171 sub pay { Link Here
166
        $fine->amountoutstanding( $old_amountoutstanding - $amount_to_pay );
183
        $fine->amountoutstanding( $old_amountoutstanding - $amount_to_pay );
167
        $fine->store();
184
        $fine->store();
168
185
186
        # If we need to make a note of the item associated with this line,
187
        # in order that we can potentially renew it, do so.
188
        if (
189
            $old_amountoutstanding - $amount_to_pay == 0 &&
190
            $fine->accounttype &&
191
            $fine->accounttype eq 'OVERDUE' &&
192
            $fine->status &&
193
            $fine->status eq 'UNRETURNED'
194
        ) {
195
            $overdue_unreturned->{$fine->itemnumber} = $fine;
196
        }
197
169
        if (   $fine->amountoutstanding == 0
198
        if (   $fine->amountoutstanding == 0
170
            && $fine->itemnumber
199
            && $fine->itemnumber
171
            && $fine->accounttype
200
            && $fine->accounttype
Lines 245-250 sub pay { Link Here
245
        }
274
        }
246
    );
275
    );
247
276
277
    # If we have overdue unreturned items that have had payments made
278
    # against them, check whether the balance on those items is now zero
279
    # and, if the syspref is set, renew them
280
    # Same logic exists in Koha::Account::Line::apply
281
    if (
282
        C4::Context->preference('RenewAccruingItemWhenPaid') &&
283
        keys %{$overdue_unreturned}
284
    ) {
285
        foreach my $itemnumber (keys %{$overdue_unreturned}) {
286
            # Only do something if this item has no fines left on it
287
            my $fine = C4::Overdues::GetFine( $itemnumber, $self->{patron_id} );
288
            next if $fine && $fine > 0;
289
290
            my ( $renew_ok, $error ) =
291
                C4::Circulation::CanBookBeRenewed(
292
                    $self->{patron_id}, $itemnumber
293
                );
294
            if ( $renew_ok ) {
295
                C4::Circulation::AddRenewal(
296
                    $self->{patron_id},
297
                    $itemnumber,
298
                    $library_id,
299
                    undef,
300
                    undef,
301
                    1
302
                );
303
            }
304
        }
305
    }
306
248
    if ( C4::Context->preference("FinesLog") ) {
307
    if ( C4::Context->preference("FinesLog") ) {
249
        logaction(
308
        logaction(
250
            "FINES", 'CREATE',
309
            "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::Offsets;
26
use Koha::Account::Offsets;
26
use Koha::Database;
27
use Koha::Database;
Lines 203-208 sub apply { Link Here
203
204
204
    my $schema = Koha::Database->new->schema;
205
    my $schema = Koha::Database->new->schema;
205
206
207
    # Item numbers that have had a fine paid where the line has a accounttype
208
    # of OVERDUE and a status of UNRETURNED. We might want to try and renew
209
    # these items.
210
    my $overdue_unreturned = {};
211
206
    $schema->txn_do( sub {
212
    $schema->txn_do( sub {
207
        while ( my $debit = $debits->next ) {
213
        while ( my $debit = $debits->next ) {
208
214
Lines 235-240 sub apply { Link Here
235
            $self->amountoutstanding( $available_credit * -1 )->store;
241
            $self->amountoutstanding( $available_credit * -1 )->store;
236
            $debit->amountoutstanding( $owed - $amount_to_cancel )->store;
242
            $debit->amountoutstanding( $owed - $amount_to_cancel )->store;
237
243
244
            # If we need to make a note of the item associated with this line,
245
            # in order that we can potentially renew it, do so.
246
            # Same logic existing in Koha::Account::pay
247
            if (
248
                $debit->amountoutstanding == 0 &&
249
                $debit->accounttype &&
250
                $debit->accounttype eq 'OVERDUE' &&
251
                $debit->status &&
252
                $debit->status eq 'UNRETURNED'
253
            ) {
254
                $overdue_unreturned->{$debit->itemnumber} = $debit;
255
            }
256
238
            # Same logic exists in Koha::Account::pay
257
            # Same logic exists in Koha::Account::pay
239
            if (   $debit->amountoutstanding == 0
258
            if (   $debit->amountoutstanding == 0
240
                && $debit->itemnumber
259
                && $debit->itemnumber
Lines 247-252 sub apply { Link Here
247
        }
266
        }
248
    });
267
    });
249
268
269
    # If we have overdue unreturned items that have had payments made
270
    # against them, check whether the balance on those items is now zero
271
    # and, if the syspref is set, renew them
272
    # Same logic existing in Koha::Account::pay
273
    if (
274
        C4::Context->preference('RenewAccruingItemWhenPaid') &&
275
        keys %{$overdue_unreturned}
276
    ) {
277
        foreach my $itemnumber (keys %{$overdue_unreturned}) {
278
            # Only do something if this item has no fines left on it
279
            my $fine = C4::Overdues::GetFine( $itemnumber, $self->borrowernumber );
280
            next if $fine && $fine > 0;
281
282
            my ( $renew_ok, $error ) =
283
                C4::Circulation::CanBookBeRenewed(
284
                    $self->borrowernumber, $itemnumber
285
                );
286
            if ( $renew_ok ) {
287
                C4::Circulation::AddRenewal(
288
                    $self->borrowernumber,
289
                    $itemnumber,
290
                    $overdue_unreturned->{$itemnumber}->{branchcode},
291
                    undef,
292
                    undef,
293
                    1
294
                );
295
            }
296
        }
297
    }
298
250
    return $available_credit;
299
    return $available_credit;
251
}
300
}
252
301
253
- 

Return to bug 23051