Add two columns to the Accounts page: "Total (Period)" & "Balance (Period)"

These are the recursive and non-recursive, respectively, period balances,
   where the accounting period is specified in the preferences.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13165 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Chris Shoemaker 2006-02-09 04:53:43 +00:00
parent 0d046e26d5
commit 1b418bfeec

View File

@ -45,6 +45,7 @@
#include "gnc-icons.h"
#include "gnc-ui-util.h"
#include "dialog-utils.h"
#include "window-main-summarybar.h"
#define SAMPLE_ACCOUNT_VALUE "$1,000,000.00"
@ -337,6 +338,45 @@ sort_by_placeholder (GtkTreeModel *f_model,
return 1;
}
#define RECURSE GINT_TO_POINTER(1)
static void
cdf_period(GtkTreeViewColumn *col, GtkCellRenderer *cell,
GtkTreeModel *s_model, GtkTreeIter *iter, gpointer data)
{
Account *acct;
time_t t1, t2;
const char *str;
g_return_if_fail(GTK_TREE_VIEW_COLUMN(col));
g_return_if_fail(GTK_CELL_RENDERER(cell));
g_return_if_fail(GTK_TREE_MODEL_SORT(s_model));
acct = gnc_tree_view_account_get_account_from_iter(s_model, iter);
t1 = gnc_main_window_summary_get_start();
t2 = gnc_main_window_summary_get_end();
if (t2 > t1) {
GValue *value;
gnc_numeric b1, b2, b3;
g_value_init (value, G_TYPE_STRING);
if (data == RECURSE) {
b1 = xaccAccountGetBalanceAsOfDateInCurrency(acct, t1, NULL, TRUE);
b2 = xaccAccountGetBalanceAsOfDateInCurrency(acct, t2, NULL, TRUE);
} else {
b1 = xaccAccountGetBalanceAsOfDate(acct, t1);
b2 = xaccAccountGetBalanceAsOfDate(acct, t2);
}
b3 = gnc_numeric_sub(b2, b1, GNC_DENOM_AUTO, GNC_HOW_DENOM_FIXED);
if (gnc_reverse_balance (acct))
b3 = gnc_numeric_neg (b3);
str = xaccPrintAmount(b3, gnc_account_print_info(acct, TRUE));
} else str = "";
g_object_set(cell, "text", str, NULL);
}
/************************************************************/
/* New View Creation */
@ -445,6 +485,17 @@ gnc_tree_view_account_new_with_group (AccountGroup *group, gboolean show_root)
GNC_TREE_MODEL_ACCOUNT_COL_COLOR_BALANCE,
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
sort_by_balance_value);
{
GtkTreeViewColumn *col = gnc_tree_view_add_numeric_column(
view, _("Balance (Period)"), "balance-period", SAMPLE_ACCOUNT_VALUE,
GNC_TREE_VIEW_COLUMN_DATA_NONE, GNC_TREE_VIEW_COLUMN_COLOR_NONE,
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS, NULL);
GtkCellRenderer *cr = gnc_tree_view_column_get_renderer(col);
gtk_tree_view_column_set_cell_data_func(
col, cr, cdf_period, NULL, NULL);
}
gnc_tree_view_add_numeric_column(view, _("Cleared"), "cleared",
SAMPLE_ACCOUNT_VALUE,
GNC_TREE_MODEL_ACCOUNT_COL_CLEARED,
@ -493,6 +544,16 @@ gnc_tree_view_account_new_with_group (AccountGroup *group, gboolean show_root)
GNC_TREE_MODEL_ACCOUNT_COL_COLOR_TOTAL,
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
sort_by_total_value);
{
GtkTreeViewColumn *col = gnc_tree_view_add_numeric_column(
view, _("Total (Period)"), "total-period", SAMPLE_ACCOUNT_VALUE,
GNC_TREE_VIEW_COLUMN_DATA_NONE, GNC_TREE_VIEW_COLUMN_COLOR_NONE,
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS, NULL);
GtkCellRenderer *cr = gnc_tree_view_column_get_renderer(col);
gtk_tree_view_column_set_cell_data_func(
col, cr, cdf_period, RECURSE, NULL);
}
priv->notes_column
= gnc_tree_view_add_text_column(view, _("Notes"), "notes", NULL,
"Sample account notes.",