+ ################################
+ #
+ # Nation specific customisations
+ #
+ ################################
+
+ # Germany
+
+ 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(83 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} = [];
+
+ if ( $form->{format} eq 'pdf' or $form->{format} eq 'postscript') {
+
+ $form->{IN} = "$form->{type}-$form->{year}.tex";
+ $form->{padding} = "~~";
+ $form->{bold} = "\textbf{";
+ $form->{endbold} = "}";
+ $form->{br} = '\\\\';
+
+ # Zahlenformatierung für Latex USTVA Formulare
+
+ foreach my $number (@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) {
+ $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '');
+ $form->{$number} =~ s/${decimal_comma}/~~/g;
+ }
+
+ } elsif ( $form->{format} eq 'html') { # Formatierungen für HTML Ausgabe
+
+ $form->{IN} = $form->{type} . '.html';
+ $form->{padding} = " ";
+ $form->{bold} = "<b>";
+ $form->{endbold} = "</b>";
+ $form->{br} = "<br>";
+ $form->{address} =~ s/\\n/\n/g;
+
+ foreach $number (@category_cent) {
+ $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '2', '0');
+ }
+
+ foreach $number (@category_euro) {
+ $form->{$number} = $form->format_amount(\%myconfig, $form->{$number}, '0', '0');
+ }
+
+ } elsif ( $form->{format} eq 'elsterwinston' ) {
+
+ $form->{IN} = 'winston.xml';
+
+ #
+ # Build Winston filename
+ #
+
+ my $file = 'U'; # 1. char 'U' = USTVA
+ $file .= $form->{period};
+ #4. and 5. char = year modulo 100
+ $file .= sprintf("%02d", $form->{year} % 100);
+ #6. to 18. char = Elstersteuernummer
+ #Beispiel: Steuernummer in Bayern
+ #111/222/33334 ergibt für UStVA Jan 2004: U01049111022233334
+ $file .= $form->{elsterFFFF};
+ $file .= $form->{elstersteuernummer};
+ #file suffix
+ $file .= '.xml';
+ $file =~ s|.*/||;
+ $form->{tmpfile} = "$userspath/$file";
+
+ $form->{attachment_filename} = $file;
+
+ # Zahlenformatierung für Winston
+
+ my $temp_numberformat = $myconfig{numberformat};
+
+ # Numberformat must be '1000.00' for Winston
+
+ $myconfig{numberformat} = '1000.00';
+
+ foreach my $number (@category_cent) {
+ $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';
+ }
+
+ foreach my $number (@category_euro) {
+ $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '0', '') : '';
+ }
+ # Re-set Numberformat
+ $myconfig{numberformat} = $temp_numberformat;
+
+ # push Kennziffern to <%foreach Array fo easyer
+ # output in xml format. Thx to Moritz.
+ my %winston_id_for = (
+ # No Winston remap?!
+ );
+
+ foreach my $kennziffer (@category_cent, @category_euro) {
+
+ next if ( $kennziffer =~ m/Z\d\d/);
+ next if ( $form->{$kennziffer} == 0 );
+
+ if (defined $winston_id_for{$kennziffer} ) {
+ push(@{ $form->{id}}, $winston_id_for{$kennziffer});
+ } else {
+ push(@{ $form->{id}}, "Kz$kennziffer");
+ }
+ push(@{ $form->{amount}}, $form->{$kennziffer});
+ }
+
+ } elsif ( $form->{format} eq 'elstertaxbird' ) {
+
+ # Define serveral filenames
+ $form->{IN} = 'taxbird.txb';
+
+ $form->{attachment_filename} = "USTVA-" . $form->{period}
+ . sprintf("%02d", $form->{year} % 100) . ".txb";
+
+ $form->{attachment_filename} =~ s|.*/||;
+ $form->{tmpfile} = "$userspath/" . $form->{attachment_filename};
+
+ # TODO: set Output to UTF-8 or system Preference
+ #$form->{"iconv"} = Text::Iconv->new($myconfig{dbcharset}, "UTF-8");
+ #my $iconv = $self->{"iconv"};
+ #$iconv->convert($variable);
+ if ($form->{period} =~ /^[4]\d$/ ){
+ my %periods = ( # Lx => taxbird
+ '41' => '12',
+ '42' => '13',
+ '43' => '14',
+ '44' => '15',
+ );
+
+ foreach my $quarter ( keys %periods ) {
+ $form->{taxbird_period} = $periods{$quarter} if ( $form->{period} eq $quarter);
+ }
+ } elsif ($form->{period} =~ /^\d+$/ ) {
+ $form->{period} =~ s/^0//g;
+ my $period = $form->{period};
+ $period * 1;
+ $period--;
+ $form->{taxbird_period} = $period;
+ } else {
+ $form->header;
+ USTVA::error( $locale->text('Wrong Period' ));
+ ::end_of_request();
+ }
+
+ # heuristics for address splitting
+ # lx-office holds the entire address in a single field.
+ # taxbird expects it to be splitted into street, zipcode and city
+ if ($form->{co_street} =~ /\n/) {
+ my $new_co_street;
+ for (split /\n/, $form->{co_street}) {
+ if (/(\d{3,5})\s+(\w+)/) {
+ $form->{co_zip} = $1;
+ $form->{co_city} = $2;
+ } else {
+ $new_co_street .= $_;
+ }
+ }
+ $form->{co_street} = $new_co_street;
+ } else {
+ $form->{co_zip} = $form->{co_city};
+ $form->{co_zip} =~ s/\D//g;
+ $form->{co_city} =~ s/\d//g;
+ $form->{co_city} =~ s/^\s//g;
+ }
+
+ my $tax_office = first { $_->{name} eq $form->{elsterland} } @{ $ustva->{tax_office_information} };
+ $form->{taxbird_land_nr} = $tax_office->{taxbird_nr} if $tax_office;
+
+ ($form->{co_phone_prefix}, $form->{co_phone}) = split("-", $form->{tel});
+ $form->{co_phone_prefix} =~ s/\s//g;
+ $form->{co_phone} =~ s/\s//g;
+
+ $form->{taxbird_steuernummer} = $form->{steuernummer};
+ # $form->{taxbird_steuernummer} =~ s/\D//g;
+# $form->{taxbird_steuernummer} =~ s/\///; # ersten Querstrich ersetzen
+
+ # Numberformatting for Taxbird
+ my $temp_numberformat = $myconfig{numberformat};
+ # Numberformat must be '1000,00' for Taxbird ?!
+ $myconfig{numberformat} = '1000,00';
+ foreach my $number (@category_cent) {
+ $form->{$number} = ( $form->{$number} !=0 ) ? $form->format_amount(\%myconfig, $form->{$number}, '2', '') : '';