+ my $price_factor = $price_factors{$form->{"price_factor_id_$i"}} || { 'factor' => 1 };
+
+ push @{ $form->{runningnumber} }, $position;
+ push @{ $form->{number} }, $form->{"partnumber_$i"};
+ push @{ $form->{description} }, $form->{"description_$i"};
+ push @{ $form->{longdescription} }, $form->{"longdescription_$i"};
+ push @{ $form->{qty} }, $form->format_amount($myconfig, $form->{"qty_$i"});
+ push @{ $form->{ship} }, $form->format_amount($myconfig, $form->{"ship_$i"});
+ push @{ $form->{unit} }, $form->{"unit_$i"};
+ push @{ $form->{bin} }, $form->{"bin_$i"};
+ push @{ $form->{partnotes} }, $form->{"partnotes_$i"};
+ push @{ $form->{serialnumber} }, $form->{"serialnumber_$i"};
+ push @{ $form->{reqdate} }, $form->{"reqdate_$i"};
+ push @{ $form->{sellprice} }, $form->{"sellprice_$i"};
+ push @{ $form->{listprice} }, $form->{"listprice_$i"};
+ push @{ $form->{price_factor} }, $price_factor->{formatted_factor};
+ push @{ $form->{price_factor_name} }, $price_factor->{description};
+
+ my $sellprice = $form->parse_amount($myconfig, $form->{"sellprice_$i"});
+ my ($dec) = ($sellprice =~ /\.(\d+)/);
+ my $decimalplaces = max 2, length($dec);
+
+ my $discount = $form->round_amount($form->{"qty_$i"} * $sellprice * $form->{"discount_$i"} / 100 / $price_factor->{factor}, $decimalplaces);
+ my $linetotal = $form->round_amount($form->{"qty_$i"} * $sellprice * (100 - $form->{"discount_$i"}) / 100 / $price_factor->{factor}, 2);
+ my $nodiscount_linetotal = $form->round_amount($form->{"qty_$i"} * $sellprice / $price_factor->{factor}, 2);
+ $form->{"netprice_$i"} = $form->round_amount($form->{"qty_$i"} ? ($linetotal / $form->{"qty_$i"}) : 0, 2);
+
+ push @{ $form->{netprice} }, ($form->{"netprice_$i"} != 0) ? $form->format_amount($myconfig, $form->{"netprice_$i"}, $decimalplaces) : '';
+
+ $linetotal = ($linetotal != 0) ? $linetotal : '';
+
+ push @{ $form->{discount} }, ($discount != 0) ? $form->format_amount($myconfig, $discount * -1, $decimalplaces) : '';
+ push @{ $form->{p_discount} }, $form->{"discount_$i"};
+
+ $form->{ordtotal} += $linetotal;
+ $form->{nodiscount_total} += $nodiscount_linetotal;
+ $form->{discount_total} += $discount;
+
+ if ($subtotal_header) {
+ $discount_subtotal += $linetotal;
+ $nodiscount_subtotal += $nodiscount_linetotal;
+ }
+
+ if ($form->{"subtotal_$i"} && $subtotal_header && ($subtotal_header != $i)) {
+ push @{ $form->{discount_sub} }, $form->format_amount($myconfig, $discount_subtotal, 2);
+ push @{ $form->{nodiscount_sub} }, $form->format_amount($myconfig, $nodiscount_subtotal, 2);
+
+ $discount_subtotal = 0;
+ $nodiscount_subtotal = 0;
+ $subtotal_header = 0;