From: Sven Schöling Date: Tue, 7 Jan 2014 14:20:50 +0000 (+0100) Subject: Neuer Accessor value_as_text, der alle Daten formatiert ausgibt X-Git-Tag: release-3.1.0beta1~22^2~25^2~12 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=be5edc51066e3aec49b02c04e21762f9e112ea47;p=kivitendo-erp.git Neuer Accessor value_as_text, der alle Daten formatiert ausgibt --- diff --git a/SL/DB/CustomVariable.pm b/SL/DB/CustomVariable.pm index 144acef00..6073925bf 100644 --- a/SL/DB/CustomVariable.pm +++ b/SL/DB/CustomVariable.pm @@ -43,6 +43,40 @@ sub value { goto &text_value; # text, textfield, date and select } +sub value_as_text { + my $self = $_[0]; + my $type = $self->config->type; + + die 'not an accessor' if @_ > 1; + + if ($type eq 'boolean') { + return $self->bool_value ? $::locale->text('Yes') : $::locale->text('No'); + } elsif ($type eq 'timestamp') { + return $::locale->reformat_date( { dateformat => 'yy-mm-dd' }, $self->timestamp_value->ymd, $::myconfig{dateformat}); + } elsif ($type eq 'number') { + return $::form->format_amount(\%::myconfig, $self->number_value, $self->config->processed_options->{PRECISION}); + } elsif ( $type eq 'customer' ) { + require SL::DB::Customer; + + my $id = int($self->number_value); + my $customer = $id ? SL::DB::Customer->new(id => $id)->load() : 0; + return $customer ? $customer->name : ''; + } elsif ( $type eq 'vendor' ) { + require SL::DB::Vendor; + + my $id = int($self->number_value); + return $id ? SL::DB::Vendor->new(id => $id)->load() : 0; + } elsif ( $type eq 'part' ) { + require SL::DB::Part; + + my $id = int($self->number_value); + my $vendor = $id ? SL::DB::Part->new(id => $id)->load() : 0; + return $vendor ? $vendor->name : ''; + } + + goto &text_value; # text, textfield, date and select +} + sub is_valid { my ($self) = @_;