GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
Dbo/Accounts/Item.h
Go to the documentation of this file.
1#line 2 "src/Dbo/Accounts/Item.h"
2
3#ifndef __DBO_ACCOUNTS_ITEM_H___
4#define __DBO_ACCOUNTS_ITEM_H___
5
6#include "../BaseItem.h"
7#include "Definition.h"
8
9/*
10** Predefine the Account class that fixin to come up.
11**
12*/
13namespace GCW {
14 namespace Dbo {
15 namespace Accounts {
16 class Item;
17 }
18 }
19}
20
21/*
22** Define these dbo_traits to prevent the system from
23** automatically generating an ID field or a VERSION
24** field, and instead substitute the guid field
25** as the primary key.
26**
27*/
28template<> struct Wt::Dbo::dbo_traits< GCW::Dbo::Accounts::Item >
30{
31 using IdType = std::string;
32 static auto invalidId()-> IdType { return std::string(); }
33 static auto surrogateIdField()-> const char * { return nullptr; }
34 static auto versionField()-> const char * { return nullptr; }
35};
36
37template<> struct Wt::Dbo::dbo_traits< const GCW::Dbo::Accounts::Item > : Wt::Dbo::dbo_traits< GCW::Dbo::Accounts::Item > {};
38
39/*
40** Now we can start building our class!
41**
42*/
43namespace GCW {
44 namespace Dbo {
45 namespace Accounts {
46
47/*!
48** \brief Account Item Class
49**
50** This class represents an 'account' within gnucash. This is a Dbo object
51** so this class is used as the interface between the gnucashew application
52** and the back-end database.
53**
54** \dot
55** digraph AccountMap
56** {
57** AccountsItem;
58** }
59** \enddot
60**
61** \par Native GnuCash Account Sqlite Schema
62** \code
63** CREATE TABLE accounts
64** (
65** guid text(32) PRIMARY KEY NOT NULL,
66** name text(2048) NOT NULL,
67** account_type text(2048) NOT NULL,
68** commodity_guid text(32),
69** commodity_scu integer NOT NULL,
70** non_std_scu integer NOT NULL,
71** parent_guid text(32),
72** code text(2048),
73** description text(2048),
74** hidden integer,
75** placeholder integer
76** );
77** sqlite> select * from accounts;
78** guid name type commodity scu nss parent code desc h p
79** aa283385e0cf4f57b3360ca5a843bde5|Root Account |ROOT |10b24d11b4b94b8789d1830da2695bbb|100|0 | | | |0|0
80** 6e5313b77b4247039f0240ca79e4d871|Assets |ASSET|10b24d11b4b94b8789d1830da2695bbb|100|0 |aa283385e0cf4f57b3360ca5a843bde5| |Assets |0|1
81** b61b07c024fc463489f5db031135a29e|Current Assets |ASSET|10b24d11b4b94b8789d1830da2695bbb|100|0 |6e5313b77b4247039f0240ca79e4d871| |Current Assets |0|1
82** 822a857c5f484affa5a6a3e62f4b700f|Checking Account|BANK |10b24d11b4b94b8789d1830da2695bbb|100|0 |b61b07c024fc463489f5db031135a29e| |Checking Account|0|0
83** 9e851f524a6a44ef8c93a6b52b004cae|Savings Account |BANK |10b24d11b4b94b8789d1830da2695bbb|100|0 |b61b07c024fc463489f5db031135a29e| |Savings Account |0|0
84** \endcode
85**
86*/
87class Item
88: public GCW::Dbo::BaseItem< Item >
89{
90 public:
91
92 /*!
93 ** \brief ctor
94 */
95 Item(){}
96
97 /*!
98 ** \brief ctor with guid.
99 */
100 Item( const std::string & _guid ): m_guid( _guid ){}
101
102 /*!
103 ** \brief Account Definition
104 **
105 ** Return the definition object for the account.
106 */
107 auto accountDef() const-> const GCW::Dbo::Accounts::AccountDef_t &;
108
109 /*!
110 ** \brief Account Debit/Credit
111 **
112 ** Return the account Debit/Credit type.
113 */
114 auto accountDrCr() const-> GCW::Dbo::Accounts::DrCr;
115
116 /*!
117 ** \brief Account Type
118 **
119 ** Return the account Type as an enum.
120 */
121 auto accountType() const-> GCW::Dbo::Accounts::Type;
122
123 /*!
124 ** \brief GUID
125 **
126 ** Return account 'guid' value - the primary key for the account
127 */
128 auto guid() const-> const std::string & { return m_guid; }
129
130 /*!
131 ** \brief Name
132 **
133 ** Return account printable 'name' value
134 */
135 auto name() const-> const std::string & { return m_name; }
136
137 /*!
138 ** \brief Type Name
139 **
140 ** Return account type as a 'string' value. This is, in fact, how the account
141 ** type is actually recorded in the back-end database, as a 'text' string such
142 ** as 'BANK', 'CASH', 'INCOME' and so forth. GnuCashew takes this text value
143 ** and uses that to switch to the GCW::Dbo::Accounts::Type account type enum.
144 **
145 ** \ref Item::accountType()
146 */
147 auto accountTypeName() const-> const std::string & { return m_account_typeName; }
148
149 /*!
150 ** \brief Commodity GUID
151 **
152 **
153 */
154 auto commodity_guid() const-> const std::string & { return m_commodity_guid; }
155
156 /*!
157 ** \brief Commodity SCU (Special Currency Unit)
158 **
159 ** Currency Unit is usually 1/100. This field allows it to be changed. If this value
160 ** is non-standard, the Item::non_std_scu() will return true.
161 **
162 */
163 auto commodity_scu() const-> const int { return m_commodity_scu; }
164
165 /*!
166 ** \brief Non Standard SCU (Special Currency Unit)
167 **
168 ** If the Item::commodity_scu() is non-standard, this returns true
169 **
170 */
171 auto non_std_scu() const-> const int { return m_non_std_scu; }
172
173 /*!
174 ** \brief Parent GUID
175 **
176 ** Link to a parent account.
177 **
178 ** \note All accounts 'require' a parent account link, with the exception
179 ** of the internal 'root' account.
180 */
181 auto parent_guid() const-> const std::string & { return m_parent_guid; }
182
183 /*!
184 ** \brief Code
185 **
186 ** Use this to carry the 'account number' or other code related to the account
187 */
188 auto code() const-> const std::string & { return m_code; }
189
190 /*!
191 ** \brief Description
192 **
193 */
194 auto description() const-> const std::string & { return m_description; }
195
196 /*!
197 ** \brief Hidden
198 **
199 ** 'true' causes this account to not appear in a lot of the lists and things
200 */
201 auto hidden() const-> const int { return m_hidden; }
202
203 /*!
204 ** \brief Placeholder
205 **
206 ** 'true' causes this account to not allow transactions to be posted in to
207 */
208 auto placeHolder() const-> const int { return m_placeHolder; }
209
210 /*!
211 ** \brief Full Name
212 **
213 ** Return the 'full name representation' of the account. This includes all
214 ** parent accounts, using the ':' separator.
215 **
216 ** \par Example
217 ** \code
218 ** Assets:Current Assets:Checking Account
219 ** \endcode
220 **
221 */
222 auto fullName() const-> std::string;
223
224 /*!
225 ** \brief Has Color
226 **
227 ** Returns 'true' if this account has a color assigned to it.
228 */
229 auto hasColor() const-> bool;
230
231 /*!
232 ** \brief Color
233 **
234 ** Return the color as a string-value.
235 */
236 auto color() const-> std::string;
237
238 /*!
239 ** \brief persist the data
240 **
241 ** This connects this object to the back-end database.
242 */
243 template< class Action > void persist( Action & action )
244 {
245 Wt::Dbo::id ( action, m_guid , GCW::Dbo::Accounts::Field::guid , 32 ); // text(32) PRIMARY KEY NOT NULL
246 Wt::Dbo::field( action, m_name , GCW::Dbo::Accounts::Field::name , 2048 ); // text(2048) NOT NULL
247 Wt::Dbo::field( action, m_account_typeName , GCW::Dbo::Accounts::Field::account_typeName , 2048 ); // text(2048) NOT NULL
252 Wt::Dbo::field( action, m_code , GCW::Dbo::Accounts::Field::code , 2048 ); // text(2048)
256 }
257
258 private:
259
260 std::string m_guid ;
261 std::string m_name ;
262 std::string m_account_typeName ;
263 std::string m_commodity_guid ;
266 std::string m_parent_guid ;
267 std::string m_code ;
268 std::string m_description ;
271
272}; // endclass Item
273
274 } // endnamespace Accounts {
275 } // endnamespace Dbo {
276} // endnamespace GCW {
277
278#endif // __ACCOUNTS_H___
279
auto hasColor() const -> bool
Has Color.
auto color() const -> std::string
Color.
auto guid() const -> const std::string &
GUID.
auto hidden() const -> const int
Hidden.
void persist(Action &action)
persist the data
auto placeHolder() const -> const int
Placeholder.
auto accountDrCr() const -> GCW::Dbo::Accounts::DrCr
Account Debit/Credit.
auto accountType() const -> GCW::Dbo::Accounts::Type
Account Type.
auto fullName() const -> std::string
Full Name.
auto commodity_scu() const -> const int
Commodity SCU (Special Currency Unit)
Item(const std::string &_guid)
ctor with guid.
auto parent_guid() const -> const std::string &
Parent GUID.
auto commodity_guid() const -> const std::string &
Commodity GUID.
auto description() const -> const std::string &
Description.
auto name() const -> const std::string &
Name.
auto code() const -> const std::string &
Code.
auto non_std_scu() const -> const int
Non Standard SCU (Special Currency Unit)
auto accountTypeName() const -> const std::string &
Type Name.
auto accountDef() const -> const GCW::Dbo::Accounts::AccountDef_t &
Account Definition.
void id(Action &action, V &value, const std::string &name="id", int size=-1)
void field(Action &action, V &value, const std::string &name, int size=-1)
const Wt::WFormModel::Field name
const Wt::WFormModel::Field guid
endGCW::Dbo::Accounts::s_accountDefs
const Wt::WFormModel::Field description
const Wt::WFormModel::Field commodity_scu
const Wt::WFormModel::Field account_typeName
const Wt::WFormModel::Field code
const Wt::WFormModel::Field non_std_scu
const Wt::WFormModel::Field commodity_guid
const Wt::WFormModel::Field placeHolder
const Wt::WFormModel::Field hidden
const Wt::WFormModel::Field parent_guid
DrCr
Account Debit/Credit Enum.
Definition App.h:18