Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 0eaaf55c

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID 0eaaf55c4e550eb173547c98d66b1a818cddeda3
  • Vorgänger a6c95ed0
  • Nachfolger db6f9544

EmailJournal: ZUGFeRD-Emailanhänge in Kreditorenbuchen konvertieren

Unterschiede anzeigen:

SL/DB/EmailJournal.pm
use strict;
use SL::Webdav;
use SL::File;
use SL::DB::MetaSetup::EmailJournal;
use SL::DB::Manager::EmailJournal;
use SL::DB::Helper::AttrSorted;
use SL::DB::Helper::LinkedRecords;
__PACKAGE__->meta->add_relationship(
attachments => {
......
return $result || ($self->id <=> $other->id);
}
sub process_attachments_as_purchase_invoices {
my ($self) = @_;
my $attachments = $self->attachments_sorted;
foreach my $attachment (@$attachments) {
my $ap_invoice = $attachment->create_ap_invoice();
next unless $ap_invoice;
# link to email journal
$self->link_to_record($ap_invoice);
# copy file to webdav folder
if ($::instance_conf->get_webdav_documents) {
my $webdav = SL::Webdav->new(
type => 'accounts_payable',
number => $ap_invoice->invnumber,
);
my $webdav_file = SL::Webdav::File->new(
webdav => $webdav,
filename => $attachment->name,
);
eval {
$webdav_file->store(data => \$attachment->content);
1;
} or do {
die 'Storing the ZUGFeRD file to the WebDAV folder failed: ' . $@;
};
}
# copy file to doc storage
if ($::instance_conf->get_doc_storage) {
eval {
SL::File->save(
object_id => $ap_invoice->id,
object_type => 'purchase_invoice',
mime_type => 'application/pdf',
source => 'uploaded',
file_type => 'document',
file_name => $attachment->name,
file_contents => $attachment->content,
);
1;
} or do {
die 'Storing the ZUGFeRD file in the storage backend failed: ' . $@;
};
}
}
my $new_ext_status = join('_', $self->extended_status, 'processed');
$self->update({ extended_status => $new_ext_status});
}
1;
__END__
SL/DB/EmailJournalAttachment.pm
use strict;
use XML::LibXML;
use SL::ZUGFeRD;
use SL::DB::PurchaseInvoice;
use SL::DB::MetaSetup::EmailJournalAttachment;
use SL::DB::Manager::EmailJournalAttachment;
use SL::DB::Helper::ActsAsList (group_by => [ qw(email_journal_id) ]);
__PACKAGE__->meta->initialize;
sub create_ap_invoice {
my ($self) = @_;
my $content = $self->content; # scalar ref
return unless $content =~ m/^%PDF/;
my $zugferd_info = SL::ZUGFeRD->extract_from_pdf($content);
return unless $zugferd_info->{result} == SL::ZUGFeRD::RES_OK();
my $zugferd_xml = XML::LibXML->load_xml(string => $zugferd_info->{invoice_xml});
return SL::DB::PurchaseInvoice->create_from_zugferd_xml($zugferd_xml)->save();
}
1;

Auch abrufbar als: Unified diff