LibOFX

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- 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                : benoitg@coeus.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(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     /*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   {
    00062     strncpy(data.currency, ((OfxStatementContainer*)parentcontainer)->data.currency, OFX_CURRENCY_LENGTH); /* In ISO-4217 format */
    00063     data.currency_valid = true;
    00064   }
    00065 }
    00066 OfxAccountContainer::~OfxAccountContainer()
    00067 {
    00068   /*  if (parentcontainer->type == "STATEMENT")
    00069       {
    00070       ((OfxStatementContainer*)parentcontainer)->add_account(data);
    00071       }
    00072       ofx_proc_account_cb (data);*/
    00073 }
    00074
    00075 void OfxAccountContainer::add_attribute(const string identifier, const string value)
    00076 {
    00077   if ( identifier == "BANKID")
    00078   {
    00079     strncpy(bankid, value.c_str(), OFX_BANKID_LENGTH);
    00080     data.bank_id_valid = true;
    00081     strncpy(data.bank_id, value.c_str(), OFX_BANKID_LENGTH);
    00082   }
    00083   else if ( identifier == "BRANCHID")
    00084   {
    00085     strncpy(branchid, value.c_str(), OFX_BRANCHID_LENGTH);
    00086     data.branch_id_valid = true;
    00087     strncpy(data.branch_id, value.c_str(), OFX_BRANCHID_LENGTH);
    00088   }
    00089   else if ( identifier == "ACCTID")
    00090   {
    00091     strncpy(acctid, value.c_str(), OFX_ACCTID_LENGTH);
    00092     data.account_number_valid = true;
    00093     strncpy(data.account_number, value.c_str(), OFX_ACCTID_LENGTH);
    00094   }
    00095   else if ( identifier == "ACCTKEY")
    00096   {
    00097     strncpy(acctkey, value.c_str(), OFX_ACCTKEY_LENGTH);
    00098   }
    00099   else if ( identifier == "BROKERID")     /* For investment accounts */
    00100   {
    00101     strncpy(brokerid, value.c_str(), OFX_BROKERID_LENGTH);
    00102     data.broker_id_valid = true;
    00103     strncpy(data.broker_id, value.c_str(), OFX_BROKERID_LENGTH);
    00104   }
    00105   else if ((identifier == "ACCTTYPE") || (identifier == "ACCTTYPE2"))
    00106   {
    00107     data.account_type_valid = true;
    00108     if (value == "CHECKING")
    00109     {
    00110       data.account_type = data.OFX_CHECKING;
    00111     }
    00112     else if (value == "SAVINGS")
    00113     {
    00114       data.account_type = data.OFX_SAVINGS;
    00115     }
    00116     else if (value == "MONEYMRKT")
    00117     {
    00118       data.account_type = data.OFX_MONEYMRKT;
    00119     }
    00120     else if (value == "CREDITLINE")
    00121     {
    00122       data.account_type = data.OFX_CREDITLINE;
    00123     }
    00124     else if (value == "CMA")
    00125     {
    00126       data.account_type = data.OFX_CMA;
    00127     }
    00128     /* AccountType CREDITCARD is set at object creation, if appropriate */
    00129     else
    00130     {
    00131       data.account_type_valid = false;
    00132     }
    00133   }
    00134   else
    00135   {
    00136     /* Redirect unknown identifiers to the base class */
    00137     OfxGenericContainer::add_attribute(identifier, value);
    00138   }
    00139 }//end OfxAccountContainer::add_attribute()
    00140
    00141 int OfxAccountContainer::gen_event()
    00142 {
    00143   libofx_context->accountCallback(data);
    00144   return true;
    00145 }
    00146
    00147 int  OfxAccountContainer::add_to_main_tree()
    00148 {
    00149   gen_account_id ();
    00150
    00151   if (MainContainer != NULL)
    00152   {
    00153     return MainContainer->add_container(this);
    00154   }
    00155   else
    00156   {
    00157     return false;
    00158   }
    00159 }
    00160
    00161 void OfxAccountContainer::gen_account_id(void)
    00162 {
    00163   if (data.account_type == OfxAccountData::OFX_CREDITCARD)
    00164   {
    00165     strncat(data.account_id, acctid, OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
    00166     strncat(data.account_id, " ", OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
    00167     strncat(data.account_id, acctkey, OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
    00168
    00169     strncat(data.account_name, "Credit card ", OFX_ACCOUNT_NAME_LENGTH - strlen(data.account_name));
    00170     strncat(data.account_name, acctid, OFX_ACCOUNT_NAME_LENGTH - strlen(data.account_name));
    00171   }
    00172   else if (data.account_type == OfxAccountData::OFX_INVESTMENT)
    00173   {
    00174     strncat(data.account_id, brokerid, OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
    00175     strncat(data.account_id, " ", OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
    00176     strncat(data.account_id, acctid, OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
    00177
    00178     strncat(data.account_name, "Investment account ", OFX_ACCOUNT_NAME_LENGTH - strlen(data.account_name));
    00179     strncat(data.account_name, acctid, OFX_ACCOUNT_NAME_LENGTH - strlen(data.account_name));
    00180     strncat(data.account_name, " at broker ", OFX_ACCOUNT_NAME_LENGTH - strlen(data.account_name));
    00181     strncat(data.account_name, brokerid, OFX_ACCOUNT_NAME_LENGTH - strlen(data.account_name));
    00182   }
    00183   else
    00184   {
    00185     strncat(data.account_id, bankid, OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
    00186     strncat(data.account_id, " ", OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
    00187     strncat(data.account_id, branchid, OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
    00188     strncat(data.account_id, " ", OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
    00189     strncat(data.account_id, acctid, OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
    00190
    00191     strncat(data.account_name, "Bank account ", OFX_ACCOUNT_NAME_LENGTH - strlen(data.account_name));
    00192     strncat(data.account_name, acctid, OFX_ACCOUNT_NAME_LENGTH - strlen(data.account_name));
    00193   }
    00194   if (strlen(data.account_id) >= 0)
    00195   {
    00196     data.account_id_valid = true;
    00197   }
    00198 }//end OfxAccountContainer::gen_account_id()