Changed balance_sheet operation in class table to class type for sign convert in...
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Thu, 11 Jun 2009 11:56:17 +0000 (11:56 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Thu, 11 Jun 2009 11:56:17 +0000 (11:56 +0000)
CHANGELOG.txt
gl/includes/db/gl_db_account_types.inc
gl/includes/db/gl_db_accounts.inc
gl/inquiry/gl_trial_balance.php
gl/manage/gl_account_classes.php
includes/types.inc
includes/ui/ui_lists.inc
reporting/rep705.php
reporting/rep706.php
reporting/rep707.php
reporting/rep708.php

index baf92580440fc16e47bc22efbe81213a29fc1d48..ee629ad8a715aceb2790ddeb5a498984f0eca521 100644 (file)
@@ -19,6 +19,18 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+11-Jun-2009 Joe Hunt
+! Changed balance_sheet operation in class table to class type for sign convert in Balance Sheet, Profit and Loss Statement and Monthly Breakdown
+$ /gl/manage/gl_account_classes.php
+  /gl/includes/db/gl_db_account_types.inc
+  /gl/includes/db/gl_db_accounts.inc
+  /gl/inquiry/gl_trial_balance.php
+  /includes/types.inc
+  /reporting/rep705.php
+  /reporting/rep706.php
+  /reporting/rep707.php
+  /reporting/rep708.php
+  
 09-Jun-2009 Joe Hunt
 # Bad format in due date column in search dimensions
 $ /dimensions/inquiry/search_dimensions.php
index f5375bbddb8414602b702310777f25edba48192f..d731b80b66cbb4aa83d64a08528d6d79030434a1 100644 (file)
@@ -100,6 +100,16 @@ 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)
 {
index b544094e325551c51f0afd1fb79f308ff349513e..bcecad749aba6f546f97e4c7ba22f27bd3e6ab64 100644 (file)
@@ -51,13 +51,17 @@ function get_gl_accounts($from=null, $to=null)
 
 function get_gl_accounts_all($balance=-1)
 {
-        $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
+       if ($balance == 1)
+               $where ="WHERE balance_sheet>0 AND balance_sheet<".CL_INCOME;
+       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 
                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)
-               $sql .= "WHERE ".TB_PREF."chart_class.balance_sheet=$balance ";                                 
-        $sql .= "ORDER BY ".TB_PREF."chart_class.cid, IF(parent > 0,parent,".TB_PREF."chart_types.id), 
+               $sql .= $where;                                 
+        $sql .= " ORDER BY ".TB_PREF."chart_class.cid, IF(parent > 0,parent,".TB_PREF."chart_types.id), 
                IF(parent > 0,".TB_PREF."chart_types.id, parent), ".TB_PREF."chart_master.account_code";
 
        return db_query($sql, "could not get gl accounts");
@@ -80,7 +84,7 @@ function is_account_balancesheet($code)
 
        $result = db_query($sql,"could not retreive the account class for $code");
        $row = db_fetch_row($result);
-       return $row[0];
+       return $row[0] > 0 && $row[0] < CL_INCOME;
 }
 
 function get_gl_account_name($code)
index 27fc37df0e70b185ccf17a2f85d094e64c31fa70..6d33b98c7ff254cf373bd40e4102dcb05e3f351b 100644 (file)
@@ -66,7 +66,7 @@ function get_balance($account, $from, $to, $from_incl=true, $to_incl=true)
        if ($from_incl)
                $sql .= " tran_date >= '$from_date'  AND";
        else
-               $sql .= " tran_date > IF(".TB_PREF."chart_class.balance_sheet=1, '0000-00-00', '$from_date') AND";
+               $sql .= " tran_date > IF(balance_sheet>0 AND balance_sheet<".CL_INCOME.", '0000-00-00', '$from_date') AND";
        $to_date = date2sql($to);
        if ($to_incl)
                $sql .= " tran_date <= '$to_date' ";
index 65a6429d37c472ded2bf2a606ecbdcd8e828472e..9015c5835b4af0a378de734cae698c3a30534f15 100644 (file)
@@ -106,7 +106,7 @@ if ($Mode == 'RESET')
 $result = get_account_classes();
 start_form();
 start_table($table_style);
-$th = array(_("Class ID"), _("Class Name"), _("Balance Sheet"), "", "");
+$th = array(_("Class ID"), _("Class Name"), _("Class Type"), "", "");
 table_header($th);
 
 $k = 0;
@@ -115,17 +115,9 @@ while ($myrow = db_fetch($result))
 
        alt_table_row_color($k);
 
-       if ($myrow["balance_sheet"] == 0) 
-       {
-               $bs_text = _("No");
-       } 
-       else 
-       {
-               $bs_text = _("Yes");
-       }
        label_cell($myrow["cid"]);
        label_cell($myrow['class_name']);
-       label_cell($bs_text);
+       label_cell($class_types[$myrow["balance_sheet"]]);
        edit_button_cell("Edit".$myrow["cid"], _("Edit"));
        delete_button_cell("Delete".$myrow["cid"], _("Delete"));
        end_row();
@@ -163,7 +155,7 @@ else
 
 text_row_ex(_("Class Name:"), 'name', 50, 60);
 
-yesno_list_row(_("Balance Sheet:"), 'Balance', null, "", "", false);
+class_types_list_row(_("Class Type:"), 'Balance', null);
 
 end_table(1);
 
index 38c3101b39009e04d9247cf99647ce98abe25059..e12efa0d088164faa73059d0a5b34f27e2354aba 100644 (file)
@@ -309,6 +309,22 @@ class wo_types
        }
 }
 
+define('CL_ASSETS', 1);
+define('CL_LIABILITIES', 2);
+define('CL_EQUITY', 3);
+define('CL_INCOME', 4);
+define('CL_COGS', 5);
+define('CL_EXPENSE', 6);
+
+$class_types = array(
+               CL_ASSETS => _("Assets"),
+               CL_LIABILITIES => _("Liabilities"),
+               CL_EQUITY => _("Equity"),
+               CL_INCOME => _("Income"),
+               CL_COGS => _("Cost of Goods Sold"),
+               CL_EXPENSE => _("Expense"),
+);
+
 define('WO_LABOUR', 0);
 define('WO_OVERHEAD', 1);
 
index a1b65af1bc4472cd0f1c15fc0f40ce5277347726..f136c38229cccdced7113d1c99ee5d869689a716 100644 (file)
@@ -2067,4 +2067,17 @@ function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on
 }
 
 
+function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
+{
+       global $class_types;
+       
+       echo "<tr><td>$label</td><td>";
+       array_selector($name, $selected_id, $class_types, 
+               array( 
+                       'select_submit'=> $submit_on_change
+               ) );
+       echo "</td></tr>\n";
+}
+
+
 ?>
\ No newline at end of file
index b3927d4ce1c038d35b571e0b6bba3ad136513ac2..341d6e5dd586ceb32b0e837b45de67152cffb8f4 100644 (file)
@@ -47,18 +47,18 @@ function getPeriods($year, $account, $dimension, $dimension2)
        $date02 = date('Y-m-d',mktime(0,0,0,$mo-10,1,$yr));
        $date01 = date('Y-m-d',mktime(0,0,0,$mo-11,1,$yr));
 
-    $sql = "SELECT SUM(CASE WHEN tran_date >= '$date01' AND tran_date < '$date02' THEN -amount / 1000 ELSE 0 END) AS per01,
-                               SUM(CASE WHEN tran_date >= '$date02' AND tran_date < '$date03' THEN -amount / 1000 ELSE 0 END) AS per02,
-                               SUM(CASE WHEN tran_date >= '$date03' AND tran_date < '$date04' THEN -amount / 1000 ELSE 0 END) AS per03,
-                               SUM(CASE WHEN tran_date >= '$date04' AND tran_date < '$date05' THEN -amount / 1000 ELSE 0 END) AS per04,
-                               SUM(CASE WHEN tran_date >= '$date05' AND tran_date < '$date06' THEN -amount / 1000 ELSE 0 END) AS per05,
-                               SUM(CASE WHEN tran_date >= '$date06' AND tran_date < '$date07' THEN -amount / 1000 ELSE 0 END) AS per06,
-                               SUM(CASE WHEN tran_date >= '$date07' AND tran_date < '$date08' THEN -amount / 1000 ELSE 0 END) AS per07,
-                               SUM(CASE WHEN tran_date >= '$date08' AND tran_date < '$date09' THEN -amount / 1000 ELSE 0 END) AS per08,
-                               SUM(CASE WHEN tran_date >= '$date09' AND tran_date < '$date10' THEN -amount / 1000 ELSE 0 END) AS per09,
-                               SUM(CASE WHEN tran_date >= '$date10' AND tran_date < '$date11' THEN -amount / 1000 ELSE 0 END) AS per10,
-                               SUM(CASE WHEN tran_date >= '$date11' AND tran_date < '$date12' THEN -amount / 1000 ELSE 0 END) AS per11,
-                               SUM(CASE WHEN tran_date >= '$date12' AND tran_date < '$date13' THEN -amount / 1000 ELSE 0 END) AS per12
+    $sql = "SELECT SUM(CASE WHEN tran_date >= '$date01' AND tran_date < '$date02' THEN amount / 1000 ELSE 0 END) AS per01,
+                               SUM(CASE WHEN tran_date >= '$date02' AND tran_date < '$date03' THEN amount / 1000 ELSE 0 END) AS per02,
+                               SUM(CASE WHEN tran_date >= '$date03' AND tran_date < '$date04' THEN amount / 1000 ELSE 0 END) AS per03,
+                               SUM(CASE WHEN tran_date >= '$date04' AND tran_date < '$date05' THEN amount / 1000 ELSE 0 END) AS per04,
+                               SUM(CASE WHEN tran_date >= '$date05' AND tran_date < '$date06' THEN amount / 1000 ELSE 0 END) AS per05,
+                               SUM(CASE WHEN tran_date >= '$date06' AND tran_date < '$date07' THEN amount / 1000 ELSE 0 END) AS per06,
+                               SUM(CASE WHEN tran_date >= '$date07' AND tran_date < '$date08' THEN amount / 1000 ELSE 0 END) AS per07,
+                               SUM(CASE WHEN tran_date >= '$date08' AND tran_date < '$date09' THEN amount / 1000 ELSE 0 END) AS per08,
+                               SUM(CASE WHEN tran_date >= '$date09' AND tran_date < '$date10' THEN amount / 1000 ELSE 0 END) AS per09,
+                               SUM(CASE WHEN tran_date >= '$date10' AND tran_date < '$date11' THEN amount / 1000 ELSE 0 END) AS per10,
+                               SUM(CASE WHEN tran_date >= '$date11' AND tran_date < '$date12' THEN amount / 1000 ELSE 0 END) AS per11,
+                               SUM(CASE WHEN tran_date >= '$date12' AND tran_date < '$date13' THEN amount / 1000 ELSE 0 END) AS per12
                        FROM ".TB_PREF."gl_trans
                                WHERE account='$account'";
        if ($dimension > 0)
@@ -198,6 +198,9 @@ function print_annual_expense_breakdown()
        $level = 0;
        $last = -1;
 
+       $closeclass = false;
+       $convert = 1;
+
        $accounts = get_gl_accounts_all(0);
 
        while ($account=db_fetch($accounts))
@@ -235,7 +238,7 @@ function print_annual_expense_breakdown()
                                                $rep->TextCol(0, 2,     _('Total') . " " . $typename[$level]);
                                                for ($i = 1; $i <= 12; $i++)
                                                {
-                                                       $rep->AmountCol($i + 1, $i + 2, $total[$level][$i], $dec);
+                                                       $rep->AmountCol($i + 1, $i + 2, $total[$level][$i] * $convert, $dec);
                                                        $total[$level][$i] = 0.0;
                                                }
                                        }
@@ -252,7 +255,7 @@ function print_annual_expense_breakdown()
                                        $rep->TextCol(0, 2,     _('Total') . " " . $classname);
                                        for ($i = 1; $i <= 12; $i++)
                                        {
-                                               $rep->AmountCol($i + 1, $i + 2, $total2[$i], $dec);
+                                               $rep->AmountCol($i + 1, $i + 2, $total2[$i] * $convert, $dec);
                                                $sales[$i] += $total2[$i];
                                        }
                                        $rep->Font();
@@ -279,6 +282,7 @@ function print_annual_expense_breakdown()
                        $rep->Line($rep->row);
                        $rep->NewLine();
                }
+               $convert = get_account_class_convert($account['ClassID']);
                $classname = $account['AccountClassName'];
 
                if ($account['account_code'] != null)
@@ -291,7 +295,7 @@ function print_annual_expense_breakdown()
 
                        for ($i = 1; $i <= 12; $i++)
                        {
-                               $rep->AmountCol($i + 1, $i + 2, $balance[$i], $dec);
+                               $rep->AmountCol($i + 1, $i + 2, $balance[$i] * $convert, $dec);
                                $total2[$i] += $balance[$i];
                        }
                        for ($j = 0; $j <= $level; $j++)
@@ -329,7 +333,7 @@ function print_annual_expense_breakdown()
                                        $rep->TextCol(0, 2,     _('Total') . " " . $typename[$level]);
                                        for ($i = 1; $i <= 12; $i++)
                                        {
-                                               $rep->AmountCol($i + 1, $i + 2, $total[$level][$i], $dec);
+                                               $rep->AmountCol($i + 1, $i + 2, $total[$level][$i] * $convert, $dec);
                                                $total[$level][$i] = 0.0;
                                        }
                                }
@@ -347,14 +351,14 @@ function print_annual_expense_breakdown()
                                $rep->TextCol(0, 2,     _('Total') . " " . $classname);
                                for ($i = 1; $i <= 12; $i++)
                                {
-                                       $rep->AmountCol($i + 1, $i + 2, $total2[$i], $dec);
+                                       $rep->AmountCol($i + 1, $i + 2, $total2[$i] * $convert, $dec);
                                        $calc[$i] = $sales[$i] + $total2[$i];
                                }
 
                                $rep->NewLine(2);
                                $rep->TextCol(0, 2,     _('Calculated Return'));
                                for ($i = 1; $i <= 12; $i++)
-                                       $rep->AmountCol($i + 1, $i + 2, $calc[$i], $dec);
+                                       $rep->AmountCol($i + 1, $i + 2, $calc[$i] * -1, $dec); // always convert
                                $rep->Font();
 
                                $rep->NewLine();
index b7b67e896ab33f25dd3dbae71de5db6f47e8b269..91261cf8dab5a04b9a9cced5f3062ea71173e814 100644 (file)
@@ -118,11 +118,12 @@ function print_balance_sheet()
        $typeclose = array(0,0,0,0,0,0,0,0,0,0);
        $typename = array('','','','','','','','','','');
        $closing = array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1);
-       $parent = array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1);
+       //$parent = array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1);
        $level = 0;
        $last = -1;
        
        $closeclass = false;
+       $convert = 1;
        $rep->NewLine();
 
        $accounts = get_gl_accounts_all(1);
@@ -147,7 +148,6 @@ function print_balance_sheet()
                                $closeclass = true;
                        }
                }
-
                if ($account['AccountTypeName'] != $typename[$level])
                {
                        //$rep->NewLine();
@@ -163,9 +163,9 @@ function print_balance_sheet()
                                                $rep->Line($rep->row);
                                                $rep->NewLine();
                                                $rep->TextCol(0, 2,     _('Total') . " " . $typename[$level]);
-                                               $rep->AmountCol(2, 3, $typeopen[$level], $dec);
-                                               $rep->AmountCol(3, 4, $typeperiod[$level], $dec);
-                                               $rep->AmountCol(4, 5, $typeclose[$level], $dec);
+                                               $rep->AmountCol(2, 3, $typeopen[$level] * $convert, $dec);
+                                               $rep->AmountCol(3, 4, $typeperiod[$level] * $convert, $dec);
+                                               $rep->AmountCol(4, 5, $typeclose[$level] * $convert, $dec);
                                                if ($graphics)
                                                {
                                                        $pg->x[] = $typename[$level];
@@ -185,9 +185,9 @@ function print_balance_sheet()
                                        $rep->NewLine();
                                        $rep->Font('bold');
                                        $rep->TextCol(0, 2,     _('Total') . " " . $classname);
-                                       $rep->AmountCol(2, 3, $classopen, $dec);
-                                       $rep->AmountCol(3, 4, $classperiod, $dec);
-                                       $rep->AmountCol(4, 5, $classclose, $dec);
+                                       $rep->AmountCol(2, 3, $classopen * $convert, $dec);
+                                       $rep->AmountCol(3, 4, $classperiod * $convert, $dec);
+                                       $rep->AmountCol(4, 5, $classclose * $convert, $dec);
                                        $rep->Font();
                                        $assetsopen += $classopen;
                                        $assetsperiod += $classperiod;
@@ -215,6 +215,7 @@ function print_balance_sheet()
                        $rep->Line($rep->row);
                        $rep->NewLine();
                }
+               $convert = get_account_class_convert($account['ClassID']);
                $classname = $account['AccountClassName'];
 
                if ($account['account_code'] != null)
@@ -231,9 +232,9 @@ function print_balance_sheet()
                        $rep->TextCol(0, 1,     $account['account_code']);
                        $rep->TextCol(1, 2,     $account['account_name']);
 
-                       $rep->AmountCol(2, 3, $prev_balance, $dec);
-                       $rep->AmountCol(3, 4, $curr_balance, $dec);
-                       $rep->AmountCol(4, 5, $curr_balance + $prev_balance, $dec);
+                       $rep->AmountCol(2, 3, $prev_balance * $convert, $dec);
+                       $rep->AmountCol(3, 4, $curr_balance * $convert, $dec);
+                       $rep->AmountCol(4, 5, ($curr_balance + $prev_balance) * $convert, $dec);
 
                        $rep->NewLine();
 
@@ -263,9 +264,9 @@ function print_balance_sheet()
                                        $rep->Line($rep->row);
                                        $rep->NewLine();
                                        $rep->TextCol(0, 2,     _('Total') . " " . $typename[$level]);
-                                       $rep->AmountCol(2, 3, $typeopen[$level], $dec);
-                                       $rep->AmountCol(3, 4, $typeperiod[$level], $dec);
-                                       $rep->AmountCol(4, 5, $typeclose[$level], $dec);
+                                       $rep->AmountCol(2, 3, $typeopen[$level] * $convert, $dec);
+                                       $rep->AmountCol(3, 4, $typeperiod[$level] * $convert, $dec);
+                                       $rep->AmountCol(4, 5, $typeclose[$level] * $convert, $dec);
                                        if ($graphics)
                                        {
                                                $pg->x[] = $typename[$level];
@@ -287,9 +288,9 @@ function print_balance_sheet()
                                $rep->Line($rep->row);
                                $rep->NewLine();
                                $rep->TextCol(0, 2,     _('Calculated Return'));
-                               $rep->AmountCol(2, 3, $calculateopen, $dec);
-                               $rep->AmountCol(3, 4, $calculateperiod, $dec);
-                               $rep->AmountCol(4, 5, $calculateclose, $dec);
+                               $rep->AmountCol(2, 3, $calculateopen * $convert, $dec);
+                               $rep->AmountCol(3, 4, $calculateperiod * $convert, $dec);
+                               $rep->AmountCol(4, 5, $calculateclose * $convert, $dec);
                                if ($graphics)
                                {
                                        $pg->x[] = _('Calculated Return');
@@ -298,9 +299,9 @@ function print_balance_sheet()
                                $rep->NewLine(2);
                                $rep->Font('bold');
                                $rep->TextCol(0, 2,     _('Total') . " " . $classname);
-                               $rep->AmountCol(2, 3, -$assetsopen, $dec);
-                               $rep->AmountCol(3, 4, -$assetsperiod, $dec);
-                               $rep->AmountCol(4, 5, -$assetsclose, $dec);
+                               $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();
                        }
index 5dd9c1b2e282484590a78c4f4885f381820cec11..df551fc36fd1770359b7505b830e71b8c2b936df 100644 (file)
@@ -154,6 +154,9 @@ function print_profit_and_loss_statement()
        $salesacc = 0.0;
        $last = -1;
 
+       $closeclass = false;
+       $convert = 1;
+
        $accounts = get_gl_accounts_all(0);
 
        while ($account=db_fetch($accounts))
@@ -193,8 +196,8 @@ function print_profit_and_loss_statement()
                                                $rep->Line($rep->row);
                                                $rep->NewLine();
                                                $rep->TextCol(0, 2,     _('Total') . " " . $typename[$level]);
-                                               $rep->AmountCol(2, 3, $typeper[$level], $dec);
-                                               $rep->AmountCol(3, 4, $typeacc[$level], $dec);
+                                               $rep->AmountCol(2, 3, $typeper[$level] * $convert, $dec);
+                                               $rep->AmountCol(3, 4, $typeacc[$level] * $convert, $dec);
                                                $rep->AmountCol(4, 5, Achieve($typeper[$level], $typeacc[$level]), $pdec);
                                                if ($graphics)
                                                {
@@ -216,8 +219,8 @@ function print_profit_and_loss_statement()
                                        $rep->NewLine();
                                        $rep->Font('bold');
                                        $rep->TextCol(0, 2,     _('Total') . " " . $classname);
-                                       $rep->AmountCol(2, 3, $classper, $dec);
-                                       $rep->AmountCol(3, 4, $classacc, $dec);
+                                       $rep->AmountCol(2, 3, $classper * $convert, $dec);
+                                       $rep->AmountCol(3, 4, $classacc * $convert, $dec);
                                        $rep->AmountCol(4, 5, Achieve($classper, $classacc), $pdec);
                                        $rep->Font();
                                        $salesper += $classper;
@@ -245,12 +248,13 @@ function print_profit_and_loss_statement()
                        $rep->Line($rep->row);
                        $rep->NewLine();
                }
+               $convert = get_account_class_convert($account['ClassID']);
                $classname = $account['AccountClassName'];
 
                if ($account['account_code'] != null)
                {
-                       $per_balance *= -1;
-                       $acc_balance *= -1;
+                       //$per_balance *= -1;
+                       //$acc_balance *= -1;
                
                        for ($i = 0; $i <= $level; $i++)
                        {
@@ -262,8 +266,8 @@ function print_profit_and_loss_statement()
                        $rep->TextCol(0, 1,     $account['account_code']);
                        $rep->TextCol(1, 2,     $account['account_name']);
 
-                       $rep->AmountCol(2, 3, $per_balance, $dec);
-                       $rep->AmountCol(3, 4, $acc_balance, $dec);
+                       $rep->AmountCol(2, 3, $per_balance * $convert, $dec);
+                       $rep->AmountCol(3, 4, $acc_balance * $convert, $dec);
                        $rep->AmountCol(4, 5, Achieve($per_balance, $acc_balance), $pdec);
 
                        $rep->NewLine();
@@ -294,8 +298,8 @@ function print_profit_and_loss_statement()
                                        $rep->Line($rep->row);
                                        $rep->NewLine();
                                        $rep->TextCol(0, 2,     _('Total') . " " . $typename[$level]);
-                                       $rep->AmountCol(2, 3, $typeper[$level], $dec);
-                                       $rep->AmountCol(3, 4, $typeacc[$level], $dec);
+                                       $rep->AmountCol(2, 3, $typeper[$level] * $convert, $dec);
+                                       $rep->AmountCol(3, 4, $typeacc[$level] * $convert, $dec);
                                        $rep->AmountCol(4, 5, Achieve($typeper[$level], $typeacc[$level]), $pdec);
                                        if ($graphics)
                                        {
@@ -321,14 +325,14 @@ function print_profit_and_loss_statement()
 
                                $rep->Font('bold');
                                $rep->TextCol(0, 2,     _('Total') . " " . $classname);
-                               $rep->AmountCol(2, 3, $classper, $dec);
-                               $rep->AmountCol(3, 4, $classacc, $dec);
+                               $rep->AmountCol(2, 3, $classper * $convert, $dec);
+                               $rep->AmountCol(3, 4, $classacc * $convert, $dec);
                                $rep->AmountCol(4, 5, Achieve($classper, $classacc), $pdec);
 
                                $rep->NewLine(2);
                                $rep->TextCol(0, 2,     _('Calculated Return'));
-                               $rep->AmountCol(2, 3, $calculateper, $dec);
-                               $rep->AmountCol(3, 4, $calculateacc, $dec);
+                               $rep->AmountCol(2, 3, $calculateper *-1, $dec); // always convert
+                               $rep->AmountCol(3, 4, $calculateacc * -1, $dec);
                                $rep->AmountCol(4, 5, Achieve($calculateper, $calculateacc), $pdec);
                                if ($graphics)
                                {
index 6f3086b534c49c517e724a229cbc06bae9b694ae..f46cba8d1dadec355dfec02791d6f39b8da3f095 100644 (file)
@@ -45,7 +45,7 @@ function get_balance($account, $dimension, $dimension2, $from, $to, $from_incl=t
        if ($from_incl)
                $sql .= " tran_date >= '$from_date'  AND";
        else
-               $sql .= " tran_date > IF(".TB_PREF."chart_class.balance_sheet=1, '0000-00-00', '$from_date') AND";
+               $sql .= " tran_date > IF(balance_sheet>0 AND balance_sheet<".CL_INCOME.", '0000-00-00', '$from_date') AND";
        $to_date = date2sql($to);
        if ($to_incl)
                $sql .= " tran_date <= '$to_date' ";