@@ -, +, @@ --- Koha/Account.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/Koha/Account.pm +++ a/Koha/Account.pm @@ -131,11 +131,12 @@ sub pay { # Were not passed a specific line to pay, or the payment was for more # than the what was owed on the given line. In that case pay down other # lines with remaining balance. - my @outstanding_fines; - @outstanding_fines = Koha::Account::Lines->search( + # We select all lines with both positive and negative amountoutstanding + # this allows credits to be applied by the logic below and negative balances to be cleared + my @outstanding_fines = Koha::Account::Lines->search( { borrowernumber => $self->{patron_id}, - amountoutstanding => { '>' => 0 }, + amountoutstanding => { '<>' => 0 }, } ) if $balance_remaining > 0; --