From 6b4a71ff376e8337b708127f9f6c63c1d70d0af3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Wed, 21 Jan 2015 00:01:36 +0100 Subject: [PATCH] Nicht editierbare CVars nicht rendern, aber richtig speichern und drucken. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Dazu werden die Werte dieser Variablen aus der DB gelesen, nämlich: - aus custom_variables zu den Stammdaten, wenn die Artikelzeile neu hinzugekommen ist - aus custom_variables zur Artikelzeile, wenn die Zeile schon im Beleg gespeichert war Hier für Angebote/Aufträge und Lieferscheine. Todo: - Für Rechnungen muss das noch gemacht werden (wenn dort die item-ids persistent sind). - Gruppieren nach Warengruppen im Ausdruck muss getestet werden, aber das geht im Moment ohnehin nicht. Siehe auch Ticket 1836 (trac.kivitendo.de) bzw. 4 und 25 (redmine.kivitendo-premium.de) --- SL/DO.pm | 35 +++++++++++++++++++ SL/OE.pm | 35 +++++++++++++++++++ .../webpages/amcvar/render_inputs_block.html | 10 ++++-- 3 files changed, 77 insertions(+), 3 deletions(-) diff --git a/SL/DO.pm b/SL/DO.pm index de9a728de..584ad59ad 100644 --- a/SL/DO.pm +++ b/SL/DO.pm @@ -298,6 +298,7 @@ SQL 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')|; @@ -308,7 +309,23 @@ 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"}); my $item_unit = $part_unit_map{$form->{"id_$i"}}; @@ -983,6 +1000,24 @@ 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 }; + push @{ $form->{TEMPLATE_ARRAYS}->{"ic_cvar_$_->{name}"} }, CVar->format_to_template(CVar->parse($form->{"ic_cvar_$_->{name}_$i"}, $_), $_) for @{ $ic_cvar_configs }; diff --git a/SL/OE.pm b/SL/OE.pm index 2985e89d0..a60b86c5a 100644 --- a/SL/OE.pm +++ b/SL/OE.pm @@ -512,13 +512,30 @@ sub save { 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; @@ -1377,6 +1394,24 @@ 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 }; + push @{ $form->{TEMPLATE_ARRAYS}->{"ic_cvar_$_->{name}"} }, CVar->format_to_template(CVar->parse($form->{"ic_cvar_$_->{name}_$i"}, $_), $_) for @{ $ic_cvar_configs }; diff --git a/templates/webpages/amcvar/render_inputs_block.html b/templates/webpages/amcvar/render_inputs_block.html index 3141a5a11..5d668e1b0 100644 --- a/templates/webpages/amcvar/render_inputs_block.html +++ b/templates/webpages/amcvar/render_inputs_block.html @@ -10,9 +10,10 @@ SET render_cvar_tag_options.no_id = 1; END; %] -[%- IF (cvar.hide_non_editable && !cvar.var.flag_editable) || cvar.partsgroup_filtered %] -[%- L.hidden_tag(cvar_tag_name, cvar.var.value, render_cvar_tag_options) %] -[%- ELSIF !cvar.valid %] + +[%- IF (!cvar.hide_non_editable || cvar.var.flag_editable) && !cvar.partsgroup_filtered %] + +[%- IF !cvar.valid %] [%- IF show_disabled_message %] [% 'Element disabled' | $T8 %] [%- END %] @@ -71,4 +72,7 @@ [% render_cvar_tag_options.maxlength=cvar.var.maxlength IF cvar.var.maxlength; L.input_tag(cvar_tag_name, cvar.value, render_cvar_tag_options) %] [%- END %] + +[%- END %] + [%- END %] -- 2.20.1