+sub custom_variables_validity_by_trans_id {
+  $main::lxdebug->enter_sub(2);
+
+  my $self     = shift;
+  my %params   = @_;
+
+  return sub { 0 } unless $params{trans_id};
+
+  my $myconfig = \%main::myconfig;
+  my $form     = $main::form;
+
+  my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
+
+  my $query    = qq|SELECT config_id, COUNT(*) FROM custom_variables_validity WHERE trans_id = ? GROUP BY config_id|;
+
+  my %invalids = selectall_as_map($form, $dbh, $query, 'config_id', 'count', $params{trans_id});
+
+  $main::lxdebug->leave_sub(2);
+
+  return sub { !$invalids{+shift} };
+}
+
+sub parse {
+  my ($self, $value, $config) = @_;
+
+  return $::form->parse_amount(\%::myconfig, $value)          if $config->{type} eq 'number';
+  return DateTime->from_lxoffice($value)                      if $config->{type} eq 'date';
+  return !ref $value ? SL::DB::Manager::Customer->find_by(id => $value * 1) : $value  if $config->{type} eq 'customer';
+  return !ref $value ? SL::DB::Manager::Vendor->find_by(id => $value * 1)   : $value  if $config->{type} eq 'vendor';
+  return !ref $value ? SL::DB::Manager::Part->find_by(id => $value * 1)     : $value  if $config->{type} eq 'part';
+  return $value;
+}
+
+sub format_to_template {
+  my ($self, $value, $config) = @_;
+  # stupid template expects everything formated. except objects
+  # do not use outside of print routines for legacy templates
+
+  return $::form->format_amount(\%::myconfig, $value) if $config->{type} eq 'number';
+  return $value->to_lxoffice if $config->{type} eq 'date' && blessed $value && $value->can('to_lxoffice');
+  return $value;
+}
+