kivitendo/SL/Template/Plugin/LxERP.pm @ 7bd5c745
2ef21b8f | Sven Schöling | package SL::Template::Plugin::LxERP;
|
||
use base qw( Template::Plugin );
|
||||
use Template::Plugin;
|
||||
8c7e4493 | Moritz Bunkus | |||
use List::Util qw(min);
|
||||
use SL::AM;
|
||||
2ef21b8f | Sven Schöling | |||
sub new {
|
||||
my $class = shift;
|
||||
my $context = shift;
|
||||
bless { }, $class;
|
||||
}
|
||||
sub format_amount {
|
||||
my ($self, $var, $places, $skip_zero) = @_;
|
||||
return $main::form->format_amount(\%main::myconfig, $var * 1, $places) unless $skip_zero && $var == 0;
|
||||
return '';
|
||||
}
|
||||
8c7e4493 | Moritz Bunkus | sub format_amount_units {
|
||
my ($self, $amount, $amount_unit, $part_unit) = @_;
|
||||
return $main::form->format_amount_units('amount' => $amount,
|
||||
'part_unit' => $part_unit,
|
||||
'amount_unit' => $amount_unit,
|
||||
'conv_units' => 'convertible_not_smaller');
|
||||
}
|
||||
2ef21b8f | Sven Schöling | sub format_percent {
|
||
my ($self, $var, $places, $skip_zero) = @_;
|
||||
return $self->format_amount($var * 100, $places, $skip_zero);
|
||||
}
|
||||
d1e4ee79 | Moritz Bunkus | sub escape_br {
|
||
my ($self, $var) = @_;
|
||||
$var =~ s/\r//g;
|
||||
$var =~ s/\n/<br>/g;
|
||||
return $var;
|
||||
}
|
||||
8c7e4493 | Moritz Bunkus | sub format_string {
|
||
my $self = shift;
|
||||
my $string = shift;
|
||||
return $main::form->format_string($string, @_);
|
||||
}
|
||||
sub numtextrows {
|
||||
my $self = shift;
|
||||
return $main::form->numtextrows(@_);
|
||||
}
|
||||
sub _turn90_word {
|
||||
my $self = shift;
|
||||
my $word = shift || "";
|
||||
2ef21b8f | Sven Schöling | |||
7bd5c745 | Moritz Bunkus | return join '<br>', map { $locale->quote_special_chars('HTML', $_) } split(m//, $word);
|
||
8c7e4493 | Moritz Bunkus | }
|
||
sub turn90 {
|
||||
my $self = shift;
|
||||
my $word = shift;
|
||||
my $args = shift;
|
||||
$args ||= { };
|
||||
$word ||= "";
|
||||
$args->{split_by} ||= 'chars';
|
||||
$args->{class} = " class=\"$args->{class}\"" if ($args->{class});
|
||||
if ($args->{split_by} eq 'words') {
|
||||
my @words = split m/\s+/, $word;
|
||||
if (1 >= scalar @words) {
|
||||
return $self->_turn90_word($words[0]);
|
||||
}
|
||||
return qq|<table><tr>| . join('', map { '<td valign="bottom"' . $args->{class} . '>' . $self->_turn90_word($_) . '</td>' } @words) . qq|</tr></table>|;
|
||||
} else {
|
||||
return $self->_turn90_word($word);
|
||||
}
|
||||
}
|
||||
1;
|