]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Form.pm
TOTAL ERTRAG & AUFWAND ==> GEWINN/VERLUST
[mfinanz.git] / SL / Form.pm
index 099a6736e6181c6900cb93bfff2d032c0cb3f2f5..35050a0c7ac72325db63be0979af0fa297843d0c 100644 (file)
@@ -945,17 +945,15 @@ sub parse_amount {
     return 0;
   }
 
-  if (   ($myconfig->{numberformat} eq '1.000,00')
-      || ($myconfig->{numberformat} eq '1000,00')) {
+  if ($myconfig->{numberformat} eq '1,000.00') {
+    $amount =~ s/,//g;
+  } elsif ($myconfig->{numberformat} eq '1.000,00') {
     $amount =~ s/\.//g;
-    $amount =~ s/,/\./g;
-  }
-
-  if ($myconfig->{numberformat} eq "1'000.00") {
+  } elsif ($myconfig->{numberformat} eq "1'000.00") {
     $amount =~ s/\'//g;
   }
 
-  $amount =~ s/,//g;
+  $amount =~ s/,/\./g;
 
   $main::lxdebug->leave_sub(2);
 
@@ -969,7 +967,18 @@ sub parse_amount {
 }
 
 sub round_amount {
-  my ($self, $amount, $places) = @_;
+  my ($self, $amount, $places, $adjust) = @_;
+
+  if ($adjust) {
+    my $precision = 0.01;
+    # Round amounts to eight places before rounding to the requested
+    # number of places. This gets rid of errors due to internal floating
+    # point representation.
+    $amount = int($amount * 10**8 + .5 * ($amount <=> 0)) / 10**8  if $places < 8;
+    $amount = int($amount / ($precision = _get_precision()) + ($amount <=> 0) * .5) * $precision;
+    $amount = int($amount * 10**$places + .5 * ($amount <=> 0)) / 10**$places;
+    return $amount;
+  }
 
   return 0 if !defined $amount;
 
@@ -3685,6 +3694,20 @@ sub calculate_tax {
   return ($amount,$tax);
 };
 
+sub _get_precision {
+  my ( $self ) = @_;
+  my $precision = 0.01;
+  eval {
+    my $client = $::auth->{client};
+    my $dbconnect = 'dbi:Pg:dbname=' . $client->{dbname} . ';host=' . $client->{dbhost} . ';port=' . $client->{dbport};
+    my $dbh       = DBI->connect($dbconnect, $client->{dbuser}, $client->{dbpasswd});
+    my $query = q{ SELECT precision FROM defaults };
+    ($precision) = selectrow_query($::form, $dbh, $query);
+    $dbh->disconnect;
+  };
+  return $precision;
+}
+
 1;
 
 __END__