Revision bdc944ea
Von Kivitendo Admin vor mehr als 9 Jahren hinzugefügt
SL/Controller/Taxzones.pm | ||
---|---|---|
4 | 4 |
|
5 | 5 |
use parent qw(SL::Controller::Base); |
6 | 6 |
|
7 |
#use List::Util qw(first); |
|
8 |
|
|
9 | 7 |
use SL::DB::TaxZone; |
10 | 8 |
use SL::Helper::Flash; |
11 | 9 |
use SL::Locale::String; |
... | ... | |
18 | 16 |
); |
19 | 17 |
|
20 | 18 |
__PACKAGE__->run_before('check_auth'); |
21 |
__PACKAGE__->run_before('load_config', only => [ qw(edit update) ]); #destroy
|
|
19 |
__PACKAGE__->run_before('load_config', only => [ qw(edit update delete) ]);
|
|
22 | 20 |
|
23 | 21 |
# |
24 | 22 |
# actions |
... | ... | |
29 | 27 |
|
30 | 28 |
my $taxzones = SL::DB::Manager::TaxZone->get_all_sorted(); |
31 | 29 |
|
32 |
$::form->header; |
|
33 | 30 |
$self->render('taxzones/list', |
34 | 31 |
title => t8('List of tax zones'), |
35 | 32 |
TAXZONES => $taxzones); |
... | ... | |
69 | 66 |
$self->create_or_update; |
70 | 67 |
} |
71 | 68 |
|
69 |
sub action_delete { |
|
70 |
my ($self) = @_; |
|
71 |
|
|
72 |
# allow deletion of unused tax zones. Will fail, due to database |
|
73 |
# constraints, if tax zone is used anywhere |
|
74 |
|
|
75 |
my $db = $self->{config}->db; |
|
76 |
$db->do_transaction(sub { |
|
77 |
my $taxzone_charts = SL::DB::Manager::TaxzoneChart->get_all(where => [ taxzone_id => $self->config->id ]); |
|
78 |
foreach my $taxzonechart ( @{$taxzone_charts} ) { $taxzonechart->delete }; |
|
79 |
$self->config->delete(); |
|
80 |
flash_later('info', $::locale->text('The tax zone has been deleted.')); |
|
81 |
}) || flash_later('error', $::locale->text('The tax zone is in use and cannot be deleted.')); |
|
82 |
|
|
83 |
$self->redirect_to(action => 'list'); |
|
84 |
|
|
85 |
} |
|
86 |
|
|
72 | 87 |
sub action_reorder { |
73 | 88 |
my ($self) = @_; |
74 | 89 |
|
... | ... | |
100 | 115 |
my $is_new = !$self->config->id; |
101 | 116 |
|
102 | 117 |
my $params = delete($::form->{config}) || { }; |
118 |
|
|
103 | 119 |
delete $params->{id}; |
104 | 120 |
|
105 |
$self->config->assign_attributes(%{ $params }); |
|
121 |
my @errors; |
|
122 |
|
|
123 |
my $db = $self->config->db; |
|
124 |
$db->do_transaction( sub { |
|
125 |
|
|
126 |
# always allow editing of description and obsolete |
|
127 |
$self->config->assign_attributes( %{$params} ) ; |
|
128 |
|
|
129 |
push(@errors, $self->config->validate); # check for description |
|
130 |
|
|
131 |
if (@errors) { |
|
132 |
die @errors . "\n"; |
|
133 |
}; |
|
106 | 134 |
|
107 |
my @errors = $self->config->validate;
|
|
135 |
$self->config->save;
|
|
108 | 136 |
|
109 |
if (@errors) { |
|
110 |
flash('error', @errors); |
|
111 |
$self->show_form(title => $is_new ? t8('Add taxzone') : t8('Edit taxzone')); |
|
112 |
return; |
|
113 |
} |
|
137 |
if ( $is_new or $self->config->orphaned ) { |
|
138 |
# Save taxzone_charts |
|
139 |
my $buchungsgruppen = SL::DB::Manager::Buchungsgruppe->get_all_sorted(); |
|
114 | 140 |
|
115 |
$self->config->save; |
|
116 |
$self->config->obsolete($::form->{"obsolete"}); |
|
141 |
foreach my $bg (@{ $buchungsgruppen }) { |
|
142 |
my $income_accno_id = $::form->{"income_accno_id_" . $bg->id}; |
|
143 |
my $expense_accno_id = $::form->{"expense_accno_id_" . $bg->id}; |
|
117 | 144 |
|
118 |
#Save taxzone_charts for new taxzones:
|
|
119 |
if ($is_new) {
|
|
120 |
my $buchungsgruppen = SL::DB::Manager::Buchungsgruppe->get_all_sorted();
|
|
145 |
my ($income_accno, $expense_accno);
|
|
146 |
$income_accno = SL::DB::Manager::Chart->find_by( id => $income_accno_id ) if $income_accno_id;
|
|
147 |
$expense_accno = SL::DB::Manager::Chart->find_by( id => $expense_accno_id ) if $expense_accno_id;
|
|
121 | 148 |
|
122 |
foreach my $bg (@{ $buchungsgruppen }) {
|
|
123 |
my $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by_or_create(buchungsgruppen_id => $bg->id, taxzone_id => $self->config->id);
|
|
149 |
push(@errors, t8('Buchungsgruppe #1 needs a valid income account' , $bg->description)) unless $income_accno;
|
|
150 |
push(@errors, t8('Buchungsgruppe #1 needs a valid expense account', $bg->description)) unless $expense_accno;
|
|
124 | 151 |
|
125 |
$taxzone_chart->taxzone_id($self->config->id); |
|
126 |
$taxzone_chart->buchungsgruppen_id($bg->id); |
|
127 |
$taxzone_chart->income_accno_id($::form->{"income_accno_id_" . $bg->id}); |
|
128 |
$taxzone_chart->expense_accno_id($::form->{"expense_accno_id_" . $bg->id}); |
|
129 |
$taxzone_chart->save; |
|
152 |
my $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by_or_create(buchungsgruppen_id => $bg->id, taxzone_id => $self->config->id); |
|
153 |
# if taxzonechart doesn't exist an empty new TaxzoneChart object is |
|
154 |
# created by find_by_or_create, so we have to assign buchungsgruppe and |
|
155 |
# taxzone again for the new case to work |
|
156 |
$taxzone_chart->taxzone_id($self->config->id); |
|
157 |
$taxzone_chart->buchungsgruppen_id($bg->id); |
|
158 |
$taxzone_chart->income_accno_id($income_accno->id); |
|
159 |
$taxzone_chart->expense_accno_id($expense_accno->id); |
|
160 |
$taxzone_chart->save; |
|
161 |
} |
|
130 | 162 |
} |
131 |
} |
|
163 |
} ) || die @errors ? join("\n", @errors) . "\n" : $db->error . "\n"; |
|
164 |
# die with rollback of taxzone save if saving of any of the taxzone_charts fails |
|
165 |
# only show the $db->error if we haven't already identified the likely error ourselves |
|
132 | 166 |
|
133 | 167 |
flash_later('info', $is_new ? t8('The taxzone has been created.') : t8('The taxzone has been saved.')); |
134 | 168 |
$self->redirect_to(action => 'list'); |
SL/DB/TaxZone.pm | ||
---|---|---|
23 | 23 |
return @errors; |
24 | 24 |
} |
25 | 25 |
|
26 |
sub orphaned { |
|
27 |
my ($self) = @_; |
|
28 |
die 'not an accessor' if @_ > 1; |
|
29 |
|
|
30 |
my @classes = qw(Customer Vendor Invoice Order DeliveryOrder PurchaseInvoice); |
|
31 |
foreach my $class ( @classes ) { |
|
32 |
my $module = 'SL::DB::' . $class; |
|
33 |
eval "require $module"; |
|
34 |
my $manager = 'SL::DB::Manager::' . $class; |
|
35 |
return 0 if $manager->get_all_count( query => [ taxzone_id => $self->id ] ); |
|
36 |
}; |
|
37 |
return 1; |
|
38 |
} |
|
39 |
|
|
26 | 40 |
1; |
locale/de/all | ||
---|---|---|
416 | 416 |
'Break up the update and contact a service provider.' => 'Diese Option bricht das Update ab. Bitte kontaktieren Sie Ihren Administrator oder beauftragen einen Dienstleister.', |
417 | 417 |
'Buchungsdatum' => 'Buchungsdatum', |
418 | 418 |
'Buchungsgruppe' => 'Buchungsgruppe', |
419 |
'Buchungsgruppe #1 needs a valid expense account' => 'Buchungsgruppe #1 braucht ein gültiges Aufwandskonto', |
|
420 |
'Buchungsgruppe #1 needs a valid income account' => 'Buchungsgruppe #1 braucht ein gültiges Erfolgskonto', |
|
419 | 421 |
'Buchungsgruppe (database ID)' => 'Buchungsgruppe (Datenbank-ID)', |
420 | 422 |
'Buchungsgruppe (name)' => 'Buchungsgruppe (Name)', |
421 | 423 |
'Buchungsgruppen' => 'Buchungsgruppen', |
... | ... | |
2807 | 2809 |
'The task server is not running.' => 'Der Task-Server läuft nicht.', |
2808 | 2810 |
'The task server was started successfully.' => 'Der Task-Server wurde erfolgreich gestartet.', |
2809 | 2811 |
'The task server was stopped successfully.' => 'Der Task-Server wurde erfolgreich beendet.', |
2812 |
'The tax zone has been deleted.' => 'Die Steuerzone wurde gelöscht.', |
|
2813 |
'The tax zone is in use and cannot be deleted.' => 'Die Steuerzone wird benutzt und kann nicht gelöscht werden', |
|
2810 | 2814 |
'The taxzone has been created.' => 'Die Steuerzone wurde erstellt.', |
2811 | 2815 |
'The taxzone has been saved.' => 'Die Steuerzone wurde gespeichert.', |
2812 | 2816 |
'The third way is to download the module from the above mentioned URL and to install the module manually following the installations instructions contained in the source archive.' => 'Die dritte Variante besteht darin, das Paket von der oben genannten URL herunterzuladen und es manuell zu installieren. Beachten Sie dabei die im Paket enthaltenen Installationsanweisungen.', |
templates/webpages/taxzones/form.html | ||
---|---|---|
12 | 12 |
[%- FOREACH bg = BUCHUNGSGRUPPEN %] |
13 | 13 |
<tr> |
14 | 14 |
<th align="right">[% 'Revenue' | $T8 %] [% HTML.escape(bg.description) %]</th> |
15 |
[%- IF SELF.config.id %] |
|
16 |
<td>[% CHARTLIST.${bg.id}.income_accno %] -- [% CHARTLIST.${bg.id}.income_accno_description %]</td> |
|
17 |
[%- ELSE %] |
|
15 |
[%- IF NOT SELF.config.id %] |
|
18 | 16 |
<td>[% L.chart_picker('income_accno_id_' _ bg.id, SELF.defaults.income_accno_id, choose=1, type='IC_income,IC_sale', style=style) %]</td> |
17 |
[%- ELSIF SELF.config.id AND SELF.config.orphaned %] |
|
18 |
<td>[% L.chart_picker('income_accno_id_' _ bg.id, CHARTLIST.${bg.id}.income_accno_id, choose=1, type='IC_income,IC_sale', style=style) %]</td> |
|
19 |
[%- ELSE %] |
|
20 |
<td>[% CHARTLIST.${bg.id}.income_accno %] -- [% CHARTLIST.${bg.id}.income_accno_description %]</td> |
|
19 | 21 |
[%- END %] |
20 | 22 |
</tr> |
21 | 23 |
<tr> |
22 | 24 |
<th align="right">[% 'Expense' | $T8 %] [% HTML.escape(bg.description) %]</th> |
23 |
[%- IF SELF.config.id %] |
|
24 |
<td>[% CHARTLIST.${bg.id}.expense_accno %] -- [% CHARTLIST.${bg.id}.expense_accno_description %]</td> |
|
25 |
[%- ELSE %] |
|
25 |
[%- IF NOT SELF.config.id %] |
|
26 | 26 |
<td>[% L.chart_picker('expense_accno_id_' _ bg.id, SELF.defaults.expense_accno_id, choose=1, type='IC_expense,IC_cogs', style=style) %]</td> |
27 |
[%- ELSIF SELF.config.id AND SELF.config.orphaned %] |
|
28 |
<td>[% L.chart_picker('expense_accno_id_' _ bg.id, CHARTLIST.${bg.id}.expense_accno_id, choose=1, type='IC_expense,IC_cogs', style=style) %]</td> |
|
29 |
[%- ELSE %] |
|
30 |
<td>[% CHARTLIST.${bg.id}.expense_accno %] -- [% CHARTLIST.${bg.id}.expense_accno_description %]</td> |
|
27 | 31 |
[%- END %] |
28 | 32 |
</tr> |
29 | 33 |
[%- END %] |
... | ... | |
34 | 38 |
<p> |
35 | 39 |
[% L.hidden_tag("action", "Taxzones/dispatch") %] |
36 | 40 |
[% L.submit_tag("action_" _ (SELF.config.id ? "update" : "create"), LxERP.t8('Save'), onclick="return check_prerequisites();") %] |
41 |
[%- IF SELF.config.id AND SELF.config.orphaned %] |
|
42 |
[% L.submit_tag("action_delete", LxERP.t8('Delete'), confirm=LxERP.t8('Are you sure?')) %] |
|
43 |
[%- END %] |
|
37 | 44 |
<a href="[% SELF.url_for(action='list') %]">[%- LxERP.t8("Cancel") %]</a> |
38 | 45 |
</p> |
39 | 46 |
|
Auch abrufbar als: Unified diff
Steuerzonen überarbeitet - Prüfung und Löschen
Nicht benutzte Steuerzonen können jetzt gelöscht werden, sowie deren
Kontenzuordnungen geändert werden (wie bei Buchungsgruppen). Siehe
Feature #70.
Schlägt die Speicherung neuer Steuerzonen fehl, weil z.B. die
Buchungsgruppenkonten fehlen, gibt es nun einen Rollback und eine
ordentliche Fehlermeldung, siehe Fehler #68.