mirror of
https://github.com/Gnucash/gnucash.git
synced 2026-07-29 23:58:03 -05:00
* src/app-utils/options.scm: Create two new functions to centralize
date-selection option creation. * src/app-utils/app-utils.scm: export the new scheme functions * src/app-utils/prefs.scm: Modify Herbert's patch to centralize the date-selection option code. * src/report/report-system/options-utilities.scm: use the new centralized date-selection option-creation code. * src/app-utils/global-options.c: * src/app-utils/global-options.h: add gnc_lookup_date_option() function * src/app-utils/gnc-ui-util.c: * src/app-utils/gnc-ui-util.h: add gnc_ui_account_get_balance_in_currency() function * src/app-utils/prefs.scm: add preferences for summarybar * src/engine/Account.c: * src/engine/Account.h: add xaccAccountConvertBalanceToCurrencyAsOfDate() function * src/gnome/window-main-summarybar.c: summarybar can now display a grand total of all commodities, profits of a period of time and net assets at the end of the period; summarybar can be configured with some options under edit->preferences git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9780 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -1,3 +1,30 @@
|
||||
2004-01-15 Derek Atkins <derek@ihtfp.com>
|
||||
|
||||
* src/app-utils/options.scm: Create two new functions to centralize
|
||||
date-selection option creation.
|
||||
* src/app-utils/app-utils.scm: export the new scheme functions
|
||||
* src/app-utils/prefs.scm: Modify Herbert's patch to centralize
|
||||
the date-selection option code.
|
||||
* src/report/report-system/options-utilities.scm: use the new
|
||||
centralized date-selection option-creation code.
|
||||
|
||||
2004-01-13 Herbert Thoma <herbie@hthoma.de>
|
||||
|
||||
* src/app-utils/global-options.c:
|
||||
* src/app-utils/global-options.h: add gnc_lookup_date_option()
|
||||
function
|
||||
* src/app-utils/gnc-ui-util.c:
|
||||
* src/app-utils/gnc-ui-util.h: add
|
||||
gnc_ui_account_get_balance_in_currency() function
|
||||
* src/app-utils/prefs.scm: add preferences for summarybar
|
||||
* src/engine/Account.c:
|
||||
* src/engine/Account.h: add
|
||||
xaccAccountConvertBalanceToCurrencyAsOfDate() function
|
||||
* src/gnome/window-main-summarybar.c: summarybar can now display
|
||||
a grand total of all commodities, profits of a period of time
|
||||
and net assets at the end of the period; summarybar can be
|
||||
configured with some options under edit->preferences
|
||||
|
||||
2004-01-13 Christian Stimming <stimming@tuhh.de>
|
||||
|
||||
* src/import-export/hbci/hbci-interaction.c, gnc-hbci-utils.c: Add
|
||||
|
||||
@@ -70,6 +70,8 @@
|
||||
(export gnc:make-radiobutton-option)
|
||||
(export gnc:make-radiobutton-callback-option)
|
||||
(export gnc:make-list-option)
|
||||
(export gnc:options-make-end-date!)
|
||||
(export gnc:options-make-date-interval!)
|
||||
|
||||
(export gnc:make-number-range-option)
|
||||
(export gnc:make-internal-option)
|
||||
|
||||
@@ -239,6 +239,40 @@ gnc_lookup_multichoice_option(const char *section, const char *name,
|
||||
name, default_value);
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
* gnc_lookup_date_option *
|
||||
* looks up a date option. If present, returns the absolute date *
|
||||
* represented in the set_ab_value argument provided, otherwise *
|
||||
* copies the default_value argument (if non-NULL) to the *
|
||||
* set_value argument. If the default_value argument is NULL, *
|
||||
* copies the current date to set_ab_value. Whatever value is *
|
||||
* stored in set_value is return as an approximate (no *
|
||||
* nanoseconds) time_t value. set_value may be NULL, in which *
|
||||
* case only the return value can be used. If is_relative is *
|
||||
* non-NULL, it is set to whether the date option is currently *
|
||||
* storing a relative date. If it is, and set_rel_value *
|
||||
* is non-NULL, it returns a newly allocated string *
|
||||
* representing the scheme symbol for that relative date *
|
||||
* *
|
||||
* Args: section - section name of option *
|
||||
* name - name of option *
|
||||
* set_ab_value - location to store absolute option value *
|
||||
* set_rel_value - location to store relative option value *
|
||||
* default - default value if not found *
|
||||
* Return: time_t approximation of set_value *
|
||||
\********************************************************************/
|
||||
time_t
|
||||
gnc_lookup_date_option(const char *section,
|
||||
const char *name,
|
||||
gboolean *is_relative,
|
||||
Timespec *set_ab_value,
|
||||
char **set_rel_value,
|
||||
Timespec *default_value)
|
||||
{
|
||||
return gnc_option_db_lookup_date_option(global_options, section, name,
|
||||
is_relative, set_ab_value,
|
||||
set_rel_value, default_value);
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
* gnc_lookup_number_option *
|
||||
|
||||
@@ -56,6 +56,10 @@ char * gnc_lookup_font_option(const char *section, const char *name,
|
||||
char * gnc_lookup_multichoice_option(const char *section, const char *name,
|
||||
const char *default_value);
|
||||
|
||||
time_t gnc_lookup_date_option(const char *section, const char *name,
|
||||
gboolean *is_relative, Timespec *set_ab_value,
|
||||
char **set_rel_value, Timespec *default_value);
|
||||
|
||||
gdouble gnc_lookup_number_option(const char *section, const char *name,
|
||||
gdouble default_value);
|
||||
|
||||
|
||||
@@ -299,6 +299,19 @@ gnc_ui_account_get_balance (Account *account, gboolean recurse)
|
||||
account, recurse, NULL, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine retrives the total balance in an account converted to
|
||||
* a given currency, possibly including all sub-accounts under the
|
||||
* specified account.
|
||||
*/
|
||||
gnc_numeric
|
||||
gnc_ui_account_get_balance_in_currency (Account *account, gnc_commodity *currency,
|
||||
gboolean recurse)
|
||||
{
|
||||
return gnc_ui_account_get_balance_internal (xaccAccountGetBalanceInCurrency,
|
||||
account, recurse, NULL, currency);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine retrives the reconciled balance in an account,
|
||||
* possibly including all sub-accounts under the specified account.
|
||||
|
||||
@@ -124,6 +124,9 @@ char * gnc_ui_account_get_field_value_string (Account *account,
|
||||
gnc_numeric gnc_ui_account_get_balance (Account *account,
|
||||
gboolean include_children);
|
||||
|
||||
gnc_numeric gnc_ui_account_get_balance_in_currency (Account *account,
|
||||
gnc_commodity *currency,
|
||||
gboolean recurse);
|
||||
/**
|
||||
* This routine retrives the reconciled balance in an account,
|
||||
* possibly including all sub-accounts under the specified account.
|
||||
|
||||
@@ -1465,3 +1465,47 @@
|
||||
(display header port)
|
||||
(display code port)
|
||||
(close port)))))
|
||||
|
||||
(define (gnc:options-make-end-date! options pagename optname sort-tag info)
|
||||
(gnc:register-option
|
||||
options
|
||||
(gnc:make-date-option
|
||||
pagename optname
|
||||
sort-tag info
|
||||
(lambda ()
|
||||
(cons 'relative 'today))
|
||||
#f 'both
|
||||
'(
|
||||
today
|
||||
end-this-month
|
||||
end-prev-month
|
||||
end-current-quarter
|
||||
end-prev-quarter
|
||||
end-cal-year
|
||||
end-prev-year
|
||||
end-cur-fin-year
|
||||
end-prev-fin-year
|
||||
))))
|
||||
|
||||
(define (gnc:options-make-date-interval! options pagename name-from info-from
|
||||
name-to info-to sort-tag)
|
||||
(gnc:register-option
|
||||
options
|
||||
(gnc:make-date-option
|
||||
pagename name-from
|
||||
(string-append sort-tag "a") info-from
|
||||
(lambda () (cons 'relative 'start-cal-year))
|
||||
#f 'both
|
||||
'(
|
||||
today
|
||||
start-this-month
|
||||
start-prev-month
|
||||
start-current-quarter
|
||||
start-prev-quarter
|
||||
start-cal-year
|
||||
start-prev-year
|
||||
start-cur-fin-year
|
||||
start-prev-fin-year
|
||||
)))
|
||||
(gnc:options-make-end-date! options pagename name-to
|
||||
(string-append sort-tag "b") info-to))
|
||||
|
||||
@@ -307,6 +307,26 @@ not each row")
|
||||
#f))
|
||||
|
||||
|
||||
;;; Summarybar Options
|
||||
|
||||
(gnc:register-configuration-option
|
||||
(gnc:make-simple-boolean-option
|
||||
(N_ "Summarybar") (N_ "Show grand total")
|
||||
"a" (N_ "Show a grand total of all accounts converted to the default report currency")
|
||||
#t))
|
||||
|
||||
(gnc:register-configuration-option
|
||||
(gnc:make-simple-boolean-option
|
||||
(N_ "Summarybar") (N_ "Show non currency commodities")
|
||||
"b" (N_ "Show non currency commodities")
|
||||
#t))
|
||||
|
||||
(gnc:options-make-date-interval!
|
||||
gnc:*options-entries* (N_ "Summarybar")
|
||||
(N_ "Start date") (N_ "Start date for profit/loss calculation")
|
||||
(N_ "End date") (N_ "End date for profit/loss and date for net assets calculation")
|
||||
"c")
|
||||
|
||||
;;; Reconcile Options
|
||||
|
||||
(gnc:register-configuration-option
|
||||
|
||||
@@ -1741,6 +1741,36 @@ xaccAccountConvertBalanceToCurrency(Account *account, /* for book */
|
||||
return balance;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a balance from one currency to another with price of
|
||||
* a given date.
|
||||
*/
|
||||
gnc_numeric
|
||||
xaccAccountConvertBalanceToCurrencyAsOfDate(Account *account, /* for book */
|
||||
gnc_numeric balance,
|
||||
gnc_commodity *balance_currency,
|
||||
gnc_commodity *new_currency,
|
||||
time_t date)
|
||||
{
|
||||
QofBook *book;
|
||||
GNCPriceDB *pdb;
|
||||
Timespec ts;
|
||||
|
||||
if (gnc_numeric_zero_p (balance) ||
|
||||
gnc_commodity_equiv (balance_currency, new_currency))
|
||||
return balance;
|
||||
|
||||
book = xaccGroupGetBook (xaccAccountGetRoot (account));
|
||||
pdb = gnc_book_get_pricedb (book);
|
||||
|
||||
ts.tv_sec = date;
|
||||
ts.tv_nsec = 0;
|
||||
|
||||
balance = gnc_pricedb_convert_balance_nearest_price(pdb, balance, balance_currency, new_currency, ts);
|
||||
|
||||
return balance;
|
||||
}
|
||||
|
||||
/*
|
||||
* Given an account and a GetBalanceFn pointer, extract the requested
|
||||
* balance from the account and then convert it to the desired
|
||||
|
||||
@@ -337,6 +337,12 @@ gnc_numeric xaccAccountConvertBalanceToCurrency(Account *account, /* for book */
|
||||
gnc_numeric balance,
|
||||
gnc_commodity *balance_currency,
|
||||
gnc_commodity *new_currency);
|
||||
gnc_numeric xaccAccountConvertBalanceToCurrencyAsOfDate(Account *account, /* for book */
|
||||
gnc_numeric balance,
|
||||
gnc_commodity *balance_currency,
|
||||
gnc_commodity *new_currency,
|
||||
time_t date);
|
||||
|
||||
gnc_numeric xaccAccountGetBalanceInCurrency (Account *account,
|
||||
gnc_commodity *report_commodity,
|
||||
gboolean include_children);
|
||||
|
||||
@@ -48,6 +48,7 @@ typedef struct {
|
||||
GtkWidget * totals_combo;
|
||||
GList * totals_list;
|
||||
int component_id;
|
||||
SCM callback_id;
|
||||
} GNCMainSummary;
|
||||
|
||||
#define WINDOW_SUMMARYBAR_CM_CLASS "summary-bar"
|
||||
@@ -63,6 +64,7 @@ typedef struct {
|
||||
gnc_commodity * currency;
|
||||
gnc_numeric assets;
|
||||
gnc_numeric profits;
|
||||
gint total_mode;
|
||||
} GNCCurrencyAcc;
|
||||
|
||||
|
||||
@@ -70,7 +72,8 @@ typedef struct {
|
||||
*
|
||||
* This is maintained for the duration, where there is one per
|
||||
* currency, plus (eventually) one for the default currency
|
||||
* accumulation (like the EURO). */
|
||||
* accumulation (like the EURO) or grand total or non currency
|
||||
* commodities total. */
|
||||
|
||||
typedef struct {
|
||||
char *namespace;
|
||||
@@ -79,9 +82,30 @@ typedef struct {
|
||||
GtkWidget *assets_label;
|
||||
GtkWidget *profits_label;
|
||||
gint touched : 1;
|
||||
gint total_mode;
|
||||
} GNCCurrencyItem;
|
||||
|
||||
|
||||
/* defines for total_mode in GNCCurrencyAcc and GNCCurrencyItem */
|
||||
|
||||
#define TOTAL_SINGLE 0
|
||||
#define TOTAL_CURR_TOTAL 1
|
||||
#define TOTAL_NON_CURR_TOTAL 2
|
||||
#define TOTAL_GRAND_TOTAL 3
|
||||
|
||||
|
||||
/* options for summarybar */
|
||||
|
||||
typedef struct {
|
||||
gnc_commodity *default_currency;
|
||||
gboolean euro;
|
||||
gboolean grand_total;
|
||||
gboolean non_currency;
|
||||
time_t start_date;
|
||||
time_t end_date;
|
||||
} GNCSummarybarOptions;
|
||||
|
||||
|
||||
/* Build a single currency item.
|
||||
*
|
||||
* This function handles the building of a single currency item for
|
||||
@@ -89,7 +113,7 @@ typedef struct {
|
||||
* but now only handles a single currency. */
|
||||
|
||||
static GNCCurrencyItem *
|
||||
gnc_ui_build_currency_item(gnc_commodity * currency)
|
||||
gnc_ui_build_currency_item(gnc_commodity * currency, gint total_mode)
|
||||
{
|
||||
GtkWidget *label;
|
||||
GtkWidget *topbox;
|
||||
@@ -107,6 +131,8 @@ gnc_ui_build_currency_item(gnc_commodity * currency)
|
||||
item->namespace = g_strdup (gnc_commodity_get_namespace (currency));
|
||||
item->mnemonic = g_strdup (gnc_commodity_get_mnemonic (currency));
|
||||
|
||||
item->total_mode = total_mode;
|
||||
|
||||
listitem = gtk_list_item_new();
|
||||
item->listitem = listitem;
|
||||
|
||||
@@ -126,8 +152,26 @@ gnc_ui_build_currency_item(gnc_commodity * currency)
|
||||
gtk_widget_show(hbox);
|
||||
gtk_box_pack_start(GTK_BOX(topbox), hbox, FALSE, FALSE, 5);
|
||||
|
||||
label_str = g_strdup_printf ("%s (%s):", _("Net Assets"),
|
||||
mnemonic ? mnemonic : "");
|
||||
switch(total_mode)
|
||||
{
|
||||
case TOTAL_CURR_TOTAL:
|
||||
label_str = g_strdup_printf ("%s (%s):", _("Net Assets total"),
|
||||
mnemonic ? mnemonic : "");
|
||||
break;
|
||||
case TOTAL_NON_CURR_TOTAL:
|
||||
label_str = g_strdup_printf ("%s (%s):", _("Net Assets non currency commodities total"),
|
||||
mnemonic ? mnemonic : "");
|
||||
break;
|
||||
case TOTAL_GRAND_TOTAL:
|
||||
label_str = g_strdup_printf ("%s (%s):", _("Net Assets grand total"),
|
||||
mnemonic ? mnemonic : "");
|
||||
break;
|
||||
case TOTAL_SINGLE:
|
||||
default:
|
||||
label_str = g_strdup_printf ("%s (%s):", _("Net Assets"),
|
||||
mnemonic ? mnemonic : "");
|
||||
break;
|
||||
}
|
||||
label = gtk_label_new(label_str);
|
||||
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
|
||||
gtk_widget_show(label);
|
||||
@@ -144,8 +188,26 @@ gnc_ui_build_currency_item(gnc_commodity * currency)
|
||||
gtk_widget_show(hbox);
|
||||
gtk_box_pack_start(GTK_BOX(topbox), hbox, FALSE, FALSE, 5);
|
||||
|
||||
label_str = g_strdup_printf ("%s (%s):", _("Profits"),
|
||||
mnemonic ? mnemonic : "");
|
||||
switch(total_mode)
|
||||
{
|
||||
case TOTAL_CURR_TOTAL:
|
||||
label_str = g_strdup_printf ("%s (%s):", _("Profits total"),
|
||||
mnemonic ? mnemonic : "");
|
||||
break;
|
||||
case TOTAL_NON_CURR_TOTAL:
|
||||
label_str = g_strdup_printf ("%s (%s):", _("Profits non currency commodities total"),
|
||||
mnemonic ? mnemonic : "");
|
||||
break;
|
||||
case TOTAL_GRAND_TOTAL:
|
||||
label_str = g_strdup_printf ("%s (%s):", _("Profits grand total"),
|
||||
mnemonic ? mnemonic : "");
|
||||
break;
|
||||
case TOTAL_SINGLE:
|
||||
default:
|
||||
label_str = g_strdup_printf ("%s (%s):", _("Profits"),
|
||||
mnemonic ? mnemonic : "");
|
||||
break;
|
||||
}
|
||||
label = gtk_label_new(label_str);
|
||||
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
|
||||
gtk_widget_show(label);
|
||||
@@ -182,7 +244,8 @@ gnc_ui_currency_item_destroy (GNCCurrencyItem *item)
|
||||
* This will search the given list, and if no accumulator is found,
|
||||
* will allocate a fresh one. */
|
||||
static GNCCurrencyAcc *
|
||||
gnc_ui_get_currency_accumulator(GList **list, gnc_commodity * currency)
|
||||
gnc_ui_get_currency_accumulator(GList **list, gnc_commodity * currency,
|
||||
gint total_mode)
|
||||
{
|
||||
GList *current;
|
||||
GNCCurrencyAcc *found;
|
||||
@@ -190,7 +253,8 @@ gnc_ui_get_currency_accumulator(GList **list, gnc_commodity * currency)
|
||||
for (current = g_list_first(*list); current;
|
||||
current = g_list_next(current)) {
|
||||
found = current->data;
|
||||
if (gnc_commodity_equiv(currency, found->currency)) {
|
||||
if ((gnc_commodity_equiv(currency, found->currency)) &&
|
||||
(found->total_mode == total_mode)) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
@@ -199,6 +263,7 @@ gnc_ui_get_currency_accumulator(GList **list, gnc_commodity * currency)
|
||||
found->currency = currency;
|
||||
found->assets = gnc_numeric_zero ();
|
||||
found->profits = gnc_numeric_zero ();
|
||||
found->total_mode = total_mode;
|
||||
*list = g_list_append (*list, found);
|
||||
|
||||
return found;
|
||||
@@ -206,7 +271,8 @@ gnc_ui_get_currency_accumulator(GList **list, gnc_commodity * currency)
|
||||
|
||||
static gboolean
|
||||
gnc_ui_currency_item_match (const GNCCurrencyItem *item,
|
||||
const gnc_commodity *commodity)
|
||||
const gnc_commodity *commodity,
|
||||
gint total_mode)
|
||||
{
|
||||
if (!item || !commodity) return FALSE;
|
||||
|
||||
@@ -214,7 +280,8 @@ gnc_ui_currency_item_match (const GNCCurrencyItem *item,
|
||||
(safe_strcmp (item->namespace,
|
||||
gnc_commodity_get_namespace (commodity)) == 0) &&
|
||||
(safe_strcmp (item->mnemonic,
|
||||
gnc_commodity_get_mnemonic (commodity)) == 0);
|
||||
gnc_commodity_get_mnemonic (commodity)) == 0) &&
|
||||
(item->total_mode == total_mode);
|
||||
|
||||
}
|
||||
|
||||
@@ -229,6 +296,7 @@ gnc_ui_currency_item_match (const GNCCurrencyItem *item,
|
||||
static GNCCurrencyItem *
|
||||
gnc_ui_get_currency_item (GList **list,
|
||||
gnc_commodity * currency,
|
||||
gint total_mode,
|
||||
GtkWidget *holder)
|
||||
{
|
||||
GList *current;
|
||||
@@ -239,11 +307,11 @@ gnc_ui_get_currency_item (GList **list,
|
||||
{
|
||||
found = current->data;
|
||||
|
||||
if (gnc_ui_currency_item_match (found, currency))
|
||||
if (gnc_ui_currency_item_match (found, currency, total_mode))
|
||||
return found;
|
||||
}
|
||||
|
||||
found = gnc_ui_build_currency_item(currency);
|
||||
found = gnc_ui_build_currency_item(currency, total_mode);
|
||||
*list = g_list_append(*list, found);
|
||||
|
||||
current = g_list_append(NULL, found->listitem);
|
||||
@@ -254,29 +322,24 @@ gnc_ui_get_currency_item (GList **list,
|
||||
|
||||
static void
|
||||
gnc_ui_accounts_recurse (AccountGroup *group, GList **currency_list,
|
||||
gboolean euro)
|
||||
GNCSummarybarOptions options)
|
||||
{
|
||||
gnc_numeric amount;
|
||||
gnc_numeric start_amount;
|
||||
gnc_numeric start_amount_default_currency;
|
||||
gnc_numeric end_amount;
|
||||
gnc_numeric end_amount_default_currency;
|
||||
AccountGroup *children;
|
||||
GNCAccountType account_type;
|
||||
gnc_commodity * account_currency;
|
||||
gnc_commodity * default_currency;
|
||||
gnc_commodity * euro_commodity;
|
||||
GNCCurrencyAcc *currency_accum;
|
||||
GNCCurrencyAcc *currency_accum = NULL;
|
||||
GNCCurrencyAcc *euro_accum = NULL;
|
||||
GNCCurrencyAcc *grand_total_accum = NULL;
|
||||
GNCCurrencyAcc *non_curr_accum = NULL;
|
||||
GList *list;
|
||||
GList *node;
|
||||
gboolean non_currency = FALSE;
|
||||
|
||||
default_currency = gnc_default_currency ();
|
||||
|
||||
if (euro)
|
||||
{
|
||||
euro_commodity = gnc_get_euro ();
|
||||
euro_accum = gnc_ui_get_currency_accumulator(currency_list,
|
||||
euro_commodity);
|
||||
}
|
||||
else
|
||||
euro_commodity = NULL;
|
||||
|
||||
list = xaccGroupGetAccountList (group);
|
||||
for (node = list; node; node = node->next)
|
||||
@@ -286,8 +349,35 @@ gnc_ui_accounts_recurse (AccountGroup *group, GList **currency_list,
|
||||
account_type = xaccAccountGetType(account);
|
||||
account_currency = xaccAccountGetCommodity(account);
|
||||
children = xaccAccountGetChildren(account);
|
||||
currency_accum = gnc_ui_get_currency_accumulator(currency_list,
|
||||
account_currency);
|
||||
|
||||
if(options.grand_total)
|
||||
grand_total_accum = gnc_ui_get_currency_accumulator(currency_list,
|
||||
options.default_currency,
|
||||
TOTAL_GRAND_TOTAL);
|
||||
|
||||
if (options.euro)
|
||||
{
|
||||
euro_commodity = gnc_get_euro ();
|
||||
euro_accum = gnc_ui_get_currency_accumulator(currency_list,
|
||||
euro_commodity,
|
||||
TOTAL_CURR_TOTAL);
|
||||
}
|
||||
else
|
||||
euro_commodity = NULL;
|
||||
|
||||
if(safe_strcmp(gnc_commodity_get_namespace(account_currency),
|
||||
GNC_COMMODITY_NS_ISO) != 0) {
|
||||
non_currency = TRUE;
|
||||
non_curr_accum = gnc_ui_get_currency_accumulator(currency_list,
|
||||
options.default_currency,
|
||||
TOTAL_NON_CURR_TOTAL);
|
||||
}
|
||||
|
||||
if(!non_currency || options.non_currency) {
|
||||
currency_accum = gnc_ui_get_currency_accumulator(currency_list,
|
||||
account_currency,
|
||||
TOTAL_SINGLE);
|
||||
}
|
||||
|
||||
switch (account_type)
|
||||
{
|
||||
@@ -300,47 +390,104 @@ gnc_ui_accounts_recurse (AccountGroup *group, GList **currency_list,
|
||||
case LIABILITY:
|
||||
case PAYABLE:
|
||||
case RECEIVABLE:
|
||||
amount = gnc_ui_account_get_balance (account, FALSE);
|
||||
/* unreverse sign */
|
||||
if (gnc_reverse_balance (account))
|
||||
amount = gnc_numeric_neg (amount);
|
||||
end_amount = xaccAccountGetBalanceAsOfDate(account, options.end_date);
|
||||
end_amount_default_currency = xaccAccountConvertBalanceToCurrencyAsOfDate
|
||||
(account, end_amount, account_currency, options.default_currency,
|
||||
options.end_date);
|
||||
|
||||
currency_accum->assets =
|
||||
gnc_numeric_add (currency_accum->assets, amount,
|
||||
gnc_commodity_get_fraction (account_currency),
|
||||
GNC_RND_ROUND);
|
||||
if(!non_currency || options.non_currency) {
|
||||
currency_accum->assets =
|
||||
gnc_numeric_add (currency_accum->assets, end_amount,
|
||||
gnc_commodity_get_fraction (account_currency),
|
||||
GNC_RND_ROUND);
|
||||
}
|
||||
|
||||
if (euro && (currency_accum != euro_accum))
|
||||
if(non_currency) {
|
||||
non_curr_accum->assets =
|
||||
gnc_numeric_add (non_curr_accum->assets, end_amount_default_currency,
|
||||
gnc_commodity_get_fraction (options.default_currency),
|
||||
GNC_RND_ROUND);
|
||||
}
|
||||
|
||||
if(options.grand_total) {
|
||||
grand_total_accum->assets =
|
||||
gnc_numeric_add (grand_total_accum->assets, end_amount_default_currency,
|
||||
gnc_commodity_get_fraction (options.default_currency),
|
||||
GNC_RND_ROUND);
|
||||
}
|
||||
|
||||
if (options.euro && (currency_accum != euro_accum)) {
|
||||
euro_accum->assets =
|
||||
gnc_numeric_add (euro_accum->assets,
|
||||
gnc_convert_to_euro(account_currency, amount),
|
||||
gnc_convert_to_euro(account_currency, end_amount),
|
||||
gnc_commodity_get_fraction (euro_commodity),
|
||||
GNC_RND_ROUND);
|
||||
}
|
||||
|
||||
if (children != NULL)
|
||||
gnc_ui_accounts_recurse(children, currency_list, euro);
|
||||
gnc_ui_accounts_recurse(children, currency_list, options);
|
||||
break;
|
||||
case INCOME:
|
||||
case EXPENSE:
|
||||
amount = gnc_ui_account_get_balance (account, FALSE);
|
||||
/* unreverse sign */
|
||||
if (gnc_reverse_balance (account))
|
||||
amount = gnc_numeric_neg (amount);
|
||||
start_amount = xaccAccountGetBalanceAsOfDate(account, options.start_date);
|
||||
start_amount_default_currency = xaccAccountConvertBalanceToCurrencyAsOfDate
|
||||
(account, start_amount, account_currency, options.default_currency,
|
||||
options.start_date);
|
||||
end_amount = xaccAccountGetBalanceAsOfDate(account, options.end_date);
|
||||
end_amount_default_currency = xaccAccountConvertBalanceToCurrencyAsOfDate
|
||||
(account, end_amount, account_currency, options.default_currency,
|
||||
options.end_date);
|
||||
|
||||
currency_accum->profits =
|
||||
gnc_numeric_sub (currency_accum->profits, amount,
|
||||
gnc_commodity_get_fraction (account_currency),
|
||||
GNC_RND_ROUND);
|
||||
if(!non_currency || options.non_currency) {
|
||||
currency_accum->profits =
|
||||
gnc_numeric_add (currency_accum->profits, start_amount,
|
||||
gnc_commodity_get_fraction (account_currency),
|
||||
GNC_RND_ROUND);
|
||||
currency_accum->profits =
|
||||
gnc_numeric_sub (currency_accum->profits, end_amount,
|
||||
gnc_commodity_get_fraction (account_currency),
|
||||
GNC_RND_ROUND);
|
||||
}
|
||||
|
||||
if (euro && (currency_accum != euro_accum))
|
||||
euro_accum->profits =
|
||||
gnc_numeric_sub (euro_accum->profits,
|
||||
gnc_convert_to_euro(account_currency, amount),
|
||||
if(non_currency) {
|
||||
non_curr_accum->profits =
|
||||
gnc_numeric_add (non_curr_accum->profits, start_amount_default_currency,
|
||||
gnc_commodity_get_fraction (options.default_currency),
|
||||
GNC_RND_ROUND);
|
||||
non_curr_accum->profits =
|
||||
gnc_numeric_sub (non_curr_accum->profits, end_amount_default_currency,
|
||||
gnc_commodity_get_fraction (options.default_currency),
|
||||
GNC_RND_ROUND);
|
||||
}
|
||||
|
||||
if(options.grand_total) {
|
||||
grand_total_accum->profits =
|
||||
gnc_numeric_add (grand_total_accum->profits,
|
||||
start_amount_default_currency,
|
||||
gnc_commodity_get_fraction (options.default_currency),
|
||||
GNC_RND_ROUND);
|
||||
grand_total_accum->profits =
|
||||
gnc_numeric_sub (grand_total_accum->profits,
|
||||
end_amount_default_currency,
|
||||
gnc_commodity_get_fraction (options.default_currency),
|
||||
GNC_RND_ROUND);
|
||||
}
|
||||
|
||||
if (options.euro && (currency_accum != euro_accum)) {
|
||||
euro_accum->profits =
|
||||
gnc_numeric_add (euro_accum->profits,
|
||||
gnc_convert_to_euro(account_currency, start_amount),
|
||||
gnc_commodity_get_fraction (euro_commodity),
|
||||
GNC_RND_ROUND);
|
||||
euro_accum->profits =
|
||||
gnc_numeric_sub (euro_accum->profits,
|
||||
gnc_convert_to_euro(account_currency, end_amount),
|
||||
gnc_commodity_get_fraction (euro_commodity),
|
||||
GNC_RND_ROUND);
|
||||
}
|
||||
|
||||
if (children != NULL)
|
||||
gnc_ui_accounts_recurse(children, currency_list, euro);
|
||||
gnc_ui_accounts_recurse(children, currency_list, options);
|
||||
break;
|
||||
case EQUITY:
|
||||
/* no-op, see comments at top about summing assets */
|
||||
@@ -365,8 +512,9 @@ gnc_ui_accounts_recurse (AccountGroup *group, GList **currency_list,
|
||||
* EUR amounts and a EUR (total) line which summs up all EURO
|
||||
* member currencies.
|
||||
*
|
||||
* There should be a 'grand total', too, which sums up all accounts
|
||||
* converted to one common currency. */
|
||||
* There can be a 'grand total', too, which sums up all accounts
|
||||
* converted to one common currency and a total of all non
|
||||
* currency commodities (e.g. stock, funds). */
|
||||
|
||||
static void
|
||||
gnc_main_window_summary_refresh (GNCMainSummary * summary)
|
||||
@@ -374,26 +522,44 @@ gnc_main_window_summary_refresh (GNCMainSummary * summary)
|
||||
AccountGroup *group;
|
||||
char asset_string[256];
|
||||
char profit_string[256];
|
||||
gnc_commodity * default_currency;
|
||||
GNCCurrencyAcc *currency_accum;
|
||||
GNCCurrencyItem *currency_item;
|
||||
GList *currency_list;
|
||||
GList *current;
|
||||
gboolean euro;
|
||||
GNCSummarybarOptions options;
|
||||
|
||||
default_currency = gnc_default_currency ();
|
||||
|
||||
euro = gnc_lookup_boolean_option("International",
|
||||
"Enable EURO support",
|
||||
FALSE);
|
||||
options.default_currency = gnc_default_report_currency ();
|
||||
|
||||
options.euro = gnc_lookup_boolean_option("International",
|
||||
"Enable EURO support",
|
||||
FALSE);
|
||||
options.grand_total = gnc_lookup_boolean_option("Summarybar",
|
||||
"Show grand total",
|
||||
TRUE);
|
||||
options.non_currency = gnc_lookup_boolean_option("Summarybar",
|
||||
"Show non currency commodities",
|
||||
TRUE);
|
||||
/* we will need the balance of the last transaction before the start
|
||||
date, so subtract 1 from start date */
|
||||
options.start_date = gnc_lookup_date_option("Summarybar", "Start date", NULL,
|
||||
NULL, NULL, NULL) - 1;
|
||||
options.end_date = gnc_lookup_date_option("Summarybar", "End date", NULL,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
currency_list = NULL;
|
||||
|
||||
/* grand total should be first in the list */
|
||||
if(options.grand_total) {
|
||||
gnc_ui_get_currency_accumulator (¤cy_list, options.default_currency,
|
||||
TOTAL_GRAND_TOTAL);
|
||||
}
|
||||
/* Make sure there's at least one accumulator in the list. */
|
||||
gnc_ui_get_currency_accumulator (¤cy_list, default_currency);
|
||||
gnc_ui_get_currency_accumulator (¤cy_list, options.default_currency,
|
||||
TOTAL_SINGLE);
|
||||
|
||||
group = gnc_get_current_group ();
|
||||
gnc_ui_accounts_recurse(group, ¤cy_list, euro);
|
||||
gnc_ui_accounts_recurse(group, ¤cy_list, options);
|
||||
|
||||
for (current = g_list_first(summary->totals_list); current;
|
||||
current = g_list_next(current)) {
|
||||
@@ -406,6 +572,7 @@ gnc_main_window_summary_refresh (GNCMainSummary * summary)
|
||||
currency_accum = current->data;
|
||||
currency_item = gnc_ui_get_currency_item(&summary->totals_list,
|
||||
currency_accum->currency,
|
||||
currency_accum->total_mode,
|
||||
summary->totals_combo);
|
||||
currency_item->touched = 1;
|
||||
|
||||
@@ -434,7 +601,8 @@ gnc_main_window_summary_refresh (GNCMainSummary * summary)
|
||||
|
||||
currency_item = current->data;
|
||||
if (currency_item->touched == 0 &&
|
||||
!gnc_ui_currency_item_match(currency_item, default_currency)) {
|
||||
!gnc_ui_currency_item_match(currency_item, options.default_currency,
|
||||
TOTAL_SINGLE)) {
|
||||
currency_list = g_list_prepend(currency_list, currency_item->listitem);
|
||||
summary->totals_list = g_list_remove_link(summary->totals_list,
|
||||
current);
|
||||
@@ -456,6 +624,7 @@ gnc_main_window_summary_refresh (GNCMainSummary * summary)
|
||||
static void
|
||||
gnc_main_window_summary_destroy_cb(GtkObject * obj, gpointer data) {
|
||||
GNCMainSummary * summary = data;
|
||||
gnc_unregister_option_change_callback_id(summary->callback_id);
|
||||
gnc_unregister_gui_component(summary->component_id);
|
||||
g_list_free(summary->totals_list);
|
||||
g_free(summary);
|
||||
@@ -467,11 +636,17 @@ summarybar_refresh_handler(GHashTable * changes, gpointer user_data) {
|
||||
gnc_main_window_summary_refresh(summary);
|
||||
}
|
||||
|
||||
static void
|
||||
summarybar_option_change_handler(gpointer user_data) {
|
||||
GNCMainSummary * summary = user_data;
|
||||
gnc_main_window_summary_refresh(summary);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
gnc_main_window_summary_new (void) {
|
||||
GNCMainSummary * retval = g_new0(GNCMainSummary, 1);
|
||||
GNCCurrencyItem * def_item;
|
||||
gnc_commodity * default_currency = gnc_default_currency ();
|
||||
gnc_commodity * default_currency = gnc_default_report_currency ();
|
||||
|
||||
retval->hbox = gtk_hbox_new (FALSE, 5);
|
||||
retval->totals_combo = gtk_select_new ();
|
||||
@@ -479,12 +654,17 @@ gnc_main_window_summary_new (void) {
|
||||
retval->component_id = gnc_register_gui_component(WINDOW_SUMMARYBAR_CM_CLASS,
|
||||
summarybar_refresh_handler,
|
||||
NULL, retval);
|
||||
retval->callback_id = gnc_register_option_change_callback(summarybar_option_change_handler,
|
||||
retval,
|
||||
"Summarybar",
|
||||
NULL);
|
||||
gnc_gui_component_watch_entity_type (retval->component_id,
|
||||
GNC_ID_ACCOUNT,
|
||||
GNC_EVENT_MODIFY | GNC_EVENT_DESTROY);
|
||||
|
||||
def_item = gnc_ui_get_currency_item (&retval->totals_list,
|
||||
default_currency,
|
||||
TOTAL_SINGLE,
|
||||
retval->totals_combo);
|
||||
|
||||
|
||||
|
||||
@@ -28,68 +28,16 @@
|
||||
;; This is one single end-date of a report.
|
||||
(define (gnc:options-add-report-date!
|
||||
options pagename optname sort-tag)
|
||||
(gnc:register-option
|
||||
options
|
||||
(gnc:make-date-option
|
||||
pagename optname
|
||||
sort-tag (N_ "Select a date to report on")
|
||||
(lambda ()
|
||||
(cons 'relative 'today))
|
||||
#f 'both
|
||||
'(
|
||||
today
|
||||
end-this-month
|
||||
end-prev-month
|
||||
end-current-quarter
|
||||
end-prev-quarter
|
||||
end-cal-year
|
||||
end-prev-year
|
||||
end-cur-fin-year
|
||||
end-prev-fin-year
|
||||
))))
|
||||
|
||||
(gnc:options-make-end-date! options pagename optname sort-tag
|
||||
(N_ "Select a date to report on")))
|
||||
|
||||
;; This is a date-interval for a report.
|
||||
(define (gnc:options-add-date-interval!
|
||||
options pagename name-from name-to sort-tag)
|
||||
(gnc:register-option
|
||||
options
|
||||
(gnc:make-date-option
|
||||
pagename name-from
|
||||
(string-append sort-tag "a")
|
||||
(N_ "Start of reporting period")
|
||||
(lambda () (cons 'relative 'start-cal-year))
|
||||
#f 'both
|
||||
'(
|
||||
today
|
||||
start-this-month
|
||||
start-prev-month
|
||||
start-current-quarter
|
||||
start-prev-quarter
|
||||
start-cal-year
|
||||
start-prev-year
|
||||
start-cur-fin-year
|
||||
start-prev-fin-year
|
||||
)))
|
||||
(gnc:register-option
|
||||
options
|
||||
(gnc:make-date-option
|
||||
pagename name-to
|
||||
(string-append sort-tag "b")
|
||||
(N_ "End of reporting period")
|
||||
(lambda () (cons 'relative 'today))
|
||||
#f 'both
|
||||
'(
|
||||
today
|
||||
end-this-month
|
||||
end-prev-month
|
||||
end-current-quarter
|
||||
end-prev-quarter
|
||||
end-cal-year
|
||||
end-prev-year
|
||||
end-cur-fin-year
|
||||
end-prev-fin-year
|
||||
))))
|
||||
(gnc:options-make-date-interval! options pagename
|
||||
name-from (N_ "Start of reporting period")
|
||||
name-to (N_ "End of reporting period")
|
||||
sort-tag))
|
||||
|
||||
;; A date interval multichoice option.
|
||||
(define (gnc:options-add-interval-choice!
|
||||
|
||||
Reference in New Issue
Block a user