r21216 - gnucash/trunk - Move ui related balance calculation functions to separate file
Geert Janssens
gjanssens at code.gnucash.org
Tue Aug 23 17:20:27 EDT 2011
Author: gjanssens
Date: 2011-08-23 17:20:27 -0400 (Tue, 23 Aug 2011)
New Revision: 21216
Trac: http://svn.gnucash.org/trac/changeset/21216
Added:
gnucash/trunk/src/app-utils/gnc-ui-balances.c
gnucash/trunk/src/app-utils/gnc-ui-balances.h
Modified:
gnucash/trunk/po/POTFILES.in
gnucash/trunk/src/app-utils/Makefile.am
gnucash/trunk/src/app-utils/gnc-ui-util.c
gnucash/trunk/src/app-utils/gnc-ui-util.h
gnucash/trunk/src/gnome-utils/gnc-tree-model-account.c
gnucash/trunk/src/gnome-utils/gnc-tree-model-owner.c
gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c
gnucash/trunk/src/gnome-utils/gnc-tree-view-owner.c
gnucash/trunk/src/gnome/window-reconcile.c
Log:
Move ui related balance calculation functions to separate file
Modified: gnucash/trunk/po/POTFILES.in
===================================================================
--- gnucash/trunk/po/POTFILES.in 2011-08-23 21:20:15 UTC (rev 21215)
+++ gnucash/trunk/po/POTFILES.in 2011-08-23 21:20:27 UTC (rev 21216)
@@ -23,6 +23,7 @@
src/app-utils/gnc-help-utils.c
src/app-utils/gncmod-app-utils.c
src/app-utils/gnc-sx-instance-model.c
+src/app-utils/gnc-ui-balances.c
src/app-utils/gnc-ui-util.c
src/app-utils/guile-util.c
src/app-utils/option-util.c
Modified: gnucash/trunk/src/app-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/app-utils/Makefile.am 2011-08-23 21:20:15 UTC (rev 21215)
+++ gnucash/trunk/src/app-utils/Makefile.am 2011-08-23 21:20:27 UTC (rev 21216)
@@ -59,6 +59,7 @@
gnc-helpers.c \
gnc-sx-instance-model.c \
gncmod-app-utils.c \
+ gnc-ui-balances.c \
gnc-ui-util.c \
guile-util.c \
option-util.c
@@ -89,6 +90,7 @@
gnc-help-utils.h \
gnc-helpers.h \
gnc-sx-instance-model.h \
+ gnc-ui-balances.h \
gnc-ui-util.h \
guile-util.h \
option-util.h
Added: gnucash/trunk/src/app-utils/gnc-ui-balances.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-balances.c (rev 0)
+++ gnucash/trunk/src/app-utils/gnc-ui-balances.c 2011-08-23 21:20:27 UTC (rev 21216)
@@ -0,0 +1,319 @@
+/********************************************************************\
+ * gnc-ui-balances.c -- utility functions for calculating *
+ * account and owner balances used in the *
+ * the GnuCash UI *
+ * Copyright (C) 2000 Dave Peticolas <dave at krondo.com> *
+ * Copyright (C) 2011 Geert Janssens <geert at kobaltwit.be> *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License as *
+ * published by the Free Software Foundation; either version 2 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact: *
+ * *
+ * Free Software Foundation Voice: +1-617-542-5942 *
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
+ * Boston, MA 02110-1301, USA gnu at gnu.org *
+\********************************************************************/
+
+#include "config.h"
+
+#include "gnc-ui-balances.h"
+#include "gnc-ui-util.h"
+
+#include <glib.h>
+
+#include "Account.h"
+#include "gncOwner.h"
+#include "qof.h"
+
+static QofLogModule log_module = GNC_MOD_GUI;
+
+/********************************************************************
+ * Balance calculations related to accounts
+ ********************************************************************/
+
+/*
+ * This is a wrapper routine around an xaccGetBalanceInCurrency
+ * function that handles additional needs of the gui.
+ *
+ * @param fn The underlying function in Account.c to call to retrieve
+ * a specific balance from the account.
+ * @param account The account to retrieve data about.
+ * @param recurse Include all sub-accounts of this account.
+ * @param negative An indication of whether or not the returned value
+ * is negative. This can be used by the caller to
+ * easily decode whether or not to color the output.
+ * @param commodity The commodity in which the account balance should
+ * be returned. If NULL, the value will be returned in
+ * the commodity of the account. This is normally used
+ * to specify a currency, which forces the conversion
+ * of things like stock account values from share
+ * values to an amount the requested currency.
+ */
+gnc_numeric
+gnc_ui_account_get_balance_full (xaccGetBalanceInCurrencyFn fn,
+ const Account *account,
+ gboolean recurse,
+ gboolean *negative,
+ const gnc_commodity *commodity)
+{
+ gnc_numeric balance;
+
+ balance = fn(account, commodity, recurse);
+
+ /* reverse sign if needed */
+ if (gnc_reverse_balance (account))
+ balance = gnc_numeric_neg (balance);
+
+ /* Record whether the balance is negative. */
+ if (negative)
+ *negative = gnc_numeric_negative_p(balance);
+
+ return balance;
+}
+
+/*
+ * This routine retrieves the total balance in an account, possibly
+ * including all sub-accounts under the specified account.
+ */
+gnc_numeric
+gnc_ui_account_get_balance (const Account *account, gboolean recurse)
+{
+ return gnc_ui_account_get_balance_full (xaccAccountGetBalanceInCurrency,
+ account, recurse, NULL, NULL);
+}
+
+/*
+ * This routine retrieves 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 (const Account *account,
+ const gnc_commodity *currency,
+ gboolean recurse)
+{
+ return gnc_ui_account_get_balance_full (xaccAccountGetBalanceInCurrency,
+ account, recurse, NULL, currency);
+}
+
+/*
+ * This routine retrieves the reconciled balance in an account,
+ * possibly including all sub-accounts under the specified account.
+ */
+gnc_numeric
+gnc_ui_account_get_reconciled_balance (const Account *account,
+ gboolean recurse)
+{
+ return gnc_ui_account_get_balance_full (xaccAccountGetReconciledBalanceInCurrency,
+ account, recurse, NULL, NULL);
+}
+
+
+/**
+ * Wrapper around gnc_ui_account_get_balance_full that converts
+ * the resulting number to a character string. The number is
+ * formatted according to the specification of the account currency.
+ * The caller is responsible for g_free'ing the returned memory.
+ *
+ * @param fn The underlying function in Account.c to call to retrieve
+ * a specific balance from the account.
+ * @param account The account to retrieve data about.
+ * @param recurse Include all sub-accounts of this account.
+ * @param negative An indication of whether or not the returned value
+ * is negative. This can be used by the caller to
+ * easily decode whether or not to color the output.
+ */
+gchar *
+gnc_ui_account_get_print_balance (xaccGetBalanceInCurrencyFn fn,
+ const Account *account,
+ gboolean recurse,
+ gboolean *negative)
+{
+ GNCPrintAmountInfo print_info;
+ gnc_numeric balance;
+
+ balance = gnc_ui_account_get_balance_full(fn, account, recurse,
+ negative, NULL);
+ print_info = gnc_account_print_info(account, TRUE);
+ return g_strdup(xaccPrintAmount(balance, print_info));
+}
+
+
+/**
+ * Wrapper around gnc_ui_account_get_balance_full that converts
+ * the resulting number to a character string. The number is
+ * formatted according to the specification of the default reporting
+ * currency.
+ *
+ * @param fn The underlying function in Account.c to call to retrieve
+ * a specific balance from the account.
+ * @param account The account to retrieve data about.
+ * @param recurse Include all sub-accounts of this account.
+ * @param negative An indication of whether or not the returned value
+ * is negative. This can be used by the caller to
+ * easily decode whether or not to color the output.
+ */
+gchar *
+gnc_ui_account_get_print_report_balance (xaccGetBalanceInCurrencyFn fn,
+ const Account *account,
+ gboolean recurse,
+ gboolean *negative)
+{
+ GNCPrintAmountInfo print_info;
+ gnc_numeric balance;
+ gnc_commodity *report_commodity;
+
+ report_commodity = gnc_default_report_currency();
+ balance = gnc_ui_account_get_balance_full(fn, account, recurse,
+ negative, report_commodity);
+ print_info = gnc_commodity_print_info(report_commodity, TRUE);
+ return g_strdup(xaccPrintAmount(balance, print_info));
+}
+
+
+gnc_numeric
+gnc_ui_account_get_balance_as_of_date (Account *account,
+ time_t date,
+ gboolean include_children)
+{
+ gnc_numeric balance;
+ gnc_commodity *currency;
+
+ if (account == NULL)
+ return gnc_numeric_zero ();
+
+ currency = xaccAccountGetCommodity (account);
+ balance = xaccAccountGetBalanceAsOfDate (account, date);
+
+ if (include_children)
+ {
+ GList *children, *node;
+
+ children = gnc_account_get_descendants(account);
+
+ for (node = children; node; node = node->next)
+ {
+ Account *child;
+ gnc_commodity *child_currency;
+ gnc_numeric child_balance;
+
+ child = node->data;
+ child_currency = xaccAccountGetCommodity (child);
+ child_balance = xaccAccountGetBalanceAsOfDate (child, date);
+ child_balance = xaccAccountConvertBalanceToCurrency (child,
+ child_balance, child_currency, currency);
+ balance = gnc_numeric_add_fixed (balance, child_balance);
+ }
+
+ g_list_free(children);
+ }
+
+ /* reverse sign if needed */
+ if (gnc_reverse_balance (account))
+ balance = gnc_numeric_neg (balance);
+
+ return balance;
+}
+
+
+/********************************************************************
+ * Balance calculations related to owners
+ ********************************************************************/
+
+/*
+ * This is a wrapper routine around an gncOwnerGetBalanceInCurrency
+ * function that handles additional needs of the gui.
+ *
+ * @param owner The owner to retrieve data about.
+ * @param negative An indication of whether or not the returned value
+ * is negative. This can be used by the caller to
+ * easily decode whether or not to color the output.
+ * @param commodity The commodity in which the account balance should
+ * be returned. If NULL, the value will be returned in
+ * the commodity of the owner. This is normally used
+ * to specify a currency, which forces the conversion
+ * of things like stock account values from share
+ * values to an amount the requested currency.
+ */
+gnc_numeric
+gnc_ui_owner_get_balance_full (GncOwner *owner,
+ gboolean *negative,
+ const gnc_commodity *commodity)
+{
+ gnc_numeric balance;
+
+ if (!owner)
+ return gnc_numeric_zero ();
+
+ balance = gncOwnerGetBalanceInCurrency (owner, commodity);
+
+ /* reverse sign if needed */
+ if ((gncOwnerGetType (owner) != GNC_OWNER_CUSTOMER))
+ balance = gnc_numeric_neg (balance);
+
+ /* Record whether the balance is negative. */
+ if (negative)
+ *negative = gnc_numeric_negative_p (balance);
+
+ return balance;
+}
+
+
+/**
+ * Wrapper around gnc_ui_owner_get_balance_full that converts
+ * the resulting number to a character string. The number is
+ * formatted according to the specification of the owner currency.
+ * The caller is responsible for g_free'ing the returned memory.
+ *
+ * @param owner The owner to retrieve data about.
+ * @param negative An indication of whether or not the returned value
+ * is negative. This can be used by the caller to
+ * easily decode whether or not to color the output.
+ */
+gchar *
+gnc_ui_owner_get_print_balance (GncOwner *owner,
+ gboolean *negative)
+{
+ gnc_numeric balance;
+ GNCPrintAmountInfo print_info;
+
+ balance = gnc_ui_owner_get_balance_full (owner, negative, NULL);
+ print_info = gnc_commodity_print_info (gncOwnerGetCurrency (owner), TRUE);
+ return g_strdup (xaccPrintAmount (balance, print_info));
+}
+
+/**
+ * Wrapper around gnc_ui_owner_get_balance_full that converts
+ * the resulting number to a character string. The number is
+ * formatted according to the specification of the default reporting
+ * currency.
+ *
+ * @param account The owner to retrieve data about.
+ * @param negative An indication of whether or not the returned value
+ * is negative. This can be used by the caller to
+ * easily decode whether or not to color the output.
+ */
+gchar *
+gnc_ui_owner_get_print_report_balance (GncOwner *owner,
+ gboolean *negative)
+{
+ GNCPrintAmountInfo print_info;
+ gnc_numeric balance;
+ gnc_commodity *report_commodity;
+
+ report_commodity = gnc_default_report_currency ();
+ balance = gnc_ui_owner_get_balance_full (owner, negative,
+ report_commodity);
+ print_info = gnc_commodity_print_info (report_commodity, TRUE);
+ return g_strdup (xaccPrintAmount (balance, print_info));
+}
+
Added: gnucash/trunk/src/app-utils/gnc-ui-balances.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-balances.h (rev 0)
+++ gnucash/trunk/src/app-utils/gnc-ui-balances.h 2011-08-23 21:20:27 UTC (rev 21216)
@@ -0,0 +1,146 @@
+/********************************************************************\
+ * gnc-ui-balances.c -- utility functions for calculating *
+ * account and owner balances used in the *
+ * the GnuCash UI *
+ * Copyright (C) 2000 Dave Peticolas <dave at krondo.com> *
+ * Copyright (C) 2011 Geert Janssens <geert at kobaltwit.be> *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License as *
+ * published by the Free Software Foundation; either version 2 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact: *
+ * *
+ * Free Software Foundation Voice: +1-617-542-5942 *
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
+ * Boston, MA 02110-1301, USA gnu at gnu.org *
+\********************************************************************/
+
+
+
+#ifndef GNC_UI_BALANCES_H_
+#define GNC_UI_BALANCES_H_
+
+#include <glib.h>
+
+#include "Account.h"
+#include "gncOwner.h"
+#include "qof.h"
+
+/********************************************************************
+ * Balance calculations related to accounts
+ ********************************************************************/
+
+gnc_numeric
+gnc_ui_account_get_balance_full (xaccGetBalanceInCurrencyFn fn,
+ const Account *account,
+ gboolean recurse,
+ gboolean *negative,
+ const gnc_commodity *commodity);
+
+/**
+ * This routine retrieves the total balance in an account, possibly
+ * including all sub-accounts under the specified account.
+ *
+ * @param account The account to retrieve data about.
+ * @param include_children Include all sub-accounts of this account.
+ */
+gnc_numeric gnc_ui_account_get_balance (const Account *account,
+ gboolean include_children);
+
+gnc_numeric gnc_ui_account_get_balance_in_currency (const Account *account,
+ const gnc_commodity *currency,
+ gboolean recurse);
+/**
+ * This routine retrieves the reconciled balance in an account,
+ * possibly including all sub-accounts under the specified account.
+ *
+ * @param account The account to retrieve data about.
+ * @param include_children Include all sub-accounts of this account.
+ */
+gnc_numeric gnc_ui_account_get_reconciled_balance(const Account *account,
+ gboolean include_children);
+
+/**
+ * Wrapper around gnc_ui_account_get_balance_internal that converts
+ * the resulting number to a character string. The number is
+ * formatted according to the specification of the account currency.
+ *
+ * @param fn The underlying function in Account.c to call to retrieve
+ * a specific balance from the account.
+ * @param account The account to retrieve data about.
+ * @param recurse Include all sub-accounts of this account.
+ * @param negative An indication of whether or not the returned value
+ * is negative. This can be used by the caller to
+ * easily decode whether or not to color the output.
+ */
+gchar *
+gnc_ui_account_get_print_balance (xaccGetBalanceInCurrencyFn fn,
+ const Account *account,
+ gboolean recurse,
+ gboolean *negative);
+
+/**
+ * Wrapper around gnc_ui_account_get_balance_internal that converts
+ * the resulting number to a character string. The number is
+ * formatted according to the specification of the default reporting
+ * currency.
+ *
+ * @param fn The underlying function in Account.c to call to retrieve
+ * a specific balance from the account.
+ * @param account The account to retrieve data about.
+ * @param recurse Include all sub-accounts of this account.
+ * @param negative An indication of whether or not the returned value
+ * is negative. This can be used by the caller to
+ * easily decode whether or not to color the output.
+ */
+gchar *
+gnc_ui_account_get_print_report_balance (xaccGetBalanceInCurrencyFn fn,
+ const Account *account,
+ gboolean recurse,
+ gboolean *negative);
+
+gnc_numeric gnc_ui_account_get_balance_as_of_date (Account *account,
+ time_t date,
+ gboolean include_children);
+
+/********************************************************************
+ * Balance calculations related to owners
+ ********************************************************************/
+
+/** Get the balance for the underlying owner object.
+ * The returned value is always positive,
+ * intended to be displayed to a user. However the real sign
+ * of the balance is indicated via the "negative" parameter.
+ */
+gnc_numeric gnc_ui_owner_get_balance_full (GncOwner *owner,
+ gboolean *negative,
+ const gnc_commodity *commodity);
+
+/** Get the balance for the underlying owner object in string format
+ * and the owner's native currency.
+ * The returned value is always positive,
+ * intended to be displayed to a user. However the real sign
+ * of the balance is indicated via the "negative" parameter.
+ */
+gchar * gnc_ui_owner_get_print_balance (GncOwner *owner,
+ gboolean *negative);
+
+/** Get the balance for the underlying owner object in string format
+ * and in the default report currency.
+ * The returned value is always positive,
+ * intended to be displayed to a user. However the real sign
+ * of the balance is indicated via the "negative" parameter.
+ */
+gchar * gnc_ui_owner_get_print_report_balance (GncOwner *owner,
+ gboolean *negative);
+
+
+#endif /* GNC_UI_BALANCES_H_ */
Modified: gnucash/trunk/src/app-utils/gnc-ui-util.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.c 2011-08-23 21:20:15 UTC (rev 21215)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.c 2011-08-23 21:20:27 UTC (rev 21216)
@@ -271,278 +271,6 @@
}
-/*
- * This is a wrapper routine around an xaccGetBalanceInCurrency
- * function that handles additional needs of the gui.
- *
- * @param fn The underlying function in Account.c to call to retrieve
- * a specific balance from the account.
- * @param account The account to retrieve data about.
- * @param recurse Include all sub-accounts of this account.
- * @param negative An indication of whether or not the returned value
- * is negative. This can be used by the caller to
- * easily decode whether or not to color the output.
- * @param commodity The commodity in which the account balance should
- * be returned. If NULL, the value will be returned in
- * the commodity of the account. This is normally used
- * to specify a currency, which forces the conversion
- * of things like stock account values from share
- * values to an amount the requested currency.
- */
-gnc_numeric
-gnc_ui_account_get_balance_full (xaccGetBalanceInCurrencyFn fn,
- const Account *account,
- gboolean recurse,
- gboolean *negative,
- const gnc_commodity *commodity)
-{
- gnc_numeric balance;
-
- balance = fn(account, commodity, recurse);
-
- /* reverse sign if needed */
- if (gnc_reverse_balance (account))
- balance = gnc_numeric_neg (balance);
-
- /* Record whether the balance is negative. */
- if (negative)
- *negative = gnc_numeric_negative_p(balance);
-
- return balance;
-}
-
-/*
- * This routine retrieves the total balance in an account, possibly
- * including all sub-accounts under the specified account.
- */
-gnc_numeric
-gnc_ui_account_get_balance (const Account *account, gboolean recurse)
-{
- return gnc_ui_account_get_balance_full (xaccAccountGetBalanceInCurrency,
- account, recurse, NULL, NULL);
-}
-
-/*
- * This routine retrieves 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 (const Account *account,
- const gnc_commodity *currency,
- gboolean recurse)
-{
- return gnc_ui_account_get_balance_full (xaccAccountGetBalanceInCurrency,
- account, recurse, NULL, currency);
-}
-
-/*
- * This routine retrieves the reconciled balance in an account,
- * possibly including all sub-accounts under the specified account.
- */
-gnc_numeric
-gnc_ui_account_get_reconciled_balance (const Account *account,
- gboolean recurse)
-{
- return gnc_ui_account_get_balance_full (xaccAccountGetReconciledBalanceInCurrency,
- account, recurse, NULL, NULL);
-}
-
-
-/**
- * Wrapper around gnc_ui_account_get_balance_full that converts
- * the resulting number to a character string. The number is
- * formatted according to the specification of the account currency.
- * The caller is responsible for g_free'ing the returned memory.
- *
- * @param fn The underlying function in Account.c to call to retrieve
- * a specific balance from the account.
- * @param account The account to retrieve data about.
- * @param recurse Include all sub-accounts of this account.
- * @param negative An indication of whether or not the returned value
- * is negative. This can be used by the caller to
- * easily decode whether or not to color the output.
- */
-gchar *
-gnc_ui_account_get_print_balance (xaccGetBalanceInCurrencyFn fn,
- const Account *account,
- gboolean recurse,
- gboolean *negative)
-{
- GNCPrintAmountInfo print_info;
- gnc_numeric balance;
-
- balance = gnc_ui_account_get_balance_full(fn, account, recurse,
- negative, NULL);
- print_info = gnc_account_print_info(account, TRUE);
- return g_strdup(xaccPrintAmount(balance, print_info));
-}
-
-
-/**
- * Wrapper around gnc_ui_account_get_balance_full that converts
- * the resulting number to a character string. The number is
- * formatted according to the specification of the default reporting
- * currency.
- *
- * @param fn The underlying function in Account.c to call to retrieve
- * a specific balance from the account.
- * @param account The account to retrieve data about.
- * @param recurse Include all sub-accounts of this account.
- * @param negative An indication of whether or not the returned value
- * is negative. This can be used by the caller to
- * easily decode whether or not to color the output.
- */
-gchar *
-gnc_ui_account_get_print_report_balance (xaccGetBalanceInCurrencyFn fn,
- const Account *account,
- gboolean recurse,
- gboolean *negative)
-{
- GNCPrintAmountInfo print_info;
- gnc_numeric balance;
- gnc_commodity *report_commodity;
-
- report_commodity = gnc_default_report_currency();
- balance = gnc_ui_account_get_balance_full(fn, account, recurse,
- negative, report_commodity);
- print_info = gnc_commodity_print_info(report_commodity, TRUE);
- return g_strdup(xaccPrintAmount(balance, print_info));
-}
-
-
-gnc_numeric
-gnc_ui_account_get_balance_as_of_date (Account *account,
- time_t date,
- gboolean include_children)
-{
- gnc_numeric balance;
- gnc_commodity *currency;
-
- if (account == NULL)
- return gnc_numeric_zero ();
-
- currency = xaccAccountGetCommodity (account);
- balance = xaccAccountGetBalanceAsOfDate (account, date);
-
- if (include_children)
- {
- GList *children, *node;
-
- children = gnc_account_get_descendants(account);
-
- for (node = children; node; node = node->next)
- {
- Account *child;
- gnc_commodity *child_currency;
- gnc_numeric child_balance;
-
- child = node->data;
- child_currency = xaccAccountGetCommodity (child);
- child_balance = xaccAccountGetBalanceAsOfDate (child, date);
- child_balance = xaccAccountConvertBalanceToCurrency (child,
- child_balance, child_currency, currency);
- balance = gnc_numeric_add_fixed (balance, child_balance);
- }
-
- g_list_free(children);
- }
-
- /* reverse sign if needed */
- if (gnc_reverse_balance (account))
- balance = gnc_numeric_neg (balance);
-
- return balance;
-}
-
-/*
- * This is a wrapper routine around an gncOwnerGetBalanceInCurrency
- * function that handles additional needs of the gui.
- *
- * @param owner The owner to retrieve data about.
- * @param negative An indication of whether or not the returned value
- * is negative. This can be used by the caller to
- * easily decode whether or not to color the output.
- * @param commodity The commodity in which the account balance should
- * be returned. If NULL, the value will be returned in
- * the commodity of the owner. This is normally used
- * to specify a currency, which forces the conversion
- * of things like stock account values from share
- * values to an amount the requested currency.
- */
-gnc_numeric
-gnc_ui_owner_get_balance_full (GncOwner *owner,
- gboolean *negative,
- const gnc_commodity *commodity)
-{
- gnc_numeric balance;
-
- if (!owner)
- return gnc_numeric_zero ();
-
- balance = gncOwnerGetBalanceInCurrency (owner, commodity);
-
- /* reverse sign if needed */
- if ((gncOwnerGetType (owner) != GNC_OWNER_CUSTOMER))
- balance = gnc_numeric_neg (balance);
-
- /* Record whether the balance is negative. */
- if (negative)
- *negative = gnc_numeric_negative_p (balance);
-
- return balance;
-}
-
-
-/**
- * Wrapper around gnc_ui_owner_get_balance_full that converts
- * the resulting number to a character string. The number is
- * formatted according to the specification of the owner currency.
- * The caller is responsible for g_free'ing the returned memory.
- *
- * @param owner The owner to retrieve data about.
- * @param negative An indication of whether or not the returned value
- * is negative. This can be used by the caller to
- * easily decode whether or not to color the output.
- */
-gchar *
-gnc_ui_owner_get_print_balance (GncOwner *owner,
- gboolean *negative)
-{
- gnc_numeric balance;
- GNCPrintAmountInfo print_info;
-
- balance = gnc_ui_owner_get_balance_full (owner, negative, NULL);
- print_info = gnc_commodity_print_info (gncOwnerGetCurrency (owner), TRUE);
- return g_strdup (xaccPrintAmount (balance, print_info));
-}
-
-/**
- * Wrapper around gnc_ui_owner_get_balance_full that converts
- * the resulting number to a character string. The number is
- * formatted according to the specification of the default reporting
- * currency.
- *
- * @param account The owner to retrieve data about.
- * @param negative An indication of whether or not the returned value
- * is negative. This can be used by the caller to
- * easily decode whether or not to color the output.
- */
-gchar *
-gnc_ui_owner_get_print_report_balance (GncOwner *owner,
- gboolean *negative)
-{
- GNCPrintAmountInfo print_info;
- gnc_numeric balance;
- gnc_commodity *report_commodity;
-
- report_commodity = gnc_default_report_currency ();
- balance = gnc_ui_owner_get_balance_full (owner, negative,
- report_commodity);
- print_info = gnc_commodity_print_info (report_commodity, TRUE);
- return g_strdup (xaccPrintAmount (balance, print_info));
-}
-
/* Caller is responsible for g_free'ing returned memory */
char *
gnc_ui_account_get_tax_info_string (const Account *account)
Modified: gnucash/trunk/src/app-utils/gnc-ui-util.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.h 2011-08-23 21:20:15 UTC (rev 21215)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.h 2011-08-23 21:20:27 UTC (rev 21216)
@@ -107,110 +107,10 @@
* of things like stock account values from share
* values to an amount the requested currency.
*/
-gnc_numeric
-gnc_ui_account_get_balance_full (xaccGetBalanceInCurrencyFn fn,
- const Account *account,
- gboolean recurse,
- gboolean *negative,
- const gnc_commodity *commodity);
-
-/**
- * This routine retrives the total balance in an account, possibly
- * including all sub-accounts under the specified account.
- *
- * @param account The account to retrieve data about.
- * @param include_children Include all sub-accounts of this account.
- */
-gnc_numeric gnc_ui_account_get_balance (const Account *account,
- gboolean include_children);
-
-gnc_numeric gnc_ui_account_get_balance_in_currency (const Account *account,
- const gnc_commodity *currency,
- gboolean recurse);
-/**
- * This routine retrives the reconciled balance in an account,
- * possibly including all sub-accounts under the specified account.
- *
- * @param account The account to retrieve data about.
- * @param include_children Include all sub-accounts of this account.
- */
-gnc_numeric gnc_ui_account_get_reconciled_balance(const Account *account,
- gboolean include_children);
-
-/**
- * Wrapper around gnc_ui_account_get_balance_internal that converts
- * the resulting number to a character string. The number is
- * formatted according to the specification of the account currency.
- *
- * @param fn The underlying function in Account.c to call to retrieve
- * a specific balance from the account.
- * @param account The account to retrieve data about.
- * @param recurse Include all sub-accounts of this account.
- * @param negative An indication of whether or not the returned value
- * is negative. This can be used by the caller to
- * easily decode whether or not to color the output.
- */
-gchar *
-gnc_ui_account_get_print_balance (xaccGetBalanceInCurrencyFn fn,
- const Account *account,
- gboolean recurse,
- gboolean *negative);
-
-/**
- * Wrapper around gnc_ui_account_get_balance_internal that converts
- * the resulting number to a character string. The number is
- * formatted according to the specification of the default reporting
- * currency.
- *
- * @param fn The underlying function in Account.c to call to retrieve
- * a specific balance from the account.
- * @param account The account to retrieve data about.
- * @param recurse Include all sub-accounts of this account.
- * @param negative An indication of whether or not the returned value
- * is negative. This can be used by the caller to
- * easily decode whether or not to color the output.
- */
-gchar *
-gnc_ui_account_get_print_report_balance (xaccGetBalanceInCurrencyFn fn,
- const Account *account,
- gboolean recurse,
- gboolean *negative);
-
-/** Get the balance for the underlying owner object.
- * The returned value is always positive,
- * intended to be displayed to a user. However the real sign
- * of the balance is indicated via the "negative" parameter.
- */
-gnc_numeric gnc_ui_owner_get_balance_full (GncOwner *owner,
- gboolean *negative,
- const gnc_commodity *commodity);
-
-/** Get the balance for the underlying owner object in string format
- * and the owner's native currency.
- * The returned value is always positive,
- * intended to be displayed to a user. However the real sign
- * of the balance is indicated via the "negative" parameter.
- */
-gchar * gnc_ui_owner_get_print_balance (GncOwner *owner,
- gboolean *negative);
-
-/** Get the balance for the underlying owner object in string format
- * and in the default report currency.
- * The returned value is always positive,
- * intended to be displayed to a user. However the real sign
- * of the balance is indicated via the "negative" parameter.
- */
-gchar * gnc_ui_owner_get_print_report_balance (GncOwner *owner,
- gboolean *negative);
-
char *gnc_ui_account_get_tax_info_string (const Account *account);
char *gnc_ui_account_get_tax_info_sub_acct_string (const Account *account);
-gnc_numeric gnc_ui_account_get_balance_as_of_date (Account *account,
- time_t date,
- gboolean include_children);
-
const char * gnc_get_reconcile_str (char reconciled_flag);
const char * gnc_get_reconcile_valid_flags (void);
const char * gnc_get_reconcile_flag_order (void);
Modified: gnucash/trunk/src/gnome/window-reconcile.c
===================================================================
--- gnucash/trunk/src/gnome/window-reconcile.c 2011-08-23 21:20:15 UTC (rev 21215)
+++ gnucash/trunk/src/gnome/window-reconcile.c 2011-08-23 21:20:27 UTC (rev 21216)
@@ -47,6 +47,7 @@
#include "gnc-main-window.h"
#include "gnc-plugin-page-register.h"
#include "gnc-ui.h"
+#include "gnc-ui-balances.h"
#include "guile-util.h"
#include "reconcile-list.h"
#include "window-reconcile.h"
Modified: gnucash/trunk/src/gnome-utils/gnc-tree-model-account.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-model-account.c 2011-08-23 21:20:15 UTC (rev 21215)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-model-account.c 2011-08-23 21:20:27 UTC (rev 21216)
@@ -38,6 +38,7 @@
#include "gnc-engine.h"
#include "gnc-event.h"
#include "gnc-gobject-utils.h"
+#include "gnc-ui-balances.h"
#include "gnc-ui-util.h"
#define TREE_MODEL_ACCOUNT_CM_CLASS "tree-model-account"
Modified: gnucash/trunk/src/gnome-utils/gnc-tree-model-owner.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-model-owner.c 2011-08-23 21:20:15 UTC (rev 21215)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-model-owner.c 2011-08-23 21:20:27 UTC (rev 21216)
@@ -36,6 +36,7 @@
#include "gnc-engine.h"
#include "gnc-event.h"
#include "gnc-gobject-utils.h"
+#include "gnc-ui-balances.h"
#include "gnc-ui-util.h"
#define TREE_MODEL_OWNER_CM_CLASS "tree-model-owner"
Modified: gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c 2011-08-23 21:20:15 UTC (rev 21215)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c 2011-08-23 21:20:27 UTC (rev 21216)
@@ -43,7 +43,7 @@
#include "gnc-hooks.h"
#include "gnc-session.h"
#include "gnc-icons.h"
-#include "gnc-ui-util.h"
+#include "gnc-ui-balances.h"
#include "dialog-utils.h"
#include "window-main-summarybar.h"
Modified: gnucash/trunk/src/gnome-utils/gnc-tree-view-owner.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-view-owner.c 2011-08-23 21:20:15 UTC (rev 21215)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-view-owner.c 2011-08-23 21:20:27 UTC (rev 21216)
@@ -42,7 +42,7 @@
#include "gnc-hooks.h"
#include "gnc-session.h"
#include "gnc-icons.h"
-#include "gnc-ui-util.h"
+#include "gnc-ui-balances.h"
#include "dialog-utils.h"
#include "window-main-summarybar.h"
#include "assistant-utils.h"
More information about the gnucash-changes
mailing list