# adjust prices by unit, ignore if pricegroup changed
if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
$form->{"sellprice_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units) || 1;
+ $form->{"lastcost_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units) || 1;
$form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
}
my $this_unit = $form->{"unit_$i"};
} else {
$real_sellprice = $linetotal;
};
- my $real_lastcost = $form->{"lastcost_$i"} * $form->{"qty_$i"} / ( $form->{"marge_price_factor_$i"} || 1 );
+ my $real_lastcost = $form->round_amount($form->{"lastcost_$i"} * $form->{"qty_$i"} / $price_factor, 2);
my $marge_percent_warn = $myconfig{marge_percent_warn} * 1 || 15;
my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
$ar->{price_factor} = 1 unless $ar->{price_factor};
# calculate individual sellprice
# discount was already accounted for in db sellprice
- $ar->{sellprice} = $ar->{sellprice} / $ar->{price_factor} / $basefactor;
- $ar->{lastcost} = $ar->{lastcost} / $ar->{price_factor};
+ $ar->{sellprice} = $ar->{sellprice} / $ar->{price_factor} / $basefactor;
+ $ar->{lastcost} = $ar->{lastcost} / $ar->{price_factor} / $basefactor;
$ar->{sellprice_total} = $ar->{qty} * ( $ar->{fxsellprice} * ( 1 - $ar->{discount} ) ) / $ar->{price_factor};
$ar->{lastcost_total} = $ar->{qty} * $ar->{lastcost} * $basefactor;
# marge_percent wird neu berechnet, da Wert in invoice leer ist (Bug)