Bei fehlender Übersetzung nicht übersetzten Begriff zurückggeben.
[kivitendo-erp.git] / SL / Template / Plugin / LxERP.pm
1 package SL::Template::Plugin::LxERP;
2
3 use base qw( Template::Plugin );
4 use Template::Plugin;
5
6 use List::Util qw(min);
7
8 use SL::AM;
9
10 use strict;
11
12 sub new {
13   my $class   = shift;
14   my $context = shift;
15
16   bless { }, $class;
17 }
18
19 sub format_amount {
20   my ($self, $var, $places, $skip_zero, $dash) = @_;
21
22   return $main::form->format_amount(\%main::myconfig, $var * 1, $places, $dash) unless $skip_zero && $var == 0;
23   return '';
24 }
25
26 sub round_amount {
27   my ($self, $var, $places, $skip_zero) = @_;
28
29   return $main::form->round_amount($var * 1, $places) unless $skip_zero && $var == 0;
30   return '';
31 }
32
33 sub format_amount_units {
34   my ($self, $amount, $amount_unit, $part_unit) = @_;
35
36   return $main::form->format_amount_units('amount'      => $amount,
37                                           'part_unit'   => $part_unit,
38                                           'amount_unit' => $amount_unit,
39                                           'conv_units'  => 'convertible_not_smaller');
40 }
41
42 sub format_percent {
43   my ($self, $var, $places, $skip_zero) = @_;
44
45   return $self->format_amount($var * 100, $places, $skip_zero);
46 }
47
48 sub escape_br {
49   my ($self, $var) = @_;
50
51   $var =~ s/\r//g;
52   $var =~ s/\n/<br>/g;
53
54   return $var;
55 }
56
57 sub format_string {
58   my $self   = shift;
59   my $string = shift;
60
61   return $main::form->format_string($string, @_);
62 }
63
64 sub numtextrows {
65   my $self = shift;
66
67   return $main::form->numtextrows(@_);
68 }
69
70 sub _turn90_word {
71   my $self = shift;
72   my $word = shift || "";
73
74   return join '<br>', map { $main::locale->quote_special_chars('HTML', $_) } split(m//, $word);
75 }
76
77 sub turn90 {
78   my $self            = shift;
79   my $word            = shift;
80   my $args            = shift;
81
82   $args             ||= { };
83   $word             ||= "";
84
85   $args->{split_by} ||= 'chars';
86   $args->{class}      = " class=\"$args->{class}\"" if ($args->{class});
87
88   if ($args->{split_by} eq 'words') {
89     my @words = split m/\s+/, $word;
90
91     if (1 >= scalar @words) {
92       return $self->_turn90_word($words[0]);
93     }
94
95     return qq|<table><tr>| . join('', map { '<td valign="bottom"' . $args->{class} . '>' . $self->_turn90_word($_) . '</td>' } @words) . qq|</tr></table>|;
96
97   } else {
98     return $self->_turn90_word($word);
99   }
100 }
101
102 sub abs {
103   my $self = shift;
104   my $var  = shift;
105
106   return $var < 0 ? $var * -1 : $var;
107 }
108
109 sub t8 {
110   my ($self, $text, $args) = @_;
111   $self->{locale} ||= Locale->new($::myconfig{countrycode}, 'all');
112   return $self->{locale}->text($text, @args) || $text;
113 }
114
115 1;