% my $id = stash 'id'; % title $id ? "Change debit $id" : "Enter new debit";

Essentials

% my %r; % $r{billId} = begin % end % $r{date} = begin (Format: YYYY-MM-DD) % end % $r{purpose} = begin % end % $r{category} = begin % my $category = $debit->category // ''; % end % $r{value} = begin Cent % end % $r{targetCredit} = begin % if ( !@$targets ) {
There are no target credits available. Target credits are credits of other accounts that either still have a value of 0, or which have already been targetted. Please create a target credit record first, because all debits must refer to one so settlements can be fulfilled.
% $targets = [ ['', '', ''] ]; % } % my $cmpacc = $targets->[0][1]; % my $target = $debit->targetCredit // ''; % end % if ( !stash 'account' ) { % $r{debtor} = begin % my $g = param 'group'; debtor %>"> % end % }
% for my $f ( $debit->result_source->columns ) { % my $renderer = $r{$f} // do { % my $value = $debit->$f // next; % begin <%= $value %> % end % };
<%= $renderer->() %>
% }
% my %used_credits; % if ( $debit->in_storage ) { % my $i = $debit->incomings; % if ( $i->count() ) {

Incomings

If you want to revoke any incomings, just check those.

% while ( my $t = $i->next ) { % my $c = $t->credit; % $used_credits{ $t->credId } = 1; % }
Rtimestamppaidvaluenote
<%= $t->timestamp %> <%== nl2br $c->purpose %> <%== money $t->amount %>
% } % else {

Debit not paid, yet.

% } % } % my $account = stash('account'); % if ( $account ||= $debit->debtor ) {

Pay with credits

% my $credits = app->db->resultset("Account")->find($account)->available_credits; % if ( $credits->count() ) {

<%= $debit->value && $debit->value == $debit->paid ? "The debt is already settled. Unless you revoke any incomings above, there is no point in checking" : "Check" %> <%= %used_credits ? "other" : "" %> credits you want to pay this debit with:

% while ( my $c = $credits->next ) { % next if $used_credits{ $c->credId }; % }
Sdatepurposeto spendnote
<%= $c->date %> <%== nl2br $c->purpose %> <%== money $c->difference %>
% } % else {

Currently no credits available.

% } % }