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 #======================================================================
29 require "bin/mozilla/common.pl";
34 #use warnings; # FATAL=> 'all';
35 #use vars qw($locale $form %myconfig);
37 #use CGI::Carp "fatalsToBrowser";
39 use List::Util qw(first);
48 # this is for our long dates
49 # $locale->text('January')
50 # $locale->text('February')
51 # $locale->text('March')
52 # $locale->text('April')
53 # $locale->text('May ')
54 # $locale->text('June')
55 # $locale->text('July')
56 # $locale->text('August')
57 # $locale->text('September')
58 # $locale->text('October')
59 # $locale->text('November')
60 # $locale->text('December')
62 # this is for our short month
63 # $locale->text('Jan')
64 # $locale->text('Feb')
65 # $locale->text('Mar')
66 # $locale->text('Apr')
67 # $locale->text('May')
68 # $locale->text('Jun')
69 # $locale->text('Jul')
70 # $locale->text('Aug')
71 # $locale->text('Sep')
72 # $locale->text('Oct')
73 # $locale->text('Nov')
74 # $locale->text('Dec')
76 #############################
79 $::lxdebug->enter_sub();
82 my $locale = $::locale;
83 my %myconfig = %::myconfig;
85 $::auth->assert('advance_turnover_tax_return');
87 $form->{title} = $locale->text('UStVA');
88 $form->{kz10} = ''; #Berichtigte Anmeldung? Ja =1 Nein=0
90 my $year = substr($form->datetonum($form->current_date(\%myconfig), \%myconfig ),
97 # Einlesen der Finanzamtdaten
98 my $ustva = USTVA->new();
99 $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
101 # Hier Einlesen der user-config
102 # steuernummer entfernt für prerelease
104 signature name company address businessnumber
105 tel fax email co_chief co_department
106 co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
107 co_name1 co_name2 co_street co_street1 co_zip
108 co_city co_city1 co_country co_tel co_tel1
109 co_tel2 co_fax co_fax1 co_email co_email1
110 co_url co_url1 ustid duns co_bankname
111 co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
112 co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2
116 map { $form->{$_} = $myconfig{$_} } @a;
118 my $openings = $form->{FA_Oeffnungszeiten};
119 $openings =~ s/\\\\n/<br>/g;
121 my $company_given = ($form->{company} ne '')
122 ? qq|<h3>$form->{company}</h3>\n|
123 : qq|<a href="am.pl?action=config">|
124 . $locale->text('No Company Name given') . qq|!</a><br>|;
127 # Anpassungen der Variablennamen auf pre 2.1.1 Namen
128 # klären, ob $form->{company_street|_address} gesetzt sind
129 if ($form->{address} ne '') {
130 my $temp = $form->{address};
131 $temp =~ s/\n/<br \/>/;
132 ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
133 $form->{co_city} =~ s/\n//g;
138 ($form->{co_street} && ($form->{co_zip} || $form->{co_city}))
139 ? qq|$form->{co_street}<br>|
140 . qq|$form->{co_street1}<br>|
141 . qq|$form->{co_zip} $form->{co_city}|
142 : qq|<a href="am.pl?action=config|
143 . qq|&level=Programm--Preferences">|
144 . $locale->text('No Company Address given')
147 $form->{co_email} = $form->{email} unless $form->{co_email};
148 $form->{co_tel} = $form->{tel} unless $form->{co_tel};
149 $form->{co_fax} = $form->{fax} unless $form->{co_fax};
150 $form->{co_url} = $form->{urlx} unless $form->{co_url};
152 my $taxnumber_given = ($form->{steuernummer} ne '') ? $form->{steuernummer} : qq|<a href="ustva.pl?action=config_step1">Keine Steuernummer hinterlegt!</a><br>|;
154 my $ustva_vorauswahl = &ustva_vorauswahl();
156 my @all_years = $form->all_years(\%myconfig);
158 my $select_year = qq|<select name=year title="|
159 . $locale->text('Year') . qq|">|;
160 foreach my $key (@all_years) {
161 $select_year .= qq|<option |;
162 $select_year .= qq|selected| if ($key eq $form->{year});
163 $select_year .= qq| >$key</option>|;
165 $select_year .= qq|</select>|;
168 $_checked = "checked" if ($form->{kz10} eq '1');
169 my $checkbox_kz_10 = qq|<input name="FA_10" id=FA_10 class=checkbox|
170 . qq| type=checkbox value="1" $_checked title = "|
171 . $locale->text('Amended Advance Turnover Tax Return (Nr. 10)')
173 . $locale->text('Amended Advance Turnover Tax Return');
175 my $method_local = ($form->{method} eq 'accrual') ? $locale->text('accrual')
176 : ($form->{method} eq 'cash') ? $locale->text('cash')
179 my $period_local = ( $form->{FA_voranmeld} eq 'month') ? $locale->text('month')
180 : ( $form->{FA_voranmeld} eq 'quarter') ? $locale->text('quarter')
183 my $tax_office_banks_ref = [
184 { BLZ => $form->{FA_BLZ_1},
185 Kontonummer => $form->{FA_Kontonummer_1},
186 Bankbezeichnung => $form->{FA_Bankbezeichnung_1}
188 { BLZ => $form->{FA_BLZ_2},
189 Kontonummer => $form->{FA_Kontonummer_2},
190 Bankbezeichnung => $form->{FA_Bankbezeichnung_oertlich}
194 # Which COA is in use?
196 $ustva->get_coa($form, \%myconfig);
199 openings => $openings,
200 company_given => $company_given,
201 address_given => $address_given,
202 taxnumber_given => $taxnumber_given,
203 taxnumber => $myconfig{taxnumber},
204 select_year => $select_year,
205 period_local => $period_local,
206 method_local => $method_local,
207 ustva_vorauswahl => $ustva_vorauswahl,
208 checkbox_kz_10 => $checkbox_kz_10,
209 tax_office_banks => $tax_office_banks_ref,
210 select_options => &show_options,
214 print($form->parse_html_template('ustva/report', $template_ref));
218 $::lxdebug->leave_sub();
224 $::lxdebug->enter_sub();
226 $::auth->assert('advance_turnover_tax_return');
228 # parse help documents under doc
229 $::form->{templates} = 'doc';
230 $::form->{help} = 'ustva';
231 $::form->{type} = 'help';
232 $::form->{format} = 'html';
235 $::lxdebug->leave_sub();
239 $::lxdebug->enter_sub();
241 $::auth->assert('advance_turnover_tax_return');
244 $::lxdebug->leave_sub();
245 call_sub($::form->{"nextsub"});
248 sub ustva_vorauswahl {
249 $::lxdebug->enter_sub();
252 my $locale = $::locale;
253 my %myconfig = %::myconfig;
255 $::auth->assert('advance_turnover_tax_return');
257 my $select_vorauswahl;
259 #Aktuelles Datum zerlegen:
260 my $date = $form->datetonum($form->current_date(\%myconfig), \%myconfig);
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|);
275 # Testdaten erzeugen:
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>
286 if ($form->{FA_voranmeld} eq 'month') {
288 # Vorauswahl bei monatlichem Voranmeldungszeitraum
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'),
305 my $yy = $form->{year} * 10000;
306 $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
310 # Offset für Dauerfristverlängerung
311 $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
314 $yymmdd <= ($yy + 110 + $dfv) && do {
315 $form->{year} = $form->{year} - 1;
319 $yymmdd <= ($yy + 210 + $dfv) && do {
323 $yymmdd <= ($yy + 310 + $dfv) && do {
327 $yymmdd <= ($yy + 410 + $dfv) && do {
331 $yymmdd <= ($yy + 510 + $dfv) && do {
335 $yymmdd <= ($yy + 610 + $dfv) && do {
339 $yymmdd <= ($yy + 710 + $dfv) && do {
343 $yymmdd <= ($yy + 810 + $dfv) && do {
347 $yymmdd <= ($yy + 910 + $dfv) && do {
351 $yymmdd <= ($yy + 1010 + $dfv) && do {
355 $yymmdd <= ($yy + 1110 + $dfv) && do {
359 $yymmdd <= ($yy + 1210) && do {
363 $yymmdd <= ($yy + 1231) && do {
369 $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
370 . $locale->text('Select a period') . qq|" >|;
373 foreach $key (sort keys %liste) {
375 $selected = 'selected' if ($sel eq $key);
376 $select_vorauswahl .= qq|
377 <option value="$key" $selected> $liste{$key}</option>
380 $select_vorauswahl .= qq|</select>|;
382 } elsif ($form->{FA_voranmeld} eq 'quarter') {
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'),);
391 my $yy = $form->{year} * 10000;
392 $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
394 my $dfv = ''; # Offset für Dauerfristverlängerung
395 $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
398 $yymmdd <= ($yy + 110 + $dfv) && do {
399 $form->{year} = $form->{year} - 1;
403 $yymmdd <= ($yy + 410 + $dfv) && do {
407 $yymmdd <= ($yy + 710 + $dfv) && do {
411 $yymmdd <= ($yy + 1010 + $dfv) && do {
415 $yymmdd <= ($yy + 1231) && do {
420 $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
421 . $locale->text('Select a period') . qq|" >|;
423 foreach $key (sort keys %liste) {
425 $selected = 'selected' if ($sel eq $key);
426 $select_vorauswahl .= qq|
427 <option value="$key" $selected>$liste{$key}</option>
430 $select_vorauswahl .= qq|\n</select>
435 # keine Vorauswahl bei Voranmeldungszeitraum
436 $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
437 . $locale->text('Select a period') . qq|" >|;
439 my %listea = ('41' => '1. Quarter',
440 '42' => '2. Quarter',
441 '43' => '3. Quarter',
442 '44' => '4. Quarter',);
444 my %listeb = ('01' => 'January',
458 foreach $key (sort keys %listea) {
459 $select_vorauswahl .= qq|
460 <option value="$key">|
461 . $locale->text("$listea{$key}")
465 foreach $key (sort keys %listeb) {
466 $select_vorauswahl .= qq|
467 <option value="$key">|
468 . $locale->text("$listeb{$key}")
471 $select_vorauswahl .= qq|</select>|;
473 $::lxdebug->leave_sub();
475 return $select_vorauswahl;
479 # $::lxdebug->enter_sub();
481 # $::lxdebug->leave_sub();
485 $::lxdebug->enter_sub();
487 $::lxdebug->leave_sub();
491 $::lxdebug->enter_sub();
493 $::auth->assert('advance_turnover_tax_return');
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">|;
502 qq| <option value=html selected>|
503 . $::locale->text('Preview')
505 if ($::lx_office_conf{print_templates}{latex}) {
507 qq| <option value=pdf>|
508 . $::locale->text('UStVA (PDF-Dokument)')
512 #my $disabled= qq|disabled="disabled"|;
513 #$disabled='' if ($form->{elster} eq '1' );
514 if ($::form->{elster} eq '1') {
516 qq|<option value=elsterwinston>|
517 . $::locale->text('ELSTER Export (Winston)')
519 . qq|<option value=elstertaxbird>|
520 . $::locale->text('ELSTER Export (Taxbird)')
524 #$format .= qq|<option value=elster>|.$locale->text('ELSTER Export nach Winston').qq|</option>|;
525 my $show_options = qq|
528 <select name=format title = "|
529 . $::locale->text('Choose Outputformat') . qq|">$format</select>
531 $::lxdebug->leave_sub();
533 return $show_options;
537 $::lxdebug->enter_sub();
540 my $locale = $::locale;
541 my %myconfig = %::myconfig;
543 $::auth->assert('advance_turnover_tax_return');
545 my $defaults = SL::DB::Default->get;
546 $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
547 $form->{templates} = $defaults->templates;
549 # Aufruf von get_config zum Einlesen der Finanzamtdaten aus finanzamt.ini
551 my $ustva = USTVA->new();
552 $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
554 # init some form vars
555 my @anmeldungszeitraum =
556 qw('0401' '0402' '0403'
560 '0441' '0442' '0443' '0444');
562 foreach my $item (@anmeldungszeitraum) {
566 #forgotten the year --> thisyear
567 if ($form->{year} !~ m/^\d\d\d\d$/) {
568 $form->{year} = substr(
570 $form->current_date(\%myconfig), \%myconfig
573 $::lxdebug->message(LXDebug->DEBUG1,
574 qq|Actual year from Database: $form->{year}\n|);
578 # using dates in ISO-8601 format: yyyymmmdd for Postgres...
582 if ($form->{period} eq "13") {
583 $form->{fromdate} = "$form->{year}0101";
584 $form->{todate} = "$form->{year}1231";
588 if ($form->{period} eq "41") {
589 $form->{fromdate} = "$form->{year}0101";
590 $form->{todate} = "$form->{year}0331";
591 $form->{'0441'} = "X";
593 if ($form->{period} eq "42") {
594 $form->{fromdate} = "$form->{year}0401";
595 $form->{todate} = "$form->{year}0630";
596 $form->{'0442'} = "X";
598 if ($form->{period} eq "43") {
599 $form->{fromdate} = "$form->{year}0701";
600 $form->{todate} = "$form->{year}0930";
601 $form->{'0443'} = "X";
603 if ($form->{period} eq "44") {
604 $form->{fromdate} = "$form->{year}1001";
605 $form->{todate} = "$form->{year}1231";
606 $form->{'0444'} = "X";
611 $form->{period} eq "01" && do {
612 $form->{fromdate} = "$form->{year}0101";
613 $form->{todate} = "$form->{year}0131";
614 $form->{'0401'} = "X";
617 $form->{period} eq "02" && do {
618 $form->{fromdate} = "$form->{year}0201";
620 #this works from 1901 to 2099, 1900 and 2100 fail.
621 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
622 $form->{todate} = "$form->{year}02$leap";
623 $form->{"0402"} = "X";
626 $form->{period} eq "03" && do {
627 $form->{fromdate} = "$form->{year}0301";
628 $form->{todate} = "$form->{year}0331";
629 $form->{"0403"} = "X";
632 $form->{period} eq "04" && do {
633 $form->{fromdate} = "$form->{year}0401";
634 $form->{todate} = "$form->{year}0430";
635 $form->{"0404"} = "X";
638 $form->{period} eq "05" && do {
639 $form->{fromdate} = "$form->{year}0501";
640 $form->{todate} = "$form->{year}0531";
641 $form->{"0405"} = "X";
644 $form->{period} eq "06" && do {
645 $form->{fromdate} = "$form->{year}0601";
646 $form->{todate} = "$form->{year}0630";
647 $form->{"0406"} = "X";
650 $form->{period} eq "07" && do {
651 $form->{fromdate} = "$form->{year}0701";
652 $form->{todate} = "$form->{year}0731";
653 $form->{"0407"} = "X";
656 $form->{period} eq "08" && do {
657 $form->{fromdate} = "$form->{year}0801";
658 $form->{todate} = "$form->{year}0831";
659 $form->{"0408"} = "X";
662 $form->{period} eq "09" && do {
663 $form->{fromdate} = "$form->{year}0901";
664 $form->{todate} = "$form->{year}0930";
665 $form->{"0409"} = "X";
668 $form->{period} eq "10" && do {
669 $form->{fromdate} = "$form->{year}1001";
670 $form->{todate} = "$form->{year}1031";
671 $form->{"0410"} = "X";
674 $form->{period} eq "11" && do {
675 $form->{fromdate} = "$form->{year}1101";
676 $form->{todate} = "$form->{year}1130";
677 $form->{"0411"} = "X";
680 $form->{period} eq "12" && do {
681 $form->{fromdate} = "$form->{year}1201";
682 $form->{todate} = "$form->{year}1231";
683 $form->{"0412"} = "X";
688 # Kontrollvariablen für die Templates
689 $form->{"year$_"} = ($form->{year} >= $_ ) ? "1":"0" for 2007..2107;
692 $ustva->ustva(\%myconfig, \%$form);
694 # reformat Dates to dateformat
695 $form->{fromdate} = $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);
697 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
698 $form->{todate} = $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
700 $form->{longperiod} =
701 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1, 0, 0);
703 # if there are any dates construct a where
704 if ($form->{fromdate} || $form->{todate}) {
706 $form->{todate} = $form->current_date(\%myconfig) unless ($form->{todate});
708 my $longtodate = $locale->date(\%myconfig, $form->{todate}, 1, 0, 0);
709 my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
711 my $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1, 0, 0);
712 my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);
714 $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
715 $form->{longperiod} =
716 $locale->text('for Period')
717 . qq|<br>\n$longfromdate |
718 . $locale->text('to (date)')
722 if ($form->{comparefromdate} || $form->{comparetodate}) {
723 my $longcomparefromdate =
724 $locale->date(\%myconfig, $form->{comparefromdate}, 1, 0, 0);
725 my $shortcomparefromdate =
726 $locale->date(\%myconfig, $form->{comparefromdate}, 0, 0, 0);
728 my $longcomparetodate =
729 $locale->date(\%myconfig, $form->{comparetodate}, 1, 0, 0);
730 my $shortcomparetodate =
731 $locale->date(\%myconfig, $form->{comparetodate}, 0, 0, 0);
733 $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
734 $form->{longperiod} .=
735 "<br>\n$longcomparefromdate "
736 . $locale->text('to (date)')
737 . qq| $longcomparetodate|;
740 $form->{Datum_heute} =
741 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0, 0, 0);
743 # setup variables for the form
744 my @a = qw(company businessnumber tel fax email
745 co_chief co_department co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
746 co_name1 co_name2 co_street co_street1 co_zip co_city co_city1 co_country co_tel co_tel1 co_tel2
747 co_fax co_fax1 co_email co_email1 co_url co_url1 ustid duns
748 co_bankname co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
749 co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2 co_accountnr3);
751 map { $form->{$_} = $myconfig{$_} } @a;
753 if ($form->{address} ne '') {
754 my $temp = $form->{address};
755 $temp =~ s/\\n/<br \/>/;
756 ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
757 $form->{co_city} =~ s/\\n//g;
760 ################################
762 # Nation specific customisations
764 ################################
768 if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') {
771 # Outputformat specific customisation's
774 my @category_cent = $ustva->report_variables({
775 myconfig => \%myconfig,
778 attribute => 'position',
782 push @category_cent, qw(Z43 Z45 Z53 Z62 Z65 Z67);
784 my @category_euro = $ustva->report_variables({
785 myconfig => \%myconfig,
788 attribute => 'position',
793 $form->{amount} = [];
795 if ( $form->{format} eq 'pdf' or $form->{format} eq 'postscript') {
797 $form->{IN} = "$form->{type}-$form->{year}.tex";
798 $form->{padding} = "~~";
799 $form->{bold} = "\textbf{";
800 $form->{endbold} = "}";
801 $form->{br} = '\\\\';
803 # Zahlenformatierung für Latex USTVA Formulare
805 foreach my $number (@category_euro) {
806 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '');
809 my ${decimal_comma} = ( $myconfig{numberformat} eq '1.000,00'
810 or $myconfig{numberformat} eq '1000,00' ) ? ',':'.';
812 foreach my $number (@category_cent) {
813 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '');
814 $form->{$number} =~ s/${decimal_comma}/~~/g;
817 } elsif ( $form->{format} eq 'html') { # Formatierungen für HTML Ausgabe
819 $form->{IN} = $form->{type} . '.html';
820 $form->{padding} = " ";
821 $form->{bold} = "<b>";
822 $form->{endbold} = "</b>";
823 $form->{br} = "<br>";
824 $form->{address} =~ s/\\n/\n/g;
826 foreach my $number (@category_cent) {
827 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '0');
830 foreach my $number (@category_euro) {
831 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '0');
834 } elsif ( $form->{format} eq 'elsterwinston' ) {
836 $form->{IN} = 'winston.xml';
839 # Build Winston filename
842 my $file = 'U'; # 1. char 'U' = USTVA
843 $file .= $form->{period};
844 #4. and 5. char = year modulo 100
845 $file .= sprintf("%02d", $form->{year} % 100);
846 #6. to 18. char = Elstersteuernummer
847 #Beispiel: Steuernummer in Bayern
848 #111/222/33334 ergibt für UStVA Jan 2004: U01049111022233334
849 $file .= $form->{elsterFFFF};
850 $file .= $form->{elstersteuernummer};
855 $form->{attachment_filename} = $file;
857 # Zahlenformatierung für Winston
859 my $temp_numberformat = $myconfig{numberformat};
861 # Numberformat must be '1000,00' for Winston
863 $myconfig{numberformat} = '1000,00';
865 foreach my $number (@category_cent) {
866 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
869 foreach my $number (@category_euro) {
870 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
872 # Re-set Numberformat
873 $myconfig{numberformat} = $temp_numberformat;
875 # push Kennziffern to <%foreach Array fo easyer
876 # output in xml format. Thx to Moritz.
877 my %winston_id_for = (
881 foreach my $kennziffer (@category_cent, @category_euro) {
883 next if ( $kennziffer =~ m/Z\d\d/);
884 next if ( $form->{$kennziffer} == 0 );
886 if (defined $winston_id_for{$kennziffer} ) {
887 push(@{ $form->{id}}, $winston_id_for{$kennziffer});
889 push(@{ $form->{id}}, "Kz$kennziffer");
891 push(@{ $form->{amount}}, $form->{$kennziffer});
894 } elsif ( $form->{format} eq 'elstertaxbird' ) {
896 # Define serveral filenames
897 $form->{IN} = 'taxbird.txb';
899 $form->{attachment_filename} = "USTVA-" . ($form->{period} * 1) . sprintf("%02d", $form->{year} % 100) . ".txb";
901 $form->{attachment_filename} =~ s|.*/||;
903 # TODO: set Output to UTF-8 or system Preference
904 #$form->{"iconv"} = Text::Iconv->new($myconfig{dbcharset}, "UTF-8");
905 #my $iconv = $self->{"iconv"};
906 #$iconv->convert($variable);
907 if ($form->{period} =~ /^[4]\d$/ ){
908 my %periods = ( # Lx => taxbird
915 foreach my $quarter ( keys %periods ) {
916 $form->{taxbird_period} = $periods{$quarter} if ( $form->{period} eq $quarter);
918 } elsif ($form->{period} =~ /^\d+$/ ) {
919 $form->{period} =~ s/^0//g;
920 my $period = $form->{period};
923 $form->{taxbird_period} = $period;
926 USTVA::error( $locale->text('Wrong Period' ));
930 # heuristics for address splitting
931 # lx-office holds the entire address in a single field.
932 # taxbird expects it to be splitted into street, zipcode and city
933 if ($form->{co_street} =~ /\n/) {
935 for (split /\n/, $form->{co_street}) {
936 if (/(\d{3,5})\s+(\w+)/) {
937 $form->{co_zip} = $1;
938 $form->{co_city} = $2;
940 $new_co_street .= $_;
943 $form->{co_street} = $new_co_street;
945 $form->{co_zip} = $form->{co_city};
946 $form->{co_zip} =~ s/\D//g;
947 $form->{co_city} =~ s/\d//g;
948 $form->{co_city} =~ s/^\s//g;
951 my $tax_office = first { $_->{name} eq $form->{elsterland} } @{ $ustva->{tax_office_information} };
952 $form->{taxbird_land_nr} = $tax_office->{taxbird_nr} if $tax_office;
954 ($form->{co_phone_prefix}, $form->{co_phone}) = split("-", $form->{tel});
955 $form->{co_phone_prefix} =~ s/\s//g;
956 $form->{co_phone} =~ s/\s//g;
958 $form->{taxbird_steuernummer} = $form->{steuernummer};
959 # $form->{taxbird_steuernummer} =~ s/\D//g;
960 # $form->{taxbird_steuernummer} =~ s/\///; # ersten Querstrich ersetzen
962 # Numberformatting for Taxbird
963 my $temp_numberformat = $myconfig{numberformat};
964 # Numberformat must be '1000,00' for Taxbird ?!
965 $myconfig{numberformat} = '1000,00';
966 foreach my $number (@category_cent) {
967 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
970 foreach my $number (@category_euro) {
971 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
973 # Re-set Numberformat
974 $myconfig{numberformat} = $temp_numberformat;
976 # push Kennziffern to <%foreach Array fo easyer
977 # output in xml format. Thx to Moritz.
978 my %taxbird_id_for = (
980 '511' => 'Kz51-calc',
981 '861' => 'Kz86-calc',
982 '971' => 'Kz97-calc',
983 '931' => 'Kz93-calc',
984 '811' => 'Kz81-calc',
985 '891' => 'Kz89-calc',
986 'Z45' => 'uebertrag',
988 'Z62' => 'ust-minus-vost',
989 'Z65' => 'ust-sum+69',
994 for my $kennziffer (@category_cent, @category_euro) {
996 next if ($kennziffer eq 'Z43');
998 if ($form->{$kennziffer} != 0){
999 if (defined $taxbird_id_for{$kennziffer}) {
1000 push(@{ $form->{id}}, $taxbird_id_for{$kennziffer});
1002 push(@{ $form->{id}}, "Kz$kennziffer");
1004 push(@{ $form->{amount}}, $form->{$kennziffer});
1008 } elsif ( $form->{format} eq '' ){ # No format error.
1010 USTVA::error( $locale->text('Application Error. No Format given' ) . "!");
1013 } else { # All other Formats are wrong
1015 USTVA::error( $locale->text('Application Error. Wrong Format') . ": " . $form->{format} );
1020 } else # Outputformat for generic output
1023 my @category_cent = $ustva->report_variables({
1024 myconfig => \%myconfig,
1027 attribute => 'position',
1031 my @category_euro = $ustva->report_variables({
1032 myconfig => \%myconfig,
1035 attribute => 'position',
1039 $form->{USTVA} = [];
1041 if ( $form->{format} eq 'generic') { # Formatierungen für HTML Ausgabe
1044 for my $kennziffer (@category_cent, @category_euro) {
1046 $rec_ref->{id} = $kennziffer;
1047 $rec_ref->{amount} = $form->format_amount(\%myconfig, $form->{$kennziffer}, 2, '0');
1049 $::lxdebug->message($LXDebug::DEBUG, "Kennziffer $kennziffer: '$form->{$kennziffer}'" );
1050 $::lxdebug->dump($LXDebug::DEBUG, $rec_ref );
1051 push @ { $form->{USTVA} }, $rec_ref;
1058 if ( $form->{period} eq '13' and $form->{format} ne 'html') {
1062 'Yearly taxreport not yet implemented')
1066 $form->{templates} = "doc" if ( $form->{type} eq 'help' );
1068 if ($form->{format} eq 'generic'){
1072 my $template_ref = {
1073 taxnumber => $myconfig{taxnumber},
1076 print($form->parse_html_template('ustva/generic_taxreport', $template_ref));
1081 $form->parse_template(\%myconfig, $::lx_office_conf{paths}{userspath});
1085 $::lxdebug->leave_sub();
1089 $::lxdebug->enter_sub();
1091 $::auth->assert('advance_turnover_tax_return');
1093 $::form->{title} = $::locale->text('Tax Office Preferences');
1095 # edit all taxauthority prefs
1099 my $ustva = USTVA->new();
1100 $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
1102 my $land = $::form->{elsterland};
1103 my $amt = $::form->{elsterFFFF};
1106 $::form->{title} = $::locale->text('Tax Office Preferences');
1109 my $select_tax_office = $ustva->fa_auswahl($land, $amt, $ustva->query_finanzamt(\%::myconfig, $::form));
1110 my $checked_accrual = $::form->{method} eq 'accrual' ? q|checked="checked"| : '';
1111 my $checked_cash = $::form->{method} eq 'cash' ? q|checked="checked"| : '';
1112 my $checked_monthly = $::form->{FA_voranmeld} eq 'month' ? "checked" : '';
1113 my $checked_quarterly = $::form->{FA_voranmeld} eq 'quarter' ? "checked" : '';
1114 my $checked_dauerfristverlaengerung = $::form->{FA_dauerfrist} eq '1' ? "checked" : '';
1115 my $checked_kz_71 = $::form->{FA_71} eq 'X' ? "checked" : '';
1117 my $_hidden_variables_ref;
1119 my %_hidden_local_variables = (
1120 'saved' => $::locale->text('Check Details'),
1121 'nextsub' => 'config_step2',
1125 foreach my $variable (keys %_hidden_local_variables) {
1126 push @{ $_hidden_variables_ref },
1127 { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
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
1141 foreach my $variable (@_hidden_form_variables) {
1142 push @{ $_hidden_variables_ref},
1143 { 'variable' => $variable, 'value' => $::form->{$variable} };
1146 # Which COA is in use?
1148 $ustva->get_coa($::form, \%::myconfig);
1151 my $steuernummer_new = '';
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,
1165 # Ausgabe des Templates
1166 print($::form->parse_html_template('ustva/config_step1', $template_ref));
1168 $::lxdebug->leave_sub();
1172 $::lxdebug->enter_sub();
1175 my $locale = $::locale;
1176 my %myconfig = %::myconfig;
1178 $::auth->assert('advance_turnover_tax_return');
1182 my $elsterland = '';
1183 my $elster_amt = '';
1184 my $elsterFFFF = '';
1185 my $elstersteuernummer = '';
1187 my $ustva = USTVA->new();
1188 $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini')
1189 if ($form->{saved} eq $locale->text('saved'));
1191 # Auf Übergabefehler checken
1192 USTVA::info( $locale->text('Missing Tax Authoritys Preferences') . "\n"
1193 . $locale->text('USTVA-Hint: Tax Authoritys'))
1194 if ( $form->{elsterFFFF_new} eq 'Auswahl'
1195 || $form->{elsterland_new} eq 'Auswahl');
1196 USTVA::info( $locale->text('Missing Method!') . "\n"
1197 . $locale->text('USTVA-Hint: Method'))
1198 if ($form->{method} eq '');
1200 # Klären, ob Variablen bereits befüllt sind UND ob veräderungen auf
1201 # der vorherigen Maske stattfanden: $change = 1(in der edit sub,
1202 # mittels get_config)
1204 my $change = $form->{elsterland} eq $form->{elsterland_new}
1205 && $form->{elsterFFFF} eq $form->{elsterFFFF_new} ? '0' : '1';
1206 $change = '0' if ($form->{saved} eq $locale->text('saved'));
1207 my $elster_init = $ustva->query_finanzamt(\%myconfig, $form);
1209 my %elster_init = %$elster_init;
1211 if ($change eq '1') {
1214 $elsterland = $form->{elsterland_new};
1215 $elsterFFFF = $form->{elsterFFFF_new};
1216 $form->{elsterland} = $elsterland;
1217 $form->{elsterFFFF} = $elsterFFFF;
1218 $form->{steuernummer} = '';
1220 create_steuernummer();
1222 # rebuild elster_amt
1223 my $amt = $elster_init{$elsterFFFF};
1225 # load the predefined hash data into the FA_* Vars
1226 my @variables = qw(FA_Name FA_Strasse FA_PLZ FA_Ort
1227 FA_Telefon FA_Fax FA_PLZ_Grosskunden FA_PLZ_Postfach
1229 FA_BLZ_1 FA_Kontonummer_1 FA_Bankbezeichnung_1
1230 FA_BLZ_2 FA_Kontonummer_2 FA_Bankbezeichnung_oertlich
1231 FA_Oeffnungszeiten FA_Email FA_Internet);
1233 for (my $i = 0; $i <= 20; $i++) {
1234 $form->{ $variables[$i] } =
1235 $elster_init->{$elsterland}->{$elsterFFFF}->[$i];
1240 $elsterland = $form->{elsterland};
1241 $elsterFFFF = $form->{elsterFFFF};
1244 my $stnr = $form->{steuernummer};
1246 my $patterncount = $form->{patterncount};
1247 my $elster_pattern = $form->{elster_pattern};
1248 my $delimiter = $form->{delimiter};
1249 my $steuernummer = $stnr eq '' ? $form->{steuernummer} : '';
1251 $form->{FA_Oeffnungszeiten} =~ s/\\\\n/\n/g;
1254 $ustva->get_coa($form, \%myconfig);
1256 my $input_steuernummer = $ustva->steuernummer_input(
1257 $form->{elsterland},
1258 $form->{elsterFFFF},
1259 $form->{steuernummer}
1262 $::lxdebug->message(LXDebug->DEBUG1, qq|$input_steuernummer|);
1265 my $_hidden_variables_ref;
1267 my %_hidden_local_variables = (
1268 'elsterland' => $elsterland,
1269 'elsterFFFF' => $elsterFFFF,
1271 'elstersteuernummer' => $elstersteuernummer,
1272 'steuernummer' => $stnr,
1273 'lastsub' => 'config_step1',
1274 'nextsub' => 'save',
1278 foreach my $variable (keys %_hidden_local_variables) {
1279 push @{ $_hidden_variables_ref },
1280 { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
1283 my @_hidden_form_variables = qw(
1284 FA_steuerberater_name FA_steuerberater_street
1285 FA_steuerberater_city FA_steuerberater_tel
1293 foreach my $variable (@_hidden_form_variables) {
1294 push @{ $_hidden_variables_ref},
1295 { 'variable' => $variable, 'value' => $form->{$variable} };
1298 my $template_ref = {
1299 input_steuernummer => $input_steuernummer,
1300 readonly => '', #q|disabled="disabled"|,
1301 callback => $form->{callback},
1302 hidden_variables => $_hidden_variables_ref,
1305 # Ausgabe des Templates
1306 print($form->parse_html_template('ustva/config_step2', $template_ref));
1309 $::lxdebug->leave_sub();
1312 sub create_steuernummer {
1313 $::lxdebug->enter_sub();
1315 $::auth->assert('advance_turnover_tax_return');
1317 my $part = $::form->{part};
1318 my $patterncount = $::form->{patterncount};
1319 my $delimiter = $::form->{delimiter};
1320 my $elster_pattern = $::form->{elster_pattern};
1322 # rebuild steuernummer and elstersteuernummer
1323 # es gibt eine gespeicherte steuernummer $form->{steuernummer}
1324 # und die parts und delimiter
1329 my $steuernummer_new = $part;
1330 my $elstersteuernummer_new = $::form->{elster_FFFF};
1331 $elstersteuernummer_new .= '0';
1333 for ($h = 1; $h < $patterncount; $h++) {
1334 $steuernummer_new .= qq|$delimiter|;
1335 for (my $i = 1; $i <= length($elster_pattern); $i++) {
1336 $steuernummer_new .= $::form->{"part_$h\_$i"};
1337 $elstersteuernummer_new .= $::form->{"part_$h\_$i"};
1340 if ($::form->{steuernummer} ne $steuernummer_new) {
1341 $::form->{steuernummer} = $steuernummer_new;
1342 $::form->{elstersteuernummer} = $elstersteuernummer_new;
1343 $::form->{steuernummer_new} = $steuernummer_new;
1345 $::form->{steuernummer_new} = '';
1346 $::form->{elstersteuernummer_new} = '';
1348 $::lxdebug->leave_sub();
1352 $::lxdebug->enter_sub();
1354 $::auth->assert('advance_turnover_tax_return');
1356 my $filename = "$::form->{login}_$::form->{filename}";
1357 $filename =~ s|.*/||;
1359 #zuerst die steuernummer aus den part, parts_X_Y und delimiter herstellen
1360 create_steuernummer();
1362 # Textboxen formatieren: Linebreaks entfernen
1364 $::form->{FA_Oeffnungszeiten} =~ s/\r\n/\\n/g;
1366 #URL mit http:// davor?
1367 $::form->{FA_Internet} =~ s/^http:\/\///;
1368 $::form->{FA_Internet} = 'http://' . $::form->{FA_Internet};
1371 elster elsterland elstersteuernummer steuernummer
1372 elsteramt elsterFFFF FA_Name FA_Strasse
1373 FA_PLZ FA_Ort FA_Telefon FA_Fax
1374 FA_PLZ_Grosskunden FA_PLZ_Postfach FA_Postfach FA_BLZ_1
1375 FA_Kontonummer_1 FA_Bankbezeichnung_1 FA_BLZ_2 FA_Kontonummer_2
1376 FA_Bankbezeichnung_oertlich FA_Oeffnungszeiten
1377 FA_Email FA_Internet FA_voranmeld method FA_steuerberater_name
1378 FA_steuerberater_street FA_steuerberater_city FA_steuerberater_tel
1379 FA_71 FA_dauerfrist);
1381 # Hier kommt dann die Plausibilitätsprüfung der ELSTERSteuernummer
1382 if ($::form->{elstersteuernummer} ne '000000000') {
1384 $::form->{elster} = '1';
1386 open my $ustvaconfig, ">", "$::lx_office_conf{paths}{userspath}/$filename" or $::form->error("$filename : $!");
1388 # create the config file
1389 print {$ustvaconfig} qq|# Configuration file for USTVA\n\n|;
1391 foreach $key (sort @config) {
1392 $::form->{$key} =~ s/\\/\\\\/g;
1394 $::form->{$key} =~ s/\r\n/\n/g;
1396 print {$ustvaconfig} qq|$key=|;
1397 if ($::form->{$key} ne 'Y') {
1398 print {$ustvaconfig} qq|$::form->{$key}\n|;
1400 if ($::form->{$key} eq 'Y') {
1401 print {$ustvaconfig} qq|checked \n|;
1404 print {$ustvaconfig} qq|\n\n|;
1406 $::form->{saved} = $::locale->text('saved');
1410 $::form->{saved} = $::locale->text('Choose a Tax Number');
1414 $::lxdebug->leave_sub();
1419 $::lxdebug->enter_sub();
1421 # allow Symbolic references just here:
1422 call_sub($::form->{"nextsub"});
1423 $::lxdebug->leave_sub();
1427 $::lxdebug->enter_sub();
1428 call_sub($::form->{"lastsub"});
1429 $::lxdebug->leave_sub();