X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FHelper%2FPriceTaxCalculator.pm;h=d95d1430937e89bd4d2d3b978a362b9b3faa8716;hb=927579ba66919f6fda8f2a34ff56c679fd76dc5d;hp=af5664694f424f0ad2a9411dc2c5fb4f9d09023a;hpb=c312836ce432677d4f7876f1e3a2b6d99f433cd6;p=kivitendo-erp.git diff --git a/SL/DB/Helper/PriceTaxCalculator.pm b/SL/DB/Helper/PriceTaxCalculator.pm index af5664694..d95d14309 100644 --- a/SL/DB/Helper/PriceTaxCalculator.pm +++ b/SL/DB/Helper/PriceTaxCalculator.pm @@ -74,7 +74,14 @@ sub _calculate_item { $item->base_qty($item_unit->convert_to($item->qty, $part_unit)); $item->fxsellprice($item->sellprice) if $data->{is_invoice}; - my $num_dec = _num_decimal_places($item->sellprice); + my $num_dec = _num_decimal_places($item->sellprice) || 2; + # ^ we need at least 2 decimal places ^ + # my test case 43.00 € with 0 decimal places and 0.5 discount -> + # : sellprice before:43.00000 + # : num dec before:0 + # : discount / sellprice ratio: 22 / 21 + # : discount = 43 * 0.5 _round(21.5, 0) = 22 + # TODO write a test case my $discount = _round($item->sellprice * ($item->discount || 0), $num_dec); my $sellprice = _round($item->sellprice - $discount, $num_dec); @@ -124,6 +131,7 @@ sub _calculate_item { my $chart = $item->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; push @{ $data->{assembly_items} }, []; if ($item->part->is_assembly) {