1 package SL::DB::EmailJournalAttachment;
5 use SL::DB::MetaSetup::EmailJournalAttachment;
6 use SL::DB::Manager::EmailJournalAttachment;
7 use SL::DB::Helper::ActsAsList (group_by => [ qw(email_journal_id) ]);
12 __PACKAGE__->meta->initialize;
14 sub add_file_to_record {
15 my ($self, $record) = @_;
17 # copy file to webdav folder
18 if ($::instance_conf->get_webdav_documents) {
19 my $record_type = $record->record_type;
20 # TODO: file and webdav use different types
21 $record_type = 'accounts_payable' if $record_type eq 'ap_transaction';
22 $record_type = 'invoice' if $record_type eq 'ar_transaction';
23 $record_type = 'general_ledger' if $record_type eq 'gl_transaction';
24 $record_type = 'invoice' if $record_type eq 'invoice_storno';
25 $record_type = 'purchase_invoice' if $record_type eq 'purchase_credit_note';
26 my $webdav = SL::Webdav->new(
28 number => $record->record_number,
30 my $webdav_file = SL::Webdav::File->new(
32 filename => $self->name,
35 $webdav_file->store(data => \$self->content);
38 die 'Storing the attachment file to the WebDAV folder failed: ' . $@;
41 # copy file to doc storage
42 if ($::instance_conf->get_doc_storage) {
43 my $record_type = $record->record_type;
44 # TODO: file and webdav use different types
45 $record_type = 'purchase_invoice' if $record_type eq 'ap_transaction';
46 $record_type = 'purchase_invoice' if $record_type eq 'purchase_credit_note';
47 $record_type = 'invoice' if $record_type eq 'ar_transaction';
48 $record_type = 'invoice' if $record_type eq 'invoice_storno';
51 object_id => $record->id,
52 object_type => $record_type,
54 file_type => 'document',
55 file_name => $self->name,
56 file_contents => $self->content,
57 mime_type => $self->mime_type,
61 die 'Storing the attachment file to the file management failed: ' . $@;