+ $printtitle = 0; //Flag for printing type name
+
+ //Get Accounts directly under this group/type
+ $result = get_gl_accounts(null, null, $type);
+ while ($account=db_fetch($result))
+ {
+ if ($tags != -1)
+ {
+ if (!is_record_in_tags($tags, TAG_ACCOUNT, $account['account_code']))
+ continue;
+ }
+ $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;
+
+ //Print Type Title if it has atleast one non-zero account
+ if (!$printtitle)
+ {
+ $printtitle = 1;
+ $rep->row -= 4;
+ $rep->TextCol(0, 5, $typename);
+ $rep->row -= 4;
+ $rep->Line($rep->row);
+ $rep->NewLine();
+ }
+
+ $rep->TextCol(0, 1, $account['account_code']);
+ $rep->TextCol(1, 2, $account['account_name']);
+
+ $rep->AmountCol(2, 3, $prev_balance * $convert, $dec);
+ $rep->AmountCol(3, 4, $curr_balance * $convert, $dec);
+ $rep->AmountCol(4, 5, ($prev_balance + $curr_balance) * $convert, $dec);
+
+ $rep->NewLine();
+
+ $code_open_balance += $prev_balance;
+ $code_period_balance += $curr_balance;
+ }
+
+ //Get Account groups/types under this group/type
+ $result = get_account_types(false, false, $type);
+ while ($accounttype=db_fetch($result))
+ {
+ //Print Type Title if has sub types and not previously printed
+ if (!$printtitle)
+ {
+ $printtitle = 1;
+ $rep->row -= 4;
+ $rep->TextCol(0, 5, $typename);
+ $rep->row -= 4;
+ $rep->Line($rep->row);
+ $rep->NewLine();
+ }
+
+ $totals_arr = display_type($accounttype["id"], $accounttype["name"], $from, $to, $convert, $dec,
+ $rep, $dimension, $dimension2, $pg, $graphics);
+ $open_balance_total += $totals_arr[0];
+ $period_balance_total += $totals_arr[1];
+ }
+
+ //Display Type Summary if total is != 0 OR head is printed (Needed in case of unused hierarchical COA)
+ if (($code_open_balance + $open_balance_total + $code_period_balance + $period_balance_total) != 0 || $printtitle)
+ {
+ $rep->row += 6;
+ $rep->Line($rep->row);
+ $rep->NewLine();
+ $rep->TextCol(0, 2, _('Total') . " " . $typename);
+ $rep->AmountCol(2, 3, ($code_open_balance + $open_balance_total) * $convert, $dec);
+ $rep->AmountCol(3, 4, ($code_period_balance + $period_balance_total) * $convert, $dec);
+ $rep->AmountCol(4, 5, ($code_open_balance + $open_balance_total + $code_period_balance + $period_balance_total) * $convert, $dec);
+ if ($graphics)
+ {
+ $pg->x[] = $typename;
+ $pg->y[] = abs($code_open_balance + $open_balance_total);
+ $pg->z[] = abs($code_period_balance + $period_balance_total);
+ }
+ $rep->NewLine();
+ }
+
+ $totals_arr[0] = $code_open_balance + $open_balance_total;
+ $totals_arr[1] = $code_period_balance + $period_balance_total;
+ return $totals_arr;
+}
+
+print_balance_sheet();