aee71a4834fd5dc26b7d9c9fcdeb43f7fc5d0ffc
[kivitendo-erp.git] / SL / Helper / GlAttachments.pm
1 #
2 # Helper for General Ledger Reports
3 #
4 # 1. Fetch the Count of PDF-Documents of one item of a General Ledger Report
5 # 2. Append the contents of all items of a General Ledger Report
6
7 package SL::Helper::GlAttachments;
8
9 use strict;
10
11 use Exporter 'import';
12 our @EXPORT_OK = qw(count_gl_attachments append_gl_pdf_attachments);
13 our %EXPORT_TAGS = (
14   all => \@EXPORT_OK,
15 );
16 use SL::File;
17
18 my %gl_types = (
19   'ar' => 'invoice',
20   'ap' => 'purchase_invoice',
21   'gl' => 'gl_transaction',
22 );
23
24 #
25 # Fetch the Count of PDF-Documents with are related to the $id parameter
26 # The parameter $gltype may be 'ar','ap' or 'gl'.
27 #
28 sub count_gl_pdf_attachments {
29   my ($self,$id,$gltype) = @_;
30   return SL::File->get_all_count(object_id   => $id,
31                                  object_type => $gl_types{$gltype},
32                                  mime_type   => 'application/pdf',
33                                  );
34 }
35
36 # Append the contents of all PDF-Documents to the base $content
37 # This Method is only used in SL/Reportgenerator.pm if the $form->{GD} array is set.
38 # The elements of the array need the two elements $ref->{type},$ref->{id}
39 #
40 sub append_gl_pdf_attachments {
41   my ($self,$form,$content) = @_;
42   my @filelist;
43   foreach my $ref (@{ $form->{GL} }) {
44     my @files = SL::File->get_all(object_id   => $ref->{id},
45                                   object_type => $gl_types{$ref->{type}},
46                                   mime_type   => 'application/pdf',
47                                  );
48     push @filelist, $_->get_file for @files;
49   }
50   return $self->merge_pdfs(file_names => \@filelist , inp_content => $content );
51 }
52
53 1;
54
55 __END__
56
57 =encoding utf-8
58
59 =head1 NAME
60
61 SL::Helper::GlAttachments - Helper for General Ledger Reports
62
63 =head1 SYNOPSIS
64
65    $self->count_gl_pdf_attachments($ref->{id},$ref->{type});
66    $self->append_gl_pdf_attachments($form,$base_content);
67
68
69 =head1 DESCRIPTION
70
71 Helper for General Ledger Reports
72
73 1. Fetch the Count of PDF-Documents of one item of a General Ledger Report
74
75 2. Append the contents of all items of a General Ledger Report
76
77
78 =head1 METHODS
79
80 =head2 C<count_gl_pdf_attachments>
81
82 count_gl_pdf_attachments($id,$type);
83
84 Fetch the Count of PDF-Documents with are related to the $id parameter
85 The parameter $type may be 'ar','ap' or 'gl'.
86
87 =head2 C<append_gl_pdf_attachments>
88
89 append_gl_pdf_attachments($form,$content);
90
91 Append the contents of all PDF-Documents to the base $content
92 This Method is only used in SL/Reportgenerator.pm if the $form->{GD} array is set.
93 The elements of the array need the two elements $ref->{type},$ref->{id}
94
95 =head1 AUTHOR
96
97 Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>
98
99
100 =cut
101