+use List::Util qw(first);
+
+use SL::DBUtils;
+
+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', },
+  );
+
+sub new {
+  my $type = shift;
+
+  my $self = {};
+
+  bless $self, $type;
+
+  $self->_init(@_);
+
+  return $self;
+}
+
+sub _init {
+  my $self = shift;
+
+  $self->{tax_office_information} = [];
+
+  foreach (@tax_office_information) {
+    my $entry      = \%{ $_ };
+    $entry->{name} = $::locale->{iconv_utf8}->convert($entry->{name});
+    push @{ $self->{tax_office_information} }, $entry;
+  }
+}
+
+sub get_coa {
+
+  my ( $self, $form, $myconfig) = @_;
+
+  my $query = q{ SELECT coa FROM defaults };
+
+  my $dbh = $form->dbconnect($myconfig);
+  my $sth = $dbh->prepare($query);
+  $sth->execute() || $form->dberror($query);
+
+  my ($coa) = selectrow_query($form, $dbh, $query);
+
+  $sth->finish;
+  $dbh->disconnect;
+
+  $form->{coa} = $coa;
+  $form->{"COA_$coa"} = '1';
+  $form->{COA_Germany} = '1' if ($coa =~ m/^germany/i);
+
+  return;
+}
+
+
+sub report_variables {
+  # Get all positions for taxreport out of the database
+  # Needs Databaseupdate Pg-upgrade2/USTVA_abstraction.pl
+
+  return unless defined wantarray;
+
+  my ( $self,
+       $arg_ref) = @_;
+
+  my $myconfig   = $arg_ref->{myconfig};
+  my $form       = $arg_ref->{form};
+  my $type       = $arg_ref->{type}; # 'paied' || 'received' || ''
+  my $attribute  = $arg_ref->{attribute}; #
+  my $dec_places = (defined $arg_ref->{dec_places}) ? $arg_ref->{dec_places}:undef;
+
+  my $where_type = $type ? "AND tax.report_headings.type = '$type'" : '';
+  my $where_dcp  = defined $dec_places ? "AND tax.report_variables.dec_places = '$dec_places'" : '';
+
+  my $query = qq|
+    SELECT $attribute
+    FROM tax.report_variables
+    LEFT JOIN tax.report_headings
+      ON (tax.report_variables.heading_id = tax.report_headings.id)
+    WHERE 1=1
+    $where_type
+    $where_dcp
+  |;
+
+  my $dbh = $form->dbconnect($myconfig);
+  my $sth = $dbh->prepare($query);
+
+  $sth->execute() || $form->dberror($query);
+
+  my @positions;
+
+  while ( my $row_ref = $sth->fetchrow_arrayref() ) {
+    push @positions, @$row_ref;  # Copy the array contents
+  }
+
+  $sth->finish;
+
+  $dbh->disconnect;
+
+  return @positions;
+
+}
+