X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FBankAccount.pm;h=fba783c73ae9312a99c695d1525c98a3bc08136a;hb=b775c378552e6b5bf59f98046cdf4e577cd351df;hp=c293c6c347384f3d48dccaff552b21d5e6d4f6b7;hpb=4fd22b569d4436293e0a9d364d7356b5bfc503e5;p=kivitendo-erp.git diff --git a/SL/DB/BankAccount.pm b/SL/DB/BankAccount.pm index c293c6c34..fba783c73 100644 --- a/SL/DB/BankAccount.pm +++ b/SL/DB/BankAccount.pm @@ -1,13 +1,51 @@ -# This file has been auto-generated only because it didn't exist. -# Feel free to modify it at will; it will not be overwritten automatically. - package SL::DB::BankAccount; use strict; use SL::DB::MetaSetup::BankAccount; +use SL::DB::Manager::BankAccount; +use SL::DB::Helper::ActsAsList; +use SL::DB::Helper::IBANValidation; + +__PACKAGE__->meta->initialize; + +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; + require SL::DB::Chart; + my $chart = SL::DB::Manager::Chart->find_by( id => $chart_id ); + if ( $chart ) { + 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}; + push @errors, $self->validate_ibans; + + return @errors; +} + +sub displayable_name { + my ($self) = @_; -# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. -__PACKAGE__->meta->make_manager_class; + return join ' ', grep $_, $self->name, $self->bank, $self->iban; +} 1;