<?lsmb#   This is a comment block; it's ignored by the template engine.

   Version:  1.2
   Date:     2023-02-02
   File:     balance_sheet.tex
   Set:      demo

Template version numbers are explicitly not aligned across templates or
releases. No explicit versioning was applied before 2021-01-04.

Version   Changes
1.1       Merged xelatex targetting templates with those targetting pdflatex
1.2       Fixed company address not showing

-?>
<?lsmb FILTER latex { format="$FORMAT($PROCESSOR)" } -?>

<?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[10pt]{article}
\usepackage{longtable}
\usepackage[<?lsmb SETTINGS.papersize ?>paper,top=2cm,bottom=1.5cm,left=1.1cm,right=1.5cm]{geometry}
\begin{document}
\renewcommand\baselinestretch{1.2}\selectfont
\begin{center}
\Huge{<?lsmb text('Balance Sheet') ?>}

<?lsmb HLINES.1 ?>

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


\texttt{<?lsmb SETTINGS.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_description;
   ELSE;
     desc = report.rheads.ids.$row.props.account_description;
   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_description _ '}';
    END;
    desc = '\textbf{\emph{' _ desc _ '}}';
  END;
-?>%
<?lsmb
   j = 0;
   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 -?>
