From 73a78da630ce363f70062447dd82a8a0ece8cd89 Mon Sep 17 00:00:00 2001 From: Rolf Fluehmann Date: Mon, 4 Jan 2016 16:56:42 +0100 Subject: [PATCH] Form: round_amount precision support --- SL/DB/MetaSetup/Default.pm | 1 + SL/Form.pm | 7 ++++++- sql/Pg-upgrade2/defaults_add_precision.sql | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 sql/Pg-upgrade2/defaults_add_precision.sql diff --git a/SL/DB/MetaSetup/Default.pm b/SL/DB/MetaSetup/Default.pm index 49628afe6..af3da6ac7 100644 --- a/SL/DB/MetaSetup/Default.pm +++ b/SL/DB/MetaSetup/Default.pm @@ -76,6 +76,7 @@ __PACKAGE__->meta->columns( payments_changeable => { type => 'integer', default => '0', not_null => 1 }, pdonumber => { type => 'text' }, ponumber => { type => 'text' }, + precision => { type => 'numeric', precision => 15, scale => 5, default => '0.01', not_null => 1 }, profit_determination => { type => 'text' }, project_status_id => { type => 'integer' }, project_type_id => { type => 'integer' }, diff --git a/SL/Form.pm b/SL/Form.pm index 32064f3c0..b9263004b 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -947,10 +947,15 @@ sub parse_amount { } sub round_amount { - my ($self, $amount, $places) = @_; + my ($self, $amount, $places, $adjust) = @_; return 0 if !defined $amount; + 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 index 000000000..88f854cab --- /dev/null +++ b/sql/Pg-upgrade2/defaults_add_precision.sql @@ -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); + -- 2.20.1