X-Git-Url: http://wagnertech.de/git?p=kivitendo-erp.git;a=blobdiff_plain;f=SL%2FController%2FBankAccount.pm;fp=SL%2FController%2FBankAccount.pm;h=0000000000000000000000000000000000000000;hp=dff431282199568d95a7a20dda8233ce4a62d919;hb=53593baa211863fbf66540cf1bcc36c8fb37257f;hpb=deb4d2dbb676d7d6f69dfe7815d6e0cb09bd4a44 diff --git a/SL/Controller/BankAccount.pm b/SL/Controller/BankAccount.pm deleted file mode 100644 index dff431282..000000000 --- a/SL/Controller/BankAccount.pm +++ /dev/null @@ -1,122 +0,0 @@ -package SL::Controller::BankAccount; - -use strict; - -use parent qw(SL::Controller::Base); - -use SL::Helper::Flash; -use SL::Locale::String; -use SL::DB::Default; -use SL::DB::Manager::BankAccount; -use SL::DB::Manager::BankTransaction; - -use Rose::Object::MakeMethods::Generic ( - scalar => [ qw(bank_account) ], -); - -__PACKAGE__->run_before('check_auth'); -__PACKAGE__->run_before('load_bank_account', only => [ qw(edit update delete) ]); - -# -# actions -# - -sub action_list { - my ($self) = @_; - - $self->render('bankaccounts/list', - title => t8('Bank accounts'), - BANKACCOUNTS => SL::DB::Manager::BankAccount->get_all_sorted, - ); -} - -sub action_new { - my ($self) = @_; - - $self->{bank_account} = SL::DB::BankAccount->new; - $self->render('bankaccounts/form', - title => t8('Add bank account')); -} - -sub action_edit { - my ($self) = @_; - - $self->render('bankaccounts/form', title => t8('Edit bank account')); -} - -sub action_create { - my ($self) = @_; - - $self->{bank_account} = SL::DB::BankAccount->new; - $self->create_or_update; -} - -sub action_update { - my ($self) = @_; - $self->create_or_update; -} - -sub action_delete { - my ($self) = @_; - - if ( $self->{bank_account}->{number_of_bank_transactions} > 0 ) { - flash_later('error', $::locale->text('The bank account has been used and cannot be deleted.')); - } elsif ( eval { $self->{bank_account}->delete; 1; } ) { - flash_later('info', $::locale->text('The bank account has been deleted.')); - } else { - flash_later('error', $::locale->text('The bank account has been used and cannot be deleted.')); - }; - $self->redirect_to(action => 'list'); - -} - -sub action_reorder { - my ($self) = @_; - - SL::DB::BankAccount->reorder_list(@{ $::form->{account_id} || [] }); - $self->render(\'', { type => 'json' }); -} - -# -# filters -# - -sub check_auth { - $::auth->assert('config'); -} - -sub load_bank_account { - my ($self) = @_; - - $self->{bank_account} = SL::DB::BankAccount->new(id => $::form->{id})->load; - $self->{bank_account}->{number_of_bank_transactions} = SL::DB::Manager::BankTransaction->get_all_count( query => [ local_bank_account_id => $self->{bank_account}->{id} ] ); -} - -# -# helpers -# - -sub create_or_update { - my ($self) = @_; - my $is_new = !$self->{bank_account}->id; - - my $params = delete($::form->{bank_account}) || { }; - - $self->{bank_account}->assign_attributes(%{ $params }); - - my @errors = $self->{bank_account}->validate; - - if (@errors) { - flash('error', @errors); - $self->render('bankaccounts/form', - title => $is_new ? t8('Add bank account') : t8('Edit bank account')); - return; - } - - $self->{bank_account}->save; - - flash_later('info', $is_new ? t8('The bank account has been created.') : t8('The bank account has been saved.')); - $self->redirect_to(action => 'list'); -} - -1;