~mdoyen/homebank/5.8.x

« back to all changes in this revision

Viewing changes to src/ui-budget-tabview.c

  • Committer: Maxime Doyen
  • Date: 2024-10-04 16:03:54 UTC
  • Revision ID: homebank@free.fr-20241004160354-br2eh82qvga8kztk
5.8.4 release

Show diffs side-by-side

added added

removed removed

Lines of Context:
125
125
        UI_BUD_TABVIEW_IS_SAME_AMOUNT,
126
126
        UI_BUD_TABVIEW_IS_SUB_CATEGORY,
127
127
        UI_BUD_TABVIEW_HAS_BUDGET,
 
128
 
 
129
        UI_BUD_TABVIEW_TOTAL,
128
130
        UI_BUD_TABVIEW_SAME_AMOUNT,
129
131
        UI_BUD_TABVIEW_JANUARY,
130
132
        UI_BUD_TABVIEW_FEBRUARY,
302
304
        {
303
305
                if (parent_search.iterator)
304
306
                {
305
 
                        DB(g_print("\tRecursion optimisation: parent key %d already exists\n", parent_search.row_category_key));
 
307
                        DB(g_print("  Recursion optimisation: parent key %d already exists\n", parent_search.row_category_key));
306
308
                        // If parent already exists, stop recursion
307
309
                        parent = parent_search.iterator;
308
310
                }
326
328
                        -1);
327
329
        }
328
330
 
329
 
        DB(g_print("insert new category %s (key: %d, type: %d)\n",
330
 
                bdg_category->name, bdg_category->key, category_type_get (bdg_category)));
 
331
        DB(g_print(" >insert '%s'\n", bdg_category->fullname));
331
332
 
332
333
        gtk_tree_store_set(
333
334
                budget,
542
543
        return;
543
544
}
544
545
 
 
546
 
 
547
static gdouble test_sum(Category *catitem, gdouble *total_tab)
 
548
{
 
549
gdouble totalcat = 0.0;
 
550
 
 
551
        for(gint j=1;j<=12;j++)
 
552
        {
 
553
                if(!(catitem->flags & GF_CUSTOM))
 
554
                {
 
555
                        total_tab[j] += catitem->budget[0];
 
556
                        totalcat += catitem->budget[0];
 
557
                }
 
558
                else
 
559
                {
 
560
                        total_tab[j] += catitem->budget[j];
 
561
                        totalcat += catitem->budget[j];
 
562
                }
 
563
        }
 
564
        total_tab[0] += totalcat;
 
565
        return totalcat;
 
566
}
 
567
 
 
568
 
 
569
 
 
570
static void test_total_sum(GtkTreeStore *budget, GtkTreeIter *root, gdouble *total_tab)
 
571
{
 
572
GtkTreeIter iter, child;
 
573
gboolean valid, cvalid, cheader, sep;
 
574
guint32 key, ckey;
 
575
 
 
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);
 
578
        while (valid)
 
579
        {
 
580
        Category *catitem;
 
581
 
 
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,
 
586
                        -1);
 
587
 
 
588
                if( cheader == FALSE && sep == FALSE )
 
589
                {
 
590
                gdouble tmpsum = 0.0;
 
591
 
 
592
                        catitem = da_cat_get(key);
 
593
                        DB( g_print(" iter: %d %s\n", key, catitem->name) );
 
594
                        tmpsum += test_sum(catitem, total_tab);
 
595
 
 
596
                        // children ?
 
597
                        cvalid = gtk_tree_model_iter_children (GTK_TREE_MODEL(budget), &child, &iter);
 
598
                        while (cvalid)
 
599
                        {
 
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,
 
604
                                        -1);
 
605
 
 
606
                                if( cheader == FALSE && sep == FALSE )
 
607
                                {
 
608
                                gdouble cbudget;
 
609
 
 
610
                                        catitem = da_cat_get(ckey);
 
611
                                        DB( g_print(" child: %d %s\n", ckey, catitem->name) );
 
612
                                        cbudget = test_sum(catitem, total_tab);
 
613
 
 
614
                                        tmpsum += cbudget;
 
615
                                        gtk_tree_store_set (
 
616
                                                budget,
 
617
                                                &child,
 
618
                                                UI_BUD_TABVIEW_TOTAL, cbudget,
 
619
                                                -1);
 
620
 
 
621
                                }
 
622
 
 
623
                                cvalid = gtk_tree_model_iter_next(GTK_TREE_MODEL(budget), &child);
 
624
                        }
 
625
 
 
626
                        gtk_tree_store_set (
 
627
                                budget,
 
628
                                &iter,
 
629
                                UI_BUD_TABVIEW_TOTAL, tmpsum,
 
630
                                -1);
 
631
 
 
632
                }
 
633
 
 
634
                valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(budget), &iter);
 
635
        }
 
636
 
 
637
 
 
638
}
 
639
 
 
640
 
 
641
 
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)
548
645
{
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;
553
 
guint32 n_category;
554
 
 
555
 
        // Go through all categories to compute totals
556
 
        n_category = da_cat_get_max_key();
557
 
 
558
 
        for(guint32 i=1; i<=n_category; ++i)
559
 
        {
560
 
        Category *bdg_category;
561
 
        gboolean cat_is_income;
562
 
 
563
 
                bdg_category = da_cat_get(i);
564
 
 
565
 
                if (bdg_category == NULL)
566
 
                {
567
 
                        continue;
568
 
                }
569
 
 
570
 
                cat_is_income = (category_type_get (bdg_category) == 1);
571
 
                cat_is_same_amount = (! (bdg_category->flags & GF_CUSTOM));
572
 
 
573
 
                for (gint j=0; j<=11; ++j)
574
 
                {
575
 
                        if (cat_is_income)
576
 
                        {
577
 
                                if (cat_is_same_amount)
578
 
                                {
579
 
                                        total_income[j] += bdg_category->budget[0];
580
 
                                }
581
 
                                else
582
 
                                {
583
 
                                        total_income[j] += bdg_category->budget[j+1];
584
 
                                }
585
 
                        }
586
 
                        else
587
 
                        {
588
 
                                if (cat_is_same_amount)
589
 
                                {
590
 
                                        total_expense[j] += bdg_category->budget[0];
591
 
                                }
592
 
                                else
593
 
                                {
594
 
                                        total_expense[j] += bdg_category->budget[j+1];
595
 
                                }
596
 
                        }
597
 
                }
598
 
        }
 
648
double total_income[13] = {0}, total_expense[13] = {0};
 
649
 
 
650
        // Retrieve required root
 
651
        root_search.row_is_root = TRUE;
 
652
        root_search.row_is_total = FALSE;
 
653
 
 
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,
 
658
                &root_search);
 
659
 
 
660
        test_total_sum(budget, root_search.iterator, total_income);
 
661
 
 
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,
 
666
                &root_search);
 
667
 
 
668
        test_total_sum(budget, root_search.iterator, total_expense);
 
669
 
599
670
 
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],
654
726
                -1);
655
727
 
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],
691
764
                -1);
692
765
 
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],
728
802
                -1);
729
803
 
730
804
        g_free(root_search.iterator);
1048
1122
        return order;
1049
1123
}
1050
1124
 
 
1125
 
 
1126
static void ui_bud_tabview_model_populate (GtkTreeStore *budget)
 
1127
{
 
1128
GtkTreeIter *iter_income, *iter_expense;
 
1129
guint32 n_category;
 
1130
ui_bud_tabview_search_criteria_t root_search = ui_bud_tabview_search_criteria_default;
 
1131
 
 
1132
        DB( g_print("\n[ui-budget] model populate\n") )
 
1133
 
 
1134
        /* Create tree roots */
 
1135
        ui_bud_tabview_model_insert_roots (budget);
 
1136
 
 
1137
        // Retrieve required root
 
1138
        root_search.row_is_root = TRUE;
 
1139
        root_search.row_is_total = FALSE;
 
1140
 
 
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,
 
1144
                &root_search);
 
1145
        iter_income = root_search.iterator;
 
1146
 
 
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,
 
1150
                &root_search);
 
1151
        iter_expense = root_search.iterator;
 
1152
 
 
1153
        /* Create rows for real categories */
 
1154
        n_category = da_cat_get_max_key();
 
1155
 
 
1156
        for(guint32 i=1; i<=n_category; ++i)
 
1157
        {
 
1158
        Category *bdg_category;
 
1159
        gboolean cat_is_income;
 
1160
 
 
1161
                bdg_category = da_cat_get(i);
 
1162
 
 
1163
                if (bdg_category == NULL)
 
1164
                {
 
1165
                        continue;
 
1166
                }
 
1167
 
 
1168
                cat_is_income = (category_type_get (bdg_category) == 1);
 
1169
 
 
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));
 
1174
 
 
1175
                // Compute totals and initiate category in right tree root
 
1176
                if (cat_is_income)
 
1177
                {
 
1178
                        ui_bud_tabview_model_add_category_with_lineage(budget, iter_income, &(bdg_category->key));
 
1179
                }
 
1180
                else if (!cat_is_income)
 
1181
                {
 
1182
                        ui_bud_tabview_model_add_category_with_lineage(budget, iter_expense, &(bdg_category->key));
 
1183
                }
 
1184
        }
 
1185
 
 
1186
        /* Create rows for total root */
 
1187
        ui_bud_tabview_model_update_monthly_total(GTK_TREE_STORE(budget));
 
1188
 
 
1189
        g_free(root_search.iterator);
 
1190
}
 
1191
 
 
1192
 
1051
1193
// the budget model creation
1052
1194
static GtkTreeModel * ui_bud_tabview_model_new ()
1053
1195
{
1054
1196
GtkTreeStore *budget;
1055
 
GtkTreeIter *iter_income, *iter_expense;
1056
 
guint32 n_category;
1057
 
ui_bud_tabview_search_criteria_t root_search = ui_bud_tabview_search_criteria_default;
1058
1197
 
1059
1198
        // Create Tree Store
1060
1199
        budget = gtk_tree_store_new ( UI_BUD_TABVIEW_NUMBER_COLOMNS,
1070
1209
                G_TYPE_BOOLEAN, // UI_BUD_TABVIEW_IS_SAME_AMOUNT
1071
1210
                G_TYPE_BOOLEAN, // UI_BUD_TABVIEW_IS_SUB_CATEGORY
1072
1211
                G_TYPE_BOOLEAN, // UI_BUD_TABVIEW_HAS_BUDGET
 
1212
                G_TYPE_DOUBLE, // UI_BUD_TABVIEW_TOTAL
1073
1213
                G_TYPE_DOUBLE, // UI_BUD_TABVIEW_SAME_AMOUNT
1074
1214
                G_TYPE_DOUBLE, // UI_BUD_TABVIEW_JANUARY
1075
1215
                G_TYPE_DOUBLE, // UI_BUD_TABVIEW_FEBRUARY
1086
1226
        );
1087
1227
 
1088
1228
        // Populate the store
1089
 
 
1090
 
        /* Create tree roots */
1091
 
        ui_bud_tabview_model_insert_roots (budget);
1092
 
 
1093
 
        // Retrieve required root
1094
 
        root_search.row_is_root = TRUE;
1095
 
        root_search.row_is_total = FALSE;
1096
 
 
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,
1100
 
                &root_search);
1101
 
        iter_income = root_search.iterator;
1102
 
 
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,
1106
 
                &root_search);
1107
 
        iter_expense = root_search.iterator;
1108
 
 
1109
 
        /* Create rows for real categories */
1110
 
        n_category = da_cat_get_max_key();
1111
 
 
1112
 
        for(guint32 i=1; i<=n_category; ++i)
1113
 
        {
1114
 
        Category *bdg_category;
1115
 
        gboolean cat_is_income;
1116
 
 
1117
 
                bdg_category = da_cat_get(i);
1118
 
 
1119
 
                if (bdg_category == NULL)
1120
 
                {
1121
 
                        continue;
1122
 
                }
1123
 
 
1124
 
                cat_is_income = (category_type_get (bdg_category) == 1);
1125
 
 
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));
1130
 
 
1131
 
                // Compute totals and initiate category in right tree root
1132
 
                if (cat_is_income)
1133
 
                {
1134
 
                        ui_bud_tabview_model_add_category_with_lineage(budget, iter_income, &(bdg_category->key));
1135
 
                }
1136
 
                else if (!cat_is_income)
1137
 
                {
1138
 
                        ui_bud_tabview_model_add_category_with_lineage(budget, iter_expense, &(bdg_category->key));
1139
 
                }
1140
 
        }
1141
 
 
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);
1144
1230
 
1145
1231
        /* Sort categories on same node level */
1146
1232
        gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE(budget),
1149
1235
        gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (budget),
1150
1236
                UI_BUD_TABVIEW_CATEGORY_NAME, GTK_SORT_ASCENDING);
1151
1237
 
1152
 
        g_free(root_search.iterator);
1153
 
 
1154
1238
        return GTK_TREE_MODEL(budget);
1155
1239
}
1156
1240
 
 
1241
 
1157
1242
/**
1158
1243
 * GtkTreeView functions
1159
1244
 **/
1160
 
 
1161
1245
static void ui_bud_tabview_icon_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
1162
1246
{
1163
 
ui_bud_tabview_data_t *data = user_data;
 
1247
//ui_bud_tabview_data_t *data = user_data;
1164
1248
gchar *iconname = NULL;
1165
1249
gboolean has_budget, is_monitoring_forced;
1166
1250
ui_bud_tabview_view_mode_t view_mode = UI_BUD_TABVIEW_VIEW_SUMMARY;
1170
1254
        UI_BUD_TABVIEW_HAS_BUDGET, &has_budget,
1171
1255
        -1);
1172
1256
 
1173
 
        view_mode = hbtk_switcher_get_active (HBTK_SWITCHER(data->RA_mode));
 
1257
        //view_mode = hbtk_switcher_get_active (HBTK_SWITCHER(data->RA_mode));
1174
1258
 
1175
1259
        //5.3 added
1176
1260
        if( is_monitoring_forced )
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)
1192
1276
{
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;
1197
1281
 
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,
1201
1285
                -1);
1202
1286
 
1203
 
        view_mode = hbtk_switcher_get_active (HBTK_SWITCHER(data->RA_mode));
 
1287
        //view_mode = hbtk_switcher_get_active (HBTK_SWITCHER(data->RA_mode));
1204
1288
 
1205
 
        if (view_mode != UI_BUD_TABVIEW_VIEW_SUMMARY && has_budget)
 
1289
        //if (view_mode != UI_BUD_TABVIEW_VIEW_SUMMARY && has_budget)
 
1290
        if (has_budget)
1206
1291
        {
1207
1292
                weight = PANGO_WEIGHT_BOLD;
1208
1293
        }
1311
1396
// to enable or not edition on month columns
1312
1397
static void ui_bud_tabview_view_display_is_same_amount (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
1313
1398
{
1314
 
gboolean is_same_amount, is_root, is_total, is_visible, is_sensitive;
 
1399
gboolean is_same_amount, is_total, is_root, is_visible, is_sensitive;
1315
1400
 
1316
1401
        gtk_tree_model_get(model, iter,
1317
1402
                UI_BUD_TABVIEW_IS_ROOT, &is_root,
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)
1342
1427
{
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;
1346
1429
gchar *text;
1347
1430
gchar *fgcolor;
1348
1431
gboolean is_visible = TRUE;
 
1432
gdouble celltotal;
 
1433
                
1349
1434
 
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,
1355
1441
                -1);
1356
1442
 
1357
 
        if (is_same_amount)
 
1443
        /*if (is_same_amount)
1358
1444
        {
1359
1445
                total = 12.0 * amount;
1360
1446
        }
1367
1453
                }
1368
1454
        }
1369
1455
 
1370
 
        text = g_strdup_printf("%.2f", total);
1371
 
        fgcolor = get_normal_color_amount(total);
 
1456
        text = g_strdup_printf("%.2f // %.2f", total, celltotal);*/
 
1457
        text = g_strdup_printf("%.2f", celltotal);
 
1458
        fgcolor = get_normal_color_amount(celltotal);
1372
1459
 
1373
1460
        if (is_root)
1374
1461
        {
1377
1464
 
1378
1465
        // Finally, visibility depends on set amount
1379
1466
        //is_visible = (is_visible && amount != 0.0);
 
1467
 
1380
1468
        //#1859275 visibility to be tested on total
1381
 
        is_visible = (is_visible && total != 0.0);
 
1469
        is_visible = (is_visible && celltotal != 0.0);
 
1470
 
1382
1471
 
1383
1472
        g_object_set(renderer,
1384
1473
                "text", text,
1394
1483
static void ui_bud_tabview_view_display_monthly_average(GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
1395
1484
{
1396
1485
gboolean is_same_amount = FALSE, is_total = FALSE, is_root = FALSE;
1397
 
gdouble amount = 0.0;
 
1486
gdouble amount = 0.0, celltotal;
1398
1487
gdouble average = 0.0;
1399
1488
gchar *text;
1400
1489
gchar *fgcolor;
1405
1494
                UI_BUD_TABVIEW_IS_SAME_AMOUNT, &is_same_amount,
1406
1495
                UI_BUD_TABVIEW_SAME_AMOUNT, &amount,
1407
1496
                UI_BUD_TABVIEW_IS_TOTAL, &is_total,
 
1497
                UI_BUD_TABVIEW_TOTAL, &celltotal,
1408
1498
                -1);
1409
1499
 
1410
 
        if (is_same_amount)
 
1500
        /*if (is_same_amount)
1411
1501
        {
1412
1502
                average = amount;
1413
1503
        }
1419
1509
                        average += amount;
1420
1510
                }
1421
1511
                average = hb_amount_round(average / 12.0, 2);
1422
 
        }
 
1512
        }*/
 
1513
 
 
1514
        average = hb_amount_round(celltotal / 12.0, 2);
1423
1515
 
1424
1516
        text = g_strdup_printf("%.2f", average);
1425
1517
        fgcolor = get_normal_color_amount(average);