DuxReiNummariae 1.1.0-alpha.19
Simple and powerful budgeting application
Loading...
Searching...
No Matches
drn::accounting::Transaction Class Referencefinal

Represents a financial transaction, typically involving the transfer of money between two accounts. More...

#include <Transaction.hpp>

Collaboration diagram for drn::accounting::Transaction:

Public Member Functions

 Transaction ()
 Default constructor with all values defaulted and the transaction status unreconciled.
 Transaction (const ::QDate &occurredOn)
 Basic date constructor. Useful for when constructing piece-wise. All other values are defaulted and the transaction status unreconciled.
 Transaction (const ::QDate &occurredOn, AccountNumber debiting, AccountNumber crediting, pecunia::Money amount, std::optional<::QString > description=std::nullopt, std::optional< TransactionNumber > id=std::nullopt, const TransactionStatuses &status=TransactionStatuses::Unreconciled)
 New transaction initialisation constructor.
 Transaction (const ::QDate &occurredOn, const AccountCode &debiting, const AccountCode &crediting, const pecunia::Money &amount, std::optional<::QString > description=std::nullopt, std::optional< TransactionNumber > id=std::nullopt, const TransactionStatuses &status=TransactionStatuses::Unreconciled)
 New transaction initialisation constructor.
 Transaction (const Transaction &)=default
 Transaction (Transaction &&) noexcept=default
const pecunia::Money & amount () const noexcept
 Retrieves the monetary value associated with the transaction.
void changeCredit (const AccountCode &code, const internal::AccountTransactionKey &allowed)
 Changes the crediting account code.
void changeDebit (const AccountCode &code, const internal::AccountTransactionKey &allowed)
 Changes the debiting account code.
void convertAmount (const pecunia::Currency &changeTo, const internal::AccountTransactionKey &allowed)
 Converts the transaction amount into a requested currency.
const AccountCodecrediting () const noexcept
 Retrieves the account code associated with the crediting side of the transaction.
const AccountCodedebiting () const noexcept
 Retrieves the account code associated with the debiting side of the transaction.
const std::optional<::QString > & description () const noexcept
 Retrieves the description associated with the transaction if available.
void markCleared ()
 Changes the transaction to have cleared the account.
void markReconciled ()
 Changes the transaction to have reconciled with the account.
void markUnreconciled ()
 Changes the transaction to have not cleared nor reconciled with the account.
const std::optional< TransactionNumber > & number () const noexcept
 Retrieves the current transaction number if it exists.
const ::QDate & occurredOn () const noexcept
 Retrieves the date when the transaction occurred.
bool operator!= (const Transaction &other) const noexcept=default
std::strong_ordering operator<=> (const Transaction &other) const noexcept
 Performs a three-way comparison between this transaction and another transaction.
Transactionoperator= (const Transaction &other)
 Assigns all attributes of another transaction to the current transaction.
Transactionoperator= (Transaction &&other) noexcept
 Transfers the state of another transaction object to the current object, ensuring the current object’s data reflects that of the source. This is useful for operations involving ownership transfer of resources from one transaction to another.
bool operator== (const Transaction &other) const noexcept
 Compares this transaction with another to determine if they are equal.
void setNumber (TransactionNumber value, const internal::AccountTransactionKey &allowed)
 Changes the number of the transaction. Once set it cannot be changed.
const TransactionStatusesstatus () const noexcept
 Retrieves the current state of the transaction regarding its reconciliation status.

Detailed Description

Represents a financial transaction, typically involving the transfer of money between two accounts.

This encapsulates all relevant details associated with a financial transaction, including the date of occurrence, the accounts involved (debited and credited), the amount transferred, a description of the transaction, its identifier if available, and its reconciliation status. This is immutable for most of its core attributes and is designed to safely manage essential transaction details. Mutation of the essential details is only allowed via a key enforced by the compiler.

Constructor & Destructor Documentation

◆ Transaction() [1/6]

drn::accounting::Transaction::Transaction ( )

Default constructor with all values defaulted and the transaction status unreconciled.

Here is the caller graph for this function:

◆ Transaction() [2/6]

drn::accounting::Transaction::Transaction ( const ::QDate & occurredOn)
explicit

Basic date constructor. Useful for when constructing piece-wise. All other values are defaulted and the transaction status unreconciled.

Parameters
occurredOnThe date the transaction occurred on.
Here is the call graph for this function:

◆ Transaction() [3/6]

drn::accounting::Transaction::Transaction ( const ::QDate & occurredOn,
const AccountCode & debiting,
const AccountCode & crediting,
const pecunia::Money & amount,
std::optional<::QString > description = std::nullopt,
std::optional< TransactionNumber > id = std::nullopt,
const TransactionStatuses & status = TransactionStatuses::Unreconciled )

New transaction initialisation constructor.

Exceptions
TransactionErrorWhen the transaction date is invalid.
TransactionErrorWhen the code of the debit account is the same as the code of the credit account.
TransactionErrorWhen the amount is less than zero.
Parameters
occurredOnThe date the Transaction occurred on.
debitingThe code of the account that is debited.
creditingThe code of the account that is credited.
amountThe amount of money applied to each account.
descriptionA human friendly description of the transaction.
idThe identifier for the transaction in the general ledger book iff its posted.
statusThe current status of the transaction.
Here is the call graph for this function:

◆ Transaction() [4/6]

drn::accounting::Transaction::Transaction ( const ::QDate & occurredOn,
AccountNumber debiting,
AccountNumber crediting,
pecunia::Money amount,
std::optional<::QString > description = std::nullopt,
std::optional< TransactionNumber > id = std::nullopt,
const TransactionStatuses & status = TransactionStatuses::Unreconciled )

New transaction initialisation constructor.

Exceptions
TransactionErrorWhen the transaction date is invalid.
TransactionErrorWhen the number of the debit account is the same as the number of the credit account.
TransactionErrorWhen the amount is less than zero.
Parameters
occurredOnThe date the Transaction occurred on.
debitingThe ledger number of the account that is debited.
creditingThe ledger number of the account that is credited.
amountThe amount of money applied to each account.
descriptionA human friendly description of the transaction.
idThe identifier for the transaction in the general ledger book iff its posted.
statusThe current status of the transaction.
Here is the call graph for this function:

◆ Transaction() [5/6]

drn::accounting::Transaction::Transaction ( const Transaction & )
default
Here is the call graph for this function:

◆ Transaction() [6/6]

drn::accounting::Transaction::Transaction ( Transaction && )
defaultnoexcept
Here is the call graph for this function:

Member Function Documentation

◆ amount()

const pecunia::Money & drn::accounting::Transaction::amount ( ) const
nodiscardnoexcept

Retrieves the monetary value associated with the transaction.

Returns
The monetary value of the transaction.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ changeCredit()

void drn::accounting::Transaction::changeCredit ( const AccountCode & code,
const internal::AccountTransactionKey & allowed )

Changes the crediting account code.

Exceptions
TransactionErrorWhen the new account code is the same as the debiting account.
Parameters
codeThe new account code.
allowedThe object that allows access to modifying the transaction.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ changeDebit()

void drn::accounting::Transaction::changeDebit ( const AccountCode & code,
const internal::AccountTransactionKey & allowed )

Changes the debiting account code.

Exceptions
TransactionErrorWhen the new account code is the same as the crediting account.
Parameters
codeThe new account code.
allowedThe object that allows access to modifying the transaction.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ convertAmount()

void drn::accounting::Transaction::convertAmount ( const pecunia::Currency & changeTo,
const internal::AccountTransactionKey & allowed )

Converts the transaction amount into a requested currency.

Exceptions
TransactionErrorWhen the currency of the amount is the same as the request currency.
Parameters
changeToThe currency to change the transaction into.
allowedThe object that allows access to modifying the transaction.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ crediting()

const AccountCode & drn::accounting::Transaction::crediting ( ) const
nodiscardnoexcept

Retrieves the account code associated with the crediting side of the transaction.

Returns
The account code representing the crediting part of the transaction.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ debiting()

const AccountCode & drn::accounting::Transaction::debiting ( ) const
nodiscardnoexcept

Retrieves the account code associated with the debiting side of the transaction.

Returns
The account code representing the debiting part of the transaction.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ description()

const std::optional<::QString > & drn::accounting::Transaction::description ( ) const
nodiscardnoexcept

Retrieves the description associated with the transaction if available.

This provides access to a textual description that explains the transaction. This description can be useful in providing contextual information for their purpose.

Returns
An optional value that holds the description of the transaction if one exists. If no description is available, the optional value will hold no data.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ markCleared()

void drn::accounting::Transaction::markCleared ( )

Changes the transaction to have cleared the account.

Exceptions
TransactionErrorWhen the transaction is already reconciled.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ markReconciled()

void drn::accounting::Transaction::markReconciled ( )

Changes the transaction to have reconciled with the account.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ markUnreconciled()

void drn::accounting::Transaction::markUnreconciled ( )

Changes the transaction to have not cleared nor reconciled with the account.

Exceptions
TransactionErrorWhen the transaction is already reconciled.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ number()

const std::optional< TransactionNumber > & drn::accounting::Transaction::number ( ) const
nodiscardnoexcept

Retrieves the current transaction number if it exists.

Returns
The optional transaction number associated with the transaction. If no transaction number has been associated, it returns an uninitialised optional state.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ occurredOn()

const ::QDate & drn::accounting::Transaction::occurredOn ( ) const
nodiscardnoexcept

Retrieves the date when the transaction occurred.

Returns
The date when the transaction took place.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator!=()

bool drn::accounting::Transaction::operator!= ( const Transaction & other) const
nodiscarddefaultnoexcept
Here is the call graph for this function:

◆ operator<=>()

std::strong_ordering drn::accounting::Transaction::operator<=> ( const Transaction & other) const
nodiscardnoexcept

Performs a three-way comparison between this transaction and another transaction.

The purpose is to determine the order of transactions based on a set of prioritised attributes such as status, number, etc. This is helpful in sorting, equality checks, and other operations requiring transactional order evaluation.

Parameters
otherThe transaction against which this transaction will be compared.
Returns
The result of the three-way comparison.
Here is the call graph for this function:

◆ operator=() [1/2]

Transaction & drn::accounting::Transaction::operator= ( const Transaction & other)

Assigns all attributes of another transaction to the current transaction.

This copies the details of another transaction into the current transaction. It ensures that the current transaction has identical properties to the other transaction.

Parameters
otherThe transaction whose attributes are to be assigned to the current transaction.
Postcondition
The current transaction object will have identical attributes to the other transaction object.
Returns
The updated current transaction object.
Here is the call graph for this function:

◆ operator=() [2/2]

Transaction & drn::accounting::Transaction::operator= ( Transaction && other)
noexcept

Transfers the state of another transaction object to the current object, ensuring the current object’s data reflects that of the source. This is useful for operations involving ownership transfer of resources from one transaction to another.

Parameters
otherThe source transaction object whose data will be transferred.
Postcondition
The current transaction object will have its state updated to match that of the source transaction object.
The source transaction object will be left in a valid but unspecified state.
Returns
The current transaction object with updated state.
Here is the call graph for this function:

◆ operator==()

bool drn::accounting::Transaction::operator== ( const Transaction & other) const
nodiscardnoexcept

Compares this transaction with another to determine if they are equal.

This method checks if two transactions are equivalent by comparing all their properties. It is useful for identifying whether two transactions represent the same entity, aiding in tasks such as deduplication, or validation within financial systems.

Parameters
otherThe transaction to be compared against.
Returns
True if the transactions are equivalent; otherwise, false.
Here is the call graph for this function:

◆ setNumber()

void drn::accounting::Transaction::setNumber ( TransactionNumber value,
const internal::AccountTransactionKey & allowed )

Changes the number of the transaction. Once set it cannot be changed.

Exceptions
TransactionErrorWhen the transaction number is already set.
Parameters
valueThe new unique identifier for the transaction in the accounting system.
allowedThe object that allows access to modify the transaction.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ status()

const TransactionStatuses & drn::accounting::Transaction::status ( ) const
nodiscardnoexcept

Retrieves the current state of the transaction regarding its reconciliation status.

Returns
The current reconciliation status of the transaction.
Here is the call graph for this function:
Here is the caller graph for this function: