\documentclass{scrartcl}
\usepackage[latin1]{inputenc}
\usepackage{tabularx}
\usepackage[top=2cm,bottom=-1cm,left=2cm,right=1cm]{geometry}
\usepackage{graphicx}
\setlength{\parindent}{0pt}

\begin{document}

\newlength{\descrwidth}\setlength{\descrwidth}{10cm}

\newsavebox{\hdr}
\sbox{\hdr}{
  \fontfamily{cmss}\fontsize{10pt}{12pt}\selectfont

  \parbox{\textwidth}{
    \parbox[b]{12cm}{
      <?lsmb company ?>
      
      <?lsmb address ?>}\hfill
    \begin{tabular}[b]{rr@{}}
    Telefone & <?lsmb tel ?>\\
    Fax & <?lsmb fax ?>
    \end{tabular}

    \rule[1.5ex]{\textwidth}{0.5pt}
  }
}
    
\fontfamily{cmss}\fontshape{n}\selectfont

\markboth{<?lsmb company ?>\hfill <?lsmb invnumber ?>}{\usebox{\hdr}}

\pagestyle{myheadings}
%\thispagestyle{empty}     use this with letterhead paper

<?lsmb pagebreak 65 27 37 ?>
\end{tabular*}

  \rule{\textwidth}{2pt}
  
  \hfill
  \begin{tabularx}{7cm}{Xr@{}}
  \textbf{Subtotal} & \textbf{<?lsmb sumcarriedforward ?>} \\
  \end{tabularx}

\newpage

\markright{<?lsmb company ?>\hfill <?lsmb invnumber ?>}

\vspace*{-12pt}

\begin{tabular*}{\textwidth}{@{}lp{\descrwidth}@{\extracolsep\fill}rlrrr@{}}
  \textbf{Number} & \textbf{Description} & \textbf{Qt'y} &
    \textbf{Unit} & \textbf{Price} & \textbf{Disc} & \textbf{Amount} \\
  & carried forward from page <?lsmb lastpage ?> & & & & & <?lsmb sumcarriedforward ?> \\
<?lsmb end pagebreak ?>


\fontfamily{cmss}\fontsize{10pt}{12pt}\selectfont

\vspace*{0.5cm}

\parbox[t]{1cm}{\hfill}
  \parbox[t]{10.5cm}{
  \textbf{To}
  \vspace{0.5cm}

<?lsmb name ?>

<?lsmb address1 ?>

<?lsmb if address2 ?>
<?lsmb address2 ?>
<?lsmb end address2 ?>

<?lsmb city ?> <?lsmb state ?> <?lsmb zipcode ?>

<?lsmb if country ?>
<?lsmb country ?>
<?lsmb end country ?>

\vspace{0.3cm}

%<?lsmb if contact ?>
%Attn: <?lsmb contact ?>
%\vspace{0.3cm}
%<?lsmb end contact ?>
\vspace{0.5cm}

<?lsmb if customerphone ?>
Tel: <?lsmb customerphone ?>
<?lsmb end customerphone ?>

<?lsmb if customerfax ?>
Fax: <?lsmb customerfax ?>
<?lsmb end customerfax ?>

<?lsmb email ?>
}
\parbox[t]{7.5cm}{
\textbf{Ship To}
\vspace{0.5cm}

<?lsmb shiptoname ?>

<?lsmb shiptoaddress1 ?>

<?lsmb if shiptoaddress2 ?>
<?lsmb shiptoaddress2 ?>
<?lsmb end shiptoaddress2 ?>

<?lsmb shiptocity ?> <?lsmb shiptostate ?> <?lsmb shiptozipcode ?>

<?lsmb if shiptocountry ?>
<?lsmb shiptocountry ?>
<?lsmb end shiptocountry ?>

\vspace{0.3cm}

\vspace{0.3cm}

<?lsmb if shiptocontact ?>
Attn: <?lsmb shiptocontact ?>
\vspace{0.3cm}
<?lsmb end shiptocontact ?>

<?lsmb if shiptophone ?>
Tel: <?lsmb shiptophone ?>
<?lsmb end shiptophone ?>

<?lsmb if shiptofax ?>
Fax: <?lsmb shiptofax ?>
<?lsmb end shiptofax ?>

<?lsmb shiptoemail ?>
}
\hfill

\vspace{1cm}

\textbf{F A T U R A}
\hfill

\vspace{1cm}

\begin{tabular}[t]{l@{\hspace{0.3cm}}l}
  \textbf{Data} & <?lsmb invdate ?> \\
  \textbf{Número} & <?lsmb invnumber ?> \\
  \textbf{Pedido} & <?lsmb ordnumber ?> \\
  \textbf{Produto} & <?lsmb employee ?>
\end{tabular}

\vspace{1cm}

\begin{tabular*}{\textwidth}{@{}lp{\descrwidth}@{\extracolsep\fill}rlrrr@{}}
  \textbf{Número} & \textbf{Descrição} & \textbf{Quant.} &
    \textbf{Unid.} & \textbf{Preço} & \textbf{Disc.} & \textbf{Total} \\
<?lsmb foreach number ?>
  <?lsmb number ?> & <?lsmb description ?> & <?lsmb qty ?> &
    <?lsmb unit ?> & <?lsmb sellprice ?> & <?lsmb discount ?> & <?lsmb linetotal ?> \\
<?lsmb end number ?>
\end{tabular*}


\parbox{\textwidth}{
\rule{\textwidth}{2pt}

\vspace{0.2cm}

\hfill
\begin{tabularx}{7cm}{Xr@{}}
  \textbf{Subtotal} & \textbf{<?lsmb subtotal ?>} \\
<?lsmb foreach tax ?>
  <?lsmb taxdescription ?> em <?lsmb taxbase ?> & <?lsmb tax ?> \\
<?lsmb end tax ?>
<?lsmb if paid ?>
  \textbf{Pago} & - <?lsmb paid ?> \\
<?lsmb end paid ?>
  \hline
  \textbf{Pendente} & \textbf{<?lsmb total ?>} \\
\end{tabularx}

\vspace{0.3cm}

\hfill
  Preços em \textbf{<?lsmb currency ?>}.

\vspace{12pt}

<?lsmb if notes ?>
  <?lsmb notes ?>
<?lsmb end if ?>

}

\vfill

<?lsmb if paid ?>
\begin{tabularx}{10cm}{@{}lXlr@{}}
  \textbf{Pagamentos} & & & \\
  \hline
  \textbf{Data} & \textbf{Conta} & \textbf{Origem} & \textbf{Total} \\
<?lsmb end paid ?>
<?lsmb foreach payment ?>
  <?lsmb paymentdate ?> & <?lsmb paymentaccount ?> & <?lsmb paymentsource ?> & <?lsmb payment ?> \\
<?lsmb end payment ?>
<?lsmb if paid ?>
\end{tabularx}
<?lsmb end paid ?>

\vspace{1cm}

\centerline{\textbf{Obrigado por estarmos fazendo negócio!}}

\end{document}

