1
0
Fork
You've already forked mt940-ledger
0
Interactively convert mt940 csv files to ledger
  • C++ 96.7%
  • Makefile 1.8%
  • Nix 1.5%
Find a file
2019年06月12日 18:32:15 +02:00
.gitignore Don’t hard-core g++, add Nix packaging 2019年06月12日 18:29:41 +02:00
.travis.yml Add travis badge and build 2019年06月12日 18:32:15 +02:00
argument_parser.cpp add templates, split into files 2016年03月25日 19:48:29 +01:00
argument_parser.hpp polishing 2016年03月28日 13:43:32 +02:00
banking_arguments.cpp fix signed arguments 2016年03月28日 13:55:59 +02:00
banking_arguments.hpp polishing 2016年03月28日 13:43:32 +02:00
csv.cpp add templates, split into files 2016年03月25日 19:48:29 +01:00
csv.hpp polishing 2016年03月28日 13:43:32 +02:00
default.nix Don’t hard-core g++, add Nix packaging 2019年06月12日 18:29:41 +02:00
LICENSE polishing 2016年03月28日 13:43:32 +02:00
main.cpp polishing 2016年03月28日 13:43:32 +02:00
Makefile Don’t hard-core g++, add Nix packaging 2019年06月12日 18:29:41 +02:00
readline.cpp polishing 2016年03月28日 13:43:32 +02:00
readline.hpp polishing 2016年03月28日 13:43:32 +02:00
Readme.org Add travis badge and build 2019年06月12日 18:32:15 +02:00
template.txt polishing 2016年03月28日 13:43:32 +02:00
templates.cpp add readline support 2016年03月26日 13:32:46 +01:00
templates.hpp polishing 2016年03月28日 13:43:32 +02:00

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):

Parameter Description
template-file See above example
separator CSV separator
skip-header Skip the first line of the CSV file
date-format CSV date format to parse via strptime
column-date Column for the date
column-summary Column for the summary (negative if not present)
column-purpose SWIFT column for purpose (negative if not present)
column-payer Column for the payer (negative if not present)
column-amount Column for the amount
column-currency Column 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.