Skip to content

Account

This class defines an Account of a [[Book]].

It maintains a balance of all amount credited and debited in it by [[Transactions]].

An Account can be grouped by [[Groups]].

Remarks

Account has no getBalance() method. To retrieve account balances, use Book.getBalancesReport and read the resulting BalancesContainer.

Extends

  • ResourceProperty<bkper.Account>

Constructors

Constructor

new Account(book, payload?): Account;

Parameters

ParameterType
bookBook
payload?Account

Returns

Account

Overrides

ResourceProperty<bkper.Account>.constructor

Properties

payload

payload: Account;

The underlying payload data for this resource

Inherited from

ResourceProperty.payload

Methods

addGroup()

addGroup(group): Account;

Adds a group to the Account.

Parameters

ParameterTypeDescription
groupGroup | GroupThe group to add

Returns

Account

This Account, for chaining


create()

create(): Promise<Account>;

Performs create new Account.

Returns

Promise<Account>

Promise with this Account after creation


deleteProperty()

deleteProperty(key): this;

Deletes a custom property.

Parameters

ParameterTypeDescription
keystringThe property key

Returns

this

This resource, for chaining

Inherited from

ResourceProperty.deleteProperty

getGroups()

getGroups(): Promise<Group[]>;

Gets the [[Groups]] of this Account.

When groups are already embedded in the account payload (e.g. from Bkper.getBook with includeGroups), resolves them from the book’s cache instead of making API calls.

Returns

Promise<Group[]>

Promise with the [[Groups]] of this Account


getId()

getId(): string | undefined;

Gets the Account internal id.

Returns

string | undefined

The Account internal id


getName()

getName(): string | undefined;

Gets the Account name.

Returns

string | undefined

The Account name


getNormalizedName()

getNormalizedName(): string;

Gets the normalized name of this Account without spaces or special characters.

Returns

string

The name of this Account without spaces or special characters


getProperties()

getProperties(): object;

Gets the custom properties stored in this resource.

Returns

object

Object with key/value pair properties

Inherited from

ResourceProperty.getProperties

getProperty()

getProperty(...keys): string | undefined;

Gets the property value for given keys. First property found will be retrieved.

Parameters

ParameterTypeDescription
keysstring[]The property keys to search for

Returns

string | undefined

The property value or undefined if not found

Inherited from

ResourceProperty.getProperty

getPropertyKeys()

getPropertyKeys(): string[];

Gets the custom properties keys stored in this resource.

Returns

string[]

Array of property keys sorted alphabetically

Inherited from

ResourceProperty.getPropertyKeys

getType()

getType(): AccountType;

Gets the type of this Account.

Returns

AccountType

The [[AccountType]] of this Account


getVisibleProperties()

getVisibleProperties(): object;

Gets the visible custom properties stored in this resource. Hidden properties (those ending with ”_”) are excluded from the result.

Returns

object

Object with key/value pair properties, excluding hidden properties

Inherited from

ResourceProperty.getVisibleProperties

hasTransactionPosted()

hasTransactionPosted(): boolean | undefined;

Tells if the Account has any transaction already posted.

Accounts with transaction posted, even with zero balance, can only be archived.

Returns

boolean | undefined

True if the Account has transactions posted


isArchived()

isArchived(): boolean | undefined;

Tells if this Account is archived.

Returns

boolean | undefined

True if the Account is archived


isBalanceVerified()

isBalanceVerified(): boolean | undefined;

Tells if the balance of this Account has been verified/audited.

Returns

boolean | undefined

True if the balance of this Account has been verified/audited


isCredit()

isCredit(): boolean | undefined;

Tells if the Account has a Credit nature or Debit otherwise.

Credit Accounts are just for representation purposes. It increase or decrease the absolute balance. It doesn’t affect the overall balance or the behavior of the system.

The absolute balance of credit Accounts increase when it participate as a credit/origin in a transaction. Its usually for Accounts that increase the balance of the assets, like revenue Accounts.

Crediting a credit
Thus ---------------------> Account increases its absolute balance
Debiting a debit
Debiting a credit
Thus ---------------------> Account decreases its absolute balance
Crediting a debit

As a rule of thumb, and for simple understanding, almost all Accounts are Debit nature (NOT credit), except the ones that “offers” amount for the books, like revenue Accounts.

Returns

boolean | undefined

True if the Account has credit nature


isInGroup()

isInGroup(group): Promise<boolean>;

Tells if this Account is in the [[Group]].

Parameters

ParameterTypeDescription
groupstring | GroupThe Group name, id or object

Returns

Promise<boolean>

Promise with true if the Account is in the group


isPermanent()

isPermanent(): boolean | undefined;

Tells if the Account is permanent.

Permanent Accounts are the ones which final balance is relevant and keep its balances over time.

They are also called Real Accounts

Usually represents assets or tangibles, capable of being perceived by the senses or the mind, like bank Accounts, money, debts and so on.

Returns

boolean | undefined

True if its a permanent Account


json()

json(): Account;

Gets an immutable copy of the JSON payload for this resource.

Returns

Account

An immutable copy of the json payload

Inherited from

ResourceProperty.json

remove()

remove(): Promise<Account>;

Performs delete Account.

Returns

Promise<Account>

Promise with this Account after deletion


removeGroup()

removeGroup(group): Promise<Account>;

Removes a group from the Account.

Parameters

ParameterTypeDescription
groupstring | GroupThe group name, id or object to remove

Returns

Promise<Account>

Promise with this Account, for chaining


setArchived()

setArchived(archived): Account;

Sets Account archived/unarchived.

Parameters

ParameterTypeDescription
archivedbooleanTrue to archive, false to unarchive

Returns

Account

This Account, for chaining


setGroups()

setGroups(groups): Account;

Sets the groups of the Account.

Parameters

ParameterTypeDescription
groupsGroup[] | Group[]The groups to set

Returns

Account

This Account, for chaining


setName()

setName(name): Account;

Sets the name of the Account.

Parameters

ParameterTypeDescription
namestringThe name to set

Returns

Account

This Account, for chaining


setProperties()

setProperties(properties): this;

Sets the custom properties of this resource.

Parameters

ParameterTypeDescription
properties{ [key: string]: string; }Object with key/value pair properties

Returns

this

This resource, for chaining

Inherited from

ResourceProperty.setProperties

setProperty()

setProperty(key, value): this;

Sets a custom property in this resource.

Parameters

ParameterTypeDescription
keystringThe property key
valuestring | null | undefinedThe property value, or null/undefined to clean it

Returns

this

This resource, for chaining

Inherited from

ResourceProperty.setProperty

setType()

setType(type): Account;

Sets the type of the Account.

Parameters

ParameterTypeDescription
typeAccountTypeThe [[AccountType]] to set

Returns

Account

This Account, for chaining


setVisibleProperties()

setVisibleProperties(properties): this;

Sets the custom properties of this resource, filtering out hidden properties. Hidden properties are those whose keys end with an underscore ”_”.

Parameters

ParameterTypeDescription
properties{ [key: string]: string; }Object with key/value pair properties

Returns

this

This resource, for chaining

Inherited from

ResourceProperty.setVisibleProperties

setVisibleProperty()

setVisibleProperty(key, value): this;

Sets a custom property in this resource, filtering out hidden properties. Hidden properties are those whose keys end with an underscore ”_”.

Parameters

ParameterTypeDescription
keystringThe property key
valuestring | null | undefinedThe property value, or null/undefined to clean it

Returns

this

This resource, for chaining

Inherited from

ResourceProperty.setVisibleProperty

update()

update(): Promise<Account>;

Performs update Account, applying pending changes.

Returns

Promise<Account>

Promise with this Account after update