- Main Page
- Namespaces
- Data Structures
- Files

# 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 OfxAccountData* account, time_t date_from )
    00032 {
    00033   OfxStatementRequest strq( *login, *account, date_from );
    00034   string request = OfxHeader(login->header_version) + 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 OfxAccountData& account, time_t from ):
    00045   OfxRequest(fi),
    00046   m_account(account),
    00047   m_date_from(from)
    00048 {
    00049   Add( SignOnRequest() );
    00050
    00051   if ( account.account_type == account.OFX_CREDITCARD )
    00052     Add(CreditCardStatementRequest());
    00053   else if ( account.account_type == account.OFX_INVESTMENT )
    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.bank_id );
    00063   bankacctfromTag.Add( "ACCTID", m_account.account_number );
    00064   if ( m_account.account_type ==  m_account.OFX_CHECKING )
    00065     bankacctfromTag.Add( "ACCTTYPE", "CHECKING" );
    00066   else if  ( m_account.account_type == m_account.OFX_SAVINGS )
    00067     bankacctfromTag.Add( "ACCTTYPE", "SAVINGS" );
    00068   else if  ( m_account.account_type == m_account.OFX_MONEYMRKT )
    00069     bankacctfromTag.Add( "ACCTTYPE", "MONEYMRKT" );
    00070   else if  ( m_account.account_type == m_account.OFX_CREDITLINE )
    00071     bankacctfromTag.Add( "ACCTTYPE", "CREDITLINE" );
    00072   else if  ( m_account.account_type == m_account.OFX_CMA )
    00073     bankacctfromTag.Add( "ACCTTYPE", "CMA" );
    00074
    00075   OfxAggregate inctranTag("INCTRAN");
    00076   inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
    00077   inctranTag.Add( "INCLUDE","Y" );
    00078
    00079   OfxAggregate stmtrqTag("STMTRQ");
    00080   stmtrqTag.Add( bankacctfromTag );
    00081   stmtrqTag.Add( inctranTag );
    00082
    00083   return RequestMessage("BANK","STMT", stmtrqTag);
    00084 }
    00085
    00086 OfxAggregate OfxStatementRequest::CreditCardStatementRequest(void) const
    00087 {/*
    00088   QString dtstart_string = _dtstart.toString(Qt::ISODate).remove(QRegExp("[^0-9]"));
    00089
    00090   return message("CREDITCARD","CCSTMT",Tag("CCSTMTRQ")
    00091     .subtag(Tag("CCACCTFROM").element("ACCTID",accountnum()))
    00092     .subtag(Tag("INCTRAN").element("DTSTART",dtstart_string).element("INCLUDE","Y")));
    00093 }
    00094 */
    00095   OfxAggregate ccacctfromTag("CCACCTFROM");
    00096   ccacctfromTag.Add( "ACCTID", m_account.account_number );
    00097
    00098   OfxAggregate inctranTag("INCTRAN");
    00099   inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
    00100   inctranTag.Add( "INCLUDE","Y" );
    00101
    00102   OfxAggregate ccstmtrqTag("CCSTMTRQ");
    00103   ccstmtrqTag.Add( ccacctfromTag );
    00104   ccstmtrqTag.Add( inctranTag );
    00105
    00106   return RequestMessage("CREDITCARD","CCSTMT", ccstmtrqTag);
    00107 }
    00108
    00109 OfxAggregate OfxStatementRequest::InvestmentStatementRequest(void) const
    00110 {
    00111   OfxAggregate invacctfromTag("INVACCTFROM");
    00112
    00113   invacctfromTag.Add( "BROKERID", m_account.broker_id );
    00114   invacctfromTag.Add( "ACCTID", m_account.account_number );
    00115
    00116   OfxAggregate inctranTag("INCTRAN");
    00117   inctranTag.Add( "DTSTART", time_t_to_ofxdate( m_date_from ) );
    00118   inctranTag.Add( "INCLUDE","Y" );
    00119
    00120   OfxAggregate incposTag("INCPOS");
    00121   incposTag.Add( "DTASOF", time_t_to_ofxdatetime( time(NULL) ) );
    00122   incposTag.Add( "INCLUDE","Y" );
    00123
    00124   OfxAggregate invstmtrqTag("INVSTMTRQ");
    00125   invstmtrqTag.Add( invacctfromTag );
    00126   invstmtrqTag.Add( inctranTag );
    00127   invstmtrqTag.Add( "INCOO","Y" );
    00128   invstmtrqTag.Add( incposTag );
    00129   invstmtrqTag.Add( "INCBAL","Y" );
    00130
    00131   return RequestMessage("INVSTMT","INVSTMT", invstmtrqTag);
    00132 }
    00133
    00134 char* libofx_request_payment( const OfxFiLogin* login, const OfxAccountData* account, const OfxPayee* payee, const OfxPayment* payment )
    00135 {
    00136   OfxPaymentRequest strq( *login, *account, *payee, *payment );
    00137   string request = OfxHeader(login->header_version) + strq.Output();
    00138
    00139   unsigned size = request.size();
    00140   char* result = (char*)malloc(size + 1);
    00141   request.copy(result,size);
    00142   result[size] = 0;
    00143
    00144   return result;
    00145 }
    00146
    00147 OfxPaymentRequest::OfxPaymentRequest( const OfxFiLogin& fi, const OfxAccountData& account, const OfxPayee& payee, const OfxPayment& payment ):
    00148   OfxRequest(fi),
    00149   m_account(account),
    00150   m_payee(payee),
    00151   m_payment(payment)
    00152 {
    00153   Add( SignOnRequest() );
    00154
    00155   OfxAggregate bankacctfromTag("BANKACCTFROM");
    00156   bankacctfromTag.Add( "BANKID", m_account.bank_id );
    00157   bankacctfromTag.Add( "ACCTID", m_account.account_number );
    00158   if ( m_account.account_type == m_account.OFX_CHECKING)
    00159     bankacctfromTag.Add( "ACCTTYPE", "CHECKING" );
    00160   else if  ( m_account.account_type == m_account.OFX_SAVINGS )
    00161     bankacctfromTag.Add( "ACCTTYPE", "SAVINGS" );
    00162   else if  ( m_account.account_type == m_account.OFX_MONEYMRKT )
    00163     bankacctfromTag.Add( "ACCTTYPE", "MONEYMRKT" );
    00164   else if  ( m_account.account_type ==  m_account.OFX_CREDITLINE )
    00165     bankacctfromTag.Add( "ACCTTYPE", "CREDITLINE" );
    00166   else if  ( m_account.account_type == m_account.OFX_CMA )
    00167     bankacctfromTag.Add( "ACCTTYPE", "CMA" );
    00168
    00169   OfxAggregate payeeTag("PAYEE");
    00170   payeeTag.Add( "NAME", m_payee.name );
    00171   payeeTag.Add( "ADDR1", m_payee.address1 );
    00172   payeeTag.Add( "CITY", m_payee.city );
    00173   payeeTag.Add( "STATE", m_payee.state );
    00174   payeeTag.Add( "POSTALCODE", m_payee.postalcode );
    00175   payeeTag.Add( "PHONE", m_payee.phone );
    00176
    00177   OfxAggregate pmtinfoTag("PMTINFO");
    00178   pmtinfoTag.Add( bankacctfromTag );
    00179   pmtinfoTag.Add( "TRNAMT", m_payment.amount );
    00180   pmtinfoTag.Add( payeeTag );
    00181   pmtinfoTag.Add( "PAYACCT", m_payment.account );
    00182   pmtinfoTag.Add( "DTDUE", m_payment.datedue );
    00183   pmtinfoTag.Add( "MEMO", m_payment.memo );
    00184
    00185   OfxAggregate pmtrqTag("PMTRQ");
    00186   pmtrqTag.Add( pmtinfoTag );
    00187
    00188   Add( RequestMessage("BILLPAY","PMT", pmtrqTag) );
    00189 }
    00190
    00191 CFCT char* libofx_request_payment_status( const struct OfxFiLogin* login, const char* transactionid )
    00192 {
    00193 #if 0
    00194   OfxAggregate pmtinqrqTag( "PMTINQRQ" );
    00195   pmtinqrqTag.Add( "SRVRTID", transactionid );
    00196
    00197   OfxRequest ofx(*login);
    00198   ofx.Add( ofx.SignOnRequest() );
    00199   ofx.Add( ofx.RequestMessage("BILLPAY","PMTINQ", pmtinqrqTag) );
    00200
    00201   string request = OfxHeader() + ofx.Output();
    00202
    00203   unsigned size = request.size();
    00204   char* result = (char*)malloc(size + 1);
    00205   request.copy(result,size);
    00206   result[size] = 0;
    00207 #else
    00208   OfxAggregate payeesyncrq( "PAYEESYNCRQ" );
    00209   payeesyncrq.Add( "TOKEN", "0" );
    00210   payeesyncrq.Add( "TOKENONLY", "N" );
    00211   payeesyncrq.Add( "REFRESH", "Y" );
    00212   payeesyncrq.Add( "REJECTIFMISSING", "N" );
    00213
    00214   OfxAggregate message( "BILLPAYMSGSRQV1" );
    00215   message.Add( payeesyncrq );
    00216
    00217   OfxRequest ofx(*login);
    00218   ofx.Add( ofx.SignOnRequest() );
    00219   ofx.Add( message );
    00220
    00221   string request = OfxHeader(login->header_version) + ofx.Output();
    00222
    00223   unsigned size = request.size();
    00224   char* result = (char*)malloc(size + 1);
    00225   request.copy(result,size);
    00226   result[size] = 0;
    00227
    00228 #endif
    00229   return result;
    00230 }
    00231
    00232 // vim:cin:si:ai:et:ts=2:sw=2:
    00233