&& !defined($cash_register) );
my @fines_paid; # List of account lines paid on with this payment
- # Item numbers that have had a fine paid where the line has a accounttype
- # of OVERDUE and a status of UNRETURNED. We might want to try and renew
- # these items.
- my $overdue_unreturned = {};
+
+ # The outcome of any attempted item renewals as a result of fines being
+ # paid off
+ my $renew_outcomes = [];
my $balance_remaining = $amount; # Set it now so we can adjust the amount if necessary
$balance_remaining ||= 0;
$fine->amountoutstanding($new_amountoutstanding)->store();
$balance_remaining = $balance_remaining - $amount_to_pay;
- # If we need to make a note of the item associated with this line,
- # in order that we can potentially renew it, do so.
- if (
- $new_amountoutstanding == 0 &&
- $fine->accounttype &&
- $fine->accounttype eq 'OVERDUE' &&
- $fine->status &&
- $fine->status eq 'UNRETURNED'
- ) {
- $overdue_unreturned->{$fine->itemnumber} = $fine;
+ # Attempt to renew the item associated with this debit if
+ # appropriate
+ if ($fine->renewable) {
+ # We're ignoring the definition of $interface above, by all
+ # accounts we can't rely on C4::Context::interface, so here
+ # we're only using what we've been explicitly passed
+ my $outcome = $fine->renew_item({ interface => $interface });
+ push @{$renew_outcomes}, $outcome if $outcome;
}
# Same logic exists in Koha::Account::Line::apply
# If we need to make a note of the item associated with this line,
# in order that we can potentially renew it, do so.
- if (
- $old_amountoutstanding - $amount_to_pay == 0 &&
- $fine->accounttype &&
- $fine->accounttype eq 'OVERDUE' &&
- $fine->status &&
- $fine->status eq 'UNRETURNED'
- ) {
- $overdue_unreturned->{$fine->itemnumber} = $fine;
+ my $amt = $old_amountoutstanding - $amount_to_pay;
+ if ($fine->renewable) {
+ my $outcome = $fine->renew_item;
+ push @{$renew_outcomes}, $outcome;
}
if ( $fine->amountoutstanding == 0
}
);
- # If we have overdue unreturned items that have had payments made
- # against them, check whether the balance on those items is now zero
- # and, if the syspref is set, renew them
- # Same logic exists in Koha::Account::Line::apply
- if (
- C4::Context->preference('RenewAccruingItemWhenPaid') &&
- keys %{$overdue_unreturned}
- ) {
- foreach my $itemnumber (keys %{$overdue_unreturned}) {
- # Only do something if this item has no fines left on it
- my $fine = C4::Overdues::GetFine( $itemnumber, $self->{patron_id} );
- next if $fine && $fine > 0;
-
- my ( $renew_ok, $error ) =
- C4::Circulation::CanBookBeRenewed(
- $self->{patron_id}, $itemnumber
- );
- if ( $renew_ok ) {
- C4::Circulation::AddRenewal(
- $self->{patron_id},
- $itemnumber,
- $library_id,
- undef,
- undef,
- 1
- );
- }
- }
- }
-
if ( C4::Context->preference("FinesLog") ) {
logaction(
"FINES", 'CREATE',
}
}
- return $payment->id;
+ return { payment_id => $payment->id, renew_result => $renew_outcomes };
}
=head3 add_credit