GnuCashew ~ GnuCash Enabled Web
GCW
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 */
13 namespace 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 */
28 template<> struct Wt::Dbo::dbo_traits< GCW::Dbo::Accounts::Item >
29 : public Wt::Dbo::dbo_default_traits
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 
37 template<> 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 */
43 namespace 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 */
87 class 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
248  Wt::Dbo::field( action, m_commodity_guid , GCW::Dbo::Accounts::Field::commodity_guid , 32 ); // text(32)
249  Wt::Dbo::field( action, m_commodity_scu , GCW::Dbo::Accounts::Field::commodity_scu ); // integer NOT NULL
250  Wt::Dbo::field( action, m_non_std_scu , GCW::Dbo::Accounts::Field::non_std_scu ); // integer NOT NULL
251  Wt::Dbo::field( action, m_parent_guid , GCW::Dbo::Accounts::Field::parent_guid , 32 ); // text(32)
252  Wt::Dbo::field( action, m_code , GCW::Dbo::Accounts::Field::code , 2048 ); // text(2048)
253  Wt::Dbo::field( action, m_description , GCW::Dbo::Accounts::Field::description , 2048 ); // text(2048)
254  Wt::Dbo::field( action, m_hidden , GCW::Dbo::Accounts::Field::hidden ); // integer
255  Wt::Dbo::field( action, m_placeHolder , GCW::Dbo::Accounts::Field::placeHolder ); // integer
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 ;
269  int m_hidden ;
271 
272 }; // endclass Item
273 
274  } // endnamespace Accounts {
275  } // endnamespace Dbo {
276 } // endnamespace GCW {
277 
278 #endif // __ACCOUNTS_H___
279 
Account Item Class.
Definition: Item.h:89
auto hasColor() const -> bool
Has Color.
Definition: Item.cpp:59
auto color() const -> std::string
Color.
Definition: Item.cpp:67
std::string m_name
Definition: Item.h:261
auto guid() const -> const std::string &
GUID.
Definition: Item.h:128
auto hidden() const -> const int
Hidden.
Definition: Item.h:201
void persist(Action &action)
persist the data
Definition: Item.h:243
auto placeHolder() const -> const int
Placeholder.
Definition: Item.h:208
auto accountDrCr() const -> GCW::Dbo::Accounts::DrCr
Account Debit/Credit.
Definition: Item.cpp:25
std::string m_code
Definition: Item.h:267
std::string m_account_typeName
Definition: Item.h:262
auto accountType() const -> GCW::Dbo::Accounts::Type
Account Type.
Definition: Item.cpp:38
auto fullName() const -> std::string
Full Name.
Definition: Item.cpp:51
auto commodity_scu() const -> const int
Commodity SCU (Special Currency Unit)
Definition: Item.h:163
std::string m_description
Definition: Item.h:268
Item(const std::string &_guid)
ctor with guid.
Definition: Item.h:100
auto parent_guid() const -> const std::string &
Parent GUID.
Definition: Item.h:181
auto commodity_guid() const -> const std::string &
Commodity GUID.
Definition: Item.h:154
std::string m_parent_guid
Definition: Item.h:266
auto description() const -> const std::string &
Description.
Definition: Item.h:194
auto name() const -> const std::string &
Name.
Definition: Item.h:135
auto code() const -> const std::string &
Code.
Definition: Item.h:188
auto non_std_scu() const -> const int
Non Standard SCU (Special Currency Unit)
Definition: Item.h:171
auto accountTypeName() const -> const std::string &
Type Name.
Definition: Item.h:147
std::string m_guid
Definition: Item.h:260
auto accountDef() const -> const GCW::Dbo::Accounts::AccountDef_t &
Account Definition.
Definition: Item.cpp:12
std::string m_commodity_guid
Definition: Item.h:263
const Wt::WFormModel::Field name
Definition: Accounts.cpp:47
const Wt::WFormModel::Field guid
Definition: Accounts.cpp:46
const Wt::WFormModel::Field description
Definition: Accounts.cpp:54
const Wt::WFormModel::Field commodity_scu
Definition: Accounts.cpp:50
const Wt::WFormModel::Field account_typeName
Definition: Accounts.cpp:48
const Wt::WFormModel::Field code
Definition: Accounts.cpp:53
const Wt::WFormModel::Field non_std_scu
Definition: Accounts.cpp:51
const Wt::WFormModel::Field commodity_guid
Definition: Accounts.cpp:49
const Wt::WFormModel::Field placeHolder
Definition: Accounts.cpp:56
const Wt::WFormModel::Field hidden
Definition: Accounts.cpp:55
const Wt::WFormModel::Field parent_guid
Definition: Accounts.cpp:52
Type
Account Type.
Definition: Definition.h:51
DrCr
Account Debit/Credit Enum.
Definition: Definition.h:24
const Wt::WFormModel::Field action
Definition: Entries.cpp:14
const Wt::WFormModel::Field id
Definition: Definition.h:17
Definition: App.h:17
Definition: guid.cpp:397
static auto versionField() -> const char *
Definition: Item.h:34
static auto surrogateIdField() -> const char *
Definition: Item.h:33
static auto invalidId() -> IdType
Definition: Item.h:32