Dunning: Email und Zahlungsbedingung in Mahnlaufbericht aufgenommen
[kivitendo-erp.git] / SL / Template / Excel.pm
1 package SL::Template::Excel;
2
3 use strict;
4 use parent qw(SL::Template::Simple);
5
6 sub new {
7   my $type = shift;
8
9   my $self = $type->SUPER::new(@_);
10
11   return $self;
12 }
13
14 sub _init {
15   my $self = shift;
16
17   $self->{source}    = shift;
18   $self->{form}      = shift;
19   $self->{myconfig}  = shift;
20   $self->{userspath} = shift;
21
22   $self->{error}     = undef;
23
24   $self->set_tag_style('<<', '>>');
25 }
26
27 sub get_mime_type() {
28   my ($self) = @_;
29
30   return "application/msexcel";
31 }
32
33 sub uses_temp_file {
34   return 1;
35 }
36
37 sub parse {
38   $main::lxdebug->enter_sub();
39
40   my $self   = shift;
41   local *OUT = shift;
42   my $form   = $self->{"form"};
43
44   open(IN, "$form->{templates}/$form->{IN}") or do { $self->{"error"} = "$!"; return 0; };
45   my @lines = <IN>;
46   close IN;
47
48   my $contents = join("", @lines);
49   my @indices;
50   $contents =~ s%
51     ( $self->{tag_start} [<]* (\s?) [<>\s]* ([\w\s]+) [<>\s]* $self->{tag_end} )
52   %
53     $self->format_vars(align_right => $2 ne '', varstring => $3, length => length($1), indices =>  \@indices)
54   %egx;
55
56   if (!defined($contents)) {
57     $main::lxdebug->leave_sub();
58     return 0;
59   }
60
61   print OUT $contents;
62
63   $main::lxdebug->leave_sub();
64   return 1;
65 }
66
67 sub format_vars {
68   my ($self, %params) = @_;
69   my $form            = $self->{"form"};
70   my @indices         = @{ $params{indices} };
71   my $align_right     = $params{align_right};
72   my $varstring       = $params{varstring};
73   my $length          = $params{length};
74
75   $varstring =~ s/(\w+)/ $self->_get_loop_variable($1, 0, @indices) /eg;
76   my $old_string=$varstring;
77   my $new_string = sprintf "%*s", ($align_right ? 1 : -1 ) * $length, $varstring;
78   return substr $new_string, ($align_right ? (0, $length) : -$length);
79 }
80
81 1;