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