- 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);
-
- $item->price_factor( ! $item->price_factor_obj ? 1 : ($item->price_factor_obj->factor || 1));
- $item->marge_price_factor(! $item->part->price_factor ? 1 : ($item->part->price_factor->factor || 1));
- my $linetotal = _round($sellprice * $item->qty / $item->price_factor, 2) * $data->{exchangerate};
- $linetotal = _round($linetotal, 2);
-
- $data->{invoicediff} += $sellprice * $item->qty * $data->{exchangerate} / $item->price_factor - $linetotal if $self->taxincluded;