diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt
index cb49492a94..6d8c942149 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt
@@ -52,7 +52,11 @@
| Total due: |
+[% IF outstanding_credits.total_outstanding < 0 %]
+ [% total + outstanding_credits.total_outstanding | $Price %] |
+[% ELSE %]
[% total | $Price %] |
+[% END %]
@@ -109,6 +113,12 @@
[% line.amountoutstanding | $Price %] |
[% END %]
+[% IF outstanding_credits.total_outstanding < 0 %]
+
+ | Outstanding credits could be applied |
+ [% outstanding_credits.total_outstanding | $Price %] |
+
+[% END %]
[% IF ( account_grp.total ) %]
diff --git a/members/pay.pl b/members/pay.pl
index b2216aa511..848141906e 100755
--- a/members/pay.pl
+++ b/members/pay.pl
@@ -87,6 +87,9 @@ elsif ( $input->param('writeoff_selected') ) {
elsif ( $input->param('woall') ) {
writeoff_all(@names);
}
+elsif ( $input->param('apply_credits') ) {
+ apply_credits({ patron => $patron, cgi => $input });
+}
elsif ( $input->param('confirm_writeoff') ) {
my $accountlines_id = $input->param('accountlines_id');
my $amount = $input->param('amountwrittenoff');
@@ -138,7 +141,9 @@ output_html_with_http_headers $input, $cookie, $template->output;
sub add_accounts_to_template {
my $patron = Koha::Patrons->find( $borrowernumber );
- my $account_lines = $patron->account->outstanding_debits;
+ my $account = $patron->account;
+ my $outstanding_credits = $account->outstanding_credits;
+ my $account_lines = $account->outstanding_debits;
my $total = $account_lines->total_outstanding;
my @accounts;
while ( my $account_line = $account_lines->next ) {
@@ -157,7 +162,9 @@ sub add_accounts_to_template {
patron => $patron,
accounts => \@accounts,
total => $total,
+ outstanding_credits => $outstanding_credits
);
+
return;
}
@@ -273,3 +280,15 @@ sub payselected {
print $input->redirect($redirect);
return;
}
+
+sub apply_credits {
+ my ($args) = @_;
+
+ my $patron = $args->{patron};
+ my $cgi = $args->{cgi};
+
+ $patron->account->reconcile_balance();
+
+ print $cgi->redirect("/cgi-bin/koha/members/pay.pl?borrowernumber=" . $patron->borrowernumber );
+ return;
+}