Example #1
0
static void
gnc_plugin_business_cmd_export_employee (GtkAction *action, GncMainWindowActionData *mw)
{
    QofSession *current_session, *chart_session;
    QofBook *book;
    QofCollection *coll;
    gchar *filename;
    gboolean success;

    current_session = gnc_get_current_session();
    book = qof_session_get_book(current_session);
    chart_session = qof_session_new();
    success = FALSE;
    filename = gnc_file_dialog(_("Export Employees to XML"), NULL,
                               NULL, GNC_FILE_DIALOG_EXPORT);
    if (filename)
    {
        gchar* url = g_strdup_printf( "qsf:%s", filename );
        qof_session_begin(chart_session, url, TRUE, TRUE);
        coll = qof_book_get_collection(book, GNC_ID_EMPLOYEE);
        success = qof_instance_copy_coll_r(chart_session, coll);
        if (success)
        {
            qof_session_save(chart_session, NULL);
        }
        g_free(url);
    }
    show_session_error(qof_session_get_error(chart_session), filename,
                       GNC_FILE_DIALOG_EXPORT);
    qof_session_end(chart_session);
    g_free(filename);
    gnc_set_current_session(current_session);
}
Example #2
0
static gchar *
gnc_plugin_bi_import_getFilename(void)
{
    // prepare file import dialog
    gchar *filename;
    GList *filters;
    GtkFileFilter *filter;
    filters = NULL;
    filter = gtk_file_filter_new ();
    gtk_file_filter_set_name (filter, "comma separated values (*.csv)");
    gtk_file_filter_add_pattern (filter, "*.csv");
    filters = g_list_append( filters, filter );
    filter = gtk_file_filter_new ();
    gtk_file_filter_set_name (filter, "text files (*.txt)");
    gtk_file_filter_add_pattern (filter, "*.txt");
    filters = g_list_append( filters, filter );
    filename = gnc_file_dialog(_("Import Bills or Invoices from csv"), filters, NULL, GNC_FILE_DIALOG_IMPORT);

    return filename;
}
Example #3
0
void
gnc_file_aqbanking_import(const gchar *aqbanking_importername,
                          const gchar *aqbanking_profilename,
                          gboolean execute_transactions)
{
    gchar *default_dir;
    gchar *selected_filename = NULL;
    gint dtaus_fd = -1;
    AB_BANKING *api = NULL;
    gboolean online = FALSE;
    GncGWENGui *gui = NULL;
    AB_IMEXPORTER *importer;
    GWEN_DB_NODE *db_profiles = NULL;
    GWEN_DB_NODE *db_profile;
    AB_IMEXPORTER_CONTEXT *context = NULL;
    GWEN_IO_LAYER *io;
    GncABImExContextImport *ieci = NULL;
    AB_JOB_LIST2 *job_list = NULL;

    /* Select a file */
    default_dir = gnc_get_default_directory(GCONF_SECTION_AQBANKING);
    selected_filename = gnc_file_dialog(_("Select a file to import"),
                                        NULL, default_dir,
                                        GNC_FILE_DIALOG_IMPORT);
    g_free(default_dir);

    if (!selected_filename)
        goto cleanup;
    DEBUG("filename: %s", selected_filename);

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

    dtaus_fd = g_open(selected_filename, O_RDONLY, 0);
    if (dtaus_fd == -1)
    {
        DEBUG("Could not open file %s", selected_filename);
        goto cleanup;
    }

    /* Get the API */
    api = gnc_AB_BANKING_new();
    if (!api)
    {
        g_warning("gnc_file_aqbanking_import: Couldn't get AqBanking API");
        goto cleanup;
    }
    if (AB_Banking_OnlineInit(api
#ifdef AQBANKING_VERSION_4_PLUS
                              , 0
#endif
                             ) != 0)
    {
        g_warning("gnc_file_aqbanking_import: "
                  "Couldn't initialize AqBanking API");
        goto cleanup;
    }
    online = TRUE;

    /* Get a GUI object */
    gui = gnc_GWEN_Gui_get(NULL);
    if (!gui)
    {
        g_warning("gnc_ab_getbalance: Couldn't initialize Gwenhywfar GUI");
        goto cleanup;
    }

    /* Get import module */
    importer = AB_Banking_GetImExporter(api, aqbanking_importername);
    if (!importer)
    {
        g_warning("Import module %s not found", aqbanking_importername);
        gnc_error_dialog(NULL, "%s",
                         _("Import module for DTAUS import not found."));
        goto cleanup;
    }

    /* Load the import profile */
    db_profiles = AB_Banking_GetImExporterProfiles(api, aqbanking_importername);

    /* Select profile */
    db_profile = GWEN_DB_GetFirstGroup(db_profiles);
    while (db_profile)
    {
        const gchar *name;

        name = GWEN_DB_GetCharValue(db_profile, "name", 0, 0);
        g_return_if_fail(name);
        if (g_ascii_strcasecmp(name, aqbanking_profilename) == 0)
            break;
        db_profile = GWEN_DB_GetNextGroup(db_profile);
    }
    if (!db_profile)
    {
        g_warning("Profile \"%s\" for importer \"%s\" not found",
                  aqbanking_profilename, aqbanking_importername);
        /* For debugging: Print those available names that have been found */
        db_profile = GWEN_DB_GetFirstGroup(db_profiles);
        while (db_profile)
        {
            const char *name = GWEN_DB_GetCharValue(db_profile, "name", 0, 0);
            g_warning("Only found profile \"%s\"\n", name ? name : "(null)");
            db_profile = GWEN_DB_GetNextGroup(db_profile);
        }
        goto cleanup;
    }

    /* Create a context to store the results */
    context = AB_ImExporterContext_new();

    /* Wrap file in buffered gwen io */
    io = GWEN_Io_LayerFile_new(dtaus_fd, -1);
    dtaus_fd = -1;
    if (GWEN_Io_Manager_RegisterLayer(io))
    {
        g_warning("gnc_file_aqbanking_import: Failed to wrap file");
        goto cleanup;
    }

    /* Run the import */
    if (AB_ImExporter_Import(importer, context, io, db_profile, 0))
    {
        g_warning("gnc_file_aqbanking_import: Error on import");
        goto cleanup;
    }

    /* Close the file */
    GWEN_Io_Layer_free(io);

    /* Import the results */
    ieci = gnc_ab_import_context(context, AWAIT_TRANSACTIONS,
                                 execute_transactions,
                                 execute_transactions ? api : NULL,
                                 NULL);

    /* Extract the list of jobs */
    job_list = gnc_ab_ieci_get_job_list(ieci);

    if (execute_transactions)
    {
        if (gnc_ab_ieci_run_matcher(ieci))
        {
            /* FIXME */
            /* gnc_hbci_multijob_execute(NULL, api, job_list, gui); */
        }
    }

cleanup:
    if (job_list)
        AB_Job_List2_FreeAll(job_list);
    if (ieci)
        g_free(ieci);
    if (context)
        AB_ImExporterContext_free(context);
    if (db_profiles)
        GWEN_DB_Group_free(db_profiles);
    if (gui)
        gnc_GWEN_Gui_release(gui);
    if (online)
#ifdef AQBANKING_VERSION_4_PLUS
        AB_Banking_OnlineFini(api, 0);
#else
        AB_Banking_OnlineFini(api);
#endif
    if (api)
        gnc_AB_BANKING_fini(api);
    if (dtaus_fd != -1)
        close(dtaus_fd);
    if (selected_filename)
        g_free(selected_filename);
}
void gnc_file_log_replay (void)
{
    char *selected_filename;
    char *default_dir;
    char read_buf[256];
    char *read_retval;
    GtkFileFilter *filter;
    FILE *log_file;
    char * record_start_str = "===== START";
    /* NOTE: This string must match src/engine/TransLog.cpp (sans newline) */
    char * expected_header_orig = "mod\ttrans_guid\tsplit_guid\ttime_now\t"
                                  "date_entered\tdate_posted\tacc_guid\tacc_name\tnum\tdescription\t"
                                  "notes\tmemo\taction\treconciled\tamount\tvalue\tdate_reconciled";
    static char *expected_header = NULL;

    /* Use g_strdup_printf so we don't get accidental tab -> space conversion */
    if (!expected_header)
        expected_header = g_strdup(expected_header_orig);

    qof_log_set_level(GNC_MOD_IMPORT, QOF_LOG_DEBUG);
    ENTER(" ");

    /* Don't log the log replay. This would only result in redundant logs */
    xaccLogDisable();

    default_dir = gnc_get_default_directory(GCONF_SECTION);

    filter = gtk_file_filter_new();
    gtk_file_filter_set_name(filter, "*.log");
    gtk_file_filter_add_pattern(filter, "*.[Ll][Oo][Gg]");
    selected_filename = gnc_file_dialog(_("Select a .log file to replay"),
                                        g_list_prepend(NULL, filter),
                                        default_dir,
                                        GNC_FILE_DIALOG_OPEN);
    g_free(default_dir);

    if (selected_filename != NULL)
    {
        /* Remember the directory as the default. */
        default_dir = g_path_get_dirname(selected_filename);
        gnc_set_default_directory(GCONF_SECTION, default_dir);
        g_free(default_dir);

        /*strncpy(file,selected_filename, 255);*/
        DEBUG("Filename found: %s", selected_filename);
        if (xaccFileIsCurrentLog(selected_filename))
        {
            g_warning("Cannot open the current log file: %s", selected_filename);
            gnc_error_dialog(NULL,
                             /* Translators: %s is the file name. */
                             _("Cannot open the current log file: %s"),
                             selected_filename);
        }
        else
        {
            DEBUG("Opening selected file");
            log_file = g_fopen(selected_filename, "r");
            if (!log_file || ferror(log_file) != 0)
            {
                int err = errno;
                perror("File open failed");
                gnc_error_dialog(NULL,
                                 /* Translation note:
                                  * First argument is the filename,
                                  * second argument is the error.
                                  */
                                 _("Failed to open log file: %s: %s"),
                                 selected_filename,
                                 strerror(err));
            }
            else
            {
                if ((read_retval = fgets(read_buf, sizeof(read_buf), log_file)) == NULL)
                {
                    DEBUG("Read error or EOF");
                    gnc_info_dialog(NULL, "%s",
                                    _("The log file you selected was empty."));
                }
                else
                {
                    if (strncmp(expected_header, read_buf, strlen(expected_header)) != 0)
                    {
                        PERR("File header not recognised:\n%s", read_buf);
                        PERR("Expected:\n%s", expected_header);
                        gnc_error_dialog(NULL, "%s",
                                         _("The log file you selected cannot be read.  "
                                           "The file header was not recognized."));
                    }
                    else
                    {
                        do
                        {
                            read_retval = fgets(read_buf, sizeof(read_buf), log_file);
                            /*DEBUG("Chunk read: %s",read_retval);*/
                            if (strncmp(record_start_str, read_buf, strlen(record_start_str)) == 0) /* If a record started */
                            {
                                process_trans_record(log_file);
                            }
                        }
                        while (feof(log_file) == 0);
                    }
                }
                fclose(log_file);
            }
        }
        g_free(selected_filename);
    }
    /* Start logging again */
    xaccLogEnable();

    LEAVE("");
}
Example #5
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");
    }
}