X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/b9d2f81497c6ff60be298ed1e7697c0c6a4316fa..53593baa211863fbf66540cf1bcc36c8fb37257f:/SL/DB/Helper/Attr.pm diff --git a/SL/DB/Helper/Attr.pm b/SL/DB/Helper/Attr.pm index 6f2dd55e2..21645f4e1 100644 --- a/SL/DB/Helper/Attr.pm +++ b/SL/DB/Helper/Attr.pm @@ -29,12 +29,14 @@ sub make { sub _make_by_type { my ($package, $name, $type) = @_; - _as_number ($package, $name, places => -2) if $type =~ /numeric | real | float/xi; - _as_percent($package, $name, places => 2) if $type =~ /numeric | real | float/xi; - _as_number ($package, $name, places => 0) if $type =~ /int/xi; - _as_date ($package, $name) if $type =~ /date | timestamp/xi; - _as_timestamp($package, $name) if $type =~ /timestamp/xi; - _as_bool_yn($package, $name) if $type =~ /bool/xi; + _as_number ($package, $name, places => -2) if $type =~ /numeric | real | float/xi; + _as_null_number($package, $name, places => -2) if $type =~ /numeric | real | float/xi; + _as_percent ($package, $name, places => 2) if $type =~ /numeric | real | float/xi; + _as_number ($package, $name, places => 0) if $type =~ /int/xi; + _as_null_number($package, $name, places => 0) if $type =~ /int/xi; + _as_date ($package, $name) if $type =~ /date | timestamp/xi; + _as_timestamp ($package, $name) if $type =~ /timestamp/xi; + _as_bool_yn ($package, $name) if $type =~ /bool/xi; } sub _as_number { @@ -54,6 +56,23 @@ sub _as_number { }; } +sub _as_null_number { + my $package = shift; + my $attribute = shift; + my %params = @_; + + $params{places} = 2 if !defined($params{places}); + + no strict 'refs'; + *{ $package . '::' . $attribute . '_as_null_number' } = sub { + my ($self, $string) = @_; + + $self->$attribute($string eq '' ? undef : $::form->parse_amount(\%::myconfig, $string)) if @_ > 1; + + return defined $self->$attribute ? $::form->format_amount(\%::myconfig, $self->$attribute, $params{places}) : ''; + }; +} + sub _as_percent { my $package = shift; my $attribute = shift;