! -> 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
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)
{
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");
$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)
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' ";
$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;
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();
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);
}
}
+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);
}
+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
$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)
$level = 0;
$last = -1;
+ $closeclass = false;
+ $convert = 1;
+
$accounts = get_gl_accounts_all(0);
while ($account=db_fetch($accounts))
$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;
}
}
$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();
$rep->Line($rep->row);
$rep->NewLine();
}
+ $convert = get_account_class_convert($account['ClassID']);
$classname = $account['AccountClassName'];
if ($account['account_code'] != null)
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++)
$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;
}
}
$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();
$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);
$closeclass = true;
}
}
-
if ($account['AccountTypeName'] != $typename[$level])
{
//$rep->NewLine();
$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];
$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;
$rep->Line($rep->row);
$rep->NewLine();
}
+ $convert = get_account_class_convert($account['ClassID']);
$classname = $account['AccountClassName'];
if ($account['account_code'] != null)
$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();
$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];
$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');
$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();
}
$salesacc = 0.0;
$last = -1;
+ $closeclass = false;
+ $convert = 1;
+
$accounts = get_gl_accounts_all(0);
while ($account=db_fetch($accounts))
$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)
{
$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;
$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++)
{
$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();
$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)
{
$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)
{
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' ";