Merge branch 'b-3.6.1' into mebil
[kivitendo-erp.git] / SL / Template / Plugin / LxERP.pm
index 1bd03da..66424fc 100644 (file)
@@ -1,12 +1,15 @@
 package SL::Template::Plugin::LxERP;
 
 use base qw( Template::Plugin );
+use Scalar::Util qw();
 use Template::Plugin;
 
 use List::Util qw(min);
 
 use SL::AM;
 
+use strict;
+
 sub new {
   my $class   = shift;
   my $context = shift;
@@ -14,25 +17,35 @@ sub new {
   bless { }, $class;
 }
 
+sub is_rdbo {
+  my ($self, $obj, $wanted_class) = @_;
+
+  $wanted_class = !$wanted_class         ? 'Rose::DB::Object'
+                : $wanted_class =~ m{::} ? $wanted_class
+                :                          "SL::DB::${wanted_class}";
+
+  return Scalar::Util::blessed($obj) ? $obj->isa($wanted_class) : 0;
+}
+
 sub format_amount {
-  my ($self, $var, $places, $skip_zero) = @_;
+  my ($self, $var, $places, $skip_zero, $dash) = @_;
 
-  return $main::form->format_amount(\%main::myconfig, $var * 1, $places) unless $skip_zero && $var == 0;
+  return $main::form->format_amount(\%main::myconfig, $var * 1, $places, $dash) unless $skip_zero && $var == 0;
   return '';
 }
 
-sub format_amount_units {
-  my ($self, $amount, $amount_unit, $part_unit) = @_;
+sub round_amount {
+  my ($self, $var, $places, $skip_zero) = @_;
 
-  return $main::form->format_amount_units('amount'      => $amount,
-                                          'part_unit'   => $part_unit,
-                                          'amount_unit' => $amount_unit,
-                                          'conv_units'  => 'convertible_not_smaller');
+  return $main::form->round_amount($var * 1, $places) unless $skip_zero && $var == 0;
+  return '';
 }
 
 sub format_percent {
   my ($self, $var, $places, $skip_zero) = @_;
 
+  $places ||= 2;
+
   return $self->format_amount($var * 100, $places, $skip_zero);
 }
 
@@ -90,4 +103,16 @@ sub turn90 {
   }
 }
 
+sub abs {
+  my $self = shift;
+  my $var  = shift;
+
+  return $var < 0 ? $var * -1 : $var;
+}
+
+sub t8 {
+  my ($self, $text, @args) = @_;
+  return $::locale->text($text, @args) || $text;
+}
+
 1;