PriceSource: Erste Version
[kivitendo-erp.git] / bin / mozilla / oe.pl
index ad5406c..b9abb0f 100644 (file)
@@ -594,6 +594,8 @@ sub update {
 
   check_oe_access();
 
+  my $order = _make_record();
+
   set_headings($form->{"id"} ? "edit" : "add");
 
   $form->{update} = 1;
@@ -692,12 +694,6 @@ sub update {
         $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();
@@ -1510,10 +1506,6 @@ sub invoice {
       $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();
@@ -2118,3 +2110,29 @@ sub dispatcher {
 
   $::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;
+}
+