Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision dd33cbec

Von Moritz Bunkus vor fast 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
1154 1154
    $mail->{message} .= $_ while <IN>;
1155 1155
    close(IN);
1156 1156

  
1157
  } else {
1158
    $main::lxdebug->message(LXDebug->DEBUG2(),"action_oldfile=" . $self->{action_oldfile}." action_nofile=".$self->{action_nofile});
1159
    if (!$self->{"do_not_attach"} && !$self->{action_nofile}) {
1160
      my $attachment_name  =  $self->{attachment_filename}  || $self->{tmpfile};
1161
      $attachment_name     =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format);
1162
      if ( $self->{action_oldfile} ) {
1163
        $main::lxdebug->message(LXDebug->DEBUG2(),"object_id =>". $self->{id}." object_type =>". $self->{formname});
1164
        my ( $attfile ) = SL::File->get_all(object_id   => $self->{id},
1165
                                            object_type => $self->{formname},
1166
                                            file_type   => 'document');
1167
        $main::lxdebug->message(LXDebug->DEBUG2(), "old file obj=".$attfile);
1168
        push @attfiles, $attfile if $attfile;
1169
      } else {
1170
        push @{ $mail->{attachments} }, { path => $self->{tmpfile},
1171
                                          id   => $self->{print_file_id},
1172
                                          type => "application/pdf",
1173
                                          name => $attachment_name };
1157
  } elsif (($self->{attachment_policy} // '') ne 'no_file') {
1158
    my $attachment_name  =  $self->{attachment_filename}  || $self->{tmpfile};
1159
    $attachment_name     =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format);
1160

  
1161
    if (($self->{attachment_policy} // '') eq 'old_file') {
1162
      my ( $attfile ) = SL::File->get_all(object_id   => $self->{id},
1163
                                          object_type => $self->{formname},
1164
                                          file_type   => 'document');
1165

  
1166
      if ($attfile) {
1167
        $attfile->{override_file_name} = $attachment_name if $attachment_name;
1168
        push @attfiles, $attfile;
1174 1169
      }
1170

  
1171
    } else {
1172
      push @{ $mail->{attachments} }, { path => $self->{tmpfile},
1173
                                        id   => $self->{print_file_id},
1174
                                        type => "application/pdf",
1175
                                        name => $attachment_name };
1175 1176
    }
1176 1177
  }
1177
  if (!$self->{"do_not_attach"}) {
1178
    for my $i (1 .. $self->{attfile_count}) {
1179
      if (  $self->{"attsel_$i"} ) {
1180
        my $attfile = SL::File->get(id => $self->{"attfile_$i"});
1181
        $main::lxdebug->message(LXDebug->DEBUG2(), "att file=".$self->{"attfile_$i"}." obj=".$attfile);
1182
        push @attfiles, $attfile if $attfile;
1183
      }
1184
    }
1185
    for my $i (1 .. $self->{attfile_cv_count}) {
1186
      if (  $self->{"attsel_cv_$i"} ) {
1187
        my $attfile = SL::File->get(id => $self->{"attfile_cv_$i"});
1188
        $main::lxdebug->message(LXDebug->DEBUG2(), "att file=".$self->{"attfile_$i"}." obj=".$attfile);
1189
        push @attfiles, $attfile if $attfile;
1190
      }
1191
    }
1192
    for my $i (1 .. $self->{attfile_part_count}) {
1193
      if (  $self->{"attsel_part_$i"} ) {
1194
        my $attfile = SL::File->get(id => $self->{"attfile_part_$i"});
1195
        $main::lxdebug->message(LXDebug->DEBUG2(), "att file=".$self->{"attfile_$i"}." obj=".$attfile);
1196
        push @attfiles, $attfile if $attfile;
1197
      }
1198
    }
1199
    foreach my $attfile ( @attfiles ) {
1200
      push @{ $mail->{attachments} }, { path    => $attfile->get_file,
1201
                                        id      => $attfile->id,
1202
                                        type    => $attfile->mime_type,
1203
                                        name    => $attfile->file_name,
1204
                                        content => $attfile->get_content ? ${ $attfile->get_content } : undef };
1205
    }
1178

  
1179
  push @attfiles,
1180
    grep { $_ }
1181
    map  { SL::File->get(id => $_) }
1182
    @{ $self->{attach_file_ids} // [] };
1183

  
1184
  foreach my $attfile ( @attfiles ) {
1185
    push @{ $mail->{attachments} }, {
1186
      path    => $attfile->get_file,
1187
      id      => $attfile->id,
1188
      type    => $attfile->mime_type,
1189
      name    => $attfile->{override_file_name} // $attfile->file_name,
1190
      content => $attfile->get_content ? ${ $attfile->get_content } : undef,
1191
    };
1206 1192
  }
1193

  
1207 1194
  $mail->{message}  =~ s/\r//g;
1208 1195
  $mail->{message} .= $full_signature;
1209 1196
  $self->{emailerr} = $mail->send();
bin/mozilla/io.pl
41 41
use CGI;
42 42
use List::MoreUtils qw(any uniq apply);
43 43
use List::Util qw(min max first);
44
use List::UtilsBy qw(sort_by uniq_by);
44 45

  
45 46
use SL::ClientJS;
46 47
use SL::CVar;
......
1924 1925
  );
1925 1926
}
1926 1927

  
1928
sub _get_files_for_email_dialog {
1929
  my %files = map { ($_ => []) } qw(versions files vc_files part_files);
1930

  
1931
  return %files if !$::instance_conf->get_doc_storage;
1932

  
1933
  $files{versions} = [ SL::File->get_all_versions(object_id => $::form->{id},    object_type => $::form->{type}, file_type => 'document') ];
1934
  $files{files}    = [ SL::File->get_all(         object_id => $::form->{id},    object_type => $::form->{type}, file_type => 'attachment') ];
1935
  $files{vc_files} = [ SL::File->get_all(         object_id => $::form->{vc_id}, object_type => $::form->{vc},   file_type => 'attachment') ]
1936
    if $::form->{vc} && $::form->{"vc_id"};
1937

  
1938
  my @parts =
1939
    uniq_by { $_->{id} }
1940
    grep    { $_->{id} }
1941
    map     {
1942
      +{ id         => $::form->{"id_$_"},
1943
         partnumber => $::form->{"partnumber_$_"},
1944
       }
1945
    } (1 .. $::form->{rowcount});
1946

  
1947
  foreach my $part (@parts) {
1948
    my @pfiles = SL::File->get_all(object_id => $part->{id}, object_type => 'part');
1949
    push @{ $files{part_files} }, map { +{ %{ $_ }, partnumber => $part->{partnumber} } } @pfiles;
1950
  }
1951

  
1952
  foreach my $key (keys %files) {
1953
    $files{$key} = [ sort_by { lc $_->{db_file}->{file_name} } @{ $files{$key} } ];
1954
  }
1955

  
1956
  return %files;
1957
}
1958

  
1927 1959
sub show_sales_purchase_email_dialog {
1928 1960
  my $contact    = $::form->{cp_id} ? SL::DB::Contact->load_cached($::form->{cp_id}) : undef;
1929 1961
  my $email_form = {
......
1932 1964
    attachment_filename => $::form->generate_attachment_filename,
1933 1965
  };
1934 1966

  
1935
  my $html = $::form->parse_html_template("common/_send_email_dialog", {
1936
    email_form => $email_form,
1937
    show_bcc   => $::auth->assert('email_bcc', 'may fail'),
1967
  my %files = _get_files_for_email_dialog();
1968
  my $html  = $::form->parse_html_template("common/_send_email_dialog", {
1969
    email_form  => $email_form,
1970
    show_bcc    => $::auth->assert('email_bcc', 'may fail'),
1971
    FILES       => \%files,
1972
    is_customer => $::form->{vc} eq 'customer',
1938 1973
  });
1939 1974

  
1940 1975
  print $::form->ajax_response_header, $html;
......
1954 1989

  
1955 1990
  $::form->{media} = 'email';
1956 1991

  
1957
  print_form("return");
1958
  Common->save_email_status(\%::myconfig, $::form);
1992
  if (($::form->{attachment_policy} // '') =~ m{^(?:old_file|no_file)$}) {
1993
    $::form->send_email(\%::myconfig, 'pdf');
1994

  
1995
  } else {
1996
    print_form("return");
1997
    Common->save_email_status(\%::myconfig, $::form);
1998
  }
1959 1999

  
1960 2000
  flash_later('info', $::locale->text('The email has been sent.'));
1961 2001

  
js/kivi.SalesPurchase.js
268 268
  this.show_email_dialog = function(send_action) {
269 269
    $('#form').data('send-email-action', send_action || 'send_sales_purchase_email');
270 270

  
271
    var vc   = $('#vc').val();
272
    var data = {
273
      action:      'show_sales_purchase_email_dialog',
274
      cp_id:       $('#cp_id').val(),
275
      donumber:    $('#donumber').val(),
276
      format:      $('#format').val(),
277
      formname:    $('#formname').val(),
278
      id:          $('#id').val(),
279
      invnumber:   $('#invnumber').val(),
280
      language_id: $('#language_id').val(),
281
      media:       'email',
282
      ordnumber:   $('#ordnumber').val(),
283
      rowcount:    $('#rowcount').val(),
284
      quonumber:   $('#quonumber').val(),
285
      type:        $('#type').val(),
286
      vc:          vc,
287
      vc_id:       $('#' + vc + '_id').val(),
288
    };
289

  
290
    $('[name^=id_],[name^=partnumber_]').each(function(idx, elt) {
291
      var val = $(elt).val() || '';
292
      if (val !== '')
293
        data[ $(elt).attr('name') ] = val;
294
    });
295

  
271 296
    kivi.popup_dialog({
272 297
      id:     'send_email_dialog',
273 298
      url:    'io.pl',
274 299
      load:   kivi.SalesPurchase.setup_send_email_dialog,
275
      data:   {
276
        action:      'show_sales_purchase_email_dialog',
277
        type:        $('#type').val(),
278
        formname:    $('#formname').val(),
279
        format:      $('#format').val(),
280
        media:       'email',
281
        ordnumber:   $('#ordnumber').val(),
282
        donumber:    $('#donumber').val(),
283
        invnumber:   $('#invnumber').val(),
284
        quonumber:   $('#quonumber').val(),
285
        cp_id:       $('#cp_id').val(),
286
        language_id: $('#language_id').val(),
287
      },
300
      data:   data,
288 301
      dialog: {
289 302
        height:      600,
290 303
        title:       kivi.t8('Send email'),
......
295 308
    return true;
296 309
  };
297 310

  
311
  this.activate_send_email_actions_regarding_printout = function() {
312
    var selected = $('#email_form_attachment_policy').val();
313
    $('#email_form_attachment_filename').parents('tr')[selected !== 'no_file' ? 'show' : 'hide']();
314
    $('#email_form_print_options')[selected === 'normal' ? 'show' : 'hide']();
315
  };
316

  
298 317
  // Printing records.
299 318
  this.setup_print_dialog = function() {
300 319
    kivi.SalesPurchase.show_all_print_options_elements();
locale/de/all
702 702
  'Create and print invoices'   => 'Rechnungen erzeugen und ausdrucken',
703 703
  'Create and print invoices for all delivery orders matching the filter' => 'Rechnungen für alle den Suchkriterien entsprechenden Lieferscheine erzeugen und ausdrucken',
704 704
  'Create and print invoices for all selected delivery orders' => 'Rechnungen für alle Lieferscheine erzeugen und ausdrucken',
705
  'Create and send a new printout for this record' => 'Neuen Belegausdruck erstellen und verschicken',
705 706
  'Create bank collection'      => 'Bankeinzug erstellen',
706 707
  'Create bank collection via SEPA XML' => 'Bankeinzug via SEPA XML erstellen',
707 708
  'Create bank transfer'        => 'Überweisung erstellen',
......
1013 1014
  'Documentation (in German)'   => 'Dokumentation',
1014 1015
  'Documents'                   => 'Dokumente',
1015 1016
  'Documents in the WebDAV repository' => 'Dokumente im WebDAV-Repository',
1017
  'Don\'t include a printout of the record with the email' => 'Keinen Belegausdruck mit E-Mail schicken',
1018
  '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',
1016 1019
  'Done'                        => 'Fertig',
1017 1020
  'Done.'                       => 'Fertig.',
1018 1021
  'Double partnumbers'          => 'Doppelte Artikelnummern',
......
1327 1330
  'Filemanagement'              => 'Dateimanagement',
1328 1331
  'Filename'                    => 'Dateiname',
1329 1332
  'Files'                       => 'Dateien',
1333
  'Files from customer'         => 'Kundendateien',
1334
  'Files from parts'            => 'Artikeldateien',
1335
  'Files from vendor'           => 'Lieferantendateien',
1330 1336
  'Filter'                      => 'Filter',
1331 1337
  'Filter by Partsgroups'       => 'Nach Warengruppen filtern',
1332 1338
  'Filter date by'              => 'Datum filtern nach',
......
2350 2356
  'Record number'               => 'Belegnummer',
2351 2357
  'Record templates'            => 'Belegvorlagen',
2352 2358
  'Record type to create'       => 'Anzulegender Belegtyp',
2359
  'Record\'s files'             => 'Belegdateien',
2353 2360
  'Recorded Tax'                => 'Gespeicherte Steuern',
2354 2361
  'Recorded taxkey'             => 'Gespeicherter Steuerschlüssel',
2355 2362
  'Reduced Master Data'         => 'Abschlag',
......
2585 2592
  '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',
2586 2593
  'Send email'                  => 'E-Mail verschicken',
2587 2594
  'Send invoice via email'      => 'Rechnung via E-Mail verschicken',
2595
  'Send printout of record'     => 'Belegausdruck mitschicken',
2596
  'Send the last printout created for this record' => 'Den zuletzt erstellen Belegausdruck mitschicken',
2588 2597
  'Sender'                      => 'AbsenderIn',
2589 2598
  'Sending E-mail: '            => 'E-Mail versenden: ',
2590 2599
  '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
1
[%- USE HTML %][%- USE LxERP -%][%- USE L -%]
1
[%- USE HTML %][%- USE LxERP -%][%- USE L -%][%- USE P -%]
2
[%- SET have_files = 0 %]
3

  
4
[% BLOCK attach_file_list %]
5
  [% IF files.as_list.size %]
6
   [% SET have_files = 1 ;
7
      FOREACH file = files.as_list %]
8
    <tr>
9
     <th align="right" nowrap>
10
      [% IF loop.first %]
11
       [% label %]
12
      [% END %]
13
     </th>
14
     <td>
15
      [% P.checkbox_tag("email_form.attach_file_ids[]", label=file.db_file.file_name, value=file.db_file.id, checked="1") %]
16
     </td>
17
    </tr>
18
   [% END %]
19
  [% END %]
20
[% END %]
2 21

  
3 22
<table>
4 23
 <tbody>
......
8 27
   </th>
9 28
   <td>
10 29
    [% L.input_tag("email_form.to", email_form.to, size="80") %]
11
    [% L.link("#", "[+]", onclick="\$('[data-toggle-recipients=1]').toggle()", "data-toggle-recipients"="1") %]
12
    [% L.link("#", "[-]", onclick="\$('[data-toggle-recipients=1]').toggle()", "data-toggle-recipients"="1", class="hidden") %]
30
    <span class="interactive cursor-pointer"        onclick="$('[data-toggle-recipients=1]').toggle()" data-toggle-recipients="1">[+]</span>
31
    <span class="interactive cursor-pointer hidden" onclick="$('[data-toggle-recipients=1]').toggle()" data-toggle-recipients="1">[-]</span>
13 32
   </td>
14 33
  </tr>
15 34

  
......
35 54
   <td>[% L.textarea_tag("email_form.message", email_form.message, rows="15" cols="80" wrap="soft") %]</td>
36 55
  </tr>
37 56

  
57
[% IF INSTANCE_CONF.get_doc_storage %]
58
  <tr>
59
   <th align="right" nowrap>[% LxERP.t8("Send printout of record") %]</th>
60
   <td>
61
    [% 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") ;
62
           options       = [
63
             [ "normal",   LxERP.t8("Create and send a new printout for this record") ],
64
             [ "old_file", LxERP.t8("Send the last printout created for this record") ],
65
             [ "no_file",  no_file_label ],
66
           ] ;
67
       L.select_tag("email_form.attachment_policy", options, onchange="kivi.SalesPurchase.activate_send_email_actions_regarding_printout()") %]
68
   </td>
69
  </tr>
70
[% END %]
71

  
38 72
  <tr>
39
   <th align="right" nowrap>[% LxERP.t8("Attachment name") %]</th>
73
   <th align="right" nowrap>
74
[% IF !INSTANCE_CONF.get_doc_storage %]
75
    [% LxERP.t8("Attachment name") %]
76
[% END %]
77
   </th>
40 78
   <td>[% L.input_tag("email_form.attachment_filename", email_form.attachment_filename, size="80") %]</td>
41 79
  </tr>
80

  
81
[% IF INSTANCE_CONF.get_doc_storage %]
82
  [% PROCESS attach_file_list
83
             files = FILES.files
84
             label = LxERP.t8("Record's files") %]
85

  
86
  [% PROCESS attach_file_list
87
             files = FILES.vc_files
88
             label = is_customer ? LxERP.t8("Files from customer") : LxERP.t8("Files from vendor") %]
89

  
90
  [% PROCESS attach_file_list
91
             files = FILES.part_files
92
             label = LxERP.t8("Files from parts") %]
93
[% END %]
42 94
 </tbody>
43 95
</table>
44 96

  

Auch abrufbar als: Unified diff