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();
80 my $locale = $::locale;
81 my %myconfig = %::myconfig;
83 $::auth->assert('advance_turnover_tax_return');
85 $form->{title} = $locale->text('UStVA');
86 $form->{kz10} = ''; #Berichtigte Anmeldung? Ja =1 Nein=0
88 my $year = substr($form->datetonum($form->current_date(\%myconfig), \%myconfig ),
95 # Einlesen der Finanzamtdaten
96 my $ustva = USTVA->new();
97 $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
99 # Hier Einlesen der user-config
100 # steuernummer entfernt für prerelease
102 signature name company address businessnumber
103 tel fax email co_chief co_department
104 co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
105 co_name1 co_name2 co_street co_street1 co_zip
106 co_city co_city1 co_country co_tel co_tel1
107 co_tel2 co_fax co_fax1 co_email co_email1
108 co_url co_url1 ustid duns co_bankname
109 co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
110 co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2
114 map { $form->{$_} = $myconfig{$_} } @a;
116 my $openings = $form->{FA_Oeffnungszeiten};
117 $openings =~ s/\\\\n/<br>/g;
119 my $company_given = ($form->{company} ne '')
120 ? qq|<h3>$form->{company}</h3>\n|
121 : qq|<a href="am.pl?action=config">|
122 . $locale->text('No Company Name given') . qq|!</a><br>|;
125 # Anpassungen der Variablennamen auf pre 2.1.1 Namen
126 # klären, ob $form->{company_street|_address} gesetzt sind
127 if ($form->{address} ne '') {
128 my $temp = $form->{address};
129 $temp =~ s/\n/<br \/>/;
130 ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
131 $form->{co_city} =~ s/\n//g;
136 ($form->{co_street} && ($form->{co_zip} || $form->{co_city}))
137 ? qq|$form->{co_street}<br>|
138 . qq|$form->{co_street1}<br>|
139 . qq|$form->{co_zip} $form->{co_city}|
140 : qq|<a href="am.pl?action=config|
141 . qq|&level=Programm--Preferences">|
142 . $locale->text('No Company Address given')
145 $form->{co_email} = $form->{email} unless $form->{co_email};
146 $form->{co_tel} = $form->{tel} unless $form->{co_tel};
147 $form->{co_fax} = $form->{fax} unless $form->{co_fax};
148 $form->{co_url} = $form->{urlx} unless $form->{co_url};
150 my $taxnumber_given = ($form->{steuernummer} ne '') ? $form->{steuernummer} : qq|<a href="ustva.pl?action=config_step1">Keine Steuernummer hinterlegt!</a><br>|;
152 my $ustva_vorauswahl = &ustva_vorauswahl();
154 my @all_years = $form->all_years(\%myconfig);
156 my $select_year = qq|<select name=year title="|
157 . $locale->text('Year') . qq|">|;
158 foreach my $key (@all_years) {
159 $select_year .= qq|<option |;
160 $select_year .= qq|selected| if ($key eq $form->{year});
161 $select_year .= qq| >$key</option>|;
163 $select_year .= qq|</select>|;
166 $_checked = "checked" if ($form->{kz10} eq '1');
167 my $checkbox_kz_10 = qq|<input name="FA_10" id=FA_10 class=checkbox|
168 . qq| type=checkbox value="1" $_checked title = "|
169 . $locale->text('Amended Advance Turnover Tax Return (Nr. 10)')
171 . $locale->text('Amended Advance Turnover Tax Return');
173 my $method_local = ($form->{method} eq 'accrual') ? $locale->text('accrual')
174 : ($form->{method} eq 'cash') ? $locale->text('cash')
177 my $period_local = ( $form->{FA_voranmeld} eq 'month') ? $locale->text('month')
178 : ( $form->{FA_voranmeld} eq 'quarter') ? $locale->text('quarter')
181 my $tax_office_banks_ref = [
182 { BLZ => $form->{FA_BLZ_1},
183 Kontonummer => $form->{FA_Kontonummer_1},
184 Bankbezeichnung => $form->{FA_Bankbezeichnung_1}
186 { BLZ => $form->{FA_BLZ_2},
187 Kontonummer => $form->{FA_Kontonummer_2},
188 Bankbezeichnung => $form->{FA_Bankbezeichnung_oertlich}
192 # Which COA is in use?
194 $ustva->get_coa($form, \%myconfig);
197 openings => $openings,
198 company_given => $company_given,
199 address_given => $address_given,
200 taxnumber_given => $taxnumber_given,
201 taxnumber => $myconfig{taxnumber},
202 select_year => $select_year,
203 period_local => $period_local,
204 method_local => $method_local,
205 ustva_vorauswahl => $ustva_vorauswahl,
206 checkbox_kz_10 => $checkbox_kz_10,
207 tax_office_banks => $tax_office_banks_ref,
208 select_options => &show_options,
212 print($form->parse_html_template('ustva/report', $template_ref));
216 $::lxdebug->leave_sub();
222 $::lxdebug->enter_sub();
224 $::auth->assert('advance_turnover_tax_return');
226 # parse help documents under doc
227 my $tmp = $::form->{templates};
228 $::form->{templates} = 'doc';
229 $::form->{help} = 'ustva';
230 $::form->{type} = 'help';
231 $::form->{format} = 'html';
234 #$form->{templates} = $tmp;
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 # Aufruf von get_config zum Einlesen der Finanzamtdaten aus finanzamt.ini
547 my $ustva = USTVA->new();
548 $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
550 # init some form vars
551 my @anmeldungszeitraum =
552 qw('0401' '0402' '0403'
556 '0441' '0442' '0443' '0444');
558 foreach my $item (@anmeldungszeitraum) {
562 #forgotten the year --> thisyear
563 if ($form->{year} !~ m/^\d\d\d\d$/) {
564 $form->{year} = substr(
566 $form->current_date(\%myconfig), \%myconfig
569 $::lxdebug->message(LXDebug->DEBUG1,
570 qq|Actual year from Database: $form->{year}\n|);
574 # using dates in ISO-8601 format: yyyymmmdd for Postgres...
578 if ($form->{period} eq "13") {
579 $form->{fromdate} = "$form->{year}0101";
580 $form->{todate} = "$form->{year}1231";
584 if ($form->{period} eq "41") {
585 $form->{fromdate} = "$form->{year}0101";
586 $form->{todate} = "$form->{year}0331";
587 $form->{'0441'} = "X";
589 if ($form->{period} eq "42") {
590 $form->{fromdate} = "$form->{year}0401";
591 $form->{todate} = "$form->{year}0630";
592 $form->{'0442'} = "X";
594 if ($form->{period} eq "43") {
595 $form->{fromdate} = "$form->{year}0701";
596 $form->{todate} = "$form->{year}0930";
597 $form->{'0443'} = "X";
599 if ($form->{period} eq "44") {
600 $form->{fromdate} = "$form->{year}1001";
601 $form->{todate} = "$form->{year}1231";
602 $form->{'0444'} = "X";
607 $form->{period} eq "01" && do {
608 $form->{fromdate} = "$form->{year}0101";
609 $form->{todate} = "$form->{year}0131";
610 $form->{'0401'} = "X";
613 $form->{period} eq "02" && do {
614 $form->{fromdate} = "$form->{year}0201";
616 #this works from 1901 to 2099, 1900 and 2100 fail.
617 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
618 $form->{todate} = "$form->{year}02$leap";
619 $form->{"0402"} = "X";
622 $form->{period} eq "03" && do {
623 $form->{fromdate} = "$form->{year}0301";
624 $form->{todate} = "$form->{year}0331";
625 $form->{"0403"} = "X";
628 $form->{period} eq "04" && do {
629 $form->{fromdate} = "$form->{year}0401";
630 $form->{todate} = "$form->{year}0430";
631 $form->{"0404"} = "X";
634 $form->{period} eq "05" && do {
635 $form->{fromdate} = "$form->{year}0501";
636 $form->{todate} = "$form->{year}0531";
637 $form->{"0405"} = "X";
640 $form->{period} eq "06" && do {
641 $form->{fromdate} = "$form->{year}0601";
642 $form->{todate} = "$form->{year}0630";
643 $form->{"0406"} = "X";
646 $form->{period} eq "07" && do {
647 $form->{fromdate} = "$form->{year}0701";
648 $form->{todate} = "$form->{year}0731";
649 $form->{"0407"} = "X";
652 $form->{period} eq "08" && do {
653 $form->{fromdate} = "$form->{year}0801";
654 $form->{todate} = "$form->{year}0831";
655 $form->{"0408"} = "X";
658 $form->{period} eq "09" && do {
659 $form->{fromdate} = "$form->{year}0901";
660 $form->{todate} = "$form->{year}0930";
661 $form->{"0409"} = "X";
664 $form->{period} eq "10" && do {
665 $form->{fromdate} = "$form->{year}1001";
666 $form->{todate} = "$form->{year}1031";
667 $form->{"0410"} = "X";
670 $form->{period} eq "11" && do {
671 $form->{fromdate} = "$form->{year}1101";
672 $form->{todate} = "$form->{year}1130";
673 $form->{"0411"} = "X";
676 $form->{period} eq "12" && do {
677 $form->{fromdate} = "$form->{year}1201";
678 $form->{todate} = "$form->{year}1231";
679 $form->{"0412"} = "X";
684 # Kontrollvariablen für die Templates
685 $form->{"year$_"} = ($form->{year} >= $_ ) ? "1":"0" for 2007..2107;
688 $ustva->ustva(\%myconfig, \%$form);
690 # reformat Dates to dateformat
691 $form->{fromdate} = $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);
693 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
694 $form->{todate} = $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
696 $form->{longperiod} =
697 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1, 0, 0);
699 # if there are any dates construct a where
700 if ($form->{fromdate} || $form->{todate}) {
702 $form->{todate} = $form->current_date(\%myconfig) unless ($form->{todate});
704 my $longtodate = $locale->date(\%myconfig, $form->{todate}, 1, 0, 0);
705 my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
707 my $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1, 0, 0);
708 my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);
710 $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
711 $form->{longperiod} =
712 $locale->text('for Period')
713 . qq|<br>\n$longfromdate |
714 . $locale->text('to (date)')
718 if ($form->{comparefromdate} || $form->{comparetodate}) {
719 my $longcomparefromdate =
720 $locale->date(\%myconfig, $form->{comparefromdate}, 1, 0, 0);
721 my $shortcomparefromdate =
722 $locale->date(\%myconfig, $form->{comparefromdate}, 0, 0, 0);
724 my $longcomparetodate =
725 $locale->date(\%myconfig, $form->{comparetodate}, 1, 0, 0);
726 my $shortcomparetodate =
727 $locale->date(\%myconfig, $form->{comparetodate}, 0, 0, 0);
729 $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
730 $form->{longperiod} .=
731 "<br>\n$longcomparefromdate "
732 . $locale->text('to (date)')
733 . qq| $longcomparetodate|;
736 $form->{Datum_heute} =
737 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0, 0, 0);
739 # setup variables for the form
740 my @a = qw(company businessnumber tel fax email
741 co_chief co_department co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
742 co_name1 co_name2 co_street co_street1 co_zip co_city co_city1 co_country co_tel co_tel1 co_tel2
743 co_fax co_fax1 co_email co_email1 co_url co_url1 ustid duns
744 co_bankname co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
745 co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2 co_accountnr3);
747 map { $form->{$_} = $myconfig{$_} } @a;
749 if ($form->{address} ne '') {
750 my $temp = $form->{address};
751 $temp =~ s/\\n/<br \/>/;
752 ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
753 $form->{co_city} =~ s/\\n//g;
756 ################################
758 # Nation specific customisations
760 ################################
764 if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') {
767 # Outputformat specific customisation's
770 my @category_cent = $ustva->report_variables({
771 myconfig => \%myconfig,
774 attribute => 'position',
778 push @category_cent, qw(83 Z43 Z45 Z53 Z62 Z65 Z67);
780 my @category_euro = $ustva->report_variables({
781 myconfig => \%myconfig,
784 attribute => 'position',
789 $form->{amount} = [];
791 if ( $form->{format} eq 'pdf' or $form->{format} eq 'postscript') {
793 $form->{IN} = "$form->{type}-$form->{year}.tex";
794 $form->{padding} = "~~";
795 $form->{bold} = "\textbf{";
796 $form->{endbold} = "}";
797 $form->{br} = '\\\\';
799 # Zahlenformatierung für Latex USTVA Formulare
801 foreach my $number (@category_euro) {
802 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '');
805 my ${decimal_comma} = ( $myconfig{numberformat} eq '1.000,00'
806 or $myconfig{numberformat} eq '1000,00' ) ? ',':'.';
808 foreach my $number (@category_cent) {
809 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '');
810 $form->{$number} =~ s/${decimal_comma}/~~/g;
813 } elsif ( $form->{format} eq 'html') { # Formatierungen für HTML Ausgabe
815 $form->{IN} = $form->{type} . '.html';
816 $form->{padding} = " ";
817 $form->{bold} = "<b>";
818 $form->{endbold} = "</b>";
819 $form->{br} = "<br>";
820 $form->{address} =~ s/\\n/\n/g;
822 foreach my $number (@category_cent) {
823 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '0');
826 foreach my $number (@category_euro) {
827 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '0');
830 } elsif ( $form->{format} eq 'elsterwinston' ) {
832 $form->{IN} = 'winston.xml';
835 # Build Winston filename
838 my $file = 'U'; # 1. char 'U' = USTVA
839 $file .= $form->{period};
840 #4. and 5. char = year modulo 100
841 $file .= sprintf("%02d", $form->{year} % 100);
842 #6. to 18. char = Elstersteuernummer
843 #Beispiel: Steuernummer in Bayern
844 #111/222/33334 ergibt für UStVA Jan 2004: U01049111022233334
845 $file .= $form->{elsterFFFF};
846 $file .= $form->{elstersteuernummer};
850 $form->{tmpfile} = "$::lx_office_conf{paths}{userspath}/$file";
852 $form->{attachment_filename} = $file;
854 # Zahlenformatierung für Winston
856 my $temp_numberformat = $myconfig{numberformat};
858 # Numberformat must be '1000.00' for Winston
860 $myconfig{numberformat} = '1000.00';
862 foreach my $number (@category_cent) {
863 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
866 foreach my $number (@category_euro) {
867 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
869 # Re-set Numberformat
870 $myconfig{numberformat} = $temp_numberformat;
872 # push Kennziffern to <%foreach Array fo easyer
873 # output in xml format. Thx to Moritz.
874 my %winston_id_for = (
878 foreach my $kennziffer (@category_cent, @category_euro) {
880 next if ( $kennziffer =~ m/Z\d\d/);
881 next if ( $form->{$kennziffer} == 0 );
883 if (defined $winston_id_for{$kennziffer} ) {
884 push(@{ $form->{id}}, $winston_id_for{$kennziffer});
886 push(@{ $form->{id}}, "Kz$kennziffer");
888 push(@{ $form->{amount}}, $form->{$kennziffer});
891 } elsif ( $form->{format} eq 'elstertaxbird' ) {
893 # Define serveral filenames
894 $form->{IN} = 'taxbird.txb';
896 $form->{attachment_filename} = "USTVA-" . $form->{period}
897 . sprintf("%02d", $form->{year} % 100) . ".txb";
899 $form->{attachment_filename} =~ s|.*/||;
900 $form->{tmpfile} = "$::lx_office_conf{paths}{userspath}/" . $form->{attachment_filename};
902 # TODO: set Output to UTF-8 or system Preference
903 #$form->{"iconv"} = Text::Iconv->new($myconfig{dbcharset}, "UTF-8");
904 #my $iconv = $self->{"iconv"};
905 #$iconv->convert($variable);
906 if ($form->{period} =~ /^[4]\d$/ ){
907 my %periods = ( # Lx => taxbird
914 foreach my $quarter ( keys %periods ) {
915 $form->{taxbird_period} = $periods{$quarter} if ( $form->{period} eq $quarter);
917 } elsif ($form->{period} =~ /^\d+$/ ) {
918 $form->{period} =~ s/^0//g;
919 my $period = $form->{period};
922 $form->{taxbird_period} = $period;
925 USTVA::error( $locale->text('Wrong Period' ));
929 # heuristics for address splitting
930 # lx-office holds the entire address in a single field.
931 # taxbird expects it to be splitted into street, zipcode and city
932 if ($form->{co_street} =~ /\n/) {
934 for (split /\n/, $form->{co_street}) {
935 if (/(\d{3,5})\s+(\w+)/) {
936 $form->{co_zip} = $1;
937 $form->{co_city} = $2;
939 $new_co_street .= $_;
942 $form->{co_street} = $new_co_street;
944 $form->{co_zip} = $form->{co_city};
945 $form->{co_zip} =~ s/\D//g;
946 $form->{co_city} =~ s/\d//g;
947 $form->{co_city} =~ s/^\s//g;
950 my $tax_office = first { $_->{name} eq $form->{elsterland} } @{ $ustva->{tax_office_information} };
951 $form->{taxbird_land_nr} = $tax_office->{taxbird_nr} if $tax_office;
953 ($form->{co_phone_prefix}, $form->{co_phone}) = split("-", $form->{tel});
954 $form->{co_phone_prefix} =~ s/\s//g;
955 $form->{co_phone} =~ s/\s//g;
957 $form->{taxbird_steuernummer} = $form->{steuernummer};
958 # $form->{taxbird_steuernummer} =~ s/\D//g;
959 # $form->{taxbird_steuernummer} =~ s/\///; # ersten Querstrich ersetzen
961 # Numberformatting for Taxbird
962 my $temp_numberformat = $myconfig{numberformat};
963 # Numberformat must be '1000,00' for Taxbird ?!
964 $myconfig{numberformat} = '1000,00';
965 foreach my $number (@category_cent) {
966 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
969 foreach my $number (@category_euro) {
970 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
972 # Re-set Numberformat
973 $myconfig{numberformat} = $temp_numberformat;
975 # push Kennziffern to <%foreach Array fo easyer
976 # output in xml format. Thx to Moritz.
977 my %taxbird_id_for = (
979 '511' => 'Kz51-calc',
980 '861' => 'Kz86-calc',
981 '971' => 'Kz97-calc',
982 '931' => 'Kz93-calc',
983 '811' => 'Kz81-calc',
984 '891' => 'Kz89-calc',
985 'Z45' => 'uebertrag',
987 'Z62' => 'ust-minus-vost',
988 'Z65' => 'ust-sum+69',
993 for my $kennziffer (@category_cent, @category_euro) {
995 next if ($kennziffer eq 'Z43');
997 if ($form->{$kennziffer} != 0){
998 if (defined $taxbird_id_for{$kennziffer}) {
999 push(@{ $form->{id}}, $taxbird_id_for{$kennziffer});
1001 push(@{ $form->{id}}, "Kz$kennziffer");
1003 push(@{ $form->{amount}}, $form->{$kennziffer});
1007 } elsif ( $form->{format} eq '' ){ # No format error.
1009 USTVA::error( $locale->text('Application Error. No Format given' ) . "!");
1012 } else { # All other Formats are wrong
1014 USTVA::error( $locale->text('Application Error. Wrong Format') . ": " . $form->{format} );
1019 } else # Outputformat for generic output
1022 my @category_cent = $ustva->report_variables({
1023 myconfig => \%myconfig,
1026 attribute => 'position',
1030 my @category_euro = $ustva->report_variables({
1031 myconfig => \%myconfig,
1034 attribute => 'position',
1038 $form->{USTVA} = [];
1040 if ( $form->{format} eq 'generic') { # Formatierungen für HTML Ausgabe
1043 for my $kennziffer (@category_cent, @category_euro) {
1045 $rec_ref->{id} = $kennziffer;
1046 $rec_ref->{amount} = $form->format_amount(\%myconfig, $form->{$kennziffer}, 2, '0');
1048 $::lxdebug->message($LXDebug::DEBUG, "Kennziffer $kennziffer: '$form->{$kennziffer}'" );
1049 $::lxdebug->dump($LXDebug::DEBUG, $rec_ref );
1050 push @ { $form->{USTVA} }, $rec_ref;
1057 if ( $form->{period} eq '13' and $form->{format} ne 'html') {
1061 'Yearly taxreport not yet implemented')
1065 $form->{templates} = $myconfig{templates};
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 = q|checked="checked"| if ($::form->{method} eq 'accrual');
1111 my $checked_cash = q|checked="checked"| if ($::form->{method} eq 'cash');
1112 my $checked_monthly = "checked" if ($::form->{FA_voranmeld} eq 'month');
1113 my $checked_quarterly = "checked" if ($::form->{FA_voranmeld} eq 'quarter');
1114 my $checked_dauerfristverlaengerung = "checked" if ($::form->{FA_dauerfrist} eq '1');
1115 my $checked_kz_71 = "checked" if ($::form->{FA_71} eq 'X');
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');
1186 my $elsterland = '';
1187 my $elster_amt = '';
1188 my $elsterFFFF = '';
1189 my $elstersteuernummer = '';
1191 my $ustva = USTVA->new();
1192 $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini')
1193 if ($form->{saved} eq $locale->text('saved'));
1195 # Auf Übergabefehler checken
1196 USTVA::info( $locale->text('Missing Tax Authoritys Preferences') . "\n"
1197 . $locale->text('USTVA-Hint: Tax Authoritys'))
1198 if ( $form->{elsterFFFF_new} eq 'Auswahl'
1199 || $form->{elsterland_new} eq 'Auswahl');
1200 USTVA::info( $locale->text('Missing Method!') . "\n"
1201 . $locale->text('USTVA-Hint: Method'))
1202 if ($form->{method} eq '');
1204 # Klären, ob Variablen bereits befüllt sind UND ob veräderungen auf
1205 # der vorherigen Maske stattfanden: $change = 1(in der edit sub,
1206 # mittels get_config)
1208 my $change = $form->{elsterland} eq $form->{elsterland_new}
1209 && $form->{elsterFFFF} eq $form->{elsterFFFF_new} ? '0' : '1';
1210 $change = '0' if ($form->{saved} eq $locale->text('saved'));
1211 my $elster_init = $ustva->query_finanzamt(\%myconfig, $form);
1213 my %elster_init = %$elster_init;
1215 if ($change eq '1') {
1218 $elsterland = $form->{elsterland_new};
1219 $elsterFFFF = $form->{elsterFFFF_new};
1220 $form->{elsterland} = $elsterland;
1221 $form->{elsterFFFF} = $elsterFFFF;
1222 $form->{steuernummer} = '';
1224 create_steuernummer();
1226 # rebuild elster_amt
1228 foreach $amt (keys %{ $elster_init{ $form->{elsterland} } }) {
1230 if ($elster_init{ $form->{elsterland}{$amt} eq $form->{elsterFFFF} });
1233 # load the predefined hash data into the FA_* Vars
1234 my @variables = qw(FA_Name FA_Strasse FA_PLZ FA_Ort
1235 FA_Telefon FA_Fax FA_PLZ_Grosskunden FA_PLZ_Postfach
1237 FA_BLZ_1 FA_Kontonummer_1 FA_Bankbezeichnung_1
1238 FA_BLZ_2 FA_Kontonummer_2 FA_Bankbezeichnung_oertlich
1239 FA_Oeffnungszeiten FA_Email FA_Internet);
1241 for (my $i = 0; $i <= 20; $i++) {
1242 $form->{ $variables[$i] } =
1243 $elster_init->{$elsterland}->{$elsterFFFF}->[$i];
1248 $elsterland = $form->{elsterland};
1249 $elsterFFFF = $form->{elsterFFFF};
1252 my $stnr = $form->{steuernummer};
1254 my $patterncount = $form->{patterncount};
1255 my $elster_pattern = $form->{elster_pattern};
1256 my $delimiter = $form->{delimiter};
1257 my $steuernummer = $form->{steuernummer} if ($stnr eq '');
1259 $form->{FA_Oeffnungszeiten} =~ s/\\\\n/\n/g;
1262 $ustva->get_coa($form, \%myconfig);
1264 my $input_steuernummer = $ustva->steuernummer_input(
1265 $form->{elsterland},
1266 $form->{elsterFFFF},
1267 $form->{steuernummer}
1270 $::lxdebug->message(LXDebug->DEBUG1, qq|$input_steuernummer|);
1273 my $_hidden_variables_ref;
1275 my %_hidden_local_variables = (
1276 'elsterland' => $elsterland,
1277 'elsterFFFF' => $elsterFFFF,
1279 'elstersteuernummer' => $elstersteuernummer,
1280 'steuernummer' => $stnr,
1281 'lastsub' => 'config_step1',
1282 'nextsub' => 'save',
1286 foreach my $variable (keys %_hidden_local_variables) {
1287 push @{ $_hidden_variables_ref },
1288 { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
1291 my @_hidden_form_variables = qw(
1292 FA_steuerberater_name FA_steuerberater_street
1293 FA_steuerberater_city FA_steuerberater_tel
1301 foreach my $variable (@_hidden_form_variables) {
1302 push @{ $_hidden_variables_ref},
1303 { 'variable' => $variable, 'value' => $form->{$variable} };
1306 my $template_ref = {
1307 input_steuernummer => $input_steuernummer,
1308 readonly => '', #q|disabled="disabled"|,
1309 callback => $form->{callback},
1310 hidden_variables => $_hidden_variables_ref,
1313 # Ausgabe des Templates
1314 print($form->parse_html_template('ustva/config_step2', $template_ref));
1317 $::lxdebug->leave_sub();
1320 sub create_steuernummer {
1321 $::lxdebug->enter_sub();
1323 $::auth->assert('advance_turnover_tax_return');
1325 my $part = $::form->{part};
1326 my $patterncount = $::form->{patterncount};
1327 my $delimiter = $::form->{delimiter};
1328 my $elster_pattern = $::form->{elster_pattern};
1330 # rebuild steuernummer and elstersteuernummer
1331 # es gibt eine gespeicherte steuernummer $form->{steuernummer}
1332 # und die parts und delimiter
1337 my $steuernummer_new = $part;
1338 my $elstersteuernummer_new = $::form->{elster_FFFF};
1339 $elstersteuernummer_new .= '0';
1341 for ($h = 1; $h < $patterncount; $h++) {
1342 $steuernummer_new .= qq|$delimiter|;
1343 for (my $i = 1; $i <= length($elster_pattern); $i++) {
1344 $steuernummer_new .= $::form->{"part_$h\_$i"};
1345 $elstersteuernummer_new .= $::form->{"part_$h\_$i"};
1348 if ($::form->{steuernummer} ne $steuernummer_new) {
1349 $::form->{steuernummer} = $steuernummer_new;
1350 $::form->{elstersteuernummer} = $elstersteuernummer_new;
1351 $::form->{steuernummer_new} = $steuernummer_new;
1353 $::form->{steuernummer_new} = '';
1354 $::form->{elstersteuernummer_new} = '';
1356 $::lxdebug->leave_sub();
1360 $::lxdebug->enter_sub();
1362 $::auth->assert('advance_turnover_tax_return');
1364 my $filename = "$::form->{login}_$::form->{filename}";
1365 $filename =~ s|.*/||;
1367 #zuerst die steuernummer aus den part, parts_X_Y und delimiter herstellen
1368 create_steuernummer();
1370 # Textboxen formatieren: Linebreaks entfernen
1372 $::form->{FA_Oeffnungszeiten} =~ s/\r\n/\\n/g;
1374 #URL mit http:// davor?
1375 $::form->{FA_Internet} =~ s/^http:\/\///;
1376 $::form->{FA_Internet} = 'http://' . $::form->{FA_Internet};
1379 elster elsterland elstersteuernummer steuernummer
1380 elsteramt elsterFFFF FA_Name FA_Strasse
1381 FA_PLZ FA_Ort FA_Telefon FA_Fax
1382 FA_PLZ_Grosskunden FA_PLZ_Postfach FA_Postfach FA_BLZ_1
1383 FA_Kontonummer_1 FA_Bankbezeichnung_1 FA_BLZ_2 FA_Kontonummer_2
1384 FA_Bankbezeichnung_oertlich FA_Oeffnungszeiten
1385 FA_Email FA_Internet FA_voranmeld method FA_steuerberater_name
1386 FA_steuerberater_street FA_steuerberater_city FA_steuerberater_tel
1387 FA_71 FA_dauerfrist);
1389 # Hier kommt dann die Plausibilitätsprüfung der ELSTERSteuernummer
1390 if ($::form->{elstersteuernummer} ne '000000000') {
1392 $::form->{elster} = '1';
1394 open my $ustvaconfig, ">", "$::lx_office_conf{paths}{userspath}/$filename" or $::form->error("$filename : $!");
1396 # create the config file
1397 print {$ustvaconfig} qq|# Configuration file for USTVA\n\n|;
1399 foreach $key (sort @config) {
1400 $::form->{$key} =~ s/\\/\\\\/g;
1402 $::form->{$key} =~ s/\r\n/\n/g;
1404 print {$ustvaconfig} qq|$key=|;
1405 if ($::form->{$key} ne 'Y') {
1406 print {$ustvaconfig} qq|$::form->{$key}\n|;
1408 if ($::form->{$key} eq 'Y') {
1409 print {$ustvaconfig} qq|checked \n|;
1412 print {$ustvaconfig} qq|\n\n|;
1414 $::form->{saved} = $::locale->text('saved');
1418 $::form->{saved} = $::locale->text('Choose a Tax Number');
1422 $::lxdebug->leave_sub();
1427 $::lxdebug->enter_sub();
1429 # allow Symbolic references just here:
1430 call_sub($::form->{"nextsub"});
1431 $::lxdebug->leave_sub();
1435 $::lxdebug->enter_sub();
1436 call_sub($::form->{"lastsub"});
1437 $::lxdebug->leave_sub();