% --------------------------------------%--------------------------------------
% ---------------------------- Identification part ----------------------------
% --------------------------------------%--------------------------------------

\RequirePackage{rcs}

\RCS$Date: 1999/06/09 13:48:55 $
\RCS$RCSfile: aarr.cls,v $
\RCS$Revision: 0.4 $
\RCS$State: Exp $
\RCS$Author: anders $

\input{aausercs}

% --------------------------------------%--------------------------------------
% ------------------------------ Package loading ------------------------------
% --------------------------------------%--------------------------------------

\LoadClass[a4paper]{article}
\RequirePackage[latin1]{inputenc}
\RequirePackage{aanokcalc}
\RequirePackage{tabularx}
\RequirePackage{aabetong}
\RequirePackage{aanorsk}
\RequirePackage{Vmargin}


% --------------------------------------%--------------------------------------
% --------------------------------- Main code ---------------------------------
% --------------------------------------%--------------------------------------

% Papirstørrelse og sideoppsett
\setpapersize{A4}
\setmarginsrb{15mm}{15mm}{15mm}{15mm}{0mm}{0mm}{0mm}{0mm}
\pagestyle{empty}

% Kommandoer for å skrive ut verdier i reiseregning
\newcommand{\printdate}{\@date}
\newcommand{\printauthor}{\@author}
\newcommand{\printtitle}{\@title}
\newcommand{\printreisested}{~}
\newcommand{\printlnr}{~}
\newcounter{rrln}\setcounter{rrln}{0}
\renewcommand{\therrln}{\alph{rrln}}
\newcounter{rrli}\setcounter{rrli}{1}
\renewcommand{\therrli}{\alph{rrli}}
\newcounter{ffln}\setcounter{ffln}{0}
\renewcommand{\theffln}{\alph{ffln}}
\newcounter{ffli}
\renewcommand{\theffli}{\alph{ffli}}

% Defaultverdier
\def\rra{{\ }}\def\rrb{{\ }}\def\rrc{{\ }}\def\rrd{{\ }}
\def\rre{{\ }}\def\rrf{{\ }}\def\rrg{{\ }}
\def\ffla{{\ }}\def\fflb{{\ }}\def\fflc{{\ }}
\setval{affi}{0,00}

% Kommandoer for å gi verdier til felt i reiseregning
\def\@author{{\ }}\def\@title{{\ }}
\newcommand{\navn}[1]{\author{#1}}
\newcommand{\formaal}[1]{\title{#1}}
\newcommand{\reisested}[1]{\renewcommand{\printreisested}{#1}}
\newcommand{\dato}[1]{\date{#1}}
\newcommand{\reiserute}[7][~]{%
  \stepcounter{rrln}%
  \def\rra{#2}\def\rrb{#3}\def\rrc{#4}\def\rrd{#5}
  \def\rre{#6}\def\rrf{#7}\def\rrg{#1}%
  \expandafter\def\csname \therrln rrl\endcsname{%
    & \multicolumn{1}{|c|}{#2} & #3 & #4 & #5 & 
    \multicolumn{3}{l|}{#6} & \multicolumn{1}{l|}{#7} &
    \makebox[1pt][l]{#1}}}
\newcommand{\finansiering}[4][~]{%
  \stepcounter{ffln}%
  \def\ffla{#2}\def\fflb{#3}\def\fflc{#1}%
  \expandafter\setval{\theffln ffi}{#4}%
  \expandafter\def\csname \theffln ffl\endcsname{%
    & \multicolumn{5}{|l|}{$-$ #2} & \multicolumn{2}{l|}{#3} &
    \printconst{#4} & \makebox[1pt][l]{#1}}}

% Utgangsverider

% Satser
\setval{bilprkm}{3,25}\setval{bilprpas}{0,50}
\setval{kostk}{240,00}\setval{kostl}{440,00}\setval{kosto}{440,00}
\setval{kostu}{690,00}  % Storbritania
\setval{trekkf}{60,00}\setval{trekkl}{170,00}\setval{trekkm}{210,00}
\setval{unatt}{400,00}
\setval{nattu}{1310,00} % Storbritania
\setval{adm}{38,00}

% Utgifter etter satser (antall)
\setnval[$3{,}20/\mbox{km}$ utenom Tromsø]{bilkm}{0}\setnval{bilpas}{0}
\setnval{numkostk}{0}\setnval{numkostl}{0}
\setnval{numkosto}{0}
\setnval{numkostu}{0}
\setnval{numtrekkf}{0}\setnval{numtrekkl}{0}\setnval{numtrekkm}{0}
\setnval{numunatt}{0}
\setnval{numnattu}{0}
\setnval{numadm}{0}

% Utgifter etter bilag
\setval{bilett}{0,00}
\setval{transbi}{0,00}
\setval{transub}{0,00}
\setval{kurs}{0,00}
\setval{onattbi}{0,00}
\setval{onattub}{0,00}
\setval{gebyrur}{0,00}
\setval{regning}{0,00}

% Forskudd
\setval{forskudd}{0,00}
\setval{unireiser}{0,00}

% Regn ut resultat
\AtBeginDocument{%
  \mulval{sumbilkm}{bilkm}{bilprkm}
  \mulval{sumbilpas}{bilpas}{bilprpas}
  \mulval{sumkostk}{numkostk}{kostk}
  \mulval{sumkostl}{numkostl}{kostl}
  \mulval{sumkosto}{numkosto}{kosto}
  \mulval{sumkostu}{numkostu}{kostu}
  \mulval{sumtrekkf}{numtrekkf}{trekkf}
  \mulval{sumtrekkl}{numtrekkl}{trekkl}
  \mulval{sumtrekkm}{numtrekkm}{trekkm}
  \subval{sumtrekk}{sumtrekkf,sumtrekkl,sumtrekkm}
  \mulval{sumunatt}{numunatt}{unatt}
  \mulval{sumnattu}{numnattu}{nattu}
  \mulval{sumadm}{numadm}{adm}
  \subval{utbetalt}{forskudd,unireiser}
  \sumval{brutto}{%
    sumbilkm,sumbilpas,sumkostk,sumkostl,sumkosto,sumkostu,sumtrekk,%
    sumunatt,sumnattu,sumadm,bilett,transbi,transub,kurs,onattbi,onattub,%
    gebyrur,regning}
  \sumval{lonn}{brutto,utbetalt}
  \setval{sumfi}{0,00}
  \setcounter{ffli}{0}
  \whiledo{\value{ffli}<\value{ffln}}{%
    \stepcounter{ffli}
    \giveval{finansiering}{sumfi}
    \sumval{sumfi}{finansiering,\theffli ffi}}
  \subval{finansiering}{sumfi}
  \sumval{rest}{brutto,finansiering}}

% Generer reiseregninga med denne kommandoen
\newcommand{\GenererReiseregning}{%
  \section*{Reiseregning NORUT Informasjonsteknologi as}

  \begin{tabularx}{\linewidth}{@{}m{0pt}@{}c|r|c|r|c|r|r|r|X|}\hline
    % Hode
    &\multicolumn{7}{|l|}{\textbf{Navn:} \printauthor} & 
    \multicolumn{2}{l|}{\textbf{Reisested:} \printreisested} \\ \hline
    &\multicolumn{9}{|l|}{\textbf{Formål:} \printtitle} \\ \hline
    &\multicolumn{9}{c}{~} \\ \hline
    % Reisebeskrivelse
    &\multicolumn{2}{|l|}{\textbf{Avreise}} &
    \multicolumn{2}{l|}{\textbf{Ankomst}} &
    \multicolumn{3}{l|}{\textbf{Reiserute}} &
    \multicolumn{1}{l|}{\textbf{Skyss-}} &
    \textbf{Passasjer/kommentar} \\ \cline{1-5}
    &\multicolumn{1}{|c|}{\textbf{Dato}} & \multicolumn{1}{c|}{\textbf{Kl.}} &
    \textbf{Dato} & \multicolumn{1}{c|}{\textbf{Kl.}} &
    \multicolumn{3}{l|}{~} &
    \multicolumn{1}{l|}{\textbf{middel}} &  \\ \hline
    \whiledo{\value{rrli}<\value{rrln}}{%
      \csname \therrli rrl\endcsname \stepcounter{rrli}\\}%
    &\multicolumn{1}{|c|}{\rra} & \rrb & \rrc & \rrd &
    \multicolumn{3}{l|}{\rre} &
    \multicolumn{1}{l|}{\rrf} & \makebox[1pt][l]{\rrg} \\ \hline
    &\multicolumn{9}{c}{~} \\ \hline
    % Utgifter
    &\multicolumn{4}{|l|}{\textbf{Utgifter}} &
    \textbf{Kode} & \textbf{Antall} & \textbf{Sats} & 
    \multicolumn{1}{l|}{\textbf{Beløp}} &
    \textbf{Kommentar} \\ \hline
    &\multicolumn{4}{|l|}{\phantom{$+$} Bil inntil 9000km} &
    4000 & \printnval{bilkm} & \printval{bilprkm} &
    \printval{sumbilkm} & \printcom{bilkm} \\
    &\multicolumn{4}{|l|}{$+$ Bil, tillegg passasjerer} &
    4040 & \printnval{bilpas} & \printval{bilprpas} &
    \printval{sumbilpas} & \printcom{bilpas} \\ \hline
    &\multicolumn{4}{|l|}{$+$ Kost innenlands 6--12 t} &
    4110 & \printnval{numkostk} & \printval{kostk} &
    \printval{sumkostk} & \printcom{} \\ 
    &\multicolumn{4}{|l|}{$+$ Kost innenlands over 12 t} &
    4120 & \printnval{numkostl} & \printval{kostl} &
    \printval{sumkostl} & \printcom{numkostl} \\ 
    &\multicolumn{4}{|l|}{$+$ Kost ved overnatting} &
    4130 & \printnval{numkosto} & \printval{kosto} &
    \printval{sumkosto} & \printcom{numkosto} \\ 
    &\multicolumn{4}{|l|}{$+$ Kost utenlands} &
    4300 & \printnval{numkostu} & \printval{kostu} &
    \printval{sumkostu} & \printcom{numkostu} \\ \hline
    &\multicolumn{4}{|l|}{$-$ Fratrekk frokost} &
    4140 & \printnval{numtrekkf} & \printval{trekkf} &
    \printval{sumtrekkf} & \printcom{numtrekkf} \\ 
    &\multicolumn{4}{|l|}{$-$ Fratrekk lunsj} &
    4145 & \printnval{numtrekkl} & \printval{trekkl} &
    \printval{sumtrekkl} & \printcom{numtrekkl} \\ 
    &\multicolumn{4}{|l|}{$-$ Fratrekk middag} &
    4150 & \printnval{numtrekkm} & \printval{trekkm} &
    \printval{sumtrekkm} & \printcom{numtrekkm} \\ \hline
    &\multicolumn{4}{|l|}{$+$ Ulegitimetert nattillegg} &
    4490 & \printnval{numunatt} & \printval{unatt} &
    \printval{sumunatt} & \printcom{numunatt} \\ 
    &\multicolumn{4}{|l|}{$+$ Natt-tillegg utenlands} &
    4500 & \printnval{numnattu} & \printval{nattu} &
    \printval{sumnattu} & \printcom{numnattu} \\ 
    &\multicolumn{4}{|l|}{$+$ Administrasjonstillegg} &
    4470 & \printnval{numadm} & \printval{adm} &
    \printval{sumadm} & \printcom{numadm} \\ \hline
    &\multicolumn{4}{|l|}{$+$ Bilettutgifter ifølge bilag} &
    4401 & \multicolumn{2}{l|}{} &
    \printval{bilett} & \printcom{bilett} \\
    &\multicolumn{4}{|l|}{$+$ Diverse transport ifølge bilag} &
    4402 & \multicolumn{2}{l|}{} &
    \printval{transbi} & \printcom{transbi} \\
    &\multicolumn{4}{|l|}{$+$ Diverse transport uten bilag} &
    4402 & \multicolumn{2}{l|}{} &
    \printval{transub} & \printcom{transub} \\
    &\multicolumn{4}{|l|}{$+$ Kursavgift o.l.\ ifølge bilag} &
    4403 & \multicolumn{2}{l|}{} &
    \printval{kurs} & \printcom{kurs} \\
    &\multicolumn{4}{|l|}{$+$ Overnatting ifølge bilag} &
    4410 & \multicolumn{2}{l|}{} &
    \printval{onattbi} & \printcom{onattbi} \\
    &\multicolumn{4}{|l|}{$+$ Overnatting/kost ifølge bilag} &
    4420 & \multicolumn{2}{l|}{} &
    \printval{onattub} & \printcom{onattub} \\
    &\multicolumn{4}{|l|}{$+$ Gebyr UniReiser} &
    4404 & \multicolumn{2}{l|}{} &
    \printval{gebyrur} & \printcom{gebyrur} \\ 
    &\multicolumn{4}{|l|}{$+$ Utlegg etter regning} &
    4400 & \multicolumn{2}{l|}{} &
    \printval{regning} & \printcom{regning} \\ \hline
    &\multicolumn{4}{|l|}{$=$ Brutto reiseregning} & &
    \multicolumn{2}{l|}{} & 
    \printval*{brutto} & \printcom{brutto} \\ \hline\hline
    &\multicolumn{4}{|l|}{$-$ Reiseforskudd} &
    8715 & \multicolumn{2}{l|}{} &
    \printval{forskudd} & \printcom{forskudd} \\
    &\multicolumn{4}{|l|}{$-$ Faktura, UniReiser} &
    8715 & \multicolumn{2}{l|}{} &
    \printval{unireiser} & \printcom{unireiser} \\ \hline
    &\multicolumn{4}{|l|}{$=$ Over lønnssystemet} & &
    \multicolumn{2}{l|}{} & 
    \printval*{lonn} & \printcom{lonn} \\ \hline\hline
    &\multicolumn{9}{c}{~} \\ \hline
    % Finansiering
    &\multicolumn{5}{|l|}{\textbf{Finansiering}} &
    \multicolumn{2}{l|}{\textbf{Prosjektnr.}} &
    \multicolumn{1}{l|}{\textbf{Beløp}} &
    \textbf{Kommentar} \\ \hline
    &\multicolumn{5}{|l|}{Brutto reiseregning} &
    \multicolumn{2}{l|}{} & \printval{brutto} &
    \setcounter{ffli}{1} \\ \hline%
    \whiledo{\value{ffli}<\value{ffln}}{%
      \csname \theffli ffl\endcsname\stepcounter{ffli}\\}
    &\multicolumn{5}{|l|}{$-$ \ffla} & \multicolumn{2}{l|}{\fflb} &
    \printval*{\theffli ffi} &
    \makebox[0pt][l]{\fflc} \\ \hline
    &\multicolumn{5}{|l|}{$=$ Manglende finansiering} &
    \multicolumn{2}{l|}{} & \printval*{rest} & \\ \hline
    &\multicolumn{9}{c}{~} \\ 
  \end{tabularx} 

  \begin{tabularx}{\linewidth}{|X|X|X|}\hline
    \textbf{Underskrift}\hfil\printdate &
    \textbf{Attestasjon} &
    \textbf{Anvisning} \\
    & & \\
    & & \\ \hline
    \multicolumn{1}{l}{Regningsutsteder} &
    \multicolumn{1}{l}{Forskningsleder} &
    \multicolumn{1}{l}{Adm dir/økonomiansvarlig}
  \end{tabularx}}
