GnuCashew ~ GnuCash Enabled Web
GCW
|
Account Register Model. More...
#include <AccountRegisterModel.h>
Inherits Wt::WStandardItemModel.
Public Types | |
enum class | ViewMode { BASIC_LEDGER , AUTOSPLIT_LEDGER , TRANSACTION_JOURNAL } |
Public Member Functions | |
AccountRegisterModel (const std::string &_accountGuid="", bool _editable=true) | |
ctor More... | |
auto | setAccountGuid (const std::string &_accountGuid) -> void |
auto | refreshFromDisk () -> void |
Refresh From Disk. More... | |
auto | saveToDisk () -> void |
auto | viewMode () const -> ViewMode |
auto | setViewMode (ViewMode _viewMode) -> void |
auto | doubleLine () const -> bool |
auto | setDoubleLine (bool _doubleLine) -> void |
auto | isDeletable (const Wt::WModelIndex &_index) -> bool |
Is Read Only. More... | |
auto | isEditable (int _row) -> bool |
auto | isEditable (const Wt::WModelIndex &_index) -> bool |
auto | getSplitGuid (const Wt::WModelIndex &_index) -> std::string |
Get GUID from row. More... | |
auto | getSplitGuid (int _row) -> std::string |
auto | getDate (const Wt::WModelIndex &_index) -> Wt::WDateTime |
Get Date from the index. More... | |
auto | getAction (const Wt::WModelIndex &_index) -> std::string |
Get Action. More... | |
auto | getDescription (const Wt::WModelIndex &_index) -> std::string |
Get Description. More... | |
auto | getTransferText (const Wt::WModelIndex &_index) -> std::string |
Get Transfer Account Text. More... | |
auto | getTransferGuid (const Wt::WModelIndex &_index) -> std::string |
Get Transfer Account GUID. More... | |
auto | getReconcile (const Wt::WModelIndex &_index) -> std::string |
Get Reconciliation. More... | |
auto | getNumeric (const Wt::WModelIndex &_index) -> GCW_NUMERIC |
Get numeric value. More... | |
auto | getDebit (const Wt::WModelIndex &_index) -> GCW_NUMERIC |
Get Debit value. More... | |
auto | getCredit (const Wt::WModelIndex &_index) -> GCW_NUMERIC |
Get Credit value. More... | |
auto | getValue (const Wt::WModelIndex &_index) -> GCW_NUMERIC |
Get Value (positive or negative) More... | |
auto | getBalance (const Wt::WModelIndex &_index) -> GCW_NUMERIC |
auto | present () const -> GCW_NUMERIC |
auto | future () const -> GCW_NUMERIC |
auto | cleared () const -> GCW_NUMERIC |
auto | reconciled () const -> GCW_NUMERIC |
auto | projected () const -> GCW_NUMERIC |
auto | makeRow (const std::string &_splitGuid) -> RowItem |
auto | suggestionsFromColumn (int _column) const -> std::set< std::string > |
Column Suggestions. More... | |
auto | setData (const Wt::WModelIndex &_index, const Wt::cpp17::any &_value, Wt::ItemDataRole _role) -> bool |
auto | goneDirty () -> Wt::Signal< Wt::WModelIndex > & |
Private Types | |
using | RowItem = std::vector< std::unique_ptr< Wt::WStandardItem > > |
using | ColItem = Wt::WStandardItem * |
Private Member Functions | |
auto | getString (const Wt::WModelIndex &_index, int column) -> std::string |
auto | saveToDisk (const Wt::WModelIndex &_index) -> void |
Private Attributes | |
Wt::Signal< Wt::WModelIndex > | m_goneDirty |
bool | m_editable = false |
Editable Indicator. More... | |
ViewMode | m_viewMode = ViewMode::BASIC_LEDGER |
bool | m_doubleLine = false |
std::string | m_accountGuid |
Account GUID. More... | |
std::string | m_lastDate |
GCW_NUMERIC | m_present |
GCW_NUMERIC | m_future |
GCW_NUMERIC | m_cleared |
GCW_NUMERIC | m_reconciled |
GCW_NUMERIC | m_projected |
Account Register Model.
This model is used to present account details to the 'editor register' (the spreadsheet-looing book-like-looking thing that the user posts transactions through.
Definition at line 21 of file AccountRegisterModel.h.
|
private |
Definition at line 25 of file AccountRegisterModel.h.
|
private |
Definition at line 24 of file AccountRegisterModel.h.
|
strong |
Enumerator | |
---|---|
BASIC_LEDGER | basic one-line per transaction |
AUTOSPLIT_LEDGER | one-line ledger that auto-opens to multi-line for each selected row |
TRANSACTION_JOURNAL | self explanatory |
Definition at line 29 of file AccountRegisterModel.h.
GCW::Eng::AccountRegisterModel::AccountRegisterModel | ( | const std::string & | _accountGuid = "" , |
bool | _editable = true |
||
) |
ctor
This opens the model associated with a specific account.
Definition at line 35 of file AccountRegisterModel.cpp.
References GCW::Gui::BillPay::asString(), GCW::Cfg::date_format(), m_lastDate, and refreshFromDisk().
|
inline |
Definition at line 168 of file AccountRegisterModel.h.
References m_cleared.
|
inline |
Definition at line 55 of file AccountRegisterModel.h.
References m_doubleLine.
|
inline |
Definition at line 167 of file AccountRegisterModel.h.
References m_future.
auto GCW::Eng::AccountRegisterModel::getAction | ( | const Wt::WModelIndex & | _index | ) | -> std::string |
auto GCW::Eng::AccountRegisterModel::getBalance | ( | const Wt::WModelIndex & | _index | ) | -> GCW_NUMERIC |
auto GCW::Eng::AccountRegisterModel::getCredit | ( | const Wt::WModelIndex & | _index | ) | -> GCW_NUMERIC |
auto GCW::Eng::AccountRegisterModel::getDate | ( | const Wt::WModelIndex & | _index | ) | -> Wt::WDateTime |
Get Date from the index.
This pulls the 'date' column out and returns it as a WDateTime value.
Definition at line 188 of file AccountRegisterModel.cpp.
References COL_DATE, GCW_DATE_DEFAULT_TIME, and GCW_DATE_FORMAT_DISPLAY.
auto GCW::Eng::AccountRegisterModel::getDebit | ( | const Wt::WModelIndex & | _index | ) | -> GCW_NUMERIC |
auto GCW::Eng::AccountRegisterModel::getDescription | ( | const Wt::WModelIndex & | _index | ) | -> std::string |
Get Description.
Definition at line 216 of file AccountRegisterModel.cpp.
References COL_DESCRIPTION.
auto GCW::Eng::AccountRegisterModel::getNumeric | ( | const Wt::WModelIndex & | _index | ) | -> GCW_NUMERIC |
Get numeric value.
This returns the numeric value of the line. This is suitable for querying either the debit or credit column values (and is really intended for internal use). The 'value' is pulled from the Display value of the index and converted to a GCW_NUMERIC value.
Definition at line 249 of file AccountRegisterModel.cpp.
References GCW::Gui::BillPay::asString(), and GCW_NUMERIC.
auto GCW::Eng::AccountRegisterModel::getReconcile | ( | const Wt::WModelIndex & | _index | ) | -> std::string |
Get Reconciliation.
Definition at line 241 of file AccountRegisterModel.cpp.
References COL_RECONCILE.
auto GCW::Eng::AccountRegisterModel::getSplitGuid | ( | const Wt::WModelIndex & | _index | ) | -> std::string |
Get GUID from row.
This will retrieve the GUID value from the row.
Definition at line 295 of file AccountRegisterModel.cpp.
References GCW::Gui::BillPay::asString(), and COL_DATE.
auto GCW::Eng::AccountRegisterModel::getSplitGuid | ( | int | _row | ) | -> std::string |
Definition at line 309 of file AccountRegisterModel.cpp.
References COL_DATE.
|
private |
Definition at line 174 of file AccountRegisterModel.cpp.
References GCW::Gui::BillPay::asString().
auto GCW::Eng::AccountRegisterModel::getTransferGuid | ( | const Wt::WModelIndex & | _index | ) | -> std::string |
Get Transfer Account GUID.
Definition at line 232 of file AccountRegisterModel.cpp.
References GCW::Dbo::Accounts::byFullName(), and GCW::Dbo::Accounts::Field::guid.
auto GCW::Eng::AccountRegisterModel::getTransferText | ( | const Wt::WModelIndex & | _index | ) | -> std::string |
Get Transfer Account Text.
Definition at line 224 of file AccountRegisterModel.cpp.
References COL_TRANSFER.
auto GCW::Eng::AccountRegisterModel::getValue | ( | const Wt::WModelIndex & | _index | ) | -> GCW_NUMERIC |
Get Value (positive or negative)
The value that gets stored in the back-end database is either positive for debit, and negative for credit. This function will read-out the debit and credit columns in the register display and figure out if the returned value should be returned positive or negative corrected.
This function always positive for debit, and negative for credit values.
Definition at line 280 of file AccountRegisterModel.cpp.
References GCW_NUMERIC.
|
inline |
Definition at line 186 of file AccountRegisterModel.h.
References m_goneDirty.
auto GCW::Eng::AccountRegisterModel::isDeletable | ( | const Wt::WModelIndex & | _index | ) | -> bool |
Is Read Only.
This returns .true. if the item can be deleted.
If this transaction split has no guid then it's a new row, and cannot be deleted
If this transaction split is reconciled, then it is considered not deletable
Definition at line 105 of file AccountRegisterModel.cpp.
References GCW::Dbo::Transactions::Manager::loadSplit(), and GCW::Dbo::Transactions::Manager::thisSplit().
auto GCW::Eng::AccountRegisterModel::isEditable | ( | const Wt::WModelIndex & | _index | ) | -> bool |
If this transaction split has no guid then it's a new row, and cannot be deleted
If this transaction split is reconciled, then it is considered not deletable
Definition at line 132 of file AccountRegisterModel.cpp.
References GCW::Dbo::Transactions::Manager::loadSplit(), and GCW::Dbo::Transactions::Manager::thisSplit().
auto GCW::Eng::AccountRegisterModel::isEditable | ( | int | _row | ) | -> bool |
Definition at line 159 of file AccountRegisterModel.cpp.
auto GCW::Eng::AccountRegisterModel::makeRow | ( | const std::string & | _splitGuid | ) | -> RowItem |
Definition at line 1266 of file AccountRegisterModel.cpp.
|
inline |
Definition at line 166 of file AccountRegisterModel.h.
References m_present.
|
inline |
Definition at line 170 of file AccountRegisterModel.h.
References m_projected.
|
inline |
Definition at line 169 of file AccountRegisterModel.h.
References m_reconciled.
auto GCW::Eng::AccountRegisterModel::refreshFromDisk | ( | ) | -> void |
Refresh From Disk.
This procedure reads from the gnucash storage source (either postgres or sqlite) and loads all of the transactions and their associated splits in to the model suitable for editing within an automatic table view.
Before refreshing from disk, the entire contents of the model are cleared, so it is important to make sure anything to be saved from the model should be done first.
In order to produce a proper 'register' of items, it is important to load the data from the 'splits' side of the transaction rather than the transaction itself.
Note that when the splits are loaded based on the account ID, they are returned in a std::vector(sorted_by_date) that is sorted based on the transction date. This chosen sort method insures that the running balance can be accurately calculated on the fly, since each item is pulled from the vector in a sorted order, and the running balance is included in the model row. The user can sort the user interface later and still have the line-item-balance remain accurate.
Each item is processed from the vector in sequential order. In this process we grab the contents of the split, and generate a model item row containing all of the column values. Maintain a running balance as we go along to keep the balance reflected within the view. The result is a multi-column row item that is added to the model. This allows the model to be subsequently re-sorted or subset-extracted without affecting the running balances and so forth.
From the initial split item, we get a handle on the transaction, and then load all of the other splits associated with this transaction.
The 'num' column is a simple text-column.
The 'description' column is a simple text-column.
The 'account' text depends on the target account defined in the split. There are three possibilities here;
The reconcile column is a simple text-column.
There are two 'types' of accounts; Debit/Credit. Gnucash stores split information as a single value that is positive or negative. If the value is positive, then it is posted to the debit (left) column. If the value is negative, it is posted to credit (right) column.
Depending on the account type (debit/credit), that value is then either 'added' or 'subtracted' from the account balance. If this is a 'credit' account, then the value is subtracted, and if it is a debit account, the value is added.
Therefore, if this is a credit account, such as a credit card, then a 'positive' value, posted to the debit column, would 'decrease' the balance in that account. Therefore, the value, being positive, is 'subtracted' from the running balance. If the value were negative, it would be posted to the credit column, and again would be 'subtracted' from the running balance, and a negative value being subtracted from a value causes the result to 'increase'.
If this is a debit account, such as a bank checking account, a 'positive' value, posted to the debit column (again), would 'increase' the balance in that account.
So, that's the funky GAAP math done here.
What follows is a pretty good explanation of the debit/credit stuff;
Debit/Credit is just Left/Right. Maybe this will help
(now, we'll once again, make all terms 'positive')Assets + Expenses = Liabilities + Equity + Income
And there, you have the full Accounting Equation with the five major account types that GnuCash uses.
In double-entry accounting, ALL transactions are in the form of: Debit = Credit Left = Right
The 'Debit' accounts (those that are normally (positive) a Debit balance, and increase with a Debit, decrease with a Credit) are on the left of the equation: Assets Expenses
The 'Credit' accounts (those that are normally (positive) a Credit balance, and increase with a Credit, decrease with a Debit) are those on the right of the equation: Liabilities Equity Income
A negative balance in any account would indicate either an entry error or a contra-balance situation. (rare for individuals)
You can move funds from the left to the right, or vice versa, or between any accounts or types on the same side of the equation. (I will use the abbreviations Dr. and Cr. here) Most texts will write transactions Debit first, then Credit as shown below. The amounts are not shown, because they must be equal.
*it is rare and unusual for an individual to shift Equity to Liabilities and vice versa. Forgiveness of Debt may in some jurisdictions be a transfer from Liabilities to Income.
Load everything blank (except for the memo)
After all the split items are loaded, an additional ~blank~ item is included at the end of the vector, for coding new entries.
poke all the header labels in. Note that some of the labels change depending on the account debit/credit type. We get those from the accountDef.
Definition at line 550 of file AccountRegisterModel.cpp.
References GCW::Dbo::Splits::byAccount(), GCW::Dbo::Accounts::byGuid(), GCW::Dbo::Splits::bySplit(), GCW::Dbo::Accounts::ACCOUNTDEF_S::colAccount, GCW::Dbo::Accounts::ACCOUNTDEF_S::colCr, GCW::Dbo::Accounts::ACCOUNTDEF_S::colDr, GCW::Dbo::Prefrences::CREDIT, GCW::Cfg::date_format(), GCW::Cfg::decimal_format(), GCW::Dbo::Accounts::Field::description, GCW::Dbo::Accounts::fullName(), GCW_NUMERIC, GCW::Dbo::Prefrences::get(), GCW::Dbo::Accounts::Field::guid, GCW::Dbo::Prefrences::INCOME_EXPENSE, GCW::Dbo::Accounts::Field::name, GCW::Dbo::Prefrences::NEGVAL_EXTRA, GCW::Dbo::Prefrences::NORMAL, GCW::Dbo::Accounts::s_accountDefs, GCW::Gui::BillPay::toString(), and TR.
Referenced by AccountRegisterModel().
auto GCW::Eng::AccountRegisterModel::saveToDisk | ( | ) | -> void |
Definition at line 166 of file AccountRegisterModel.cpp.
References FUNCTION_HEADER.
|
private |
Definition at line 317 of file AccountRegisterModel.cpp.
References COL_ACTION, COL_CREDIT, COL_DATE, COL_DEBIT, COL_DESCRIPTION, COL_NOTES, COL_RECONCILE, COL_TRANSFER, GCW::Dbo::Transactions::Manager::loadSplit(), GCW::Dbo::Transactions::Manager::newTransaction(), GCW::Dbo::Transactions::Manager::setAction(), GCW::Dbo::Transactions::Manager::setDate(), GCW::Dbo::Transactions::Manager::setDescription(), GCW::Dbo::Transactions::Manager::setNotes(), GCW::Dbo::Transactions::Manager::setReconcile(), GCW::Dbo::Transactions::Manager::setTransferGuid(), and GCW::Dbo::Transactions::Manager::setValue().
auto GCW::Eng::AccountRegisterModel::setAccountGuid | ( | const std::string & | _accountGuid | ) | -> void |
Definition at line 82 of file AccountRegisterModel.cpp.
auto GCW::Eng::AccountRegisterModel::setData | ( | const Wt::WModelIndex & | _index, |
const Wt::cpp17::any & | _value, | ||
Wt::ItemDataRole | _role | ||
) | -> bool |
Definition at line 421 of file AccountRegisterModel.cpp.
References GCW::Gui::BillPay::asString(), BREAKFOOTER, BREAKHEADER, COL_BALANCE, COL_DATE, and GCW::Dbo::Accounts::Field::name.
auto GCW::Eng::AccountRegisterModel::setDoubleLine | ( | bool | _doubleLine | ) | -> void |
Definition at line 98 of file AccountRegisterModel.cpp.
auto GCW::Eng::AccountRegisterModel::setViewMode | ( | ViewMode | _viewMode | ) | -> void |
Definition at line 91 of file AccountRegisterModel.cpp.
auto GCW::Eng::AccountRegisterModel::suggestionsFromColumn | ( | int | _column | ) | const -> std::set< std::string > |
Column Suggestions.
This produces a unique-set of items that represent all the text-values for that particular column. This is used to produce a suggestion-box for the register.
Definition at line 1276 of file AccountRegisterModel.cpp.
References GCW::Gui::BillPay::asString().
|
inline |
Definition at line 53 of file AccountRegisterModel.h.
References m_viewMode.
|
private |
Account GUID.
The model is associated with a single account.
Definition at line 255 of file AccountRegisterModel.h.
|
private |
Definition at line 266 of file AccountRegisterModel.h.
Referenced by cleared().
|
private |
Definition at line 247 of file AccountRegisterModel.h.
Referenced by doubleLine().
|
private |
Editable Indicator.
The model can be either R/W (read-write) or R/O (read-only).
Definition at line 244 of file AccountRegisterModel.h.
|
private |
Definition at line 265 of file AccountRegisterModel.h.
Referenced by future().
|
private |
Definition at line 230 of file AccountRegisterModel.h.
Referenced by goneDirty().
|
private |
Definition at line 262 of file AccountRegisterModel.h.
Referenced by AccountRegisterModel().
|
private |
Definition at line 264 of file AccountRegisterModel.h.
Referenced by present().
|
private |
Definition at line 268 of file AccountRegisterModel.h.
Referenced by projected().
|
private |
Definition at line 267 of file AccountRegisterModel.h.
Referenced by reconciled().
|
private |
Definition at line 246 of file AccountRegisterModel.h.
Referenced by viewMode().