+ foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
+ push(@projectnumber_values, $item->{"id"});
+ $projectnumber_labels{$item->{"id"}} = $item->{"projectnumber"};
+ }
+
+ _update_part_information();
+ _update_ship() if ($is_s_p_order);
+ _update_custom_variables();
+
+ my $totalweight = 0;
+
+ # rows
+
+ my @ROWS;
+ for my $i (1 .. $numrows) {
+ my %column_data = ();
+
+ # undo formatting
+ map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
+ qw(qty discount sellprice lastcost price_new price_old)
+ unless ($form->{simple_save});
+
+# unit begin
+ $form->{"unit_old_$i"} ||= $form->{"unit_$i"};
+ $form->{"selected_unit_$i"} ||= $form->{"unit_$i"};
+
+ if ( !$all_units->{$form->{"selected_unit_$i"}} # Die ausgewaehlte Einheit ist fuer diesen Artikel nicht gueltig
+ || !AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units)) { # (z.B. Dimensionseinheit war ausgewaehlt, es handelt sich aber
+ $form->{"unit_old_$i"} = $form->{"selected_unit_$i"} = $form->{"unit_$i"}; # um eine Dienstleistung). Dann keinerlei Umrechnung vornehmen.
+ }
+ # 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"};
+ $this_unit = $form->{"selected_unit_$i"} if AM->convert_unit($this_unit, $form->{"selected_unit_$i"}, $all_units);
+
+ if (0 < scalar @{ $form->{ALL_PRICE_FACTORS} }) {
+ my @values = ('', map { $_->{id} } @{ $form->{ALL_PRICE_FACTORS} });
+ my %labels = map { $_->{id} => $_->{description} } @{ $form->{ALL_PRICE_FACTORS} };
+
+ $column_data{price_factor} =
+ NTI($cgi->popup_menu('-name' => "price_factor_id_$i",
+ '-default' => $form->{"price_factor_id_$i"},
+ '-values' => \@values,
+ '-labels' => \%labels,
+ '-style' => 'width:90px'));
+ } else {
+ $column_data{price_factor} = ' ';
+ }
+ $form->{"weight_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"partunit_$i"}, $all_units) || 1;
+
+ $column_data{"unit"} = AM->unit_select_html($all_units, "unit_$i", $this_unit, $form->{"id_$i"} ? $form->{"unit_$i"} : undef);
+# / unit ending
+
+#count the max of decimalplaces of sellprice and lastcost, so the same number of decimalplaces
+#is shown for lastcost and sellprice.
+ my $decimalplaces = ($form->{"sellprice_$i"} =~ /\.(\d+)/) ? max 2, length $1 : 2;
+ $decimalplaces = ($form->{"lastcost_$i"} =~ /\.(\d+)/) ? max $decimalplaces, length $1 : $decimalplaces;
+
+ my $price_factor = $price_factors{$form->{"price_factor_id_$i"}} || 1;
+ my $discount = $form->round_amount($form->{"qty_$i"} * $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100 / $price_factor, 2);
+ my $linetotal = $form->round_amount($form->{"qty_$i"} * $form->{"sellprice_$i"} * (100 - $form->{"discount_$i"}) / 100 / $price_factor, 2);
+ my $rows = $form->numtextrows($form->{"description_$i"}, 30, 6);
+
+ $column_data{runningnumber} = $cgi->textfield(-name => "runningnumber_$i", -size => 5, -value => $i); # HuT
+ $column_data{partnumber} = $cgi->textfield(-name => "partnumber_$i", -size => 12, -value => $form->{"partnumber_$i"});
+ $column_data{description} = (($rows > 1) # if description is too large, use a textbox instead
+ ? $cgi->textarea( -name => "description_$i", -default => $form->{"description_$i"}, -rows => $rows, -columns => 30)
+ : $cgi->textfield(-name => "description_$i", -size => 30, -value => $form->{"description_$i"}))
+ . $cgi->button(-value => $locale->text('L'), -onClick => "set_longdescription_window('longdescription_$i')");
+
+ my $qty_dec = ($form->{"qty_$i"} =~ /\.(\d+)/) ? length $1 : 2;
+
+ $column_data{qty} = $cgi->textfield(-name => "qty_$i", -size => 5, -value => $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec));
+ $column_data{qty} .= $cgi->button(-onclick => "calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)", -value => $locale->text('*/'))
+ . $cgi->hidden(-name => "formel_$i", -value => $form->{"formel_$i"}) . $cgi->hidden("-name" => "alu_$i", "-value" => $form->{"alu_$i"})
+ if $form->{"formel_$i"};
+
+ $column_data{ship} = '';
+ if ($form->{"id_$i"}) {
+ my $ship_qty = $form->{"ship_$i"} * 1;
+ $ship_qty *= $all_units->{$form->{"partunit_$i"}}->{factor};
+ $ship_qty /= ( $all_units->{$form->{"unit_$i"}}->{factor} || 1 );
+
+ $column_data{ship} = $form->format_amount(\%myconfig, $form->round_amount($ship_qty, 2) * 1) . ' ' . $form->{"unit_$i"};
+ }
+
+ # build in drop down list for pricesgroups
+ # $sellprice_value setzt den Wert etwas unabhängiger von der Darstellung.
+ # Hintergrund: Preisgruppen werden hier überprüft und neu berechnet.
+ # Vorher wurde der ganze cgi->textfield Block zweimal identisch eingebaut, dass passiert
+ # jetzt nach der Abfrage.
+ my $sellprice_value;
+ if ($form->{"prices_$i"}) {
+ $column_data{sellprice_pg} = qq|<select name="sellprice_pg_$i" style="width: 8em">$form->{"prices_$i"}</select>|;
+ $sellprice_value =($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"})
+ ? $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces)
+ : $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
+ } else {
+ # for last row and report
+ # set pricegroup drop down list from report menu
+ if ($form->{"sellprice_$i"} != 0) {
+ # remember the pricegroup_id in pricegroup_old
+ # but don't overwrite it
+ $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"};
+ my $default_option = $form->{"sellprice_$i"}.'--'.$form->{"pricegroup_id_$i"};
+ $column_data{sellprice_pg} = NTI($cgi->popup_menu("sellprice_pg_$i", [ $default_option ], $default_option, { $default_option => $form->{"pricegroup_$i"} || '' }));
+ } else {
+ $column_data{sellprice_pg} = qq| |;