GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
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*/
17namespace 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*/
32template<> struct Wt::Dbo::dbo_traits< GCW::Dbo::Transactions::Item >
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
41template<> 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*/
47namespace GCW {
48 namespace Dbo {
49 namespace Transactions {
50
51extern const char * s_tableName;
52
53/*!
54** \brief Transaction Item
55**
56**
57** \code
58** CREATE TABLE transactions
59** (
60** guid text(32) PRIMARY KEY NOT NULL,
61** currency_guid text(32) NOT NULL,
62** num text(2048) NOT NULL,
63** post_date text(19),
64** enter_date text(19),
65** description text(2048)
66** );
67** CREATE INDEX tx_post_date_index ON transactions(post_date);
68** sqlite> select * from transactions;
69** 4b2259ef3fbb486bad1b42f28ec84346|10b24d11b4b94b8789d1830da2695bbb||2023-05-28 10:59:00|2023-05-28 21:46:09|transaction memo
70** 8e841d9c97914cd5a5bd47062e7c91e3|10b24d11b4b94b8789d1830da2695bbb||2023-07-04 10:59:00|2023-07-05 16:19:43|2nd transaction
71** \endcode
72**
73*/
74class Item
75: public Wt::Dbo::Dbo< Item >
76{
77 public:
78
81 using Vector = std::vector< Ptr >;
82
83 Item() {};
84 Item( const std::string & _txGuid ) { m_guid = _txGuid; }
85
86 auto guid () const-> const std::string & { return m_guid ; }
87 auto currency_guid () const-> const std::string & { return m_currency_guid ; }
88 auto num () const-> const std::string & { return m_num ; }
89 auto post_date () const-> const std::string & { return m_post_date ; }
90 auto enter_date () const-> const std::string & { return m_enter_date ; }
91 auto description () const-> const std::string & { return m_description ; }
92
93 auto set_currency_guid ( const std::string & _guid )-> void
94 {
95 m_currency_guid = _guid;
96 }
97
98 auto set_enter_date ( const Wt::WDate & _value )-> void;
99 auto set_enter_date ( const Wt::WDateTime & _value )-> void;
100
101 auto set_num ( const std::string & _value )-> void;
102
103 /*!
104 ** \brief Post Date as String
105 **
106 ** This pulls the post-date from the back-end and formats it with
107 ** the requested format. This is used for screen-representations
108 ** of the date.
109 **
110 */
111 auto post_date_as_string( const std::string & _format ) const-> std::string
112 {
114 return d.toString( _format ).toUTF8();
115 }
116
117 /*!
118 ** \brief Date as WDate
119 **
120 ** This will take the stored string-date of the transaction and covert it to
121 ** a system WDateTime value.
122 **
123 */
124 auto post_date_as_date() const-> Wt::WDateTime
125 {
126 return
128 }
129
130 auto set_post_date( const Wt::WDate & _value )-> void ;
131 auto set_post_date( const Wt::WDateTime & _value )-> void ;
132
133 auto set_description( const std::string & _value )-> void ;
134
135 template< class Action > void persist( Action & action )
136 {
137 Wt::Dbo::id ( action, m_guid , "guid" , 32 ); // text(32) PRIMARY KEY NOT NULL,
138 Wt::Dbo::field( action, m_currency_guid , "currency_guid" , 32 ); // text(32) NOT NULL,
139 Wt::Dbo::field( action, m_num , "num" , 2048 ); // text(2048) NOT NULL,
140 Wt::Dbo::field( action, m_post_date , "post_date" , 19 ); // text(19),
141 Wt::Dbo::field( action, m_enter_date , "enter_date" , 19 ); // text(19),
142 Wt::Dbo::field( action, m_description , "description" , 2048 ); // text(2048)
143 }
144
145 private:
146
147 auto set_enter_date( const std::string & _value )-> void ;
148 auto set_post_date( const std::string & _value )-> void ;
149
150 std::string m_guid ;
151 std::string m_currency_guid ;
152 std::string m_num ;
153 std::string m_post_date ;
154 std::string m_enter_date ;
155 std::string m_description ;
156
157}; // endclass Item
158
159/*!
160** \brief Load Transaction by Guid
161**
162*/
163auto load( const std::string & _txGuid )-> Item::Ptr ;
164
165/*!
166** \brief Load Transaction by Guid
167**
168*/
169auto byGuid( const std::string & _txGuid )-> Item::Ptr ;
170
171/*!
172** \brief Add Transaction with Guid
173**
174*/
175auto add( const std::string & _txGuid )-> Item::Ptr ;
176
177/*!
178** \brief Load Transactions for Account Guid
179**
180*/
181auto byAccount( const std::string & _accountGuid )-> Item::Vector ;
182
183/*
184** \brief Load Transaction for Account Guid and Month
185**
186*/
187auto byAccountMonth( const std::string & _accountGuid, int _month )-> Item::Vector ;
188
189/*!
190** \brief Load Transactions for 'num' and Month
191**
192** The 'num' column is the column immediately to the right of the
193** date field. This query is used to find all the transactions
194** that have this value in the 'num' field for a particular month.
195**
196*/
197auto byNumMonth( const std::string & _num, int _month )-> Item::Vector ;
198
199 } // endnamespace Transactions {
200 } // endnamespace Dbo {
201} // endnamespace GCW {
202
203#endif // end#ifndef __TRANSACTIONS_H___
204
205
auto set_num(const std::string &_value) -> void
auto enter_date() const -> const std::string &
Item(const std::string &_txGuid)
auto set_post_date(const Wt::WDate &_value) -> void
auto description() const -> const std::string &
auto post_date_as_string(const std::string &_format) const -> std::string
Post Date as String.
std::vector< Ptr > Vector
auto set_enter_date(const Wt::WDate &_value) -> void
auto set_description(const std::string &_value) -> void
auto currency_guid() const -> const std::string &
auto num() const -> const std::string &
auto set_currency_guid(const std::string &_guid) -> void
auto post_date_as_date() const -> Wt::WDateTime
Date as WDate.
Wt::Dbo::ptr< Item > Ptr
void persist(Action &action)
auto guid() const -> const std::string &
auto post_date() const -> const std::string &
static WDateTime fromString(const WString &s)
#define GCW_DATETIME_FORMAT_STORAGE
Definition gcwglobal.h:14
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)
auto add(const std::string &_txGuid) -> Item::Ptr
Add Transaction with Guid.
auto byGuid(const std::string &_txGuid) -> Item::Ptr
Load Transaction by Guid.
auto byAccount(const std::string &_accountGuid) -> Item::Vector
Load Transactions for Account Guid.
auto byNumMonth(const std::string &_num, int _month) -> Item::Vector
Load Transactions for 'num' and Month.
auto byAccountMonth(const std::string &_accountGuid, int _month) -> Item::Vector
auto load(const std::string &_txGuid) -> Item::Ptr
Load Transaction by Guid.
Definition App.h:18