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., 51 Franklin Street, Fifth Floor, Boston,
 
  23 #======================================================================
 
  24 # German Tax authority Module and later ELSTER Interface
 
  25 # 08.01.14  ELSTER Interface software (taxbird/winston) removed
 
  26 #======================================================================
 
  31 require "bin/mozilla/common.pl";
 
  36 #use warnings; # FATAL=> 'all';
 
  37 #use vars qw($locale $form %myconfig);
 
  39 #use CGI::Carp "fatalsToBrowser";
 
  41 use List::Util qw(first);
 
  49 # this is for our long dates
 
  50 # $locale->text('January')
 
  51 # $locale->text('February')
 
  52 # $locale->text('March')
 
  53 # $locale->text('April')
 
  54 # $locale->text('May ')
 
  55 # $locale->text('June')
 
  56 # $locale->text('July')
 
  57 # $locale->text('August')
 
  58 # $locale->text('September')
 
  59 # $locale->text('October')
 
  60 # $locale->text('November')
 
  61 # $locale->text('December')
 
  63 # this is for our short month
 
  64 # $locale->text('Jan')
 
  65 # $locale->text('Feb')
 
  66 # $locale->text('Mar')
 
  67 # $locale->text('Apr')
 
  68 # $locale->text('May')
 
  69 # $locale->text('Jun')
 
  70 # $locale->text('Jul')
 
  71 # $locale->text('Aug')
 
  72 # $locale->text('Sep')
 
  73 # $locale->text('Oct')
 
  74 # $locale->text('Nov')
 
  75 # $locale->text('Dec')
 
  77 #############################
 
  80   $::lxdebug->enter_sub();
 
  83   my $locale   = $::locale;
 
  84   my %myconfig = %::myconfig;
 
  86   $::auth->assert('advance_turnover_tax_return');
 
  88   my $defaults   = SL::DB::Default->get;
 
  89   $form->{title} = $locale->text('UStVA');
 
  90   $form->{kz10}  = '';                       #Berichtigte Anmeldung? Ja =1 Nein=0
 
  92   my $year = substr($form->datetonum($form->current_date(\%myconfig), \%myconfig ),
 
  99   # Einlesen der Finanzamtdaten
 
 100   my $ustva = USTVA->new();
 
 101   $ustva->get_config();
 
 102   $ustva->get_finanzamt();
 
 104   my $geierlein_enabled = 0;
 
 105   my $geierlein_path = $::lx_office_conf{paths}{geierlein_path};
 
 107   if ( $geierlein_path && length($geierlein_path) > 0 ) {$geierlein_enabled=1;}
 
 109 #  $::lxdebug->message(LXDebug->DEBUG2,"geierlein_enabled=".$geierlein_enabled." path=".$geierlein_path);
 
 110   # Hier Einlesen der user-config
 
 111   # steuernummer entfernt für prerelease
 
 114     tel            fax           email         co_chief       co_department
 
 115     co_custom1     co_custom2    co_custom3    co_custom4     co_custom5
 
 116     co_name1       co_name2      co_street     co_street1     co_zip
 
 117     co_city        co_city1      co_country    co_tel         co_tel1
 
 118     co_tel2        co_fax        co_fax1       co_email       co_email1
 
 119     co_url         co_url1       co_bankname
 
 120     co_bankname1   co_bankname2  co_bankname3  co_blz         co_blz1
 
 121     co_blz2        co_blz3       co_accountnr  co_accountnr1  co_accountnr2
 
 125   $form->{$_} = $myconfig{$_} for @a;
 
 127   my $openings = $form->{fa_oeffnungszeiten};
 
 128   $openings =~ s/\\\\n/<br>/g;
 
 130   my $company_given = ($form->{company} ne '')
 
 131     ? qq|<h3>$form->{company}</h3>\n|
 
 132     : qq|<a href="controller.pl?action=ClientConfig/edit">|
 
 133       . $locale->text('No Company Name given') . qq|!</a><br>|;
 
 136   # Anpassungen der Variablennamen auf pre 2.1.1 Namen
 
 137   # klären, ob $form->{company_street|_address} gesetzt sind
 
 138   if ($form->{address} ne '') {
 
 139     my $temp = $form->{address};
 
 140     $temp =~ s/\n/<br \/>/;
 
 141     ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
 
 142     $form->{co_city} =~ s/\n//g;
 
 147     ($form->{co_street} && ($form->{co_zip} || $form->{co_city}))
 
 148     ? qq|$form->{co_street}<br>|
 
 149         . qq|$form->{co_street1}<br>|
 
 150         . qq|$form->{co_zip} $form->{co_city}|
 
 151     : qq|<a href="controller.pl?action=ClientConfig/edit">|
 
 152         . $locale->text('No Company Address given')
 
 155   $form->{co_email} = $form->{email} unless $form->{co_email};
 
 156   $form->{co_tel}   = $form->{tel}   unless $form->{co_tel};
 
 157   $form->{co_fax}   = $form->{fax}   unless $form->{co_fax};
 
 158   $form->{co_url}   = $form->{urlx}  unless $form->{co_url};
 
 160   my $taxnumber_given = ($form->{taxnumber} ne '') ? $form->{taxnumber} : qq|<a href="ustva.pl?action=config_step1">Keine Steuernummer hinterlegt!</a><br>|;
 
 161   my $fa_name_given = ($form->{fa_name} ne '') ? $form->{fa_name} : qq|<a href="ustva.pl?action=config_step1">Kein Finanzamt hinterlegt!</a><br>|;
 
 162   my $ustva_vorauswahl = &ustva_vorauswahl();
 
 164   my @all_years = $form->all_years(\%myconfig);
 
 166   my $select_year = qq|<select name=year title="|
 
 167     . $locale->text('Year') . qq|">|;
 
 168   foreach my $key (@all_years) {
 
 169     $select_year .= qq|<option |;
 
 170     $select_year .= qq|selected| if ($key eq $form->{year});
 
 171     $select_year .= qq| >$key</option>|;
 
 173   $select_year   .=  qq|</select>|;
 
 176   $_checked = "checked" if ($form->{kz10} eq '1');
 
 177   my $checkbox_kz_10 = qq|<input name="FA_10" id=FA_10 class=checkbox|
 
 178     . qq| type=checkbox value="1" $_checked title = "|
 
 179     . $locale->text('Amended Advance Turnover Tax Return').'(Nr. 10)'
 
 181     . $locale->text('Amended Advance Turnover Tax Return');
 
 183   $_checked = "checked" if ($form->{kz22} eq '1');
 
 184   my $checkbox_kz_22 = qq|<input name="FA_22" id=FA_22 class=checkbox|
 
 185     . qq| type=checkbox value="1" $_checked title = "|
 
 186     . $locale->text('Receipts attached/extra').'(Nr. 22)'
 
 188     . $locale->text('Receipts attached/extra');
 
 190   $_checked = "checked" if ($form->{kz29} eq '1');
 
 191   my $checkbox_kz_29 = qq|<input name="FA_29" id=FA_29 class=checkbox|
 
 192     . qq| type=checkbox value="1" $_checked title = "|
 
 193     . $locale->text('Accounting desired').'(Nr. 29)'
 
 195     . $locale->text('Accounting desired');
 
 197   $_checked = "checked" if ($form->{kz26} eq '1');
 
 198   my $checkbox_kz_26 = qq|<input name="FA_26" id=FA_26 class=checkbox|
 
 199     . qq| type=checkbox value="1" $_checked title = "|
 
 200     . $locale->text('Direct debit revoked').'(Nr. 26)'
 
 202     . $locale->text('Direct debit revoked');
 
 204   my $method_local = ($form->{accounting_method} eq 'accrual') ? $locale->text('accrual')
 
 205                    : ($form->{accounting_method} eq 'cash')    ? $locale->text('cash')
 
 208   my $period_local = ( $form->{fa_voranmeld} eq 'month')   ? $locale->text('month')
 
 209                    : ( $form->{fa_voranmeld} eq 'quarter') ? $locale->text('quarter')
 
 212   my @tax_office_banks_ref = (
 
 213     { BLZ             => $form->{fa_blz_1},
 
 214       Kontonummer     => $form->{fa_kontonummer_1},
 
 215       Bankbezeichnung => $form->{fa_bankbezeichnung_1}
 
 217     { BLZ             => $form->{fa_blz_2},
 
 218       Kontonummer     => $form->{fa_kontonummer_2},
 
 219       Bankbezeichnung => $form->{fa_bankbezeichnung_2}
 
 223   $ustva->get_coa($form); # fetches coa and modifies some form variables
 
 226     openings         => $openings,
 
 227     company_given    => $company_given,
 
 228     address_given    => $address_given,
 
 229     taxnumber_given  => $taxnumber_given,
 
 230     fa_name_given    => $fa_name_given,
 
 231     taxnumber        => $defaults->taxnumber,
 
 232     select_year      => $select_year,
 
 233     period_local     => $period_local,
 
 234     method_local     => $method_local,
 
 235     ustva_vorauswahl => $ustva_vorauswahl,
 
 236     checkbox_kz_10   => $checkbox_kz_10,
 
 237     checkbox_kz_22   => $checkbox_kz_22,
 
 238     checkbox_kz_29   => $checkbox_kz_29,
 
 239     checkbox_kz_26   => $checkbox_kz_26,
 
 240     tax_office_banks => \@tax_office_banks_ref,
 
 241     geierlein_enabled => $geierlein_enabled,
 
 242     geierlein_path   => $geierlein_path,
 
 243     select_options   => &show_options,
 
 247   print($form->parse_html_template('ustva/report', $template_ref));
 
 251   $::lxdebug->leave_sub();
 
 257   $::lxdebug->enter_sub();
 
 259   $::auth->assert('advance_turnover_tax_return');
 
 261   # parse help documents under doc
 
 262   $::form->{templates} = 'doc';
 
 263   $::form->{help}      = 'ustva';
 
 264   $::form->{type}      = 'help';
 
 265   $::form->{format}    = 'html';
 
 268   $::lxdebug->leave_sub();
 
 272   $::lxdebug->enter_sub();
 
 274   $::auth->assert('advance_turnover_tax_return');
 
 277   $::lxdebug->leave_sub();
 
 278   call_sub($::form->{"nextsub"});
 
 281 sub ustva_vorauswahl {
 
 282   $::lxdebug->enter_sub();
 
 285   my $locale   = $::locale;
 
 286   my %myconfig = %::myconfig;
 
 288   $::auth->assert('advance_turnover_tax_return');
 
 290   my $select_vorauswahl;
 
 292   #Aktuelles Datum zerlegen:
 
 293   my $date = $form->datetonum($form->current_date(\%myconfig), \%myconfig);
 
 295   #$locale->date($myconfig, $form->current_date($myconfig), 0)=~ /(\d\d).(\d\d).(\d\d\d\d)/;
 
 296   $form->{day}   = substr($date, 6, 2);
 
 297   $form->{month} = substr($date, 4, 2);
 
 298   $form->{year}  = substr($date, 0, 4);
 
 299   $::lxdebug->message(LXDebug->DEBUG1, qq|
 
 300     Actual date from Database: $date\n
 
 301     Actual year from Database: $form->{year}\n
 
 302     Actual day from Database: $form->{day}\n
 
 303     Actual month from Database: $form->{month}\n|);
 
 308   # Testdaten erzeugen:
 
 310   #$form->{month}= '01';
 
 311   #$form->{year}= 2004;
 
 312   $select_vorauswahl = qq|
 
 313      <input type="hidden" name="day" value="$form->{day}">
 
 314      <input type="hidden" name="month" value="$form->{month}">
 
 315      <input type="hidden" name="yymmdd" value="$yymmdd">
 
 316      <input type="hidden" name="sel" value="$sel">
 
 319   if ($form->{fa_voranmeld} eq 'month') {
 
 321     # Vorauswahl bei monatlichem Voranmeldungszeitraum
 
 323     my %liste = ('01' => $locale->text('January'),
 
 324                  '02' => $locale->text('February'),
 
 325                  '03' => $locale->text('March'),
 
 326                  '04' => $locale->text('April'),
 
 327                  '05' => $locale->text('May'),
 
 328                  '06' => $locale->text('June'),
 
 329                  '07' => $locale->text('July'),
 
 330                  '08' => $locale->text('August'),
 
 331                  '09' => $locale->text('September'),
 
 332                  '10' => $locale->text('October'),
 
 333                  '11' => $locale->text('November'),
 
 334                  '12' => $locale->text('December'),
 
 335                  '13' => $locale->text('Yearly'),
 
 338     my $yy = $form->{year} * 10000;
 
 339     $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
 
 343     # Offset für Dauerfristverlängerung
 
 344     $dfv = '100' if ($form->{fa_dauerfrist} eq '1');
 
 347       $yymmdd <= ($yy + 110 + $dfv) && do {
 
 348         $form->{year} = $form->{year} - 1;
 
 352       $yymmdd <= ($yy + 210 + $dfv) && do {
 
 356       $yymmdd <= ($yy + 310 + $dfv) && do {
 
 360       $yymmdd <= ($yy + 410 + $dfv) && do {
 
 364       $yymmdd <= ($yy + 510 + $dfv) && do {
 
 368       $yymmdd <= ($yy + 610 + $dfv) && do {
 
 372       $yymmdd <= ($yy + 710 + $dfv) && do {
 
 376       $yymmdd <= ($yy + 810 + $dfv) && do {
 
 380       $yymmdd <= ($yy + 910 + $dfv) && do {
 
 384       $yymmdd <= ($yy + 1010 + $dfv) && do {
 
 388       $yymmdd <= ($yy + 1110 + $dfv) && do {
 
 392       $yymmdd <= ($yy + 1210) && do {
 
 396       $yymmdd <= ($yy + 1231) && do {
 
 402     $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
 
 403   . $locale->text('Select a period') . qq|" >|;
 
 406     foreach $key (sort keys %liste) {
 
 408       $selected = 'selected' if ($sel eq $key);
 
 409       $select_vorauswahl .= qq|
 
 410          <option value="$key" $selected> $liste{$key}</option>
 
 413     $select_vorauswahl .= qq|</select>|;
 
 415   } elsif ($form->{fa_voranmeld} eq 'quarter') {
 
 417     # Vorauswahl bei quartalsweisem Voranmeldungszeitraum
 
 418     my %liste = ('41'  => $locale->text('1. Quarter'),
 
 419                  '42'  => $locale->text('2. Quarter'),
 
 420                  '43'  => $locale->text('3. Quarter'),
 
 421                  '44'  => $locale->text('4. Quarter'),
 
 422                  '13' => $locale->text('Yearly'),);
 
 424     my $yy = $form->{year} * 10000;
 
 425     $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
 
 427     my $dfv = '';    # Offset für Dauerfristverlängerung
 
 428     $dfv = '100' if ($form->{fa_dauerfrist} eq '1');
 
 431       $yymmdd <= ($yy + 110 + $dfv) && do {
 
 432         $form->{year} = $form->{year} - 1;
 
 436       $yymmdd <= ($yy + 410 + $dfv) && do {
 
 440       $yymmdd <= ($yy + 710 + $dfv) && do {
 
 444       $yymmdd <= ($yy + 1010 + $dfv) && do {
 
 448       $yymmdd <= ($yy + 1231) && do {
 
 453     $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
 
 454       . $locale->text('Select a period') . qq|" >|;
 
 456     foreach $key (sort keys %liste) {
 
 458       $selected = 'selected' if ($sel eq $key);
 
 459       $select_vorauswahl .= qq|
 
 460          <option value="$key" $selected>$liste{$key}</option>
 
 463     $select_vorauswahl .= qq|\n</select>
 
 468     # keine Vorauswahl bei Voranmeldungszeitraum
 
 469     $select_vorauswahl .= qq|<select id="zeitraum" name="period" title="|
 
 470       . $locale->text('Select a period') . qq|" >|;
 
 472     my %listea = ('41' => '1. Quarter',
 
 473                   '42' => '2. Quarter',
 
 474                   '43' => '3. Quarter',
 
 475                   '44' => '4. Quarter',);
 
 477     my %listeb = ('01' => 'January',
 
 491     foreach $key (sort keys %listea) {
 
 492       $select_vorauswahl .= qq|
 
 493          <option value="$key">|
 
 494         . $locale->text("$listea{$key}")
 
 498     foreach $key (sort keys %listeb) {
 
 499       $select_vorauswahl .= qq|
 
 500          <option value="$key">|
 
 501         . $locale->text("$listeb{$key}")
 
 504     $select_vorauswahl .= qq|</select>|;
 
 506   $::lxdebug->leave_sub();
 
 508   return $select_vorauswahl;
 
 512 #  $::lxdebug->enter_sub();
 
 514 #  $::lxdebug->leave_sub();
 
 518   $::lxdebug->enter_sub();
 
 520   $::lxdebug->leave_sub();
 
 524   $::lxdebug->enter_sub();
 
 526   $::auth->assert('advance_turnover_tax_return');
 
 528   #  $form->{PD}{$form->{type}} = "selected";
 
 529   #  $form->{DF}{$form->{format}} = "selected";
 
 530   #  $form->{OP}{$form->{media}} = "selected";
 
 531   #  $form->{SM}{$form->{sendmode}} = "selected";
 
 532   my $type   = qq|      <input type=hidden name="type" value="ustva">|;
 
 533   my $media  = qq|      <input type=hidden name="media" value="screen">|;
 
 535       qq|       <option value=html selected>|
 
 536     . $::locale->text('HTML')
 
 539   #my $disabled= qq|disabled="disabled"|;
 
 540   #$disabled='' if ($form->{elster} eq '1' );
 
 541   #if ($::form->{elster} eq '1') {
 
 544         qq|<option value=elstertaxbird>|
 
 545       . $::locale->text('ELSTER Export (via Geierlein)')
 
 549   my $show_options = qq|
 
 552     <select name=format title = "|
 
 553     . $::locale->text('Choose Outputformat') . qq|">$format</select>
 
 555   $::lxdebug->leave_sub();
 
 557   return $show_options;
 
 561   $::lxdebug->enter_sub();
 
 564   my $locale   = $::locale;
 
 565   my %myconfig = %::myconfig;
 
 567   $::auth->assert('advance_turnover_tax_return');
 
 569   my $defaults = SL::DB::Default->get;
 
 570   $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
 
 571   $form->{templates} = $defaults->templates;
 
 574   my $ustva = USTVA->new();
 
 575   $ustva->get_config();
 
 576   $ustva->get_finanzamt();
 
 578   # Setze Anmeldungszeitraum
 
 580   $ustva->set_FromTo(\%$form);
 
 583   $ustva->ustva(\%myconfig, \%$form);
 
 585   # reformat Dates to dateformat
 
 586   $form->{fromdate} = $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);
 
 588   $form->{todate} = $form->current_date(\%myconfig) unless $form->{todate};
 
 589   $form->{todate} = $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
 
 591   $form->{longperiod} =
 
 592     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1, 0, 0);
 
 594   # if there are any dates construct a where
 
 595   if ($form->{fromdate} || $form->{todate}) {
 
 597     $form->{todate} = $form->current_date(\%myconfig)  unless ($form->{todate});
 
 599     my $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1, 0, 0);
 
 600     my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
 
 602     my $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1, 0, 0);
 
 603     my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);
 
 605     $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
 
 606     $form->{longperiod}      =
 
 607         $locale->text('for Period')
 
 608       . qq|<br>\n$longfromdate |
 
 609       . $locale->text('to (date)')
 
 613   if ($form->{comparefromdate} || $form->{comparetodate}) {
 
 614     my $longcomparefromdate =
 
 615       $locale->date(\%myconfig, $form->{comparefromdate}, 1, 0, 0);
 
 616     my $shortcomparefromdate =
 
 617       $locale->date(\%myconfig, $form->{comparefromdate}, 0, 0, 0);
 
 619     my $longcomparetodate =
 
 620       $locale->date(\%myconfig, $form->{comparetodate}, 1, 0, 0);
 
 621     my $shortcomparetodate =
 
 622       $locale->date(\%myconfig, $form->{comparetodate}, 0, 0, 0);
 
 624     $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
 
 625     $form->{longperiod} .=
 
 626         "<br>\n$longcomparefromdate "
 
 627       . $locale->text('to (date)')
 
 628       . qq| $longcomparetodate|;
 
 631   $form->{Datum_heute} =
 
 632     $locale->date(\%myconfig, $form->current_date(\%myconfig), 0, 0, 0);
 
 634   # setup variables for the form
 
 635   my @a = qw(tel fax email
 
 636     co_chief co_department co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
 
 637     co_name1 co_name2  co_street co_street1 co_zip co_city co_city1 co_country co_tel co_tel1 co_tel2
 
 638     co_fax co_fax1 co_email co_email1 co_url co_url1
 
 639     co_bankname co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
 
 640     co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2 co_accountnr3);
 
 642   $form->{$_} = $myconfig{$_} for @a;
 
 643   $form->{$_} = $defaults->$_ for qw(company address co_ustid duns);
 
 645   if ($form->{address} ne '') {
 
 646     my $temp = $form->{address};
 
 647     $temp =~ s/\n/<br \/>/;
 
 648     ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp,2);
 
 649     $form->{co_city} =~ s/\\n//g;
 
 652   ################################
 
 654   # Nation specific customisations
 
 656   ################################
 
 660   if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') {
 
 663    $form->{amount} = [];
 
 665    if ( $form->{format} eq 'pdf' or $form->{format} eq 'postscript') {
 
 667       $form->{IN} = "$form->{type}-$form->{year}.tex";
 
 668       $form->{padding} = "~~";
 
 669       $form->{bold}    = "\textbf{";
 
 670       $form->{endbold} = "}";
 
 671       $form->{br}      = '\\\\';
 
 673       # Zahlenformatierung für Latex USTVA Formulare
 
 675       foreach my $number (@{$::form->{category_euro}}) {
 
 676         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '');
 
 679       my ${decimal_comma} = ( $myconfig{numberformat} eq '1.000,00'
 
 680            or $myconfig{numberformat} eq '1000,00' ) ? ',':'.';
 
 682       foreach my $number (@{$::form->{category_cent}}) {
 
 683         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '');
 
 684         $form->{$number} =~ s/${decimal_comma}/~~/g;
 
 687     } elsif ( $form->{format} eq 'html') { # Formatierungen für HTML Ausgabe
 
 689       $form->{IN} = $form->{type} . '.html';
 
 690       $form->{padding} = "  ";
 
 691       $form->{bold}    = "<b>";
 
 692       $form->{endbold} = "</b>";
 
 693       $form->{br}      = "<br>";
 
 694       $form->{address} =~ s/\\n/\n/g;
 
 696       foreach my $number (@{$::form->{category_cent}}) {
 
 697         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '0');
 
 700       foreach my $number (@{$::form->{category_euro}}) {
 
 701         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '0');
 
 703     } elsif ( $form->{format} eq '' ){ # No format error.
 
 706       USTVA::error( $locale->text('Application Error. No Format given' ) . "!");
 
 707       $::dispatcher->end_request;
 
 709     } else { # All other Formats are wrong
 
 711       USTVA::error( $locale->text('Application Error. Wrong Format') . ": " . $form->{format} );
 
 712       $::dispatcher->end_request;
 
 716   } else  # Outputformat for generic output
 
 721     if ( $form->{format} eq 'generic') { # Formatierungen für HTML Ausgabe
 
 724       for my $kennziffer (@{$::form->{category_cent}}, @{$::form->{category_euro}}) {
 
 726         $rec_ref->{id} = $kennziffer;
 
 727         $rec_ref->{amount} = $form->format_amount(\%myconfig, $form->{$kennziffer}, 2, '0');
 
 729         $::lxdebug->message($LXDebug::DEBUG, "Kennziffer $kennziffer: '$form->{$kennziffer}'" );
 
 730         $::lxdebug->dump($LXDebug::DEBUG, $rec_ref );
 
 731         push @ { $form->{USTVA} }, $rec_ref;
 
 738   if ( $form->{period} eq '13' and $form->{format} ne 'html') {
 
 742       'Yearly taxreport not yet implemented')
 
 746   $form->{templates} = "doc" if ( $form->{type} eq 'help' );
 
 748   if ($form->{format} eq 'generic'){
 
 753         taxnumber => $defaults->taxnumber,
 
 756     print($form->parse_html_template('ustva/generic_taxreport', $template_ref));
 
 758   } elsif ( $form->{format} eq 'elstertaxbird' ) {
 
 759    $form->parse_template(\%myconfig);
 
 762    # add a prefix for ustva pos numbers, i.e.: 81 ->  post_ustva_81
 
 763    $form->{"pos_ustva_$_"} = $form->{$_} for grep { m{^\d+} } keys %{ $form };
 
 764    $form->{title} = $locale->text('Advance turnover tax return');
 
 767    print $form->parse_html_template('ustva/ustva');
 
 772   $::lxdebug->leave_sub();
 
 776   $::lxdebug->enter_sub();
 
 778   $::auth->assert('advance_turnover_tax_return');
 
 780 $::form->{title} = $::locale->text('Tax Office Preferences');
 
 782   # edit all taxauthority prefs
 
 786   my $ustva = USTVA->new();
 
 787   $ustva->get_config();
 
 788   $ustva->get_finanzamt();
 
 790   my $land = $::form->{fa_land_nr};
 
 791   my $amt  = $::form->{fa_bufa_nr};
 
 794   $::form->{title} = $::locale->text('Tax Office Preferences');
 
 797   my $select_tax_office               = $ustva->fa_auswahl($land, $amt, $ustva->query_finanzamt(\%::myconfig, $::form));
 
 798   my $method_local = ($::form->{accounting_method} eq 'accrual') ? $::locale->text('accrual')
 
 799                    : ($::form->{accounting_method} eq 'cash')    ? $::locale->text('cash')
 
 802   my $checked_monthly                 = $::form->{fa_voranmeld}  eq 'month'   ? "checked"            : '';
 
 803   my $checked_quarterly               = $::form->{fa_voranmeld}  eq 'quarter' ? "checked"            : '';
 
 804   my $checked_dauerfristverlaengerung = $::form->{da_dauerfrist} eq '1'       ? "checked"            : '';
 
 806   my $_hidden_variables_ref;
 
 808   my %_hidden_local_variables = (
 
 809     'saved'       => $::locale->text('Check Details'),
 
 810     'nextsub'     => 'config_step2',
 
 814   foreach my $variable (keys %_hidden_local_variables) {
 
 815     push @{ $_hidden_variables_ref },
 
 816         { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
 
 819   my @_hidden_form_variables = $ustva->get_fiamt_vars();
 
 820   push @_hidden_form_variables ,qw(fa_bufa_nr taxnumber accounting_method coa);
 
 822   foreach my $variable (@_hidden_form_variables) {
 
 823     push @{ $_hidden_variables_ref},
 
 824         { 'variable' => $variable, 'value' => $::form->{$variable} };
 
 827   $ustva->get_coa($::form); # fetches coa and modifies some form variables
 
 829   # Variablen für das Template zur Verfügung stellen
 
 831      select_tax_office               => $select_tax_office,
 
 832      method_local                    => $method_local,
 
 833      checked_monthly                 => $checked_monthly,
 
 834      checked_quarterly               => $checked_quarterly,
 
 835      checked_dauerfristverlaengerung => $checked_dauerfristverlaengerung,
 
 836      hidden_variables                => $_hidden_variables_ref,
 
 840   # Ausgabe des Templates
 
 841   print($::form->parse_html_template('ustva/config_step1', $template_ref));
 
 843   $::lxdebug->leave_sub();
 
 847   $::lxdebug->enter_sub();
 
 850   my $locale   = $::locale;
 
 851   my %myconfig = %::myconfig;
 
 853   $::auth->assert('advance_turnover_tax_return');
 
 860   my $ustva = USTVA->new();
 
 861   $ustva->get_config() if ($form->{saved} eq $locale->text('saved'));
 
 862   my $coa = $::form->{coa};
 
 863   $form->{"COA_$coa"}  = '1';
 
 864   $form->{COA_Germany} = '1' if ($coa =~ m/^germany/i);
 
 865   $ustva->get_finanzamt();
 
 868   # Auf Übergabefehler checken
 
 869   USTVA::info(  $locale->text('Missing Tax Authoritys Preferences') . "\n"
 
 870               . $locale->text('USTVA-Hint: Tax Authoritys'))
 
 871     if (   $form->{fa_bufa_nr_new} eq 'Auswahl'
 
 872         || $form->{fa_land_nr_new} eq 'Auswahl');
 
 873   USTVA::info(  $locale->text('Missing Method!') . "\n"
 
 874               . $locale->text('USTVA-Hint: Method'))
 
 875     if ($form->{accounting_method} eq '');
 
 877   # Klären, ob Variablen bereits befüllt sind UND ob veränderungen auf
 
 878   # der vorherigen Maske stattfanden: $change = 1(in der edit sub,
 
 879   # mittels get_config)
 
 881 #  $::lxdebug->message(LXDebug->DEBUG2,"land old=".$form->{fa_land_nr}." new=".$form->{fa_land_nr_new});
 
 882 #  $::lxdebug->message(LXDebug->DEBUG2,"bufa old=".$form->{fa_bufa_nr}." new=".$form->{fa_bufa_nr_new});
 
 883   my $change = $form->{fa_land_nr} eq $form->{fa_land_nr_new}
 
 884     && $form->{fa_bufa_nr} eq $form->{fa_bufa_nr_new} ? '0' : '1';
 
 885   $change = '0' if ($form->{saved} eq $locale->text('saved'));
 
 888   if ($change eq '1') {
 
 891     $fa_land_nr           = $form->{fa_land_nr_new};
 
 892     $fa_bufa_nr           = $form->{fa_bufa_nr_new};
 
 893     $form->{fa_land_nr}   = $fa_land_nr;
 
 894     $form->{fa_bufa_nr}   = $fa_bufa_nr;
 
 895     $form->{taxnumber} = '';
 
 897     create_steuernummer();
 
 900     $ustva->get_finanzamt();
 
 904     $fa_land_nr = $form->{fa_land_nr};
 
 905     $fa_bufa_nr = $form->{fa_bufa_nr};
 
 908 #  $::lxdebug->message(LXDebug->DEBUG2, "form stnr=".$form->{taxnumber}." fa_bufa_nr=".$fa_bufa_nr.
 
 909 #                      " pattern=".$form->{elster_pattern}." fa_land_nr=".$fa_land_nr);
 
 910   my $stnr = $form->{taxnumber};
 
 912   my $taxnumber      = $stnr eq '' ? $form->{taxnumber} : '';
 
 914   $form->{fa_oeffnungszeiten} =~ s/\\\\n/\n/g;
 
 917   $ustva->get_coa($form); # fetches coa and modifies some form variables
 
 919   my $input_steuernummer = $ustva->steuernummer_input(
 
 925 #  $::lxdebug->message(LXDebug->DEBUG2, qq|$input_steuernummer|);
 
 928   my $_hidden_variables_ref;
 
 930   my %_hidden_local_variables = (
 
 931       'fa_land_nr'          => $fa_land_nr,
 
 932       'fa_bufa_nr'          => $fa_bufa_nr,
 
 934       'taxnumber'           => $stnr,
 
 935       'lastsub'             => 'config_step1',
 
 940   foreach my $variable (keys %_hidden_local_variables) {
 
 941     push @{ $_hidden_variables_ref },
 
 942         { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
 
 945   my @_hidden_form_variables = qw(
 
 946     fa_dauerfrist fa_steuerberater_city fa_steuerberater_name
 
 947     fa_steuerberater_street fa_steuerberater_tel
 
 948     fa_voranmeld fa_dauerfrist
 
 954   foreach my $variable (@_hidden_form_variables) {
 
 955     push @{ $_hidden_variables_ref},
 
 956         { 'variable' => $variable, 'value' => $form->{$variable} };
 
 960      input_steuernummer              => $input_steuernummer,
 
 961      readonly                        => '', #q|disabled="disabled"|,
 
 962      callback                        => $form->{callback},
 
 963      COA_Germany                     => $form->{COA_Germany},
 
 964      hidden_variables                => $_hidden_variables_ref,
 
 967   # Ausgabe des Templates
 
 968   print($form->parse_html_template('ustva/config_step2', $template_ref));
 
 971   $::lxdebug->leave_sub();
 
 974 sub create_steuernummer {
 
 975   $::lxdebug->enter_sub();
 
 977   $::auth->assert('advance_turnover_tax_return');
 
 979   my $part           = $::form->{part};
 
 980   my $patterncount   = $::form->{patterncount};
 
 981   my $delimiter      = $::form->{delimiter1};
 
 982   my $elster_pattern = $::form->{elster_pattern};
 
 985   # es gibt eine gespeicherte steuernummer $form->{taxnumber}
 
 986   # und die parts und delimiter
 
 991   my $taxnumber_new       = $part;
 
 993   for ($h = 1; $h < $patterncount; $h++) {
 
 994     $delimiter = $::form->{delimiter2} if $h > 1;
 
 995     $taxnumber_new .= qq|$delimiter|;
 
 996     for (my $i = 1; $i <= length($elster_pattern); $i++) {
 
 997       $taxnumber_new       .= $::form->{"part_$h\_$i"};
 
1000 #  $::lxdebug->message(LXDebug->DEBUG2, "oldstnr=".$::form->{taxnumber}." newstnr=".$taxnumber_new);
 
1001   if ($::form->{taxnumber} ne $taxnumber_new) {
 
1002     $::form->{taxnumber}       = $taxnumber_new;
 
1003     $::form->{taxnumber_new}   = $taxnumber_new;
 
1005     $::form->{taxnumber_new}       = '';
 
1007   $::lxdebug->leave_sub();
 
1011   $::lxdebug->enter_sub();
 
1013   $::auth->assert('advance_turnover_tax_return');
 
1015   #zuerst die steuernummer aus den part, parts_X_Y und delimiter herstellen
 
1016   create_steuernummer();
 
1018   # Textboxen formatieren: Linebreaks entfernen
 
1020   $::form->{fa_oeffnungszeiten} =~ s/\r\n/\\n/g;
 
1022   #URL mit http:// davor?
 
1023   $::form->{fa_internet} =~ s/^http:\/\///;
 
1024   $::form->{fa_internet} = 'http://' . $::form->{fa_internet};
 
1026   # Hier kommt dann die Plausibilitätsprüfung der ELSTERSteuernummer TODO ??
 
1028     my $ustva = USTVA->new();
 
1029     $ustva->save_config();
 
1031     #$::form->{elster} = '1';
 
1032     $::form->{saved} = $::locale->text('saved');
 
1036     $::form->{saved} = $::locale->text('Choose a Tax Number');
 
1040   $::lxdebug->leave_sub();
 
1045   $::lxdebug->enter_sub();
 
1047   # allow Symbolic references just here:
 
1048   call_sub($::form->{"nextsub"});
 
1049   $::lxdebug->leave_sub();
 
1053   $::lxdebug->enter_sub();
 
1054   call_sub($::form->{"lastsub"});
 
1055   $::lxdebug->leave_sub();