1 #=====================================================================
3 # Copyright (c) 2004 by Udo Spallek, Aachen
7 # Web: http://www.lx-office.org
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.
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 #======================================================================
28 require "bin/mozilla/common.pl";
33 #use warnings; # FATAL=> 'all';
34 #use vars qw($locale $form %myconfig);
36 #use CGI::Carp "fatalsToBrowser";
38 use List::Util qw(first);
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')
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')
74 #############################
77 $lxdebug->enter_sub();
79 $auth->assert('advance_turnover_tax_return');
81 my $myconfig = \%myconfig;
83 $form->{title} = $locale->text('UStVA');
84 $form->{kz10} = ''; #Berichtigte Anmeldung? Ja =1 Nein=0
86 my $year = substr($form->datetonum($form->current_date(\%myconfig), \%myconfig ),
93 # Einlesen der Finanzamtdaten
94 my $ustva = USTVA->new();
95 $ustva->get_config($userspath, 'finanzamt.ini');
97 # Hier Einlesen der user-config
98 # steuernummer entfernt für prerelease
100 signature name company address businessnumber
101 tel fax email co_chief co_department
102 co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
103 co_name1 co_name2 co_street co_street1 co_zip
104 co_city co_city1 co_country co_tel co_tel1
105 co_tel2 co_fax co_fax1 co_email co_email1
106 co_url co_url1 ustid duns co_bankname
107 co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
108 co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2
112 map { $form->{$_} = $myconfig->{$_} } @a;
114 my $openings = $form->{FA_Oeffnungszeiten};
115 $openings =~ s/\\\\n/<br>/g;
117 my $company_given = ($form->{company} ne '')
118 ? qq|<h3>$form->{company}</h3>\n|
119 : qq|<a href="am.pl?action=config">|
120 . $locale->text('No Company Name given') . qq|!</a><br>|;
123 # Anpassungen der Variablennamen auf pre 2.1.1 Namen
124 # klären, ob $form->{company_street|_address} gesetzt sind
125 if ($form->{address} ne '') {
126 my $temp = $form->{address};
127 $temp =~ s/\n/<br \/>/;
128 ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
129 $form->{co_city} =~ s/\n//g;
134 ($form->{co_street} && ($form->{co_zip} || $form->{co_city}))
135 ? qq|$form->{co_street}<br>|
136 . qq|$form->{co_street1}<br>|
137 . qq|$form->{co_zip} $form->{co_city}|
138 : qq|<a href="am.pl?action=config|
139 . qq|&level=Programm--Preferences">|
140 . $locale->text('No Company Address given')
143 $form->{co_email} = $form->{email} unless $form->{co_email};
144 $form->{co_tel} = $form->{tel} unless $form->{co_tel};
145 $form->{co_fax} = $form->{fax} unless $form->{co_fax};
146 $form->{co_url} = $form->{urlx} unless $form->{co_url};
148 my $taxnumber_given = ($form->{steuernummer} ne '') ? $form->{steuernummer} : qq|<a href="ustva.pl?action=config_step1">Keine Steuernummer hinterlegt!</a><br>|;
150 my $ustva_vorauswahl = &ustva_vorauswahl();
152 my @all_years = $form->all_years(\%myconfig);
154 my $select_year = qq|<select name=year title="|
155 . $locale->text('Year') . qq|">|;
156 foreach my $key (@all_years) {
157 $select_year .= qq|<option |;
158 $select_year .= qq|selected| if ($key eq $form->{year});
159 $select_year .= qq| >$key</option>|;
161 $select_year .= qq|</select>|;
164 $_checked = "checked" if ($form->{kz10} eq '1');
165 my $checkbox_kz_10 = qq|<input name="FA_10" id=FA_10 class=checkbox|
166 . qq| type=checkbox value="1" $_checked title = "|
167 . $locale->text('Amended Advance Turnover Tax Return (Nr. 10)')
169 . $locale->text('Amended Advance Turnover Tax Return');
171 my $method_local = ($form->{method} eq 'accrual') ? $locale->text('accrual')
172 : ($form->{method} eq 'cash') ? $locale->text('cash')
175 my $period_local = ( $form->{FA_voranmeld} eq 'month') ? $locale->text('month')
176 : ( $form->{FA_voranmeld} eq 'quarter') ? $locale->text('quarter')
179 my $tax_office_banks_ref = [
180 { BLZ => $form->{FA_BLZ_1},
181 Kontonummer => $form->{FA_Kontonummer_1},
182 Bankbezeichnung => $form->{FA_Bankbezeichnung_1}
184 { BLZ => $form->{FA_BLZ_2},
185 Kontonummer => $form->{FA_Kontonummer_2},
186 Bankbezeichnung => $form->{FA_Bankbezeichnung_oertlich}
190 # Which COA is in use?
192 $ustva->get_coa($form, $myconfig);
195 openings => $openings,
196 company_given => $company_given,
197 address_given => $address_given,
198 taxnumber_given => $taxnumber_given,
199 taxnumber => $myconfig->{taxnumber},
200 select_year => $select_year,
201 period_local => $period_local,
202 method_local => $method_local,
203 ustva_vorauswahl => $ustva_vorauswahl,
204 checkbox_kz_10 => $checkbox_kz_10,
205 tax_office_banks => $tax_office_banks_ref,
206 select_options => &show_options,
210 print($form->parse_html_template('ustva/report', $template_ref));
214 $lxdebug->leave_sub();
220 $lxdebug->enter_sub();
222 $auth->assert('advance_turnover_tax_return');
224 # parse help documents under doc
225 my $tmp = $form->{templates};
226 $form->{templates} = 'doc';
227 $form->{help} = 'ustva';
228 $form->{type} = 'help';
229 $form->{format} = 'html';
232 #$form->{templates} = $tmp;
233 $lxdebug->leave_sub();
237 $lxdebug->enter_sub();
239 $auth->assert('advance_turnover_tax_return');
243 $lxdebug->leave_sub();
244 call_sub($form->{"nextsub"});
248 sub ustva_vorauswahl {
249 $lxdebug->enter_sub();
251 $auth->assert('advance_turnover_tax_return');
253 my $select_vorauswahl;
255 #Aktuelles Datum zerlegen:
256 my $date = $form->datetonum($form->current_date(\%myconfig), \%myconfig);
258 #$locale->date($myconfig, $form->current_date($myconfig), 0)=~ /(\d\d).(\d\d).(\d\d\d\d)/;
259 $form->{day} = substr($date, 6, 2);
260 $form->{month} = substr($date, 4, 2);
261 $form->{year} = substr($date, 0, 4);
262 $lxdebug->message(LXDebug::DEBUG1, qq|
263 Actual date from Database: $date\n
264 Actual year from Database: $form->{year}\n
265 Actual day from Database: $form->{day}\n
266 Actual month from Database: $form->{month}\n|);
271 # Testdaten erzeugen:
273 #$form->{month}= '01';
274 #$form->{year}= 2004;
275 $select_vorauswahl = qq|
276 <input type=hidden name=day value=$form->{day}>
277 <input type=hidden name=month value=$form->{month}>
278 <input type=hidden name=yymmdd value=$yymmdd>
279 <input type=hidden name=sel value=$sel>
282 if ($form->{FA_voranmeld} eq 'month') {
284 # Vorauswahl bei monatlichem Voranmeldungszeitraum
286 my %liste = ('01' => $locale->text('January'),
287 '02' => $locale->text('February'),
288 '03' => $locale->text('March'),
289 '04' => $locale->text('April'),
290 '05' => $locale->text('May'),
291 '06' => $locale->text('June'),
292 '07' => $locale->text('July'),
293 '08' => $locale->text('August'),
294 '09' => $locale->text('September'),
295 '10' => $locale->text('October'),
296 '11' => $locale->text('November'),
297 '12' => $locale->text('December'),
298 '13' => $locale->text('Yearly'),
301 my $yy = $form->{year} * 10000;
302 $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
306 # Offset für Dauerfristverlängerung
307 $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
310 $yymmdd <= ($yy + 110 + $dfv) && do {
311 $form->{year} = $form->{year} - 1;
315 $yymmdd <= ($yy + 210 + $dfv) && do {
319 $yymmdd <= ($yy + 310 + $dfv) && do {
323 $yymmdd <= ($yy + 410 + $dfv) && do {
327 $yymmdd <= ($yy + 510 + $dfv) && do {
331 $yymmdd <= ($yy + 610 + $dfv) && do {
335 $yymmdd <= ($yy + 710 + $dfv) && do {
339 $yymmdd <= ($yy + 810 + $dfv) && do {
343 $yymmdd <= ($yy + 910 + $dfv) && do {
347 $yymmdd <= ($yy + 1010 + $dfv) && do {
351 $yymmdd <= ($yy + 1110 + $dfv) && do {
355 $yymmdd <= ($yy + 1210) && do {
359 $yymmdd <= ($yy + 1231) && do {
365 $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
366 . $locale->text('Select a period') . qq|" >|;
369 foreach $key (sort keys %liste) {
371 $selected = 'selected' if ($sel eq $key);
372 $select_vorauswahl .= qq|
373 <option value="$key" $selected> $liste{$key}</option>
376 $select_vorauswahl .= qq|</select>|;
378 } elsif ($form->{FA_voranmeld} eq 'quarter') {
380 # Vorauswahl bei quartalsweisem Voranmeldungszeitraum
381 my %liste = ('41' => $locale->text('1. Quarter'),
382 '42' => $locale->text('2. Quarter'),
383 '43' => $locale->text('3. Quarter'),
384 '44' => $locale->text('4. Quarter'),
385 '13' => $locale->text('Yearly'),);
387 my $yy = $form->{year} * 10000;
388 $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
390 my $dfv = ''; # Offset für Dauerfristverlängerung
391 $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
394 $yymmdd <= ($yy + 110 + $dfv) && do {
395 $form->{year} = $form->{year} - 1;
399 $yymmdd <= ($yy + 410 + $dfv) && do {
403 $yymmdd <= ($yy + 710 + $dfv) && do {
407 $yymmdd <= ($yy + 1010 + $dfv) && do {
411 $yymmdd <= ($yy + 1231) && do {
416 $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
417 . $locale->text('Select a period') . qq|" >|;
419 foreach $key (sort keys %liste) {
421 $selected = 'selected' if ($sel eq $key);
422 $select_vorauswahl .= qq|
423 <option value="$key" $selected>$liste{$key}</option>
426 $select_vorauswahl .= qq|\n</select>
431 # keine Vorauswahl bei Voranmeldungszeitraum
432 $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
433 . $locale->text('Select a period') . qq|" >|;
435 my %listea = ('41' => '1. Quarter',
436 '42' => '2. Quarter',
437 '43' => '3. Quarter',
438 '44' => '4. Quarter',);
440 my %listeb = ('01' => 'January',
454 foreach $key (sort keys %listea) {
455 $select_vorauswahl .= qq|
456 <option value="$key">|
457 . $locale->text("$listea{$key}")
461 foreach $key (sort keys %listeb) {
462 $select_vorauswahl .= qq|
463 <option value="$key">|
464 . $locale->text("$listeb{$key}")
467 $select_vorauswahl .= qq|</select>|;
469 $lxdebug->leave_sub();
471 return $select_vorauswahl;
475 # $lxdebug->enter_sub();
477 # $lxdebug->leave_sub();
481 $lxdebug->enter_sub();
483 $lxdebug->leave_sub();
487 $lxdebug->enter_sub();
489 $auth->assert('advance_turnover_tax_return');
491 # $form->{PD}{$form->{type}} = "selected";
492 # $form->{DF}{$form->{format}} = "selected";
493 # $form->{OP}{$form->{media}} = "selected";
494 # $form->{SM}{$form->{sendmode}} = "selected";
495 my $type = qq| <input type=hidden name="type" value="ustva">|;
496 my $media = qq| <input type=hidden name="media" value="screen">|;
498 qq| <option value=html selected>|
499 . $locale->text('Preview')
501 if ($latex_templates) {
503 qq| <option value=pdf>|
504 . $locale->text('UStVA (PDF-Dokument)')
508 #my $disabled= qq|disabled="disabled"|;
509 #$disabled='' if ($form->{elster} eq '1' );
510 if ($form->{elster} eq '1') {
512 qq|<option value=elsterwinston>|
513 . $locale->text('ELSTER Export (Winston)')
515 . qq|<option value=elstertaxbird>|
516 . $locale->text('ELSTER Export (Taxbird)')
520 #$format .= qq|<option value=elster>|.$locale->text('ELSTER Export nach Winston').qq|</option>|;
521 my $show_options = qq|
524 <select name=format title = "|
525 . $locale->text('Choose Outputformat') . qq|">$format</select>
527 $lxdebug->leave_sub();
529 return $show_options;
533 $lxdebug->enter_sub();
535 $auth->assert('advance_turnover_tax_return');
537 # Aufruf von get_config zum Einlesen der Finanzamtdaten aus finanzamt.ini
539 my $ustva = USTVA->new();
540 $ustva->get_config($userspath, 'finanzamt.ini');
542 # init some form vars
543 my @anmeldungszeitraum =
544 qw('0401' '0402' '0403'
548 '0441' '0442' '0443' '0444');
550 foreach my $item (@anmeldungszeitraum) {
554 #forgotten the year --> thisyear
555 if ($form->{year} !~ m/^\d\d\d\d$/) {
556 $form->{year} = substr(
558 $form->current_date(\%myconfig), \%myconfig
561 $lxdebug->message(LXDebug::DEBUG1,
562 qq|Actual year from Database: $form->{year}\n|);
566 # using dates in ISO-8601 format: yyyymmmdd for Postgres...
570 if ($form->{period} eq "13") {
571 $form->{fromdate} = "$form->{year}0101";
572 $form->{todate} = "$form->{year}1231";
576 if ($form->{period} eq "41") {
577 $form->{fromdate} = "$form->{year}0101";
578 $form->{todate} = "$form->{year}0331";
579 $form->{'0441'} = "X";
581 if ($form->{period} eq "42") {
582 $form->{fromdate} = "$form->{year}0401";
583 $form->{todate} = "$form->{year}0630";
584 $form->{'0442'} = "X";
586 if ($form->{period} eq "43") {
587 $form->{fromdate} = "$form->{year}0701";
588 $form->{todate} = "$form->{year}0930";
589 $form->{'0443'} = "X";
591 if ($form->{period} eq "44") {
592 $form->{fromdate} = "$form->{year}1001";
593 $form->{todate} = "$form->{year}1231";
594 $form->{'0444'} = "X";
599 $form->{period} eq "01" && do {
600 $form->{fromdate} = "$form->{year}0101";
601 $form->{todate} = "$form->{year}0131";
602 $form->{'0401'} = "X";
605 $form->{period} eq "02" && do {
606 $form->{fromdate} = "$form->{year}0201";
608 #this works from 1901 to 2099, 1900 and 2100 fail.
609 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
610 $form->{todate} = "$form->{year}02$leap";
611 $form->{"0402"} = "X";
614 $form->{period} eq "03" && do {
615 $form->{fromdate} = "$form->{year}0301";
616 $form->{todate} = "$form->{year}0331";
617 $form->{"0403"} = "X";
620 $form->{period} eq "04" && do {
621 $form->{fromdate} = "$form->{year}0401";
622 $form->{todate} = "$form->{year}0430";
623 $form->{"0404"} = "X";
626 $form->{period} eq "05" && do {
627 $form->{fromdate} = "$form->{year}0501";
628 $form->{todate} = "$form->{year}0531";
629 $form->{"0405"} = "X";
632 $form->{period} eq "06" && do {
633 $form->{fromdate} = "$form->{year}0601";
634 $form->{todate} = "$form->{year}0630";
635 $form->{"0406"} = "X";
638 $form->{period} eq "07" && do {
639 $form->{fromdate} = "$form->{year}0701";
640 $form->{todate} = "$form->{year}0731";
641 $form->{"0407"} = "X";
644 $form->{period} eq "08" && do {
645 $form->{fromdate} = "$form->{year}0801";
646 $form->{todate} = "$form->{year}0831";
647 $form->{"0408"} = "X";
650 $form->{period} eq "09" && do {
651 $form->{fromdate} = "$form->{year}0901";
652 $form->{todate} = "$form->{year}0930";
653 $form->{"0409"} = "X";
656 $form->{period} eq "10" && do {
657 $form->{fromdate} = "$form->{year}1001";
658 $form->{todate} = "$form->{year}1031";
659 $form->{"0410"} = "X";
662 $form->{period} eq "11" && do {
663 $form->{fromdate} = "$form->{year}1101";
664 $form->{todate} = "$form->{year}1130";
665 $form->{"0411"} = "X";
668 $form->{period} eq "12" && do {
669 $form->{fromdate} = "$form->{year}1201";
670 $form->{todate} = "$form->{year}1231";
671 $form->{"0412"} = "X";
676 # Kontrollvariablen für die Templates
677 $form->{"year$_"} = ($form->{year} >= $_ ) ? "1":"0" for 2007..2107;
680 $ustva->ustva(\%myconfig, \%$form);
682 # reformat Dates to dateformat
683 $form->{fromdate} = $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);
685 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
686 $form->{todate} = $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
688 $form->{longperiod} =
689 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1, 0, 0);
691 # if there are any dates construct a where
692 if ($form->{fromdate} || $form->{todate}) {
694 $form->{todate} = $form->current_date($myconfig) unless ($form->{todate});
696 my $longtodate = $locale->date($myconfig, $form->{todate}, 1, 0, 0);
697 my $shorttodate = $locale->date($myconfig, $form->{todate}, 0, 0, 0);
699 my $longfromdate = $locale->date($myconfig, $form->{fromdate}, 1, 0, 0);
700 my $shortfromdate = $locale->date($myconfig, $form->{fromdate}, 0, 0, 0);
702 $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
703 $form->{longperiod} =
704 $locale->text('for Period')
705 . qq|<br>\n$longfromdate |
706 . $locale->text('to (date)')
710 if ($form->{comparefromdate} || $form->{comparetodate}) {
711 my $longcomparefromdate =
712 $locale->date(\%myconfig, $form->{comparefromdate}, 1, 0, 0);
713 my $shortcomparefromdate =
714 $locale->date(\%myconfig, $form->{comparefromdate}, 0, 0, 0);
716 my $longcomparetodate =
717 $locale->date(\%myconfig, $form->{comparetodate}, 1, 0, 0);
718 my $shortcomparetodate =
719 $locale->date(\%myconfig, $form->{comparetodate}, 0, 0, 0);
721 $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
722 $form->{longperiod} .=
723 "<br>\n$longcomparefromdate "
724 . $locale->text('to (date)')
725 . qq| $longcomparetodate|;
728 $form->{Datum_heute} =
729 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0, 0, 0);
731 # setup variables for the form
732 my @a = qw(company businessnumber tel fax email
733 co_chief co_department co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
734 co_name1 co_name2 co_street co_street1 co_zip co_city co_city1 co_country co_tel co_tel1 co_tel2
735 co_fax co_fax1 co_email co_email1 co_url co_url1 ustid duns
736 co_bankname co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
737 co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2 co_accountnr3);
739 map { $form->{$_} = $myconfig{$_} } @a;
741 if ($form->{address} ne '') {
742 my $temp = $form->{address};
743 $temp =~ s/\\n/<br \/>/;
744 ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
745 $form->{co_city} =~ s/\\n//g;
748 ################################
750 # Nation specific customisations
752 ################################
756 if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') {
759 # Outputformat specific customisation's
762 my @category_cent = $ustva->report_variables({
763 myconfig => \%myconfig,
766 attribute => 'position',
770 push @category_cent, qw(83 Z43 Z45 Z53 Z62 Z65 Z67);
772 my @category_euro = $ustva->report_variables({
773 myconfig => \%myconfig,
776 attribute => 'position',
781 $form->{amount} = [];
783 if ( $form->{format} eq 'pdf' or $form->{format} eq 'postscript') {
785 $form->{IN} = "$form->{type}-$form->{year}.tex";
786 $form->{padding} = "~~";
787 $form->{bold} = "\textbf{";
788 $form->{endbold} = "}";
789 $form->{br} = '\\\\';
791 # Zahlenformatierung für Latex USTVA Formulare
793 foreach my $number (@category_euro) {
794 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '');
797 my ${decimal_comma} = ( $myconfig{numberformat} eq '1.000,00'
798 or $myconfig{numberformat} eq '1000,00' ) ? ',':'.';
800 foreach my $number (@category_cent) {
801 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '');
802 $form->{$number} =~ s/${decimal_comma}/~~/g;
805 } elsif ( $form->{format} eq 'html') { # Formatierungen für HTML Ausgabe
807 $form->{IN} = $form->{type} . '.html';
808 $form->{padding} = " ";
809 $form->{bold} = "<b>";
810 $form->{endbold} = "</b>";
811 $form->{br} = "<br>";
812 $form->{address} =~ s/\\n/\n/g;
814 foreach $number (@category_cent) {
815 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '0');
818 foreach $number (@category_euro) {
819 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '0');
822 } elsif ( $form->{format} eq 'elsterwinston' ) {
824 $form->{IN} = 'winston.xml';
827 # Build Winston filename
830 my $file = 'U'; # 1. char 'U' = USTVA
831 $file .= $form->{period};
832 #4. and 5. char = year modulo 100
833 $file .= sprintf("%02d", $form->{year} % 100);
834 #6. to 18. char = Elstersteuernummer
835 #Beispiel: Steuernummer in Bayern
836 #111/222/33334 ergibt für UStVA Jan 2004: U01049111022233334
837 $file .= $form->{elsterFFFF};
838 $file .= $form->{elstersteuernummer};
842 $form->{tmpfile} = "$userspath/$file";
844 $form->{attachment_filename} = $file;
846 # Zahlenformatierung für Winston
848 my $temp_numberformat = $myconfig{numberformat};
850 # Numberformat must be '1000.00' for Winston
852 $myconfig{numberformat} = '1000.00';
854 foreach my $number (@category_cent) {
855 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
858 foreach my $number (@category_euro) {
859 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
861 # Re-set Numberformat
862 $myconfig{numberformat} = $temp_numberformat;
864 # push Kennziffern to <%foreach Array fo easyer
865 # output in xml format. Thx to Moritz.
866 my %winston_id_for = (
870 foreach my $kennziffer (@category_cent, @category_euro) {
872 next if ( $kennziffer =~ m/Z\d\d/);
873 next if ( $form->{$kennziffer} == 0 );
875 if (defined $winston_id_for{$kennziffer} ) {
876 push(@{ $form->{id}}, $winston_id_for{$kennziffer});
878 push(@{ $form->{id}}, "Kz$kennziffer");
880 push(@{ $form->{amount}}, $form->{$kennziffer});
883 } elsif ( $form->{format} eq 'elstertaxbird' ) {
885 # Define serveral filenames
886 $form->{IN} = 'taxbird.txb';
888 $form->{attachment_filename} = "USTVA-" . $form->{period}
889 . sprintf("%02d", $form->{year} % 100) . ".txb";
891 $form->{attachment_filename} =~ s|.*/||;
892 $form->{tmpfile} = "$userspath/" . $form->{attachment_filename};
894 # TODO: set Output to UTF-8 or system Preference
895 #$form->{"iconv"} = Text::Iconv->new($myconfig{dbcharset}, "UTF-8");
896 #my $iconv = $self->{"iconv"};
897 #$iconv->convert($variable);
898 if ($form->{period} =~ /^[4]\d$/ ){
899 my %periods = ( # Lx => taxbird
906 foreach my $quarter ( keys %periods ) {
907 $form->{taxbird_period} = $periods{$quarter} if ( $form->{period} eq $quarter);
909 } elsif ($form->{period} =~ /^\d+$/ ) {
910 $form->{period} =~ s/^0//g;
911 my $period = $form->{period};
914 $form->{taxbird_period} = $period;
917 USTVA::error( $locale->text('Wrong Period' ));
921 # heuristics for address splitting
922 # lx-office holds the entire address in a single field.
923 # taxbird expects it to be splitted into street, zipcode and city
924 if ($form->{co_street} =~ /\n/) {
926 for (split /\n/, $form->{co_street}) {
927 if (/(\d{3,5})\s+(\w+)/) {
928 $form->{co_zip} = $1;
929 $form->{co_city} = $2;
931 $new_co_street .= $_;
934 $form->{co_street} = $new_co_street;
936 $form->{co_zip} = $form->{co_city};
937 $form->{co_zip} =~ s/\D//g;
938 $form->{co_city} =~ s/\d//g;
939 $form->{co_city} =~ s/^\s//g;
942 my $tax_office = first { $_->{name} eq $form->{elsterland} } @{ $ustva->{tax_office_information} };
943 $form->{taxbird_land_nr} = $tax_office->{taxbird_nr} if $tax_office;
945 ($form->{co_phone_prefix}, $form->{co_phone}) = split("-", $form->{tel});
946 $form->{co_phone_prefix} =~ s/\s//g;
947 $form->{co_phone} =~ s/\s//g;
949 $form->{taxbird_steuernummer} = $form->{steuernummer};
950 # $form->{taxbird_steuernummer} =~ s/\D//g;
951 # $form->{taxbird_steuernummer} =~ s/\///; # ersten Querstrich ersetzen
953 # Numberformatting for Taxbird
954 my $temp_numberformat = $myconfig{numberformat};
955 # Numberformat must be '1000,00' for Taxbird ?!
956 $myconfig{numberformat} = '1000,00';
957 foreach my $number (@category_cent) {
958 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
961 foreach my $number (@category_euro) {
962 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
964 # Re-set Numberformat
965 $myconfig{numberformat} = $temp_numberformat;
967 # push Kennziffern to <%foreach Array fo easyer
968 # output in xml format. Thx to Moritz.
969 my %taxbird_id_for = (
971 '511' => 'Kz51-calc',
972 '861' => 'Kz86-calc',
973 '971' => 'Kz97-calc',
974 '931' => 'Kz93-calc',
975 '811' => 'Kz81-calc',
976 '891' => 'Kz89-calc',
977 'Z45' => 'uebertrag',
979 'Z62' => 'ust-minus-vost',
980 'Z65' => 'ust-sum+69',
985 for my $kennziffer (@category_cent, @category_euro) {
987 next if ($kennziffer eq 'Z43');
989 if ($form->{$kennziffer} != 0){
990 if (defined $taxbird_id_for{$kennziffer}) {
991 push(@{ $form->{id}}, $taxbird_id_for{$kennziffer});
993 push(@{ $form->{id}}, "Kz$kennziffer");
995 push(@{ $form->{amount}}, $form->{$kennziffer});
999 } elsif ( $form->{format} eq '' ){ # No format error.
1001 USTVA::error( $locale->text('Application Error. No Format given' ) . "!");
1004 } else { # All other Formats are wrong
1006 USTVA::error( $locale->text('Application Error. Wrong Format') . ": " . $form->{format} );
1011 } else # Outputformat for generic output
1014 my @category_cent = $ustva->report_variables({
1015 myconfig => \%myconfig,
1018 attribute => 'position',
1022 my @category_euro = $ustva->report_variables({
1023 myconfig => \%myconfig,
1026 attribute => 'position',
1030 $form->{USTVA} = [];
1032 if ( $form->{format} eq 'generic') { # Formatierungen für HTML Ausgabe
1035 for my $kennziffer (@category_cent, @category_euro) {
1037 $rec_ref->{id} = $kennziffer;
1038 $rec_ref->{amount} = $form->format_amount(\%myconfig, $form->{$kennziffer}, 2, '0');
1040 $lxdebug->message($LXDebug::DEBUG, "Kennziffer $kennziffer: '$form->{$kennziffer}'" );
1041 $lxdebug->dump($LXDebug::DEBUG, $rec_ref );
1042 push @ { $form->{USTVA} }, $rec_ref;
1049 if ( $form->{period} eq '13' and $form->{format} ne 'html') {
1053 'Yearly taxreport not yet implemented')
1057 $form->{templates} = $myconfig{templates};
1058 $form->{templates} = "doc" if ( $form->{type} eq 'help' );
1060 if ($form->{format} eq 'generic'){
1065 taxnumber => $myconfig{taxnumber},
1068 print($form->parse_html_template('ustva/generic_taxreport', $template_ref));
1073 $form->parse_template(\%myconfig, $userspath);
1077 $lxdebug->leave_sub();
1081 $lxdebug->enter_sub();
1083 $auth->assert('advance_turnover_tax_return');
1085 $form->{title} = $locale->text('Tax Office Preferences');
1087 # edit all taxauthority prefs
1091 my $ustva = USTVA->new();
1092 $ustva->get_config($userspath, 'finanzamt.ini');
1094 my $land = $form->{elsterland};
1095 my $amt = $form->{elsterFFFF};
1098 $form->{title} = $locale->text('Tax Office Preferences');
1101 my $select_tax_office = $ustva->fa_auswahl($land, $amt, $ustva->query_finanzamt(\%myconfig, $form));
1102 my $checked_accrual = q|checked="checked"| if ($form->{method} eq 'accrual');
1103 my $checked_cash = q|checked="checked"| if ($form->{method} eq 'cash');
1104 my $checked_monthly = "checked" if ($form->{FA_voranmeld} eq 'month');
1105 my $checked_quarterly = "checked" if ($form->{FA_voranmeld} eq 'quarter');
1106 my $checked_dauerfristverlaengerung = "checked" if ($form->{FA_dauerfrist} eq '1');
1107 my $checked_kz_71 = "checked" if ($form->{FA_71} eq 'X');
1109 my $_hidden_variables_ref;
1111 my %_hidden_local_variables = (
1112 'saved' => $locale->text('Check Details'),
1113 'nextsub' => 'config_step2',
1117 foreach my $variable (keys %_hidden_local_variables) {
1118 push @{ $_hidden_variables_ref },
1119 { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
1122 my @_hidden_form_variables = qw(
1123 FA_Name FA_Strasse FA_PLZ
1124 FA_Ort FA_Telefon FA_Fax
1125 FA_PLZ_Grosskunden FA_PLZ_Postfach FA_Postfach
1126 FA_BLZ_1 FA_Kontonummer_1 FA_Bankbezeichnung_1
1127 FA_BLZ_2 FA_Kontonummer_2 FA_Bankbezeichnung_oertlich
1128 FA_Oeffnungszeiten FA_Email FA_Internet
1129 steuernummer elsterland elstersteuernummer
1133 foreach my $variable (@_hidden_form_variables) {
1134 push @{ $_hidden_variables_ref},
1135 { 'variable' => $variable, 'value' => $form->{$variable} };
1138 # Which COA is in use?
1140 $ustva->get_coa($form, \%myconfig);
1143 my $steuernummer_new = '';
1145 # Variablen für das Template zur Verfügung stellen
1146 my $template_ref = {
1147 select_tax_office => $select_tax_office,
1148 checked_accrual => $checked_accrual,
1149 checked_cash => $checked_cash,
1150 checked_monthly => $checked_monthly,
1151 checked_quarterly => $checked_quarterly,
1152 checked_dauerfristverlaengerung => $checked_dauerfristverlaengerung,
1153 hidden_variables => $_hidden_variables_ref,
1157 # Ausgabe des Templates
1158 print($form->parse_html_template('ustva/config_step1', $template_ref));
1160 $lxdebug->leave_sub();
1164 $lxdebug->enter_sub();
1166 $auth->assert('advance_turnover_tax_return');
1174 my $elsterland = '';
1175 my $elster_amt = '';
1176 my $elsterFFFF = '';
1177 my $elstersteuernummer = '';
1179 my $ustva = USTVA->new();
1180 $ustva->get_config($userspath, 'finanzamt.ini')
1181 if ($form->{saved} eq $locale->text('saved'));
1183 # Auf Übergabefehler checken
1184 USTVA::info( $locale->text('Missing Tax Authoritys Preferences') . "\n"
1185 . $locale->text('USTVA-Hint: Tax Authoritys'))
1186 if ( $form->{elsterFFFF_new} eq 'Auswahl'
1187 || $form->{elsterland_new} eq 'Auswahl');
1188 USTVA::info( $locale->text('Missing Method!') . "\n"
1189 . $locale->text('USTVA-Hint: Method'))
1190 if ($form->{method} eq '');
1192 # Klären, ob Variablen bereits befüllt sind UND ob veräderungen auf
1193 # der vorherigen Maske stattfanden: $change = 1(in der edit sub,
1194 # mittels get_config)
1196 my $change = $form->{elsterland} eq $form->{elsterland_new}
1197 && $form->{elsterFFFF} eq $form->{elsterFFFF_new} ? '0' : '1';
1198 $change = '0' if ($form->{saved} eq $locale->text('saved'));
1199 my $elster_init = $ustva->query_finanzamt(\%myconfig, $form);
1201 my %elster_init = %$elster_init;
1203 if ($change eq '1') {
1206 $elsterland = $form->{elsterland_new};
1207 $elsterFFFF = $form->{elsterFFFF_new};
1208 $form->{elsterland} = $elsterland;
1209 $form->{elsterFFFF} = $elsterFFFF;
1210 $form->{steuernummer} = '';
1212 create_steuernummer();
1214 # rebuild elster_amt
1216 foreach $amt (keys %{ $elster_init{ $form->{elsterland} } }) {
1218 if ($elster_init{ $form->{elsterland}{$amt} eq $form->{elsterFFFF} });
1221 # load the predefined hash data into the FA_* Vars
1222 my @variables = qw(FA_Name FA_Strasse FA_PLZ FA_Ort
1223 FA_Telefon FA_Fax FA_PLZ_Grosskunden FA_PLZ_Postfach
1225 FA_BLZ_1 FA_Kontonummer_1 FA_Bankbezeichnung_1
1226 FA_BLZ_2 FA_Kontonummer_2 FA_Bankbezeichnung_oertlich
1227 FA_Oeffnungszeiten FA_Email FA_Internet);
1229 for (my $i = 0; $i <= 20; $i++) {
1230 $form->{ $variables[$i] } =
1231 $elster_init->{$elsterland}->{$elsterFFFF}->[$i];
1236 $elsterland = $form->{elsterland};
1237 $elsterFFFF = $form->{elsterFFFF};
1240 my $stnr = $form->{steuernummer};
1242 my $patterncount = $form->{patterncount};
1243 my $elster_pattern = $form->{elster_pattern};
1244 my $delimiter = $form->{delimiter};
1245 my $steuernummer = $form->{steuernummer} if ($steuernummer eq '');
1247 $form->{FA_Oeffnungszeiten} =~ s/\\\\n/\n/g;
1250 $ustva->get_coa($form, \%myconfig);
1252 my $input_steuernummer = $ustva->steuernummer_input(
1253 $form->{elsterland},
1254 $form->{elsterFFFF},
1255 $form->{steuernummer}
1258 $lxdebug->message(LXDebug::DEBUG1, qq|$input_steuernummer|);
1261 my $_hidden_variables_ref;
1263 my %_hidden_local_variables = (
1264 'elsterland' => $elsterland,
1265 'elsterFFFF' => $elsterFFFF,
1266 'warnung' => $warnung,
1267 'elstersteuernummer' => $elstersteuernummer,
1268 'steuernummer' => $stnr,
1269 'lastsub' => 'config_step1',
1270 'nextsub' => 'save',
1274 foreach my $variable (keys %_hidden_local_variables) {
1275 push @{ $_hidden_variables_ref },
1276 { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
1279 my @_hidden_form_variables = qw(
1280 FA_steuerberater_name FA_steuerberater_street
1281 FA_steuerberater_city FA_steuerberater_tel
1289 foreach my $variable (@_hidden_form_variables) {
1290 push @{ $_hidden_variables_ref},
1291 { 'variable' => $variable, 'value' => $form->{$variable} };
1294 my $template_ref = {
1295 tax_office_data => $tax_office_data,
1296 input_steuernummer => $input_steuernummer,
1297 readonly => '', #q|disabled="disabled"|,
1298 callback => $callback,
1299 hidden_variables => $_hidden_variables_ref,
1302 # Ausgabe des Templates
1303 print($form->parse_html_template('ustva/config_step2', $template_ref));
1306 $lxdebug->leave_sub();
1309 sub create_steuernummer {
1310 $lxdebug->enter_sub();
1312 $auth->assert('advance_turnover_tax_return');
1314 my $part = $form->{part};
1315 my $patterncount = $form->{patterncount};
1316 my $delimiter = $form->{delimiter};
1317 my $elster_pattern = $form->{elster_pattern};
1319 # rebuild steuernummer and elstersteuernummer
1320 # es gibt eine gespeicherte steuernummer $form->{steuernummer}
1321 # und die parts und delimiter
1326 my $steuernummer_new = $part;
1327 my $elstersteuernummer_new = $form->{elster_FFFF};
1328 $elstersteuernummer_new .= '0';
1330 for ($h = 1; $h < $patterncount; $h++) {
1331 $steuernummer_new .= qq|$delimiter|;
1332 for (my $i = 1; $i <= length($elster_pattern); $i++) {
1333 $steuernummer_new .= $form->{"part_$h\_$i"};
1334 $elstersteuernummer_new .= $form->{"part_$h\_$i"};
1337 if ($form->{steuernummer} ne $steuernummer_new) {
1338 $form->{steuernummer} = $steuernummer_new;
1339 $form->{elstersteuernummer} = $elstersteuernummer_new;
1340 $form->{steuernummer_new} = $steuernummer_new;
1342 $form->{steuernummer_new} = '';
1343 $form->{elstersteuernummer_new} = '';
1345 $lxdebug->leave_sub();
1349 $lxdebug->enter_sub();
1351 $auth->assert('advance_turnover_tax_return');
1353 my $filename = "$form->{login}_$form->{filename}";
1354 $filename =~ s|.*/||;
1356 #zuerst die steuernummer aus den part, parts_X_Y und delimiter herstellen
1357 create_steuernummer();
1359 # Textboxen formatieren: Linebreaks entfernen
1361 $form->{FA_Oeffnungszeiten} =~ s/\r\n/\\n/g;
1363 #URL mit http:// davor?
1364 $form->{FA_Internet} =~ s/^http:\/\///;
1365 $form->{FA_Internet} = 'http://' . $form->{FA_Internet};
1368 elster elsterland elstersteuernummer steuernummer
1369 elsteramt elsterFFFF FA_Name FA_Strasse
1370 FA_PLZ FA_Ort FA_Telefon FA_Fax
1371 FA_PLZ_Grosskunden FA_PLZ_Postfach FA_Postfach FA_BLZ_1
1372 FA_Kontonummer_1 FA_Bankbezeichnung_1 FA_BLZ_2 FA_Kontonummer_2
1373 FA_Bankbezeichnung_oertlich FA_Oeffnungszeiten
1374 FA_Email FA_Internet FA_voranmeld method FA_steuerberater_name
1375 FA_steuerberater_street FA_steuerberater_city FA_steuerberater_tel
1376 FA_71 FA_dauerfrist);
1378 # Hier kommt dann die Plausibilitätsprüfung der ELSTERSteuernummer
1379 if ($form->{elstersteuernummer} ne '000000000') {
1381 $form->{elster} = '1';
1383 open my $ustvaconfig, ">", "$userspath/$filename" or $form->error("$filename : $!");
1385 # create the config file
1386 print {$ustvaconfig} qq|# Configuration file for USTVA\n\n|;
1388 foreach $key (sort @config) {
1389 $form->{$key} =~ s/\\/\\\\/g;
1391 $form->{$key} =~ s/\r\n/\n/g;
1393 print {$ustvaconfig} qq|$key=|;
1394 if ($form->{$key} ne 'Y') {
1395 print {$ustvaconfig} qq|$form->{$key}\n|;
1397 if ($form->{$key} eq 'Y') {
1398 print {$ustvaconfig} qq|checked \n|;
1401 print {$ustvaconfig} qq|\n\n|;
1403 $form->{saved} = $locale->text('saved');
1407 $form->{saved} = $locale->text('Choose a Tax Number');
1411 $lxdebug->leave_sub();
1416 $lxdebug->enter_sub();
1418 # allow Symbolic references just here:
1420 call_sub($form->{"nextsub"});
1422 $lxdebug->leave_sub();
1426 $lxdebug->enter_sub();
1427 call_sub($form->{"lastsub"});
1428 $lxdebug->leave_sub();