X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/f5c454e3855012bdb1928f3e4c4964403d4d8163..86b6ff8a570d2fdc5fa53ba3dc9b3833e657e2e6:/SL/Controller/Buchungsgruppen.pm diff --git a/SL/Controller/Buchungsgruppen.pm b/SL/Controller/Buchungsgruppen.pm index bbb589383..aac6f73ab 100644 --- a/SL/Controller/Buchungsgruppen.pm +++ b/SL/Controller/Buchungsgruppen.pm @@ -9,13 +9,15 @@ use SL::Helper::Flash; use SL::Locale::String; use SL::DB::TaxzoneChart; use SL::Controller::ClientConfig; +use SL::DB::Default; use Rose::Object::MakeMethods::Generic ( scalar => [ qw(config) ], + 'scalar --get_set_init' => [ qw(defaults) ], ); __PACKAGE__->run_before('check_auth'); -__PACKAGE__->run_before('load_config', only => [ qw(edit update) ]); #destroy +__PACKAGE__->run_before('load_config', only => [ qw(edit update delete) ]); # # actions @@ -25,7 +27,7 @@ sub action_list { my ($self) = @_; my $buchungsgruppen = SL::DB::Manager::Buchungsgruppe->get_all_sorted(); - my $taxzones = SL::DB::Manager::TaxZone->get_all_sorted(); + my $taxzones = SL::DB::Manager::TaxZone->get_all_sorted(query => [ obsolete => 0 ]); my %chartlist = (); foreach my $gruppe (@{ $buchungsgruppen }) { @@ -59,6 +61,11 @@ sub show_form { sub action_edit { my ($self) = @_; + # Allow editing of the charts of the Buchungsgruppe if it isn't assigned to + # any parts. This is checked inside the template via the Buchungsgruppen + # orphaned method, where an IF-ELSE statement toggles between L.select_tag + # and text. + $self->show_form(title => t8('Edit Buchungsgruppe'), CHARTLIST => SL::DB::TaxzoneChart->get_all_accounts_by_buchungsgruppen_id($self->config->id)); } @@ -75,6 +82,24 @@ sub action_update { $self->create_or_update; } +sub action_delete { + my ($self) = @_; + + # allow deletion of unused Buchungsgruppen. Will fail, due to database + # constraint, if Buchungsgruppe is connected to a part + + my $db = $self->{config}->db; + $db->do_transaction(sub { + my $taxzone_charts = SL::DB::Manager::TaxzoneChart->get_all(where => [ buchungsgruppen_id => $self->config->id ]); + foreach my $taxzonechart ( @{$taxzone_charts} ) { $taxzonechart->delete }; + $self->config->delete(); + flash_later('info', $::locale->text('The buchungsgruppe has been deleted.')); + }) || flash_later('error', $::locale->text('The buchungsgruppe is in use and cannot be deleted.')); + + $self->redirect_to(action => 'list'); + +} + sub action_reorder { my ($self) = @_; @@ -120,8 +145,8 @@ sub create_or_update { $self->config->save; - #Save taxzone_charts: - if ($is_new) { + # Save or update taxzone_charts for new or unused Buchungsgruppen + if ($is_new or $self->config->orphaned) { my $taxzones = SL::DB::Manager::TaxZone->get_all_sorted(); foreach my $tz (@{ $taxzones }) { @@ -138,4 +163,10 @@ sub create_or_update { $self->redirect_to(action => 'list'); } +# +# initializers +# + +sub init_defaults { SL::DB::Default->get } + 1;