LibOFX: ofx_request_statement.cpp Source File

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- 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 char* libofx_request_payment( const OfxFiLogin* login, const OfxAccountInfo* account, const OfxPayee* payee, const OfxPayment* payment )
    00127 {
    00128   OfxPaymentRequest strq( *login, *account, *payee, *payment );
    00129   string request = OfxHeader() + strq.Output();
    00130
    00131   unsigned size = request.size();
    00132   char* result = (char*)malloc(size + 1);
    00133   request.copy(result,size);
    00134   result[size] = 0;
    00135
    00136   return result;
    00137 }
    00138
    00139 OfxPaymentRequest::OfxPaymentRequest( const OfxFiLogin& fi, const OfxAccountInfo& account, const OfxPayee& payee, const OfxPayment& payment ):
    00140   OfxRequest(fi),
    00141   m_account(account),
    00142   m_payee(payee),
    00143   m_payment(payment)
    00144 {
    00145   Add( SignOnRequest() );
    00146
    00147   OfxAggregate bankacctfromTag("BANKACCTFROM");
    00148   bankacctfromTag.Add( "BANKID", m_account.bankid );
    00149   bankacctfromTag.Add( "ACCTID", m_account.accountid );
    00150   bankacctfromTag.Add( "ACCTTYPE", "CHECKING" );
    00151   // FIXME "CHECKING" should not be hard-coded
    00152
    00153   OfxAggregate payeeTag("PAYEE");
    00154   payeeTag.Add( "NAME", m_payee.name );
    00155   payeeTag.Add( "ADDR1", m_payee.address1 );
    00156   payeeTag.Add( "CITY", m_payee.city );
    00157   payeeTag.Add( "STATE", m_payee.state );
    00158   payeeTag.Add( "POSTALCODE", m_payee.postalcode );
    00159   payeeTag.Add( "PHONE", m_payee.phone );
    00160
    00161   OfxAggregate pmtinfoTag("PMTINFO");
    00162   pmtinfoTag.Add( bankacctfromTag );
    00163   pmtinfoTag.Add( "TRNAMT", m_payment.amount );
    00164   pmtinfoTag.Add( payeeTag );
    00165   pmtinfoTag.Add( "PAYACCT", m_payment.account );
    00166   pmtinfoTag.Add( "DTDUE", m_payment.datedue );
    00167   pmtinfoTag.Add( "MEMO", m_payment.memo );
    00168
    00169   OfxAggregate pmtrqTag("PMTRQ");
    00170   pmtrqTag.Add( pmtinfoTag );
    00171
    00172   Add( RequestMessage("BILLPAY","PMT", pmtrqTag) );
    00173 }
    00174
    00175 CFCT char* libofx_request_payment_status( const struct OfxFiLogin* login, const char* transactionid )
    00176 {
    00177 #if 0
    00178   OfxAggregate pmtinqrqTag( "PMTINQRQ" );
    00179   pmtinqrqTag.Add( "SRVRTID", transactionid );
    00180
    00181   OfxRequest ofx(*login);
    00182   ofx.Add( ofx.SignOnRequest() );
    00183   ofx.Add( ofx.RequestMessage("BILLPAY","PMTINQ", pmtinqrqTag) );
    00184
    00185   string request = OfxHeader() + ofx.Output();
    00186
    00187   unsigned size = request.size();
    00188   char* result = (char*)malloc(size + 1);
    00189   request.copy(result,size);
    00190   result[size] = 0;
    00191 #else
    00192   OfxAggregate payeesyncrq( "PAYEESYNCRQ" );
    00193   payeesyncrq.Add( "TOKEN", "0" );
    00194   payeesyncrq.Add( "TOKENONLY", "N" );
    00195   payeesyncrq.Add( "REFRESH", "Y" );
    00196   payeesyncrq.Add( "REJECTIFMISSING", "N" );
    00197
    00198   OfxAggregate message( "BILLPAYMSGSRQV1" );
    00199   message.Add( payeesyncrq );
    00200
    00201   OfxRequest ofx(*login);
    00202   ofx.Add( ofx.SignOnRequest() );
    00203   ofx.Add( message );
    00204
    00205   string request = OfxHeader() + ofx.Output();
    00206
    00207   unsigned size = request.size();
    00208   char* result = (char*)malloc(size + 1);
    00209   request.copy(result,size);
    00210   result[size] = 0;
    00211
    00212 #endif
    00213   return result;
    00214 }
    00215
    00216 // vim:cin:si:ai:et:ts=2:sw=2:
    00217