Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

ofx2qif.c

Go to the documentation of this file.
00001 /***************************************************************************
00002                                    ofx2qif.c
00003                              -------------------
00004     copyright            : (C) 2002 by Benoit Grégoire
00005     email                : bock@step.polymtl.ca
00006 ***************************************************************************/
00032 /***************************************************************************
00033  *                                                                         *
00034  *   This program is free software; you can redistribute it and/or modify  *
00035  *   it under the terms of the GNU General Public License as published by  *
00036  *   the Free Software Foundation; either version 2 of the License, or     *
00037  *   (at your option) any later version.                                   *
00038  *                                                                         *
00039  ***************************************************************************/
00040 
00041 #include <stdio.h>
00042 #include <string.h>
00043 #include <time.h>
00044 #include "libofx.h"
00045 
00046 #define QIF_FILE_MAX_SIZE 256000 
00047 
00048 int main (int argc, char *argv[])
00049 {
00050 extern int ofx_PARSER_msg;
00051 extern int ofx_DEBUG_msg;
00052 extern int ofx_WARNING_msg;
00053 extern int ofx_ERROR_msg;
00054 extern int ofx_INFO_msg;
00055 extern int ofx_STATUS_msg;
00056  ofx_PARSER_msg = false;
00057  ofx_DEBUG_msg = false;
00058  ofx_WARNING_msg = false;
00059  ofx_ERROR_msg = false;
00060  ofx_INFO_msg = false;
00061  ofx_STATUS_msg = false;
00062 
00063 ofx_proc_file(argc, argv);
00064 return 0;
00065 }
00066 
00067 int ofx_proc_status_cb(struct OfxStatusData data)
00068 {
00069 return 0;
00070 }
00071 int ofx_proc_security_cb(struct OfxSecurityData data)
00072 {
00073 return 0;
00074 }
00075 int ofx_proc_transaction_cb(struct OfxTransactionData data)
00076 {
00077   char dest_string[255];
00078   char trans_buff[4096];
00079   struct tm temp_tm;
00080   char trans_list_buff[4096];
00081 
00082   if(data.date_posted_valid==true){
00083     temp_tm = *localtime(&(data.date_posted));
00084     sprintf(trans_buff, "D%d%s%d%s%d%s", temp_tm.tm_mday, "/", temp_tm.tm_mon+1, "/", temp_tm.tm_year+1900, "\n");
00085     strncat(trans_list_buff, trans_buff, QIF_FILE_MAX_SIZE - strlen(trans_list_buff));
00086   }
00087   if(data.amount_valid==true){
00088     sprintf(trans_buff, "T%.2f%s",data.amount,"\n");
00089     strncat(trans_list_buff, trans_buff, QIF_FILE_MAX_SIZE - strlen(trans_list_buff));
00090   }
00091   if(data.check_number_valid==true){
00092     sprintf(trans_buff, "N%s%s",data.check_number,"\n");
00093     strncat(trans_list_buff, trans_buff, QIF_FILE_MAX_SIZE - strlen(trans_list_buff));
00094   }
00095   else if(data.reference_number_valid==true){
00096     sprintf(trans_buff, "N%s%s",data.reference_number,"\n");
00097       strncat(trans_list_buff, trans_buff, QIF_FILE_MAX_SIZE - strlen(trans_list_buff));
00098 }
00099 if(data.name_valid==true){
00100     sprintf(trans_buff, "P%s%s",data.name,"\n");
00101         strncat(trans_list_buff, trans_buff, QIF_FILE_MAX_SIZE - strlen(trans_list_buff));
00102 }
00103 if(data.memo_valid==true){
00104     sprintf(trans_buff, "M%s%s",data.memo,"\n");
00105         strncat(trans_list_buff, trans_buff, QIF_FILE_MAX_SIZE - strlen(trans_list_buff));
00106 }
00107 /* Add PAYEE and ADRESS here once supported by the library */
00108 
00109 
00110 if(data.transactiontype_valid==true){
00111     switch(data.transactiontype){
00112         case OFX_CREDIT: strncpy(dest_string, "Generic credit", sizeof(dest_string));
00113         break;
00114         case OFX_DEBIT: strncpy(dest_string, "Generic debit", sizeof(dest_string));
00115         break;
00116         case OFX_INT: strncpy(dest_string, "Interest earned or paid (Note: Depends on signage of amount)", sizeof(dest_string));
00117         break;
00118         case OFX_DIV: strncpy(dest_string, "Dividend", sizeof(dest_string));
00119         break;
00120         case OFX_FEE: strncpy(dest_string, "FI fee", sizeof(dest_string));
00121         break;
00122         case OFX_SRVCHG: strncpy(dest_string, "Service charge", sizeof(dest_string));
00123         break;
00124         case OFX_DEP: strncpy(dest_string, "Deposit", sizeof(dest_string));
00125         break;
00126         case OFX_ATM: strncpy(dest_string, "ATM debit or credit (Note: Depends on signage of amount)", sizeof(dest_string));
00127         break;
00128         case OFX_POS: strncpy(dest_string, "Point of sale debit or credit (Note: Depends on signage of amount)", sizeof(dest_string));
00129         break;
00130         case OFX_XFER: strncpy(dest_string, "Transfer", sizeof(dest_string));
00131         break;
00132         case OFX_CHECK: strncpy(dest_string, "Check", sizeof(dest_string));
00133         break;
00134         case OFX_PAYMENT: strncpy(dest_string, "Electronic payment", sizeof(dest_string));
00135         break;
00136         case OFX_CASH: strncpy(dest_string, "Cash withdrawal", sizeof(dest_string));
00137         break;
00138         case OFX_DIRECTDEP: strncpy(dest_string, "Direct deposit", sizeof(dest_string));
00139         break;
00140         case OFX_DIRECTDEBIT: strncpy(dest_string, "Merchant initiated debit", sizeof(dest_string));
00141         break;
00142         case OFX_REPEATPMT: strncpy(dest_string, "Repeating payment/standing order", sizeof(dest_string));
00143         break;
00144         case OFX_OTHER: strncpy(dest_string, "Other", sizeof(dest_string));
00145         break;
00146         default : strncpy(dest_string, "Unknown transaction type", sizeof(dest_string));
00147         break;
00148     }
00149     sprintf(trans_buff, "L%s%s",dest_string,"\n");
00150     strncat(trans_list_buff, trans_buff, QIF_FILE_MAX_SIZE - strlen(trans_list_buff));
00151 }
00152  sprintf(trans_buff, "^\n");
00153  strncat(trans_list_buff, trans_buff, QIF_FILE_MAX_SIZE - strlen(trans_list_buff));
00154  printf(trans_list_buff);
00155  return 0;
00156 }/* end ofx_proc_transaction() */
00157 
00158 int ofx_proc_statement_cb(struct OfxStatementData data)
00159 {
00160   struct tm temp_tm;
00161 
00162   printf("!Account\n");
00163   if(data.account_id_valid==true){
00164     /* Use the account id as the qif name of the account */
00165     printf("N%s%s",data.account_id,"\n");
00166   }
00167   if(data.account_ptr->account_type_valid==true)
00168     {
00169       switch(data.account_ptr->account_type){
00170       case OFX_CHECKING : printf("TBank\n");
00171         break;
00172       case OFX_SAVINGS :  printf("TBank\n");
00173         break;
00174       case OFX_MONEYMRKT :  printf("TOth A\n");
00175         break;
00176       case OFX_CREDITLINE :  printf("TOth L\n");
00177         break;
00178       case OFX_CMA :  printf("TOth A\n");
00179         break;
00180       case OFX_CREDITCARD :   printf("TCCard\n");
00181         break;
00182       default: perror("WRITEME: ofx_proc_account() This is an unknown account type!");
00183       }
00184     }
00185   printf("DOFX online account\n");
00186 
00187   if(data.ledger_balance_date_valid==true){
00188     temp_tm = *localtime(&(data.ledger_balance_date));
00189     printf("/%d%s%d%s%d%s", temp_tm.tm_mday, "/", temp_tm.tm_mon+1, "/", temp_tm.tm_year+1900, "\n");
00190   }
00191   if(data.ledger_balance_valid==true){
00192     printf("$%.2f%s",data.ledger_balance,"\n");
00193   }
00194   printf("^\n");
00195   /*The transactions will follow, here is the header */
00196   if(data.account_ptr->account_type_valid==true){
00197     switch(data.account_ptr->account_type){
00198     case OFX_CHECKING : printf("!Type:Bank\n");
00199       break;
00200     case OFX_SAVINGS : printf("!Type:Bank\n");
00201       break;
00202     case OFX_MONEYMRKT : printf("!Type:Oth A\n");
00203       break;
00204     case OFX_CREDITLINE : printf("!Type:Oth L\n");
00205       break;
00206     case OFX_CMA : printf("!Type:Oth A\n");
00207       break;
00208     case OFX_CREDITCARD : printf("!Type:CCard\n");
00209       break;
00210     default: perror("WRITEME: ofx_proc_account() This is an unknown account type!");
00211     }
00212   }
00213 
00214   return 0;
00215 }/* end ofx_proc_statement() */
00216   
00217 int ofx_proc_account_cb(struct OfxAccountData data)
00218 {
00219   char dest_string[255]="";
00220   
00221   
00222   //    strncat(trans_list_buff, dest_string, QIF_FILE_MAX_SIZE - strlen(trans_list_buff));
00223   printf(dest_string);
00224  return 0;
00225 }/* end ofx_proc_account() */

Generated on Sun Nov 24 20:26:31 2002 for LibOFX by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002