/* HomeBank -- Free, easy, personal accounting for everyone.
- * Copyright (C) 1995-2014 Maxime DOYEN
+ * Copyright (C) 1995-2016 Maxime DOYEN
*
* This file is part of HomeBank.
*
#include "homebank.h"
-#include "import.h"
-#include "imp_qif.h"
+//#include "ui-assist-import.h"
+#include "hb-import.h"
/****************************************************************************/
-/* Debug macros */
+/* Debug macros */
/****************************************************************************/
#define MYDEBUG 0
return g_malloc0(sizeof(QIF_Tran));
}
+
static void
da_qif_tran_free(QIF_Tran *item)
{
}
-
-
static void
da_qif_tran_destroy(QifContext *ctx)
{
ctx->q_tra = NULL;
}
+
static void
da_qif_tran_new(QifContext *ctx)
{
}
-
static void
da_qif_tran_move(QIF_Tran *sitem, QIF_Tran *ditem)
{
gint ndcount = 0;
gchar dc;
- DB( g_print("\n(qif) hb_qif_parser_get_amount\n") );
+ //DB( g_print("\n[qif] hb_qif_parser_get_amount\n") );
amount = 0.0;
for(i=l;i>=0;i--)
{
- DB( g_print(" %d :: %c :: ds='%c' ndcount=%d\n", i, string[i], dc, ndcount) );
+ //DB( g_print(" %d :: %c :: ds='%c' ndcount=%d\n", i, string[i], dc, ndcount) );
if( string[i] == '-' || string[i] == '+' ) continue;
}
}
- DB( g_print(" s='%s' :: ds='%c'\n", string, dc) );
+ //DB( g_print(" s='%s' :: ds='%c'\n", string, dc) );
new_str = g_malloc (l+3); //#1214077
*p++ = '\0';
amount = g_ascii_strtod(new_str, NULL);
- DB( g_print(" -> amount was='%s' => to='%s' double='%f'\n", string, new_str, amount) );
+ //DB( g_print(" -> amount was='%s' => to='%s' double='%f'\n", string, new_str, amount) );
g_free(new_str);
{
Transaction *item;
- //DB( g_print("(transaction) transaction_get_child_transfer\n") );
+ DB( g_print("([qif] get_child_transfer\n") );
//DB( g_print(" search: %d %s %f %d=>%d\n", src->date, src->wording, src->amount, src->account, src->kxferacc) );
gchar **typestr;
gint type = QIF_NONE;
- DB( g_print("--------\n(account) block type\n") );
+ DB( g_print("--------\n[qif] block type\n") );
//DB( g_print(" -> str: %s type: %d\n", qif_line, type) );
GIOChannel *io;
QIF_Tran tran = { 0 };
- DB( g_print("(qif) hb_qif_parser_parse\n") );
+ DB( g_print("\n[qif] hb_qif_parser_parse\n") );
io = g_io_channel_new_file(filename, "r", NULL);
if(io != NULL)
if(g_str_has_prefix(value, "X") || g_str_has_prefix(value, "R") )
{
tran.reconciled = TRUE;
- }
+ }
+ tran.cleared = FALSE;
+ if(g_str_has_prefix(value, "*") || g_str_has_prefix(value, "c") )
+ {
+ tran.cleared = TRUE;
+ }
break;
}
}
-
-
/*
** this is our main qif entry point
*/
GList *qiflist;
GList *list = NULL;
- DB( g_print("(qif) account import qif\n") );
+ DB( g_print("\n[qif] account import qif\n") );
// allocate our GLists
da_qif_tran_new(&ctx);
//isodate = hb_qif_parser_check_iso_date(&ctx);
//DB( g_print(" -> date is dd/mm/yy: %d\n", isodate) );
- DB( g_print("(qif) transform to hb txn\n") );
+ DB( g_print("\n\n -> transform to hb txn\n") );
DB( g_print(" -> %d qif txn\n", g_list_length(ctx.q_tra)) );
{
QIF_Tran *item = qiflist->data;
Transaction *newope, *child;
- Account *accitem, *existitem;
+ Account *accitem;
Payee *payitem;
Category *catitem;
- gchar *name;
+ gchar *name, *tmpmemo, *tmppayee;
gint nsplit;
newope = da_transaction_malloc();
//newope->paymode = atoi(str_array[1]);
//newope->info = g_strdup(str_array[2]);
- newope->wording = g_strdup(item->memo);
+ //#916690 manage memo, swap memo/payee
+ tmpmemo = item->memo;
+ tmppayee = item->payee;
+ if( PREFS->dtex_qifswap )
+ {
+ tmpmemo = item->payee;
+ tmppayee = item->memo;
+ }
+
+ if( PREFS->dtex_qifmemo )
+ newope->wording = g_strdup(tmpmemo);
+
newope->info = g_strdup(item->info);
newope->amount = item->amount;
newope->amount *= -1;
// payee + append
- if( item->payee != NULL )
+ if( tmppayee != NULL )
{
- payitem = da_pay_get_by_name(item->payee);
+ payitem = da_pay_get_by_name(tmppayee);
if(payitem == NULL)
{
- //DB( g_print(" -> append pay: '%s'\n", item->payee ) );
+ //DB( g_print(" -> append pay: '%s'\n", tmppayee ) );
payitem = da_pay_malloc();
- payitem->name = g_strdup(item->payee);
+ payitem->name = g_strdup(tmppayee);
payitem->imported = TRUE;
da_pay_append(payitem);
//remove brackets
accname = hb_strdup_nobrackets(item->category);
- // account + append
- accitem = da_acc_get_by_name(accname);
- if(accitem == NULL)
- {
- DB( g_print(" -> append dest acc: '%s'\n", accname ) );
-
- accitem = da_acc_malloc();
- accitem->name = g_strdup(accname);
- accitem->imported = TRUE;
- accitem->imp_name = g_strdup(accname);
- da_acc_append(accitem);
- }
+ accitem = import_create_account(accname, NULL);
newope->kxferacc = accitem->key;
newope->paymode = PAYMODE_INTXFER;
{
QIFSplit *s = &item->splits[nsplit];
Split *hbs;
+ guint32 kcat = 0;
DB( g_print(" -> append split %d: '%s' '%.2f' '%s'\n", nsplit, s->category, s->amount, s->memo) );
-
+
if( s->category != NULL )
{
catitem = da_cat_append_ifnew_by_fullname(s->category, TRUE ); // TRUE = imported
if( catitem != NULL )
{
- DB( g_print(" -> append ok\n" ) );
-
- hbs = da_split_new(catitem->key, s->amount, s->memo);
- da_transaction_splits_append(newope, hbs);
- hbs = NULL;
+ kcat = catitem->key;
}
- }
-
+ }
+
+ hbs = da_split_new(kcat, s->amount, s->memo);
+
+ da_splits_append(newope->splits, hbs);
+
+ //da_transaction_splits_append(newope, hbs);
+ hbs = NULL;
}
}
// account + append
- name = strcmp(QIF_UNKNOW_ACCOUNT_NAME, item->account) == 0 ? QIF_UNKNOW_ACCOUNT_NAME : item->account;
+ name = strcmp(QIF_UNKNOW_ACCOUNT_NAME, item->account) == 0 ? "" : item->account;
DB( g_print(" -> account name is '%s'\n", name ) );
- accitem = da_acc_get_by_imp_name(name);
- if( accitem == NULL )
- {
- // check for an existing account before creating it
- existitem = da_acc_get_by_name(name);
-
- accitem = import_create_account(name, NULL);
- DB( g_print(" -> creating account '%s'\n", name ) );
-
- if( existitem != NULL )
- {
- accitem->imp_key = existitem->key;
- DB( g_print(" -> existitem is '%d' %s\n", existitem->key, existitem->name ) );
- }
- }
+ accitem = import_create_account(name, NULL);
newope->kacc = accitem->key;
newope->flags |= OF_INCOME;
if( item->reconciled )
- newope->flags |= OF_VALID;
-
+ newope->status = TXN_STATUS_RECONCILED;
+ else
+ if( item->cleared )
+ newope->status = TXN_STATUS_CLEARED;
+
child = account_qif_get_child_transfer(newope, list);
if( child != NULL)
{