GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
GCW::Eng::Transaction::Manager Class Reference

Transaction Manager. More...

#include <TransactionManager.h>

Public Types

using RowItem = std::vector< std::unique_ptr< Wt::WStandardItem > >
 
using TxItem = GCW::Dbo::Transactions::Item::Ptr
 
using SpItem = GCW::Dbo::Splits::Item::Ptr
 

Public Member Functions

 Manager ()
 
 Manager (Gui::AccountRegister::Model *_model)
 
auto model () const -> Gui::AccountRegister::Model *
 
auto loadTransaction (const std::string &_transactionGuid) -> void
 Set Transaction.
 
auto deleteTransaction () -> bool
 Delete Transaction.
 
auto setSplitItem (GCW::Dbo::Splits::Item::Ptr _splitItem) -> void
 
auto loadSplit (const std::string &_splitGuid) -> void
 Set Split.
 
auto sortSplits () -> void
 Sort Splits.
 
auto isBalanced () -> bool
 Is Transaction Balanced.
 
auto balanceValue () -> GCW_NUMERIC
 Balance Value.
 
auto newTransaction (const std::string &_accountGuid1, const std::string &_accountGuid2, const Wt::WDate &_date=Wt::WDate::currentDate(), GCW_NUMERIC _value=GCW_NUMERIC(0), const std::string &_description="") -> void
 New Transaction.
 
auto transactionItem () const -> GCW::Dbo::Transactions::Item::Ptr
 Transaction Item.
 
auto prefrenceItem () const -> const GCW::Dbo::Prefrences::Item &
 
auto splits () const -> GCW::Dbo::Splits::Item::Vector
 Splits Vector.
 
auto otherSplits () const -> GCW::Dbo::Splits::Item::Vector
 
auto otherGuid () const -> std::string
 Other GUID.
 
auto getDate () const -> Wt::WDateTime
 Set Date.
 
auto getDateAsString () const -> Wt::WString
 
auto setDate (const Wt::WDateTime &_value) -> void
 
auto setDate (const Wt::WDate &_value) -> void
 
auto setAction (const std::string &_value) -> void
 Set Action.
 
auto getDescription () const -> std::string
 Set Description.
 
auto setDescription (const std::string &_value) -> void
 
auto setDescription (const Wt::WString &_value) -> void
 
auto getNum () const -> std::string
 Set Num.
 
auto setNum (const std::string &_value) -> void
 
auto setNum (const Wt::WString &_value) -> void
 
auto setTransferGuid (const std::string &_value) -> void
 Set Transfer GUID.
 
auto setReconcile (const std::string &_value) -> void
 
auto getValue () const -> GCW_NUMERIC
 
auto getValueAsString () const -> std::string
 
auto setValue (GCW_NUMERIC _value) -> void
 
auto setValue (const std::string &_acctGuid, GCW_NUMERIC _value) -> void
 
auto setNotes (const std::string &_acctGuid, const std::string &_value) -> void
 
auto split (const std::string &_splitGuid) const -> GCW::Dbo::Splits::Item::Ptr
 
auto forAccountSplit (const std::string &_accountGuid) const -> GCW::Dbo::Splits::Item::Ptr
 Load Split for Account.
 
auto thisSplit () const -> GCW::Dbo::Splits::Item::Ptr
 
auto thatSplit () const -> GCW::Dbo::Splits::Item::Ptr
 
auto fromSplit () const -> GCW::Dbo::Splits::Item::Ptr
 
auto toSplit () const -> GCW::Dbo::Splits::Item::Ptr
 
auto getFromAccount () const -> std::string
 
auto getToAccount () const -> std::string
 
auto setReadOnly (bool _value) -> void
 
auto appendRow (bool _editable) -> void
 
auto appendEmptyRow (bool _editable) -> void
 
auto insertDoubleLine (int _row) -> void
 

Private Member Functions

auto highlightNegativeBalance (RowItem &_row) const -> void
 
auto flags (bool _editable) const -> Wt::WFlags< Wt::ItemFlag >
 
auto createText (const std::string &_text) const -> std::unique_ptr< Wt::WStandardItem >
 
auto createBlank () const -> std::unique_ptr< Wt::WStandardItem >
 
auto createEmpty () const -> std::unique_ptr< Wt::WStandardItem >
 
auto createDate (const TxItem &_txItem, bool _editable) const -> std::unique_ptr< Wt::WStandardItem >
 
auto createNum (const TxItem &_txItem, bool _editable) const -> std::unique_ptr< Wt::WStandardItem >
 
auto createNum (const SpItem &_spItem, bool _editable) const -> std::unique_ptr< Wt::WStandardItem >
 
auto createDescription (const TxItem &_txItem, bool _editable) const -> std::unique_ptr< Wt::WStandardItem >
 
auto createDescription (const SpItem &_spItem, bool _editable) const -> std::unique_ptr< Wt::WStandardItem >
 
auto createAccount (const SpItem &_spItem, bool _editable) const -> std::unique_ptr< Wt::WStandardItem >
 
auto createReconcile (const SpItem &_spItem, bool _editable) const -> std::unique_ptr< Wt::WStandardItem >
 
auto createDebit (const SpItem &_spItem, bool _editable) const -> std::unique_ptr< Wt::WStandardItem >
 
auto createCredit (const SpItem &_spItem, bool _editable) const -> std::unique_ptr< Wt::WStandardItem >
 
auto createBalance () const -> std::unique_ptr< Wt::WStandardItem >
 
auto appendBasicLedger (bool _editable) const -> void
 
auto appendAutosplitLedger (bool _editable) const -> void
 
auto appendTransactionJournal (bool _editable) const -> void
 
auto appendGeneralJournal (bool _editable) const -> void
 

Private Attributes

Gui::AccountRegister::Modelm_model = nullptr
 
Wt::WModelIndex m_index
 
std::string m_splitGuid
 
GCW::Dbo::Transactions::Item::Ptr m_transactionItem
 
GCW::Dbo::Prefrences::Item m_prefrenceItem
 
GCW::Dbo::Splits::Item::Vector m_splits
 

Detailed Description

Transaction Manager.

This is a convenience class for grouping all the transaction manipulation tasks in to one place. It allows new transactions to be created, and takes care of insuring that the transaction is always in balance, and always contains the requisite debits and credits to insure a properly balanced transaction.

The Transaction Manager is a 'friend' class to the AccountRegisterModel. This allows the manager to poke directly in to the model and manipulate it.

Definition at line 36 of file TransactionManager.h.

Member Typedef Documentation

◆ RowItem

using GCW::Eng::Transaction::Manager::RowItem = std::vector< std::unique_ptr< Wt::WStandardItem > >

Definition at line 40 of file TransactionManager.h.

◆ SpItem

Definition at line 42 of file TransactionManager.h.

◆ TxItem

Definition at line 41 of file TransactionManager.h.

Constructor & Destructor Documentation

◆ Manager() [1/2]

GCW::Eng::Transaction::Manager::Manager ( )

Definition at line 7 of file TransactionManager.cpp.

◆ Manager() [2/2]

GCW::Eng::Transaction::Manager::Manager ( Gui::AccountRegister::Model _model)

Definition at line 14 of file TransactionManager.cpp.

Member Function Documentation

◆ appendAutosplitLedger()

auto GCW::Eng::Transaction::Manager::appendAutosplitLedger ( bool  _editable) const -> void
private

Definition at line 940 of file TransactionManager.cpp.

◆ appendBasicLedger()

auto GCW::Eng::Transaction::Manager::appendBasicLedger ( bool  _editable) const -> void
private

Definition at line 909 of file TransactionManager.cpp.

References GCW_RECONCILE_NO.

◆ appendEmptyRow()

auto GCW::Eng::Transaction::Manager::appendEmptyRow ( bool  _editable) -> void

◆ appendGeneralJournal()

auto GCW::Eng::Transaction::Manager::appendGeneralJournal ( bool  _editable) const -> void
private

Definition at line 1000 of file TransactionManager.cpp.

◆ appendRow()

auto GCW::Eng::Transaction::Manager::appendRow ( bool  _editable) -> void

◆ appendTransactionJournal()

auto GCW::Eng::Transaction::Manager::appendTransactionJournal ( bool  _editable) const -> void
private

Definition at line 946 of file TransactionManager.cpp.

References GCW_RECONCILE_NO.

◆ balanceValue()

auto GCW::Eng::Transaction::Manager::balanceValue ( ) -> GCW_NUMERIC

Balance Value.

This checks the splits on the transaction and returns the 'balance value' which should be zero when the transaction is in balance.

see; gnucash/libgnucash/engine/Transaction.cpp:1030

◆ createAccount()

auto GCW::Eng::Transaction::Manager::createAccount ( const SpItem _spItem,
bool  _editable 
) const -> std::unique_ptr< Wt::WStandardItem >
private
Another Imbalance
This is another problem... We have another split, but the account we are split-to doesn't exist. This is a problem and should not happen and represents an error in the database. This means the account containing this guid nolonger exists. That should never happen.

Definition at line 742 of file TransactionManager.cpp.

References Wt::WString::arg(), GCW::Dbo::Accounts::byGuid(), GCW::Dbo::Accounts::fullName(), Wt::WString::toUTF8(), and TR.

◆ createBalance()

auto GCW::Eng::Transaction::Manager::createBalance ( ) const -> std::unique_ptr< Wt::WStandardItem >
private

Definition at line 867 of file TransactionManager.cpp.

References GCW::Cfg::decimal_format().

◆ createBlank()

auto GCW::Eng::Transaction::Manager::createBlank ( ) const -> std::unique_ptr< Wt::WStandardItem >
private

Definition at line 463 of file TransactionManager.cpp.

◆ createCredit()

auto GCW::Eng::Transaction::Manager::createCredit ( const SpItem _spItem,
bool  _editable 
) const -> std::unique_ptr< Wt::WStandardItem >
private

Definition at line 841 of file TransactionManager.cpp.

◆ createDate()

auto GCW::Eng::Transaction::Manager::createDate ( const TxItem _txItem,
bool  _editable 
) const -> std::unique_ptr< Wt::WStandardItem >
private
Note
The post_date column (col-0) also carries with it the guid of the split item itself, so that the originating split can be located from the table view. The guid can be accessed by;
Wt::WString splitRowGuid = Wt::asString( standardItem.data( Wt::ItemDataRole::User ) )
static constexpr const int User
WString asString(const cpp17::any &v, const WString &formatString=WString())
See also
getSplitGuid

Definition at line 489 of file TransactionManager.cpp.

References Wt::WDate::currentDate(), Wt::ItemDataRole::Edit, GCW_DATE_DEFAULT_TIME, and Wt::ItemDataRole::User.

◆ createDebit()

auto GCW::Eng::Transaction::Manager::createDebit ( const SpItem _spItem,
bool  _editable 
) const -> std::unique_ptr< Wt::WStandardItem >
private

Definition at line 818 of file TransactionManager.cpp.

◆ createDescription() [1/2]

auto GCW::Eng::Transaction::Manager::createDescription ( const SpItem _spItem,
bool  _editable 
) const -> std::unique_ptr< Wt::WStandardItem >
private

Definition at line 612 of file TransactionManager.cpp.

◆ createDescription() [2/2]

auto GCW::Eng::Transaction::Manager::createDescription ( const TxItem _txItem,
bool  _editable 
) const -> std::unique_ptr< Wt::WStandardItem >
private

Definition at line 591 of file TransactionManager.cpp.

◆ createEmpty()

auto GCW::Eng::Transaction::Manager::createEmpty ( ) const -> std::unique_ptr< Wt::WStandardItem >
private

Definition at line 476 of file TransactionManager.cpp.

◆ createNum() [1/2]

auto GCW::Eng::Transaction::Manager::createNum ( const SpItem _spItem,
bool  _editable 
) const -> std::unique_ptr< Wt::WStandardItem >
private

Definition at line 570 of file TransactionManager.cpp.

◆ createNum() [2/2]

auto GCW::Eng::Transaction::Manager::createNum ( const TxItem _txItem,
bool  _editable 
) const -> std::unique_ptr< Wt::WStandardItem >
private

Definition at line 549 of file TransactionManager.cpp.

◆ createReconcile()

auto GCW::Eng::Transaction::Manager::createReconcile ( const SpItem _spItem,
bool  _editable 
) const -> std::unique_ptr< Wt::WStandardItem >
private

Definition at line 801 of file TransactionManager.cpp.

◆ createText()

auto GCW::Eng::Transaction::Manager::createText ( const std::string &  _text) const -> std::unique_ptr< Wt::WStandardItem >
private

Definition at line 450 of file TransactionManager.cpp.

◆ deleteTransaction()

auto GCW::Eng::Transaction::Manager::deleteTransaction ( ) -> bool

Delete Transaction.

This insures all splits and any other data associated with the transaction is properly removed.

Definition at line 110 of file TransactionManager.cpp.

References GCW::app().

◆ flags()

auto GCW::Eng::Transaction::Manager::flags ( bool  _editable) const -> Wt::WFlags< Wt::ItemFlag >
private

Definition at line 435 of file TransactionManager.cpp.

References Wt::DeferredToolTip, Wt::Editable, and Wt::Selectable.

◆ forAccountSplit()

auto GCW::Eng::Transaction::Manager::forAccountSplit ( const std::string &  _accountGuid) const -> GCW::Dbo::Splits::Item::Ptr

Load Split for Account.

When we know the account guid, this will fetch the associated split

Note
this assumes an account only has a single split

Definition at line 248 of file TransactionManager.cpp.

References split().

◆ fromSplit()

auto GCW::Eng::Transaction::Manager::fromSplit ( ) const -> GCW::Dbo::Splits::Item::Ptr

Definition at line 199 of file TransactionManager.cpp.

References split().

◆ getDate()

auto GCW::Eng::Transaction::Manager::getDate ( ) const -> Wt::WDateTime

Set Date.

This sets the date on the Transaction of the element.

Definition at line 262 of file TransactionManager.cpp.

◆ getDateAsString()

auto GCW::Eng::Transaction::Manager::getDateAsString ( ) const -> Wt::WString

Definition at line 270 of file TransactionManager.cpp.

References GCW_DATE_FORMAT_DISPLAY.

◆ getDescription()

auto GCW::Eng::Transaction::Manager::getDescription ( ) const -> std::string

Set Description.

This sets the description on the Transaction of the element.

Definition at line 307 of file TransactionManager.cpp.

◆ getFromAccount()

auto GCW::Eng::Transaction::Manager::getFromAccount ( ) const -> std::string

Definition at line 225 of file TransactionManager.cpp.

References GCW::Dbo::Accounts::fullName(), and TR8.

◆ getNum()

auto GCW::Eng::Transaction::Manager::getNum ( ) const -> std::string

Set Num.

On the Transaction, the 'num' is the action field, on the splits it is the action value. So, in transaction it's called 'num' and in the splits it's called 'action'.

Definition at line 332 of file TransactionManager.cpp.

◆ getToAccount()

auto GCW::Eng::Transaction::Manager::getToAccount ( ) const -> std::string

Definition at line 236 of file TransactionManager.cpp.

References GCW::Dbo::Accounts::fullName(), and TR8.

◆ getValue()

auto GCW::Eng::Transaction::Manager::getValue ( ) const -> GCW_NUMERIC

Definition at line 375 of file TransactionManager.cpp.

◆ getValueAsString()

auto GCW::Eng::Transaction::Manager::getValueAsString ( ) const -> std::string

Definition at line 383 of file TransactionManager.cpp.

◆ highlightNegativeBalance()

auto GCW::Eng::Transaction::Manager::highlightNegativeBalance ( RowItem _row) const -> void
private

◆ insertDoubleLine()

auto GCW::Eng::Transaction::Manager::insertDoubleLine ( int  _row) -> void

◆ isBalanced()

auto GCW::Eng::Transaction::Manager::isBalanced ( ) -> bool

Is Transaction Balanced.

This checks the transaction and indicates if it is in balance or not.

see; gnucash/libgnucash/engine/Transaction.cpp:1030

◆ loadSplit()

auto GCW::Eng::Transaction::Manager::loadSplit ( const std::string &  _splitGuid) -> void

Set Split.

Set transaction based on any one of the splits.

This will load the split, then load the transaction for that split, causing all the other splits to load.

Definition at line 135 of file TransactionManager.cpp.

References GCW::Dbo::Splits::load().

Referenced by GCW::Gui::AccountRegister::Model::saveToDisk().

◆ loadTransaction()

auto GCW::Eng::Transaction::Manager::loadTransaction ( const std::string &  _transactionGuid) -> void

Set Transaction.

Set transaction based on the transaction Guid. This will load the transaction as well as all the splits associated with it.

Definition at line 94 of file TransactionManager.cpp.

References GCW::Dbo::Splits::byTransaction(), and GCW::Dbo::Transactions::load().

◆ model()

auto GCW::Eng::Transaction::Manager::model ( ) const -> Gui::AccountRegister::Model *
inline

Definition at line 47 of file TransactionManager.h.

References m_model.

◆ newTransaction()

auto GCW::Eng::Transaction::Manager::newTransaction ( const std::string &  _accountGuid1,
const std::string &  _accountGuid2,
const Wt::WDate _date = Wt::WDate::currentDate(),
GCW_NUMERIC  _value = GCW_NUMERIC(0),
const std::string &  _description = "" 
) -> void

New Transaction.

This will create a new Transaction for an account within the system fully populated with at least two splits.

The process begins by loading up the two accounts.

Todo:
query why qty used here

this transaction posting shows that .value. as well as .quantity. are set at the same time. If .quantity. is not set, then when re-opening the sql file in gnucash native causes the gnucash to take a very long time to load. This only happens once, and upon examining the database afterwords, all the splits have the same .value. set to .quantity. So, some sort of massive update is happening there on file-open. Therefore, we will set .quantity. along with .value. Doing so seems to mitigate the long/slow load time.

Definition at line 23 of file TransactionManager.cpp.

References GCW::Dbo::Splits::add(), GCW::Dbo::Transactions::add(), GCW::app(), Wt::WDate::currentDate(), GCW_DEFAULT_DATE, GCW_RECONCILE_NO, GCW::Dbo::Accounts::load(), and GCW::Core::newGuid().

Referenced by GCW::Gui::BillPay::PaymentWidget::saveData(), and GCW::Gui::AccountRegister::Model::saveToDisk().

◆ otherGuid()

auto GCW::Eng::Transaction::Manager::otherGuid ( ) const -> std::string

Other GUID.

When there are only two splits, this will return the guid of the split item that does not match the guid provided.

Definition at line 159 of file TransactionManager.cpp.

◆ otherSplits()

auto GCW::Eng::Transaction::Manager::otherSplits ( ) const -> GCW::Dbo::Splits::Item::Vector

Definition at line 420 of file TransactionManager.cpp.

References GCW::Dbo::Splits::bySplitExcept().

◆ prefrenceItem()

auto GCW::Eng::Transaction::Manager::prefrenceItem ( ) const -> const GCW::Dbo::Prefrences::Item &
inline

Definition at line 119 of file TransactionManager.h.

References m_prefrenceItem.

◆ setAction()

auto GCW::Eng::Transaction::Manager::setAction ( const std::string &  _value) -> void

Set Action.

This sets the Action on the split. The 'action' is stored in the Split item and this function will apply the value to both sides of the split.

Definition at line 298 of file TransactionManager.cpp.

References GCW::app().

Referenced by GCW::Gui::AccountRegister::Model::saveToDisk().

◆ setDate() [1/2]

auto GCW::Eng::Transaction::Manager::setDate ( const Wt::WDate _value) -> void

Definition at line 287 of file TransactionManager.cpp.

References GCW::app().

◆ setDate() [2/2]

auto GCW::Eng::Transaction::Manager::setDate ( const Wt::WDateTime _value) -> void

◆ setDescription() [1/2]

auto GCW::Eng::Transaction::Manager::setDescription ( const std::string &  _value) -> void

◆ setDescription() [2/2]

auto GCW::Eng::Transaction::Manager::setDescription ( const Wt::WString _value) -> void

Definition at line 324 of file TransactionManager.cpp.

◆ setNotes()

auto GCW::Eng::Transaction::Manager::setNotes ( const std::string &  _acctGuid,
const std::string &  _value 
) -> void

◆ setNum() [1/2]

auto GCW::Eng::Transaction::Manager::setNum ( const std::string &  _value) -> void

Definition at line 340 of file TransactionManager.cpp.

References GCW::app().

Referenced by GCW::Gui::BillPay::PaymentWidget::saveData().

◆ setNum() [2/2]

auto GCW::Eng::Transaction::Manager::setNum ( const Wt::WString _value) -> void

Definition at line 349 of file TransactionManager.cpp.

◆ setReadOnly()

auto GCW::Eng::Transaction::Manager::setReadOnly ( bool  _value) -> void

Definition at line 428 of file TransactionManager.cpp.

◆ setReconcile()

auto GCW::Eng::Transaction::Manager::setReconcile ( const std::string &  _value) -> void

Definition at line 366 of file TransactionManager.cpp.

References GCW::app().

Referenced by GCW::Gui::AccountRegister::Model::saveToDisk().

◆ setSplitItem()

auto GCW::Eng::Transaction::Manager::setSplitItem ( GCW::Dbo::Splits::Item::Ptr  _splitItem) -> void

◆ setTransferGuid()

auto GCW::Eng::Transaction::Manager::setTransferGuid ( const std::string &  _value) -> void

Set Transfer GUID.

This sets the (other) split (identified by guid) to the account given.

Definition at line 357 of file TransactionManager.cpp.

References GCW::app().

Referenced by GCW::Gui::AccountRegister::Model::saveToDisk().

◆ setValue() [1/2]

auto GCW::Eng::Transaction::Manager::setValue ( const std::string &  _acctGuid,
GCW_NUMERIC  _value 
) -> void

Definition at line 401 of file TransactionManager.cpp.

References GCW::app().

◆ setValue() [2/2]

auto GCW::Eng::Transaction::Manager::setValue ( GCW_NUMERIC  _value) -> void

◆ sortSplits()

auto GCW::Eng::Transaction::Manager::sortSplits ( ) -> void

Sort Splits.

Sorts first Debits, then Credits

◆ split()

auto GCW::Eng::Transaction::Manager::split ( const std::string &  _splitGuid) const -> GCW::Dbo::Splits::Item::Ptr

Definition at line 171 of file TransactionManager.cpp.

◆ splits()

auto GCW::Eng::Transaction::Manager::splits ( ) const -> GCW::Dbo::Splits::Item::Vector
inline

Splits Vector.

This returns the splits vector

Definition at line 126 of file TransactionManager.h.

References m_splits.

◆ thatSplit()

auto GCW::Eng::Transaction::Manager::thatSplit ( ) const -> GCW::Dbo::Splits::Item::Ptr

Definition at line 191 of file TransactionManager.cpp.

References split().

◆ thisSplit()

auto GCW::Eng::Transaction::Manager::thisSplit ( ) const -> GCW::Dbo::Splits::Item::Ptr

Definition at line 183 of file TransactionManager.cpp.

References split().

◆ toSplit()

auto GCW::Eng::Transaction::Manager::toSplit ( ) const -> GCW::Dbo::Splits::Item::Ptr

Definition at line 213 of file TransactionManager.cpp.

References split().

◆ transactionItem()

auto GCW::Eng::Transaction::Manager::transactionItem ( ) const -> GCW::Dbo::Transactions::Item::Ptr
inline

Transaction Item.

This returns the transaction pointer object

Definition at line 118 of file TransactionManager.h.

References m_transactionItem.

Referenced by GCW::Gui::AccountRegister::Model::refreshFromDisk().

Member Data Documentation

◆ m_index

Wt::WModelIndex GCW::Eng::Transaction::Manager::m_index
private

Definition at line 264 of file TransactionManager.h.

◆ m_model

Gui::AccountRegister::Model* GCW::Eng::Transaction::Manager::m_model = nullptr
private

Definition at line 263 of file TransactionManager.h.

Referenced by model().

◆ m_prefrenceItem

GCW::Dbo::Prefrences::Item GCW::Eng::Transaction::Manager::m_prefrenceItem
private

Definition at line 267 of file TransactionManager.h.

Referenced by prefrenceItem().

◆ m_splitGuid

std::string GCW::Eng::Transaction::Manager::m_splitGuid
private

Definition at line 265 of file TransactionManager.h.

◆ m_splits

GCW::Dbo::Splits::Item::Vector GCW::Eng::Transaction::Manager::m_splits
private

Definition at line 268 of file TransactionManager.h.

Referenced by splits().

◆ m_transactionItem

GCW::Dbo::Transactions::Item::Ptr GCW::Eng::Transaction::Manager::m_transactionItem
private

Definition at line 266 of file TransactionManager.h.

Referenced by transactionItem().


The documentation for this class was generated from the following files: