check_oe_access();
+ my $order = _make_record();
+
set_headings($form->{"id"} ? "edit" : "add");
$form->{update} = 1;
$form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
$form->{"lastcost_$i"} = $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces);
$form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
-
- # get pricegroups for parts
- IS->get_pricegroups_for_parts(\%myconfig, \%$form);
-
- # build up html code for prices_$i
- &set_pricegroup($i);
}
display_form();
$form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
}
- # show pricegroup in newly loaded invoice when creating invoice from quotation/order
- IS->get_pricegroups_for_parts(\%myconfig, \%$form);
- set_pricegroup($_) for 1 .. $form->{rowcount};
-
&display_form;
$main::lxdebug->leave_sub();
$::form->error($::locale->text('No action defined.'));
}
+
+sub _make_record {
+ my $obj = SL::DB::Order->new;
+
+ for my $method (keys %$::form) {
+ next unless $obj->can($method);
+ next unless $obj->meta->column($method);
+
+ if ($obj->meta->column($method)->isa('Rose::DB::Object::Metadata::Column::Date')) {
+ $obj->${\"$method\_as_date"}($::form->{$method});
+ } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::(?:Integer|Numeric|Float|DoublePrecsion)$/) {
+ $obj->$method($::form->{$method});
+ }
+ }
+
+ my @items;
+ for my $i (1 .. $::form->{rowcount}) {
+ next unless $::form->{"id_$i"};
+ push @items, _make_record_item($i)
+ }
+
+ $obj->orderitems(@items);
+
+ return $obj;
+}
+