+function display_type ($type, $typename, $yr, $mo, $convert, &$dec, &$rep, $dimension, $dimension2, $tags)
+{
+ $ctotal = array(1 => 0,0,0,0,0,0,0,0,0,0,0,0,0,0);
+ $total = array(1 => 0,0,0,0,0,0,0,0,0,0,0,0,0,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;
+ }
+ $bal = getPeriods($yr, $mo, $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;
+
+ //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();
+ }
+
+ $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']);
+
+ for ($i = 1; $i <= 12; $i++)
+ {
+ $rep->AmountCol($i + 1, $i + 2, $balance[$i] * $convert, $dec);
+ $ctotal[$i] += $balance[$i];
+ }
+
+ $rep->NewLine();
+ }
+
+ //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"], $yr, $mo, $convert, $dec, $rep, $dimension, $dimension2, $tags);
+ for ($i = 1; $i <= 12; $i++)
+ {
+ $total[$i] += $totals_arr[$i];
+ }
+ }
+
+ //Display Type Summary if total is != 0 OR head is printed (Needed in case of unused hierarchical COA)
+ if ($printtitle)
+ {
+ $rep->row += 6;
+ $rep->Line($rep->row);
+ $rep->NewLine();
+ $rep->TextCol(0, 2, _('Total') . " " . $typename);
+ for ($i = 1; $i <= 12; $i++)
+ $rep->AmountCol($i + 1, $i + 2, ($total[$i] + $ctotal[$i]) * $convert, $dec);
+ $rep->NewLine();
+ }
+ for ($i = 1; $i <= 12; $i++)
+ $totals_arr[$i] = $total[$i] + $ctotal[$i];
+ return $totals_arr;
+}
+
+//----------------------------------------------------------------------------------------------------
+