Added rudimentary HTTP interface

This commit is contained in:
Florian "flowdy" Heß
2017-01-15 16:27:22 +01:00
parent 6d31efee39
commit f4bcbcad6f
26 changed files with 1758 additions and 38 deletions

View File

@@ -0,0 +1,16 @@
% title 'Transfer history';
<p>Reverse ordered list:</p>
<table>
<tr><th>Timestamp</th><th>Purpose (own/other/debit)</th><th>debit</th><th>credit</th><th>note</th></tr>
% while ( my $hr = $history->next ) {
<tr><td><%= $hr->date %></td><td>
% my $this = $hr->this_credit;
<strong>On <a href="/credit/<%= $hr->credId %>"><%= <%= $this->credId %></a>:</strong> <%= $this->purpose %><br>
% my $that = $hr->that_credit;
<strong>With <%= $that->account->ID %>/<a href="/credit/<%= $that->credId %>"><%= <%= $that->credId %></a>:</strong> <%= $that->purpose %><br>
<strong>Pay <%= $hr->billId %>:</strong> <%= $hr->purpose %>
</td><td class="number"><%= $hr->debit %></td><td class="number"><%= $hr->credit %></td><td><%= $hr->note %></td></tr>
% }
</table>

View File

@@ -0,0 +1,51 @@
% title 'Accounts';
<table class="accounts">
<col class="account"><col class="even_until"><col class="arrears"><col><col><col class="transfer"><col class="available"><col><col><col class="earned"><col class="promised"><col class="history"><col class="report">
<tr><th>Account</th><th>Even until</th><th colspan="3">Arrears</th><th>Transfer</th><th colspan="3">Available</th><th>Earned</th><th>Promised</th><th>History</th><th>Report</th></tr>
% my ($type) = q{};
% my $inter_header = begin
<tr><th colspan="13"><%= shift || 'Club management accounts' %></th></tr>
% end
% while ( my $account = $accounts->next ) {
% my $bal = $account->balance;
% my $t = $account->type // q{};
% if ( $type ne $t ) {
% $type = $t;
<%= $inter_header->($t) %>
% }
% my $u = $account->ID;
<tr><th><%= $u %></th>
<td class="even_until"><%= $bal->even_until // "never" %></td><td class="number"><%= $bal->arrears %></td><td><a href="<%= $u %>/debits">list</td><td><a href="<%= $u %>/out">add</a></td>
<td class="centered">
% my $which = ($bal->arrears && 1) + ($bal->available && 1);
% if ( $which == 2 ) {
<a class="transfer-btn" href="<%= $u %>/transfer">C&hArr;D!</a>
% }
% elsif ( $which ) {
<span style="background-color:rgba(224,224,0,0.4);">N/A</span>
% }
% else {
<span style="background-color:rgba(0,224,0,0.4);">N/A</span>
% }
</td><td class="number"><%= $bal->available %></td><td><a href="<%= $u %>/credits">list</a></td><td><a href="<%= $u %>/in">add</a></td><td class="number"><%= $bal->earned %></td><td class="number"><%= $bal->promised %></td><td><a href="<%= $u %>/history">History</a></td><td><a href="<%= $u %>/report">Report</a></td></tr>
% } # while
</table>
<div class="help">
<h2>Column explanation</h2>
<dl>
<dt>Even till:</dt>
<dd><p>Date of debt up to and including which all is settled.</p></dd>
<dt>Arrears:</dt>
<dd><p>Unpaid debits</p></dd>
<dt>Transfer:</dt>
<dd><p>Link to a view where you can match credit and debit and have the software transfer money in between automatically. Yellow "N/A" means there is no money to transfer as either credit or debit is 0. Green "N/A" means there is no money to transfer because the account is even.</p></dd>
<dt>Available:</dt>
<dd><p>Credits that have not been used or not to full extent, yet</p></dd>
<dt>Earned:</dt>
<dd><p>Paid debits targetting credits of that account.</p></dd>
<dt>Promised:</dt>
<dd><p>Unpaid or not fully paid debits targetting credits of that account.</p></dd>
</dl>
</div>

View File

@@ -0,0 +1,39 @@
% title 'Make transfers';
<p>Check at least one item of each table that belong together.</p>
<form method="post">
<h2>Available credits</h2>
<p>Check credits you want to <strong>pay above debit(s)</strong> with.</p>
<table>
<tr><th>S</th><th>date</th><th>purpose</th><th>to spend</th></tr>
% while ( my $d = $credits->next ) {
<tr><td><input type="checkbox" name="credits" value="<%= $d->credId %>"></td>
<td><%= $d->date %></td>
<td><%= $d->purpose %></td>
<td><%= $d->difference %></td>
</tr>
% }
</table>
<h2>Current arrears</h2>
<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 ) {
<tr><td><input type="checkbox" name="debits" value="<%= $d->billId %>"></td>
<td><%= $d->date %></td>
<td><%= $d->purpose %></td>
<td><%= $d->difference %></td>
</tr>
% }
</table>
<p><button type="submit">Make transfers</button>
<a href="<%= url_for('home') %>">Return to account list</a></p>
</form>

View File

@@ -0,0 +1,8 @@
% title 'Bank statement';
<table>
<tr><th>Date</th><th>Account</th><th>Purpose</th><th>Debit</th><th>Credit</th></tr>
% while ( my $record = $records->next ) {
<tr><td><%= $record->date %></td><td><%= $record->account %></td><td><%= $record->purpose %></td><td><%= $record->debit %></td><td><%= $record->credit %></td></tr>
% }
</table>

View File

@@ -0,0 +1,8 @@
% title 'Income of ' . $account;
<table class="income">
<tr><th>Id</th><th>Date</th><th>Purpose</th><th>value</th><th>spent</th></tr>
% while ( my $credit = $credits->next ) {
<tr><td class="number"><a href="/credit/<%= $credit->credId %>"><%= $credit->credId %></a></td><td><%= $credit->date %></td><td><%= $credit->purpose %></td><td class="number"><%= $credit->value %></td><td class="number"><%= $credit->spent %></td></tr>
% }
</table>

View File

@@ -0,0 +1,82 @@
% 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
% $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>
% 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;
<tr><td><input type="checkbox" name="revoke" value="<%= $t->billId %>"></td>
<td><%= $t->timestamp %></td>
<td><%= $d->purpose %></td>
<td><%= $t->amount %></td>
<td><%= $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>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 ) {
<tr><td><input type="checkbox" name="spendFor" value="<%= $d->billId %>"></td>
<td><%= $d->date %></td>
<td><%= $d->purpose %></td>
<td><%= $d->difference %></td>
</tr>
% }
</table>
% }
% else {
<p>Currently no arrears to pay.</p>
% }
% }
<button type="submit">Submit</button>
</form>

View File

@@ -0,0 +1,9 @@
% title 'Outcome of ' . $account;
<table class="income">
<tr><th>Id</th><th>Date</th><th>Purpose</th><th>value</th><th>paid</th><th>to</th></tr>
% while ( my $debit = $debits->next ) {
% my $tgt = $debit->target;
<tr><td><a href="/debit/<%= $debit->billId %>"><%= $debit->billId %></a></td><td><%= $debit->date %></td><td><%= $debit->purpose %></td><td class="number"><%= $debit->value %></td><td class="number"><%= $debit->paid %><td><a href="/credit/<%= $tgt->credId %>"><%= $tgt->account->ID %></a></tr>
% }
</table>

View File

@@ -0,0 +1,109 @@
% 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
<input id="purpose" name="purpose" style="width:100%" value="<%= $debit->purpose %>">
% 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 (mandatory) --</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
% $r{debtor} = begin
<input id="debtor" name="debtor" value="<%= $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>
% 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;
<tr><td><input type="checkbox" name="revoke" value="<%= $t->credId %>"></td>
<td><%= $t->timestamp %></td>
<td><%= $c->purpose %></td>
<td><%= $t->amount %></td>
<td><%= $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>Check 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></tr>
% while ( my $d = $credits->next ) {
<tr><td><input type="checkbox" name="payWith" value="<%= $d->credId %>"></td>
<td><%= $d->date %></td>
<td><%= $d->purpose %></td>
<td><%= $d->difference %></td>
</tr>
% }
</table>
% }
% else {
<p>Currently no credits available.</p>
% }
% }
<button type="submit">Submit</button>
</form>

View File

@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, minimum-scale=1" />
<title>TrsrDB<% if (my $t = title) { %>: <%= $t %><% } %></title>
<link rel="stylesheet" type="text/css"
href="/style.css" media="screen,projection">
% my $scripts = stash 'addScripts';
% for my $script ( @$scripts ) {
<script src="/scripts/<%= $script %>.js"></script>
% }
</head>
<body>
% if ( my $t = title ) {
<h1>Treasure DB: <%= $t %></h1>
% }
<%= content %>
</body>
</html>

View File

@@ -0,0 +1,19 @@
% for ( $retry_msg // () ) {
% $_ = $_ eq 'authfailure' ? "Authentication failed: User does not exist "
% . "or the password was wrong."
% : $_ eq 'loggedOut' ? "You have been logged out. All session cookies "
% . "are expired and deleted. If you want to re-login:"
% : undef;
% }
% title 'User login';
% if ( $retry_msg ) {
<p class="error"><%= $retry_msg %></p>
% }
<form method="post" action="/login"><p>
User id: <input name="user" type="text" placeholder="user id or email" value="<%= param('user') %>"><br>
Password: <input name="password" type="password"><br>
<input type="submit" value="Login">
</p></form>