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

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

Return to bug 23051