LibOFX
ofx_container_account.cpp
Go to the documentation of this file.
1/***************************************************************************
2 ofx_container_account.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
30extern OfxMainContainer * MainContainer;
31
32/***************************************************************************
33 * OfxAccountContainer *
34 ***************************************************************************/
35
36OfxAccountContainer::OfxAccountContainer(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 = "ACCOUNT";
41 if (para_tag_identifier == "CCACCTFROM")
42 {
43 /*Set the type for a creditcard account. Bank account specific
44 OFX elements will set this attribute elsewhere */
45 ASSIGN(data.account_type, data.OFX_CREDITCARD);
46 }
47 if (para_tag_identifier == "INVACCTFROM")
48 {
49 /*Set the type for an investment account. Bank account specific
50 OFX elements will set this attribute elsewhere */
51 ASSIGN(data.account_type, data.OFX_INVESTMENT);
52 }
53 if (parentcontainer != NULL && ((OfxStatementContainer*)parentcontainer)->data.currency_valid == true)
54 {
55 ASSIGN_STRNCPY(data.currency, std::string(((OfxStatementContainer*)parentcontainer)->data.currency));
56 }
57}
58OfxAccountContainer::~OfxAccountContainer()
59{
60 /* if (parentcontainer->type == "STATEMENT")
61 {
62 ((OfxStatementContainer*)parentcontainer)->add_account(data);
63 }
64 ofx_proc_account_cb (data);*/
65}
66
67void OfxAccountContainer::add_attribute(const string identifier, const string value)
68{
69 if ( identifier == "BANKID")
70 {
71 m_bankid = value;
72 ASSIGN_STRNCPY(data.bank_id, value);
73 }
74 else if ( identifier == "BRANCHID")
75 {
76 m_branchid = value;
77 ASSIGN_STRNCPY(data.branch_id, value);
78 }
79 else if ( identifier == "ACCTID")
80 {
81 m_acctid = value;
82 ASSIGN_STRNCPY(data.account_number, value);
83 }
84 else if ( identifier == "ACCTKEY")
85 {
86 m_acctkey = value;
87 }
88 else if ( identifier == "BROKERID") /* For investment accounts */
89 {
90 m_brokerid = value;
91 ASSIGN_STRNCPY(data.broker_id, value);
92 }
93 else if ((identifier == "ACCTTYPE") || (identifier == "ACCTTYPE2"))
94 {
95 data.account_type_valid = true;
96 if (value == "CHECKING")
97 {
98 data.account_type = data.OFX_CHECKING;
99 }
100 else if (value == "SAVINGS")
101 {
102 data.account_type = data.OFX_SAVINGS;
103 }
104 else if (value == "MONEYMRKT")
105 {
106 data.account_type = data.OFX_MONEYMRKT;
107 }
108 else if (value == "CREDITLINE")
109 {
110 data.account_type = data.OFX_CREDITLINE;
111 }
112 else if (value == "CMA")
113 {
114 data.account_type = data.OFX_CMA;
115 }
116 /* AccountType CREDITCARD is set at object creation, if appropriate */
117 else
118 {
119 data.account_type_valid = false;
120 }
121 }
122 else
123 {
124 /* Redirect unknown identifiers to the base class */
125 OfxGenericContainer::add_attribute(identifier, value);
126 }
127}//end OfxAccountContainer::add_attribute()
128
130{
131 libofx_context->accountCallback(data);
132 return true;
133}
134
136{
137 gen_account_id ();
138
139 if (MainContainer != NULL)
140 {
141 return MainContainer->add_container(this);
142 }
143 else
144 {
145 return false;
146 }
147}
148
149void OfxAccountContainer::gen_account_id(void)
150{
151 if (data.account_type == OfxAccountData::OFX_CREDITCARD)
152 {
153 STRNCPY(data.account_id, string(data.account_id) + m_acctid + " " + m_acctkey);
154 STRNCPY(data.account_name, string(data.account_name) + "Credit card " + m_acctid);
155 }
156 else if (data.account_type == OfxAccountData::OFX_INVESTMENT)
157 {
158 STRNCPY(data.account_id, string(data.account_id) + m_brokerid + " " + m_acctid);
159 STRNCPY(data.account_name, string(data.account_name) + "Investment account " +
160 m_acctid + " at broker " + m_brokerid);
161 }
162 else
163 {
164 STRNCPY(data.account_id, string(data.account_id) + m_bankid + " " + m_branchid + " " + m_acctid);
165 STRNCPY(data.account_name, string(data.account_name) + "Bank account " + m_acctid);
166 }
167 data.account_id_valid = true;
168}//end OfxAccountContainer::gen_account_id()
virtual int gen_event()
Generate libofx.h events.
void add_attribute(const string identifier, const string value)
Add data to a container object.
int add_to_main_tree()
Add this container to the main tree.
A generic container for an OFX SGML element. Every container inherits from OfxGenericContainer.
virtual void add_attribute(const string identifier, const string value)
Add data to a container object.
The root container. Created by the <OFX> OFX element or by the export functions.
Represents a statement for either a bank account or a credit card account.
Main header file containing the LibOfx API.
Message IO functionality.
LibOFX internal object code.
Various simple functions for type conversion & al.
void STRNCPY(T &dest, const std::string &src)
#define ASSIGN_STRNCPY(DEST, VALUE)
#define ASSIGN(DEST, VALUE)
char bank_id[OFX_BANKID_LENGTH]
Definition libofx.h:324
char account_name[OFX_ACCOUNT_NAME_LENGTH]
Definition libofx.h:297
char account_number[OFX_ACCTID_LENGTH]
Definition libofx.h:320
char account_id[OFX_ACCOUNT_ID_LENGTH]
Definition libofx.h:290