From ebbe126b8b1986df22e3339a3b755de683bbcd03 Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Tue, 26 May 2009 16:03:24 +0000 Subject: [PATCH] Again fixed nested subtypes in account types correctly in COA, Monthly Breakdown, Balance Sheet and P&L Statement Fixed wider combobox for backup-files in company backup --- CHANGELOG.txt | 15 ++- admin/backups.php | 2 +- gl/includes/db/gl_db_account_types.inc | 13 ++ gl/includes/db/gl_db_accounts.inc | 20 +-- reporting/rep701.php | 60 +++++---- reporting/rep705.php | 150 ++++++++++++++-------- reporting/rep706.php | 163 +++++++++++++----------- reporting/rep707.php | 168 +++++++++++++------------ 8 files changed, 352 insertions(+), 239 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 3574c50..d22d272 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,13 +19,24 @@ Legend: ! -> Note $ -> Affected files +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 + /gl/includes/db/gl_db_account_types.inc + /reporting/rep701.php + /reporting/rep705.php + /reporting/rep706.php + /reporting/rep707.php +# fixed wider combobox for backup-files in company backup +$ /admin/backups.php + 25-May-2009 Joe Hunt # Fixed Supplier Credit so Purchase Order Outstanding is decreased too. $ /purchasing/includes/db/grn_db.inc # Fixed so nested subtypes in account types are nested correctly in Balance Sheet and P&L Statement $ /gl/includes/db/gl_db_accounts.inc -$ /reporting/rep706.php -$ /reporting/rep707.php + /reporting/rep706.php + /reporting/rep707.php ! Extra column in Stock Check Sheet, On Order and option for selecting Only Shortage. $ /reporting/rep303.php /reporting/reports_main.php diff --git a/admin/backups.php b/admin/backups.php index f78e1d5..728d3f2 100644 --- a/admin/backups.php +++ b/admin/backups.php @@ -84,7 +84,7 @@ function get_backup_file_combo() if (preg_match("/.sql(.zip|.gz)?$/", $file)) $opt_files .= ""; - $selector = ""; + $selector = ""; $Ajax->addUpdate('cmd_backups', "_cmd_backups_sel", $selector); $selector = "".$selector."\n"; diff --git a/gl/includes/db/gl_db_account_types.inc b/gl/includes/db/gl_db_account_types.inc index 21a8c2c..39af247 100644 --- a/gl/includes/db/gl_db_account_types.inc +++ b/gl/includes/db/gl_db_account_types.inc @@ -52,6 +52,19 @@ function get_account_type_name($id) } +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"; diff --git a/gl/includes/db/gl_db_accounts.inc b/gl/includes/db/gl_db_accounts.inc index 695743d..380d5b4 100644 --- a/gl/includes/db/gl_db_accounts.inc +++ b/gl/includes/db/gl_db_accounts.inc @@ -49,20 +49,22 @@ function get_gl_accounts($from=null, $to=null) return db_query($sql, "could not get gl accounts"); } -function get_gl_accounts_all($balance=-1) +function get_gl_accounts_in_type($type) { - $sql = "SELECT ".TB_PREF."chart_master.*,".TB_PREF."chart_types.name AS AccountTypeName,".TB_PREF."chart_types.parent, - ".TB_PREF."chart_class.class_name AS AccountClassName - FROM ".TB_PREF."chart_master,".TB_PREF."chart_types, ".TB_PREF."chart_class - WHERE ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id AND - ".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, ".TB_PREF."chart_types.id, ".TB_PREF."chart_master.account_code"; + $sql = "SELECT * FROM ".TB_PREF."chart_master WHERE account_type=$type ORDER BY 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'"; diff --git a/reporting/rep701.php b/reporting/rep701.php index 63c90c3..6a44328 100644 --- a/reporting/rep701.php +++ b/reporting/rep701.php @@ -60,49 +60,55 @@ function print_Chart_of_Accounts() $classname = ''; $group = ''; - $accounts = get_gl_accounts_all(); + $types = get_account_types_all(); - while ($account=db_fetch($accounts)) + while ($type=db_fetch($types)) { - if ($showbalance == 1) - { - $begin = begin_fiscalyear(); - if (is_account_balancesheet($account["account_code"])) - $begin = ""; - $balance = get_gl_trans_from_to($begin, ToDay(), $account["account_code"], 0); - } - if ($account['AccountTypeName'] != $group) + if (!num_accounts_in_type($type['AccountType'], $type['parent'])) + continue; + if ($type['AccountTypeName'] != $group) { if ($classname != '') $rep->row -= 4; - if ($account['AccountClassName'] != $classname) + if ($type['AccountClassName'] != $classname) { $rep->Font('bold'); - $rep->TextCol(0, 4, $account['AccountClassName']); + $rep->TextCol(0, 4, $type['AccountClassName']); $rep->Font(); //$rep->row -= ($rep->lineHeight + 4); $rep->NewLine(); } - $group = $account['AccountTypeName']; - $rep->TextCol(0, 4, $account['AccountTypeName']); + $group = $type['AccountTypeName']; + $rep->TextCol(0, 4, $type['AccountTypeName']); //$rep->Line($rep->row - 4); //$rep->row -= ($rep->lineHeight + 4); $rep->NewLine(); } - $classname = $account['AccountClassName']; - - $rep->TextCol(0, 1, $account['account_code']); - $rep->TextCol(1, 2, $account['account_name']); - $rep->TextCol(2, 3, $account['account_code2']); - if ($showbalance == 1) - $rep->AmountCol(3, 4, $balance, $dec); - - $rep->NewLine(); - if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight) + $classname = $type['AccountClassName']; + + $accounts = get_gl_accounts_in_type($type['AccountType']); + while ($account=db_fetch($accounts)) { - $rep->Line($rep->row - 2); - $rep->Header(); - } + if ($showbalance == 1) + { + $begin = begin_fiscalyear(); + if (is_account_balancesheet($account["account_code"])) + $begin = ""; + $balance = get_gl_trans_from_to($begin, ToDay(), $account["account_code"], 0); + } + $rep->TextCol(0, 1, $account['account_code']); + $rep->TextCol(1, 2, $account['account_name']); + $rep->TextCol(2, 3, $account['account_code2']); + if ($showbalance == 1) + $rep->AmountCol(3, 4, $balance, $dec); + + $rep->NewLine(); + if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight) + { + $rep->Line($rep->row - 2); + $rep->Header(); + } + } } $rep->Line($rep->row); $rep->End(); diff --git a/reporting/rep705.php b/reporting/rep705.php index 699cc28..8516da4 100644 --- a/reporting/rep705.php +++ b/reporting/rep705.php @@ -179,24 +179,32 @@ function print_annual_expense_breakdown() $rep->Header(); $classname = ''; - $group = ''; - $total = Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0); + $total = Array( + 0 => Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0), + Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0), + Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0), + Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0), + Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0), + Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0), + Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0), + Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0), + Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0), + Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0)); $total2 = Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0); $sales = Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0); $calc = Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0); - $accounts = get_gl_accounts_all(0); + $typename = array('','','','','','','','','',''); + $closing = array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1); + $level = 0; + $last = -1; - while ($account = db_fetch($accounts)) + $types = get_account_types_all(0); + + while ($type = db_fetch($types)) { - $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']) + if (!num_accounts_in_type($type['AccountType'], $type['parent'])) 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 ($account['AccountClassName'] != $classname) + if ($type['AccountClassName'] != $classname) { if ($classname != '') { @@ -204,18 +212,28 @@ function print_annual_expense_breakdown() } } - if ($account['AccountTypeName'] != $group) + if ($type['AccountTypeName'] != $typename[$level]) { - if ($group != '') + if ($typename[$level] != '') { - $rep->row += 6; - $rep->Line($rep->row); - $rep->NewLine(); - $rep->TextCol(0, 2, _('Total') . " " . $group); - for ($i = 1; $i <= 12; $i++) - $rep->AmountCol($i + 1, $i + 2, $total[$i], $dec); - $total = Array(1 => 0,0,0,0,0,0,0,0,0,0,0,0); - $rep->NewLine(); + for ( ; $level >= 0, $typename[$level] != ''; $level--) + { + if ($type['parent'] == $closing[$level] || $type['parent'] == $last || $type['parent'] <= 0) + { + $rep->row += 6; + $rep->Line($rep->row); + $rep->NewLine(); + $rep->TextCol(0, 2, _('Total') . " " . $typename[$level]); + for ($i = 1; $i <= 12; $i++) + { + $rep->AmountCol($i + 1, $i + 2, $total[$level][$i], $dec); + $total[$level][$i] = 0.0; + } + } + else + break; + $rep->NewLine(); + } if ($closeclass) { $rep->row += 6; @@ -234,56 +252,88 @@ function print_annual_expense_breakdown() $closeclass = false; } } - if ($account['AccountClassName'] != $classname) + if ($type['AccountClassName'] != $classname) { $rep->Font('bold'); - $rep->TextCol(0, 5, $account['AccountClassName']); + $rep->TextCol(0, 5, $type['AccountClassName']); $rep->Font(); $rep->NewLine(); } - $group = $account['AccountTypeName']; + $level++; + if ($type['parent'] != $last) + $last = $type['parent']; + $typename[$level] = $type['AccountTypeName']; + $closing[$level] = $type['parent']; $rep->row -= 4; - $rep->TextCol(0, 5, $account['AccountTypeName']); + $rep->TextCol(0, 5, $type['AccountTypeName']); $rep->row -= 4; $rep->Line($rep->row); $rep->NewLine(); } - $classname = $account['AccountClassName']; - $rep->TextCol(0, 1, $account['account_code']); - $rep->TextCol(1, 2, $account['account_name']); - for ($i = 1; $i <= 12; $i++) + $classname = $type['AccountClassName']; + + $accounts = get_gl_accounts_in_type($type['AccountType']); + while ($account=db_fetch($accounts)) { - $rep->AmountCol($i + 1, $i + 2, $balance[$i], $dec); - $total[$i] += $balance[$i]; - $total2[$i] += $balance[$i]; - } + $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']); + $rep->TextCol(0, 1, $account['account_code']); + $rep->TextCol(1, 2, $account['account_name']); - $rep->NewLine(); + for ($i = 1; $i <= 12; $i++) + { + $rep->AmountCol($i + 1, $i + 2, $balance[$i], $dec); + $total2[$i] += $balance[$i]; + } + for ($j = 0; $j <= $level; $j++) + { + for ($i = 1; $i <= 12; $i++) + $total[$j][$i] += $balance[$i]; + } + $rep->NewLine(); - if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight) - { - $rep->Line($rep->row - 2); - $rep->Header(); - } + if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight) + { + $rep->Line($rep->row - 2); + $rep->Header(); + } + } } - if ($account['AccountClassName'] != $classname) + if ($type['AccountClassName'] != $classname) { if ($classname != '') { $closeclass = true; } } - if ($account['AccountTypeName'] != $group) + if ($type['AccountTypeName'] != $typename[$level]) { - if ($group != '') + if ($typename[$level] != '') { - $rep->row += 6; - $rep->Line($rep->row); - $rep->NewLine(); - $rep->TextCol(0, 2, _('Total') . " " . $group); - for ($i = 1; $i <= 12; $i++) - $rep->AmountCol($i + 1, $i + 2, $total[$i], $dec); - $rep->NewLine(); + for ( ; $level >= 0, $typename[$level] != ''; $level--) + { + if ($type['parent'] == $closing[$level] || $type['parent'] == $last || $type['parent'] <= 0) + { + $rep->row += 6; + $rep->Line($rep->row); + $rep->NewLine(); + $rep->TextCol(0, 2, _('Total') . " " . $typename[$level]); + for ($i = 1; $i <= 12; $i++) + { + $rep->AmountCol($i + 1, $i + 2, $total[$level][$i], $dec); + $total[$level][$i] = 0.0; + } + } + else + break; + $rep->NewLine(); + } if ($closeclass) { $rep->row += 6; diff --git a/reporting/rep706.php b/reporting/rep706.php index f490e08..e69fc0d 100644 --- a/reporting/rep706.php +++ b/reporting/rep706.php @@ -117,24 +117,20 @@ function print_balance_sheet() $typeperiod = array(0,0,0,0,0,0,0,0,0,0); $typeclose = array(0,0,0,0,0,0,0,0,0,0); $typename = array('','','','','','','','','',''); - $parent = array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1); + $closing = array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1); $level = 0; + $last = -1; $closeclass = false; $rep->NewLine(); - $accounts = get_gl_accounts_all(1); + $types = get_account_types_all(1); - while ($account=db_fetch($accounts)) + while ($type=db_fetch($types)) { - $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) + if (!num_accounts_in_type($type['AccountType'], $type['parent'])) continue; - - if ($account['AccountClassName'] != $classname) + if ($type['AccountClassName'] != $classname) { if ($classname != '') { @@ -142,30 +138,36 @@ function print_balance_sheet() } } - if ($account['AccountTypeName'] != $typename[$level]) + if ($type['AccountTypeName'] != $typename[$level]) { - if ($typename[$level] != '' && $account['parent'] == -1) + //$rep->NewLine(); + //$rep->TextCol(0, 5, "level = $level, closing[level] = ".$closing[$level].", type[parent] = ".$type['parent']." last = ".$last); + //$rep->NewLine(); + if ($typename[$level] != '') { - for ( ; $level >= 0; $level--) + for ( ; $level >= 0, $typename[$level] != ''; $level--) { - $rep->row += 6; - $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); - $typeopen[$level] = $typeperiod[$level] = $typeclose[$level] = 0.0; - if ($parent[$level] == -1) + if ($type['parent'] == $closing[$level] || $type['parent'] == $last || $type['parent'] <= 0) + { + $rep->row += 6; + $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); + if ($graphics) + { + $pg->x[] = $$typename[$level]; + $pg->y[] = abs($typeclose[$level]); + } + $typeopen[$level] = $typeperiod[$level] = $typeclose[$level] = 0.0; + } + else break; $rep->NewLine(); } - if ($graphics) - { - $pg->x[] = $$typename[$level]; - $pg->y[] = abs($typeclose[$level]); - } - $rep->NewLine(); + //$rep->NewLine(); if ($closeclass) { $rep->row += 6; @@ -185,80 +187,95 @@ function print_balance_sheet() $closeclass = false; } } - if ($account['AccountClassName'] != $classname) + if ($type['AccountClassName'] != $classname) { $rep->Font('bold'); - $rep->TextCol(0, 5, $account['AccountClassName']); + $rep->TextCol(0, 5, $type['AccountClassName']); $rep->Font(); $rep->NewLine(); } - if ($account['parent'] != -1 && $account['parent'] != $parent[$level]) - $level++; - $typename[$level] = $account['AccountTypeName']; + $level++; + if ($type['parent'] != $last) + $last = $type['parent']; + $typename[$level] = $type['AccountTypeName']; + $closing[$level] = $type['parent']; $rep->row -= 4; - $rep->TextCol(0, 5, $account['AccountTypeName']); + $rep->TextCol(0, 5, $type['AccountTypeName']); $rep->row -= 4; $rep->Line($rep->row); $rep->NewLine(); } - $classname = $account['AccountClassName']; - $parent[$level] = $account['parent']; + $classname = $type['AccountClassName']; - for ($i = 0; $i <= $level; $i++) + $accounts = get_gl_accounts_in_type($type['AccountType']); + while ($account=db_fetch($accounts)) { - $typeopen[$i] += $prev_balance; - $typeperiod[$i] += $curr_balance; - $typeclose[$i] = $typeopen[$i] + $typeperiod[$i]; - } - $classopen += $prev_balance; - $classperiod += $curr_balance; - $classclose = $classopen + $classperiod; - $rep->TextCol(0, 1, $account['account_code']); - $rep->TextCol(1, 2, $account['account_name']); + $prev_balance = get_gl_balance_from_to("", $from, $account["account_code"], $dimension, $dimension2); - $rep->AmountCol(2, 3, $prev_balance, $dec); - $rep->AmountCol(3, 4, $curr_balance, $dec); - $rep->AmountCol(4, 5, $curr_balance + $prev_balance, $dec); + $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2); - $rep->NewLine(); + if (!$prev_balance && !$curr_balance) + continue; - if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight) - { - $rep->Line($rep->row - 2); - $rep->Header(); - } + for ($i = 0; $i <= $level; $i++) + { + $typeopen[$i] += $prev_balance; + $typeperiod[$i] += $curr_balance; + $typeclose[$i] = $typeopen[$i] + $typeperiod[$i]; + } + $classopen += $prev_balance; + $classperiod += $curr_balance; + $classclose = $classopen + $classperiod; + $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->NewLine(); + + if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight) + { + $rep->Line($rep->row - 2); + $rep->Header(); + } + } } - if ($account['AccountClassName'] != $classname) + if ($type['AccountClassName'] != $classname) { if ($classname != '') { $closeclass = true; } } - if ($account['AccountTypeName'] != $typename[$level]) + if ($type['AccountTypeName'] != $typename[$level]) { if ($typename[$level] != '') { - for ( ; $level >= 0; $level--) + for ( ; $level >= 0, $typename[$level] != ''; $level--) { - $rep->row += 6; - $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); - $typeopen[$level] = $typeperiod[$level] = $typeclose[$level] = 0.0; - if ($parent[$level] == -1) + if ($type['parent'] == $closing[$level] || $type['parent'] == $last || $type['parent'] <= 0) + { + $rep->row += 6; + $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); + if ($graphics) + { + $pg->x[] = $$typename[$level]; + $pg->y[] = abs($typeclose[$level]); + } + $typeopen[$level] = $typeperiod[$level] = $typeclose[$level] = 0.0; + } + else break; $rep->NewLine(); } - if ($graphics) - { - $pg->x[] = $$typename[$level]; - $pg->y[] = abs($typeclose[$level]); - } - $rep->NewLine(); + //$rep->NewLine(); if ($closeclass) { $calculateopen = -$assetsopen - $classopen; diff --git a/reporting/rep707.php b/reporting/rep707.php index d562218..7799ffe 100644 --- a/reporting/rep707.php +++ b/reporting/rep707.php @@ -145,28 +145,23 @@ function print_profit_and_loss_statement() $typeper = array(0,0,0,0,0,0,0,0,0,0); $typeacc = array(0,0,0,0,0,0,0,0,0,0); $typename = array('','','','','','','','','',''); - $parent = array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1); + $closing = array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1); $level = 0; $classper = 0.0; $classacc = 0.0; $salesper = 0.0; $salesacc = 0.0; + $last = -1; - $accounts = get_gl_accounts_all(0); + $types = get_account_types_all(0); - while ($account=db_fetch($accounts)) + while ($type=db_fetch($types)) { - $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) + if (!num_accounts_in_type($type['AccountType'], $type['parent'])) continue; - if ($account['AccountClassName'] != $classname) + if ($type['AccountClassName'] != $classname) { if ($classname != '') { @@ -174,31 +169,34 @@ function print_profit_and_loss_statement() } } - if ($account['AccountTypeName'] != $typename[$level]) + if ($type['AccountTypeName'] != $typename[$level]) { - if ($typename[$level] != '' && $account['parent'] == -1) + if ($typename[$level] != '') { - for ( ; $level >= 0; $level--) + for ( ; $level >= 0, $typename[$level] != ''; $level--) { - $rep->row += 6; - $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(4, 5, Achieve($typeper[$level], $typeacc[$level]), $pdec); - $typeper[$level] = $typeacc[$level] = 0.0; - if ($parent[$level] == -1) + if ($type['parent'] == $closing[$level] || $type['parent'] == $last || $type['parent'] <= 0) + { + $rep->row += 6; + $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(4, 5, Achieve($typeper[$level], $typeacc[$level]), $pdec); + if ($graphics) + { + $pg->x[] = $typename[$level]; + $pg->y[] = abs($typeper[$level]); + $pg->z[] = abs($typeacc[$level]); + } + $typeper[$level] = $typeacc[$level] = 0.0; + } + else break; $rep->NewLine(); } - if ($graphics) - { - $pg->x[] = $typename[$level]; - $pg->y[] = abs($typeper[$level]); - $pg->z[] = abs($typeacc[$level]); - } - $rep->NewLine(); + //$rep->NewLine(); if ($closeclass) { $rep->row += 6; @@ -217,82 +215,98 @@ function print_profit_and_loss_statement() $closeclass = false; } } - if ($account['AccountClassName'] != $classname) + if ($type['AccountClassName'] != $classname) { $rep->Font('bold'); - $rep->TextCol(0, 5, $account['AccountClassName']); + $rep->TextCol(0, 5, $type['AccountClassName']); $rep->Font(); $rep->NewLine(); } - if ($account['parent'] != -1 && $account['parent'] != $parent[$level]) - $level++; - $typename[$level] = $account['AccountTypeName']; + $level++; + if ($type['parent'] != $last) + $last = $type['parent']; + $typename[$level] = $type['AccountTypeName']; + $closing[$level] = $type['parent']; $rep->row -= 4; - $rep->TextCol(0, 5, $account['AccountTypeName']); + $rep->TextCol(0, 5, $type['AccountTypeName']); $rep->row -= 4; $rep->Line($rep->row); $rep->NewLine(); } - $classname = $account['AccountClassName']; - $parent[$level] = $account['parent']; + $classname = $type['AccountClassName']; - $per_balance *= -1; - $acc_balance *= -1; - - for ($i = 0; $i <= $level; $i++) + $accounts = get_gl_accounts_in_type($type['AccountType']); + while ($account=db_fetch($accounts)) { - $typeper[$i] += $per_balance; - $typeacc[$i] += $acc_balance; - } - $classper += $per_balance; - $classacc += $acc_balance; - $rep->TextCol(0, 1, $account['account_code']); - $rep->TextCol(1, 2, $account['account_name']); + $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; + + for ($i = 0; $i <= $level; $i++) + { + $typeper[$i] += $per_balance; + $typeacc[$i] += $acc_balance; + } + $classper += $per_balance; + $classacc += $acc_balance; + $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(4, 5, Achieve($per_balance, $acc_balance), $pdec); + $rep->AmountCol(2, 3, $per_balance, $dec); + $rep->AmountCol(3, 4, $acc_balance, $dec); + $rep->AmountCol(4, 5, Achieve($per_balance, $acc_balance), $pdec); - $rep->NewLine(); + $rep->NewLine(); - if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight) - { - $rep->Line($rep->row - 2); - $rep->Header(); - } + if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight) + { + $rep->Line($rep->row - 2); + $rep->Header(); + } + } } - if ($account['AccountClassName'] != $classname) + if ($type['AccountClassName'] != $classname) { if ($classname != '') { $closeclass = true; } } - if ($account['AccountTypeName'] != $typename[$level]) + if ($type['AccountTypeName'] != $typename[$level]) { if ($typename[$level] != '') { - for ( ; $level >= 0; $level--) + for ( ; $level >= 0, $typename[$level] != ''; $level--) { - $rep->row += 6; - $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(4, 5, Achieve($typeper[$level], $typeacc[$level]), $pdec); - $typeper[$level] = $typeacc[$level] = 0.0; - if ($parent[$level] == -1) + if ($type['parent'] == $closing[$level] || $type['parent'] == $last || $type['parent'] <= 0) + { + $rep->row += 6; + $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(4, 5, Achieve($typeper[$level], $typeacc[$level]), $pdec); + if ($graphics) + { + $pg->x[] = $typename[$level]; + $pg->y[] = abs($typeper[$level]); + $pg->z[] = abs($typeacc[$level]); + } + $typeper[$level] = $typeacc[$level] = 0.0; + } + else break; $rep->NewLine(); } - if ($graphics) - { - $pg->x[] = $typename[$level]; - $pg->y[] = abs($typeper[$level]); - $pg->z[] = abs($typeacc[$level]); - } - $rep->NewLine(); + //$rep->NewLine(); if ($closeclass) { $rep->Line($rep->row + 6); -- 2.30.2