Merge von 843,844 aus unstable: UStVa Bugfix, locales, Update help
[kivitendo-erp.git] / bin / mozilla / ustva.pl
index e04bc45..2e42f18 100644 (file)
@@ -29,7 +29,7 @@ require "$form->{path}/arap.pl";
 #use strict;
 #no strict 'refs';
 #use diagnostics;
-#use warnings FATAL=> 'all';
+#use warnings; # FATAL=> 'all';
 #use vars qw($locale $form %myconfig);
 #our ($myconfig);
 #use CGI::Carp "fatalsToBrowser";
@@ -76,13 +76,7 @@ sub report {
   $form->{title} = $locale->text('UStVA');
   $form->{kz10}  = '';                       #Berichtigte Anmeldung? Ja =1
 
-  #  $accrual = ($eur) ? "" : "checked";
-  #  $cash = ($eur) ? "checked" : "";
-  my $year = '';
-  my $null = '';
-  ($null, $null, $null, $null, $null, $year, $null, $null, $null) =
-    localtime();
-  $year += 1900;
+  my $year = substr($form->datetonum($form->current_date(\%myconfig), \%myconfig),0,4);
 
   my $department = '';
   local $hide = '';
@@ -109,9 +103,17 @@ sub report {
   # Hier Aufruf von get_config aus bin/mozilla/fa.pl zum
   # Einlesen der Finanzamtdaten
   &get_config($userspath, 'finanzamt.ini');
-
+  
+  # Hier Einlesen der user-config
+  # steuernummer entfernt für prerelease
   my @a = qw(signature name company address businessnumber tel fax email
-    company_street company_city company_email);
+    co_chief co_department co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
+    co_name1 co_name2
+    co_street co_street1 co_zip co_city co_city1 co_country co_tel co_tel1 co_tel2
+    co_fax co_fax1 co_email co_email1 co_url co_url1 ustid duns
+    co_bankname co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
+    co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2 co_accountnr3);
+
   map { $form->{$_} = $myconfig->{$_} } @a;
 
   my $oeffnungszeiten = $form->{FA_Oeffnungszeiten};
@@ -132,35 +134,46 @@ sub report {
            | . $locale->text('Kein Firmenname hinterlegt!') . qq|</a><br>
     |;
   }
+  
+  # Anpassungen der Variablennamen auf pre 2.1.1 Namen
+  # klären, ob $form->{company_street|_address} gesetzt sind
+  #
 
-  #klären, ob $form->{company_street|_address} gesetzt sind
-  ###
   if ($form->{address} ne '') {
     my $temp = $form->{address};
     $temp =~ s/\\n/<br \/>/;
-    print qq|$temp|;
-    ($form->{company_street}, $form->{company_city}) = split("<br \/", $temp);
-  } elsif ($form->{address} eq ''
-         and ($form->{company_street} ne '' and $form->{company_city} ne '')) {
-    print qq|$form->{company_street}<br>\n| if ($form->{company_street} ne '');
-    print qq|$form->{company_city}\n|       if ($form->{company_city}   ne '');
-         } elsif ($form->{company_street} eq '' or $form->{company_city} eq '') {
+    ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
+  }
+
+  if (    $form->{co_street} ne ''
+      and ($form->{co_zip} ne ''
+      or $form->{co_city} ne '') ) {
+    print qq|
+    $form->{co_street}<br>
+    $form->{co_street1}<br>
+    $form->{co_zip} $form->{co_city}|;
+      } else {
     print qq|
          <a href=am.pl?path=$form->{path}&action=config&level=Programm--Preferences&login=$form->{login}&password=$form->{password}>
          | . $locale->text('Keine Firmenadresse hinterlegt!') . qq|</a>\n|;
   }
-
+  $form->{co_email}=$form->{email} unless $form->{co_email};
+  $form->{co_tel}=$form->{tel} unless $form->{co_tel};
+  $form->{co_fax}=$form->{fax} unless $form->{co_fax};
+  $form->{co_url}=$form->{urlx} unless $form->{co_url};
+  
+  
   print qq|
          <br>
          <br>
          | . $locale->text('Tel.: ') . qq|
-         $form->{tel}
+         $form->{co_tel}
          <br>
          | . $locale->text('Fax.: ') . qq|
-         $form->{fax}    
+         $form->{co_fax}         
          <br>
          <br>
-         $form->{email}          
+         $form->{co_email}       
          <br>
          <br>
          | . $locale->text('Steuernummer: ') . qq|
@@ -214,7 +227,7 @@ sub report {
 
     # accounting years if SQL-Ledger Version < 2.4.1
     #    $year = $form->{year} * 1;
-    @years = sort { $b <=> $a } (2000 .. ($year));
+    @years = sort { $b <=> $a } (2003 .. ($year+1));
     $form->{all_years} = \@years;
   }
   map { $form->{selectaccountingyear} .= qq|<option>$_\n| }
@@ -395,31 +408,6 @@ sub report {
          </fieldset>
       |;
 
-    # Stichtag der nächsten USTVA berechnen
-    #
-    # ($stichtag, $tage_bis, $ical) = FA->stichtag($today[dd.mm.yyyy],
-    #                                              $FA_dauerfrist[1,0],
-    #                                              $FA_voranmeld[month, quarter])
-    #$tmpdateform= $myconfig{dateformat};
-    #  $myconfig{dateformat}= "dd.mm.yyyy";
-    #  $form->{today} = $form->datetonum($form->current_date(\%myconfig), \%myconfig);
-    #  ($stichtag, $description, $tage_bis, $ical) = FA::stichtag($form->{today}, $form->{FA_dauerfrist},$form->{FA_voranmeld});
-    #   $form->{today} = $form->date($stichtag, \%myconfig );
-    #$myconfig{dateformat}= $tmpdateform;
-
-    #print qq|
-    #   <br>
-    #   <br>
-    #   <fieldset>
-    #    <label>
-    #    |.$locale->text('Anstehende Voranmeldungen').qq|
-    #    </label>
-    #     <h2 class="confirm">$stichtag<h2>
-    #     <h3>$description</h3>
-    #     <h4>$form->{today}</h4>
-    #
-    #   </fieldset>|;
-
   } else {
     print qq|
      <td width="50%" valign="bottom">
@@ -427,14 +415,10 @@ sub report {
      <legend>
      <b>| . $locale->text('Hinweise') . qq|</b>
      </legend>
-      <h2 class="confirm">Die Ausgabefunktionen sind wegen fehlender Daten deaktiviert.</h2>
-      <h3>Hilfe:</h3>
+      <h2 class="confirm">| . $locale->text('Missing Preferences: Outputroutine disabled') . qq|</h2>
+      <h3>| . $locale->text('Help:') . qq|</h3>
       <ul>
-      <li><a href="ustva.pl?path=$form->{path}&action=edit&level=Programm--Finanzamteinstellungen&login=$form->{login}&password=$form->{password}">
-      Bitte 'Einstellungen' wählen um die Erweiterten UStVa Funktionen nutzen zu können.</a></li>
-      <br>
-      <li><a href="am.pl?path=$form->{path}&action=config&level=Programm--Preferences&login=$form->{login}&password=$form->{password}">
-      Firmendaten können bei den Benutzereinstellungen verändert werden.</a></li>
+      <li>| . $locale->text('Hint-Missing-Preferences') . qq|</li>
       </ul>
       </fieldset>
      |;
@@ -461,8 +445,8 @@ sub report {
   <br>
   <input type="hidden" name="address" value="$form->{address}">
   <input type="hidden" name="reporttype" value="custom">
-  <input type="hidden" name="company_street" value="$form->{company_street}">
-  <input type="hidden" name="company_city" value="$form->{company_city}">
+  <input type="hidden" name="co_street" value="$form->{co_street}">
+  <input type="hidden" name="co_city" value="$form->{co_city}">
   <input type="hidden" name="path" value="$form->{path}">
   <input type="hidden" name="login" value="$form->{login}">
   <input type="hidden" name="password" value="$form->{password}">
@@ -472,8 +456,6 @@ sub report {
      <input type=hidden name=nextsub value=generate_ustva>
      <input $hide type=submit class=submit name=action value="|
     . $locale->text('Show') . qq|">
-     <input type=submit class=submit name=action value="|
-    . $locale->text('Config') . qq|">
    </td>
    <td align="right">
 
@@ -493,7 +475,6 @@ sub report {
   </body>
   </html>
   |;
-
   $lxdebug->leave_sub();
 }
 
@@ -501,7 +482,6 @@ sub report {
 
 sub help {
   $lxdebug->enter_sub();
-
   # parse help documents under doc
   my $tmp = $form->{templates};
   $form->{templates} = 'doc';
@@ -516,25 +496,28 @@ sub help {
 
 sub show {
   $lxdebug->enter_sub();
-
   #&generate_ustva();
   no strict 'refs';
+  $lxdebug->leave_sub();
   &{ $form->{nextsub} };
   use strict 'refs';
-  $lxdebug->leave_sub();
 }
 
 sub ustva_vorauswahl {
   $lxdebug->enter_sub();
-
   #Aktuelles Datum zerlegen:
-  $locale->date(\%myconfig, $form->current_date(\%myconfig, '0', '0'), 0) =~
-    /(\d\d).(\d\d).(\d\d\d\d)/;
+  my $date = $form->datetonum($form->current_date(\%myconfig), \%myconfig);
 
   #$locale->date($myconfig, $form->current_date($myconfig), 0)=~ /(\d\d).(\d\d).(\d\d\d\d)/;
-  $form->{day}   = $1;
-  $form->{month} = $2;
-  $form->{year}  = $3;
+  $form->{day}   = substr($date, 6, 2);
+  $form->{month} = substr($date, 4, 2);
+  $form->{year}  = substr($date, 0, 4);
+  $lxdebug->message(LXDebug::DEBUG1, qq|
+    Actual date from Database: $date\n    
+    Actual year from Database: $form->{year}\n
+    Actual day from Database: $form->{day}\n
+    Actual month from Database: $form->{month}\n|);
+  
   my $sel    = '';
   my $yymmdd = '';
 
@@ -568,13 +551,18 @@ sub ustva_vorauswahl {
                  '09' => 'September',
                  '10' => 'October',
                  '11' => 'November',
-                 '12' => 'December');
-
+                 '12' => 'December',
+                 '13' => 'Yearly',
+                );
+       
     my $yy = $form->{year} * 10000;
     $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
+    $yymmdd = 20060121;
     $sel    = '';
-    my $dfv = '0';    # Offset für Dauerfristverlängerung
-                      #$dfv = '100' if ($form->{FA_dauerfrist} eq '1');
+    my $dfv = '0';    
+    
+    # Offset für Dauerfristverlängerung
+    $dfv = '100' if ($form->{FA_dauerfrist} eq '1');
 
   SWITCH: {
       $yymmdd <= ($yy + 110 + $dfv) && do {
@@ -648,10 +636,12 @@ sub ustva_vorauswahl {
   } elsif ($form->{FA_voranmeld} eq 'quarter') {
 
     # Vorauswahl bei quartalsweisem Voranmeldungszeitraum
-    my %liste = ('A' => '1.',
-                 'B' => '2.',
-                 'C' => '3.',
-                 'D' => '4.',);
+    my %liste = ( 'A' => $locale->text('1. Quarter'),
+                  'B' => $locale->text('2. Quarter'),
+                  'C' => $locale->text('3. Quarter'),
+                  'D' => $locale->text('4. Quarter'),
+                 '13' => $locale->text('Yearly'),
+                 );
 
     my $yy = $form->{year} * 10000;
     $yymmdd = "$form->{year}$form->{month}$form->{day}" * 1;
@@ -689,9 +679,7 @@ sub ustva_vorauswahl {
       my $selected = '';
       $selected = 'selected' if ($sel eq $key);
       print qq|
-         <option value="$key" $selected>$liste{$key} |
-        . $locale->text('Quarter')
-        . qq|</option>
+         <option value="$key" $selected>$liste{$key}</option>
      |;
     }
     print qq|\n</select>
@@ -703,10 +691,10 @@ sub ustva_vorauswahl {
     print qq|<select id="zeitraum" name="duetyp" title="|
       . $locale->text('Select a period') . qq|" >|;
 
-    my %listea = ('A' => '1.',
-                  'B' => '2.',
-                  'C' => '3.',
-                  'D' => '4.',);
+    my %listea = ('A' => '1. Quarter',
+                  'B' => '2. Quarter',
+                  'C' => '3. Quarter',
+                  'D' => '4. Quarter',);
 
     my %listeb = ('01' => 'January',
                   '02' => 'February',
@@ -719,22 +707,20 @@ sub ustva_vorauswahl {
                   '09' => 'September',
                   '10' => 'October',
                   '11' => 'November',
-                  '12' => 'December',);
+                  '12' => 'December',
+                  '13' => 'Yearly',
+                  );
     my $key = '';
     foreach $key (sort keys %listea) {
       print qq|
-         <option value="$key">$listea{$key} |
-        . $locale->text('Quarter')
-        . qq|</option>
-         
-     |;
+         <option value="$key">| . $locale->text("$listea{$key}"). 
+         qq|</option>\n|;
     }
 
     foreach $key (sort keys %listeb) {
       print qq|
-         <option value="$key">| . $locale->text("$listeb{$key}") . qq|</option>
-         
-     |;
+         <option value="$key">| . $locale->text("$listeb{$key}"). 
+         qq|</option>\n|;
     }
     print qq|</select>|;
   }
@@ -748,7 +734,9 @@ sub config {
 }
 
 sub debug {
+  $lxdebug->enter_sub();
   $form->debug();
+  $lxdebug->leave_sub();
 }
 
 sub show_options {
@@ -810,127 +798,130 @@ sub generate_ustva {
 
     #forgotten the year --> thisyear
     if ($form->{year} !~ m/^\d\d\d\d$/) {
-      $locale->date(\$myconfig, $form->current_date(\$myconfig), 0) =~
-        /(\d\d\d\d)/;
-      $form->{year} = $1;
+      $form->{year} = substr($form->datetonum($form->current_date(\%myconfig), \%myconfig),0,4);
+      $lxdebug->message(LXDebug::DEBUG1, qq|Actual year from Database: $form->{year}\n|);
     }
 
     #yearly report
     if ($form->{duetyp} eq "13") {
-      $form->{fromdate} = "1.1.$form->{year}";
-      $form->{todate}   = "31.12.$form->{year}";
+      $form->{fromdate} = "$form->{year}0101";
+      $form->{todate}   = "$form->{year}1231";
     }
 
     #Quater reports
     if ($form->{duetyp} eq "A") {
-      $form->{fromdate} = "1.1.$form->{year}";
-      $form->{todate}   = "31.3.$form->{year}";
+      $form->{fromdate} = "$form->{year}0101";
+      $form->{todate}   = "$form->{year}0331";
       $form->{'0441'}   = "X";
     }
     if ($form->{duetyp} eq "B") {
-      $form->{fromdate} = "1.4.$form->{year}";
-      $form->{todate}   = "30.6.$form->{year}";
+      $form->{fromdate} = "$form->{year}0401";
+      $form->{todate}   = "$form->{year}0630";
       $form->{'0442'}   = "X";
     }
     if ($form->{duetyp} eq "C") {
-      $form->{fromdate} = "1.7.$form->{year}";
-      $form->{todate}   = "30.9.$form->{year}";
+      $form->{fromdate} = "$form->{year}0701";
+      $form->{todate}   = "$form->{year}0930";
       $form->{'0443'}   = "X";
     }
     if ($form->{duetyp} eq "D") {
-      $form->{fromdate} = "1.10.$form->{year}";
-      $form->{todate}   = "31.12.$form->{year}";
+      $form->{fromdate} = "$form->{year}1001";
+      $form->{todate}   = "$form->{year}1231";
       $form->{'0444'}   = "X";
     }
 
     #Monthly reports
   SWITCH: {
       $form->{duetyp} eq "01" && do {
-        $form->{fromdate} = "1.1.$form->{year}";
-        $form->{todate}   = "31.1.$form->{year}";
+        $form->{fromdate} = "$form->{year}0101";
+        $form->{todate}   = "$form->{year}0131";
         $form->{'0401'}   = "X";
         last SWITCH;
       };
       $form->{duetyp} eq "02" && do {
-        $form->{fromdate} = "1.2.$form->{year}";
+        $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} = "$leap.2.$form->{year}";
+        $form->{todate} = "$form->{year}02$leap";
         $form->{"0402"} = "X";
         last SWITCH;
       };
       $form->{duetyp} eq "03" && do {
-        $form->{fromdate} = "1.3.$form->{year}";
-        $form->{todate}   = "31.3.$form->{year}";
+        $form->{fromdate} = "$form->{year}0301";
+        $form->{todate}   = "$form->{year}0331";
         $form->{"0403"}   = "X";
         last SWITCH;
       };
       $form->{duetyp} eq "04" && do {
-        $form->{fromdate} = "1.4.$form->{year}";
-        $form->{todate}   = "30.4.$form->{year}";
+        $form->{fromdate} = "$form->{year}0401";
+        $form->{todate}   = "$form->{year}0430";
         $form->{"0404"}   = "X";
         last SWITCH;
       };
       $form->{duetyp} eq "05" && do {
-        $form->{fromdate} = "1.5.$form->{year}";
-        $form->{todate}   = "31.5.$form->{year}";
+        $form->{fromdate} = "$form->{year}0501";
+        $form->{todate}   = "$form->{year}0531";
         $form->{"0405"}   = "X";
         last SWITCH;
       };
       $form->{duetyp} eq "06" && do {
-        $form->{fromdate} = "1.6.$form->{year}";
-        $form->{todate}   = "30.6.$form->{year}";
+        $form->{fromdate} = "$form->{year}0601";
+        $form->{todate}   = "$form->{year}0630";
         $form->{"0406"}   = "X";
         last SWITCH;
       };
       $form->{duetyp} eq "07" && do {
-        $form->{fromdate} = "1.7.$form->{year}";
-        $form->{todate}   = "31.7.$form->{year}";
+        $form->{fromdate} = "$form->{year}0701";
+        $form->{todate}   = "$form->{year}0731";
         $form->{"0407"}   = "X";
         last SWITCH;
       };
       $form->{duetyp} eq "08" && do {
-        $form->{fromdate} = "1.8.$form->{year}";
-        $form->{todate}   = "31.8.$form->{year}";
+        $form->{fromdate} = "$form->{year}0801";
+        $form->{todate}   = "$form->{year}0831";
         $form->{"0408"}   = "X";
         last SWITCH;
       };
       $form->{duetyp} eq "09" && do {
-        $form->{fromdate} = "1.9.$form->{year}";
-        $form->{todate}   = "30.9.$form->{year}";
+        $form->{fromdate} = "$form->{year}0901";
+        $form->{todate}   = "$form->{year}0930";
         $form->{"0409"}   = "X";
         last SWITCH;
       };
       $form->{duetyp} eq "10" && do {
-        $form->{fromdate} = "1.10.$form->{year}";
-        $form->{todate}   = "31.10.$form->{year}";
+        $form->{fromdate} = "$form->{year}1001";
+        $form->{todate}   = "$form->{year}1031";
         $form->{"0410"}   = "X";
         last SWITCH;
       };
       $form->{duetyp} eq "11" && do {
-        $form->{fromdate} = "1.11.$form->{year}";
-        $form->{todate}   = "30.11.$form->{year}";
+        $form->{fromdate} = "$form->{year}1101";
+        $form->{todate}   = "$form->{year}1130";
         $form->{"0411"}   = "X";
         last SWITCH;
       };
       $form->{duetyp} eq "12" && do {
-        $form->{fromdate} = "1.12.$form->{year}";
-        $form->{todate}   = "31.12.$form->{year}";
+        $form->{fromdate} = "$form->{year}1201";
+        $form->{todate}   = "$form->{year}1231";
         $form->{"0412"}   = "X";
         last SWITCH;
       };
     }
   }
 
-  #$myconfig = \%myconfig;
-  RP->ustva(\%myconfig, \%$form);
-
-  #??($form->{department}) = split /--/, $form->{department};
+  # using dates in ISO-8601 format: yyyymmmdd  for Postgres...
+  USTVA->ustva(\%myconfig, \%$form);
+  
+  # reformat Dates to dateformat
+  $form->{fromdate}= $locale->date(\%myconfig, $form->{fromdate}, 0, 0, 0);
+  
+  $form->{todate} = $form->current_date($myconfig) unless $form->{todate};
+  $form->{todate}= $locale->date(\%myconfig, $form->{todate}, 0, 0, 0);
 
   $form->{period} =
     $locale->date(\%myconfig, $form->current_date(\%myconfig), 1, 0, 0);
-  $form->{todate} = $form->current_date($myconfig) unless $form->{todate};
+
 
   # if there are any dates construct a where
   if ($form->{fromdate} || $form->{todate}) {
@@ -975,14 +966,20 @@ sub generate_ustva {
     $locale->date(\%myconfig, $form->current_date(\%myconfig), 0, 0, 0);
 
   # setup variables for the form
-  my @a = ();
-  @a = qw(company businessnumber tel fax email company_email);
+  # steuernummer für prerelease entfernt
+  my @a = qw(company businessnumber tel fax email
+    co_chief co_department co_custom1 co_custom2 co_custom3 co_custom4 co_custom5
+    co_name1 co_name2  co_street co_street1 co_zip co_city co_city1 co_country co_tel co_tel1 co_tel2
+    co_fax co_fax1 co_email co_email1 co_url co_url1 ustid duns
+    co_bankname co_bankname1 co_bankname2 co_bankname3 co_blz co_blz1
+    co_blz2 co_blz3 co_accountnr co_accountnr1 co_accountnr2 co_accountnr3);
+
   map { $form->{$_} = $myconfig{$_} } @a;
 
   if ($form->{address} ne '') {
     my $temp = $form->{address};
     $temp =~ s/\\n/<br \/>/;
-    ($form->{company_street}, $form->{company_city}) = split("<br \/>", $temp);
+    ($form->{co_street}, $form->{co_city}) = split("<br \/>", $temp);
   }
 
   if (   $form->{format} eq 'pdf'
@@ -992,13 +989,27 @@ sub generate_ustva {
     $form->{endbold} = "}";
     $form->{br}      = '\\\\';
 
-    my @numbers = qw(51r 86r 97r 93r 96 43 45
-      66 62 67);
+    
+    my @numbers = qw(511 861 36 80 971 931 98 96 53 74
+                     85 65 66 61 62 Z67 63 64 59 69 39 83
+                     Z43 Z45 Z53 Z62 Z65);
+      
     my $number = '';
-    foreach $number (@numbers) {
-      $form->{$number} =~ s/,/~~/g;
+    # Zahlenformatierung für Latex USTVA Formulare
+    if ($myconfig{numberformat} eq '1.000,00' or 
+         $myconfig{numberformat} eq '1000,00') {
+      foreach $number (@numbers) {
+        $form->{$number} =~ s/,/~~/g;
+      }
+    }  
+    if ($myconfig{numberformat} eq '1000.00' or 
+         $myconfig{numberformat} eq '1,000.00') {
+      foreach $number (@numbers) {
+        $form->{$number} =~ s/\./~~/g;
+      }
     }
-      } elsif ($form->{format} eq 'html') {
+  # Formatierungen für HTML Ausgabe
+  } elsif ($form->{format} eq 'html') {
     $form->{padding} = "&nbsp;&nbsp;";
     $form->{bold}    = "<b>";
     $form->{endbold} = "</b>";
@@ -1008,13 +1019,26 @@ sub generate_ustva {
   }
 
   if ($form->{format} eq 'elster') {
-    &create_winston();
+    if ($form->{duetyp} eq '13'){
+      $form->header;
+      USTVA::info($locale->text('Impossible to create yearly Tax Report via Winston.<br \> Not yet implemented!'));
+    } else {
+      &create_winston();
+    }
   } else {
     $form->{templates} = $myconfig{templates};
     $form->{templates} = "doc" if ($form->{type} eq 'help');
 
     $form->{IN} = "$form->{type}";
     $form->{IN} = "$form->{help}" if ($form->{type} eq 'help');
+    $form->{IN} = 'USTE' if ($form->{duetyp} eq '13' && 
+                             $form->{format} ne 'html');
+    
+    if ($form->{IN} eq 'USTE'){
+      $form->header;
+      USTVA::info($locale->text('Impossible to create yearly Tax Report as PDF or PS.<br \> Not yet implemented!'));
+    }
+    
     $form->{IN} .= "-$form->{year}"
       if (   $form->{format} eq 'pdf'
           or $form->{format} eq 'postscript');
@@ -1034,7 +1058,6 @@ sub generate_ustva {
 
 sub edit {
   $lxdebug->enter_sub();
-
   # edit all taxauthority prefs
 
   $form->header;
@@ -1045,6 +1068,11 @@ sub edit {
   my $land = $form->{elsterland};
   my $amt  = $form->{elsterFFFF};
 
+  my $callback = '';
+  $callback =
+    "$form->{cbscript}?action=edit&login=$form->{cblogin}&path=$form->{cbpath}&root=$form->{cbroot}&rpw=$form->{cbrpw}"
+    if ($form->{cbscript} ne '' and $form->{cblogin} ne '');
+
   $form->{title} = $locale->text('Finanzamt - Einstellungen');
   print qq|
     <body>
@@ -1167,8 +1195,16 @@ sub edit {
            <!--<input type=submit class=submit name=action value="|
     . $locale->text('debug')
     . qq|">-->
+           |;
+  print qq|
+           <input type="button" name="Verweis" value="|
+    . $locale->text('Back to user config...') . qq|" 
+            onClick="self.location.href='$callback'">| if ($callback ne '');
+  print qq|
+           &nbsp; &nbsp;
            <input type=submit class=submit name=action value="|
     . $locale->text('continue') . qq|">
+
          </td>
        </tr>
      </table>
@@ -1184,7 +1220,7 @@ sub edit {
 
   #<input type=hidden name="steuernummer_new" value="$form->{$steuernummer_new}">
   print qq|
-
+          <input type=hidden name="callback" value="$callback">
           <input type=hidden name="nextsub" value="edit_form">
           <input type=hidden name="warnung" value="1">
           <input type=hidden name="saved" value="|
@@ -1228,17 +1264,13 @@ sub edit_form {
 
   # Auf Übergabefehler checken
   USTVA::info(
-    $locale->text(
-      'Bitte das Bundesland UND die Stadt bzw. den Einzugsbereich Ihres zuständigen Finanzamts auswählen.'
-    ))
+    $locale->text('Missing Tax Authoritys Preferences') . "\n" . 
+    $locale->text('USTVA-Hint: Tax Authoritys'))
     if (   $form->{elsterFFFF_new} eq 'Auswahl'
         || $form->{elsterland_new} eq 'Auswahl');
   USTVA::info(
-    $locale->text(
-      'Es fehlen Angaben zur Versteuerung. 
-  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.'
-    ))
+    $locale->text('Missing Method!') . "\n" . 
+    $locale->text('USTVA-Hint: Method'))
     if ($form->{method} eq '');
 
   # Klären, ob Variablen bereits befüllt sind UND ob veräderungen auf
@@ -1341,18 +1373,17 @@ sub edit_form {
       <tr>
          <td align="left">
 
-
-          <!--<input type=hidden name=nextsub value="debug">
-          <input type=submit class=submit name=action value="|
-    . $locale->text('debug') . qq|">
-          <input type=hidden name=nextsub value="test">
-          <input type=submit class=submit name=action value="|
-    . $locale->text('test')
-    . qq|">-->
           <input type=hidden name=lastsub value="edit">
-          <input type=submit class=submit name=action value="|
-    . $locale->text('back') . qq|">
-  |;
+          |;
+  print qq|<input type=submit class=submit name=action value="|
+    . $locale->text('back') . qq|">|
+    if ($form->{callback} eq '');
+
+  print qq|
+           <input type="button" name="Verweis" value="|
+    . $locale->text('Back to user config...') . qq|" 
+            onClick="self.location.href='$form->{callback}'">|
+    if ($form->{callback} ne '');
 
   if ($form->{warnung} eq "1") {
     print qq|
@@ -1383,7 +1414,7 @@ sub edit_form {
   my @variables = qw(FA_steuerberater_name FA_steuerberater_street
     FA_steuerberater_city FA_steuerberater_tel
     FA_voranmeld method
-    FA_dauerfrist FA_71 FA_Name elster
+    FA_dauerfrist FA_71 elster
     path login password type elster_init saved
   );
   my $variable = '';
@@ -1397,6 +1428,7 @@ sub edit_form {
           <input type=hidden name="warnung" value="$warnung">
           <input type=hidden name="elstersteuernummer" value="$elstersteuernummer">
           <input type=hidden name="steuernummer" value="$stnr">
+          <input type=hidden name="callback" value="$form->{callback}">
   </form>
   |;
   $lxdebug->leave_sub();
@@ -1443,8 +1475,15 @@ sub get_config {
 
   my ($userpath, $filename) = @_;
   my ($key,      $value)    = '';
-  open(FACONF, "$userpath/$filename")
-    or $form->error("$userpath/$filename : $!");
+  open(FACONF, "$userpath/$form->{login}_$filename")
+    or    #falls Datei nicht vorhanden ist
+    sub {
+    open(FANEW, ">$userpath/$form->{login}_$filename")
+      or $form->error("$userpath/$filename : $!");
+    close FANEW;
+    open(FACONF, "$userpath/$form->{login}_$filename")
+      or $form->error("$userpath/$form->{username}_$filename : $!");
+    };
   while (<FACONF>) {
     last if /^\[/;
     next if /^(#|\s)/;
@@ -1473,7 +1512,7 @@ sub get_config {
 
 sub save {
   $lxdebug->enter_sub();
-  my $filename = $form->{filename};
+  my $filename = "$form->{login}_$form->{filename}";
 
   #zuerst die steuernummer aus den part, parts_X_Y und delimiter herstellen
   create_steuernummer;
@@ -1558,6 +1597,16 @@ sub show_fa_daten {
                     </legend>
 
                   <table width="100%">
+                   <tr>
+                    <td>
+                    | . $locale->text('Finanzamt') . qq|
+                    </td>
+                   </tr>
+                   <tr>
+                    <td colspan="2">
+                     <input name="FA_Name" size="40" title="FA_Name" value="$form->{FA_Name}" $readonly>
+                    <td>
+                   </tr>
                    <tr>
                     <td colspan="2">
                      <input name="FA_Strasse" size="40" title="FA_Strasse" value="$form->{FA_Strasse}" $readonly>
@@ -1893,7 +1942,6 @@ Content-Disposition: attachment; filename="$elsterfile"\n\n|;
 
 sub continue {
   $lxdebug->enter_sub();
-
   # allow Symbolic references just here:
   no strict 'refs';
   &{ $form->{nextsub} };
@@ -1901,7 +1949,11 @@ sub continue {
   $lxdebug->leave_sub();
 }
 
-sub back { &{ $form->{lastsub} } }
+sub back { 
+  $lxdebug->enter_sub();
+  &{ $form->{lastsub} }; 
+  $lxdebug->leave_sub();
+}
 
 sub elster_hash {
   $lxdebug->enter_sub();
@@ -2039,15 +2091,13 @@ sub elster_conf {
                       'logfile'  => 'log/faxmlsend.log',
                       'conffile' => 'faxmlsend.cnf',
                       'debug'    => '-debug' };
-
   $lxdebug->leave_sub();
-
   return $elster_conf;
+
 }
 
 sub elster_xml {
   $lxdebug->enter_sub();
-
   my $elster_conf = &elster_conf();
 
   #  $k51 = sprintf("%d", $form->parse_amount(\%myconfig, $form->{"51"})); # Umsätze zu 16% USt