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(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
00037 OfxGenericContainer(p_libofx_context, 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 data.bank_id_valid=true;
00079 strncpy(data.bank_id, value.c_str(), OFX_BANKID_LENGTH);
00080 }
00081 else if( identifier=="BRANCHID"){
00082 strncpy(branchid,value.c_str(),OFX_BRANCHID_LENGTH);
00083 data.branch_id_valid=true;
00084 strncpy(data.branch_id, value.c_str(), OFX_BRANCHID_LENGTH);
00085 }
00086 else if( identifier=="ACCTID"){
00087 strncpy(acctid,value.c_str(),OFX_ACCTID_LENGTH);
00088 data.account_number_valid=true;
00089 strncpy(data.account_number, value.c_str(), OFX_ACCTID_LENGTH);
00090 }
00091 else if( identifier=="ACCTKEY"){
00092 strncpy(acctkey,value.c_str(),OFX_ACCTKEY_LENGTH);
00093 }
00094 else if( identifier=="BROKERID"){
00095 strncpy(brokerid,value.c_str(),OFX_BROKERID_LENGTH);
00096 }
00097 else if((identifier=="ACCTTYPE")||(identifier=="ACCTTYPE2")){
00098 data.account_type_valid=true;
00099 if(value=="CHECKING"){
00100 data.account_type=data.OFX_CHECKING;
00101 }
00102 else if(value=="SAVINGS"){
00103 data.account_type=data.OFX_SAVINGS;
00104 }
00105 else if(value=="MONEYMRKT"){
00106 data.account_type=data.OFX_MONEYMRKT;
00107 }
00108 else if(value=="CREDITLINE"){
00109 data.account_type=data.OFX_CREDITLINE;
00110 }
00111 else if(value=="CMA"){
00112 data.account_type=data.OFX_CMA;
00113 }
00114
00115 else{
00116 data.account_type_valid=false;
00117 }
00118 }
00119 else{
00120
00121 OfxGenericContainer::add_attribute(identifier, value);
00122 }
00123 }
00124
00125 int OfxAccountContainer::gen_event()
00126 {
00127 libofx_context->accountCallback(data);
00128 return true;
00129 }
00130
00131 int OfxAccountContainer::add_to_main_tree()
00132 {
00133 gen_account_id ();
00134
00135 if(MainContainer != NULL)
00136 {
00137 return MainContainer->add_container(this);
00138 }
00139 else
00140 {
00141 return false;
00142 }
00143 }
00144
00145 void OfxAccountContainer::gen_account_id(void)
00146 {
00147 if(data.account_type==OfxAccountData::OFX_CREDITCARD){
00148 strncat(data.account_id,acctid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00149 strncat(data.account_id," ",OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00150 strncat(data.account_id,acctkey,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00151
00152 strncat(data.account_name,"Credit card ",OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
00153 strncat(data.account_name,acctid,OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
00154 }
00155 else if(data.account_type==OfxAccountData::OFX_INVESTMENT){
00156 strncat(data.account_id,brokerid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00157 strncat(data.account_id," ",OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00158 strncat(data.account_id,acctid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00159
00160 strncat(data.account_name,"Investment account ",OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
00161 strncat(data.account_name,acctid,OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
00162 strncat(data.account_name," at broker ",OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
00163 strncat(data.account_name,brokerid,OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
00164 }
00165 else{
00166 strncat(data.account_id,bankid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00167 strncat(data.account_id," ",OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00168 strncat(data.account_id,branchid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00169 strncat(data.account_id," ",OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00170 strncat(data.account_id,acctid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
00171
00172 strncat(data.account_name,"Bank account ",OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
00173 strncat(data.account_name,acctid,OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
00174 }
00175 if(strlen(data.account_id)>=0){
00176 data.account_id_valid=true;
00177 }
00178 }