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