X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=inline;f=SL%2FController%2FBuchungsgruppen.pm;h=aac6f73ab76b4cd40d0c202e58fd6e8535279a86;hb=89360aadb2c3e0854a2815e5d0ed8a9efd1c5889;hp=f3f07d58ad44fc1ff33333e8747179c903be49e2;hpb=6e6038682b1a2b6e6bc74f1eee40eba21afcb7e9;p=kivitendo-erp.git diff --git a/SL/Controller/Buchungsgruppen.pm b/SL/Controller/Buchungsgruppen.pm index f3f07d58a..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 @@ -59,11 +61,12 @@ sub show_form { sub action_edit { my ($self) = @_; - # check whether buchungsgruppe is assigned to any parts - my $number_of_parts_with_buchungsgruppe = SL::DB::Manager::Part->get_objects_count(where => [ buchungsgruppen_id => $self->config->id]); + # 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'), - linked_parts => $number_of_parts_with_buchungsgruppe, CHARTLIST => SL::DB::TaxzoneChart->get_all_accounts_by_buchungsgruppen_id($self->config->id)); } @@ -79,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) = @_; @@ -124,11 +145,8 @@ sub create_or_update { $self->config->save; - # check whether there are any assigned parts - my $number_of_parts_with_buchungsgruppe = SL::DB::Manager::Part->get_objects_count(where => [ buchungsgruppen_id => $self->config->id]); - - # Save or update taxzone_charts: - if ($is_new or $number_of_parts_with_buchungsgruppe == 0) { + # 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 }) { @@ -145,4 +163,10 @@ sub create_or_update { $self->redirect_to(action => 'list'); } +# +# initializers +# + +sub init_defaults { SL::DB::Default->get } + 1;