GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
Transactions.cpp
Go to the documentation of this file.
1#line 2 "src/Dbo/Transactions.cpp"
2
3#include "../App.h"
4#include "Transactions.h"
5
6const char * GCW::Dbo::Transactions::s_tableName = "transactions";
7
8auto
10set_num( const std::string & _value )-> void
11{
12 m_num = _value;
13
14}
15
16auto
18set_enter_date ( const std::string & _value )-> void
19{
20 m_enter_date = _value;
21}
22
23auto
25set_enter_date ( const Wt::WDateTime & _value )-> void
26{
27 m_enter_date = _value.toString( GCW_DATE_FORMAT_STORAGE ).toUTF8();
28}
29
30auto
32set_post_date( const std::string & _value )-> void
33{
34 m_post_date = _value;
35}
36
37auto
39set_post_date( const Wt::WDateTime & _value )-> void
40{
41 /*
42 ** BUGBUG: This is a very weird thing! The gnucash system seems to post transactions
43 ** with a post_date of "yyyy-MM-dd 10:59:00" with the 'hours and minutes'
44 ** set to that value accordingly. If the record is posted as '00:00:00'
45 ** hours, gnucash will interpret the date as being in the day before.
46 **
47 ** So, therefore, when posting the 'post_date' of a transaction, it is
48 ** a requirement that the hours be set like this.
49 */
50 m_post_date = _value.toString( "yyyy-MM-dd 10:59:00" ).toUTF8();
51
52} // endset_post_date( const Wt::WDateTime & _value )-> void
53
54auto
56set_description( const std::string & _value )-> void
57{
58 m_description = _value;
59}
60
61auto
63load( const std::string & _txGuid )-> GCW::Dbo::Transactions::Item::Ptr
64{
66
67 /*
68 ** If the session isn't open then there's nothing to load.
69 **
70 */
71 if( GCW::app()-> gnucashew_session().isOpen() )
72 {
73
74 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
75
76 retVal =
77 GCW::app()-> gnucashew_session().find< GCW::Dbo::Transactions::Item >()
78 .where( "guid = ?" )
79 .bind( _txGuid )
80 ;
81
82 } // endif( GCW::app()-> gnucashew_session().isOpen() )
83
84
85 return retVal;
86
87} // endGCW::Dbo::Transactions::Item::Ptr GCW::Dbo::Transactions::byGuid( const std::string & _txGuid )
88
89auto
91byGuid( const std::string & _txGuid )-> GCW::Dbo::Transactions::Item::Ptr
92{
93 return load( _txGuid );
94
95} // endGCW::Dbo::Transactions::Item::Ptr GCW::Dbo::Transactions::byGuid( const std::string & _txGuid )
96
97auto
99add( const std::string & _txGuid )-> Item::Ptr
100{
101 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
102
103 return
104 GCW::app()-> gnucashew_session().addNew< Item >( _txGuid );
105
106} // endadd( const std::string & _txGuid )-> Item::Ptr
107
108auto
110byAccount( const std::string & _accountGuid )-> GCW::Dbo::Transactions::Item::Vector
111{
113
114 /*
115 ** If the session isn't open then there's nothing to load.
116 **
117 */
118 if( GCW::app()-> gnucashew_session().isOpen() )
119 {
120
121 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
122
123 /*
124 ** Pull all transactions that have a split that matches this
125 ** account. Sort the results by post_date:ascending, so that any
126 ** subsequent views can process the items in sequential order.
127 **
128 */
129 auto results =
130 GCW::app()-> gnucashew_session().find< GCW::Dbo::Transactions::Item >()
131 .where( "guid in (select tx_guid from splits where account_guid = ?)" )
132 .bind( _accountGuid )
133 .orderBy( "post_date" )
134 .resultList();
135 ;
136
137 for( auto result : results )
138 retVal.push_back( result );
139
140 } // endif( GCW::app()-> gnucashew_session().isOpen() )
141
142 return retVal;
143
144} // endGCW::Dbo::Transactions::Item::Vector GCW::Dbo::Transactions::byAccount( const std::string & _accountGuid )
145
146auto
148byAccountMonth( const std::string & _accountGuid, int _month )-> GCW::Dbo::Transactions::Item::Vector
149{
151
152 auto thisYear = Wt::WDate::currentDate().year();
153
154 /*
155 ** if the transaction item is within this month and year
156 ** then it's a keeper
157 */
158 for( auto item : byAccount( _accountGuid ) )
159 if( item-> post_date_as_date().date().month() == _month
160 && item-> post_date_as_date().date().year() == thisYear
161 )
162 retVal.push_back( item );
163
164 return retVal;
165
166} // endbyAccountMonth( const std::string & _accountGuid, int _month )-> GCW::Dbo::Transactions::Item::Vector
167
168auto
170byNumMonth( const std::string & _num, int _month )-> GCW::Dbo::Transactions::Item::Vector
171{
173
174 auto date = Wt::WDate( Wt::WDate::currentDate().year(), _month, 1 ).toString( "yyyy-MM" );
175
176 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
177 auto results =
178 GCW::app()-> gnucashew_session().find< GCW::Dbo::Transactions::Item >()
179 .where( "num = ? and post_date LIKE ?" )
180 .bind( _num )
181 .bind( date + "%" )
182 .orderBy( "post_date" )
183 .resultList();
184 ;
185
186 for( auto item : results )
187 retVal.push_back( item );
188
189 return retVal;
190
191} // endbyNumMonth( const std::string & _num, int _month )-> GCW::Dbo::Transactions::Item::Vector
192
auto set_num(const std::string &_value) -> void
std::vector< Ptr > Vector
auto set_enter_date(const std::string &_value) -> void
auto set_description(const std::string &_value) -> void
auto set_post_date(const std::string &_value) -> void
WString toString() const
static WDate currentDate()
int year() const
#define GCW_DATE_FORMAT_STORAGE
Definition gcwglobal.h:12
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.
App * app()
Definition App.cpp:75