Documents and document types

Documentation •
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 @doctype attribute.

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 typeCode
Double-entry accounting100.*
Income and expense accounting110.*
Cash book130.*
Simple table400.100
Addresses and labels400.120
Library and collections400.140
Fixed assets register400.150
Estimates and invoices400.400
Inventory400.500
Timesheet400.600

Accounting variants

In accounting files, the type code indicates whether the file manages VAT and foreign currencies.

CodeAccountingVATForeign currencies
100.100Double-entryNoNo
100.110Double-entryYesNo
100.120Double-entry (multi-currency)NoYes
100.130Double-entry (multi-currency)YesYes
110.100Income and expenseNoNo
110.110Income and expenseYesNo
130.100Cash bookNoNo
130.110Cash bookYesNo

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.

ValueMeaning
nodocumentNo open file is required.
*Any document type.
100.*All types of a group, here all double-entry accounting files.
100.110One 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:

For the complete list of methods by document type and their requirements, see API availability by document type.

How can we help you better?

Let us know what topic we should expand or add to make this page more useful.

Send us your feedback

Share this article: Twitter | Facebook | LinkedIn | Email