Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision dd33cbec

Von Moritz Bunkus vor etwa 8 Jahren hinzugefügt

  • ID dd33cbecc78ee154df73ebf578be8f660af2357c
  • Vorgänger 66b2b0ed
  • Nachfolger 4825c38f

ActionBar/Dateimanagement: Verschicken von Dateien via E-Mail wieder implementiert

Unterschiede anzeigen:

SL/Form.pm
$mail->{message} .= $_ while <IN>;
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();
bin/mozilla/io.pl
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;
......
);
}
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 = {
......
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;
......
$::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.'));
js/kivi.SalesPurchase.js
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'),
......
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();
locale/de/all
'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',
......
'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',
......
'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',
......
'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',
......
'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.',
templates/webpages/common/_send_email_dialog.html
[%- 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 %]
<tr>
<th align="right" nowrap>
[% IF loop.first %]
[% label %]
[% END %]
</th>
<td>
[% P.checkbox_tag("email_form.attach_file_ids[]", label=file.db_file.file_name, value=file.db_file.id, checked="1") %]
</td>
</tr>
[% END %]
[% END %]
[% END %]
<table>
<tbody>
......
</th>
<td>
[% 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") %]
<span class="interactive cursor-pointer" onclick="$('[data-toggle-recipients=1]').toggle()" data-toggle-recipients="1">[+]</span>
<span class="interactive cursor-pointer hidden" onclick="$('[data-toggle-recipients=1]').toggle()" data-toggle-recipients="1">[-]</span>
</td>
</tr>
......
<td>[% L.textarea_tag("email_form.message", email_form.message, rows="15" cols="80" wrap="soft") %]</td>
</tr>
[% IF INSTANCE_CONF.get_doc_storage %]
<tr>
<th align="right" nowrap>[% LxERP.t8("Send printout of record") %]</th>
<td>
[% 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()") %]
</td>
</tr>
[% END %]
<tr>
<th align="right" nowrap>[% LxERP.t8("Attachment name") %]</th>
<th align="right" nowrap>
[% IF !INSTANCE_CONF.get_doc_storage %]
[% LxERP.t8("Attachment name") %]
[% END %]
</th>
<td>[% L.input_tag("email_form.attachment_filename", email_form.attachment_filename, size="80") %]</td>
</tr>
[% 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 %]
</tbody>
</table>

Auch abrufbar als: Unified diff