mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug 754533 Add CSV Register Export
Allow you to do a CSV export of the active Register View
This commit is contained in:
parent
f82717496a
commit
50350c40a7
@ -1803,6 +1803,24 @@ gnc_plugin_page_register_summarybar_position_changed (gpointer prefs, gchar* pre
|
||||
(position == GTK_POS_TOP ? 0 : -1) );
|
||||
}
|
||||
|
||||
/** This function is called to get the query associated with this
|
||||
* plugin page.
|
||||
*
|
||||
* @param page A pointer to the GncPluginPage.
|
||||
*/
|
||||
Query *
|
||||
gnc_plugin_page_register_get_query (GncPluginPage *plugin_page)
|
||||
{
|
||||
GncPluginPageRegister *page;
|
||||
GncPluginPageRegisterPrivate *priv;
|
||||
|
||||
g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(plugin_page));
|
||||
|
||||
page = GNC_PLUGIN_PAGE_REGISTER (plugin_page);
|
||||
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(page);
|
||||
return gnc_ledger_display_get_query (priv->ledger);
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
/* "Sort By" Dialog */
|
||||
/************************************************************/
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "gnc-ledger-display.h"
|
||||
#include "gnc-plugin-page.h"
|
||||
#include "gnc-split-reg.h"
|
||||
#include "Query.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -133,6 +134,15 @@ GNCSplitReg *
|
||||
gnc_plugin_page_register_get_gsr (GncPluginPage *plugin_page);
|
||||
|
||||
|
||||
/** Get the Query associated with this "register" plugin page.
|
||||
*
|
||||
* @param plugin_page The "register" page to modify.
|
||||
*
|
||||
* @return The query.
|
||||
*/
|
||||
Query *
|
||||
gnc_plugin_page_register_get_query (GncPluginPage *plugin_page);
|
||||
|
||||
/** Get the Account associated with this register page.
|
||||
*
|
||||
* @param page A "register" page.
|
||||
|
@ -1825,6 +1825,24 @@ gnc_plugin_page_register2_summarybar_position_changed (gpointer prefs, gchar* pr
|
||||
(position == GTK_POS_TOP ? 0 : -1) );
|
||||
}
|
||||
|
||||
/** This function is called to get the query associated with this
|
||||
* plugin page.
|
||||
*
|
||||
* @param page A pointer to the GncPluginPage.
|
||||
*/
|
||||
Query *
|
||||
gnc_plugin_page_register2_get_query (GncPluginPage *plugin_page)
|
||||
{
|
||||
GncPluginPageRegister2 *page;
|
||||
GncPluginPageRegister2Private *priv;
|
||||
|
||||
g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER2(plugin_page));
|
||||
|
||||
page = GNC_PLUGIN_PAGE_REGISTER2 (plugin_page);
|
||||
priv = GNC_PLUGIN_PAGE_REGISTER2_GET_PRIVATE(page);
|
||||
return gnc_ledger_display2_get_query (priv->ledger);
|
||||
}
|
||||
|
||||
/*#################################################################################*/
|
||||
/*#################################################################################*/
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "gnc-ledger-display2.h"
|
||||
#include "gnc-plugin-page.h"
|
||||
#include "gnc-split-reg2.h"
|
||||
#include "Query.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
/** @ingroup Register
|
||||
@ -136,6 +137,16 @@ GNCLedgerDisplay2 *
|
||||
gnc_plugin_page_register2_get_ledger (GncPluginPage *plugin_page);
|
||||
|
||||
|
||||
/** Get the Query associated with this "register" plugin page.
|
||||
*
|
||||
* @param plugin_page A "register" page.
|
||||
*
|
||||
* @return The query.
|
||||
*/
|
||||
Query *
|
||||
gnc_plugin_page_register2_get_query (GncPluginPage *plugin_page);
|
||||
|
||||
|
||||
/** Get the Account associated with this register page.
|
||||
*
|
||||
* @param page A "register" page.
|
||||
|
@ -38,6 +38,9 @@ AM_CPPFLAGS = \
|
||||
-I${top_srcdir}/src/app-utils \
|
||||
-I${top_srcdir}/src/gnome \
|
||||
-I${top_srcdir}/src/gnome-utils \
|
||||
-I${top_srcdir}/src/register/ledger-core \
|
||||
-I${top_srcdir}/src/register/register-core \
|
||||
-I${top_srcdir}/src/register/register-gnome \
|
||||
-I${top_srcdir}/src/import-export \
|
||||
-I${top_srcdir}/src/libqof/qof \
|
||||
-I${top_srcdir}/lib/libc \
|
||||
|
@ -87,12 +87,22 @@ static const gchar *finish_trans_string = N_(
|
||||
"You can also verify your selections by clicking on 'Back' or 'Cancel' to Abort Export.\n");
|
||||
|
||||
static const gchar *start_tree_string = N_(
|
||||
"This assistant will help you export the Account Tree to a file\n"
|
||||
" with the separator specified below.\n\n"
|
||||
"Select the settings you require for the file and then click 'Forward' to proceed"
|
||||
" or 'Cancel' to Abort Export.\n");
|
||||
"This assistant will help you export the Account Tree to a file\n"
|
||||
" with the separator specified below.\n\n"
|
||||
"Select the settings you require for the file and then click 'Forward' to proceed"
|
||||
" or 'Cancel' to Abort Export.\n");
|
||||
|
||||
static const gchar *start_trans_string = N_(
|
||||
"This assistant will help you export the Transactions to a file\n"
|
||||
" with the separator specified below.\n\n"
|
||||
"There will be multiple rows for each transaction and may"
|
||||
" require further manipulation to get them in a format you can use.\n\n"
|
||||
"Each Transaction will appear once in the export and will be listed in"
|
||||
" the order the accounts were processed\n\n"
|
||||
"Select the settings you require for the file and then click 'Forward' to proceed"
|
||||
" or 'Cancel' to Abort Export.\n");
|
||||
|
||||
static const gchar *start_trans_simple_string = N_(
|
||||
"This assistant will help you export the Transactions to a file\n"
|
||||
" with the separator specified below.\n\n"
|
||||
"There will be multiple rows for each transaction and may require further"
|
||||
@ -617,7 +627,12 @@ csv_export_assistant_start_page_prepare (GtkAssistant *assistant,
|
||||
if (info->export_type == XML_EXPORT_TREE)
|
||||
gtk_label_set_text (GTK_LABEL(info->start_label), gettext (start_tree_string));
|
||||
else
|
||||
gtk_label_set_text (GTK_LABEL(info->start_label), gettext (start_trans_string));
|
||||
{
|
||||
if ((info->export_type == XML_EXPORT_REGISTER) && (info->account == NULL))
|
||||
gtk_label_set_text (GTK_LABEL(info->start_label), gettext (start_trans_string));
|
||||
else
|
||||
gtk_label_set_text (GTK_LABEL(info->start_label), gettext (start_trans_simple_string));
|
||||
}
|
||||
|
||||
/* Enable the Assistant Buttons */
|
||||
gtk_assistant_set_page_complete (assistant, page, TRUE);
|
||||
@ -671,7 +686,12 @@ csv_export_assistant_finish_page_prepare (GtkAssistant *assistant,
|
||||
if (info->export_type == XML_EXPORT_TREE)
|
||||
text = g_strdup_printf (gettext (finish_tree_string), info->file_name);
|
||||
else
|
||||
text = g_strdup_printf (gettext (finish_trans_string), info->file_name, info->csva.num_accounts);
|
||||
{
|
||||
if ((info->export_type == XML_EXPORT_REGISTER) && (info->account != NULL))
|
||||
text = g_strdup_printf (gettext (finish_trans_string), info->file_name, 1);
|
||||
else
|
||||
text = g_strdup_printf (gettext (finish_trans_string), info->file_name, info->csva.num_accounts);
|
||||
}
|
||||
|
||||
gtk_label_set_text (GTK_LABEL(info->finish_label), text);
|
||||
g_free (text);
|
||||
@ -805,11 +825,13 @@ csv_export_assistant_create (CsvExportInfo *info)
|
||||
/* Account Page */
|
||||
info->account_page = GTK_WIDGET(gtk_builder_get_object(builder, "account_page"));
|
||||
|
||||
if (info->export_type == XML_EXPORT_TREE)
|
||||
if ((info->export_type == XML_EXPORT_TREE) || (info->export_type == XML_EXPORT_REGISTER))
|
||||
{
|
||||
GtkWidget *chkbox = GTK_WIDGET(gtk_builder_get_object(builder, "simple_layout"));
|
||||
|
||||
gtk_widget_destroy (chkbox);
|
||||
// If export is an account tree or info->account is NULL (Search/gl register)
|
||||
if ((info->export_type == XML_EXPORT_TREE) || (info->account == NULL))
|
||||
gtk_widget_destroy (chkbox);
|
||||
gtk_widget_destroy (info->account_page);
|
||||
}
|
||||
else
|
||||
@ -947,3 +969,29 @@ gnc_file_csv_export (CsvExportType export_type)
|
||||
gtk_widget_show_all (info->window);
|
||||
gnc_window_adjust_for_screen (GTK_WINDOW(info->window));
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************\
|
||||
* gnc_file_csv_export_register *
|
||||
* opens up a assistant to export register transactions based. * *
|
||||
* Args: export_type *
|
||||
* Args: Query *
|
||||
* Args: Account *
|
||||
* Return: nothing *
|
||||
\********************************************************************/
|
||||
void
|
||||
gnc_file_csv_export_register (CsvExportType export_type, Query *q, Account *acc)
|
||||
{
|
||||
CsvExportInfo *info;
|
||||
|
||||
info = g_new0 (CsvExportInfo, 1);
|
||||
info->export_type = export_type;
|
||||
info->query = q;
|
||||
info->account = acc;
|
||||
csv_export_assistant_create (info);
|
||||
gnc_register_gui_component (ASSISTANT_CSV_EXPORT_CM_CLASS,
|
||||
NULL, csv_export_close_handler,
|
||||
info);
|
||||
gtk_widget_show_all (info->window);
|
||||
gnc_window_adjust_for_screen (GTK_WINDOW(info->window));
|
||||
}
|
||||
|
@ -29,11 +29,13 @@
|
||||
#define GNC_ASSISTANT_CSV_EXPORT_H
|
||||
|
||||
#include "Account.h"
|
||||
#include "Query.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
XML_EXPORT_TREE,
|
||||
XML_EXPORT_TRANS
|
||||
XML_EXPORT_TRANS,
|
||||
XML_EXPORT_REGISTER
|
||||
} CsvExportType;
|
||||
|
||||
typedef struct
|
||||
@ -68,6 +70,9 @@ typedef struct
|
||||
CsvExportDate csvd;
|
||||
CsvExportAcc csva;
|
||||
GList *trans_list;
|
||||
|
||||
Query *query;
|
||||
Account *account;
|
||||
|
||||
GtkWidget *start_page;
|
||||
GtkWidget *account_page;
|
||||
@ -96,9 +101,14 @@ typedef struct
|
||||
} CsvExportInfo;
|
||||
|
||||
|
||||
/** The gnc_file_csv_export() will let the user export thte
|
||||
/** The gnc_file_csv_export() will let the user export the
|
||||
* account tree or transactions to a delimited file.
|
||||
*/
|
||||
void gnc_file_csv_export (CsvExportType export_type);
|
||||
|
||||
/** The gnc_file_csv_export_register() will let the user export the
|
||||
* active register transactions to a delimited file.
|
||||
*/
|
||||
void gnc_file_csv_export_register (CsvExportType export_type, Query *query, Account *acc);
|
||||
|
||||
#endif
|
||||
|
@ -570,26 +570,29 @@ make_complex_split_line (Transaction *trans, Split *split, CsvExportInfo *info)
|
||||
static
|
||||
void account_splits (CsvExportInfo *info, Account *acc, FILE *fh )
|
||||
{
|
||||
Query *q;
|
||||
GSList *p1, *p2;
|
||||
GList *splits;
|
||||
QofBook *book;
|
||||
|
||||
q = qof_query_create_for (GNC_ID_SPLIT);
|
||||
book = gnc_get_current_book();
|
||||
qof_query_set_book (q, book);
|
||||
// Setup the query for normal transaction export
|
||||
if (info->export_type == XML_EXPORT_TRANS)
|
||||
{
|
||||
info->query = qof_query_create_for (GNC_ID_SPLIT);
|
||||
book = gnc_get_current_book();
|
||||
qof_query_set_book (info->query, book);
|
||||
|
||||
/* Sort by transaction date */
|
||||
p1 = g_slist_prepend (NULL, TRANS_DATE_POSTED);
|
||||
p1 = g_slist_prepend (p1, SPLIT_TRANS);
|
||||
p2 = g_slist_prepend (NULL, QUERY_DEFAULT_SORT);
|
||||
qof_query_set_sort_order (q, p1, p2, NULL);
|
||||
/* Sort by transaction date */
|
||||
p1 = g_slist_prepend (NULL, TRANS_DATE_POSTED);
|
||||
p1 = g_slist_prepend (p1, SPLIT_TRANS);
|
||||
p2 = g_slist_prepend (NULL, QUERY_DEFAULT_SORT);
|
||||
qof_query_set_sort_order (info->query, p1, p2, NULL);
|
||||
|
||||
xaccQueryAddSingleAccountMatch (q, acc, QOF_QUERY_AND);
|
||||
xaccQueryAddDateMatchTT (q, TRUE, info->csvd.start_time, TRUE, info->csvd.end_time, QOF_QUERY_AND);
|
||||
xaccQueryAddSingleAccountMatch (info->query, acc, QOF_QUERY_AND);
|
||||
xaccQueryAddDateMatchTT (info->query, TRUE, info->csvd.start_time, TRUE, info->csvd.end_time, QOF_QUERY_AND);
|
||||
}
|
||||
|
||||
/* Run the query */
|
||||
for (splits = qof_query_run (q); splits; splits = splits->next)
|
||||
for (splits = qof_query_run (info->query); splits; splits = splits->next)
|
||||
{
|
||||
Split *split;
|
||||
Transaction *trans;
|
||||
@ -609,7 +612,11 @@ void account_splits (CsvExportInfo *info, Account *acc, FILE *fh )
|
||||
if (g_list_find (info->trans_list, trans) != NULL)
|
||||
continue;
|
||||
|
||||
// Simple Layout
|
||||
// Look for blank split
|
||||
if (xaccSplitGetAccount (split) == NULL)
|
||||
continue;
|
||||
|
||||
// This will be a simple layout equivalent to a single line register view.
|
||||
if (info->simple_layout)
|
||||
{
|
||||
line = make_simple_trans_line (acc, trans, split, info);
|
||||
@ -655,7 +662,8 @@ void account_splits (CsvExportInfo *info, Account *acc, FILE *fh )
|
||||
}
|
||||
info->trans_list = g_list_prepend (info->trans_list, trans); // add trans to trans_list
|
||||
}
|
||||
qof_query_destroy (q);
|
||||
if (info->export_type == XML_EXPORT_TRANS)
|
||||
qof_query_destroy (info->query);
|
||||
g_list_free (splits);
|
||||
}
|
||||
|
||||
@ -729,13 +737,19 @@ void csv_transactions_export (CsvExportInfo *info)
|
||||
}
|
||||
g_free (header);
|
||||
|
||||
/* Go through list of accounts */
|
||||
for (ptr = info->csva.account_list, i = 0; ptr; ptr = g_list_next(ptr), i++)
|
||||
if (info->export_type == XML_EXPORT_TRANS)
|
||||
{
|
||||
acc = ptr->data;
|
||||
DEBUG("Account being processed is : %s", xaccAccountGetName (acc));
|
||||
account_splits (info, acc, fh);
|
||||
/* Go through list of accounts */
|
||||
for (ptr = info->csva.account_list, i = 0; ptr; ptr = g_list_next(ptr), i++)
|
||||
{
|
||||
acc = ptr->data;
|
||||
DEBUG("Account being processed is : %s", xaccAccountGetName (acc));
|
||||
account_splits (info, acc, fh);
|
||||
}
|
||||
}
|
||||
else
|
||||
account_splits (info, info->account, fh);
|
||||
|
||||
g_list_free (info->trans_list); // free trans_list
|
||||
}
|
||||
else
|
||||
|
@ -5,6 +5,7 @@
|
||||
<placeholder name="FileExportPlaceholder">
|
||||
<menuitem name="FileCsvExportTree" action="CsvExportTreeAction"/>
|
||||
<menuitem name="FileCsvExportTrans" action="CsvExportTransAction"/>
|
||||
<menuitem name="FileCsvExportRegister" action="CsvExportRegisterAction"/>
|
||||
</placeholder>
|
||||
</menu>
|
||||
</menu>
|
||||
|
@ -30,6 +30,12 @@
|
||||
|
||||
#include "assistant-csv-export.h"
|
||||
|
||||
#include "gnc-plugin-page-register.h"
|
||||
/*################## Added for Reg2 #################*/
|
||||
#include "gnc-plugin-page-register2.h"
|
||||
/*################## Added for Reg2 #################*/
|
||||
#include "Query.h"
|
||||
|
||||
static void gnc_plugin_csv_export_class_init (GncPluginCsvExportClass *klass);
|
||||
static void gnc_plugin_csv_export_init (GncPluginCsvExport *plugin);
|
||||
static void gnc_plugin_csv_export_finalize (GObject *object);
|
||||
@ -37,6 +43,7 @@ static void gnc_plugin_csv_export_finalize (GObject *object);
|
||||
/* Command callbacks */
|
||||
static void gnc_plugin_csv_export_tree_cmd (GtkAction *action, GncMainWindowActionData *data);
|
||||
static void gnc_plugin_csv_export_trans_cmd (GtkAction *action, GncMainWindowActionData *data);
|
||||
static void gnc_plugin_csv_export_register_cmd (GtkAction *action, GncMainWindowActionData *data);
|
||||
|
||||
#define PLUGIN_ACTIONS_NAME "gnc-plugin-csv-export-actions"
|
||||
#define PLUGIN_UI_FILENAME "gnc-plugin-csv-export-ui.xml"
|
||||
@ -53,6 +60,11 @@ static GtkActionEntry gnc_plugin_actions [] =
|
||||
N_("Export the Transactions to a CSV file"),
|
||||
G_CALLBACK (gnc_plugin_csv_export_trans_cmd)
|
||||
},
|
||||
{
|
||||
"CsvExportRegisterAction", GTK_STOCK_CONVERT, N_("Export _Active Register to CSV..."), NULL,
|
||||
N_("Export the Active Register to a CSV file"),
|
||||
G_CALLBACK (gnc_plugin_csv_export_register_cmd)
|
||||
},
|
||||
};
|
||||
static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
|
||||
|
||||
@ -156,6 +168,33 @@ gnc_plugin_csv_export_trans_cmd (GtkAction *action,
|
||||
gnc_file_csv_export(XML_EXPORT_TRANS);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_plugin_csv_export_register_cmd (GtkAction *action,
|
||||
GncMainWindowActionData *data)
|
||||
{
|
||||
Query *query;
|
||||
GList *splits;
|
||||
Account *acc;
|
||||
|
||||
GncPluginPage *page = gnc_main_window_get_current_page (data->window);
|
||||
|
||||
if (GNC_IS_PLUGIN_PAGE_REGISTER(page))
|
||||
{
|
||||
query = gnc_plugin_page_register_get_query (page);
|
||||
acc = gnc_plugin_page_register_get_account (GNC_PLUGIN_PAGE_REGISTER(page));
|
||||
gnc_file_csv_export_register (XML_EXPORT_REGISTER, query, acc);
|
||||
}
|
||||
|
||||
/*################## Added for Reg2 #################*/
|
||||
if (GNC_IS_PLUGIN_PAGE_REGISTER2(page))
|
||||
{
|
||||
query = gnc_plugin_page_register2_get_query (page);
|
||||
acc = gnc_plugin_page_register2_get_account (GNC_PLUGIN_PAGE_REGISTER2(page));
|
||||
gnc_file_csv_export_register (XML_EXPORT_REGISTER, query, acc);
|
||||
}
|
||||
/*################## Added for Reg2 #################*/
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Plugin Bootstrapping *
|
||||
************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user