File: ofx_container_account.cpp

package info (click to toggle)
libofx 1%3A0.8.2-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 7,764 kB
  • ctags: 21,113
  • sloc: sh: 8,771; cpp: 5,475; ansic: 2,208; makefile: 200; xml: 61
file content (180 lines) | stat: -rw-r--r-- 6,935 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/***************************************************************************
         ofx_container_account.cpp 
                             -------------------
    copyright            : (C) 2002 by Benoit Grgoire
    email                : bock@step.polymtl.ca
***************************************************************************/
/**@file
 * \brief Implementation of OfxAccountContainer for bank, credit card and 
investment accounts.
*/
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string>
#include "messages.hh"
#include "libofx.h"
#include "ofx_containers.hh"
#include "ofx_utilities.hh"

extern OfxMainContainer * MainContainer;

/***************************************************************************
 *                      OfxAccountContainer                                *
 ***************************************************************************/

OfxAccountContainer::OfxAccountContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
  OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
{
  memset(&data,0,sizeof(data));
  type="ACCOUNT";
  strcpy(bankid,"");
  strcpy(branchid,"");
  strcpy(acctid,"");
  strcpy(acctkey,"");
  strcpy(brokerid,"");
  if(para_tag_identifier== "CCACCTFROM")
    {
      /*Set the type for a creditcard account.  Bank account specific 
	OFX elements will set this attribute elsewhere */
      data.account_type = data.OFX_CREDITCARD;
      data.account_type_valid = true;
    }
  if(para_tag_identifier== "INVACCTFROM")
    {
      /*Set the type for an investment account.  Bank account specific 
	OFX elements will set this attribute elsewhere */
      data.account_type = data.OFX_INVESTMENT;
      data.account_type_valid = true;
    }
  if (parentcontainer!=NULL&&((OfxStatementContainer*)parentcontainer)->data.currency_valid==true){
    strncpy(data.currency,((OfxStatementContainer*)parentcontainer)->data.currency,OFX_CURRENCY_LENGTH); /* In ISO-4217 format */
    data.currency_valid=true;
  }
}
OfxAccountContainer::~OfxAccountContainer()
{
  /*  if (parentcontainer->type == "STATEMENT")
      {
      ((OfxStatementContainer*)parentcontainer)->add_account(data);
      }
      ofx_proc_account_cb (data);*/
}

void OfxAccountContainer::add_attribute(const string identifier, const string value)
{
  if( identifier=="BANKID"){
    strncpy(bankid,value.c_str(),OFX_BANKID_LENGTH);
    data.bank_id_valid=true;
    strncpy(data.bank_id, value.c_str(), OFX_BANKID_LENGTH);
  }
  else if( identifier=="BRANCHID"){
    strncpy(branchid,value.c_str(),OFX_BRANCHID_LENGTH);
    data.branch_id_valid=true;
    strncpy(data.branch_id, value.c_str(), OFX_BRANCHID_LENGTH);
  }
  else if( identifier=="ACCTID"){
    strncpy(acctid,value.c_str(),OFX_ACCTID_LENGTH);
    data.account_number_valid=true;
    strncpy(data.account_number, value.c_str(), OFX_ACCTID_LENGTH);
  }
  else if( identifier=="ACCTKEY"){
    strncpy(acctkey,value.c_str(),OFX_ACCTKEY_LENGTH);
  }
  else if( identifier=="BROKERID"){ /* For investment accounts */
    strncpy(brokerid,value.c_str(),OFX_BROKERID_LENGTH);
    data.broker_id_valid=true;
    strncpy(data.broker_id, value.c_str(), OFX_BROKERID_LENGTH);
  }
  else if((identifier=="ACCTTYPE")||(identifier=="ACCTTYPE2")){
    data.account_type_valid=true;
    if(value=="CHECKING"){
      data.account_type=data.OFX_CHECKING;
    }
    else if(value=="SAVINGS"){
      data.account_type=data.OFX_SAVINGS;
    }
    else if(value=="MONEYMRKT"){
      data.account_type=data.OFX_MONEYMRKT;
    }
    else if(value=="CREDITLINE"){
      data.account_type=data.OFX_CREDITLINE;
    }
    else if(value=="CMA"){
      data.account_type=data.OFX_CMA;
    }
    /* AccountType CREDITCARD is set at object creation, if appropriate */
    else{
      data.account_type_valid=false;
    }
  }
  else{
    /* Redirect unknown identifiers to the base class */
    OfxGenericContainer::add_attribute(identifier, value);
  }
}//end OfxAccountContainer::add_attribute()

int OfxAccountContainer::gen_event()
{
  libofx_context->accountCallback(data);
  return true;
}

int  OfxAccountContainer::add_to_main_tree()
{
  gen_account_id ();

  if(MainContainer != NULL)
    {
      return MainContainer->add_container(this);
    }
  else
    {
      return false;
    }
}

void OfxAccountContainer::gen_account_id(void)
{
  if(data.account_type==OfxAccountData::OFX_CREDITCARD){
    strncat(data.account_id,acctid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    strncat(data.account_id," ",OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    strncat(data.account_id,acctkey,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));

    strncat(data.account_name,"Credit card ",OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
    strncat(data.account_name,acctid,OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
  }
  else if(data.account_type==OfxAccountData::OFX_INVESTMENT){
    strncat(data.account_id,brokerid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    strncat(data.account_id," ",OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    strncat(data.account_id,acctid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));

    strncat(data.account_name,"Investment account ",OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
    strncat(data.account_name,acctid,OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
    strncat(data.account_name," at broker ",OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
    strncat(data.account_name,brokerid,OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
  }
  else{
    strncat(data.account_id,bankid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    strncat(data.account_id," ",OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    strncat(data.account_id,branchid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    strncat(data.account_id," ",OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    strncat(data.account_id,acctid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));

    strncat(data.account_name,"Bank account ",OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
    strncat(data.account_name,acctid,OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
  }
  if(strlen(data.account_id)>=0){
    data.account_id_valid=true;
  }
}//end OfxAccountContainer::gen_account_id()