+
+ # calculate individual sellprice, discount is already accounted for in column sellprice in db
+
+ # The sellprice total can be calculated from sellprice or fxsellprice (the
+ # value that was actually entered in the sellprice field and is always
+ # stored seperately). However, for fxsellprice this method only works when
+ # the tax is not included, because otherwise fxsellprice includes the tax
+ # and there is no simple way to extract the tax rate of the article from
+ # the big query.
+ #
+ # Using fxsellprice is potentially more accurate (certainly for tax
+ # included), because we can use the same method as is used while the
+ # invoice is generated.
+ #
+ # sellprice however has already been converted to the net value (but
+ # rounded in the process, which leads to rounding errors when calculating
+ # the linetotal from the rounded sellprice in the report. These rounding
+ # errors can quickly amount to several cents when qty is large)
+ #
+ # For calculating sellprice_total from fxsellprice, you would use:
+ # sellprice_total_including_tax = qty * fxsellprice * (1-discount) / price_factor * exchangerate
+ # $ar->{sellprice_total_including_tax} = $form->round_amount( $ar->{qty} * ( $ar->{fxsellprice} * ( 1 - $ar->{discount} ) ) / $ar->{price_factor}, $form->{"decimalplaces"});
+
+ $ar->{sellprice} = $ar->{sellprice} / $ar->{price_factor} / $basefactor;
+ $ar->{sellprice_total} = $form->round_amount( $ar->{qty} * $ar->{sellprice} / $ar->{price_factor} , $form->{"decimalplaces"});
+