Skip to content

Finance Schema

The finance schema contains 3 models that manage financial operations including wallet management, categorized income/expense tracking, and inter-wallet transfers.

Source: packages/core/src/models/schemas/finance/

Models Overview

ModelTable NameDescription
FinanceWalletfinance.FinanceWalletFinancial accounts (cash, bank, e-wallet, credit card)
FinanceCategoryfinance.FinanceCategoryIncome and expense categorization
FinanceTransactionfinance.FinanceTransactionIndividual financial transactions

FinanceWallet

Financial accounts for tracking money flow per merchant.

Wallet Types

TypeValueDescription
CASH100_CASHPhysical cash
BANK200_BANKBank account
EWALLET300_EWALLETElectronic wallet (Momo, ZaloPay, etc.)
CREDIT_CARD400_CREDIT_CARDCredit card

Columns

ColumnTypeConstraintsDescription
statustextNOT NULL, DEFAULT ACTIVATEDWallet status (ACTIVATED, ARCHIVED)
namejsonb (i18n)NOT NULLInternationalized name
typetextNOT NULLWallet type (CASH, BANK, EWALLET, CREDIT_CARD)
account_numbertextBank account or card number
bank_nametextBank/institution name
currencytextNOT NULL, DEFAULT 'VND'Currency code
initial_balancedecimal(15,4)NOT NULL, DEFAULT '0'Starting balance
current_balancedecimal(15,4)NOT NULL, DEFAULT '0'Current balance
is_defaultbooleanNOT NULL, DEFAULT falseDefault wallet for the merchant
is_excludedbooleanNOT NULL, DEFAULT falseExcluded from reports
merchant_idtextNOT NULLFK to Merchant
created_bytextCreator user ID
modified_bytextLast modifier user ID
+ common columnsid, createdAt, modifiedAt, deletedAt, metadata

FinanceCategory

Income and expense categorization with hierarchical support and predefined categories.

Category Types

TypeValueDescription
INCOME100_INCOMEIncome category
EXPENSE200_EXPENSEExpense category

Columns

ColumnTypeConstraintsDescription
statustextNOT NULL, DEFAULT ACTIVATEDCategory status (ACTIVATED, ARCHIVED)
namejsonb (i18n)NOT NULLInternationalized name
descriptionjsonb (i18n)Internationalized description
typetextNOT NULLCategory type (INCOME or EXPENSE)
identifiertextNOT NULL, UNIQUEAuto-generated unique identifier
merchant_idtextFK to Merchant (null for global categories)
parent_idtextFK to parent FinanceCategory
+ common columns

Fixed Finance Categories

Income categories:

CodeValueDescription
SALE000_SALERevenue from sales
OTHER_INCOME001_OTHER_INCOMEOther income sources
REFUND_INCOME002_REFUND_INCOMERefund received

Expense categories:

CodeValueDescription
PURCHASE100_PURCHASEInventory purchases
OTHER_EXPENSE101_OTHER_EXPENSEMiscellaneous expenses
REFUND_EXPENSE102_REFUND_EXPENSERefunds issued

Operating expense categories:

CodeValueDescription
OPERATING200_OPERATINGGeneral operating expenses
SALARY201_SALARYStaff salaries
RENT_UTILITIES202_RENT_UTILITIESRent and utilities
MARKETING203_MARKETINGMarketing and advertising
SHIPPING204_SHIPPINGShipping and logistics
MAINTENANCE205_MAINTENANCEEquipment/facility maintenance

Interest categories:

CodeValueDescription
COLLECT_INTEREST300_COLLECT_INTERESTInterest income
PAY_INTEREST301_PAY_INTERESTInterest expense

FinanceTransaction

Individual financial transactions with wallet-to-wallet transfer support.

Transaction Types

TypeValueDescription
INCOME100_INCOMEMoney coming in
EXPENSE200_EXPENSEMoney going out
TRANSFER300_TRANSFERMoney moving between wallets

Transaction Statuses

StatusValueTerminalDescription
PENDING200_PENDINGNoAwaiting completion
COMPLETED303_COMPLETEDYesSuccessfully completed
CANCELLED505_CANCELLEDYesCancelled

Columns

ColumnTypeConstraintsDescription
statustextNOT NULL, DEFAULT COMPLETEDTransaction status
typetextNOT NULLTransaction type (INCOME, EXPENSE, TRANSFER)
amountdecimal(15,4)NOT NULLTransaction amount
currencytextNOT NULL, DEFAULT 'VND'Currency code
exchange_ratedecimal(19,6)Exchange rate (for multi-currency)
transaction_dateisoTimestampNOT NULLTransaction date (ISO 8601 string)
finance_wallet_idtextNOT NULLFK to source FinanceWallet
to_finance_wallet_idtextFK to destination FinanceWallet (for TRANSFER type)
finance_category_idtextFK to FinanceCategory
reference_typetextReference entity type (e.g., SaleOrder, PurchaseOrder)
reference_idtextReference entity ID
merchant_idtextNOT NULLFK to Merchant
metadatajsonbTFinanceTransactionMetadata (sale order payment details)
created_bytextCreator user ID
modified_bytextLast modifier user ID
+ common columns

Entity Relationships

Event-Driven Integration

The finance package automatically creates transactions based on events from other services:

EventActionCategoryType
Commerce initialized (merchant onboarding)Create default Cash wallet----
Payment success (sale order)Create INCOME transactionSALEINCOME
Purchase order receivedCreate EXPENSE transactionPURCHASEEXPENSE

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.