-/*
-** this is our main qif entry point
-*/
-GList *
-account_import_qif(gchar *filename, ImportContext *ictx)
-{
-QifContext ctx = { 0 };
-GList *qiflist;
-GList *list = NULL;
-
- DB( g_print("\n[qif] account import qif\n") );
-
- // allocate our GLists
- da_qif_tran_new(&ctx);
- ctx.is_ccard = FALSE;
-
- // parse !!
- hb_qif_parser_parse(&ctx, filename, ictx->encoding);
-
- // check iso date format in file
- //isodate = hb_qif_parser_check_iso_date(&ctx);
- //DB( g_print(" -> date is dd/mm/yy: %d\n", isodate) );
-
- DB( g_print("\n\n -> start transform all qif txn to hb txn\n") );
-
- DB( g_print(" -> %d qif txn\n", g_list_length(ctx.q_tra)) );
-
- // transform our qif transactions to homebank ones
- qiflist = g_list_first(ctx.q_tra);
- while (qiflist != NULL)
- {
- QIF_Tran *item = qiflist->data;
- Transaction *newope, *child;
- Account *accitem;
- Payee *payitem;
- Category *catitem;
- gchar *name, *tmpmemo, *tmppayee;
- gint nsplit;
-
- newope = da_transaction_malloc();
-
- newope->date = hb_date_get_julian(item->date, ictx->datefmt);
- if( newope->date == 0 )
- ictx->cnt_err_date++;
-
- //newope->paymode = atoi(str_array[1]);
- //newope->info = g_strdup(str_array[2]);
-
- //#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->memo = g_strdup(tmpmemo);
-
- newope->info = g_strdup(item->info);
- newope->amount = item->amount;
-
- //#773282 invert amount for ccard accounts
- if(ctx.is_ccard)
- newope->amount *= -1;
-
- // payee + append
- if( tmppayee != NULL )
- {
- payitem = da_pay_get_by_name(tmppayee);
- if(payitem == NULL)
- {
- //DB( g_print(" -> append pay: '%s'\n", tmppayee ) );
-
- payitem = da_pay_malloc();
- payitem->name = g_strdup(tmppayee);
- payitem->imported = TRUE;
- da_pay_append(payitem);
-
- ictx->cnt_new_pay += 1;
- }
- newope->kpay = payitem->key;
- }
-
- // LCategory of transaction
- // L[Transfer account name]
- // LCategory of transaction/Class of transaction
- // L[Transfer account]/Class of transaction
- if( item->category != NULL )
- {
- if(g_str_has_prefix(item->category, "[")) // this is a transfer account name
- {
- gchar *accname;
-
- //DB ( g_print(" -> transfer to: '%s'\n", item->category) );
-
- //remove brackets
- accname = hb_strdup_nobrackets(item->category);
-
- accitem = import_create_account(accname, NULL);
-
- newope->kxferacc = accitem->key;
- newope->paymode = PAYMODE_INTXFER;
-
- g_free(accname);
- }
- else
- {
- //DB ( g_print(" -> append cat: '%s'\n", item->category) );
-
- catitem = da_cat_append_ifnew_by_fullname(item->category, TRUE );
- if( catitem != NULL )
- {
- ictx->cnt_new_cat += 1;
- newope->kcat = catitem->key;
- }
- }
- }
-
- // splits, if not a xfer
- if( newope->paymode != PAYMODE_INTXFER )
- {
- for(nsplit=0;nsplit<item->nb_splits;nsplit++)
- {
- 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 )
- {
- 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 ? "" : item->account;
-
- DB( g_print(" -> account name is '%s'\n", name ) );
-
- accitem = import_create_account(name, NULL);
-
- newope->kacc = accitem->key;
-
- newope->flags |= OF_ADDED;
- if( newope->amount > 0 )
- newope->flags |= OF_INCOME;
-
- if( item->reconciled )
- 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)
- {
- //DB( g_print(" -> transaction already exist\n" ) );
- da_transaction_free(newope);
- }
- else
- {
- //DB( g_print(" -> append trans. acc:'%s', memo:'%s', val:%.2f\n", item->account, item->memo, item->amount ) );
- list = g_list_append(list, newope);
- }
-
- qiflist = g_list_next(qiflist);
- }
-
- // destroy our GLists
- da_qif_tran_destroy(&ctx);
-
- DB( g_print(" -> %d txn converted\n", g_list_length(list)) );
- DB( g_print(" -> %d errors\n", ictx->cnt_err_date) );
-
- return list;
-}