! -> Note
$ -> Affected files
+27-May-2009 Joe Hunt
+# After heavy testing a new set of nested subtypes in COA, Monthly Breakdown, Balance Sheet and P&L Statement.
+$ /gl/includes/db/gl_db_accounts.inc
+ /gl/includes/db/gl_db_account_types.inc
+ /reporting/rep701.php
+ /reporting/rep705.php
+ /reporting/rep706.php
+ /reporting/rep707.php
+
26-May-2009 Joe Hunt
# Again fixed nested subtypes in account types correctly in COA, Monthly Breakdown, Balance Sheet and P&L Statement
$ /gl/includes/db/gl_db_accounts.inc
return $row[0];
}
-
-function get_account_types_all($balance=-1)
-{
- $sql = "SELECT ".TB_PREF."chart_types.name AS AccountTypeName,".TB_PREF."chart_types.parent,".TB_PREF."chart_types.id AS AccountType,
- ".TB_PREF."chart_class.class_name AS AccountClassName
- FROM ".TB_PREF."chart_types, ".TB_PREF."chart_class
- WHERE ".TB_PREF."chart_types.class_id=".TB_PREF."chart_class.cid";
- if ($balance != -1)
- $sql .= " AND ".TB_PREF."chart_class.balance_sheet=$balance";
- $sql .= " ORDER BY ".TB_PREF."chart_class.cid, IF(parent > -1,parent,".TB_PREF."chart_types.id), parent";
-
- return db_query($sql, "could not get gl types");
-}
-
function delete_account_type($id)
{
$sql = "DELETE FROM ".TB_PREF."chart_types WHERE id = $id";
return db_query($sql, "could not get gl accounts");
}
-function get_gl_accounts_in_type($type)
+function get_gl_accounts_all($balance=-1)
{
- $sql = "SELECT * FROM ".TB_PREF."chart_master WHERE account_type=$type ORDER BY account_code";
+ $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
+ 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),
+ IF(parent > 0,".TB_PREF."chart_types.id, parent), ".TB_PREF."chart_master.account_code";
return db_query($sql, "could not get gl accounts");
}
-function num_accounts_in_type($type, $parent)
-{
- $sql = "SELECT COUNT(*) FROM ".TB_PREF."chart_master WHERE account_type=$type OR account_type=$parent";
-
- $result = db_query($sql, "could not get gl accounts");
- $row = db_fetch_row($result);
- return $row[0];
-}
-
function get_gl_account($code)
{
$sql = "SELECT * FROM ".TB_PREF."chart_master WHERE account_code='$code'";
$classname = '';
$group = '';
- $types = get_account_types_all();
+ $accounts = get_gl_accounts_all();
- while ($type=db_fetch($types))
+ while ($account=db_fetch($accounts))
{
- if (!num_accounts_in_type($type['AccountType'], $type['parent']))
- continue;
- if ($type['AccountTypeName'] != $group)
+ if ($account['AccountTypeName'] != $group)
{
if ($classname != '')
$rep->row -= 4;
- if ($type['AccountClassName'] != $classname)
+ if ($account['AccountClassName'] != $classname)
{
$rep->Font('bold');
- $rep->TextCol(0, 4, $type['AccountClassName']);
+ $rep->TextCol(0, 4, $account['AccountClassName']);
$rep->Font();
//$rep->row -= ($rep->lineHeight + 4);
$rep->NewLine();
}
- $group = $type['AccountTypeName'];
- $rep->TextCol(0, 4, $type['AccountTypeName']);
+ $group = $account['AccountTypeName'];
+ $rep->TextCol(0, 4, $account['AccountTypeName']);
//$rep->Line($rep->row - 4);
//$rep->row -= ($rep->lineHeight + 4);
$rep->NewLine();
}
- $classname = $type['AccountClassName'];
+ $classname = $account['AccountClassName'];
- $accounts = get_gl_accounts_in_type($type['AccountType']);
- while ($account=db_fetch($accounts))
+ if ($account['account_code'] != null)
{
if ($showbalance == 1)
{
$level = 0;
$last = -1;
- $types = get_account_types_all(0);
+ $accounts = get_gl_accounts_all(0);
- while ($type = db_fetch($types))
+ while ($account=db_fetch($accounts))
{
- if (!num_accounts_in_type($type['AccountType'], $type['parent']))
+ if ($account['account_code'] == null && $account['parent'] > 0)
continue;
- if ($type['AccountClassName'] != $classname)
+
+ if ($account['account_code'] != null)
+ {
+ $bal = getPeriods($year, $account["account_code"], $dimension, $dimension2);
+ if (!$bal['per01'] && !$bal['per02'] && !$bal['per03'] && !$bal['per04'] &&
+ !$bal['per05'] && !$bal['per06'] && !$bal['per07'] && !$bal['per08'] &&
+ !$bal['per09'] && !$bal['per10'] && !$bal['per11'] && !$bal['per12'])
+ continue;
+ }
+ if ($account['AccountClassName'] != $classname)
{
if ($classname != '')
{
}
}
- if ($type['AccountTypeName'] != $typename[$level])
+ if ($account['AccountTypeName'] != $typename[$level])
{
if ($typename[$level] != '')
{
for ( ; $level >= 0, $typename[$level] != ''; $level--)
{
- if ($type['parent'] == $closing[$level] || $type['parent'] == $last || $type['parent'] <= 0)
+ if ($account['parent'] == $closing[$level] || $account['parent'] < $last)
{
$rep->row += 6;
$rep->Line($rep->row);
$closeclass = false;
}
}
- if ($type['AccountClassName'] != $classname)
+ if ($account['AccountClassName'] != $classname)
{
$rep->Font('bold');
- $rep->TextCol(0, 5, $type['AccountClassName']);
+ $rep->TextCol(0, 5, $account['AccountClassName']);
$rep->Font();
$rep->NewLine();
}
$level++;
- if ($type['parent'] != $last)
- $last = $type['parent'];
- $typename[$level] = $type['AccountTypeName'];
- $closing[$level] = $type['parent'];
+ if ($account['parent'] != $last)
+ $last = $account['parent'];
+ $typename[$level] = $account['AccountTypeName'];
+ $closing[$level] = $account['parent'];
$rep->row -= 4;
- $rep->TextCol(0, 5, $type['AccountTypeName']);
+ $rep->TextCol(0, 5, $account['AccountTypeName']);
$rep->row -= 4;
$rep->Line($rep->row);
$rep->NewLine();
}
- $classname = $type['AccountClassName'];
+ $classname = $account['AccountClassName'];
- $accounts = get_gl_accounts_in_type($type['AccountType']);
- while ($account=db_fetch($accounts))
+ if ($account['account_code'] != null)
{
- $bal = getPeriods($year, $account["account_code"], $dimension, $dimension2);
- if (!$bal['per01'] && !$bal['per02'] && !$bal['per03'] && !$bal['per04'] &&
- !$bal['per05'] && !$bal['per06'] && !$bal['per07'] && !$bal['per08'] &&
- !$bal['per09'] && !$bal['per10'] && !$bal['per11'] && !$bal['per12'])
- continue;
$balance = array(1 => $bal['per01'], $bal['per02'], $bal['per03'], $bal['per04'],
$bal['per05'], $bal['per06'], $bal['per07'], $bal['per08'],
$bal['per09'], $bal['per10'], $bal['per11'], $bal['per12']);
}
}
}
- if ($type['AccountClassName'] != $classname)
+ if ($account['AccountClassName'] != $classname)
{
if ($classname != '')
{
$closeclass = true;
}
}
- if ($type['AccountTypeName'] != $typename[$level])
+ if ($account['AccountTypeName'] != $typename[$level])
{
if ($typename[$level] != '')
{
for ( ; $level >= 0, $typename[$level] != ''; $level--)
{
- if ($type['parent'] == $closing[$level] || $type['parent'] == $last || $type['parent'] <= 0)
+ if ($account['parent'] == $closing[$level] || $account['parent'] < $last)
{
$rep->row += 6;
$rep->Line($rep->row);
$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);
$level = 0;
$last = -1;
$closeclass = false;
$rep->NewLine();
- $types = get_account_types_all(1);
+ $accounts = get_gl_accounts_all(1);
- while ($type=db_fetch($types))
+ while ($account=db_fetch($accounts))
{
- if (!num_accounts_in_type($type['AccountType'], $type['parent']))
+ if ($account['account_code'] == null && $account['parent'] > 0)
continue;
- if ($type['AccountClassName'] != $classname)
+ if ($account['account_code'] != null)
+ {
+ $prev_balance = get_gl_balance_from_to("", $from, $account["account_code"], $dimension, $dimension2);
+
+ $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
+
+ if (!$prev_balance && !$curr_balance)
+ continue;
+ }
+ if ($account['AccountClassName'] != $classname)
{
if ($classname != '')
{
}
}
- if ($type['AccountTypeName'] != $typename[$level])
+ if ($account['AccountTypeName'] != $typename[$level])
{
//$rep->NewLine();
- //$rep->TextCol(0, 5, "level = $level, closing[level] = ".$closing[$level].", type[parent] = ".$type['parent']." last = ".$last);
+ //$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 ($type['parent'] == $closing[$level] || $type['parent'] == $last || $type['parent'] <= 0)
+ if ($account['parent'] == $closing[$level] || $account['parent'] < $last)
{
$rep->row += 6;
$rep->Line($rep->row);
$closeclass = false;
}
}
- if ($type['AccountClassName'] != $classname)
+ if ($account['AccountClassName'] != $classname)
{
$rep->Font('bold');
- $rep->TextCol(0, 5, $type['AccountClassName']);
+ $rep->TextCol(0, 5, $account['AccountClassName']);
$rep->Font();
$rep->NewLine();
}
$level++;
- if ($type['parent'] != $last)
- $last = $type['parent'];
- $typename[$level] = $type['AccountTypeName'];
- $closing[$level] = $type['parent'];
+ if ($account['parent'] != $last)
+ $last = $account['parent'];
+ $typename[$level] = $account['AccountTypeName'];
+ $closing[$level] = $account['parent'];
$rep->row -= 4;
- $rep->TextCol(0, 5, $type['AccountTypeName']);
+ $rep->TextCol(0, 5, $account['AccountTypeName']);
$rep->row -= 4;
$rep->Line($rep->row);
$rep->NewLine();
}
- $classname = $type['AccountClassName'];
+ $classname = $account['AccountClassName'];
- $accounts = get_gl_accounts_in_type($type['AccountType']);
- while ($account=db_fetch($accounts))
+ if ($account['account_code'] != null)
{
- $prev_balance = get_gl_balance_from_to("", $from, $account["account_code"], $dimension, $dimension2);
-
- $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
-
- if (!$prev_balance && !$curr_balance)
- continue;
-
for ($i = 0; $i <= $level; $i++)
{
$typeopen[$i] += $prev_balance;
}
}
}
- if ($type['AccountClassName'] != $classname)
+ if ($account['AccountClassName'] != $classname)
{
if ($classname != '')
{
$closeclass = true;
}
}
- if ($type['AccountTypeName'] != $typename[$level])
+ if ($account['AccountTypeName'] != $typename[$level])
{
if ($typename[$level] != '')
{
for ( ; $level >= 0, $typename[$level] != ''; $level--)
{
- if ($type['parent'] == $closing[$level] || $type['parent'] == $last || $type['parent'] <= 0)
+ if ($account['parent'] == $closing[$level] || $account['parent'] < $last)
{
$rep->row += 6;
$rep->Line($rep->row);
$salesacc = 0.0;
$last = -1;
- $types = get_account_types_all(0);
+ $accounts = get_gl_accounts_all(0);
- while ($type=db_fetch($types))
+ while ($account=db_fetch($accounts))
{
- if (!num_accounts_in_type($type['AccountType'], $type['parent']))
+ if ($account['account_code'] == null && $account['parent'] > 0)
continue;
- if ($type['AccountClassName'] != $classname)
+ if ($account['account_code'] != null)
+ {
+ $per_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
+
+ if ($compare == 2)
+ $acc_balance = get_budget_trans_from_to($begin, $end, $account["account_code"], $dimension, $dimension2);
+ else
+ $acc_balance = get_gl_trans_from_to($begin, $end, $account["account_code"], $dimension, $dimension2);
+ if (!$per_balance && !$acc_balance)
+ continue;
+ }
+
+ if ($account['AccountClassName'] != $classname)
{
if ($classname != '')
{
}
}
- if ($type['AccountTypeName'] != $typename[$level])
+ if ($account['AccountTypeName'] != $typename[$level])
{
if ($typename[$level] != '')
{
for ( ; $level >= 0, $typename[$level] != ''; $level--)
{
- if ($type['parent'] == $closing[$level] || $type['parent'] == $last || $type['parent'] <= 0)
+ if ($account['parent'] == $closing[$level] || $account['parent'] < $last)
{
$rep->row += 6;
$rep->Line($rep->row);
$closeclass = false;
}
}
- if ($type['AccountClassName'] != $classname)
+ if ($account['AccountClassName'] != $classname)
{
$rep->Font('bold');
- $rep->TextCol(0, 5, $type['AccountClassName']);
+ $rep->TextCol(0, 5, $account['AccountClassName']);
$rep->Font();
$rep->NewLine();
}
$level++;
- if ($type['parent'] != $last)
- $last = $type['parent'];
- $typename[$level] = $type['AccountTypeName'];
- $closing[$level] = $type['parent'];
+ if ($account['parent'] != $last)
+ $last = $account['parent'];
+ $typename[$level] = $account['AccountTypeName'];
+ $closing[$level] = $account['parent'];
$rep->row -= 4;
- $rep->TextCol(0, 5, $type['AccountTypeName']);
+ $rep->TextCol(0, 5, $account['AccountTypeName']);
$rep->row -= 4;
$rep->Line($rep->row);
$rep->NewLine();
}
- $classname = $type['AccountClassName'];
+ $classname = $account['AccountClassName'];
- $accounts = get_gl_accounts_in_type($type['AccountType']);
- while ($account=db_fetch($accounts))
+ if ($account['account_code'] != null)
{
- $per_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
-
- if ($compare == 2)
- $acc_balance = get_budget_trans_from_to($begin, $end, $account["account_code"], $dimension, $dimension2);
- else
- $acc_balance = get_gl_trans_from_to($begin, $end, $account["account_code"], $dimension, $dimension2);
- if (!$per_balance && !$acc_balance)
- continue;
$per_balance *= -1;
$acc_balance *= -1;
}
}
}
- if ($type['AccountClassName'] != $classname)
+ if ($account['AccountClassName'] != $classname)
{
if ($classname != '')
{
$closeclass = true;
}
}
- if ($type['AccountTypeName'] != $typename[$level])
+ if ($account['AccountTypeName'] != $typename[$level])
{
if ($typename[$level] != '')
{
for ( ; $level >= 0, $typename[$level] != ''; $level--)
{
- if ($type['parent'] == $closing[$level] || $type['parent'] == $last || $type['parent'] <= 0)
+ if ($account['parent'] == $closing[$level] || $account['parent'] < $last)
{
$rep->row += 6;
$rep->Line($rep->row);