28 #include "gnc-ui-balances.h" 32 #include <glib/gi18n.h> 39 G_GNUC_UNUSED
static QofLogModule log_module = GNC_MOD_GUI;
64 gnc_ui_account_get_balance_full (xaccGetBalanceInCurrencyFn fn,
68 const gnc_commodity *commodity)
72 balance = fn(account, commodity, recurse);
75 if (gnc_reverse_balance (account))
90 gnc_ui_account_get_balance (
const Account *account, gboolean recurse)
92 return gnc_ui_account_get_balance_full (xaccAccountGetBalanceInCurrency,
93 account, recurse, NULL, NULL);
115 gnc_ui_account_get_reconciled_balance (
const Account *account,
118 return gnc_ui_account_get_balance_full (xaccAccountGetReconciledBalanceInCurrency,
119 account, recurse, NULL, NULL);
138 gnc_ui_account_get_print_balance (xaccGetBalanceInCurrencyFn fn,
146 balance = gnc_ui_account_get_balance_full(fn, account, recurse,
148 print_info = gnc_account_print_info(account, TRUE);
169 gnc_ui_account_get_print_report_balance (xaccGetBalanceInCurrencyFn fn,
176 gnc_commodity *report_commodity;
179 balance = gnc_ui_account_get_balance_full(fn, account, recurse,
180 negative, report_commodity);
181 print_info = gnc_commodity_print_info(report_commodity, TRUE);
187 account_get_balance_as_of_date (
Account *account,
189 gboolean include_children,
190 xaccGetBalanceAsOfDateFn fn)
192 QofBook *book = gnc_account_get_book (account);
195 gnc_commodity *currency;
198 return gnc_numeric_zero ();
201 balance = fn (account, date);
203 if (include_children)
205 GList *children, *node;
209 for (node = children; node; node = node->next)
212 gnc_commodity *child_currency;
213 gnc_numeric child_balance;
215 child =
static_cast<Account*
>(node->data);
217 child_balance = fn (child, date);
222 balance = gnc_numeric_add_fixed (balance, child_balance);
225 g_list_free(children);
229 if (gnc_reverse_balance (account))
236 gnc_ui_account_get_balance_as_of_date (
Account *account,
238 gboolean include_children)
240 return account_get_balance_as_of_date (account, date, include_children,
245 gnc_ui_account_get_reconciled_balance_as_of_date (
Account *account,
247 gboolean include_children)
249 return account_get_balance_as_of_date (account, date, include_children,
256 account_balance_for_limit (
const Account *account)
258 return gnc_ui_account_get_balance_as_of_date
264 account_balance_limit_reached (
const Account *account, gnc_numeric balance_limit)
266 gnc_numeric balance = account_balance_for_limit (account);
271 if (gnc_reverse_balance (account))
279 get_limit_info (
const Account *account, gnc_numeric *limit, gboolean higher)
281 gboolean reverse = gnc_reverse_balance (account);
282 if ((higher && reverse) || (!higher && !reverse))
289 gnc_ui_account_is_higher_balance_limit_reached (
const Account *account,
292 gnc_numeric balance_limit;
293 gboolean limit_valid = FALSE;
294 gboolean retval = FALSE;
296 g_return_val_if_fail (GNC_IS_ACCOUNT(account), FALSE);
298 limit_valid = get_limit_info (account, &balance_limit, TRUE);
306 if (account_balance_limit_reached (account, balance_limit) == 1)
313 gnc_ui_account_is_lower_balance_limit_reached (
const Account *account,
316 gnc_numeric balance_limit;
317 gboolean limit_valid = FALSE;
318 gboolean retval = FALSE;
320 g_return_val_if_fail (GNC_IS_ACCOUNT(account), FALSE);
322 limit_valid = get_limit_info (account, &balance_limit, FALSE);
330 if (account_balance_limit_reached (account, balance_limit) == -1)
337 make_limit_explanation (
const Account *account,
const char* template_str,
338 gboolean zero, gboolean higher)
342 gnc_numeric acct_bal = account_balance_for_limit (account);
347 rv = g_strdup_printf (_(template_str), fullname, bal_str);
351 get_limit_info (account, &limit, higher);
352 if (gnc_reverse_balance (account))
355 rv = g_strdup_printf (_(template_str), fullname, bal_str, lim_str);
364 get_balance_limit_info (
const Account *account, gboolean icon)
366 gboolean lower_limit_reached, higher_limit_reached;
367 gboolean lower_is_zero = FALSE;
368 gboolean higher_is_zero = FALSE;
369 const char *higher_template = N_(
"%s balance of %s is above the upper limit %s.");
370 const char *lower_template = N_(
"%s balance of %s is below the lower limit %s.");
371 const char *zero_template = N_(
"%s balance of %s should be zero.");
373 g_return_val_if_fail (GNC_IS_ACCOUNT(account), NULL);
375 higher_limit_reached = gnc_ui_account_is_higher_balance_limit_reached (account, &higher_is_zero);
378 if (higher_limit_reached && !higher_is_zero)
379 return icon ? g_strdup (
"go-top") : make_limit_explanation (account, higher_template, FALSE, TRUE);
381 lower_limit_reached = gnc_ui_account_is_lower_balance_limit_reached (account, &lower_is_zero);
383 if (lower_limit_reached && (!lower_is_zero || !higher_is_zero))
384 return icon ? g_strdup (
"go-bottom") : make_limit_explanation (account, lower_template, FALSE, FALSE);
386 if (higher_limit_reached && !lower_is_zero)
387 return icon ? g_strdup (
"go-top") : make_limit_explanation (account, higher_template, FALSE, TRUE);
389 if ((lower_limit_reached || higher_limit_reached ) && lower_is_zero && higher_is_zero)
390 return icon ? g_strdup (
"dialog-warning") : make_limit_explanation (account, zero_template, TRUE, FALSE);
396 gnc_ui_account_get_balance_limit_icon_name (
const Account *account)
398 char *icon = get_balance_limit_info (account, TRUE);
399 return icon ? icon : g_strdup (
"");
403 gnc_ui_account_get_balance_limit_explanation (
const Account *account)
405 return get_balance_limit_info (account, FALSE);
428 gnc_ui_owner_get_balance_full (
GncOwner *owner,
430 const gnc_commodity *commodity)
435 return gnc_numeric_zero ();
463 gnc_ui_owner_get_print_balance (
GncOwner *owner,
469 balance = gnc_ui_owner_get_balance_full (owner, negative, NULL);
470 print_info = gnc_commodity_print_info (gncOwnerGetCurrency (owner), TRUE);
487 gnc_ui_owner_get_print_report_balance (
GncOwner *owner,
492 gnc_commodity *report_commodity;
495 balance = gnc_ui_owner_get_balance_full (owner, negative,
497 print_info = gnc_commodity_print_info (report_commodity, TRUE);
Business Interface: Object OWNERs.
const char * gnc_print_amount_with_bidi_ltr_isolate(gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
utility functions for the GnuCash UI
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value...
const char * xaccPrintAmount(gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
API for Transactions and Splits (journal entries)
gint gnc_numeric_compare(gnc_numeric a, gnc_numeric b)
Returns 1 if a>b, -1 if b>a, 0 if a == b.
gnc_commodity * gnc_default_report_currency(void)
Return the default currency for use in reports, as set by the user.
GNCPriceDB * gnc_pricedb_get_db(QofBook *book)
Return the pricedb associated with the book.
gboolean gnc_numeric_negative_p(gnc_numeric a)
Returns 1 if a < 0, otherwise returns 0.
gnc_numeric gnc_pricedb_convert_balance_latest_price(GNCPriceDB *pdb, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency)
Convert a balance from one currency to another using the most recent price between the two...
gboolean xaccAccountGetLowerBalanceLimit(const Account *acc, gnc_numeric *balance)
Get the lower balance limit for the account.
gchar * gnc_account_get_full_name(const Account *account)
The gnc_account_get_full_name routine returns the fully qualified name of the account using the given...
gnc_numeric xaccAccountGetReconciledBalanceAsOfDate(Account *acc, time64 date)
Get the reconciled balance of the account at the end of the day of the date specified.
Account handling public routines.
gnc_numeric gncOwnerGetBalanceInCurrency(const GncOwner *owner, const gnc_commodity *report_currency)
Given an owner, extract the open balance from the owner and then convert it to the desired currency...
gnc_numeric xaccAccountGetBalanceAsOfDate(Account *acc, time64 date)
Get the balance of the account at the end of the day before the date specified.
GncOwnerType gncOwnerGetType(const GncOwner *owner)
Returns the GncOwnerType of this owner.
GList * gnc_account_get_descendants(const Account *account)
This routine returns a flat list of all of the accounts that are descendants of the specified account...
gboolean xaccAccountGetIncludeSubAccountBalances(const Account *acc)
Get whether to include balances of sub accounts.
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity.
gboolean xaccAccountGetHigherBalanceLimit(const Account *acc, gnc_numeric *balance)
Get the higher balance limit for the account.
time64 gnc_time(time64 *tbuf)
get the current time
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
time64 gnc_time64_get_day_end(time64 time_val)
The gnc_time64_get_day_end() routine will take the given time in seconds and adjust it to the last se...