bankstatement 0.9.2 available in CTAN
Recently, the new version 0.9.2 of bankstatement is available in CTAN (see Announcement (ctan-ann@ctan.org)). Here is a brief summary of the new features in the README:
Changes in v0.9.2:
* use of
siunitx
to force two decimals, if csv data contains
other formats like16.2 -> 16.20
* added support for Standard Bank (Namibia) and namibian
feature requests by Dr. Eberhard Lisse
* organized package in
dtx
format
The update should be available soon also in TeXLive and MiKTeX!
HowTo support arbitrary CSV formats
#bankstatement #howto
Using the example of the new csv
format file csv-standard-bank-na.def
I would like to explain – hopefully comprehensible – how to support more or less arbitrary csv
formats. Take just one of the existing files and adjust them accordingly!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
\renewcommand*\STM@JK@dbkeys{ValueDate,PostingDate,Reference,Narrative,Amount,Balance}% \renewcommand*\STM@JK@DTLforeach% {% \DTLforeach{\STM@JK@dbname}% {\postingdate=PostingDate,\valuedate=ValueDate,\reference=Reference,\narrative=Narrative,\amount=Amount,\balance=Balance}% {% \parbox[t]{\widthof{ (YYYY-MM-DD) }}{\leavevmode\hphantom{(}\postingdate\\(\valuedate)} &% \parbox[t]{\STM@JK@referencewidth}{\raggedright% \DTLifstringeq{\reference}{}{}{\reference\\}% \DTLifstringeq{\narrative}{}{}{\narrative\\}% } &% \parbox[t]{\widthof{1234567.89)}}{\raggedleft\DTLifStartsWith{\amount}{-}{\textcolor{\STM@JK@negativecolor}{\num{\amount}\hphantom{)}}}{\num{\amount}\hphantom{)}}\\(\num{\balance})} \DTLiflastrow{% \ifthenelse{\equal{\STM@JK@closingbalance}{none}}% {}% {\\\midrule\\ & \STM@JK@closingbalancename & \DTLifStartsWith{\STM@JK@closingbalance}{-}% {\textcolor{\STM@JK@negativecolor}{\num{\STM@JK@closingbalance}}}{\num{\STM@JK@closingbalance}}}% \\\bottomrule% }% {\\ & & \\}% }% }% \DTLsetseparator{,}% \renewcommand*\STM@JK@noheader{false}% \sisetup{detect-all,round-integer-to-decimal,round-mode=places,round-precision=2}% |
- First one determines the order of the keys in the
csv
file.
1\renewcommand*\STM@JK@dbkeys{ValueDate,PostingDate,Reference,Narrative,Amount,Balance}% - Then we define
\STM@JK@DTLforeach ; a macro that reads the
csv
file line by line and outputs them as LaTeX table row. It uses to the \DTLforeach macro (datatool.sty
)
123456789101112131415161718192021\renewcommand*\STM@JK@DTLforeach%{%\DTLforeach{\STM@JK@dbname}%{\postingdate=PostingDate,\valuedate=ValueDate,\reference=Reference,\narrative=Narrative,\amount=Amount,\balance=Balance}%{%\parbox[t]{\widthof{ (YYYY-MM-DD) }}{\leavevmode\hphantom{(}\postingdate\\(\valuedate)} &%\parbox[t]{\STM@JK@referencewidth}{\raggedright%\DTLifstringeq{\reference}{}{}{\reference\\}%\DTLifstringeq{\narrative}{}{}{\narrative\\}%} &%\parbox[t]{\widthof{1234567.89)}}{\raggedleft\DTLifStartsWith{\amount}{-}{\textcolor{\STM@JK@negativecolor}{\num{\amount}\hphantom{)}}}{\num{\amount}\hphantom{)}}\\(\num{\balance})}\DTLiflastrow{%\ifthenelse{\equal{\STM@JK@closingbalance}{none}}%{}%{\\\midrule\\ & \STM@JK@closingbalancename & \DTLifStartsWith{\STM@JK@closingbalance}{-}%{\textcolor{\STM@JK@negativecolor}{\num{\STM@JK@closingbalance}}}{\num{\STM@JK@closingbalance}}}%\\\bottomrule%}%{\\ & & \\}%}%}%- As the first argument you pass the name of the
csv
file. No change! - The second argument maps the
csv
keys to macros - In the third and final argument, the output of the three-column table row is done
- In the first column we output the posting and value dates
1\parbox[t]{\widthof{ (YYYY-MM-DD) }}{\leavevmode\hphantom{(}\postingdate\\(\valuedate)} &% - In the second column we output the reference, which may be composed of several
csv
keys.
1234\parbox[t]{\STM@JK@referencewidth}{\raggedright%\DTLifstringeq{\reference}{}{}{\reference\\}%\DTLifstringeq{\narrative}{}{}{\narrative\\}%} &% - In the third column we output the value. A negative amount will be typeset in red (negativcolor option)
1\parbox[t]{\widthof{1234567.89)}}{\raggedleft\DTLifStartsWith{\amount}{-}{\textcolor{\STM@JK@negativecolor}{\num{\amount}\hphantom{)}}}{\num{\amount}\hphantom{)}}\\(\num{\balance})} - Finally, a test on the last row of data is performed and the closing balance or a blank line is issued.
1234567\DTLiflastrow{%\ifthenelse{\equal{\STM@JK@closingbalance}{none}}%{}%{\\\midrule\\ & \STM@JK@closingbalancename & \DTLifStartsWith{\STM@JK@closingbalance}{-}{\textcolor{\STM@JK@negativecolor}{\num{\STM@JK@closingbalance}}}{\num{\STM@JK@closingbalance}}}%\\\bottomrule%}%{\\ & & \\}%
- In the first column we output the posting and value dates
- As the first argument you pass the name of the
- In the last step, we define the separator of the
csv
file and determine whether it has a header row (Caution: header → noheader=false! (noheader option (datatool.sty))). The last line can be usually simply copied (siunitx
setup)!
123\DTLsetseparator{,}%\renewcommand*\STM@JK@noheader{false}%\sisetup{detect-all,round-integer-to-decimal,round-mode=places,round-precision=2}%
Hopefully this helps to adapt and support other csv
formats! 😉
HowTo support other languages
#bankstatement #howto
Using the example of the new file stmnamibian.def
I’d like to briefly explain how to support other languages. One recognizes immediately, that the filename must follow the pattern stmLANGUAGE.def
. First, we consider the definition file for english:
1 2 3 4 5 6 7 8 9 10 |
\renewcommand*\STM@JK@holdername{Account Holder}% \renewcommand*\STM@JK@bicname{BIC}% \renewcommand*\STM@JK@ibanname{IBAN}% \renewcommand*\STM@JK@firstcolumnheading{\bfseries Date}% \renewcommand*\STM@JK@secondcolumnheading{\bfseries Reference}% \renewcommand*\STM@JK@thirdcolumnheading{\bfseries Amount (GBP)}% \renewcommand*\STM@JK@openingbalancename{Opening Balance}% \renewcommand*\STM@JK@closingbalancename{Closing Balance}% \sisetup{output-decimal-marker={.}}% \endinput |
If you want to support a namibian bank now, it requires of course the change of currency (3rd column) and the SEPA terms BIC and IBAN:
1 2 3 4 5 6 7 8 9 10 |
\renewcommand*\STM@JK@holdername{Account Holder}% \renewcommand*\STM@JK@bicname{Branch Code}% \renewcommand*\STM@JK@ibanname{Account Number}% \renewcommand*\STM@JK@firstcolumnheading{\bfseries Date}% \renewcommand*\STM@JK@secondcolumnheading{\bfseries Reference}% \renewcommand*\STM@JK@thirdcolumnheading{\bfseries Amount (NAD)}% \renewcommand*\STM@JK@openingbalancename{Opening Balance}% \renewcommand*\STM@JK@closingbalancename{Closing Balance}% \sisetup{output-decimal-marker={.}}% \endinput |
siunitx for rounding to 2 decimals exactly
#bankstatement #develop
The latest version of bankstatement
ensures that account transactions having exactly two decimals. Especially when an amount of e.g. 16.2€ is stored in the csv
file (16.2 → 16.20).
In addition, the use of siunitx allows the determination of the decimal marker on dependence on the language – however independent of notation in the csv
file, like
\sisetup{output-decimal-marker={.}} in the file stmenglish.def
. This is more important in other languages where the comma acts as decimal marker!