1 #line 2 "src/Dbo/SessionGnuCash.cpp"
4 #define TESTFILE "gnucash-dev.gnucash"
8 #include "../Glb/Core.h"
19 GCW::Dbo::GnuCash::Session::
60 GCW::Dbo::GnuCash::Session::
67 GCW::Dbo::GnuCash::Session::
68 open(
const std::string & _path )
79 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << path() << std::endl;
82 gnc_engine_init( 0,
nullptr );
84 m_session = qof_session_new( qof_book_new() );
86 std::cout << __FILE__ <<
":" << __LINE__ <<
" qof_session_begin" << std::endl;
87 std::string url =
"sqlite3://" + path();
92 qof_session_begin( m_session, url.c_str(), SESSION_READ_ONLY );
95 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: " << qof_session_get_error( m_session ) << std::endl;
97 if( qof_session_get_error( m_session ) != 0 )
99 std::cout << __FILE__ <<
":" << __LINE__ <<
" error opening qof_session" << std::endl;
103 std::cout << __FILE__ <<
":" << __LINE__ <<
" qof_session_load" << std::endl;
104 qof_session_load( m_session, NULL );
106 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: " << qof_session_get_error( m_session ) << std::endl;
113 std::cout << __FILE__ <<
":" << __LINE__ <<
" qof_session_get_book" << std::endl;
114 auto book = getBook();
116 std::cout << __FILE__ <<
":" << __LINE__ <<
" gnc_book_get_root_account" << std::endl;
120 std::cout << __FILE__ <<
":" << __LINE__ <<
" gnc_book_count_transactions:" << book.count_transactions() << std::endl;
124 std::cout << __FILE__ <<
":" << __LINE__ <<
" rootGuid: " <<
rootAccount.guid() << std::endl;
125 std::cout << __FILE__ <<
":" << __LINE__ <<
" rootName: " <<
rootAccount.name() << std::endl;
126 std::cout << __FILE__ <<
":" << __LINE__ <<
" rootCode: " <<
rootAccount.code() << std::endl;
127 std::cout << __FILE__ <<
":" << __LINE__ <<
" rootDesc: " <<
rootAccount.description() << std::endl;
130 std::cout << __FILE__ <<
":" << __LINE__ <<
" size: " <<
rootAccount.children().size() << std::endl;
143 std::cout << __FILE__ <<
":" << __LINE__
145 <<
" guid: " << child.guid()
146 <<
" name: " << child.name()
151 std::cout << __FILE__ <<
":" << __LINE__ <<
" qof_session_save" << std::endl;
152 qof_session_save( m_session, NULL );
169 std::cout << __FILE__ <<
":" << __LINE__ <<
" open finished." << std::endl;
177 GCW::Dbo::GnuCash::Session::
180 std::cout << __FILE__ <<
":" << __LINE__ <<
" qof_session_end" << std::endl;
182 qof_session_end( m_session );
186 gnc_engine_shutdown();
190 GCW::Dbo::GnuCash::Book
191 GCW::Dbo::GnuCash::Session::
205 GCW::Dbo::GnuCash::Book::
206 Book( GCW::Dbo::GnuCash::Session * _session )
207 : m_session( _session )
209 m_book = qof_session_get_book( m_session-> qofSession() );
212 GCW::Dbo::GnuCash::Account
216 return Account( gnc_book_get_root_account( m_book ),
this );
220 GCW::Dbo::GnuCash::Account
221 GCW::Dbo::GnuCash::Book::
222 accountByGuid(
const std::string _guid )
224 return GCW::Dbo::GnuCash::Account();
228 GCW::Dbo::GnuCash::Book::
231 return gnc_book_count_transactions( m_book );
242 std::string _to_string(
const char * s )
254 GCW::Dbo::GnuCash::Account::
255 Account( ::Account * _gncAccount, Book * _book )
256 : m_gncAccount( _gncAccount ),
261 GCW::Dbo::GnuCash::Account::
262 Account(
const Account & _copy )
263 : m_gncAccount( _copy.m_gncAccount ),
264 m_book( _copy.m_book )
269 GCW::Dbo::GnuCash::Account::
275 GCW::Dbo::GnuCash::Book *
276 GCW::Dbo::GnuCash::Account::
286 return _to_string( guid_to_string( xaccAccountGetGUID( gncAccount() ) ) );
293 return _to_string( xaccAccountGetName( gncAccount() ) );
300 return _to_string( xaccAccountGetCode( gncAccount() ) );
307 return _to_string( xaccAccountGetDescription( gncAccount() ) );
314 return _to_string( xaccAccountGetNotes( gncAccount() ) );
317 std::vector< GCW::Dbo::GnuCash::Account >
318 GCW::Dbo::GnuCash::Account::
321 std::vector< GCW::Dbo::GnuCash::Account > retVal;
323 for(
int i=0; i< gnc_account_n_children( gncAccount() ); i++ )
324 retVal.push_back( GCW::Dbo::GnuCash::Account( gnc_account_nth_child( gncAccount(), i ), book() ) );
auto open(const std::string &_path) -> bool
Open a database.
const Wt::WFormModel::Field name
const Wt::WFormModel::Field guid
const Wt::WFormModel::Field description
const Wt::WFormModel::Field code
auto rootAccount() -> Item::Ptr
Load Root Account.
const Wt::WFormModel::Field notes