USTVA: Patch zur besseren Unterstuetzung der oesterreichischen Verhaeltnisse.
[kivitendo-erp.git] / bin / mozilla / ustva.pl
1 #!/bin/perl
2 #=====================================================================
3 # Lx-Office ERP
4 # Copyright (c) 2004 by Udo Spallek, Aachen
5 #
6 #  Author: Udo Spallek
7 #   Email: udono@gmx.net
8 #     Web: http://www.lx-office.org
9 #
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #======================================================================
24 # German Tax authority Module and later ELSTER Interface
25 #======================================================================
26
27 require "$form->{path}/arap.pl";
28
29 #use strict;
30 #no strict 'refs';
31 #use diagnostics;
32 #use warnings; # FATAL=> 'all';
33 #use vars qw($locale $form %myconfig);
34 #our ($myconfig);
35 #use CGI::Carp "fatalsToBrowser";
36
37 use SL::PE;
38 use SL::RP;
39 use SL::USTVA;
40 use SL::User;
41 1;
42
43 # this is for our long dates
44 # $locale->text('January')
45 # $locale->text('February')
46 # $locale->text('March')
47 # $locale->text('April')
48 # $locale->text('May ')
49 # $locale->text('June')
50 # $locale->text('July')
51 # $locale->text('August')
52 # $locale->text('September')
53 # $locale->text('October')
54 # $locale->text('November')
55 # $locale->text('December')
56
57 # this is for our short month
58 # $locale->text('Jan')
59 # $locale->text('Feb')
60 # $locale->text('Mar')
61 # $locale->text('Apr')
62 # $locale->text('May')
63 # $locale->text('Jun')
64 # $locale->text('Jul')
65 # $locale->text('Aug')
66 # $locale->text('Sep')
67 # $locale->text('Oct')
68 # $locale->text('Nov')
69 # $locale->text('Dec')
70
71 # $form->parse_html_template('generic/util_hidden_variables');
72
73 #############################
74
75 sub report {
76   $lxdebug->enter_sub();
77
78   my $myconfig = \%myconfig;
79
80   $form->{title} = $locale->text('UStVA');
81   $form->{kz10}  = '';                       #Berichtigte Anmeldung? Ja =1 Nein=0
82
83   my $year = substr($form->datetonum($form->current_date(\%myconfig), \%myconfig ),
84              0, 4);
85
86   my $department = '';
87   local $hide = '';
88   $form->header;
89
90   # Einlesen der Finanzamtdaten
91   &get_config($userspath, 'finanzamt.ini');
92
93   # Hier Einlesen der user-config
94   # steuernummer entfernt für prerelease
95   my @a = qw(
96     signature      name          company       address        businessnumber 
97     tel            fax           email         co_chief       co_department 
98     co_custom1     co_custom2    co_custom3    co_custom4     co_custom5
99     co_name1       co_name2      co_street     co_street1     co_zip 
100     co_city        co_city1      co_country    co_tel         co_tel1 
101     co_tel2        co_fax        co_fax1       co_email       co_email1
102     co_url         co_url1       ustid         duns           co_bankname 
103     co_bankname1   co_bankname2  co_bankname3  co_blz         co_blz1
104     co_blz2        co_blz3       co_accountnr  co_accountnr1  co_accountnr2 
105     co_accountnr3
106   );
107
108   map { $form->{$_} = $myconfig->{$_} } @a;
109
110   my $openings = $form->{FA_Oeffnungszeiten};
111   $openings =~ s/\\\\n/<br>/g;
112
113   my $company_given = ($form->{company} ne '') 
114     ? qq|<h3>$form->{company}</h3>\n|
115     : qq|<a href=am.pl?path=$form->{path}&action=config|
116       . qq|&level=Programm--Preferences&login=$form->{login}|
117       . qq|&password=$form->{password}>| 
118       . $locale->text('No Company Name given') . qq|!</a><br>|;
119
120
121   # Anpassungen der Variablennamen auf pre 2.1.1 Namen
122   # klären, ob $form->{company_street|_address} gesetzt sind
123   if ($form->{address} ne '') {
124     my $temp = $form->{address};
125     $temp =~ s/\\n/<br \/>/;
126     ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
127     $form->{co_city} =~ s/\\n//g;
128   }
129
130
131   my $address_given = 
132     ($form->{co_street} ne '' 
133       and ( 
134         $form->{co_zip} ne ''
135           or $form->{co_city} ne ''
136       )
137     ) 
138     ? qq|$form->{co_street}<br>|
139         . qq|$form->{co_street1}<br>|
140         . qq|$form->{co_zip} $form->{co_city}|
141     : qq|<a href=am.pl?path=$form->{path}&action=config|
142         . qq|&level=Programm--Preferences&login=$form->{login}|
143         . qq|&password=$form->{password}>| 
144         . $locale->text('No Company Address given') 
145         . qq|!</a>\n|;
146
147   $form->{co_email} = $form->{email} unless $form->{co_email};
148   $form->{co_tel}   = $form->{tel}   unless $form->{co_tel};
149   $form->{co_fax}   = $form->{fax}   unless $form->{co_fax};
150   $form->{co_url}   = $form->{urlx}  unless $form->{co_url};
151
152   my $taxnumber_given = ($form->{steuernummer} ne '')
153     ? qq|$form->{steuernummer}|
154     : qq|<a href="ustva.pl?path=$form->{path}&action="config_step1"|
155       . qq|&level=Programm--Finanzamteinstellungen&login=$form->{login}|
156       . qq|&password=$form->{password}">Keine Steuernummer hinterlegt!|
157       . qq|</a><br>|;
158
159   my $ustva_vorauswahl = &ustva_vorauswahl();
160
161   my @all_years = $form->all_years(\%myconfig);
162
163   my $select_year = qq|<select name=year title="| 
164     . $locale->text('Year') . qq|">|;
165   foreach my $key (@all_years) {
166     $select_year .= qq|<option |;
167     $select_year .= qq|selected| if ($key eq $form->{year});
168     $select_year .= qq| >$key</option>|;
169   }
170   $select_year   .=  qq|</select>|;
171
172   my $_checked = '';
173   $_checked = "checked" if ($form->{kz10} eq '1');
174   my $checkbox_kz_10 = qq|<input name="FA_10" id=FA_10 class=checkbox|
175     . qq| type=checkbox value="1" $_checked title = "|
176     . $locale->text('Amended Advance Turnover Tax Return (Nr. 10)')
177     . qq|">| 
178     . $locale->text('Amended Advance Turnover Tax Return'); 
179
180   my $method_local = ($form->{method} eq 'accrual') ? $locale->text('accrual') 
181                    : ($form->{method} eq 'cash')    ? $locale->text('cash')
182                    : '';
183
184   my $period_local = ( $form->{FA_voranmeld} eq 'month')   ? $locale->text('month')
185                    : ( $form->{FA_voranmeld} eq 'quarter') ? $locale->text('quarter')
186                    : '';  
187
188   my $tax_office_banks_ref = [
189     { BLZ             => $form->{FA_BLZ_1},
190       Kontonummer     => $form->{FA_Kontonummer_1},
191       Bankbezeichnung => $form->{FA_Bankbezeichnung_1}
192     },
193     { BLZ             => $form->{FA_BLZ_2},
194       Kontonummer     => $form->{FA_Kontonummer_2},
195       Bankbezeichnung => $form->{FA_Bankbezeichnung_oertlich}
196     }
197   ];
198  
199   
200   my $template_ref = {
201     openings         => $openings,  
202     company_given    => $company_given,
203     address_given    => $address_given,     
204     taxnumber_given  => $taxnumber_given,
205     select_year      => $select_year,      
206     period_local     => $period_local,
207     method_local     => $method_local,
208     ustva_vorauswahl => $ustva_vorauswahl,
209     checkbox_kz_10   => $checkbox_kz_10,
210     tax_office_banks => $tax_office_banks_ref,    
211     select_options   => &show_options,    
212   };
213   
214   print($form->parse_html_template('ustva/report', $template_ref));
215
216
217
218   $lxdebug->leave_sub();
219 }
220
221
222
223 sub help {
224   $lxdebug->enter_sub();
225
226   # parse help documents under doc
227   my $tmp = $form->{templates};
228   $form->{templates} = 'doc';
229   $form->{help}      = 'ustva';
230   $form->{type}      = 'help';
231   $form->{format}    = 'html';
232   &generate_ustva();
233
234   #$form->{templates} = $tmp;
235   $lxdebug->leave_sub();
236 }
237
238 sub show {
239   $lxdebug->enter_sub();
240
241   #&generate_ustva();
242   no strict 'refs';
243   $lxdebug->leave_sub();
244   &{ $form->{nextsub} };
245   use strict 'refs';
246 }
247
248 sub ustva_vorauswahl {
249   $lxdebug->enter_sub();
250
251   my $select_vorauswahl;
252
253   #Aktuelles Datum zerlegen:
254   my $date = $form->datetonum($form->current_date(\%myconfig), \%myconfig);
255
256   #$locale->date($myconfig, $form->current_date($myconfig), 0)=~ /(\d\d).(\d\d).(\d\d\d\d)/;
257   $form->{day}   = substr($date, 6, 2);
258   $form->{month} = substr($date, 4, 2);
259   $form->{year}  = substr($date, 0, 4);
260   $lxdebug->message(LXDebug::DEBUG1, qq|
261     Actual date from Database: $date\n    
262     Actual year from Database: $form->{year}\n
263     Actual day from Database: $form->{day}\n
264     Actual month from Database: $form->{month}\n|);
265
266   my $sel    = '';
267   my $yymmdd = '';
268
269   # Testdaten erzeugen:
270   #$form->{day}= '11';
271   #$form->{month}= '01';
272   #$form->{year}= 2004;
273   $select_vorauswahl = qq|
274      <input type=hidden name=day value=$form->{day}>
275      <input type=hidden name=month value=$form->{month}>
276      <input type=hidden name=yymmdd value=$yymmdd>
277      <input type=hidden name=sel value=$sel>
278   |;
279
280   if ($form->{FA_voranmeld} eq 'month') {
281
282     # Vorauswahl bei monatlichem Voranmeldungszeitraum
283
284     my %liste = ('01' => $locale->text('January'),
285                  '02' => $locale->text('February'),
286                  '03' => $locale->text('March'),
287                  '04' => $locale->text('April'),
288                  '05' => $locale->text('May'),
289                  '06' => $locale->text('June'),
290                  '07' => $locale->text('July'),
291                  '08' => $locale->text('August'),
292                  '09' => $locale->text('September'),
293                  '10' => $locale->text('October'),
294                  '11' => $locale->text('November'),
295                  '12' => $locale->text('December'),
296                  '13' => $locale->text('Yearly'),
297                 );
298
299     my $yy = $form->{year} * 10000;
300     $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
301     $sel    = '';
302     my $dfv = '';
303
304     # Offset für Dauerfristverlängerung
305     $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
306
307   SWITCH: {
308       $yymmdd <= ($yy + 110 + $dfv) && do {
309         $form->{year} = $form->{year} - 1;
310         $sel = '12';
311         last SWITCH;
312       };
313       $yymmdd <= ($yy + 210 + $dfv) && do {
314         $sel = '01';
315         last SWITCH;
316       };
317       $yymmdd <= ($yy + 310 + $dfv) && do {
318         $sel = '02';
319         last SWITCH;
320       };
321       $yymmdd <= ($yy + 410 + $dfv) && do {
322         $sel = '03';
323         last SWITCH;
324       };
325       $yymmdd <= ($yy + 510 + $dfv) && do {
326         $sel = '04';
327         last SWITCH;
328       };
329       $yymmdd <= ($yy + 610 + $dfv) && do {
330         $sel = '05';
331         last SWITCH;
332       };
333       $yymmdd <= ($yy + 710 + $dfv) && do {
334         $sel = '06';
335         last SWITCH;
336       };
337       $yymmdd <= ($yy + 810 + $dfv) && do {
338         $sel = '07';
339         last SWITCH;
340       };
341       $yymmdd <= ($yy + 910 + $dfv) && do {
342         $sel = '08';
343         last SWITCH;
344       };
345       $yymmdd <= ($yy + 1010 + $dfv) && do {
346         $sel = '09';
347         last SWITCH;
348       };
349       $yymmdd <= ($yy + 1110 + $dfv) && do {
350         $sel = '10';
351         last SWITCH;
352       };
353       $yymmdd <= ($yy + 1210) && do {
354         $sel = '11';
355         last SWITCH;
356       };
357       $yymmdd <= ($yy + 1231) && do {
358         $sel = '12';
359         last SWITCH;
360       };
361
362     }
363     $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
364   . $locale->text('Select a period') . qq|" >|;
365
366     my $key = '';
367     foreach $key (sort keys %liste) {
368       my $selected = '';
369       $selected = 'selected' if ($sel eq $key);
370       $select_vorauswahl .= qq|
371          <option value="$key" $selected> $liste{$key}</option>
372       |;
373     }
374     $select_vorauswahl .= qq|</select>|;
375
376   } elsif ($form->{FA_voranmeld} eq 'quarter') {
377
378     # Vorauswahl bei quartalsweisem Voranmeldungszeitraum
379     my %liste = ('41'  => $locale->text('1. Quarter'),
380                  '42'  => $locale->text('2. Quarter'),
381                  '43'  => $locale->text('3. Quarter'),
382                  '44'  => $locale->text('4. Quarter'),
383                  '13' => $locale->text('Yearly'),);
384
385     my $yy = $form->{year} * 10000;
386     $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
387     $sel    = '';
388     my $dfv = '';    # Offset für Dauerfristverlängerung
389     $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
390
391   SWITCH: {
392       $yymmdd <= ($yy + 110 + $dfv) && do {
393         $form->{year} = $form->{year} - 1;
394         $sel = '44';
395         last SWITCH;
396       };
397       $yymmdd <= ($yy + 410 + $dfv) && do {
398         $sel = '41';
399         last SWITCH;
400       };
401       $yymmdd <= ($yy + 710 + $dfv) && do {
402         $sel = '42';
403         last SWITCH;
404       };
405       $yymmdd <= ($yy + 1010 + $dfv) && do {
406         $sel = '43';
407         last SWITCH;
408       };
409       $yymmdd <= ($yy + 1231) && do {
410         $sel = '44';
411       };
412     }
413
414     $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
415       . $locale->text('Select a period') . qq|" >|;
416     my $key = '';
417     foreach $key (sort keys %liste) {
418       my $selected = '';
419       $selected = 'selected' if ($sel eq $key);
420       $select_vorauswahl .= qq|
421          <option value="$key" $selected>$liste{$key}</option>
422      |;
423     }
424     $select_vorauswahl .= qq|\n</select>
425    |;
426
427   } else {
428
429     # keine Vorauswahl bei Voranmeldungszeitraum
430     $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
431       . $locale->text('Select a period') . qq|" >|;
432
433     my %listea = ('41' => '1. Quarter',
434                   '42' => '2. Quarter',
435                   '43' => '3. Quarter',
436                   '44' => '4. Quarter',);
437
438     my %listeb = ('01' => 'January',
439                   '02' => 'February',
440                   '03' => 'March',
441                   '04' => 'April',
442                   '05' => 'May',
443                   '06' => 'June',
444                   '07' => 'July',
445                   '08' => 'August',
446                   '09' => 'September',
447                   '10' => 'October',
448                   '11' => 'November',
449                   '12' => 'December',
450                   '13' => 'Yearly',);
451     my $key = '';
452     foreach $key (sort keys %listea) {
453       $select_vorauswahl .= qq|
454          <option value="$key">|
455         . $locale->text("$listea{$key}")
456         . qq|</option>\n|;
457     }
458
459     foreach $key (sort keys %listeb) {
460       $select_vorauswahl .= qq|
461          <option value="$key">|
462         . $locale->text("$listeb{$key}")
463         . qq|</option>\n|;
464     }
465     $select_vorauswahl .= qq|</select>|;
466   }
467   $lxdebug->leave_sub();
468   
469   return $select_vorauswahl;
470 }
471
472 #sub config {
473 #  $lxdebug->enter_sub();
474 #  config_step1();
475 #  $lxdebug->leave_sub();
476 #}
477
478 sub debug {
479   $lxdebug->enter_sub();
480   $form->debug();
481   $lxdebug->leave_sub();
482 }
483
484 sub show_options {
485   $lxdebug->enter_sub();
486
487   #  $form->{PD}{$form->{type}} = "selected";
488   #  $form->{DF}{$form->{format}} = "selected";
489   #  $form->{OP}{$form->{media}} = "selected";
490   #  $form->{SM}{$form->{sendmode}} = "selected";
491   my $type   = qq|      <input type=hidden name="type" value="ustva">|;
492   my $media  = qq|      <input type=hidden name="media" value="screen">|;
493   my $format =
494       qq|       <option value=html selected>|
495     . $locale->text('Preview')
496     . qq|</option>|;
497   if ($latex_templates) {
498     $format .=
499         qq|    <option value=pdf>|
500       . $locale->text('UStVA (PDF-Dokument)')
501       . qq|</option>|;
502   }
503
504   #my $disabled= qq|disabled="disabled"|;
505   #$disabled='' if ($form->{elster} eq '1' );
506   if ($form->{elster} eq '1') {
507     $format .=
508         qq|<option value=elsterwinston>|
509       . $locale->text('ELSTER Export (Winston)')
510       . qq|</option>|
511       . qq|<option value=elstertaxbird>|
512       . $locale->text('ELSTER Export (Taxbird)')
513       . qq|</option>|;      
514   }
515
516   #$format .= qq|<option value=elster>|.$locale->text('ELSTER Export nach Winston').qq|</option>|;
517   my $show_options = qq|
518     $type
519     $media
520     <select name=format title = "|
521     . $locale->text('Choose Outputformat') . qq|">$format</select>
522   |;
523   $lxdebug->leave_sub();
524   
525   return $show_options;
526 }
527
528 sub generate_ustva {
529   $lxdebug->enter_sub();
530
531   # Aufruf von get_config aus bin/mozilla/ustva.pl zum
532   # Einlesen der Finanzamtdaten aus finanzamt.ini
533
534   get_config($userspath, 'finanzamt.ini');
535
536   # init some form vars
537   my @anmeldungszeitraum =
538     qw('0401' '0402' '0403' 
539        '0404' '0405' '0406' 
540        '0407' '0408' '0409' 
541        '0410' '0411' '0412' 
542        '0441' '0442' '0443' '0444');
543
544   foreach my $item (@anmeldungszeitraum) {
545     $form->{$item} = "";
546   }
547
548     #forgotten the year --> thisyear
549     if ($form->{year} !~ m/^\d\d\d\d$/) {
550       $form->{year} = substr(
551                              $form->datetonum(
552                                     $form->current_date(\%myconfig), \%myconfig
553                              ),
554                              0, 4);
555       $lxdebug->message(LXDebug::DEBUG1,
556                         qq|Actual year from Database: $form->{year}\n|);
557     }
558
559     #
560     # using dates in ISO-8601 format: yyyymmmdd  for Postgres...
561     #
562     
563     #yearly report
564     if ($form->{period} eq "13") {
565       $form->{fromdate} = "$form->{year}0101";
566       $form->{todate}   = "$form->{year}1231";
567     }
568
569     #Quater reports
570     if ($form->{period} eq "41") {
571       $form->{fromdate} = "$form->{year}0101";
572       $form->{todate}   = "$form->{year}0331";
573       $form->{'0441'}   = "X";
574     }
575     if ($form->{period} eq "42") {
576       $form->{fromdate} = "$form->{year}0401";
577       $form->{todate}   = "$form->{year}0630";
578       $form->{'0442'}   = "X";
579     }
580     if ($form->{period} eq "43") {
581       $form->{fromdate} = "$form->{year}0701";
582       $form->{todate}   = "$form->{year}0930";
583       $form->{'0443'}   = "X";
584     }
585     if ($form->{period} eq "44") {
586       $form->{fromdate} = "$form->{year}1001";
587       $form->{todate}   = "$form->{year}1231";
588       $form->{'0444'}   = "X";
589     }
590
591     #Monthly reports
592   SWITCH: {
593       $form->{period} eq "01" && do {
594         $form->{fromdate} = "$form->{year}0101";
595         $form->{todate}   = "$form->{year}0131";
596         $form->{'0401'}   = "X";
597         last SWITCH;
598       };
599       $form->{period} eq "02" && do {
600         $form->{fromdate} = "$form->{year}0201";
601
602         #this works from 1901 to 2099, 1900 and 2100 fail.
603         my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
604         $form->{todate} = "$form->{year}02$leap";
605         $form->{"0402"} = "X";
606         last SWITCH;
607       };
608       $form->{period} eq "03" && do {
609         $form->{fromdate} = "$form->{year}0301";
610         $form->{todate}   = "$form->{year}0331";
611         $form->{"0403"}   = "X";
612         last SWITCH;
613       };
614       $form->{period} eq "04" && do {
615         $form->{fromdate} = "$form->{year}0401";
616         $form->{todate}   = "$form->{year}0430";
617         $form->{"0404"}   = "X";
618         last SWITCH;
619       };
620       $form->{period} eq "05" && do {
621         $form->{fromdate} = "$form->{year}0501";
622         $form->{todate}   = "$form->{year}0531";
623         $form->{"0405"}   = "X";
624         last SWITCH;
625       };
626       $form->{period} eq "06" && do {
627         $form->{fromdate} = "$form->{year}0601";
628         $form->{todate}   = "$form->{year}0630";
629         $form->{"0406"}   = "X";
630         last SWITCH;
631       };
632       $form->{period} eq "07" && do {
633         $form->{fromdate} = "$form->{year}0701";
634         $form->{todate}   = "$form->{year}0731";
635         $form->{"0407"}   = "X";
636         last SWITCH;
637       };
638       $form->{period} eq "08" && do {
639         $form->{fromdate} = "$form->{year}0801";
640         $form->{todate}   = "$form->{year}0831";
641         $form->{"0408"}   = "X";
642         last SWITCH;
643       };
644       $form->{period} eq "09" && do {
645         $form->{fromdate} = "$form->{year}0901";
646         $form->{todate}   = "$form->{year}0930";
647         $form->{"0409"}   = "X";
648         last SWITCH;
649       };
650       $form->{period} eq "10" && do {
651         $form->{fromdate} = "$form->{year}1001";
652         $form->{todate}   = "$form->{year}1031";
653         $form->{"0410"}   = "X";
654         last SWITCH;
655       };
656       $form->{period} eq "11" && do {
657         $form->{fromdate} = "$form->{year}1101";
658         $form->{todate}   = "$form->{year}1130";
659         $form->{"0411"}   = "X";
660         last SWITCH;
661       };
662       $form->{period} eq "12" && do {
663         $form->{fromdate} = "$form->{year}1201";
664         $form->{todate}   = "$form->{year}1231";
665         $form->{"0412"}   = "X";
666         last SWITCH;
667       };
668     }
669
670   # Kontrollvariable für die Templates 
671   $form->{'year2007'} = ($form->{year} >= 2007 ) ? "1":"0";
672
673
674   # Get the USTVA
675   USTVA->ustva(\%myconfig, \%$form);
676
677   # reformat Dates to dateformat
678   $form->{fromdate} = $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);
679
680   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
681   $form->{todate} = $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
682
683   $form->{longperiod} =
684     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1, 0, 0);
685
686   # if there are any dates construct a where
687   if ($form->{fromdate} || $form->{todate}) {
688
689     $form->{todate} = $form->current_date($myconfig)  unless ($form->{todate});
690
691     my $longtodate  = $locale->date($myconfig, $form->{todate}, 1, 0, 0);
692     my $shorttodate = $locale->date($myconfig, $form->{todate}, 0, 0, 0);
693
694     my $longfromdate  = $locale->date($myconfig, $form->{fromdate}, 1, 0, 0);
695     my $shortfromdate = $locale->date($myconfig, $form->{fromdate}, 0, 0, 0);
696
697     $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
698     $form->{longperiod}      =
699         $locale->text('for Period')
700       . qq|<br>\n$longfromdate |
701       . $locale->text('to (date)')
702       . qq| $longtodate|;
703   }
704
705   if ($form->{comparefromdate} || $form->{comparetodate}) {
706     my $longcomparefromdate =
707       $locale->date(\%myconfig, $form->{comparefromdate}, 1, 0, 0);
708     my $shortcomparefromdate =
709       $locale->date(\%myconfig, $form->{comparefromdate}, 0, 0, 0);
710
711     my $longcomparetodate =
712       $locale->date(\%myconfig, $form->{comparetodate}, 1, 0, 0);
713     my $shortcomparetodate =
714       $locale->date(\%myconfig, $form->{comparetodate}, 0, 0, 0);
715
716     $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
717     $form->{longperiod} .=
718         "<br>\n$longcomparefromdate "
719       . $locale->text('to (date)')
720       . qq| $longcomparetodate|;
721   }
722
723   $form->{Datum_heute} =
724     $locale->date(\%myconfig, $form->current_date(\%myconfig), 0, 0, 0);
725
726   # setup variables for the form
727   my @a = qw(company businessnumber tel fax email
728     co_chief co_department co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
729     co_name1 co_name2  co_street co_street1 co_zip co_city co_city1 co_country co_tel co_tel1 co_tel2
730     co_fax co_fax1 co_email co_email1 co_url co_url1 ustid duns
731     co_bankname co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
732     co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2 co_accountnr3);
733
734   map { $form->{$_} = $myconfig{$_} } @a;
735
736   if ($form->{address} ne '') {
737     my $temp = $form->{address};
738     $temp =~ s/\\n/<br \/>/;
739     ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
740     $form->{co_city} =~ s/\\n//g;
741   }
742
743   ################################
744   #
745   # Nation specific customisations
746   #
747   ################################
748   
749   # Germany
750   
751   if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') {
752       
753     #
754     # Outputformat specific customisation's
755     #
756
757     my @category_cent = qw(
758       511 861 36   80   971  931  98   96   53   74
759       85  65  66   61   62   67   63   64   59   69 
760       39  83  811  891  Z43  Z45  Z53  Z62  Z65  Z67
761       
762     );
763
764     my @category_euro = qw(
765       41 44 49 43 48 51 86 35 77 76 91 89
766       97 93 95 94 42 60 45 52 73 84 81 
767     );
768     
769     $form->{id} = [];
770     $form->{amount} = [];
771
772     if ( $form->{format} eq 'pdf' or $form->{format} eq 'postscript') {
773
774       $form->{IN} = "$form->{type}-$form->{year}.tex";
775       $form->{padding} = "~~";
776       $form->{bold}    = "\textbf{";
777       $form->{endbold} = "}";
778       $form->{br}      = '\\\\';
779
780       # Zahlenformatierung für Latex USTVA Formulare
781
782       foreach my $number (@category_euro) {
783         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '');
784       }
785
786       my ${decimal_comma} = ( $myconfig{numberformat} eq '1.000,00'
787            or $myconfig{numberformat} eq '1000,00' ) ? ',':'.';
788
789       foreach my $number (@category_cent) {
790         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '');
791         $form->{$number} =~ s/${decimal_comma}/~~/g;
792       }
793
794     } elsif ( $form->{format} eq 'html') { # Formatierungen für HTML Ausgabe
795
796       $form->{IN} = $form->{type} . '.html';
797       $form->{padding} = "&nbsp;&nbsp;";
798       $form->{bold}    = "<b>";
799       $form->{endbold} = "</b>";
800       $form->{br}      = "<br>";
801       $form->{address} =~ s/\\n/\n/g;
802
803       foreach $number (@category_cent) {
804         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '0');
805       }
806       
807       foreach $number (@category_euro) {
808         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '0');
809       }
810
811     } elsif ( $form->{format} eq 'elsterwinston' ) {
812
813       $form->{IN} = 'winston.xml';
814       
815       #
816       # Build Winston filename
817       #
818       
819       my $file = 'U';     # 1. char 'U' = USTVA
820       $file .= $form->{period};
821       #4. and 5. char = year modulo 100
822       $file .= sprintf("%02d", $form->{year} % 100);
823       #6. to 18. char = Elstersteuernummer
824       #Beispiel: Steuernummer in Bayern
825       #111/222/33334 ergibt für UStVA Jan 2004: U01049111022233334
826       $file .= $form->{elsterFFFF};
827       $file .= $form->{elstersteuernummer};
828       #file suffix
829       $file .= '.xml';
830       $form->{tmpfile} = "$userspath/$file";
831
832       $form->{attachment_filename} = "$file";
833    
834       # Zahlenformatierung für Winston
835
836       my $temp_numberformat = $myconfig{numberformat};
837
838       # Numberformat must be '1000.00' for Winston
839
840       $myconfig{numberformat} = '1000.00';
841
842       foreach my $number (@category_cent) {
843         $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
844       }
845       
846       foreach my $number (@category_euro) {
847         $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
848       }
849       # Re-set Numberformat
850       $myconfig{numberformat} = $temp_numberformat;
851
852
853       # push Kennziffern to <%foreach Array fo easyer
854       # output in xml format. Thx to Moritz.
855       my %winston_id_for = (
856        # No Winston remap?!
857       );
858             
859
860       foreach my $kennziffer (@category_cent, @category_euro) {
861
862         next if ( $kennziffer =~ m/Z\d\d/);
863         next if (   $form->{$kennziffer} == 0 );
864         
865         if (defined $winston_id_for{$kennziffer} ) {
866           push(@{ $form->{id}}, $winston_id_for{$kennziffer});
867         } else {
868           push(@{ $form->{id}}, "$kennziffer"); 
869         }
870         push(@{ $form->{amount}}, $form->{$kennziffer});
871       }    
872
873
874     } elsif ( $form->{format} eq 'elstertaxbird' ) {
875
876       # Define serveral filenames
877       $form->{IN} = 'taxbird.txb';
878
879       $form->{attachment_filename} = "USTVA-" . $form->{period} 
880       . sprintf("%02d", $form->{year} % 100) . ".txb";
881       
882       $form->{tmpfile} = "$userspath/" . $form->{attachment_filename};
883
884       # TODO: set Output to UTF-8 or system Preference
885       #$form->{"iconv"} = Text::Iconv->new($myconfig{dbcharset}, "UTF-8");
886       #my $iconv = $self->{"iconv"};
887       #$iconv->convert($variable);
888       if ($form->{period} =~ /^[4]\d$/ ){
889         my %periods = ( # Lx => taxbird
890                      '41' => '12',
891                      '42' => '13',
892                      '43' => '14',
893                      '44' => '15',
894                    );
895       
896         foreach my $quarter ( keys %periods ) {
897           $form->{taxbird_period} = $periods{$quarter} if ( $form->{period} eq $quarter);
898         }
899       } elsif ($form->{period} =~ /^\d+$/ ) {
900         $form->{period} =~ s/^0//g;
901         my $period = $form->{period};
902         $period * 1;
903         $period--;
904         $form->{period} = $period;
905       } else {
906         $form->header;
907         USTVA::error( $locale->text('Wrong Period' ));
908         exit(0);
909       }
910       
911       my %lands = ( # Lx => taxbird # TODO: besser als array...
912                   'Baden Würtemberg'       => '0',
913                   'Bayern'                 => '1',
914                   'Berlin'                 => '2',
915                   'Brandenburg'            => '3',
916                   'Bremen'                 => '4',
917                   'Hamburg'                => '5',
918                   'Hessen'                 => '6',
919                   'Mecklenburg Vorpommern' => '7',
920                   'Niedersachsen'          => '8',
921                   'Nordrhein Westfalen'    => '9',
922                   'Rheinland Pfalz'        => '10',
923                   'Saarland'               => '11',
924                   'Sachsen'                => '12',
925                   'Sachsen Anhalt'         => '13',
926                   'Schleswig Holstein'     => '14',
927                   'Thüringen'              => '15',
928             );
929       foreach my $land ( keys %lands ){
930         $form->{taxbird_land_nr} = $lands{$land} if ($form->{elsterland} eq $land );
931       }
932       
933       $form->{co_zip} = $form->{co_city};
934       $form->{co_zip} =~ s/\D//g;
935       $form->{co_city} =~ s/\d//g;
936       $form->{co_city} =~ s/^\s//g;
937       
938       ($form->{co_phone_prefix}, $form->{co_phone}) = split("-", $form->{tel});
939       $form->{co_phone_prefix} =~ s/\s//g;
940       $form->{co_phone} =~ s/\s//g;
941       
942        $form->{taxbird_steuernummer} = $form->{steuernummer};
943       #      $form->{taxbird_steuernummer} =~ s/\D//g;
944       $form->{taxbird_steuernummer} =~ s/\///; # ersten Querstrich ersetzen
945       
946       # Numberformatting for Taxbird
947       my $temp_numberformat = $myconfig{numberformat};
948       # Numberformat must be '1000,00' for Taxbird ?!
949       $myconfig{numberformat} = '1000,00';
950       foreach my $number (@category_cent) {
951         $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
952       }
953       
954       foreach my $number (@category_euro) {
955         $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
956       }
957       # Re-set Numberformat
958       $myconfig{numberformat} = $temp_numberformat;
959       
960       # push Kennziffern to <%foreach Array fo easyer
961       # output in xml format. Thx to Moritz.
962       my %taxbird_id_for = (
963            
964           '511'  =>  'Kz51-calc',
965           '861'  =>  'Kz86-calc',
966           '971'  =>  'Kz97-calc',
967           '931'  =>  'Kz93-calc',
968           '811'  =>  'Kz81-calc',
969           '891'  =>  'Kz89-calc',
970           'Z45'  =>  'uebertrag',
971           'Z53'  =>  'ust-sum',
972           'Z62'  =>  'ust-minus-vost',
973           'Z65'  =>  'ust-sum+69',
974           'Z67'  =>  'ust-vz',
975       );
976             
977       
978       for my $kennziffer (@category_cent, @category_euro) {
979
980         next if ($kennziffer eq 'Z43');
981
982         if ($form->{$kennziffer} != 0){
983           if (defined $taxbird_id_for{$kennziffer}) {
984             push(@{ $form->{id}}, $taxbird_id_for{$kennziffer});
985           } else {
986             push(@{ $form->{id}}, "Kz$kennziffer"); 
987           }
988           push(@{ $form->{amount}}, $form->{$kennziffer});
989         }
990       }    
991       
992     } elsif ( $form->{format} eq '' ){ # No format error.
993       $form->header;
994       USTVA::error( $locale->text('Application Error. No Format given' ) . "!");
995       exit(0);
996    
997     } else { # All other Formats are wrong
998       $form->header;
999       USTVA::error( $locale->text('Application Error. Wrong Format') . ": " . $form->{format} );
1000       exit(0);
1001     }
1002
1003   # Austria
1004   } elsif ($form->{coa} eq 'Austria') {
1005
1006     #
1007     # Outputformat specific customisation's
1008     #
1009
1010     my @category_euro = qw(
1011       511 861 36   80   971  931  98   96   53   74
1012       85  65  66   61   62   67   63   64   59   69 
1013       39  83  811  891  Z43  Z45  Z53  Z62  Z65  Z67
1014       41 44 49 43 48 51 86 35 77 76 91 89
1015       97 93 95 94 42 60 45 52 73 84 81 
1016     );
1017     
1018
1019     if ( $form->{format} eq 'html') { # Formatierungen für HTML Ausgabe
1020
1021       $form->{IN} = $form->{type} . '.html';
1022       $form->{padding} = "&nbsp;&nbsp;";
1023       $form->{bold}    = "<b>";
1024       $form->{endbold} = "</b>";
1025       $form->{br}      = "<br>";
1026       $form->{address} =~ s/\\n/\n/g;
1027
1028       foreach $number (@category_euro) {
1029         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '0');
1030       }
1031     }
1032     
1033   }
1034
1035   # end nation specific customisations
1036   
1037   if ( $form->{period} eq '13' and $form->{format} ne 'html') {
1038     $form->header;
1039     USTVA::info(
1040       $locale->text(
1041       'Yearly taxreport not yet implemented')
1042       . '!');
1043   }
1044     
1045   $form->{templates} = $myconfig{templates};
1046   $form->{templates} = "doc" if ( $form->{type} eq 'help' );
1047
1048   $form->parse_template(\%myconfig, $userspath);
1049
1050   $lxdebug->leave_sub();
1051 }
1052
1053 sub config_step1 {
1054   $lxdebug->enter_sub();
1055
1056   # edit all taxauthority prefs
1057
1058   $form->header;
1059   &get_config($userspath, 'finanzamt.ini');
1060
1061   my $land = $form->{elsterland};
1062   my $amt  = $form->{elsterFFFF};
1063
1064
1065   if ($form->{cbscript} ne '' and $form->{cblogin} ne '') {
1066     $callback =  qq|$form->{cbscript}|
1067                 .qq|?action="config_step1"|
1068                 .qq|&login="$form->{cblogin}"|
1069                 .qq|&path="$form->{cbpath}"|
1070                 .qq|&root="$form->{cbroot}"|
1071                 .qq|&rpw="$form->{cbrpw}"|;
1072   }
1073
1074   $form->{title} = $locale->text('Tax Office Preferences');
1075
1076
1077   my $select_tax_office = USTVA->fa_auswahl($land, $amt, &elster_hash());
1078   my $checked_accrual = q|checked="checked"| if ($form->{method} eq 'accrual');
1079   my $checked_cash = q|checked="checked"| if ($form->{method} eq 'cash');
1080   my $checked_monthly = "checked" if ($form->{FA_voranmeld} eq 'month');
1081   my $checked_quarterly = "checked" if ($form->{FA_voranmeld} eq 'quarter');
1082   my $checked_dauerfristverlaengerung = "checked" if ($form->{FA_dauerfrist} eq '1');
1083   my $checked_kz_71 = "checked" if ($form->{FA_71} eq 'X');
1084
1085   my $_hidden_variables_ref;
1086
1087   my %_hidden_local_variables = (    
1088     'saved'       => $locale->text('Check Details'),
1089     'nextsub'     => 'config_step2',
1090     'warnung'     => '0',
1091   );
1092
1093   foreach my $variable (keys %_hidden_local_variables) {
1094     push @{ $_hidden_variables_ref }, 
1095         { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
1096   }
1097
1098   my @_hidden_form_variables = qw(
1099     FA_Name             FA_Strasse        FA_PLZ             
1100     FA_Ort              FA_Telefon        FA_Fax           
1101     FA_PLZ_Grosskunden  FA_PLZ_Postfach   FA_Postfach 
1102     FA_BLZ_1            FA_Kontonummer_1  FA_Bankbezeichnung_1  
1103     FA_BLZ_2            FA_Kontonummer_2  FA_Bankbezeichnung_oertlich
1104     FA_Oeffnungszeiten  FA_Email          FA_Internet
1105     steuernummer        elsterland        elstersteuernummer
1106     elsterFFFF          path              login
1107     password
1108   );
1109
1110   foreach my $variable (@_hidden_form_variables) {
1111     push @{ $_hidden_variables_ref}, 
1112         { 'variable' => $variable, 'value' => $form->{$variable} };
1113   }
1114
1115   # hä? kann die weg?
1116   my $steuernummer_new = '';
1117
1118   # Variablen für das Template zur Verfügung stellen
1119   my $template_ref = {
1120      select_tax_office               => $select_tax_office,
1121      checked_accrual                 => $checked_accrual,
1122      checked_cash                    => $checked_cash,
1123      checked_monthly                 => $checked_monthly,
1124      checked_quarterly               => $checked_quarterly,
1125      checked_dauerfristverlaengerung => $checked_dauerfristverlaengerung,
1126      hidden_variables                => $_hidden_variables_ref,
1127      
1128   };
1129   
1130   # Ausgabe des Templates
1131   print($form->parse_html_template('ustva/config_step1', $template_ref));
1132
1133   $lxdebug->leave_sub();
1134 }
1135
1136 sub config_step2 {
1137   $lxdebug->enter_sub();
1138   $form->header();
1139
1140 #  print qq|
1141 #    <body>
1142 #  |;
1143
1144   my $elsterland         = '';
1145   my $elster_amt         = '';
1146   my $elsterFFFF         = '';
1147   my $elstersteuernummer = '';
1148   &get_config($userspath, 'finanzamt.ini')
1149     if ($form->{saved} eq $locale->text('saved'));
1150
1151   # Auf Übergabefehler checken
1152   USTVA::info(  $locale->text('Missing Tax Authoritys Preferences') . "\n"
1153               . $locale->text('USTVA-Hint: Tax Authoritys'))
1154     if (   $form->{elsterFFFF_new} eq 'Auswahl'
1155         || $form->{elsterland_new} eq 'Auswahl');
1156   USTVA::info(  $locale->text('Missing Method!') . "\n"
1157               . $locale->text('USTVA-Hint: Method'))
1158     if ($form->{method} eq '');
1159
1160   # Klären, ob Variablen bereits befüllt sind UND ob veräderungen auf
1161   # der vorherigen Maske stattfanden: $change = 1(in der edit sub,
1162   # mittels get_config)
1163
1164   my $change = $form->{elsterland} eq $form->{elsterland_new}
1165     && $form->{elsterFFFF} eq $form->{elsterFFFF_new} ? '0' : '1';
1166   $change = '0' if ($form->{saved} eq $locale->text('saved'));
1167   my $elster_init = &elster_hash();
1168
1169   my %elster_init = %$elster_init;
1170
1171   if ($change eq '1') {
1172
1173     # Daten ändern
1174     $elsterland           = $form->{elsterland_new};
1175     $elsterFFFF           = $form->{elsterFFFF_new};
1176     $form->{elsterland}   = $elsterland;
1177     $form->{elsterFFFF}   = $elsterFFFF;
1178     $form->{steuernummer} = '';
1179     
1180     create_steuernummer();
1181
1182     # rebuild elster_amt
1183     my $amt = '';
1184     foreach $amt (keys %{ $elster_init{ $form->{elsterland} } }) {
1185       $elster_amt = $amt
1186         if ($elster_init{ $form->{elsterland}{$amt} eq $form->{elsterFFFF} });
1187     }
1188
1189     # load the predefined hash data into the FA_* Vars
1190     my @variables = qw(FA_Name FA_Strasse FA_PLZ FA_Ort
1191       FA_Telefon FA_Fax FA_PLZ_Grosskunden FA_PLZ_Postfach
1192       FA_Postfach
1193       FA_BLZ_1 FA_Kontonummer_1 FA_Bankbezeichnung_1
1194       FA_BLZ_2 FA_Kontonummer_2 FA_Bankbezeichnung_oertlich
1195       FA_Oeffnungszeiten FA_Email FA_Internet);
1196
1197     for (my $i = 0; $i <= 20; $i++) {
1198       $form->{ $variables[$i] } =
1199         $elster_init->{$elsterland}->{$elsterFFFF}->[$i];
1200     }
1201
1202   } else {
1203
1204     $elsterland = $form->{elsterland};
1205     $elsterFFFF = $form->{elsterFFFF};
1206
1207   }
1208   my $stnr = $form->{steuernummer};
1209   $stnr =~ s/\D+//g;
1210   my $patterncount   = $form->{patterncount};
1211   my $elster_pattern = $form->{elster_pattern};
1212   my $delimiter      = $form->{delimiter};
1213   my $steuernummer = $form->{steuernummer} if ($steuernummer eq '');
1214
1215   $form->{FA_Oeffnungszeiten} =~ s/\\\\n/\n/g;
1216   
1217   
1218
1219   my $input_steuernummer = USTVA->steuernummer_input(
1220                              $form->{elsterland}, 
1221                              $form->{elsterFFFF},
1222                              $form->{steuernummer}
1223   );
1224
1225   $lxdebug->message(LXDebug::DEBUG1, qq|$input_steuernummer|);
1226  
1227
1228   my $_hidden_variables_ref;
1229
1230   my %_hidden_local_variables = (
1231       'elsterland'          => $elsterland,
1232       'elsterFFFF'          => $elsterFFFF,
1233       'warnung'             => $warnung,
1234       'elstersteuernummer'  => $elstersteuernummer,
1235       'steuernummer'        => $stnr,
1236       'lastsub'             => 'config_step1',
1237       'nextsub'             => 'save',
1238       
1239   );
1240   
1241   foreach my $variable (keys %_hidden_local_variables) {
1242     push @{ $_hidden_variables_ref }, 
1243         { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
1244   }
1245  
1246   my @_hidden_form_variables = qw(
1247     FA_steuerberater_name   FA_steuerberater_street 
1248     FA_steuerberater_city   FA_steuerberater_tel
1249     FA_voranmeld            method
1250     FA_dauerfrist           FA_71 
1251     elster                  path 
1252     login                   password 
1253     type                    elster_init 
1254     saved                   callback
1255   );
1256
1257
1258
1259   foreach my $variable (@_hidden_form_variables) {
1260     push @{ $_hidden_variables_ref}, 
1261         { 'variable' => $variable, 'value' => $form->{$variable} };
1262   }
1263
1264   my $template_ref = {
1265      tax_office_data                 => $tax_office_data,
1266      input_steuernummer              => $input_steuernummer,
1267      readonly                        => '', #q|disabled="disabled"|,
1268      callback                        => $callback,
1269      hidden_variables                => $_hidden_variables_ref,
1270   };
1271   
1272   # Ausgabe des Templates
1273   print($form->parse_html_template('ustva/config_step2', $template_ref));
1274
1275
1276   $lxdebug->leave_sub();
1277 }
1278
1279 sub create_steuernummer {
1280   $lxdebug->enter_sub();
1281   my $part           = $form->{part};
1282   my $patterncount   = $form->{patterncount};
1283   my $delimiter      = $form->{delimiter};
1284   my $elster_pattern = $form->{elster_pattern};
1285
1286   # rebuild steuernummer and elstersteuernummer
1287   # es gibt eine gespeicherte steuernummer $form->{steuernummer}
1288   # und die parts und delimiter
1289
1290   my $h = 0;
1291   my $i = 0;
1292
1293   my $steuernummer_new       = $part;
1294   my $elstersteuernummer_new = $form->{elster_FFFF};
1295   $elstersteuernummer_new .= '0';
1296
1297   for ($h = 1; $h < $patterncount; $h++) {
1298     $steuernummer_new .= qq|$delimiter|;
1299     for (my $i = 1; $i <= length($elster_pattern); $i++) {
1300       $steuernummer_new       .= $form->{"part_$h\_$i"};
1301       $elstersteuernummer_new .= $form->{"part_$h\_$i"};
1302     }
1303   }
1304   if ($form->{steuernummer} ne $steuernummer_new) {
1305     $form->{steuernummer}       = $steuernummer_new;
1306     $form->{elstersteuernummer} = $elstersteuernummer_new;
1307     $form->{steuernummer_new}   = $steuernummer_new;
1308   } else {
1309     $form->{steuernummer_new}       = '';
1310     $form->{elstersteuernummer_new} = '';
1311   }
1312   $lxdebug->leave_sub();
1313 }
1314
1315 sub get_config {
1316   $lxdebug->enter_sub();
1317
1318   my ($userpath, $filename) = @_;
1319   my ($key,      $value)    = '';
1320   open(FACONF, "$userpath/$form->{login}_$filename")
1321     or    #falls Datei nicht vorhanden ist
1322     sub {
1323     open(FANEW, ">$userpath/$form->{login}_$filename")
1324       or $form->error("$userpath/$filename : $!");
1325     close FANEW;
1326     open(FACONF, "$userpath/$form->{login}_$filename")
1327       or $form->error("$userpath/$form->{username}_$filename : $!");
1328     };
1329   while (<FACONF>) {
1330     last if /^\[/;
1331     next if /^(#|\s)/;
1332
1333     # remove comments
1334     s/\s#.*//g;
1335
1336     # remove any trailing whitespace
1337     s/^\s*(.*?)\s*$/$1/;
1338     ($key, $value) = split /=/, $_, 2;
1339
1340     $form->{$key} = "$value";
1341
1342   }
1343   close FACONF;
1344
1345   $lxdebug->leave_sub();
1346 }
1347
1348 sub save {
1349   $lxdebug->enter_sub();
1350   my $filename = "$form->{login}_$form->{filename}";
1351
1352   #zuerst die steuernummer aus den part, parts_X_Y und delimiter herstellen
1353   create_steuernummer();
1354
1355   # Textboxen formatieren: Linebreaks entfernen
1356   #
1357   $form->{FA_Oeffnungszeiten} =~ s/\r\n/\\n/g;
1358
1359   #URL mit http:// davor?
1360   $form->{FA_Internet} =~ s/^http:\/\///;
1361   $form->{FA_Internet} = 'http://' . $form->{FA_Internet};
1362
1363   my @config = qw(
1364     elster              elsterland            elstersteuernummer  steuernummer
1365     elsteramt           elsterFFFF            FA_Name             FA_Strasse
1366     FA_PLZ              FA_Ort                FA_Telefon          FA_Fax 
1367     FA_PLZ_Grosskunden  FA_PLZ_Postfach       FA_Postfach         FA_BLZ_1 
1368     FA_Kontonummer_1    FA_Bankbezeichnung_1  FA_BLZ_2            FA_Kontonummer_2
1369     FA_Bankbezeichnung_oertlich FA_Oeffnungszeiten
1370     FA_Email FA_Internet FA_voranmeld method FA_steuerberater_name
1371     FA_steuerberater_street FA_steuerberater_city FA_steuerberater_tel
1372     FA_71 FA_dauerfrist);
1373
1374   # Hier kommt dann die Plausibilitätsprüfung der ELSTERSteuernummer
1375   if ($form->{elstersteuernummer} ne '000000000') {
1376     $form->{elster} = '1';
1377     open(CONF, ">$userspath/$filename") or $form->error("$filename : $!");
1378
1379     # create the config file
1380     print CONF qq|# Configuration file for USTVA\n\n|;
1381     my $key = '';
1382     foreach $key (sort @config) {
1383       $form->{$key} =~ s/\\/\\\\/g;
1384       # strip M
1385       $form->{$key} =~ s/\r\n/\n/g;
1386
1387       print CONF qq|$key=|;
1388       if ($form->{$key} ne 'Y') {
1389         print CONF qq|$form->{$key}\n|;
1390       }
1391       if ($form->{$key} eq 'Y') {
1392         print CONF qq|checked \n|;
1393       }
1394     }
1395     print CONF qq|\n\n|;
1396     close CONF;
1397     $form->{saved} = $locale->text('saved');
1398
1399   } else {
1400
1401     $form->{saved} = $locale->text('Choose a Tax Number');
1402   }
1403
1404   config_step2();
1405   $lxdebug->leave_sub();
1406 }
1407
1408
1409 sub continue {
1410   $lxdebug->enter_sub();
1411
1412   # allow Symbolic references just here:
1413   no strict 'refs';
1414   &{ $form->{nextsub} };
1415   use strict 'refs';
1416   $lxdebug->leave_sub();
1417 }
1418
1419 sub back {
1420   $lxdebug->enter_sub();
1421   &{ $form->{lastsub} };
1422   $lxdebug->leave_sub();
1423 }
1424
1425 sub elster_hash {
1426   $lxdebug->enter_sub();
1427   my $finanzamt = USTVA->query_finanzamt(\%myconfig, \%$form);
1428   $lxdebug->leave_sub();
1429   return $finanzamt;
1430 }
1431
1432