Beim Verschicken von Sammelrechnungen per Email einen besseren Namen für den Dateianh...
[kivitendo-erp.git] / bin / mozilla / rp.pl
index 32ec6ef..152db95 100644 (file)
 #======================================================================
 
 require "$form->{path}/arap.pl";
+require "bin/mozilla/common.pl";
 
 use SL::PE;
 use SL::RP;
+use SL::USTVA;
 
 1;
 
@@ -130,6 +132,21 @@ sub report {
        </tr>
 | if $form->{selectdepartment};
 
+  $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
+                                   "all" => 1 });
+
+  my %project_labels = ();
+  my @project_values = ("");
+  foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
+    push(@project_values, $item->{"id"});
+    $project_labels{$item->{"id"}} = $item->{"projectnumber"};
+  }
+
+  my $projectnumber =
+    NTI($cgi->popup_menu('-name' => "project_id",
+                         '-values' => \@project_values,
+                         '-labels' => \%project_labels));
+
   # use JavaScript Calendar or not
   $form->{jsscript} = $jscalendar;
   $jsscript = "";
@@ -269,8 +286,7 @@ sub report {
          <td><input name=l_heading class=checkbox type=checkbox value=Y>&nbsp;|
       . $locale->text('Heading') . qq|
          <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
-      . $locale->text('Subtotal')
-      . qq|</td>
+      . $locale->text('Subtotal') . qq|</td>
        </tr>
 
 $jsscript
@@ -281,21 +297,19 @@ $jsscript
     print qq|
        <tr>
          <th align=right nowrap>| . $locale->text('Project') . qq|</th>
-         <td colspan=3><input name=projectnumber size=25</td>
+         <td colspan=3>$projectnumber</td>
        </tr>
         <input type=hidden name=nextsub value=generate_income_statement>
 </table>
 <table>
        <tr>
          <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
-      . $locale->text('Customized Report')
-      . qq|</th>
+      . $locale->text('Customized Report') . qq|</th>
        </tr>
        <tr>
          <th colspan=1>| . $locale->text('Year') . qq|</th>
          <td><input name=year size=11 title="|
-      . $locale->text('YYYY')
-      . qq|" value="$year"></td>
+      . $locale->text('YYYY') . qq|" value="$year"></td>
        </tr>
 |;
 
@@ -310,70 +324,54 @@ $jsscript
                <td align=right>&nbsp; <input name=duetyp class=radio type=radio value="13"
 "checked"></td>
                <td><input name=duetyp class=radio type=radio value="A" $checked >&nbsp;1. |
-      . $locale->text('Quarter')
-      . qq|</td>
+      . $locale->text('Quarter') . qq|</td>
 |;
     $checked = "";
     print qq|
                <td><input name=duetyp class=radio type=radio value="1" $checked >&nbsp;|
-      . $locale->text('January')
-      . qq|</td>
+      . $locale->text('January') . qq|</td>
 |;
     $checked = "";
     print qq|
                <td><input name=duetyp class=radio type=radio value="5" $checked >&nbsp;|
-      . $locale->text('May')
-      . qq|</td>
+      . $locale->text('May') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="9" $checked >&nbsp;|
-      . $locale->text('September')
-      . qq|</td>
+      . $locale->text('September') . qq|</td>
 
        </tr>
        <tr>
                <td align= right>&nbsp;</td>
                <td><input name=duetyp class=radio type=radio value="B" $checked>&nbsp;2. |
-      . $locale->text('Quarter')
-      . qq|</td>
+      . $locale->text('Quarter') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="2" $checked >&nbsp;|
-      . $locale->text('February')
-      . qq|</td>
+      . $locale->text('February') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="6" $checked >&nbsp;|
-      . $locale->text('June')
-      . qq|</td>
+      . $locale->text('June') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="10" $checked >&nbsp;|
-      . $locale->text('October')
-      . qq|</td>
+      . $locale->text('October') . qq|</td>
        </tr>
        <tr>
                <td> &nbsp;</td>
                <td><input name=duetyp class=radio type=radio value="C" $checked>&nbsp;3. |
-      . $locale->text('Quarter')
-      . qq|</td>
+      . $locale->text('Quarter') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="3" $checked >&nbsp;|
-      . $locale->text('March')
-      . qq|</td>
+      . $locale->text('March') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="7" $checked >&nbsp;|
-      . $locale->text('July')
-      . qq|</td>
+      . $locale->text('July') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="11" $checked >&nbsp;|
-      . $locale->text('November')
-      . qq|</td>
+      . $locale->text('November') . qq|</td>
 
        </tr>
        <tr>
                <td> &nbsp;</td>
                <td><input name=duetyp class=radio type=radio value="D" $checked>&nbsp;4. |
-      . $locale->text('Quarter')
-      . qq|&nbsp;</td>
+      . $locale->text('Quarter') . qq|&nbsp;</td>
                <td><input name=duetyp class=radio type=radio value="4" $checked >&nbsp;|
-      . $locale->text('April')
-      . qq|</td>
+      . $locale->text('April') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="8" $checked >&nbsp;|
-      . $locale->text('August')
-      . qq|</td>
+      . $locale->text('August') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="12" $checked >&nbsp;|
-      . $locale->text('December')
-      . qq|</td>
+      . $locale->text('December') . qq|</td>
 
        </tr>
        <tr>
@@ -381,8 +379,7 @@ $jsscript
        </tr>
        <tr>
           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
-      . $locale->text('Free report period')
-      . qq|</th>
+      . $locale->text('Free report period') . qq|</th>
          <td align=left colspan=4>| . $locale->text('From') . qq|&nbsp;
              $button1
               $button1_2&nbsp;
@@ -399,8 +396,7 @@ $jsscript
          <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
       . $locale->text('Accrual') . qq|
          &nbsp;<input name=method class=radio type=radio value=cash $cash>|
-      . $locale->text('EUR')
-      . qq|</td>
+      . $locale->text('EUR') . qq|</td>
        </tr>
 
 $jsscript
@@ -411,21 +407,19 @@ $jsscript
     print qq|
        <tr>
          <th align=right nowrap>| . $locale->text('Project') . qq|</th>
-         <td colspan=3><input name=projectnumber size=25</td>
+         <td colspan=3>$projectnumber</td>
        </tr>
         <input type=hidden name=nextsub value=generate_bwa>
 </table>
 <table>
        <tr>
          <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
-      . $locale->text('Customized Report')
-      . qq|</th>
+      . $locale->text('Customized Report') . qq|</th>
        </tr>
        <tr>
          <th colspan=1>| . $locale->text('Year') . qq|</th>
          <td><input name=year size=11 title="|
-      . $locale->text('YYYY')
-      . qq|" value="$year"></td>
+      . $locale->text('YYYY') . qq|" value="$year"></td>
        </tr>
 |;
 
@@ -440,70 +434,54 @@ $jsscript
                <td align=right>&nbsp; <input name=duetyp class=radio type=radio value="13"
 $checked></td>
                <td><input name=duetyp class=radio type=radio value="A" $checked >&nbsp;1. |
-      . $locale->text('Quarter')
-      . qq|</td>
+      . $locale->text('Quarter') . qq|</td>
 |;
     $checked = "checked";
     print qq|
                <td><input name=duetyp class=radio type=radio value="1" $checked >&nbsp;|
-      . $locale->text('January')
-      . qq|</td>
+      . $locale->text('January') . qq|</td>
 |;
     $checked = "";
     print qq|
                <td><input name=duetyp class=radio type=radio value="5" $checked >&nbsp;|
-      . $locale->text('May')
-      . qq|</td>
+      . $locale->text('May') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="9" $checked >&nbsp;|
-      . $locale->text('September')
-      . qq|</td>
+      . $locale->text('September') . qq|</td>
 
        </tr>
        <tr>
                <td align= right>&nbsp;</td>
                <td><input name=duetyp class=radio type=radio value="B" $checked>&nbsp;2. |
-      . $locale->text('Quarter')
-      . qq|</td>
+      . $locale->text('Quarter') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="2" $checked >&nbsp;|
-      . $locale->text('February')
-      . qq|</td>
+      . $locale->text('February') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="6" $checked >&nbsp;|
-      . $locale->text('June')
-      . qq|</td>
+      . $locale->text('June') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="10" $checked >&nbsp;|
-      . $locale->text('October')
-      . qq|</td>
+      . $locale->text('October') . qq|</td>
        </tr>
        <tr>
                <td> &nbsp;</td>
                <td><input name=duetyp class=radio type=radio value="C" $checked>&nbsp;3. |
-      . $locale->text('Quarter')
-      . qq|</td>
+      . $locale->text('Quarter') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="3" $checked >&nbsp;|
-      . $locale->text('March')
-      . qq|</td>
+      . $locale->text('March') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="7" $checked >&nbsp;|
-      . $locale->text('July')
-      . qq|</td>
+      . $locale->text('July') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="11" $checked >&nbsp;|
-      . $locale->text('November')
-      . qq|</td>
+      . $locale->text('November') . qq|</td>
 
        </tr>
        <tr>
                <td> &nbsp;</td>
                <td><input name=duetyp class=radio type=radio value="D" $checked>&nbsp;4. |
-      . $locale->text('Quarter')
-      . qq|&nbsp;</td>
+      . $locale->text('Quarter') . qq|&nbsp;</td>
                <td><input name=duetyp class=radio type=radio value="4" $checked >&nbsp;|
-      . $locale->text('April')
-      . qq|</td>
+      . $locale->text('April') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="8" $checked >&nbsp;|
-      . $locale->text('August')
-      . qq|</td>
+      . $locale->text('August') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="12" $checked >&nbsp;|
-      . $locale->text('December')
-      . qq|</td>
+      . $locale->text('December') . qq|</td>
 
        </tr>
        <tr>
@@ -511,8 +489,7 @@ $checked></td>
        </tr>
        <tr>
           <th align=left><input name=reporttype class=radio type=radio value="free" $checked> |
-      . $locale->text('Free report period')
-      . qq|</th>
+      . $locale->text('Free report period') . qq|</th>
          <td align=left colspan=4>| . $locale->text('From') . qq|&nbsp;
              $button1
               $button1_2&nbsp;
@@ -529,12 +506,13 @@ $checked></td>
          <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
       . $locale->text('Accrual') . qq|
          &nbsp;<input name=method class=radio type=radio value=cash $cash>|
-      . $locale->text('EUR')
-      . qq|</td>
+      . $locale->text('EUR') . qq|</td>
        </tr>
         <tr>
-         <th align=right colspan=4>| . $locale->text('Decimalplaces') . qq|</th>
-             <td><input name=decimalplaces size=3></td>
+         <th align=right colspan=4>|
+      . $locale->text('Decimalplaces')
+      . qq|</th>
+             <td><input name=decimalplaces size=3 value="2"></td>
          </tr>
                                     
 $jsscript
@@ -551,14 +529,12 @@ $jsscript
 <table>
        <tr>
          <th align=left><input name=reporttype class=radio type=radio value="custom" checked> |
-      . $locale->text('Zeitraum')
-      . qq|</th>
+      . $locale->text('Zeitraum') . qq|</th>
        </tr>
        <tr>
          <th colspan=1>| . $locale->text('Year') . qq|</th>
          <td><input name=year size=11 title="|
-      . $locale->text('YYYY')
-      . qq|" value="$year"></td>
+      . $locale->text('YYYY') . qq|" value="$year"></td>
        </tr>
 |;
 
@@ -573,70 +549,54 @@ $jsscript
                <td align=right>&nbsp; <input name=duetyp class=radio type=radio value="13"
 $checked></td>
                <td><input name=duetyp class=radio type=radio value="A" $checked >&nbsp;1. |
-      . $locale->text('Quarter')
-      . qq|</td>
+      . $locale->text('Quarter') . qq|</td>
 |;
     $checked = "checked";
     print qq|
                <td><input name=duetyp class=radio type=radio value="1" $checked >&nbsp;|
-      . $locale->text('January')
-      . qq|</td>
+      . $locale->text('January') . qq|</td>
 |;
     $checked = "";
     print qq|
                <td><input name=duetyp class=radio type=radio value="5" $checked >&nbsp;|
-      . $locale->text('May')
-      . qq|</td>
+      . $locale->text('May') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="9" $checked >&nbsp;|
-      . $locale->text('September')
-      . qq|</td>
+      . $locale->text('September') . qq|</td>
 
        </tr>
        <tr>
                <td align= right>&nbsp;</td>
                <td><input name=duetyp class=radio type=radio value="B" $checked>&nbsp;2. |
-      . $locale->text('Quarter')
-      . qq|</td>
+      . $locale->text('Quarter') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="2" $checked >&nbsp;|
-      . $locale->text('February')
-      . qq|</td>
+      . $locale->text('February') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="6" $checked >&nbsp;|
-      . $locale->text('June')
-      . qq|</td>
+      . $locale->text('June') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="10" $checked >&nbsp;|
-      . $locale->text('October')
-      . qq|</td>
+      . $locale->text('October') . qq|</td>
        </tr>
        <tr>
                <td> &nbsp;</td>
                <td><input name=duetyp class=radio type=radio value="C" $checked>&nbsp;3. |
-      . $locale->text('Quarter')
-      . qq|</td>
+      . $locale->text('Quarter') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="3" $checked >&nbsp;|
-      . $locale->text('March')
-      . qq|</td>
+      . $locale->text('March') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="7" $checked >&nbsp;|
-      . $locale->text('July')
-      . qq|</td>
+      . $locale->text('July') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="11" $checked >&nbsp;|
-      . $locale->text('November')
-      . qq|</td>
+      . $locale->text('November') . qq|</td>
 
        </tr>
        <tr>
                <td> &nbsp;</td>
                <td><input name=duetyp class=radio type=radio value="D" $checked>&nbsp;4. |
-      . $locale->text('Quarter')
-      . qq|&nbsp;</td>
+      . $locale->text('Quarter') . qq|&nbsp;</td>
                <td><input name=duetyp class=radio type=radio value="4" $checked >&nbsp;|
-      . $locale->text('April')
-      . qq|</td>
+      . $locale->text('April') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="8" $checked >&nbsp;|
-      . $locale->text('August')
-      . qq|</td>
+      . $locale->text('August') . qq|</td>
                <td><input name=duetyp class=radio type=radio value="12" $checked >&nbsp;|
-      . $locale->text('December')
-      . qq|</td>
+      . $locale->text('December') . qq|</td>
 
        </tr>
        <tr>
@@ -647,8 +607,7 @@ $checked></td>
          <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
       . $locale->text('Accrual') . qq|
          &nbsp;<input name=method class=radio type=radio value=cash $cash>|
-      . $locale->text('EUR')
-      . qq|</td>
+      . $locale->text('EUR') . qq|</td>
        </tr>
        <tr>
          <th colspan=4>|;
@@ -678,7 +637,7 @@ $checked></td>
        </tr>
        <tr>
          <th align=right>| . $locale->text('Decimalplaces') . qq|</th>
-         <td><input name=decimalplaces size=3></td>
+         <td><input name=decimalplaces size=3 value="2"></td>
        </tr>
       </table>
     </td>
@@ -691,8 +650,7 @@ $checked></td>
          <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
       . $locale->text('Accrual') . qq|
          &nbsp;<input name=method class=radio type=radio value=cash $cash>|
-      . $locale->text('EUR')
-      . qq|</td>
+      . $locale->text('EUR') . qq|</td>
        </tr>
 
        <tr>
@@ -702,8 +660,7 @@ $checked></td>
          <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
       . $locale->text('Subtotal') . qq|
          <input name=l_accno class=checkbox type=checkbox value=Y>&nbsp;|
-      . $locale->text('Account Number')
-      . qq|</td>
+      . $locale->text('Account Number') . qq|</td>
        </tr>
 
 $jsscript
@@ -739,8 +696,7 @@ $jsscript
          <input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
       . $locale->text('Subtotal') . qq|
          <input name=all_accounts class=checkbox type=checkbox value=Y>&nbsp;|
-      . $locale->text('All Accounts')
-      . qq|</td>
+      . $locale->text('All Accounts') . qq|</td>
        </tr>
 
 $jsscript
@@ -748,8 +704,6 @@ $jsscript
   }
 
   if ($form->{report} =~ /^tax_/) {
-    $gifi = "";
-
     $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
 
     RP->get_taxaccounts(\%myconfig, \%$form);
@@ -786,39 +740,12 @@ $jsscript
 
          </td>
        </tr>
-|;
-
-    if (@{ $form->{gifi_taxaccounts} }) {
-      print qq|
-        <tr>
-         <th align=right>| . $locale->text('GIFI') . qq|</th>
-         <td colspan=3>
-|;
-
-      foreach $ref (@{ $form->{gifi_taxaccounts} }) {
-
-        print
-          qq|<input name=accno class=radio type=radio value="gifi_$ref->{accno}">&nbsp;$ref->{description}
-
-      <input name="gifi_$ref->{accno}_description" type=hidden value="$ref->{description}">
-      <input name="gifi_$ref->{accno}_rate" type=hidden value="$ref->{rate}">|;
-
-      }
-
-      print qq|
-         </td>
-       </tr>
-|;
-    }
-
-    print qq|
        <tr>
          <th align=right>| . $locale->text('Method') . qq|</th>
          <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
       . $locale->text('Accrual') . qq|
          &nbsp;<input name=method class=radio type=radio value=cash $cash>|
-      . $locale->text('EUR')
-      . qq|</td>
+      . $locale->text('EUR') . qq|</td>
        </tr>
       </table>
     </td>
@@ -869,8 +796,6 @@ $jsscript
   }
 
   if ($form->{report} =~ /^nontaxable_/) {
-    $gifi = "";
-
     $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
 
     print qq|
@@ -891,8 +816,7 @@ $jsscript
          <td colspan=3><input name=method class=radio type=radio value=accrual $accrual>|
       . $locale->text('Accrual') . qq|
          &nbsp;<input name=method class=radio type=radio value=cash $cash>|
-      . $locale->text('EUR')
-      . qq|</td>
+      . $locale->text('EUR') . qq|</td>
        </tr>
         <tr>
          <th align=right>| . $locale->text('Include in Report') . qq|</th>
@@ -935,8 +859,6 @@ $jsscript
   }
 
   if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
-    $gifi = "";
-
     if ($form->{report} eq 'ar_aging') {
       $label = $locale->text('Customer');
       $form->{vc} = 'customer';
@@ -985,8 +907,6 @@ $jsscript
   # above action can be removed if there is more than one input field
 
   if ($form->{report} =~ /(receipts|payments)$/) {
-    $gifi = "";
-
     $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
 
     RP->paymentaccounts(\%myconfig, \%$form);
@@ -1034,8 +954,7 @@ $jsscript
         <tr>
          <td align=right><input type=checkbox style=checkbox name=fx_transaction value=1 checked></td>
          <th align=left colspan=3>|
-      . $locale->text('Include Exchangerate Difference')
-      . qq|</td>
+      . $locale->text('Include Exchangerate Difference') . qq|</td>
        </tr>
 
 $jsscript
@@ -1065,9 +984,8 @@ $jsscript
     . $locale->text('Continue') . qq|">
 |;
 
-  # Hier Aufruf von get_config aus bin/mozilla/fa.pl zum
-  # Einlesen der Finanzamtdaten
-  get_config($userspath, 'finanzamt.ini');
+  # Hier Aufruf von get_config zum Einlesen der Finanzamtdaten
+  USTVA->get_config($userspath, 'finanzamt.ini');
 
   $disabled = qq|disabled="disabled"|;
   $disabled = '' if ($form->{elster} eq '1');
@@ -1126,10 +1044,6 @@ sub generate_income_statement {
   $form->{endbold} = "</b>";
   $form->{br}      = "<br>";
 
-  &get_project(generate_income_statement);
-
-  $form->{projectnumber} = $form->{projectnumber_1};
-
   if ($form->{reporttype} eq "custom") {
 
     #forgotten the year --> thisyear
@@ -1252,10 +1166,10 @@ sub generate_income_statement {
     $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
     $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
 
-    $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
+    $form->{this_period} = "$shortfromdate\n$shorttodate";
     $form->{period}      =
         $locale->text('for Period')
-      . qq|<br>\n$longfromdate |
+      . qq|\n$longfromdate |
       . $locale->text('Bis')
       . qq| $longtodate|;
   }
@@ -1269,9 +1183,9 @@ sub generate_income_statement {
     $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
     $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
 
-    $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
+    $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
     $form->{period} .=
-        "<br>\n$longcomparefromdate "
+        "\n$longcomparefromdate "
       . $locale->text('Bis')
       . qq| $longcomparetodate|;
   }
@@ -1279,7 +1193,6 @@ sub generate_income_statement {
   # setup variables for the form
   @a = qw(company address businessnumber);
   map { $form->{$_} = $myconfig{$_} } @a;
-  $form->{address} =~ s/\\n/<br>/g;
 
   $form->{templates} = $myconfig{templates};
 
@@ -1318,9 +1231,9 @@ sub generate_balance_sheet {
   $form->{IN} = "balance_sheet.html";
 
   # setup company variables for the form
-  map { $form->{$_} = $myconfig{$_} }
+  map { $form->{$_} = $myconfig{$_};
+        $form->{$_} =~ s/\\n/\n/g; }
     (qw(company address businessnumber nativecurr));
-  $form->{address} =~ s/\\n/<br>/g;
 
   $form->{templates} = $myconfig{templates};
 
@@ -1411,11 +1324,6 @@ sub list_accounts {
   $column_header{endbalance} =
     qq|<th class=listheading>| . $locale->text('Balance') . qq|</th>|;
 
-  if ($form->{accounttype} eq 'gifi') {
-    $column_header{accno} =
-      qq|<th class=listheading>| . $locale->text('GIFI') . qq|</th>|;
-  }
-
   $form->header;
 
   print qq|
@@ -1446,20 +1354,12 @@ sub list_accounts {
     $description = $form->escape($ref->{description});
 
     $href =
-      qq|ca.pl?path=$form->{path}&action=list_transactions&accounttype=$form->{accounttype}&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&sort=transdate&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&eur=$form->{eur}&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title&nextsub=$form->{nextsub}|;
-
-    if ($form->{accounttype} eq 'gifi') {
-      $href .= "&gifi_accno=$ref->{accno}&gifi_description=$description";
-      $na = $locale->text('N/A');
-      map { $ref->{$_} = $na } qw(accno description) unless $ref->{accno};
-    } else {
-      $href .= "&accno=$ref->{accno}&description=$description";
-    }
+      qq|ca.pl?path=$form->{path}&action=list_transactions&accounttype=$form->{accounttype}&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&sort=transdate&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&eur=$form->{eur}&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title&nextsub=$form->{nextsub}&accno=$ref->{accno}&description=$description|;
 
     $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
 
-    $debit  = $form->format_amount(\%myconfig, $ref->{debit},  2, "&nbsp;");
-    $credit = $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;");
+    $debit  = ($ref->{debit} != 0) ? $form->format_amount(\%myconfig, $ref->{debit},  2, "&nbsp;") : "&nbsp;";
+    $credit = ($ref->{credit} != 0) ? $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;") : "&nbsp;";
     $begbalance =
       $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2, "&nbsp;");
     $endbalance =
@@ -1738,14 +1638,14 @@ sub aging {
       $i++;
 
       if ($subtotal) {
-        $c0subtotal =
-          $form->format_amount(\%myconfig, $c0subtotal, 2, "&nbsp");
-        $c30subtotal =
-          $form->format_amount(\%myconfig, $c30subtotal, 2, "&nbsp");
-        $c60subtotal =
-          $form->format_amount(\%myconfig, $c60subtotal, 2, "&nbsp");
-        $c90subtotal =
-          $form->format_amount(\%myconfig, $c90subtotal, 2, "&nbsp");
+        $c0subtotal = ($c0subtotal != 0) ? 
+          $form->format_amount(\%myconfig, $c0subtotal, 2, "&nbsp") : "";
+        $c30subtotal = ($c30subtotal != 0) ?
+          $form->format_amount(\%myconfig, $c30subtotal, 2, "&nbsp") : "";
+        $c60subtotal = ($c60subtotal != 0) ?
+          $form->format_amount(\%myconfig, $c60subtotal, 2, "&nbsp") : "";
+        $c90subtotal = ($c90subtotal != 0) ?
+          $form->format_amount(\%myconfig, $c90subtotal, 2, "&nbsp") : "";
       }
 
       $column_data{ct}        = qq|<th>&nbsp;</th>|;
@@ -1801,10 +1701,10 @@ sub aging {
     $c60total += $ref->{c60};
     $c90total += $ref->{c90};
 
-    $ref->{c0}  = $form->format_amount(\%myconfig, $ref->{c0},  2, "&nbsp;");
-    $ref->{c30} = $form->format_amount(\%myconfig, $ref->{c30}, 2, "&nbsp;");
-    $ref->{c60} = $form->format_amount(\%myconfig, $ref->{c60}, 2, "&nbsp;");
-    $ref->{c90} = $form->format_amount(\%myconfig, $ref->{c90}, 2, "&nbsp;");
+    $ref->{c0}  = ($ref->{c0} != 0) ? $form->format_amount(\%myconfig, $ref->{c0},  2, "&nbsp;") : "";
+    $ref->{c30} = ($ref->{c30} != 0) ? $form->format_amount(\%myconfig, $ref->{c30}, 2, "&nbsp;") : "";
+    $ref->{c60} = ($ref->{c60} != 0) ?  $form->format_amount(\%myconfig, $ref->{c60}, 2, "&nbsp;") : "";
+    $ref->{c90} = ($ref->{c90} != 0) ?  $form->format_amount(\%myconfig, $ref->{c90}, 2, "&nbsp;") : "";
 
     $href =
       qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=|
@@ -1916,16 +1816,10 @@ sub aging {
 <input class=submit type=submit name=action value="|
       . $locale->text('Print') . qq|">
 <input class=submit type=submit name=action value="|
-      . $locale->text('E-mail') . qq|">
-|;
-  }
-
-  if ($form->{menubar}) {
-    require "$form->{path}/menu.pl";
-    &menubar;
-  }
+      . $locale->text('E-mail') . qq|">|;
+}
 
-  print qq|
+print qq|
 </form>
 
 </body>
@@ -1947,66 +1841,6 @@ sub select_all {
   $lxdebug->leave_sub();
 }
 
-sub print_options {
-  $lxdebug->enter_sub();
-
-  $form->{sendmode} = "attachment";
-  $form->{copies}   = 2 unless $form->{copies};
-
-  $form->{PD}{ $form->{type} }     = "selected";
-  $form->{DF}{ $form->{format} }   = "selected";
-  $form->{OP}{ $form->{media} }    = "selected";
-  $form->{SM}{ $form->{sendmode} } = "selected";
-
-  $type = qq|
-           <option value=statement $form->{PD}{statement}>|
-    . $locale->text('Statement');
-
-  if ($form->{media} eq 'email') {
-    $media = qq|
-           <option value=attachment $form->{SM}{attachment}>|
-      . $locale->text('Attachment') . qq|
-           <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
-  } else {
-    $media = qq|
-           <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
-    if ($myconfig{printer} && $latex) {
-      $media .= qq|
-            <option value=printer $form->{OP}{printer}>|
-        . $locale->text('Printer');
-    }
-  }
-
-  if ($latex) {
-    $format .= qq|
-            <option value=postscript $form->{DF}{postscript}>|
-      . $locale->text('Postscript') . qq|
-           <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF');
-  }
-
-  print qq|
-<table>
-  <tr>
-    <td><select name=type>$type</select></td>
-    <td><select name=format>$format</select></td>
-    <td><select name=media>$media</select></td>
-|;
-
-  if ($myconfig{printer} && $latex && $form->{media} ne 'email') {
-    print qq|
-      <td>| . $locale->text('Copies') . qq|
-      <input name=copies size=2 value=$form->{copies}></td>
-|;
-  }
-
-  print qq|
-  </tr>
-</table>
-|;
-
-  $lxdebug->leave_sub();
-}
-
 sub e_mail {
   $lxdebug->enter_sub();
 
@@ -2169,26 +2003,36 @@ sub print {
 sub print_form {
   $lxdebug->enter_sub();
 
+  my %replacements =
+    (
+     "ä" => "ae", "ö" => "oe", "ü" => "ue",
+     "Ä" => "Ae", "Ö" => "Oe", "Ü" => "Ue",
+     "ß" => "ss",
+     " " => "_"
+    );
+
   $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
 
   $form->{templates} = "$myconfig{templates}";
 
-  # setup variables for the form
-  @a = qw(company address businessnumber tel fax);
-  map { $form->{$_} = $myconfig{$_} } @a;
-  $form->format_string(@a);
-
-  $form->{IN} = "$form->{type}.html";
-
+  my $suffix = "html";
+  my $attachment_suffix = "html";
   if ($form->{format} eq 'postscript') {
     $form->{postscript} = 1;
-    $form->{IN} =~ s/html$/tex/;
-  }
-  if ($form->{format} eq 'pdf') {
+    $suffix = "tex";
+    $attachment_suffix = "ps";
+  } elsif ($form->{format} eq 'pdf') {
     $form->{pdf} = 1;
-    $form->{IN} =~ s/html$/tex/;
+    $suffix = "tex";
+    $attachment_suffix = "pdf";
   }
 
+  $form->{IN} = "$form->{type}.$suffix";
+
+
+  # Save $form->{email} because it will be overwritten.
+  $form->{EMAIL_RECIPIENT} = $form->{email};
+
   $i = 0;
   while (@{ $form->{AG} }) {
 
@@ -2205,7 +2049,6 @@ sub print_form {
           (name, street, zipcode, city, country, contact, email,
            "$form->{ct}phone", "$form->{ct}fax");
         map { $form->{$_} = $ref->{$_} } @a;
-        $form->format_string(@a);
 
         $form->{ $form->{ct} } = $form->{name};
         $form->{"$form->{ct}_id"} = $ref->{ctid};
@@ -2246,12 +2089,21 @@ sub print_form {
             $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
         } (c0, c30, c60, c90, "");
 
+        $form->{attachment_filename} = $locale->text("Statement") . "_$form->{todate}.$attachment_suffix";
+        map({ $form->{attachment_filename} =~ s/$_/$replacements{$_}/g; } keys(%replacements));
+
         $form->parse_template(\%myconfig, $userspath);
 
       }
     }
   }
-
+  # saving the history
+  if(!exists $form->{addition} && $form->{id} ne "") {
+       $form->{addition} = "PRINTED";
+       $form->{what_done} = $form->{type};
+       $form->save_history($form->dbconnect(\%myconfig));
+  }
+  # /saving the history 
   $lxdebug->leave_sub();
 }
 
@@ -2264,10 +2116,10 @@ sub statement_details {
   push @{ $form->{duedate} },   $ref->{duedate};
 
   foreach $item (qw(c0 c30 c60 c90)) {
-    eval {
+    if ($ref->{exchangerate} * 1) {
       $ref->{$item} =
         $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
-    };
+    }
     $form->{"${item}total"} += $ref->{$item};
     $form->{total}          += $ref->{$item};
     push @{ $form->{$item} },
@@ -2286,12 +2138,6 @@ sub generate_tax_report {
   $description = $form->escape($form->{$descvar});
   $ratevar     = "$form->{accno}_rate";
 
-  if ($form->{accno} =~ /^gifi_/) {
-    $descvar     = "gifi_$form->{accno}_description";
-    $description = $form->escape($form->{$descvar});
-    $ratevar     = "gifi_$form->{accno}_rate";
-  }
-
   $department = $form->escape($form->{department});
 
   # construct href
@@ -2304,9 +2150,6 @@ sub generate_tax_report {
   $callback    =
     "$form->{script}?path=$form->{path}&action=generate_tax_report&login=$form->{login}&password=$form->{password}&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
 
-  $form->{title} = $locale->text('GIFI') . " - "
-    if ($form->{accno} =~ /^gifi_/);
-
   $title = $form->escape($form->{title});
   $href .= "&title=$title";
   $title = $form->escape($form->{title}, 1);
@@ -2769,7 +2612,16 @@ sub print_options {
   $lxdebug->enter_sub();
 
   $form->{sendmode} = "attachment";
-  $form->{copies}   = 2 unless $form->{copies};
+
+  $form->{"format"} =
+    $form->{"format"} ? $form->{"format"} :
+    $myconfig{"template_format"} ? $myconfig{"template_format"} :
+    "pdf";
+
+  $form->{"copies"} =
+    $form->{"copies"} ? $form->{"copies"} :
+    $myconfig{"copies"} ? $myconfig{"copies"} :
+    2;
 
   $form->{PD}{ $form->{type} }     = "selected";
   $form->{DF}{ $form->{format} }   = "selected";
@@ -2793,14 +2645,14 @@ sub print_options {
   } else {
     $media = qq|
            <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
-    if ($myconfig{printer} && $latex) {
+    if ($myconfig{printer} && $latex_templates) {
       $media .= qq|
             <option value=printer $form->{OP}{printer}>|
         . $locale->text('Printer');
     }
   }
 
-  if ($latex) {
+  if ($latex_templates) {
     $format .= qq|
             <option value=html $form->{DF}{html}>|
       . $locale->text('HTML') . qq|
@@ -2820,7 +2672,7 @@ sub print_options {
     <td><select name=media>$media</select></td>
 |;
 
-  if ($myconfig{printer} && $latex && $form->{media} ne 'email') {
+  if ($myconfig{printer} && $latex_templates && $form->{media} ne 'email') {
     print qq|
       <td>| . $locale->text('Copies') . qq|
       <input name=copies size=2 value=$form->{copies}></td>
@@ -2842,8 +2694,6 @@ sub generate_bwa {
   $form->{endbold} = "</b>";
   $form->{br}      = "<br>";
 
-  #  &get_project(generate_bwa);
-
   if ($form->{reporttype} eq "custom") {
 
     #forgotten the year --> thisyear
@@ -3009,10 +2859,10 @@ sub generate_bwa {
     $longfromdate  = $locale->date(\%germandate, $form->{fromdate}, 1);
     $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
 
-    $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
+    $form->{this_period} = "$shortfromdate\n$shorttodate";
     $form->{period}      =
         $locale->text('for Period')
-      . qq|<br>\n$longfromdate |
+      . qq|\n$longfromdate |
       . $locale->text('bis')
       . qq| $longtodate|;
   }
@@ -3020,7 +2870,6 @@ sub generate_bwa {
   # setup variables for the form
   @a = qw(company address businessnumber);
   map { $form->{$_} = $myconfig{$_} } @a;
-  $form->{address} =~ s/\\n/<br>/g;
   $form->{templates} = $myconfig{templates};
 
   $form->{IN} = "bwa.html";
@@ -3033,9 +2882,8 @@ sub generate_bwa {
 sub generate_ustva {
   $lxdebug->enter_sub();
 
-  # Hier Aufruf von get_config aus bin/mozilla/fa.pl zum
-  # Einlesen der Finanzamtdaten
-  get_config($userspath, 'finanzamt.ini');
+  # Hier Aufruf von get_config zum Einlesen der Finanzamtdaten
+  USTVA->get_config($userspath, 'finanzamt.ini');
 
   #  &get_project(generate_bwa);
   @anmeldungszeitraum =
@@ -3189,7 +3037,7 @@ sub generate_ustva {
     $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
     $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
 
-    $form->{this_period} = "$shortfromdate<br>\n$shorttodate";
+    $form->{this_period} = "$shortfromdate\n$shorttodate";
     $form->{period}      =
         $locale->text('for Period')
       . qq|<br>\n$longfromdate |
@@ -3206,9 +3054,9 @@ sub generate_ustva {
     $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
     $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
 
-    $form->{last_period} = "$shortcomparefromdate<br>\n$shortcomparetodate";
+    $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
     $form->{period} .=
-        "<br>\n$longcomparefromdate "
+        "\n$longcomparefromdate "
       . $locale->text('bis')
       . qq| $longcomparetodate|;
   }