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

SF.net SVN: ledger-smb:[3129] addons/1.3/enhanced_tb/trunk



Revision: 3129
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3129&view=rev
Author:   einhverfr
Date:     2011-03-18 22:46:07 +0000 (Fri, 18 Mar 2011)

Log Message:
-----------
Precision handling now moved into controller script to allow for future work done for localized rounding rules.

Modified Paths:
--------------
    addons/1.3/enhanced_tb/trunk/LedgerSMB/DBObject/TrialBalance.pm
    addons/1.3/enhanced_tb/trunk/scripts/trial_balance.pl
    addons/1.3/enhanced_tb/trunk/sql/modules/trial_balance.sql

Modified: addons/1.3/enhanced_tb/trunk/LedgerSMB/DBObject/TrialBalance.pm
===================================================================
--- addons/1.3/enhanced_tb/trunk/LedgerSMB/DBObject/TrialBalance.pm	2011-03-18 21:55:43 UTC (rev 3128)
+++ addons/1.3/enhanced_tb/trunk/LedgerSMB/DBObject/TrialBalance.pm	2011-03-18 22:46:07 UTC (rev 3129)
@@ -94,7 +94,8 @@
         $self->{heading},
         $self->_db_array_literal( @{$self->{accounts}} ), # Creates the array literal
         $ignore_yearend,
-        $self->{department}
+        $self->{department},
+        $self->{precision}
     ]);
     return ..hidden..;
 }

Modified: addons/1.3/enhanced_tb/trunk/scripts/trial_balance.pl
===================================================================
--- addons/1.3/enhanced_tb/trunk/scripts/trial_balance.pl	2011-03-18 21:55:43 UTC (rev 3128)
+++ addons/1.3/enhanced_tb/trunk/scripts/trial_balance.pl	2011-03-18 22:46:07 UTC (rev 3129)
@@ -272,7 +272,11 @@
     $report->request_merge($request);
     
     my @rep_acc = ();
-    
+    if ($request->{discrete_amounts}){
+        $report->{precision} = $LedgerSMB::Sysconfig::decimal_places;
+    } else {
+        $report->{precision} = undef;
+    }
     my $total_debits = new Math::BigFloat(0);
     my $total_credits = new Math::BigFloat(0);
     # print STDERR Dumper($report->run());

Modified: addons/1.3/enhanced_tb/trunk/sql/modules/trial_balance.sql
===================================================================
--- addons/1.3/enhanced_tb/trunk/sql/modules/trial_balance.sql	2011-03-18 21:55:43 UTC (rev 3128)
+++ addons/1.3/enhanced_tb/trunk/sql/modules/trial_balance.sql	2011-03-18 22:46:07 UTC (rev 3129)
@@ -22,7 +22,7 @@
 
 CREATE OR REPLACE FUNCTION trial_balance__generate 
 (i_date_from DATE, i_date_to DATE, in_heading INT, in_accounts INT[],
- in_ignore_yearend TEXT, in_department INT, in_discrete_amounts bool) 
+ in_ignore_yearend TEXT, in_department INT, in_precision int) 
 returns setof tb_row AS
 $$
 DECLARE
@@ -37,11 +37,7 @@
     include_trans   INT;
     precision    int;
 BEGIN
-    IF in_discrete_amounts THEN
-       SELECT value INTO precision 
-         FROM defaults
-        WHERE setting_key = 'decimal_places';
-    END IF;
+    precision := coalesce(in_precision, 1000);
     -- don't bother with checking from/to dates for NULL below.
     IF i_date_from IS NULL THEN
      SELECT min(transdate) - '1 day'::interval INTO date_from from acc_trans;
@@ -96,9 +92,9 @@
                 -- main trial balance query
 		SELECT a.id, a.accno, a.description, a.gifi_accno,
 			(COALESCE(SUM(CASE WHEN ac.transdate < date_from 
-                THEN COALESCE(round(ac.amount, COALESCE(precision, 1000)), 0) 
+                THEN COALESCE(round(ac.amount, precision), 0) 
                 ELSE 0 END), 0) + 
-                COALESCE(round(cpa.amount, COALESCE(precision, 1000)), 0))
+                COALESCE(round(cpa.amount, precision), 0))
                 * CASE WHEN a.contra THEN -1 ELSE 1 END
 				* CASE WHEN a.category IN ('A', 'E') THEN -1 ELSE 1 END,
 			
@@ -107,17 +103,17 @@
 			-- between the start checkpoint and the start_date.
 			-- Most conditions are for the case of either start or the
 			-- checkpoint missing.
-			COALESCE(abs(round(cpb.debits, COALESCE(precision, 1000))), 0) +
+			COALESCE(abs(round(cpb.debits, precision)), 0) +
 			COALESCE(SUM(CASE WHEN COALESCE(ac.amount, 1) > 0 THEN 0
 			ELSE
 			    CASE WHEN (cpb.end_date IS NOT NULL
 			               AND ac.transdate > cpb.end_date) OR
 			               (cpb.end_date IS NULL
 			               AND ac.transdate >= date_from) 
-			            THEN round(ac.amount, COALESCE(precision, 1000)) * -1
+			            THEN round(ac.amount, precision) * -1
 			        WHEN (cpb.end_date IS NOT NULL AND
 			              ac.transdate < date_from)
-			            THEN round(ac.amount, COALESCE(precision, 1000)) * -1
+			            THEN round(ac.amount, precision) * -1
 			        ELSE 0
 			    END
 			END), 0) - 
@@ -128,14 +124,14 @@
 			ELSE 0 END,
 			
 			-- see comment in debits for explanation of the case below.            
-            COALESCE(round(cpb.credits, COALESCE(precision, 1000)), 0) +     
+            COALESCE(round(cpb.credits, precision), 0) +     
             COALESCE(SUM (CASE WHEN COALESCE(ac.amount, -1) < 0 THEN 0 
             ELSE    
                 CASE WHEN (cpb.end_date IS NOT NULL 
                            AND ac.transdate > cpb.end_date) OR
                            (cpb.end_date IS NULL 
                            AND ac.transdate >= date_from)
-                        THEN round(ac.amount, COALESCE(precision, 1000))
+                        THEN round(ac.amount, precision)
                      WHEN (cpb.end_date IS NOT NULL AND 
                            ac.transdate < date_from)
                         THEN -ac.amount
@@ -150,8 +146,8 @@
 			               ac.transdate > cpb.end_date) AND 
 		                   (ac.transdate >= date_from)
                         THEN 
-                        COALESCE(round(ac.amount, COALESCE(precision, 1000)), 0) ELSE 0 END), 0) +
-                        COALESCE(round(cpb.amount, COALESCE(precision, 1000)), 0))
+                        COALESCE(round(ac.amount, precision), 0) ELSE 0 END), 0) +
+                        COALESCE(round(cpb.amount, precision), 0))
                * CASE WHEN a.contra 
                         THEN -1 ELSE 1 END
                * CASE WHEN a.category IN ('A', 'E') 


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