GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
TransactionManager.h
Go to the documentation of this file.
1#line 2 "src/Eng/TransactionManager.h"
2
3#ifndef __ENG_TRANSACTIONMANAGER_H___
4#define __ENG_TRANSACTIONMANAGER_H___
5
6#include "../Dbo/Accounts/Accounts.h"
7#include "../Dbo/Prefrences.h"
8#include "../Dbo/Splits/Splits.h"
9#include "../Dbo/Transactions/Transactions.h"
10
11/*
12** Now we can start building our class!
13**
14*/
15namespace GCW {
16 namespace Gui {
17 namespace AccountRegister {
18 class Model ;
19 }
20 }
21 namespace Eng {
22 namespace Transaction {
23
24/*!
25** \brief Transaction Manager
26**
27** This is a convenience class for grouping all the transaction manipulation tasks in to one place.
28** It allows new transactions to be created, and takes care of insuring that the transaction is
29** always in balance, and always contains the requisite debits and credits to insure a properly
30** balanced transaction.
31**
32** The Transaction Manager is a 'friend' class to the AccountRegisterModel. This allows the manager
33** to poke directly in to the model and manipulate it.
34**
35*/
37{
38 public:
39
40 using RowItem = std::vector< std::unique_ptr< Wt::WStandardItem > > ;
43
44 Manager();
46
47 auto model() const-> Gui::AccountRegister::Model * { return m_model ; }
48
49 /*!
50 ** \brief Set Transaction
51 **
52 ** Set transaction based on the transaction Guid. This will load
53 ** the transaction as well as all the splits associated with it.
54 */
55 auto loadTransaction( const std::string & _transactionGuid )-> void ;
56
57 /*!
58 ** \brief Delete Transaction
59 **
60 ** This insures all splits and any other data associated with the
61 ** transaction is properly removed.
62 */
63 auto deleteTransaction()-> bool ;
64
65 auto setSplitItem( GCW::Dbo::Splits::Item::Ptr _splitItem )-> void ;
66
67 /*!
68 ** \brief Set Split
69 **
70 ** Set transaction based on any one of the splits.
71 **
72 ** This will load the split, then load the transaction for that split,
73 ** causing all the other splits to load.
74 */
75 auto loadSplit( const std::string & _splitGuid )-> void ;
76
77 /*!
78 ** \brief Sort Splits
79 **
80 ** Sorts first Debits, then Credits
81 */
82 auto sortSplits()-> void ;
83
84 /*!
85 ** \brief Is Transaction Balanced
86 **
87 ** This checks the transaction and indicates if it is in
88 ** balance or not.
89 **
90 ** \ref see; gnucash/libgnucash/engine/Transaction.cpp:1030
91 */
92 auto isBalanced()-> bool ;
93
94 /*!
95 ** \brief Balance Value
96 **
97 ** This checks the splits on the transaction and returns
98 ** the 'balance value' which should be zero when the
99 ** transaction is in balance.
100 **
101 ** \ref see; gnucash/libgnucash/engine/Transaction.cpp:1030
102 */
104
105 /*!
106 ** \brief New Transaction
107 **
108 ** This will create a new Transaction for an account within the
109 ** system fully populated with at least two splits.
110 */
111 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 ;
112
113 /*!
114 ** \brief Transaction Item
115 **
116 ** This returns the transaction pointer object
117 */
118 auto transactionItem() const-> GCW::Dbo::Transactions::Item::Ptr { return m_transactionItem; }
119 auto prefrenceItem() const-> const GCW::Dbo::Prefrences::Item & { return m_prefrenceItem; }
120
121 /*!
122 ** \brief Splits Vector
123 **
124 ** This returns the splits vector
125 */
126 auto splits() const-> GCW::Dbo::Splits::Item::Vector { return m_splits; }
127
128 auto otherSplits() const-> GCW::Dbo::Splits::Item::Vector ;
129
130 /*!
131 ** \brief Other GUID
132 **
133 ** When there are only two splits, this will return the guid of the
134 ** split item that _does not_ match the guid provided.
135 */
136 auto otherGuid() const-> std::string ;
137
138 /*!
139 ** \brief Set Date
140 **
141 ** This sets the date on the Transaction of the element.
142 */
143 auto getDate() const-> Wt::WDateTime ;
144 auto getDateAsString() const-> Wt::WString ;
145 auto setDate( const Wt::WDateTime & _value )-> void ;
146 auto setDate( const Wt::WDate & _value )-> void ;
147
148 /*!
149 ** \brief Set Action
150 **
151 ** This sets the Action on the split. The 'action' is stored in
152 ** the Split item and this function will apply the value to
153 ** both sides of the split.
154 */
155 auto setAction( const std::string & _value )-> void ;
156
157 /*!
158 ** \brief Set Description
159 **
160 ** This sets the description on the Transaction of the element.
161 */
162 auto getDescription() const-> std::string ;
163 auto setDescription( const std::string & _value )-> void ;
164 auto setDescription( const Wt::WString & _value )-> void ;
165
166 /*!
167 ** \brief Set Num
168 **
169 ** On the Transaction, the 'num' is the action field, on the splits
170 ** it is the action value. So, in transaction it's called 'num' and
171 ** in the splits it's called 'action'.
172 */
173 auto getNum() const-> std::string ;
174 auto setNum( const std::string & _value )-> void ;
175 auto setNum( const Wt::WString & _value )-> void ;
176
177 /*!
178 ** \brief Set Transfer GUID
179 **
180 ** This sets the (other) split (identified by guid) to the account
181 ** given.
182 */
183 auto setTransferGuid( const std::string & _value )-> void ;
184
185 /*!
186 ** \brief
187 **
188 **
189 */
190 auto setReconcile( const std::string & _value )-> void ;
191
192 /*!
193 ** \brief
194 **
195 **
196 */
197 auto getValue() const-> GCW_NUMERIC ;
198 auto getValueAsString() const-> std::string ;
199 auto setValue( GCW_NUMERIC _value )-> void ;
200 auto setValue( const std::string & _acctGuid, GCW_NUMERIC _value )-> void ;
201
202 /*!
203 ** \brief
204 **
205 **
206 */
207 auto setNotes( const std::string & _acctGuid, const std::string & _value )-> void ;
208
209 auto split( const std::string & _splitGuid ) const-> GCW::Dbo::Splits::Item::Ptr ;
210
211 /*!
212 ** \brief Load Split for Account
213 **
214 ** When we know the account guid, this will fetch the associated split
215 **
216 ** \note this assumes an account only has a single split
217 */
218 auto forAccountSplit( const std::string & _accountGuid ) const-> GCW::Dbo::Splits::Item::Ptr ;
219
220 auto thisSplit() const-> GCW::Dbo::Splits::Item::Ptr ;
221 auto thatSplit() const-> GCW::Dbo::Splits::Item::Ptr ;
222
223 auto fromSplit() const-> GCW::Dbo::Splits::Item::Ptr ;
224 auto toSplit() const-> GCW::Dbo::Splits::Item::Ptr ;
225
226 auto getFromAccount() const-> std::string ;
227 auto getToAccount() const-> std::string ;
228
229 auto setReadOnly( bool _value )-> void ;
230
231 /*
232 ** append the row to the model
233 */
234 auto appendRow( bool _editable )-> void ;
235 auto appendEmptyRow( bool _editable )-> void ;
236 auto insertDoubleLine( int _row )-> void ;
237
238 private:
239
240 auto highlightNegativeBalance( RowItem & _row ) const-> void ;
241
242 auto flags( bool _editable ) const-> Wt::WFlags< Wt::ItemFlag > ;
243
244 auto createText ( const std::string & _text ) const-> std::unique_ptr< Wt::WStandardItem > ;
245 auto createBlank ( ) const-> std::unique_ptr< Wt::WStandardItem > ;
246 auto createEmpty ( ) const-> std::unique_ptr< Wt::WStandardItem > ;
247 auto createDate ( const TxItem & _txItem, bool _editable ) const-> std::unique_ptr< Wt::WStandardItem > ;
248 auto createNum ( const TxItem & _txItem, bool _editable ) const-> std::unique_ptr< Wt::WStandardItem > ;
249 auto createNum ( const SpItem & _spItem, bool _editable ) const-> std::unique_ptr< Wt::WStandardItem > ;
250 auto createDescription ( const TxItem & _txItem, bool _editable ) const-> std::unique_ptr< Wt::WStandardItem > ;
251 auto createDescription ( const SpItem & _spItem, bool _editable ) const-> std::unique_ptr< Wt::WStandardItem > ;
252 auto createAccount ( const SpItem & _spItem, bool _editable ) const-> std::unique_ptr< Wt::WStandardItem > ;
253 auto createReconcile ( const SpItem & _spItem, bool _editable ) const-> std::unique_ptr< Wt::WStandardItem > ;
254 auto createDebit ( const SpItem & _spItem, bool _editable ) const-> std::unique_ptr< Wt::WStandardItem > ;
255 auto createCredit ( const SpItem & _spItem, bool _editable ) const-> std::unique_ptr< Wt::WStandardItem > ;
256 auto createBalance ( ) const-> std::unique_ptr< Wt::WStandardItem > ;
257
258 auto appendBasicLedger ( bool _editable ) const-> void ;
259 auto appendAutosplitLedger ( bool _editable ) const-> void ;
260 auto appendTransactionJournal ( bool _editable ) const-> void ;
261 auto appendGeneralJournal ( bool _editable ) const-> void ;
262
263 Gui::AccountRegister::Model * m_model = nullptr ;
264 Wt::WModelIndex m_index ;
265 std::string m_splitGuid ;
266 GCW::Dbo:: Transactions ::Item::Ptr m_transactionItem ;
267 GCW::Dbo:: Prefrences ::Item m_prefrenceItem ;
268 GCW::Dbo:: Splits ::Item::Vector m_splits ;
269
270}; // endclass Manager
271
272 } // namespace Transaction {
273 } // namespace Eng {
274} // namespace GCW {
275
276#endif // #ifndef __ENG_TRANSACTIONMANAGER_H___
277
278
Wt::Dbo::ptr< Item > Ptr
Definition BaseItem.h:39
Wt::Dbo::ptr< Item > Ptr
auto createBalance() const -> std::unique_ptr< Wt::WStandardItem >
auto highlightNegativeBalance(RowItem &_row) const -> void
auto isBalanced() -> bool
Is Transaction Balanced.
auto appendAutosplitLedger(bool _editable) const -> void
auto setTransferGuid(const std::string &_value) -> void
Set Transfer GUID.
auto deleteTransaction() -> bool
Delete Transaction.
auto insertDoubleLine(int _row) -> void
auto createAccount(const SpItem &_spItem, bool _editable) const -> std::unique_ptr< Wt::WStandardItem >
auto forAccountSplit(const std::string &_accountGuid) const -> GCW::Dbo::Splits::Item::Ptr
Load Split for Account.
auto setReconcile(const std::string &_value) -> void
GCW::Dbo::Splits::Item::Vector m_splits
auto getToAccount() const -> std::string
auto toSplit() const -> GCW::Dbo::Splits::Item::Ptr
auto getDateAsString() const -> Wt::WString
GCW::Dbo::Transactions::Item::Ptr m_transactionItem
auto appendBasicLedger(bool _editable) const -> void
auto createDescription(const TxItem &_txItem, bool _editable) const -> std::unique_ptr< Wt::WStandardItem >
auto getDescription() const -> std::string
Set Description.
GCW::Dbo::Transactions::Item::Ptr TxItem
auto setSplitItem(GCW::Dbo::Splits::Item::Ptr _splitItem) -> void
auto thisSplit() const -> GCW::Dbo::Splits::Item::Ptr
auto getDate() const -> Wt::WDateTime
Set Date.
auto transactionItem() const -> GCW::Dbo::Transactions::Item::Ptr
Transaction Item.
auto createBlank() const -> std::unique_ptr< Wt::WStandardItem >
auto model() const -> Gui::AccountRegister::Model *
auto setDescription(const std::string &_value) -> void
auto appendRow(bool _editable) -> void
auto createCredit(const SpItem &_spItem, bool _editable) const -> std::unique_ptr< Wt::WStandardItem >
auto getValue() const -> GCW_NUMERIC
auto getNum() const -> std::string
Set Num.
auto balanceValue() -> GCW_NUMERIC
Balance Value.
auto fromSplit() const -> GCW::Dbo::Splits::Item::Ptr
Gui::AccountRegister::Model * m_model
auto createReconcile(const SpItem &_spItem, bool _editable) const -> std::unique_ptr< Wt::WStandardItem >
auto prefrenceItem() const -> const GCW::Dbo::Prefrences::Item &
GCW::Dbo::Splits::Item::Ptr SpItem
std::vector< std::unique_ptr< Wt::WStandardItem > > RowItem
auto otherGuid() const -> std::string
Other GUID.
auto setNum(const std::string &_value) -> void
auto setDate(const Wt::WDateTime &_value) -> void
auto loadSplit(const std::string &_splitGuid) -> void
Set Split.
auto split(const std::string &_splitGuid) const -> GCW::Dbo::Splits::Item::Ptr
auto setAction(const std::string &_value) -> void
Set Action.
auto setNotes(const std::string &_acctGuid, const std::string &_value) -> void
auto setReadOnly(bool _value) -> void
auto setValue(GCW_NUMERIC _value) -> void
auto appendGeneralJournal(bool _editable) const -> void
auto createDebit(const SpItem &_spItem, bool _editable) const -> std::unique_ptr< Wt::WStandardItem >
auto getValueAsString() const -> std::string
auto thatSplit() const -> GCW::Dbo::Splits::Item::Ptr
GCW::Dbo::Prefrences::Item m_prefrenceItem
auto createDate(const TxItem &_txItem, bool _editable) const -> std::unique_ptr< Wt::WStandardItem >
auto otherSplits() const -> GCW::Dbo::Splits::Item::Vector
auto createEmpty() const -> std::unique_ptr< Wt::WStandardItem >
auto appendTransactionJournal(bool _editable) const -> void
auto createNum(const TxItem &_txItem, bool _editable) const -> std::unique_ptr< Wt::WStandardItem >
auto splits() const -> GCW::Dbo::Splits::Item::Vector
Splits Vector.
auto getFromAccount() const -> std::string
auto flags(bool _editable) const -> Wt::WFlags< Wt::ItemFlag >
auto sortSplits() -> void
Sort Splits.
auto createText(const std::string &_text) const -> std::unique_ptr< Wt::WStandardItem >
auto appendEmptyRow(bool _editable) -> void
auto loadTransaction(const std::string &_transactionGuid) -> void
Set Transaction.
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.
Account Register Model.
Definition Model.h:30
static WDate currentDate()
#define GCW_NUMERIC
Internal Numeric Type.
Definition gcwglobal.h:40
Definition App.h:18