From: G. Richardson Date: Sun, 3 Aug 2014 23:26:14 +0000 (+0200) Subject: Buchungsgruppen - löschen und beim Erstellen Standardkonten benutzen X-Git-Tag: release-3.2.0beta~370 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=058d70b8ae5406a40ce5ddba2d11cc8563d06751;p=kivitendo-erp.git Buchungsgruppen - löschen und beim Erstellen Standardkonten benutzen Wenn eine Buchungsgruppe noch nicht einer Waren zugeordnet ist kann diese noch bearbeitet (Kontenzuordnung) oder gelöscht werden. Beim neu Erstellen von Buchungsgruppen werden die Standardkonten aus der Mandantenkonfiguration (Erlös/Aufwand/Bestand) vorausgewählt. --- diff --git a/SL/Controller/Buchungsgruppen.pm b/SL/Controller/Buchungsgruppen.pm index f3f07d58a..3ecba1369 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,7 +61,10 @@ sub show_form { sub action_edit { my ($self) = @_; - # check whether buchungsgruppe is assigned to any parts + # Allow editing of Buchungsgruppe if it isn't assigned to any parts. The + # variable is checked in the template, which toggles between L.select_tag and + # text. + my $number_of_parts_with_buchungsgruppe = SL::DB::Manager::Part->get_objects_count(where => [ buchungsgruppen_id => $self->config->id]); $self->show_form(title => t8('Edit Buchungsgruppe'), @@ -79,6 +84,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) = @_; @@ -145,4 +168,10 @@ sub create_or_update { $self->redirect_to(action => 'list'); } +# +# initializers +# + +sub init_defaults { SL::DB::Default->get } + 1; diff --git a/templates/webpages/buchungsgruppen/form.html b/templates/webpages/buchungsgruppen/form.html index 88c19f320..9fe2fd9db 100644 --- a/templates/webpages/buchungsgruppen/form.html +++ b/templates/webpages/buchungsgruppen/form.html @@ -1,4 +1,6 @@ -[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE T8 -%]

[% HTML.escape(title) %]

+[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE T8 -%] + +

[% HTML.escape(title) %]

[%- L.hidden_tag("id", SELF.config.id) %] @@ -12,6 +14,8 @@ [% 'Inventory account' | $T8 %] [%- IF SELF.config.id AND linked_parts != 0 %] [%- CHARTLIST.inventory_accno %] -- [%- CHARTLIST.inventory_accno_description %] + [%- ELSIF NOT SELF.config.id AND linked_parts != 0 %] + [%- L.select_tag("config.inventory_accno_id", ACCOUNTS.ic, title_sub=\account_label, default=SELF.defaults.inventory_accno_id) %] [%- ELSE %] [%- L.select_tag("config.inventory_accno_id", ACCOUNTS.ic, title_sub=\account_label, default=SELF.config.inventory_accno_id) %] [%- END %] @@ -21,6 +25,8 @@ [% 'Revenue' | $T8 %] [% HTML.escape(tz.description) %] [%- IF SELF.config.id AND linked_parts != 0 %] [% CHARTLIST.${tz.id}.income_accno %] -- [% CHARTLIST.${tz.id}.income_accno_description %] + [%- ELSIF NOT SELF.config.id AND linked_parts != 0 %] + [%- L.select_tag('income_accno_id_' _ tz.id, ACCOUNTS.ic_income, title_sub=\account_label, default=SELF.defaults.income_accno_id) %] [%- ELSE %] [%- L.select_tag('income_accno_id_' _ tz.id, ACCOUNTS.ic_income, title_sub=\account_label, default=CHARTLIST.${tz.id}.income_accno_id) %] [%- END %] @@ -29,6 +35,8 @@ [% 'Expense' | $T8 %] [% HTML.escape(tz.description) %] [%- IF SELF.config.id AND linked_parts != 0 %] [% CHARTLIST.${tz.id}.expense_accno %] -- [% CHARTLIST.${tz.id}.expense_accno_description %] + [%- ELSIF NOT SELF.config.id AND linked_parts != 0 %] + [%- L.select_tag('expense_accno_id_' _ tz.id, ACCOUNTS.ic_expense, title_sub=\account_label, default=SELF.defaults.expense_accno_id) %] [%- ELSE %] [%- L.select_tag('expense_accno_id_' _ tz.id, ACCOUNTS.ic_expense, title_sub=\account_label, default=CHARTLIST.${tz.id}.expense_accno_id) %] [%- END %] @@ -39,7 +47,9 @@

[% L.hidden_tag("action", "Buchungsgruppen/dispatch") %] [% L.submit_tag("action_" _ (SELF.config.id ? "update" : "create"), LxERP.t8('Save'), onclick="return check_prerequisites();") %] - [%- LxERP.t8("Cancel") %] + [%- IF SELF.config.id AND linked_parts == 0 %] + [% L.submit_tag("action_delete", LxERP.t8('Delete'), confirm=LxERP.t8('Are you sure?')) %] + [%- END %]


diff --git a/templates/webpages/buchungsgruppen/list.html b/templates/webpages/buchungsgruppen/list.html index 799814383..ba80499fe 100644 --- a/templates/webpages/buchungsgruppen/list.html +++ b/templates/webpages/buchungsgruppen/list.html @@ -8,7 +8,7 @@ [ LxERP.t8('reorder item') %] [% 'Description' | $T8 %] - [% 'Inventory' | $T8 %] + [% 'Inventory account' | $T8 %] [%- FOREACH tz = TAXZONES %] [% 'Revenue' | $T8 %] [% HTML.escape(tz.description) %] [% 'Expense' | $T8 %] [% HTML.escape(tz.description) %]