AddStatementTransaction

AddStatementTransaction (ref, date, tofrom, desc, amt)

Use this function to add a transaction to a bank statement import. The function only works when a Load Statement dialog is open, so can only be used from a statement loading script.

Statement Loading Scripts

Statement Loading in MoneyWorks supports well-defined bank statement formats (QIF and OFX/QBO). Some banks only provide CSV format and the problem is that CSV is not a format as such, but merely a field delimiter specification (namely commas between fields). The fields themselves will be arbitrary. Bank statements in CSV format will differ between banks. Statements may also be available in other formats. This is where Statement Loading Scripts are useful.

You may place an external .mwscript file in MoneyWorks Standard Plugins/Scripts/Bank Statement Importers/. These scripts will show up as format options in the Bank Statement loading window...

Screen Shot 2015-07-21 at 10.09.09 am

When you select the importer script and click Load Statement File, MoneyWorks will load your script and execute the Load handler. The Load handler should open a text file, parse it, and call AddStatementTransaction for each transaction it finds in the file.

And here is an example for importing tab-delimited data scraped from a Kiwibank PDF bank statement using Tabula.

constant meta = "Kiwibank scraped PDF statement as Tab separated. http://cognito.co.nz"

on TrimQuotes(str)
    if Left(str, 1) = "$"
        let str = Right(str, Length(str) - 1)
    endif
    if Left(str, 1) = "\"" and Right(str, 1) = "\""
        return Mid(str, 2, Length(str) - 2)
    endif
    return str
end


on Load
    foreach line in textfile ""         // no filename -> present a file open dialog
        let transdate = TrimQuotes(Slice(line, 1, "\t"))    // slice automatically trims whitespace
        let procdate = TrimQuotes(Slice(line, 2, "\t"))
        let card = TrimQuotes(Slice(line, 3, "\t"))
        let desc = TrimQuotes(Slice(line, 4, "\t"))
        let credit = TrimQuotes(Slice(line, 5, "\t"))
        let debit = TrimQuotes(Slice(line, 6, "\t"))
        let amt = TextToNum(credit) - TextToNum(debit)
        if transdate = "" // skip currency conversion lines
            continue
        endif
        AddStatementTransaction("", TextToDate(transdate), desc, "", amt)
    endfor
end

Availability

MoneyWorks 7.2 and later (including Express and Cashbook).

Posted in Functions | Comments Off on AddStatementTransaction