Skip to content

Commit

Permalink
Change the balance limit icon if both limits are zero
Browse files Browse the repository at this point in the history
When higher and lower limits are zero, when used for a a suspense
account, change the icon to 'dialog-warning'. This type of use is to
indicate that a non zero balance exists.
  • Loading branch information
Bob-IT committed Dec 17, 2022
1 parent 3be25ff commit 7536fca
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
7 changes: 1 addition & 6 deletions gnucash/gnome-utils/gnc-tree-model-account.c
Expand Up @@ -833,12 +833,7 @@ gnc_tree_model_account_get_value (GtkTreeModel *tree_model,

case GNC_TREE_MODEL_ACCOUNT_COL_BALANCE_LIMIT:
g_value_init (value, G_TYPE_STRING);
if (gnc_ui_account_is_higher_balance_limit_reached (account))
string = "go-top";
else if (gnc_ui_account_is_lower_balance_limit_reached (account))
string = "go-bottom";
else
string = "";
string = gnc_ui_account_get_balance_limit_icon_name (account);
g_value_set_string (value, string);
break;

Expand Down
41 changes: 39 additions & 2 deletions libgnucash/app-utils/gnc-ui-balances.c
Expand Up @@ -272,7 +272,8 @@ account_balance_limit_reached (const Account *account, gnc_numeric balance_limit
}

gboolean
gnc_ui_account_is_higher_balance_limit_reached (const Account *account)
gnc_ui_account_is_higher_balance_limit_reached (const Account *account,
gboolean *is_zero)
{
gnc_numeric balance_limit;
gboolean limit_valid = FALSE;
Expand All @@ -289,14 +290,18 @@ gnc_ui_account_is_higher_balance_limit_reached (const Account *account)
if (!limit_valid)
return retval;

if (gnc_numeric_zero_p (balance_limit))
*is_zero = TRUE;

if (account_balance_limit_reached (account, balance_limit) == 1)
retval = TRUE;

return retval;
}

gboolean
gnc_ui_account_is_lower_balance_limit_reached (const Account *account)
gnc_ui_account_is_lower_balance_limit_reached (const Account *account,
gboolean *is_zero)
{
gnc_numeric balance_limit;
gboolean limit_valid = FALSE;
Expand All @@ -313,12 +318,44 @@ gnc_ui_account_is_lower_balance_limit_reached (const Account *account)
if (!limit_valid)
return retval;

if (gnc_numeric_zero_p (balance_limit))
*is_zero = TRUE;

if (account_balance_limit_reached (account, balance_limit) == -1)
retval = TRUE;

return retval;
}

gchar *
gnc_ui_account_get_balance_limit_icon_name (const Account *account)
{
gboolean lower_limit_reached, higher_limit_reached;
gboolean lower_is_zero = FALSE;
gboolean higher_is_zero = FALSE;

g_return_val_if_fail (GNC_IS_ACCOUNT(account), g_strdup (""));

higher_limit_reached = gnc_ui_account_is_higher_balance_limit_reached (account, &higher_is_zero);

// assume the higher value will be set mostly so test that first
if (higher_limit_reached && !higher_is_zero)
return g_strdup ("go-top");

lower_limit_reached = gnc_ui_account_is_lower_balance_limit_reached (account, &lower_is_zero);

if (lower_limit_reached && (!lower_is_zero || !higher_is_zero))
return g_strdup ("go-bottom");

if (higher_limit_reached && !lower_is_zero)
return g_strdup ("go-top");

if ((lower_limit_reached || higher_limit_reached ) && lower_is_zero && higher_is_zero)
return g_strdup ("dialog-warning");

return g_strdup ("");
}

/********************************************************************
* Balance calculations related to owners
********************************************************************/
Expand Down
16 changes: 14 additions & 2 deletions libgnucash/app-utils/gnc-ui-balances.h
Expand Up @@ -160,18 +160,30 @@ GList * gnc_account_get_autoclear_splits (Account *account, gnc_numeric toclear_
*
* @param account A pointer to the account.
*
* @param is_zero A return value, set to TRUE if limit is zero
*
* @return TRUE if account balance has passed limit.
*/
gboolean gnc_ui_account_is_higher_balance_limit_reached (const Account *account);
gboolean gnc_ui_account_is_higher_balance_limit_reached (const Account *account, gboolean *is_zero);

/** Test the account balance as of today for it passing the
* lower limit if set.
*
* @param account A pointer to the account.
*
* @param is_zero A return value, set to TRUE if limit is zero
*
* @return TRUE if account balance has passed limit.
*/
gboolean gnc_ui_account_is_lower_balance_limit_reached (const Account *account);
gboolean gnc_ui_account_is_lower_balance_limit_reached (const Account *account, gboolean *is_zero);

/** Test the account balance as of today for it passing the
* lower and higher limits if set.
*
* @param account A pointer to the account.
*
* @return The icon name to be displayed.
*/
gchar * gnc_ui_account_get_balance_limit_icon_name (const Account *account);

#endif /* GNC_UI_BALANCES_H_ */

0 comments on commit 7536fca

Please sign in to comment.