GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
AccountsTreeViewModel.cpp
Go to the documentation of this file.
1#line 2 "src/Eng/AccountsTreeViewModel.cpp"
2
3#include <any>
4
5#include <Wt/Json/Array.h>
6#include <Wt/Json/Parser.h>
7#include <Wt/Json/Serializer.h>
8#include <Wt/WText.h>
9#include <Wt/WTreeTableNode.h>
10#include <Wt/WVBoxLayout.h>
11
12#include "../define.h"
13#include "../GnuCashew.h"
15
16auto
18load( int _columnCount )-> void
19{
20 m_columnCount = _columnCount;
21
22 /*
23 ** If the session isn't open then there's nothing to load.
24 */
25 if( !GCW::app()-> gnucashew_session().isOpen() )
26 return;
27
28 /*
29 ** load the data in to the model
30 */
31 auto rootAccount = GCW::Dbo::Accounts::rootAccount();
32 if( rootAccount-> guid() != "" )
33 {
34 load( invisibleRootItem(), rootAccount );
35
36 /*
37 ** define all the columns
38 */
39 int col = 0;
40// std::cout << __FILE__ << ":" << __LINE__ << " " << col << " " << m_columnCount << std::endl;
41
42 if( col < m_columnCount )
43 {
44// std::cout << __FILE__ << ":" << __LINE__ << " " << col << " " << m_columnCount << std::endl;
45 setHeaderData( col++, TR( "gcw.AccountsTreeView.column.accountname" ) );
46 }
47
48 if( col < m_columnCount )
49 {
50// std::cout << __FILE__ << ":" << __LINE__ << " " << col << " " << m_columnCount << std::endl;
51 setHeaderData( col++, TR( "gcw.AccountsTreeView.column.accountcode" ) );
52 }
53
54 if( col < m_columnCount )
55 {
56// std::cout << __FILE__ << ":" << __LINE__ << " " << col << " " << m_columnCount << std::endl;
57 setHeaderData( col++, TR( "gcw.AccountsTreeView.column.description" ) );
58 }
59
60 if( col < m_columnCount )
61 {
62// std::cout << __FILE__ << ":" << __LINE__ << " " << col << " " << m_columnCount << std::endl;
63 setHeaderData( col++, TR( "gcw.AccountsTreeView.column.taxinfo" ) );
64 }
65
66 if( col < m_columnCount )
67 {
68// std::cout << __FILE__ << ":" << __LINE__ << " " << col << " " << m_columnCount << std::endl;
69 setHeaderData( col++, TR( "gcw.AccountsTreeView.column.notes" ) );
70 }
71
72 if( col < m_columnCount )
73 {
74// std::cout << __FILE__ << ":" << __LINE__ << " " << col << " " << m_columnCount << std::endl;
75 setHeaderData( col++, TR( "gcw.AccountsTreeView.column.futureminimumusd" ) );
76 }
77
78 if( col < m_columnCount )
79 {
80// std::cout << __FILE__ << ":" << __LINE__ << " " << col << " " << m_columnCount << std::endl;
81 setHeaderData( col++, TR( "gcw.AccountsTreeView.column.total" ) );
82 }
83
84 } // endif( rootAccount-> guid() != "" )
85
86// std::cout << __FILE__ << ":" << __LINE__ << " columnCount:" << columnCount() << std::endl;
87
88} // endload( int _columnCount )-> void
89
90auto
92load( Wt::WStandardItem * _treeItem, GCW::Dbo::Accounts::Item::Ptr _parentAccount )-> void
93{
94 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
95
96 /*
97 ** This 'builds' a row of account info, with the account
98 ** 'name' on the first column, and other bits about the account
99 ** on the remaining columns.
100 */
101 auto _append = [=]( Wt::WStandardItem * _item, GCW::Dbo::Accounts::Item::Ptr _accountItem )
102 {
103 std::vector< std::unique_ptr< Wt::WStandardItem > > columns;
104
105 auto accountName = std::make_unique< Wt::WStandardItem >( _accountItem-> name() );
106 auto retVal = accountName.get();
107 accountName-> setToolTip( _accountItem-> guid() );
108
109#ifdef NEVER
110 if( _accountItem-> hasColor() )
111 {
112 auto accountColor = _accountItem-> color();
113 std::cout << __FILE__ << ":" << __LINE__ << " " << accountColor << std::endl;
114 }
115#endif
116
117 /*
118 ** set the 'model->data::User' element to contain the guid of the account, so
119 ** we can recover it later.
120 */
121 accountName-> setData( _accountItem-> guid(), Wt::ItemDataRole::User );
122 int col = 0;
123// std::cout << __FILE__ << ":" << __LINE__ << " " << col << " " << m_columnCount << std::endl;
124
125 if( col++ < m_columnCount )
126 {
127// std::cout << __FILE__ << ":" << __LINE__ << " " << col << " " << m_columnCount << std::endl;
128 columns.push_back( std::move( accountName ) );
129 }
130
131 if( col++ < m_columnCount )
132 {
133// std::cout << __FILE__ << ":" << __LINE__ << " " << col << " " << m_columnCount << std::endl;
134 columns.push_back( std::make_unique< Wt::WStandardItem >( _accountItem-> code () ) );
135 }
136
137 if( col++ < m_columnCount )
138 {
139// std::cout << __FILE__ << ":" << __LINE__ << " " << col << " " << m_columnCount << std::endl;
140 columns.push_back( std::make_unique< Wt::WStandardItem >( _accountItem-> description () ) );
141 }
142
143 if( col++ < m_columnCount )
144 {
145// std::cout << __FILE__ << ":" << __LINE__ << " " << col << " " << m_columnCount << std::endl;
146 columns.push_back( std::make_unique< Wt::WStandardItem >() );
147 }
148
149 if( col++ < m_columnCount )
150 {
151// std::cout << __FILE__ << ":" << __LINE__ << " " << col << " " << m_columnCount << std::endl;
152 columns.push_back( std::make_unique< Wt::WStandardItem >() );
153 }
154
155 if( col++ < m_columnCount )
156 {
157// std::cout << __FILE__ << ":" << __LINE__ << " " << col << " " << m_columnCount << std::endl;
158 columns.push_back( std::make_unique< Wt::WStandardItem >() );
159 }
160
161 if( col++ < m_columnCount )
162 {
163// std::cout << __FILE__ << ":" << __LINE__ << " " << col << " " << m_columnCount << std::endl;
164 columns.push_back( std::make_unique< Wt::WStandardItem >() );
165 }
166
167 _item-> appendRow( std::move( columns ) );
168
169 return retVal;
170
171 }; // end_append()
172
173 /*
174 ** Pick up all the accounts that are children to the
175 ** specified account.
176 */
177 auto childAccounts =
178 GCW::app()-> gnucashew_session().find< GCW::Dbo::Accounts::Item >()
179 .where( "parent_guid = ?" )
180 .bind( _parentAccount-> guid() )
181 .resultList()
182 ;
183
184 /*
185 ** Loop through each child-account for this parent account
186 */
187 for( auto account : childAccounts )
188 {
189 /*
190 ** Append the tree-item
191 */
192 auto ti = _append( _treeItem, account );
193
194 /*
195 ** Perform a recursive-load on this account to pick up
196 ** any more child accounts
197 */
198 load( ti, account );
199
200 } // endfor( auto account : accounts )
201
202} // endload( Wt::WStandardItem * _treeItem, GCW::Dbo::Accounts::Item::Ptr _parentAccount )-> void
203
204
Wt::Dbo::ptr< Item > Ptr
Definition BaseItem.h:39
auto load(int _columnCount) -> void
static constexpr const int User
#define TR(X)
Definition define.h:17
auto rootAccount() -> Item::Ptr
Load Root Account.
App * app()
Definition App.cpp:75