GnuCashew ~ GnuCash Enabled Web
GCW
Transactions.h
Go to the documentation of this file.
1 #line 2 "src/Dbo/Transactions.h"
2 
3 #ifndef __DBO_TRANSACTIONS_H___
4 #define __DBO_TRANSACTIONS_H___
5 
6 #include <Wt/Dbo/Dbo.h>
7 #include <Wt/WDate.h>
8 #include <Wt/WDateTime.h>
9 
10 #include "../../Glb/gcwglobal.h"
11 #include "../Splits/Splits.h"
12 
13 /*
14 ** Predefine the Account class that fixin to come up.
15 **
16 */
17 namespace GCW {
18  namespace Dbo {
19  namespace Transactions {
20  class Item;
21  }
22  }
23 }
24 
25 /*
26 ** Define these dbo_traits to prevent the system from
27 ** automatically generating an ID field or a VERSION
28 ** field, and instead substitute the guid field
29 ** as the primary key.
30 **
31 */
32 template<> struct Wt::Dbo::dbo_traits< GCW::Dbo::Transactions::Item >
33 : public Wt::Dbo::dbo_default_traits
34 {
35  using IdType = std::string;
36  static IdType invalidId() { return std::string(); }
37  static const char * surrogateIdField() { return nullptr; }
38  static const char * versionField() { return nullptr; }
39 };
40 
41 template<> struct Wt::Dbo::dbo_traits< const GCW::Dbo::Transactions::Item > : Wt::Dbo::dbo_traits< GCW::Dbo::Transactions::Item > {};
42 
43 /*
44 ** Now we can start building our class!
45 **
46 */
47 namespace GCW {
48  namespace Dbo {
49  namespace Transactions {
50 
51 /*!
52 ** \brief Transaction Item
53 **
54 **
55 ** \code
56 ** CREATE TABLE transactions
57 ** (
58 ** guid text(32) PRIMARY KEY NOT NULL,
59 ** currency_guid text(32) NOT NULL,
60 ** num text(2048) NOT NULL,
61 ** post_date text(19),
62 ** enter_date text(19),
63 ** description text(2048)
64 ** );
65 ** CREATE INDEX tx_post_date_index ON transactions(post_date);
66 ** sqlite> select * from transactions;
67 ** 4b2259ef3fbb486bad1b42f28ec84346|10b24d11b4b94b8789d1830da2695bbb||2023-05-28 10:59:00|2023-05-28 21:46:09|transaction memo
68 ** 8e841d9c97914cd5a5bd47062e7c91e3|10b24d11b4b94b8789d1830da2695bbb||2023-07-04 10:59:00|2023-07-05 16:19:43|2nd transaction
69 ** \endcode
70 **
71 */
72 class Item
73 : public Wt::Dbo::Dbo< Item >
74 {
75  public:
76 
77  using Ptr = Wt::Dbo::ptr< Item >;
78  using Collection = Wt::Dbo::collection< Ptr >;
79  using Vector = std::vector< Ptr >;
80 
81  Item() {};
82  Item( const std::string & _txGuid ) { m_guid = _txGuid; }
83 
84  auto guid () const-> const std::string & { return m_guid ; }
85  auto currency_guid () const-> const std::string & { return m_currency_guid ; }
86  auto num () const-> const std::string & { return m_num ; }
87  auto post_date () const-> const std::string & { return m_post_date ; }
88  auto enter_date () const-> const std::string & { return m_enter_date ; }
89  auto description () const-> const std::string & { return m_description ; }
90 
91  auto set_currency_guid ( const std::string & _guid )-> void
92  {
93  m_currency_guid = _guid;
94  }
95 
96  auto set_enter_date ( const std::string & _value )-> void;
97  auto set_enter_date ( const Wt::WDateTime & _value )-> void;
98 
99  auto set_num ( const std::string & _value )-> void;
100 
101  /*!
102  ** \brief Post Date as String
103  **
104  ** This pulls the post-date from the back-end and formats it with
105  ** the requested format. This is used for screen-representations
106  ** of the date.
107  **
108  */
109  auto post_date_as_string( const std::string & _format ) const-> std::string
110  {
111  auto d = Wt::WDateTime::fromString( post_date(), "yyyy-MM-dd hh:mm:ss" );
112  return d.toString( _format ).toUTF8();
113  }
114 
115  /*!
116  ** \brief Date as WDate
117  **
118  ** This will take the stored string-date of the transaction and covert it to
119  ** a system WDateTime value.
120  **
121  */
122  auto post_date_as_date() const-> Wt::WDateTime
123  {
124  return
125  Wt::WDateTime::fromString( post_date(), "yyyy-MM-dd hh:mm:ss" );
126  }
127 
128  auto set_post_date( const std::string & _value )-> void ;
129  auto set_post_date( const Wt::WDateTime & _value )-> void ;
130 
131  auto set_description( const std::string & _value )-> void ;
132 
133  template< class Action > void persist( Action & action )
134  {
135  Wt::Dbo::id ( action, m_guid , "guid" , 32 ); // text(32) PRIMARY KEY NOT NULL,
136  Wt::Dbo::field( action, m_currency_guid , "currency_guid" , 32 ); // text(32) NOT NULL,
137  Wt::Dbo::field( action, m_num , "num" , 2048 ); // text(2048) NOT NULL,
138  Wt::Dbo::field( action, m_post_date , "post_date" , 19 ); // text(19),
139  Wt::Dbo::field( action, m_enter_date , "enter_date" , 19 ); // text(19),
140  Wt::Dbo::field( action, m_description , "description" , 2048 ); // text(2048)
141  }
142 
143  std::string m_guid ;
144  std::string m_currency_guid ;
145  std::string m_num ;
146  std::string m_post_date ;
147  std::string m_enter_date ;
148  std::string m_description ;
149 
150 }; // endclass Item
151 
152 extern const char * s_tableName;
153 
154 /*!
155 ** \brief Load Transaction by Guid
156 **
157 */
158 auto load( const std::string & _txGuid )-> Item::Ptr ;
159 auto byGuid( const std::string & _txGuid )-> Item::Ptr ;
160 auto add( const std::string & _txGuid )-> Item::Ptr ;
161 auto byAccount( const std::string & _accountGuid )-> Item::Vector ;
162 
163  } // endnamespace Transactions {
164  } // endnamespace Dbo {
165 } // endnamespace GCW {
166 
167 #endif // end#ifndef __TRANSACTIONS_H___
168 
169 
auto set_num(const std::string &_value) -> void
auto enter_date() const -> const std::string &
Definition: Transactions.h:88
Item(const std::string &_txGuid)
Definition: Transactions.h:82
auto description() const -> const std::string &
Definition: Transactions.h:89
auto post_date_as_string(const std::string &_format) const -> std::string
Post Date as String.
Definition: Transactions.h:109
std::vector< Ptr > Vector
Definition: Transactions.h:79
auto set_enter_date(const std::string &_value) -> void
auto set_description(const std::string &_value) -> void
auto currency_guid() const -> const std::string &
Definition: Transactions.h:85
auto num() const -> const std::string &
Definition: Transactions.h:86
auto set_currency_guid(const std::string &_guid) -> void
Definition: Transactions.h:91
auto post_date_as_date() const -> Wt::WDateTime
Date as WDate.
Definition: Transactions.h:122
Wt::Dbo::ptr< Item > Ptr
Definition: Transactions.h:77
void persist(Action &action)
Definition: Transactions.h:133
auto guid() const -> const std::string &
Definition: Transactions.h:84
Wt::Dbo::collection< Ptr > Collection
Definition: Transactions.h:78
auto set_post_date(const std::string &_value) -> void
auto post_date() const -> const std::string &
Definition: Transactions.h:87
const Wt::WFormModel::Field action
Definition: Entries.cpp:14
const Wt::WFormModel::Field id
Definition: Definition.h:17
auto add(const std::string &_txGuid) -> Item::Ptr
const char * s_tableName
Definition: Transactions.cpp:6
auto byGuid(const std::string &_txGuid) -> Item::Ptr
auto byAccount(const std::string &_accountGuid) -> Item::Vector
auto load(const std::string &_txGuid) -> Item::Ptr
Load Transaction by Guid.
Definition: App.h:17
Definition: GncLock.h:6
Definition: guid.cpp:397