%<?lsmb FILTER latex ?>
%
%<?lsmb
  IF hierarchy == 'flat-hierarchy';
    max_path_depth = 1;
  ELSE;
    max_path_depth = 0;
    FOREACH row IN report.sorted_row_ids ;
       IF max_path_depth < report.rheads.ids.$row.path.size ;
          max_path_depth = report.rheads.ids.$row.path.size ;
       END;
    END;
  END;
  last_col_no = max_path_depth + 1 + report.sorted_col_ids.size;
  IF report.legacy_hierarchy ;
     hierarchy = 'flat-hierarchy';
  ELSE ;
     hierarchy = 'full-hierarchy';
  END ;

 -?>

\documentclass[12pt]{article}
\usepackage{longtable}
\begin{document}
\renewcommand\baselinestretch{1.2}\selectfont
\begin{center}
\Huge{<?lsmb text('Balance Sheet') ?>}

\small{
\texttt{<?lsmb company_name ?>}


\texttt{<?lsmb company_address ?>}
}
\end{center}


\begin{longtable}{@{\extracolsep{10pt}}<?lsmb i = 1; WHILE i <= max_path_depth ; 'l'; i = i + 1; END;
-?>p{2cm}<?lsmb
 FOREACH c IN report.sorted_col_ids; 'r'; END -?>}
\\
\multicolumn{<?lsmb max_path_depth + 1 ?>}{l}{}
<?lsmb
 FOREACH col IN report.sorted_col_ids;
     ' & \shortstack{';
     report.cheads.ids.$col.props.description ;
     '} ';
 END;
 ?> \\
\\
<?lsmb FOREACH row IN report.sorted_row_ids;
  IF report.rheads.ids.$row.props.section_for ;
    row_id = report.rheads.ids.$row.props.section_for ;
    IF report.rheads.ids.$row_id.props.account_category == 'QL';
      NEXT;
    END;
  END;

   IF hierarchy == 'flat-hierarchy';
     path_depth = 1;
   ELSE;
     path_depth = report.rheads.ids.$row.path.size;
   END;
   path_prefix_len = path_depth - 1;
   path_suffix_len = max_path_depth - path_prefix_len;

   IF report.incl_accnos && report.rheads.ids.$row.props.account_number;
     desc = report.rheads.ids.$row.props.account_number _ ' - ' _ report.rheads.ids.$row.props.account_desc;
   ELSE;
     desc = report.rheads.ids.$row.props.account_desc;
   END;

  IF report.rheads.ids.$row.props.account_type != 'A';
    IF NOT report.rheads.ids.$row.props.section_for ;
      '\cline{' _ path_depth _ '-' _ last_col_no _ '} ';
    ELSE;
      row_id = report.rheads.ids.$row.props.section_for ;
      desc = '\Large{' _ report.rheads.ids.$row_id.props.account_desc _ '}';
    END;
    desc = '\textbf{\emph{' _ desc _ '}}';
  END;
-?>%
<?lsmb
   j = 1;
   WHILE j < path_prefix_len ;
    '& ';
    j = j + 1;
   END;
-?>
<?lsmb IF path_suffix_len > 1 -?>
\multicolumn{<?lsmb path_suffix_len ?>}{l}{<?lsmb desc ?>}%
<?lsmb ELSE; ?>
<?lsmb desc ?>
<?lsmb END -?>
%
& %
<?lsmb FOREACH col IN report.sorted_col_ids;
  ' & '; report.cells.$row.$col;
END; -?>
%
\\
%
<?lsmb IF report.rheads.ids.$row.props.account_type != 'A'; -?>
  <?lsmb IF report.rheads.ids.$row.props.section_for; -?>
\cline{<?lsmb path_depth ?>-<?lsmb last_col_no ?>}
\noalign{\vskip 2pt}
\cline{<?lsmb path_depth ?>-<?lsmb last_col_no ?>}
  <?lsmb ELSE -?>
\\
  <?lsmb END -?>

<?lsmb END ?>
<?lsmb END ?>

\end{longtable}

\end{document}
<?lsmb END ?>
