Revision 834abeb4
Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt
SL/Controller/ZUGFeRD.pm | ||
---|---|---|
use SL::Helper::DateTime;
|
||
use SL::VATIDNr;
|
||
use SL::ZUGFeRD;
|
||
use SL::SessionFile;
|
||
|
||
use XML::LibXML;
|
||
|
||
... | ... | |
sub action_upload_zugferd {
|
||
my ($self, %params) = @_;
|
||
|
||
$self->setup_zugferd_action_bar;
|
||
$self->pre_render();
|
||
$self->render('zugferd/form', title => $::locale->text('Factur-X/ZUGFeRD import'));
|
||
}
|
||
|
||
sub action_import_zugferd {
|
||
my ($self, %params) = @_;
|
||
my $file = $::form->{file};
|
||
my $file_name = $::form->{file_name};
|
||
|
||
die t8("missing file for action import") unless $::form->{file};
|
||
die t8("can only parse a pdf file") unless $::form->{file} =~ m/^%PDF/;
|
||
die t8("missing file for action import") unless $file;
|
||
die t8("can only parse a pdf file") unless $file =~ m/^%PDF/;
|
||
|
||
my $info = SL::ZUGFeRD->extract_from_pdf($::form->{file});
|
||
my $info = SL::ZUGFeRD->extract_from_pdf($file);
|
||
|
||
if ($info->{result} != SL::ZUGFeRD::RES_OK()) {
|
||
# An error occurred; log message from parser:
|
||
... | ... | |
my $ibanmessage;
|
||
$ibanmessage = $iban ne $vendor->iban ? "Record IBAN $iban doesn't match vendor IBAN " . $vendor->iban : $iban if $iban;
|
||
|
||
my $url = $self->url_for(
|
||
# save the zugferd file to session file for reuse in ap.pl
|
||
my $session_file = SL::SessionFile->new($file_name, mode => 'w');
|
||
$session_file->fh->print($file);
|
||
$session_file->fh->close;
|
||
|
||
$self->redirect_to(
|
||
controller => 'ap.pl',
|
||
action => 'load_record_template',
|
||
id => $template_ap->id,
|
||
... | ... | |
'form_defaults.paid_1_suggestion' => $::form->format_amount(\%::myconfig, $total, 2),
|
||
'form_defaults.notes' => "ZUGFeRD Import. Type: $type\nIBAN: " . $ibanmessage,
|
||
'form_defaults.taxincluded' => 0,
|
||
'form_defaults.direct_debit' => $direct_debit,
|
||
'form_defaults.direct_debit' => $direct_debit,
|
||
'form_defaults.zugferd_session_file' => $file_name,
|
||
);
|
||
|
||
$self->redirect_to($url);
|
||
|
||
}
|
||
|
||
sub check_auth {
|
||
... | ... | |
}
|
||
}
|
||
|
||
sub pre_render {
|
||
my ($self) = @_;
|
||
|
||
$::request->{layout}->use_javascript("${_}.js") for qw(
|
||
kivi.ZUGFeRD
|
||
);
|
||
|
||
$self->setup_zugferd_action_bar;
|
||
}
|
||
|
||
|
||
1;
|
||
__END__
|
bin/mozilla/ap.pl | ||
---|---|---|
$form->{what_done} = "invoice";
|
||
$form->save_history;
|
||
}
|
||
# save zugferd file
|
||
my $file_name = delete $form->{zugferd_session_file};
|
||
if ($file_name) {
|
||
my $file = SL::SessionFile->new($file_name, mode => '<');
|
||
if (!$file->fh) {
|
||
SL::Helper::Flash::flash_later('error',
|
||
t8('Could not open ZUGFeRD file for reading: #1', $@));
|
||
} else {
|
||
|
||
# copy file to webdav folder
|
||
if ($form->{invnumber} && $::instance_conf->get_webdav_documents) {
|
||
my $webdav = SL::Webdav->new(
|
||
type => 'accounts_payable',
|
||
number => $form->{invnumber},
|
||
);
|
||
my $webdav_file = SL::Webdav::File->new(
|
||
webdav => $webdav,
|
||
filename => $file_name,
|
||
);
|
||
eval {
|
||
$webdav_file->store(file => $file->file_name());
|
||
1;
|
||
} or do {
|
||
$form->{zugferd_session_file} = $file_name;
|
||
SL::Helper::Flash::flash_later('error',
|
||
t8('Storing the ZUGFeRD file to the WebDAV folder failed: #1', $@));
|
||
};
|
||
}
|
||
if ($form->{id} && $::instance_conf->get_doc_storage) {
|
||
eval {
|
||
SL::File->save(
|
||
object_id => $form->{id},
|
||
object_type => 'purchase_invoice',
|
||
mime_type => 'application/pdf',
|
||
source => 'uploaded',
|
||
file_type => 'document',
|
||
file_name => $file_name,
|
||
file_path => $file->file_name(),
|
||
);
|
||
1;
|
||
} or do {
|
||
$form->{zugferd_session_file} = $file_name;
|
||
SL::Helper::Flash::flash_later('error',
|
||
t8('Storing the ZUGFeRD file in the storage backend failed: #1', $@));
|
||
};
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!$inline) {
|
||
my $msg = $locale->text("AP transaction '#1' posted (ID: #2)", $form->{invnumber}, $form->{id});
|
js/kivi.ZUGFeRD.js | ||
---|---|---|
namespace('kivi.ZUGFeRD', function(ns) {
|
||
ns.update_file_name = function() {
|
||
let file = document.getElementById("file").files[0];
|
||
if (file) {
|
||
document.getElementById("file_name").value = file.name;
|
||
}
|
||
};
|
||
});
|
templates/design40_webpages/ap/form_header.html | ||
---|---|---|
<input type="hidden" name="taxaccounts" value="[% taxaccounts | html %]">
|
||
<input type="hidden" name="rowcount" value="[% rowcount | html %]">
|
||
<input type="hidden" name="paidaccounts" value="[% paidaccounts | html %]">
|
||
[% L.hidden_tag('zugferd_session_file', zugferd_session_file) %]
|
||
|
||
[% P.hidden_tag('convert_from_oe_id', convert_from_oe_id) %]
|
||
|
templates/design40_webpages/zugferd/form.html | ||
---|---|---|
<p>[% "Import a Factur-X/ZUGFeRD file:" | $T8 %]</p>
|
||
|
||
<form method="post" action="controller.pl" enctype="multipart/form-data" id="form">
|
||
[% L.input_tag('file', '', type => 'file', accept => '.pdf') %]
|
||
[% L.input_tag('file', '', type => 'file', accept => '.pdf', onchange='kivi.ZUGFeRD.update_file_name();') %]
|
||
[% L.hidden_tag('file_name', '') %]
|
||
</form>
|
||
|
||
</div>
|
templates/webpages/ap/form_header.html | ||
---|---|---|
<input type="hidden" name="rowcount" value="[% rowcount | html %]">
|
||
|
||
<input type="hidden" name="paidaccounts" value="[% paidaccounts | html %]">
|
||
[% L.hidden_tag('zugferd_session_file', zugferd_session_file) %]
|
||
|
||
[%- P.hidden_tag('convert_from_oe_id', convert_from_oe_id) -%]
|
||
|
templates/webpages/zugferd/form.html | ||
---|---|---|
</p>
|
||
|
||
<form method="post" action="controller.pl" enctype="multipart/form-data" id="form">
|
||
[% L.input_tag('file', '', type => 'file', accept => '.pdf') %]
|
||
[% L.input_tag('file', '', type => 'file', accept => '.pdf', onchange='kivi.ZUGFeRD.update_file_name();') %]
|
||
[% L.hidden_tag('file_name', '') %]
|
||
</form>
|
Auch abrufbar als: Unified diff
ZUGFeRD: speicher ZUGFeRD-Datei zur erstellten Kreditorenbuchung