kivitendo/SL/DB/EmailJournalAttachment.pm @ 7b1da9c3
24ab7ec0 | Moritz Bunkus | package SL::DB::EmailJournalAttachment;
|
||
use strict;
|
||||
use SL::DB::MetaSetup::EmailJournalAttachment;
|
||||
use SL::DB::Manager::EmailJournalAttachment;
|
||||
use SL::DB::Helper::ActsAsList (group_by => [ qw(email_journal_id) ]);
|
||||
2064c057 | Tamino Steinert | use SL::Webdav;
|
||
use SL::File;
|
||||
24ab7ec0 | Moritz Bunkus | __PACKAGE__->meta->initialize;
|
||
2064c057 | Tamino Steinert | sub add_file_to_record {
|
||
my ($self, $record) = @_;
|
||||
# copy file to webdav folder
|
||||
if ($::instance_conf->get_webdav_documents) {
|
||||
my $record_type = $record->record_type;
|
||||
0cf1c8d8 | Tamino Steinert | # TODO: file and webdav use different types
|
||
2064c057 | Tamino Steinert | $record_type = 'accounts_payable' if $record_type eq 'ap_transaction';
|
||
6b4a061d | Tamino Steinert | $record_type = 'invoice' if $record_type eq 'ar_transaction';
|
||
6dc75be3 | Tamino Steinert | $record_type = 'general_ledger' if $record_type eq 'gl_transaction';
|
||
0cf1c8d8 | Tamino Steinert | $record_type = 'invoice' if $record_type eq 'invoice_storno';
|
||
8bb63908 | Tamino Steinert | $record_type = 'purchase_invoice' if $record_type eq 'purchase_credit_note';
|
||
2064c057 | Tamino Steinert | my $webdav = SL::Webdav->new(
|
||
type => $record_type,
|
||||
number => $record->record_number,
|
||||
);
|
||||
my $webdav_file = SL::Webdav::File->new(
|
||||
webdav => $webdav,
|
||||
filename => $self->name,
|
||||
);
|
||||
eval {
|
||||
$webdav_file->store(data => \$self->content);
|
||||
1;
|
||||
} or do {
|
||||
die 'Storing the attachment file to the WebDAV folder failed: ' . $@;
|
||||
};
|
||||
}
|
||||
# copy file to doc storage
|
||||
if ($::instance_conf->get_doc_storage) {
|
||||
my $record_type = $record->record_type;
|
||||
0cf1c8d8 | Tamino Steinert | # TODO: file and webdav use different types
|
||
2064c057 | Tamino Steinert | $record_type = 'purchase_invoice' if $record_type eq 'ap_transaction';
|
||
8bb63908 | Tamino Steinert | $record_type = 'purchase_invoice' if $record_type eq 'purchase_credit_note';
|
||
0cf1c8d8 | Tamino Steinert | $record_type = 'invoice' if $record_type eq 'ar_transaction';
|
||
$record_type = 'invoice' if $record_type eq 'invoice_storno';
|
||||
2064c057 | Tamino Steinert | eval {
|
||
SL::File->save(
|
||||
object_id => $record->id,
|
||||
object_type => $record_type,
|
||||
source => 'uploaded',
|
||||
file_type => 'document',
|
||||
file_name => $self->name,
|
||||
file_contents => $self->content,
|
||||
mime_type => $self->mime_type,
|
||||
);
|
||||
1;
|
||||
} or do {
|
||||
die 'Storing the attachment file to the file management failed: ' . $@;
|
||||
};
|
||||
}
|
||||
}
|
||||
24ab7ec0 | Moritz Bunkus | 1;
|