treasuredb/templates/credit/upsert.html.ep

103 lines
3.2 KiB
Plaintext

% my $id = stash 'id';
% title $id ? "Change credit $id" : "Enter new credit";
<form class="<%= url_for %>" method="post">
<h2>Essentials</h2>
% my %r;
% $r{date} = begin
<input id="date" name="date" value="<%= $credit->date %>"> (Format: YYYY-MM-DD)
% end
% $r{purpose} = begin
<textarea id="purpose" name="purpose" style="width:100%"><%= $credit->purpose %></textarea>
% end
% $r{category} = begin
% my $category = $credit->category // '';
<select id="category" name="category">
<option value="">-- Please select --</option>
% while ( my $c = $categories->next ) {
<option value="<%= $c->ID %>" <%== $category == $c->ID ? 'selected="selected"' :'' %>>
<%= $c->label %>
</option>
% }
</select>
% end
% $r{value} = begin
<input id="value" name="value" value="<%= $credit->value %>"> Cent (target credit? See <a href="#help">help</a>)
% end
% $r{account} = begin
<%= $credit->account->ID %>
% end
<dl class="upsert">
% for my $f ( $credit->result_source->columns ) {
% my $renderer = $r{$f} // do {
% my $value = $credit->$f // next;
% begin
<%= $value %>
% end
% };
<dt><label for="<%= $f %>"><%= $f %>:</label></dt>
<dd><%= $renderer->() %></dd>
% }
</dl>
% my %paid_debits;
% if ( $credit->in_storage ) {
% my $o = $credit->outgoings;
% if ( $o->count() ) {
<h2>Outgoings</h2>
<p>If you want to <strong>revoke</strong> any outgoings, please check those.</p>
<table>
<tr><th>R</th><th>timestamp</th><th>paid</th><th>value</th><th>note</th></tr>
% while ( my $t = $o->next ) {
% my $d = $t->debit;
% $paid_debits{ $t->billId } = 1;
<tr><td><input type="checkbox" name="revoke" value="<%= $t->billId %>"></td>
<td><%= $t->timestamp %></td>
<td><%== nl2br $d->purpose %></td>
<td class="number"><%== money $t->amount %></td>
<td><input type="text" name="note[<%= $t->billId %>]" value="<%= $t->note %>"></td>
</tr>
% }
</table>
% }
% else {
<p>Credit not used, yet.</p>
% }
% }
% my $account = stash('account');
% if ( $account //= $credit->account ) {
<h2>Spend for arrears</h2>
% my $arrears = ( ref $account ? $account : app->db->resultset("Account")->find($account) )->current_arrears;
% if ( $arrears->count() ) {
<p><%= $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 <strong>spend this credit</strong> for:</p>
<table>
<tr><th>S</th><th>date</th><th>purpose</th><th>to pay</th><th>note</th></tr>
% while ( my $d = $arrears->next ) {
% next if $paid_debits{ $d->billId };
<tr><td><input type="checkbox" name="spendFor" value="<%= $d->billId %>"></td>
<td><%= $d->date %></td>
<td><%== nl2br $d->purpose %></td>
<td class="number"><%== money $d->difference %></td>
<td><input type="text" name="note[<%= $d->billId %>]"></td>
</tr>
% }
</table>
% }
% else {
<p>Currently no arrears to pay.</p>
% }
% }
<p><button type="submit">Submit</button></p>
</form>
% stash help => $_ for begin
<h2>How to declare a target credit?</h2>
<p>A target credit can be declared by assigning it an initial value of 0 (zero).</p>
% end