X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/bc524b0df0ada3c9e7b4ad08cd62ade6a498fb11..96717bed8061efaa4d626d5da34122ef0cb3e8d2:/SL/DB/Helper/PriceTaxCalculator.pm diff --git a/SL/DB/Helper/PriceTaxCalculator.pm b/SL/DB/Helper/PriceTaxCalculator.pm index 2478292a4..673bb248a 100644 --- a/SL/DB/Helper/PriceTaxCalculator.pm +++ b/SL/DB/Helper/PriceTaxCalculator.pm @@ -37,6 +37,8 @@ sub calculate_prices_and_taxes { $self->netamount( 0); $self->marge_total(0); + SL::DB::Manager::Chart->cache_taxkeys(date => $self->transdate); + my $idx = 0; foreach my $item ($self->items) { $idx++; @@ -74,7 +76,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);