Script packaging

Deze documentatie is verouderd

De meest volledige en bijgewerkte documentatie is die van Banana Boekhouding Plus: Probeer het nu

In this article

It is possible to package script composed by two or more files (.js, .ui and .qml files) in one single .rcc resource file. This is very practical for distributing the script.

The .rcc resource file have to contain a main.js file. This file is executed by Banana Accounting when running the script. Relative paths are resolved from the resource root path.

To package the script Banana Accounting use the tool rcc from the Qt Resource system.

Create a .rcc package

  • Install the Qt Sdk
     
  • Create a .qrc file with the list of the files to be included
    and set alias="main.js" to the file to be executed while running the script

    Example: ch.banana.script.report.jaml.qrc
<!DOCTYPE RCC><RCC version="1.0">
 <qresource>
     <file alias="main.js">ch.banana.script.report.jaml.js</file>
     <file>lib/jaml-all.js</file>
 </qresource>
 </RCC>
  • Compile the .qrc file
rcc -binary ch.banana.script.report.jaml.qrc -o ch.banana.script.report.jaml.rcc
  • Load and test the created .rcc file in Banana Accounting

 

Example: main script to create a html report using the Jaml library

// Test script using jaml to generate html
//
// @id = ch.banana.script.report.jaml
// @version = 1.2
// @pubdate = 2014-06-10
// @publisher = Banana.ch SA
// @description = Html by jaml
// @task = app.command
// @outputformat = none
// @inputdatasource = none
// @includejs = lib/jaml-all.js
// @timeout = -1
//

function exec( string) {
    startdate = '';
    enddate = '';

    // Select an account
    accountList = getAccountsList();
    selectedAccount = Banana.Ui.getItem('Choose an account', '', accountList, -1, false);
    if (typeof selectedAccount === 'undefined')
        return;
    selectedAccount = selectedAccount.slice(0, selectedAccount.indexOf(' ')); // Extract account id

    // Get account balances
    currentBalance = Banana.document.currentBalance(selectedAccount, startdate, enddate);
    currentBalanceCurrency = Banana.document.currentBalanceCurrency(selectedAccount, startdate, enddate);
    currentBudget = Banana.document.budgetBalance(selectedAccount, startdate, enddate);
    currentBudgetCurrency = Banana.document.budgetBalanceCurrency(selectedAccount, startdate, enddate);

    // Jaml template to print a table with the account's balances
    Jaml.register('accountBalances', function(balances) {
        table(
            tr(
                td("Opening"),
                td(balances.opening)                        
            ),
            tr(
                td("Debit"),
                td(balances.debit)                        
            ),
            tr(
                td("Credit"),
                td(balances.credit)                        
            ),
            tr(
                td("Total"),
                td(balances.total)                        
            ),
            tr(
                td("Balance"),
                td(balances.balance)                        
            )
        );
    });        
    
    // Jaml template for the html page with current, current currency, budget and budget currency balancies
    Jaml.register('accountDetails', function() {
        html(
            head(
                title("Done with jaml")
            ),
            body(
                h1("Account: " + selectedAccount),
                p("Start date: " + startdate),
                p("End date: " + enddate),
                h2("Current"),
                Jaml.render('accountBalances', currentBalance),
                h2("Current currency"),
                Jaml.render('accountBalances', currentBalanceCurrency),
                h2("Budget"),
                Jaml.render('accountBalances', currentBudget),
                h2("Budget currency"),
                Jaml.render('accountBalances', currentBudgetCurrency)
            )
        );
    });        

    // Show result
    var text = Jaml.render('accountDetails');
    Banana.Ui.showText('',text);
}

/** This function return the account list as ['1000 Cash',...] */
function getAccountsList() {
    var accountList = [];
    var tableAccounts = Banana.document.table('Accounts');
    if (tableAccounts) {
        for(var i=0; i<tableAccounts.rowCount; i++) {
            var account = tableAccounts.value(i, 'Account');
            if (typeof account === 'undefined' || account === '')
                continue;
            var description = tableAccounts.value(i, 'Description');
            accountList.push(account + ' ' + description);
        }
    }
    return accountList;
}