use List::MoreUtils qw( uniq );
use Try::Tiny;
-use C4::Circulation qw( ReturnLostItem );
+use C4::Circulation qw( ReturnLostItem CanBookBeRenewed AddRenewal );
use C4::Letters;
use C4::Log qw( logaction );
use C4::Stats qw( UpdateStats );
+use C4::Overdues qw(GetFine);
use Koha::Patrons;
use Koha::Account::Lines;
use Koha::Account::Offsets;
+use Koha::Account::DebitTypes;
use Koha::DateUtils qw( dt_from_string );
use Koha::Exceptions;
use Koha::Exceptions::Account;
my @fines_paid; # List of account lines paid on with this payment
+ # 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;
+ # 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 ( $new_amountoutstanding == 0
&& $fine->itemnumber
$fine->amountoutstanding( $old_amountoutstanding - $amount_to_pay );
$fine->store();
+ # If we need to make a note of the item associated with this line,
+ # in order that we can potentially renew it, do so.
+ my $amt = $old_amountoutstanding - $amount_to_pay;
+ if ($fine->renewable) {
+ my $outcome = $fine->renew_item;
+ push @{$renew_outcomes}, $outcome;
+ }
+
if ( $fine->amountoutstanding == 0
&& $fine->itemnumber
&& $fine->debit_type_code
UpdateStats(
{
branch => $library_id,
- type => $type,
+ type => lc($type),
amount => $amount,
borrowernumber => $self->{patron_id},
}
lang => $patron->lang,
tables => {
borrowers => $self->{patron_id},
- branches => $self->{library_id},
+ branches => $library_id,
},
substitute => {
credit => $payment,
}
}
- return $payment->id;
+ return { payment_id => $payment->id, renew_result => $renew_outcomes };
}
=head3 add_credit
- 'CREDIT'
- 'PAYMENT'
- 'FORGIVEN'
- - 'LOST_RETURN'
+ - 'LOST_FOUND'
- 'WRITEOFF'
=cut
my $account_offset = Koha::Account::Offset->new(
{
credit_id => $line->id,
- type => $Koha::Account::offset_type->{$credit_type},
+ type => $Koha::Account::offset_type->{$credit_type} // $Koha::Account::offset_type->{CREDIT},
amount => $amount
}
)->store();
UpdateStats(
{
branch => $library_id,
- type => $credit_type,
+ type => lc($credit_type),
amount => $amount,
borrowernumber => $self->{patron_id},
}
our $offset_type = {
'CREDIT' => 'Manual Credit',
'FORGIVEN' => 'Writeoff',
- 'LOST_RETURN' => 'Lost Item',
+ 'LOST_FOUND' => 'Lost Item Found',
'PAYMENT' => 'Payment',
'WRITEOFF' => 'Writeoff',
'ACCOUNT' => 'Account Fee',