Banana.Document

Questa documentazione è superata

La documentazione più completa e aggiornata è quella di Banana Contabilità Plus: Provalo subito

In this article

Banana.Document is the interface to a document in Banana Accounting. The current opened document can be accessed through the property Banana.document. A document can be also opened with the method Banana.application.openDocument.

Properties

cursor

Return a Cursor object with the current position of the cursor and the range of the selected rows.

Introduced in 7.0.5.0

isValid

Return false if no document is opened, otherwise true.

Deprecated since 7.0.7.0.

//To test if document is valid
if (!document)
   return;

locale

Return the locale of the document in the form of "language_country", where language is a lowercase, two-letter ISO 639 language code, and country is an uppercase, two- or three-letter ISO 3166 country code.

Introduced in 7.0.2.0

rounding

Return the rounding context of the current file that can be used with the SDecimal math functions.
Introduced in 7.0.7.0

tableNames

Return an array with the xml names of the tables in the document.

Introduced in 7.0.5.0

selecetedTable

Return the xml name of the current selected table.

Deprecated since 7.0.5.0, use instead the cursor.table property.

 

Methods

addMessage(msg)

Add the message msg to the document. The message is showed in the pane "Messages", and in a dialog if the application option "Show Messages" is turned on.

See also: Application.AddMessage, Table.AddMessage, Row.AddMessage.

clearMessages()

Clear all the document's messages showed in the pane "Messages".

Introduced in 7.0.2.0

info(section, id)

Return the info value of the document referenced by section and id. Section and Id correspond to the xml name listed in the Info table, see command File info in menu "Tools" and set the view to complete to see the XML columns. If the value referenced by section and id doesn't exist, an object of type undefined is returned.

Example:

// Get some value of the accounting file 
var FileName= Banana.document.info("Base","FileName");
var DecimalsAmounts= Banana.document.info("Base","DecimalsAmounts");
var HeaderLeft= Banana.document.info("Base","HeaderLeft");
var HeaderRight= Banana.document.info("Base","HeaderRight");
var BasicCurrency= Banana.document.info("AccountingDataBase","BasicCurrency");
// for openingDate and closureDate use instead startDate and endDate
var openingDate = Banana.document.info("AccountingDataBase","OpeningDate");
var closureDate = Banana.document.info("AccountingDataBase","ClosureDate");
// for file accounting type
var FileType = Banana.document.info("Base","FileType");
var FileGroup = Banana.document.info("Base","FileTypeGroup");
var FileNumber = Banana.document.info("Base","FileTypeNumber");

FileTypeGroup / FileTypeNumber combinations:

  • 100 Double entry accounting
    • 100 No VAT
    • 110 With VAT
    • 120 Multi Currency
    • 130 Multi Currency with VAT
  • 110 Income and Expense accounting
    • 100 No VAT
    • 110 With VAT
  • 130 Cash Book
    • 100 No VAT
    • 110 With VAT
  • 400 Address / Labels
    • 110 Labels
    • 120 Address

scriptSaveSettings(string)

Save the settings of the script in the document. The next time the script is run, it si possible to read the saved settings with "scriptReadSettings".

Settings are saved and restore under the script id, if you change the id your settings will not be retrieved.

Introduced in 7.0.4.0

Example:

// Save script settings
var paramToString = JSON.stringify(param);
var value = Banana.document.scriptSaveSettings(paramToString);

scriptReadSettings()

Return the saved settings of the script.

Settings are saved and restore under the script id, if you change the id your settings will not be retrieved.

Introduced in 7.0.4.0

Example:

// Initialise parameter
param = {
   "searchText": "",
   "matchCase": "false",
   "wholeText": "false"
};

// Readscript settings
var data = Banana.document.scriptReadSettings();
if (data.length > 0) {
   param = JSON.parse(data);
}

table(xmlTableName)

Return the table referenced by the name xmlTableName as a Table object, or undefined if it doesn't exist.

value(tableName, rowNr, columnName)

Return the value in table tableName, row rowNr and column columnName as string. If the table, row or column are not founds it return an object of type undefined.

 

Methods for accounting's files

accountsReport([startDate, endDate])

Return the account report for the specified period. Start and end date can be a string in form 'YYYY-MM-DD' or a date object.

Introduced in 7.0.2.0

budgetBalance(account [, startDate, endDate, function(rowObj, rowNr, table)])

Sum the amounts fo opening, debit, credit, total and balance for all budget transactions for this accounts .

See for more detail the function currentBalance.

Introduced in 7.0.7.0

budgetCard(account [, startDate, endDate, function(rowObj, rowNr, table)])

Return for the given account and period a Table object with the budget account card.

For more ditails see currentCars.

Introduced in 7.0.5.0

currentBalance(account [, startDate, endDate, function(rowObj, rowNr, table) ])

Sum the amounts fo opening, debit, credit, total and balance for all transactions for this accounts.

Example: 

var currentBal = Banana.document.currentBalance('1000','','');
var openingBalance = currentBal.opening;
var endBalance = currentBal.balance;

Return value:

  • Is an object that has
    • opening the amount at the begining of the period (all transactions before)
    • debit the amount of debit transactions for the period
    • credit the amount of credit transactions for the period
    • total the difference between debit-credit for the period
    • balance opening + debit-credit for the period
    • openingCurrency the amount at the begining of the period in the account currency
    • debitCurrency the amount of debit transactions for the period in the account currency
    • creditCurrency the amount of credit transactions for the period in the account currency
    • totalCurrency the difference between debit-credit for the period in the account currency
    • balanceCurrency opening + debit-credit for the period in the account currency
    • count the number of lines that have bben found and used for this computation

Account:

  • can be an account id, a cost center or a segment.
  • can be a cobination of account and segments, separeted by the semicolon ":"
    In this case it returns all the transactions that have the indicated account and segments
    • 1000:A1:B1
  • can be differents accounts and multiple segments separated by the "|"
    In this case it incluse all transactions that have the one of the specified accounts and one of the specified segments
    • 1000|1001
    • 1000|1001:A1:B1
    • 1000|1001:A1|A2:B1
  • can be a wildCardMatching
    Wildcards can be used for accounts, segments, Groups or BClass and in combination
    • ?  Matches any single character.
    • *  Matches zero or more of any characters
    • [...] Set of charachtes
    • "100?" match "1001, 1002, 1003, 100A, ...)
    • "100*" Matches all accounts starting with 100
    • "100*|200*:A?" Matches all accounts starting with 100 or 200 and with segments with A and of two charachters.
    • "[1234]000" Matches "1000 2000 3000 4000"
  • can be
    • BClass=1
    • BClass=1|2
    • Gr=100
    • Gr=100|101|102
      In this case it returns all transactions that have an account belonging to this group (even cascade)
  • Contra Account
    • After the "&" you can insert a contra account 
    • 1000&2000 return all transctions of the account 1000 that have a contra account 2000.
    • As per accounts you can specify multiple contra accounts, BClass=, Gr= with also wildcards.

Start date:

  • is a string in form 'YYYY-MM-DD' or a date object.
  • If startDate is empty the accounting start date is taken.

End date:

  • is a string in form 'YYYY-MM-DD' or a date object.
  • If endDate is empty the accounting end date is taken.

function(rowObj, rowNr, table)

This fuction will be called for each row of the selected account.
The function should return true if you want this row to be included in the calculation.

function exec( string) {
    // We retrive the total sales (account 4000) only for the cost center P1
    var balanceData = Banana.document.currentBalance('4000','', '', onlyCostCenter);
    // sales is a revenue so is negative and we invert the value
    var salesCC1 = -balanceData.total;
    // display the information
    Banana.Ui.showText("Sales of Project P1: " + salesCC1);
}

// this function return true only if the row has the cost center code  "P1"
function onlyCostCenter( row, rowNr, table){
   if(row.value('JCC1') === 'P1') {
      return true;
   }
   return false;
}

Introduced in 7.0.7

currentCard(account [, startDate, endDate, function(rowObj, rowNr, table)])

Return for the given account and period a Table object with the the transactions for this account.

Row are sorted by JCTransactionDate

parameters:

  • account can be any accounts, cost center or segment as specifiend in currentBalance.
  • startDate any date or symbol as specifiend in currentBalance.
  • endDate any date or symbol as specifiend in currentBalance.

Return columns to use:

  • JCTransactionDate the date of the transction
  • JCAccount the account for this line
  • JCDebit amount debit
  • JCCredit the amount credit
  • JCBalance the Balance
  • JCBalanceCurrency the Balance in Account Currency
    If accounts in different currency are selected the amount is 0

Introduced in 7.0.5.0

 

projectionBalance(account, projectionStartDate [, startDate, endDate, function(rowObj, rowNr, table) ])

Same as currentBalance but use the budget data starting from the projectionStartDate.

This functions calculate a projection of the end of year result (or specified period) combining the current data and the budget data for the period non yet booked.

if projectionStartDate is empty the result will be the same as currentBalance.

If you have already booked the 1. semester and would like to have a projection up to the end of the year

// We have booked the 1. semester and would like to have
// a projection up to the end of the yer
var cashProjection = Banana.document.projectionBalance('1000','2015-07-01');
var cashEnd = projection.balance;
var salesProjection = Banana.document.projectionBalance('3000','2015-07-01').total;
var salesForYear = -salesProjection.total;

Introduced in 7.0.7

projectionCard(account, projectionStartDate [, startDate, endDate, function(rowObj, rowNr, table) ])

Same as currentCard but use the budget data starting from the projectionStartDate.

If projectionStart date is empty result will be the same s currentCard.

Introduced in 7.0.7

endPeriod([period])

Return the end date in the form of 'YYYY-MM-DD'.

The endDate and startDate functions are used to retrieve the date of the accounting, so that you can create scripts that works on file of different years.

var dateEnd = Banana.document.endPeriod();
var dateStartFebruary = Banana.document.endPeriod('2M');

 

Period:

  • If period is not present the return value is the end date of the accounting.
  • The period is added the starting account date, and than is returned the last date of the period..
  • Period (for example 2M = 2 months) is a number followed by one of the following charachters
    • D for days
    • M for months
    • Q for quarters
    • S for semesters
    • Y for years
  • Assuming that the Start accounting date is 2015-01-01
    • 1M return 2015-01-02
    • 2M return 2015-02-28
    • 2Q return 2015-06-30
    • 2S return 2015-12-31
    • 2Y return 2016-12-31

See also startDate.

Introduced in 7.0.5.0

startPeriod ([period])

Return the end date in the form of 'YYYY-MM-DD'.

The endPeriod and startPeriod functions are used to retrieve the date of the accounting, so that you can create scripts that works on file of different years.

var dateStart = Banana.document.endPeriod();
var dateStart3Q = Banana.document.endPeriod('3Q');

 

Period:

  • If period is not present return the start date.
  • Period (for example 2M = 2 months) is a number followed by one of the following charachters
    • D is for Days
    • M for Months
    • Q for Quorters
    • S for Semester
    • Y for year
  • With 1 the starting date of the accounting is returned.
  • Assuming that the Start accounting date is 2015-01-01
    • 1M return 2015-01-01
    • 2M return 2015-02-01
    • 2Q return 2015-04-01 
    • 2S return 2015-07-01
    • 2Y return 2016-01-01

See also endDate.

Introduced in 7.0.5.0

vatBudgetBalance(vatCode[, startDate, endDate, function(rowObj, rowNr, table) ])

Sum the vat amounts for the specified vat code and period, using the Budget data.

Introduced in 7.0.7

vatCurrentCard(vatCode[, startDate, endDate, function(rowObj, rowNr, table) ])

Retrieve the transactions relative to the specified VatCode see .

Introduced in 7.0.7

vatCurrentBalance(vatCode[, startDate, endDate, function(rowObj, rowNr, table) ])

Sum the vat amounts for the specified vat code and period.

For more info see the description of the function currentBalance.

Example: 

var currentVat = Banana.document.currentBalance('V15','','');
var vatTaxable = currentVat .vatTaxable;
var vatPosted = currentVat .vatPosted;

Return value:

  • Is an object that has
    • vatTaxable the amount of the taxable column
      (the sign is the same as the vatAmount)
    • vatAmount the amount of vat
    • vatNotDeductible the amount not deductible
    • vatPosted VatAmount - VatNotDeductible
    • count the number of lines that have bben found and used for this computation

VatCode:

One or more VatCode defined in the tabel Vat Codes.
Multiple vat code can be separated by "|" for example "V10|V20", or you can use vildcard "V*".
 

Introduced in 7.0.7

vatProjectionBalance(vatCode, projectionStartDate, [, startDate, endDate, function(rowObj, rowNr, table) ])

Same as vatCurrenBalance but use the budget data starting from the projectionStartDate.

Introduced in 7.0.8

vatProjectiontCard(vatCode, projectionStartDate, [, startDate, endDate, function(rowObj, rowNr, table) ])

Same as vatCurrentCard but use the budget data starting from the projectionStartDate.

Introduced in 7.0.8

vatReport([startDate, endDate])

Return the vat report for the specified period.

Start and end date are strings in form 'YYYY-MM-DD' or a date object. If startDate is empty the accounting start date is taken. If endDate is empty the accounting end date is taken.

Introduced in 7.0.2.0