6593fb708020f391f1b3f9b13b658cb55348dac5
[kivitendo-erp.git] / SL / DB / Helpers / AttrNumber.pm
1 package SL::DB::Helpers::AttrNumber;
2
3 use strict;
4
5 use Carp;
6 use English;
7
8 sub define {
9   my $package     = shift;
10   my $attribute   = shift;
11   my %params      = @_;
12
13   $params{places} = 2 if !defined($params{places});
14
15   no strict 'refs';
16   *{ $package . '::' . $attribute . '_as_number' } = sub {
17     my ($self, $string) = @_;
18
19     $self->$attribute($::form->parse_amount(\%::myconfig, $string)) if @_ > 1;
20
21     return $::form->format_amount(\%::myconfig, $self->$attribute, $params{places});
22   };
23
24   return 1;
25 }
26
27 1;