X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/4440782f0737cd715dbd96851ecc2dbd8cd639f2..82515b2d93dc5632f24d6e0b6f8f05f3fd19fbb0:/SL/DB/Helpers/AttrPercent.pm diff --git a/SL/DB/Helpers/AttrPercent.pm b/SL/DB/Helpers/AttrPercent.pm new file mode 100644 index 000000000..24f816404 --- /dev/null +++ b/SL/DB/Helpers/AttrPercent.pm @@ -0,0 +1,37 @@ +package SL::DB::Helpers::AttrPercent; + +use strict; + +use Carp; +use English; + +sub define { + my $package = shift; + my $attribute = shift; + my %params = @_; + + $params{places} = 2 if !defined($params{places}); + + my $code = <${attribute}(\$::form->parse_amount(\\\%::myconfig, \$_[0]) / 100); + } + + return \$::form->format_amount(\\\%::myconfig, 100 * \$self->${attribute}, $params{places}); +} + +1; +CODE + + eval $code; + croak "Defining '${attribute}_as_number' failed: $EVAL_ERROR" if $EVAL_ERROR; + + return 1; +} + +1;