mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Get MT940 importer compile again (experimental; requires
aqbanking-1.9.7). It is not yet tested with actual files. Bug#325170. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13380 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
3d5d84836f
commit
f6fc0dfa91
@ -1,5 +1,9 @@
|
|||||||
2006-02-24 Christian Stimming <stimming@tuhh.de>
|
2006-02-24 Christian Stimming <stimming@tuhh.de>
|
||||||
|
|
||||||
|
* src/import-export/mt940/gnc-mt940-import.c: Get MT940 importer
|
||||||
|
compile again (experimental; requires aqbanking-1.9.7). It is not
|
||||||
|
yet tested with actual files. Bug#325170.
|
||||||
|
|
||||||
* src/import-export/import-account-matcher.h: Make gchar argument
|
* src/import-export/import-account-matcher.h: Make gchar argument
|
||||||
const because it is only used as a const.
|
const because it is only used as a const.
|
||||||
|
|
||||||
|
18
configure.in
18
configure.in
@ -750,14 +750,22 @@ AC_ARG_ENABLE( mt940,
|
|||||||
fi)
|
fi)
|
||||||
if test x${MT940_DIR} = xmt940 ;
|
if test x${MT940_DIR} = xmt940 ;
|
||||||
then
|
then
|
||||||
AC_MSG_ERROR([Sorry, MT940 support is currently broken since it depended on the hbci module with the old openhbci 0.9.x library. But the hbci module has now been ported to a new hbci library called aqbanking. That library contains a MT940 parser, too, so porting shouldnt be too difficult. Nevertheless someone needs to do the porting work before this can be enabled again.])
|
AC_MSG_WARN([MT940 importing support is enabled but is totally experimental!])
|
||||||
PKG_CHECK_MODULES(MT940, aqbanking >= "1.0.0", [], [
|
# Use a very recent aqbanking (released 2006-02-06) due to significant
|
||||||
AC_AQBANKING(1,0,0)
|
# simplifications with file importing. Since this is
|
||||||
|
# experimental and not used by anyone anyway, I guess it should be
|
||||||
|
# okay. May very well be disabled for 2.0.x stable series anyway.
|
||||||
|
PKG_CHECK_MODULES(HBCI, aqbanking >= "1.9.7", [], [
|
||||||
|
AC_AQBANKING(1,9,7)
|
||||||
|
if test x${have_aqbanking} != xyes;
|
||||||
|
then
|
||||||
|
AC_MSG_ERROR([Could not find aqbanking. If you use --enable-mt940, you *have* to enable aqbanking.])
|
||||||
|
fi
|
||||||
|
HBCI_LIBS="${aqbanking_libs}"
|
||||||
|
HBCI_CFLAGS="${aqbanking_includes}"
|
||||||
])
|
])
|
||||||
# Note: HBCI_LIBS is changed again below in the --enable-hbci
|
# Note: HBCI_LIBS is changed again below in the --enable-hbci
|
||||||
# section. So check for mt940 first and *not* the other way round!
|
# section. So check for mt940 first and *not* the other way round!
|
||||||
HBCI_LIBS="${OPENHBCI_LIBS}"
|
|
||||||
HBCI_CFLAGS="${OPENHBCI_CFLAGS}"
|
|
||||||
|
|
||||||
AS_SCRUB_INCLUDE(HBCI_CFLAGS)
|
AS_SCRUB_INCLUDE(HBCI_CFLAGS)
|
||||||
AC_SUBST(HBCI_LIBS)
|
AC_SUBST(HBCI_LIBS)
|
||||||
|
@ -27,6 +27,7 @@ libgncmod_mt940_la_LIBADD = \
|
|||||||
|
|
||||||
AM_CFLAGS = \
|
AM_CFLAGS = \
|
||||||
-I${top_srcdir}/src \
|
-I${top_srcdir}/src \
|
||||||
|
-I${top_srcdir}/src/core-utils \
|
||||||
-I${top_srcdir}/src/engine \
|
-I${top_srcdir}/src/engine \
|
||||||
-I${top_srcdir}/src/gnc-module \
|
-I${top_srcdir}/src/gnc-module \
|
||||||
-I${top_srcdir}/src/app-utils \
|
-I${top_srcdir}/src/app-utils \
|
||||||
@ -34,6 +35,10 @@ AM_CFLAGS = \
|
|||||||
-I${top_srcdir}/src/gnome-utils \
|
-I${top_srcdir}/src/gnome-utils \
|
||||||
-I${top_srcdir}/src/import-export \
|
-I${top_srcdir}/src/import-export \
|
||||||
-I$(top_srcdir)/src/import-export/hbci \
|
-I$(top_srcdir)/src/import-export/hbci \
|
||||||
|
-I${top_srcdir}/src/register \
|
||||||
|
-I${top_srcdir}/src/register/register-core \
|
||||||
|
-I${top_srcdir}/src/register/register-gnome \
|
||||||
|
-I${top_srcdir}/src/register/ledger-core \
|
||||||
${G_WRAP_COMPILE_ARGS} \
|
${G_WRAP_COMPILE_ARGS} \
|
||||||
${GUILE_INCS} \
|
${GUILE_INCS} \
|
||||||
${GNOME_CFLAGS} \
|
${GNOME_CFLAGS} \
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
/** @internal
|
/** @internal
|
||||||
@file gnc-mt940-import.c
|
@file gnc-mt940-import.c
|
||||||
@brief MT940 import module code
|
@brief MT940 import module code
|
||||||
@author Copyright (c) 2002 Benoit Grégoire <bock@step.polymtl.ca>, Copyright (c) 2003 Jan-Pascal van Best <janpascal@vanbest.org>, Copyright (c) 2006 Florian Steinel
|
@author Copyright (c) 2002 Benoit Grégoire <bock@step.polymtl.ca>, Copyright (c) 2003 Jan-Pascal van Best <janpascal@vanbest.org>, Copyright (c) 2006 Florian Steinel, 2006 Christian Stimming.
|
||||||
*/
|
*/
|
||||||
/* See aqbanking-1.6.0beta/src/tools/aqbanking-tool/import.c for hints */
|
/* See aqbanking-1.6.0beta/src/tools/aqbanking-tool/import.c for hints */
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
@ -29,10 +29,13 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <glib/gi18n.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include <aqbanking/banking.h>
|
||||||
#include <aqbanking/imexporter.h>
|
#include <aqbanking/imexporter.h>
|
||||||
|
|
||||||
#include "gnc-ui.h"
|
#include "gnc-ui.h"
|
||||||
@ -43,6 +46,7 @@
|
|||||||
#include "gnc-engine.h"
|
#include "gnc-engine.h"
|
||||||
#include "gnc-file.h"
|
#include "gnc-file.h"
|
||||||
#include "gnc-ui-util.h"
|
#include "gnc-ui-util.h"
|
||||||
|
#include "gnc-gconf-utils.h"
|
||||||
|
|
||||||
#include "gnc-hbci-gettrans.h"
|
#include "gnc-hbci-gettrans.h"
|
||||||
|
|
||||||
@ -56,11 +60,14 @@
|
|||||||
|
|
||||||
static QofLogModule log_module = GNC_MOD_IMPORT;
|
static QofLogModule log_module = GNC_MOD_IMPORT;
|
||||||
|
|
||||||
|
/* Callback declarations */
|
||||||
|
static const AB_TRANSACTION *
|
||||||
|
translist_cb (const AB_TRANSACTION *element, void *user_data);
|
||||||
|
static AB_IMEXPORTER_ACCOUNTINFO *
|
||||||
|
accountinfolist_cb(AB_IMEXPORTER_ACCOUNTINFO *element, void *user_data);
|
||||||
|
|
||||||
/* Note: This file is broken. See
|
/* Note: This is not yet tested, see
|
||||||
http://bugzilla.gnome.org/show_bug.cgi?id=325170 . The patch from
|
http://bugzilla.gnome.org/show_bug.cgi?id=325170 . */
|
||||||
there is already included, but the file still won't compile. */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
@ -72,7 +79,7 @@ void gnc_file_mt940_import (void)
|
|||||||
{
|
{
|
||||||
char *selected_filename;
|
char *selected_filename;
|
||||||
char *default_dir;
|
char *default_dir;
|
||||||
FILE *mt940_file;
|
int mt940_fd;
|
||||||
GNCImportMainMatcher *gnc_mt940_importer_gui = NULL;
|
GNCImportMainMatcher *gnc_mt940_importer_gui = NULL;
|
||||||
|
|
||||||
/* gnc_should_log(MOD_IMPORT, GNC_LOG_TRACE); */
|
/* gnc_should_log(MOD_IMPORT, GNC_LOG_TRACE); */
|
||||||
@ -97,36 +104,57 @@ void gnc_file_mt940_import (void)
|
|||||||
DEBUG("Filename found: %s",selected_filename);
|
DEBUG("Filename found: %s",selected_filename);
|
||||||
|
|
||||||
/* Create the Generic transaction importer GUI. */
|
/* Create the Generic transaction importer GUI. */
|
||||||
gnc_mt940_importer_gui = gnc_gen_trans_list_new(NULL, NULL, FALSE);
|
gnc_mt940_importer_gui = gnc_gen_trans_list_new(NULL, NULL, FALSE, 42);
|
||||||
|
|
||||||
DEBUG("Opening selected file");
|
DEBUG("Opening selected file");
|
||||||
mt940_file = fopen(selected_filename, "r");
|
mt940_fd = open(selected_filename, O_RDONLY);
|
||||||
|
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
AB_BANKING *tr;
|
AB_BANKING *ab;
|
||||||
AB_IMEXPORTER *importer;
|
AB_IMEXPORTER *importer;
|
||||||
AB_IMEXPORTER_CONTEXT *ctx=0;
|
AB_IMEXPORTER_CONTEXT *ctx=0;
|
||||||
GWEN_BUFFEREDIO *buffio;
|
GWEN_BUFFEREDIO *buffio;
|
||||||
const list_HBCI_Transaction *transactions;
|
GWEN_DB_NODE *dbProfiles;
|
||||||
/*list_HBCI_Transaction_iter *iter;*/
|
GWEN_DB_NODE *dbProfile;
|
||||||
|
const char *importerName = "swift"; /* possible values: csv, swift, dtaus, */
|
||||||
|
const char *profileName = "default";
|
||||||
|
|
||||||
tr=AB_Banking_new();
|
ab = AB_Banking_new("gnucash", 0);
|
||||||
/* get import module */
|
/* get import module */
|
||||||
importer=AB_Banking_GetImExporter(tr, "swift"); /* possible values: csv, swift, dtaus, */
|
importer=AB_Banking_GetImExporter(ab, importerName);
|
||||||
if (!importer) {
|
if (!importer) {
|
||||||
DEBUG("Import module swift not found");
|
DEBUG("Import module swift not found");
|
||||||
}
|
}
|
||||||
|
g_assert(importer);
|
||||||
|
|
||||||
/* load the import profile */
|
/* load the import profile */
|
||||||
//dbProfiles=AB_Banking_GetImExporterProfiles(tr, "swift");
|
dbProfiles=AB_Banking_GetImExporterProfiles(ab, importerName);
|
||||||
dbProfile="default";
|
|
||||||
|
/* select profile */
|
||||||
|
dbProfile=GWEN_DB_GetFirstGroup(dbProfiles);
|
||||||
|
while(dbProfile) {
|
||||||
|
const char *name;
|
||||||
|
|
||||||
|
name=GWEN_DB_GetCharValue(dbProfile, "name", 0, 0);
|
||||||
|
g_assert(name);
|
||||||
|
if (strcasecmp(name, profileName)==0)
|
||||||
|
break;
|
||||||
|
dbProfile=GWEN_DB_GetNextGroup(dbProfile);
|
||||||
|
}
|
||||||
|
g_assert(dbProfile);
|
||||||
|
/*if (!dbProfile) {
|
||||||
|
DBG_ERROR(AQT_LOGDOMAIN,
|
||||||
|
"Profile \"%s\" for importer \"%s\" not found",
|
||||||
|
profileName, importerName);
|
||||||
|
return 3;
|
||||||
|
}*/
|
||||||
|
|
||||||
/* import new context */
|
/* import new context */
|
||||||
ctx=AB_ImExporterContext_new();
|
ctx=AB_ImExporterContext_new();
|
||||||
|
|
||||||
/* Wrap file in gwen_bufferedio */
|
/* Wrap file in gwen_bufferedio */
|
||||||
buffio = GWEN_BufferedIO_File_new(mt940_file);
|
buffio = GWEN_BufferedIO_File_new(mt940_fd);
|
||||||
|
|
||||||
result = AB_ImExporter_Import(importer,
|
result = AB_ImExporter_Import(importer,
|
||||||
ctx,
|
ctx,
|
||||||
@ -137,42 +165,20 @@ void gnc_file_mt940_import (void)
|
|||||||
|
|
||||||
GWEN_BufferedIO_Close(buffio);
|
GWEN_BufferedIO_Close(buffio);
|
||||||
GWEN_BufferedIO_free(buffio);
|
GWEN_BufferedIO_free(buffio);
|
||||||
|
GWEN_DB_Group_free(dbProfiles);
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Now get all accountinfos */
|
/* Now get all accountinfos */
|
||||||
AB_TRANSACTION *ab_trans;
|
|
||||||
struct trans_list_data data;
|
struct trans_list_data data;
|
||||||
Account *gnc_acc;
|
GNCImportMainMatcher *importer_generic_gui;
|
||||||
AB_IMEXPORTER_ACCOUNTINFO * accinfo;
|
GtkWidget *parent = NULL;
|
||||||
|
|
||||||
/* Create importer GUI */
|
/* Create importer GUI */
|
||||||
importer_generic_gui = gnc_gen_trans_list_new(parent, NULL, TRUE, 14);
|
importer_generic_gui = gnc_gen_trans_list_new(parent, NULL, TRUE, 14);
|
||||||
data.importer_generic = importer_generic_gui;
|
data.importer_generic = importer_generic_gui;
|
||||||
|
|
||||||
/* Iterate through all accounts */
|
/* Iterate through all accounts */
|
||||||
accinfo = AB_ImExporterContext_GetFirstAccountInfo(ctx);
|
AB_ImExporterContext_AccountInfoForEach(ctx, accountinfolist_cb, &data);
|
||||||
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. */
|
/* all accounts finished. */
|
||||||
|
|
||||||
AB_ImExporterContext_free(ctx);
|
AB_ImExporterContext_free(ctx);
|
||||||
@ -183,6 +189,7 @@ void gnc_file_mt940_import (void)
|
|||||||
DEBUG("ERROR: Error on deinit (%d)\n",result);
|
DEBUG("ERROR: Error on deinit (%d)\n",result);
|
||||||
|
|
||||||
g_free(selected_filename);
|
g_free(selected_filename);
|
||||||
|
AB_Banking_free(ab);
|
||||||
|
|
||||||
|
|
||||||
/* and run the gnucash importer. */
|
/* and run the gnucash importer. */
|
||||||
@ -192,4 +199,40 @@ void gnc_file_mt940_import (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static AB_IMEXPORTER_ACCOUNTINFO *
|
||||||
|
accountinfolist_cb(AB_IMEXPORTER_ACCOUNTINFO *accinfo, void *user_data) {
|
||||||
|
Account *gnc_acc;
|
||||||
|
struct trans_list_data *data = user_data;
|
||||||
|
const char *bank_code =
|
||||||
|
AB_ImExporterAccountInfo_GetBankCode(accinfo);
|
||||||
|
const char *account_number =
|
||||||
|
AB_ImExporterAccountInfo_GetAccountNumber(accinfo);
|
||||||
|
const char *account_name =
|
||||||
|
AB_ImExporterAccountInfo_GetAccountName(accinfo);
|
||||||
|
gchar *online_id = g_strconcat (bank_code, account_number, NULL);
|
||||||
|
|
||||||
|
gnc_acc = gnc_import_select_account(online_id, 1, account_name, NULL,
|
||||||
|
NO_TYPE, NULL, NULL);
|
||||||
|
g_free(online_id);
|
||||||
|
if (gnc_acc) {
|
||||||
|
/* Store chosen gnucash account in callback data */
|
||||||
|
data->gnc_acc = gnc_acc;
|
||||||
|
|
||||||
|
/* Iterate through all transactions. */
|
||||||
|
AB_ImExporterAccountInfo_TransactionsForEach (accinfo, translist_cb, data);
|
||||||
|
/* all transactions finished. */
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const AB_TRANSACTION *
|
||||||
|
translist_cb (const AB_TRANSACTION *element, void *user_data) {
|
||||||
|
/* This callback in the hbci module will add the imported
|
||||||
|
transaction to gnucash's importer. */
|
||||||
|
/* The call will use "element" only as const* */
|
||||||
|
gnc_hbci_trans_list_cb( (AB_TRANSACTION*) element, user_data);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
@ -25,9 +25,12 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
|
|
||||||
#include "gnc-plugin-mt940.h"
|
#include "gnc-engine.h"
|
||||||
#include "gnc-plugin-manager.h"
|
#include "gnc-plugin-manager.h"
|
||||||
|
#include "gnc-plugin-mt940.h"
|
||||||
#include "gnc-mt940-import.h"
|
#include "gnc-mt940-import.h"
|
||||||
|
#include "gnc-plugin-page-account-tree.h"
|
||||||
|
#include "gnc-plugin-page-register.h"
|
||||||
|
|
||||||
static void gnc_plugin_mt940_class_init (GncPluginMt940Class *klass);
|
static void gnc_plugin_mt940_class_init (GncPluginMt940Class *klass);
|
||||||
static void gnc_plugin_mt940_init (GncPluginMt940 *plugin);
|
static void gnc_plugin_mt940_init (GncPluginMt940 *plugin);
|
||||||
|
@ -26,9 +26,14 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#include "gnc-mt940-import.h"
|
#include <gtk/gtk.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <libguile.h>
|
||||||
|
|
||||||
#include "gnc-module.h"
|
#include "gnc-module.h"
|
||||||
#include "gnc-module-api.h"
|
#include "gnc-module-api.h"
|
||||||
|
|
||||||
|
#include "gnc-mt940-import.h"
|
||||||
#include "gnc-plugin-mt940.h"
|
#include "gnc-plugin-mt940.h"
|
||||||
|
|
||||||
/* version of the gnc module system interface we require */
|
/* version of the gnc module system interface we require */
|
||||||
|
Loading…
Reference in New Issue
Block a user