1 package SL::DB::BankAccount;
 
   5 use SL::DB::MetaSetup::BankAccount;
 
   6 use SL::DB::Manager::BankAccount;
 
   7 use SL::DB::Helper::ActsAsList;
 
   8 use SL::DB::Helper::IBANValidation;
 
  10 __PACKAGE__->meta->initialize;
 
  17   if ( not $self->{chart_id} ) {
 
  18     push @errors, $::locale->text('There is no connected chart.');
 
  20     # check whether the assigned chart is valid or is already being used by
 
  21     # another bank account (there is also a UNIQUE database constraint on
 
  24     my $chart_id = $self->chart_id;
 
  25     require SL::DB::Chart;
 
  26     my $chart = SL::DB::Manager::Chart->find_by( id => $chart_id );
 
  28       my $linked_bank = SL::DB::Manager::BankAccount->find_by( chart_id => $chart_id );
 
  30         if ( not $self->{id} or ( $self->{id} && $linked_bank->id != $self->{id} )) {
 
  31           push @errors, $::locale->text('The account #1 is already being used by bank account #2.', $chart->displayable_name, $linked_bank->{name});
 
  35       push @errors, $::locale->text('The chart is not valid.');
 
  39   push @errors, $::locale->text('The IBAN is missing.') unless $self->{iban};
 
  40   push @errors, $self->validate_ibans;
 
  45 sub displayable_name {
 
  48   return join ' ', grep $_, $self->name, $self->bank, $self->iban;