GnuCash c935c2f+
Loading...
Searching...
No Matches
dialog-find-transactions.c
1/********************************************************************\
2 * dialog-find-transactions.c : locate transactions and show them *
3 * Copyright (C) 2000 Bill Gribble <grib@billgribble.com> *
4 * *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License as *
7 * published by the Free Software Foundation; either version 2 of *
8 * the License, or (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License*
16 * along with this program; if not, contact: *
17 * *
18 * Free Software Foundation Voice: +1-617-542-5942 *
19 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20 * Boston, MA 02110-1301, USA gnu@gnu.org *
21\********************************************************************/
22
23#include <config.h>
24
25#include <gtk/gtk.h>
26#include <glib/gi18n.h>
27#include <stdio.h>
28
29#include "gnc-ui-util.h"
30#include "Query.h"
31#include "qof.h"
32#include "SX-book.h"
33#include "Transaction.h"
34#include "dialog-find-transactions.h"
35#include "gnc-main-window.h"
37#include "search-param.h"
38#include "dialog-utils.h"
39
40#define GNC_PREFS_GROUP_SEARCH "dialogs.find"
41
43{
44 QofQuery *q;
45 QofQuery *ledger_q;
46 GNCSearchWindow *sw;
47 GtkWindow *parent;
48};
49
50static void
51do_find_cb (QofQuery *query, gpointer user_data, gpointer *result)
52{
53 struct _ftd_data *ftd = user_data;
54 GNCLedgerDisplay *ledger;
55 gboolean new_ledger = FALSE;
56 GncPluginPage *page;
57
58 ledger = gnc_ledger_display_find_by_query (ftd->ledger_q);
59 if (!ledger)
60 {
61 new_ledger = TRUE;
62 ledger = gnc_ledger_display_query (query, SEARCH_LEDGER,
63 REG_STYLE_JOURNAL);
64 }
65 else
66 gnc_ledger_display_set_query (ledger, query);
67
68 if (new_ledger)
69 {
71 gnc_main_window_open_page (GNC_MAIN_WINDOW(ftd->parent), page);
72 }
73 else
75
76 qof_query_destroy (ftd->q);
77
78 gnc_search_dialog_destroy (ftd->sw);
79}
80
81static void
82free_ftd_cb (gpointer user_data)
83{
84 struct _ftd_data *ftd = user_data;
85
86 if (!ftd)
87 return;
88
89 g_free (ftd);
90}
91
92GNCSearchWindow *
93gnc_ui_find_transactions_dialog_create(GtkWindow *parent, GNCLedgerDisplay * orig_ledg)
94{
95 QofIdType type = GNC_ID_SPLIT;
96 struct _ftd_data *ftd;
97 static GList *params = NULL;
98 QofQuery *start_q, *show_q = NULL;
99 gboolean num_action =
100 qof_book_use_split_action_for_num_field(gnc_get_current_book());
101
102 /* Build parameter list in reverse order */
103 if (params == NULL)
104 {
105 params = gnc_search_param_prepend (params, N_("All Accounts"),
107 type, SPLIT_TRANS, TRANS_SPLITLIST,
108 SPLIT_ACCOUNT_GUID, NULL);
109 params = gnc_search_param_prepend (params, N_("Account"), GNC_ID_ACCOUNT,
110 type, SPLIT_ACCOUNT, QOF_PARAM_GUID,
111 NULL);
112 params = gnc_search_param_prepend (params, N_("Balanced"), NULL,
113 type, SPLIT_TRANS, TRANS_IS_BALANCED,
114 NULL);
115 params = gnc_search_param_prepend (params, N_("Closing Entries"), NULL,
116 type, SPLIT_TRANS, TRANS_IS_CLOSING,
117 NULL);
118 params = gnc_search_param_prepend (params, N_("Reconcile"), RECONCILED_MATCH_TYPE,
119 type, SPLIT_RECONCILE, NULL);
120 params = gnc_search_param_prepend (params, N_("Share Price"), NULL,
121 type, SPLIT_SHARE_PRICE, NULL);
122 params = gnc_search_param_prepend (params, N_("Shares"), NULL,
123 type, SPLIT_AMOUNT, NULL);
124 params = gnc_search_param_prepend (params, N_("Value"), NULL,
125 type, SPLIT_VALUE, NULL);
126 params = gnc_search_param_prepend (params, N_("Date Posted"), NULL,
127 type, SPLIT_TRANS, TRANS_DATE_POSTED,
128 NULL);
129 params = gnc_search_param_prepend (params, N_("Reconciled Date"), NULL,
130 type, SPLIT_DATE_RECONCILED, NULL);
131 params = gnc_search_param_prepend (params, (num_action
132 ? N_("Number/Action")
133 : N_("Action")), NULL,
134 type, SPLIT_ACTION, NULL);
135 params = gnc_search_param_prepend (params, (num_action
136 ? N_("Transaction Number")
137 : N_("Number")), NULL,
138 type, SPLIT_TRANS, TRANS_NUM, NULL);
139 {
140 GList *params2 = NULL;
141 params2 = gnc_search_param_prepend (params2, "", NULL,
142 type, SPLIT_MEMO, NULL);
143 params2 = gnc_search_param_prepend (params2, "", NULL,
144 type, SPLIT_TRANS, TRANS_DESCRIPTION,
145 NULL);
146 params2 = gnc_search_param_prepend (params2, "", NULL,
147 type, SPLIT_TRANS, TRANS_NOTES, NULL);
148 params = gnc_search_param_prepend_compound (params,
149 N_("Description, Notes, or Memo"),
150 params2,
151 GTK_JUSTIFY_LEFT, SEARCH_PARAM_ANY);
152 }
153 params = gnc_search_param_prepend (params, N_("Memo"), NULL,
154 type, SPLIT_MEMO, NULL);
155 params = gnc_search_param_prepend (params, N_("Notes"), NULL,
156 type, SPLIT_TRANS, TRANS_NOTES, NULL);
157 params = gnc_search_param_prepend (params, N_("Description"), NULL,
158 type, SPLIT_TRANS, TRANS_DESCRIPTION,
159 NULL);
160 }
161 else
162 {
163 GList *l;
164 for (l = params; l; l = l->next)
165 {
166 GNCSearchParam *param = l->data;
167
168 if (num_action)
169 {
170 if (strcmp (gnc_search_param_get_title (param), N_("Action")) == 0)
171 gnc_search_param_set_title (param, N_("Number/Action"));
172 if (strcmp (gnc_search_param_get_title (param), N_("Number")) == 0)
173 gnc_search_param_set_title (param, N_("Transaction Number"));
174 }
175 else
176 {
177 if (strcmp (gnc_search_param_get_title (param), N_("Number/Action")) == 0)
178 gnc_search_param_set_title (param, N_("Action"));
179 if (strcmp (gnc_search_param_get_title (param), N_("Transaction Number")) == 0)
180 gnc_search_param_set_title (param, N_("Number"));
181 }
182 }
183 }
184
185 ftd = g_new0 (struct _ftd_data, 1);
186
187 if (orig_ledg)
188 {
189 ftd->ledger_q = gnc_ledger_display_get_query (orig_ledg);
190 start_q = show_q = qof_query_copy (ftd->ledger_q);
191 }
192 else
193 {
194 start_q = qof_query_create ();
195 qof_query_set_book (start_q, gnc_get_current_book ());
196 ftd->q = start_q; // save this to destroy it later
197 }
198
199 ftd->parent = parent;
200
201 ftd->sw = gnc_search_dialog_create (parent, type, _("Find Transaction"),
202 params, NULL, start_q, show_q,
203 NULL, do_find_cb, NULL,
204 ftd, free_ftd_cb, GNC_PREFS_GROUP_SEARCH, NULL,
205 "gnc-class-transactions");
206 if (!ftd->sw)
207 {
208 free_ftd_cb (ftd);
209 return NULL;
210 }
211
212 return ftd->sw;
213}
Anchor Scheduled Transaction info in a book.
API for Transactions and Splits (journal entries)
Functions for adding content to a window.
Functions providing a register page for the GnuCash UI.
utility functions for the GnuCash UI
gboolean qof_book_use_split_action_for_num_field(const QofBook *book)
Returns TRUE if this book uses split action field as the 'Num' field, FALSE if it uses transaction nu...
#define ACCOUNT_MATCH_ALL_TYPE
This is the type-override when you want to match all accounts.
Definition Account.h:1754
const gchar * QofIdType
QofIdType declaration.
Definition qofid.h:80
void gnc_main_window_open_page(GncMainWindow *window, GncPluginPage *page)
Display a data plugin page in a window.
Query * gnc_ledger_display_get_query(GNCLedgerDisplay *ld)
return the query associated with a ledger
void gnc_ledger_display_refresh(GNCLedgerDisplay *ld)
redisplay/redraw only the indicated window.
GNCLedgerDisplay * gnc_ledger_display_query(Query *query, SplitRegisterType type, SplitRegisterStyle style)
display a general ledger for an arbitrary query
void gnc_ledger_display_set_query(GNCLedgerDisplay *ledger_display, Query *q)
Set the query used for a register.
GNCLedgerDisplay * gnc_ledger_display_find_by_query(Query *q)
If the given ledger display still exists, return it.
QofQuery * qof_query_copy(QofQuery *q)
Make a copy of the indicated query.
void qof_query_set_book(QofQuery *query, QofBook *book)
Set the book to be searched.
void qof_query_destroy(QofQuery *query)
Frees the resources associate with a Query object.
QofQuery * qof_query_create(void)
Create a new query.
Definition qofquery.cpp:918
GncPluginPage * gnc_plugin_page_register_new_ledger(GNCLedgerDisplay *ledger)
Create a new "register" plugin page, given a pointer to an already created ledger.
#define SPLIT_ACCOUNT_GUID
for guid_match_all
Definition Split.h:571
The instance data structure for a content plugin.
A Query.
Definition qofquery.cpp:75