# Account

This class defines an [Account](https://en.wikipedia.org/wiki/Account_(bookkeeping)) of a [[Book]].

It maintains a balance of all amount [credited and debited](http://en.wikipedia.org/wiki/Debits_and_credits) in it by [[Transactions]].

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

## Remarks

`Account` has no `getBalance()` method. To retrieve account balances, use
[Book.getBalancesReport](https://bkper.com/docs/api/bkper-js/classes/book.md#getbalancesreport) and read the resulting [BalancesContainer](https://bkper.com/docs/api/bkper-js/interfaces/balancescontainer.md).

## Extends

- `ResourceProperty`\<`bkper.Account`\>

### Constructor

```ts
new Account(book, payload?): Account;
```

#### Parameters

| Parameter | Type |
| :------ | :------ |
| `book` | [`Book`](https://bkper.com/docs/api/bkper-js/classes/book.md) |
| `payload?` | `Account` |

#### Returns

`Account`

#### Overrides

```ts
ResourceProperty<bkper.Account>.constructor
```

### payload

```ts
payload: Account;
```

The underlying payload data for this resource

#### Inherited from

```ts
ResourceProperty.payload
```

### addGroup()

```ts
addGroup(group): Account;
```

Adds a group to the Account.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `group` | `Group` \| [`Group`](https://bkper.com/docs/api/bkper-js/classes/group.md) | The group to add |

#### Returns

`Account`

This Account, for chaining

***

### create()

```ts
create(): Promise;
```

Performs create new Account.

#### Returns

`Promise`\<`Account`\>

Promise with this Account after creation

***

### deleteProperty()

```ts
deleteProperty(key): this;
```

Deletes a custom property.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `key` | `string` | The property key |

#### Returns

`this`

This resource, for chaining

#### Inherited from

```ts
ResourceProperty.deleteProperty
```

***

### getGroups()

```ts
getGroups(): Promise;
```

Gets the [[Groups]] of this Account.

When groups are already embedded in the account payload (e.g. from
[Bkper.getBook](https://bkper.com/docs/api/bkper-js/classes/bkper.md#getbook) with includeGroups), resolves them from the
book's cache instead of making API calls.

#### Returns

`Promise`\<[`Group`](https://bkper.com/docs/api/bkper-js/classes/group.md)[]\>

Promise with the [[Groups]] of this Account

***

### getId()

```ts
getId(): string | undefined;
```

Gets the Account internal id.

#### Returns

`string` \| `undefined`

The Account internal id

***

### getName()

```ts
getName(): string | undefined;
```

Gets the Account name.

#### Returns

`string` \| `undefined`

The Account name

***

### getNormalizedName()

```ts
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()

```ts
getProperties(): object;
```

Gets the custom properties stored in this resource.

#### Returns

`object`

Object with key/value pair properties

#### Inherited from

```ts
ResourceProperty.getProperties
```

***

### getProperty()

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

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

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| ...`keys` | `string`[] | The property keys to search for |

#### Returns

`string` \| `undefined`

The property value or undefined if not found

#### Inherited from

```ts
ResourceProperty.getProperty
```

***

### getPropertyKeys()

```ts
getPropertyKeys(): string[];
```

Gets the custom properties keys stored in this resource.

#### Returns

`string`[]

Array of property keys sorted alphabetically

#### Inherited from

```ts
ResourceProperty.getPropertyKeys
```

***

### getType()

```ts
getType(): AccountType;
```

Gets the type of this Account.

#### Returns

[`AccountType`](https://bkper.com/docs/api/bkper-js/enumerations/accounttype.md)

The [[AccountType]] of this Account

***

### getVisibleProperties()

```ts
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

```ts
ResourceProperty.getVisibleProperties
```

***

### hasTransactionPosted()

```ts
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()

```ts
isArchived(): boolean | undefined;
```

Tells if this Account is archived.

#### Returns

`boolean` \| `undefined`

True if the Account is archived

***

### isBalanceVerified()

```ts
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()

```ts
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()

```ts
isInGroup(group): Promise<boolean>;
```

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

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `group` | `string` \| [`Group`](https://bkper.com/docs/api/bkper-js/classes/group.md) | The Group name, id or object |

#### Returns

`Promise`\<`boolean`\>

Promise with true if the Account is in the group

***

### isPermanent()

```ts
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](http://en.wikipedia.org/wiki/Account_(Accountancy)#Based_on_periodicity_of_flow)

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()

```ts
json(): Account;
```

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

#### Returns

`Account`

An immutable copy of the json payload

#### Inherited from

```ts
ResourceProperty.json
```

***

### remove()

```ts
remove(): Promise;
```

Performs delete Account.

#### Returns

`Promise`\<`Account`\>

Promise with this Account after deletion

***

### removeGroup()

```ts
removeGroup(group): Promise;
```

Removes a group from the Account.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `group` | `string` \| [`Group`](https://bkper.com/docs/api/bkper-js/classes/group.md) | The group name, id or object to remove |

#### Returns

`Promise`\<`Account`\>

Promise with this Account, for chaining

***

### setArchived()

```ts
setArchived(archived): Account;
```

Sets Account archived/unarchived.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `archived` | `boolean` | True to archive, false to unarchive |

#### Returns

`Account`

This Account, for chaining

***

### setGroups()

```ts
setGroups(groups): Account;
```

Sets the groups of the Account.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `groups` | [`Group`](https://bkper.com/docs/api/bkper-js/classes/group.md)[] \| `Group`[] | The groups to set |

#### Returns

`Account`

This Account, for chaining

***

### setName()

```ts
setName(name): Account;
```

Sets the name of the Account.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The name to set |

#### Returns

`Account`

This Account, for chaining

***

### setProperties()

```ts
setProperties(properties): this;
```

Sets the custom properties of this resource.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `properties` | \{ \[`key`: `string`\]: `string`; \} | Object with key/value pair properties |

#### Returns

`this`

This resource, for chaining

#### Inherited from

```ts
ResourceProperty.setProperties
```

***

### setProperty()

```ts
setProperty(key, value): this;
```

Sets a custom property in this resource.

Property keys are normalized and validated by the API when saved. Keep keys
to 30 characters or fewer after normalization. Use a trailing underscore
(`_`) for hidden/internal properties.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `key` | `string` | The property key |
| `value` | `string` \| `null` \| `undefined` | The property value, or null/undefined to clean it |

#### Returns

`this`

This resource, for chaining

#### Inherited from

```ts
ResourceProperty.setProperty
```

***

### setType()

```ts
setType(type): Account;
```

Sets the type of the Account.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `type` | [`AccountType`](https://bkper.com/docs/api/bkper-js/enumerations/accounttype.md) | The [[AccountType]] to set |

#### Returns

`Account`

This Account, for chaining

***

### setVisibleProperties()

```ts
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

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `properties` | \{ \[`key`: `string`\]: `string`; \} | Object with key/value pair properties |

#### Returns

`this`

This resource, for chaining

#### Inherited from

```ts
ResourceProperty.setVisibleProperties
```

***

### setVisibleProperty()

```ts
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

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `key` | `string` | The property key |
| `value` | `string` \| `null` \| `undefined` | The property value, or null/undefined to clean it |

#### Returns

`this`

This resource, for chaining

#### Inherited from

```ts
ResourceProperty.setVisibleProperty
```

***

### update()

```ts
update(): Promise;
```

Performs update Account, applying pending changes.

#### Returns

`Promise`\<`Account`\>

Promise with this Account after update
