2003-09-16 Christian Stimming <stimming@tuhh.de>

* src/import-export/hbci/gnc-hbci-kvp.c: Fix broken compile due to
	Linas' change of the kvp_frame_get_frame() arguments. By
	Jan-Pascal van Best <j.p.vanbest@tbm.tudelft.nl>

	* src/import-export/hbci/gnc-hbci-gettrans.[hc]: Code
	refactorization so that the mt940 importer can re-use the existing
	import functions from the hbci module. By Jan-Pascal van Best
	<j.p.vanbest@tbm.tudelft.nl>

	* src/import-export/mt940/gncmod-mt940-import.[hc]: Import module
	for SWIFT MT940 files added. By Jan-Pascal van Best
	<j.p.vanbest@tbm.tudelft.nl>


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9345 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2003-09-16 21:50:24 +00:00
parent 572d2faa56
commit 7ad10128ed
14 changed files with 424 additions and 14 deletions

View File

@ -88,6 +88,7 @@ Other Contributors:
Andrew Arensburger <arensb@cfar.umd.edu> for FreeBSD & other patches
Matt Armstrong <matt_armstrong@bigfoot.com> for misc fixes
Fred Baube <fred@moremagic.com> for attempted Java port/MoneyDance
Jan-Pascal van Best <j.p.vanbest@tbm.tudelft.nl> MT940 importer
Dennis Björklund <dennisb@cs.chalmers.se> Swedish translation
Andreas Bogk <andreas@andreas.org> Postgres backend patch
Per Bojsen <bojsen@worldnet.att.net> several core dump fixes

View File

@ -1,3 +1,18 @@
2003-09-16 Christian Stimming <stimming@tuhh.de>
* src/import-export/hbci/gnc-hbci-kvp.c: Fix broken compile due to
Linas' change of the kvp_frame_get_frame() arguments. By
Jan-Pascal van Best <j.p.vanbest@tbm.tudelft.nl>
* src/import-export/hbci/gnc-hbci-gettrans.[hc]: Code
refactorization so that the mt940 importer can re-use the existing
import functions from the hbci module. By Jan-Pascal van Best
<j.p.vanbest@tbm.tudelft.nl>
* src/import-export/mt940/gncmod-mt940-import.[hc]: Import module
for SWIFT MT940 files added. By Jan-Pascal van Best
<j.p.vanbest@tbm.tudelft.nl>
2003-09-14 Derek Atkins <derek@ihtfp.com>
* src/backend/postgres/test/run-tests.sh: small fix from

View File

@ -583,6 +583,16 @@ then
AC_SUBST(HBCI_CFLAGS)
fi
AC_SUBST(HBCI_DIR)
### --------------------------------------------------------------------------
### MT940
AC_ARG_ENABLE( mt940,
[ --enable-mt940 compile with MT940 support (needs --enable-hbci)],
if test "x$enableval" != "xno" ; then
MT940_DIR=mt940
fi)
AC_SUBST(MT940_DIR)
### --------------------------------------------------------------------------
### i18n
@ -1137,6 +1147,7 @@ AC_OUTPUT( m4/Makefile intl/Makefile po/Makefile.in
accounts/el_GR/Makefile
accounts/es_ES/Makefile
accounts/fr_FR/Makefile
accounts/it/Makefile
accounts/pt_BR/Makefile
accounts/pt_PT/Makefile
accounts/sk/Makefile
@ -1205,6 +1216,7 @@ AC_OUTPUT( m4/Makefile intl/Makefile po/Makefile.in
src/import-export/qif-io-core/test/Makefile
src/import-export/ofx/Makefile
src/import-export/ofx/test/Makefile
src/import-export/mt940/Makefile
src/import-export/log-replay/Makefile
src/import-export/hbci/Makefile
src/import-export/hbci/glade/Makefile

View File

@ -1,5 +1,5 @@
SUBDIRS = . binary-import qif qif-import ${OFX_DIR} ${HBCI_DIR} log-replay test
DIST_SUBDIRS = binary-import qif qif-import qif-io-core ofx hbci log-replay test
SUBDIRS = . binary-import qif qif-import ${OFX_DIR} ${HBCI_DIR} ${MT940_DIR} log-replay test
DIST_SUBDIRS = binary-import qif qif-import qif-io-core ofx hbci mt940 log-replay test
pkglib_LTLIBRARIES=libgncmod-generic-import.la

View File

@ -241,19 +241,29 @@ gnc_hbci_gettrans_final(GtkWidget *parent,
static void *trans_list_cb (const HBCI_Transaction *h_trans,
void *user_data)
{
time_t current_time, tt1, tt2;
/*struct tm tm1, tm2;*/
Account *gnc_acc;
GNCBook *book;
Transaction *gnc_trans;
Split *split;
struct trans_list_data *data = user_data;
g_assert(data);
g_assert(h_trans);
gnc_acc = data->gnc_acc;
g_assert(gnc_acc);
gnc_hbci_trans_import(h_trans,data->importer_generic,gnc_acc);
return NULL;
}
void gnc_hbci_trans_import(const HBCI_Transaction *h_trans,
GNCImportMainMatcher *importer_generic,
Account *gnc_acc)
{
time_t current_time, tt1, tt2;
/*struct tm tm1, tm2;*/
GNCBook *book;
Transaction *gnc_trans;
Split *split;
book = xaccAccountGetBook(gnc_acc);
gnc_trans = xaccMallocTransaction(book);
xaccTransBeginEdit(gnc_trans);
@ -321,8 +331,6 @@ static void *trans_list_cb (const HBCI_Transaction *h_trans,
}
/* Instead of xaccTransCommitEdit(gnc_trans) */
g_assert (data->importer_generic);
gnc_gen_trans_list_add_trans (data->importer_generic, gnc_trans);
return NULL;
g_assert (importer_generic);
gnc_gen_trans_list_add_trans (importer_generic, gnc_trans);
}

View File

@ -25,7 +25,10 @@
#include <gnome.h>
#include <openhbci/outboxaccjobs.h>
#include <openhbci/transaction.h>
#include "Account.h"
#include "import-main-matcher.h"
/** Start a GetTrans job. */
void
@ -39,5 +42,10 @@ gnc_hbci_gettrans_final(GtkWidget *parent,
const HBCI_OutboxJobGetTransactions *trans_job,
gboolean run_until_done);
/** Import HBCI transaction into gnucash account using importer_generic
*/
void gnc_hbci_trans_import(const HBCI_Transaction *h_trans,
GNCImportMainMatcher *importer_generic,
Account *gnc_acc);
#endif /* GNC_HBCI_GETTRANS_H */

View File

@ -125,7 +125,7 @@ void gnc_hbci_set_book_template_list (GNCBook *b, GList *template_list)
kvp_frame *gnc_hbci_get_book_kvp (GNCBook *b)
{
kvp_frame *toplevel = gnc_book_get_slots (b);
return kvp_frame_get_frame (toplevel, HBCI_KEY, NULL);
return kvp_frame_get_frame (toplevel, HBCI_KEY);
}
@ -134,5 +134,5 @@ kvp_frame *gnc_hbci_get_book_kvp (GNCBook *b)
kvp_frame *gnc_hbci_get_account_kvp (Account *a)
{
kvp_frame *toplevel = xaccAccountGetSlots (a);
return kvp_frame_get_frame (toplevel, HBCI_KEY, NULL);
return kvp_frame_get_frame (toplevel, HBCI_KEY);
}

View File

@ -0,0 +1,7 @@
.deps
.libs
.scm-links
*.la
*.lo
Makefile
Makefile.in

View File

@ -0,0 +1,48 @@
SUBDIRS = .
# test
pkglib_LTLIBRARIES=libgncmod-mt940.la
libgncmod_mt940_la_SOURCES = \
gnc-mt940-import.c \
gncmod-mt940-import.c
noinst_HEADERS = \
gnc-mt940-import.h
libgncmod_mt940_la_LDFLAGS = -module
libgncmod_mt940_la_LIBADD = \
${top_builddir}/src/gnc-module/libgncmodule.la \
${top_builddir}/src/engine/libgncmod-engine.la \
${top_builddir}/src/import-export/libgncmod-generic-import.la \
${GLIB_LIBS} \
$(HBCI_LIBS)
gncscmdir = ${GNC_SCM_INSTALL_DIR}/mt940
gncscm_DATA = \
mt940-import.scm
AM_CFLAGS = \
-I${top_srcdir}/src \
-I${top_srcdir}/src/engine \
-I${top_srcdir}/src/gnc-module \
-I${top_srcdir}/src/app-utils \
-I${top_srcdir}/src/app-file \
-I${top_srcdir}/src/gnome \
-I${top_srcdir}/src/gnome-utils \
-I${top_srcdir}/src/import-export \
-I$(top_srcdir)/src/import-export/hbci \
${GNOME_INCLUDEDIR} \
${GTKHTML_CFLAGS} \
${GLADE_CFLAGS} \
${GUILE_INCS} \
${GLIB_CFLAGS} \
$(HBCI_CFLAGS)
EXTRA_DIST = \
.cvsignore \
${gncscm_DATA}
CLEANFILES = mt940 import-export gnucash g-wrapped .scm-links

View File

@ -0,0 +1,173 @@
/********************************************************************\
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
* Boston, MA 02111-1307, USA gnu@gnu.org *
\********************************************************************/
/** @addtogroup Import_Export
@{ */
/** @internal
@file gnc-mt940-import.c
@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>
*/
#define _GNU_SOURCE
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <glib.h>
#include <gmodule.h>
#include <openhbci/swiftparser.h>
#include "gnc-hbci-gettrans.h"
#include "import-account-matcher.h"
#include "import-main-matcher.h"
#include "Account.h"
#include "Transaction.h"
#include "global-options.h"
#include "gnc-engine-util.h"
#include "gnc-file-dialog.h"
#include "gnc-ui-util.h"
#include "gnc-hbci-utils.h"
#include "gnc-mt940-import.h"
static short module = MOD_IMPORT;
static void *trans_importer_cb (const HBCI_Transaction *h_trans,
void *user_data);
/********************************************************************\
* gnc_file_mt940_import
* Entry point
\********************************************************************/
SCM scm_gnc_file_mt940_import ()
{
gnc_file_mt940_import();
return SCM_EOL;
}
void gnc_file_mt940_import (void)
{
const char *selected_filename;
char *default_dir;
FILE *mt940_file;
GNCImportMainMatcher *gnc_mt940_importer_gui = NULL;
gnc_should_log(MOD_IMPORT, GNC_LOG_TRACE);
DEBUG("gnc_file_mt940_import(): Begin...\n");
default_dir = gnc_lookup_string_option("__paths", "Import MT940", NULL);
if (default_dir == NULL)
gnc_init_default_directory(&default_dir);
selected_filename = gnc_file_dialog(_("Select an MT940 file to process"),
NULL,
default_dir);
if(selected_filename!=NULL)
{
/* Remember the directory as the default. */
gnc_extract_directory(&default_dir, selected_filename);
gnc_set_string_option("__paths", "Import MT940", default_dir);
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");
fseek(mt940_file,0,SEEK_END);
unsigned long filesize=ftell(mt940_file);
rewind(mt940_file);
char *mt940_records=g_malloc(filesize+1);
fread(mt940_records,1,filesize,mt940_file);
mt940_records[filesize]='\0';
DEBUG("Read file data: %s\n",mt940_records);
{
int pos=0;
int result;
HBCI_transactionReport *tr;
const list_HBCI_Transaction *transactions;
/*list_HBCI_Transaction_iter *iter;*/
tr=HBCI_transactionReport_new();
while(pos<filesize){
DEBUG("Parsing mt940 string, pos=%d\n",pos);
result=HBCI_SWIFTparser_readMT940(mt940_records,tr,&pos);
DEBUG("Parsing result: %d\n", result);
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);
}
g_free(mt940_records);
}
}
/* 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;
}
/** @} */

View File

@ -0,0 +1,35 @@
/********************************************************************\
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
* Boston, MA 02111-1307, USA gnu@gnu.org *
\********************************************************************/
/** @file
@brief mt940 import module interface
*
gnc-mt940-import.h
@author Copyright (c) 2002 Benoit Grégoire <bock@step.polymtl.ca>
*/
#ifndef MT940_IMPORT_H
#define MT940_IMPORT_H
/** The gnc_file_mt940_import() routine will pop up a standard file
* selection dialogue asking the user to pick an MT940 file. If one
* is selected then the MT940 file is opened and read. Its contents
* are merged into the existing session (if any). The current
* session continues to remain open for editing. */
void gnc_file_mt940_import (void);
SCM scm_gnc_file_mt940_import (void);
#endif

View File

@ -0,0 +1,92 @@
/********************************************************************\
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
* Boston, MA 02111-1307, USA gnu@gnu.org *
\********************************************************************/
/** @addtogroup Import_Export
@{ */
/**@internal
@file gncmod-mt940-import.c
@brief module definition/initialization for the mt940 importer
@author Copyright (c) 2002 Benoit Grégoire bock@step.polymtl.ca
*/
#include "config.h"
#include <glib.h>
#include <libguile.h>
#include "guile-mappings.h"
#include "gnc-mt940-import.h"
#include "gnc-module.h"
#include "gnc-module-api.h"
/* version of the gnc module system interface we require */
int libgncmod_mt940_LTX_gnc_module_system_interface = 0;
/* module versioning uses libtool semantics. */
int libgncmod_mt940_LTX_gnc_module_current = 0;
int libgncmod_mt940_LTX_gnc_module_revision = 0;
int libgncmod_mt940_LTX_gnc_module_age = 0;
//static GNCModule bus_core;
//static GNCModule file;
/* forward references */
char *libgncmod_mt940_LTX_gnc_module_path(void);
char *libgncmod_mt940_LTX_gnc_module_description(void);
int libgncmod_mt940_LTX_gnc_module_init(int refcount);
int libgncmod_mt940_LTX_gnc_module_end(int refcount);
char *
libgncmod_mt940_LTX_gnc_module_path(void)
{
return g_strdup("gnucash/import-export/mt940");
}
char *
libgncmod_mt940_LTX_gnc_module_description(void)
{
return g_strdup("Gnome GUI and C code for MT940 importer");
}
int
libgncmod_mt940_LTX_gnc_module_init(int refcount)
{
if(!gnc_module_load("gnucash/engine", 0))
{
return FALSE;
}
if(!gnc_module_load("gnucash/app-utils", 0))
{
return FALSE;
}
if(!gnc_module_load("gnucash/gnome-utils", 0))
{
return FALSE;
}
if(!gnc_module_load("gnucash/import-export", 0))
{
return FALSE;
}
scm_c_eval_string("(load-from-path \"mt940/mt940-import.scm\")");
scm_c_define_gsubr("gnc:mt940-import", 0, 0, 0, scm_gnc_file_mt940_import);
return TRUE;
}
int
libgncmod_mt940_LTX_gnc_module_end(int refcount)
{
return TRUE;
}
/** @}*/

View File

@ -0,0 +1,10 @@
(define (add-mt940-menu-item)
(gnc:add-extension
(gnc:make-menu-item(N_ "Import MT940")
(N_ "Process an MT940 response file")
(list gnc:window-name-main "File" "_Import" "")
(lambda ()
(gnc:mt940-import)))))
(gnc:hook-add-dangler gnc:*ui-startup-hook* add-mt940-menu-item)

View File

@ -428,6 +428,7 @@ string and 'directories' must be a list of strings."
(load-module "gnucash/import-export/binary-import" 0 #f)
(load-module "gnucash/import-export/qif-import" 0 #f)
(load-module "gnucash/import-export/ofx" 0 #t)
(load-module "gnucash/import-export/mt940" 0 #t)
(load-module "gnucash/import-export/log-replay" 0 #t)
(load-module "gnucash/import-export/hbci" 0 #t)
(load-module "gnucash/report/report-system" 0 #f)