In this article
Introduction
This page provides you with step-by-step guidance for creating an extension to import a typical bank statement in CSV format.
You find simple examples in the Repository China/ImportExtensions. All the examples have also their own test.
The steps in order to experiment with import Banana Extension are the following:
- Create a CSV file example
- Create the import Banana Extension
- Install the Banana Extension
- Run the import Banana Extension
Create the CSV file
For test purpose we create a file in CSV format using the format specified import income & expenses transactions in CSV formatg.
Copy the following CSV example, paste it on your text editor and save it as csv_example.csv:
"Date","Description","Income","Expenses" "2019-01-01","Income transaction text","100.00","" "2019-02-02","Expense transaction text","","200.00"
- First line is the fields header. Fields names are case sensitive and must correspond to the NameXml (English) of the columns in Banana Accounting.
- Fields names and data values are between double quotes.
- Fields and values are separated with a comma
- Each line is a new record
- The format for the Date fields is yyyy-mm-dd
Create the import Extension
Copy the following JavaScript code, paste it on your text editor and save it as import_transaction_example.js:
// @id = ch.banana.app.importtransactionexample // @api = 1.0 // @pubdate = 2018-10-30 // @publisher = Banana.ch SA // @description = Example Import Transactions (*.csv) // @doctype = * // @docproperties = // @task = import.transactions // @outputformat = transactions.simple // @inputdatasource = openfiledialog // @inputencoding = latin1 // @inputfilefilter = Text files (*.txt *.csv);;All files (*.*) /* CSV file example: "Date","Description","Income","Expenses" "2019-01-01","Income transaction text","100.00","" "2019-02-02","Expense transaction text","","200.00" */ // Parse the data and return the data to be imported as a tab separated file. function exec(inText) { // Convert a csv file to an array of array. // Parameters are: text to convert, values separator, delimiter for text values var csvFile = Banana.Converter.csvToArray(inText, ',', '"'); // Converts a table (array of array) to a tsv file (tabulator separated values) var tsvFile = Banana.Converter.arrayToTsv(csvFile); // Return the converted tsv file return tsvFile; }
When it is used transaction.simple as @outputformat attribute in the script, it's important that CSV file includes "Income" and "Expenses" fields.
Install the Extension
For the installation of the Banana Extension, see Install your Banana Extension.
Run the import Extension
To run an import Extension follow the steps below:
- Open an accounting file in Banana Accounting.
- In Banana select from the menu Accounts the command Import to accounting...
- From the import type selection select Transactions.
- From the list select the Example Import Transactions (*.csv) Banana Extension.
- Click on Browse and look for the csv_example.csv file, then click to Open.
- Click Ok to begin the import process.
- On the dialog window select a Destination account and click on Ok to terminate and import the data.
The data from the CSV file are imported into the Transactions table of your accounting file like the following examples.
- For a Double-Entry accounting:
You can now replace all the [CA] values with the appropriate contra-account, so that the Credit transactions will be balanced with the Debit transactions.
- For an Income & Expenses accounting:
For each transaction you can now enter an income or expense category, as defined in the Categories table.
More about Import Extensions