Tabs aus *.pl Dateien entfernt.
[kivitendo-erp.git] / bin / mozilla / datev.pl
1 #=====================================================================
2 # Lx-Office ERP
3 # Copyright (c) 2004
4 #
5 #  Author: Philip Reetz
6 #   Email: p.reetz@linet-services.de
7 #     Web: http://www.lx-office.org
8 #
9 #
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.
14 #
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 #======================================================================
23 #
24 # Datev export module
25 #
26 #======================================================================
27
28 use POSIX qw(strftime getcwd);
29 use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
30
31 use SL::Common;
32 use SL::DATEV;
33
34 use strict;
35
36 1;
37
38 # end of main
39
40 require "bin/mozilla/common.pl";
41
42 sub continue { call_sub($main::form->{"nextsub"}); }
43
44 sub export {
45   $main::lxdebug->enter_sub();
46
47   my $form     = $main::form;
48   my %myconfig = %main::myconfig;
49   my $locale   = $main::locale;
50
51   $main::auth->assert('datev_export');
52
53   $form->{title} = $locale->text("DATEX - Export Assistent");
54
55   DATEV->get_datev_stamm(\%myconfig, \%$form);
56   $form->header;
57
58   print qq|
59 <body>
60
61 <form method=post action=$form->{script}>
62
63
64 <table width=100%>
65   <tr>
66     <th class=listtop>$form->{title}</th>
67   </tr>
68   <tr>
69     <th align=left>| . $locale->text("DATEV Angaben") . qq|</th>
70   </tr>
71   <tr height="5"></tr>
72   <tr valign=top>
73     <td>
74       <table>
75         <tr>
76           <td align=left nowrap>| . $locale->text("Beraternummer") . qq|</td>
77           <td><input name=beraternr size=10 maxlength=7 value="$form->{beraternr}"></td>
78
79           <td align=left nowrap>| . $locale->text("DFV-Kennzeichen") . qq|</td>
80           <td><input name=dfvkz size=5 maxlength=2 value="$form->{dfvkz}"></td>
81         </tr>
82         <tr>
83           <td align=left nowrap>| . $locale->text("Beratername") . qq|</td>
84           <td><input name=beratername size=10 maxlength=9 value="$form->{beratername}"></td>
85
86           <td align=left nowrap>| . $locale->text("Password") . qq|</td>
87           <td><input name=passwort size=5 maxlength=4 value="$form->{passwort}"></td>
88         </tr>
89         <tr>
90           <td align=left nowrap>| . $locale->text("Mandantennummer") . qq|</td>
91           <td><input name=mandantennr size=10 maxlength=5 value="$form->{mandantennr}"></td>
92
93           <td align=left nowrap>| . $locale->text("Medium Number") . qq|</td>
94           <td><input name=datentraegernr size=5 maxlength=3 value="$form->{datentraegernr}"></td>
95         </tr>
96         <tr>
97           | . # OBE-Export noch nicht implementiert! <td><input checked name=kne type=checkbox class=checkbox value=1> | . $locale->text("Kontonummernerweiterung (KNE)") . qq|</td>
98     qq|<td><input type="hidden" name="kne" value="1"></td>
99           <td></td>
100
101           <td align=left nowrap>| . $locale->text("Abrechnungsnummer") . qq|</td>
102           <td><input name=abrechnungsnr size=5 maxlength=3 value="$form->{abrechnungsnr}"></td>
103         </tr>
104
105         <tr>
106           <td><input name=exporttype type=radio class=radio value=0 checked> |
107     . $locale->text("Export Buchungsdaten") . qq|</td>
108           <td></td>
109
110           <td><input name=exporttype type=radio class=radio value=1> |
111     . $locale->text("Export Stammdaten") . qq|</td>
112           <td></td>
113         </td>
114       </table>
115     </td>
116   </tr>
117   <tr>
118     <td><hr size=3 noshade></td>
119   </tr>
120 </table>
121
122 <input type=hidden name=nextsub value=export2>
123
124 <br>
125 <input type=submit class=submit name=action value="|
126     . $locale->text('Continue') . qq|">
127 </form>
128
129 </body>
130 </html>
131 |;
132   $main::lxdebug->leave_sub();
133 }
134
135 sub export2 {
136   $main::lxdebug->enter_sub();
137
138   my $form     = $main::form;
139
140   $main::auth->assert('datev_export');
141
142   if ($form->{exporttype} == 0) {
143     &export_bewegungsdaten();
144   } else {
145     &export_stammdaten();
146   }
147   $main::lxdebug->leave_sub();
148 }
149
150 sub export_bewegungsdaten {
151   $main::lxdebug->enter_sub();
152
153   my $form     = $main::form;
154   my %myconfig = %main::myconfig;
155   my $locale   = $main::locale;
156
157   $main::auth->assert('datev_export');
158
159   $form->{title} = $locale->text("DATEX - Export Assistent");
160
161   $form->{allemonate} =
162       qq|<option value=1>|
163     . $locale->text('January')
164     . qq|</option>
165                          <option value=2>|
166     . $locale->text('February') . qq|</option>
167                          <option value=3>|
168     . $locale->text('March') . qq|</option>
169                          <option value=4>|
170     . $locale->text('April') . qq|</option>
171                          <option value=5>|
172     . $locale->text('May') . qq|</option>
173                          <option value=6>|
174     . $locale->text('June') . qq|</option>
175                          <option value=7>|
176     . $locale->text('July') . qq|</option>
177                          <option value=8>|
178     . $locale->text('August') . qq|</option>
179                          <option value=9>|
180     . $locale->text('September') . qq|</option>
181                          <option value=10>|
182     . $locale->text('October') . qq|</option>
183                          <option value=11>|
184     . $locale->text('November') . qq|</option>
185                          <option value=12>|
186     . $locale->text('December') . qq|</option>|;
187
188   $form->{allequartale} =
189       qq|<option selected value=1>|
190     . $locale->text('I')
191     . qq|</option>
192                          <option value=2>| . $locale->text('II') . qq|</option>
193                          <option value=3>|
194     . $locale->text('III') . qq|</option>
195                          <option value=4>|
196     . $locale->text('IV') . qq|</option>|;
197   $form->{"jsscript"} = 1;
198   $form->header;
199
200   print qq|
201 <body>
202
203 <form method=post action=$form->{script}>
204
205
206 <table width=100%>
207   <tr>
208     <th class=listtop>$form->{title}</th>
209   </tr>
210   <tr>
211     <th align=left>| . $locale->text("Zeitraum") . qq|</th>
212   </tr>
213   <tr height="5"></tr>
214   <tr valign=top>
215     <td>
216       <table>
217         <tr>
218           <td align=left><input checked name=zeitraum class=radio type=radio value=monat>&nbsp;</td><td align=left>|
219     . $locale->text('Monat') . qq|</td>
220           <td align=left></td>
221           <td align=left></td>
222           <td align=left><select name=monat>$form->{allemonate}</select></td>
223         </tr>
224         <tr>
225           <td align=left><input name=zeitraum class=radio type=radio value=quartal>&nbsp;</td><td align=left>|
226     . $locale->text('Quartal') . qq|</td>
227           <td align=left></td>
228           <td align=left></td>
229           <td align=left><select name=quartal>$form->{allequartale}</select></td>
230         </tr>
231         <tr>
232           <td align=left><input name=zeitraum class=radio type=radio value=zeit>&nbsp;</td><td align=left>|
233     . $locale->text('Datum von') . qq|</td>
234           <td align=left><input id=transdatefrom name=transdatefrom size=10>
235             <input type="button" name="transdatefrom" id="trigger_transdatefrom" value="?"></td>
236           <td align=left>| . $locale->text('bis') . qq|</td>
237           <td align=left><input id=transdateto name=transdateto size=10>
238             <input type="button" name="transdateto" id="trigger_transdateto" value="?"></td>
239         </tr>
240       </table>
241     </td>
242   </tr>
243   <tr>
244     <td><hr size=3 noshade></td>
245   </tr>
246 </table>
247
248 | . $form->write_trigger(\%myconfig, 2,
249                          "transdatefrom", "BL", "trigger_transdatefrom",
250                          "transdateto", "BL", "trigger_transdateto") . qq|
251
252 <input type=hidden name=beraternr value="$form->{beraternr}">
253 <input type=hidden name=dfvkz value="$form->{dfvkz}">
254 <input type=hidden name=beratername value="$form->{beratername}">
255 <input type=hidden name=passwort value="$form->{passwort}">
256 <input type=hidden name=mandantennr value="$form->{mandantennr}">
257 <input type=hidden name=datentraegernr value="$form->{datentraegernr}">
258 <input type=hidden name=kne value="$form->{kne}">
259 <input type=hidden name=abrechnungsnr value="$form->{abrechnungsnr}">
260
261 <input type=hidden name=exporttype value="$form->{exporttype}">
262
263 <input type=hidden name=nextsub value=export3>
264
265 <br>
266 <input type=submit class=submit name=action value="|
267     . $locale->text('Continue') . qq|">
268 </form>
269
270 </body>
271 </html>
272 |;
273
274   $main::lxdebug->leave_sub();
275 }
276
277 sub export_stammdaten {
278   $main::lxdebug->enter_sub();
279
280   my $form     = $main::form;
281   my $locale   = $main::locale;
282
283   $main::auth->assert('datev_export');
284
285   $form->{title} = $locale->text("DATEX - Export Assistent");
286
287   $form->header;
288
289   print qq|
290 <body>
291
292 <form method=post action=$form->{script}>
293 <table width=100%>
294   <tr>
295     <th class=listtop>$form->{title}</th>
296   </tr>
297   <tr>
298     <th align=left>| . $locale->text("Konten") . qq|</th>
299   </tr>
300   <tr height="5"></tr>
301   <tr valign=top>
302     <td>
303       <table>
304         <tr>
305           <td align=left>| . $locale->text('Von Konto: ') . qq|</td>
306           <td align=left><input name=accnofrom size=8 maxlength=8></td>
307         </tr>
308         <tr>
309           <td align=left>| . $locale->text('Bis Konto: ') . qq|</td>
310           <td align=left><input name=accnoto size=8 maxlength=8></td>
311         </tr>
312       </table>
313     </td>
314   </tr>
315   <tr>
316     <td><hr size=3 noshade></td>
317   </tr>
318 </table>
319 <input type=hidden name=beraternr value="$form->{beraternr}">
320 <input type=hidden name=dfvkz value="$form->{dfvkz}">
321 <input type=hidden name=beratername value="$form->{beratername}">
322 <input type=hidden name=passwort value="$form->{passwort}">
323 <input type=hidden name=mandantennr value="$form->{mandantennr}">
324 <input type=hidden name=datentraegernr value="$form->{datentraegernr}">
325 <input type=hidden name=kne value="$form->{kne}">
326 <input type=hidden name=abrechnungsnr value="$form->{abrechnungsnr}">
327
328 <input type=hidden name=exporttype value="$form->{exporttype}">
329
330 <input type=hidden name=nextsub value=export3>
331
332 <br>
333 <input type=submit class=submit name=action value="|
334     . $locale->text('Continue') . qq|">
335 </form>
336
337 </body>
338 </html>
339 |;
340
341   $main::lxdebug->leave_sub();
342 }
343
344 sub export3 {
345   $main::lxdebug->enter_sub();
346
347   my $form     = $main::form;
348   my %myconfig = %main::myconfig;
349   my $locale   = $main::locale;
350
351   $main::auth->assert('datev_export');
352
353   DATEV::clean_temporary_directories();
354
355   DATEV->save_datev_stamm(\%myconfig, \%$form);
356
357   my $link = "datev.pl?action=download&download_token=";
358
359   if ($form->{kne}) {
360     my $result = DATEV->kne_export(\%myconfig, \%$form);
361     if ($result && @{ $result->{filenames} }) {
362       $link .= Q($result->{download_token});
363
364       print(qq|<br><b>| . $locale->text('KNE-Export erfolgreich!') . qq|</b><br><br><a href="$link">Download</a>|);
365
366     } else {
367       $form->error("KNE-Export schlug fehl.");
368     }
369   } else {
370     # OBE-Export nicht implementiert.
371
372     # my @filenames = DATEV->obe_export(\%myconfig, \%$form);
373     # if (@filenames) {
374     #   print(qq|<br><b>| . $locale->text('OBE-Export erfolgreich!') . qq|</b><br>|);
375     #   $link .= "&filenames=" . $form->escape(join(":", @filenames));
376     #   print(qq|<br><a href="$link">Download</a>|);
377     # } else {
378     #   $form->error("OBE-Export schlug fehl.");
379     # }
380   }
381
382   print("</body></html>");
383
384   $main::lxdebug->leave_sub();
385 }
386
387 sub download {
388   $main::lxdebug->enter_sub();
389
390   my $form     = $main::form;
391   my $locale   = $main::locale;
392
393   $main::auth->assert('datev_export');
394
395   my $tmp_name = Common->tmpname();
396   my $zip_name = strftime("lx-office-datev-export-%Y%m%d.zip", localtime(time()));
397
398   my $cwd = getcwd();
399
400   my $path = DATEV::get_path_for_download_token($form->{download_token});
401   if (!$path) {
402     $form->error($locale->text("Your download does not exist anymore. Please re-run the DATEV export assistant."));
403   }
404
405   chdir($path) || die("chdir $path");
406
407   my @filenames = glob "*";
408
409   if (!@filenames) {
410     chdir($cwd);
411     DATEV::clean_temporary_directories();
412     $form->error($locale->text("Your download does not exist anymore. Please re-run the DATEV export assistant."));
413   }
414
415   my $zip = Archive::Zip->new();
416   map { $zip->addFile($_); } @filenames;
417   $zip->writeToFileNamed($tmp_name);
418
419   chdir($cwd);
420
421   open(IN, $tmp_name) || die("open $tmp_name");
422   print("Content-Type: application/zip\n");
423   print("Content-Disposition: attachment; filename=\"${zip_name}\"\n\n");
424   while (<IN>) {
425     print($_);
426   }
427   close(IN);
428
429   unlink($tmp_name);
430
431   DATEV::clean_temporary_directories();
432
433   $main::lxdebug->leave_sub();
434 }