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