mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add account balance test functions to gnc-ui-balance
This commit is contained in:
parent
5108c52ea4
commit
60ab654d2b
@ -250,6 +250,70 @@ gnc_ui_account_get_reconciled_balance_as_of_date (Account *account,
|
||||
xaccAccountGetReconciledBalanceAsOfDate);
|
||||
}
|
||||
|
||||
static gint
|
||||
account_balance_limit_reached (const Account *account, gnc_numeric balance_limit)
|
||||
{
|
||||
// we use today's date because account may have future dated splits
|
||||
gnc_numeric balance = xaccAccountGetBalanceAsOfDate ((Account*)account,
|
||||
gnc_time64_get_day_end (gnc_time (NULL)));
|
||||
|
||||
if (gnc_numeric_zero_p (balance))
|
||||
return 0;
|
||||
|
||||
if (gnc_reverse_balance (account))
|
||||
balance_limit = gnc_numeric_neg (balance_limit);
|
||||
|
||||
// Returns 1 if a>b, -1 if b>a, 0 if a == b
|
||||
return gnc_numeric_compare (balance, balance_limit);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnc_ui_account_is_higher_balance_limit_reached (const Account *account)
|
||||
{
|
||||
gnc_numeric balance_limit;
|
||||
gboolean limit_valid = FALSE;
|
||||
gboolean retval = FALSE;
|
||||
gint compare_result;
|
||||
|
||||
g_return_val_if_fail (GNC_IS_ACCOUNT(account), FALSE);
|
||||
|
||||
if (gnc_reverse_balance (account))
|
||||
limit_valid = xaccAccountGetLowerBalanceLimit (account, &balance_limit);
|
||||
else
|
||||
limit_valid = xaccAccountGetHigherBalanceLimit (account, &balance_limit);
|
||||
|
||||
if (!limit_valid)
|
||||
return retval;
|
||||
|
||||
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_numeric balance_limit;
|
||||
gboolean limit_valid = FALSE;
|
||||
gboolean retval = FALSE;
|
||||
gint compare_result;
|
||||
|
||||
g_return_val_if_fail (GNC_IS_ACCOUNT(account), FALSE);
|
||||
|
||||
if (gnc_reverse_balance (account))
|
||||
limit_valid = xaccAccountGetHigherBalanceLimit (account, &balance_limit);
|
||||
else
|
||||
limit_valid = xaccAccountGetLowerBalanceLimit (account, &balance_limit);
|
||||
|
||||
if (!limit_valid)
|
||||
return retval;
|
||||
|
||||
if (account_balance_limit_reached (account, balance_limit) == -1)
|
||||
retval = TRUE;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* Balance calculations related to owners
|
||||
|
@ -154,4 +154,24 @@ gchar * gnc_ui_owner_get_print_report_balance (GncOwner *owner,
|
||||
*/
|
||||
GList * gnc_account_get_autoclear_splits (Account *account, gnc_numeric toclear_value,
|
||||
gchar **errmsg);
|
||||
|
||||
/** Test the account balance as of today for it passing the
|
||||
* higher limit if set.
|
||||
*
|
||||
* @param account A pointer to the account.
|
||||
*
|
||||
* @return TRUE if account balance has passed limit.
|
||||
*/
|
||||
gboolean gnc_ui_account_is_higher_balance_limit_reached (const Account *account);
|
||||
|
||||
/** Test the account balance as of today for it passing the
|
||||
* lower limit if set.
|
||||
*
|
||||
* @param account A pointer to the account.
|
||||
*
|
||||
* @return TRUE if account balance has passed limit.
|
||||
*/
|
||||
gboolean gnc_ui_account_is_lower_balance_limit_reached (const Account *account);
|
||||
|
||||
|
||||
#endif /* GNC_UI_BALANCES_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user