Example Extension for Journal reporting

Documentación •
En este artículo

In the following we will explain what need to be considered when creating a new BananaApps for a journal reporting.

  • Retrieving the transactions data.
  • Creating specific reports using the functionalities offered by the Banana API.

Documentation

Example files

Transactions table

The following table is an example of transactions:

We see above different types of transactions. The transactions can be on a single line or over multiple lines, with or without VAT.

The idea here is to print a journal’s table that contains all the accounts and the transactions. The final result it’s the following one:

Javascript API equivalent

To retrieve a Table object with all the amount registered on the accounts, we use the Journal’s API:

var journal = Banana.document.journal(Banana.document.originType, Banana.document.accountType);

where

originType specifies the row to be filtered for. Can be one of:

  • ORIGINTYPE_NONE no filter is applyied and all rows are returned (current and budget)
  • ORIGINTYPE_CURRENT only the normal transactions are returned
  • ORIGINTYPE_BUDGET only the budget transactions are returned

accountType specifies the row to be filtered for. Can be one of:

  • ACCOUNTTYPE_NONE no filter is applied and all rows are returned.
  • ACCOUNTTYPE_NORMAL only rows for normal accounts are returned
  • ACCOUNTTYPE_CC1 only rows for Cost Center 1 are returned
  • ACCOUNTTYPE_CC2 only rows for Cost Center 2 are returned
  • ACCOUNTTYPE_CC3 only rows for Cost Center 1 are returned
  • ACCOUNTTYPE_CC Cost Center rows are returned same as using (ACCOUNTTYPE_CC1 | ACCOUNTTYPE_CC2 | ACCOUNTTYPE_CC3)

The returned table has all the columns of the transaction's table plus many other (please, visit the Journal's API for more information).

Code example

A common use to create and use a journal table to retrieve transactions data would be:

// Copyright [2024] [Banana.ch SA - Lugano Switzerland]
// @id = ch.banana.addon.journalreport.js
// @api = 1.0
// @pubdate = 2016-06-01
// @publisher = Banana.ch SA
// @description = Journal Report Example
// @task = app.command
// @doctype = 100.*;110.*;130.*
// @docproperties = 
// @outputformat = none
// @inputdataform = none
// @timeout = -1



function exec() {

	//Create the report
	var report = Banana.Report.newReport('Report title');

	//Create a journal table
	var journal = Banana.document.journal(Banana.document.ORIGINTYPE_CURRENT, Banana.document.ACCOUNTTYPE_NORMAL);

	//Print the table header
	var table = report.addTable("table");
	tableRow = table.addRow();
	tableRow.addCell("JContraAccountGroup", "bold", 1);
	tableRow.addCell("JRowOrigin", "bold", 1);
	tableRow.addCell("JDate", "bold", 1);
	tableRow.addCell("JAccount", "bold", 1);
	tableRow.addCell("JContraAccount", "bold", 1);
	tableRow.addCell("JDescription", "bold", 1);
	tableRow.addCell("JAccountDescription", "bold", 1);
	tableRow.addCell("JAmount", "bold", 1);

	//Read the table row by row and save some values
	for (var i = 0; i < journal.rowCount; i++) {
		
		var tRow = journal.row(i);

		//From the journal table we want only the transactions rows
		if (tRow.value('JOperationType') == Banana.document.OPERATIONTYPE_TRANSACTION) {

			var jContraAccountGroup = tRow.value('JContraAccountGroup');
			var jRowOrigin = tRow.value('JRowOrigin');
			var jDate = tRow.value('JDate');
			var jAccount = tRow.value('JAccount');
			var jContraAccount = tRow.value('JContraAccount');
			var jDescription = tRow.value('JDescription');
			var jAccountDescription = tRow.value('JAccountDescription');
			var jAmount = tRow.value('JAmount');
	
			tableRow = table.addRow();
			tableRow.addCell(jContraAccountGroup, "", 1);
			tableRow.addCell(jRowOrigin, "", 1);
			tableRow.addCell(jDate, "", 1);
			tableRow.addCell(jAccount, "", 1);
			tableRow.addCell(jContraAccount, "", 1);
			tableRow.addCell(jDescription, "", 1);
			tableRow.addCell(jAccountDescription, "", 1);
			tableRow.addCell(jAmount, "right", 1);
		}
	}

	//We apply some style and print the report
	var stylesheet = Banana.Report.newStyleSheet();
	
	var pageStyle = stylesheet.addStyle("@page");
    pageStyle.setAttribute("margin", "15mm 5mm 10mm 5mm");

    stylesheet.addStyle("body", "font-size: 7pt; font-family: Helvetica");
    stylesheet.addStyle(".bold", "font-weight:bold");
    stylesheet.addStyle(".right", "text-align:right");
    stylesheet.addStyle(".backgroundColor", "background-color:#464e7e");

    style = stylesheet.addStyle(".table");
	style.setAttribute("width", "100%");
	stylesheet.addStyle("table.table td", "border: thin solid black");

	Banana.Report.preview(report, stylesheet);
}

Results of the Journal’s table for each transaction

The journal’s table above is useful to better understand exactly how the journal works.

In general:

  • For each account used in the transaction table (AccountDebit, AccountCredit, CC1, CC2, CC3) the program generates a journal row with the JAccount column set with the specific account.
  • For a double entry account transaction that use AccountDebit, AccountCredit, AccountVat, CC1, CC2, CC3 the Journal will contain six rows. If the transaction has only AccountDebit and AccountCredit, then two rows will be generated.

All transactions in specific:

  • Doc 001 – Single line transaction without VAT


    Journal:


    One line for the 2020 JAccount
    One line for the 1010 JAccount

 

  • Doc 005 – Single line transaction with VAT


    Journal:


    One line for the 3260 JAccount
    One line for the 1000 JAccount
    One line for the 2020 JAccount

 

  • Doc 006 – Single line transaction with negative VAT


    Journal:


    One line for the 1000 JAccount
    One line for the 4100 JAccount
    One line for the 2020 JAccount. The VAT amount is in negative for the fact that the VAT amount is registered in credit, and therefore the amount must be pay to the tax authority

 

  • Doc 011 – Multiple lines transaction with VAT


    Journal:


    One line for the 1010 JAccount
    One line for the 3270 JAccount
    One line for the 2020 JAccount
    One line for the 3200 JAccount

 

 

Help us improve the documentation

We welcome feedback on how to improve this page.

Tell us what theme needs a better explanation or how to clarify a topic.

Share this article: Twitter | Facebook | LinkedIn | Email