Various fixes; added full name to account data; do never transfer unchecked

This commit is contained in:
Florian "flowdy" Heß 2017-02-02 22:23:23 +01:00
parent ba30ec40a2
commit 8b1a68f07b
12 changed files with 66 additions and 31 deletions

View File

@ -4,7 +4,7 @@ package TrsrDB::Account;
use base qw/DBIx::Class::Core/;
__PACKAGE__->table('Account');
__PACKAGE__->add_columns(qw/ID type altId IBAN/);
__PACKAGE__->add_columns(qw/ID name type altId IBAN/);
__PACKAGE__->set_primary_key('ID');
__PACKAGE__->has_many(

View File

@ -30,24 +30,37 @@ sub upsert {
my $account_rs = $db->resultset("Account");
my $account;
if ( my $name = $self->stash("account") ) {
$self->stash( name => $name );
$self->stash( id => $name );
$account = $account_rs->find($name);
}
else {
$self->stash( name => undef );
$self->stash( id => undef );
$account = $account_rs->new({});
}
$self->stash( account => $account );
my $iban = $self->param("IBAN") // $account->IBAN;
if ( $self->req->method eq 'POST' ) {
my $p = $self->req->params->to_hash;
if ( $p->{IBAN} eq q{*} ) {
$p->{IBAN} = q{};
}
elsif ( !$iban ) {
delete $p->{IBAN};
}
for my $field ($account->result_source->columns) {
my $value = $self->param($field);
my $value = $p->{ $field };
$account->$field($value);
}
$account->update_or_insert();
$self->redirect_to("home");
}
else {
if ( defined( $iban ) ) {
$iban = q{*} if !$iban;
$account->IBAN($iban);
}
my @types = $account_rs->search({ type => { '!=' => q// } }, {
columns => ['type'], distinct => 1
})->get_column("type")->all;
@ -78,22 +91,22 @@ sub transfer {
my $db = $self->app->db;
my $account = $db->resultset("Account")->find( $self->stash("account") );
my $credits = $account->available_credits;
my $arrears = $account->current_arrears;
my $credits_rs = $account->available_credits;
my $arrears_rs = $account->current_arrears;
if ( $self->req->method eq 'POST' ) {
$db->make_transfers(
$self->every_param('credits')
=> $self->every_param('debits')
);
my $credit_ids = $self->every_param('credits');
my $arrear_ids = $self->every_param('debits');
if ( $self->req->method eq 'POST' && @$credit_ids && @$arrear_ids ) {
$db->make_transfers( $credit_ids => $arrear_ids );
}
if ( !( $credits->count && $arrears->count ) ) {
if ( !( $credits_rs->count && $arrears_rs->count ) ) {
$self->redirect_to('home');
return;
}
$self->stash( credits => $credits, arrears => $arrears );
$self->stash( credits => $credits_rs, arrears => $arrears_rs );
return;

View File

@ -52,7 +52,7 @@ sub upsert {
return;
}
for my $field ( qw/account date purpose category value/ ) {
for my $field ( qw/date purpose category value/ ) {
my $value = $self->param($field);
$value = undef if !length $value;
$credit->$field($value);

View File

@ -1,5 +1,6 @@
CREATE TABLE Account (
ID PRIMARY KEY NOT NULL,
name,
type NOT NULL,
altId NOT NULL, -- e.g. when type "member", no. in external member table
IBAN -- target account for returned payments (set '' to enable

View File

@ -71,6 +71,7 @@ table.history p.linked-credit {
input, textarea {
border: 1px solid #ddd;
padding: 2px;
}
dl dt {
@ -88,6 +89,7 @@ dl dd {
select {
border: 1px solid #ddd;
background-color:transparent;
padding: 2px;
}
.help {

View File

@ -17,7 +17,7 @@
<%= $inter_header->($t) %>
% }
% my $u = $account->ID;
<tr><th><a href="/account/<%= $u %>"><%= $u %></a></th>
<tr><th><a href="/account/<%= $u %>" title="<%= $account->name %>"><%= $u %></a></th>
<td class="even_until"><%= $bal->even_until // "never" %></td><td class="number"><%== money $bal->arrears %></td><td><a href="<%= $u %>/debits"><img class="icon" alt="List" src="/list.svg" alt="List"></td><td><a title="Add a debit" href="<%= $u %>/out"><img class="icon" src="/add-debit.svg" alt="Charge"></a></td>
<td class="centered">
% my $which = ($bal->arrears && 1) + ($bal->available && 1);

View File

@ -1,6 +1,6 @@
% title 'Make transfers for ' . $account;
<p>Check at least one item of both tables. Make sure they correspond in regard to their purposes. <em><strong>Caution:</strong> When you do not check any items in either table, this effectively is to check all in it!</em></p>
<p>Check at least one item of both tables. Make sure they correspond in regard to their purposes.</em></p>
<form method="post">

View File

@ -1,17 +1,20 @@
% title $name ? "Account $name" : "Create account";
% title $id ? "Account $id" : "Create account";
% my %r;
% $r{ID} = begin
<input id="ID" name="ID" value="<%= $account->ID %>">
% end
% $r{name} = begin
<input id="name" name="name" value="<%= $account->name %>">
% end
% $r{type} = begin
<input id="type" name="type" value="<%= $account->type %>"> (<%= join(", ", @$types) %> or a new?)
<input id="type" name="type" value="<%= $account->type %>"> (Currently there: <%= join(", ", @$types) %>)
% end
% $r{altId} = begin
<input id="altId" name="altId" value="<%= $account->altId %>">
% end
% $r{IBAN} = begin
<input id="IBAN" name="IBAN" value="<%= $account->IBAN %>">
<input id="IBAN" name="IBAN" value="<%= $account->IBAN %>"> (may also be empty or '*' s. help)
% end
<form method="post">
@ -32,4 +35,9 @@
<button type="submit">Submit</button>
</form>
% my $help = begin
<p><strong>What to input into "IBAN"?</strong> To restrict outgoing payments from that account to a certain bank account, insert its account number. To allow outgoing payment to any bank account, input wildcard (*). To disallow outgoing payment from that account, input nothing.</p>
<p>When inserting a proper number, this number must be included in all outgoing payments from that account. Outgoing payments differ from internal payments in that transferCredit is undefined.</p>
% end
% stash help => $help;

View File

@ -92,6 +92,6 @@
% }
% }
<button type="submit">Submit</button>
<p><button type="submit">Submit</button></p>
</form>

View File

@ -6,7 +6,14 @@
<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><%== nl2br $debit->purpose %></td><td class="number"><%== money $debit->value %></td><td class="number <%= $debit->paid < $debit->value ? "mark" : "" %>"><%== money $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 <%= $debit->paid < $debit->value ? "mark" : "" %>"><%== money $debit->paid %><td>
% if ( $tgt ) {
<a href="/credit/<%= $tgt->credId %>"><%= $tgt->account->ID %></a>
% }
% else {
(outgoing)
% }
</td></tr>
% }
</table>

View File

@ -30,9 +30,8 @@
% 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>
<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>
% $targets = [ ['', '', ''] ];
oops
% }
% my $cmpacc = $targets->[0][1];
% my $target = $debit->targetCredit // '';
@ -103,7 +102,7 @@ oops
<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>
<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>
<table>
<tr><th>S</th><th>date</th><th>purpose</th><th>to spend</th><th>note</th></tr>
% while ( my $c = $credits->next ) {
@ -122,6 +121,6 @@ oops
% }
% }
<button type="submit">Submit</button>
<p><button type="submit">Submit</button></p>
</form>

View File

@ -12,12 +12,17 @@
% }
<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>
<dl>
<dt>User id</dt>
<dd><input name="user" type="text" placeholder="user id or email" value="<%= param('user') %>"></dd>
<dt>Password</dt>
<dd><input name="password" type="password"></dd>
% if ( my $token = param 'token' ) {
Repeat: <input name="samepassword" type="password"><br>
<input type="hidden" name="token" value="<%= $token %>"><br>
<dt>Repeat</dt>
<dd><input name="samepassword" type="password">
<input type="hidden" name="token" value="<%= $token %>">
</dd>
% }
<button type="submit">Login</button>
<p><button type="submit">Login</button></p>
</p></form>
</form>