mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Allow the balances of sub accounts to be used in limits
This commit is contained in:
parent
841b06940e
commit
a15c6f81b3
@ -111,6 +111,7 @@ typedef struct _AccountWindow
|
||||
GtkWidget *balance_grid;
|
||||
GtkWidget *higher_balance_limit_edit;
|
||||
GtkWidget *lower_balance_limit_edit;
|
||||
GtkWidget *include_balance_sub_accts;
|
||||
gboolean balance_is_reversed;
|
||||
|
||||
GtkWidget *opening_balance_button;
|
||||
@ -336,6 +337,11 @@ gnc_account_to_ui (AccountWindow *aw)
|
||||
|
||||
aw->balance_is_reversed = gnc_reverse_balance (account);
|
||||
|
||||
flag = xaccAccountGetIncludeSubAccountBalances (account);
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(aw->include_balance_sub_accts),
|
||||
flag);
|
||||
|
||||
balance_limit_valid = xaccAccountGetHigherBalanceLimit (account, &balance_limit);
|
||||
if (balance_limit_valid)
|
||||
{
|
||||
@ -433,7 +439,8 @@ gnc_ui_to_account (AccountWindow *aw)
|
||||
gboolean flag;
|
||||
gnc_numeric balance;
|
||||
gnc_numeric balance_limit;
|
||||
gint balance_limit_valid;
|
||||
gint higher_balance_limit_valid;
|
||||
gint lower_balance_limit_valid;
|
||||
gboolean use_equity, nonstd;
|
||||
time64 date;
|
||||
gint index, old_scu, new_scu;
|
||||
@ -546,10 +553,16 @@ gnc_ui_to_account (AccountWindow *aw)
|
||||
if (parent_account != gnc_account_get_parent (account))
|
||||
gnc_account_append_child (parent_account, account);
|
||||
|
||||
balance_limit_valid = gnc_amount_edit_expr_is_valid (GNC_AMOUNT_EDIT(aw->higher_balance_limit_edit),
|
||||
&balance_limit, TRUE, NULL);
|
||||
flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(
|
||||
aw->include_balance_sub_accts));
|
||||
|
||||
if (balance_limit_valid == 0)
|
||||
xaccAccountSetIncludeSubAccountBalances (account, flag);
|
||||
|
||||
higher_balance_limit_valid = gnc_amount_edit_expr_is_valid (GNC_AMOUNT_EDIT(
|
||||
aw->higher_balance_limit_edit),
|
||||
&balance_limit, TRUE, NULL);
|
||||
|
||||
if (higher_balance_limit_valid == 0)
|
||||
{
|
||||
if (aw->balance_is_reversed)
|
||||
{
|
||||
@ -560,7 +573,7 @@ gnc_ui_to_account (AccountWindow *aw)
|
||||
xaccAccountSetHigherBalanceLimit (account, balance_limit);
|
||||
}
|
||||
|
||||
if (balance_limit_valid == -1)
|
||||
if (higher_balance_limit_valid == -1)
|
||||
{
|
||||
if (aw->balance_is_reversed)
|
||||
xaccAccountClearLowerBalanceLimit (account);
|
||||
@ -568,10 +581,11 @@ gnc_ui_to_account (AccountWindow *aw)
|
||||
xaccAccountClearHigherBalanceLimit (account);
|
||||
}
|
||||
|
||||
balance_limit_valid = gnc_amount_edit_expr_is_valid (GNC_AMOUNT_EDIT(aw->lower_balance_limit_edit),
|
||||
&balance_limit, TRUE, NULL);
|
||||
lower_balance_limit_valid = gnc_amount_edit_expr_is_valid (GNC_AMOUNT_EDIT(
|
||||
aw->lower_balance_limit_edit),
|
||||
&balance_limit, TRUE, NULL);
|
||||
|
||||
if (balance_limit_valid == 0)
|
||||
if (lower_balance_limit_valid == 0)
|
||||
{
|
||||
if (aw->balance_is_reversed)
|
||||
{
|
||||
@ -582,7 +596,7 @@ gnc_ui_to_account (AccountWindow *aw)
|
||||
xaccAccountSetLowerBalanceLimit (account, balance_limit);
|
||||
}
|
||||
|
||||
if (balance_limit_valid == -1)
|
||||
if (lower_balance_limit_valid == -1)
|
||||
{
|
||||
if (aw->balance_is_reversed)
|
||||
xaccAccountClearHigherBalanceLimit (account);
|
||||
@ -590,6 +604,9 @@ gnc_ui_to_account (AccountWindow *aw)
|
||||
xaccAccountClearLowerBalanceLimit (account);
|
||||
}
|
||||
|
||||
if ((higher_balance_limit_valid == -1) && (lower_balance_limit_valid == -1))
|
||||
xaccAccountSetIncludeSubAccountBalances (account, FALSE);
|
||||
|
||||
xaccAccountCommitEdit (account);
|
||||
|
||||
balance = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT(aw->opening_balance_edit));
|
||||
@ -1618,6 +1635,8 @@ gnc_account_window_create (GtkWindow *parent, AccountWindow *aw)
|
||||
gnc_amount_edit_show_warning_symbol (GNC_AMOUNT_EDIT(aw->lower_balance_limit_edit), TRUE);
|
||||
gtk_widget_show (aw->lower_balance_limit_edit);
|
||||
|
||||
aw->include_balance_sub_accts = GTK_WIDGET(gtk_builder_get_object (builder, "include_sub_accts_tb"));
|
||||
|
||||
aw->more_properties_page =
|
||||
gtk_notebook_get_nth_page (GTK_NOTEBOOK(aw->notebook), 1);
|
||||
|
||||
@ -2103,14 +2122,6 @@ gnc_ui_edit_account_window (GtkWindow *parent, Account *account)
|
||||
if (xaccAccountGetSplitList (account) != NULL)
|
||||
gtk_widget_hide (aw->opening_balance_page);
|
||||
|
||||
// Note: we are hiding the notebook page here, when other items
|
||||
// are added this will need adjusting.
|
||||
if (gnc_account_n_children (account) > 0)
|
||||
{
|
||||
gtk_widget_hide (GTK_WIDGET(aw->balance_grid));
|
||||
gtk_widget_hide (GTK_WIDGET(aw->more_properties_page));
|
||||
}
|
||||
|
||||
parent_acct = gnc_account_get_parent (account);
|
||||
if (parent_acct == NULL)
|
||||
parent_acct = account; // must be at the root
|
||||
|
@ -1691,7 +1691,7 @@
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">18</property>
|
||||
<child>
|
||||
<!-- n-columns=2 n-rows=3 -->
|
||||
<!-- n-columns=2 n-rows=4 -->
|
||||
<object class="GtkGrid" id="balance_grid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
@ -1783,6 +1783,23 @@ Clear the entry to have no warning.</property>
|
||||
<property name="width">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="include_sub_accts_tb">
|
||||
<property name="label" translatable="yes">_Include sub accounts</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">False</property>
|
||||
<property name="use-underline">True</property>
|
||||
<property name="draw-indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -253,9 +253,13 @@ gnc_ui_account_get_reconciled_balance_as_of_date (Account *account,
|
||||
static gint
|
||||
account_balance_limit_reached (const Account *account, gnc_numeric balance_limit)
|
||||
{
|
||||
gboolean inc_sub = xaccAccountGetIncludeSubAccountBalances (account);
|
||||
|
||||
// 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)));
|
||||
gnc_numeric balance = gnc_ui_account_get_balance_as_of_date (
|
||||
(Account*)account,
|
||||
gnc_time64_get_day_end (gnc_time (NULL)),
|
||||
inc_sub);
|
||||
|
||||
if (gnc_numeric_zero_p (balance))
|
||||
return 0;
|
||||
|
@ -76,6 +76,7 @@ static const std::string AB_TRANS_RETRIEVAL("trans-retrieval");
|
||||
static const std::string KEY_BALANCE_LIMIT("balance-limit");
|
||||
static const std::string KEY_BALANCE_HIGHER_LIMIT_VALUE("higher-value");
|
||||
static const std::string KEY_BALANCE_LOWER_LIMIT_VALUE("lower-value");
|
||||
static const std::string KEY_BALANCE_INCLUDE_SUB_ACCTS("inlude-sub-accts");
|
||||
|
||||
static gnc_numeric GetBalanceAsOfDate (Account *acc, time64 date, gboolean ignclosing);
|
||||
|
||||
@ -336,6 +337,7 @@ gnc_account_init(Account* acc)
|
||||
priv->higher_balance_cached = false;
|
||||
priv->lower_balance_limit = gnc_numeric_create (1,0);
|
||||
priv->lower_balance_cached = false;
|
||||
priv->include_sub_account_balances = TriState::Unset;
|
||||
|
||||
priv->last_num = (char*) is_unset;
|
||||
priv->tax_us_code = (char*) is_unset;
|
||||
@ -5141,6 +5143,47 @@ xaccAccountClearLowerBalanceLimit (Account *acc)
|
||||
clear_balance_limits (acc, false);
|
||||
}
|
||||
|
||||
gboolean
|
||||
xaccAccountGetIncludeSubAccountBalances (const Account *acc)
|
||||
{
|
||||
g_return_val_if_fail (GNC_IS_ACCOUNT(acc), false);
|
||||
|
||||
if (GET_PRIVATE(acc)->include_sub_account_balances == TriState::Unset)
|
||||
{
|
||||
gboolean inc_sub = boolean_from_key (acc, {KEY_BALANCE_LIMIT,
|
||||
KEY_BALANCE_INCLUDE_SUB_ACCTS});
|
||||
|
||||
GET_PRIVATE(acc)->include_sub_account_balances = inc_sub ? TriState::True
|
||||
: TriState::False;
|
||||
}
|
||||
return GET_PRIVATE(acc)->include_sub_account_balances == TriState::True;
|
||||
}
|
||||
|
||||
void
|
||||
xaccAccountSetIncludeSubAccountBalances (Account *acc, gboolean inc_sub)
|
||||
{
|
||||
g_return_if_fail (GNC_IS_ACCOUNT(acc));
|
||||
|
||||
if (inc_sub != xaccAccountGetIncludeSubAccountBalances (acc))
|
||||
{
|
||||
GValue v = G_VALUE_INIT;
|
||||
g_value_init (&v, G_TYPE_BOOLEAN);
|
||||
g_value_set_boolean (&v, inc_sub);
|
||||
std::vector<std::string> path {KEY_BALANCE_LIMIT,
|
||||
KEY_BALANCE_INCLUDE_SUB_ACCTS};
|
||||
xaccAccountBeginEdit (acc);
|
||||
if (inc_sub)
|
||||
qof_instance_set_path_kvp (QOF_INSTANCE(acc), &v, path);
|
||||
else
|
||||
qof_instance_set_path_kvp (QOF_INSTANCE(acc), nullptr, path);
|
||||
GET_PRIVATE(acc)->include_sub_account_balances =
|
||||
inc_sub ? TriState::True : TriState::False;
|
||||
mark_account (acc);
|
||||
xaccAccountCommitEdit (acc);
|
||||
g_value_unset (&v);
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
|
@ -1233,6 +1233,22 @@ typedef enum
|
||||
* @param account The account to clear the limit on
|
||||
*/
|
||||
void xaccAccountClearLowerBalanceLimit (Account *account);
|
||||
|
||||
/** Get whether to include balances of sub accounts.
|
||||
*
|
||||
* @param account The account to get setting on
|
||||
*
|
||||
* @return TRUE to include, default is FALSE
|
||||
*/
|
||||
gboolean xaccAccountGetIncludeSubAccountBalances (const Account *account);
|
||||
|
||||
/** Set whether to include balances of sub accounts.
|
||||
*
|
||||
* @param account The account to set the setting on
|
||||
*
|
||||
* @param include Set to TRUE for including sub account balances
|
||||
*/
|
||||
void xaccAccountSetIncludeSubAccountBalances (Account *account, gboolean include);
|
||||
/** @} */
|
||||
|
||||
/** DOCUMENT ME! */
|
||||
|
@ -125,7 +125,8 @@ typedef struct AccountPrivate
|
||||
gboolean higher_balance_cached;
|
||||
gnc_numeric lower_balance_limit;
|
||||
gboolean lower_balance_cached;
|
||||
|
||||
TriState include_sub_account_balances;
|
||||
|
||||
gboolean balance_dirty; /* balances in splits incorrect */
|
||||
|
||||
GList *splits; /* list of split pointers */
|
||||
|
Loading…
Reference in New Issue
Block a user