From: Moritz Bunkus Date: Fri, 10 Dec 2021 09:52:10 +0000 (+0100) Subject: Order-Controller: Unterstützung für Drucken & E-Mailen von HTML-Vorlagen X-Git-Tag: kivitendo-mebil_0.1-0~10^2~2^2~271 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=30b8dc1025aad59401d2648d0a39776bcb084c85;p=kivitendo-erp.git Order-Controller: Unterstützung für Drucken & E-Mailen von HTML-Vorlagen --- diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 8361ee5a0..81f15e1d0 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -280,8 +280,8 @@ sub action_print { my $groupitems = $::form->{print_options}->{groupitems}; my $printer_id = $::form->{print_options}->{printer_id}; - # only pdf and opendocument by now - if (none { $format eq $_ } qw(pdf opendocument opendocument_pdf)) { + # only PDF, OpenDocument & HTML for now + if (none { $format eq $_ } qw(pdf opendocument opendocument_pdf html)) { return $self->js->flash('error', t8('Format \'#1\' is not supported yet/anymore.', $format))->render; } @@ -297,25 +297,25 @@ sub action_print { $form->{format} = $format; $form->{formname} = $formname; $form->{language} = '_' . $self->order->language->template_code if $self->order->language; - my $pdf_filename = $form->generate_attachment_filename(); + my $doc_filename = $form->generate_attachment_filename(); - my $pdf; - my @errors = $self->generate_pdf(\$pdf, { format => $format, + my $doc; + my @errors = $self->generate_doc(\$doc, { format => $format, formname => $formname, language => $self->order->language, printer_id => $printer_id, groupitems => $groupitems }); if (scalar @errors) { - return $self->js->flash('error', t8('Conversion to PDF failed: #1', $errors[0]))->render; + return $self->js->flash('error', t8('Generating the document failed: #1', $errors[0]))->render; } if ($media eq 'screen') { # screen/download - $self->js->flash('info', t8('The PDF has been created')); + $self->js->flash('info', t8('The document has been created.')); $self->send_file( - \$pdf, - type => SL::MIME->mime_type_from_ext($pdf_filename), - name => $pdf_filename, + \$doc, + type => SL::MIME->mime_type_from_ext($doc_filename), + name => $doc_filename, js_no_render => 1, ); @@ -324,13 +324,13 @@ sub action_print { my $printer_id = $::form->{print_options}->{printer_id}; SL::DB::Printer->new(id => $printer_id)->load->print_document( copies => $copies, - content => $pdf, + content => $doc, ); - $self->js->flash('info', t8('The PDF has been printed')); + $self->js->flash('info', t8('The document has been printed.')); } - my @warnings = $self->store_pdf_to_webdav_and_filemanagement($pdf, $pdf_filename); + my @warnings = $self->store_doc_to_webdav_and_filemanagement($doc, $doc_filename); if (scalar @warnings) { $self->js->flash('warning', $_) for @warnings; } @@ -367,7 +367,7 @@ sub action_preview_pdf { my $pdf_filename = $form->generate_attachment_filename(); my $pdf; - my @errors = $self->generate_pdf(\$pdf, { format => $format, + my @errors = $self->generate_doc(\$pdf, { format => $format, formname => $formname, language => $self->order->language, }); @@ -475,24 +475,24 @@ sub action_send_email { $::form->{media} = 'email'; if (($::form->{attachment_policy} // '') !~ m{^(?:old_file|no_file)$}) { - my $pdf; - my @errors = $self->generate_pdf(\$pdf, {media => $::form->{media}, + my $doc; + my @errors = $self->generate_doc(\$doc, {media => $::form->{media}, format => $::form->{print_options}->{format}, formname => $::form->{print_options}->{formname}, language => $self->order->language, printer_id => $::form->{print_options}->{printer_id}, groupitems => $::form->{print_options}->{groupitems}}); if (scalar @errors) { - return $self->js->flash('error', t8('Conversion to PDF failed: #1', $errors[0]))->render($self); + return $self->js->flash('error', t8('Generating the document failed: #1', $errors[0]))->render($self); } - my @warnings = $self->store_pdf_to_webdav_and_filemanagement($pdf, $::form->{attachment_filename}); + my @warnings = $self->store_doc_to_webdav_and_filemanagement($doc, $::form->{attachment_filename}); if (scalar @warnings) { flash_later('warning', $_) for @warnings; } my $sfile = SL::SessionFile::Random->new(mode => "w"); - $sfile->fh->print($pdf); + $sfile->fh->print($doc); $sfile->fh->close; $::form->{tmpfile} = $sfile->file_name; @@ -500,7 +500,7 @@ sub action_send_email { } $::form->{id} = $self->order->id; # this is used in SL::Mailer to create a linked record to the mail - $::form->send_email(\%::myconfig, 'pdf'); + $::form->send_email(\%::myconfig, $::form->{print_options}->{format}); # internal notes my $intnotes = $self->order->intnotes; @@ -1885,7 +1885,7 @@ sub pre_render { no_queue => 1, no_postscript => 1, no_opendocument => 0, - no_html => 1}, + no_html => 0}, ); foreach my $item (@{$self->order->orderitems}) { @@ -2071,8 +2071,8 @@ sub setup_edit_action_bar { } } -sub generate_pdf { - my ($self, $pdf_ref, $params) = @_; +sub generate_doc { + my ($self, $doc_ref, $params) = @_; my $order = $self->order; my @errors = (); @@ -2094,6 +2094,9 @@ sub generate_pdf { if ($print_form->{format} =~ /(opendocument|oasis)/i) { $template_ext = 'odt'; $template_type = 'OpenDocument'; + } elsif ($print_form->{format} =~ m{html}i) { + $template_ext = 'html'; + $template_type = 'HTML'; } # search for the template @@ -2115,7 +2118,7 @@ sub generate_pdf { eval { $print_form->prepare_for_printing; - $$pdf_ref = SL::Helper::CreatePDF->create_pdf( + $$doc_ref = SL::Helper::CreatePDF->create_pdf( format => $print_form->{format}, template_type => $template_type, template => $template_file, @@ -2310,7 +2313,7 @@ sub save_history { )->save; } -sub store_pdf_to_webdav_and_filemanagement { +sub store_doc_to_webdav_and_filemanagement { my ($self, $content, $filename) = @_; my $order = $self->order; @@ -2330,21 +2333,21 @@ sub store_pdf_to_webdav_and_filemanagement { $webdav_file->store(data => \$content); 1; } or do { - push @errors, t8('Storing PDF to webdav folder failed: #1', $@); + push @errors, t8('Storing the document to the WebDAV folder failed: #1', $@); }; } if ($order->id && $::instance_conf->get_doc_storage) { eval { SL::File->save(object_id => $order->id, object_type => $order->type, - mime_type => 'application/pdf', + mime_type => SL::MIME->mime_type_from_ext($filename), source => 'created', file_type => 'document', file_name => $filename, file_contents => $content); 1; } or do { - push @errors, t8('Storing PDF in storage backend failed: #1', $@); + push @errors, t8('Storing the document in the storage backend failed: #1', $@); }; } diff --git a/js/kivi.Order.js b/js/kivi.Order.js index 7c97a97e4..729407274 100644 --- a/js/kivi.Order.js +++ b/js/kivi.Order.js @@ -96,6 +96,9 @@ namespace('kivi.Order', function(ns) { $('#print_options_form table').first().remove().appendTo('#email_form_print_options'); + $('select#format').change(kivi.Order.adjust_email_attachment_name_for_template_format); + kivi.Order.adjust_email_attachment_name_for_template_format(); + var to_focus = $('#email_form_to').val() === '' ? 'to' : 'subject'; $('#email_form_' + to_focus).focus(); }; @@ -155,6 +158,20 @@ namespace('kivi.Order', function(ns) { email_dialog.dialog("close"); }; + ns.adjust_email_attachment_name_for_template_format = function() { + var $filename_elt = $('#email_form_attachment_filename'); + var $format_elt = $('select#format'); + + if (!$filename_elt || !$format_elt) + return; + + var format = $format_elt.val().toLowerCase(); + var new_ext = format == 'html' ? 'html' : format == 'opendocument' ? 'odt' : 'pdf'; + var filename = $filename_elt.val(); + + $filename_elt.val(filename.replace(/[^.]+$/, new_ext)); + }; + ns.set_number_in_title = function(elt) { $('#nr_in_title').html($(elt).val()); }; diff --git a/locale/de/all b/locale/de/all index 11d51a17c..5a66718a9 100755 --- a/locale/de/all +++ b/locale/de/all @@ -1622,6 +1622,7 @@ $self->{texts} = { 'General ledger transactions can only be changed on the day they are posted.' => 'Dialogbuchungen können nur am Buchungstag geändert werden.', 'General settings' => 'Allgemeine Einstellungen', 'Generate and print sales delivery orders' => 'Erzeuge und drucke Lieferscheine', + 'Generating the document failed: #1' => 'Das Dokument konnte nicht erzeugt werden: #1', 'Germany' => 'Deutschland', 'Get one order' => 'Hole eine Bestellung', 'Get one order by shopordernumber' => 'Hole eine Bestellung über Shopbestellnummer', @@ -3261,6 +3262,8 @@ $self->{texts} = { 'Storage Type for shopimages' => 'Speichertyp für Shopbilder', 'Storing PDF in storage backend failed: #1' => 'Speichern der PDF-Datei im Datei-Speicher fehlgeschlagen: #1', 'Storing PDF to webdav folder failed: #1' => 'Speichern der PDF im WebDAV Ordner fehlgeschlagen: #1', + 'Storing the document in the storage backend failed: #1' => 'Das Ablegen des Dokuments im Dokumentenspeicher schlug fehl: #1', + 'Storing the document to the WebDAV folder failed: #1' => 'Das Ablegen des Dokuments im WebDAV-Ordner schlug fehl: #1', 'Storing the emails in the journal is currently disabled in the client configuration.' => 'Das Speichern von versendeten E-Mails ist derzeit in der Mandantenkonfigurierung abgeschaltet.', 'Storno' => 'Storno', 'Storno (one letter abbreviation)' => 'S', @@ -3510,6 +3513,8 @@ $self->{texts} = { 'The display of (mainly) picker results can be configured. To insert the value of one option use <%Name%>.' => 'Die Anzeigenamen von (hauptsächlich) Auswahl-Ergebnissen (Picker) können konfiguriert werden. Um einen Wert einer Option in die Anzeige aufzunehmen, verwenden Sie <%Name%>.', 'The document has been changed by another user. No mail was sent. Please reopen it in another window and copy the changes to the new window' => 'Die Daten wurden bereits von einem anderen Benutzer verändert. Deshalb ist das Dokument ungültig und es wurde keine E-Mail verschickt. Bitte öffnen Sie das Dokument erneut in einem extra Fenster und übertragen Sie die Daten', 'The document has been changed by another user. Please reopen it in another window and copy the changes to the new window' => 'Die Daten wurden bereits von einem anderen Benutzer verändert. Deshalb ist das Dokument ungültig. Bitte öffnen Sie das Dokument erneut in einem extra Fenster und übertragen Sie die Daten', + 'The document has been created.' => 'Das Dokument wurde erzeugt.', + 'The document has been printed.' => 'Das Dokument wurde gedruckt.', 'The documents have been sent to the printer \'#1\'.' => 'Die Dokumente sind zum Drucker \'#1\' geschickt', 'The dunnings have been printed.' => 'Die Mahnung(en) wurden gedruckt.', 'The email has been sent.' => 'Die E-Mail wurde verschickt.',