diff --git a/TrsrDB/Account.pm b/TrsrDB/Account.pm index 357a65c..e54ae4e 100644 --- a/TrsrDB/Account.pm +++ b/TrsrDB/Account.pm @@ -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( diff --git a/TrsrDB/HTTP/Account.pm b/TrsrDB/HTTP/Account.pm index aadfe56..224c7e1 100644 --- a/TrsrDB/HTTP/Account.pm +++ b/TrsrDB/HTTP/Account.pm @@ -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; diff --git a/TrsrDB/HTTP/Credit.pm b/TrsrDB/HTTP/Credit.pm index 6c43b49..9355607 100644 --- a/TrsrDB/HTTP/Credit.pm +++ b/TrsrDB/HTTP/Credit.pm @@ -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); diff --git a/schema/tables.sql b/schema/tables.sql index c3f097a..e04b7b7 100644 --- a/schema/tables.sql +++ b/schema/tables.sql @@ -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 diff --git a/site/style.css b/site/style.css index 52f442b..4d40e9a 100644 --- a/site/style.css +++ b/site/style.css @@ -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 { diff --git a/templates/account/list.html.ep b/templates/account/list.html.ep index 39ba6ee..e0aa604 100644 --- a/templates/account/list.html.ep +++ b/templates/account/list.html.ep @@ -17,7 +17,7 @@ <%= $inter_header->($t) %> % } % my $u = $account->ID; -<%= $u %> +<%= $u %> <%= $bal->even_until // "never" %><%== money $bal->arrears %>ListCharge % my $which = ($bal->arrears && 1) + ($bal->available && 1); diff --git a/templates/account/transfer.html.ep b/templates/account/transfer.html.ep index fcf919a..3ee4b2a 100644 --- a/templates/account/transfer.html.ep +++ b/templates/account/transfer.html.ep @@ -1,6 +1,6 @@ % title 'Make transfers for ' . $account; -

Check at least one item of both tables. Make sure they correspond in regard to their purposes. Caution: When you do not check any items in either table, this effectively is to check all in it!

+

Check at least one item of both tables. Make sure they correspond in regard to their purposes.

diff --git a/templates/account/upsert.html.ep b/templates/account/upsert.html.ep index 9a2cd0c..4a2b086 100644 --- a/templates/account/upsert.html.ep +++ b/templates/account/upsert.html.ep @@ -1,17 +1,20 @@ -% title $name ? "Account $name" : "Create account"; +% title $id ? "Account $id" : "Create account"; % my %r; % $r{ID} = begin % end +% $r{name} = begin + +% end % $r{type} = begin - (<%= join(", ", @$types) %> or a new?) + (Currently there: <%= join(", ", @$types) %>) % end % $r{altId} = begin % end % $r{IBAN} = begin - + (may also be empty or '*' – s. help) % end @@ -32,4 +35,9 @@
+% my $help = begin +

What to input into "IBAN"? 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.

+

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.

+% end +% stash help => $help; diff --git a/templates/credit/upsert.html.ep b/templates/credit/upsert.html.ep index 19f234c..82cf7f9 100644 --- a/templates/credit/upsert.html.ep +++ b/templates/credit/upsert.html.ep @@ -92,6 +92,6 @@ % } % } - +

diff --git a/templates/debit/list.html.ep b/templates/debit/list.html.ep index e16948c..de6ef01 100644 --- a/templates/debit/list.html.ep +++ b/templates/debit/list.html.ep @@ -6,7 +6,14 @@ IdDatePurposevaluepaidto % while ( my $debit = $debits->next ) { % my $tgt = $debit->target; -<%= $debit->billId %><%= $debit->date %><%== nl2br $debit->purpose %><%== money $debit->value %>"><%== money $debit->paid %><%= $tgt->account->ID %> +<%= $debit->billId %><%= $debit->date %><%== nl2br $debit->purpose %><%== money $debit->value %>"><%== money $debit->paid %> +% if ( $tgt ) { +<%= $tgt->account->ID %> +% } +% else { +(outgoing) +% } + % } diff --git a/templates/debit/upsert.html.ep b/templates/debit/upsert.html.ep index 8779fd5..a1b3ed7 100644 --- a/templates/debit/upsert.html.ep +++ b/templates/debit/upsert.html.ep @@ -30,9 +30,8 @@ % end % $r{targetCredit} = begin % if ( !@$targets ) { -

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.

+
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.
% $targets = [ ['', '', ''] ]; -oops % } % my $cmpacc = $targets->[0][1]; % my $target = $debit->targetCredit // ''; @@ -103,7 +102,7 @@ oops

Pay with credits

% my $credits = app->db->resultset("Account")->find($account)->available_credits; % if ( $credits->count() ) { -

<%= $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 pay this debit with:

+

<%= $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 pay this debit with:

% while ( my $c = $credits->next ) { @@ -122,6 +121,6 @@ oops % } % } - +

diff --git a/templates/user/login.html.ep b/templates/user/login.html.ep index 8611311..03bcd95 100644 --- a/templates/user/login.html.ep +++ b/templates/user/login.html.ep @@ -12,12 +12,17 @@ % }

- User id:
- Password:
+

+
User id
+
+
Password
+
% if ( my $token = param 'token' ) { - Repeat:
-
+
Repeat
+
+ +
% } - +

-

+
Sdatepurposeto spendnote