From: Bernd Bleßmann Date: Wed, 4 Feb 2015 15:21:01 +0000 (+0100) Subject: Nicht-editierbare CVars bei "als neu speichern/verwenden" richtig setzen. X-Git-Tag: release-3.2.0~55 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=b8125c17c8add08c9b84fb054f797547a853dd3a;p=kivitendo-erp.git Nicht-editierbare CVars bei "als neu speichern/verwenden" richtig setzen. --- diff --git a/SL/DO.pm b/SL/DO.pm index d537c92f7..5adccd535 100644 --- 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"}, $_), $_) diff --git a/SL/IR.pm b/SL/IR.pm index 33f3ec4df..a87fca31b 100644 --- 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"}; } } diff --git a/SL/IS.pm b/SL/IS.pm index 7522bd248..43303e894 100644 --- 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"}; } } diff --git a/SL/OE.pm b/SL/OE.pm index df43e2a4a..c2cde7306 100644 --- 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); diff --git a/bin/mozilla/do.pl b/bin/mozilla/do.pl index d4fa8160f..e3c192a69 100644 --- a/bin/mozilla/do.pl +++ b/bin/mozilla/do.pl @@ -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; diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index 54e480373..a54f65deb 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -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 => $_}, ( diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index c535bcfec..4cd96ca9f 100644 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -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(); diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index 4adc9f708..95185519e 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -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(); diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index e81cb48f8..8a14425d5 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -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.