Zudem das Ermitteln der Werte in eine Subroutine ausgelagert.
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__
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')|;
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 $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"}, $_), $_)
return $delivered ? 1 : 0;
}
-
1;
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')|;
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 = <<SQL;
return $duedate;
}
-
1;
$sth->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"}, $_), $_)
$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')|;
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 = <<SQL;
$pricegroup_id *= 1;
$pricegroup_id = undef if !$pricegroup_id;
+ CVar->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;
$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"}, $_), $_)