LibOFX: ofx_container_statement.cpp Source File

LibOFX

fx-0.9.14/lib/ofx_container_statement.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 ofx_container_statement.cpp
3 -------------------
4 copyright : (C) 2002 by Benoit Gr�goire
5 email : benoitg@coeus.ca
6 ***************************************************************************/
11 /***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <string>
25 #include "messages.hh"
26 #include "libofx.h"
27 #include "ofx_containers.hh"
28 #include "ofx_utilities.hh"
29
30 extern OfxMainContainer * MainContainer;
31
32 /***************************************************************************
33 * OfxStatementContainer *
34 ***************************************************************************/
35
36 OfxStatementContainer::OfxStatementContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
37 OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
38 {
39 memset(&data, 0, sizeof(data));
40 type = "STATEMENT";
41 }
42 OfxStatementContainer::~OfxStatementContainer()
43 {
44 /* while(transaction_queue.empty()!=true)
45 {
46 ofx_proc_transaction_cb(transaction_queue.front());
47 transaction_queue.pop();
48 }*/
49 }
50 void OfxStatementContainer::add_attribute(const string identifier, const string value)
51 {
52 if (identifier == "CURDEF")
53 {
54 strncpy(data.currency, value.c_str(), OFX_CURRENCY_LENGTH);
55 data.currency_valid = true;
56 }
57 else if (identifier == "MKTGINFO")
58 {
59 strncpy(data.marketing_info, value.c_str(), OFX_MARKETING_INFO_LENGTH);
60 data.marketing_info_valid = true;
61 }
62 else if (identifier == "DTSTART")
63 {
64 data.date_start = ofxdate_to_time_t(value);
65 data.date_start_valid = true;
66 }
67 else if (identifier == "DTEND")
68 {
69 data.date_end = ofxdate_to_time_t(value);
70 data.date_end_valid = true;
71 }
72 else
73 {
74 OfxGenericContainer::add_attribute(identifier, value);
75 }
76 }//end OfxStatementContainer::add_attribute()
77
78 void OfxStatementContainer::add_balance(OfxBalanceContainer* ptr_balance_container)
79 {
80 if (ptr_balance_container->tag_identifier == "LEDGERBAL")
81 {
82 data.ledger_balance = ptr_balance_container->amount;
83 data.ledger_balance_valid = ptr_balance_container->amount_valid;
84 data.ledger_balance_date = ptr_balance_container->date;
85 data.ledger_balance_date_valid = ptr_balance_container->date_valid;
86 }
87 else if (ptr_balance_container->tag_identifier == "AVAILBAL")
88 {
89 data.available_balance = ptr_balance_container->amount;
90 data.available_balance_valid = ptr_balance_container->amount_valid;
91 data.available_balance_date = ptr_balance_container->date;
92 data.available_balance_date_valid = ptr_balance_container->date_valid;
93 }
94 else
95 {
96 message_out(ERROR, "OfxStatementContainer::add_balance(): the balance has unknown tag_identifier: " + ptr_balance_container->tag_identifier);
97 }
98 }
99
100
101 int OfxStatementContainer::add_to_main_tree()
102 {
103 if (MainContainer != NULL)
104 {
105 return MainContainer->add_container(this);
106 }
107 else
108 {
109 return false;
110 }
111 }
112
113 int OfxStatementContainer::gen_event()
114 {
115 libofx_context->statementCallback(data);
116 return true;
117 }
118
119
120 void OfxStatementContainer::add_account(OfxAccountData * account_data)
121 {
122 if (account_data->account_id_valid == true)
123 {
124 data.account_ptr = account_data;
125 strncpy(data.account_id, account_data->account_id, OFX_ACCOUNT_ID_LENGTH);
126 data.account_id_valid = true;
127 }
128 }
129 /*void OfxStatementContainer::add_transaction(const OfxTransactionData transaction_data)
130 {
131 transaction_queue.push(transaction_data);
132 }*/
OfxStatementData::ledger_balance_date
time_t ledger_balance_date
Definition: inc/libofx.h:661
OfxStatementContainer::gen_event
virtual int gen_event()
Generate libofx.h events.
Definition: ofx_container_statement.cpp:113
OfxAccountData
An abstraction of an account.
Definition: inc/libofx.h:271
OfxBalanceContainer::date
time_t date
Definition: ofx_containers.hh:119
ofx_utilities.hh
Various simple functions for type conversion & al.
OfxGenericContainer
A generic container for an OFX SGML element. Every container inherits from OfxGenericContainer.
Definition: ofx_containers.hh:33
OfxStatementData::available_balance
double available_balance
Definition: inc/libofx.h:669
OfxAccountData::account_id
char account_id[OFX_ACCOUNT_ID_LENGTH]
Definition: inc/libofx.h:285
OfxStatementData::date_start
time_t date_start
Definition: inc/libofx.h:681
OfxStatementData::date_end
time_t date_end
Definition: inc/libofx.h:688
OfxGenericContainer::add_attribute
virtual void add_attribute(const string identifier, const string value)
Add data to a container object.
Definition: ofx_container_generic.cpp:57
LibofxContext
Definition: context.hh:25
OfxStatementData::marketing_info
char marketing_info[OFX_MARKETING_INFO_LENGTH]
Definition: inc/libofx.h:693
OfxStatementData::account_id
char account_id[OFX_ACCOUNT_ID_LENGTH]
Definition: inc/libofx.h:650
message_out
int message_out(OfxMsgType error_type, const string message)
Message output function.
Definition: messages.cpp:61
messages.hh
Message IO functionality.
ofxdate_to_time_t
time_t ofxdate_to_time_t(const string ofxdate)
Convert a C++ string containing a time in OFX format to a C time_t.
Definition: ofx_utilities.cpp:131
OfxStatementData::account_ptr
struct OfxAccountData * account_ptr
Definition: inc/libofx.h:652
OfxBalanceContainer::amount
double amount
Definition: ofx_containers.hh:117
ERROR
Definition: messages.hh:34
OfxGenericContainer::tag_identifier
string tag_identifier
Definition: ofx_containers.hh:37
OfxGenericContainer::type
string type
Definition: ofx_containers.hh:36
OfxStatementContainer::add_attribute
void add_attribute(const string identifier, const string value)
Add data to a container object.
Definition: ofx_container_statement.cpp:50
OfxStatementData::available_balance_date_valid
int available_balance_date_valid
Definition: inc/libofx.h:675
OfxStatementData::currency
char currency[OFX_CURRENCY_LENGTH]
Definition: inc/libofx.h:647
OfxStatementData::ledger_balance
double ledger_balance
Definition: inc/libofx.h:658
OfxMainContainer
The root container. Created by the <OFX> OFX element or by the export functions.
Definition: ofx_containers.hh:247
OfxBalanceContainer
Represents the <BALANCE> OFX SGML entity.
Definition: ofx_containers.hh:110
ofx_containers.hh
LibOFX internal object code.
OfxStatementContainer::add_to_main_tree
virtual int add_to_main_tree()
Add this container to the main tree.
Definition: ofx_container_statement.cpp:101