Projekt

Allgemein

Profil

Herunterladen (4,57 KB) Statistiken
| Zweig: | Markierung: | Revision:
d319704a Moritz Bunkus
#=====================================================================
# Lx-Office ERP
# Copyright (c) 2004
#
# Author: Philip Reetz
# Email: p.reetz@linet-services.de
# Web: http://www.lx-office.org
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#======================================================================
#
# Datev export module
#
#======================================================================

39f3d12c Moritz Bunkus
use POSIX qw(strftime getcwd);
use Archive::Zip qw(:ERROR_CODES :CONSTANTS);

use SL::Common;
d319704a Moritz Bunkus
use SL::DATEV;

27309ff1 Sven Schöling
use strict;

d319704a Moritz Bunkus
1;

# end of main

40782548 Moritz Bunkus
require "bin/mozilla/common.pl";

27309ff1 Sven Schöling
sub continue { call_sub($main::form->{"nextsub"}); }
d319704a Moritz Bunkus
sub export {
6fc9c2bb Sven Schöling
$::lxdebug->enter_sub;
$::auth->assert('datev_export');
b65a230d Sven Schöling
6fc9c2bb Sven Schöling
DATEV->get_datev_stamm(\%::myconfig, $::form);
$::form->header;
print $::form->parse_html_template('datev/export');
0576299f Moritz Bunkus
6fc9c2bb Sven Schöling
$::lxdebug->leave_sub;
d319704a Moritz Bunkus
}

sub export2 {
6fc9c2bb Sven Schöling
$::lxdebug->enter_sub;
$::auth->assert('datev_export');
8c7e4493 Moritz Bunkus
6fc9c2bb Sven Schöling
if ($::form->{exporttype} == 0) {
export_bewegungsdaten();
d319704a Moritz Bunkus
} else {
6fc9c2bb Sven Schöling
export_stammdaten();
d319704a Moritz Bunkus
}
6fc9c2bb Sven Schöling
$::lxdebug->leave_sub;
d319704a Moritz Bunkus
}

sub export_bewegungsdaten {
6fc9c2bb Sven Schöling
$::lxdebug->enter_sub;
$::auth->assert('datev_export');
27309ff1 Sven Schöling
6fc9c2bb Sven Schöling
$::form->header;
print $::form->parse_html_template('datev/export_bewegungsdaten');
d319704a Moritz Bunkus
6fc9c2bb Sven Schöling
$::lxdebug->leave_sub;
d319704a Moritz Bunkus
}

sub export_stammdaten {
6fc9c2bb Sven Schöling
$::lxdebug->enter_sub;
$::auth->assert('datev_export');
d319704a Moritz Bunkus
6fc9c2bb Sven Schöling
$::form->header;
print $::form->parse_html_template('datev/export_stammdaten');
d319704a Moritz Bunkus
6fc9c2bb Sven Schöling
$::lxdebug->leave_sub;
d319704a Moritz Bunkus
}

sub export3 {
27309ff1 Sven Schöling
$main::lxdebug->enter_sub();

my $form = $main::form;
my %myconfig = %main::myconfig;
my $locale = $main::locale;
d319704a Moritz Bunkus
27309ff1 Sven Schöling
$main::auth->assert('datev_export');
8c7e4493 Moritz Bunkus
f8138d17 Moritz Bunkus
DATEV::clean_temporary_directories();

d319704a Moritz Bunkus
DATEV->save_datev_stamm(\%myconfig, \%$form);

f8138d17 Moritz Bunkus
my $link = "datev.pl?action=download&download_token=";
39f3d12c Moritz Bunkus
d319704a Moritz Bunkus
if ($form->{kne}) {
f8138d17 Moritz Bunkus
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>|);

a3501388 Moritz Bunkus
print $form->parse_html_template('datev/net_gross_difference') if @{ $form->{net_gross_differences} };

39f3d12c Moritz Bunkus
} else {
$form->error("KNE-Export schlug fehl.");
d319704a Moritz Bunkus
}
} else {
f8138d17 Moritz Bunkus
# 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.");
# }
d319704a Moritz Bunkus
}
39f3d12c Moritz Bunkus
print("</body></html>");

27309ff1 Sven Schöling
$main::lxdebug->leave_sub();
39f3d12c Moritz Bunkus
}

sub download {
27309ff1 Sven Schöling
$main::lxdebug->enter_sub();

my $form = $main::form;
my $locale = $main::locale;
39f3d12c Moritz Bunkus
27309ff1 Sven Schöling
$main::auth->assert('datev_export');
8c7e4493 Moritz Bunkus
39f3d12c Moritz Bunkus
my $tmp_name = Common->tmpname();
f8138d17 Moritz Bunkus
my $zip_name = strftime("lx-office-datev-export-%Y%m%d.zip", localtime(time()));
39f3d12c Moritz Bunkus
my $cwd = getcwd();

f8138d17 Moritz Bunkus
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."));
}
39f3d12c Moritz Bunkus
my $zip = Archive::Zip->new();
f8138d17 Moritz Bunkus
map { $zip->addFile($_); } @filenames;
39f3d12c Moritz Bunkus
$zip->writeToFileNamed($tmp_name);
f8138d17 Moritz Bunkus
39f3d12c Moritz Bunkus
chdir($cwd);

open(IN, $tmp_name) || die("open $tmp_name");
e652a0c2 Moritz Bunkus
$::locale->with_raw_io(\*STDOUT, sub {
print("Content-Type: application/zip\n");
print("Content-Disposition: attachment; filename=\"${zip_name}\"\n\n");
while (<IN>) {
print($_);
}
});
39f3d12c Moritz Bunkus
close(IN);

unlink($tmp_name);

f8138d17 Moritz Bunkus
DATEV::clean_temporary_directories();

27309ff1 Sven Schöling
$main::lxdebug->leave_sub();
d319704a Moritz Bunkus
}