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