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 "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
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
00081
00082
00083
00084
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
00127