Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 55a27184

Von Tamino Steinert vor 8 Monaten hinzugefügt

  • ID 55a27184f6df83204fc2cedd643de36f79c52506
  • Vorgänger 52e9ef58
  • Nachfolger d3425278

Helper::EmailProcessing: Nutze neue Funktionen

Unterschiede anzeigen:

SL/Helper/EmailProcessing.pm
8 8
use XML::LibXML;
9 9

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

  
14 12
use SL::DB::PurchaseInvoice;
15 13

  
......
51 49
sub _add_attachment_to_record {
52 50
  my ($self, $email_journal, $attachment, $record) = @_;
53 51

  
54
  # link to email journal
55
  $email_journal->link_to_record($record);
56

  
57
  # copy file to webdav folder
58
  if ($::instance_conf->get_webdav_documents) {
59
    my $record_type = $record->record_type;
60
    # TODO: file and webdav use different types for ap_transaction
61
    $record_type = 'accounts_payable' if $record_type eq 'ap_transaction';
62
    my $webdav = SL::Webdav->new(
63
      type     => $record_type,
64
      number   => $record->record_number,
65
    );
66
    my $webdav_file = SL::Webdav::File->new(
67
      webdav => $webdav,
68
      filename => $attachment->name,
69
    );
70
    eval {
71
      $webdav_file->store(data => \$attachment->content);
72
      1;
73
    } or do {
74
      die 'Storing the attachment file to the WebDAV folder failed: ' . $@;
75
    };
76
  }
77
  # copy file to doc storage
78
  if ($::instance_conf->get_doc_storage) {
79
    my $record_type = $record->record_type;
80
    # TODO: file and webdav use different types for ap_invoice
81
    $record_type = 'purchase_invoice' if $record_type eq 'ap_transaction';
82
    eval {
83
      SL::File->save(
84
        object_id     => $record->id,
85
        object_type   => $record_type,
86
        source        => 'uploaded',
87
        file_type     => 'document',
88
        file_name     => $attachment->name,
89
        file_contents => $attachment->content,
90
        mime_type     => $attachment->mime_type,
91
      );
92
      1;
93
    } or do {
94
      die 'Storing the ZUGFeRD file in the storage backend failed: ' . $@;
95
    };
96
  }
97

  
98
  my $new_ext_status = join(' ', $email_journal->extended_status,
99
    'created_record_' . $record->record_type);
100
  $email_journal->update_attributes(extended_status => $new_ext_status);
52
  $attachment->add_file_to_record($record);
101 53

  
102
  # TODO: hardlink in db to email_journal
54
  $email_journal->link_to_record($record);
103 55
}
104 56

  
105 57
1;

Auch abrufbar als: Unified diff