00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "config.h"
00024
00025 #include <gtk/gtk.h>
00026 #include <glib/gi18n.h>
00027 #include <stdio.h>
00028
00029 #include "gnc-ui-util.h"
00030 #include "Query.h"
00031 #include "qof.h"
00032 #include "SX-book.h"
00033 #include "Transaction.h"
00034 #include "dialog-find-transactions.h"
00035 #include "gnc-main-window.h"
00036 #include "gnc-plugin-page-register.h"
00037 #include "search-param.h"
00038
00039 #define GCONF_SECTION "dialogs/find"
00040
00041 struct _ftd_data
00042 {
00043 QofQuery * q;
00044 QofQuery * ledger_q;
00045 GNCSearchWindow * sw;
00046 };
00047
00048 static void
00049 do_find_cb (QofQuery *query, gpointer user_data, gpointer *result)
00050 {
00051 struct _ftd_data *ftd = user_data;
00052 GNCLedgerDisplay *ledger;
00053 gboolean new_ledger = FALSE;
00054 GncPluginPage *page;
00055
00056 ledger = gnc_ledger_display_find_by_query (ftd->ledger_q);
00057 if (!ledger)
00058 {
00059 new_ledger = TRUE;
00060 ledger = gnc_ledger_display_query (query, SEARCH_LEDGER,
00061 REG_STYLE_JOURNAL);
00062 }
00063 else
00064 gnc_ledger_display_set_query (ledger, query);
00065
00066 gnc_ledger_display_refresh (ledger);
00067
00068 if (new_ledger)
00069 {
00070 page = gnc_plugin_page_register_new_ledger (ledger);
00071 gnc_main_window_open_page (NULL, page);
00072 }
00073
00074 qof_query_destroy (ftd->q);
00075
00076 gnc_search_dialog_destroy (ftd->sw);
00077 }
00078
00079 static void
00080 free_ftd_cb (gpointer user_data)
00081 {
00082 struct _ftd_data *ftd = user_data;
00083
00084 if (!ftd)
00085 return;
00086
00087 g_free (ftd);
00088 }
00089
00090 GNCSearchWindow *
00091 gnc_ui_find_transactions_dialog_create(GNCLedgerDisplay * orig_ledg)
00092 {
00093 QofIdType type = GNC_ID_SPLIT;
00094 struct _ftd_data *ftd;
00095 static GList *params = NULL;
00096 QofQuery *start_q, *show_q = NULL;
00097
00098
00099 if (params == NULL)
00100 {
00101 params = gnc_search_param_prepend (params, N_("All Accounts"),
00102 ACCOUNT_MATCH_ALL_TYPE,
00103 type, SPLIT_TRANS, TRANS_SPLITLIST,
00104 SPLIT_ACCOUNT_GUID, NULL);
00105 params = gnc_search_param_prepend (params, N_("Account"), GNC_ID_ACCOUNT,
00106 type, SPLIT_ACCOUNT, QOF_PARAM_GUID,
00107 NULL);
00108 params = gnc_search_param_prepend (params, N_("Balanced"), NULL,
00109 type, SPLIT_TRANS, TRANS_IS_BALANCED,
00110 NULL);
00111 params = gnc_search_param_prepend (params, N_("Reconcile"), RECONCILED_MATCH_TYPE,
00112 type, SPLIT_RECONCILE, NULL);
00113 params = gnc_search_param_prepend (params, N_("Share Price"), NULL,
00114 type, SPLIT_SHARE_PRICE, NULL);
00115 params = gnc_search_param_prepend (params, N_("Shares"), NULL,
00116 type, SPLIT_AMOUNT, NULL);
00117 params = gnc_search_param_prepend (params, N_("Value"), NULL,
00118 type, SPLIT_VALUE, NULL);
00119 params = gnc_search_param_prepend (params, N_("Date Posted"), NULL,
00120 type, SPLIT_TRANS, TRANS_DATE_POSTED,
00121 NULL);
00122 params = gnc_search_param_prepend (params, N_("Notes"), NULL,
00123 type, SPLIT_TRANS, TRANS_NOTES, NULL);
00124 params = gnc_search_param_prepend (params, N_("Action"), NULL,
00125 type, SPLIT_ACTION, NULL);
00126 params = gnc_search_param_prepend (params, N_("Number"), NULL,
00127 type, SPLIT_TRANS, TRANS_NUM, NULL);
00128 params = gnc_search_param_prepend (params, N_("Memo"), NULL,
00129 type, SPLIT_MEMO, NULL);
00130 params = gnc_search_param_prepend (params, N_("Description"), NULL,
00131 type, SPLIT_TRANS, TRANS_DESCRIPTION,
00132 NULL);
00133 }
00134
00135 ftd = g_new0 (struct _ftd_data, 1);
00136
00137 if (orig_ledg)
00138 {
00139 ftd->ledger_q = gnc_ledger_display_get_query (orig_ledg);
00140 start_q = show_q = qof_query_copy (ftd->ledger_q);
00141 }
00142 else
00143 {
00144 start_q = qof_query_create ();
00145 qof_query_set_book (start_q, gnc_get_current_book ());
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 {
00160 Account *tRoot;
00161 GList *al;
00162
00163 tRoot = gnc_book_get_template_root( gnc_get_current_book() );
00164 al = gnc_account_get_descendants( tRoot );
00165 xaccQueryAddAccountMatch( start_q, al, QOF_GUID_MATCH_NONE, QOF_QUERY_AND );
00166 g_list_free (al);
00167 al = NULL;
00168 tRoot = NULL;
00169 }
00170
00171 ftd->q = start_q;
00172 }
00173
00174 ftd->sw = gnc_search_dialog_create (type, _("Find Transaction"),
00175 params, NULL, start_q, show_q,
00176 NULL, do_find_cb, NULL,
00177 ftd, free_ftd_cb, GCONF_SECTION, NULL);
00178
00179 if (!ftd->sw)
00180 {
00181 free_ftd_cb (ftd);
00182 return NULL;
00183 }
00184
00185 return ftd->sw;
00186 }