ZUGFeRD: Rechnungen mit ZUGFeRD-Daten erzeugen
[kivitendo-erp.git] / SL / DB / Helper / PDF_A.pm
1 package SL::DB::Helper::PDF_A;
2
3 use strict;
4
5 use parent qw(Exporter);
6 our @EXPORT = qw(create_pdf_a_print_options);
7
8 use Carp;
9 use Template;
10
11 sub _create_xmp_data {
12   my ($self, %params) = @_;
13
14         use Cwd;
15   my $template = Template->new({
16     INTERPOLATE  => 0,
17     EVAL_PERL    => 0,
18     ABSOLUTE     => 1,
19     PLUGIN_BASE  => 'SL::Template::Plugin',
20     ENCODING     => 'utf8',
21   }) || croak;
22
23   my $output = '';
24   $template->process(SL::System::Process::exe_dir() . '/templates/pdf/pdf_a_metadata.xmp', \%params, \$output) || croak $template->error;
25
26   return $output;
27 }
28
29 sub create_pdf_a_print_options {
30   my ($self) = @_;
31
32   require SL::DB::Language;
33
34   my $language_code = $self->can('language_id') && $self->language_id ? SL::DB::Language->load_cached($self->language_id)->template_code : undef;
35   $language_code  ||= 'de';
36   my $pdf_language  = $language_code =~ m{deutsch|german|^de$}i   ? 'de-DE'
37                     : $language_code =~ m{englisch|english|^en$}i ? 'en-US'
38                     :                                               '';
39   my $author        = do {
40     no warnings 'once';
41     $::instance_conf->get_company
42   };
43
44   my $timestamp =  DateTime->now_local->strftime('%Y-%m-%dT%H:%M:%S%z');
45   $timestamp    =~ s{(..)$}{:$1};
46
47   return {
48     version => '3b',
49     xmp     => _create_xmp_data(
50       $self,
51       pdf_a_version     => '3',
52       pdf_a_conformance => 'B',
53       producer          => 'pdfTeX',
54       timestamp         => $timestamp, # 2019-11-05T15:26:20+01:00
55       meta_data => {
56         title    => $self->displayable_name,
57         author   => $author,
58         language => $pdf_language,
59       },
60       zugferd              => {
61         conformance_level  => 'EXTENDED',
62         document_file_name => 'ZUGFeRD-invoice.xml',
63         document_type      => 'INVOICE',
64         version            => '1.0',
65       },
66     ),
67   };
68 }
69
70 1;