1 #=====================================================================
6 # Email: p.reetz@linet-services.de
7 # Web: http://www.lx-office.org
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #======================================================================
26 #======================================================================
28 use POSIX qw(strftime getcwd);
29 use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
40 require "bin/mozilla/common.pl";
42 sub continue { call_sub($main::form->{"nextsub"}); }
45 $::lxdebug->enter_sub;
46 $::auth->assert('datev_export');
48 DATEV->get_datev_stamm(\%::myconfig, $::form);
50 print $::form->parse_html_template('datev/export');
52 $::lxdebug->leave_sub;
56 $::lxdebug->enter_sub;
57 $::auth->assert('datev_export');
59 if ($::form->{exporttype} == 0) {
60 export_bewegungsdaten();
64 $::lxdebug->leave_sub;
67 sub export_bewegungsdaten {
68 $::lxdebug->enter_sub;
69 $::auth->assert('datev_export');
72 print $::form->parse_html_template('datev/export_bewegungsdaten');
74 $::lxdebug->leave_sub;
77 sub export_stammdaten {
78 $::lxdebug->enter_sub;
79 $::auth->assert('datev_export');
82 print $::form->parse_html_template('datev/export_stammdaten');
84 $::lxdebug->leave_sub;
88 $main::lxdebug->enter_sub();
90 my $form = $main::form;
91 my %myconfig = %main::myconfig;
92 my $locale = $main::locale;
94 $main::auth->assert('datev_export');
96 DATEV::clean_temporary_directories();
98 DATEV->save_datev_stamm(\%myconfig, \%$form);
100 my $link = "datev.pl?action=download&download_token=";
103 my $result = DATEV->kne_export(\%myconfig, \%$form);
104 if ($result && @{ $result->{filenames} }) {
105 $link .= Q($result->{download_token});
107 print(qq|<br><b>| . $locale->text('KNE-Export erfolgreich!') . qq|</b><br><br><a href="$link">Download</a>|);
109 print $form->parse_html_template('datev/net_gross_difference') if @{ $form->{net_gross_differences} };
112 $form->error("KNE-Export schlug fehl.");
115 # OBE-Export nicht implementiert.
117 # my @filenames = DATEV->obe_export(\%myconfig, \%$form);
119 # print(qq|<br><b>| . $locale->text('OBE-Export erfolgreich!') . qq|</b><br>|);
120 # $link .= "&filenames=" . $form->escape(join(":", @filenames));
121 # print(qq|<br><a href="$link">Download</a>|);
123 # $form->error("OBE-Export schlug fehl.");
127 print("</body></html>");
129 $main::lxdebug->leave_sub();
133 $main::lxdebug->enter_sub();
135 my $form = $main::form;
136 my $locale = $main::locale;
138 $main::auth->assert('datev_export');
140 my $tmp_name = Common->tmpname();
141 my $zip_name = strftime("lx-office-datev-export-%Y%m%d.zip", localtime(time()));
145 my $path = DATEV::get_path_for_download_token($form->{download_token});
147 $form->error($locale->text("Your download does not exist anymore. Please re-run the DATEV export assistant."));
150 chdir($path) || die("chdir $path");
152 my @filenames = glob "*";
156 DATEV::clean_temporary_directories();
157 $form->error($locale->text("Your download does not exist anymore. Please re-run the DATEV export assistant."));
160 my $zip = Archive::Zip->new();
161 map { $zip->addFile($_); } @filenames;
162 $zip->writeToFileNamed($tmp_name);
166 open(IN, $tmp_name) || die("open $tmp_name");
167 $::locale->with_raw_io(\*STDOUT, sub {
168 print("Content-Type: application/zip\n");
169 print("Content-Disposition: attachment; filename=\"${zip_name}\"\n\n");
178 DATEV::clean_temporary_directories();
180 $main::lxdebug->leave_sub();