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()-> void ;
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 )-> 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 setReadOnly( bool _value )-> void ;
224
225 /*
226 ** append the row to the model
227 */
228 auto appendRow()-> void ;
229
230 private:
231
232 auto highlightNegativeBalance( RowItem & _row ) const-> void ;
233
234 auto createText ( const std::string & _text ) const-> std::unique_ptr< Wt::WStandardItem > ;
235 auto createBlank ( ) const-> std::unique_ptr< Wt::WStandardItem > ;
236 auto createEmpty ( ) const-> std::unique_ptr< Wt::WStandardItem > ;
237 auto createDate ( TxItem _txItem ) const-> std::unique_ptr< Wt::WStandardItem > ;
238 auto createNum ( TxItem _txItem ) const-> std::unique_ptr< Wt::WStandardItem > ;
239 auto createNum ( SpItem _spItem ) const-> std::unique_ptr< Wt::WStandardItem > ;
240 auto createDescription ( TxItem _txItem ) const-> std::unique_ptr< Wt::WStandardItem > ;
241 auto createDescription ( SpItem _spItem ) const-> std::unique_ptr< Wt::WStandardItem > ;
242 auto createAccount ( SpItem _spItem ) const-> std::unique_ptr< Wt::WStandardItem > ;
243 auto createReconcile ( SpItem _spItem ) const-> std::unique_ptr< Wt::WStandardItem > ;
244 auto createDebit ( SpItem _spItem ) const-> std::unique_ptr< Wt::WStandardItem > ;
245 auto createCredit ( SpItem _spItem ) const-> std::unique_ptr< Wt::WStandardItem > ;
246 auto createBalance ( ) const-> std::unique_ptr< Wt::WStandardItem > ;
247
248 auto appendBasicLedger () const-> void ;
249 auto appendAutosplitLedger () const-> void ;
250 auto appendTransactionJournal () const-> void ;
251 auto appendGeneralJournal () const-> void ;
252
253 Gui::AccountRegister::Model * m_model = nullptr ;
254 Wt::WModelIndex m_index ;
255 std::string m_splitGuid ;
256 GCW::Dbo:: Transactions ::Item::Ptr m_transactionItem ;
257 GCW::Dbo:: Prefrences ::Item m_prefrenceItem ;
258 GCW::Dbo:: Splits ::Item::Vector m_splits ;
259
260}; // endclass Manager
261
262 } // namespace Transaction {
263 } // namespace Eng {
264} // namespace GCW {
265
266#endif // #ifndef __ENG_TRANSACTIONMANAGER_H___
267
268
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 createCredit(SpItem _spItem) const -> std::unique_ptr< Wt::WStandardItem >
auto setTransferGuid(const std::string &_value) -> void
Set Transfer GUID.
auto newTransaction(const std::string &_accountGuid1, const std::string &_accountGuid2) -> void
New Transaction.
auto createReconcile(SpItem _spItem) 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 getDateAsString() const -> Wt::WString
GCW::Dbo::Transactions::Item::Ptr m_transactionItem
auto getDescription() const -> std::string
Set Description.
GCW::Dbo::Transactions::Item::Ptr TxItem
auto setSplitItem(GCW::Dbo::Splits::Item::Ptr _splitItem) -> void
auto createDescription(TxItem _txItem) const -> std::unique_ptr< Wt::WStandardItem >
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 appendAutosplitLedger() const -> void
auto createDebit(SpItem _spItem) const -> std::unique_ptr< Wt::WStandardItem >
auto createBlank() const -> std::unique_ptr< Wt::WStandardItem >
auto model() const -> Gui::AccountRegister::Model *
auto setDescription(const std::string &_value) -> void
auto deleteTransaction() -> void
Delete Transaction.
auto getValue() const -> GCW_NUMERIC
auto appendTransactionJournal() const -> void
auto getNum() const -> std::string
Set Num.
auto balanceValue() -> GCW_NUMERIC
Balance Value.
Gui::AccountRegister::Model * m_model
auto prefrenceItem() const -> const GCW::Dbo::Prefrences::Item &
GCW::Dbo::Splits::Item::Ptr SpItem
auto createNum(TxItem _txItem) const -> std::unique_ptr< Wt::WStandardItem >
std::vector< std::unique_ptr< Wt::WStandardItem > > RowItem
auto otherGuid() const -> std::string
Other GUID.
auto createAccount(SpItem _spItem) const -> std::unique_ptr< Wt::WStandardItem >
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 createDate(TxItem _txItem) const -> std::unique_ptr< Wt::WStandardItem >
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() const -> void
auto getValueAsString() const -> std::string
auto thatSplit() const -> GCW::Dbo::Splits::Item::Ptr
GCW::Dbo::Prefrences::Item m_prefrenceItem
auto otherSplits() const -> GCW::Dbo::Splits::Item::Vector
auto createEmpty() const -> std::unique_ptr< Wt::WStandardItem >
auto splits() const -> GCW::Dbo::Splits::Item::Vector
Splits Vector.
auto sortSplits() -> void
Sort Splits.
auto createText(const std::string &_text) const -> std::unique_ptr< Wt::WStandardItem >
auto loadTransaction(const std::string &_transactionGuid) -> void
Set Transaction.
Account Register Model.
Definition Model.h:30
#define GCW_NUMERIC
Internal Numeric Type.
Definition gcwglobal.h:38
Definition App.h:18