X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/77061a7b4a39fe5fedbc1186bf9f048e78627cde..28fee2e2ebc6746bcfeb47c0318e79789ba1c850:/SL/DB/BankAccount.pm diff --git a/SL/DB/BankAccount.pm b/SL/DB/BankAccount.pm index 4ef201b99..9ac755beb 100644 --- a/SL/DB/BankAccount.pm +++ b/SL/DB/BankAccount.pm @@ -6,9 +6,40 @@ package SL::DB::BankAccount; use strict; use SL::DB::MetaSetup::BankAccount; +use SL::DB::Manager::BankAccount; +use SL::DB::Helper::ActsAsList; __PACKAGE__->meta->initialize; -# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. -__PACKAGE__->meta->make_manager_class; + +sub validate { + my ($self) = @_; + + my @errors; + + if ( not $self->{chart_id} ) { + push @errors, $::locale->text('There is no connected chart.'); + } else { + # check whether the assigned chart is valid or is already being used by + # another bank account (there is also a UNIQUE database constraint on + # chart_id) + + my $chart_id = $self->chart_id; + my $chart = SL::DB::Chart->new( id => $chart_id ); + if ( $chart->load(speculative => 1) ) { + my $linked_bank = SL::DB::Manager::BankAccount->find_by( chart_id => $chart_id ); + if ( $linked_bank ) { + if ( not $self->{id} or ( $self->{id} && $linked_bank->id != $self->{id} )) { + push @errors, $::locale->text('The account #1 is already being used by bank account #2.', $chart->displayable_name, $linked_bank->{name}); + }; + }; + } else { + push @errors, $::locale->text('The chart is not valid.'); + }; + }; + + push @errors, $::locale->text('The IBAN is missing.') unless $self->{iban}; + + return @errors; +} 1;