railslove / cmxl

your friendly MT940 SWIFT file parser for bank statements
http://railslove.com
MIT License
46 stars 25 forks source link

Field 61: Statement Line cannot parse transactions of type 'S' #38

Closed bkues3 closed 4 years ago

bkues3 commented 5 years ago

There are three acceptable codes for transaction type ('S', 'N', and 'F') in Field 61 of MT940, but the parser in Cmxl::Fields::Transaction only handles two of them ('N' and 'F').

See this link for more information about the acceptable codes.

I believe this issue can be resolved simply by adding this missing third letter to the swift_code group of the regex, so that it becomes as follows.

%r{^(?<date>\d{6})(?<entry_date>\d{4})?(?<storno_flag>R?)(?<funds_code>[CD]{1})(?<currency_letter>[a-zA-Z])?(?<amount>\d{1,12},\d{0,2})(?<swift_code>(?:S|N|F).{3})(?<reference>NONREF|(.(?!\/\/)){,16}([^\/]){,1})((?:\/\/)(?<bank_reference>[^\n]{,16}))?((?:\n)(?<supplementary>.{,34}))?$}

Here is an example line that is not currently handled correctly.

:61:1911181118CR653,00S445328556-76501096
bumi commented 4 years ago

Thanks for reporting this and the link. A pull request for this is very welcome. Can you add the suggested change and include a test case with the example data that you've seen?

bkues3 commented 4 years ago

Pull request #42 has been created to resolve this issue.