547
static gdouble test_sum(Category *catitem, gdouble *total_tab)
549
gdouble totalcat = 0.0;
551
for(gint j=1;j<=12;j++)
553
if(!(catitem->flags & GF_CUSTOM))
555
total_tab[j] += catitem->budget[0];
556
totalcat += catitem->budget[0];
560
total_tab[j] += catitem->budget[j];
561
totalcat += catitem->budget[j];
564
total_tab[0] += totalcat;
570
static void test_total_sum(GtkTreeStore *budget, GtkTreeIter *root, gdouble *total_tab)
572
GtkTreeIter iter, child;
573
gboolean valid, cvalid, cheader, sep;
576
//valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(budget), &iter);
577
valid = gtk_tree_model_iter_children (GTK_TREE_MODEL(budget), &iter, root);
582
gtk_tree_model_get(GTK_TREE_MODEL(budget), &iter,
583
UI_BUD_TABVIEW_CATEGORY_KEY, &key,
584
UI_BUD_TABVIEW_IS_CHILD_HEADER, &cheader,
585
UI_BUD_TABVIEW_IS_SEPARATOR, &sep,
588
if( cheader == FALSE && sep == FALSE )
590
gdouble tmpsum = 0.0;
592
catitem = da_cat_get(key);
593
DB( g_print(" iter: %d %s\n", key, catitem->name) );
594
tmpsum += test_sum(catitem, total_tab);
597
cvalid = gtk_tree_model_iter_children (GTK_TREE_MODEL(budget), &child, &iter);
600
gtk_tree_model_get(GTK_TREE_MODEL(budget), &child,
601
UI_BUD_TABVIEW_CATEGORY_KEY, &ckey,
602
UI_BUD_TABVIEW_IS_CHILD_HEADER, &cheader,
603
UI_BUD_TABVIEW_IS_SEPARATOR, &sep,
606
if( cheader == FALSE && sep == FALSE )
610
catitem = da_cat_get(ckey);
611
DB( g_print(" child: %d %s\n", ckey, catitem->name) );
612
cbudget = test_sum(catitem, total_tab);
618
UI_BUD_TABVIEW_TOTAL, cbudget,
623
cvalid = gtk_tree_model_iter_next(GTK_TREE_MODEL(budget), &child);
629
UI_BUD_TABVIEW_TOTAL, tmpsum,
634
valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(budget), &iter);
545
642
// Update (or insert) total rows for a budget according to the view mode
546
643
// This function will is used to initiate model and to refresh it after change by user
547
644
static void ui_bud_tabview_model_update_monthly_total(GtkTreeStore* budget)
549
646
ui_bud_tabview_search_criteria_t root_search = ui_bud_tabview_search_criteria_default;
550
647
GtkTreeIter total_root, child;
551
double total_income[12] = {0}, total_expense[12] = {0};
552
gboolean cat_is_same_amount;
555
// Go through all categories to compute totals
556
n_category = da_cat_get_max_key();
558
for(guint32 i=1; i<=n_category; ++i)
560
Category *bdg_category;
561
gboolean cat_is_income;
563
bdg_category = da_cat_get(i);
565
if (bdg_category == NULL)
570
cat_is_income = (category_type_get (bdg_category) == 1);
571
cat_is_same_amount = (! (bdg_category->flags & GF_CUSTOM));
573
for (gint j=0; j<=11; ++j)
577
if (cat_is_same_amount)
579
total_income[j] += bdg_category->budget[0];
583
total_income[j] += bdg_category->budget[j+1];
588
if (cat_is_same_amount)
590
total_expense[j] += bdg_category->budget[0];
594
total_expense[j] += bdg_category->budget[j+1];
648
double total_income[13] = {0}, total_expense[13] = {0};
650
// Retrieve required root
651
root_search.row_is_root = TRUE;
652
root_search.row_is_total = FALSE;
654
//#2036404 compute total
655
root_search.row_category_type = UI_BUD_TABVIEW_CAT_TYPE_INCOME;
656
gtk_tree_model_foreach(GTK_TREE_MODEL(budget),
657
(GtkTreeModelForeachFunc) ui_bud_tabview_model_search_iterator,
660
test_total_sum(budget, root_search.iterator, total_income);
662
//#2036404 compute total
663
root_search.row_category_type = UI_BUD_TABVIEW_CAT_TYPE_EXPENSE;
664
gtk_tree_model_foreach(GTK_TREE_MODEL(budget),
665
(GtkTreeModelForeachFunc) ui_bud_tabview_model_search_iterator,
668
test_total_sum(budget, root_search.iterator, total_expense);
600
671
// Retrieve total root and insert required total rows
601
672
root_search.row_is_root = TRUE;
639
710
UI_BUD_TABVIEW_CATEGORY_FULLNAME, _(UI_BUD_TABVIEW_VIEW_MODE[UI_BUD_TABVIEW_VIEW_INCOME]),
640
711
UI_BUD_TABVIEW_CATEGORY_TYPE, UI_BUD_TABVIEW_CAT_TYPE_INCOME,
641
712
UI_BUD_TABVIEW_IS_TOTAL, TRUE,
642
UI_BUD_TABVIEW_JANUARY, total_income[0],
643
UI_BUD_TABVIEW_FEBRUARY, total_income[1],
644
UI_BUD_TABVIEW_MARCH, total_income[2],
645
UI_BUD_TABVIEW_APRIL, total_income[3],
646
UI_BUD_TABVIEW_MAY, total_income[4],
647
UI_BUD_TABVIEW_JUNE, total_income[5],
648
UI_BUD_TABVIEW_JULY, total_income[6],
649
UI_BUD_TABVIEW_AUGUST, total_income[7],
650
UI_BUD_TABVIEW_SEPTEMBER, total_income[8],
651
UI_BUD_TABVIEW_OCTOBER, total_income[9],
652
UI_BUD_TABVIEW_NOVEMBER, total_income[10],
653
UI_BUD_TABVIEW_DECEMBER, total_income[11],
713
UI_BUD_TABVIEW_TOTAL, total_income[0],
714
UI_BUD_TABVIEW_JANUARY, total_income[1],
715
UI_BUD_TABVIEW_FEBRUARY, total_income[2],
716
UI_BUD_TABVIEW_MARCH, total_income[3],
717
UI_BUD_TABVIEW_APRIL, total_income[4],
718
UI_BUD_TABVIEW_MAY, total_income[5],
719
UI_BUD_TABVIEW_JUNE, total_income[6],
720
UI_BUD_TABVIEW_JULY, total_income[7],
721
UI_BUD_TABVIEW_AUGUST, total_income[8],
722
UI_BUD_TABVIEW_SEPTEMBER, total_income[9],
723
UI_BUD_TABVIEW_OCTOBER, total_income[10],
724
UI_BUD_TABVIEW_NOVEMBER, total_income[11],
725
UI_BUD_TABVIEW_DECEMBER, total_income[12],
656
728
// Then look for Expenses
676
748
UI_BUD_TABVIEW_CATEGORY_FULLNAME, _(UI_BUD_TABVIEW_VIEW_MODE[UI_BUD_TABVIEW_VIEW_EXPENSE]),
677
749
UI_BUD_TABVIEW_CATEGORY_TYPE, UI_BUD_TABVIEW_CAT_TYPE_EXPENSE,
678
750
UI_BUD_TABVIEW_IS_TOTAL, TRUE,
679
UI_BUD_TABVIEW_JANUARY, total_expense[0],
680
UI_BUD_TABVIEW_FEBRUARY, total_expense[1],
681
UI_BUD_TABVIEW_MARCH, total_expense[2],
682
UI_BUD_TABVIEW_APRIL, total_expense[3],
683
UI_BUD_TABVIEW_MAY, total_expense[4],
684
UI_BUD_TABVIEW_JUNE, total_expense[5],
685
UI_BUD_TABVIEW_JULY, total_expense[6],
686
UI_BUD_TABVIEW_AUGUST, total_expense[7],
687
UI_BUD_TABVIEW_SEPTEMBER, total_expense[8],
688
UI_BUD_TABVIEW_OCTOBER, total_expense[9],
689
UI_BUD_TABVIEW_NOVEMBER, total_expense[10],
690
UI_BUD_TABVIEW_DECEMBER, total_expense[11],
751
UI_BUD_TABVIEW_TOTAL, total_expense[0],
752
UI_BUD_TABVIEW_JANUARY, total_expense[1],
753
UI_BUD_TABVIEW_FEBRUARY, total_expense[2],
754
UI_BUD_TABVIEW_MARCH, total_expense[3],
755
UI_BUD_TABVIEW_APRIL, total_expense[4],
756
UI_BUD_TABVIEW_MAY, total_expense[5],
757
UI_BUD_TABVIEW_JUNE, total_expense[6],
758
UI_BUD_TABVIEW_JULY, total_expense[7],
759
UI_BUD_TABVIEW_AUGUST, total_expense[8],
760
UI_BUD_TABVIEW_SEPTEMBER, total_expense[9],
761
UI_BUD_TABVIEW_OCTOBER, total_expense[10],
762
UI_BUD_TABVIEW_NOVEMBER, total_expense[11],
763
UI_BUD_TABVIEW_DECEMBER, total_expense[12],
693
766
// Finally, set Balance total row
713
786
UI_BUD_TABVIEW_CATEGORY_FULLNAME, _(UI_BUD_TABVIEW_VIEW_MODE[UI_BUD_TABVIEW_VIEW_SUMMARY]),
714
787
UI_BUD_TABVIEW_CATEGORY_TYPE, UI_BUD_TABVIEW_CAT_TYPE_NONE,
715
788
UI_BUD_TABVIEW_IS_TOTAL, TRUE,
716
UI_BUD_TABVIEW_JANUARY, total_income[0] + total_expense[0],
717
UI_BUD_TABVIEW_FEBRUARY, total_income[1] + total_expense[1],
718
UI_BUD_TABVIEW_MARCH, total_income[2] + total_expense[2],
719
UI_BUD_TABVIEW_APRIL, total_income[3] + total_expense[3],
720
UI_BUD_TABVIEW_MAY, total_income[4] + total_expense[4],
721
UI_BUD_TABVIEW_JUNE, total_income[5] + total_expense[5],
722
UI_BUD_TABVIEW_JULY, total_income[6] + total_expense[6],
723
UI_BUD_TABVIEW_AUGUST, total_income[7] + total_expense[7],
724
UI_BUD_TABVIEW_SEPTEMBER, total_income[8] + total_expense[8],
725
UI_BUD_TABVIEW_OCTOBER, total_income[9] + total_expense[9],
726
UI_BUD_TABVIEW_NOVEMBER, total_income[10] + total_expense[10],
727
UI_BUD_TABVIEW_DECEMBER, total_income[11] + total_expense[11],
789
UI_BUD_TABVIEW_TOTAL, total_income[0] + total_expense[0],
790
UI_BUD_TABVIEW_JANUARY, total_income[1] + total_expense[1],
791
UI_BUD_TABVIEW_FEBRUARY, total_income[2] + total_expense[2],
792
UI_BUD_TABVIEW_MARCH, total_income[3] + total_expense[3],
793
UI_BUD_TABVIEW_APRIL, total_income[4] + total_expense[4],
794
UI_BUD_TABVIEW_MAY, total_income[5] + total_expense[5],
795
UI_BUD_TABVIEW_JUNE, total_income[6] + total_expense[6],
796
UI_BUD_TABVIEW_JULY, total_income[7] + total_expense[7],
797
UI_BUD_TABVIEW_AUGUST, total_income[8] + total_expense[8],
798
UI_BUD_TABVIEW_SEPTEMBER, total_income[9] + total_expense[9],
799
UI_BUD_TABVIEW_OCTOBER, total_income[10] + total_expense[10],
800
UI_BUD_TABVIEW_NOVEMBER, total_income[11] + total_expense[11],
801
UI_BUD_TABVIEW_DECEMBER, total_income[12] + total_expense[12],
730
804
g_free(root_search.iterator);
1126
static void ui_bud_tabview_model_populate (GtkTreeStore *budget)
1128
GtkTreeIter *iter_income, *iter_expense;
1130
ui_bud_tabview_search_criteria_t root_search = ui_bud_tabview_search_criteria_default;
1132
DB( g_print("\n[ui-budget] model populate\n") )
1134
/* Create tree roots */
1135
ui_bud_tabview_model_insert_roots (budget);
1137
// Retrieve required root
1138
root_search.row_is_root = TRUE;
1139
root_search.row_is_total = FALSE;
1141
root_search.row_category_type = UI_BUD_TABVIEW_CAT_TYPE_INCOME;
1142
gtk_tree_model_foreach(GTK_TREE_MODEL(budget),
1143
(GtkTreeModelForeachFunc) ui_bud_tabview_model_search_iterator,
1145
iter_income = root_search.iterator;
1147
root_search.row_category_type = UI_BUD_TABVIEW_CAT_TYPE_EXPENSE;
1148
gtk_tree_model_foreach(GTK_TREE_MODEL(budget),
1149
(GtkTreeModelForeachFunc) ui_bud_tabview_model_search_iterator,
1151
iter_expense = root_search.iterator;
1153
/* Create rows for real categories */
1154
n_category = da_cat_get_max_key();
1156
for(guint32 i=1; i<=n_category; ++i)
1158
Category *bdg_category;
1159
gboolean cat_is_income;
1161
bdg_category = da_cat_get(i);
1163
if (bdg_category == NULL)
1168
cat_is_income = (category_type_get (bdg_category) == 1);
1170
DB(g_print(" category %d:'%s' isincome=%d, issub=%d hasbudget=%d parent=%d\n",
1171
bdg_category->key, bdg_category->name,
1172
cat_is_income, (bdg_category->flags & GF_SUB),
1173
(bdg_category->flags & GF_BUDGET), bdg_category->parent));
1175
// Compute totals and initiate category in right tree root
1178
ui_bud_tabview_model_add_category_with_lineage(budget, iter_income, &(bdg_category->key));
1180
else if (!cat_is_income)
1182
ui_bud_tabview_model_add_category_with_lineage(budget, iter_expense, &(bdg_category->key));
1186
/* Create rows for total root */
1187
ui_bud_tabview_model_update_monthly_total(GTK_TREE_STORE(budget));
1189
g_free(root_search.iterator);
1051
1193
// the budget model creation
1052
1194
static GtkTreeModel * ui_bud_tabview_model_new ()
1054
1196
GtkTreeStore *budget;
1055
GtkTreeIter *iter_income, *iter_expense;
1057
ui_bud_tabview_search_criteria_t root_search = ui_bud_tabview_search_criteria_default;
1059
1198
// Create Tree Store
1060
1199
budget = gtk_tree_store_new ( UI_BUD_TABVIEW_NUMBER_COLOMNS,
1088
1228
// Populate the store
1090
/* Create tree roots */
1091
ui_bud_tabview_model_insert_roots (budget);
1093
// Retrieve required root
1094
root_search.row_is_root = TRUE;
1095
root_search.row_is_total = FALSE;
1097
root_search.row_category_type = UI_BUD_TABVIEW_CAT_TYPE_INCOME;
1098
gtk_tree_model_foreach(GTK_TREE_MODEL(budget),
1099
(GtkTreeModelForeachFunc) ui_bud_tabview_model_search_iterator,
1101
iter_income = root_search.iterator;
1103
root_search.row_category_type = UI_BUD_TABVIEW_CAT_TYPE_EXPENSE;
1104
gtk_tree_model_foreach(GTK_TREE_MODEL(budget),
1105
(GtkTreeModelForeachFunc) ui_bud_tabview_model_search_iterator,
1107
iter_expense = root_search.iterator;
1109
/* Create rows for real categories */
1110
n_category = da_cat_get_max_key();
1112
for(guint32 i=1; i<=n_category; ++i)
1114
Category *bdg_category;
1115
gboolean cat_is_income;
1117
bdg_category = da_cat_get(i);
1119
if (bdg_category == NULL)
1124
cat_is_income = (category_type_get (bdg_category) == 1);
1126
DB(g_print(" category %d:'%s' isincome=%d, issub=%d hasbudget=%d parent=%d\n",
1127
bdg_category->key, bdg_category->name,
1128
cat_is_income, (bdg_category->flags & GF_SUB),
1129
(bdg_category->flags & GF_BUDGET), bdg_category->parent));
1131
// Compute totals and initiate category in right tree root
1134
ui_bud_tabview_model_add_category_with_lineage(budget, iter_income, &(bdg_category->key));
1136
else if (!cat_is_income)
1138
ui_bud_tabview_model_add_category_with_lineage(budget, iter_expense, &(bdg_category->key));
1142
/* Create rows for total root */
1143
ui_bud_tabview_model_update_monthly_total(GTK_TREE_STORE(budget));
1229
ui_bud_tabview_model_populate(budget);
1145
1231
/* Sort categories on same node level */
1146
1232
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE(budget),
1190
1274
// Display category name in bold if it has budget
1191
1275
static void ui_bud_tabview_view_display_category_name (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
1193
ui_bud_tabview_data_t *data = user_data;
1277
//ui_bud_tabview_data_t *data = user_data;
1194
1278
gboolean has_budget, is_sub_category;
1195
1279
PangoWeight weight = PANGO_WEIGHT_NORMAL;
1196
ui_bud_tabview_view_mode_t view_mode = UI_BUD_TABVIEW_VIEW_SUMMARY;
1280
//ui_bud_tabview_view_mode_t view_mode = UI_BUD_TABVIEW_VIEW_SUMMARY;
1198
1282
gtk_tree_model_get(model, iter,
1199
1283
UI_BUD_TABVIEW_IS_SUB_CATEGORY, &is_sub_category,
1200
1284
UI_BUD_TABVIEW_HAS_BUDGET, &has_budget,
1203
view_mode = hbtk_switcher_get_active (HBTK_SWITCHER(data->RA_mode));
1287
//view_mode = hbtk_switcher_get_active (HBTK_SWITCHER(data->RA_mode));
1205
if (view_mode != UI_BUD_TABVIEW_VIEW_SUMMARY && has_budget)
1289
//if (view_mode != UI_BUD_TABVIEW_VIEW_SUMMARY && has_budget)
1207
1292
weight = PANGO_WEIGHT_BOLD;
1340
1425
// Compute dynamically the annual total
1341
1426
static void ui_bud_tabview_view_display_annual_total (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
1343
gboolean is_same_amount = FALSE, is_total = FALSE, is_root = FALSE;
1344
gdouble amount = 0.0;
1345
gdouble total = 0.0;
1428
gboolean is_root = FALSE;
1347
1430
gchar *fgcolor;
1348
1431
gboolean is_visible = TRUE;
1350
1435
gtk_tree_model_get(model, iter,
1351
1436
UI_BUD_TABVIEW_IS_ROOT, &is_root,
1352
UI_BUD_TABVIEW_IS_SAME_AMOUNT, &is_same_amount,
1353
UI_BUD_TABVIEW_SAME_AMOUNT, &amount,
1354
UI_BUD_TABVIEW_IS_TOTAL, &is_total,
1437
//UI_BUD_TABVIEW_IS_SAME_AMOUNT, &is_same_amount,
1438
//UI_BUD_TABVIEW_SAME_AMOUNT, &amount,
1439
//UI_BUD_TABVIEW_IS_TOTAL, &is_total,
1440
UI_BUD_TABVIEW_TOTAL, &celltotal,
1443
/*if (is_same_amount)
1359
1445
total = 12.0 * amount;