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

Essentials

% my %r; % $r{date} = begin (Format: YYYY-MM-DD) % end % $r{purpose} = begin % end % $r{category} = begin % my $category = $credit->category // ''; % end % $r{value} = begin Cent (declare target credit with "0") % end % $r{account} = begin <%= $credit->account->ID %> % end
% for my $f ( $credit->result_source->columns ) { % my $renderer = $r{$f} // do { % my $value = $credit->$f // next; % begin <%= $value %> % end % };
<%= $renderer->() %>
% }
% my %paid_debits; % if ( $credit->in_storage ) { % my $o = $credit->outgoings; % if ( $o->count() ) {

Outgoings

If you want to revoke any outgoings, please check those.

% while ( my $t = $o->next ) { % my $d = $t->debit; % $paid_debits{ $t->billId } = 1; % }
Rtimestamppaidvaluenote
<%= $t->timestamp %> <%== nl2br $d->purpose %> <%== money $t->amount %>
% } % else {

Credit not used, yet.

% } % } % my $account = stash('account'); % if ( $account //= $credit->account ) {

Spend for arrears

% my $arrears = ( ref $account ? $account : app->db->resultset("Account")->find($account) )->current_arrears; % if ( $arrears->count() ) {

<%= $credit->value && $credit->value == $credit->spent ? "The credit is already spent. Unless you revoke any outgoings above, there is no point in checking" : "Check" %> <%= %paid_debits ? "other" : "" %> debits you want to spend this credit for:

% while ( my $d = $arrears->next ) { % next if $paid_debits{ $d->billId }; % }
Sdatepurposeto paynote
<%= $d->date %> <%== nl2br $d->purpose %> <%== money $d->difference %>
% } % else {

Currently no arrears to pay.

% } % }