summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xLedgerSMB.pm9
-rw-r--r--LedgerSMB/Sysconfig.pm2
-rw-r--r--ledgersmb.conf.default3
-rw-r--r--scripts/payment.pl25
4 files changed, 24 insertions, 15 deletions
diff --git a/LedgerSMB.pm b/LedgerSMB.pm
index 1ea5e63c..cf480bd4 100755
--- a/LedgerSMB.pm
+++ b/LedgerSMB.pm
@@ -521,7 +521,14 @@ sub parse_amount {
sub round_amount {
my ( $self, $amount, $places ) = @_;
-
+
+ #
+ # We will grab the default value, if it isnt defined
+ #
+ if (!$places){
+ $places = ${LedgerSMB::Sysconfig::decimal_places};
+ }
+
# These rounding rules follow from the previous implementation.
# They should be changed to allow different rules for different accounts.
if ($amount >= 0) {
diff --git a/LedgerSMB/Sysconfig.pm b/LedgerSMB/Sysconfig.pm
index 4b50ab75..ca0e5d15 100644
--- a/LedgerSMB/Sysconfig.pm
+++ b/LedgerSMB/Sysconfig.pm
@@ -83,7 +83,7 @@ read_config( 'ledgersmb.conf' => %config ) or die;
# Root variables
for $var (
qw(pathsep logging check_max_invoices language auth latex
- db_autoupdate force_username_case max_post_size)
+ db_autoupdate force_username_case max_post_size decimal_places)
)
{
${$var} = $config{''}{$var} if $config{''}{$var};
diff --git a/ledgersmb.conf.default b/ledgersmb.conf.default
index 65fcfe0e..29bd705d 100644
--- a/ledgersmb.conf.default
+++ b/ledgersmb.conf.default
@@ -13,6 +13,9 @@ check_max_invoices : 5
# Maximum POST size to prevent DoS (4MB default)
max_post_size : 4194304
+# Define global settings for decimal places
+decimal_places : 2
+
[environment]
# If the server can't find applications, append to the path
PATH: /usr/local/pgsql/bin
diff --git a/scripts/payment.pl b/scripts/payment.pl
index dd3a309d..52142119 100644
--- a/scripts/payment.pl
+++ b/scripts/payment.pl
@@ -654,9 +654,9 @@ for my $ref (0 .. $#array_options) {
# LETS SET THE EXCHANGERATE VALUES
my $due_fx; my $topay_fx_value;
if ("$exchangerate") {
- $topay_fx_value = $due_fx = "$array_options[$ref]->{due}"/"$exchangerate" - "$array_options[$ref]->{discount}"/"$exchangerate";
+ $topay_fx_value = $due_fx = $request->round_amount("$array_options[$ref]->{due}"/"$exchangerate");
if ($request->{"optional_discount_$array_options[$ref]->{invoice_id}"}) {
- $topay_fx_value = $due_fx = $due_fx - "$array_options[$ref]->{discount}"/"$exchangerate";
+ $topay_fx_value = $due_fx = $request->round_amount($due_fx - "$array_options[$ref]->{discount}"/"$exchangerate");
}
} else {
$topay_fx_value = $due_fx = "N/A";
@@ -664,16 +664,15 @@ for my $ref (0 .. $#array_options) {
# We need to check for unhandled overpayment, see the post function for details
# First we will see if the discount should apply?
my $temporary_discount = 0;
- if (($request->{"optional_discount_$array_options[$ref]->{invoice_id}"})&&($due_fx <= $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} + $array_options[$ref]->{discount}/"$exchangerate")) {
- $temporary_discount = "$array_options[$ref]->{discount}"/"$exchangerate";
-
- }
+ if (($request->{"optional_discount_$array_options[$ref]->{invoice_id}"})&&($due_fx <= $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} + $request->round_amount($array_options[$ref]->{discount}/"$exchangerate"))) {
+ $temporary_discount = $request->round_amount("$array_options[$ref]->{discount}"/"$exchangerate");
+ }
# We need to compute the unhandled_overpayment, notice that all the values inside the if already have
# the exchangerate applied
if ( $due_fx < $request->{"topay_fx_$array_options[$ref]->{invoice_id}"}) {
# We need to store all the overpayments so we can use it on the screen
- $unhandled_overpayment = $unhandled_overpayment + $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} - $due_fx ;
- $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} = $due_fx;
+ $unhandled_overpayment = $request->round_amount($unhandled_overpayment + $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} - $due_fx );
+ $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} = "$due_fx";
}
push @invoice_data, { invoice => { number => $array_options[$ref]->{invnumber},
id => $array_options[$ref]->{invoice_id},
@@ -686,7 +685,7 @@ for my $ref (0 .. $#array_options) {
discount => $request->{"optional_discount_$array_options[$ref]->{invoice_id}"} ? "$array_options[$ref]->{discount}" : 0 ,
optional_discount => $request->{"optional_discount_$array_options[$ref]->{invoice_id}"},
exchange_rate => "$exchangerate",
- due_fx => $due_fx, # This was set at the begining of the for statement
+ due_fx => "$due_fx", # This was set at the begining of the for statement
topay => "$array_options[$ref]->{due}" - "$array_options[$ref]->{discount}",
source_text => $request->{"source_text_$array_options[$ref]->{invoice_id}"},
optional => $request->{"optional_pay_$array_options[$ref]->{invoice_id}"},
@@ -695,9 +694,9 @@ for my $ref (0 .. $#array_options) {
topay_fx => { name => "topay_fx_$array_options[$ref]->{invoice_id}",
value => $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} ?
$request->{"topay_fx_$array_options[$ref]->{invoice_id}"} eq 'N/A' ?
- $topay_fx_value :
+ "$topay_fx_value" :
$request->{"topay_fx_$array_options[$ref]->{invoice_id}"} :
- $topay_fx_value
+ "$topay_fx_value"
# Ugly hack, but works ;) ...
}#END HASH
};# END PUSH
@@ -799,7 +798,7 @@ my $select = {
vendorcustomer => { name => 'vendor-customer',
value => $request->{'vendor-customer'}
},
- unhandled_overpayment => { name => 'unhandledoverpayment', value => $unhandled_overpayment } ,
+ unhandled_overpayment => { name => 'unhandledoverpayment', value => "$unhandled_overpayment" } ,
vc => { name => $Payment->{company_name}, # We will assume that the first Billing Information as default
address => [ {text => $vc_options[0]->{'line_one'}},
{text => $vc_options[0]->{'line_two'}},
@@ -912,7 +911,7 @@ for my $ref (0 .. $#array_options) {
#
if ( "$array_options[$ref]->{due}"/"$request->{exrate}" < $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} + $temporary_discount ) {
# We need to store all the overpayments so we can use it on a new payment2 screen
- $unhandled_overpayment = $unhandled_overpayment + $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} + $temporary_discount - $array_options[$ref]->{amount} ;
+ $unhandled_overpayment = $request->round_amount($unhandled_overpayment + $request->{"topay_fx_$array_options[$ref]->{invoice_id}"} + $temporary_discount - $array_options[$ref]->{amount}) ;
}
if ($request->{"optional_discount_$array_options[$ref]->{invoice_id}"}) {