LibOFX
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 = !value.empty();
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 == "DTASOF")
63  {
64  data.date_asof = ofxdate_to_time_t(value);
65  data.date_asof_valid = true;
66  }
67  else if (identifier == "DTSTART")
68  {
69  data.date_start = ofxdate_to_time_t(value);
70  data.date_start_valid = true;
71  }
72  else if (identifier == "DTEND")
73  {
74  data.date_end = ofxdate_to_time_t(value);
75  data.date_end_valid = true;
76  }
77  else
78  {
79  OfxGenericContainer::add_attribute(identifier, value);
80  }
81 }//end OfxStatementContainer::add_attribute()
82 
83 void OfxStatementContainer::add_balance(OfxBalanceContainer* ptr_balance_container)
84 {
85  if (ptr_balance_container->tag_identifier == "LEDGERBAL")
86  {
87  data.ledger_balance = ptr_balance_container->amount;
88  data.ledger_balance_valid = ptr_balance_container->amount_valid;
89  data.ledger_balance_date = ptr_balance_container->date;
90  data.ledger_balance_date_valid = ptr_balance_container->date_valid;
91  }
92  else if (ptr_balance_container->tag_identifier == "AVAILBAL"
93  || ptr_balance_container->tag_identifier == "INV401KBAL")
94  {
95  data.available_balance = ptr_balance_container->amount;
96  data.available_balance_valid = ptr_balance_container->amount_valid;
97  data.available_balance_date = ptr_balance_container->date;
98  data.available_balance_date_valid = ptr_balance_container->date_valid;
99  }
100  else if (ptr_balance_container->tag_identifier == "INVBAL")
101  {
102  data.available_balance = ptr_balance_container->amount;
103  data.available_balance_valid = ptr_balance_container->amount_valid;
104  data.available_balance_date = ptr_balance_container->date;
105  data.available_balance_date_valid = ptr_balance_container->date_valid;
106  data.margin_balance = ptr_balance_container->margin_balance;
107  data.margin_balance_valid = ptr_balance_container->margin_balance_valid;
108  data.short_balance = ptr_balance_container->short_balance;
109  data.short_balance_valid = ptr_balance_container->short_balance_valid;
110  data.buying_power = ptr_balance_container->buying_power;
111  data.buying_power_valid = ptr_balance_container->buying_power_valid;
112  }
113  else
114  {
115  message_out(ERROR, "OfxStatementContainer::add_balance(): the balance has unknown tag_identifier: " + ptr_balance_container->tag_identifier);
116  }
117 }
118 
119 
121 {
122  if (MainContainer != NULL)
123  {
124  return MainContainer->add_container(this);
125  }
126  else
127  {
128  return false;
129  }
130 }
131 
133 {
134  libofx_context->statementCallback(data);
135  return true;
136 }
137 
138 
139 void OfxStatementContainer::add_account(OfxAccountData * account_data)
140 {
141  if (account_data->account_id_valid == true)
142  {
143  data.account_ptr = account_data;
144  strncpy(data.account_id, account_data->account_id, OFX_ACCOUNT_ID_LENGTH);
145  data.account_id_valid = true;
146  }
147 }
148 /*void OfxStatementContainer::add_transaction(const OfxTransactionData transaction_data)
149 {
150  transaction_queue.push(transaction_data);
151 }*/
time_t ledger_balance_date
Definition: inc/libofx.h:1083
virtual int gen_event()
Generate libofx.h events.
An abstraction of an account.
Definition: inc/libofx.h:276
A generic container for an OFX SGML element. Every container inherits from OfxGenericContainer.
double available_balance
Definition: inc/libofx.h:1095
char account_id[OFX_ACCOUNT_ID_LENGTH]
Definition: inc/libofx.h:290
Various simple functions for type conversion & al.
virtual void add_attribute(const string identifier, const string value)
Add data to a container object.
char marketing_info[OFX_MARKETING_INFO_LENGTH]
Definition: inc/libofx.h:1131
time_t ofxdate_to_time_t(const string ofxdate)
Convert a C++ string containing a time in OFX format to a C time_t.
char account_id[OFX_ACCOUNT_ID_LENGTH]
Definition: inc/libofx.h:1072
double short_balance
Definition: inc/libofx.h:1108
int message_out(OfxMsgType error_type, const string message)
Message output function.
time_t available_balance_date
Definition: inc/libofx.h:1100
LibOFX internal object code.
struct OfxAccountData * account_ptr
Definition: inc/libofx.h:1074
Message IO functionality.
double margin_balance
Definition: inc/libofx.h:1104
void add_attribute(const string identifier, const string value)
Add data to a container object.
char currency[OFX_CURRENCY_LENGTH]
Definition: inc/libofx.h:1069
double ledger_balance
Definition: inc/libofx.h:1080
The root container. Created by the <OFX> OFX element or by the export functions.
Represents the <BALANCE>, <INVBAL> or <INV401KBAL> OFX SGML entity.
virtual int add_to_main_tree()
Add this container to the main tree.