Revision 30b8dc10
Von Moritz Bunkus vor fast 3 Jahren hinzugefügt
SL/Controller/Order.pm | ||
---|---|---|
280 | 280 |
my $groupitems = $::form->{print_options}->{groupitems}; |
281 | 281 |
my $printer_id = $::form->{print_options}->{printer_id}; |
282 | 282 |
|
283 |
# only pdf and opendocument by now
|
|
284 |
if (none { $format eq $_ } qw(pdf opendocument opendocument_pdf)) { |
|
283 |
# only PDF, OpenDocument & HTML for now
|
|
284 |
if (none { $format eq $_ } qw(pdf opendocument opendocument_pdf html)) {
|
|
285 | 285 |
return $self->js->flash('error', t8('Format \'#1\' is not supported yet/anymore.', $format))->render; |
286 | 286 |
} |
287 | 287 |
|
... | ... | |
297 | 297 |
$form->{format} = $format; |
298 | 298 |
$form->{formname} = $formname; |
299 | 299 |
$form->{language} = '_' . $self->order->language->template_code if $self->order->language; |
300 |
my $pdf_filename = $form->generate_attachment_filename();
|
|
300 |
my $doc_filename = $form->generate_attachment_filename();
|
|
301 | 301 |
|
302 |
my $pdf;
|
|
303 |
my @errors = $self->generate_pdf(\$pdf, { format => $format,
|
|
302 |
my $doc;
|
|
303 |
my @errors = $self->generate_doc(\$doc, { format => $format,
|
|
304 | 304 |
formname => $formname, |
305 | 305 |
language => $self->order->language, |
306 | 306 |
printer_id => $printer_id, |
307 | 307 |
groupitems => $groupitems }); |
308 | 308 |
if (scalar @errors) { |
309 |
return $self->js->flash('error', t8('Conversion to PDF failed: #1', $errors[0]))->render;
|
|
309 |
return $self->js->flash('error', t8('Generating the document failed: #1', $errors[0]))->render;
|
|
310 | 310 |
} |
311 | 311 |
|
312 | 312 |
if ($media eq 'screen') { |
313 | 313 |
# screen/download |
314 |
$self->js->flash('info', t8('The PDF has been created'));
|
|
314 |
$self->js->flash('info', t8('The document has been created.'));
|
|
315 | 315 |
$self->send_file( |
316 |
\$pdf,
|
|
317 |
type => SL::MIME->mime_type_from_ext($pdf_filename),
|
|
318 |
name => $pdf_filename,
|
|
316 |
\$doc,
|
|
317 |
type => SL::MIME->mime_type_from_ext($doc_filename),
|
|
318 |
name => $doc_filename,
|
|
319 | 319 |
js_no_render => 1, |
320 | 320 |
); |
321 | 321 |
|
... | ... | |
324 | 324 |
my $printer_id = $::form->{print_options}->{printer_id}; |
325 | 325 |
SL::DB::Printer->new(id => $printer_id)->load->print_document( |
326 | 326 |
copies => $copies, |
327 |
content => $pdf,
|
|
327 |
content => $doc,
|
|
328 | 328 |
); |
329 | 329 |
|
330 |
$self->js->flash('info', t8('The PDF has been printed'));
|
|
330 |
$self->js->flash('info', t8('The document has been printed.'));
|
|
331 | 331 |
} |
332 | 332 |
|
333 |
my @warnings = $self->store_pdf_to_webdav_and_filemanagement($pdf, $pdf_filename);
|
|
333 |
my @warnings = $self->store_doc_to_webdav_and_filemanagement($doc, $doc_filename);
|
|
334 | 334 |
if (scalar @warnings) { |
335 | 335 |
$self->js->flash('warning', $_) for @warnings; |
336 | 336 |
} |
... | ... | |
367 | 367 |
my $pdf_filename = $form->generate_attachment_filename(); |
368 | 368 |
|
369 | 369 |
my $pdf; |
370 |
my @errors = $self->generate_pdf(\$pdf, { format => $format,
|
|
370 |
my @errors = $self->generate_doc(\$pdf, { format => $format,
|
|
371 | 371 |
formname => $formname, |
372 | 372 |
language => $self->order->language, |
373 | 373 |
}); |
... | ... | |
475 | 475 |
$::form->{media} = 'email'; |
476 | 476 |
|
477 | 477 |
if (($::form->{attachment_policy} // '') !~ m{^(?:old_file|no_file)$}) { |
478 |
my $pdf;
|
|
479 |
my @errors = $self->generate_pdf(\$pdf, {media => $::form->{media},
|
|
478 |
my $doc;
|
|
479 |
my @errors = $self->generate_doc(\$doc, {media => $::form->{media},
|
|
480 | 480 |
format => $::form->{print_options}->{format}, |
481 | 481 |
formname => $::form->{print_options}->{formname}, |
482 | 482 |
language => $self->order->language, |
483 | 483 |
printer_id => $::form->{print_options}->{printer_id}, |
484 | 484 |
groupitems => $::form->{print_options}->{groupitems}}); |
485 | 485 |
if (scalar @errors) { |
486 |
return $self->js->flash('error', t8('Conversion to PDF failed: #1', $errors[0]))->render($self);
|
|
486 |
return $self->js->flash('error', t8('Generating the document failed: #1', $errors[0]))->render($self);
|
|
487 | 487 |
} |
488 | 488 |
|
489 |
my @warnings = $self->store_pdf_to_webdav_and_filemanagement($pdf, $::form->{attachment_filename});
|
|
489 |
my @warnings = $self->store_doc_to_webdav_and_filemanagement($doc, $::form->{attachment_filename});
|
|
490 | 490 |
if (scalar @warnings) { |
491 | 491 |
flash_later('warning', $_) for @warnings; |
492 | 492 |
} |
493 | 493 |
|
494 | 494 |
my $sfile = SL::SessionFile::Random->new(mode => "w"); |
495 |
$sfile->fh->print($pdf);
|
|
495 |
$sfile->fh->print($doc);
|
|
496 | 496 |
$sfile->fh->close; |
497 | 497 |
|
498 | 498 |
$::form->{tmpfile} = $sfile->file_name; |
... | ... | |
500 | 500 |
} |
501 | 501 |
|
502 | 502 |
$::form->{id} = $self->order->id; # this is used in SL::Mailer to create a linked record to the mail |
503 |
$::form->send_email(\%::myconfig, 'pdf');
|
|
503 |
$::form->send_email(\%::myconfig, $::form->{print_options}->{format});
|
|
504 | 504 |
|
505 | 505 |
# internal notes |
506 | 506 |
my $intnotes = $self->order->intnotes; |
... | ... | |
1885 | 1885 |
no_queue => 1, |
1886 | 1886 |
no_postscript => 1, |
1887 | 1887 |
no_opendocument => 0, |
1888 |
no_html => 1},
|
|
1888 |
no_html => 0},
|
|
1889 | 1889 |
); |
1890 | 1890 |
|
1891 | 1891 |
foreach my $item (@{$self->order->orderitems}) { |
... | ... | |
2071 | 2071 |
} |
2072 | 2072 |
} |
2073 | 2073 |
|
2074 |
sub generate_pdf {
|
|
2075 |
my ($self, $pdf_ref, $params) = @_;
|
|
2074 |
sub generate_doc {
|
|
2075 |
my ($self, $doc_ref, $params) = @_;
|
|
2076 | 2076 |
|
2077 | 2077 |
my $order = $self->order; |
2078 | 2078 |
my @errors = (); |
... | ... | |
2094 | 2094 |
if ($print_form->{format} =~ /(opendocument|oasis)/i) { |
2095 | 2095 |
$template_ext = 'odt'; |
2096 | 2096 |
$template_type = 'OpenDocument'; |
2097 |
} elsif ($print_form->{format} =~ m{html}i) { |
|
2098 |
$template_ext = 'html'; |
|
2099 |
$template_type = 'HTML'; |
|
2097 | 2100 |
} |
2098 | 2101 |
|
2099 | 2102 |
# search for the template |
... | ... | |
2115 | 2118 |
eval { |
2116 | 2119 |
$print_form->prepare_for_printing; |
2117 | 2120 |
|
2118 |
$$pdf_ref = SL::Helper::CreatePDF->create_pdf(
|
|
2121 |
$$doc_ref = SL::Helper::CreatePDF->create_pdf(
|
|
2119 | 2122 |
format => $print_form->{format}, |
2120 | 2123 |
template_type => $template_type, |
2121 | 2124 |
template => $template_file, |
... | ... | |
2310 | 2313 |
)->save; |
2311 | 2314 |
} |
2312 | 2315 |
|
2313 |
sub store_pdf_to_webdav_and_filemanagement {
|
|
2316 |
sub store_doc_to_webdav_and_filemanagement {
|
|
2314 | 2317 |
my ($self, $content, $filename) = @_; |
2315 | 2318 |
|
2316 | 2319 |
my $order = $self->order; |
... | ... | |
2330 | 2333 |
$webdav_file->store(data => \$content); |
2331 | 2334 |
1; |
2332 | 2335 |
} or do { |
2333 |
push @errors, t8('Storing PDF to webdav folder failed: #1', $@);
|
|
2336 |
push @errors, t8('Storing the document to the WebDAV folder failed: #1', $@);
|
|
2334 | 2337 |
}; |
2335 | 2338 |
} |
2336 | 2339 |
if ($order->id && $::instance_conf->get_doc_storage) { |
2337 | 2340 |
eval { |
2338 | 2341 |
SL::File->save(object_id => $order->id, |
2339 | 2342 |
object_type => $order->type, |
2340 |
mime_type => 'application/pdf',
|
|
2343 |
mime_type => SL::MIME->mime_type_from_ext($filename),
|
|
2341 | 2344 |
source => 'created', |
2342 | 2345 |
file_type => 'document', |
2343 | 2346 |
file_name => $filename, |
2344 | 2347 |
file_contents => $content); |
2345 | 2348 |
1; |
2346 | 2349 |
} or do { |
2347 |
push @errors, t8('Storing PDF in storage backend failed: #1', $@);
|
|
2350 |
push @errors, t8('Storing the document in the storage backend failed: #1', $@);
|
|
2348 | 2351 |
}; |
2349 | 2352 |
} |
2350 | 2353 |
|
Auch abrufbar als: Unified diff
Order-Controller: Unterstützung für Drucken & E-Mailen von HTML-Vorlagen