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

ofx_container_transaction.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  *                      OfxTransactionContainer                            *
00034  ***************************************************************************/
00035 
00036 OfxTransactionContainer::OfxTransactionContainer(OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
00037   OfxGenericContainer(para_parentcontainer, para_tag_identifier)
00038 {
00039   OfxGenericContainer * tmp_parentcontainer=parentcontainer;
00040 
00041   memset(&data,0,sizeof(data));
00042   type="TRANSACTION";
00043   /* Find the parent statement container*/
00044   while(tmp_parentcontainer!=NULL&&tmp_parentcontainer->type!="STATEMENT")
00045     {
00046       tmp_parentcontainer=parentcontainer->parentcontainer;
00047     }  
00048   if (tmp_parentcontainer!=NULL){
00049     parent_statement=(OfxStatementContainer*)tmp_parentcontainer;
00050   }
00051   else{
00052     parent_statement=NULL;
00053     message_out(ERROR,"Unable to find the enclosing statement container this transaction");
00054   }
00055   if (parent_statement!=NULL&&parent_statement->data.account_id_valid==true){
00056     strncpy(data.account_id,parent_statement->data.account_id,OFX_ACCOUNT_ID_LENGTH);
00057     data.account_id_valid = true;
00058   }
00059 }
00060 OfxTransactionContainer::~OfxTransactionContainer()
00061 {
00062 
00063 }
00064 
00065 int OfxTransactionContainer::gen_event()
00066 {
00067   if(data.unique_id_valid==true&&MainContainer != NULL)
00068     {
00069       data.security_data_ptr = MainContainer->find_security(data.unique_id);
00070       if(data.security_data_ptr!=NULL)
00071         {
00072           data.security_data_valid = true;
00073         }
00074     }
00075   ofx_proc_transaction_cb(data);
00076   return true;
00077 }
00078 
00079 int  OfxTransactionContainer::add_to_main_tree()
00080 {
00081 
00082   if(MainContainer != NULL)
00083     {
00084       return MainContainer->add_container(this);
00085     }
00086   else
00087     {
00088       return false;
00089     }
00090 }
00091 
00092 
00093 void OfxTransactionContainer::add_attribute(const string identifier, const string value)
00094 {
00095 
00096   if(identifier=="DTPOSTED"){
00097     data.date_posted = ofxdate_to_time_t(value);
00098     data.date_posted_valid = true;
00099   }
00100   else if(identifier=="DTUSER"){
00101     data.date_initiated = ofxdate_to_time_t(value);
00102     data.date_initiated_valid = true;
00103   }
00104   else if(identifier=="DTAVAIL"){
00105     data.date_funds_available = ofxdate_to_time_t(value);
00106     data.date_funds_available_valid = true;
00107   }
00108   else if(identifier=="FITID"){
00109     strncpy(data.fi_id,value.c_str(), sizeof(data.fi_id));
00110     data.fi_id_valid = true;
00111   }
00112   else if(identifier=="CORRECTFITID"){
00113     strncpy(data.fi_id_corrected,value.c_str(), sizeof(data.fi_id));
00114     data.fi_id_corrected_valid = true;
00115   }
00116   else if(identifier=="CORRECTACTION"){
00117     data.fi_id_correction_action_valid=true;
00118     if(value=="REPLACE"){
00119       data.fi_id_correction_action=data.REPLACE;
00120     }
00121     else if(value=="DELETE"){
00122       data.fi_id_correction_action=data.DELETE;
00123     }
00124     else{
00125       data.fi_id_correction_action_valid=false;
00126     }
00127   }
00128   else if((identifier=="SRVRTID")||(identifier=="SRVRTID2")){
00129     strncpy(data.server_transaction_id,value.c_str(), sizeof(data.server_transaction_id));
00130     data.server_transaction_id_valid = true;
00131   }
00132   else if(identifier=="MEMO" || identifier=="MEMO2"){
00133     strncpy(data.memo,value.c_str(), sizeof(data.memo));
00134     data.memo_valid = true;
00135   }
00136   else{
00137     /* Redirect unknown identifiers to the base class */
00138     OfxGenericContainer::add_attribute(identifier, value);
00139   }
00140 }// end OfxTransactionContainer::add_attribute()
00141 
00142 void OfxTransactionContainer::add_account(OfxAccountData * account_data)
00143 {
00144   if(account_data->account_id_valid==true)
00145     {
00146       data.account_ptr = account_data;
00147       strncpy(data.account_id,account_data->account_id,OFX_ACCOUNT_ID_LENGTH);
00148       data.account_id_valid = true;
00149     }
00150 }
00151 
00152 /***************************************************************************
00153  *                      OfxBankTransactionContainer                        *
00154  ***************************************************************************/
00155 
00156 OfxBankTransactionContainer::OfxBankTransactionContainer(OfxGenericContainer *para_parentcontainer, string para_tag_identifier): 
00157   OfxTransactionContainer(para_parentcontainer, para_tag_identifier)
00158 {
00159   ;
00160 }
00161 void OfxBankTransactionContainer::add_attribute(const string identifier, const string value)
00162 {
00163   if( identifier=="TRNTYPE"){
00164     data.transactiontype_valid=true;
00165     if(value=="CREDIT"){
00166       data.transactiontype=data.OFX_CREDIT;
00167     }
00168     else if(value=="DEBIT"){
00169       data.transactiontype=data.OFX_DEBIT;
00170     }
00171     else if(value=="INT"){
00172       data.transactiontype=data.OFX_INT;
00173     }
00174     else if(value=="DIV"){
00175       data.transactiontype=data.OFX_DIV;
00176     }
00177     else if(value=="FEE"){
00178       data.transactiontype=data.OFX_FEE;
00179     }
00180     else if(value=="SRVCHG"){
00181       data.transactiontype=data.OFX_SRVCHG;
00182     }
00183     else if(value=="DEP"){
00184       data.transactiontype=data.OFX_DEP;
00185     }
00186     else if(value=="ATM"){
00187       data.transactiontype=data.OFX_ATM;
00188     }
00189     else if(value=="POS"){
00190       data.transactiontype=data.OFX_POS;
00191     }
00192     else if(value=="XFER"){
00193       data.transactiontype=data.OFX_XFER;
00194     }
00195     else if(value=="CHECK"){
00196       data.transactiontype=data.OFX_CHECK;
00197     }
00198     else if(value=="PAYMENT"){
00199       data.transactiontype=data.OFX_PAYMENT;
00200     }
00201     else if(value=="CASH"){
00202       data.transactiontype=data.OFX_CASH;
00203     }
00204     else if(value=="DIRECTDEP"){
00205       data.transactiontype=data.OFX_DIRECTDEP;
00206     }
00207     else if(value=="DIRECTDEBIT"){
00208       data.transactiontype=data.OFX_DIRECTDEBIT;
00209     }
00210     else if(value=="REPEATPMT"){
00211       data.transactiontype=data.OFX_REPEATPMT;
00212     }
00213     else if(value=="OTHER"){
00214       data.transactiontype=data.OFX_OTHER;
00215     }
00216     else {
00217       data.transactiontype_valid=false;
00218     }
00219   }//end TRANSTYPE
00220   else if(identifier=="TRNAMT"){
00221     data.amount=ofxamount_to_double(value);
00222     data.amount_valid=true;
00223     data.units = -data.amount;
00224     data.units_valid=true;
00225     data.unitprice = 1,00;
00226     data.unitprice_valid=true;
00227   }
00228   else if(identifier=="CHECKNUM"){
00229     strncpy(data.check_number,value.c_str(), sizeof(data.check_number));
00230     data.check_number_valid = true;
00231   }
00232   else if(identifier=="REFNUM"){
00233     strncpy(data.reference_number,value.c_str(), sizeof(data.reference_number));
00234     data.reference_number_valid = true;
00235   }
00236   else if(identifier=="SIC"){
00237     data.standard_industrial_code = atoi(value.c_str());
00238     data.standard_industrial_code_valid = true;
00239   }
00240   else if((identifier=="PAYEEID")||(identifier=="PAYEEID2")){
00241     strncpy(data.payee_id,value.c_str(), sizeof(data.payee_id));
00242     data.payee_id_valid = true;
00243   }
00244   else if(identifier=="NAME"){
00245     strncpy(data.name,value.c_str(), sizeof(data.name));
00246     data.name_valid = true;
00247   }
00248   else{
00249     /* Redirect unknown identifiers to base class */
00250     OfxTransactionContainer::add_attribute(identifier, value);
00251   }
00252 }//end OfxBankTransactionContainer::add_attribute
00253  
00254 
00255 /***************************************************************************
00256  *                    OfxInvestmentTransactionContainer                    *
00257  ***************************************************************************/
00258 
00259 OfxInvestmentTransactionContainer::OfxInvestmentTransactionContainer(OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
00260   OfxTransactionContainer(para_parentcontainer, para_tag_identifier)
00261 {
00262   type="INVESTMENT";
00263   data.transactiontype=data.OFX_OTHER;
00264   data.transactiontype_valid=true;
00265   
00266   data.invtransactiontype_valid=true; 
00267   if(para_tag_identifier=="BUYDEBT"){
00268     data.invtransactiontype=data.OFX_BUYDEBT;
00269   }
00270   else if(para_tag_identifier=="BUYMF"){
00271     data.invtransactiontype=data.OFX_BUYMF;
00272   }
00273   else if(para_tag_identifier=="BUYOPT"){
00274     data.invtransactiontype=data.OFX_BUYOPT;
00275   }
00276   else if(para_tag_identifier=="BUYOTHER"){
00277     data.invtransactiontype=data.OFX_BUYOTHER;
00278   }
00279   else if(para_tag_identifier=="BUYSTOCK"){
00280     data.invtransactiontype=data.OFX_BUYSTOCK;
00281   }
00282   else if(para_tag_identifier=="CLOSUREOPT"){
00283     data.invtransactiontype=data.OFX_CLOSUREOPT;
00284   }
00285   else if(para_tag_identifier=="INCOME"){
00286     data.invtransactiontype=data.OFX_INCOME;
00287   }
00288   else if(para_tag_identifier=="INVEXPENSE"){
00289     data.invtransactiontype=data.OFX_INVEXPENSE;
00290   }
00291   else if(para_tag_identifier=="JRNLFUND"){
00292     data.invtransactiontype=data.OFX_JRNLFUND;
00293   }
00294   else if(para_tag_identifier=="JRNLSEC"){
00295     data.invtransactiontype=data.OFX_JRNLSEC;
00296   }
00297   else if(para_tag_identifier=="MARGININTEREST"){
00298     data.invtransactiontype=data.OFX_MARGININTEREST;
00299   }
00300   else if(para_tag_identifier=="REINVEST"){
00301     data.invtransactiontype=data.OFX_REINVEST;
00302   }
00303   else if(para_tag_identifier=="RETOFCAP"){
00304     data.invtransactiontype=data.OFX_RETOFCAP;
00305   }
00306   else if(para_tag_identifier=="SELLDEBT"){
00307     data.invtransactiontype=data.OFX_SELLDEBT;
00308   }
00309   else if(para_tag_identifier=="SELLMF"){
00310     data.invtransactiontype=data.OFX_SELLMF;
00311   }
00312   else if(para_tag_identifier=="SELLOPT"){
00313     data.invtransactiontype=data.OFX_SELLOPT;
00314   }
00315   else if(para_tag_identifier=="SELLOTHER"){
00316     data.invtransactiontype=data.OFX_SELLOTHER;
00317   }
00318   else if(para_tag_identifier=="SELLSTOCK"){
00319     data.invtransactiontype=data.OFX_SELLSTOCK;
00320   }
00321   else if(para_tag_identifier=="SPLIT"){
00322     data.invtransactiontype=data.OFX_SPLIT;
00323   }
00324   else if(para_tag_identifier=="TRANSFER"){
00325     data.invtransactiontype=data.OFX_TRANSFER;
00326   }
00327   else{
00328     message_out(ERROR, "This should not happen, "+para_tag_identifier+" is an unknown investment transaction type");
00329     data.invtransactiontype_valid=false; 
00330   }
00331 }
00332 
00333 void OfxInvestmentTransactionContainer::add_attribute(const string identifier, const string value)
00334 {
00335   if(identifier=="UNIQUEID"){
00336     strncpy(data.unique_id,value.c_str(), sizeof(data.unique_id));
00337     data.unique_id_valid = true;
00338   }
00339   else if(identifier=="UNIQUEIDTYPE"){
00340     strncpy(data.unique_id_type,value.c_str(), sizeof(data.unique_id_type));
00341     data.unique_id_type_valid = true;
00342   }
00343   else if(identifier=="UNITS"){
00344     data.units=ofxamount_to_double(value);
00345     data.units_valid = true;
00346   }
00347   else if(identifier=="UNITPRICE"){
00348     data.unitprice=ofxamount_to_double(value);
00349     data.unitprice_valid = true;
00350   }
00351   else if(identifier=="MKTVAL"){
00352     message_out(DEBUG, "MKTVAL of "+value+" ignored since MKTVAL should always be UNITS*UNITPRICE");
00353   }
00354   else if(identifier=="TOTAL"){
00355     data.amount=ofxamount_to_double(value);
00356     data.amount_valid = true;
00357   }
00358   else if(identifier=="DTSETTLE"){
00359     data.date_posted = ofxdate_to_time_t(value);
00360     data.date_posted_valid = true;
00361   }
00362   else if(identifier=="DTTRADE"){
00363     data.date_initiated = ofxdate_to_time_t(value);
00364     data.date_initiated_valid = true;
00365   }
00366   else{
00367     /* Redirect unknown identifiers to the base class */
00368     OfxTransactionContainer::add_attribute(identifier, value);
00369   }
00370 }//end OfxInvestmentTransactionContainer::add_attribute
00371 

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