Migration von parts.bin nach wirklichen Lager und Lagerplatz s.a. Ticket 2284
[kivitendo-erp.git] / SL / OE.pm
index a865e3d..7302088 100644 (file)
--- a/SL/OE.pm
+++ b/SL/OE.pm
@@ -419,9 +419,13 @@ sub save {
 
       $reqdate = ($form->{"reqdate_$i"}) ? $form->{"reqdate_$i"} : undef;
 
-      # get pricegroup_id and save ist
+      # Get pricegroup_id and save it. Unfortunately the interface
+      # also uses ID "0" for signalling that none is selected, but "0"
+      # must not be stored in the database. Therefore we cannot simply
+      # use conv_i().
       ($null, my $pricegroup_id) = split(/--/, $form->{"sellprice_pg_$i"});
       $pricegroup_id *= 1;
+      $pricegroup_id  = undef if !$pricegroup_id;
 
       # save detail record in orderitems table
       my $orderitems_id = $form->{"orderitems_id_$i"};
@@ -441,7 +445,7 @@ sub save {
            $form->{"qty_$i"}, $baseqty,
            $fxsellprice, $form->{"discount_$i"},
            $form->{"unit_$i"}, conv_date($reqdate), conv_i($form->{"project_id_$i"}),
-           $form->{"serialnumber_$i"}, $form->{"ship_$i"}, conv_i($pricegroup_id),
+           $form->{"serialnumber_$i"}, $form->{"ship_$i"}, $pricegroup_id,
            $form->{"ordnumber_$i"}, conv_date($form->{"transdate_$i"}),
            $form->{"cusordnumber_$i"}, $form->{"subtotal_$i"} ? 't' : 'f',
            $form->{"marge_percent_$i"}, $form->{"marge_absolut_$i"},
@@ -687,11 +691,6 @@ sub delete {
            qq|WHERE trans_id = ?|;
   do_query($form, $dbh, $query, @values);
 
-  # delete OE record
-  $query = qq|DELETE FROM oe | .
-           qq|WHERE id = ?|;
-  do_query($form, $dbh, $query, @values);
-
   # delete individual entries
   $query = qq|DELETE FROM orderitems | .
            qq|WHERE trans_id = ?|;
@@ -701,6 +700,11 @@ sub delete {
            qq|WHERE trans_id = ? AND module = 'OE'|;
   do_query($form, $dbh, $query, @values);
 
+  # delete OE record
+  $query = qq|DELETE FROM oe | .
+           qq|WHERE id = ?|;
+  do_query($form, $dbh, $query, @values);
+
   my $rc = $dbh->commit;
 
   if ($rc) {
@@ -870,7 +874,7 @@ sub retrieve {
            c3.accno AS expense_accno,   c3.new_chart_id AS expense_new_chart,   date($transdate) - c3.valid_from as expense_valid,
            oe.ordnumber AS ordnumber_oe, oe.transdate AS transdate_oe, oe.cusordnumber AS cusordnumber_oe,
            p.partnumber, p.assembly, p.listprice, o.description, o.qty,
-           o.sellprice, o.parts_id AS id, o.unit, o.discount, p.bin, p.notes AS partnotes, p.inventory_accno_id AS part_inventory_accno_id,
+           o.sellprice, o.parts_id AS id, o.unit, o.discount, p.notes AS partnotes, p.inventory_accno_id AS part_inventory_accno_id,
            o.reqdate, o.project_id, o.serialnumber, o.ship, o.lastcost,
            o.ordnumber, o.transdate, o.cusordnumber, o.subtotal, o.longdescription,
            o.price_factor_id, o.price_factor, o.marge_price_factor,
@@ -1107,7 +1111,7 @@ sub order_details {
   $form->{discount} = [];
 
   $form->{TEMPLATE_ARRAYS} = { };
-  IC->prepare_parts_for_printing();
+  IC->prepare_parts_for_printing(myconfig => $myconfig, form => $form);
 
   my $ic_cvar_configs = CVar->get_configs(module => 'IC');