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