Nicht-editierbare CVars bei "als neu speichern/verwenden" richtig setzen.
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Wed, 4 Feb 2015 15:21:01 +0000 (16:21 +0100)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Wed, 4 Feb 2015 17:41:28 +0000 (18:41 +0100)
SL/DO.pm
SL/IR.pm
SL/IS.pm
SL/OE.pm
bin/mozilla/do.pl
bin/mozilla/io.pl
bin/mozilla/ir.pl
bin/mozilla/is.pl
bin/mozilla/oe.pl

index d537c92..5adccd5 100644 (file)
--- a/SL/DO.pm
+++ b/SL/DO.pm
@@ -300,7 +300,7 @@ SQL
                                     dbh                => $dbh,
                                     row                => $i, 
                                     sub_module         => 'delivery_order_items',
-                                    may_converted_from => ['orderitems']);
+                                    may_converted_from => ['orderitems', 'delivery_order_items']);
 
     my $position = $i;
 
@@ -395,8 +395,9 @@ SQL
                                 name_prefix  => 'ic_',
                                 name_postfix => "_$i",
                                 dbh          => $dbh);
+
     # link order items with doi, for future extension look at foreach IS.pm
-    if ($form->{"converted_from_orderitems_id_$i"}) {
+    if (!$form->{saveasnew} && $form->{"converted_from_orderitems_id_$i"}) {
       RecordLinks->create_links('dbh'        => $dbh,
                                 'mode'       => 'ids',
                                 'from_table' => 'orderitems',
@@ -404,8 +405,8 @@ SQL
                                 'to_table'   => 'delivery_order_items',
                                 'to_id'      =>  $form->{"delivery_order_items_id_$i"},
       );
-      delete $form->{"converted_from_orderitems_id_$i"};
     }
+    delete $form->{"converted_from_orderitems_id_$i"};
   }
 
   # 1. search for orphaned dois; processed_dois may be empty (no transfer) TODO: be supersafe and alter same statement for doi and oi
@@ -1009,7 +1010,7 @@ sub order_details {
                                     dbh                => $dbh,
                                     row                => $i, 
                                     sub_module         => 'delivery_order_items',
-                                    may_converted_from => ['orderitems']);
+                                    may_converted_from => ['orderitems', 'delivery_order_items']);
 
     push @{ $form->{TEMPLATE_ARRAYS}->{"ic_cvar_$_->{name}"} },
       CVar->format_to_template(CVar->parse($form->{"ic_cvar_$_->{name}_$i"}, $_), $_)
index 33f3ec4..a87fca3 100644 (file)
--- a/SL/IR.pm
+++ b/SL/IR.pm
@@ -373,7 +373,7 @@ sub post_invoice {
                                     dbh                => $dbh,
                                     row                => $i, 
                                     sub_module         => 'invoice',
-                                    may_converted_from => ['delivery_order_items', 'orderitems']);
+                                    may_converted_from => ['delivery_order_items', 'orderitems', 'invoice']);
 
     if (!$form->{"invoice_id_$i"}) {
       # there is no persistent id, therefore create one with all necessary constraints
@@ -416,9 +416,10 @@ SQL
                                 name_prefix  => 'ic_',
                                 name_postfix => "_$i",
                                 dbh          => $dbh);
+
     # link previous items with invoice items See IS.pm (no credit note -> no invoice item)
     foreach (qw(delivery_order_items orderitems)) {
-      if ($form->{"converted_from_${_}_id_$i"}) {
+      if (!$form->{useasnew} && $form->{"converted_from_${_}_id_$i"}) {
         RecordLinks->create_links('dbh'        => $dbh,
                                   'mode'       => 'ids',
                                   'from_table' => $_,
@@ -426,8 +427,8 @@ SQL
                                   'to_table'   => 'invoice',
                                   'to_id'      => $form->{"invoice_id_$i"},
         );
-        delete $form->{"converted_from_${_}_id_$i"};
       }
+      delete $form->{"converted_from_${_}_id_$i"};
     }
   }
 
index 7522bd2..43303e8 100644 (file)
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -812,7 +812,7 @@ SQL
     }
     # link previous items with invoice items
     foreach (qw(delivery_order_items orderitems invoice)) {
-      if ($form->{"converted_from_${_}_id_$i"}) {
+      if (!$form->{useasnew} && $form->{"converted_from_${_}_id_$i"}) {
         RecordLinks->create_links('dbh'        => $dbh,
                                   'mode'       => 'ids',
                                   'from_table' => $_,
@@ -820,8 +820,8 @@ SQL
                                   'to_table'   => 'invoice',
                                   'to_id'      => $form->{"invoice_id_$i"},
         );
-        delete $form->{"converted_from_${_}_id_$i"};
       }
+      delete $form->{"converted_from_${_}_id_$i"};
     }
   }
 
index df43e2a..c2cde73 100644 (file)
--- a/SL/OE.pm
+++ b/SL/OE.pm
@@ -568,9 +568,10 @@ SQL
                                   name_prefix  => 'ic_',
                                   name_postfix => "_$i",
                                   dbh          => $dbh);
+
       # link previous items with orderitems
       foreach (qw(orderitems invoice)) {
-        if ($form->{"converted_from_${_}_id_$i"}) {
+        if (!$form->{saveasnew} && $form->{"converted_from_${_}_id_$i"}) {
           RecordLinks->create_links('dbh'        => $dbh,
                                     'mode'       => 'ids',
                                     'from_table' => $_,
@@ -578,11 +579,12 @@ SQL
                                     'to_table'   => 'orderitems',
                                     'to_id'      => $orderitems_id,
           );
-          delete $form->{"converted_from_${_}_id_$i"};
         }
+        delete $form->{"converted_from_${_}_id_$i"};
       }
     }
   }
+
   # search for orphaned ids
   $query  = sprintf 'SELECT id FROM orderitems WHERE trans_id = ? AND NOT id IN (%s)', join ', ', ("?") x scalar @processed_orderitems;
   @values = (conv_i($form->{id}), map { conv_i($_) } @processed_orderitems);
index d4fa816..e3c192a 100644 (file)
@@ -962,7 +962,7 @@ sub save_as_new {
   $form->{delivered} = 0;
   map { delete $form->{$_} } qw(printed emailed queued);
   delete @{ $form }{ grep { m/^stock_(?:in|out)_\d+/ } keys %{ $form } };
-  delete $form->{"delivery_order_items_id_$_"} for 1 .. $form->{"rowcount"};
+  $form->{"converted_from_delivery_order_items_id_$_"} = delete $form->{"delivery_order_items_id_$_"} for 1 .. $form->{"rowcount"};
   # Let kivitendo assign a new order number if the user hasn't changed the
   # previous one. If it has been changed manually then use it as-is.
   $form->{donumber} =~ s/^\s*//g;
index 54e4803..a54f65d 100644 (file)
@@ -442,7 +442,7 @@ sub display_row {
       push @hidden_vars, qw(orderitems_id converted_from_orderitems_id converted_from_invoice_id);
     }
     if ($is_invoice) {
-      push @hidden_vars, qw(invoice_id converted_from_orderitems_id converted_from_delivery_order_items_id);
+      push @hidden_vars, qw(invoice_id converted_from_orderitems_id converted_from_delivery_order_items_id converted_from_invoice_id);
     }
     if ($::form->{type} =~ /credit_note/) {
       push @hidden_vars, qw(invoice_id converted_from_invoice_id);
@@ -451,7 +451,7 @@ sub display_row {
       map { $form->{"${_}_${i}"} = $form->format_amount(\%myconfig, $form->{"${_}_${i}"}) } qw(sellprice discount lastcost);
       push @hidden_vars, grep { defined $form->{"${_}_${i}"} } qw(sellprice discount not_discountable price_factor_id lastcost);
       push @hidden_vars, "stock_${stock_in_out}_sum_qty", "stock_${stock_in_out}";
-      push @hidden_vars, qw(delivery_order_items_id converted_from_orderitems_id);
+      push @hidden_vars, qw(delivery_order_items_id converted_from_orderitems_id converted_from_delivery_order_items_id);
     }
 
     my @HIDDENS = map { value => $_}, (
index c535bcf..4cd96ca 100644 (file)
@@ -333,7 +333,7 @@ sub form_header {
     max_dunning_level dunning_amount
     shiptoname shiptostreet shiptozipcode shiptocity shiptocountry  shiptocontact shiptophone shiptofax
     shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
-    convert_from_do_ids convert_from_oe_ids show_details gldate
+    convert_from_do_ids convert_from_oe_ids show_details gldate useasnew
   ), @custom_hiddens,
   map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}];
 
@@ -620,7 +620,10 @@ sub use_as_new {
   $form->{paidaccounts} = 1;
   $form->{rowcount}--;
   $form->{invdate} = $form->current_date(\%myconfig);
-  delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
+
+  $form->{"converted_from_invoice_id_$_"} = delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
+
+  $form->{useasnew} = 1;
   &display_form;
 
   $main::lxdebug->leave_sub();
index 4adc9f7..9518551 100644 (file)
@@ -380,7 +380,7 @@ sub form_header {
     max_dunning_level dunning_amount
     shiptoname shiptostreet shiptozipcode shiptocity shiptocountry  shiptocontact shiptophone shiptofax
     shiptoemail shiptodepartment_1 shiptodepartment_2  shiptocp_gender message email subject cc bcc taxaccounts cursor_fokus
-    convert_from_do_ids convert_from_oe_ids convert_from_ar_ids
+    convert_from_do_ids convert_from_oe_ids convert_from_ar_ids useasnew
     invoice_id
     show_details
   ), @custom_hiddens,
@@ -834,8 +834,10 @@ sub use_as_new {
   $form->{employee_id}  = SL::DB::Manager::Employee->current->id;
   $form->{forex}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
   $form->{exchangerate} = $form->{forex} if $form->{forex};
-  delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
 
+  $form->{"converted_from_invoice_id_$_"} = delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
+
+  $form->{useasnew} = 1;
   &display_form;
 
   $main::lxdebug->leave_sub();
index e81cb48..8a14425 100644 (file)
@@ -1621,7 +1621,7 @@ sub save_as_new {
 
   $form->{saveasnew} = 1;
   map { delete $form->{$_} } qw(printed emailed queued delivered closed);
-  delete $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"};
+  $form->{"converted_from_orderitems_id_$_"} = delete $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"};
 
   # Let kivitendo assign a new order number if the user hasn't changed the
   # previous one. If it has been changed manually then use it as-is.