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 # TODO: set Output to UTF-8 or system Preference
907 #$form->{"iconv"} = Text::Iconv->new($myconfig{dbcharset}, "UTF-8");
908 #my $iconv = $self->{"iconv"};
909 #$iconv->convert($variable);
910 if ($form->{period} =~ /^[4]\d$/ ){
911 my %periods = ( # Lx => taxbird
918 foreach my $quarter ( keys %periods ) {
919 $form->{taxbird_period} = $periods{$quarter} if ( $form->{period} eq $quarter);
921 } elsif ($form->{period} =~ /^\d+$/ ) {
922 $form->{period} =~ s/^0//g;
923 my $period = $form->{period};
926 $form->{taxbird_period} = $period;
929 USTVA::error( $locale->text('Wrong Period' ));
933 # heuristics for address splitting
934 # lx-office holds the entire address in a single field.
935 # taxbird expects it to be splitted into street, zipcode and city
936 if ($form->{co_street} =~ /\n/) {
938 for (split /\n/, $form->{co_street}) {
939 if (/(\d{3,5})\s+(\w+)/) {
940 $form->{co_zip} = $1;
941 $form->{co_city} = $2;
943 $new_co_street .= $_;
946 $form->{co_street} = $new_co_street;
948 $form->{co_zip} = $form->{co_city};
949 $form->{co_zip} =~ s/\D//g;
950 $form->{co_city} =~ s/\d//g;
951 $form->{co_city} =~ s/^\s//g;
954 my $tax_office = first { $_->{name} eq $form->{elsterland} } @{ $ustva->{tax_office_information} };
955 $form->{taxbird_land_nr} = $tax_office->{taxbird_nr} if $tax_office;
957 ($form->{co_phone_prefix}, $form->{co_phone}) = split("-", $form->{tel});
958 $form->{co_phone_prefix} =~ s/\s//g;
959 $form->{co_phone} =~ s/\s//g;
961 $form->{taxbird_steuernummer} = $form->{steuernummer};
962 # $form->{taxbird_steuernummer} =~ s/\D//g;
963 # $form->{taxbird_steuernummer} =~ s/\///; # ersten Querstrich ersetzen
965 # Numberformatting for Taxbird
966 my $temp_numberformat = $myconfig{numberformat};
967 # Numberformat must be '1000,00' for Taxbird ?!
968 $myconfig{numberformat} = '1000,00';
969 foreach my $number (@category_cent) {
970 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
973 foreach my $number (@category_euro) {
974 $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
976 # Re-set Numberformat
977 $myconfig{numberformat} = $temp_numberformat;
979 # push Kennziffern to <%foreach Array fo easyer
980 # output in xml format. Thx to Moritz.
981 my %taxbird_id_for = (
983 '511' => 'Kz51-calc',
984 '861' => 'Kz86-calc',
985 '971' => 'Kz97-calc',
986 '931' => 'Kz93-calc',
987 '811' => 'Kz81-calc',
988 '891' => 'Kz89-calc',
989 'Z45' => 'uebertrag',
991 'Z62' => 'ust-minus-vost',
992 'Z65' => 'ust-sum+69',
997 for my $kennziffer (@category_cent, @category_euro) {
999 next if ($kennziffer eq 'Z43');
1001 if ($form->{$kennziffer} != 0){
1002 if (defined $taxbird_id_for{$kennziffer}) {
1003 push(@{ $form->{id}}, $taxbird_id_for{$kennziffer});
1005 push(@{ $form->{id}}, "Kz$kennziffer");
1007 push(@{ $form->{amount}}, $form->{$kennziffer});
1011 } elsif ( $form->{format} eq '' ){ # No format error.
1013 USTVA::error( $locale->text('Application Error. No Format given' ) . "!");
1016 } else { # All other Formats are wrong
1018 USTVA::error( $locale->text('Application Error. Wrong Format') . ": " . $form->{format} );
1023 } else # Outputformat for generic output
1026 my @category_cent = $ustva->report_variables({
1027 myconfig => \%myconfig,
1030 attribute => 'position',
1034 my @category_euro = $ustva->report_variables({
1035 myconfig => \%myconfig,
1038 attribute => 'position',
1042 $form->{USTVA} = [];
1044 if ( $form->{format} eq 'generic') { # Formatierungen für HTML Ausgabe
1047 for my $kennziffer (@category_cent, @category_euro) {
1049 $rec_ref->{id} = $kennziffer;
1050 $rec_ref->{amount} = $form->format_amount(\%myconfig, $form->{$kennziffer}, 2, '0');
1052 $::lxdebug->message($LXDebug::DEBUG, "Kennziffer $kennziffer: '$form->{$kennziffer}'" );
1053 $::lxdebug->dump($LXDebug::DEBUG, $rec_ref );
1054 push @ { $form->{USTVA} }, $rec_ref;
1061 if ( $form->{period} eq '13' and $form->{format} ne 'html') {
1065 'Yearly taxreport not yet implemented')
1069 $form->{templates} = "doc" if ( $form->{type} eq 'help' );
1071 if ($form->{format} eq 'generic'){
1075 my $template_ref = {
1076 taxnumber => $defaults->taxnumber,
1079 print($form->parse_html_template('ustva/generic_taxreport', $template_ref));
1084 $form->parse_template(\%myconfig, $::lx_office_conf{paths}{userspath});
1088 $::lxdebug->leave_sub();
1092 $::lxdebug->enter_sub();
1094 $::auth->assert('advance_turnover_tax_return');
1096 $::form->{title} = $::locale->text('Tax Office Preferences');
1098 # edit all taxauthority prefs
1102 my $ustva = USTVA->new();
1103 $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
1105 my $land = $::form->{elsterland};
1106 my $amt = $::form->{elsterFFFF};
1109 $::form->{title} = $::locale->text('Tax Office Preferences');
1112 my $select_tax_office = $ustva->fa_auswahl($land, $amt, $ustva->query_finanzamt(\%::myconfig, $::form));
1113 my $checked_accrual = $::form->{method} eq 'accrual' ? q|checked="checked"| : '';
1114 my $checked_cash = $::form->{method} eq 'cash' ? q|checked="checked"| : '';
1115 my $checked_monthly = $::form->{FA_voranmeld} eq 'month' ? "checked" : '';
1116 my $checked_quarterly = $::form->{FA_voranmeld} eq 'quarter' ? "checked" : '';
1117 my $checked_dauerfristverlaengerung = $::form->{FA_dauerfrist} eq '1' ? "checked" : '';
1118 my $checked_kz_71 = $::form->{FA_71} eq 'X' ? "checked" : '';
1120 my $_hidden_variables_ref;
1122 my %_hidden_local_variables = (
1123 'saved' => $::locale->text('Check Details'),
1124 'nextsub' => 'config_step2',
1128 foreach my $variable (keys %_hidden_local_variables) {
1129 push @{ $_hidden_variables_ref },
1130 { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
1133 my @_hidden_form_variables = qw(
1134 FA_Name FA_Strasse FA_PLZ
1135 FA_Ort FA_Telefon FA_Fax
1136 FA_PLZ_Grosskunden FA_PLZ_Postfach FA_Postfach
1137 FA_BLZ_1 FA_Kontonummer_1 FA_Bankbezeichnung_1
1138 FA_BLZ_2 FA_Kontonummer_2 FA_Bankbezeichnung_oertlich
1139 FA_Oeffnungszeiten FA_Email FA_Internet
1140 steuernummer elsterland elstersteuernummer
1144 foreach my $variable (@_hidden_form_variables) {
1145 push @{ $_hidden_variables_ref},
1146 { 'variable' => $variable, 'value' => $::form->{$variable} };
1149 # Which COA is in use?
1151 $ustva->get_coa($::form, \%::myconfig);
1154 my $steuernummer_new = '';
1156 # Variablen für das Template zur Verfügung stellen
1157 my $template_ref = {
1158 select_tax_office => $select_tax_office,
1159 checked_accrual => $checked_accrual,
1160 checked_cash => $checked_cash,
1161 checked_monthly => $checked_monthly,
1162 checked_quarterly => $checked_quarterly,
1163 checked_dauerfristverlaengerung => $checked_dauerfristverlaengerung,
1164 hidden_variables => $_hidden_variables_ref,
1168 # Ausgabe des Templates
1169 print($::form->parse_html_template('ustva/config_step1', $template_ref));
1171 $::lxdebug->leave_sub();
1175 $::lxdebug->enter_sub();
1178 my $locale = $::locale;
1179 my %myconfig = %::myconfig;
1181 $::auth->assert('advance_turnover_tax_return');
1185 my $elsterland = '';
1186 my $elster_amt = '';
1187 my $elsterFFFF = '';
1188 my $elstersteuernummer = '';
1190 my $ustva = USTVA->new();
1191 $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini')
1192 if ($form->{saved} eq $locale->text('saved'));
1194 # Auf Übergabefehler checken
1195 USTVA::info( $locale->text('Missing Tax Authoritys Preferences') . "\n"
1196 . $locale->text('USTVA-Hint: Tax Authoritys'))
1197 if ( $form->{elsterFFFF_new} eq 'Auswahl'
1198 || $form->{elsterland_new} eq 'Auswahl');
1199 USTVA::info( $locale->text('Missing Method!') . "\n"
1200 . $locale->text('USTVA-Hint: Method'))
1201 if ($form->{method} eq '');
1203 # Klären, ob Variablen bereits befüllt sind UND ob veräderungen auf
1204 # der vorherigen Maske stattfanden: $change = 1(in der edit sub,
1205 # mittels get_config)
1207 my $change = $form->{elsterland} eq $form->{elsterland_new}
1208 && $form->{elsterFFFF} eq $form->{elsterFFFF_new} ? '0' : '1';
1209 $change = '0' if ($form->{saved} eq $locale->text('saved'));
1210 my $elster_init = $ustva->query_finanzamt(\%myconfig, $form);
1212 my %elster_init = %$elster_init;
1214 if ($change eq '1') {
1217 $elsterland = $form->{elsterland_new};
1218 $elsterFFFF = $form->{elsterFFFF_new};
1219 $form->{elsterland} = $elsterland;
1220 $form->{elsterFFFF} = $elsterFFFF;
1221 $form->{steuernummer} = '';
1223 create_steuernummer();
1225 # rebuild elster_amt
1226 my $amt = $elster_init{$elsterFFFF};
1228 # load the predefined hash data into the FA_* Vars
1229 my @variables = qw(FA_Name FA_Strasse FA_PLZ FA_Ort
1230 FA_Telefon FA_Fax FA_PLZ_Grosskunden FA_PLZ_Postfach
1232 FA_BLZ_1 FA_Kontonummer_1 FA_Bankbezeichnung_1
1233 FA_BLZ_2 FA_Kontonummer_2 FA_Bankbezeichnung_oertlich
1234 FA_Oeffnungszeiten FA_Email FA_Internet);
1236 for (my $i = 0; $i <= 20; $i++) {
1237 $form->{ $variables[$i] } =
1238 $elster_init->{$elsterland}->{$elsterFFFF}->[$i];
1243 $elsterland = $form->{elsterland};
1244 $elsterFFFF = $form->{elsterFFFF};
1247 my $stnr = $form->{steuernummer};
1249 my $patterncount = $form->{patterncount};
1250 my $elster_pattern = $form->{elster_pattern};
1251 my $delimiter = $form->{delimiter};
1252 my $steuernummer = $stnr eq '' ? $form->{steuernummer} : '';
1254 $form->{FA_Oeffnungszeiten} =~ s/\\\\n/\n/g;
1257 $ustva->get_coa($form, \%myconfig);
1259 my $input_steuernummer = $ustva->steuernummer_input(
1260 $form->{elsterland},
1261 $form->{elsterFFFF},
1262 $form->{steuernummer}
1265 $::lxdebug->message(LXDebug->DEBUG1, qq|$input_steuernummer|);
1268 my $_hidden_variables_ref;
1270 my %_hidden_local_variables = (
1271 'elsterland' => $elsterland,
1272 'elsterFFFF' => $elsterFFFF,
1274 'elstersteuernummer' => $elstersteuernummer,
1275 'steuernummer' => $stnr,
1276 'lastsub' => 'config_step1',
1277 'nextsub' => 'save',
1281 foreach my $variable (keys %_hidden_local_variables) {
1282 push @{ $_hidden_variables_ref },
1283 { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
1286 my @_hidden_form_variables = qw(
1287 FA_steuerberater_name FA_steuerberater_street
1288 FA_steuerberater_city FA_steuerberater_tel
1296 foreach my $variable (@_hidden_form_variables) {
1297 push @{ $_hidden_variables_ref},
1298 { 'variable' => $variable, 'value' => $form->{$variable} };
1301 my $template_ref = {
1302 input_steuernummer => $input_steuernummer,
1303 readonly => '', #q|disabled="disabled"|,
1304 callback => $form->{callback},
1305 hidden_variables => $_hidden_variables_ref,
1308 # Ausgabe des Templates
1309 print($form->parse_html_template('ustva/config_step2', $template_ref));
1312 $::lxdebug->leave_sub();
1315 sub create_steuernummer {
1316 $::lxdebug->enter_sub();
1318 $::auth->assert('advance_turnover_tax_return');
1320 my $part = $::form->{part};
1321 my $patterncount = $::form->{patterncount};
1322 my $delimiter = $::form->{delimiter};
1323 my $elster_pattern = $::form->{elster_pattern};
1325 # rebuild steuernummer and elstersteuernummer
1326 # es gibt eine gespeicherte steuernummer $form->{steuernummer}
1327 # und die parts und delimiter
1332 my $steuernummer_new = $part;
1333 my $elstersteuernummer_new = $::form->{elster_FFFF};
1334 $elstersteuernummer_new .= '0';
1336 for ($h = 1; $h < $patterncount; $h++) {
1337 $steuernummer_new .= qq|$delimiter|;
1338 for (my $i = 1; $i <= length($elster_pattern); $i++) {
1339 $steuernummer_new .= $::form->{"part_$h\_$i"};
1340 $elstersteuernummer_new .= $::form->{"part_$h\_$i"};
1343 if ($::form->{steuernummer} ne $steuernummer_new) {
1344 $::form->{steuernummer} = $steuernummer_new;
1345 $::form->{elstersteuernummer} = $elstersteuernummer_new;
1346 $::form->{steuernummer_new} = $steuernummer_new;
1348 $::form->{steuernummer_new} = '';
1349 $::form->{elstersteuernummer_new} = '';
1351 $::lxdebug->leave_sub();
1355 $::lxdebug->enter_sub();
1357 $::auth->assert('advance_turnover_tax_return');
1359 my $filename = "$::form->{login}_$::form->{filename}";
1360 $filename =~ s|.*/||;
1362 #zuerst die steuernummer aus den part, parts_X_Y und delimiter herstellen
1363 create_steuernummer();
1365 # Textboxen formatieren: Linebreaks entfernen
1367 $::form->{FA_Oeffnungszeiten} =~ s/\r\n/\\n/g;
1369 #URL mit http:// davor?
1370 $::form->{FA_Internet} =~ s/^http:\/\///;
1371 $::form->{FA_Internet} = 'http://' . $::form->{FA_Internet};
1374 elster elsterland elstersteuernummer steuernummer
1375 elsteramt elsterFFFF FA_Name FA_Strasse
1376 FA_PLZ FA_Ort FA_Telefon FA_Fax
1377 FA_PLZ_Grosskunden FA_PLZ_Postfach FA_Postfach FA_BLZ_1
1378 FA_Kontonummer_1 FA_Bankbezeichnung_1 FA_BLZ_2 FA_Kontonummer_2
1379 FA_Bankbezeichnung_oertlich FA_Oeffnungszeiten
1380 FA_Email FA_Internet FA_voranmeld method FA_steuerberater_name
1381 FA_steuerberater_street FA_steuerberater_city FA_steuerberater_tel
1382 FA_71 FA_dauerfrist);
1384 # Hier kommt dann die Plausibilitätsprüfung der ELSTERSteuernummer
1385 if ($::form->{elstersteuernummer} ne '000000000') {
1387 $::form->{elster} = '1';
1389 open my $ustvaconfig, ">", "$::lx_office_conf{paths}{userspath}/$filename" or $::form->error("$filename : $!");
1391 # create the config file
1392 print {$ustvaconfig} qq|# Configuration file for USTVA\n\n|;
1394 foreach $key (sort @config) {
1395 $::form->{$key} =~ s/\\/\\\\/g;
1397 $::form->{$key} =~ s/\r\n/\n/g;
1399 print {$ustvaconfig} qq|$key=|;
1400 if ($::form->{$key} ne 'Y') {
1401 print {$ustvaconfig} qq|$::form->{$key}\n|;
1403 if ($::form->{$key} eq 'Y') {
1404 print {$ustvaconfig} qq|checked \n|;
1407 print {$ustvaconfig} qq|\n\n|;
1409 $::form->{saved} = $::locale->text('saved');
1413 $::form->{saved} = $::locale->text('Choose a Tax Number');
1417 $::lxdebug->leave_sub();
1422 $::lxdebug->enter_sub();
1424 # allow Symbolic references just here:
1425 call_sub($::form->{"nextsub"});
1426 $::lxdebug->leave_sub();
1430 $::lxdebug->enter_sub();
1431 call_sub($::form->{"lastsub"});
1432 $::lxdebug->leave_sub();