Skip to content

pmiddend/mt940-ledger

Repository files navigation

mt940-ledger

https://travis-ci.org/pmiddend/mt940-ledger.svg?branch=master

mt940 is a small program to interactively process a file stored in MT940 CSV format (which is exported by at least one large German bank) and store the results in ledger format.

Dependencies

mt940-ledger only depends on the readline library, make and a recent C++11 compiler (gcc-4.9 or clang). On Ubuntu, you can install the package libreadline-dev and build-essential and you should be good to go.

Build

To build mt940-ledger, simply clone the repository, switch to it and execute make. The executable produced will be called mt940-ledger. If your compiler is clang, use make CC=/usr/bin/clang++ to build. Currently, there is no install target available, and the Makefile isn’t set up with proper care (pull requests welcome).

If you’re using the Nix package manager, just run nix-build and you can execute the program via result/bin/mt940-ledger.

Usage

Example

mt940-ledger has a lot of command line parameters, all of them are mandatory (because I was too lazy to implement optional command line options). Let’s see what a sample call looks like and what it does. Let’s say you have the following sample mt940-csv file (called sample.csv):

"Target account";"Booking date";"Value date";"Posting text";"Purpose";"Payer";"Account number";"BIC";"Amount";"Currency"
"133731338";"29.01.16";"29.01.16";"Music for you";"SVWZ+Spotify";"Friend of mine";"DE423424295235";"INGFOOBAR";"-7,00";"EUR"
...

In the shell, we enter the following

./mt940-ledger            \
  --separator=\;          \
  --skip-header=true      \
  --date-format=%d.%m.%y  \
  --column-date=1         \
  --column-summary=3      \
  --column-purpose=4      \
  --column-payer=5        \
  --column-amount=8       \
  --column-currency=9     \
  --template-file=tem.txt \
  sample.csv              \
  /tmp/output.dat

As you can see, there’s a template-file argument. Each entry in the csv file is mapped to this template, inserting the appropriate placeholders. tem.txt looks like this:

${date} ${purpose}
    ; summary: ${summary}
    ; purpose: ${purpose}
    ; payer: ${payer}
    ${account}              ${amount} ${currency}
    Assets:Main

The output of the call above is the following:

2016/01/29 Spotify
    ; summary: Music for you
    ; purpose: Spotify
    ; payer: Friend of mine
    ${account}              -7,00 EUR
    Assets:Main

enter “s” to skip the entry, ctrl+d to exit
purpose [Spotify] 

Now we enter the purpose or press return to use “Spotify” as our purpose (which is fine). Then we are prompted for the target account (for example Expenses:Leisure:Music) and then /tmp/output.dat gets a new entry:

2016/01/29 Spotify
    ; summary: Music for you
    ; purpose: Spotify
    ; payer: Friend of mine
    Expenses:Leisure:Music              -7,00 EUR
    Assets:Main

Command line parameters

The following parameters exist (columns start with index zero, boolean values are yes/no,0/1,true/false):

ParameterDescription
template-fileSee above example
separatorCSV separator
skip-headerSkip the first line of the CSV file
date-formatCSV date format to parse via strptime
column-dateColumn for the date
column-summaryColumn for the summary (negative if not present)
column-purposeSWIFT column for purpose (negative if not present)
column-payerColumn for the payer (negative if not present)
column-amountColumn for the amount
column-currencyColumn for the currency

SWIFT columns follow the SWIFT coding. If your CSV file has a column with funny strings in it like SVWZ+ or +EREF, it’s SWIFT. Use column-purpose on it. mt940-ledger will parse the “real” purpose from it.

There are two positional arguments (ones without a --foo= parameter in front of them). The first one is the input CSV file, the second one the output file. There is no magic - constant meaning stdout.