Account

Hugh Jeremy edited this page Aug 17, 2018 · 7 revisions

Documentation > Account

An Account is collection of related economic activity. For example, an Account might represent a bank account, income from a particular client, or entity equity. Many Accounts together compose an Entity.

Accounts themselves are composed of Transactions, and the sum of constituent transactions yield an Account Balance.

The Accounts that compose an Entity may be viewed together as part of the Tree.

Properties

.id - Number

An identifier for this account, unique within an Entity

Example: 42


.session - Session

The Session used to initialise this Account


.entity - Entity

The Entity of which this Account is a member


.name - String

A friendly name for this Account

Example: "Subscription revenue"


.type - Type

The type of the Account, one of .asset, .liability, .income, .expense or .equity

Example: Type.income


.parentAccountId - Number or null

The identifier of this Account's parent, if there is one

Example: 154


.globalUnitId - Number or null

The identifier of this Account's denominating Global Unit, or null if this Account is denominated by a Custom Unit

Example: 5


.customUnitId - Number or null

The identifier of this Account's denominating Custom Unit, or null if this Account is denominated by a Global Unit

Example: null


.counterPartyEntityId - String or null

The identifier of an Entity identified as a counter-party to this Account, if any

Example: null


.description - String

Friendly description of this Account

Example: "Sweet loot from accounting API subscriptions"


.colour - String

Hex colour value associated with this Account

Example: "#FFFFFF"

Methods

static .retrieve()

Retrieve an existing Account

Parameters

  1. session: Session
  2. entity: Entity
  3. accountId: Number - 42
  4. callback: (Error, Account)

Example

const _ = Account.retrieve(
  session,
  megaCorp,
  42,
  (error, account) => {
    console.log(account.id) // Logs 42
});

static .createWithGlobalUnit()

Create a new Account denominated in a Global Unit - One of the 36 daily priced currencies available by default in Amatino.

Parameters

  1. session: Session
  2. entity: Entity
  3. name: String
  4. type: Type
  5. parent: Number or null
  6. globalUnitId: Number
  7. counterPartyEntity: String or null
  8. description: String
  9. colour: String or null
  10. callback: (Error, Account)

Example

const _ = Account.createWithGlobalUnit(
  session,
  megaCorp,
  "Subscription income",
  Type.revenue,
  null,
  5,
  null,
  "Sweet loot from accounting software subscriptions",
  null,
  (error, account) => {
    console.log(account.name) // Logs 'Subscription income'
]);

static .createWithCustomUnit()

Create a new Account denominated in a Custom Unit. For example, you might have created a Custom Unit for Bitcoin, Apple stock, or hourly U.S. Dollar prices.

Parameters

  1. session: Session
  2. entity: Entity
  3. name: String
  4. type: Type
  5. parent: Number or null
  6. customUnitId: Number
  7. counterPartyEntity: String or null
  8. description: String
  9. colour: String or null
  10. callback: (Error, Account)

Example

const _ = Account.createWithCustomUnitDenomination(
  session,
  megaCorp,
  "Bitcoin Holdings",
  Type.asset,
  null,
  3,
  null,
  "Bitcoin account at Coinbase",
  null,
  (error, account) => {
    console.log(account.name) // Logs 'Bitcoin Holdings'
]);

.update()

Update an Account. For example, you might wish to change its name, description, or parent.

Parameters

  1. name: String
  2. type: Type
  3. parentAccountId: Number or null
  4. globalUnitId: Number or null
  5. customUnitId: Number or `null
  6. counterPartyEntityId: String or null
  7. description: String
  8. colour: String or null
  9. callback: (Error, Account)

Example

account.update(
  "New, improved account name",
  account.type,
  account.parentAccountId,
  account.globalUnitId,
  account.customUnitId,
  account.counterPartyEntityId,
  "New, improved account description",
  account.colour,
  (error, account) => {
    console.log(account.name); // logs 'New, improved account name'
  }
);

.delete()

Deletes the Account. This requires some consideration: Deleting an account does not delete Transactions party to it. As such, the deletion operation requires some additional data telling Amatino what you want to happen to those Transactions. In addition, Amatino needs to know what you would like to happen to any children of this Account.

The entryReplacementAccount is the Account to which any party Entries should be moved. If you have deleted all party Transactions, then you can specify any Account here. deleteChildren flags whether child Accounts should also be deleted. Finally, newChildParentAccount tells Amatino where surviving direct children should be re-parented. If you supply null, they will become new top-level Accounts. In both cases, the children's descendants retain their existing parent / child relationships.

Parameters

  1. entryReplacementAccount: Account
  2. deleteChildren: Boolean
  3. newChildParentAccount: Account or null
  4. callback: (Error, [Object])

The [Object] Array in parameter #4 contains objects of the form: {"account_id": 42} - Wherein each Object represents a deleted Account. For example, if you delete all children, the array will contain an object specifying the ID of each deleted child, as well as the target.

Example

// Suppose we have two Account instances, `equipment` and `fixedAssets`.
equipment.delete(
  fixedAssets,
  false,
  fixedAssets, // All `equipment` children will be re-parented by `fixedAssets`
  (error, deletedAccountIds) => {
    for (let i = 0; i < deletedAccountIds.length; i++) {
      const deletedId = deletedAccountIds[i]['account_id']
      console.log('Deleted account with ID:', deletedId)
    }
  }
)'
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.