<tfoot>
<tr>
<td class="total" colspan="6">Total due:</td>
+[% IF outstanding_credits.total_outstanding < 0 %]
+ <td style="text-align: right;">[% total + outstanding_credits.total_outstanding | $Price %]</td>
+[% ELSE %]
<td style="text-align: right;">[% total | $Price %]</td>
+[% END %]
</tr>
</tfoot>
<tbody>
<td class="debit" style="text-align: right;">[% line.amountoutstanding | $Price %]</td>
</tr>
[% END %]
+[% IF outstanding_credits.total_outstanding < 0 %]
+<tr>
+ <td class="total" colspan="6">Outstanding credits could be applied <input type="submit" id="apply_credits" name="apply_credits" value="Apply credits" class="submit" /></td>
+ <td class="credit" style="text-align: right;">[% outstanding_credits.total_outstanding | $Price %]</td>
+</tr>
+[% END %]
[% IF ( account_grp.total ) %]
<tr>
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');
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 ) {
patron => $patron,
accounts => \@accounts,
total => $total,
+ outstanding_credits => $outstanding_credits
);
+
return;
}
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;
+}