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

# ofx_request_statement.cpp

Go to the documentation of this file.

    00001 /***************************************************************************
    00002          ofx_request_statement.cpp
    00003                              -------------------
    00004     copyright            : (C) 2005 by Ace Jones
    00005     email                : acejones@users.sourceforge.net
    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 "libofx.h"
    00026 #include "ofx_utilities.hh"
    00027 #include "ofx_request_statement.hh"
    00028
    00029 using namespace std;
    00030
    00031 char* libofx_request_statement( const OfxFiLogin* login, const OfxAccountInfo* account, time_t date_from )
    00032 {
    00033   OfxStatementRequest strq( *login, *account, date_from );
    00034   string request = OfxHeader() + strq.Output();
    00035
    00036   unsigned size = request.size();
    00037   char* result = (char*)malloc(size + 1);
    00038   request.copy(result,size);
    00039   result[size] = 0;
    00040
    00041   return result;
    00042 }
    00043
    00044 OfxStatementRequest::OfxStatementRequest( const OfxFiLogin& fi, const OfxAccountInfo& account, time_t from ):
    00045   OfxRequest(fi),
    00046   m_account(account),
    00047   m_date_from(from)
    00048 {
    00049   Add( SignOnRequest() );
    00050
    00051   if ( account.type == OFX_CREDITCARD_ACCOUNT )
    00052     Add(CreditCardStatementRequest());
    00053   else if ( account.type == OFX_INVEST_ACCOUNT )
    00054     Add(InvestmentStatementRequest());
    00055   else
    00056     Add(BankStatementRequest());
    00057 }
    00058
    00059 OfxAggregate OfxStatementRequest::BankStatementRequest(void) const
    00060 {
    00061   OfxAggregate bankacctfromTag("BANKACCTFROM");
    00062   bankacctfromTag.Add( "BANKID", m_account.bankid );
    00063   bankacctfromTag.Add( "ACCTID", m_account.accountid );
    00064   bankacctfromTag.Add( "ACCTTYPE", "CHECKING" );
    00065   // FIXME "CHECKING" should not be hard-coded
    00066
    00067   OfxAggregate inctranTag("INCTRAN");
    00068   inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
    00069   inctranTag.Add( "INCLUDE","Y" );
    00070
    00071   OfxAggregate stmtrqTag("STMTRQ");
    00072   stmtrqTag.Add( bankacctfromTag );
    00073   stmtrqTag.Add( inctranTag );
    00074
    00075   return RequestMessage("BANK","STMT", stmtrqTag);
    00076 }
    00077
    00078 OfxAggregate OfxStatementRequest::CreditCardStatementRequest(void) const
    00079 {/*
    00080   QString dtstart_string = _dtstart.toString(Qt::ISODate).remove(QRegExp("[^0-9]"));
    00081
    00082   return message("CREDITCARD","CCSTMT",Tag("CCSTMTRQ")
    00083     .subtag(Tag("CCACCTFROM").element("ACCTID",accountnum()))
    00084     .subtag(Tag("INCTRAN").element("DTSTART",dtstart_string).element("INCLUDE","Y")));
    00085 }
    00086 */
    00087   OfxAggregate ccacctfromTag("CCACCTFROM");
    00088   ccacctfromTag.Add( "ACCTID", m_account.accountid );
    00089
    00090   OfxAggregate inctranTag("INCTRAN");
    00091   inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
    00092   inctranTag.Add( "INCLUDE","Y" );
    00093
    00094   OfxAggregate ccstmtrqTag("CCSTMTRQ");
    00095   ccstmtrqTag.Add( ccacctfromTag );
    00096   ccstmtrqTag.Add( inctranTag );
    00097
    00098   return RequestMessage("CREDITCARD","CCSTMT", ccstmtrqTag);
    00099 }
    00100
    00101 OfxAggregate OfxStatementRequest::InvestmentStatementRequest(void) const
    00102 {
    00103   OfxAggregate invacctfromTag("INVACCTFROM");
    00104
    00105   invacctfromTag.Add( "BROKERID", m_account.brokerid );
    00106   invacctfromTag.Add( "ACCTID", m_account.accountid );
    00107
    00108   OfxAggregate inctranTag("INCTRAN");
    00109   inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
    00110   inctranTag.Add( "INCLUDE","Y" );
    00111
    00112   OfxAggregate incposTag("INCPOS");
    00113   incposTag.Add( "DTASOF", time_t_to_ofxdatetime( time(NULL) ) );
    00114   incposTag.Add( "INCLUDE","Y" );
    00115
    00116   OfxAggregate invstmtrqTag("INVSTMTRQ");
    00117   invstmtrqTag.Add( invacctfromTag );
    00118   invstmtrqTag.Add( inctranTag );
    00119   invstmtrqTag.Add( "INCOO","Y" );
    00120   invstmtrqTag.Add( incposTag );
    00121   invstmtrqTag.Add( "INCBAL","Y" );
    00122
    00123   return RequestMessage("INVSTMT","INVSTMT", invstmtrqTag);
    00124 }
    00125
    00126 // vim:cin:si:ai:et:ts=2:sw=2:
    00127