X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FDB%2FHelper%2FPriceTaxCalculator.pm;h=bde711a797a97fc0a3995566a7701e61686bc34e;hb=53593baa211863fbf66540cf1bcc36c8fb37257f;hp=f5bc61c4a78b06887ab9b4615837d0bb4e43d51f;hpb=d04f241a1cc93b3917f375731fdc0bef608beeb7;p=kivitendo-erp.git diff --git a/SL/DB/Helper/PriceTaxCalculator.pm b/SL/DB/Helper/PriceTaxCalculator.pm index f5bc61c4a..bde711a79 100644 --- a/SL/DB/Helper/PriceTaxCalculator.pm +++ b/SL/DB/Helper/PriceTaxCalculator.pm @@ -44,7 +44,8 @@ sub calculate_prices_and_taxes { # set exchangerate in $data>{exchangerate} if ( ref($self) eq 'SL::DB::Order' ) { # orders store amount in the order currency - $data{exchangerate} = 1; + $data{exchangerate} = 1; + $data{allow_optional_items} = 1; } else { # invoices store amount in the default currency _get_exchangerate($self, \%data, %params); @@ -54,7 +55,7 @@ sub calculate_prices_and_taxes { $self->netamount( 0); $self->marge_total(0); - SL::DB::Manager::Chart->cache_taxkeys(date => $self->deliverydate // $self->transdate); + SL::DB::Manager::Chart->cache_taxkeys(date => $self->effective_tax_point); my $idx = 0; foreach my $item (@{ $self->items_sorted }) { @@ -110,7 +111,7 @@ sub _calculate_item { $data->{invoicediff} += $sellprice * (1 - $item->discount) * $item->qty * $data->{exchangerate} / $item->price_factor - $linetotal if $self->taxincluded; - my $taxkey = $part->get_taxkey(date => $self->deliverydate // $self->transdate, is_sales => $data->{is_sales}, taxzone => $self->taxzone_id); + my $taxkey = $part->get_taxkey(date => $self->effective_tax_point, is_sales => $data->{is_sales}, taxzone => $self->taxzone_id); my $tax_rate = $taxkey->tax->rate; my $tax_amount = undef; @@ -121,21 +122,21 @@ sub _calculate_item { } else { $tax_amount = $linetotal * $tax_rate; } - - if ($taxkey->tax->chart_id) { - $data->{taxes_by_chart_id}->{ $taxkey->tax->chart_id } ||= 0; - $data->{taxes_by_chart_id}->{ $taxkey->tax->chart_id } += $tax_amount; - $data->{taxes_by_tax_id}->{ $taxkey->tax_id } ||= 0; - $data->{taxes_by_tax_id}->{ $taxkey->tax_id } += $tax_amount; - } elsif ($tax_amount) { - die "tax_amount != 0 but no chart_id for taxkey " . $taxkey->id . " tax " . $taxkey->tax->id; - } - my $chart = $part->get_chart(type => $data->{is_sales} ? 'income' : 'expense', taxzone => $self->taxzone_id); - $data->{amounts}->{ $chart->id } ||= { taxkey => $taxkey->taxkey_id, tax_id => $taxkey->tax_id, amount => 0 }; - $data->{amounts}->{ $chart->id }->{amount} += $linetotal; - $data->{amounts}->{ $chart->id }->{amount} -= $tax_amount if $self->taxincluded; + unless ($data->{allow_optional_items} && $item->optional) { + if ($taxkey->tax->chart_id) { + $data->{taxes_by_chart_id}->{ $taxkey->tax->chart_id } ||= 0; + $data->{taxes_by_chart_id}->{ $taxkey->tax->chart_id } += $tax_amount; + $data->{taxes_by_tax_id}->{ $taxkey->tax_id } ||= 0; + $data->{taxes_by_tax_id}->{ $taxkey->tax_id } += $tax_amount; + } elsif ($tax_amount) { + die "tax_amount != 0 but no chart_id for taxkey " . $taxkey->id . " tax " . $taxkey->tax->id; + } + $data->{amounts}->{ $chart->id } ||= { taxkey => $taxkey->taxkey_id, tax_id => $taxkey->tax_id, amount => 0 }; + $data->{amounts}->{ $chart->id }->{amount} += $linetotal; + $data->{amounts}->{ $chart->id }->{amount} -= $tax_amount if $self->taxincluded; + } my $linetotal_cost = 0; if (!$linetotal) { @@ -150,8 +151,10 @@ sub _calculate_item { $item->marge_total( $linetotal_net - $linetotal_cost); $item->marge_percent($item->marge_total * 100 / $linetotal_net); - $self->marge_total( $self->marge_total + $item->marge_total); - $data->{lastcost_total} += $linetotal_cost; + unless ($data->{allow_optional_items} && $item->optional) { + $self->marge_total( $self->marge_total + $item->marge_total); + $data->{lastcost_total} += $linetotal_cost; + } } push @{ $data->{assembly_items} }, [];