]> wagnertech.de Git - mfinanz.git/blobdiff - bin/mozilla/io.pl
ZUGFeRD: Rechnungen mit ZUGFeRD-Daten erzeugen
[mfinanz.git] / bin / mozilla / io.pl
index f8c660d2ae559716ad1aecac685a32eee615ddf2..1ee0d2c090ff61bf1d7ce80f4f8dedb6fe846a18 100644 (file)
@@ -1288,6 +1288,10 @@ sub print_form {
     $form->{TEMPLATE_DRIVER_OPTIONS}->{variable_content_types} = $form->get_variable_content_types();
   }
 
+  if ($form->{format} =~ m{pdf}) {
+    _maybe_attach_zugferd_data($form);
+  }
+
   $form->isblank("email", $locale->text('E-mail address missing!'))
     if ($form->{media} eq 'email');
   $form->isblank("${inv}date",
@@ -2110,3 +2114,25 @@ sub send_sales_purchase_email {
 
   print $::form->redirect_header($script . '?action=edit&id=' . $::form->escape($id) . '&type=' . $::form->escape($type));
 }
+
+sub _maybe_attach_zugferd_data {
+  my ($form) = @_;
+
+  my $record = _make_record();
+
+  return if !$record || !$record->can('create_pdf_a_print_options') || !$record->can('create_zugferd_data');
+
+  my $xmlfile = File::Temp->new;
+  $xmlfile->print($record->create_zugferd_data);
+  $xmlfile->close;
+
+  $form->{TEMPLATE_DRIVER_OPTIONS}->{pdf_a}           = $record->create_pdf_a_print_options(zugferd_xmp_data => $record->create_zugferd_xmp_data);
+  $form->{TEMPLATE_DRIVER_OPTIONS}->{pdf_attachments} = [
+    { source       => $xmlfile,
+      name         => 'ZUGFeRD-invoice.xml',
+      description  => $::locale->text('ZUGFeRD invoice'),
+      relationship => '/Alternative',
+      mime_type    => 'text/xml',
+    }
+  ];
+}