2 #=====================================================================
4 # Copyright (c) 2004 by Udo Spallek, Aachen
8 # Web: http://www.lx-office.org
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #======================================================================
24 # German Tax authority Module and later ELSTER Interface
25 #======================================================================
27 require "bin/mozilla/common.pl";
32 #use warnings; # FATAL=> 'all';
33 #use vars qw($locale $form %myconfig);
35 #use CGI::Carp "fatalsToBrowser";
43 # this is for our long dates
44 # $locale->text('January')
45 # $locale->text('February')
46 # $locale->text('March')
47 # $locale->text('April')
48 # $locale->text('May ')
49 # $locale->text('June')
50 # $locale->text('July')
51 # $locale->text('August')
52 # $locale->text('September')
53 # $locale->text('October')
54 # $locale->text('November')
55 # $locale->text('December')
57 # this is for our short month
58 # $locale->text('Jan')
59 # $locale->text('Feb')
60 # $locale->text('Mar')
61 # $locale->text('Apr')
62 # $locale->text('May')
63 # $locale->text('Jun')
64 # $locale->text('Jul')
65 # $locale->text('Aug')
66 # $locale->text('Sep')
67 # $locale->text('Oct')
68 # $locale->text('Nov')
69 # $locale->text('Dec')
71 #############################
74 $lxdebug->enter_sub();
76 $auth->assert('advance_turnover_tax_return');
78 my $myconfig = \%myconfig;
80 $form->{title} = $locale->text('UStVA');
81 $form->{kz10} = ''; #Berichtigte Anmeldung? Ja =1 Nein=0
83 my $year = substr($form->datetonum($form->current_date(\%myconfig), \%myconfig ),
90 # Einlesen der Finanzamtdaten
91 USTVA->get_config($userspath, 'finanzamt.ini');
93 # Hier Einlesen der user-config
94 # steuernummer entfernt für prerelease
96 signature name company address businessnumber
97 tel fax email co_chief co_department
98 co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
99 co_name1 co_name2 co_street co_street1 co_zip
100 co_city co_city1 co_country co_tel co_tel1
101 co_tel2 co_fax co_fax1 co_email co_email1
102 co_url co_url1 ustid duns co_bankname
103 co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
104 co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2
108 map { $form->{$_} = $myconfig->{$_} } @a;
110 my $openings = $form->{FA_Oeffnungszeiten};
111 $openings =~ s/\\\\n/<br>/g;
113 my $company_given = ($form->{company} ne '')
114 ? qq|<h3>$form->{company}</h3>\n|
115 : qq|<a href="am.pl?action=config|
116 . qq|&level=Programm--Preferences">|
117 . $locale->text('No Company Name given') . qq|!</a><br>|;
120 # Anpassungen der Variablennamen auf pre 2.1.1 Namen
121 # klären, ob $form->{company_street|_address} gesetzt sind
122 if ($form->{address} ne '') {
123 my $temp = $form->{address};
124 $temp =~ s/\n/<br \/>/;
125 ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
126 $form->{co_city} =~ s/\n//g;
131 ($form->{co_street} && ($form->{co_zip} || $form->{co_city}))
132 ? qq|$form->{co_street}<br>|
133 . qq|$form->{co_street1}<br>|
134 . qq|$form->{co_zip} $form->{co_city}|
135 : qq|<a href="am.pl?action=config|
136 . qq|&level=Programm--Preferences">|
137 . $locale->text('No Company Address given')
140 $form->{co_email} = $form->{email} unless $form->{co_email};
141 $form->{co_tel} = $form->{tel} unless $form->{co_tel};
142 $form->{co_fax} = $form->{fax} unless $form->{co_fax};
143 $form->{co_url} = $form->{urlx} unless $form->{co_url};
145 my $taxnumber_given = ($form->{steuernummer} ne '') ? $form->{steuernummer} : qq|<a href="ustva.pl?action=config_step1">Keine Steuernummer hinterlegt!</a><br>|;
147 my $ustva_vorauswahl = &ustva_vorauswahl();
149 my @all_years = $form->all_years(\%myconfig);
151 my $select_year = qq|<select name=year title="|
152 . $locale->text('Year') . qq|">|;
153 foreach my $key (@all_years) {
154 $select_year .= qq|<option |;
155 $select_year .= qq|selected| if ($key eq $form->{year});
156 $select_year .= qq| >$key</option>|;
158 $select_year .= qq|</select>|;
161 $_checked = "checked" if ($form->{kz10} eq '1');
162 my $checkbox_kz_10 = qq|<input name="FA_10" id=FA_10 class=checkbox|
163 . qq| type=checkbox value="1" $_checked title = "|
164 . $locale->text('Amended Advance Turnover Tax Return (Nr. 10)')
166 . $locale->text('Amended Advance Turnover Tax Return');
168 my $method_local = ($form->{method} eq 'accrual') ? $locale->text('accrual')
169 : ($form->{method} eq 'cash') ? $locale->text('cash')
172 my $period_local = ( $form->{FA_voranmeld} eq 'month') ? $locale->text('month')
173 : ( $form->{FA_voranmeld} eq 'quarter') ? $locale->text('quarter')
176 my $tax_office_banks_ref = [
177 { BLZ => $form->{FA_BLZ_1},
178 Kontonummer => $form->{FA_Kontonummer_1},
179 Bankbezeichnung => $form->{FA_Bankbezeichnung_1}
181 { BLZ => $form->{FA_BLZ_2},
182 Kontonummer => $form->{FA_Kontonummer_2},
183 Bankbezeichnung => $form->{FA_Bankbezeichnung_oertlich}
187 # Which COA is in use?
189 USTVA->get_coa($form, $myconfig);
192 openings => $openings,
193 company_given => $company_given,
194 address_given => $address_given,
195 taxnumber_given => $taxnumber_given,
196 taxnumber => $myconfig->{taxnumber},
197 select_year => $select_year,
198 period_local => $period_local,
199 method_local => $method_local,
200 ustva_vorauswahl => $ustva_vorauswahl,
201 checkbox_kz_10 => $checkbox_kz_10,
202 tax_office_banks => $tax_office_banks_ref,
203 select_options => &show_options,
207 print($form->parse_html_template('ustva/report', $template_ref));
211 $lxdebug->leave_sub();
217 $lxdebug->enter_sub();
219 $auth->assert('advance_turnover_tax_return');
221 # parse help documents under doc
222 my $tmp = $form->{templates};
223 $form->{templates} = 'doc';
224 $form->{help} = 'ustva';
225 $form->{type} = 'help';
226 $form->{format} = 'html';
229 #$form->{templates} = $tmp;
230 $lxdebug->leave_sub();
234 $lxdebug->enter_sub();
236 $auth->assert('advance_turnover_tax_return');
240 $lxdebug->leave_sub();
241 call_sub($form->{"nextsub"});
245 sub ustva_vorauswahl {
246 $lxdebug->enter_sub();
248 $auth->assert('advance_turnover_tax_return');
250 my $select_vorauswahl;
252 #Aktuelles Datum zerlegen:
253 my $date = $form->datetonum($form->current_date(\%myconfig), \%myconfig);
255 #$locale->date($myconfig, $form->current_date($myconfig), 0)=~ /(\d\d).(\d\d).(\d\d\d\d)/;
256 $form->{day} = substr($date, 6, 2);
257 $form->{month} = substr($date, 4, 2);
258 $form->{year} = substr($date, 0, 4);
259 $lxdebug->message(LXDebug::DEBUG1, qq|
260 Actual date from Database: $date\n
261 Actual year from Database: $form->{year}\n
262 Actual day from Database: $form->{day}\n
263 Actual month from Database: $form->{month}\n|);
268 # Testdaten erzeugen:
270 #$form->{month}= '01';
271 #$form->{year}= 2004;
272 $select_vorauswahl = qq|
273 <input type=hidden name=day value=$form->{day}>
274 <input type=hidden name=month value=$form->{month}>
275 <input type=hidden name=yymmdd value=$yymmdd>
276 <input type=hidden name=sel value=$sel>
279 if ($form->{FA_voranmeld} eq 'month') {
281 # Vorauswahl bei monatlichem Voranmeldungszeitraum
283 my %liste = ('01' => $locale->text('January'),
284 '02' => $locale->text('February'),
285 '03' => $locale->text('March'),
286 '04' => $locale->text('April'),
287 '05' => $locale->text('May'),
288 '06' => $locale->text('June'),
289 '07' => $locale->text('July'),
290 '08' => $locale->text('August'),
291 '09' => $locale->text('September'),
292 '10' => $locale->text('October'),
293 '11' => $locale->text('November'),
294 '12' => $locale->text('December'),
295 '13' => $locale->text('Yearly'),
298 my $yy = $form->{year} * 10000;
299 $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
303 # Offset für Dauerfristverlängerung
304 $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
307 $yymmdd <= ($yy + 110 + $dfv) && do {
308 $form->{year} = $form->{year} - 1;
312 $yymmdd <= ($yy + 210 + $dfv) && do {
316 $yymmdd <= ($yy + 310 + $dfv) && do {
320 $yymmdd <= ($yy + 410 + $dfv) && do {
324 $yymmdd <= ($yy + 510 + $dfv) && do {
328 $yymmdd <= ($yy + 610 + $dfv) && do {
332 $yymmdd <= ($yy + 710 + $dfv) && do {
336 $yymmdd <= ($yy + 810 + $dfv) && do {
340 $yymmdd <= ($yy + 910 + $dfv) && do {
344 $yymmdd <= ($yy + 1010 + $dfv) && do {
348 $yymmdd <= ($yy + 1110 + $dfv) && do {
352 $yymmdd <= ($yy + 1210) && do {
356 $yymmdd <= ($yy + 1231) && do {
362 $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
363 . $locale->text('Select a period') . qq|" >|;
366 foreach $key (sort keys %liste) {
368 $selected = 'selected' if ($sel eq $key);
369 $select_vorauswahl .= qq|
370 <option value="$key" $selected> $liste{$key}</option>
373 $select_vorauswahl .= qq|</select>|;
375 } elsif ($form->{FA_voranmeld} eq 'quarter') {
377 # Vorauswahl bei quartalsweisem Voranmeldungszeitraum
378 my %liste = ('41' => $locale->text('1. Quarter'),
379 '42' => $locale->text('2. Quarter'),
380 '43' => $locale->text('3. Quarter'),
381 '44' => $locale->text('4. Quarter'),
382 '13' => $locale->text('Yearly'),);
384 my $yy = $form->{year} * 10000;
385 $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
387 my $dfv = ''; # Offset für Dauerfristverlängerung
388 $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
391 $yymmdd <= ($yy + 110 + $dfv) && do {
392 $form->{year} = $form->{year} - 1;
396 $yymmdd <= ($yy + 410 + $dfv) && do {
400 $yymmdd <= ($yy + 710 + $dfv) && do {
404 $yymmdd <= ($yy + 1010 + $dfv) && do {
408 $yymmdd <= ($yy + 1231) && do {
413 $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
414 . $locale->text('Select a period') . qq|" >|;
416 foreach $key (sort keys %liste) {
418 $selected = 'selected' if ($sel eq $key);
419 $select_vorauswahl .= qq|
420 <option value="$key" $selected>$liste{$key}</option>
423 $select_vorauswahl .= qq|\n</select>
428 # keine Vorauswahl bei Voranmeldungszeitraum
429 $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
430 . $locale->text('Select a period') . qq|" >|;
432 my %listea = ('41' => '1. Quarter',
433 '42' => '2. Quarter',
434 '43' => '3. Quarter',
435 '44' => '4. Quarter',);
437 my %listeb = ('01' => 'January',
451 foreach $key (sort keys %listea) {
452 $select_vorauswahl .= qq|
453 <option value="$key">|
454 . $locale->text("$listea{$key}")
458 foreach $key (sort keys %listeb) {
459 $select_vorauswahl .= qq|
460 <option value="$key">|
461 . $locale->text("$listeb{$key}")
464 $select_vorauswahl .= qq|</select>|;
466 $lxdebug->leave_sub();
468 return $select_vorauswahl;
472 # $lxdebug->enter_sub();
474 # $lxdebug->leave_sub();
478 $lxdebug->enter_sub();
480 $lxdebug->leave_sub();
484 $lxdebug->enter_sub();
486 $auth->assert('advance_turnover_tax_return');
488 # $form->{PD}{$form->{type}} = "selected";
489 # $form->{DF}{$form->{format}} = "selected";
490 # $form->{OP}{$form->{media}} = "selected";
491 # $form->{SM}{$form->{sendmode}} = "selected";
492 my $type = qq| <input type=hidden name="type" value="ustva">|;
493 my $media = qq| <input type=hidden name="media" value="screen">|;
495 qq| <option value=html selected>|
496 . $locale->text('Preview')
498 if ($latex_templates) {
500 qq| <option value=pdf>|
501 . $locale->text('UStVA (PDF-Dokument)')
505 #my $disabled= qq|disabled="disabled"|;
506 #$disabled='' if ($form->{elster} eq '1' );
507 if ($form->{elster} eq '1') {
509 qq|<option value=elsterwinston>|
510 . $locale->text('ELSTER Export (Winston)')
512 . qq|<option value=elstertaxbird>|
513 . $locale->text('ELSTER Export (Taxbird)')
517 #$format .= qq|<option value=elster>|.$locale->text('ELSTER Export nach Winston').qq|</option>|;
518 my $show_options = qq|
521 <select name=format title = "|
522 . $locale->text('Choose Outputformat') . qq|">$format</select>
524 $lxdebug->leave_sub();
526 return $show_options;
530 $lxdebug->enter_sub();
532 $auth->assert('advance_turnover_tax_return');
534 # Aufruf von get_config zum Einlesen der Finanzamtdaten aus finanzamt.ini
536 USTVA->get_config($userspath, 'finanzamt.ini');
538 # init some form vars
539 my @anmeldungszeitraum =
540 qw('0401' '0402' '0403'
544 '0441' '0442' '0443' '0444');
546 foreach my $item (@anmeldungszeitraum) {
550 #forgotten the year --> thisyear
551 if ($form->{year} !~ m/^\d\d\d\d$/) {
552 $form->{year} = substr(
554 $form->current_date(\%myconfig), \%myconfig
557 $lxdebug->message(LXDebug::DEBUG1,
558 qq|Actual year from Database: $form->{year}\n|);
562 # using dates in ISO-8601 format: yyyymmmdd for Postgres...
566 if ($form->{period} eq "13") {
567 $form->{fromdate} = "$form->{year}0101";
568 $form->{todate} = "$form->{year}1231";
572 if ($form->{period} eq "41") {
573 $form->{fromdate} = "$form->{year}0101";
574 $form->{todate} = "$form->{year}0331";
575 $form->{'0441'} = "X";
577 if ($form->{period} eq "42") {
578 $form->{fromdate} = "$form->{year}0401";
579 $form->{todate} = "$form->{year}0630";
580 $form->{'0442'} = "X";
582 if ($form->{period} eq "43") {
583 $form->{fromdate} = "$form->{year}0701";
584 $form->{todate} = "$form->{year}0930";
585 $form->{'0443'} = "X";
587 if ($form->{period} eq "44") {
588 $form->{fromdate} = "$form->{year}1001";
589 $form->{todate} = "$form->{year}1231";
590 $form->{'0444'} = "X";
595 $form->{period} eq "01" && do {
596 $form->{fromdate} = "$form->{year}0101";
597 $form->{todate} = "$form->{year}0131";
598 $form->{'0401'} = "X";
601 $form->{period} eq "02" && do {
602 $form->{fromdate} = "$form->{year}0201";
604 #this works from 1901 to 2099, 1900 and 2100 fail.
605 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
606 $form->{todate} = "$form->{year}02$leap";
607 $form->{"0402"} = "X";
610 $form->{period} eq "03" && do {
611 $form->{fromdate} = "$form->{year}0301";
612 $form->{todate} = "$form->{year}0331";
613 $form->{"0403"} = "X";
616 $form->{period} eq "04" && do {
617 $form->{fromdate} = "$form->{year}0401";
618 $form->{todate} = "$form->{year}0430";
619 $form->{"0404"} = "X";
622 $form->{period} eq "05" && do {
623 $form->{fromdate} = "$form->{year}0501";
624 $form->{todate} = "$form->{year}0531";
625 $form->{"0405"} = "X";
628 $form->{period} eq "06" && do {
629 $form->{fromdate} = "$form->{year}0601";
630 $form->{todate} = "$form->{year}0630";
631 $form->{"0406"} = "X";
634 $form->{period} eq "07" && do {
635 $form->{fromdate} = "$form->{year}0701";
636 $form->{todate} = "$form->{year}0731";
637 $form->{"0407"} = "X";
640 $form->{period} eq "08" && do {
641 $form->{fromdate} = "$form->{year}0801";
642 $form->{todate} = "$form->{year}0831";
643 $form->{"0408"} = "X";
646 $form->{period} eq "09" && do {
647 $form->{fromdate} = "$form->{year}0901";
648 $form->{todate} = "$form->{year}0930";
649 $form->{"0409"} = "X";
652 $form->{period} eq "10" && do {
653 $form->{fromdate} = "$form->{year}1001";
654 $form->{todate} = "$form->{year}1031";
655 $form->{"0410"} = "X";
658 $form->{period} eq "11" && do {
659 $form->{fromdate} = "$form->{year}1101";
660 $form->{todate} = "$form->{year}1130";
661 $form->{"0411"} = "X";
664 $form->{period} eq "12" && do {
665 $form->{fromdate} = "$form->{year}1201";
666 $form->{todate} = "$form->{year}1231";
667 $form->{"0412"} = "X";
672 # Kontrollvariable für die Templates
673 $form->{'year2007'} = ($form->{year} >= 2007 ) ? "1":"0";
677 USTVA->ustva(\%myconfig, \%$form);
679 # reformat Dates to dateformat
680 $form->{fromdate} = $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);
682 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
683 $form->{todate} = $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
685 $form->{longperiod} =
686 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1, 0, 0);
688 # if there are any dates construct a where
689 if ($form->{fromdate} || $form->{todate}) {
691 $form->{todate} = $form->current_date($myconfig) unless ($form->{todate});
693 my $longtodate = $locale->date($myconfig, $form->{todate}, 1, 0, 0);
694 my $shorttodate = $locale->date($myconfig, $form->{todate}, 0, 0, 0);
696 my $longfromdate = $locale->date($myconfig, $form->{fromdate}, 1, 0, 0);
697 my $shortfromdate = $locale->date($myconfig, $form->{fromdate}, 0, 0, 0);
699 $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
700 $form->{longperiod} =
701 $locale->text('for Period')
702 . qq|<br>\n$longfromdate |
703 . $locale->text('to (date)')
707 if ($form->{comparefromdate} || $form->{comparetodate}) {
708 my $longcomparefromdate =
709 $locale->date(\%myconfig, $form->{comparefromdate}, 1, 0, 0);
710 my $shortcomparefromdate =
711 $locale->date(\%myconfig, $form->{comparefromdate}, 0, 0, 0);
713 my $longcomparetodate =
714 $locale->date(\%myconfig, $form->{comparetodate}, 1, 0, 0);
715 my $shortcomparetodate =
716 $locale->date(\%myconfig, $form->{comparetodate}, 0, 0, 0);
718 $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
719 $form->{longperiod} .=
720 "<br>\n$longcomparefromdate "
721 . $locale->text('to (date)')
722 . qq| $longcomparetodate|;
725 $form->{Datum_heute} =
726 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0, 0, 0);
728 # setup variables for the form
729 my @a = qw(company businessnumber tel fax email
730 co_chief co_department co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
731 co_name1 co_name2 co_street co_street1 co_zip co_city co_city1 co_country co_tel co_tel1 co_tel2
732 co_fax co_fax1 co_email co_email1 co_url co_url1 ustid duns
733 co_bankname co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
734 co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2 co_accountnr3);
736 map { $form->{$_} = $myconfig{$_} } @a;
738 if ($form->{address} ne '') {
739 my $temp = $form->{address};
740 $temp =~ s/\\n/<br \/>/;
741 ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
742 $form->{co_city} =~ s/\\n//g;
745 ################################
747 # Nation specific customisations
749 ################################
753 if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') {
756 # Outputformat specific customisation's
759 my @category_cent = USTVA->report_variables({
760 myconfig => \%myconfig,
763 attribute => 'position',
767 push @category_cent, qw(83 Z43 Z45 Z53 Z62 Z65 Z67);
769 my @category_euro = USTVA->report_variables({
770 myconfig => \%myconfig,
773 attribute => 'position',
778 $form->{amount} = [];
780 if ( $form->{format} eq 'pdf' or $form->{format} eq 'postscript') {
782 $form->{IN} = "$form->{type}-$form->{year}.tex";
783 $form->{padding} = "~~";
784 $form->{bold} = "\textbf{";
785 $form->{endbold} = "}";
786 $form->{br} = '\\\\';
788 # Zahlenformatierung für Latex USTVA Formulare
790 foreach my $number (@category_euro) {
791 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '');
794 my ${decimal_comma} = ( $myconfig{numberformat} eq '1.000,00'
795 or $myconfig{numberformat} eq '1000,00' ) ? ',':'.';
797 foreach my $number (@category_cent) {
798 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '');
799 $form->{$number} =~ s/${decimal_comma}/~~/g;
802 } elsif ( $form->{format} eq 'html') { # Formatierungen für HTML Ausgabe
804 $form->{IN} = $form->{type} . '.html';
805 $form->{padding} = " ";
806 $form->{bold} = "<b>";
807 $form->{endbold} = "</b>";
808 $form->{br} = "<br>";
809 $form->{address} =~ s/\\n/\n/g;
811 foreach $number (@category_cent) {
812 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '0');
815 foreach $number (@category_euro) {
816 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '0');
819 } elsif ( $form->{format} eq 'elsterwinston' ) {
821 $form->{IN} = 'winston.xml';
824 # Build Winston filename
827 my $file = 'U'; # 1. char 'U' = USTVA
828 $file .= $form->{period};
829 #4. and 5. char = year modulo 100
830 $file .= sprintf("%02d", $form->{year} % 100);
831 #6. to 18. char = Elstersteuernummer
832 #Beispiel: Steuernummer in Bayern
833 #111/222/33334 ergibt für UStVA Jan 2004: U01049111022233334
834 $file .= $form->{elsterFFFF};
835 $file .= $form->{elstersteuernummer};
839 $form->{tmpfile} = "$userspath/$file";
841 $form->{attachment_filename} = $file;
843 # Zahlenformatierung für Winston
845 my $temp_numberformat = $myconfig{numberformat};
847 # Numberformat must be '1000.00' for Winston
849 $myconfig{numberformat} = '1000.00';
851 foreach my $number (@category_cent) {
852 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
855 foreach my $number (@category_euro) {
856 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
858 # Re-set Numberformat
859 $myconfig{numberformat} = $temp_numberformat;
861 # push Kennziffern to <%foreach Array fo easyer
862 # output in xml format. Thx to Moritz.
863 my %winston_id_for = (
867 foreach my $kennziffer (@category_cent, @category_euro) {
869 next if ( $kennziffer =~ m/Z\d\d/);
870 next if ( $form->{$kennziffer} == 0 );
872 if (defined $winston_id_for{$kennziffer} ) {
873 push(@{ $form->{id}}, $winston_id_for{$kennziffer});
875 push(@{ $form->{id}}, "Kz$kennziffer");
877 push(@{ $form->{amount}}, $form->{$kennziffer});
880 } elsif ( $form->{format} eq 'elstertaxbird' ) {
882 # Define serveral filenames
883 $form->{IN} = 'taxbird.txb';
885 $form->{attachment_filename} = "USTVA-" . $form->{period}
886 . sprintf("%02d", $form->{year} % 100) . ".txb";
888 $form->{attachment_filename} =~ s|.*/||;
889 $form->{tmpfile} = "$userspath/" . $form->{attachment_filename};
891 # TODO: set Output to UTF-8 or system Preference
892 #$form->{"iconv"} = Text::Iconv->new($myconfig{dbcharset}, "UTF-8");
893 #my $iconv = $self->{"iconv"};
894 #$iconv->convert($variable);
895 if ($form->{period} =~ /^[4]\d$/ ){
896 my %periods = ( # Lx => taxbird
903 foreach my $quarter ( keys %periods ) {
904 $form->{taxbird_period} = $periods{$quarter} if ( $form->{period} eq $quarter);
906 } elsif ($form->{period} =~ /^\d+$/ ) {
907 $form->{period} =~ s/^0//g;
908 my $period = $form->{period};
911 $form->{period} = $period;
914 USTVA::error( $locale->text('Wrong Period' ));
918 my %lands = ( # Lx => taxbird # TODO: besser als array...
919 'Baden Württemberg' => '0',
922 'Brandenburg' => '3',
926 'Mecklenburg Vorpommern' => '7',
927 'Niedersachsen' => '8',
928 'Nordrhein Westfalen' => '9',
929 'Rheinland Pfalz' => '10',
932 'Sachsen Anhalt' => '13',
933 'Schleswig Holstein' => '14',
936 foreach my $land ( keys %lands ){
937 $form->{taxbird_land_nr} = $lands{$land} if ($form->{elsterland} eq $land );
940 $form->{co_zip} = $form->{co_city};
941 $form->{co_zip} =~ s/\D//g;
942 $form->{co_city} =~ s/\d//g;
943 $form->{co_city} =~ s/^\s//g;
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 # edit all taxauthority prefs
1088 USTVA->get_config($userspath, 'finanzamt.ini');
1090 my $land = $form->{elsterland};
1091 my $amt = $form->{elsterFFFF};
1094 $form->{title} = $locale->text('Tax Office Preferences');
1097 my $select_tax_office = USTVA->fa_auswahl($land, $amt, &elster_hash());
1098 my $checked_accrual = q|checked="checked"| if ($form->{method} eq 'accrual');
1099 my $checked_cash = q|checked="checked"| if ($form->{method} eq 'cash');
1100 my $checked_monthly = "checked" if ($form->{FA_voranmeld} eq 'month');
1101 my $checked_quarterly = "checked" if ($form->{FA_voranmeld} eq 'quarter');
1102 my $checked_dauerfristverlaengerung = "checked" if ($form->{FA_dauerfrist} eq '1');
1103 my $checked_kz_71 = "checked" if ($form->{FA_71} eq 'X');
1105 my $_hidden_variables_ref;
1107 my %_hidden_local_variables = (
1108 'saved' => $locale->text('Check Details'),
1109 'nextsub' => 'config_step2',
1113 foreach my $variable (keys %_hidden_local_variables) {
1114 push @{ $_hidden_variables_ref },
1115 { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
1118 my @_hidden_form_variables = qw(
1119 FA_Name FA_Strasse FA_PLZ
1120 FA_Ort FA_Telefon FA_Fax
1121 FA_PLZ_Grosskunden FA_PLZ_Postfach FA_Postfach
1122 FA_BLZ_1 FA_Kontonummer_1 FA_Bankbezeichnung_1
1123 FA_BLZ_2 FA_Kontonummer_2 FA_Bankbezeichnung_oertlich
1124 FA_Oeffnungszeiten FA_Email FA_Internet
1125 steuernummer elsterland elstersteuernummer
1129 foreach my $variable (@_hidden_form_variables) {
1130 push @{ $_hidden_variables_ref},
1131 { 'variable' => $variable, 'value' => $form->{$variable} };
1134 # Which COA is in use?
1136 USTVA->get_coa($form, \%myconfig);
1139 my $steuernummer_new = '';
1141 # Variablen für das Template zur Verfügung stellen
1142 my $template_ref = {
1143 select_tax_office => $select_tax_office,
1144 checked_accrual => $checked_accrual,
1145 checked_cash => $checked_cash,
1146 checked_monthly => $checked_monthly,
1147 checked_quarterly => $checked_quarterly,
1148 checked_dauerfristverlaengerung => $checked_dauerfristverlaengerung,
1149 hidden_variables => $_hidden_variables_ref,
1153 # Ausgabe des Templates
1154 print($form->parse_html_template('ustva/config_step1', $template_ref));
1156 $lxdebug->leave_sub();
1160 $lxdebug->enter_sub();
1162 $auth->assert('advance_turnover_tax_return');
1170 my $elsterland = '';
1171 my $elster_amt = '';
1172 my $elsterFFFF = '';
1173 my $elstersteuernummer = '';
1174 USTVA->get_config($userspath, 'finanzamt.ini')
1175 if ($form->{saved} eq $locale->text('saved'));
1177 # Auf Übergabefehler checken
1178 USTVA::info( $locale->text('Missing Tax Authoritys Preferences') . "\n"
1179 . $locale->text('USTVA-Hint: Tax Authoritys'))
1180 if ( $form->{elsterFFFF_new} eq 'Auswahl'
1181 || $form->{elsterland_new} eq 'Auswahl');
1182 USTVA::info( $locale->text('Missing Method!') . "\n"
1183 . $locale->text('USTVA-Hint: Method'))
1184 if ($form->{method} eq '');
1186 # Klären, ob Variablen bereits befüllt sind UND ob veräderungen auf
1187 # der vorherigen Maske stattfanden: $change = 1(in der edit sub,
1188 # mittels get_config)
1190 my $change = $form->{elsterland} eq $form->{elsterland_new}
1191 && $form->{elsterFFFF} eq $form->{elsterFFFF_new} ? '0' : '1';
1192 $change = '0' if ($form->{saved} eq $locale->text('saved'));
1193 my $elster_init = &elster_hash();
1195 my %elster_init = %$elster_init;
1197 if ($change eq '1') {
1200 $elsterland = $form->{elsterland_new};
1201 $elsterFFFF = $form->{elsterFFFF_new};
1202 $form->{elsterland} = $elsterland;
1203 $form->{elsterFFFF} = $elsterFFFF;
1204 $form->{steuernummer} = '';
1206 create_steuernummer();
1208 # rebuild elster_amt
1210 foreach $amt (keys %{ $elster_init{ $form->{elsterland} } }) {
1212 if ($elster_init{ $form->{elsterland}{$amt} eq $form->{elsterFFFF} });
1215 # load the predefined hash data into the FA_* Vars
1216 my @variables = qw(FA_Name FA_Strasse FA_PLZ FA_Ort
1217 FA_Telefon FA_Fax FA_PLZ_Grosskunden FA_PLZ_Postfach
1219 FA_BLZ_1 FA_Kontonummer_1 FA_Bankbezeichnung_1
1220 FA_BLZ_2 FA_Kontonummer_2 FA_Bankbezeichnung_oertlich
1221 FA_Oeffnungszeiten FA_Email FA_Internet);
1223 for (my $i = 0; $i <= 20; $i++) {
1224 $form->{ $variables[$i] } =
1225 $elster_init->{$elsterland}->{$elsterFFFF}->[$i];
1230 $elsterland = $form->{elsterland};
1231 $elsterFFFF = $form->{elsterFFFF};
1234 my $stnr = $form->{steuernummer};
1236 my $patterncount = $form->{patterncount};
1237 my $elster_pattern = $form->{elster_pattern};
1238 my $delimiter = $form->{delimiter};
1239 my $steuernummer = $form->{steuernummer} if ($steuernummer eq '');
1241 $form->{FA_Oeffnungszeiten} =~ s/\\\\n/\n/g;
1244 USTVA->get_coa($form, \%myconfig);
1246 my $input_steuernummer = USTVA->steuernummer_input(
1247 $form->{elsterland},
1248 $form->{elsterFFFF},
1249 $form->{steuernummer}
1252 $lxdebug->message(LXDebug::DEBUG1, qq|$input_steuernummer|);
1255 my $_hidden_variables_ref;
1257 my %_hidden_local_variables = (
1258 'elsterland' => $elsterland,
1259 'elsterFFFF' => $elsterFFFF,
1260 'warnung' => $warnung,
1261 'elstersteuernummer' => $elstersteuernummer,
1262 'steuernummer' => $stnr,
1263 'lastsub' => 'config_step1',
1264 'nextsub' => 'save',
1268 foreach my $variable (keys %_hidden_local_variables) {
1269 push @{ $_hidden_variables_ref },
1270 { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
1273 my @_hidden_form_variables = qw(
1274 FA_steuerberater_name FA_steuerberater_street
1275 FA_steuerberater_city FA_steuerberater_tel
1283 foreach my $variable (@_hidden_form_variables) {
1284 push @{ $_hidden_variables_ref},
1285 { 'variable' => $variable, 'value' => $form->{$variable} };
1288 my $template_ref = {
1289 tax_office_data => $tax_office_data,
1290 input_steuernummer => $input_steuernummer,
1291 readonly => '', #q|disabled="disabled"|,
1292 callback => $callback,
1293 hidden_variables => $_hidden_variables_ref,
1296 # Ausgabe des Templates
1297 print($form->parse_html_template('ustva/config_step2', $template_ref));
1300 $lxdebug->leave_sub();
1303 sub create_steuernummer {
1304 $lxdebug->enter_sub();
1306 $auth->assert('advance_turnover_tax_return');
1308 my $part = $form->{part};
1309 my $patterncount = $form->{patterncount};
1310 my $delimiter = $form->{delimiter};
1311 my $elster_pattern = $form->{elster_pattern};
1313 # rebuild steuernummer and elstersteuernummer
1314 # es gibt eine gespeicherte steuernummer $form->{steuernummer}
1315 # und die parts und delimiter
1320 my $steuernummer_new = $part;
1321 my $elstersteuernummer_new = $form->{elster_FFFF};
1322 $elstersteuernummer_new .= '0';
1324 for ($h = 1; $h < $patterncount; $h++) {
1325 $steuernummer_new .= qq|$delimiter|;
1326 for (my $i = 1; $i <= length($elster_pattern); $i++) {
1327 $steuernummer_new .= $form->{"part_$h\_$i"};
1328 $elstersteuernummer_new .= $form->{"part_$h\_$i"};
1331 if ($form->{steuernummer} ne $steuernummer_new) {
1332 $form->{steuernummer} = $steuernummer_new;
1333 $form->{elstersteuernummer} = $elstersteuernummer_new;
1334 $form->{steuernummer_new} = $steuernummer_new;
1336 $form->{steuernummer_new} = '';
1337 $form->{elstersteuernummer_new} = '';
1339 $lxdebug->leave_sub();
1343 $lxdebug->enter_sub();
1345 $auth->assert('advance_turnover_tax_return');
1347 my $filename = "$form->{login}_$form->{filename}";
1348 $filename =~ s|.*/||;
1350 #zuerst die steuernummer aus den part, parts_X_Y und delimiter herstellen
1351 create_steuernummer();
1353 # Textboxen formatieren: Linebreaks entfernen
1355 $form->{FA_Oeffnungszeiten} =~ s/\r\n/\\n/g;
1357 #URL mit http:// davor?
1358 $form->{FA_Internet} =~ s/^http:\/\///;
1359 $form->{FA_Internet} = 'http://' . $form->{FA_Internet};
1362 elster elsterland elstersteuernummer steuernummer
1363 elsteramt elsterFFFF FA_Name FA_Strasse
1364 FA_PLZ FA_Ort FA_Telefon FA_Fax
1365 FA_PLZ_Grosskunden FA_PLZ_Postfach FA_Postfach FA_BLZ_1
1366 FA_Kontonummer_1 FA_Bankbezeichnung_1 FA_BLZ_2 FA_Kontonummer_2
1367 FA_Bankbezeichnung_oertlich FA_Oeffnungszeiten
1368 FA_Email FA_Internet FA_voranmeld method FA_steuerberater_name
1369 FA_steuerberater_street FA_steuerberater_city FA_steuerberater_tel
1370 FA_71 FA_dauerfrist);
1372 # Hier kommt dann die Plausibilitätsprüfung der ELSTERSteuernummer
1373 if ($form->{elstersteuernummer} ne '000000000') {
1375 $form->{elster} = '1';
1377 open my $ustvaconfig, ">", "$userspath/$filename" or $form->error("$filename : $!");
1379 # create the config file
1380 print {$ustvaconfig} qq|# Configuration file for USTVA\n\n|;
1382 foreach $key (sort @config) {
1383 $form->{$key} =~ s/\\/\\\\/g;
1385 $form->{$key} =~ s/\r\n/\n/g;
1387 print {$ustvaconfig} qq|$key=|;
1388 if ($form->{$key} ne 'Y') {
1389 print {$ustvaconfig} qq|$form->{$key}\n|;
1391 if ($form->{$key} eq 'Y') {
1392 print {$ustvaconfig} qq|checked \n|;
1395 print {$ustvaconfig} qq|\n\n|;
1397 $form->{saved} = $locale->text('saved');
1401 $form->{saved} = $locale->text('Choose a Tax Number');
1405 $lxdebug->leave_sub();
1410 $lxdebug->enter_sub();
1412 # allow Symbolic references just here:
1414 call_sub($form->{"nextsub"});
1416 $lxdebug->leave_sub();
1420 $lxdebug->enter_sub();
1421 call_sub($form->{"lastsub"});
1422 $lxdebug->leave_sub();
1426 $lxdebug->enter_sub();
1428 $auth->assert('advance_turnover_tax_return');
1430 my $finanzamt = USTVA->query_finanzamt(\%myconfig, \%$form);
1431 $lxdebug->leave_sub();