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