\mainlanguage[de]
\usemodule[letter]
\startluacode
require("invoicelib")
\stopluacode

\setuplanguage [en] [date={year, –, mm, –, dd}] % Datum nach ISO 8601
\setupinterlinespace[3.0ex] % default: 2.8ex
\setbreakpoints[compound] % break at / and -
\setupletteroptions[language=german, whitespace=1.5ex]

\setuptabulate[distance=0pt]

\usetypescriptfile	[type-computer-modern-unicode,]
\usetypescript	[computer-modern-unicode-concrete]
\setupbodyfont	[computer-modern-unicode-concrete,rm,10pt]
\setupletteroptions[bodyfont={computer-modern-unicode-concrete,rm,10pt}]

\setupletter[
	% Sender address in envelope window
	backaddress={}
]

\startnotmode[nologo]
% Define logo for the first page
\defineletterelement[layer][head][fiee]%
	{\externalfigure[briefbogen]}

% Other logo for subsequent (right) pages
\defineletterelement[layer][nexthead][fiee]%
	{\externalfigure[briefbogen][height=2cm,width=6cm]}

% We put our logo in the head
\setupletterlayer[head,nexthead]
	[preset=lefttop,
	alternative=fiee,
	x=0mm,y=0mm,
]

\setupletterlayer[nexthead][state=right]
\stopnotmode

\setupletter[
  company={},
	name={},
	street={},
	city={},
	phone={},
	mobile={},
	email={},
	web={}
]

% center around the :
\defineletterelement[layer][location][fiee]%
	{\hskip5em \fieevis
    \setuptabulate[bodyfont=small]
	\starttabulate[|Irw(5em)|Ip|]%[distance=0pt,bodyfont=small]
    %\NC \strut      \NC{\definedfont[SerifItalic at 10pt]\correspondenceparameter{company}}\NC\NR
	\NC Who 	\NC\correspondenceparameter{name} \NC\NR
	\NC Where 		\NC\correspondenceparameter{street}\\\correspondenceparameter{city}\NC\NR
	\NC Phone 	\NC\correspondenceparameter{phone}\\\correspondenceparameter{mobile} \NC\NR
	\NC Internet 	\NC\correspondenceparameter{email}\\\correspondenceparameter{web} \NC\NR
\stoptabulate}

\setupletterlayer[location]
	[alternative=fiee,
    x=147mm,y=45mm
	]

% Our own recipient setup without too much space before the address
\defineletterelement[layer][address][fiee]%
	{\correspondenceparameter{toname}\\
	\correspondenceparameter{toaddress}
	\par}

\setupletterlayer[address][alternative=fiee]

% Subject and date on the same line, date below logo
\startsetups[letter:section:subject]
  \bTABLE[frame=off]
    \bTR % ex 169mm
      \bTD[width=\dimexpr164mm-\backspace\relax]\correspondenceparameter{subject}\eTD
     \bTD{\tf\correspondenceparameter{date}}\eTD
    \eTR
  \eTABLE
\stopsetups

\setuplettersection[subject][alternative=setups]

% account information at the foot, below the logo
\defineletterelement[layer][foot][fiee]%
  {\setuptabulate[bodyfont=small]
  \starttabulate[|Irw(39mm)|Ip|]%[distance=0pt,bodyfont=small]
		\NC Accounts \NC \NC\NR
		\NC Tax No. \NC ... \NC\NR
		\NC UStID \NC ... \NC\NR
		\NC IBAN \NC ... \NC\NR
		\NC BIC \NC ... \NC\NR
	\stoptabulate}

\setupletterlayer[foot][
	preset=leftbottom,
	x=122mm, %x=127mm,
	y=24mm, %y=34mm,
	alternative=fiee]

% switch off reference line
\setupletterlayer[reference][state=stop]

% Move the text a bit up
\setupletterlayout[firstpage][topspace=10cm]

% Adjust text start on subsequent pages
\setupletterlayout[secondpage][topspace=3cm]

% Move marks to the paper rim (won't print on most printers)
\setupletterlayer[topmark,botmark,cutmark][x=-2mm]
