Much better presentation of new Balance Sheet, P&L Statement and Monthly Breakdown.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Sun, 14 Jun 2009 10:38:01 +0000 (10:38 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Sun, 14 Jun 2009 10:38:01 +0000 (10:38 +0000)
CHANGELOG.txt
gl/includes/db/gl_db_account_types.inc
gl/includes/db/gl_db_accounts.inc
reporting/rep705.php
reporting/rep706.php
reporting/rep707.php

index 17d44a9dc2b87b17b3f4cacea355e826d4578112..2e869c16b4a38a970f8abf60d6fb1e99df2343e8 100644 (file)
@@ -19,6 +19,14 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+14-Jun-2009 Joe Hunt
+! Much better presentation of new Balance Sheet, P&L Statement and Monthly Breakdown.
+$ /gl/includes/db/gl_db_account_types.inc
+  /gl/includes/db/gl_db_accounts.inc
+  /reporting/rep705.php
+  /reporting/rep706.php
+  /reporting/rep707.php
+  
 13-Jun-2009 Joe Hunt/Pete/Tom Moulton
 ! Changed next reference method to also include partly alpha characters in front, fi. WA036 increments to WA037
 $ /includes/references.inc
index d731b80b66cbb4aa83d64a08528d6d79030434a1..ae6011cd1a9052c33f2d3b89e25bcac6ca1b4708 100644 (file)
@@ -100,17 +100,6 @@ function get_account_class_name($id)
        return $row[0];
 }
 
-function get_account_class_convert($id)
-{
-       global $class_types;
-       $sql = "SELECT balance_sheet FROM ".TB_PREF."chart_class WHERE cid = $id";
-
-       $result = db_query($sql, "could not get class type");
-
-       $row = db_fetch_row($result);
-       return (($row[0] == CL_LIABILITIES || $row[0] == CL_EQUITY || $row[0] == CL_INCOME || $row[0] == 0) ? -1 : 1); // backwards compatibility
-}
-
 function delete_account_class($id)
 {
        $sql = "DELETE FROM ".TB_PREF."chart_class WHERE cid = $id";
index bcecad749aba6f546f97e4c7ba22f27bd3e6ab64..414ad8e277f727c92035c807c25051bba7ee691d 100644 (file)
@@ -56,7 +56,8 @@ function get_gl_accounts_all($balance=-1)
        elseif ($balance == 0)  
                $where ="WHERE balance_sheet>".CL_EQUITY." OR balance_sheet=0"; // backwards compatibility
        $sql = "SELECT ".TB_PREF."chart_master.account_code, ".TB_PREF."chart_master.account_name, ".TB_PREF."chart_types.name AS AccountTypeName,".TB_PREF."chart_types.id AS AccountType,
-               ".TB_PREF."chart_types.parent, ".TB_PREF."chart_class.class_name AS AccountClassName, ".TB_PREF."chart_class.cid AS ClassID 
+               ".TB_PREF."chart_types.parent, ".TB_PREF."chart_class.class_name AS AccountClassName, ".TB_PREF."chart_class.cid AS ClassID, 
+               ".TB_PREF."chart_class.balance_sheet AS ClassType
                FROM ".TB_PREF."chart_types INNER JOIN ".TB_PREF."chart_class ON ".TB_PREF."chart_types.class_id=".TB_PREF."chart_class.cid
                LEFT JOIN ".TB_PREF."chart_master ON ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id ";
        if ($balance != -1)
index 341d6e5dd586ceb32b0e837b45de67152cffb8f4..610a82bd4675ff213a102cf3a2e45bbb87d8c37c 100644 (file)
@@ -200,6 +200,7 @@ function print_annual_expense_breakdown()
 
        $closeclass = false;
        $convert = 1;
+       $ctype = 0;
 
        $accounts = get_gl_accounts_all(0);
 
@@ -230,7 +231,7 @@ function print_annual_expense_breakdown()
                        {
                                for ( ; $level >= 0, $typename[$level] != ''; $level--) 
                                {
-                                       if ($account['parent'] == $closing[$level] || $account['parent'] < $last)
+                                       if ($account['parent'] == $closing[$level] || $account['parent'] < $last || $account['parent'] <= 0)
                                        {
                                                $rep->row += 6;
                                                $rep->Line($rep->row);
@@ -282,8 +283,9 @@ function print_annual_expense_breakdown()
                        $rep->Line($rep->row);
                        $rep->NewLine();
                }
-               $convert = get_account_class_convert($account['ClassID']);
                $classname = $account['AccountClassName'];
+               $ctype = $account['ClassType'];
+               $convert = (($ctype == CL_INCOME || $ctype == 0) ? -1 : 1); // backwards compatibility
 
                if ($account['account_code'] != null)
                {
@@ -325,7 +327,7 @@ function print_annual_expense_breakdown()
                {
                        for ( ; $level >= 0, $typename[$level] != ''; $level--) 
                        {
-                               if ($account['parent'] == $closing[$level] || $account['parent'] < $last)
+                               if ($account['parent'] == $closing[$level] || $account['parent'] < $last || $account['parent'] <= 0)
                                {
                                        $rep->row += 6;
                                        $rep->Line($rep->row);
index 91261cf8dab5a04b9a9cced5f3062ea71173e814..a8c64ec720839466a7fce992e4649eec9db8fe88 100644 (file)
@@ -112,6 +112,12 @@ function print_balance_sheet()
        $assetsopen = 0.0;
        $assetsperiod = 0.0;
        $assetsclose = 0.0;
+       $equityopen = 0.0;
+       $equityperiod = 0.0;
+       $equityclose = 0.0;
+       $lopen = 0.0;
+       $lperiod = 0.0;
+       $lclose = 0.0;
        
        $typeopen = array(0,0,0,0,0,0,0,0,0,0);
        $typeperiod = array(0,0,0,0,0,0,0,0,0,0);
@@ -123,6 +129,7 @@ function print_balance_sheet()
        $last = -1;
        
        $closeclass = false;
+       $ctype = 0;
        $convert = 1;
        $rep->NewLine();
 
@@ -157,7 +164,7 @@ function print_balance_sheet()
                        {
                                for ( ; $level >= 0, $typename[$level] != ''; $level--) 
                                {
-                                       if ($account['parent'] == $closing[$level] || $account['parent'] < $last)
+                                       if ($account['parent'] == $closing[$level] || $account['parent'] < $last || $account['parent'] <= 0)
                                        {
                                                $rep->row += 6;
                                                $rep->Line($rep->row);
@@ -189,6 +196,18 @@ function print_balance_sheet()
                                        $rep->AmountCol(3, 4, $classperiod * $convert, $dec);
                                        $rep->AmountCol(4, 5, $classclose * $convert, $dec);
                                        $rep->Font();
+                                       if ($ctype == CL_EQUITY)
+                                       {
+                                               $equityopen += $classopen;
+                                               $equityperiod += $classperiod;
+                                               $equityclose += $classclose;
+                                       }
+                                       if ($ctype == CL_LIABILITIES)
+                                       {
+                                               $lopen += $classopen;
+                                               $lperiod += $classperiod;
+                                               $lclose += $classclose;
+                                       }
                                        $assetsopen += $classopen;
                                        $assetsperiod += $classperiod;
                                        $assetsclose += $classclose;
@@ -215,8 +234,9 @@ function print_balance_sheet()
                        $rep->Line($rep->row);
                        $rep->NewLine();
                }
-               $convert = get_account_class_convert($account['ClassID']);
                $classname = $account['AccountClassName'];
+               $ctype = $account['ClassType'];
+               $convert = (($ctype == CL_LIABILITIES || $ctype == CL_EQUITY || $ctype == 0) ? -1 : 1); // backwards compatibility
 
                if ($account['account_code'] != null)
                {
@@ -254,11 +274,14 @@ function print_balance_sheet()
        }
        if ($account['AccountTypeName'] != $typename[$level])
        {
+               //$rep->NewLine();
+               //$rep->TextCol(0, 5,   "type = ".$account['AccountType'].", level = $level, closing[0]-[1]-[2]-[3] = ".$closing[0]." ".$closing[1]." ".$closing[2]." ".$closing[3]." type[parent] = ".$account['parent']." last = ".$last);
+               //$rep->NewLine();
                if ($typename[$level] != '')
                {
                        for ( ; $level >= 0, $typename[$level] != ''; $level--) 
                        {
-                               if ($account['parent'] == $closing[$level] || $account['parent'] < $last)
+                               if ($account['parent'] == $closing[$level] || $account['parent'] < $last || $account['parent'] <= 0)
                                {
                                        $rep->row += 6;
                                        $rep->Line($rep->row);
@@ -284,6 +307,12 @@ function print_balance_sheet()
                                $calculateopen = -$assetsopen - $classopen;
                                $calculateperiod = -$assetsperiod - $classperiod;
                                $calculateclose = -$assetsclose  - $classclose;
+                               if ($ctype == CL_EQUITY)
+                               {
+                                       $equityopen += $classopen;
+                                       $equityperiod += $classperiod;
+                                       $equityclose += $classclose;
+                               }
                                $rep->row += 6;
                                $rep->Line($rep->row);
                                $rep->NewLine();
@@ -302,8 +331,19 @@ function print_balance_sheet()
                                $rep->AmountCol(2, 3, -$assetsopen * $convert, $dec);
                                $rep->AmountCol(3, 4, -$assetsperiod * $convert, $dec);
                                $rep->AmountCol(4, 5, -$assetsclose * $convert, $dec);
-                               $rep->Font();
                                $rep->NewLine();
+                               if ($equityopen != 0.0 || $equityperiod != 0.0 || $equityclose != 0.0 ||
+                                       $lopen != 0.0 || $lperiod != 0.0 || $lclose != 0.0)
+                               {
+                                       $rep->NewLine();
+                                       $rep->TextCol(0, 2,     _('Total') . " " . _('Liabilities') . _(' and ') . _('Equities'));
+                                       $rep->AmountCol(2, 3, ($lopen + $equityopen + $calculateopen) * -1, $dec);
+                                       $rep->AmountCol(3, 4, ($lperiod + $equityperiod + $calculateperiod) * -1, $dec);
+                                       $rep->AmountCol(4, 5, ($lclose + $equityclose + $calculateclose) * -1, $dec);
+                                       $rep->Font();
+                                       $rep->NewLine();
+                               }
+                               $rep->Font();
                        }
                }
        }
index df551fc36fd1770359b7505b830e71b8c2b936df..7ce02b2c8c8594db6c8f2ed5b07782c549ebbd49 100644 (file)
@@ -156,6 +156,7 @@ function print_profit_and_loss_statement()
 
        $closeclass = false;
        $convert = 1;
+       $ctype = 0;
 
        $accounts = get_gl_accounts_all(0);
 
@@ -190,7 +191,7 @@ function print_profit_and_loss_statement()
                        {
                                for ( ; $level >= 0, $typename[$level] != ''; $level--) 
                                {
-                                       if ($account['parent'] == $closing[$level] || $account['parent'] < $last)
+                                       if ($account['parent'] == $closing[$level] || $account['parent'] < $last || $account['parent'] <= 0)
                                        {
                                                $rep->row += 6;
                                                $rep->Line($rep->row);
@@ -248,8 +249,9 @@ function print_profit_and_loss_statement()
                        $rep->Line($rep->row);
                        $rep->NewLine();
                }
-               $convert = get_account_class_convert($account['ClassID']);
                $classname = $account['AccountClassName'];
+               $ctype = $account['ClassType'];
+               $convert = (($ctype == CL_INCOME || $ctype == 0) ? -1 : 1); // backwards compatibility
 
                if ($account['account_code'] != null)
                {
@@ -292,7 +294,7 @@ function print_profit_and_loss_statement()
                {
                        for ( ; $level >= 0, $typename[$level] != ''; $level--) 
                        {
-                               if ($account['parent'] == $closing[$level] || $account['parent'] < $last)
+                               if ($account['parent'] == $closing[$level] || $account['parent'] < $last || $account['parent'] <= 0)
                                {
                                        $rep->row += 6;
                                        $rep->Line($rep->row);