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