Revision 631b4c04
Von Sven Schöling vor mehr als 12 Jahren hinzugefügt
bin/mozilla/datev.pl | ||
---|---|---|
29 | 29 |
use Archive::Zip qw(:ERROR_CODES :CONSTANTS); |
30 | 30 |
|
31 | 31 |
use SL::Common; |
32 |
use SL::DATEV; |
|
32 |
use SL::DATEV qw(:CONSTANTS);
|
|
33 | 33 |
|
34 | 34 |
use strict; |
35 | 35 |
|
... | ... | |
45 | 45 |
$::lxdebug->enter_sub; |
46 | 46 |
$::auth->assert('datev_export'); |
47 | 47 |
|
48 |
DATEV->get_datev_stamm(\%::myconfig, $::form); |
|
48 |
my $stamm = SL::DATEV->new->get_datev_stamm; |
|
49 |
|
|
49 | 50 |
$::form->header; |
50 |
print $::form->parse_html_template('datev/export'); |
|
51 |
print $::form->parse_html_template('datev/export', $stamm);
|
|
51 | 52 |
|
52 | 53 |
$::lxdebug->leave_sub; |
53 | 54 |
} |
... | ... | |
85 | 86 |
} |
86 | 87 |
|
87 | 88 |
sub export3 { |
88 |
$main::lxdebug->enter_sub(); |
|
89 |
|
|
90 |
my $form = $main::form; |
|
91 |
my %myconfig = %main::myconfig; |
|
92 |
my $locale = $main::locale; |
|
93 |
|
|
94 |
$main::auth->assert('datev_export'); |
|
95 |
|
|
96 |
DATEV::clean_temporary_directories(); |
|
97 |
|
|
98 |
DATEV->save_datev_stamm(\%myconfig, \%$form); |
|
89 |
$::lxdebug->enter_sub; |
|
90 |
$::auth->assert('datev_export'); |
|
99 | 91 |
|
100 |
my $link = "datev.pl?action=download&download_token="; |
|
92 |
my %data = ( |
|
93 |
exporttype => $::form->{exporttype} ? DATEV_ET_STAMM : DATEV_ET_BUCHUNGEN, |
|
94 |
format => $::form->{kne} ? DATEV_FORMAT_KNE : DATEV_FORMAT_OBE, |
|
95 |
); |
|
96 |
|
|
97 |
if ($::form->{exporttype} == DATEV_ET_STAMM) { |
|
98 |
$data{accnofrom} = $::form->{accnofrom}, |
|
99 |
$data{accnoto} = $::form->{accnoto}, |
|
100 |
} elsif ($::form->{exporttype} == DATEV_ET_BUCHUNGEN) { |
|
101 |
@data{qw(from to)} = _get_dates( |
|
102 |
$::form->{zeitraum}, $::form->{monat}, $::form->{quartal}, |
|
103 |
$::form->{transdatefrom}, $::form->{transdateto}, |
|
104 |
); |
|
105 |
} else { |
|
106 |
die 'invalid exporttype'; |
|
107 |
} |
|
101 | 108 |
|
102 |
if ($form->{kne}) { |
|
103 |
my $result = DATEV->kne_export(\%myconfig, \%$form); |
|
104 |
if ($result && @{ $result->{filenames} }) { |
|
105 |
$link .= Q($result->{download_token}); |
|
109 |
my $datev = SL::DATEV->new(%data); |
|
106 | 110 |
|
107 |
print(qq|<br><b>| . $locale->text('KNE-Export erfolgreich!') . qq|</b><br><br><a href="$link">Download</a>|); |
|
111 |
$datev->clean_temporary_directories; |
|
112 |
$datev->save_datev_stamm($::form); |
|
108 | 113 |
|
109 |
print $form->parse_html_template('datev/net_gross_difference') if @{ $form->{net_gross_differences} };
|
|
114 |
$datev->export;
|
|
110 | 115 |
|
111 |
} else {
|
|
112 |
$form->error("KNE-Export schlug fehl.");
|
|
113 |
}
|
|
116 |
if (!$datev->errors) {
|
|
117 |
$::form->header;
|
|
118 |
print $::form->parse_html_template('datev/export3', { datev => $datev });
|
|
114 | 119 |
} else { |
115 |
# OBE-Export nicht implementiert. |
|
116 |
|
|
117 |
# my @filenames = DATEV->obe_export(\%myconfig, \%$form); |
|
118 |
# if (@filenames) { |
|
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>|); |
|
122 |
# } else { |
|
123 |
# $form->error("OBE-Export schlug fehl."); |
|
124 |
# } |
|
120 |
$::form->error("Export schlug fehl.\n" . join "\n", $datev->errors); |
|
125 | 121 |
} |
126 | 122 |
|
127 |
print("</body></html>"); |
|
128 |
|
|
129 |
$main::lxdebug->leave_sub(); |
|
123 |
$::lxdebug->leave_sub; |
|
130 | 124 |
} |
131 | 125 |
|
132 | 126 |
sub download { |
... | ... | |
135 | 129 |
my $form = $main::form; |
136 | 130 |
my $locale = $main::locale; |
137 | 131 |
|
138 |
$main::auth->assert('datev_export');
|
|
132 |
$::auth->assert('datev_export'); |
|
139 | 133 |
|
140 | 134 |
my $tmp_name = Common->tmpname(); |
141 | 135 |
my $zip_name = strftime("kivitendo-datev-export-%Y%m%d.zip", localtime(time())); |
142 | 136 |
|
143 | 137 |
my $cwd = getcwd(); |
144 | 138 |
|
145 |
my $path = DATEV::get_path_for_download_token($form->{download_token}); |
|
139 |
my $datev = SL::DATEV->new(download_token => $form->{download_token}); |
|
140 |
|
|
141 |
my $path = $datev->export_path; |
|
146 | 142 |
if (!$path) { |
147 | 143 |
$form->error($locale->text("Your download does not exist anymore. Please re-run the DATEV export assistant.")); |
148 | 144 |
} |
... | ... | |
153 | 149 |
|
154 | 150 |
if (!@filenames) { |
155 | 151 |
chdir($cwd); |
156 |
DATEV::clean_temporary_directories(); |
|
157 | 152 |
$form->error($locale->text("Your download does not exist anymore. Please re-run the DATEV export assistant.")); |
158 | 153 |
} |
159 | 154 |
|
... | ... | |
175 | 170 |
|
176 | 171 |
unlink($tmp_name); |
177 | 172 |
|
178 |
DATEV::clean_temporary_directories(); |
|
179 |
|
|
180 | 173 |
$main::lxdebug->leave_sub(); |
181 | 174 |
} |
175 |
|
|
176 |
sub _get_dates { |
|
177 |
$::lxdebug->enter_sub; |
|
178 |
|
|
179 |
my ($mode, $month, $quarter, $transdatefrom, $transdateto) = @_; |
|
180 |
my ($fromdate, $todate); |
|
181 |
|
|
182 |
if ($mode eq "monat") { |
|
183 |
$fromdate = DateTime->new(day => 1, month => $month, year => DateTime->today->year); |
|
184 |
$todate = $fromdate->clone->add(months => 1)->add(days => -1); |
|
185 |
} elsif ($mode eq "quartal") { |
|
186 |
die 'quarter out of of bounds' if $quarter < 1 || $quarter > 4; |
|
187 |
$fromdate = DateTime->new(day => 1, month => (3 * $quarter - 2), year => DateTime->today->year); |
|
188 |
$todate = $fromdate->clone->add(months => 3)->add(days => -1); |
|
189 |
} elsif ($mode eq "zeit") { |
|
190 |
$fromdate = DateTime->from_lxoffice($transdatefrom); |
|
191 |
$todate = DateTime->from_lxoffice($transdateto); |
|
192 |
die 'need from and to time' unless $fromdate && $todate; |
|
193 |
} else { |
|
194 |
die 'undefined interval mode'; |
|
195 |
} |
|
196 |
|
|
197 |
$::lxdebug->leave_sub; |
|
198 |
|
|
199 |
return ($fromdate, $todate); |
|
200 |
} |
Auch abrufbar als: Unified diff
DATEV Export modular gekapselt.