00001
00002
00003
00004
00005
00006
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef HAVE_CONFIG_H
00021 #include <config.h>
00022 #endif
00023
00024 #include <string>
00025 #include "messages.hh"
00026 #include "libofx.h"
00027 #include "ofx_containers.hh"
00028 #include "ofx_utilities.hh"
00029
00030 extern OfxMainContainer * MainContainer;
00031
00032
00033
00034
00035
00036 OfxAccountContainer::OfxAccountContainer(OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
00037 OfxGenericContainer(para_parentcontainer, para_tag_identifier)
00038 {
00039 memset(&data,0,sizeof(data));
00040 type="ACCOUNT";
00041 strcpy(bankid,"");
00042 strcpy(branchid,"");
00043 strcpy(acctid,"");
00044 strcpy(acctkey,"");
00045 strcpy(brokerid,"");
00046 if(para_tag_identifier== "CCACCTFROM")
00047 {
00048
00049
00050 data.account_type = data.OFX_CREDITCARD;
00051 data.account_type_valid = true;
00052 }
00053 if(para_tag_identifier== "INVACCTFROM")
00054 {
00055
00056
00057 data.account_type = data.OFX_INVESTMENT;
00058 data.account_type_valid = true;
00059 }
00060 if (parentcontainer!=NULL&&((OfxStatementContainer*)parentcontainer)->data.currency_valid==true){
00061 strncpy(data.currency,((OfxStatementContainer*)parentcontainer)->data.currency,OFX_CURRENCY_LENGTH);
00062 data.currency_valid=true;
00063 }
00064 }
00065 OfxAccountContainer::~OfxAccountContainer()
00066 {
00067
00068
00069
00070
00071
00072 }
00073
00074 void OfxAccountContainer::add_attribute(const string identifier, const string value)
00075 {
00076 if( identifier=="BANKID"){
00077 strncpy(bankid,value.c_str(),OFX_BANKID_LENGTH);
00078 }
00079 else if( identifier=="BRANCHID"){
00080 strncpy(branchid,value.c_str(),OFX_BRANCHID_LENGTH);
00081 }
00082 else if( identifier=="ACCTID"){
00083 strncpy(acctid,value.c_str(),OFX_ACCTID_LENGTH);
00084 }
00085 else if( identifier=="ACCTKEY"){
00086 strncpy(acctkey,value.c_str(),OFX_ACCTKEY_LENGTH);
00087 }
00088 else if( identifier=="BROKERID"){
00089 strncpy(brokerid,value.c_str(),OFX_BROKERID_LENGTH);
00090 }
00091 else if((identifier=="ACCTTYPE")||(identifier=="ACCTTYPE2")){
00092 data.account_type_valid=true;
00093 if(value=="CHECKING"){
00094 data.account_type=data.OFX_CHECKING;
00095 }
00096 else if(value=="SAVINGS"){
00097 data.account_type=data.OFX_SAVINGS;
00098 }
00099 else if(value=="MONEYMRKT"){
00100 data.account_type=data.OFX_MONEYMRKT;
00101 }
00102 else if(value=="CREDITLINE"){
00103 data.account_type=data.OFX_CREDITLINE;
00104 }
00105 else if(value=="CMA"){
00106 data.account_type=data.OFX_CMA;
00107 }
00108
00109 else{
00110 data.account_type_valid=false;
00111 }
00112 }
00113 else{
00114
00115 OfxGenericContainer::add_attribute(identifier, value);
00116 }
00117 }
00118
00119 int OfxAccountContainer::gen_event()
00120 {
00121 ofx_proc_account_cb(data);
00122 return true;
00123 }
00124
00125 int OfxAccountContainer::add_to_main_tree()
00126 {
00127 gen_account_id ();
00128
00129 if(MainContainer != NULL)
00130 {
00131 return MainContainer->add_container(this);
00132 }
00133 else
00134 {
00135 return false;
00136 }
00137 }
00138
00139 void OfxAccountContainer::gen_account_id(void)
00140 {
00141 if(data.account_type==OfxAccountData::OFX_CREDITCARD){
00142 strncat(data.account_id,acctid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00143 strncat(data.account_id," ",OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00144 strncat(data.account_id,acctkey,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00145
00146 strncat(data.account_name,"Credit card ",OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
00147 strncat(data.account_name,acctid,OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
00148 }
00149 else if(data.account_type==OfxAccountData::OFX_INVESTMENT){
00150 strncat(data.account_id,brokerid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00151 strncat(data.account_id," ",OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00152 strncat(data.account_id,acctid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00153
00154 strncat(data.account_name,"Investment account ",OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
00155 strncat(data.account_name,acctid,OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
00156 strncat(data.account_name," at broker ",OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
00157 strncat(data.account_name,brokerid,OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
00158 }
00159 else{
00160 strncat(data.account_id,bankid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00161 strncat(data.account_id," ",OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00162 strncat(data.account_id,branchid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00163 strncat(data.account_id," ",OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00164 strncat(data.account_id,acctid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00165
00166 strncat(data.account_name,"Bank account ",OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
00167 strncat(data.account_name,acctid,OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
00168 }
00169 if(strlen(data.account_id)>=0){
00170 data.account_id_valid=true;
00171 }
00172 }