[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [2207] trunk



Revision: 2207
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2207&view=rev
Author:   einhverfr
Date:     2008-07-10 12:32:46 -0700 (Thu, 10 Jul 2008)

Log Message:
-----------
Committing David Mora's rounding fix.  May require new lines in ledgersmb.conf for those testing.

Modified Paths:
--------------
    trunk/LedgerSMB/Sysconfig.pm
    trunk/LedgerSMB.pm
    trunk/ledgersmb.conf.default
    trunk/scripts/payment.pl

Modified: trunk/LedgerSMB/Sysconfig.pm
===================================================================
--- trunk/LedgerSMB/Sysconfig.pm	2008-07-10 18:57:13 UTC (rev 2206)
+++ trunk/LedgerSMB/Sysconfig.pm	2008-07-10 19:32:46 UTC (rev 2207)
@@ -83,7 +83,7 @@
 # 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};

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2008-07-10 18:57:13 UTC (rev 2206)
+++ trunk/LedgerSMB.pm	2008-07-10 19:32:46 UTC (rev 2207)
@@ -521,7 +521,14 @@
 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) {

Modified: trunk/ledgersmb.conf.default
===================================================================
--- trunk/ledgersmb.conf.default	2008-07-10 18:57:13 UTC (rev 2206)
+++ trunk/ledgersmb.conf.default	2008-07-10 19:32:46 UTC (rev 2207)
@@ -13,6 +13,9 @@
 # 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

Modified: trunk/scripts/payment.pl
===================================================================
--- trunk/scripts/payment.pl	2008-07-10 18:57:13 UTC (rev 2206)
+++ trunk/scripts/payment.pl	2008-07-10 19:32:46 UTC (rev 2207)
@@ -654,9 +654,9 @@
 # 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 @@
 # 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 @@
                                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 @@
                                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 @@
   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 @@
          #
      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}"}) {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.