Ledgers: An overview
The following defines the ledger structure and how it is used in Tupertino:
LedgerBalance
: The balance of a ledger, which is used to track the balance of an organisation or partner.LedgerTransaction
: A transaction that is used to update the ledger balance.
export class LedgerBalance {
id?: string;
organisation_id?: string; // The organisation that the ledger belongs to
balance?: number; // The balance of the current ledger
currency?: string; // The currency of the current ledger
created_at?: Date; // The date the ledger was created
updated_at?: Date; // The date the ledger was last updated
Organisation?: Organisation; // The organisation that the ledger belongs to
SourceLedgerTransactions?: LedgerTransaction[]; // The source ledger transactions
DestinationLedgerTransactions?: LedgerTransaction[]; // The destination ledger transactions
}
export class LedgerTransaction {
id?: string;
operation_type?: string;
description?: string;
source_ledger_balance_id?: string;
destination_ledger_balance_id?: string;
amount?: number;
currency?: string;
refund_id?: string;
payment_id?: string;
Refund?: Refund;
Payment?: Payment;
SourceLedgerBalance?: LedgerBalance;
DestinationLedgerBalance?: LedgerBalance;
created_at?: Date;
updated_at?: Date;
}
A worked example is given below:
- A payment is created with partner
doku
, with the following details:- Payment method:
id_bri_banktransfer
- Currency:
sgd
- Amount:
100
- Payment method:
- The payment is processed by the partner, and the payment is updated as
completed
. - The ledger transactions are created:
- A
debit
transaction is created for the organisation ledger with the following details:- Operation type:
debit
- Description:
Payment for order #123
- Source ledger balance ID:
organisation_ledger_balance_id
- Destination ledger balance ID:
partner_ledger_balance_id
- Amount:
100
- Currency:
sgd
- Operation type:
- A
credit
transaction is created for the partner ledger with the following details:- Operation type:
credit
- Description:
Payment for order #123
- Source ledger balance ID:
partner_ledger_balance_id
- Destination ledger balance ID:
organisation_ledger_balance_id
- Amount:
100
- Currency:
sgd
- Operation type:
- The ledger balances are updated:
- Organisation ledger balance:
100
- Partner ledger balance:
-100
- Organisation ledger balance:
- A