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