Various fixes and completing the HTTP interface
This commit is contained in:
parent
f4bcbcad6f
commit
53ef8ff175
@ -32,6 +32,16 @@ sub startup {
|
|||||||
user => undef,
|
user => undef,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$self->helper(money => sub {
|
||||||
|
my (undef, $cent) = @_;
|
||||||
|
return if !defined $cent;
|
||||||
|
my $c100 = $cent =~ s{ (\d{0,2}) \z }{}xms && sprintf("%02d", $1);
|
||||||
|
$cent ||= 0;
|
||||||
|
return qq{<strong>$cent</strong>.$c100};
|
||||||
|
});
|
||||||
|
$self->helper(nl2br => sub {
|
||||||
|
pop =~ s{\n}{<br>}grms;
|
||||||
|
});
|
||||||
|
|
||||||
if ( my $l = $ENV{LOG} ) {
|
if ( my $l = $ENV{LOG} ) {
|
||||||
use Mojo::Log;
|
use Mojo::Log;
|
||||||
@ -53,6 +63,13 @@ sub startup {
|
|||||||
|
|
||||||
$auth->get( '/logout' )->to("user#logout");
|
$auth->get( '/logout' )->to("user#logout");
|
||||||
|
|
||||||
|
my $check = $auth->under(sub { shift->stash('grade') })->get('/');
|
||||||
|
$check->get('/bankStatement' => sub {
|
||||||
|
my $c = shift;
|
||||||
|
$c->stash( records => $c->app->db->resultset("ReconstructedBankStatement") );
|
||||||
|
$c->render('bankStatement');
|
||||||
|
});
|
||||||
|
|
||||||
my $admin = $auth->under(sub { shift->stash('grade') > 1 });
|
my $admin = $auth->under(sub { shift->stash('grade') > 1 });
|
||||||
$admin->any('/admin')->to('admin#dash');
|
$admin->any('/admin')->to('admin#dash');
|
||||||
$admin->post('/:account/in')->to('credit#upsert');
|
$admin->post('/:account/in')->to('credit#upsert');
|
||||||
@ -68,13 +85,6 @@ sub startup {
|
|||||||
|
|
||||||
$auth->get('/')->to('account#list')->name('home');
|
$auth->get('/')->to('account#list')->name('home');
|
||||||
|
|
||||||
my $check = $auth->under(sub { shift->stash('grade') })->get('/');
|
|
||||||
$check->get('/bankStatement')->to(sub {
|
|
||||||
my $c = shift;
|
|
||||||
$c->stash( records => $c->app->db->resultset("ReconstructedBankStatement") );
|
|
||||||
$c->render('bankStatement');
|
|
||||||
});
|
|
||||||
|
|
||||||
my $account = $auth->get('/:account')->under(sub {
|
my $account = $auth->get('/:account')->under(sub {
|
||||||
my $c = shift;
|
my $c = shift;
|
||||||
|
|
||||||
|
@ -31,13 +31,15 @@ sub transfer {
|
|||||||
my $db = $self->app->db;
|
my $db = $self->app->db;
|
||||||
my $account = $db->resultset("Account")->find( $self->stash("account") );
|
my $account = $db->resultset("Account")->find( $self->stash("account") );
|
||||||
|
|
||||||
if ( $self->req->method eq 'GET' ) {
|
my $credits = $account->available_credits;
|
||||||
$self->stash(
|
my $arrears = $account->current_arrears;
|
||||||
credits => $account->available_credits_rs,
|
|
||||||
arrears => $account->current_arrears_rs,
|
return $self->redirect_to('home')
|
||||||
);
|
if !( $credits->count() && $arrears->count() );
|
||||||
return;
|
|
||||||
}
|
$self->stash( credits => $credits, arrears => $arrears );
|
||||||
|
|
||||||
|
return if $self->req->method ne 'POST';
|
||||||
|
|
||||||
$db->make_transfers(
|
$db->make_transfers(
|
||||||
$self->every_param('credits')
|
$self->every_param('credits')
|
||||||
@ -47,5 +49,19 @@ sub transfer {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub report {
|
||||||
|
my $self = shift;
|
||||||
|
my $account = $self->app->db
|
||||||
|
->resultset("Account")
|
||||||
|
->find( $self->stash("account") )
|
||||||
|
;
|
||||||
|
|
||||||
|
$self->stash( report => $account->report->search_rs(
|
||||||
|
{}, { order_by => { -asc => [qw/date/] } }
|
||||||
|
) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ a.transfer-btn {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
border: 2px outset rgb(224,32,0);
|
border: 2px outset rgb(224,32,0);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
border-radius: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
table td.even_until {
|
table td.even_until {
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
echo "My database file: $1"
|
echo "My database file: $1"
|
||||||
if sqlite3 $1 < schema.sql; then
|
if sqlite3 $1 < schema.sql; then
|
||||||
diff t/schema.out <(sqlite3 $1 < t/schema.sql 2>&1)
|
diff t/schema.out <(sqlite3 $1 < t/schema.sql 2>&1) \
|
||||||
|
&& rm $1 && sqlite3 $1 < t/schema.sql \
|
||||||
|
&& TRSRDB_SQLITE_FILE=$1 perl t/schema.t \
|
||||||
|
&& rm -i $1
|
||||||
fi
|
fi
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
% while ( my $hr = $history->next ) {
|
% while ( my $hr = $history->next ) {
|
||||||
<tr><td><%= $hr->date %></td><td>
|
<tr><td><%= $hr->date %></td><td>
|
||||||
% my $this = $hr->this_credit;
|
% my $this = $hr->this_credit;
|
||||||
<strong>On <a href="/credit/<%= $hr->credId %>"><%= <%= $this->credId %></a>:</strong> <%= $this->purpose %><br>
|
<strong>On <a href="/credit/<%= $hr->credId %>"><%= <%= $this->credId %></a>:</strong> <%== nl2br $this->purpose %><br>
|
||||||
% my $that = $hr->that_credit;
|
% my $that = $hr->that_credit;
|
||||||
<strong>With <%= $that->account->ID %>/<a href="/credit/<%= $that->credId %>"><%= <%= $that->credId %></a>:</strong> <%= $that->purpose %><br>
|
<strong>With <%= $that->account->ID %>/<a href="/credit/<%= $that->credId %>"><%= <%= $that->credId %></a>:</strong> <%== nl2br $that->purpose %><br>
|
||||||
<strong>Pay <%= $hr->billId %>:</strong> <%= $hr->purpose %>
|
<strong>Pay <%= $hr->billId %>:</strong> <%== nl2br $hr->purpose %>
|
||||||
</td><td class="number"><%= $hr->debit %></td><td class="number"><%= $hr->credit %></td><td><%= $hr->note %></td></tr>
|
</td><td class="number"><%== money $hr->debit %></td><td class="number"><%== money $hr->credit %></td><td><%= $hr->note %></td></tr>
|
||||||
% }
|
% }
|
||||||
</table>
|
</table>
|
||||||
|
@ -16,22 +16,23 @@
|
|||||||
% }
|
% }
|
||||||
% my $u = $account->ID;
|
% my $u = $account->ID;
|
||||||
<tr><th><%= $u %></th>
|
<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="even_until"><%= $bal->even_until // "never" %></td><td class="number"><%== money $bal->arrears %></td><td><a href="<%= $u %>/debits">list</td><td><a href="<%= $u %>/out">add</a></td>
|
||||||
<td class="centered">
|
<td class="centered">
|
||||||
% my $which = ($bal->arrears && 1) + ($bal->available && 1);
|
% my $which = ($bal->arrears && 1) + ($bal->available && 1);
|
||||||
% if ( $which == 2 ) {
|
% if ( $which == 2 ) {
|
||||||
<a class="transfer-btn" href="<%= $u %>/transfer">C⇔D!</a>
|
<a class="transfer-btn" href="<%= $u %>/transfer">C⇔D!</a>
|
||||||
% }
|
% }
|
||||||
% elsif ( $which ) {
|
% elsif ( $which ) {
|
||||||
<span style="background-color:rgba(224,224,0,0.4);">N/A</span>
|
<span style="background-color:rgba(224,224,0,0.4);"> N/A </span>
|
||||||
% }
|
% }
|
||||||
% else {
|
% else {
|
||||||
<span style="background-color:rgba(0,224,0,0.4);">N/A</span>
|
<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>
|
</td><td class="number"><%== money $bal->available %></td><td><a href="<%= $u %>/credits">list</a></td><td><a href="<%= $u %>/in">add</a></td><td class="number"><%== money $bal->earned %></td><td class="number"><%== money $bal->promised %></td><td><a href="<%= $u %>/history">History</a></td><td><a href="<%= $u %>/report">Report</a></td></tr>
|
||||||
% } # while
|
% } # while
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<p style="text-align:center;"><a href="/bankStatement">Reconstructed bank statement</a></p>
|
||||||
<div class="help">
|
<div class="help">
|
||||||
<h2>Column explanation</h2>
|
<h2>Column explanation</h2>
|
||||||
<dl>
|
<dl>
|
||||||
|
8
templates/account/report.html.ep
Normal file
8
templates/account/report.html.ep
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
% title 'Account report';
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr><th>Date</th><th>Value</th><th>Purpose</th></tr>
|
||||||
|
% while ( my $record = $report->next ) {
|
||||||
|
<tr><td><%= $record->date %></td><td class="number"><%== money $record->value %></td><td><%== nl2br $record->purpose %></td></tr>
|
||||||
|
% }
|
||||||
|
</table>
|
@ -1,4 +1,4 @@
|
|||||||
% title 'Make transfers';
|
% title 'Make transfers for ' . $account;
|
||||||
|
|
||||||
<p>Check at least one item of each table that belong together.</p>
|
<p>Check at least one item of each table that belong together.</p>
|
||||||
|
|
||||||
@ -6,34 +6,33 @@
|
|||||||
|
|
||||||
<h2>Available credits</h2>
|
<h2>Available credits</h2>
|
||||||
|
|
||||||
<p>Check credits you want to <strong>pay above debit(s)</strong> with.</p>
|
<p>Check credits you want to <strong>spend for the arrear(s) below</strong> with.</p>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr><th>S</th><th>date</th><th>purpose</th><th>to spend</th></tr>
|
<tr><th>?</th><th>date</th><th>purpose</th><th>to spend</th></tr>
|
||||||
% while ( my $d = $credits->next ) {
|
% while ( my $d = $credits->next ) {
|
||||||
<tr><td><input type="checkbox" name="credits" value="<%= $d->credId %>"></td>
|
<tr><td><input type="checkbox" name="credits" value="<%= $d->credId %>"></td>
|
||||||
<td><%= $d->date %></td>
|
<td><%= $d->date %></td>
|
||||||
<td><%= $d->purpose %></td>
|
<td><%== nl2br $d->purpose %></td>
|
||||||
<td><%= $d->difference %></td>
|
<td class="number"><%== money $d->difference %></td>
|
||||||
</tr>
|
</tr>
|
||||||
% }
|
% }
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h2>Current arrears</h2>
|
<h2>Current arrears</h2>
|
||||||
|
|
||||||
<p>Check arrears you want to <strong>use this credit</strong> for.</p>
|
<p>Check arrears you want to <strong>settle with credit(s) above</strong>.</p>
|
||||||
<table>
|
<table>
|
||||||
<tr><th>S</th><th>date</th><th>purpose</th><th>to pay</th></tr>
|
<tr><th>?</th><th>date</th><th>purpose</th><th>to pay</th></tr>
|
||||||
% while ( my $d = $arrears->next ) {
|
% while ( my $d = $arrears->next ) {
|
||||||
<tr><td><input type="checkbox" name="debits" value="<%= $d->billId %>"></td>
|
<tr><td><input type="checkbox" name="debits" value="<%= $d->billId %>"></td>
|
||||||
<td><%= $d->date %></td>
|
<td><%= $d->date %></td>
|
||||||
<td><%= $d->purpose %></td>
|
<td><%== nl2br $d->purpose %></td>
|
||||||
<td><%= $d->difference %></td>
|
<td class="number"><%== money $d->difference %></td>
|
||||||
</tr>
|
</tr>
|
||||||
% }
|
% }
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<p><button type="submit">Make transfers</button>
|
<p><button type="submit">Make transfers</button>
|
||||||
<a href="<%= url_for('home') %>">Return to account list</a></p>
|
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
% title 'Bank statement';
|
% title 'Bank statement';
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr><th>Date</th><th>Account</th><th>Purpose</th><th>Debit</th><th>Credit</th></tr>
|
<tr><th>Date</th><th>Purpose</th><th>Account</th><th>Debit</th><th>Credit</th></tr>
|
||||||
% while ( my $record = $records->next ) {
|
% 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>
|
<tr><td><%= $record->date %></td><td><%= $record->purpose %></td><td><%= $record->account %></td><td><%= $record->debit %></td><td><%= $record->credit %></td></tr>
|
||||||
% }
|
% }
|
||||||
</table>
|
</table>
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
<table class="income">
|
<table class="income">
|
||||||
<tr><th>Id</th><th>Date</th><th>Purpose</th><th>value</th><th>spent</th></tr>
|
<tr><th>Id</th><th>Date</th><th>Purpose</th><th>value</th><th>spent</th></tr>
|
||||||
% while ( my $credit = $credits->next ) {
|
% 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>
|
<tr><td class="number"><a href="/credit/<%= $credit->credId %>"><%= $credit->credId %></a></td><td><%= $credit->date %></td><td><%== nl2br $credit->purpose %></td><td class="number"><%== money $credit->value %></td><td class="number"><%== money $credit->spent %></td></tr>
|
||||||
% }
|
% }
|
||||||
</table>
|
</table>
|
||||||
|
@ -43,8 +43,8 @@
|
|||||||
% my $d = $t->debit;
|
% my $d = $t->debit;
|
||||||
<tr><td><input type="checkbox" name="revoke" value="<%= $t->billId %>"></td>
|
<tr><td><input type="checkbox" name="revoke" value="<%= $t->billId %>"></td>
|
||||||
<td><%= $t->timestamp %></td>
|
<td><%= $t->timestamp %></td>
|
||||||
<td><%= $d->purpose %></td>
|
<td><%== nl2br $d->purpose %></td>
|
||||||
<td><%= $t->amount %></td>
|
<td class="number"><%== money $t->amount %></td>
|
||||||
<td><%= $t->note %></td>
|
<td><%= $t->note %></td>
|
||||||
</tr>
|
</tr>
|
||||||
% }
|
% }
|
||||||
@ -66,8 +66,8 @@
|
|||||||
% while ( my $d = $arrears->next ) {
|
% while ( my $d = $arrears->next ) {
|
||||||
<tr><td><input type="checkbox" name="spendFor" value="<%= $d->billId %>"></td>
|
<tr><td><input type="checkbox" name="spendFor" value="<%= $d->billId %>"></td>
|
||||||
<td><%= $d->date %></td>
|
<td><%= $d->date %></td>
|
||||||
<td><%= $d->purpose %></td>
|
<td><%== nl2br $d->purpose %></td>
|
||||||
<td><%= $d->difference %></td>
|
<td class="number"><%== money $d->difference %></td>
|
||||||
</tr>
|
</tr>
|
||||||
% }
|
% }
|
||||||
</table>
|
</table>
|
||||||
|
@ -4,6 +4,6 @@
|
|||||||
<tr><th>Id</th><th>Date</th><th>Purpose</th><th>value</th><th>paid</th><th>to</th></tr>
|
<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 ) {
|
% while ( my $debit = $debits->next ) {
|
||||||
% my $tgt = $debit->target;
|
% 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>
|
<tr><td><a href="/debit/<%= $debit->billId %>"><%= $debit->billId %></a></td><td><%= $debit->date %></td><td><%== nl2br $debit->purpose %></td><td class="number"><%== money $debit->value %></td><td class="number"><%== money $debit->paid %><td><a href="/credit/<%= $tgt->credId %>"><%= $tgt->account->ID %></a></tr>
|
||||||
% }
|
% }
|
||||||
</table>
|
</table>
|
||||||
|
@ -70,8 +70,8 @@ oops
|
|||||||
% my $c = $t->credit;
|
% my $c = $t->credit;
|
||||||
<tr><td><input type="checkbox" name="revoke" value="<%= $t->credId %>"></td>
|
<tr><td><input type="checkbox" name="revoke" value="<%= $t->credId %>"></td>
|
||||||
<td><%= $t->timestamp %></td>
|
<td><%= $t->timestamp %></td>
|
||||||
<td><%= $c->purpose %></td>
|
<td><%== nl2br $c->purpose %></td>
|
||||||
<td><%= $t->amount %></td>
|
<td><%== money $t->amount %></td>
|
||||||
<td><%= $t->note %></td>
|
<td><%= $t->note %></td>
|
||||||
</tr>
|
</tr>
|
||||||
% }
|
% }
|
||||||
@ -93,8 +93,8 @@ oops
|
|||||||
% while ( my $d = $credits->next ) {
|
% while ( my $d = $credits->next ) {
|
||||||
<tr><td><input type="checkbox" name="payWith" value="<%= $d->credId %>"></td>
|
<tr><td><input type="checkbox" name="payWith" value="<%= $d->credId %>"></td>
|
||||||
<td><%= $d->date %></td>
|
<td><%= $d->date %></td>
|
||||||
<td><%= $d->purpose %></td>
|
<td><%== nl2br $d->purpose %></td>
|
||||||
<td><%= $d->difference %></td>
|
<td><%== money $d->difference %></td>
|
||||||
</tr>
|
</tr>
|
||||||
% }
|
% }
|
||||||
</table>
|
</table>
|
||||||
|
@ -17,5 +17,6 @@
|
|||||||
% }
|
% }
|
||||||
<%= content %>
|
<%= content %>
|
||||||
|
|
||||||
|
<p style="text-align:center;"><a href="<%= url_for "home" %>">Back home – Account List</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user