
\usemodule[spreadsheet]


% Text for the first line of a specification
\def\title{%
  \startrow[bottomframe=on]
    \startcell[align=flushleft ,width=0.48\textwidth] "{\bf \sc beschrijving}" \stopcell
    \startcell[align=flushright,width=0.16\textwidth] "{\bf \sc aantal}" \stopcell
    \startcell[align=flushright,width=0.16\textwidth] "{\bf \sc prijs}" \stopcell
    \startcell[align=flushright,width=0.20\textwidth] "{\bf \sc bedrag}" \stopcell
    %% \startcell[align=flushright,width=0.25\textwidth] "{\bf \sc btw}" \stopcell
  \stoprow
}

% Simply billable
\def\billable#1#2#3{%
  \startrow
    \startcell[align=flushleft ]   "#1" \stopcell
    \startcell[align=flushright] @ "0.2f" #2 \stopcell
    \startcell[align=flushright] @ "0.2f €" #3 \stopcell
    \startcell[align=flushright] @ "0.2f €" #2 * #3 \stopcell
  \stoprow
}

% Calculate the BTW. Now we calculate a percentage of the sum instead of the sum of the percentages.
\def\btw{%
  \startrow[topframe=on]
    \startcell[align=flushleft] "BTW\ {21}\procent" \stopcell
    \startcell \strut \stopcell
    \startcell \strut \stopcell
    \startcell[align=flushright] @ "0.2f €" sum(D) * 0.21 \stopcell % Here's the value that needs rounding
  \stoprow
}

% Calculate the Grand Total
\def\total{%
  \startrow[topframe=on]
    \startcell[align=flushleft] "{\bf Factuurbedrag}" \stopcell
    \startcell \strut \stopcell
    \startcell \strut \stopcell
    \startcell[align=flushright, style=bf] @ "0.2f €" sum(D) \stopcell
  \stoprow
}

\starttext
  % Here is the specification
  \startspreadsheettable[dutch][frame=off]
    \title
    % add your line items
    \billable{Project: Foo}{2.5}{15}
    \billable{Project: Bar}{2.5}{15}
    \billable{Project: Hat}{3.5}{15}
    \btw
    \total
  \stopspreadsheettable
\stoptext
% finis


