- if ($form->{"unit_old_$i"} ne $form->{"selected_unit_$i"}) {
- my $basefactor = 1;
- if (defined($all_units->{$form->{"unit_old_$i"}}->{"factor"}) &&
- $all_units->{$form->{"unit_old_$i"}}->{"factor"}) {
- $basefactor = $all_units->{$form->{"selected_unit_$i"}}->{"factor"} /
- $all_units->{$form->{"unit_old_$i"}}->{"factor"};
- }
- $form->{"sellprice_$i"} *= $basefactor;
- $form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
- }
- }
-
- ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
- $decimalplaces = max length($dec), 2;
-
- $price_factor = $price_factors{$form->{"price_factor_id_$i"}} || 1;
- $discount = (100 - $form->{"discount_$i"} * 1) / 100;
-
- $linetotal = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"} * $discount / $price_factor, $decimalplaces);
-
- my $real_sellprice = $form->{"sellprice_$i"} * $discount / $price_factor;
-
- # marge calculations
- my ($marge_font_start, $marge_font_end);
-
- $form->{"lastcost_$i"} *= 1;
-
- $marge_price_factor = $form->{"marge_price_factor_$i"} * 1 || 1;
-
- if ($real_sellprice && ($form->{"qty_$i"} * 1)) {
- $form->{"marge_percent_$i"} = ($real_sellprice - $form->{"lastcost_$i"} / $marge_price_factor) * 100 / $real_sellprice;
- $myconfig{"marge_percent_warn"} = 15 unless (defined($myconfig{"marge_percent_warn"}));
-
- if ($form->{"id_$i"} &&
- ($form->{"marge_percent_$i"} < (1 * $myconfig{"marge_percent_warn"}))) {
- $marge_font_start = "<font color=\"#ff0000\">";
- $marge_font_end = "</font>";
- }
-
- } else {
- $form->{"marge_percent_$i"} = 0;
- }
-
- my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
- $form->{"marge_total_$i"} = ($real_sellprice - $form->{"lastcost_$i"} / $marge_price_factor) * $form->{"qty_$i"} * $marge_adjust_credit_note;
- $form->{"marge_total"} += $form->{"marge_total_$i"};
- $form->{"lastcost_total"} += $form->{"lastcost_$i"} * $form->{"qty_$i"} / $marge_price_factor;
- $form->{"sellprice_total"} += $real_sellprice * $form->{"qty_$i"};
-
- map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(marge_total marge_percent);
-
- # convert " to "
- map { $form->{"${_}_$i"} =~ s/\"/"/g }
- qw(partnumber description unit unit_old);
-
-########################################
- # Eintrag fuer Version 2.2.0 geaendert #
- # neue Optik im Rechnungsformular #
-########################################
- $column_data{runningnumber} =
- qq|<td><input name="runningnumber_$i" size="5" value="$i"></td>|; # HuT
-############## ENDE Neueintrag ##################
-
- $column_data{partnumber} =
- qq|<td><input name="partnumber_$i" size=12 value="$form->{"partnumber_$i"}"></td>|;
-
- if (($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) {
- $column_data{description} =
- qq|<td><textarea name="description_$i" rows="$rows" cols="30" wrap="soft">| . H($form->{"description_$i"}) . qq|</textarea><button type="button" onclick="set_longdescription_window('longdescription_$i')">| . $locale->text('L') . qq|</button></td>|;
- } else {
- $column_data{description} =
- qq|<td><input name="description_$i" size="30" value="| . $form->quote($form->{"description_$i"}) . qq|"><button type="button" onclick="set_longdescription_window('longdescription_$i')">| . $locale->text('L') . qq|</button></td>|;
- }
-
- (my $qty_dec) = ($form->{"qty_$i"} =~ /\.(\d+)/);
- $qty_dec = length $qty_dec;
-
- $column_data{qty} =
- qq|<td align="right"><input name="qty_$i" size="5" value="|
- . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec) .qq|">|;
- if ($form->{"formel_$i"}) {
- $column_data{qty} .= qq|<button type="button" onclick="calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)">| . $locale->text('*/') . qq|</button>|
- . $cgi->hidden("-name" => "formel_$i", "-value" => $form->{"formel_$i"}) . $cgi->hidden("-name" => "alu_$i", "-value" => $form->{"alu_$i"});