Fix zu Bug 220, Rabatt wurde nur fuer ein einzelnes Item berechnet.
[kivitendo-erp.git] / SL / RP.pm
index 7bd324b..c01a442 100644 (file)
--- a/SL/RP.pm
+++ b/SL/RP.pm
@@ -1336,7 +1336,7 @@ sub get_accounts_g {
   my @accno;
   my $accno;
   my $ref;
-
+  #print $query;
   my $sth = $dbh->prepare($query);
   $sth->execute || $form->dberror($query);
 
@@ -2088,7 +2088,7 @@ sub tax_report {
   my $ml = ($form->{db} eq 'ar') ? 1 : -1;
 
   my $sortorder = join ', ', $form->sort_columns(qw(transdate invnumber name));
-  $sortorder = $form->{sort} unless $sortorder;
+  $sortorder = $form->{sort} if $form->{sort};
 
   $query = qq|SELECT a.id, '0' AS invoice, $transdate AS transdate,
               a.invnumber, n.name, a.netamount,
@@ -2247,7 +2247,8 @@ sub payments {
 
   my $sortorder = join ', ',
     $form->sort_columns(qw(name invnumber ordnumber transdate source));
-
+    $sortorder = $form->{sort} if $form->{sort};
+    
   # cycle through each id
   foreach my $accno (split(/ /, $form->{paymentaccounts})) {
 
@@ -2344,13 +2345,14 @@ sub bwa {
     $form->{ "$key" . "gesamtleistung" } = 0;
     $form->{ "$key" . "gesamtkosten" }   = 0;
 
+
     foreach $category (@categories) {
 
       if (defined($form->{$category}{$key})) {
         $form->{"$key$category"} =
           $form->format_amount($myconfig,
                                $form->round_amount($form->{$category}{$key}, 2
-                               ));
+                               ), $form->{decimalplaces}, '0');
       }
     }
     foreach $item (@gesamtleistung) {
@@ -2372,8 +2374,8 @@ sub bwa {
       $form->{32}{$key} + $form->{33}{$key} + $form->{34}{$key};
     $form->{ "$key" . "ergebnisvorsteuern" } =
       $form->{ "$key" . "betriebsergebnis" } -
-      ($form->{ "$key" . "neutraleraufwand" } +
-       $form->{ "$key" . "neutralertrag" });
+      $form->{ "$key" . "neutraleraufwand" } +
+       $form->{ "$key" . "neutralertrag" };
     $form->{ "$key" . "ergebnis" } =
       $form->{ "$key" . "ergebnisvorsteuern" } + $form->{35}{$key};
 
@@ -2387,8 +2389,8 @@ sub bwa {
                                  ($form->{$category}{$key} /
                                     $form->{ "$key" . "gesamtleistung" } * 100
                                  ),
-                                 2
-                               ));
+                                 $form->{decimalplaces}
+                               ), $form->{decimalplaces}, '0');
         }
       }
       foreach $item (@ergebnisse) {
@@ -2398,8 +2400,8 @@ sub bwa {
                                  ( $form->{ "$key" . "$item" } /
                                      $form->{ "$key" . "gesamtleistung" } * 100
                                  ),
-                                 2
-                               ));
+                                 $form->{decimalplaces}
+                               ), $form->{decimalplaces}, '0');
       }
     }
 
@@ -2412,8 +2414,8 @@ sub bwa {
                                    ($form->{$category}{$key} /
                                       $form->{ "$key" . "gesamtkosten" } * 100
                                    ),
-                                   2
-                                 ));
+                                   $form->{decimalplaces}
+                                 ), $form->{decimalplaces}, '0');
         }
       }
       foreach $item (@ergebnisse) {
@@ -2423,8 +2425,8 @@ sub bwa {
                                    ($form->{ "$key" . "$item" } /
                                       $form->{ "$key" . "gesamtkosten" } * 100
                                    ),
-                                   2
-                               ));
+                                   $form->{decimalplaces}
+                               ), $form->{decimalplaces}, '0');
       }
     }
 
@@ -2435,8 +2437,9 @@ sub bwa {
             $form->format_amount(
                       $myconfig,
                       $form->round_amount(
-                        ($form->{$category}{$key} / $form->{10}{$key} * 100), 2
-                      ));
+                        ($form->{$category}{$key} / $form->{10}{$key} * 100), 
+                        $form->{decimalplaces}
+                      ), $form->{decimalplaces}, '0');
         }
       }
       foreach $item (@ergebnisse) {
@@ -2446,8 +2449,8 @@ sub bwa {
                                                 ($form->{ "$key" . "$item" } /
                                                    $form->{10}{$key} * 100
                                                 ),
-                                                2
-                               ));
+                                                $form->{decimalplaces}
+                               ), $form->{decimalplaces}, '0');
       }
     }
 
@@ -2458,8 +2461,9 @@ sub bwa {
             $form->format_amount(
                        $myconfig,
                        $form->round_amount(
-                         ($form->{$category}{$key} / $form->{4}{$key} * 100), 2
-                       ));
+                         ($form->{$category}{$key} / $form->{4}{$key} * 100), 
+                         $form->{decimalplaces}
+                       ), $form->{decimalplaces}, '0');
         }
       }
       foreach $item (@ergebnisse) {
@@ -2469,16 +2473,17 @@ sub bwa {
                                                 ($form->{ "$key" . "$item" } /
                                                    $form->{4}{$key} * 100
                                                 ),
-                                                2
-                               ));
+                                                $form->{decimalplaces}
+                               ), $form->{decimalplaces}, '0');
       }
     }
 
     foreach $item (@ergebnisse) {
       $form->{ "$key" . "$item" } =
         $form->format_amount($myconfig,
-                             $form->round_amount($form->{ "$key" . "$item" }, 2
-                             ));
+                             $form->round_amount($form->{ "$key" . "$item" }, 
+                             $form->{decimalplaces}
+                             ), $form->{decimalplaces}, '0');
     }
 
   }
@@ -2497,7 +2502,8 @@ sub ustva {
 
   my $last_period     = 0;
   my $category        = "pos_ustva";
-  my @categories_cent = qw(51r 86r 97r 93r 96 66 43 45 53 62 65 67);
+  my @categories_cent = qw(51r 511 86r 861 97r 971 93r 931
+                           96 66 43 45 53 62 65 67);
   my @categories_euro = qw(48 51 86 91 97 93 94);
   $form->{decimalplaces} *= 1;
 
@@ -2535,12 +2541,15 @@ sub ustva {
   #   }
   #
   #    }
-
-  $form->{"51r"} = $form->{"51"} * 0.16;
-  $form->{"86r"} = $form->{"86"} * 0.07;
-  $form->{"97r"} = $form->{"97"} * 0.16;
-  $form->{"93r"} = $form->{"93"} * 0.07;
-  $form->{"96"}  = $form->{"94"} * 0.16;
+  
+  #
+  # Berechnung der USTVA Formularfelder
+  #
+  $form->{"51r"} = $form->{"511"};
+  $form->{"86r"} = $form->{"861"};
+  $form->{"97r"} = $form->{"971"};
+  $form->{"93r"} = $form->{"931"};
+  #$form->{"96"}  = $form->{"94"} * 0.16;
   $form->{"43"}  =
     $form->{"51r"} + $form->{"86r"} + $form->{"97r"} + $form->{"93r"} +
     $form->{"96"};
@@ -2552,12 +2561,12 @@ sub ustva {
 
   foreach $item (@categories_cent) {
     $form->{$item} =
-      $form->format_amount($myconfig, $form->round_amount($form->{$item}, 2));
+      $form->format_amount($myconfig, $form->round_amount($form->{$item}, 2), 2, '0');
   }
 
   foreach $item (@categories_euro) {
     $form->{$item} =
-      $form->format_amount($myconfig, $form->round_amount($form->{$item}, 0));
+      $form->format_amount($myconfig, $form->round_amount($form->{$item}, 0), 0, '0');
   }
 
   $dbh->disconnect;