In this article
JavaScript extensions can work with several types of Banana Accounting documents: accounting files, such as double-entry accounting or the cash book, and other applications, such as Estimates and invoices or Inventory.
The document type determines:
- The data structure of the file: which tables and columns it contains.
- The API methods that an extension can use with
Banana.document. - The files for which an extension is shown in the Extensions menu, through the
@doctypeattribute.
Document types and codes
Each document type is identified by a group code and a type code, written as group.type. For example, 100.110 is double-entry accounting with VAT. The * sign stands for all types of a group: 100.* includes all double-entry accounting files.
| Document type | Code |
|---|---|
| Double-entry accounting | 100.* |
| Income and expense accounting | 110.* |
| Cash book | 130.* |
| Simple table | 400.100 |
| Addresses and labels | 400.120 |
| Library and collections | 400.140 |
| Fixed assets register | 400.150 |
| Estimates and invoices | 400.400 |
| Inventory | 400.500 |
| Timesheet | 400.600 |
Accounting variants
In accounting files, the type code indicates whether the file manages VAT and foreign currencies.
| Code | Accounting | VAT | Foreign currencies |
|---|---|---|---|
100.100 | Double-entry | No | No |
100.110 | Double-entry | Yes | No |
100.120 | Double-entry (multi-currency) | No | Yes |
100.130 | Double-entry (multi-currency) | Yes | Yes |
110.100 | Income and expense | No | No |
110.110 | Income and expense | Yes | No |
130.100 | Cash book | No | No |
130.110 | Cash book | Yes | No |
Declaring the document types of an extension
The @doctype attribute declares the document types an extension is written for. The extension's commands appear in the Extensions menu only when the open file matches. See Extension attributes.
| Value | Meaning |
|---|---|
nodocument | No open file is required. |
* | Any document type. |
100.* | All types of a group, here all double-entry accounting files. |
100.110 | One specific type, here double-entry accounting with VAT. |
100.*;110.*;130.* | Several values separated by ;, here all accounting files. |
!130.* | Excludes a type, here any file except cash books. |
@doctype only controls where the extension is available. It does not add methods to Banana.document.
Reading the document type in an extension
An extension can read the type of the open file with Banana.document.info(), using the FileTypeGroup and FileTypeNumber values of the Base section. This is useful when an extension supports several document types and must adapt its behaviour.
// @doctype = 100.*;110.*;130.*
function exec() {
if (!Banana.document) {
return;
}
var fileTypeGroup = Banana.document.info("Base", "FileTypeGroup"); // e.g. "100"
var fileTypeNumber = Banana.document.info("Base", "FileTypeNumber"); // e.g. "110"
Banana.console.log("Document type: " + fileTypeGroup + "." + fileTypeNumber);
}
All file information values are listed in the menu Tools > File info. See File info.
Available APIs
All document types share the methods of Banana.Document (Base), used to read file information, tables, rows and values, and to modify data with a DocumentChange.
Some document types add specific methods:
- Accounting files (
100.*,110.*,130.*): Banana.Document (Accounting), for examplecurrentBalance()orvatCurrentBalance(). Some methods also require VAT, foreign currencies or budget data. - Estimates and invoices (
400.400): Banana.Document (Invoice & Estimate), withcalculateInvoice()andprintInvoice().
For the complete list of methods by document type and their requirements, see API availability by document type.