[gnc-budget-view.c] much simpler negation rule: always negate.

previously negation was dependent on the row type and account
type. this change will modify the rule to *always* negate the total
amount prior to rendering.

this is because budget amounts are now natural numbers, i.e. budget
income usually negative, budget expense usually positive. the total of
budget amounts in a period (asset+liability+income+expense+equity)
should be zero.

the compulsory negation will ensure the budget equation is now much
more intuitive, i.e. an income *adds* to the budget, and an
expense *deducts* from budget; the "remaining to budget" is thus
positive if there is unallocated budget.
This commit is contained in:
Christopher Lam
2023-05-21 23:48:54 +08:00
parent b0292d7893
commit 66f4b4c2ae

View File

@@ -1219,9 +1219,6 @@ bgv_get_total_for_account (Account *account, GncBudget *budget, gnc_commodity *n
}
}
if (gnc_reverse_balance (account))
total = gnc_numeric_neg (total);
return total;
}
@@ -1317,7 +1314,6 @@ totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
gint period_num;
gnc_numeric value; // used to assist in adding and subtracting
gchar amtbuff[100]; //FIXME: overkill, where's the #define?
gboolean neg;
GNCPriceDB *pdb;
gnc_commodity *total_currency, *currency;
gnc_numeric total = gnc_numeric_zero ();
@@ -1342,8 +1338,6 @@ totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
currency = gnc_account_get_currency_or_parent (account);
acctype = xaccAccountTypeGetFundamental (xaccAccountGetType (account));
neg = gnc_reverse_balance (account);
switch (row_type)
{
case TOTALS_TYPE_ASSET_LIAB_EQ:
@@ -1351,7 +1345,6 @@ totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
(acctype != ACCT_TYPE_LIABILITY) &&
(acctype != ACCT_TYPE_EQUITY))
continue;
neg = !neg;
break;
case TOTALS_TYPE_EXPENSES:
if (acctype != ACCT_TYPE_EXPENSE)
@@ -1360,10 +1353,8 @@ totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
case TOTALS_TYPE_INCOME:
if (acctype != ACCT_TYPE_INCOME)
continue;
neg = !neg;
break;
case TOTALS_TYPE_REMAINDER:
neg = !neg;
break;
default:
continue; /* don't count if unexpected total row type is passed in... */
@@ -1383,12 +1374,14 @@ totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
gnc_budget_get_period_start_date (priv->budget, period_num));
}
if (neg)
value = gnc_numeric_neg (value);
total = gnc_numeric_add (total, value, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
}
/* because we want income to be positive, expense and transfer to
be negative. i.e. income adds to the budget, expense and
transfer deducts from budget */
total = gnc_numeric_neg (total);
xaccSPrintAmount (amtbuff, total,
gnc_commodity_print_info (total_currency,
period_num < 0 ? TRUE : FALSE));