29 #include <glib/gi18n.h>
33 #include "gnc-component-manager.h"
37 #include "gnc-locale-utils.h"
39 #include "window-main-summarybar.h"
44 GtkWidget * totals_combo;
45 GtkListStore *datamodel;
50 #define WINDOW_SUMMARYBAR_CM_CLASS "summary-bar"
52 #define GNC_PREFS_GROUP "window.pages.account-tree.summary"
53 #define GNC_PREF_GRAND_TOTAL "grand-total"
54 #define GNC_PREF_NON_CURRENCY "non-currency"
77 #define TOTAL_SINGLE 0
78 #define TOTAL_CURR_TOTAL 1
79 #define TOTAL_NON_CURR_TOTAL 2
80 #define TOTAL_GRAND_TOTAL 3
88 gboolean non_currency;
98 gnc_ui_get_currency_accumulator(GList **list,
gnc_commodity * currency, gint total_mode)
103 for (current = g_list_first(*list); current; current = g_list_next(current))
105 found = current->data;
107 && (found->total_mode == total_mode))
114 found->currency = currency;
115 found->assets = gnc_numeric_zero ();
116 found->profits = gnc_numeric_zero ();
117 found->total_mode = total_mode;
118 *list = g_list_append (*list, found);
127 gnc_ui_accounts_recurse (
Account *parent, GList **currency_list,
139 GList *children, *node;
140 gboolean non_currency = FALSE;
144 if (parent == NULL)
return;
147 for (node = children; node; node = g_list_next(node))
154 if (options.grand_total)
155 grand_total_accum = gnc_ui_get_currency_accumulator(currency_list,
156 options.default_currency,
162 non_curr_accum = gnc_ui_get_currency_accumulator(currency_list,
163 options.default_currency,
164 TOTAL_NON_CURR_TOTAL);
167 if (!non_currency || options.non_currency)
169 currency_accum = gnc_ui_get_currency_accumulator(currency_list,
174 switch (account_type)
187 end_amount_default_currency =
188 xaccAccountConvertBalanceToCurrencyAsOfDate
189 (account, end_amount, account_currency, options.default_currency,
192 if (!non_currency || options.non_currency)
194 currency_accum->assets =
202 non_curr_accum->assets =
208 if (options.grand_total)
210 grand_total_accum->assets =
211 gnc_numeric_add (grand_total_accum->assets, end_amount_default_currency,
216 gnc_ui_accounts_recurse(account, currency_list, options);
222 start_amount_default_currency =
223 xaccAccountConvertBalanceToCurrencyAsOfDate
224 (account, start_amount, account_currency, options.default_currency,
228 end_amount_default_currency =
229 xaccAccountConvertBalanceToCurrencyAsOfDate
230 (account, end_amount, account_currency, options.default_currency,
233 if (!non_currency || options.non_currency)
235 currency_accum->profits =
239 currency_accum->profits =
247 non_curr_accum->profits =
248 gnc_numeric_add (non_curr_accum->profits, start_amount_default_currency,
251 non_curr_accum->profits =
257 if (options.grand_total)
259 grand_total_accum->profits =
261 start_amount_default_currency,
264 grand_total_accum->profits =
266 end_amount_default_currency,
271 gnc_ui_accounts_recurse(account, currency_list, options);
287 g_list_free(children);
291 get_total_mode_label(
const char *mnemonic,
int total_mode)
297 case TOTAL_CURR_TOTAL:
298 label_str = g_strdup_printf( _(
"%s, Total:"), mnemonic );
300 case TOTAL_NON_CURR_TOTAL:
301 label_str = g_strdup_printf( _(
"%s, Non Currency Commodities Total:"), mnemonic );
303 case TOTAL_GRAND_TOTAL:
304 label_str = g_strdup_printf( _(
"%s, Grand Total:"), mnemonic );
308 label_str = g_strdup_printf( _(
"%s:"), mnemonic );
316 COLUMN_MNEMONIC_TYPE,
320 COLUMN_PROFITS_VALUE,
345 char asset_string[256];
346 char profit_string[256];
348 GList *currency_list;
353 root = gnc_get_current_root_account ();
355 if (options.default_currency == NULL)
360 options.grand_total =
362 options.non_currency =
364 options.start_date = gnc_accounting_period_fiscal_start();
365 options.end_date = gnc_accounting_period_fiscal_end();
367 currency_list = NULL;
370 if (options.grand_total)
372 gnc_ui_get_currency_accumulator (¤cy_list, options.default_currency,
376 gnc_ui_get_currency_accumulator (¤cy_list, options.default_currency,
379 gnc_ui_accounts_recurse(root, ¤cy_list, options);
383 char asset_amount_string[256], profit_amount_string[256];
386 lc = gnc_localeconv();
388 g_object_ref(summary->datamodel);
389 gtk_combo_box_set_model(GTK_COMBO_BOX(summary->totals_combo), NULL);
390 gtk_list_store_clear(summary->datamodel);
391 for (current = g_list_first(currency_list); current; current = g_list_next(current))
393 const char *mnemonic;
394 gchar *total_mode_label;
396 currency_accum = current->data;
399 if (mnemonic == NULL)
402 *asset_string =
'\0';
404 currency_accum->assets,
405 gnc_commodity_print_info(currency_accum->currency, TRUE));
407 *profit_string =
'\0';
409 currency_accum->profits,
410 gnc_commodity_print_info(currency_accum->currency, TRUE));
412 gtk_list_store_append(summary->datamodel, &iter);
413 total_mode_label = get_total_mode_label(mnemonic, currency_accum->total_mode);
414 gtk_list_store_set(summary->datamodel, &iter,
415 COLUMN_MNEMONIC_TYPE, total_mode_label,
416 COLUMN_ASSETS, _(
"Net Assets:"),
417 COLUMN_ASSETS_VALUE, asset_amount_string,
418 COLUMN_PROFITS, _(
"Profits:"),
419 COLUMN_PROFITS_VALUE, profit_amount_string,
421 g_free(total_mode_label);
423 gtk_combo_box_set_model(GTK_COMBO_BOX(summary->totals_combo),
424 GTK_TREE_MODEL(summary->datamodel));
425 g_object_unref(summary->datamodel);
427 gtk_combo_box_set_active(GTK_COMBO_BOX(summary->totals_combo), 0);
431 for (current = g_list_first(currency_list);
433 current = g_list_next(current))
435 g_free(current->data);
437 g_list_free(currency_list);
441 gnc_main_window_summary_destroy_cb(
GNCMainSummary *summary, gpointer data)
444 gnc_unregister_gui_component(summary->component_id);
449 summarybar_refresh_handler(GHashTable * changes, gpointer user_data)
452 gnc_main_window_summary_refresh(summary);
456 prefs_changed_cb (gpointer prefs, gchar *pref, gpointer user_data)
459 gnc_main_window_summary_refresh(summary);
463 gnc_main_window_summary_new (
void)
466 GtkCellRenderer *textRenderer;
471 gboolean expandOptions[] = { TRUE, FALSE, TRUE, FALSE, TRUE };
473 retval->datamodel = gtk_list_store_new( N_COLUMNS,
480 retval->hbox = gtk_hbox_new (FALSE, 5);
481 retval->totals_combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (retval->datamodel));
482 g_object_unref (retval->datamodel);
484 retval->component_id = gnc_register_gui_component (WINDOW_SUMMARYBAR_CM_CLASS,
485 summarybar_refresh_handler,
487 gnc_gui_component_watch_entity_type (retval->component_id,
490 | GNC_EVENT_ITEM_CHANGED);
492 for ( i = 0; i < N_COLUMNS; i++ )
494 textRenderer = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
495 gtk_cell_layout_pack_start( GTK_CELL_LAYOUT(retval->totals_combo), textRenderer, expandOptions[i] );
496 gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(retval->totals_combo), textRenderer,
"text", i );
499 gtk_container_set_border_width (GTK_CONTAINER (retval->hbox), 2);
500 gtk_box_pack_start (GTK_BOX(retval->hbox), retval->totals_combo, TRUE, TRUE, 5);
501 gtk_widget_show (retval->totals_combo);
502 gtk_widget_show (retval->hbox);
504 g_signal_connect_swapped (G_OBJECT (retval->hbox),
"destroy",
505 G_CALLBACK (gnc_main_window_summary_destroy_cb),
508 gnc_main_window_summary_refresh(retval);
511 prefs_changed_cb, retval);
gboolean gnc_commodity_is_currency(const gnc_commodity *cm)
int gnc_commodity_get_fraction(const gnc_commodity *cm)
time64 timespecToTime64(Timespec ts)
gulong gnc_prefs_register_cb(const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
utility functions for the GnuCash UI
GNCAccountType xaccAccountGetType(const Account *acc)
Timespec timespecCanonicalDayTime(Timespec t)
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Use a 64-bit unsigned int timespec.
gnc_commodity * gnc_default_currency(void)
void gnc_prefs_remove_cb_by_id(const gchar *group, guint id)
Account handling public routines.
General utilities for dealing with accounting periods.
const char * gnc_commodity_get_nice_symbol(const gnc_commodity *cm)
Additional event handling code.
gnc_numeric xaccAccountGetBalanceAsOfDate(Account *acc, time64 date)
int xaccSPrintAmount(char *bufp, gnc_numeric val, GNCPrintAmountInfo info)
Generic api to store and retrieve preferences.
gnc_numeric gnc_numeric_sub(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
GList * gnc_account_get_children(const Account *account)
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
void timespecFromTime64(Timespec *ts, time64 t)