my @fields = map { s/_1$//; $_ } grep { m/_1$/ } keys %{ $::form };
my @new_rows;
+ my $make_key = sub {
+ my ($row) = @_;
+ return $::form->{"id_${row}"} unless $::form->{"serialnumber_${row}"};
+ my $key = $::form->{"id_${row}"} . ':' . $::form->{"serialnumber_${row}"};
+ return exists $params{quantities}->{$key} ? $key : $::form->{"id_${row}"};
+ };
+
my $removed_rows = 0;
my $row = 0;
while ($row < $::form->{rowcount}) {
my $parts_id = $::form->{"id_$row"};
my $base_qty = $::form->parse_amount(\%::myconfig, $::form->{"qty_$row"}) * SL::DB::Manager::Unit->find_by(name => $::form->{"unit_$row"})->base_factor;
- my $sub_qty = min($base_qty, $params{quantities}->{$parts_id});
- $params{quantities}->{$parts_id} -= $sub_qty;
+ my $key = $make_key->($row);
+ my $sub_qty = min($base_qty, $params{quantities}->{$key});
+ $params{quantities}->{$key} -= $sub_qty;
if (!$sub_qty || ($sub_qty != $base_qty)) {
$::form->{"qty_${row}"} = $::form->format_amount(\%::myconfig, ($base_qty - $sub_qty) / SL::DB::Manager::Unit->find_by(name => $::form->{"unit_$row"})->base_factor);
next if $ord_quot->is_sales != $record->is_sales;
foreach my $item (@{ $record->items }) {
- $handled_base_qtys{ $item->parts_id } += $item->qty * $item->unit_obj->base_factor;
+ my $key = $item->parts_id;
+ $key .= ':' . $item->serialnumber if $item->serialnumber;
+ $handled_base_qtys{$key} += $item->qty * $item->unit_obj->base_factor;
}
}