X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FHelper%2FPriceTaxCalculator.pm;h=bde711a797a97fc0a3995566a7701e61686bc34e;hb=91fef42d0f6c2e37f276d97a0f5b444420e51a00;hp=15850d558946b1bb748f4a6d14bb5af333f9cba8;hpb=0b36b2259c1300ee5360a9c8d5aee1f321abd364;p=kivitendo-erp.git diff --git a/SL/DB/Helper/PriceTaxCalculator.pm b/SL/DB/Helper/PriceTaxCalculator.pm index 15850d558..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); @@ -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} }, [];