# Transaction

This class defines a Transaction between [credit and debit](http://en.wikipedia.org/wiki/Debits_and_credits) [[Accounts]].

A Transaction is the main entity on the [Double Entry](http://en.wikipedia.org/wiki/Double-entry_bookkeeping_system) [Bookkeeping](http://en.wikipedia.org/wiki/Bookkeeping) system.

## Extends

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

### Constructor

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

#### Parameters

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

#### Returns

`Transaction`

#### Overrides

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

### payload

```ts
payload: Transaction;
```

The underlying payload data for this resource

#### Inherited from

```ts
ResourceProperty.payload
```

### addFile()

```ts
addFile(file): Transaction;
```

Adds a file attachment to the Transaction.

Files not previously created in the Book will be automatically created when the transaction is persisted.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `file` | [`File`](https://bkper.com/docs/api/bkper-js/classes/file.md) | The File to add to this Transaction |

#### Returns

`Transaction`

This Transaction, for chaining

***

### addRemoteId()

```ts
addRemoteId(remoteId): Transaction;
```

Add a remote id to the Transaction.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `remoteId` | `string` | The remote id to add |

#### Returns

`Transaction`

This Transaction, for chaining

***

### addUrl()

```ts
addUrl(url): Transaction;
```

Add a url to the Transaction. Url starts with https://

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `url` | `string` | The url to add |

#### Returns

`Transaction`

This Transaction, for chaining

***

### check()

```ts
check(): Promise;
```

Perform check transaction.

#### Returns

`Promise`\<`Transaction`\>

This Transaction, for chaining

***

### create()

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

Perform create new draft transaction.

#### Returns

`Promise`\<`Transaction`\>

This Transaction, for chaining

***

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

***

### from()

```ts
from(account): Transaction;
```

Sets the credit/origin [[Account]] of this Transaction. Same as setCreditAccount()

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `account` | \| `Account` \| [`Account`](https://bkper.com/docs/api/bkper-js/classes/account.md) \| `null` \| `undefined` | The Account object, or null/undefined to clear |

#### Returns

`Transaction`

This Transaction, for chaining

***

### getAccountBalance()

```ts
getAccountBalance(raw?): Promise;
```

Gets the balance that the [[Account]] has at that day, when listing transactions of that Account.

Evolved balances is returned when searching for transactions of a permanent [[Account]].

Only comes with the last posted transaction of the day.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `raw?` | `boolean` | True to get the raw balance, no matter the credit nature of the [[Account]] |

#### Returns

`Promise`\<[`Amount`](https://bkper.com/docs/api/bkper-js/classes/amount.md) \| `undefined`\>

The account balance at the transaction date

***

### getAgentId()

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

Gets the unique identifier of the agent that created this transaction.

#### Returns

`string` \| `undefined`

The id of the agent that created this transaction

***

### getAgentLogoUrl()

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

Gets the logo URL of the agent that created this transaction.

#### Returns

`string` \| `undefined`

The logo of the agent that created this transaction

***

### getAgentLogoUrlDark()

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

Gets the dark mode logo URL of the agent that created this transaction.

#### Returns

`string` \| `undefined`

The logo of the agent that created this transaction in dark mode

***

### getAgentName()

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

Gets the name of the agent that created this transaction.

#### Returns

`string` \| `undefined`

The name of the agent that created this transaction

***

### getAmount()

```ts
getAmount(): Amount | undefined;
```

Gets the amount of this Transaction.

#### Returns

[`Amount`](https://bkper.com/docs/api/bkper-js/classes/amount.md) \| `undefined`

The amount of this Transaction

***

### getAmountFormatted()

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

Gets the formatted amount of this Transaction according to the Book format.

#### Returns

`string` \| `undefined`

The amount of this Transaction, formatted according to the Book format

***

### getBook()

```ts
getBook(): Book;
```

Gets the book associated with this transaction.

#### Returns

[`Book`](https://bkper.com/docs/api/bkper-js/classes/book.md)

The book of the Transaction

***

### getCreatedAt()

```ts
getCreatedAt(): Date;
```

Gets the date when the transaction was created.

#### Returns

`Date`

The date the transaction was created

***

### getCreatedAtFormatted()

```ts
getCreatedAtFormatted(): string;
```

Gets the formatted creation date of the transaction.

#### Returns

`string`

The date the transaction was created, formatted according to the date pattern of the [[Book]]

***

### getCreatedBy()

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

Gets the username of the user who created the transaction.

#### Returns

`string` \| `undefined`

The username of the user who created the transaction

***

### getCreditAccount()

```ts
getCreditAccount(): Promise;
```

Gets the credit account associated with this Transaction. Same as origin account

#### Returns

`Promise`\<[`Account`](https://bkper.com/docs/api/bkper-js/classes/account.md) \| `undefined`\>

The credit (origin) account

***

### getCreditAccountName()

```ts
getCreditAccountName(): Promise<string | undefined>;
```

Gets the name of this Transaction's credit account.

#### Returns

`Promise`\<`string` \| `undefined`\>

The credit account name

***

### getCreditAmount()

```ts
getCreditAmount(account): Promise;
```

Get the absolute amount of this Transaction if the given account is at the credit side.

#### Parameters

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

#### Returns

`Promise`\<[`Amount`](https://bkper.com/docs/api/bkper-js/classes/amount.md) \| `undefined`\>

The credit amount or undefined

***

### getDate()

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

Gets the transaction date in ISO format.

#### Returns

`string` \| `undefined`

The Transaction date, in ISO format yyyy-MM-dd

***

### getDateFormatted()

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

Gets the transaction date formatted according to the book's date pattern.

#### Returns

`string` \| `undefined`

The Transaction date, formatted on the date pattern of the [[Book]]

***

### getDateObject()

```ts
getDateObject(): Date;
```

Gets the transaction date as a Date object in the book's timezone.

#### Returns

`Date`

The Transaction Date object, on the time zone of the [[Book]]

***

### getDateValue()

```ts
getDateValue(): number | undefined;
```

Gets the transaction date as a numeric value.

#### Returns

`number` \| `undefined`

The Transaction date number, in format YYYYMMDD

***

### getDebitAccount()

```ts
getDebitAccount(): Promise;
```

Gets the debit account associated with this Transaction. Same as destination account

#### Returns

`Promise`\<[`Account`](https://bkper.com/docs/api/bkper-js/classes/account.md) \| `undefined`\>

The debit (destination) account

***

### getDebitAccountName()

```ts
getDebitAccountName(): Promise<string | undefined>;
```

Gets the name of this Transaction's debit account.

#### Returns

`Promise`\<`string` \| `undefined`\>

The debit account name

***

### getDebitAmount()

```ts
getDebitAmount(account): Promise;
```

Gets the absolute amount of this Transaction if the given account is at the debit side.

#### Parameters

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

#### Returns

`Promise`\<[`Amount`](https://bkper.com/docs/api/bkper-js/classes/amount.md) \| `undefined`\>

The debit amount or undefined

***

### getDescription()

```ts
getDescription(): string;
```

Gets the description of this Transaction.

#### Returns

`string`

The description of this Transaction

***

### getFiles()

```ts
getFiles(): File[];
```

Gets all files attached to the transaction.

#### Returns

[`File`](https://bkper.com/docs/api/bkper-js/classes/file.md)[]

The files attached to the transaction

***

### getId()

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

Gets the unique identifier of the transaction.

#### Returns

`string` \| `undefined`

The id of the Transaction

***

### getOtherAccount()

```ts
getOtherAccount(account): Promise;
```

Gets the [[Account]] at the other side of the transaction given the one in one side.

#### Parameters

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

#### Returns

`Promise`\<[`Account`](https://bkper.com/docs/api/bkper-js/classes/account.md) \| `undefined`\>

The account at the other side of the transaction

***

### getOtherAccountName()

```ts
getOtherAccountName(account): Promise<string | undefined>;
```

The Account name at the other side of this Transaction given the one in one side.

#### Parameters

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

#### Returns

`Promise`\<`string` \| `undefined`\>

The name of the Account at the other side

***

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

***

### getRemoteIds()

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

Gets the remote IDs associated with this transaction. Remote ids are used to avoid duplication.

#### Returns

`string`[]

The remote ids of the Transaction

***

### getStatus()

```ts
getStatus(): TransactionStatus;
```

Gets the status of the transaction.

#### Returns

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

The status of the Transaction

***

### getTags()

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

Gets all hashtags used in the transaction.

#### Returns

`string`[]

All #hashtags used on the transaction

***

### getUpdatedAt()

```ts
getUpdatedAt(): Date;
```

Gets the date when the transaction was last updated.

#### Returns

`Date`

The date the transaction was last updated

***

### getUpdatedAtFormatted()

```ts
getUpdatedAtFormatted(): string;
```

Gets the formatted last update date of the transaction.

#### Returns

`string`

The date the transaction was last updated, formatted according to the date pattern of the [[Book]]

***

### getUrls()

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

Gets all URLs associated with the transaction.

#### Returns

`string`[]

All urls of the transaction

***

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

***

### hasTag()

```ts
hasTag(tag): boolean;
```

Check if the transaction has the specified tag.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `tag` | `string` | The tag to check for |

#### Returns

`boolean`

True if the transaction has the specified tag

***

### isChecked()

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

Checks if the transaction is marked as checked.

#### Returns

`boolean` \| `undefined`

True if transaction is checked

***

### isCredit()

```ts
isCredit(account?): Promise<boolean>;
```

Tell if the given account is credit on this Transaction

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `account?` | [`Account`](https://bkper.com/docs/api/bkper-js/classes/account.md) | The Account object |

#### Returns

`Promise`\<`boolean`\>

True if the account is the credit account

***

### isDebit()

```ts
isDebit(account?): Promise<boolean>;
```

Tell if the given account is debit on the Transaction

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `account?` | [`Account`](https://bkper.com/docs/api/bkper-js/classes/account.md) | The [[Account]] object |

#### Returns

`Promise`\<`boolean`\>

True if the Account is the debit account

***

### isLocked()

```ts
isLocked(): boolean;
```

Checks if the transaction is locked by the book's lock or closing date.

#### Returns

`boolean`

True if a transaction is locked by the book lock/closing date

***

### isPosted()

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

Checks if the transaction has been posted to the accounts.

#### Returns

`boolean` \| `undefined`

True if transaction was already posted to the accounts. False if is still a Draft

***

### isTrashed()

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

Checks if the transaction is in the trash.

#### Returns

`boolean` \| `undefined`

True if transaction is in trash

***

### json()

```ts
json(): Transaction;
```

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

#### Returns

`Transaction`

An immutable copy of the json payload

#### Inherited from

```ts
ResourceProperty.json
```

***

### post()

```ts
post(): Promise;
```

Perform post transaction, changing credit and debit [[Account]] balances.

#### Returns

`Promise`\<`Transaction`\>

This Transaction, for chaining

***

### removeFile()

```ts
removeFile(file): Transaction;
```

Removes a file attachment from the Transaction.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `file` | [`File`](https://bkper.com/docs/api/bkper-js/classes/file.md) | The File to remove from this Transaction |

#### Returns

`Transaction`

This Transaction, for chaining

***

### setAmount()

```ts
setAmount(amount): Transaction;
```

Sets the amount of this Transaction.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `amount` | `string` \| `number` \| [`Amount`](https://bkper.com/docs/api/bkper-js/classes/amount.md) | The amount to set |

#### Returns

`Transaction`

This Transaction, for chaining

***

### setChecked()

```ts
setChecked(checked): Transaction;
```

Set the check state of the Transaction.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `checked` | `boolean` | The check state |

#### Returns

`Transaction`

This Transaction, for chaining

***

### setCreditAccount()

```ts
setCreditAccount(account): Transaction;
```

Sets the credit/origin [[Account]] of this Transaction. Same as from()

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `account` | \| `Account` \| [`Account`](https://bkper.com/docs/api/bkper-js/classes/account.md) \| `null` \| `undefined` | The Account object, or null/undefined to clear |

#### Returns

`Transaction`

This Transaction, for chaining

***

### setDate()

```ts
setDate(date): Transaction;
```

Sets the date of the Transaction.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `date` | `string` \| `Date` | The date to set as string or Date object |

#### Returns

`Transaction`

This Transaction, for chaining

***

### setDebitAccount()

```ts
setDebitAccount(account): Transaction;
```

Sets the debit/destination [[Account]] of this Transaction. Same as to()

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `account` | \| `Account` \| [`Account`](https://bkper.com/docs/api/bkper-js/classes/account.md) \| `null` \| `undefined` | The Account object, or null/undefined to clear |

#### Returns

`Transaction`

This Transaction, for chaining

***

### setDescription()

```ts
setDescription(description): Transaction;
```

Sets the description of the Transaction.

#### Parameters

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

#### Returns

`Transaction`

This Transaction, 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
```

***

### setUrls()

```ts
setUrls(urls): Transaction;
```

Sets the Transaction urls. Url starts with https://

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `urls` | `string`[] | The urls array |

#### Returns

`Transaction`

This Transaction, 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
```

***

### to()

```ts
to(account): Transaction;
```

Sets the debit/destination [[Account]] of this Transaction. Same as setDebitAccount()

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `account` | \| `Account` \| [`Account`](https://bkper.com/docs/api/bkper-js/classes/account.md) \| `null` \| `undefined` | The Account object, or null/undefined to clear |

#### Returns

`Transaction`

This Transaction, for chaining

***

### trash()

```ts
trash(): Promise;
```

Trash the transaction.

#### Returns

`Promise`\<`Transaction`\>

This Transaction, for chaining

***

### uncheck()

```ts
uncheck(): Promise;
```

Perform uncheck transaction.

#### Returns

`Promise`\<`Transaction`\>

This Transaction, for chaining

***

### untrash()

```ts
untrash(): Promise;
```

Untrash the transaction.

#### Returns

`Promise`\<`Transaction`\>

This Transaction, for chaining

***

### update()

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

Update transaction, applying pending changes.

#### Returns

`Promise`\<`Transaction`\>

This Transaction, for chaining
