@@ -, +, @@ - Apply this patch (on top of 21896) - On a patron's 'Fines' tab, create a 'manual invoice' (maybe more than one) - Go to the 'Pay fines' tab - On the 'create manual credit' tab, create a couple credits. - Go to the 'Pay fines' - Click on 'Apply credits' - Play with different options (credit excedes debts and vice-versa, they match, etc) - Sign off :-D --- .../prog/en/modules/members/pay.tt | 10 ++++++++++ members/pay.pl | 20 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt @@ -51,7 +51,11 @@ Total due: +[% IF outstanding_credits.total_outstanding < 0 %] + [% total + outstanding_credits.total_outstanding | $Price %] +[% ELSE %] [% total | $Price %] +[% END %] @@ -108,6 +112,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 ) %] --- a/members/pay.pl +++ a/members/pay.pl @@ -88,6 +88,8 @@ if ($payselected) { my $writeoff_all = $input->param('woall'); # writeoff all fines if ($writeoff_all) { writeoff_all(@names); +} elsif ( $input->param('apply_credits') ) { + apply_credits({ patron => $patron, cgi => $input }); } elsif ($writeoff_item) { my $accountlines_id = $input->param('accountlines_id'); my $amount = $input->param('amountwrittenoff'); @@ -141,7 +143,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 ) { @@ -160,7 +164,9 @@ sub add_accounts_to_template { patron => $patron, accounts => \@accounts, total => $total, + outstanding_credits => $outstanding_credits ); + return; } @@ -279,3 +285,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; +} --