Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 34172018

Von Tamino Steinert vor 11 Monaten hinzugefügt

  • ID 34172018b811cea6704d0c242cccf7f311e9f6d7
  • Vorgänger 8635c0d6
  • Nachfolger 6b8d5aea

EmailJournalAttachment: Funktion um Datei zum Beleg hinzufügen

Unterschiede anzeigen:

SL/DB/EmailJournalAttachment.pm
7 7
use SL::DB::Manager::EmailJournalAttachment;
8 8
use SL::DB::Helper::ActsAsList (group_by => [ qw(email_journal_id) ]);
9 9

  
10
use SL::Webdav;
11
use SL::File;
12

  
10 13
__PACKAGE__->meta->initialize;
11 14

  
15
sub add_file_to_record {
16
  my ($self, $record) = @_;
17

  
18
  # copy file to webdav folder
19
  if ($::instance_conf->get_webdav_documents) {
20
    my $record_type = $record->record_type;
21
    # TODO: file and webdav use different types for ap_transaction
22
    $record_type = 'accounts_payable' if $record_type eq 'ap_transaction';
23
    my $webdav = SL::Webdav->new(
24
      type     => $record_type,
25
      number   => $record->record_number,
26
    );
27
    my $webdav_file = SL::Webdav::File->new(
28
      webdav => $webdav,
29
      filename => $self->name,
30
    );
31
    eval {
32
      $webdav_file->store(data => \$self->content);
33
      1;
34
    } or do {
35
      die 'Storing the attachment file to the WebDAV folder failed: ' . $@;
36
    };
37
  }
38
  # copy file to doc storage
39
  if ($::instance_conf->get_doc_storage) {
40
    my $record_type = $record->record_type;
41
    # TODO: file and webdav use different types for ap_invoice
42
    $record_type = 'purchase_invoice' if $record_type eq 'ap_transaction';
43
    eval {
44
      SL::File->save(
45
        object_id     => $record->id,
46
        object_type   => $record_type,
47
        source        => 'uploaded',
48
        file_type     => 'document',
49
        file_name     => $self->name,
50
        file_contents => $self->content,
51
        mime_type     => $self->mime_type,
52
      );
53
      1;
54
    } or do {
55
      die 'Storing the attachment file to the file management failed: ' . $@;
56
    };
57
  }
58

  
59
}
60

  
12 61
1;

Auch abrufbar als: Unified diff