Revision a28a585e
Von Kivitendo Admin vor mehr als 9 Jahren hinzugefügt
SL/Controller/Buchungsgruppen.pm | ||
---|---|---|
130 | 130 |
my $params = delete($::form->{config}) || { }; |
131 | 131 |
delete $params->{id}; |
132 | 132 |
|
133 |
$self->config->assign_attributes(%{ $params });
|
|
133 |
my @errors;
|
|
134 | 134 |
|
135 |
my @errors = $self->config->validate; |
|
135 |
my $db = $self->config->db; |
|
136 |
$db->do_transaction( sub { |
|
136 | 137 |
|
137 |
if (@errors) { |
|
138 |
flash('error', @errors); |
|
139 |
$self->show_form(title => $is_new ? t8('Add taxzone') : t8('Edit taxzone')); |
|
140 |
return; |
|
141 |
} |
|
138 |
$self->config->assign_attributes(%{ $params }); # assign description and inventory_accno_id |
|
139 |
|
|
140 |
@errors = $self->config->validate; # check for description and inventory_accno_id |
|
141 |
|
|
142 |
if (@errors) { |
|
143 |
die "foo" . @errors . "\n"; |
|
144 |
}; |
|
145 |
|
|
146 |
$self->config->save; |
|
142 | 147 |
|
143 |
$self->config->save; |
|
148 |
# Save or update taxzone_charts for new or unused Buchungsgruppen |
|
149 |
if ($is_new or $self->config->orphaned) { |
|
150 |
my $taxzones = SL::DB::Manager::TaxZone->get_all_sorted(); |
|
144 | 151 |
|
145 |
# Save or update taxzone_charts for new or unused Buchungsgruppen |
|
146 |
if ($is_new or $self->config->orphaned) { |
|
147 |
my $taxzones = SL::DB::Manager::TaxZone->get_all_sorted(); |
|
152 |
foreach my $tz (@{ $taxzones }) { |
|
148 | 153 |
|
149 |
foreach my $tz (@{ $taxzones }) { |
|
150 |
my $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by_or_create(buchungsgruppen_id => $self->config->id, taxzone_id => $tz->id); |
|
151 |
$taxzone_chart->taxzone_id($tz->id); |
|
152 |
$taxzone_chart->buchungsgruppen_id($self->config->id); |
|
153 |
$taxzone_chart->income_accno_id($::form->{"income_accno_id_" . $tz->id}); |
|
154 |
$taxzone_chart->expense_accno_id($::form->{"expense_accno_id_" . $tz->id}); |
|
155 |
$taxzone_chart->save; |
|
154 |
my $income_accno_id = $::form->{"income_accno_id_" . $tz->id}; |
|
155 |
my $expense_accno_id = $::form->{"expense_accno_id_" . $tz->id}; |
|
156 |
|
|
157 |
my ($income_accno, $expense_accno); |
|
158 |
$income_accno = SL::DB::Manager::Chart->find_by( id => $income_accno_id ) if $income_accno_id; |
|
159 |
$expense_accno = SL::DB::Manager::Chart->find_by( id => $expense_accno_id ) if $expense_accno_id; |
|
160 |
|
|
161 |
push(@errors, t8('Tax zone #1 needs a valid income account' , $tz->description)) unless $income_accno; |
|
162 |
push(@errors, t8('Tax zone #1 needs a valid expense account' , $tz->description)) unless $expense_accno; |
|
163 |
|
|
164 |
my $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by_or_create(buchungsgruppen_id => $self->config->id, taxzone_id => $tz->id); |
|
165 |
$taxzone_chart->taxzone_id($tz->id); |
|
166 |
$taxzone_chart->buchungsgruppen_id($self->config->id); |
|
167 |
$taxzone_chart->income_accno_id($income_accno->id); |
|
168 |
$taxzone_chart->expense_accno_id($expense_accno->id); |
|
169 |
$taxzone_chart->save; |
|
170 |
} |
|
156 | 171 |
} |
157 |
} |
|
172 |
} ) || die @errors ? join("\n", @errors) . "\n" : $db->error . "\n"; |
|
173 |
# die with rollback of taxzone save if saving of any of the taxzone_charts fails |
|
174 |
# only show the $db->error if we haven't already identified the likely error ourselves |
|
158 | 175 |
|
159 | 176 |
flash_later('info', $is_new ? t8('The Buchungsgruppe has been created.') : t8('The Buchungsgruppe has been saved.')); |
160 | 177 |
$self->redirect_to(action => 'list'); |
Auch abrufbar als: Unified diff
Überarbeitung Speichern von Buchungsgruppen
analog zum Verhalten von Steuerzonen: beim Speichern bessere Prüfung und
gegebenenfalls Fehlermeldungen und Rollback, wenn Speichern fehlschlägt.
Verhindert, daß "unfertige" Buchungsgruppen gespeichert werden, wo die
TaxzoneCharts fehlen.