+function display_type ($type, $typename, $from, $to, $begin, $end, $compare, $convert, &$dec, &$pdec, &$rep, $dimension, $dimension2,
+ $tags, &$pg, $graphics)
+{
+ $code_per_balance = 0;
+ $code_acc_balance = 0;
+ $per_balance_total = 0;
+ $acc_balance_total = 0;
+ $totals_arr = array();
+
+ $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 && is_array($tags) && $tags[0] != false)
+ {
+ if (!is_record_in_tags($tags, TAG_ACCOUNT, $account['account_code']))
+ continue;
+ }
+ $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;
+
+ //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, $per_balance * $convert, $dec);
+ $rep->AmountCol(3, 4, $acc_balance * $convert, $dec);
+ $rep->AmountCol(4, 5, Achieve($per_balance, $acc_balance), $pdec);
+
+ $rep->NewLine();
+
+ if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight)
+ {
+ $rep->Line($rep->row - 2);
+ $rep->NewPage();
+ }
+
+ $code_per_balance += $per_balance;
+ $code_acc_balance += $acc_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, $begin, $end, $compare, $convert, $dec,
+ $pdec, $rep, $dimension, $dimension2, $tags, $pg, $graphics);
+ $per_balance_total += $totals_arr[0];
+ $acc_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_per_balance + $per_balance_total + $code_acc_balance + $acc_balance_total) != 0 || $printtitle)
+ {
+ $rep->row += 6;
+ $rep->Line($rep->row);
+ $rep->NewLine();
+ $rep->TextCol(0, 2, _('Total') . " " . $typename);
+ $rep->AmountCol(2, 3, ($code_per_balance + $per_balance_total) * $convert, $dec);
+ $rep->AmountCol(3, 4, ($code_acc_balance + $acc_balance_total) * $convert, $dec);
+ $rep->AmountCol(4, 5, Achieve(($code_per_balance + $per_balance_total), ($code_acc_balance + $acc_balance_total)), $pdec);
+ if ($graphics)
+ {
+ $pg->x[] = $typename;
+ $pg->y[] = abs($code_per_balance + $per_balance_total);
+ $pg->z[] = abs($code_acc_balance + $acc_balance_total);
+ }
+ $rep->NewLine();
+ }
+
+ $totals_arr[0] = $code_per_balance + $per_balance_total;
+ $totals_arr[1] = $code_acc_balance + $acc_balance_total;
+ return $totals_arr;
+}
+