treasuredb/templates/debit/upsert.html.ep
2017-02-01 21:34:01 +01:00

128 lines
4.1 KiB
Plaintext

% my $id = stash 'id';
% title $id ? "Change debit $id" : "Enter new debit";
<form method="post">
<h2>Essentials</h2>
% my %r;
% $r{billId} = begin
<input id="billId" name="billId" value="<%= $debit->billId %>">
% end
% $r{date} = begin
<input id="date" name="date" value="<%= $debit->date %>"> (Format: YYYY-MM-DD)
% end
% $r{purpose} = begin
<textarea id="purpose" name="purpose" style="width:100%"><%= $debit->purpose %></textarea>
% end
% $r{category} = begin
% my $category = $debit->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="<%= $debit->value %>"> Cent
% end
% $r{targetCredit} = begin
% if ( !@$targets ) {
<p style="color:red;">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.</p>
% $targets = [ ['', '', ''] ];
oops
% }
% my $cmpacc = $targets->[0][1];
% my $target = $debit->targetCredit // '';
<select id="targetCredit" title="<%= $targets_count %>" name="targetCredit">
<option value="">-- Please select (unless outgoing payment) --</option>
<optgroup label="<%= $cmpacc %>">
% for my $tc ( @$targets ) {
% my $newacc = $tc->[1];
% if ( $newacc ne $cmpacc ) {
% $cmpacc = $newacc;
</optgroup>
<optgroup label="<%= $cmpacc %>">
% }
<option value="<%= $tc->[0] %>" <%== $tc->[0] eq $target ? 'selected="selected"' :'' %>>
<%= $tc->[2] %>
</option>
% }
</optgroup>
</select>
% end
% if ( !stash 'account' ) {
% $r{debtor} = begin
% my $g = param 'group';
<input id="debtor" name="debtor" value="<%= $g ? "\@$g" : $debit->debtor %>">
% end
% }
<dl class="upsert">
% for my $f ( $debit->result_source->columns ) {
% my $renderer = $r{$f} // do {
% my $value = $debit->$f // next;
% begin
<%= $value %>
% end
% };
<dt><label for="<%= $f %>"><%= $f %>: </label></dt>
<dd><%= $renderer->() %></dd>
% }
</dl>
% my %used_credits;
% if ( $debit->in_storage ) {
% my $i = $debit->incomings;
% if ( $i->count() ) {
<h2>Incomings</h2>
<p>If you want to <strong>revoke</strong> any incomings, just check those.</p>
<table>
<tr><th>R</th><th>timestamp</th><th>paid</th><th>value</th><th>note</th></tr>
% while ( my $t = $i->next ) {
% my $c = $t->credit;
% $used_credits{ $t->credId } = 1;
<tr><td><input type="checkbox" name="revoke" value="<%= $t->credId %>"></td>
<td><%= $t->timestamp %></td>
<td><%== nl2br $c->purpose %></td>
<td class="number"><%== money $t->amount %></td>
<td><input type="text" name="note[<%= $t->credId %>]" value="<%= $t->note %>"></td>
</tr>
% }
</table>
% }
% else {
<p>Debit not paid, yet.</p>
% }
% }
% my $account = stash('account');
% if ( $account ||= $debit->debtor ) {
<h2>Pay with credits</h2>
% my $credits = app->db->resultset("Account")->find($account)->available_credits;
% if ( $credits->count() ) {
<p><%= $debit->value && $debit->value == $debit->value ? "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 <strong>pay this debit</strong> with:</p>
<table>
<tr><th>S</th><th>date</th><th>purpose</th><th>to spend</th><th>note</th></tr>
% while ( my $c = $credits->next ) {
% next if $used_credits{ $c->credId };
<tr><td><input type="checkbox" name="payWith" value="<%= $c->credId %>"></td>
<td><%= $c->date %></td>
<td><%== nl2br $c->purpose %></td>
<td><%== money $c->difference %></td>
<td><input type="text" name="note[<%= $c->credId %>]"></td>
</tr>
% }
</table>
% }
% else {
<p>Currently no credits available.</p>
% }
% }
<button type="submit">Submit</button>
</form>