X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fio.pl;h=7fc87e7c4e28f14def94ddbfbca720a54e833321;hb=1efa86b1825e32da0644fd3812060dafab3efa8e;hp=d0e1f5717360d2aaae9943d8edadc64fa34e57b6;hpb=c48270dd341297d7a1f70fd7cb48683c011213f2;p=kivitendo-erp.git diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index d0e1f5717..7fc87e7c4 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -2156,7 +2156,17 @@ sub send_sales_purchase_email { $::form->{media} = 'email'; - if (($::form->{attachment_policy} // '') =~ m{^(?:old_file|no_file)$}) { + $::form->{attachment_policy} //= ''; + + # Is an old file version available? + my $attfile; + if ($::form->{attachment_policy} eq 'old_file') { + $attfile = SL::File->get_all(object_id => $id, + object_type => $::form->{formname}, + file_type => 'document'); + } + + if ($::form->{attachment_policy} eq 'no_file' || ($::form->{attachment_policy} eq 'old_file' && $attfile)) { $::form->send_email(\%::myconfig, 'pdf'); } else { @@ -2201,3 +2211,35 @@ sub _maybe_attach_zugferd_data { $::form->error($e->message); } } + +sub download_factur_x_xml { + my ($form) = @_; + + my $record = _make_record(); + + die if !$record + || !$record->can('customer') + || !$record->customer + || !$record->can('create_pdf_a_print_options') + || !$record->can('create_zugferd_data') + || !$record->customer->create_zugferd_invoices_for_this_customer; + + my $xml_content = eval { $record->create_zugferd_data }; + + if (my $e = SL::X::ZUGFeRDValidation->caught) { + $::form->error($e->message); + } + + my $attachment_filename = $::form->generate_attachment_filename; + $attachment_filename =~ s{\.[^.]+$}{.xml}; + my %headers = ( + '-type' => 'application/xml', + '-connection' => 'close', + '-attachment' => $attachment_filename, + '-content-length' => length($xml_content), + ); + + print $::request->cgi->header(%headers); + + $::locale->with_raw_io(\*STDOUT, sub { print $xml_content }); +}