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
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*/
72class Item
73: public Wt::Dbo::Dbo< Item >
74{
75 public:
76
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
152extern const char * s_tableName;
153
154/*!
155** \brief Load Transaction by Guid
156**
157*/
158auto load( const std::string & _txGuid )-> Item::Ptr ;
159auto byGuid( const std::string & _txGuid )-> Item::Ptr ;
160auto add( const std::string & _txGuid )-> Item::Ptr ;
161auto byAccount( const std::string & _accountGuid )-> Item::Vector ;
162auto byAccountMonth( const std::string & _accountGuid, int _month )-> Item::Vector ;
163auto byNumMonth( const std::string & _num, int _month )-> Item::Vector ;
164
165 } // endnamespace Transactions {
166 } // endnamespace Dbo {
167} // endnamespace GCW {
168
169#endif // end#ifndef __TRANSACTIONS_H___
170
171
auto set_num(const std::string &_value) -> void
auto enter_date() const -> const std::string &
Item(const std::string &_txGuid)
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 std::string &_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 set_post_date(const std::string &_value) -> void
auto post_date() const -> const std::string &
static WDateTime fromString(const WString &s)
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
auto byGuid(const std::string &_txGuid) -> Item::Ptr
auto byAccount(const std::string &_accountGuid) -> Item::Vector
auto byNumMonth(const std::string &_num, int _month) -> Item::Vector
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