Represents a general ledger that manages and facilitates financial transactions, account ledgers, and general accounting operations. More...
#include <LedgerBooks.h>
Public Member Functions | |
GeneralLedger () | |
Default construction of an empty valid general ledger. | |
GeneralLedger (std::map< AccountNumber, LedgerAccount > ledgers, std::optional< AccountNumber > openingAccountNumber={}) | |
Fully initalises the object to the supplied values. | |
AccountCode | accountCode (const AccountNumber &accountNumber) const |
Provides the account code for a requested account number. | |
std::set< AccountCode > | accountCodes () const noexcept |
Provides all the known account codes in the general ledger. | |
std::set< AccountCode > | accountCodes (const AccountTypes &type) const noexcept |
Provides all the known account codes in the general ledger of a specific type. | |
std::set< AccountCode > | accountCodes (const std::set< AccountNumber > &accountNumbers) const |
Provides the account codes for a requested selection of account numbers. | |
std::set< Account > | accounts () const noexcept |
Provides all the known accounts in the general ledger. | |
std::optional< TransactionNumber > | add (const Account &toAdd, AccountNumberGenerator &generator) |
Adds a new account to general ledger books. | |
bool | canRemove (const AccountCode &code) const noexcept |
Determines if an account can be removed. | |
void | clear (const std::set< TransactionNumber > &txnNums) |
Marks all the transactions supplied as cleared. | |
void | clear (const TransactionNumber &txnNum) |
Marks the transaction for both accounts involved in the transaction as cleared. | |
void | clear (const TransactionNumber &txnNum, const AccountNumber &actNum) |
Marks the transaction of a single ledger account as cleared. | |
void | close (const AccountNumber &an) |
Closes a ledger account. | |
void | convertTo (const AccountNumber &convertAccount, const pecunia::Currency &code, AccountNumberGenerator &generator) |
Converts a ledger account's running balance from one currency into another. If the opening balance account is not created, it'll be created. | |
bool | hasLedger (const AccountCode &code) const noexcept |
Determines if an account ledger book exits in the general ledger. | |
bool | hasLedger (const AccountNumber &number) const noexcept |
Determines if an account ledger book exits in the general ledger. | |
bool | isEmpty () const noexcept |
Determines if the general ledger is empty. | |
const LedgerAccount & | ledger (const AccountCode &code) const |
Provides access to the ledger of a specific account. | |
const LedgerAccount & | ledger (const AccountNumber &number) const |
Provides access to the ledger of a specific account. | |
const std::map< AccountNumber, LedgerAccount > & | ledgers () const noexcept |
An accessor to the current ledgers in the general ledger. | |
std::set< AccountNumber > | lookUpChildren (const AccountNumber &parent) const noexcept |
Finds and retrieves the identifiers of all child accounts linked to the specified parent account. This method queries accounts hierarchically tied to the given parent and returns the results for further processing or display. | |
std::set< AccountNumber > | lookUpChildren (const AccountNumber &parent, const OpenStates &openState) const noexcept |
Identifies and retrieves all child accounts for a specified parent account, filtering by their open or closed status. | |
std::optional< Transaction > | lookUpTransaction (const TransactionNumber &txnNum) const noexcept |
Searches for a specific transaction. | |
void | open (const AccountCode &code) |
Opens a ledger. | |
const std::optional< AccountNumber > & | openingAccountNumber () const noexcept |
Provides the account code number for the ledger book tracking the opening account balances. | |
std::optional< Transaction > | openingTransaction (const AccountNumber &account) const noexcept |
Locates the opening balance transaction of an account. The oldest transaction involving the general ledger's opening account is considered to be the opening balance. | |
bool | operator!= (const GeneralLedger &other) const |
Inequality operator compares all members. | |
bool | operator== (const GeneralLedger &other) const |
Equality operator compares all members. | |
TransactionNumber | post (const Transaction &transaction) |
Posts a supplied transaction to the debiting and crediting accounts. | |
void | recode (const AccountCode &toRecode, const AccountCode &recodeAs) |
Changes the code of a ledger book and recodes all transactions. | |
void | reconcile (const std::set< TransactionNumber > &txnNums) |
Reconciles all transactions supplied. | |
void | reconcile (const TransactionNumber &txnNum) |
Reconciles the transaction supplied. | |
void | reconcile (const TransactionNumber &txnNum, const AccountNumber &actNum) |
Reconciles only those transactions supplied for a given account number. | |
TransactionNumber | refund (const TransactionNumber &txnNum, const pecunia::Money &amount) |
Processes a refund for a previously recorded transaction. | |
void | remove (const AccountNumber &an) |
Attempts to remove an account from the general ledger. This operation modifies the ledger books by erasing the specified account. | |
void | remove (const std::set< TransactionNumber > &transactionNumbers) |
Removes all the transactions supplied. | |
void | remove (const TransactionNumber &number) |
Removes the transaction supplied. | |
void | repost (const TransactionNumber &number, const Transaction &transaction) |
Replaces a non-reconciled transaction with a new transaction. | |
void | unreconcile (const std::set< TransactionNumber > &txnNums) |
Marks all the transactions supplied as unreconciled. | |
void | unreconcile (const TransactionNumber &txnNum) |
Marks the transaction supplied as unreconciled. | |
void | unreconcile (const TransactionNumber &txnNum, const AccountNumber &actNum) |
Marks the transaction supplied as unreconciled. | |
Friends | |
DRN_ACCOUNTING_EXPORT std::ostream & | operator<< (std::ostream &o, const GeneralLedger &gl) |
Stream insertion operator for a human readable general ledger account. | |
Represents a general ledger that manages and facilitates financial transactions, account ledgers, and general accounting operations.
It is used to handle bookkeeping operations by tracking accounts and their transactions. It upholds financial integrity by validating data during these operations. Furthermore, it contains all the account information relating to the accounting system’s assets, liabilities, capital, revenue, and expenses.
drn::accounting::GeneralLedger::GeneralLedger | ( | ) |
Default construction of an empty valid general ledger.
|
explicit |
Fully initalises the object to the supplied values.
AccountError | When the opening account code is not present in the ledgers. |
AccountError | When the opening account code is not an AccountTypes::Capital type. |
AccountError | When the mapped account code does not match the ledger's account code. |
AccountError | When the account for a parent does not exist. |
AccountError | When a parent account refers to a child account. |
TransactionError | When a ledger account contains an invalid transaction number. |
TransactionError | When a ledger account contains a transaction for a debiting account that does not exist. |
TransactionError | When a ledger account contains a transaction for a crediting account that does not exist. |
TransactionError | When a ledger account contains a transaction that does not contain a matching transaction in the other ledger account. |
TransactionError | When a ledger account contains a transaction number that is not mapped to the same number. |
ledgers | The ledgers to store in the general ledger. |
openingAccountNumber | The account number to use for the opening balance when opening an account. |
|
nodiscard |
Provides the account code for a requested account number.
AccountError | When an account number does not have an account code. |
accountNumber | The account number to get the account code for. |
|
nodiscardnoexcept |
Provides all the known account codes in the general ledger.
|
nodiscardnoexcept |
Provides all the known account codes in the general ledger of a specific type.
type | The type of account to provide the codes for. |
|
nodiscard |
Provides the account codes for a requested selection of account numbers.
AccountError | When an account number does not have an account code. |
accountNumbers | The account numbers to get the account codes for. |
|
nodiscardnoexcept |
Provides all the known accounts in the general ledger.
|
nodiscard |
Adds a new account to general ledger books.
AccountError | When the account already exists. |
AccountError | When the account is closed. |
AccountError | When the account type is not known. |
AccountError | When the account code is not valid. |
AccountError | When the parent account type is different than the adding account. |
toAdd | The new account to add to the ledger books. |
generator | The generator for new account numbers already to be used. |
|
nodiscardnoexcept |
Determines if an account can be removed.
code | The account code that should be checked. |
void drn::accounting::GeneralLedger::clear | ( | const std::set< TransactionNumber > & | txnNums | ) |
Marks all the transactions supplied as cleared.
txnNums | The numbers of the transactions to be cleared. |
void drn::accounting::GeneralLedger::clear | ( | const TransactionNumber & | txnNum | ) |
Marks the transaction for both accounts involved in the transaction as cleared.
Error | When the transaction number does not exist in the ledger books. |
txnNum | The number of the transaction to be cleared. |
void drn::accounting::GeneralLedger::clear | ( | const TransactionNumber & | txnNum, |
const AccountNumber & | actNum ) |
Marks the transaction of a single ledger account as cleared.
TransactionError | When the transaction number does not exist in the ledger books. |
AccountError | When the account number does not exist in the ledger books. |
txnNum | The number of the transaction to be cleared. |
actNum | The number of the ledger account whose transaction should be cleared. |
void drn::accounting::GeneralLedger::close | ( | const AccountNumber & | an | ) |
Closes a ledger account.
AccountError | Thrown if the account does not exist in the ledger. |
AccountError | Thrown if the account has non-reconciled transactions. |
AccountError | Thrown if the account is a parent account of other non-closed accounts. |
an | The unique identifier of the account to be closed. |
void drn::accounting::GeneralLedger::convertTo | ( | const AccountNumber & | convertAccount, |
const pecunia::Currency & | code, | ||
AccountNumberGenerator & | generator ) |
Converts a ledger account's running balance from one currency into another. If the opening balance account is not created, it'll be created.
TransactionError | When the supplied currency code to convert to is unknown. |
TransactionError | When the account to convert is closed. |
AccountError | When the account to convert does not exist. |
AccountError | When the account in already in the currency code to convert to. |
convertAccount | The ledger account to convert. |
code | The currency to convert the ledger account into. |
generator | The generator for new account numbers already to be used. |
|
nodiscardnoexcept |
Determines if an account ledger book exits in the general ledger.
code | The account code whose ledger status is desired. |
|
nodiscardnoexcept |
Determines if an account ledger book exits in the general ledger.
number | The account number whose ledger status is desired. |
|
nodiscardnoexcept |
Determines if the general ledger is empty.
|
nodiscard |
Provides access to the ledger of a specific account.
AccountError | When the ledger book for the supplied account code does not exist. |
code | The account code whose ledger is desired. |
|
nodiscard |
Provides access to the ledger of a specific account.
AccountError | When the ledger book for the supplied account code does not exist. |
number | The account number whose ledger is desired. |
|
nodiscardnoexcept |
An accessor to the current ledgers in the general ledger.
|
nodiscardnoexcept |
Finds and retrieves the identifiers of all child accounts linked to the specified parent account. This method queries accounts hierarchically tied to the given parent and returns the results for further processing or display.
parent | The identifier of the parent account whose child accounts are to be retrieved. |
|
nodiscardnoexcept |
Identifies and retrieves all child accounts for a specified parent account, filtering by their open or closed status.
This function parses through a collection of accounts, finding those that are directly subordinate to a specified parent account. It allows filtering based on whether the accounts are open, closed, or regardless of their state.
parent | The account identifier for which child accounts are sought. |
openState | The desired open or closed status of accounts to be included in the result set. |
|
nodiscardnoexcept |
Searches for a specific transaction.
txnNum | The transaction to search for. |
void drn::accounting::GeneralLedger::open | ( | const AccountCode & | code | ) |
Opens a ledger.
AccountError | When the account does not exist. |
AccountError | When the account to open is a child account whose parent is closed. |
code | The account code of the account ledger book to open. |
|
nodiscardnoexcept |
Provides the account code number for the ledger book tracking the opening account balances.
|
nodiscardnoexcept |
Locates the opening balance transaction of an account. The oldest transaction involving the general ledger's opening account is considered to be the opening balance.
account | The account number of the ledger to search for the opening balance. |
|
nodiscard |
Inequality operator compares all members.
other | The other object whose members should be not equal. |
|
nodiscard |
Equality operator compares all members.
other | The other object whose members should all be equal. |
|
nodiscard |
Posts a supplied transaction to the debiting and crediting accounts.
TransactionError | When the transaction has a debiting account that is not in the ledger books. |
TransactionError | When the ledger book for the debiting account is closed. |
TransactionError | When the transaction has a crediting account that is not in the ledger books. |
TransactionError | When the ledger book for the crediting account is closed. |
TransactionError | When the transaction is not unreconciled. |
AccountError | When the transaction is for a currency that is unknown and the opening account does not exist. |
TransactionError | When the transaction is for a currency that is unknown. |
transaction | The transaction that is to be posted. |
void drn::accounting::GeneralLedger::recode | ( | const AccountCode & | toRecode, |
const AccountCode & | recodeAs ) |
Changes the code of a ledger book and recodes all transactions.
AccountError | When the current account does not exist. |
AccountError | When the account is closed. |
AccountError | When the changed account code is already in use. |
AccountError | When the account for a parent does not exist. |
AccountError | When a parent account refers to a child account. |
toRecode | The account code of the account ledger book to change. |
recodeAs | The account code of the account ledger book to change to. |
void drn::accounting::GeneralLedger::reconcile | ( | const std::set< TransactionNumber > & | txnNums | ) |
Reconciles all transactions supplied.
txnNums | The numbers of the transactions to be reconciled. |
void drn::accounting::GeneralLedger::reconcile | ( | const TransactionNumber & | txnNum | ) |
Reconciles the transaction supplied.
TransactionError | When the transaction number does not exist in the ledger books. |
txnNum | The number of the transaction to be reconciled. |
void drn::accounting::GeneralLedger::reconcile | ( | const TransactionNumber & | txnNum, |
const AccountNumber & | actNum ) |
Reconciles only those transactions supplied for a given account number.
TransactionError | When a transaction number does not exist in the ledger books. |
AccountError | When the account to only reconcile is not a part of the transaction. |
AccountError | When the account to reconcile does not exist. |
actNum | The account whose transactions are to be reconciled. |
txnNum | The numbers of the transactions to be reconciled. |
|
nodiscard |
Processes a refund for a previously recorded transaction.
TransactionError | if the specified original transaction does not exist. |
TransactionError | if the refund amount is greater than the original transaction amount. |
txnNum | The identifier of the transaction for which the refund is to be made. |
amount | The amount to be refunded. |
void drn::accounting::GeneralLedger::remove | ( | const AccountNumber & | an | ) |
Attempts to remove an account from the general ledger. This operation modifies the ledger books by erasing the specified account.
AccountError | Thrown when the account is not present in the ledger books. |
AccountError | Thrown when the account is already closed. |
AccountError | Thrown when attempting to remove an opening account with transactions. |
AccountError | Thrown when attempting to remove a parent account with dependent child accounts. |
an | Refers to the unique identifier of the account to be removed. |
void drn::accounting::GeneralLedger::remove | ( | const std::set< TransactionNumber > & | transactionNumbers | ) |
Removes all the transactions supplied.
Error | When a transaction number does not exist in the ledger books. |
TransactionError | When a transaction in the ledger books is already reconciled. |
transactionNumbers | The numbers of the transactions to be removed. |
void drn::accounting::GeneralLedger::remove | ( | const TransactionNumber & | number | ) |
Removes the transaction supplied.
Error | When a transaction number does not exist in the ledger books. |
TransactionError | When a transaction in the ledger books is already reconciled. |
number | The number of the transaction to be removed. |
void drn::accounting::GeneralLedger::repost | ( | const TransactionNumber & | number, |
const Transaction & | transaction ) |
Replaces a non-reconciled transaction with a new transaction.
TransactionError | When the new transaction has a debiting account that is not in the ledger books. |
TransactionError | When the ledger book for the debiting account is closed. |
TransactionError | When the new transaction has a crediting account that is not in the ledger books. |
TransactionError | When the ledger book for the crediting account is closed. |
TransactionError | When the supplied original transaction number does not exist. |
TransactionError | When the original transaction is already reconciled. |
TransactionError | When the new transaction is not unreconciled. |
TransactionError | When the new transaction is for a currency that is unknown. |
number | The transaction number of the original transaction to replace. |
transaction | The new transaction that will replace the original one. |
void drn::accounting::GeneralLedger::unreconcile | ( | const std::set< TransactionNumber > & | txnNums | ) |
Marks all the transactions supplied as unreconciled.
Error | When a transaction number does not exist in the ledger books. |
txnNums | The numbers of the transactions to be unreconciled. |
void drn::accounting::GeneralLedger::unreconcile | ( | const TransactionNumber & | txnNum | ) |
Marks the transaction supplied as unreconciled.
Error | When the transaction number does not exist in the ledger books. |
txnNum | The number of the transaction to be unreconciled. |
void drn::accounting::GeneralLedger::unreconcile | ( | const TransactionNumber & | txnNum, |
const AccountNumber & | actNum ) |
Marks the transaction supplied as unreconciled.
TransactionError | When the transaction number does not exist in the ledger books. |
AccountError | When the account number does not exist in the ledger books. |
txnNum | The number of the transaction to be unreconciled. |
actNum | The number of the ledger account whose transaction should be cleared. |
|
friend |
Stream insertion operator for a human readable general ledger account.
o | The stream to insert the information into. |
la | The ledgers to generate the information for. |