From dd33cbecc78ee154df73ebf578be8f660af2357c Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 2 Mar 2017 13:50:06 +0100 Subject: [PATCH] ActionBar/Dateimanagement: Verschicken von Dateien via E-Mail wieder implementiert --- SL/Form.pm | 79 ++++++++----------- bin/mozilla/io.pl | 50 ++++++++++-- js/kivi.SalesPurchase.js | 45 ++++++++--- locale/de/all | 9 +++ .../webpages/common/_send_email_dialog.html | 60 +++++++++++++- 5 files changed, 175 insertions(+), 68 deletions(-) diff --git a/SL/Form.pm b/SL/Form.pm index 6f183e90a..ea724b33e 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -1154,56 +1154,43 @@ sub send_email { $mail->{message} .= $_ while ; close(IN); - } else { - $main::lxdebug->message(LXDebug->DEBUG2(),"action_oldfile=" . $self->{action_oldfile}." action_nofile=".$self->{action_nofile}); - if (!$self->{"do_not_attach"} && !$self->{action_nofile}) { - my $attachment_name = $self->{attachment_filename} || $self->{tmpfile}; - $attachment_name =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format); - if ( $self->{action_oldfile} ) { - $main::lxdebug->message(LXDebug->DEBUG2(),"object_id =>". $self->{id}." object_type =>". $self->{formname}); - my ( $attfile ) = SL::File->get_all(object_id => $self->{id}, - object_type => $self->{formname}, - file_type => 'document'); - $main::lxdebug->message(LXDebug->DEBUG2(), "old file obj=".$attfile); - push @attfiles, $attfile if $attfile; - } else { - push @{ $mail->{attachments} }, { path => $self->{tmpfile}, - id => $self->{print_file_id}, - type => "application/pdf", - name => $attachment_name }; + } elsif (($self->{attachment_policy} // '') ne 'no_file') { + my $attachment_name = $self->{attachment_filename} || $self->{tmpfile}; + $attachment_name =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format); + + if (($self->{attachment_policy} // '') eq 'old_file') { + my ( $attfile ) = SL::File->get_all(object_id => $self->{id}, + object_type => $self->{formname}, + file_type => 'document'); + + if ($attfile) { + $attfile->{override_file_name} = $attachment_name if $attachment_name; + push @attfiles, $attfile; } + + } else { + push @{ $mail->{attachments} }, { path => $self->{tmpfile}, + id => $self->{print_file_id}, + type => "application/pdf", + name => $attachment_name }; } } - if (!$self->{"do_not_attach"}) { - for my $i (1 .. $self->{attfile_count}) { - if ( $self->{"attsel_$i"} ) { - my $attfile = SL::File->get(id => $self->{"attfile_$i"}); - $main::lxdebug->message(LXDebug->DEBUG2(), "att file=".$self->{"attfile_$i"}." obj=".$attfile); - push @attfiles, $attfile if $attfile; - } - } - for my $i (1 .. $self->{attfile_cv_count}) { - if ( $self->{"attsel_cv_$i"} ) { - my $attfile = SL::File->get(id => $self->{"attfile_cv_$i"}); - $main::lxdebug->message(LXDebug->DEBUG2(), "att file=".$self->{"attfile_$i"}." obj=".$attfile); - push @attfiles, $attfile if $attfile; - } - } - for my $i (1 .. $self->{attfile_part_count}) { - if ( $self->{"attsel_part_$i"} ) { - my $attfile = SL::File->get(id => $self->{"attfile_part_$i"}); - $main::lxdebug->message(LXDebug->DEBUG2(), "att file=".$self->{"attfile_$i"}." obj=".$attfile); - push @attfiles, $attfile if $attfile; - } - } - foreach my $attfile ( @attfiles ) { - push @{ $mail->{attachments} }, { path => $attfile->get_file, - id => $attfile->id, - type => $attfile->mime_type, - name => $attfile->file_name, - content => $attfile->get_content ? ${ $attfile->get_content } : undef }; - } + + push @attfiles, + grep { $_ } + map { SL::File->get(id => $_) } + @{ $self->{attach_file_ids} // [] }; + + foreach my $attfile ( @attfiles ) { + push @{ $mail->{attachments} }, { + path => $attfile->get_file, + id => $attfile->id, + type => $attfile->mime_type, + name => $attfile->{override_file_name} // $attfile->file_name, + content => $attfile->get_content ? ${ $attfile->get_content } : undef, + }; } + $mail->{message} =~ s/\r//g; $mail->{message} .= $full_signature; $self->{emailerr} = $mail->send(); diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index af912eeb5..e5b88c41c 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -41,6 +41,7 @@ use Carp; use CGI; use List::MoreUtils qw(any uniq apply); use List::Util qw(min max first); +use List::UtilsBy qw(sort_by uniq_by); use SL::ClientJS; use SL::CVar; @@ -1924,6 +1925,37 @@ sub setup_sales_purchase_print_options { ); } +sub _get_files_for_email_dialog { + my %files = map { ($_ => []) } qw(versions files vc_files part_files); + + return %files if !$::instance_conf->get_doc_storage; + + $files{versions} = [ SL::File->get_all_versions(object_id => $::form->{id}, object_type => $::form->{type}, file_type => 'document') ]; + $files{files} = [ SL::File->get_all( object_id => $::form->{id}, object_type => $::form->{type}, file_type => 'attachment') ]; + $files{vc_files} = [ SL::File->get_all( object_id => $::form->{vc_id}, object_type => $::form->{vc}, file_type => 'attachment') ] + if $::form->{vc} && $::form->{"vc_id"}; + + my @parts = + uniq_by { $_->{id} } + grep { $_->{id} } + map { + +{ id => $::form->{"id_$_"}, + partnumber => $::form->{"partnumber_$_"}, + } + } (1 .. $::form->{rowcount}); + + foreach my $part (@parts) { + my @pfiles = SL::File->get_all(object_id => $part->{id}, object_type => 'part'); + push @{ $files{part_files} }, map { +{ %{ $_ }, partnumber => $part->{partnumber} } } @pfiles; + } + + foreach my $key (keys %files) { + $files{$key} = [ sort_by { lc $_->{db_file}->{file_name} } @{ $files{$key} } ]; + } + + return %files; +} + sub show_sales_purchase_email_dialog { my $contact = $::form->{cp_id} ? SL::DB::Contact->load_cached($::form->{cp_id}) : undef; my $email_form = { @@ -1932,9 +1964,12 @@ sub show_sales_purchase_email_dialog { attachment_filename => $::form->generate_attachment_filename, }; - my $html = $::form->parse_html_template("common/_send_email_dialog", { - email_form => $email_form, - show_bcc => $::auth->assert('email_bcc', 'may fail'), + my %files = _get_files_for_email_dialog(); + my $html = $::form->parse_html_template("common/_send_email_dialog", { + email_form => $email_form, + show_bcc => $::auth->assert('email_bcc', 'may fail'), + FILES => \%files, + is_customer => $::form->{vc} eq 'customer', }); print $::form->ajax_response_header, $html; @@ -1954,8 +1989,13 @@ sub send_sales_purchase_email { $::form->{media} = 'email'; - print_form("return"); - Common->save_email_status(\%::myconfig, $::form); + if (($::form->{attachment_policy} // '') =~ m{^(?:old_file|no_file)$}) { + $::form->send_email(\%::myconfig, 'pdf'); + + } else { + print_form("return"); + Common->save_email_status(\%::myconfig, $::form); + } flash_later('info', $::locale->text('The email has been sent.')); diff --git a/js/kivi.SalesPurchase.js b/js/kivi.SalesPurchase.js index 2fcd2132e..7637129f6 100644 --- a/js/kivi.SalesPurchase.js +++ b/js/kivi.SalesPurchase.js @@ -268,23 +268,36 @@ namespace('kivi.SalesPurchase', function(ns) { this.show_email_dialog = function(send_action) { $('#form').data('send-email-action', send_action || 'send_sales_purchase_email'); + var vc = $('#vc').val(); + var data = { + action: 'show_sales_purchase_email_dialog', + cp_id: $('#cp_id').val(), + donumber: $('#donumber').val(), + format: $('#format').val(), + formname: $('#formname').val(), + id: $('#id').val(), + invnumber: $('#invnumber').val(), + language_id: $('#language_id').val(), + media: 'email', + ordnumber: $('#ordnumber').val(), + rowcount: $('#rowcount').val(), + quonumber: $('#quonumber').val(), + type: $('#type').val(), + vc: vc, + vc_id: $('#' + vc + '_id').val(), + }; + + $('[name^=id_],[name^=partnumber_]').each(function(idx, elt) { + var val = $(elt).val() || ''; + if (val !== '') + data[ $(elt).attr('name') ] = val; + }); + kivi.popup_dialog({ id: 'send_email_dialog', url: 'io.pl', load: kivi.SalesPurchase.setup_send_email_dialog, - data: { - action: 'show_sales_purchase_email_dialog', - type: $('#type').val(), - formname: $('#formname').val(), - format: $('#format').val(), - media: 'email', - ordnumber: $('#ordnumber').val(), - donumber: $('#donumber').val(), - invnumber: $('#invnumber').val(), - quonumber: $('#quonumber').val(), - cp_id: $('#cp_id').val(), - language_id: $('#language_id').val(), - }, + data: data, dialog: { height: 600, title: kivi.t8('Send email'), @@ -295,6 +308,12 @@ namespace('kivi.SalesPurchase', function(ns) { return true; }; + this.activate_send_email_actions_regarding_printout = function() { + var selected = $('#email_form_attachment_policy').val(); + $('#email_form_attachment_filename').parents('tr')[selected !== 'no_file' ? 'show' : 'hide'](); + $('#email_form_print_options')[selected === 'normal' ? 'show' : 'hide'](); + }; + // Printing records. this.setup_print_dialog = function() { kivi.SalesPurchase.show_all_print_options_elements(); diff --git a/locale/de/all b/locale/de/all index 1a11d774c..41496079c 100755 --- a/locale/de/all +++ b/locale/de/all @@ -702,6 +702,7 @@ $self->{texts} = { 'Create and print invoices' => 'Rechnungen erzeugen und ausdrucken', 'Create and print invoices for all delivery orders matching the filter' => 'Rechnungen für alle den Suchkriterien entsprechenden Lieferscheine erzeugen und ausdrucken', 'Create and print invoices for all selected delivery orders' => 'Rechnungen für alle Lieferscheine erzeugen und ausdrucken', + 'Create and send a new printout for this record' => 'Neuen Belegausdruck erstellen und verschicken', 'Create bank collection' => 'Bankeinzug erstellen', 'Create bank collection via SEPA XML' => 'Bankeinzug via SEPA XML erstellen', 'Create bank transfer' => 'Überweisung erstellen', @@ -1013,6 +1014,8 @@ $self->{texts} = { 'Documentation (in German)' => 'Dokumentation', 'Documents' => 'Dokumente', 'Documents in the WebDAV repository' => 'Dokumente im WebDAV-Repository', + 'Don\'t include a printout of the record with the email' => 'Keinen Belegausdruck mit E-Mail schicken', + 'Don\'t include a printout of the record with the email, only selected files' => 'Keinen Belegausdruck mit E-Mail schicken, sondern nur ausgewählte Dateien', 'Done' => 'Fertig', 'Done.' => 'Fertig.', 'Double partnumbers' => 'Doppelte Artikelnummern', @@ -1327,6 +1330,9 @@ $self->{texts} = { 'Filemanagement' => 'Dateimanagement', 'Filename' => 'Dateiname', 'Files' => 'Dateien', + 'Files from customer' => 'Kundendateien', + 'Files from parts' => 'Artikeldateien', + 'Files from vendor' => 'Lieferantendateien', 'Filter' => 'Filter', 'Filter by Partsgroups' => 'Nach Warengruppen filtern', 'Filter date by' => 'Datum filtern nach', @@ -2350,6 +2356,7 @@ $self->{texts} = { 'Record number' => 'Belegnummer', 'Record templates' => 'Belegvorlagen', 'Record type to create' => 'Anzulegender Belegtyp', + 'Record\'s files' => 'Belegdateien', 'Recorded Tax' => 'Gespeicherte Steuern', 'Recorded taxkey' => 'Gespeicherter Steuerschlüssel', 'Reduced Master Data' => 'Abschlag', @@ -2585,6 +2592,8 @@ $self->{texts} = { 'Send a blind copy of all outgoing emails to current user\'s email address?' => 'Eine blinde Kopie aller ausgehenden E-Mails wird an den angemeldeten Nutzer geschickt', 'Send email' => 'E-Mail verschicken', 'Send invoice via email' => 'Rechnung via E-Mail verschicken', + 'Send printout of record' => 'Belegausdruck mitschicken', + 'Send the last printout created for this record' => 'Den zuletzt erstellen Belegausdruck mitschicken', 'Sender' => 'AbsenderIn', 'Sending E-mail: ' => 'E-Mail versenden: ', 'Sent emails can be optionally stored in the database with or without their attachments.' => 'Gesendete E-Mails können optional mit oder ohne ihre Anhänge in der Datenbank gespeichert werden.', diff --git a/templates/webpages/common/_send_email_dialog.html b/templates/webpages/common/_send_email_dialog.html index c45313ba7..51565a6f3 100644 --- a/templates/webpages/common/_send_email_dialog.html +++ b/templates/webpages/common/_send_email_dialog.html @@ -1,4 +1,23 @@ -[%- USE HTML %][%- USE LxERP -%][%- USE L -%] +[%- USE HTML %][%- USE LxERP -%][%- USE L -%][%- USE P -%] +[%- SET have_files = 0 %] + +[% BLOCK attach_file_list %] + [% IF files.as_list.size %] + [% SET have_files = 1 ; + FOREACH file = files.as_list %] + + + [% IF loop.first %] + [% label %] + [% END %] + + + [% P.checkbox_tag("email_form.attach_file_ids[]", label=file.db_file.file_name, value=file.db_file.id, checked="1") %] + + + [% END %] + [% END %] +[% END %] @@ -8,8 +27,8 @@ @@ -35,10 +54,43 @@ +[% IF INSTANCE_CONF.get_doc_storage %] + + + + +[% END %] + - + + +[% IF INSTANCE_CONF.get_doc_storage %] + [% PROCESS attach_file_list + files = FILES.files + label = LxERP.t8("Record's files") %] + + [% PROCESS attach_file_list + files = FILES.vc_files + label = is_customer ? LxERP.t8("Files from customer") : LxERP.t8("Files from vendor") %] + + [% PROCESS attach_file_list + files = FILES.part_files + label = LxERP.t8("Files from parts") %] +[% END %]
[% L.input_tag("email_form.to", email_form.to, size="80") %] - [% L.link("#", "[+]", onclick="\$('[data-toggle-recipients=1]').toggle()", "data-toggle-recipients"="1") %] - [% L.link("#", "[-]", onclick="\$('[data-toggle-recipients=1]').toggle()", "data-toggle-recipients"="1", class="hidden") %] + [+] +
[% L.textarea_tag("email_form.message", email_form.message, rows="15" cols="80" wrap="soft") %]
[% LxERP.t8("Send printout of record") %] + [% SET no_file_label = have_files ? LxERP.t8("Don't include a printout of the record with the email, only selected files") : LxERP.t8("Don't include a printout of the record with the email") ; + options = [ + [ "normal", LxERP.t8("Create and send a new printout for this record") ], + [ "old_file", LxERP.t8("Send the last printout created for this record") ], + [ "no_file", no_file_label ], + ] ; + L.select_tag("email_form.attachment_policy", options, onchange="kivi.SalesPurchase.activate_send_email_actions_regarding_printout()") %] +
[% LxERP.t8("Attachment name") %] +[% IF !INSTANCE_CONF.get_doc_storage %] + [% LxERP.t8("Attachment name") %] +[% END %] + [% L.input_tag("email_form.attachment_filename", email_form.attachment_filename, size="80") %]
-- 2.20.1