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

(-)a/Koha/Account.pm (-40 / +66 lines)
Lines 119-131 sub pay { Link Here
119
119
120
        # If we need to make a note of the item associated with this line,
120
        # If we need to make a note of the item associated with this line,
121
        # in order that we can potentially renew it, do so.
121
        # in order that we can potentially renew it, do so.
122
        if (
122
        if (_fine_paid_renewable($new_amountoutstanding, $fine)) {
123
            $new_amountoutstanding == 0 &&
124
            $fine->accounttype &&
125
            $fine->accounttype eq 'OVERDUE' &&
126
            $fine->status &&
127
            $fine->status eq 'UNRETURNED'
128
        ) {
129
            $overdue_unreturned->{$fine->itemnumber} = $fine;
123
            $overdue_unreturned->{$fine->itemnumber} = $fine;
130
        }
124
        }
131
125
Lines 191-203 sub pay { Link Here
191
185
192
        # If we need to make a note of the item associated with this line,
186
        # If we need to make a note of the item associated with this line,
193
        # in order that we can potentially renew it, do so.
187
        # in order that we can potentially renew it, do so.
194
        if (
188
        my $amt = $old_amountoutstanding - $amount_to_pay;
195
            $old_amountoutstanding - $amount_to_pay == 0 &&
189
        if (_fine_paid_renewable($amt, $fine)) {
196
            $fine->accounttype &&
197
            $fine->accounttype eq 'OVERDUE' &&
198
            $fine->status &&
199
            $fine->status eq 'UNRETURNED'
200
        ) {
201
            $overdue_unreturned->{$fine->itemnumber} = $fine;
190
            $overdue_unreturned->{$fine->itemnumber} = $fine;
202
        }
191
        }
203
192
Lines 284-315 sub pay { Link Here
284
    # If we have overdue unreturned items that have had payments made
273
    # If we have overdue unreturned items that have had payments made
285
    # against them, check whether the balance on those items is now zero
274
    # against them, check whether the balance on those items is now zero
286
    # and, if the syspref is set, renew them
275
    # and, if the syspref is set, renew them
287
    # Same logic exists in Koha::Account::Line::apply
276
    _maybe_renew($overdue_unreturned, $self->{patron_id});
288
    if (
289
        C4::Context->preference('RenewAccruingItemWhenPaid') &&
290
        keys %{$overdue_unreturned}
291
    ) {
292
        foreach my $itemnumber (keys %{$overdue_unreturned}) {
293
            # Only do something if this item has no fines left on it
294
            my $fine = C4::Overdues::GetFine( $itemnumber, $self->{patron_id} );
295
            next if $fine && $fine > 0;
296
297
            my ( $renew_ok, $error ) =
298
                C4::Circulation::CanBookBeRenewed(
299
                    $self->{patron_id}, $itemnumber
300
                );
301
            if ( $renew_ok ) {
302
                C4::Circulation::AddRenewal(
303
                    $self->{patron_id},
304
                    $itemnumber,
305
                    $library_id,
306
                    undef,
307
                    undef,
308
                    1
309
                );
310
            }
311
        }
312
    }
313
277
314
    if ( C4::Context->preference("FinesLog") ) {
278
    if ( C4::Context->preference("FinesLog") ) {
315
        logaction(
279
        logaction(
Lines 760-765 sub reconcile_balance { Link Here
760
    return $self;
724
    return $self;
761
}
725
}
762
726
727
=head3 _fine_paid_renewable
728
729
my $bool = _fine_paid_renewable($amt, $fine);
730
731
Given an outstanding amount and a fine object, determine if this item
732
is potentially renewable as a result of the fine being paid off
733
734
=cut
735
736
sub _fine_paid_renewable {
737
    my ($amt, $fine) = @_;
738
739
    return (
740
        $amt == 0 &&
741
        $fine->accounttype &&
742
        $fine->accounttype eq 'OVERDUE' &&
743
        $fine->status &&
744
        $fine->status eq 'UNRETURNED'
745
    ) ? 1 : 0;
746
}
747
748
=head3 _maybe_renew
749
750
my $result = _maybe_renew($overdue_unreturned, $patron_id, $library_id);
751
752
If we have overdue unreturned items that have had payments made
753
against them, check whether the balance on those items is now zero
754
and, if the syspref is set, renew them
755
756
=cut
757
758
sub _maybe_renew {
759
    my ($items, $patron_id) = @_;
760
761
    if (
762
        C4::Context->preference('RenewAccruingItemWhenPaid') &&
763
        keys %{$items}
764
    ) {
765
        foreach my $itemnumber (keys %{$items}) {
766
            # Only do something if this item has no fines left on it
767
            my $fine = C4::Overdues::GetFine( $itemnumber, $patron_id );
768
            next if $fine && $fine > 0;
769
770
            my ( $renew_ok, $error ) =
771
                C4::Circulation::CanBookBeRenewed($patron_id, $itemnumber);
772
            if ( $renew_ok ) {
773
                my $due_date = C4::Circulation::AddRenewal(
774
                    $patron_id,
775
                    $itemnumber,
776
                    $items->{$itemnumber}->{branchcode},
777
                    undef,
778
                    undef,
779
                    1
780
                );
781
                return $due_date;
782
            } else {
783
                return $error;
784
            }
785
        }
786
    }
787
}
788
763
1;
789
1;
764
790
765
=head2 Name mappings
791
=head2 Name mappings
(-)a/Koha/Account/Line.pm (-37 / +10 lines)
Lines 23-28 use Data::Dumper; Link Here
23
use C4::Log qw(logaction);
23
use C4::Log qw(logaction);
24
use C4::Overdues qw(GetFine);
24
use C4::Overdues qw(GetFine);
25
25
26
use Koha::Account qw( _fine_paid_renewable _maybe_renew );
26
use Koha::Account::Offsets;
27
use Koha::Account::Offsets;
27
use Koha::Database;
28
use Koha::Database;
28
use Koha::Exceptions::Account;
29
use Koha::Exceptions::Account;
Lines 243-258 sub apply { Link Here
243
244
244
            # If we need to make a note of the item associated with this line,
245
            # 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
            # in order that we can potentially renew it, do so.
246
            # Same logic existing in Koha::Account::pay
247
            my $renewable = Koha::Account::_fine_paid_renewable(
247
            if (
248
                $debit->amountoutstanding,
248
                $debit->amountoutstanding == 0 &&
249
                $debit
249
                $debit->accounttype &&
250
            );
250
                $debit->accounttype eq 'OVERDUE' &&
251
            $overdue_unreturned->{$debit->itemnumber} = $debit if $renewable;
251
                $debit->status &&
252
                $debit->status eq 'UNRETURNED'
253
            ) {
254
                $overdue_unreturned->{$debit->itemnumber} = $debit;
255
            }
256
252
257
            # Same logic exists in Koha::Account::pay
253
            # Same logic exists in Koha::Account::pay
258
            if (   $debit->amountoutstanding == 0
254
            if (   $debit->amountoutstanding == 0
Lines 269-300 sub apply { Link Here
269
    # If we have overdue unreturned items that have had payments made
265
    # If we have overdue unreturned items that have had payments made
270
    # against them, check whether the balance on those items is now zero
266
    # against them, check whether the balance on those items is now zero
271
    # and, if the syspref is set, renew them
267
    # and, if the syspref is set, renew them
272
    # Same logic existing in Koha::Account::pay
268
    Koha::Account::_maybe_renew(
273
    if (
269
        $overdue_unreturned,
274
        C4::Context->preference('RenewAccruingItemWhenPaid') &&
270
        $self->borrowernumber
275
        keys %{$overdue_unreturned}
271
    );
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
272
299
    return $available_credit;
273
    return $available_credit;
300
}
274
}
301
- 

Return to bug 23051