Ledger
Inherits: Ownable
A ledger contract representing a subledger in a general ledger system.
Supports double-entry accounting with role-based access control.
State Variables
category
Category public category;
nextAccountId
uint256 public nextAccountId = 1;
nextEntryId
uint256 public nextEntryId = 1;
name
string public name;
accounts
mapping(uint256 => Account) public accounts;
childAccounts
mapping(uint256 => uint256[]) public childAccounts;
entries
mapping(uint256 => Entry) public entries;
accountBalances
mapping(uint256 => int256) public accountBalances;
ledgerManager
address public ledgerManager;
accountants
mapping(address => bool) public accountants;
auditors
mapping(address => bool) public auditors;
Functions
onlyAccountantOrOwner
modifier onlyAccountantOrOwner();
onlyAuditorOrOwner
modifier onlyAuditorOrOwner();
constructor
constructor(address _ledgerManager, string memory _name, Category _category, address _owner, address _accountant)
Ownable(_owner);
createAccount
Create a new account in the ledger.
function createAccount(uint256 _parentAccountId, string memory _name) public onlyAccountantOrOwner returns (uint256);
Parameters
_parentAccountId
uint256
The ID of the parent account.
_name
string
The name of the account.
Returns
<none>
uint256
accountId The ID of the newly created account.
createEntry
Record a new ledger entry.
function createEntry(uint256 accountId, int256 amount, uint256 transactionId)
public
onlyAccountantOrOwner
returns (uint256);
Parameters
accountId
uint256
The ID of the account to which the entry is posted.
amount
int256
The amount of the entry.
transactionId
uint256
The ID of the transaction that the entry is part of.
Returns
<none>
uint256
The ID of the newly created entry.
getAccountBalance
Get the balance of an account.
function getAccountBalance(uint256 accountId) public view returns (int256 balance);
Parameters
accountId
uint256
The ID of the account.
Returns
balance
int256
The current balance of the account.
addAccountant
Add an accountant.
function addAccountant(address _accountant) public onlyOwner;
Parameters
_accountant
address
The address of the accountant.
removeAccountant
Remove an accountant.
function removeAccountant(address _accountant) public onlyOwner;
Parameters
_accountant
address
The address of the accountant.
addAuditor
Add an auditor.
function addAuditor(address _auditor) public onlyOwner;
Parameters
_auditor
address
The address of the auditor.
removeAuditor
Remove an auditor.
function removeAuditor(address _auditor) public onlyOwner;
Parameters
_auditor
address
The address of the auditor.
isDebitNormal
function isDebitNormal() public view returns (bool isDebit);
isCreditNormal
function isCreditNormal() public view returns (bool isCredit);
disableAccount
Disable an account, can only be done if the account balance is zero.
function disableAccount(uint256 accountId) public onlyAccountantOrOwner;
Parameters
accountId
uint256
The ID of the account to disable.
enableAccount
Enable a previously disabled account.
function enableAccount(uint256 accountId) public onlyAccountantOrOwner;
Parameters
accountId
uint256
The ID of the account to enable.
Events
AccountCreated
event AccountCreated(uint256 accountId, uint256 parentAccountId, string name);
EntryCreated
event EntryCreated(
uint256 entryId, uint256 accountId, uint256 amount, bool isDebit, EntryStatus status, uint256 transactionId
);
AccountantAdded
event AccountantAdded(address accountant);
AccountantRemoved
event AccountantRemoved(address accountant);
AuditorAdded
event AuditorAdded(address auditor);
AuditorRemoved
event AuditorRemoved(address auditor);
AccountDisabled
event AccountDisabled(uint256 accountId);
AccountEnabled
event AccountEnabled(uint256 accountId);
Structs
Account
struct Account {
uint256 parentAccountId;
uint256 accountId;
string name;
bool active;
}
Entry
struct Entry {
uint256 entryId;
address ledgerId;
uint256 accountId;
int256 amount;
EntryStatus status;
}
Enums
EntryStatus
enum EntryStatus {
Pending,
Posted,
Archived
}
Category
enum Category {
GL,
Asset,
Liability,
Equity,
Revenue,
Expense
}
Last updated
Was this helpful?