Revision 50944367
Von Bernd Bleßmann vor mehr als 4 Jahren hinzugefügt
SL/Controller/CsvImport/ARTransaction.pm | ||
---|---|---|
160 | 160 |
|
161 | 161 |
my $i = 0; |
162 | 162 |
my $num_data = scalar @{ $self->controller->data }; |
163 |
my $invoice_entry; |
|
163 | 164 |
|
164 | 165 |
foreach my $entry (@{ $self->controller->data }) { |
165 | 166 |
$self->controller->track_progress(progress => $i/$num_data * 100) if $i % 100 == 0; |
166 | 167 |
|
167 | 168 |
if ($entry->{raw_data}->{datatype} eq $self->_ar_column) { |
168 | 169 |
$self->handle_invoice($entry); |
170 |
$invoice_entry = $entry; |
|
169 | 171 |
} elsif ($entry->{raw_data}->{datatype} eq $self->_transaction_column ) { |
170 |
$self->handle_transaction($entry); |
|
172 |
die "Cannot process transaction row without an invoice row" if !$invoice_entry; |
|
173 |
$self->handle_transaction($entry, $invoice_entry); |
|
171 | 174 |
} else { |
172 | 175 |
die "unknown datatype"; |
173 | 176 |
}; |
... | ... | |
288 | 291 |
} |
289 | 292 |
|
290 | 293 |
sub check_taxkey { |
291 |
my ($self, $entry, $chart) = @_; |
|
294 |
my ($self, $entry, $invoice_entry, $chart) = @_;
|
|
292 | 295 |
|
293 | 296 |
die "check_taxkey needs chart object as an argument" unless ref($chart) eq 'SL::DB::Chart'; |
294 | 297 |
# problem: taxkey is not unique in table tax, normally one of those entries is chosen directly from a dropdown |
295 | 298 |
# so we check if the chart has an active taxkey, and if it matches the taxkey from the import, use the active taxkey |
296 | 299 |
# if the chart doesn't have an active taxkey, use the first entry from Tax that matches the taxkey |
297 | 300 |
|
298 |
my $object = $entry->{object}; |
|
301 |
my $object = $entry->{object}; |
|
302 |
my $invoice_object = $invoice_entry->{object}; |
|
303 |
|
|
299 | 304 |
unless ( defined $entry->{raw_data}->{taxkey} ) { |
300 | 305 |
push @{ $entry->{errors} }, $::locale->text('Error: taxkey missing'); # don't just assume 0, force taxkey in import |
301 | 306 |
return 0; |
302 | 307 |
}; |
303 | 308 |
|
304 |
my $tax; |
|
305 |
|
|
306 |
if ( $entry->{raw_data}->{taxkey} == $chart->get_active_taxkey->tax->taxkey ) { |
|
307 |
$tax = $chart->get_active_taxkey->tax; |
|
308 |
} else { |
|
309 |
my $tax = $chart->get_active_taxkey($invoice_object->deliverydate // $invoice_object->transdate // DateTime->today_local)->tax; |
|
310 |
if ( $entry->{raw_data}->{taxkey} != $tax->taxkey ) { |
|
309 | 311 |
# assume there is only one tax entry with that taxkey, can't guess |
310 | 312 |
$tax = SL::DB::Manager::Tax->get_first( where => [ taxkey => $entry->{raw_data}->{taxkey} ]); |
311 | 313 |
}; |
... | ... | |
340 | 342 |
}; |
341 | 343 |
|
342 | 344 |
sub handle_transaction { |
343 |
my ($self, $entry) = @_; |
|
345 |
my ($self, $entry, $invoice_entry) = @_;
|
|
344 | 346 |
|
345 | 347 |
# Prepare acc_trans data. amount is dealt with in add_transactions_to_ar |
346 | 348 |
|
... | ... | |
355 | 357 |
return 0; |
356 | 358 |
}; |
357 | 359 |
|
358 |
if ( $self->check_taxkey($entry, $chart_obj) ) { |
|
360 |
if ( $self->check_taxkey($entry, $invoice_entry, $chart_obj) ) {
|
|
359 | 361 |
# do nothing, taxkey was assigned, just continue |
360 | 362 |
} else { |
361 | 363 |
# missing taxkey, don't do anything |
Auch abrufbar als: Unified diff
CSV-Import Debitorenbuchungen: Lieferdatum bei Steuerermittlung berücksichtigen