More proposed work on mt940 importer. More refactoring of HBCI functions.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@12973 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming
2006-01-24 21:26:30 +00:00
parent bda328ea16
commit 8a1e1197cf
4 changed files with 122 additions and 113 deletions
+2 -8
View File
@@ -46,13 +46,7 @@ gboolean
gettrans_dates(GtkWidget *parent, Account *gnc_acc,
GWEN_TIME **from_date, GWEN_TIME **to_date);
static AB_TRANSACTION *trans_list_cb(AB_TRANSACTION *reportn, void *user_data);
struct trans_list_data
{
Account *gnc_acc;
GNCImportMainMatcher *importer_generic;
};
void
@@ -233,7 +227,7 @@ gnc_hbci_import_final(GtkWidget *parent,
data.importer_generic = importer_generic_gui;
data.gnc_acc = gnc_acc;
AB_Transaction_List2_ForEach (trans_list, trans_list_cb, &data);
AB_Transaction_List2_ForEach (trans_list, gnc_hbci_trans_list_cb, &data);
if (run_until_done)
return gnc_gen_trans_list_run (importer_generic_gui);
@@ -243,7 +237,7 @@ gnc_hbci_import_final(GtkWidget *parent,
/* list_AB_TRANSACTION_foreach callback. The Conversion from HBCI to
GNC transaction is done here, once for each AB_TRANSACTION. */
static AB_TRANSACTION *trans_list_cb(AB_TRANSACTION *h_trans, void *user_data)
AB_TRANSACTION *gnc_hbci_trans_list_cb(AB_TRANSACTION *h_trans, void *user_data)
{
time_t current_time;
/* time_t tt1, tt2; */
@@ -24,6 +24,8 @@
#define GNC_HBCI_GETTRANS_H
#include <aqbanking/jobgettransactions.h>
#include "import-main-matcher.h"
#include "Account.h"
/** Start a GetTrans job. */
@@ -46,5 +48,17 @@ gnc_hbci_import_final(GtkWidget *parent,
AB_TRANSACTION_LIST2 *trans_list,
gboolean run_until_done);
/** user_data struct for the gnc_hbci_trans_list_cb() structure */
struct trans_list_data
{
Account *gnc_acc;
GNCImportMainMatcher *importer_generic;
};
/** AB_TRANSACTION_LIST2_foreach callback. The Conversion from HBCI to
GNC transaction is done here, once for each AB_TRANSACTION. */
AB_TRANSACTION *gnc_hbci_trans_list_cb(AB_TRANSACTION *imported_trans,
void *user_data);
#endif /* GNC_HBCI_GETTRANS_H */
+12 -4
View File
@@ -14,10 +14,16 @@ noinst_HEADERS = \
libgncmod_mt940_la_LIBADD = \
${top_builddir}/src/gnc-module/libgncmodule.la \
${top_builddir}/src/core-utils/libcore-utils.la \
${top_builddir}/src/engine/libgncmod-engine.la \
${top_builddir}/src/import-export/libgncmod-generic-import.la \
${top_builddir}/src/import-export/hbci/libgncmod-hbci.la \
${top_builddir}/src/gnome/libgncgnome.la \
${GNOME_LIBS} \
${GLADE_LIBS} \
${QOF_LIBS} \
${GLIB_LIBS} \
$(HBCI_LIBS)
${HBCI_LIBS}
AM_CFLAGS = \
-I${top_srcdir}/src \
@@ -28,12 +34,14 @@ AM_CFLAGS = \
-I${top_srcdir}/src/gnome-utils \
-I${top_srcdir}/src/import-export \
-I$(top_srcdir)/src/import-export/hbci \
${G_WRAP_COMPILE_ARGS} \
${GUILE_INCS} \
${GLIB_CFLAGS} \
${GLADE_CFLAGS} \
${GNOME_CFLAGS} \
${GTKHTML_CFLAGS} \
$(HBCI_CFLAGS)
${GLADE_CFLAGS} \
${QOF_CFLAGS} \
${GLIB_CFLAGS} \
${HBCI_CFLAGS}
uidir = $(GNC_UI_DIR)
ui_DATA = \
+94 -101
View File
@@ -35,18 +35,20 @@
#include <aqbanking/imexporter.h>
#include "gnc-hbci-gettrans.h"
#include "import-account-matcher.h"
#include "import-main-matcher.h"
#include "Account.h"
#include "gnc-ui.h"
#include "qof.h"
#include "Transaction.h"
#include "Account.h"
#include "gnc-engine.h"
#include "gnc-file.h"
#include "gnc-ui-util.h"
#include "gnc-gconf-utils.h"
#include "gnc-hbci-utils.h"
#include "gnc-hbci-gettrans.h"
#include "import-main-matcher.h"
#include "import-account-matcher.h"
#include "gnc-hbci-gettrans.h"
#include "gnc-mt940-import.h"
@@ -54,9 +56,6 @@
static QofLogModule log_module = GNC_MOD_IMPORT;
static void *trans_importer_cb (const HBCI_Transaction *h_trans,
void *user_data);
/* Note: This file is broken. See
http://bugzilla.gnome.org/show_bug.cgi?id=325170 . The patch from
@@ -88,115 +87,109 @@ void gnc_file_mt940_import (void)
GNC_FILE_DIALOG_IMPORT);
g_free(default_dir);
if(selected_filename!=NULL)
if(selected_filename!=NULL) {
/* Remember the directory as the default. */
gnc_extract_directory(&default_dir, selected_filename);
gnc_gconf_set_string(GCONF_SECTION, KEY_LAST_PATH, default_dir, NULL);
g_free(default_dir);
/*strncpy(file,selected_filename, 255);*/
DEBUG("Filename found: %s",selected_filename);
/* Create the Generic transaction importer GUI. */
gnc_mt940_importer_gui = gnc_gen_trans_list_new(NULL, NULL, FALSE);
DEBUG("Opening selected file");
mt940_file = fopen(selected_filename, "r");
{
/* Remember the directory as the default. */
gnc_extract_directory(&default_dir, selected_filename);
gnc_gconf_set_string(GCONF_SECTION, KEY_LAST_PATH, default_dir, NULL);
g_free(default_dir);
int result;
AB_BANKING *tr;
AB_IMEXPORTER *importer;
AB_IMEXPORTER_CONTEXT *ctx=0;
GWEN_BUFFEREDIO *buffio;
const list_HBCI_Transaction *transactions;
/*list_HBCI_Transaction_iter *iter;*/
/*strncpy(file,selected_filename, 255);*/
DEBUG("Filename found: %s",selected_filename);
tr=AB_Banking_new();
/* get import module */
importer=AB_Banking_GetImExporter(tr, "swift"); /* possible values: csv, swift, dtaus, */
if (!importer) {
DEBUG("Import module swift not found");
}
/* Create the Generic transaction importer GUI. */
gnc_mt940_importer_gui = gnc_gen_trans_list_new(NULL, NULL, FALSE);
/* load the import profile */
//dbProfiles=AB_Banking_GetImExporterProfiles(tr, "swift");
dbProfile="default";
DEBUG("Opening selected file");
mt940_file = fopen(selected_filename, "r");
/* import new context */
ctx=AB_ImExporterContext_new();
fseek(mt940_file,0,SEEK_END);
unsigned long filesize=ftell(mt940_file);
rewind(mt940_file);
/* Wrap file in gwen_bufferedio */
buffio = GWEN_BufferedIO_File_new(mt940_file);
char *mt940_records=g_malloc(filesize+1);
result=AB_ImExporter_Import(importer,
ctx,
buffio,
dbProfile);
fread(mt940_records,1,filesize,mt940_file);
mt940_records[filesize]='\0';
DEBUG("Parsing result: %d\n", result);
DEBUG("Read file data: %s\n",mt940_records);
GWEN_BufferedIO_Close(buffio);
GWEN_BufferedIO_free(buffio);
{
int pos=0;
int result;
AB_BANKING *tr;
AB_IMEXPORTER *importer;
AB_IMEXPORTER_CONTEXT *ctx=0;
GWEN_DB_NODE *dbCtx;
const list_HBCI_Transaction *transactions;
/*list_HBCI_Transaction_iter *iter;*/
/* Now get all accountinfos */
AB_TRANSACTION *ab_trans;
struct trans_list_data data;
Account *gnc_acc;
AB_IMEXPORTER_ACCOUNTINFO * accinfo;
tr=AB_Banking_new();
/* get import module */
importer=AB_Banking_GetImExporter(tr, "swift"); /* possible values: csv, swift, dtaus, */
if (!importer) {
DEBUG("Import module swift not found");
/* Create importer GUI */
importer_generic_gui = gnc_gen_trans_list_new(parent, NULL, TRUE, 14);
data.importer_generic = importer_generic_gui;
/* Iterate through all accounts */
accinfo = AB_ImExporterContext_GetFirstAccountInfo(ctx);
while (accinfo) {
/* FIXME: need to get account name from accinfo
structure here */
gnc_acc = gnc_import_select_account(account_name, 1, NULL, NULL,
NO_TYPE, NULL, NULL);
/* Store chosen gnucash account in callback data */
data.gnc_acc = gnc_acc;
/* Iterate through all transactions */
ab_trans =
AB_ImExporterAccountInfo_GetFirstTransaction (accinfo);
while (ab_trans) {
/* This callback in the hbci module will add the
imported transaction to gnucash's importer */
gnc_hbci_trans_list_cb(ab_trans, &data);
ab_trans =
AB_ImExporterAccountInfo_GetNextTransaction (accinfo);
}
/* all transaction finished. */
accinfo = AB_ImExporterContext_GetNextAccountInfo(ctx);
}
/* all accounts finished. */
AB_ImExporterContext_free(ctx);
/* load the import profile */
//dbProfiles=AB_Banking_GetImExporterProfiles(tr, "swift");
dbProfile="default";
/* that's it */
result=AB_Banking_Fini(ab);
if (result)
DEBUG("ERROR: Error on deinit (%d)\n",result);
/* import new context */
ctx=AB_ImExporterContext_new();
while(pos<filesize){
DEBUG("Parsing mt940 string, pos=%d\n",pos);
g_free(selected_filename);
result=AB_ImExporter_Import(importer,
ctx,
mt940_records,
dbProfile);
DEBUG("Parsing result: %d\n", result);
AB_ImExporterContext_toDb(ctx, dbCtx);
transactions=HBCI_transactionReport_transactions(tr);
DEBUG("Got %d transactions.\n",
list_HBCI_Transaction_size(transactions));
DEBUG("Importing those transaction...\n");
list_HBCI_Transaction_foreach (transactions, trans_importer_cb, gnc_mt940_importer_gui);
DEBUG("Imported transactions, looking for next...\n");
}
HBCI_transactionReport_delete(tr);
/* and run the gnucash importer. */
gnc_gen_trans_list_run (importer_generic_gui);
}
AB_ImExporterContext_free(ctx);
/* that's is */
result=AB_Banking_Fini(ab);
if (result) {
DEBUG("ERROR: Error on deinit (%d)\n",result);
g_free(mt940_records);
g_free(selected_filename);
}
}
/* list_HBCI_Transaction_foreach callback. The Conversion from HBCI to
GNC transaction is done here, once for each HBCI_Transaction.
*/
static void *trans_importer_cb (const HBCI_Transaction *h_trans,
void *user_data)
{
Account *gnc_acc;
GNCImportMainMatcher *gnc_importer_gui = user_data;
g_assert(gnc_importer_gui);
g_assert(h_trans);
char *account_name=(char *)HBCI_Transaction_ourAccountId(h_trans);
DEBUG("Account name: \"%s\"\n",account_name);
DEBUG("Transaction code: %d\n", HBCI_Transaction_transactionCode(h_trans));
const HBCI_Value* value=HBCI_Transaction_value(h_trans);
DEBUG("Transaction value: %f\n", HBCI_Value_getValue(value));
gnc_acc = gnc_import_select_account(account_name, 1, NULL, NULL, NO_TYPE, NULL, NULL);
g_assert(gnc_acc);
gnc_hbci_trans_import(h_trans,gnc_importer_gui,gnc_acc);
// trans_importer(h_trans,gnc_importer_gui,gnc_acc);
return NULL;
}
}
/** @} */