commit a68089fb83a276f3ce78e5bd145c1cf05cc9a762
Author: Martin Helmling <martin.helmling@octosoft.eu>
Date:   Mon Jan 5 18:14:10 2015 +0100

    Geierlein: alter Elsterexport überarbeitet
    
    Generierung der Params in ODGeierlein
    
    Neuer Controller für AJAX Request
    Verallgemeinern (Teile aus ustva.pl nach SL/USTVA.pm
    
    elster_format angepasst
    
    Die Formate der Steuernummern für Baden-Württemberg und Rheinland-Pfalz
    sind in Geierlein anders als früher in taxbird
    
    Geierlein auf gleichem Webserver
    
    Da LocalStorage nur innerhalb einer Domaine funktioniert,
    Wurde nun innerhalb Kivitendo der crome/content Baum von Geierlein installiert.
    
    Also
    cd geierlein/chrome/content
    mkdir {kivitendoDocumentRoot}/geierlein
    tar cf - * | tar xf - -C {kivitendoDocumentRoot}/geierlein
    
    Natürlich gibt es auch Möglichkeiten, dies per alias-Config im apache2 zu machen
    
    Konfigurerierbar in kivitendo.conf
    
    Falls geierlein_path gestetzt ist das Feature enabled
    Pfadnahme zeigt zu geierleinverzeichnis innerhalb des kivitendo Verzeichnisses
    
    UStVa Einstellungen in Datenbank
    
    Kein finanzamt.ini mehr sondern fa_bufa_nr in Defaults,
    über diese BundesFinanzamtnummer greift man auf Finanzamt Rose-Objekt zu.
    Das ist nun auch modifizierbar.
    Nutzung von Rose,
    Sonderfälle in stnr pattern (BaWü)
    
    Falls keine Daten in Defaults wird ein ggf. vorhandenes finanzamt.ini gelesen
    und die Daten von dort übernommen
    
    Die Steuernummer wird nun nicht mehr in der Mandantenkonfig
    sondern in den UStVa Einstellungen editiert
    
    Bisher Keine Umstellung auf IBAN, BIC (ist dies notwendig?)
    
    Übergabe ohne kz83
    Geierlein berechnet das Ergebnis selbst,
    es werden nun nur Eingangsbeträge übergeben
    
    UTF-8 Umwandlung finanzamt.ini Texte
    
    Links zu Mandantenkonfig eingearbeitet
    
    Implementiert RedMine Feature #168

diff --git a/SL/Controller/ODGeierlein.pm b/SL/Controller/ODGeierlein.pm
new file mode 100644
index 000000000..749941d6b
--- /dev/null
+++ b/SL/Controller/ODGeierlein.pm
@@ -0,0 +1,129 @@
+package SL::Controller::ODGeierlein;
+
+use strict;
+use utf8;
+use List::Util qw(first);
+
+use parent qw(SL::Controller::Base);
+
+use SL::USTVA;
+
+use Rose::Object::MakeMethods::Generic;
+
+#
+# actions
+#
+
+sub action_send {
+  $::lxdebug->enter_sub();
+  my ($self) = @_;
+  my $err = '';
+
+  # Aufruf von get_config zum Einlesen der Daten aus Finanzamt und Defaults
+
+  my $ustva = USTVA->new();
+  $ustva->get_config();
+  $ustva->get_finanzamt();
+  $ustva->set_FromTo(\%$::form);
+  $::lxdebug->message($LXDebug::DEBUG2,"fromdate=".$::form->{fromdate}." todate=".$::form->{todate}." meth=".$::form->{method});
+
+  my $tax_office     = first { $_->{id} eq $::form->{fa_land_nr} } @{ $ustva->{tax_office_information} };
+
+  if ( !$::form->{co_zip} ) {
+    $::form->{co_zip} = $::form->{co_city};
+    $::form->{co_zip} =~ s/\D//g;
+    $::form->{co_city} =~ s/\d//g;
+    $::form->{co_city} =~ s/^\s//g;
+  }
+  $::form->{period}=~ s/^0//;
+
+  # Aufbau der Geierlein Parameter
+  my $params=
+    "name = "  .$::form->{company}."\nstrasse = ".$::form->{co_street}.
+    "\nplz = "    .$::form->{co_zip}."\nort = "  .$::form->{co_city}.
+    "\ntelefon = ".$::form->{co_tel}."\nemail = ".$::form->{co_email}.
+    "\nland = ".$tax_office->{taxbird_nr}."\nsteuernummer = ".$::form->{taxnumber}."\njahr = ".$::form->{year}.
+    "\nzeitraum = ".$::form->{period}."\n";
+
+  $::lxdebug->message($LXDebug::DEBUG2,"param1=".$params );
+
+  # USTVA Daten erzeugen
+  # benötigt $form->{fromdate}, $form->{todate} $form->{method}
+  $ustva->ustva(\%::myconfig, \%$::form);
+
+  my @category_cent = $ustva->report_variables({
+    myconfig    => \%::myconfig,
+    form        => $::form,
+    type        => '',
+    attribute   => 'position',
+    dec_places  => '2',
+  });
+
+  #push @category_cent, qw(Z43  Z45  Z53  Z54  Z62  Z65  Z67);
+
+  my @category_euro = $ustva->report_variables({
+    myconfig    => \%::myconfig,
+    form        => $::form,
+    type        => '',
+    attribute   => 'position',
+    dec_places  => '0',
+  });
+
+  # Numberformatting for Geierlein
+  my $temp_numberformat = $::myconfig{numberformat};
+  # Numberformat must be '1000,00' ?!
+  $::myconfig{numberformat} = '1000,00';
+  foreach my $number (@{ $::form->{category_cent} }) {
+    $::form->{$number} = ($::form->{$number} !=0) ? $::form->format_amount(\%::myconfig, $::form->{$number},'2',''):'';
+  }
+
+  foreach my $number (@{ $::form->{category_euro} }) {
+    $::form->{$number} = ($::form->{$number} !=0) ? $::form->format_amount(\%::myconfig, $::form->{$number},'0',''):'';
+  }
+  # Re-set Numberformat
+  $::myconfig{numberformat} = $temp_numberformat;
+
+  # Berichtigte Anmeldung
+  $params .= "kz10 = 1\n" if $::form->{FA_10};
+
+  # Belege (Verträge, Rechnungen, Erläuterungen usw.) werden gesondert eingereicht
+  $params .= "kz22 = 1\n" if $::form->{FA_22};
+
+  # Verrechnung des Erstattungsbetrags erwünscht / Erstattungsbetrag ist abgetreten
+  $params .= "kz29 = 1\n" if $::form->{FA_29};
+
+  # Die Einzugsermächtigung wird ausnahmsweise (z.B. wegen Verrechnungswünschen) für diesen Voranmeldungszeitraum widerrufen.
+  #  Ein ggf. verbleibender Restbetrag ist gesondert zu entrichten.
+  $params .= "kz26 = 1\n" if $::form->{FA_26};
+
+  my @unused_ids = qw(511 861 971 931 Z43 811 891 Z43 Z45 Z53 Z54 Z62 Z65 Z67 83);
+
+  for my $kennziffer (@{$::form->{category_cent}}, @{$::form->{category_euro}}) {
+    $::lxdebug->message($LXDebug::DEBUG2,"kennziffer ".$kennziffer."=".$::form->{$kennziffer});
+
+    next if first { $_ eq $kennziffer } @unused_ids;
+
+    if ($::form->{$kennziffer} != 0) {
+      $params .= "kz".$kennziffer." = ".$::form->{$kennziffer}."\n";
+    }
+  }
+
+  $::lxdebug->message($LXDebug::DEBUG2,"param2=".$params );
+
+
+  $self->js->flash($err?'error':'info',
+                   $err?$err:
+                   $::locale->text('USTVA Data sent to geierlein'));
+  $self->js->run('openGeierlein',$params) if !$err;
+  $::lxdebug->leave_sub();
+  $self->js->render;
+}
+
+
+
+#
+# filters / helpers
+#
+
+
+1;
diff --git a/SL/DB/MetaSetup/Default.pm b/SL/DB/MetaSetup/Default.pm
index 50764a454..775961593 100644
--- a/SL/DB/MetaSetup/Default.pm
+++ b/SL/DB/MetaSetup/Default.pm
@@ -49,6 +49,13 @@ __PACKAGE__->meta->columns(
   duns                                      => { type => 'text' },
   email_journal                             => { type => 'integer', default => 2 },
   expense_accno_id                          => { type => 'integer' },
+  fa_bufa_nr                                => { type => 'text' },
+  fa_dauerfrist                             => { type => 'text' },
+  fa_steuerberater_city                     => { type => 'text' },
+  fa_steuerberater_name                     => { type => 'text' },
+  fa_steuerberater_street                   => { type => 'text' },
+  fa_steuerberater_tel                      => { type => 'text' },
+  fa_voranmeld                              => { type => 'text' },
   feature_balance                           => { type => 'boolean', default => 'true', not_null => 1 },
   feature_datev                             => { type => 'boolean', default => 'true', not_null => 1 },
   feature_erfolgsrechnung                   => { type => 'boolean', default => 'false', not_null => 1 },
diff --git a/SL/USTVA.pm b/SL/USTVA.pm
index 93f83df0e..33a29ddd8 100644
--- a/SL/USTVA.pm
+++ b/SL/USTVA.pm
@@ -28,29 +28,43 @@ package USTVA;
 use List::Util qw(first);
 
 use SL::DBUtils;
+use SL::DB::Default;
+use SL::DB::Finanzamt;
 
 use utf8;
 use strict;
 
 my @tax_office_information = (
-  { 'id' =>  8, 'name' => 'Baden-Württemberg',      'taxbird_nr' => '0',  'elster_format' => 'FF/BBB/UUUUP',  },
-  { 'id' =>  9, 'name' => 'Bayern',                 'taxbird_nr' => '1',  'elster_format' => 'FFF/BBB/UUUUP', },
-  { 'id' => 11, 'name' => 'Berlin',                 'taxbird_nr' => '2',  'elster_format' => 'FF/BBB/UUUUP',  },
-  { 'id' => 12, 'name' => 'Brandenburg',            'taxbird_nr' => '3',  'elster_format' => 'FFF/BBB/UUUUP', },
-  { 'id' =>  4, 'name' => 'Bremen',                 'taxbird_nr' => '4',  'elster_format' => 'FF BBB UUUUP',  },
-  { 'id' =>  2, 'name' => 'Hamburg',                'taxbird_nr' => '5',  'elster_format' => 'FF/BBB/UUUUP',  },
-  { 'id' =>  6, 'name' => 'Hessen',                 'taxbird_nr' => '6',  'elster_format' => '0FF BBB UUUUP', },
-  { 'id' => 13, 'name' => 'Mecklenburg-Vorpommern', 'taxbird_nr' => '7',  'elster_format' => 'FFF/BBB/UUUUP', },
-  { 'id' =>  3, 'name' => 'Niedersachsen',          'taxbird_nr' => '8',  'elster_format' => 'FF/BBB/UUUUP',  },
-  { 'id' =>  5, 'name' => 'Nordrhein-Westfalen',    'taxbird_nr' => '9',  'elster_format' => 'FFF/BBBB/UUUP', },
-  { 'id' =>  7, 'name' => 'Rheinland-Pfalz',        'taxbird_nr' => '10', 'elster_format' => 'FF/BBB/UUUU/P', },
-  { 'id' => 10, 'name' => 'Saarland',               'taxbird_nr' => '11', 'elster_format' => 'FFF/BBB/UUUUP', },
-  { 'id' => 14, 'name' => 'Sachsen',                'taxbird_nr' => '12', 'elster_format' => 'FFF/BBB/UUUUP', },
-  { 'id' => 15, 'name' => 'Sachsen-Anhalt',         'taxbird_nr' => '13', 'elster_format' => 'FFF/BBB/UUUUP', },
-  { 'id' =>  1, 'name' => 'Schleswig-Holstein',     'taxbird_nr' => '14', 'elster_format' => 'FF BBB UUUUP',  },
-  { 'id' => 16, 'name' => 'Thüringen',              'taxbird_nr' => '15', 'elster_format' => 'FFF/BBB/UUUUP', },
+  { 'id' =>  8, 'name' => 'Baden-Württemberg',      'taxbird_nr' => '1',  'elster_format' => 'FFBBB/UUUUP',  },
+  { 'id' =>  9, 'name' => 'Bayern',                 'taxbird_nr' => '2',  'elster_format' => 'FFF/BBB/UUUUP', },
+  { 'id' => 11, 'name' => 'Berlin',                 'taxbird_nr' => '3',  'elster_format' => 'FF/BBB/UUUUP',  },
+  { 'id' => 12, 'name' => 'Brandenburg',            'taxbird_nr' => '4',  'elster_format' => 'FFF/BBB/UUUUP', },
+  { 'id' =>  4, 'name' => 'Bremen',                 'taxbird_nr' => '5',  'elster_format' => 'FF BBB UUUUP',  },
+  { 'id' =>  2, 'name' => 'Hamburg',                'taxbird_nr' => '6',  'elster_format' => 'FF/BBB/UUUUP',  },
+  { 'id' =>  6, 'name' => 'Hessen',                 'taxbird_nr' => '7',  'elster_format' => '0FF BBB UUUUP', },
+  { 'id' => 13, 'name' => 'Mecklenburg-Vorpommern', 'taxbird_nr' => '8',  'elster_format' => 'FFF/BBB/UUUUP', },
+  { 'id' =>  3, 'name' => 'Niedersachsen',          'taxbird_nr' => '9',  'elster_format' => 'FF/BBB/UUUUP',  },
+  { 'id' =>  5, 'name' => 'Nordrhein-Westfalen',    'taxbird_nr' => '10', 'elster_format' => 'FFF/BBBB/UUUP', },
+  { 'id' =>  7, 'name' => 'Rheinland-Pfalz',        'taxbird_nr' => '11', 'elster_format' => 'FF/BBB/UUUUP', },
+  { 'id' => 10, 'name' => 'Saarland',               'taxbird_nr' => '12', 'elster_format' => 'FFF/BBB/UUUUP', },
+  { 'id' => 14, 'name' => 'Sachsen',                'taxbird_nr' => '13', 'elster_format' => 'FFF/BBB/UUUUP', },
+  { 'id' => 15, 'name' => 'Sachsen-Anhalt',         'taxbird_nr' => '14', 'elster_format' => 'FFF/BBB/UUUUP', },
+  { 'id' =>  1, 'name' => 'Schleswig-Holstein',     'taxbird_nr' => '15', 'elster_format' => 'FF BBB UUUUP',  },
+  { 'id' => 16, 'name' => 'Thüringen',              'taxbird_nr' => '16', 'elster_format' => 'FFF/BBB/UUUUP', },
   );
 
+  my @fiamt_config = qw(taxnumber fa_bufa_nr fa_dauerfrist fa_steuerberater_city fa_steuerberater_name
+  fa_steuerberater_street fa_steuerberater_tel fa_voranmeld);
+
+  my @fiamt_finanzamt = qw(
+    fa_land_nr          fa_bufa_nr            fa_name             fa_strasse            
+    fa_plz              fa_ort                fa_telefon          fa_fax
+    fa_plz_grosskunden  fa_plz_postfach       fa_postfach         
+    fa_blz_1 fa_kontonummer_1 fa_bankbezeichnung_1
+    fa_blz_2 fa_kontonummer_2 fa_bankbezeichnung_2 fa_oeffnungszeiten
+    fa_email fa_internet);
+
+
 sub new {
   my $type = shift;
 
@@ -133,44 +147,6 @@ sub report_variables {
 
 }
 
-sub create_steuernummer {
-  $main::lxdebug->enter_sub();
-
-  my $form = $main::form;
-
-  our ($elster_FFFF);
-
-  my $part           = $form->{part};
-  my $patterncount   = $form->{patterncount};
-  my $delimiter      = $form->{delimiter};
-  my $elster_pattern = $form->{elster_pattern};
-
-  # rebuild steuernummer and elstersteuernummer
-  # es gibt eine gespeicherte steuernummer $form->{steuernummer}
-  # und die parts und delimiter
-
-  my $h = 0;
-  my $i = 0;
-
-  my $steuernummer_new        = $part;
-  my $elstersteuernummer_new  = $elster_FFFF;
-  $elstersteuernummer_new    .= '0';
-
-  for ($h = 1; $h < $patterncount; $h++) {
-    $steuernummer_new .= qq|$delimiter|;
-    for ($i = 1; $i <= length($elster_pattern); $i++) {
-      $steuernummer_new       .= $form->{"part_$h\_$i"};
-      $elstersteuernummer_new .= $form->{"part_$h\_$i"};
-    }
-  }
-  if ($form->{steuernummer} ne $steuernummer_new) {
-    $form->{steuernummer}       = $steuernummer_new;
-    $form->{elstersteuernummer} = $elstersteuernummer_new;
-    $form->{steuernummer_new}   = $steuernummer_new;
-  }
-  $main::lxdebug->leave_sub();
-  return ($steuernummer_new, $elstersteuernummer_new);
-}
 
 sub steuernummer_input {
   $main::lxdebug->enter_sub();
@@ -191,16 +167,27 @@ sub steuernummer_input {
   #Pattern description Elstersteuernummer
 
   #split the pattern
-  my $tax_office     = first { $_->{name} eq $elster_land } @{ $self->{tax_office_information} };
+  my $tax_office     = first { $_->{id} eq $elster_land } @{ $self->{tax_office_information} };
   my $elster_pattern = $tax_office->{elster_format};
+ # $::lxdebug->message(LXDebug->DEBUG2, "stnr=".$stnr." elster_FFFF=".$elster_FFFF.
+ #                     " pattern=".$elster_pattern." land=".$elster_land);
   my @elster_pattern = split(' ', $elster_pattern);
-  my $delimiter      = '&nbsp;';
+  my $delimiter1      = '&nbsp;';
+  my $delimiter2      = '&nbsp;';
   my $patterncount   = @elster_pattern;
   if ($patterncount < 2) {
     @elster_pattern = ();
     @elster_pattern = split('/', $elster_pattern);
-    $delimiter      = '/';
+    $delimiter1      = '/';
+    $delimiter2      = '/';
     $patterncount   = @elster_pattern;
+    if ($patterncount < 2) {
+        @elster_pattern = ();
+        @elster_pattern = split(' ', $elster_pattern);
+        $delimiter1      = ' ';
+        $delimiter2      = ' ';
+        $patterncount   = @elster_pattern;
+    }
   }
 
   # no we have an array of patternparts and a delimiter
@@ -208,6 +195,7 @@ sub steuernummer_input {
 
   $steuernummer_input .= qq|<b><font size="+1">|;
   my $part = '';
+#  $::lxdebug->message(LXDebug->DEBUG2, "pattern0=".$elster_pattern[0]);
 SWITCH: {
     $elster_pattern[0] eq 'FFF' && do {
       $part = substr($elster_FFFF, 1, 4);
@@ -219,6 +207,15 @@ SWITCH: {
       $steuernummer_input .= qq|$part|;
       last SWITCH;
     };
+    $elster_pattern[0] eq 'FFBBB' && do {
+      $part = substr($elster_FFFF, 2, 4);
+      $steuernummer_input .= qq|$part|;
+      $delimiter1 = '';
+      $patterncount++ ;
+      # Sonderfall BW
+      @elster_pattern = ('FF','BBB','UUUUP');
+      last SWITCH;
+    };
     $elster_pattern[0] eq 'FF' && do {
       $part = substr($elster_FFFF, 2, 4);
       $steuernummer_input .= qq|$part|;
@@ -231,19 +228,22 @@ SWITCH: {
   }
 
   #now the rest of the Steuernummer ...
-  $steuernummer_input .= qq|</b></font>|;
+  $steuernummer_input .= qq|</font></b>|;
   $steuernummer_input .= qq|\n
            <input type=hidden name="elster_pattern" value="$elster_pattern">
            <input type=hidden name="patterncount" value="$patterncount">
            <input type=hidden name="patternlength" value="$patterncount">
-           <input type=hidden name="delimiter" value="$delimiter">
+           <input type=hidden name="delimiter1" value="$delimiter1">
+           <input type=hidden name="delimiter2" value="$delimiter2">
            <input type=hidden name="part" value="$part">
   |;
 
   my $k = 0;
 
   for (my $h = 1; $h < $patterncount; $h++) {
+    my $delimiter = ( $h==1?$delimiter1:$delimiter2);
     $steuernummer_input .= qq|&nbsp;$delimiter&nbsp;\n|;
+#  $::lxdebug->message(LXDebug->DEBUG2, "pattern[$h]=".$elster_pattern[$h]);
     for (my $i = 1; $i <= length($elster_pattern[$h]); $i++) {
       $steuernummer_input .= qq|<select name="part_$h\_$i">\n|;
 
@@ -269,42 +269,46 @@ SWITCH: {
 sub fa_auswahl {
   $main::lxdebug->enter_sub();
 
-#  use SL::Form;
-
   # Referenz wird übergeben, hash of hash wird nicht
   # in neues  Hash kopiert, sondern direkt über die Referenz verändert
   # Prototyp für diese Konstruktion
 
   my ($self, $land, $elsterFFFF, $elster_init) = @_;
 
+#  $::lxdebug->message(LXDebug->DEBUG2,"land=".$land." amt=".$elsterFFFF);
   my $terminal = '';
   my $FFFF     = $elsterFFFF;
   my $ffff     = '';
   my $checked  = '';
   $checked = 'checked' if ($elsterFFFF eq '' and $land eq '');
   my %elster_land_fa;
+  my %elster_land_name = ();
 
   my $fa_auswahl = qq|
         <script language="Javascript">
         function update_auswahl()
         {
-                var elsterBLAuswahl = document.verzeichnis.elsterland_new;
-                var elsterFAAuswahl = document.verzeichnis.elsterFFFF_new;
+                var elsterBLAuswahl = document.verzeichnis.fa_land_nr_new;
+                var elsterFAAuswahl = document.verzeichnis.fa_bufa_nr_new;
 
                 elsterFAAuswahl.options.length = 0; // dropdown aufräumen
                 |;
 
   foreach my $elster_land (sort keys %$elster_init) {
     $fa_auswahl .= qq|
-               if (elsterBLAuswahl.options[elsterBLAuswahl.selectedIndex].
-               value == "$elster_land")
+               if (elsterBLAuswahl.options[elsterBLAuswahl.selectedIndex].value == "$elster_land")
                {
                |;
     my $j              = 0;
     %elster_land_fa = ();
     $FFFF = '';
     for $FFFF (keys %{ $elster_init->{$elster_land} }) {
-      $elster_land_fa{$FFFF} = $elster_init->{$elster_land}->{$FFFF}->[0];
+        if ( $FFFF eq 'name' ) {
+            $elster_land_name{$elster_land} = $elster_init->{$elster_land}{$FFFF};
+            delete $elster_init->{$elster_land}{$FFFF};
+        } else {
+            $elster_land_fa{$FFFF} = $elster_init->{$elster_land}{$FFFF}->fa_name;
+       }
     }
     foreach $ffff (sort { $elster_land_fa{$a} cmp $elster_land_fa{$b} }
                    keys(%elster_land_fa)
@@ -326,20 +330,22 @@ sub fa_auswahl {
                Bundesland
             </td>
             <td>
-              <select size="1" name="elsterland_new" onchange="update_auswahl()">|;
+              <select size="1" name="fa_land_nr_new" onchange="update_auswahl()">|;
   if ($land eq '') {
     $fa_auswahl .= qq|<option value="Auswahl" $checked>| . $main::locale->text('Select federal state...') . qq|</option>\n|;
   }
   foreach my $elster_land (sort keys %$elster_init) {
     $fa_auswahl .= qq|
                   <option value="$elster_land"|;
+#  $::lxdebug->message(LXDebug->DEBUG2,"land=".$land." elster_land=".$elster_land." lname=".$elster_land_name{$elster_land});
     if ($elster_land eq $land and $checked eq '') {
       $fa_auswahl .= qq| selected|;
     }
-    $fa_auswahl .= qq|>$elster_land</option>
+    $fa_auswahl .= qq|>$elster_land_name{$elster_land}</option>
              |;
   }
   $fa_auswahl .= qq|
+              </select>
             </td>
           </tr>
           |;
@@ -348,7 +354,7 @@ sub fa_auswahl {
   $elster_land = ($land ne '') ? $land : '';
   %elster_land_fa = ();
   for $FFFF (keys %{ $elster_init->{$elster_land} }) {
-    $elster_land_fa{$FFFF} = $elster_init->{$elster_land}->{$FFFF}->[0];
+    $elster_land_fa{$FFFF} = $elster_init->{$elster_land}{$FFFF}->fa_name;
   }
 
   $fa_auswahl .= qq|
@@ -356,7 +362,7 @@ sub fa_auswahl {
               <td>Finanzamt
               </td>
               <td>
-                 <select size="1" name="elsterFFFF_new">|;
+                 <select size="1" name="fa_bufa_nr_new">|;
   if ($elsterFFFF eq '') {
     $fa_auswahl .= qq|<option value="Auswahl" $checked>| . $main::locale->text('Select tax office...') . qq|</option>|;
   } else {
@@ -373,10 +379,10 @@ sub fa_auswahl {
     }
   }
   $fa_auswahl .= qq|
-                 </td>
-              </tr>
-            </table>
-            </select>|;
+                 </select>
+              </td>
+          </tr>
+        </table>|;
 
   $main::lxdebug->leave_sub();
 
@@ -518,69 +524,16 @@ sub query_finanzamt {
   };
   $tst->finish();
 
-  #$dbh->disconnect();
-
-  my @vars = (
-    'FA_Land_Nr',             #  0
-    'FA_BUFA_Nr',             #  1
-                              #'FA_Verteiler',                             #  2
-    'FA_Name',                #  3
-    'FA_Strasse',             #  4
-    'FA_PLZ',                 #  5
-    'FA_Ort',                 #  6
-    'FA_Telefon',             #  7
-    'FA_Fax',                 #  8
-    'FA_PLZ_Grosskunden',     #  9
-    'FA_PLZ_Postfach',        # 10
-    'FA_Postfach',            # 11
-    'FA_BLZ_1',               # 12
-    'FA_Kontonummer_1',       # 13
-    'FA_Bankbezeichnung_1',   # 14
-                              #'FA_BankIBAN_1',                            # 15
-                              #'FA_BankBIC_1',                             # 16
-                              #'FA_BankInhaber_BUFA_Nr_1',                 # 17
-    'FA_BLZ_2',               # 18
-    'FA_Kontonummer_2',       # 19
-    'FA_Bankbezeichnung_2',   # 20
-                              #'FA_BankIBAN_2',                            # 21
-                              #'FA_BankBIC_2',                             # 22
-                              #'FA_BankInhaber_BUFA_Nr_2',                 # 23
-    'FA_Oeffnungszeiten',     # 24
-    'FA_Email',               # 25
-    'FA_Internet'             # 26
-                              #'FA_zustaendige_Hauptstelle_BUFA_Nr',       # 27
-                              #'FA_zustaendige_vorgesetzte_Finanzbehoerde' # 28
-  );
-
-  my $field = join(', ', @vars);
 
-  my $query = "SELECT $field FROM finanzamt ORDER BY FA_Land_nr";
-  my $sth = $dbh->prepare($query) or $self->error($dbh->errstr);
-  $sth->execute || $form->dberror($query);
-  my $array_ref = $sth->fetchall_arrayref();
-  my $land      = '';
+  my $fiamt =  SL::DB::Finanzamt->_get_manager_class->get_all(sort => 'fa_land_nr');
+  my $land      = 0;
   my %finanzamt;
-  foreach my $row (@$array_ref) {
-    my $FA_finanzamt = $row;
-    my $tax_office   = first { $_->{id} == $FA_finanzamt->[0] } @{ $self->{tax_office_information} };
-    $land            = $tax_office->{name};
-
-    # $land = $main::locale->{iconv}->convert($land);
-
-    my $ffff = @$FA_finanzamt[1];
-
-    my $rec = {};
-    $rec->{$land} = $ffff;
-
-    shift @$row;
-    shift @$row;
-
-    $finanzamt{$land}{$ffff} = [@$FA_finanzamt];
+  foreach my $row (@$fiamt) {
+    my $tax_office   = first { $_->{id} == $row->fa_land_nr } @{ $self->{tax_office_information} };
+    $land            = $tax_office->{id};
+    $finanzamt{$land}{$row->fa_bufa_nr}  = $row;
+    $finanzamt{$land}{'name'} ||= $tax_office->{name};
   }
-
-  $sth->finish();
-  $dbh->disconnect();
-
   $main::lxdebug->leave_sub();
 
   return \%finanzamt;
@@ -654,6 +607,8 @@ sub ustva {
   my $last_period     = 0;
   my $category        = "pos_ustva";
 
+  $form->{coa} = $::instance_conf->get_coa;
+
   my @category_cent = USTVA->report_variables({
       myconfig    => $myconfig,
       form        => $form,
@@ -662,8 +617,9 @@ sub ustva {
       dec_places  => '2',
   });
 
-  push @category_cent, qw(83  Z43  Z45  Z53  Z62  Z65  Z67);
-
+  if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') {
+      push @category_cent, qw(Z43  Z45  Z53  Z54  Z62  Z65  Z67);
+  }
   my @category_euro = USTVA->report_variables({
       myconfig    => $myconfig,
       form        => $form,
@@ -672,14 +628,8 @@ sub ustva {
       dec_places  => '0',
   });
 
-  push @category_euro, USTVA->report_variables({
-      myconfig    => $myconfig,
-      form        => $form,
-      type        => '',
-      attribute   => 'position',
-      dec_places  => '0',
-  });
-
+  @{$form->{category_cent}} = @category_cent;
+  @{$form->{category_euro}} = @category_euro;
   $form->{decimalplaces} *= 1;
 
   foreach my $item (@category_cent) {
@@ -688,14 +638,11 @@ sub ustva {
   foreach my $item (@category_euro) {
     $form->{"$item"} = 0;
   }
-  my $coa_name = $::instance_conf->get_coa;
-  $form->{coa} = $coa_name;
 
   # Controlvariable for templates
+  my $coa_name = $form->{coa};
   $form->{"$coa_name"} = '1';
 
-  $main::lxdebug->message(LXDebug->DEBUG2(), "COA: '$form->{coa}',  \$form->{$coa_name} = 1");
-
   &get_accounts_ustva($dbh, $last_period, $form->{fromdate}, $form->{todate},
                       $form, $category);
 
@@ -777,10 +724,10 @@ sub get_accounts_ustva {
   my $arwhere  = "";
   my $item;
 
-    my $gltaxkey_where = "((tk.pos_ustva = 46) OR (tk.pos_ustva>=59 AND tk.pos_ustva<=67) or (tk.pos_ustva>=89 AND tk.pos_ustva<=93))";
+  my $gltaxkey_where = "((tk.pos_ustva = 46) OR (tk.pos_ustva>=59 AND tk.pos_ustva<=67) or (tk.pos_ustva>=89 AND tk.pos_ustva<=93))";
 
   if ($fromdate) {
-    if ($form->{method} eq 'cash') {
+    if ($form->{accounting_method} eq 'cash') {
       $subwhere .= " AND transdate >= '$fromdate'";
       $glwhere = " AND ac.transdate >= '$fromdate'";
       $ARwhere .= " AND acc.transdate >= '$fromdate'";
@@ -816,7 +763,7 @@ sub get_accounts_ustva {
   #
   ############################################
 
-  if ($form->{method} eq 'cash') {
+  if ($form->{accounting_method} eq 'cash') {
 
     $query = qq|
        SELECT
@@ -860,7 +807,7 @@ sub get_accounts_ustva {
        GROUP BY tk.pos_ustva
     |;
 
-  } elsif ($form->{method} eq 'accrual') {
+  } elsif ($form->{accounting_method} eq 'accrual') {
     #########################################
     # Method eq 'accrual' = Soll Versteuerung
     #########################################
@@ -889,7 +836,7 @@ sub get_accounts_ustva {
 
   } else {
 
-    $form->error("Unknown tax method: $form->{method}")
+    $form->error("Unknown tax method: $form->{accounting_method}")
 
   }
 
@@ -994,27 +941,173 @@ sub get_accounts_ustva {
 
 }
 
-sub get_config {
+sub set_FromTo {
   $main::lxdebug->enter_sub();
 
-  my ($self, $userspath, $filename) = @_;
+  my ($self, $form) = @_;
 
-  my $form = $main::form;
+  # init some form vars
+  my @anmeldungszeitraum =
+    qw('0401' '0402' '0403'
+       '0404' '0405' '0406'
+       '0407' '0408' '0409'
+       '0410' '0411' '0412'
+       '0441' '0442' '0443' '0444');
 
-  $form->error("Missing Parameter: @_") if !$userspath || !$filename;
+  foreach my $item (@anmeldungszeitraum) {
+    $form->{$item} = "";
+  }
 
-  $filename = "$::myconfig{login}_$filename";
-  $filename =~ s|.*/||;
-  $filename = "$userspath/$filename";
-  open my $FACONF, "<", $filename or do {# Annon Sub
-    # catch open error
-    # create file if file does not exist
-    open my $FANEW, ">", $filename  or $form->error("CREATE: $filename : $!");
-    close $FANEW                    or $form->error("CLOSE: $filename : $!");
+  #forgotten the year --> thisyear
+  if ($form->{year} !~ m/^\d\d\d\d$/) {
+      $form->{year} = substr(
+          $form->datetonum(
+              $form->current_date(\%::myconfig), \%::myconfig
+          ),
+          0, 4);
+      $::lxdebug->message(LXDebug->DEBUG1,
+                          qq|Actual year from Database: $form->{year}\n|);
+  }
 
-    #try again open file
-    open my $FACONF, "<", $filename or $form->error("OPEN: $filename : $!");
-  };
+  #
+  # using dates in ISO-8601 format: yyyymmmdd  for Postgres...
+  #
+
+  #yearly report
+  if ($form->{period} eq "13") {
+      $form->{fromdate} = "$form->{year}0101";
+      $form->{todate}   = "$form->{year}1231";
+  }
+
+  #quarter reports
+  if ($form->{period} eq "41") {
+      $form->{fromdate} = "$form->{year}0101";
+      $form->{todate}   = "$form->{year}0331";
+      $form->{'0441'}   = "X";
+  }
+  if ($form->{period} eq "42") {
+      $form->{fromdate} = "$form->{year}0401";
+      $form->{todate}   = "$form->{year}0630";
+      $form->{'0442'}   = "X";
+  }
+  if ($form->{period} eq "43") {
+      $form->{fromdate} = "$form->{year}0701";
+      $form->{todate}   = "$form->{year}0930";
+      $form->{'0443'}   = "X";
+  }
+  if ($form->{period} eq "44") {
+      $form->{fromdate} = "$form->{year}1001";
+      $form->{todate}   = "$form->{year}1231";
+      $form->{'0444'}   = "X";
+  }
+
+   #Monthly reports
+  SWITCH: {
+      $form->{period} eq "01" && do {
+        $form->{fromdate} = "$form->{year}0101";
+        $form->{todate}   = "$form->{year}0131";
+        $form->{'0401'}   = "X";
+        last SWITCH;
+      };
+      $form->{period} eq "02" && do {
+        $form->{fromdate} = "$form->{year}0201";
+
+        #this works from 1901 to 2099, 1900 and 2100 fail.
+        my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
+        $form->{todate} = "$form->{year}02$leap";
+        $form->{"0402"} = "X";
+        last SWITCH;
+      };
+      $form->{period} eq "03" && do {
+        $form->{fromdate} = "$form->{year}0301";
+        $form->{todate}   = "$form->{year}0331";
+        $form->{"0403"}   = "X";
+        last SWITCH;
+      };
+      $form->{period} eq "04" && do {
+        $form->{fromdate} = "$form->{year}0401";
+        $form->{todate}   = "$form->{year}0430";
+        $form->{"0404"}   = "X";
+        last SWITCH;
+      };
+      $form->{period} eq "05" && do {
+        $form->{fromdate} = "$form->{year}0501";
+        $form->{todate}   = "$form->{year}0531";
+        $form->{"0405"}   = "X";
+        last SWITCH;
+      };
+      $form->{period} eq "06" && do {
+        $form->{fromdate} = "$form->{year}0601";
+        $form->{todate}   = "$form->{year}0630";
+        $form->{"0406"}   = "X";
+        last SWITCH;
+      };
+      $form->{period} eq "07" && do {
+        $form->{fromdate} = "$form->{year}0701";
+        $form->{todate}   = "$form->{year}0731";
+        $form->{"0407"}   = "X";
+        last SWITCH;
+      };
+      $form->{period} eq "08" && do {
+        $form->{fromdate} = "$form->{year}0801";
+        $form->{todate}   = "$form->{year}0831";
+        $form->{"0408"}   = "X";
+        last SWITCH;
+      };
+      $form->{period} eq "09" && do {
+        $form->{fromdate} = "$form->{year}0901";
+        $form->{todate}   = "$form->{year}0930";
+        $form->{"0409"}   = "X";
+        last SWITCH;
+      };
+      $form->{period} eq "10" && do {
+        $form->{fromdate} = "$form->{year}1001";
+        $form->{todate}   = "$form->{year}1031";
+        $form->{"0410"}   = "X";
+        last SWITCH;
+      };
+      $form->{period} eq "11" && do {
+        $form->{fromdate} = "$form->{year}1101";
+        $form->{todate}   = "$form->{year}1130";
+        $form->{"0411"}   = "X";
+        last SWITCH;
+      };
+      $form->{period} eq "12" && do {
+        $form->{fromdate} = "$form->{year}1201";
+        $form->{todate}   = "$form->{year}1231";
+        $form->{"0412"}   = "X";
+        last SWITCH;
+      };
+    }
+
+  # Kontrollvariablen für die Templates
+  $form->{"year$_"} = ($form->{year} >= $_ ) ? "1":"0" for 2007..2107;
+
+  $main::lxdebug->leave_sub();
+}
+
+sub get_fiamt_vars {
+    return @fiamt_finanzamt;
+}
+
+sub get_oldconfig {
+  $main::lxdebug->enter_sub();
+
+  my $ret = 0;
+  my %oldkeys = (
+      'steuernummer' => 'taxnumber',
+      'elsterFFFF' => 'fa_bufa_nr',
+      'FA_dauerfrist' => 'fa_dauerfrist',
+      'FA_steuerberater_city' => 'fa_steuerberater_city',
+      'FA_steuerberater_name' => 'fa_steuerberater_name',
+      'FA_steuerberater_street' => 'fa_steuerberater_street',
+      'FA_steuerberater_tel' => 'fa_steuerberater_tel',
+      'FA_voranmeld' => 'fa_voranmeld',
+      );
+
+  my $filename = $::lx_office_conf{paths}{userspath}."/finanzamt.ini";
+  my $FACONF;
+  return unless (open( $FACONF, "<", $filename));
 
   while (<$FACONF>) {
     last if (/^\[/);
@@ -1026,15 +1119,62 @@ sub get_config {
     # remove any trailing whitespace
     s/^\s*(.*?)\s*$/$1/;
     my ($key, $value) = split(/=/, $_, 2);
-
-    $form->{$key} = "$value";
-
+    
+    $main::lxdebug->message(LXDebug->DEBUG2(), "oldkey: ".$key." val=".$value." newkey=".
+                          $oldkeys{$key}." oval=".$::form->{$oldkeys{$key}});
+    if ( $oldkeys{$key} && $::form->{$oldkeys{$key}} eq '' ) {
+        $::form->{$oldkeys{$key}} = $::locale->{iconv_utf8}->convert($value);
+        $main::lxdebug->message(LXDebug->DEBUG2(), "set ".$oldkeys{$key}."=".$::form->{$oldkeys{$key}});
+        $ret = 1;
+    }
   }
+  $main::lxdebug->leave_sub();
+  return $ret;
+}
 
-  close $FACONF;
+sub get_config {
+    $main::lxdebug->enter_sub();
+    my $defaults   = SL::DB::Default->get;
+    my @rd_config =  @fiamt_config;
+    push @rd_config ,qw(accounting_method coa company address co_ustid duns);
+    $::form->{$_} = $defaults->$_ for @rd_config;
+
+    if ( $::form->{taxnumber} eq '' || $::form->{fa_bufa_nr} eq '') {
+        #alte finanzamt.ini lesen, ggf abspeichern
+        if ( get_oldconfig() ) {
+            get_finanzamt();
+            save_config();
+        }
+    }
 
-  $main::lxdebug->leave_sub();
+    my $coa = $::form->{coa};
+    $::form->{"COA_$coa"} = '1';
+    $::form->{COA_Germany} = '1' if ($coa =~ m/^germany/i);
+    $main::lxdebug->leave_sub();
 }
 
+sub get_finanzamt {
+    $main::lxdebug->enter_sub();
+    if ( $::form->{fa_bufa_nr} && $::form->{fa_bufa_nr} ne '' ) {
+        my $fiamt =  SL::DB::Finanzamt->_get_manager_class->get_first(
+                 query => [ fa_bufa_nr => $::form->{fa_bufa_nr} ]);
+        $::form->{$_} = $fiamt->$_ for @fiamt_finanzamt;
+    }
+    $main::lxdebug->leave_sub();
+}
+
+sub save_config {
+    $main::lxdebug->enter_sub();
+    my $defaults  = SL::DB::Default->get;
+    $defaults->$_($::form->{$_}) for @fiamt_config;
+    $defaults->save;
+    if ( $defaults->fa_bufa_nr ) {
+        my $fiamt =  SL::DB::Finanzamt->_get_manager_class->get_first(
+                 query => [ fa_bufa_nr => $defaults->fa_bufa_nr ]);
+        $fiamt->$_($::form->{$_}) for @fiamt_finanzamt;
+        $fiamt->save;
+    }
+    $main::lxdebug->leave_sub();
+}
 
 1;
diff --git a/bin/mozilla/ustva.pl b/bin/mozilla/ustva.pl
index f88fce524..6c80d4665 100644
--- a/bin/mozilla/ustva.pl
+++ b/bin/mozilla/ustva.pl
@@ -98,8 +98,15 @@ sub report {
 
   # Einlesen der Finanzamtdaten
   my $ustva = USTVA->new();
-  $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
+  $ustva->get_config();
+  $ustva->get_finanzamt();
 
+  my $geierlein_enabled = 0;
+  my $geierlein_path = $::lx_office_conf{paths}{geierlein_path};
+
+  if ( $geierlein_path && length($geierlein_path) > 0 ) {$geierlein_enabled=1;} 
+
+#  $::lxdebug->message(LXDebug->DEBUG2,"geierlein_enabled=".$geierlein_enabled." path=".$geierlein_path);
   # Hier Einlesen der user-config
   # steuernummer entfernt für prerelease
   my @a = qw(
@@ -116,14 +123,13 @@ sub report {
   );
 
   $form->{$_} = $myconfig{$_} for @a;
-  $form->{$_} = $defaults->$_ for qw(company address co_ustid duns);
 
-  my $openings = $form->{FA_Oeffnungszeiten};
+  my $openings = $form->{fa_oeffnungszeiten};
   $openings =~ s/\\\\n/<br>/g;
 
   my $company_given = ($form->{company} ne '')
     ? qq|<h3>$form->{company}</h3>\n|
-    : qq|<a href="am.pl?action=config">|
+    : qq|<a href="controller.pl?action=ClientConfig/edit">|
       . $locale->text('No Company Name given') . qq|!</a><br>|;
 
 
@@ -142,8 +148,7 @@ sub report {
     ? qq|$form->{co_street}<br>|
         . qq|$form->{co_street1}<br>|
         . qq|$form->{co_zip} $form->{co_city}|
-    : qq|<a href="am.pl?action=config|
-        . qq|&level=Programm--Preferences">|
+    : qq|<a href="controller.pl?action=ClientConfig/edit">|
         . $locale->text('No Company Address given')
         . qq|!</a>\n|;
 
@@ -152,8 +157,8 @@ sub report {
   $form->{co_fax}   = $form->{fax}   unless $form->{co_fax};
   $form->{co_url}   = $form->{urlx}  unless $form->{co_url};
 
-  my $taxnumber_given = ($form->{steuernummer} ne '') ? $form->{steuernummer} : qq|<a href="ustva.pl?action=config_step1">Keine Steuernummer hinterlegt!</a><br>|;
-
+  my $taxnumber_given = ($form->{taxnumber} ne '') ? $form->{taxnumber} : qq|<a href="ustva.pl?action=config_step1">Keine Steuernummer hinterlegt!</a><br>|;
+  my $fa_name_given = ($form->{fa_name} ne '') ? $form->{fa_name} : qq|<a href="ustva.pl?action=config_step1">Kein Finanzamt hinterlegt!</a><br>|;
   my $ustva_vorauswahl = &ustva_vorauswahl();
 
   my @all_years = $form->all_years(\%myconfig);
@@ -171,30 +176,49 @@ sub report {
   $_checked = "checked" if ($form->{kz10} eq '1');
   my $checkbox_kz_10 = qq|<input name="FA_10" id=FA_10 class=checkbox|
     . qq| type=checkbox value="1" $_checked title = "|
-    . $locale->text('Amended Advance Turnover Tax Return (Nr. 10)')
+    . $locale->text('Amended Advance Turnover Tax Return').'(Nr. 10)'
     . qq|">|
     . $locale->text('Amended Advance Turnover Tax Return');
 
-  my $method_local = ($form->{method} eq 'accrual') ? $locale->text('accrual')
-                   : ($form->{method} eq 'cash')    ? $locale->text('cash')
+  $_checked = "checked" if ($form->{kz22} eq '1');
+  my $checkbox_kz_22 = qq|<input name="FA_22" id=FA_22 class=checkbox|
+    . qq| type=checkbox value="1" $_checked title = "|
+    . $locale->text('Receipts attached/extra').'(Nr. 22)'
+    . qq|">|
+    . $locale->text('Receipts attached/extra');
+
+  $_checked = "checked" if ($form->{kz29} eq '1');
+  my $checkbox_kz_29 = qq|<input name="FA_29" id=FA_29 class=checkbox|
+    . qq| type=checkbox value="1" $_checked title = "|
+    . $locale->text('Accounting desired').'(Nr. 29)'
+    . qq|">|
+    . $locale->text('Accounting desired');
+
+  $_checked = "checked" if ($form->{kz26} eq '1');
+  my $checkbox_kz_26 = qq|<input name="FA_26" id=FA_26 class=checkbox|
+    . qq| type=checkbox value="1" $_checked title = "|
+    . $locale->text('Direct debit revoked').'(Nr. 26)'
+    . qq|">|
+    . $locale->text('Direct debit revoked');
+
+  my $method_local = ($form->{accounting_method} eq 'accrual') ? $locale->text('accrual')
+                   : ($form->{accounting_method} eq 'cash')    ? $locale->text('cash')
                    : '';
 
-  my $period_local = ( $form->{FA_voranmeld} eq 'month')   ? $locale->text('month')
-                   : ( $form->{FA_voranmeld} eq 'quarter') ? $locale->text('quarter')
+  my $period_local = ( $form->{fa_voranmeld} eq 'month')   ? $locale->text('month')
+                   : ( $form->{fa_voranmeld} eq 'quarter') ? $locale->text('quarter')
                    : '';
 
-  my $tax_office_banks_ref = [
-    { BLZ             => $form->{FA_BLZ_1},
-      Kontonummer     => $form->{FA_Kontonummer_1},
-      Bankbezeichnung => $form->{FA_Bankbezeichnung_1}
+  my @tax_office_banks_ref = (
+    { BLZ             => $form->{fa_blz_1},
+      Kontonummer     => $form->{fa_kontonummer_1},
+      Bankbezeichnung => $form->{fa_bankbezeichnung_1}
     },
-    { BLZ             => $form->{FA_BLZ_2},
-      Kontonummer     => $form->{FA_Kontonummer_2},
-      Bankbezeichnung => $form->{FA_Bankbezeichnung_oertlich}
+    { BLZ             => $form->{fa_blz_2},
+      Kontonummer     => $form->{fa_kontonummer_2},
+      Bankbezeichnung => $form->{fa_bankbezeichnung_2}
     }
-  ];
-
-  # Which COA is in use?
+  );
 
   $ustva->get_coa($form); # fetches coa and modifies some form variables
 
@@ -203,13 +227,19 @@ sub report {
     company_given    => $company_given,
     address_given    => $address_given,
     taxnumber_given  => $taxnumber_given,
+    fa_name_given    => $fa_name_given,
     taxnumber        => $defaults->taxnumber,
     select_year      => $select_year,
     period_local     => $period_local,
     method_local     => $method_local,
     ustva_vorauswahl => $ustva_vorauswahl,
     checkbox_kz_10   => $checkbox_kz_10,
-    tax_office_banks => $tax_office_banks_ref,
+    checkbox_kz_22   => $checkbox_kz_22,
+    checkbox_kz_29   => $checkbox_kz_29,
+    checkbox_kz_26   => $checkbox_kz_26,
+    tax_office_banks => \@tax_office_banks_ref,
+    geierlein_enabled => $geierlein_enabled,
+    geierlein_path   => $geierlein_path,
     select_options   => &show_options,
 
   };
@@ -243,7 +273,7 @@ sub show {
 
   $::auth->assert('advance_turnover_tax_return');
 
-  #&generate_ustva();
+  #generate_ustva();
   $::lxdebug->leave_sub();
   call_sub($::form->{"nextsub"});
 }
@@ -280,13 +310,13 @@ sub ustva_vorauswahl {
   #$form->{month}= '01';
   #$form->{year}= 2004;
   $select_vorauswahl = qq|
-     <input type=hidden name=day value=$form->{day}>
-     <input type=hidden name=month value=$form->{month}>
-     <input type=hidden name=yymmdd value=$yymmdd>
-     <input type=hidden name=sel value=$sel>
+     <input type="hidden" name="day" value="$form->{day}">
+     <input type="hidden" name="month" value="$form->{month}">
+     <input type="hidden" name="yymmdd" value="$yymmdd">
+     <input type="hidden" name="sel" value="$sel">
   |;
 
-  if ($form->{FA_voranmeld} eq 'month') {
+  if ($form->{fa_voranmeld} eq 'month') {
 
     # Vorauswahl bei monatlichem Voranmeldungszeitraum
 
@@ -311,7 +341,7 @@ sub ustva_vorauswahl {
     my $dfv = '';
 
     # Offset für Dauerfristverlängerung
-    $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
+    $dfv = '100' if ($form->{fa_dauerfrist} eq '1');
 
   SWITCH: {
       $yymmdd <= ($yy + 110 + $dfv) && do {
@@ -382,7 +412,7 @@ sub ustva_vorauswahl {
     }
     $select_vorauswahl .= qq|</select>|;
 
-  } elsif ($form->{FA_voranmeld} eq 'quarter') {
+  } elsif ($form->{fa_voranmeld} eq 'quarter') {
 
     # Vorauswahl bei quartalsweisem Voranmeldungszeitraum
     my %liste = ('41'  => $locale->text('1. Quarter'),
@@ -395,7 +425,7 @@ sub ustva_vorauswahl {
     $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
     $sel    = '';
     my $dfv = '';    # Offset für Dauerfristverlängerung
-    $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
+    $dfv = '100' if ($form->{fa_dauerfrist} eq '1');
 
   SWITCH: {
       $yymmdd <= ($yy + 110 + $dfv) && do {
@@ -506,6 +536,16 @@ sub show_options {
     . $::locale->text('HTML')
     . qq|</option>|;
 
+  #my $disabled= qq|disabled="disabled"|;
+  #$disabled='' if ($form->{elster} eq '1' );
+  #if ($::form->{elster} eq '1') {
+  if ( 1 ) {
+    $format .=
+        qq|<option value=elstertaxbird>|
+      . $::locale->text('ELSTER Export (via Geierlein)')
+      . qq|</option>|;
+  }
+
   my $show_options = qq|
     $type
     $media
@@ -530,147 +570,14 @@ sub generate_ustva {
   $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
   $form->{templates} = $defaults->templates;
 
-  # Aufruf von get_config zum Einlesen der Finanzamtdaten aus finanzamt.ini
 
   my $ustva = USTVA->new();
-  $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
-
-  # init some form vars
-  my @anmeldungszeitraum =
-    qw('0401' '0402' '0403'
-       '0404' '0405' '0406'
-       '0407' '0408' '0409'
-       '0410' '0411' '0412'
-       '0441' '0442' '0443' '0444');
-
-  foreach my $item (@anmeldungszeitraum) {
-    $form->{$item} = "";
-  }
-
-    #forgotten the year --> thisyear
-    if ($form->{year} !~ m/^\d\d\d\d$/) {
-      $form->{year} = substr(
-                             $form->datetonum(
-                                    $form->current_date(\%myconfig), \%myconfig
-                             ),
-                             0, 4);
-      $::lxdebug->message(LXDebug->DEBUG1,
-                        qq|Actual year from Database: $form->{year}\n|);
-    }
+  $ustva->get_config();
+  $ustva->get_finanzamt();
 
-    #
-    # using dates in ISO-8601 format: yyyymmmdd  for Postgres...
-    #
+  # Setze Anmeldungszeitraum
 
-    #yearly report
-    if ($form->{period} eq "13") {
-      $form->{fromdate} = "$form->{year}0101";
-      $form->{todate}   = "$form->{year}1231";
-    }
-
-    #Quater reports
-    if ($form->{period} eq "41") {
-      $form->{fromdate} = "$form->{year}0101";
-      $form->{todate}   = "$form->{year}0331";
-      $form->{'0441'}   = "X";
-    }
-    if ($form->{period} eq "42") {
-      $form->{fromdate} = "$form->{year}0401";
-      $form->{todate}   = "$form->{year}0630";
-      $form->{'0442'}   = "X";
-    }
-    if ($form->{period} eq "43") {
-      $form->{fromdate} = "$form->{year}0701";
-      $form->{todate}   = "$form->{year}0930";
-      $form->{'0443'}   = "X";
-    }
-    if ($form->{period} eq "44") {
-      $form->{fromdate} = "$form->{year}1001";
-      $form->{todate}   = "$form->{year}1231";
-      $form->{'0444'}   = "X";
-    }
-
-    #Monthly reports
-  SWITCH: {
-      $form->{period} eq "01" && do {
-        $form->{fromdate} = "$form->{year}0101";
-        $form->{todate}   = "$form->{year}0131";
-        $form->{'0401'}   = "X";
-        last SWITCH;
-      };
-      $form->{period} eq "02" && do {
-        $form->{fromdate} = "$form->{year}0201";
-
-        #this works from 1901 to 2099, 1900 and 2100 fail.
-        my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
-        $form->{todate} = "$form->{year}02$leap";
-        $form->{"0402"} = "X";
-        last SWITCH;
-      };
-      $form->{period} eq "03" && do {
-        $form->{fromdate} = "$form->{year}0301";
-        $form->{todate}   = "$form->{year}0331";
-        $form->{"0403"}   = "X";
-        last SWITCH;
-      };
-      $form->{period} eq "04" && do {
-        $form->{fromdate} = "$form->{year}0401";
-        $form->{todate}   = "$form->{year}0430";
-        $form->{"0404"}   = "X";
-        last SWITCH;
-      };
-      $form->{period} eq "05" && do {
-        $form->{fromdate} = "$form->{year}0501";
-        $form->{todate}   = "$form->{year}0531";
-        $form->{"0405"}   = "X";
-        last SWITCH;
-      };
-      $form->{period} eq "06" && do {
-        $form->{fromdate} = "$form->{year}0601";
-        $form->{todate}   = "$form->{year}0630";
-        $form->{"0406"}   = "X";
-        last SWITCH;
-      };
-      $form->{period} eq "07" && do {
-        $form->{fromdate} = "$form->{year}0701";
-        $form->{todate}   = "$form->{year}0731";
-        $form->{"0407"}   = "X";
-        last SWITCH;
-      };
-      $form->{period} eq "08" && do {
-        $form->{fromdate} = "$form->{year}0801";
-        $form->{todate}   = "$form->{year}0831";
-        $form->{"0408"}   = "X";
-        last SWITCH;
-      };
-      $form->{period} eq "09" && do {
-        $form->{fromdate} = "$form->{year}0901";
-        $form->{todate}   = "$form->{year}0930";
-        $form->{"0409"}   = "X";
-        last SWITCH;
-      };
-      $form->{period} eq "10" && do {
-        $form->{fromdate} = "$form->{year}1001";
-        $form->{todate}   = "$form->{year}1031";
-        $form->{"0410"}   = "X";
-        last SWITCH;
-      };
-      $form->{period} eq "11" && do {
-        $form->{fromdate} = "$form->{year}1101";
-        $form->{todate}   = "$form->{year}1130";
-        $form->{"0411"}   = "X";
-        last SWITCH;
-      };
-      $form->{period} eq "12" && do {
-        $form->{fromdate} = "$form->{year}1201";
-        $form->{todate}   = "$form->{year}1231";
-        $form->{"0412"}   = "X";
-        last SWITCH;
-      };
-    }
-
-  # Kontrollvariablen für die Templates
-  $form->{"year$_"} = ($form->{year} >= $_ ) ? "1":"0" for 2007..2107;
+  $ustva->set_FromTo(\%$form);
 
   # Get the USTVA
   $ustva->ustva(\%myconfig, \%$form);
@@ -737,8 +644,8 @@ sub generate_ustva {
 
   if ($form->{address} ne '') {
     my $temp = $form->{address};
-    $temp =~ s/\\n/<br \/>/;
-    ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
+    $temp =~ s/\n/<br \/>/;
+    ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp,2);
     $form->{co_city} =~ s/\\n//g;
   }
 
@@ -752,32 +659,10 @@ sub generate_ustva {
 
   if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') {
 
-    #
-    # Outputformat specific customisation's
-    #
-
-    my @category_cent = $ustva->report_variables({
-        myconfig    => \%myconfig,
-        form        => $form,
-        type        => '',
-        attribute   => 'position',
-        dec_places  => '2',
-    });
-
-    push @category_cent, qw(Z43  Z45  Z53  Z62  Z65  Z67);
-
-    my @category_euro = $ustva->report_variables({
-        myconfig    => \%myconfig,
-        form        => $form,
-        type        => '',
-        attribute   => 'position',
-        dec_places  => '0',
-    });
+   $form->{id} = [];
+   $form->{amount} = [];
 
-    $form->{id} = [];
-    $form->{amount} = [];
-
-    if ( $form->{format} eq 'pdf' or $form->{format} eq 'postscript') {
+   if ( $form->{format} eq 'pdf' or $form->{format} eq 'postscript') {
 
       $form->{IN} = "$form->{type}-$form->{year}.tex";
       $form->{padding} = "~~";
@@ -787,14 +672,14 @@ sub generate_ustva {
 
       # Zahlenformatierung für Latex USTVA Formulare
 
-      foreach my $number (@category_euro) {
+      foreach my $number (@{$::form->{category_euro}}) {
         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '');
       }
 
       my ${decimal_comma} = ( $myconfig{numberformat} eq '1.000,00'
            or $myconfig{numberformat} eq '1000,00' ) ? ',':'.';
 
-      foreach my $number (@category_cent) {
+      foreach my $number (@{$::form->{category_cent}}) {
         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '');
         $form->{$number} =~ s/${decimal_comma}/~~/g;
       }
@@ -808,14 +693,15 @@ sub generate_ustva {
       $form->{br}      = "<br>";
       $form->{address} =~ s/\\n/\n/g;
 
-      foreach my $number (@category_cent) {
+      foreach my $number (@{$::form->{category_cent}}) {
         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '0');
       }
 
-      foreach my $number (@category_euro) {
+      foreach my $number (@{$::form->{category_euro}}) {
         $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '0');
       }
     } elsif ( $form->{format} eq '' ){ # No format error.
+
       $form->header;
       USTVA::error( $locale->text('Application Error. No Format given' ) . "!");
       $::dispatcher->end_request;
@@ -830,28 +716,12 @@ sub generate_ustva {
   } else  # Outputformat for generic output
   {
 
-    my @category_cent = $ustva->report_variables({
-        myconfig    => \%myconfig,
-        form        => $form,
-        type        => '',
-        attribute   => 'position',
-        dec_places  => '2',
-    });
-
-    my @category_euro = $ustva->report_variables({
-        myconfig    => \%myconfig,
-        form        => $form,
-        type        => '',
-        attribute   => 'position',
-        dec_places  => '0',
-    });
-
     $form->{USTVA} = [];
 
     if ( $form->{format} eq 'generic') { # Formatierungen für HTML Ausgabe
 
       my $rec_ref = {};
-      for my $kennziffer (@category_cent, @category_euro) {
+      for my $kennziffer (@{$::form->{category_cent}}, @{$::form->{category_euro}}) {
         $rec_ref = {};
         $rec_ref->{id} = $kennziffer;
         $rec_ref->{amount} = $form->format_amount(\%myconfig, $form->{$kennziffer}, 2, '0');
@@ -885,6 +755,8 @@ sub generate_ustva {
 
     print($form->parse_html_template('ustva/generic_taxreport', $template_ref));
 
+  } elsif ( $form->{format} eq 'elstertaxbird' ) {
+   $form->parse_template(\%myconfig);
   } else
   {
    # add a prefix for ustva pos numbers, i.e.: 81 ->  post_ustva_81
@@ -912,22 +784,24 @@ $::form->{title} = $::locale->text('Tax Office Preferences');
   $::form->header;
 
   my $ustva = USTVA->new();
-  $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini');
+  $ustva->get_config();
+  $ustva->get_finanzamt();
 
-  my $land = $::form->{elsterland};
-  my $amt  = $::form->{elsterFFFF};
+  my $land = $::form->{fa_land_nr};
+  my $amt  = $::form->{fa_bufa_nr};
 
 
   $::form->{title} = $::locale->text('Tax Office Preferences');
 
 
   my $select_tax_office               = $ustva->fa_auswahl($land, $amt, $ustva->query_finanzamt(\%::myconfig, $::form));
-  my $checked_accrual                 = $::form->{method}        eq 'accrual' ? q|checked="checked"| : '';
-  my $checked_cash                    = $::form->{method}        eq 'cash'    ? q|checked="checked"| : '';
-  my $checked_monthly                 = $::form->{FA_voranmeld}  eq 'month'   ? "checked"            : '';
-  my $checked_quarterly               = $::form->{FA_voranmeld}  eq 'quarter' ? "checked"            : '';
-  my $checked_dauerfristverlaengerung = $::form->{FA_dauerfrist} eq '1'       ? "checked"            : '';
-  my $checked_kz_71                   = $::form->{FA_71}         eq 'X'       ? "checked"            : '';
+  my $method_local = ($::form->{accounting_method} eq 'accrual') ? $::locale->text('accrual')
+                   : ($::form->{accounting_method} eq 'cash')    ? $::locale->text('cash')
+                   : '';
+
+  my $checked_monthly                 = $::form->{fa_voranmeld}  eq 'month'   ? "checked"            : '';
+  my $checked_quarterly               = $::form->{fa_voranmeld}  eq 'quarter' ? "checked"            : '';
+  my $checked_dauerfristverlaengerung = $::form->{da_dauerfrist} eq '1'       ? "checked"            : '';
 
   my $_hidden_variables_ref;
 
@@ -942,34 +816,20 @@ $::form->{title} = $::locale->text('Tax Office Preferences');
         { 'variable' => $variable, 'value' => $_hidden_local_variables{$variable} };
   }
 
-  my @_hidden_form_variables = qw(
-    FA_Name             FA_Strasse        FA_PLZ
-    FA_Ort              FA_Telefon        FA_Fax
-    FA_PLZ_Grosskunden  FA_PLZ_Postfach   FA_Postfach
-    FA_BLZ_1            FA_Kontonummer_1  FA_Bankbezeichnung_1
-    FA_BLZ_2            FA_Kontonummer_2  FA_Bankbezeichnung_oertlich
-    FA_Oeffnungszeiten  FA_Email          FA_Internet
-    steuernummer        elsterland        elstersteuernummer
-    elsterFFFF
-  );
+  my @_hidden_form_variables = $ustva->get_fiamt_vars();
+  push @_hidden_form_variables ,qw(fa_bufa_nr taxnumber accounting_method coa);
 
   foreach my $variable (@_hidden_form_variables) {
     push @{ $_hidden_variables_ref},
         { 'variable' => $variable, 'value' => $::form->{$variable} };
   }
 
-# Which COA is in use?
-
   $ustva->get_coa($::form); # fetches coa and modifies some form variables
 
-  # hä? kann die weg?
-  my $steuernummer_new = '';
-
   # Variablen für das Template zur Verfügung stellen
   my $template_ref = {
      select_tax_office               => $select_tax_office,
-     checked_accrual                 => $checked_accrual,
-     checked_cash                    => $checked_cash,
+     method_local                    => $method_local,
      checked_monthly                 => $checked_monthly,
      checked_quarterly               => $checked_quarterly,
      checked_dauerfristverlaengerung => $checked_dauerfristverlaengerung,
@@ -994,97 +854,84 @@ sub config_step2 {
 
   $form->header();
 
-  my $elsterland         = '';
-  my $elster_amt         = '';
-  my $elsterFFFF         = '';
-  my $elstersteuernummer = '';
+  my $fa_land_nr         = '';
+  my $fa_bufa_nr         = '';
 
   my $ustva = USTVA->new();
-  $ustva->get_config($::lx_office_conf{paths}{userspath}, 'finanzamt.ini')
-    if ($form->{saved} eq $locale->text('saved'));
+  $ustva->get_config() if ($form->{saved} eq $locale->text('saved'));
+  my $coa = $::form->{coa};
+  $form->{"COA_$coa"}  = '1';
+  $form->{COA_Germany} = '1' if ($coa =~ m/^germany/i);
+  $ustva->get_finanzamt();
+
 
   # Auf Übergabefehler checken
   USTVA::info(  $locale->text('Missing Tax Authoritys Preferences') . "\n"
               . $locale->text('USTVA-Hint: Tax Authoritys'))
-    if (   $form->{elsterFFFF_new} eq 'Auswahl'
-        || $form->{elsterland_new} eq 'Auswahl');
+    if (   $form->{fa_bufa_nr_new} eq 'Auswahl'
+        || $form->{fa_land_nr_new} eq 'Auswahl');
   USTVA::info(  $locale->text('Missing Method!') . "\n"
               . $locale->text('USTVA-Hint: Method'))
-    if ($form->{method} eq '');
+    if ($form->{accounting_method} eq '');
 
-  # Klären, ob Variablen bereits befüllt sind UND ob veräderungen auf
+  # Klären, ob Variablen bereits befüllt sind UND ob veränderungen auf
   # der vorherigen Maske stattfanden: $change = 1(in der edit sub,
   # mittels get_config)
 
-  my $change = $form->{elsterland} eq $form->{elsterland_new}
-    && $form->{elsterFFFF} eq $form->{elsterFFFF_new} ? '0' : '1';
+#  $::lxdebug->message(LXDebug->DEBUG2,"land old=".$form->{fa_land_nr}." new=".$form->{fa_land_nr_new});
+#  $::lxdebug->message(LXDebug->DEBUG2,"bufa old=".$form->{fa_bufa_nr}." new=".$form->{fa_bufa_nr_new});
+  my $change = $form->{fa_land_nr} eq $form->{fa_land_nr_new}
+    && $form->{fa_bufa_nr} eq $form->{fa_bufa_nr_new} ? '0' : '1';
   $change = '0' if ($form->{saved} eq $locale->text('saved'));
-  my $elster_init = $ustva->query_finanzamt(\%myconfig, $form);
 
-  my %elster_init = %$elster_init;
 
   if ($change eq '1') {
 
     # Daten ändern
-    $elsterland           = $form->{elsterland_new};
-    $elsterFFFF           = $form->{elsterFFFF_new};
-    $form->{elsterland}   = $elsterland;
-    $form->{elsterFFFF}   = $elsterFFFF;
-    $form->{steuernummer} = '';
+    $fa_land_nr           = $form->{fa_land_nr_new};
+    $fa_bufa_nr           = $form->{fa_bufa_nr_new};
+    $form->{fa_land_nr}   = $fa_land_nr;
+    $form->{fa_bufa_nr}   = $fa_bufa_nr;
+    $form->{taxnumber} = '';
 
     create_steuernummer();
 
     # rebuild elster_amt
-    my $amt = $elster_init{$elsterFFFF};
-
-    # load the predefined hash data into the FA_* Vars
-    my @variables = qw(FA_Name FA_Strasse FA_PLZ FA_Ort
-      FA_Telefon FA_Fax FA_PLZ_Grosskunden FA_PLZ_Postfach
-      FA_Postfach
-      FA_BLZ_1 FA_Kontonummer_1 FA_Bankbezeichnung_1
-      FA_BLZ_2 FA_Kontonummer_2 FA_Bankbezeichnung_oertlich
-      FA_Oeffnungszeiten FA_Email FA_Internet);
-
-    for (my $i = 0; $i <= 20; $i++) {
-      $form->{ $variables[$i] } =
-        $elster_init->{$elsterland}->{$elsterFFFF}->[$i];
-    }
+    $ustva->get_finanzamt();
 
   } else {
 
-    $elsterland = $form->{elsterland};
-    $elsterFFFF = $form->{elsterFFFF};
+    $fa_land_nr = $form->{fa_land_nr};
+    $fa_bufa_nr = $form->{fa_bufa_nr};
 
   }
-  my $stnr = $form->{steuernummer};
+#  $::lxdebug->message(LXDebug->DEBUG2, "form stnr=".$form->{taxnumber}." fa_bufa_nr=".$fa_bufa_nr.
+#                      " pattern=".$form->{elster_pattern}." fa_land_nr=".$fa_land_nr);
+  my $stnr = $form->{taxnumber};
   $stnr =~ s/\D+//g;
-  my $patterncount   = $form->{patterncount};
-  my $elster_pattern = $form->{elster_pattern};
-  my $delimiter      = $form->{delimiter};
-  my $steuernummer   = $stnr eq '' ? $form->{steuernummer} : '';
+  my $taxnumber      = $stnr eq '' ? $form->{taxnumber} : '';
 
-  $form->{FA_Oeffnungszeiten} =~ s/\\\\n/\n/g;
+  $form->{fa_oeffnungszeiten} =~ s/\\\\n/\n/g;
 
 
   $ustva->get_coa($form); # fetches coa and modifies some form variables
 
   my $input_steuernummer = $ustva->steuernummer_input(
-                             $form->{elsterland},
-                             $form->{elsterFFFF},
-                             $form->{steuernummer}
+                             $fa_land_nr,
+                             $fa_bufa_nr,
+                             $form->{taxnumber}
   );
 
-  $::lxdebug->message(LXDebug->DEBUG1, qq|$input_steuernummer|);
+#  $::lxdebug->message(LXDebug->DEBUG2, qq|$input_steuernummer|);
 
 
   my $_hidden_variables_ref;
 
   my %_hidden_local_variables = (
-      'elsterland'          => $elsterland,
-      'elsterFFFF'          => $elsterFFFF,
+      'fa_land_nr'          => $fa_land_nr,
+      'fa_bufa_nr'          => $fa_bufa_nr,
       'warnung'             => 0,
-      'elstersteuernummer'  => $elstersteuernummer,
-      'steuernummer'        => $stnr,
+      'taxnumber'           => $stnr,
       'lastsub'             => 'config_step1',
       'nextsub'             => 'save',
 
@@ -1096,12 +943,11 @@ sub config_step2 {
   }
 
   my @_hidden_form_variables = qw(
-    FA_steuerberater_name   FA_steuerberater_street
-    FA_steuerberater_city   FA_steuerberater_tel
-    FA_voranmeld            method
-    FA_dauerfrist           FA_71
-    elster
-    type                    elster_init
+    fa_dauerfrist fa_steuerberater_city fa_steuerberater_name
+    fa_steuerberater_street fa_steuerberater_tel 
+    fa_voranmeld fa_dauerfrist
+    accounting_method
+    type
     saved                   callback
   );
 
@@ -1114,6 +960,7 @@ sub config_step2 {
      input_steuernummer              => $input_steuernummer,
      readonly                        => '', #q|disabled="disabled"|,
      callback                        => $form->{callback},
+     COA_Germany                     => $form->{COA_Germany},
      hidden_variables                => $_hidden_variables_ref,
   };
 
@@ -1131,34 +978,31 @@ sub create_steuernummer {
 
   my $part           = $::form->{part};
   my $patterncount   = $::form->{patterncount};
-  my $delimiter      = $::form->{delimiter};
+  my $delimiter      = $::form->{delimiter1};
   my $elster_pattern = $::form->{elster_pattern};
 
-  # rebuild steuernummer and elstersteuernummer
-  # es gibt eine gespeicherte steuernummer $form->{steuernummer}
+  # rebuild taxnumber
+  # es gibt eine gespeicherte steuernummer $form->{taxnumber}
   # und die parts und delimiter
 
   my $h = 0;
   my $i = 0;
 
-  my $steuernummer_new       = $part;
-  my $elstersteuernummer_new = $::form->{elster_FFFF};
-  $elstersteuernummer_new .= '0';
+  my $taxnumber_new       = $part;
 
   for ($h = 1; $h < $patterncount; $h++) {
-    $steuernummer_new .= qq|$delimiter|;
+    $delimiter = $::form->{delimiter2} if $h > 1;
+    $taxnumber_new .= qq|$delimiter|;
     for (my $i = 1; $i <= length($elster_pattern); $i++) {
-      $steuernummer_new       .= $::form->{"part_$h\_$i"};
-      $elstersteuernummer_new .= $::form->{"part_$h\_$i"};
+      $taxnumber_new       .= $::form->{"part_$h\_$i"};
     }
   }
-  if ($::form->{steuernummer} ne $steuernummer_new) {
-    $::form->{steuernummer}       = $steuernummer_new;
-    $::form->{elstersteuernummer} = $elstersteuernummer_new;
-    $::form->{steuernummer_new}   = $steuernummer_new;
+#  $::lxdebug->message(LXDebug->DEBUG2, "oldstnr=".$::form->{taxnumber}." newstnr=".$taxnumber_new);
+  if ($::form->{taxnumber} ne $taxnumber_new) {
+    $::form->{taxnumber}       = $taxnumber_new;
+    $::form->{taxnumber_new}   = $taxnumber_new;
   } else {
-    $::form->{steuernummer_new}       = '';
-    $::form->{elstersteuernummer_new} = '';
+    $::form->{taxnumber_new}       = '';
   }
   $::lxdebug->leave_sub();
 }
@@ -1168,56 +1012,23 @@ sub save {
 
   $::auth->assert('advance_turnover_tax_return');
 
-  my $filename = "$::myconfig{login}_$::form->{filename}";
-  $filename =~ s|.*/||;
-
   #zuerst die steuernummer aus den part, parts_X_Y und delimiter herstellen
   create_steuernummer();
 
   # Textboxen formatieren: Linebreaks entfernen
   #
-  $::form->{FA_Oeffnungszeiten} =~ s/\r\n/\\n/g;
+  $::form->{fa_oeffnungszeiten} =~ s/\r\n/\\n/g;
 
   #URL mit http:// davor?
-  $::form->{FA_Internet} =~ s/^http:\/\///;
-  $::form->{FA_Internet} = 'http://' . $::form->{FA_Internet};
-
-  my @config = qw(
-    elster              elsterland            elstersteuernummer  steuernummer
-    elsteramt           elsterFFFF            FA_Name             FA_Strasse
-    FA_PLZ              FA_Ort                FA_Telefon          FA_Fax
-    FA_PLZ_Grosskunden  FA_PLZ_Postfach       FA_Postfach         FA_BLZ_1
-    FA_Kontonummer_1    FA_Bankbezeichnung_1  FA_BLZ_2            FA_Kontonummer_2
-    FA_Bankbezeichnung_oertlich FA_Oeffnungszeiten
-    FA_Email FA_Internet FA_voranmeld method FA_steuerberater_name
-    FA_steuerberater_street FA_steuerberater_city FA_steuerberater_tel
-    FA_71 FA_dauerfrist);
-
-  # Hier kommt dann die Plausibilitätsprüfung der ELSTERSteuernummer
-  if ($::form->{elstersteuernummer} ne '000000000') {
-
-    $::form->{elster} = '1';
+  $::form->{fa_internet} =~ s/^http:\/\///;
+  $::form->{fa_internet} = 'http://' . $::form->{fa_internet};
 
-    open my $ustvaconfig, ">", "$::lx_office_conf{paths}{userspath}/$filename" or $::form->error("$filename : $!");
+  # Hier kommt dann die Plausibilitätsprüfung der ELSTERSteuernummer TODO ??
+  if (1) {
+    my $ustva = USTVA->new();
+    $ustva->save_config();
 
-    # create the config file
-    print {$ustvaconfig} qq|# Configuration file for USTVA\n\n|;
-    my $key = '';
-    foreach $key (sort @config) {
-      $::form->{$key} =~ s/\\/\\\\/g;
-      # strip M
-      $::form->{$key} =~ s/\r\n/\n/g;
-
-      print {$ustvaconfig} qq|$key=|;
-      if ($::form->{$key} ne 'Y') {
-        print {$ustvaconfig} qq|$::form->{$key}\n|;
-      }
-      if ($::form->{$key} eq 'Y') {
-        print {$ustvaconfig} qq|checked \n|;
-      }
-    }
-    print {$ustvaconfig} qq|\n\n|;
-    close $ustvaconfig;
+    #$::form->{elster} = '1';
     $::form->{saved} = $::locale->text('saved');
 
   } else {
diff --git a/config/kivitendo.conf.default b/config/kivitendo.conf.default
index 828c732bb..99d1ea3c1 100644
--- a/config/kivitendo.conf.default
+++ b/config/kivitendo.conf.default
@@ -93,6 +93,10 @@ spool = spool
 templates = templates
 # Path to the old memberfile (ignored on new installations)
 memberfile = users/members
+# Path to ELSTER geierlein webserver path inside kivitendo
+# (must be inside kivitendo but you can set an ALIAS for apache/oe
+# if set the export to geierlein is enabled
+# geierlein_path = geierlein
 
 [mail_delivery]
 # Delivery method can be 'sendmail' or 'smtp'. For 'method = sendmail' the
diff --git a/doc/changelog b/doc/changelog
index e0ab63a72..77e9afadc 100644
--- a/doc/changelog
+++ b/doc/changelog
@@ -6,6 +6,8 @@
 
 kleinere neue Features und Detailverbesserungen:
 
+  - Für UStVA Voranmeldung über Elster gibt es die Anbindung über Geierlein (Installation/Config siehe Commit)
+  
   - In der Lager-Mandantenkonfig gibt es das Feature "Zum Fertigen Standardlager des Bestandteils verwenden".
     Statt das Ziellager des Erzeugnisses zu Verwenden, wird nun zur Prüfung der Fertigung das
     Standardlager der einzelnen Bestandteile verwendet.
diff --git a/locale/de/all b/locale/de/all
index 41fae9324..e05ea089d 100755
--- a/locale/de/all
+++ b/locale/de/all
@@ -129,6 +129,7 @@ $self->{texts} = {
   'Account number not unique!'  => 'Kontonummer bereits vorhanden!',
   'Account number of the goal/source' => 'Ziel- oder Quellkonto',
   'Account saved!'              => 'Konto gespeichert!',
+  'Accounting desired'          => 'Verrechnung des Erstattungsbetrags erwünscht',
   'Accounting method'           => 'Versteuerungsart',
   'Accrual'                     => 'Soll-Versteuerung',
   'Accrual accounting'          => 'Soll-Versteuerung',
@@ -242,7 +243,6 @@ $self->{texts} = {
   'Alternatively you can create a new part which will then be selected.' => 'Sie k&ouml;nnen auch einen neuen Artikel anlegen, der dann automatisch ausgew&auml;hlt wird.',
   'Always save orders with a projectnumber (create new projects)' => 'Aufträge immer mit Projektnummer speichern (neue Projekt erstellen)',
   'Amended Advance Turnover Tax Return' => 'Berichtigte Anmeldung',
-  'Amended Advance Turnover Tax Return (Nr. 10)' => 'Ist dies eine berichtigte Anmeldung? (Nr. 10/Zeile 15 Steuererklärung)',
   'Amount'                      => 'Betrag',
   'Amount (for verification)'   => 'Betrag (zur Überprüfung)',
   'Amount BB'                   => 'Betrag Buchungen',
@@ -923,6 +923,7 @@ $self->{texts} = {
   'Dial command missing in kivitendo configuration\'s [cti] section' => 'Wählbefehl fehlt im Abschnitt [cti] der kivitendo-Konfiguration',
   'Difference'                  => 'Differenz',
   'Dimensions'                  => 'Abmessungen',
+  'Direct debit revoked'        => 'Die Einzugsermächtigung wird widerrufen',
   'Directory'                   => 'Verzeichnis',
   'Disabled Price Sources'      => 'Deaktivierte Preisquellen',
   'Discard duplicate entries in CSV file' => 'Doppelte Einträge in CSV-Datei verwerfen',
@@ -1019,7 +1020,7 @@ $self->{texts} = {
   'EB-Wert'                     => 'EB-Wert',
   'EK'                          => 'EK',
   'ELSE'                        => 'Zusatz',
-  'ELSTER Tax Number'           => 'ELSTER-Steuernummer',
+  'ELSTER Export (via Geierlein)' => 'ELSTER Export (via Geierlein)',
   'EQUITY'                      => 'EIGENTUM',
   'EUER'                        => 'Einnahmen-/Überschussrechnung',
   'Earlier versions of kivitendo contained bugs which might have led to wrong entries in the general ledger.' => 'Frühere Versionen von kivitendo enthielten Bugs, die zu falschen Einträgen im Hauptbuch geführt haben können.',
@@ -1120,6 +1121,7 @@ $self->{texts} = {
   'Editable'                    => 'Bearbeitbar',
   'Either there are no open invoices, or you have already initiated bank transfers with the open amounts for those that are still open.' => 'Entweder gibt es keine offenen Rechnungen, oder es wurden bereits Überweisungen über die offenen Beträge aller offenen Rechnungen erstellt.',
   'Element disabled'            => 'Element deaktiviert',
+  'Email'                       => 'E-Mail',
   'Email journal'               => 'E-Mail-Journal',
   'Employee'                    => 'Bearbeiter',
   'Employee #1 saved!'          => 'Benutzer #1 gespeichert!',
@@ -1299,6 +1301,7 @@ $self->{texts} = {
   'For AP transactions it will replace the sales taxkeys with input taxkeys with the same tax rate.' => 'Bei Kreditorenbuchungen werden die Umsatzsteuer-Steuerschlüssel durch Vorsteuer-Steuerschlüssel mit demselben Steuersatz ersetzt.',
   'For AR transactions it will replace the input taxkeys with sales taxkeys with the same tax rate.' => 'Bei Debitorenbuchungen werden die Vorsteuer-Steuerschlüssel durch Umsatzsteuer-Steuerschlüssel mit demselben Steuersatz ersetzt.',
   'For all delivery orders create and print invoices' => 'Erstelle und drucke Rechnungen für alle Lieferscheine',
+  'For changeing goto USTVA Config' => 'Zum Verändern bitte zu den UStVa Einstellungen gehen',
   'For further information read this: ' => 'Für weitere Informationen zu diesem Thema lesen Sie bitte: ',
   'For part "#1" there are missing #2 #3 in the default warehouse/bin "#4/#5".' => 'Es fehlen #2 #3 des Artikels "#1" im Standardlager "#4/#5".',
   'For part "#1" there is no default warehouse and bin defined.' => 'Für Artikel "#1" ist kein Standardlager/-lagerplatz angegeben.',
@@ -1943,7 +1946,6 @@ $self->{texts} = {
   'Out of balance transaction!' => 'Buchung ist nicht ausgeglichen!',
   'Out of balance!'             => 'Summen stimmen nicht überein!',
   'Output Number Format'        => 'Zahlenformat (Ausgabe)',
-  'Outputformat'                => 'Ausgabeformat',
   'Overdue sales quotations and requests for quotations' => 'Überfällige Angebote und Preisanfragen',
   'Override'                    => 'Override',
   'Override invoice language'   => 'Diese Sprache verwenden',
@@ -1956,6 +1958,7 @@ $self->{texts} = {
   'PDF'                         => 'PDF',
   'PDF (OpenDocument/OASIS)'    => 'PDF (OpenDocument/OASIS)',
   'PDF export -- options'       => 'PDF-Export -- Optionen',
+  'PLZ Grosskunden'             => 'PLZ Grosskunden',
   'POSTED'                      => 'Gebucht',
   'POSTED AS NEW'               => 'Als neu gebucht',
   'PRINTED'                     => 'Gedruckt',
@@ -2238,6 +2241,7 @@ $self->{texts} = {
   'Receipt posted!'             => 'Beleg gebucht!',
   'Receipt, payment, reconciliation' => 'Zahlungseingang, Zahlungsausgang, Kontenabgleich',
   'Receipts'                    => 'Zahlungseingänge',
+  'Receipts attached/extra'     => 'Belege werden gesondert eingereicht',
   'Receivable account'          => 'Forderungskonto',
   'Receivables'                 => 'Forderungen',
   'Receivables account'         => 'Forderungskonto',
@@ -3134,6 +3138,7 @@ $self->{texts} = {
   'To (email)'                  => 'An',
   'To (time)'                   => 'Bis',
   'To Date'                     => 'Bis',
+  'To Geierlein'                => 'In Geierlein ELSTER Anwendung übernehmen',
   'To continue please change the taxkey 0 to another value.' => 'Um fortzufahren, ändern Sie bitte den Steuerschlüssel 0 auf einen anderen Wert.',
   'To user login'               => 'Zum Benutzerlogin',
   'Toggle marker'               => 'Markierung umschalten',
@@ -3202,6 +3207,7 @@ $self->{texts} = {
   'USTVA 2005'                  => 'USTVA 2005',
   'USTVA 2006'                  => 'USTVA 2006',
   'USTVA 2007'                  => 'USTVA 2007',
+  'USTVA Data sent to geierlein' => 'Daten sind an Geierlein ELSTER Anwendung übergeben',
   'USTVA-Hint: Method'          => 'Wenn Sie Ist-Versteuert sind, wählen Sie die Einnahmen-/Überschuß-Rechnung aus. Sind Sie Soll-Versteuert und bilanzverpflichtet, dann wählen Sie Bilanz aus.',
   'USTVA-Hint: Tax Authoritys'  => 'Bitte das Bundesland UND die Stadt bzw. den Einzugsbereich Ihres zuständigen Finanzamts auswählen.',
   'USt-IdNr.'                   => 'USt-IdNr.',
diff --git a/sql/Pg-upgrade2/defaults_add_finanzamt_data.sql b/sql/Pg-upgrade2/defaults_add_finanzamt_data.sql
new file mode 100644
index 000000000..a65c8605e
--- /dev/null
+++ b/sql/Pg-upgrade2/defaults_add_finanzamt_data.sql
@@ -0,0 +1,10 @@
+-- @tag: defaults_add_finanzamt_data
+-- @description: Fuer Umsatzsteuer Daten aus finanzamt.ini raus
+-- @depends: release_3_4_1
+ALTER TABLE defaults ADD COLUMN FA_BUFA_Nr text;
+ALTER TABLE defaults ADD COLUMN FA_dauerfrist text;
+ALTER TABLE defaults ADD COLUMN FA_steuerberater_city text;
+ALTER TABLE defaults ADD COLUMN FA_steuerberater_name text;
+ALTER TABLE defaults ADD COLUMN FA_steuerberater_street text;
+ALTER TABLE defaults ADD COLUMN FA_steuerberater_tel text;
+ALTER TABLE defaults ADD COLUMN FA_voranmeld text;
diff --git a/templates/webpages/client_config/_miscellaneous.html b/templates/webpages/client_config/_miscellaneous.html
index 0b04012d2..5183b7cca 100644
--- a/templates/webpages/client_config/_miscellaneous.html
+++ b/templates/webpages/client_config/_miscellaneous.html
@@ -21,7 +21,7 @@
 
   <tr>
    <td align="right">[% LxERP.t8("Tax number") %]</td>
-   <td>[% L.input_tag('defaults.taxnumber', SELF.defaults.taxnumber, style=style) %]</td>
+   <td>[% SELF.defaults.taxnumber %]&nbsp;&nbsp;<a href="ustva.pl?action=config_step1">([% LxERP.t8("For changeing goto USTVA Config") %])</a></td>
   </tr>
 
   <tr>
diff --git a/templates/webpages/ustva/config_step1.html b/templates/webpages/ustva/config_step1.html
index ad1f8b6b8..485098ee3 100644
--- a/templates/webpages/ustva/config_step1.html
+++ b/templates/webpages/ustva/config_step1.html
@@ -18,13 +18,9 @@
        <fieldset>
        <legend><b>[% 'Taxation' | $T8 %]</b>
        </legend>
-       <input name="method" id="accrual" class="radio" type="radio" value="accrual"
-         [% checked_accrual %]>
-       <label for="accrual">[% 'accrual' | $T8 %]</label>
-       <br>
-       <input name="method" id="cash" class="radio" type="radio" value="cash"
-         [% checked_cash %]>
-       <label for="cash">[% 'cash' | $T8 %]</label>
+            [%- IF method_local %]
+              [% method_local %]
+            [%- END %]
        </fieldset>
        <br>
        <fieldset>
@@ -32,15 +28,15 @@
        </legend>
 
 
-           <input name=FA_voranmeld id=month class=radio type=radio value="month"
+           <input name=fa_voranmeld id=month class=radio type=radio value="month"
              [% checked_monthly %]>
            <label for="month">[% 'month' | $T8 %]</label>
            <br>
-           <input name="FA_voranmeld" id=quarter class=radio type=radio value="quarter"
+           <input name="fa_voranmeld" id=quarter class=radio type=radio value="quarter"
              [% checked_quarterly %]>
            <label for="quarter">[% 'quarter' | $T8 %]</label>
            <br>
-           <input name="FA_dauerfrist" id=FA_dauerfrist class=checkbox type=checkbox value="1"
+           <input name="fa_dauerfrist" id=fa_dauerfrist class=checkbox type=checkbox value="1"
              [% checked_dauerfristverlaengerung %]>
            <label for="">[% 'Extension Of Time' | $T8 %]</label>
 
@@ -49,9 +45,9 @@
            <fieldset>
            <legend><b>[% 'Tax Consultant' | $T8 %]</b>
            </legend>
-          <!-- <input name="FA_71" id=FA_71 class=checkbox type=checkbox value="X"
+          <!-- <input name="fa_71" id=fa_71 class=checkbox type=checkbox value="X"
              [% checked_kz_71 %]>
-           <label for="FA_71">[% 'Clearing Tax Received (No 71)' | $T8 %]
+           <label for="fa_71">[% 'Clearing Tax Received (No 71)' | $T8 %]
     .      </label>
            <br>
            <br>-->
@@ -72,20 +68,20 @@
            </tr>
            <tr>
            <td>
-           <input name="FA_steuerberater_name" id=steuerberater size=25
-             value="[% HTML.escape(FA_steuerberater_name) %]">
+           <input name="fa_steuerberater_name" id=steuerberater size=25
+             value="[% HTML.escape(fa_steuerberater_name) %]">
            </td>
            <td>
-           <input name="FA_steuerberater_street" id=steuerberater size=25
-             value="[% HTML.escape(FA_steuerberater_street) %]">
+           <input name="fa_steuerberater_street" id=steuerberater size=25
+             value="[% HTML.escape(fa_steuerberater_street) %]">
            </td>
            <td>
-           <input name="FA_steuerberater_city" id=steuerberater size=25
-             value="[% HTML.escape(FA_steuerberater_city) %]">
+           <input name="fa_steuerberater_city" id=steuerberater size=25
+             value="[% HTML.escape(fa_steuerberater_city) %]">
            </td>
            <td>
-           <input name="FA_steuerberater_tel" id=steuerberater size=25
-             value="[% HTML.escape(FA_steuerberater_tel) %]">
+           <input name="fa_steuerberater_tel" id=steuerberater size=25
+             value="[% HTML.escape(fa_steuerberater_tel) %]">
            </tr>
            </table>
 
diff --git a/templates/webpages/ustva/config_step2.html b/templates/webpages/ustva/config_step2.html
index e04c721d2..a8a59c6cb 100644
--- a/templates/webpages/ustva/config_step2.html
+++ b/templates/webpages/ustva/config_step2.html
@@ -12,7 +12,7 @@
            <fieldset>
              <legend>
                <font size="+1">[% 'Tax Office' | $T8 %]
-               [% HTML.escape(FA_Name) %]</font>
+               [% HTML.escape(fa_name) %]</font>
              </legend>
              <table width="100%" valign="top">
                 <tr>
@@ -30,24 +30,33 @@
                         </tr>
                         <tr>
                           <td colspan="2">
-                            <input name="FA_Name" size="40" title="FA_Name"
-                              value="[% HTML.escape(FA_Name) %]" [% readonly %]>
+                            <input name="fa_name" size="40" title="Name"
+                              value="[% HTML.escape(fa_name) %]" [% readonly %]>
                           <td>
                         </tr>
                         <tr>
                           <td colspan="2">
-                            <input name="FA_Strasse" size="40" title="FA_Strasse"
-                              value="[% HTML.escape(FA_Strasse) %]" [% readonly %]>
-                          </td width="100%">
+                            <input name="fa_strasse" size="40" title="Strasse"
+                              value="[% HTML.escape(fa_strasse) %]" [% readonly %]>
+                          </td>
                         </tr>
                         <tr>
                           <td width="116px">
-                            <input name="FA_PLZ" size="10" title="FA_PLZ"
-                              value="[% HTML.escape(FA_PLZ) %]" [% readonly %]>
+                            <input name="fa_plz" size="10" title="PLZ"
+                              value="[% HTML.escape(fa_plz) %]" [% readonly %]>
+                          </td>
+                          <td>
+                            <input name="fa_ort" size="20" title="Ort"
+                              value="[% HTML.escape(fa_ort) %]" [% readonly %]>
+                          </td>
+                        </tr>
+                        <tr>
+                          <td>
+                            [% 'PLZ Grosskunden' | $T8 %]
                           </td>
                           <td>
-                            <input name="FA_Ort" size="20" title="FA_Ort"
-                              value="[% HTML.escape(FA_Ort) %]" [% readonly %]>
+                            <input name="fa_plz_grosskunden" size="20" title="OrtGK"
+                              value="[% HTML.escape(fa_plz_grosskunden) %]" [% readonly %]>
                           </td>
                         </tr>
                       </table>
@@ -58,22 +67,23 @@
                         <b>[% 'Contact' | $T8 %]</b>
                       </legend>
                         [% 'Telephone' | $T8 %]<br>
-                        <input name="FA_Telefon" size="40" title="FA_Telefon"
-                          value="[% HTML.escape(FA_Telefon) %]" [% readonly %]>
+                        <input name="fa_telefon" size="40" title="Telefon"
+                          value="[% HTML.escape(fa_telefon) %]" [% readonly %]>
                         <br>
                         <br>
                         [% 'Fax' | $T8 %]<br>
-                        <input name="FA_Fax" size="40" title="FA_Fax"
-                          value="[% HTML.escape(FA_Fax) %]" [% readonly %]>
+                        <input name="fa_fax" size="40" title="Fax"
+                          value="[% HTML.escape(fa_fax) %]" [% readonly %]>
                         <br>
                         <br>
-                        [% 'Internet' | $T8 %]<br>
-                        <input name="FA_Email" size="40" title="FA_Email"
-                          value="[% HTML.escape(FA_Email) %]" [% readonly %]>
+                        [% 'Email' | $T8 %]<br>
+                        <input name="fa_email" size="40" title="Email"
+                          value="[% HTML.escape(fa_email) %]" [% readonly %]>
                         <br>
+                        [% 'Internet' | $T8 %]<br>
                         <br>
-                        <input name="FA_Internet" size="40" title="" title="FA_Internet"
-                          value="[% HTML.escape(FA_Internet) %]" [% readonly %]>
+                        <input name="fa_internet" size="40" title="Internet"
+                          value="[% HTML.escape(fa_internet) %]" [% readonly %]>
                         <br>
                     </fieldset>
                   </td>
@@ -83,53 +93,53 @@
                     <legend>
                     <b>[% 'Openings' | $T8 %]</b>
                     </legend>
-                    <textarea name="FA_Oeffnungszeiten" rows="4" cols="40"
-                      [% readonly %]>[% HTML.escape(FA_Oeffnungszeiten) %]</textarea>
+                    <textarea name="fa_oeffnungszeiten" rows="4" cols="40"
+                      [% readonly %]>[% HTML.escape(fa_oeffnungszeiten) %]</textarea>
                     </fieldset>
                     <br>
                       <fieldset>
                       <legend>
                         <b>[% 'Bank Connection Tax Office' | $T8 %]</b>
-                      <legend>
+                      </legend>
                       <table>
                       <tr>
                         <td width="40%">
                           [% 'Bank' | $T8 %]
                           <br>
-                          <input name="FA_Bankbezeichnung_1" size="30"
-                            value="[% HTML.escape(FA_Bankbezeichnung_1) %]" [% readonly %]>
+                          <input name="fa_bankbezeichnung_1" size="30"
+                            value="[% HTML.escape(fa_bankbezeichnung_1) %]" [% readonly %]>
                           <br>
                           <br>
                           [% 'Account Nummer' | $T8 %]
                           <br>
-                          <input name="FA_Kontonummer_1" size="15"
-                            value="[% HTML.escape(FA_Kontonummer_1) %]" [% readonly %]>
+                          <input name="fa_kontonummer_1" size="15"
+                            value="[% HTML.escape(fa_kontonummer_1) %]" [% readonly %]>
                           <br>
                           <br>
                           [% 'Bank Code (long)' | $T8 %]
                           <br>
-                          <input name="FA_BLZ_1" size="15"
-                            value="[% HTML.escape(FA_BLZ_1) %]" [% readonly %]>
+                          <input name="fa_blz_1" size="15"
+                            value="[% HTML.escape(fa_blz_1) %]" [% readonly %]>
                         </td>
                         <td width="40%">
                           [% 'Bank' | $T8 %]
                           <br>
-                          <input name="FA_Bankbezeichnung_oertlich" size="30"
-                            value="[% HTML.escape(FA_Bankbezeichnung_oertlich) %]" [% readonly %]>
+                          <input name="fa_bankbezeichnung_2" size="30"
+                            value="[% HTML.escape(fa_bankbezeichnung_2) %]" [% readonly %]>
                           <br>
                           <br>
                           [% 'Account Nummer' | $T8 %]
                           <br>
-                          <input name="FA_Kontonummer_2" size="15"
-                            value="[% HTML.escape(FA_Kontonummer_2) %]" [% readonly %]>
+                          <input name="fa_kontonummer_2" size="15"
+                            value="[% HTML.escape(fa_kontonummer_2) %]" [% readonly %]>
                           <br>
                           <br>
                           [% 'Bank Code (long)' | $T8 %]
                           <br>
-                          <input name="FA_BLZ_2" size="15"
-                            value="[% HTML.escape(FA_BLZ_2) %]" [% readonly %]>
+                          <input name="fa_blz_2" size="15"
+                            value="[% HTML.escape(fa_blz_2) %]" [% readonly %]>
                         </td>
-                   </tr>
+              </tr>
              </table>
            </fieldset>
          </td>
@@ -157,7 +167,7 @@
 [%- END %]
 
 
-           </H2><br>
+           <br>
            </fieldset>
            <br>
            <br>
@@ -186,7 +196,6 @@
           [%- ELSE %]
 
             <input type="hidden" name="nextsub" value="save">
-            <input type="hidden" name="filename" value="finanzamt.ini">
             <input type="submit" class="submit" name="action" value="[% 'Save' | $T8 %]">
 
           [%- END %]
diff --git a/templates/webpages/ustva/report.html b/templates/webpages/ustva/report.html
index 998bbfdd7..dacbebcbb 100644
--- a/templates/webpages/ustva/report.html
+++ b/templates/webpages/ustva/report.html
@@ -2,8 +2,9 @@
 [% USE HTML %]
 <h1>[% HTML.escape(title) %]</h1>
 
- <form method="post" action="[% HTML.escape(script) %]">
+ <form method="post" id="form_do" action="[% HTML.escape(script) %]">
 
+ [%- INCLUDE 'common/flash.html' %]
  <input type="hidden" name="title" value="[% HTML.escape(title) %]">
 
  <table width="100%">
@@ -37,22 +38,18 @@
 [%- IF COA_Germany %]
             [% taxnumber_given %]
             <br />
-            [% 'ELSTER Tax Number' | $T8 %]:&nbsp;
-            [% HTML.escape(elstersteuernummer) %]
-            <br />
-            <br />
 [%- ELSE %]
             [% taxnumber %]
 [%- END %]
             </fieldset>
             <br />
 
-            [%- IF FA_steuerberater_name %]
+            [%- IF fa_steuerberater_name %]
               <fieldset>
               <legend>
                 <input checked="checked"
                  title="[% 'Assume Tax Consultant Data in Tax Computation?' | $T8 %]"
-                 name="FA_steuerberater"
+                 name="fa_steuerberater"
                  id="steuerberater"
                  class="checkbox"
                  type="checkbox"
@@ -60,10 +57,10 @@
                  &nbsp;<b>[% 'Tax Consultant' | $T8 %]</b>
                 </legend>
 
-                [% HTML.escape(FA_steuerberater_name) %]<br />
-                [% HTML.escape(FA_steuerberater_street) %]<br />
-                [% HTML.escape(FA_steuerberater_city) %]<br />
-                [% 'Tel.' | $T8 %] [% HTML.escape(FA_steuerberater_tel) %]<br />
+                [% HTML.escape(fa_steuerberater_name) %]<br />
+                [% HTML.escape(fa_steuerberater_street) %]<br />
+                [% HTML.escape(fa_steuerberater_city) %]<br />
+                [% 'Tel.' | $T8 %] [% HTML.escape(fa_steuerberater_tel) %]<br />
               </fieldset>
               <br />
             [%- END %]
@@ -73,12 +70,17 @@
             <b>[% 'Tax Period' | $T8 %]</b>
             </legend>
             [% select_year %] [% ustva_vorauswahl %]
+            <br />
             [% checkbox_kz_10 %]
+            [% checkbox_kz_22 %]
             <br />
-            [%- IF FA_voranmeld %]
+            [% checkbox_kz_29 %]
+            [% checkbox_kz_26 %]
+            <br />
+            [%- IF fa_voranmeld %]
               <br />
               [% period_local %]
-              [%- IF FA_dauerfrist %]
+              [%- IF fa_dauerfrist %]
                 [% 'With Extension Of Time' | $T8 %]
               [%- END %]
               <br />
@@ -94,32 +96,32 @@
               <legend>
                  <b>[% 'Tax Office' | $T8 %]</b>
               </legend>
-              <h3>[% HTML.escape(FA_Name) %]</h3>
+              <h3>[% fa_name_given %]</h3>
 
-              [% HTML.escape(FA_Strasse) %]
+              [% HTML.escape(fa_strasse) %]
               <br>
-              [% HTML.escape(FA_PLZ) %]&nbsp; &nbsp;[% HTML.escape(FA_Ort) %]
+              [% HTML.escape(fa_plz) %]&nbsp; &nbsp;[% HTML.escape(fa_ort) %]
               <br>
               <br>
               [% 'Tel' | $T8 %].:&nbsp;
-              [% HTML.escape(FA_Telefon) %]
+              [% HTML.escape(fa_telefon) %]
               <br>
               [% 'Fax' | $T8 %].:&nbsp;
-              [% HTML.escape(FA_Fax) %]
+              [% HTML.escape(fa_fax) %]
               <br>
               <br>
               <!-- Mailto alles Maskieren! -->
-              <a href="mailto:[% HTML.escape(FA_Email) %]
-                ?subject=&quot;[% HTML.escape(steuernummer) %]:&quot;
+              <a href="mailto:[% HTML.escape(fa_email) %]
+                ?subject=&quot;[% HTML.escape(taxnumber) %]:&quot;
                 &amp;bcc=&quot;[% HTML.escape(email) %]&quot;
                 &amp;body=&quot;Sehr%20geehrte%20Damen%20und%20Herren,
                 %0D%0A%0D%0A%0D%0AMit%20freundlichen%20Gr&uuml;&szlig;en
                 %0D%0A%0D%0A[% HTML.escape(signature) %]&quot;">
-              [% HTML.escape(FA_Email) %]
+              [% HTML.escape(fa_email) %]
               </a>
               <br>
-              <a href="[% FA_Internet %]">
-              [% HTML.escape(FA_Internet) %]
+              <a href="[% fa_internet %]">
+              [% HTML.escape(fa_internet) %]
               </a>
               <br>
               <br>
@@ -132,7 +134,7 @@
               <table>
               <tr>
 
-              [%- FOREACH row = "tax_office_banks" %]
+              [%- FOREACH row = tax_office_banks %]
                   <td width="40%">
                   [% HTML.escape(row.Bankbezeichnung) %]
                   <br>
@@ -148,22 +150,6 @@
               </table>
               <br>
               </fieldset>
-
-              <br>
-
-              <fieldset>
-              <legend>
-              <b>[% 'Outputformat' | $T8 %]</b>
-              </legend>
-[%- IF COA_Germany %]
-              [% select_options %]
-[%- ELSE %]
-              <SELECT name="format">
-                <option value="generic">[% 'Preview' | $T8 %]</option>
-              </SELECT>
-[%- END %]
-
-              </fieldset>
           </td>
         </tr>
       </table>
@@ -177,17 +163,42 @@
   <br>
   <input type="hidden" name="address" value="[% HTML.escape(address) %]">
   <input type="hidden" name="reporttype" value="custom">
+  <input type="hidden" name="co_zip" value="[% HTML.escape(co_zip) %]">
+  <input type="hidden" name="co_tel" value="[% HTML.escape(co_tel) %]">
+  <input type="hidden" name="co_email" value="[% HTML.escape(co_email) %]">
   <input type="hidden" name="co_street" value="[% HTML.escape(co_street) %]">
   <input type="hidden" name="co_city" value="[% HTML.escape(co_city) %]">
+  <input type="hidden" name="account_method" value="[% HTML.escape(account_method) %]">
+  <input type="hidden" name="fa_bufa_nr" value="[% HTML.escape(fa_bufa_nr) %]">
   <table width="100%">
   <tr>
    <td align="left">
      <input type=hidden name=nextsub value=generate_ustva>
+     <input type=hidden name=format  value=html>
      <input type=submit class=submit name=action value="[% 'Show' | $T8 %]">
    </td>
+[%- IF geierlein_enabled %]
+   <td align="left">
+     <input type=button class=submit onclick="return sendGeierlein();" value="[% 'To Geierlein' | $T8 %]">
+   </td>
+[%- END %]
    <td align="right">
-
-    </form>
    </td>
   </tr>
   </table>
+</form>
+[%- IF geierlein_enabled && geierlein_path %]
+<script type='text/javascript'>
+function sendGeierlein () {
+ kivi.submit_ajax_form('controller.pl?action=ODGeierlein/send', $('#form_do'));
+ return false;
+}
+
+function openGeierlein(myimport) {
+localStorage["geierlein.import"] = myimport;
+var geierpath = '[% geierlein_path %]';
+window.open(geierpath + '/#importLocalStorage','_blank','');
+return false;
+}
+</script>
+[%- END %]
