]> wagnertech.de Git - mfinanz.git/blobdiff - SL/CVar.pm
Constraints auf vendor/customer: Vorher alle verwaisten Einträge entfernen
[mfinanz.git] / SL / CVar.pm
index e91a2366dbb0cb6bab9b9b214cb79a988b9ceec8..bd58cbd7eff9b5dda1fbd26822420053f3565cc2 100644 (file)
@@ -3,6 +3,7 @@ package CVar;
 use strict;
 
 use List::Util qw(first);
+use Scalar::Util qw(blessed);
 use Data::Dumper;
 
 use SL::DBUtils;
@@ -706,6 +707,25 @@ sub custom_variables_validity_by_trans_id {
   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 $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->parse_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;
+}
+
 1;
 
 __END__