Report Apps

Report apps are java-script programs that are used to customize printouts like invoice documents. The main function printDocument() receives the json object from Banana, writes the document and lunches the result in a print preview window.

Copies of some report apps that you can use as starting point are available at the following address: github.com/BananaAccounting

At the moment this feature is available only within Banana Accounting Experimental.

 

Important notes

  • Banana Accounting uses Qt script engine to execute report apps.
  • Mandatory functions: printDocument(jsonInvoice, repDocObj, repStyleObj) which is the main function and settingsDialog() which is called from user to set up parameters like colour or additional text.
  • Available json objects: invoice json object, statement json object, reminder json object
  • The extension of custom report apps should be .js and the script must contains the main attributes, see Apps Attributes.
  • The attribute @id of the script should correspond to the file name.
  • System report apps are downloaded to the folder /User/.../AppData/Local/Banana.ch/.../Apps
    (Mac Users: /Users/.../Library/Application Support/Banana.ch/.../Apps)
  • Do not overwrite system report apps because updates will overwrite your changes.
  • You can save your report app anywhere, Banana Accounting saves the path to your app in the configuration file /AppData/Local/Banana.ch/.../Apps/apps.cfg

 

 

Invoice

Create personalized invoice report apps

We have published our templates on github.com/BananaAccounting. In this section you will find different basic examples.

You can save a copy of one template in your computer and make the changes you wish. In order to use your custom template in Banana you have to:

  • select the command Account2 - Customers - Print invoices...
  • In the Print invoices dialog select Manage apps...
  • In the Manage apps dialog select Add from file... and choose your invoice report file you just created

At the moment this function is available only within Banana Accounting Experimental.

Apps attributes

// @id = scriptfilename.js
// @api = 1.0
// @pubdate = yyyy-mm-dd
// @publisher = yourName
// @description = script description
// @task = report.customer.invoice

Report code

The main function is printDocument(jsonInvoice, repDocObj, repStyleObj). The  parameter jsonInvoice object contains the data, repDocObj is the document object and repStyleObj is the stylesheet object where you can add styles.

function printDocument(jsonInvoice, repDocObj, repStyleObj) {
  var param = initParam();
  var savedParam = Banana.document.getScriptSettings();
  if (savedParam.length > 0) {
    param = JSON.parse(savedParam);
    param = verifyParam(param);
  }
  printInvoice(jsonInvoice, repDocObj, repStyleObj, param);
}

The function settingsDialog() is called from Banana when you select the button Params... from dialog Manage apps. You can write any code you need for your script.

/*Update script's parameters*/
function settingsDialog() {
   var param = initParam();
   var savedParam = Banana.document.getScriptSettings();
   if (savedParam.length > 0) {
      param = JSON.parse(savedParam);
   }   
   param = verifyParam(param);
   ...
   var paramToString = JSON.stringify(param);
   var value = Banana.document.setScriptSettings(paramToString);
}

Printing custom data

You can add your own parameters in order to print specific data. For instance printing a reference order number or removing payments information if the invoice has already been paid.

if (invoiceObj.parameters.orderNo) {
    cell1.addParagraph("Reference order: " + invoiceObj.parameters.orderNo);
  }

Printing images

With the command addImage it is possible to add images into the document. For instance

var reportObj = Banana.Report;
var repDocObj = reportObj.newReport();
repDocObj.addImage("documents:logo", "logoStyle");

var logoStyle = repStyleObj.addStyle(".logoStyle");
logoStyle.setAttribute("position", "absolute");
logoStyle.setAttribute("margin-top", "5mm");
logoStyle.setAttribute("margin-left", "20mm");
logoStyle.setAttribute("width", "120px");

If you set the width, the image will be resized to the given width. If the width is not specified the image will be printed with a 72dpi resolution.

Json Object

Invoice Json Object

Data structure you can access through the report:

{
    "billing_info": {
        "payment_term": "",
        "total_amount_vat_exclusive": "500.00",
        "total_amount_vat_exclusive_before_discount": "500.00",
        "total_amount_vat_inclusive": "540.00",
        "total_amount_vat_inclusive_before_discount": "540.00",
        "total_categories": [
        ],
        "total_discount_percent": "",
        "total_discount_vat_exclusive": "",
        "total_discount_vat_inclusive": "",
        "total_rounding_difference": "",
        "total_to_pay": "540.00",
        "total_vat_amount": "40.00",
        "total_vat_amount_before_discount": "40.00",
        "total_vat_codes": [
        ],
        "total_vat_rates": [
            {
                "total_amount_vat_exclusive": "500.00",
                "total_amount_vat_inclusive": "540.00",
                "total_vat_amount": "40.00",
                "vat_rate": "8.00"
            }
        ]
    },
    "customer_info": {
        "address1": "Viale Stazione 11",
        "address2": "", 
        "address3": "", 
        "balance": "102.60", 
        "balance_base_currency": "102.60", 
        "business_name": "Rossi SA",
        "city": "Bellinzona",
        "country": "Switzerland", 
        "country_code": "CH", 
        "courtesy": "Signor", 
        "currency": "CHF", 
        "date_birth": "1999-10-06", 
        "email": "info@test.com", 
        "first_name": "Andrea", 
        "lang": "it",
        "last_name": "Rossi",
        "mobile": "0033608405", 
        "number": "1100",
        "origin_row": "26",
        "origin_table": "Accounts",
        "postal_code": "6500",
        "vat_number": "1234"
    },
    "document_info": {
        "currency": "CHF",
        "date": "20160101",
        "decimals_amounts": 2,
        "description": "",
        "doc_type": "10", 
        "locale": "it",
        "number": "201710",
        "origin_row": "1",
        "origin_table": "Transactions",
        "printed": "1", 
        "rounding_total": "0.05",
        "type": "invoice"
    },
    "items": [
        {
            "account_assignment": "3000",
            "description": "Prodotto A",
            "details": "",
            "index": "0",
            "item_type": "item",
            "mesure_unit": "",
            "number": "",
            "origin_row": "1",
            "origin_table": "Transactions",
            "quantity": "1",
            "total_amount_vat_exclusive": "500.00",
            "total_amount_vat_inclusive": "540.00",
            "total_vat_amount": "40.00",
            "unit_price": {
                "amount_vat_inclusive": "540.00",
                "calculated_amount_vat_exclusive": "500.00",
                "calculated_amount_vat_inclusive": "540.00",
                "calculated_vat_amount": "40.00",
                "currency": "CHF",
                "vat_code": "V80",
                "vat_rate": "8.00"
            }
        }
    ],
    "note": [
            {
                "date": "2017-04-24",
                "description": "commande=AWO-003530",
                "origin_row": "968",
                "origin_table": "Transactions"
            }
    ],
    "parameters": {
        "ccpaid":"1",
        "orderNo":"5440004/44",
        "myKey":"MyValue"
    },
    "payment_info": {
        "date_expected": "2017-05-24", 
        "due_date": "20160131",
        "due_days": "240",
        "due_period": "0_>90",
        "last_reminder": "",
        "last_reminder_date": "",
        "payment_date": ""
    },
    "shipping_info": {
         "address1": "26, lotissement Bellevue",
         "address2": "street2",
         "address3": "street3",
         "business_name": "Company",
         "city": "Clairac",
         "country": "FR",
         "different_shipping_address": true,
         "first_name": "Carla",
         "last_name": "Francine",
         "postal_code": "47320"
    },
    "supplier_info": {
        "address1": "Indirizzo 1",
        "address2": "Indirizzo 2",
        "business_name": "Società",
        "city": "Loc",
        "courtesy": "Signor",
        "email": "info@myweb",
        "fax": "+419100000", 
        "first_name": "Nome",
        "fiscal_number": "222",
        "last_name": "Cognome",
        "phone": "+419100000", 
        "postal_code": "CAP",
        "state": "Suisse", 
        "vat_number": "1111", 
        "web": "http://www.myweb"
    }
    "transactions": [
        {
            "balance": "-219.30",
            "balance_base_currency": "",
            "currency": "CHF",
            "date": "20170430",
            "description": "Paiement CERAT DES ALPES* 50 ml - Réf. AL07010",
            "origin_row": "1006",
            "origin_table": "Transactions"
        }
    ],
    "type": "invoice",
    "version": "1.0"
}

 

 

Source Data

Invoice Json Object Source Data

This list explains where the actual information on your invoice json object is coming from

Invoice Object Property Source
customer_info.address1 Table: Accounts, View: Address, Column: Street
customer_info.address2 Table: Accounts, View: Address, Column: AddressExtra
customer_info.address3 Table: Accounts, View: Address, Column: POBox
customer_info.balance Table: Accounts, View: Address, Column: Balance
customer_info.balance_base_currency Table: Accounts, View: Address, Column: BalanceCurrency
customer_info.bank_account Table: Accounts, View: Address, Column: BankAccount
customer_info.bank_clearing Table: Accounts, View: Address, Column: BankClearing
customer_info.bank_name Table: Accounts, View: Address, Column: BankName
customer_info.business_name Table: Accounts, View: Address, Column: OrganisationName
customer_info.city Table: Accounts, View: Address, Column: Locality
customer_info.country Table: Accounts, View: Address, Column: Country
customer_info.country_code Table: Accounts, View: Address, Column: CountryCode
customer_info.courtesy Table: Accounts, View: Address, Column: NamePrefix
customer_info.credit_limit Table: Accounts, View: Address, Column: CreditLimit
customer_info.currency Table: Accounts, View: Address, Column: Currency
customer_info.date_birth Table: Accounts, View: Address, Column: DateOfBirth
customer_info.email Table: Accounts, View: Address, Column: EmailWork
customer_info.fax Table: Accounts, View: Address, Column: Fax
customer_info.first_name Table: Accounts, View: Address, Column: FirstName
customer_info.fiscal_number Table: Accounts, View: Address, Column: FiscalNumber
customer_info.iban_number Table: Accounts, View: Address, Column: BankIban
customer_info.lang Table: Accounts, View: Address, Column: Language
customer_info.last_name Table: Accounts, View: Address, Column: FamilyName
customer_info.member_fee Table: Accounts, View: Address, Column: MemberFee
customer_info.mobile Table: Accounts, View: Address, Column: PhoneMobile
customer_info.number Table: Accounts, View: Address, Column: Account
customer_info.payment_term_days Table: Accounts, View: Address, Column: PaymentTermInDays
customer_info.phone Table: Accounts, View: Address, Column: PhoneMain
customer_info.postal_code Table: Accounts, View: Address, Column: PostalCode
customer_info.state Table: Accounts, View: Address, Column: Region
customer_info.vat_number Table: Accounts, View: Address, Column: VatNumber
customer_info.web Table: Accounts, View: Address, Column: Website
document_info.currency Invoice currency which usually corresponds to the customer account currency
document_info.date Table: Transactions, Column: DateDocument or Date
document_info.decimals_amounts Decimals are the same as the decimals used in the accounting file
document_info.description Not used
document_info.doc_type Table: Transactions, Column: DocType
document_info.greetings

Table: Transactions, Column: DocType
Transactions with DocType=10:gre
If there are many rows with 10:gre the texts are joined with ','.
More info...

document_info.locale Menu: File-File and accounting properties, Other, current Language
document_info.number Table: Transactions, Column: DocInvoice
document_info.origin_row Row index of source transaction
document_info.origin_table Table name of source transaction
document_info.rounding_total

Default value for CHF: 0.05
You can overwrite this value with the menu command: Account2 - Customers - Settings - Advanced - Invoice rounding
For multicurrency accounting: you can setup the rounding value for each currency in the table ExchangeRates, column DecimalPoints

document_info.type invoice
items Table: Transactions
All rows with the same invoice number and transaction date are invoice's items (lines)
note Table: Transactions, Column: DocType
Transactions with DocType=10:not.
More info...
parameters

Table: Transactions, Column: DocType
Transactions with DocType=10:par:key
Key: any key text you wish
Value: is taken from column Description
More info...

payment_info Calculated from journal
shipping_info

Delivery address if different from the invoice address (customer_info)
Table: Transactions, Column: DocType
Transactions with DocType=10:sadr
More info...

supplier_info.address1 Menu: File-File and accounting properties, Address, Address 1
supplier_info.address2 Menu: File-File and accounting properties, Address, Address 2
supplier_info.business_name Menu: File-File and accounting properties, Address, Company
supplier_info.city Menu: File-File and accounting properties, Address, City
supplier_info.country Menu: File-File and accounting properties, Address, Country
supplier_info.courtesy Menu: File-File and accounting properties, Address, Courtesy
supplier_info.email Menu: File-File and accounting properties, Address, Email
supplier_info.fax Menu: File-File and accounting properties, Address, Fax
supplier_info.first_name Menu: File-File and accounting properties, Address, Name
supplier_info.fiscal_number Menu: File-File and accounting properties, Address, Fiscal Number
supplier_info.last_name Menu: FilevFile and accounting properties, Address, Family Name
supplier_info.mobile Menu: File-File and accounting properties, Address, Mobile
supplier_info.phone Menu: File-File and accounting properties, Address, Phone
supplier_info.postal_code Menu: File-File and accounting properties, Address, Zip
supplier_info.state Menu: File-File and accounting properties, Address, Region
supplier_info.vat_number Menu: File-File and accounting properties, Address, Vat Number
supplier_info.web Menu: File-File and accounting properties, Address, Web
transactions Table: Transactions
All rows with the same invoice number and different transaction date, which are not considered invoice items, like payments transactions

 

 

Statement

Create personalized statement report apps

We have published our templates on github.com/BananaAccounting. In this section you will find different basic examples.

You can save a copy of one template in your computer and make the changes you wish. In order to use your custom template in Banana you have to:

  • select the command Account2 - Customers - Print statements...
  • In the Print statements dialog select Manage apps...
  • In the Manage apps dialog select Add from file... and choose your statement report file you just created

At the moment this function is available only within Banana Accounting Experimental.

Apps attributes

// @id = scriptfilename.js
// @api = 1.0
// @pubdate = yyyy-mm-dd
// @publisher = yourName
// @description = script description
// @task = report.customer.statement

Report code

The main function is printDocument(jsonStatement, repDocObj, repStyleObj). The  parameter jsonStatement object contains the data, repDocObj is the document object and repStyleObj is the stylesheet object where you can add styles.

function printDocument(jsonStatement, repDocObj, repStyleObj) {
  var param = initParam();
  var savedParam = Banana.document.getScriptSettings();
  if (savedParam.length > 0) {
    param = JSON.parse(savedParam);
    param = verifyParam(param);
  }
  printInvoice(jsonInvoice, repDocObj, repStyleObj, param);
}

The function settingsDialog() is called from Banana when you select the button Params... from dialog Manage apps. You can write any code you need for your script.

/*Update script's parameters*/
function settingsDialog() {
   var param = initParam();
   var savedParam = Banana.document.getScriptSettings();
   if (savedParam.length > 0) {
      param = JSON.parse(savedParam);
   }   
   param = verifyParam(param);
   ...
   var paramToString = JSON.stringify(param);
   var value = Banana.document.scriptSaveSettings(paramToString);
}

 

 

Json Object

Statement Json Object

Data structure you can access through the report:

{
    "customer_info": {
        "address1": "Viale Stazione 11",
        "business_name": "Rossi SA",
        "city": "Bellinzona",
        "first_name": "Andrea",
        "last_name": "Rossi",
        "number": "1100",
        "origin_row": "26",
        "origin_table": "Accounts",
        "postal_code": "6500"
    },
    "document_info": {
        "date": "20160927",
        "decimals_amounts": 2,
        "description": "",
        "locale": "it",
        "number": "",
        "type": "statement"
    },
    "items": [
        {
            "balance": "540.00",
            "credit": "",
            "currency": "CHF",
            "date": "20160101",
            "debit": "540.00",
            "due_date": "20160131",
            "due_days": "240",
            "item_type": "invoice",
            "last_reminder": "",
            "last_reminder_date": "",
            "number": "10",
            "payment_date": "",
            "status": "",
            "total_amount_vat_exclusive": "",
            "total_amount_vat_inclusive": "",
            "total_vat_amount": "",
            "unit_price": {
            }
        },
        {
            "balance": "540.00",
            "credit": "",
            "currency": "",
            "date": "",
            "debit": "540.00",
            "item_type": "total",
            "number": "",
            "status": "",
            "total_amount_vat_exclusive": "",
            "total_amount_vat_inclusive": "",
            "total_vat_amount": "",
            "unit_price": {
            }
        }
    ],
    "supplier_info": {
        "address1": "Indirizzo 1",
        "address2": "Indirizzo 2",
        "business_name": "Società",
        "city": "Loc",
        "email": "info@myweb",
        "first_name": "Nome",
        "fiscal_number": "numerofiscale",
        "last_name": "Cognome",
        "postal_code": "CAP",
        "web": "http://www.myweb"
    }
}

Reminder

Create personalized reminder report apps

We have published our templates on github.com/BananaAccounting. In this section you will find different basic examples.

You can save a copy of one template in your computer and make the changes you wish. In order to use your custom template in Banana you have to:

  • select the command Account2 - Customers - Print reminders...
  • In the Print payment reminders dialog select Manage apps...
  • In the Manage apps dialog select Add from file... and choose your reminder report file you just created

At the moment this function is available only within Banana Accounting Experimental.

Apps attributes

// @id = scriptfilename.js
// @api = 1.0
// @pubdate = yyyy-mm-dd
// @publisher = yourName
// @description = script description
// @task = report.customer.reminder

Report code

The main function is printDocument(jsonReminder, repDocObj, repStyleObj). The  parameter jsonReminder object contains the data, repDocObj is the document object and repStyleObj is the stylesheet object where you can add styles.

function printDocument(jsonReminder, repDocObj, repStyleObj) {
  var param = initParam();
  var savedParam = Banana.document.getScriptSettings();
  if (savedParam.length > 0) {
    param = JSON.parse(savedParam);
    param = verifyParam(param);
  }
  printReminder(jsonReminder, repDocObj, repStyleObj, param);
}

The function settingsDialog() is called from Banana when you select the button Params... from dialog Manage apps. You can write any code you need for your script.

/*Update script's parameters*/
function settingsDialog() {
   var param = initParam();
   var savedParam = Banana.document.getScriptSettings();
   if (savedParam.length > 0) {
      param = JSON.parse(savedParam);
   }   
   param = verifyParam(param);
   ...
   var paramString = JSON.stringify(param);
   var value = Banana.document.setScriptSettings(paramString);
}

 

Json Object

Reminder Json Object

Data structure you can access through the report:

{
    "customer_info": {
        "address1": "Viale Stazione 11",
        "business_name": "Rossi SA",
        "city": "Bellinzona",
        "first_name": "Andrea",
        "last_name": "Rossi",
        "number": "1100",
        "origin_row": "26",
        "origin_table": "Accounts",
        "postal_code": "6500"
    },
    "document_info": {
        "date": "20160927",
        "decimals_amounts": 2,
        "description": "",
        "locale": "it",
        "number": "",
        "type": "reminder"
    },
    "items": [
        {
            "balance": "540.00",
            "balance_base_currency": "540.00",
            "base_currency": "CHF",
            "credit": "",
            "credit_base_currency": "",
            "currency": "CHF",
            "date": "20160101",
            "debit": "540.00",
            "debit_base_currency": "540.00",
            "item_type": "invoice",
            "number": "10",
            "status": "1. reminder",
            "total_amount_vat_exclusive": "",
            "total_amount_vat_inclusive": "",
            "total_vat_amount": "",
            "unit_price": {
            }
        },
        {
            "balance": "540.00",
            "balance_base_currency": "540.00",
            "base_currency": "",
            "credit": "",
            "credit_base_currency": "",
            "currency": "",
            "date": "",
            "debit": "540.00",
            "debit_base_currency": "540.00",
            "item_type": "total",
            "number": "",
            "status": "",
            "total_amount_vat_exclusive": "",
            "total_amount_vat_inclusive": "",
            "total_vat_amount": "",
            "unit_price": {
            }
        }
    ],
    "supplier_info": {
        "address1": "Indirizzo 1",
        "address2": "Indirizzo 2",
        "business_name": "Società",
        "city": "Loc",
        "email": "info@myweb",
        "first_name": "Nome",
        "fiscal_number": "numerofiscale",
        "last_name": "Cognome",
        "postal_code": "CAP",
        "web": "http://www.myweb"
    }
}