Revision f8138d17
Von Moritz Bunkus vor etwa 16 Jahren hinzugefügt
SL/DATEV.pm | ||
---|---|---|
use SL::DATEV::KNEFile;
|
||
|
||
use Data::Dumper;
|
||
use File::Path;
|
||
use Time::HiRes qw(gettimeofday);
|
||
|
||
sub _get_export_path {
|
||
$main::lxdebug->enter_sub();
|
||
|
||
my ($a, $b) = gettimeofday();
|
||
my $path = get_path_for_download_token("${a}-${b}-${$}");
|
||
|
||
mkpath($path) unless (-d $path);
|
||
|
||
$main::lxdebug->leave_sub();
|
||
|
||
return $path;
|
||
}
|
||
|
||
sub get_path_for_download_token {
|
||
$main::lxdebug->enter_sub();
|
||
|
||
my $token = shift;
|
||
my $path;
|
||
|
||
if ($token =~ m|^(\d+)-(\d+)-(\d+)$|) {
|
||
$path = "${main::userspath}/datev-export-${1}-${2}-${3}";
|
||
}
|
||
|
||
$main::lxdebug->leave_sub();
|
||
|
||
return $path;
|
||
}
|
||
|
||
sub get_download_token_for_path {
|
||
$main::lxdebug->enter_sub();
|
||
|
||
my $path = shift;
|
||
my $token;
|
||
|
||
if ($path =~ m|.*datev-export-(\d+)-(\d+)-(\d+)/?$|) {
|
||
$token = "${1}-${2}-${3}";
|
||
}
|
||
|
||
$main::lxdebug->leave_sub();
|
||
|
||
return $token;
|
||
}
|
||
|
||
sub clean_temporary_directories {
|
||
$main::lxdebug->enter_sub();
|
||
|
||
foreach my $path (glob "${main::userspath}/datev-export-*") {
|
||
next unless (-d $path);
|
||
|
||
my $mtime = (stat($path))[9];
|
||
next if ((time() - $mtime) < 8 * 60 * 60);
|
||
|
||
rmtree $path;
|
||
}
|
||
|
||
$main::lxdebug->leave_sub();
|
||
}
|
||
|
||
sub _fill {
|
||
$main::lxdebug->enter_sub();
|
||
... | ... | |
$main::lxdebug->enter_sub();
|
||
|
||
my ($self, $myconfig, $form) = @_;
|
||
my @rc;
|
||
my $result;
|
||
|
||
if ($form->{exporttype} == 0) {
|
||
@rc = &kne_buchungsexport($myconfig, $form);
|
||
$result = kne_buchungsexport($myconfig, $form);
|
||
} else {
|
||
@rc = &kne_stammdatenexport($myconfig, $form);
|
||
$result = kne_stammdatenexport($myconfig, $form);
|
||
}
|
||
|
||
$main::lxdebug->leave_sub();
|
||
|
||
return @rc;
|
||
return $result;
|
||
}
|
||
|
||
sub obe_export {
|
||
... | ... | |
|
||
my @filenames;
|
||
|
||
my $export_path = $main::userspath . "/";
|
||
my $export_path = _get_export_path() . "/";
|
||
my $filename = "ED00000";
|
||
my $evfile = "EV01";
|
||
my @ed_versionsets;
|
||
... | ... | |
###
|
||
$main::lxdebug->leave_sub();
|
||
|
||
return @filenames;
|
||
return { 'download_token' => get_download_token_for_path($export_path), 'filenames' => \@filenames };
|
||
}
|
||
|
||
sub kne_stammdatenexport {
|
||
... | ... | |
|
||
my @filenames;
|
||
|
||
my $export_path = $main::userspath . "/";
|
||
my $export_path = _get_export_path() . "/";
|
||
my $filename = "ED00000";
|
||
my $evfile = "EV01";
|
||
my @ed_versionsets;
|
||
... | ... | |
|
||
$main::lxdebug->leave_sub();
|
||
|
||
return @filenames;
|
||
return { 'download_token' => get_download_token_for_path($export_path), 'filenames' => \@filenames };
|
||
}
|
||
|
||
1;
|
bin/mozilla/datev.pl | ||
---|---|---|
|
||
$auth->assert('datev_export');
|
||
|
||
DATEV::clean_temporary_directories();
|
||
|
||
DATEV->save_datev_stamm(\%myconfig, \%$form);
|
||
|
||
my $link = "datev.pl?action=download";
|
||
my $link = "datev.pl?action=download&download_token=";
|
||
|
||
if ($form->{kne}) {
|
||
my @filenames = DATEV->kne_export(\%myconfig, \%$form);
|
||
if (@filenames) {
|
||
print(qq|<br><b>| . $locale->text('KNE-Export erfolgreich!') . qq|</b><br>|);
|
||
$link .= "&filenames=" . $form->escape(join(":", @filenames));
|
||
print(qq|<br><a href="$link">Download</a>|);
|
||
my $result = DATEV->kne_export(\%myconfig, \%$form);
|
||
if ($result && @{ $result->{filenames} }) {
|
||
$link .= Q($result->{download_token});
|
||
|
||
print(qq|<br><b>| . $locale->text('KNE-Export erfolgreich!') . qq|</b><br><br><a href="$link">Download</a>|);
|
||
|
||
} else {
|
||
$form->error("KNE-Export schlug fehl.");
|
||
}
|
||
} else {
|
||
my @filenames = DATEV->obe_export(\%myconfig, \%$form);
|
||
if (@filenames) {
|
||
print(qq|<br><b>| . $locale->text('OBE-Export erfolgreich!') . qq|</b><br>|);
|
||
$link .= "&filenames=" . $form->escape(join(":", @filenames));
|
||
print(qq|<br><a href="$link">Download</a>|);
|
||
} else {
|
||
$form->error("OBE-Export schlug fehl.");
|
||
}
|
||
# OBE-Export nicht implementiert.
|
||
|
||
# my @filenames = DATEV->obe_export(\%myconfig, \%$form);
|
||
# if (@filenames) {
|
||
# print(qq|<br><b>| . $locale->text('OBE-Export erfolgreich!') . qq|</b><br>|);
|
||
# $link .= "&filenames=" . $form->escape(join(":", @filenames));
|
||
# print(qq|<br><a href="$link">Download</a>|);
|
||
# } else {
|
||
# $form->error("OBE-Export schlug fehl.");
|
||
# }
|
||
}
|
||
|
||
print("</body></html>");
|
||
... | ... | |
$auth->assert('datev_export');
|
||
|
||
my $tmp_name = Common->tmpname();
|
||
my $zip_name = strftime("lx-office-datev-export-%Y%m%d.zip",
|
||
localtime(time()));
|
||
my $zip_name = strftime("lx-office-datev-export-%Y%m%d.zip", localtime(time()));
|
||
|
||
my $cwd = getcwd();
|
||
chdir("users") || die("chdir users");
|
||
|
||
my @filenames = split(/:/, $form->{"filenames"});
|
||
map({ s|.*/||; $form->error("Eine der KNE-Exportdateien wurde nicht " .
|
||
"gefunden. Wurde der Export bereits " .
|
||
"durchgeführt?") unless (-f $_); }
|
||
@filenames);
|
||
my $path = DATEV::get_path_for_download_token($form->{download_token});
|
||
if (!$path) {
|
||
$form->error($locale->text("Your download does not exist anymore. Please re-run the DATEV export assistant."));
|
||
}
|
||
|
||
chdir($path) || die("chdir $path");
|
||
|
||
my @filenames = glob "*";
|
||
|
||
if (!@filenames) {
|
||
chdir($cwd);
|
||
DATEV::clean_temporary_directories();
|
||
$form->error($locale->text("Your download does not exist anymore. Please re-run the DATEV export assistant."));
|
||
}
|
||
|
||
my $zip = Archive::Zip->new();
|
||
map({ $zip->addFile($_); } @filenames);
|
||
map { $zip->addFile($_); } @filenames;
|
||
$zip->writeToFileNamed($tmp_name);
|
||
|
||
chdir($cwd);
|
||
|
||
open(IN, $tmp_name) || die("open $tmp_name");
|
||
... | ... | |
|
||
unlink($tmp_name);
|
||
|
||
DATEV::clean_temporary_directories();
|
||
|
||
$lxdebug->leave_sub();
|
||
}
|
Auch abrufbar als: Unified diff
Jeden DATEV-Export in ein eigenes, eindeutig benanntes Verzeichnis schreiben, damit sich DATEV-Exporte nicht gegenseitig überschreiben.
Temporäre Verzeichnisse werden beim nächsten Aufruf gelöscht, sofern sie älter als acht Stunden sind.
Fix für Bug 924.