From: Bernd Bleßmann Date: Tue, 3 Feb 2015 11:29:01 +0000 (+0100) Subject: Nicht-editierbare CVars auch im Workflow richtig setzen. ... X-Git-Tag: release-3.2.0~56 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=be42a45043cab936e86e91aa895c6fc25bab079f;p=kivitendo-erp.git Nicht-editierbare CVars auch im Workflow richtig setzen. ... Zudem das Ermitteln der Werte in eine Subroutine ausgelagert. --- diff --git a/SL/CVar.pm b/SL/CVar.pm index 6da9b3680..0ace06902 100644 --- a/SL/CVar.pm +++ b/SL/CVar.pm @@ -652,6 +652,56 @@ sub format_to_template { return $value; } +sub get_non_editable_ic_cvars { + $main::lxdebug->enter_sub(2); + my $self = shift; + my %params = @_; + + Common::check_params(\%params, qw(form dbh row sub_module may_converted_from)); + my $form = $params{form}; + my $dbh = $params{dbh}; + my $row = $params{row}; + my $sub_module = $params{sub_module}; + my $may_converted_from = $params{may_converted_from}; + + my $cvars; + if (! $form->{"${sub_module}_id_${row}"}) { + my $conv_from = 0; + foreach (@{ $may_converted_from }) { + if ($form->{"converted_from_${_}_id_$row"}) { + $cvars = CVar->get_custom_variables(dbh => $dbh, + module => 'IC', + sub_module => $_, + trans_id => $form->{"converted_from_${_}_id_$row"}, + ); + $conv_from = 1; + last; + } + } + # get values for CVars from master data for new items + if (!$conv_from) { + $cvars = CVar->get_custom_variables(dbh => $dbh, + module => 'IC', + trans_id => $form->{"id_$row"}, + ); + } + } else { + # get values for CVars from custom_variables for existing items + $cvars = CVar->get_custom_variables(dbh => $dbh, + module => 'IC', + sub_module => $sub_module, + trans_id => $form->{"${sub_module}_id_${row}"}, + ); + } + # map only non-editable CVars to form + foreach (@{ $cvars }) { + next if $_->{flag_editable}; + $form->{"ic_cvar_$_->{name}_$row"} = $_->{value} + } + + $main::lxdebug->leave_sub(2); +} + 1; __END__ diff --git a/SL/DO.pm b/SL/DO.pm index 9fdd6b700..d537c92f7 100644 --- a/SL/DO.pm +++ b/SL/DO.pm @@ -296,9 +296,14 @@ SQL for my $i (1 .. $form->{rowcount}) { next if (!$form->{"id_$i"}); + CVar->get_non_editable_ic_cvars(form => $form, + dbh => $dbh, + row => $i, + sub_module => 'delivery_order_items', + may_converted_from => ['orderitems']); + my $position = $i; - my $cvars; if (!$form->{"delivery_order_items_id_$i"}) { # there is no persistent id, therefore create one with all necessary constraints my $q_item_id = qq|SELECT nextval('delivery_order_items_id')|; @@ -309,22 +314,7 @@ SQL do_query($form, $dbh, $query, conv_i($form->{"delivery_order_items_id_$i"}), conv_i($form->{"id"}), conv_i($position), conv_i($form->{"id_$i"})); $h_item_id->finish(); - - # get values for CVars from master data for new items - $cvars = CVar->get_custom_variables(dbh => $dbh, - module => 'IC', - trans_id => $form->{"id_$i"}, - ); - } else { - # get values for CVars from custom_variables for existing items - $cvars = CVar->get_custom_variables(dbh => $dbh, - module => 'IC', - sub_module => 'delivery_order_items', - trans_id => $form->{"delivery_order_items_id_$i"}, - ); } - # map only non-editable CVars to form (editable ones are already there) - map { $form->{"ic_cvar_$_->{name}_$i"} = $_->{value} unless $_->{flag_editable} } @{ $cvars }; $form->{"qty_$i"} = $form->parse_amount($myconfig, $form->{"qty_$i"}); @@ -1015,23 +1005,11 @@ sub order_details { } } - my $cvars; - if (! $form->{"delivery_order_items_id_$i"}) { - # get values for CVars from master data for new items - $cvars = CVar->get_custom_variables(dbh => $dbh, - module => 'IC', - trans_id => $form->{"id_$i"}, - ); - } else { - # get values for CVars from custom_variables for existing items - $cvars = CVar->get_custom_variables(dbh => $dbh, - module => 'IC', - sub_module => 'delivery_order_items', - trans_id => $form->{"delivery_order_items_id_$i"}, - ); - } - # map only non-editable CVars to form (editable ones are already there) - map { $form->{"ic_cvar_$_->{name}_$i"} = $_->{value} unless $_->{flag_editable} } @{ $cvars }; + CVar->get_non_editable_ic_cvars(form => $form, + dbh => $dbh, + row => $i, + sub_module => 'delivery_order_items', + may_converted_from => ['orderitems']); push @{ $form->{TEMPLATE_ARRAYS}->{"ic_cvar_$_->{name}"} }, CVar->format_to_template(CVar->parse($form->{"ic_cvar_$_->{name}_$i"}, $_), $_) @@ -1289,5 +1267,4 @@ sub is_marked_as_delivered { return $delivered ? 1 : 0; } - 1; diff --git a/SL/IR.pm b/SL/IR.pm index dd042488b..33f3ec4df 100644 --- a/SL/IR.pm +++ b/SL/IR.pm @@ -369,7 +369,12 @@ sub post_invoice { next if $payments_only; - my $cvars; + CVar->get_non_editable_ic_cvars(form => $form, + dbh => $dbh, + row => $i, + sub_module => 'invoice', + may_converted_from => ['delivery_order_items', 'orderitems']); + if (!$form->{"invoice_id_$i"}) { # there is no persistent id, therefore create one with all necessary constraints my $q_invoice_id = qq|SELECT nextval('invoiceid')|; @@ -380,22 +385,7 @@ sub post_invoice { do_query($form, $dbh, $q_create_invoice_id, conv_i($form->{"invoice_id_$i"}), conv_i($form->{id}), conv_i($position), conv_i($form->{"id_$i"})); $h_invoice_id->finish(); - - # get values for CVars from master data for new items - $cvars = CVar->get_custom_variables(dbh => $dbh, - module => 'IC', - trans_id => $form->{"id_$i"}, - ); - } else { - # get values for CVars from custom_variables for existing items - $cvars = CVar->get_custom_variables(dbh => $dbh, - module => 'IC', - sub_module => 'invoice', - trans_id => $form->{"invoice_id_$i"}, - ); } - # map only non-editable CVars to form (editable ones are already there) - map { $form->{"ic_cvar_$_->{name}_$i"} = $_->{value} unless $_->{flag_editable} } @{ $cvars }; # save detail record in invoice table $query = <finish; } - my $cvars; - if (! $form->{"invoice_id_$i"}) { - # get values for CVars from master data for new items - $cvars = CVar->get_custom_variables(dbh => $dbh, - module => 'IC', - trans_id => $form->{"id_$i"}, - ); - } else { - # get values for CVars from custom_variables for existing items - $cvars = CVar->get_custom_variables(dbh => $dbh, - module => 'IC', - sub_module => 'invoice', - trans_id => $form->{"invoice_id_$i"}, - ); - } - # map only non-editable CVars to form (editable ones are already there) - map { $form->{"ic_cvar_$_->{name}_$i"} = $_->{value} unless $_->{flag_editable} } @{ $cvars }; + CVar->get_non_editable_ic_cvars(form => $form, + dbh => $dbh, + row => $i, + sub_module => 'invoice', + may_converted_from => ['delivery_order_items', 'orderitems', 'invoice']); push @{ $form->{TEMPLATE_ARRAYS}->{"ic_cvar_$_->{name}"} }, CVar->format_to_template(CVar->parse($form->{"ic_cvar_$_->{name}_$i"}, $_), $_) @@ -767,7 +755,12 @@ sub post_invoice { $pricegroup_id *= 1; $pricegroup_id = undef if !$pricegroup_id; - my $cvars; + CVar->get_non_editable_ic_cvars(form => $form, + dbh => $dbh, + row => $i, + sub_module => 'invoice', + 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 my $q_invoice_id = qq|SELECT nextval('invoiceid')|; @@ -778,22 +771,7 @@ sub post_invoice { do_query($form, $dbh, $q_create_invoice_id, conv_i($form->{"invoice_id_$i"}), conv_i($form->{id}), conv_i($position), conv_i($form->{"id_$i"})); $h_invoice_id->finish(); - - # get values for CVars from master data for new items - $cvars = CVar->get_custom_variables(dbh => $dbh, - module => 'IC', - trans_id => $form->{"id_$i"}, - ); - } else { - # get values for CVars from custom_variables for existing items - $cvars = CVar->get_custom_variables(dbh => $dbh, - module => 'IC', - sub_module => 'invoice', - trans_id => $form->{"invoice_id_$i"}, - ); } - # map only non-editable CVars to form (editable ones are already there) - map { $form->{"ic_cvar_$_->{name}_$i"} = $_->{value} unless $_->{flag_editable} } @{ $cvars }; # save detail record in invoice table $query = <get_non_editable_ic_cvars(form => $form, + dbh => $dbh, + row => $i, + sub_module => 'orderitems', + may_converted_from => ['orderitems', 'invoice']); + my $position = $i; # save detail record in orderitems table - my $cvars; if (! $form->{"orderitems_id_$i"}) { $query = qq|SELECT nextval('orderitemsid')|; ($form->{"orderitems_id_$i"}) = selectrow_query($form, $dbh, $query); $query = qq|INSERT INTO orderitems (id, position) VALUES (?, ?)|; do_query($form, $dbh, $query, $form->{"orderitems_id_$i"}, conv_i($position)); - - # get values for CVars from master data for new items - $cvars = CVar->get_custom_variables(dbh => $dbh, - module => 'IC', - trans_id => $form->{"id_$i"}, - ); - } else { - # get values for CVars from custom_variables for existing items - $cvars = CVar->get_custom_variables(dbh => $dbh, - module => 'IC', - sub_module => 'orderitems', - trans_id => $form->{"orderitems_id_$i"}, - ); } - # map only non-editable CVars to form (editable ones are already there) - map { $form->{"ic_cvar_$_->{name}_$i"} = $_->{value} unless $_->{flag_editable} } @{ $cvars }; my $orderitems_id = $form->{"orderitems_id_$i"}; push @processed_orderitems, $orderitems_id; @@ -1412,23 +1402,11 @@ sub order_details { $sth->finish; } - my $cvars; - if (! $form->{"orderitems_id_$i"}) { - # get values for CVars from master data for new items - $cvars = CVar->get_custom_variables(dbh => $dbh, - module => 'IC', - trans_id => $form->{"id_$i"}, - ); - } else { - # get values for CVars from custom_variables for existing items - $cvars = CVar->get_custom_variables(dbh => $dbh, - module => 'IC', - sub_module => 'orderitems', - trans_id => $form->{"orderitems_id_$i"}, - ); - } - # map only non-editable CVars to form (editable ones are already there) - map { $form->{"ic_cvar_$_->{name}_$i"} = $_->{value} unless $_->{flag_editable} } @{ $cvars }; + CVar->get_non_editable_ic_cvars(form => $form, + dbh => $dbh, + row => $i, + sub_module => 'orderitems', + may_converted_from => ['orderitems', 'invoice']); push @{ $form->{TEMPLATE_ARRAYS}->{"ic_cvar_$_->{name}"} }, CVar->format_to_template(CVar->parse($form->{"ic_cvar_$_->{name}_$i"}, $_), $_)