treasuredb/templates/credit/upsert.html.ep

99 lines
3.1 KiB
Plaintext
Raw Normal View History

2017-01-15 16:27:22 +01:00
% my $id = stash 'id';
% title $id ? "Change credit $id" : "Enter new credit";
<form 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
<input id="purpose" name="purpose" style="width:100%" value="<%= $credit->purpose %>">
% end
2017-01-29 15:57:34 +01:00
% $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
2017-01-15 16:27:22 +01:00
% $r{value} = begin
<input id="value" name="value" value="<%= $credit->value %>"> Cent (declare target credit with "0")
% end
% $r{account} = begin
<input id="account" name="account" value="<%= $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;
2017-01-15 16:27:22 +01:00
% 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;
2017-01-15 16:27:22 +01:00
<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>
2017-01-15 16:27:22 +01:00
</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->first() ) {
<p><%= $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>
2017-01-15 16:27:22 +01:00
<p>Check arrears you want to <strong>use this credit</strong> for.</p>
<table>
<tr><th>S</th><th>date</th><th>purpose</th><th>to pay</th></tr>
% while ( my $d = $arrears->next ) {
% next if $paid_debits{ $d->billId };
2017-01-15 16:27:22 +01:00
<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>
2017-01-15 16:27:22 +01:00
</tr>
% }
</table>
% }
% else {
<p>Currently no arrears to pay.</p>
% }
% }
<button type="submit">Submit</button>
</form>