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);