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 my $defaults = SL::DB::Default->get;
88 $form->{title} = $locale->text('UStVA');
89 $form->{kz10} = ''; #Berichtigte Anmeldung? Ja =1 Nein=0
91 my $year = substr($form->datetonum($form->current_date(\%myconfig), \%myconfig ),
98 # Einlesen der Finanzamtdaten
99 my $ustva = USTVA->new();
100 $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
102 # Hier Einlesen der user-config
103 # steuernummer entfernt für prerelease
106 tel fax email co_chief co_department
107 co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
108 co_name1 co_name2 co_street co_street1 co_zip
109 co_city co_city1 co_country co_tel co_tel1
110 co_tel2 co_fax co_fax1 co_email co_email1
111 co_url co_url1 co_bankname
112 co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
113 co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2
117 $form->{$_} = $myconfig{$_} for @a;
118 $form->{$_} = $defaults->$_ for qw(company address co_ustid duns);
120 my $openings = $form->{FA_Oeffnungszeiten};
121 $openings =~ s/\\\\n/<br>/g;
123 my $company_given = ($form->{company} ne '')
124 ? qq|<h3>$form->{company}</h3>\n|
125 : qq|<a href="am.pl?action=config">|
126 . $locale->text('No Company Name given') . qq|!</a><br>|;
129 # Anpassungen der Variablennamen auf pre 2.1.1 Namen
130 # klären, ob $form->{company_street|_address} gesetzt sind
131 if ($form->{address} ne '') {
132 my $temp = $form->{address};
133 $temp =~ s/\n/<br \/>/;
134 ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
135 $form->{co_city} =~ s/\n//g;
140 ($form->{co_street} && ($form->{co_zip} || $form->{co_city}))
141 ? qq|$form->{co_street}<br>|
142 . qq|$form->{co_street1}<br>|
143 . qq|$form->{co_zip} $form->{co_city}|
144 : qq|<a href="am.pl?action=config|
145 . qq|&level=Programm--Preferences">|
146 . $locale->text('No Company Address given')
149 $form->{co_email} = $form->{email} unless $form->{co_email};
150 $form->{co_tel} = $form->{tel} unless $form->{co_tel};
151 $form->{co_fax} = $form->{fax} unless $form->{co_fax};
152 $form->{co_url} = $form->{urlx} unless $form->{co_url};
154 my $taxnumber_given = ($form->{steuernummer} ne '') ? $form->{steuernummer} : qq|<a href="ustva.pl?action=config_step1">Keine Steuernummer hinterlegt!</a><br>|;
156 my $ustva_vorauswahl = &ustva_vorauswahl();
158 my @all_years = $form->all_years(\%myconfig);
160 my $select_year = qq|<select name=year title="|
161 . $locale->text('Year') . qq|">|;
162 foreach my $key (@all_years) {
163 $select_year .= qq|<option |;
164 $select_year .= qq|selected| if ($key eq $form->{year});
165 $select_year .= qq| >$key</option>|;
167 $select_year .= qq|</select>|;
170 $_checked = "checked" if ($form->{kz10} eq '1');
171 my $checkbox_kz_10 = qq|<input name="FA_10" id=FA_10 class=checkbox|
172 . qq| type=checkbox value="1" $_checked title = "|
173 . $locale->text('Amended Advance Turnover Tax Return (Nr. 10)')
175 . $locale->text('Amended Advance Turnover Tax Return');
177 my $method_local = ($form->{method} eq 'accrual') ? $locale->text('accrual')
178 : ($form->{method} eq 'cash') ? $locale->text('cash')
181 my $period_local = ( $form->{FA_voranmeld} eq 'month') ? $locale->text('month')
182 : ( $form->{FA_voranmeld} eq 'quarter') ? $locale->text('quarter')
185 my $tax_office_banks_ref = [
186 { BLZ => $form->{FA_BLZ_1},
187 Kontonummer => $form->{FA_Kontonummer_1},
188 Bankbezeichnung => $form->{FA_Bankbezeichnung_1}
190 { BLZ => $form->{FA_BLZ_2},
191 Kontonummer => $form->{FA_Kontonummer_2},
192 Bankbezeichnung => $form->{FA_Bankbezeichnung_oertlich}
196 # Which COA is in use?
198 $ustva->get_coa($form, \%myconfig);
201 openings => $openings,
202 company_given => $company_given,
203 address_given => $address_given,
204 taxnumber_given => $taxnumber_given,
205 taxnumber => $defaults->taxnumber,
206 select_year => $select_year,
207 period_local => $period_local,
208 method_local => $method_local,
209 ustva_vorauswahl => $ustva_vorauswahl,
210 checkbox_kz_10 => $checkbox_kz_10,
211 tax_office_banks => $tax_office_banks_ref,
212 select_options => &show_options,
216 print($form->parse_html_template('ustva/report', $template_ref));
220 $::lxdebug->leave_sub();
226 $::lxdebug->enter_sub();
228 $::auth->assert('advance_turnover_tax_return');
230 # parse help documents under doc
231 $::form->{templates} = 'doc';
232 $::form->{help} = 'ustva';
233 $::form->{type} = 'help';
234 $::form->{format} = 'html';
237 $::lxdebug->leave_sub();
241 $::lxdebug->enter_sub();
243 $::auth->assert('advance_turnover_tax_return');
246 $::lxdebug->leave_sub();
247 call_sub($::form->{"nextsub"});
250 sub ustva_vorauswahl {
251 $::lxdebug->enter_sub();
254 my $locale = $::locale;
255 my %myconfig = %::myconfig;
257 $::auth->assert('advance_turnover_tax_return');
259 my $select_vorauswahl;
261 #Aktuelles Datum zerlegen:
262 my $date = $form->datetonum($form->current_date(\%myconfig), \%myconfig);
264 #$locale->date($myconfig, $form->current_date($myconfig), 0)=~ /(\d\d).(\d\d).(\d\d\d\d)/;
265 $form->{day} = substr($date, 6, 2);
266 $form->{month} = substr($date, 4, 2);
267 $form->{year} = substr($date, 0, 4);
268 $::lxdebug->message(LXDebug->DEBUG1, qq|
269 Actual date from Database: $date\n
270 Actual year from Database: $form->{year}\n
271 Actual day from Database: $form->{day}\n
272 Actual month from Database: $form->{month}\n|);
277 # Testdaten erzeugen:
279 #$form->{month}= '01';
280 #$form->{year}= 2004;
281 $select_vorauswahl = qq|
282 <input type=hidden name=day value=$form->{day}>
283 <input type=hidden name=month value=$form->{month}>
284 <input type=hidden name=yymmdd value=$yymmdd>
285 <input type=hidden name=sel value=$sel>
288 if ($form->{FA_voranmeld} eq 'month') {
290 # Vorauswahl bei monatlichem Voranmeldungszeitraum
292 my %liste = ('01' => $locale->text('January'),
293 '02' => $locale->text('February'),
294 '03' => $locale->text('March'),
295 '04' => $locale->text('April'),
296 '05' => $locale->text('May'),
297 '06' => $locale->text('June'),
298 '07' => $locale->text('July'),
299 '08' => $locale->text('August'),
300 '09' => $locale->text('September'),
301 '10' => $locale->text('October'),
302 '11' => $locale->text('November'),
303 '12' => $locale->text('December'),
304 '13' => $locale->text('Yearly'),
307 my $yy = $form->{year} * 10000;
308 $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
312 # Offset für Dauerfristverlängerung
313 $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
316 $yymmdd <= ($yy + 110 + $dfv) && do {
317 $form->{year} = $form->{year} - 1;
321 $yymmdd <= ($yy + 210 + $dfv) && do {
325 $yymmdd <= ($yy + 310 + $dfv) && do {
329 $yymmdd <= ($yy + 410 + $dfv) && do {
333 $yymmdd <= ($yy + 510 + $dfv) && do {
337 $yymmdd <= ($yy + 610 + $dfv) && do {
341 $yymmdd <= ($yy + 710 + $dfv) && do {
345 $yymmdd <= ($yy + 810 + $dfv) && do {
349 $yymmdd <= ($yy + 910 + $dfv) && do {
353 $yymmdd <= ($yy + 1010 + $dfv) && do {
357 $yymmdd <= ($yy + 1110 + $dfv) && do {
361 $yymmdd <= ($yy + 1210) && do {
365 $yymmdd <= ($yy + 1231) && do {
371 $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
372 . $locale->text('Select a period') . qq|" >|;
375 foreach $key (sort keys %liste) {
377 $selected = 'selected' if ($sel eq $key);
378 $select_vorauswahl .= qq|
379 <option value="$key" $selected> $liste{$key}</option>
382 $select_vorauswahl .= qq|</select>|;
384 } elsif ($form->{FA_voranmeld} eq 'quarter') {
386 # Vorauswahl bei quartalsweisem Voranmeldungszeitraum
387 my %liste = ('41' => $locale->text('1. Quarter'),
388 '42' => $locale->text('2. Quarter'),
389 '43' => $locale->text('3. Quarter'),
390 '44' => $locale->text('4. Quarter'),
391 '13' => $locale->text('Yearly'),);
393 my $yy = $form->{year} * 10000;
394 $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
396 my $dfv = ''; # Offset für Dauerfristverlängerung
397 $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
400 $yymmdd <= ($yy + 110 + $dfv) && do {
401 $form->{year} = $form->{year} - 1;
405 $yymmdd <= ($yy + 410 + $dfv) && do {
409 $yymmdd <= ($yy + 710 + $dfv) && do {
413 $yymmdd <= ($yy + 1010 + $dfv) && do {
417 $yymmdd <= ($yy + 1231) && do {
422 $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
423 . $locale->text('Select a period') . qq|" >|;
425 foreach $key (sort keys %liste) {
427 $selected = 'selected' if ($sel eq $key);
428 $select_vorauswahl .= qq|
429 <option value="$key" $selected>$liste{$key}</option>
432 $select_vorauswahl .= qq|\n</select>
437 # keine Vorauswahl bei Voranmeldungszeitraum
438 $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
439 . $locale->text('Select a period') . qq|" >|;
441 my %listea = ('41' => '1. Quarter',
442 '42' => '2. Quarter',
443 '43' => '3. Quarter',
444 '44' => '4. Quarter',);
446 my %listeb = ('01' => 'January',
460 foreach $key (sort keys %listea) {
461 $select_vorauswahl .= qq|
462 <option value="$key">|
463 . $locale->text("$listea{$key}")
467 foreach $key (sort keys %listeb) {
468 $select_vorauswahl .= qq|
469 <option value="$key">|
470 . $locale->text("$listeb{$key}")
473 $select_vorauswahl .= qq|</select>|;
475 $::lxdebug->leave_sub();
477 return $select_vorauswahl;
481 # $::lxdebug->enter_sub();
483 # $::lxdebug->leave_sub();
487 $::lxdebug->enter_sub();
489 $::lxdebug->leave_sub();
493 $::lxdebug->enter_sub();
495 $::auth->assert('advance_turnover_tax_return');
497 # $form->{PD}{$form->{type}} = "selected";
498 # $form->{DF}{$form->{format}} = "selected";
499 # $form->{OP}{$form->{media}} = "selected";
500 # $form->{SM}{$form->{sendmode}} = "selected";
501 my $type = qq| <input type=hidden name="type" value="ustva">|;
502 my $media = qq| <input type=hidden name="media" value="screen">|;
504 qq| <option value=html selected>|
505 . $::locale->text('Preview')
507 if ($::lx_office_conf{print_templates}{latex}) {
509 qq| <option value=pdf>|
510 . $::locale->text('UStVA (PDF-Dokument)')
514 #my $disabled= qq|disabled="disabled"|;
515 #$disabled='' if ($form->{elster} eq '1' );
516 if ($::form->{elster} eq '1') {
518 qq|<option value=elsterwinston>|
519 . $::locale->text('ELSTER Export (Winston)')
521 . qq|<option value=elstertaxbird>|
522 . $::locale->text('ELSTER Export (Taxbird)')
526 #$format .= qq|<option value=elster>|.$locale->text('ELSTER Export nach Winston').qq|</option>|;
527 my $show_options = qq|
530 <select name=format title = "|
531 . $::locale->text('Choose Outputformat') . qq|">$format</select>
533 $::lxdebug->leave_sub();
535 return $show_options;
539 $::lxdebug->enter_sub();
542 my $locale = $::locale;
543 my %myconfig = %::myconfig;
545 $::auth->assert('advance_turnover_tax_return');
547 my $defaults = SL::DB::Default->get;
548 $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
549 $form->{templates} = $defaults->templates;
551 # Aufruf von get_config zum Einlesen der Finanzamtdaten aus finanzamt.ini
553 my $ustva = USTVA->new();
554 $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
556 # init some form vars
557 my @anmeldungszeitraum =
558 qw('0401' '0402' '0403'
562 '0441' '0442' '0443' '0444');
564 foreach my $item (@anmeldungszeitraum) {
568 #forgotten the year --> thisyear
569 if ($form->{year} !~ m/^\d\d\d\d$/) {
570 $form->{year} = substr(
572 $form->current_date(\%myconfig), \%myconfig
575 $::lxdebug->message(LXDebug->DEBUG1,
576 qq|Actual year from Database: $form->{year}\n|);
580 # using dates in ISO-8601 format: yyyymmmdd for Postgres...
584 if ($form->{period} eq "13") {
585 $form->{fromdate} = "$form->{year}0101";
586 $form->{todate} = "$form->{year}1231";
590 if ($form->{period} eq "41") {
591 $form->{fromdate} = "$form->{year}0101";
592 $form->{todate} = "$form->{year}0331";
593 $form->{'0441'} = "X";
595 if ($form->{period} eq "42") {
596 $form->{fromdate} = "$form->{year}0401";
597 $form->{todate} = "$form->{year}0630";
598 $form->{'0442'} = "X";
600 if ($form->{period} eq "43") {
601 $form->{fromdate} = "$form->{year}0701";
602 $form->{todate} = "$form->{year}0930";
603 $form->{'0443'} = "X";
605 if ($form->{period} eq "44") {
606 $form->{fromdate} = "$form->{year}1001";
607 $form->{todate} = "$form->{year}1231";
608 $form->{'0444'} = "X";
613 $form->{period} eq "01" && do {
614 $form->{fromdate} = "$form->{year}0101";
615 $form->{todate} = "$form->{year}0131";
616 $form->{'0401'} = "X";
619 $form->{period} eq "02" && do {
620 $form->{fromdate} = "$form->{year}0201";
622 #this works from 1901 to 2099, 1900 and 2100 fail.
623 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
624 $form->{todate} = "$form->{year}02$leap";
625 $form->{"0402"} = "X";
628 $form->{period} eq "03" && do {
629 $form->{fromdate} = "$form->{year}0301";
630 $form->{todate} = "$form->{year}0331";
631 $form->{"0403"} = "X";
634 $form->{period} eq "04" && do {
635 $form->{fromdate} = "$form->{year}0401";
636 $form->{todate} = "$form->{year}0430";
637 $form->{"0404"} = "X";
640 $form->{period} eq "05" && do {
641 $form->{fromdate} = "$form->{year}0501";
642 $form->{todate} = "$form->{year}0531";
643 $form->{"0405"} = "X";
646 $form->{period} eq "06" && do {
647 $form->{fromdate} = "$form->{year}0601";
648 $form->{todate} = "$form->{year}0630";
649 $form->{"0406"} = "X";
652 $form->{period} eq "07" && do {
653 $form->{fromdate} = "$form->{year}0701";
654 $form->{todate} = "$form->{year}0731";
655 $form->{"0407"} = "X";
658 $form->{period} eq "08" && do {
659 $form->{fromdate} = "$form->{year}0801";
660 $form->{todate} = "$form->{year}0831";
661 $form->{"0408"} = "X";
664 $form->{period} eq "09" && do {
665 $form->{fromdate} = "$form->{year}0901";
666 $form->{todate} = "$form->{year}0930";
667 $form->{"0409"} = "X";
670 $form->{period} eq "10" && do {
671 $form->{fromdate} = "$form->{year}1001";
672 $form->{todate} = "$form->{year}1031";
673 $form->{"0410"} = "X";
676 $form->{period} eq "11" && do {
677 $form->{fromdate} = "$form->{year}1101";
678 $form->{todate} = "$form->{year}1130";
679 $form->{"0411"} = "X";
682 $form->{period} eq "12" && do {
683 $form->{fromdate} = "$form->{year}1201";
684 $form->{todate} = "$form->{year}1231";
685 $form->{"0412"} = "X";
690 # Kontrollvariablen für die Templates
691 $form->{"year$_"} = ($form->{year} >= $_ ) ? "1":"0" for 2007..2107;
694 $ustva->ustva(\%myconfig, \%$form);
696 # reformat Dates to dateformat
697 $form->{fromdate} = $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);
699 $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
700 $form->{todate} = $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
702 $form->{longperiod} =
703 $locale->date(\%myconfig, $form->current_date(\%myconfig), 1, 0, 0);
705 # if there are any dates construct a where
706 if ($form->{fromdate} || $form->{todate}) {
708 $form->{todate} = $form->current_date(\%myconfig) unless ($form->{todate});
710 my $longtodate = $locale->date(\%myconfig, $form->{todate}, 1, 0, 0);
711 my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
713 my $longfromdate = $locale->date(\%myconfig, $form->{fromdate}, 1, 0, 0);
714 my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);
716 $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
717 $form->{longperiod} =
718 $locale->text('for Period')
719 . qq|<br>\n$longfromdate |
720 . $locale->text('to (date)')
724 if ($form->{comparefromdate} || $form->{comparetodate}) {
725 my $longcomparefromdate =
726 $locale->date(\%myconfig, $form->{comparefromdate}, 1, 0, 0);
727 my $shortcomparefromdate =
728 $locale->date(\%myconfig, $form->{comparefromdate}, 0, 0, 0);
730 my $longcomparetodate =
731 $locale->date(\%myconfig, $form->{comparetodate}, 1, 0, 0);
732 my $shortcomparetodate =
733 $locale->date(\%myconfig, $form->{comparetodate}, 0, 0, 0);
735 $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
736 $form->{longperiod} .=
737 "<br>\n$longcomparefromdate "
738 . $locale->text('to (date)')
739 . qq| $longcomparetodate|;
742 $form->{Datum_heute} =
743 $locale->date(\%myconfig, $form->current_date(\%myconfig), 0, 0, 0);
745 # setup variables for the form
746 my @a = qw(tel fax email
747 co_chief co_department co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
748 co_name1 co_name2 co_street co_street1 co_zip co_city co_city1 co_country co_tel co_tel1 co_tel2
749 co_fax co_fax1 co_email co_email1 co_url co_url1
750 co_bankname co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
751 co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2 co_accountnr3);
753 $form->{$_} = $myconfig{$_} for @a;
754 $form->{$_} = $defaults->$_ for qw(company address co_ustid duns);
756 if ($form->{address} ne '') {
757 my $temp = $form->{address};
758 $temp =~ s/\\n/<br \/>/;
759 ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
760 $form->{co_city} =~ s/\\n//g;
763 ################################
765 # Nation specific customisations
767 ################################
771 if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') {
774 # Outputformat specific customisation's
777 my @category_cent = $ustva->report_variables({
778 myconfig => \%myconfig,
781 attribute => 'position',
785 push @category_cent, qw(Z43 Z45 Z53 Z62 Z65 Z67);
787 my @category_euro = $ustva->report_variables({
788 myconfig => \%myconfig,
791 attribute => 'position',
796 $form->{amount} = [];
798 if ( $form->{format} eq 'pdf' or $form->{format} eq 'postscript') {
800 $form->{IN} = "$form->{type}-$form->{year}.tex";
801 $form->{padding} = "~~";
802 $form->{bold} = "\textbf{";
803 $form->{endbold} = "}";
804 $form->{br} = '\\\\';
806 # Zahlenformatierung für Latex USTVA Formulare
808 foreach my $number (@category_euro) {
809 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '');
812 my ${decimal_comma} = ( $myconfig{numberformat} eq '1.000,00'
813 or $myconfig{numberformat} eq '1000,00' ) ? ',':'.';
815 foreach my $number (@category_cent) {
816 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '');
817 $form->{$number} =~ s/${decimal_comma}/~~/g;
820 } elsif ( $form->{format} eq 'html') { # Formatierungen für HTML Ausgabe
822 $form->{IN} = $form->{type} . '.html';
823 $form->{padding} = " ";
824 $form->{bold} = "<b>";
825 $form->{endbold} = "</b>";
826 $form->{br} = "<br>";
827 $form->{address} =~ s/\\n/\n/g;
829 foreach my $number (@category_cent) {
830 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '0');
833 foreach my $number (@category_euro) {
834 $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '0');
837 } elsif ( $form->{format} eq 'elsterwinston' ) {
839 $form->{IN} = 'winston.xml';
842 # Build Winston filename
845 my $file = 'U'; # 1. char 'U' = USTVA
846 $file .= $form->{period};
847 #4. and 5. char = year modulo 100
848 $file .= sprintf("%02d", $form->{year} % 100);
849 #6. to 18. char = Elstersteuernummer
850 #Beispiel: Steuernummer in Bayern
851 #111/222/33334 ergibt für UStVA Jan 2004: U01049111022233334
852 $file .= $form->{elsterFFFF};
853 $file .= $form->{elstersteuernummer};
858 $form->{attachment_filename} = $file;
860 # Zahlenformatierung für Winston
862 my $temp_numberformat = $myconfig{numberformat};
864 # Numberformat must be '1000,00' for Winston
866 $myconfig{numberformat} = '1000,00';
868 foreach my $number (@category_cent) {
869 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
872 foreach my $number (@category_euro) {
873 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
875 # Re-set Numberformat
876 $myconfig{numberformat} = $temp_numberformat;
878 # push Kennziffern to <%foreach Array fo easyer
879 # output in xml format. Thx to Moritz.
880 my %winston_id_for = (
884 foreach my $kennziffer (@category_cent, @category_euro) {
886 next if ( $kennziffer =~ m/Z\d\d/);
887 next if ( $form->{$kennziffer} == 0 );
889 if (defined $winston_id_for{$kennziffer} ) {
890 push(@{ $form->{id}}, $winston_id_for{$kennziffer});
892 push(@{ $form->{id}}, "Kz$kennziffer");
894 push(@{ $form->{amount}}, $form->{$kennziffer});
897 } elsif ( $form->{format} eq 'elstertaxbird' ) {
899 # Define serveral filenames
900 $form->{IN} = 'taxbird.txb';
902 $form->{attachment_filename} = "USTVA-" . ($form->{period} * 1) . sprintf("%02d", $form->{year} % 100) . ".txb";
904 $form->{attachment_filename} =~ s|.*/||;
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} = "doc" if ( $form->{type} eq 'help' );
1067 if ($form->{format} eq 'generic'){
1071 my $template_ref = {
1072 taxnumber => $defaults->taxnumber,
1075 print($form->parse_html_template('ustva/generic_taxreport', $template_ref));
1080 $form->parse_template(\%myconfig, $::lx_office_conf{paths}{userspath});
1084 $::lxdebug->leave_sub();
1088 $::lxdebug->enter_sub();
1090 $::auth->assert('advance_turnover_tax_return');
1092 $::form->{title} = $::locale->text('Tax Office Preferences');
1094 # edit all taxauthority prefs
1098 my $ustva = USTVA->new();
1099 $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
1101 my $land = $::form->{elsterland};
1102 my $amt = $::form->{elsterFFFF};
1105 $::form->{title} = $::locale->text('Tax Office Preferences');
1108 my $select_tax_office = $ustva->fa_auswahl($land, $amt, $ustva->query_finanzamt(\%::myconfig, $::form));
1109 my $checked_accrual = $::form->{method} eq 'accrual' ? q|checked="checked"| : '';
1110 my $checked_cash = $::form->{method} eq 'cash' ? q|checked="checked"| : '';
1111 my $checked_monthly = $::form->{FA_voranmeld} eq 'month' ? "checked" : '';
1112 my $checked_quarterly = $::form->{FA_voranmeld} eq 'quarter' ? "checked" : '';
1113 my $checked_dauerfristverlaengerung = $::form->{FA_dauerfrist} eq '1' ? "checked" : '';
1114 my $checked_kz_71 = $::form->{FA_71} eq 'X' ? "checked" : '';
1116 my $_hidden_variables_ref;
1118 my %_hidden_local_variables = (
1119 'saved' => $::locale->text('Check Details'),
1120 'nextsub' => 'config_step2',
1124 foreach my $variable (keys %_hidden_local_variables) {
1125 push @{ $_hidden_variables_ref },
1126 { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
1129 my @_hidden_form_variables = qw(
1130 FA_Name FA_Strasse FA_PLZ
1131 FA_Ort FA_Telefon FA_Fax
1132 FA_PLZ_Grosskunden FA_PLZ_Postfach FA_Postfach
1133 FA_BLZ_1 FA_Kontonummer_1 FA_Bankbezeichnung_1
1134 FA_BLZ_2 FA_Kontonummer_2 FA_Bankbezeichnung_oertlich
1135 FA_Oeffnungszeiten FA_Email FA_Internet
1136 steuernummer elsterland elstersteuernummer
1140 foreach my $variable (@_hidden_form_variables) {
1141 push @{ $_hidden_variables_ref},
1142 { 'variable' => $variable, 'value' => $::form->{$variable} };
1145 # Which COA is in use?
1147 $ustva->get_coa($::form, \%::myconfig);
1150 my $steuernummer_new = '';
1152 # Variablen für das Template zur Verfügung stellen
1153 my $template_ref = {
1154 select_tax_office => $select_tax_office,
1155 checked_accrual => $checked_accrual,
1156 checked_cash => $checked_cash,
1157 checked_monthly => $checked_monthly,
1158 checked_quarterly => $checked_quarterly,
1159 checked_dauerfristverlaengerung => $checked_dauerfristverlaengerung,
1160 hidden_variables => $_hidden_variables_ref,
1164 # Ausgabe des Templates
1165 print($::form->parse_html_template('ustva/config_step1', $template_ref));
1167 $::lxdebug->leave_sub();
1171 $::lxdebug->enter_sub();
1174 my $locale = $::locale;
1175 my %myconfig = %::myconfig;
1177 $::auth->assert('advance_turnover_tax_return');
1181 my $elsterland = '';
1182 my $elster_amt = '';
1183 my $elsterFFFF = '';
1184 my $elstersteuernummer = '';
1186 my $ustva = USTVA->new();
1187 $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini')
1188 if ($form->{saved} eq $locale->text('saved'));
1190 # Auf Übergabefehler checken
1191 USTVA::info( $locale->text('Missing Tax Authoritys Preferences') . "\n"
1192 . $locale->text('USTVA-Hint: Tax Authoritys'))
1193 if ( $form->{elsterFFFF_new} eq 'Auswahl'
1194 || $form->{elsterland_new} eq 'Auswahl');
1195 USTVA::info( $locale->text('Missing Method!') . "\n"
1196 . $locale->text('USTVA-Hint: Method'))
1197 if ($form->{method} eq '');
1199 # Klären, ob Variablen bereits befüllt sind UND ob veräderungen auf
1200 # der vorherigen Maske stattfanden: $change = 1(in der edit sub,
1201 # mittels get_config)
1203 my $change = $form->{elsterland} eq $form->{elsterland_new}
1204 && $form->{elsterFFFF} eq $form->{elsterFFFF_new} ? '0' : '1';
1205 $change = '0' if ($form->{saved} eq $locale->text('saved'));
1206 my $elster_init = $ustva->query_finanzamt(\%myconfig, $form);
1208 my %elster_init = %$elster_init;
1210 if ($change eq '1') {
1213 $elsterland = $form->{elsterland_new};
1214 $elsterFFFF = $form->{elsterFFFF_new};
1215 $form->{elsterland} = $elsterland;
1216 $form->{elsterFFFF} = $elsterFFFF;
1217 $form->{steuernummer} = '';
1219 create_steuernummer();
1221 # rebuild elster_amt
1222 my $amt = $elster_init{$elsterFFFF};
1224 # load the predefined hash data into the FA_* Vars
1225 my @variables = qw(FA_Name FA_Strasse FA_PLZ FA_Ort
1226 FA_Telefon FA_Fax FA_PLZ_Grosskunden FA_PLZ_Postfach
1228 FA_BLZ_1 FA_Kontonummer_1 FA_Bankbezeichnung_1
1229 FA_BLZ_2 FA_Kontonummer_2 FA_Bankbezeichnung_oertlich
1230 FA_Oeffnungszeiten FA_Email FA_Internet);
1232 for (my $i = 0; $i <= 20; $i++) {
1233 $form->{ $variables[$i] } =
1234 $elster_init->{$elsterland}->{$elsterFFFF}->[$i];
1239 $elsterland = $form->{elsterland};
1240 $elsterFFFF = $form->{elsterFFFF};
1243 my $stnr = $form->{steuernummer};
1245 my $patterncount = $form->{patterncount};
1246 my $elster_pattern = $form->{elster_pattern};
1247 my $delimiter = $form->{delimiter};
1248 my $steuernummer = $stnr eq '' ? $form->{steuernummer} : '';
1250 $form->{FA_Oeffnungszeiten} =~ s/\\\\n/\n/g;
1253 $ustva->get_coa($form, \%myconfig);
1255 my $input_steuernummer = $ustva->steuernummer_input(
1256 $form->{elsterland},
1257 $form->{elsterFFFF},
1258 $form->{steuernummer}
1261 $::lxdebug->message(LXDebug->DEBUG1, qq|$input_steuernummer|);
1264 my $_hidden_variables_ref;
1266 my %_hidden_local_variables = (
1267 'elsterland' => $elsterland,
1268 'elsterFFFF' => $elsterFFFF,
1270 'elstersteuernummer' => $elstersteuernummer,
1271 'steuernummer' => $stnr,
1272 'lastsub' => 'config_step1',
1273 'nextsub' => 'save',
1277 foreach my $variable (keys %_hidden_local_variables) {
1278 push @{ $_hidden_variables_ref },
1279 { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
1282 my @_hidden_form_variables = qw(
1283 FA_steuerberater_name FA_steuerberater_street
1284 FA_steuerberater_city FA_steuerberater_tel
1292 foreach my $variable (@_hidden_form_variables) {
1293 push @{ $_hidden_variables_ref},
1294 { 'variable' => $variable, 'value' => $form->{$variable} };
1297 my $template_ref = {
1298 input_steuernummer => $input_steuernummer,
1299 readonly => '', #q|disabled="disabled"|,
1300 callback => $form->{callback},
1301 hidden_variables => $_hidden_variables_ref,
1304 # Ausgabe des Templates
1305 print($form->parse_html_template('ustva/config_step2', $template_ref));
1308 $::lxdebug->leave_sub();
1311 sub create_steuernummer {
1312 $::lxdebug->enter_sub();
1314 $::auth->assert('advance_turnover_tax_return');
1316 my $part = $::form->{part};
1317 my $patterncount = $::form->{patterncount};
1318 my $delimiter = $::form->{delimiter};
1319 my $elster_pattern = $::form->{elster_pattern};
1321 # rebuild steuernummer and elstersteuernummer
1322 # es gibt eine gespeicherte steuernummer $form->{steuernummer}
1323 # und die parts und delimiter
1328 my $steuernummer_new = $part;
1329 my $elstersteuernummer_new = $::form->{elster_FFFF};
1330 $elstersteuernummer_new .= '0';
1332 for ($h = 1; $h < $patterncount; $h++) {
1333 $steuernummer_new .= qq|$delimiter|;
1334 for (my $i = 1; $i <= length($elster_pattern); $i++) {
1335 $steuernummer_new .= $::form->{"part_$h\_$i"};
1336 $elstersteuernummer_new .= $::form->{"part_$h\_$i"};
1339 if ($::form->{steuernummer} ne $steuernummer_new) {
1340 $::form->{steuernummer} = $steuernummer_new;
1341 $::form->{elstersteuernummer} = $elstersteuernummer_new;
1342 $::form->{steuernummer_new} = $steuernummer_new;
1344 $::form->{steuernummer_new} = '';
1345 $::form->{elstersteuernummer_new} = '';
1347 $::lxdebug->leave_sub();
1351 $::lxdebug->enter_sub();
1353 $::auth->assert('advance_turnover_tax_return');
1355 my $filename = "$::form->{login}_$::form->{filename}";
1356 $filename =~ s|.*/||;
1358 #zuerst die steuernummer aus den part, parts_X_Y und delimiter herstellen
1359 create_steuernummer();
1361 # Textboxen formatieren: Linebreaks entfernen
1363 $::form->{FA_Oeffnungszeiten} =~ s/\r\n/\\n/g;
1365 #URL mit http:// davor?
1366 $::form->{FA_Internet} =~ s/^http:\/\///;
1367 $::form->{FA_Internet} = 'http://' . $::form->{FA_Internet};
1370 elster elsterland elstersteuernummer steuernummer
1371 elsteramt elsterFFFF FA_Name FA_Strasse
1372 FA_PLZ FA_Ort FA_Telefon FA_Fax
1373 FA_PLZ_Grosskunden FA_PLZ_Postfach FA_Postfach FA_BLZ_1
1374 FA_Kontonummer_1 FA_Bankbezeichnung_1 FA_BLZ_2 FA_Kontonummer_2
1375 FA_Bankbezeichnung_oertlich FA_Oeffnungszeiten
1376 FA_Email FA_Internet FA_voranmeld method FA_steuerberater_name
1377 FA_steuerberater_street FA_steuerberater_city FA_steuerberater_tel
1378 FA_71 FA_dauerfrist);
1380 # Hier kommt dann die Plausibilitätsprüfung der ELSTERSteuernummer
1381 if ($::form->{elstersteuernummer} ne '000000000') {
1383 $::form->{elster} = '1';
1385 open my $ustvaconfig, ">", "$::lx_office_conf{paths}{userspath}/$filename" or $::form->error("$filename : $!");
1387 # create the config file
1388 print {$ustvaconfig} qq|# Configuration file for USTVA\n\n|;
1390 foreach $key (sort @config) {
1391 $::form->{$key} =~ s/\\/\\\\/g;
1393 $::form->{$key} =~ s/\r\n/\n/g;
1395 print {$ustvaconfig} qq|$key=|;
1396 if ($::form->{$key} ne 'Y') {
1397 print {$ustvaconfig} qq|$::form->{$key}\n|;
1399 if ($::form->{$key} eq 'Y') {
1400 print {$ustvaconfig} qq|checked \n|;
1403 print {$ustvaconfig} qq|\n\n|;
1405 $::form->{saved} = $::locale->text('saved');
1409 $::form->{saved} = $::locale->text('Choose a Tax Number');
1413 $::lxdebug->leave_sub();
1418 $::lxdebug->enter_sub();
1420 # allow Symbolic references just here:
1421 call_sub($::form->{"nextsub"});
1422 $::lxdebug->leave_sub();
1426 $::lxdebug->enter_sub();
1427 call_sub($::form->{"lastsub"});
1428 $::lxdebug->leave_sub();