Main Page | Class Hierarchy | Data Structures | File List | Data Fields | Globals

ofx_container_account.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002          ofx_container_account.cpp 
00003                              -------------------
00004     copyright            : (C) 2002 by Benoit Grégoire
00005     email                : bock@step.polymtl.ca
00006 ***************************************************************************/
00011 /***************************************************************************
00012  *                                                                         *
00013  *   This program is free software; you can redistribute it and/or modify  *
00014  *   it under the terms of the GNU General Public License as published by  *
00015  *   the Free Software Foundation; either version 2 of the License, or     *
00016  *   (at your option) any later version.                                   *
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  *                      OfxAccountContainer                                *
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       /*Set the type for a creditcard account.  Bank account specific 
00049         OFX elements will set this attribute elsewhere */
00050       data.account_type = data.OFX_CREDITCARD;
00051       data.account_type_valid = true;
00052     }
00053   if(para_tag_identifier== "INVACCTFROM")
00054     {
00055       /*Set the type for an investment account.  Bank account specific 
00056         OFX elements will set this attribute elsewhere */
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); /* In ISO-4217 format */
00062     data.currency_valid=true;
00063   }
00064 }
00065 OfxAccountContainer::~OfxAccountContainer()
00066 {
00067   /*  if (parentcontainer->type == "STATEMENT")
00068       {
00069       ((OfxStatementContainer*)parentcontainer)->add_account(data);
00070       }
00071       ofx_proc_account_cb (data);*/
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"){ /* For investment accounts */
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     /* AccountType CREDITCARD is set at object creation, if appropriate */
00109     else{
00110       data.account_type_valid=false;
00111     }
00112   }
00113   else{
00114     /* Redirect unknown identifiers to the base class */
00115     OfxGenericContainer::add_attribute(identifier, value);
00116   }
00117 }//end OfxAccountContainer::add_attribute()
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 }//end OfxAccountContainer::gen_account_id()

Generated on Fri Sep 12 00:35:46 2003 for LibOFX by doxygen 1.3.3