2017-01-15 16:27:22 +01:00
% 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
2017-02-01 21:34:01 +01:00
<textarea id="purpose" name="purpose" style="width:100%"><%= $debit->purpose %></textarea>
2017-01-15 16:27:22 +01:00
% end
2017-01-29 15:57:34 +01:00
% $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
2017-01-15 16:27:22 +01:00
% $r{value} = begin
<input id="value" name="value" value="<%= $debit->value %>"> Cent
% end
% $r{targetCredit} = begin
% if ( !@$targets ) {
2017-02-02 22:23:23 +01:00
<div 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.</div>
2017-01-15 16:27:22 +01:00
% $targets = [ ['', '', ''] ];
% }
% my $cmpacc = $targets->[0][1];
% my $target = $debit->targetCredit // '';
<select id="targetCredit" title="<%= $targets_count %>" name="targetCredit">
2017-01-25 22:38:39 +01:00
<option value="">-- Please select (unless outgoing payment) --</option>
2017-01-15 16:27:22 +01:00
<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
2017-01-29 15:57:34 +01:00
% if ( !stash 'account' ) {
2017-01-15 16:27:22 +01:00
% $r{debtor} = begin
2017-01-25 22:38:39 +01:00
% my $g = param 'group';
<input id="debtor" name="debtor" value="<%= $g ? "\@$g" : $debit->debtor %>">
2017-01-15 16:27:22 +01:00
% end
2017-01-29 15:57:34 +01:00
% }
2017-01-15 16:27:22 +01:00
<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>
2017-01-31 22:18:16 +01:00
% my %used_credits;
2017-01-15 16:27:22 +01:00
% 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;
2017-01-31 22:18:16 +01:00
% $used_credits{ $t->credId } = 1;
2017-01-15 16:27:22 +01:00
<tr><td><input type="checkbox" name="revoke" value="<%= $t->credId %>"></td>
<td><%= $t->timestamp %></td>
2017-01-15 22:03:06 +01:00
<td><%== nl2br $c->purpose %></td>
2017-01-31 22:18:16 +01:00
<td class="number"><%== money $t->amount %></td>
<td><input type="text" name="note[<%= $t->credId %>]" value="<%= $t->note %>"></td>
2017-01-15 16:27:22 +01:00
</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;
2017-02-01 21:34:01 +01:00
% if ( $credits->count() ) {
2017-02-02 22:23:23 +01:00
<p><%= $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 <strong>pay this debit</strong> with:</p>
2017-01-15 16:27:22 +01:00
<table>
2017-01-28 14:00:20 +01:00
<tr><th>S</th><th>date</th><th>purpose</th><th>to spend</th><th>note</th></tr>
2017-01-31 22:18:16 +01:00
% 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>
2017-01-15 16:27:22 +01:00
</tr>
% }
</table>
% }
% else {
<p>Currently no credits available.</p>
% }
% }
2017-02-02 22:23:23 +01:00
<p><button type="submit">Submit</button></p>
2017-01-15 16:27:22 +01:00
</form>