Reapply "Form: round_amount precision support"
authorSven Schöling <s.schoeling@linet-services.de>
Mon, 4 Apr 2016 11:39:32 +0000 (13:39 +0200)
committerSven Schöling <s.schoeling@linet-services.de>
Mon, 4 Apr 2016 11:39:32 +0000 (13:39 +0200)
Und mit neuer Autorschaft neu.

SL/DB/MetaSetup/Default.pm
SL/Form.pm
sql/Pg-upgrade2/defaults_add_precision.sql [new file with mode: 0644]

index 4f0fcf0..96c4b0f 100644 (file)
@@ -78,6 +78,7 @@ __PACKAGE__->meta->columns(
   payments_changeable                       => { type => 'integer', default => '0', not_null => 1 },
   pdonumber                                 => { type => 'text' },
   ponumber                                  => { type => 'text' },
+  precision                                 => { type => 'numeric', default => '0.01', not_null => 1, precision => 15, scale => 5 },
   profit_determination                      => { type => 'text' },
   project_status_id                         => { type => 'integer' },
   project_type_id                           => { type => 'integer' },
index 9dbe7a7..98bb4db 100644 (file)
@@ -948,12 +948,17 @@ sub parse_amount {
 }
 
 sub round_amount {
-  my ($self, $amount, $places) = @_;
+  my ($self, $amount, $places, $adjust) = @_;
 
   return 0 if !defined $amount;
 
   $places //= 0;
 
+  if ($adjust) {
+    my $precision = $::instance_conf->get_precision || 0.01;
+    return $self->round_amount( $self->round_amount($amount / $precision, 0) * $precision, $places);
+  }
+
   # We use Perl's knowledge of string representation for
   # rounding. First, convert the floating point number to a string
   # with a high number of places. Then split the string on the decimal
diff --git a/sql/Pg-upgrade2/defaults_add_precision.sql b/sql/Pg-upgrade2/defaults_add_precision.sql
new file mode 100644 (file)
index 0000000..88f854c
--- /dev/null
@@ -0,0 +1,5 @@
+-- @tag: defaults_add_precision
+-- @description: adds new column 'precision' in table defaults, used to round amounts
+-- @depends: release_3_0_0
+ALTER TABLE defaults ADD COLUMN precision NUMERIC(15,5) NOT NULL DEFAULT(0.01);
+