Transaction
This class defines a Transaction between credit and debit [[Accounts]].
A Transaction is the main entity on the Double Entry Bookkeeping system.
Extends
ResourceProperty<bkper.Transaction>
Constructors
Constructor
new Transaction(book, payload?): Transaction;Parameters
| Parameter | Type |
|---|---|
book | Book |
payload? | Transaction |
Returns
Transaction
Overrides
ResourceProperty<bkper.Transaction>.constructorProperties
payload
payload: Transaction;The underlying payload data for this resource
Inherited from
ResourceProperty.payloadMethods
addFile()
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 | The File to add to this Transaction |
Returns
Transaction
This Transaction, for chaining
addRemoteId()
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()
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()
check(): Promise<Transaction>;Perform check transaction.
Returns
Promise<Transaction>
This Transaction, for chaining
create()
create(): Promise<Transaction>;Perform create new draft transaction.
Returns
Promise<Transaction>
This Transaction, for chaining
deleteProperty()
deleteProperty(key): this;Deletes a custom property.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The property key |
Returns
this
This resource, for chaining
Inherited from
ResourceProperty.deletePropertyfrom()
from(account): Transaction;Sets the credit/origin [[Account]] of this Transaction. Same as setCreditAccount()
Parameters
| Parameter | Type | Description |
|---|---|---|
account | | Account | Account | null | undefined | The Account object, or null/undefined to clear |
Returns
Transaction
This Transaction, for chaining
getAccountBalance()
getAccountBalance(raw?): Promise<Amount | undefined>;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 | undefined>
The account balance at the transaction date
getAgentId()
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()
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()
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()
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()
getAmount(): Amount | undefined;Gets the amount of this Transaction.
Returns
Amount | undefined
The amount of this Transaction
getAmountFormatted()
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()
getBook(): Book;Gets the book associated with this transaction.
Returns
The book of the Transaction
getCreatedAt()
getCreatedAt(): Date;Gets the date when the transaction was created.
Returns
Date
The date the transaction was created
getCreatedAtFormatted()
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()
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()
getCreditAccount(): Promise<Account | undefined>;Gets the credit account associated with this Transaction. Same as origin account
Returns
Promise<Account | undefined>
The credit (origin) account
getCreditAccountName()
getCreditAccountName(): Promise<string | undefined>;Gets the name of this Transaction’s credit account.
Returns
Promise<string | undefined>
The credit account name
getCreditAmount()
getCreditAmount(account): Promise<Amount | undefined>;Get the absolute amount of this Transaction if the given account is at the credit side.
Parameters
| Parameter | Type | Description |
|---|---|---|
account | string | Account | The account object, id or name |
Returns
Promise<Amount | undefined>
The credit amount or undefined
getDate()
getDate(): string | undefined;Gets the transaction date in ISO format.
Returns
string | undefined
The Transaction date, in ISO format yyyy-MM-dd
getDateFormatted()
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()
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()
getDateValue(): number | undefined;Gets the transaction date as a numeric value.
Returns
number | undefined
The Transaction date number, in format YYYYMMDD
getDebitAccount()
getDebitAccount(): Promise<Account | undefined>;Gets the debit account associated with this Transaction. Same as destination account
Returns
Promise<Account | undefined>
The debit (destination) account
getDebitAccountName()
getDebitAccountName(): Promise<string | undefined>;Gets the name of this Transaction’s debit account.
Returns
Promise<string | undefined>
The debit account name
getDebitAmount()
getDebitAmount(account): Promise<Amount | undefined>;Gets the absolute amount of this Transaction if the given account is at the debit side.
Parameters
| Parameter | Type | Description |
|---|---|---|
account | string | Account | The account object, id or name |
Returns
Promise<Amount | undefined>
The debit amount or undefined
getDescription()
getDescription(): string;Gets the description of this Transaction.
Returns
string
The description of this Transaction
getFiles()
getFiles(): File[];Gets all files attached to the transaction.
Returns
File[]
The files attached to the transaction
getId()
getId(): string | undefined;Gets the unique identifier of the transaction.
Returns
string | undefined
The id of the Transaction
getOtherAccount()
getOtherAccount(account): Promise<Account | undefined>;Gets the [[Account]] at the other side of the transaction given the one in one side.
Parameters
| Parameter | Type | Description |
|---|---|---|
account | string | Account | The account object, id or name |
Returns
Promise<Account | undefined>
The account at the other side of the transaction
getOtherAccountName()
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 | The Account object, id or name |
Returns
Promise<string | undefined>
The name of the Account at the other side
getProperties()
getProperties(): object;Gets the custom properties stored in this resource.
Returns
object
Object with key/value pair properties
Inherited from
ResourceProperty.getPropertiesgetProperty()
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
ResourceProperty.getPropertygetPropertyKeys()
getPropertyKeys(): string[];Gets the custom properties keys stored in this resource.
Returns
string[]
Array of property keys sorted alphabetically
Inherited from
ResourceProperty.getPropertyKeysgetRemoteIds()
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()
getStatus(): TransactionStatus;Gets the status of the transaction.
Returns
The status of the Transaction
getTags()
getTags(): string[];Gets all hashtags used in the transaction.
Returns
string[]
All #hashtags used on the transaction
getUpdatedAt()
getUpdatedAt(): Date;Gets the date when the transaction was last updated.
Returns
Date
The date the transaction was last updated
getUpdatedAtFormatted()
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()
getUrls(): string[];Gets all URLs associated with the transaction.
Returns
string[]
All urls of the transaction
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.getVisiblePropertieshasTag()
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()
isChecked(): boolean | undefined;Checks if the transaction is marked as checked.
Returns
boolean | undefined
True if transaction is checked
isCredit()
isCredit(account?): Promise<boolean>;Tell if the given account is credit on this Transaction
Parameters
| Parameter | Type | Description |
|---|---|---|
account? | Account | The Account object |
Returns
Promise<boolean>
True if the account is the credit account
isDebit()
isDebit(account?): Promise<boolean>;Tell if the given account is debit on the Transaction
Parameters
| Parameter | Type | Description |
|---|---|---|
account? | Account | The [[Account]] object |
Returns
Promise<boolean>
True if the Account is the debit account
isLocked()
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()
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()
isTrashed(): boolean | undefined;Checks if the transaction is in the trash.
Returns
boolean | undefined
True if transaction is in trash
json()
json(): Transaction;Gets an immutable copy of the JSON payload for this resource.
Returns
Transaction
An immutable copy of the json payload
Inherited from
ResourceProperty.jsonpost()
post(): Promise<Transaction>;Perform post transaction, changing credit and debit [[Account]] balances.
Returns
Promise<Transaction>
This Transaction, for chaining
removeFile()
removeFile(file): Transaction;Removes a file attachment from the Transaction.
Parameters
| Parameter | Type | Description |
|---|---|---|
file | File | The File to remove from this Transaction |
Returns
Transaction
This Transaction, for chaining
setAmount()
setAmount(amount): Transaction;Sets the amount of this Transaction.
Parameters
| Parameter | Type | Description |
|---|---|---|
amount | string | number | Amount | The amount to set |
Returns
Transaction
This Transaction, for chaining
setChecked()
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()
setCreditAccount(account): Transaction;Sets the credit/origin [[Account]] of this Transaction. Same as from()
Parameters
| Parameter | Type | Description |
|---|---|---|
account | | Account | Account | null | undefined | The Account object, or null/undefined to clear |
Returns
Transaction
This Transaction, for chaining
setDate()
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()
setDebitAccount(account): Transaction;Sets the debit/destination [[Account]] of this Transaction. Same as to()
Parameters
| Parameter | Type | Description |
|---|---|---|
account | | Account | Account | null | undefined | The Account object, or null/undefined to clear |
Returns
Transaction
This Transaction, for chaining
setDescription()
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()
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
ResourceProperty.setPropertiessetProperty()
setProperty(key, value): this;Sets a custom property in this resource.
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
ResourceProperty.setPropertysetUrls()
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()
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
ResourceProperty.setVisiblePropertiessetVisibleProperty()
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
ResourceProperty.setVisiblePropertyto()
to(account): Transaction;Sets the debit/destination [[Account]] of this Transaction. Same as setDebitAccount()
Parameters
| Parameter | Type | Description |
|---|---|---|
account | | Account | Account | null | undefined | The Account object, or null/undefined to clear |
Returns
Transaction
This Transaction, for chaining
trash()
trash(): Promise<Transaction>;Trash the transaction.
Returns
Promise<Transaction>
This Transaction, for chaining
uncheck()
uncheck(): Promise<Transaction>;Perform uncheck transaction.
Returns
Promise<Transaction>
This Transaction, for chaining
untrash()
untrash(): Promise<Transaction>;Untrash the transaction.
Returns
Promise<Transaction>
This Transaction, for chaining
update()
update(): Promise<Transaction>;Update transaction, applying pending changes.
Returns
Promise<Transaction>
This Transaction, for chaining