Exemplo n.º 1
0
static AB_IMEXPORTER_ACCOUNTINFO *
txn_accountinfo_cb(AB_IMEXPORTER_ACCOUNTINFO *element, gpointer user_data)
{
    GncABImExContextImport *data = user_data;
    Account *gnc_acc;

    g_return_val_if_fail(element && data, NULL);

    if (data->awaiting & IGNORE_TRANSACTIONS)
        /* Ignore them */
        return NULL;

    if (!AB_ImExporterAccountInfo_GetFirstTransaction(element))
        /* No transaction found */
        return NULL;
    else
        data->awaiting |= FOUND_TRANSACTIONS;

    if (!(data->awaiting & AWAIT_TRANSACTIONS))
    {
        if (gnc_verify_dialog(data->parent, TRUE, "%s",
                              _("The bank has sent transaction information "
                                "in its response."
                                "\n"
                                "Do you want to import it?")))
        {
            data->awaiting |= AWAIT_TRANSACTIONS;
        }
        else
        {
            data->awaiting |= IGNORE_TRANSACTIONS;
            return NULL;
        }
    }

    /* Lookup the corresponding gnucash account */
    gnc_acc = gnc_ab_accinfo_to_gnc_acc(element);
    if (!gnc_acc) return NULL;
    data->gnc_acc = gnc_acc;

    if (data->execute_txns)
    {
        /* Retrieve the aqbanking account that belongs to this gnucash
         * account */
        data->ab_acc = gnc_ab_get_ab_account(data->api, gnc_acc);
        if (!data->ab_acc)
        {
            gnc_error_dialog(NULL, "%s",
                             _("No Online Banking account found for this "
                               "gnucash account. These transactions will "
                               "not be executed by Online Banking."));
        }
    }
    else
    {
        data->ab_acc = NULL;
    }

    if (!data->generic_importer)
    {
        data->generic_importer = gnc_gen_trans_list_new(data->parent, NULL,
                                 TRUE, 14);
        if (data->execute_txns)
        {
            gnc_gen_trans_list_add_tp_cb(data->generic_importer,
                                         gnc_ab_trans_processed_cb, data);
        }
    }

    /* Iterate through all transactions */
    AB_ImExporterAccountInfo_TransactionsForEach(element, txn_transaction_cb,
            data);

    return NULL;
}
Exemplo n.º 2
0
void gnc_file_ofx_import (void)
{
    extern int ofx_PARSER_msg;
    extern int ofx_DEBUG_msg;
    extern int ofx_WARNING_msg;
    extern int ofx_ERROR_msg;
    extern int ofx_INFO_msg;
    extern int ofx_STATUS_msg;
    char *selected_filename;
    char *default_dir;
    LibofxContextPtr libofx_context = libofx_get_new_context();

    ofx_PARSER_msg = false;
    ofx_DEBUG_msg = false;
    ofx_WARNING_msg = true;
    ofx_ERROR_msg = true;
    ofx_INFO_msg = true;
    ofx_STATUS_msg = false;

    DEBUG("gnc_file_ofx_import(): Begin...\n");

    default_dir = gnc_get_default_directory(GNC_PREFS_GROUP);
    selected_filename = gnc_file_dialog(_("Select an OFX/QFX file to process"),
                                        NULL,
                                        default_dir,
                                        GNC_FILE_DIALOG_IMPORT);
    g_free(default_dir);

    if (selected_filename != NULL)
    {
#ifdef G_OS_WIN32
        gchar *conv_name;
#endif

        /* Remember the directory as the default. */
        default_dir = g_path_get_dirname(selected_filename);
        gnc_set_default_directory(GNC_PREFS_GROUP, default_dir);
        g_free(default_dir);

        /*strncpy(file,selected_filename, 255);*/
        DEBUG("Filename found: %s", selected_filename);

        /* Create the Generic transaction importer GUI. */
        gnc_ofx_importer_gui = gnc_gen_trans_list_new(NULL, NULL, FALSE, 42);

        /* Look up the needed preferences */
        auto_create_commodity =
            gnc_prefs_get_bool (GNC_PREFS_GROUP_IMPORT, GNC_PREF_AUTO_COMMODITY);

        /* Initialize libofx */

        /*ofx_set_statement_cb(libofx_context, ofx_proc_statement_cb, 0);*/
        ofx_set_account_cb(libofx_context, ofx_proc_account_cb, 0);
        ofx_set_transaction_cb(libofx_context, ofx_proc_transaction_cb, 0);
        ofx_set_security_cb(libofx_context, ofx_proc_security_cb, 0);
        /*ofx_set_status_cb(libofx_context, ofx_proc_status_cb, 0);*/

#ifdef G_OS_WIN32
        conv_name = g_win32_locale_filename_from_utf8(selected_filename);
        g_free(selected_filename);
        selected_filename = conv_name;
#endif

        DEBUG("Opening selected file");
        libofx_proc_file(libofx_context, selected_filename, AUTODETECT);
        g_free(selected_filename);
    }

    if (ofx_created_commodites)
    {
        /* FIXME: Present some result window about the newly created
         * commodities */
        g_warning("Created %d new commodities during import", g_list_length(ofx_created_commodites));
        g_list_free(ofx_created_commodites);
        ofx_created_commodites = NULL;
    }
    else
    {
        //g_warning("No new commodities created");
    }
}