Funktion get_config aus ustva.pl nach USTVA.pm verschoben, damit sie auch aus rp...
[kivitendo-erp.git] / bin / mozilla / rp.pl
index fe46f17..848ec62 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 = "";
@@ -280,7 +297,7 @@ $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>
@@ -390,7 +407,7 @@ $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>
@@ -495,7 +512,7 @@ $checked></td>
          <th align=right colspan=4>|
       . $locale->text('Decimalplaces')
       . qq|</th>
-             <td><input name=decimalplaces size=3></td>
+             <td><input name=decimalplaces size=3 value="2"></td>
          </tr>
                                     
 $jsscript
@@ -620,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>
@@ -687,8 +704,6 @@ $jsscript
   }
 
   if ($form->{report} =~ /^tax_/) {
-    $gifi = "";
-
     $form->{db} = ($form->{report} =~ /_collected/) ? "ar" : "ap";
 
     RP->get_taxaccounts(\%myconfig, \%$form);
@@ -725,32 +740,6 @@ $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>|
@@ -807,8 +796,6 @@ $jsscript
   }
 
   if ($form->{report} =~ /^nontaxable_/) {
-    $gifi = "";
-
     $form->{db} = ($form->{report} =~ /_sales/) ? "ar" : "ap";
 
     print qq|
@@ -872,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';
@@ -922,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);
@@ -1001,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');
@@ -1062,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
@@ -1188,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|;
   }
@@ -1205,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|;
   }
@@ -1215,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};
 
@@ -1254,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};
 
@@ -1347,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|
@@ -1382,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 =
@@ -1674,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>|;
@@ -1737,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=|
@@ -1852,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>
@@ -1883,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_templates) {
-      $media .= qq|
-            <option value=printer $form->{OP}{printer}>|
-        . $locale->text('Printer');
-    }
-  }
-
-  if ($latex_templates) {
-    $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_templates && $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();
 
@@ -2109,11 +2007,6 @@ sub print_form {
 
   $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";
 
   if ($form->{format} eq 'postscript') {
@@ -2141,7 +2034,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};
@@ -2187,7 +2079,13 @@ sub print_form {
       }
     }
   }
-
+  # 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();
 }
 
@@ -2200,10 +2098,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} },
@@ -2222,12 +2120,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
@@ -2240,9 +2132,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);
@@ -2705,7 +2594,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";
@@ -2778,8 +2676,6 @@ sub generate_bwa {
   $form->{endbold} = "</b>";
   $form->{br}      = "<br>";
 
-  #  &get_project(generate_bwa);
-
   if ($form->{reporttype} eq "custom") {
 
     #forgotten the year --> thisyear
@@ -2945,10 +2841,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|;
   }
@@ -2956,7 +2852,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";
@@ -2969,9 +2864,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 =
@@ -3125,7 +3019,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 |
@@ -3142,9 +3036,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|;
   }