GnuCashew ~ GnuCash Enabled Web
GCW
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 
6 const char * GCW::Dbo::Transactions::s_tableName = "transactions";
7 
8 auto
10 set_num( const std::string & _value )-> void
11 {
12  m_num = _value;
13 
14 }
15 
16 auto
18 set_enter_date ( const std::string & _value )-> void
19 {
20  m_enter_date = _value;
21 }
22 
23 auto
25 set_enter_date ( const Wt::WDateTime & _value )-> void
26 {
27  m_enter_date = _value.toString( GCW_DATE_FORMAT_STORAGE ).toUTF8();
28 }
29 
30 auto
32 set_post_date( const std::string & _value )-> void
33 {
34  m_post_date = _value;
35 }
36 
37 auto
39 set_post_date( const Wt::WDateTime & _value )-> void
40 {
41  m_post_date = _value.toString( "yyyy-MM-dd 00:00:00" ).toUTF8();
42 }
43 
44 auto
46 set_description( const std::string & _value )-> void
47 {
48  m_description = _value;
49 }
50 
51 auto
53 load( const std::string & _txGuid )-> GCW::Dbo::Transactions::Item::Ptr
54 {
56 
57  /*
58  ** If the session isn't open then there's nothing to load.
59  **
60  */
61  if( GCW::app()-> gnucashew_session().isOpen() )
62  {
63 
64  Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
65 
66  retVal =
67  GCW::app()-> gnucashew_session().load< GCW::Dbo::Transactions::Item >( _txGuid )
68  ;
69 
70  } // endif( GCW::app()-> gnucashew_session().isOpen() )
71 
72 
73  return retVal;
74 
75 } // endGCW::Dbo::Transactions::Item::Ptr GCW::Dbo::Transactions::byGuid( const std::string & _txGuid )
76 
77 auto
79 byGuid( const std::string & _txGuid )-> GCW::Dbo::Transactions::Item::Ptr
80 {
81  return load( _txGuid );
82 
83 } // endGCW::Dbo::Transactions::Item::Ptr GCW::Dbo::Transactions::byGuid( const std::string & _txGuid )
84 
85 auto
87 add( const std::string & _txGuid )-> Item::Ptr
88 {
89  Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
90 
91  return
92  GCW::app()-> gnucashew_session().addNew< Item >( _txGuid );
93 
94 } // endadd( const std::string & _txGuid )-> Item::Ptr
95 
96 auto
98 byAccount( const std::string & _accountGuid )-> GCW::Dbo::Transactions::Item::Vector
99 {
101 
102  /*
103  ** If the session isn't open then there's nothing to load.
104  **
105  */
106  if( GCW::app()-> gnucashew_session().isOpen() )
107  {
108 
109  Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
110 
111  /*
112  ** Pull all transactions that have a split that matches this
113  ** account. Sort the results by post_date:ascending, so that any
114  ** subsequent views can process the items in sequential order.
115  **
116  */
117  auto results =
118  GCW::app()-> gnucashew_session().find< GCW::Dbo::Transactions::Item >()
119  .where( "guid in (select tx_guid from splits where account_guid = ?)" )
120  .bind( _accountGuid )
121  .orderBy( "post_date" )
122  .resultList();
123  ;
124 
125  for( auto result : results )
126  retVal.push_back( result );
127 
128  } // endif( GCW::app()-> gnucashew_session().isOpen() )
129 
130  return retVal;
131 
132 } // endGCW::Dbo::Transactions::Item::Vector GCW::Dbo::Transactions::byAccount( const std::string & _accountGuid )
133 
auto set_num(const std::string &_value) -> void
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
Wt::Dbo::ptr< Item > Ptr
Definition: Transactions.h:77
auto set_post_date(const std::string &_value) -> void
#define GCW_DATE_FORMAT_STORAGE
Definition: gcwglobal.h:12
auto load(const std::string &_guid) -> Item::Ptr
Load Account by GUID.
Definition: Accounts.cpp:135
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.
App * app()
Definition: App.cpp:67