[grisbi-cvs] grisbi/src balance_estimate_data.c, 1.5, 1.6 balance_estimate_data.h, 1.4, 1.5 balance_estimate_hist.c, 1.2, 1.3 balance_estimate_hist.h, 1.2, 1.3 balance_estimate_tab.c, 1.42, 1.43 gsb_file_save.c, 1.150, 1.151

Pierre Biava pbiava at users.sourceforge.net
Sat Feb 20 23:19:48 CET 2010


Update of /cvsroot/grisbi/grisbi/src
In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv16134/src

Modified Files:
	balance_estimate_data.c balance_estimate_data.h 
	balance_estimate_hist.c balance_estimate_hist.h 
	balance_estimate_tab.c gsb_file_save.c 
Log Message:
additions to the budget module

Index: gsb_file_save.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_file_save.c,v
retrieving revision 1.150
retrieving revision 1.151
diff -u -d -r1.150 -r1.151
--- gsb_file_save.c	15 Feb 2010 18:35:08 -0000	1.150
+++ gsb_file_save.c	20 Feb 2010 22:19:46 -0000	1.151
@@ -34,6 +34,7 @@
 /*START_INCLUDE*/
 #include "gsb_file_save.h"
 #include "./dialog.h"
+#include "./balance_estimate_data.h"
 #include "./gsb_data_account.h"
 #include "./gsb_data_archive.h"
 #include "./gsb_data_bank.h"
@@ -2608,6 +2609,7 @@
                         gchar **file_content )
 {
     gchar *new_string;
+    GString *lignes;
 
     /* save the general informations */
     new_string = g_markup_printf_escaped ( "\t<Bet\n"
@@ -2617,7 +2619,7 @@
                         "\t\tNbre=\"%d\"\n"
                         "\t\tUT=\"%d\"\n"
                         "\t\tSD=\"%d\"\n"
-                        "\t\tFi=\"%d\" />\n",
+                        "\t\tFi=\"%d\"\n",
     etat.bet_last_account,
     etat.bet_deb_period,
     etat.bet_end_period,
@@ -2626,6 +2628,9 @@
     etat.bet_hist_data,
     etat.bet_hist_fyear );
 
+    lignes = bet_data_get_strings_to_save ( );
+    new_string = g_strconcat ( new_string, lignes -> str, "\t\t/>\n", NULL );
+
     /* append the new string to the file content
      * and return the new iterator */
 

Index: balance_estimate_data.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/balance_estimate_data.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- balance_estimate_data.h	20 Feb 2010 08:54:00 -0000	1.4
+++ balance_estimate_data.h	20 Feb 2010 22:19:46 -0000	1.5
@@ -39,8 +39,11 @@
 gchar *bet_data_get_div_name (gint div_num,
                         gint sub_div,
                         const gchar *return_value_error );
+gboolean bet_data_get_div_edited ( gint account_nb, gint div_number, gint sub_div_nb );
 gboolean bet_data_get_div_full ( gint account_nb, gint div_number );
 gint bet_data_get_div_number ( gint transaction_number, gboolean is_transaction );
+gint bet_data_get_selected_currency ( void );
+GString *bet_data_get_strings_to_save ( void );
 gint bet_data_get_sub_div_nb ( gint transaction_number, gboolean is_transaction );
 gboolean bet_data_init_variables ( void );
 gboolean bet_data_populate_div ( gint transaction_number,
@@ -52,9 +55,13 @@
                         gint div_number,
                         gint sub_div_nb,
                         gsb_real amount );
+gboolean bet_data_set_div_edited ( gint account_nb,
+                        gint div_number,
+                        gint sub_div_nb,
+                        gboolean edited );
 gboolean bet_data_set_div_full ( gint account_nb, gint div_number, gboolean full );
 gboolean bet_data_set_div_ptr ( gint type_div );
-
+void bet_data_synchronise_hist_div_list ( GHashTable  *list_div );
 SBR *initialise_struct_bet_range ( void );
 SH *initialise_struct_historical ( void );
 void free_struct_bet_range ( SBR *sbr );

Index: balance_estimate_hist.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/balance_estimate_hist.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- balance_estimate_hist.h	20 Feb 2010 08:54:00 -0000	1.2
+++ balance_estimate_hist.h	20 Feb 2010 22:19:46 -0000	1.3
@@ -35,11 +35,13 @@
     SPP_HISTORICAL_PERIOD_COLUMN,
     SPP_HISTORICAL_BALANCE_COLUMN,
     SPP_HISTORICAL_AVERAGE_COLUMN,
+    SPP_HISTORICAL_AVERAGE_AMOUNT,  /* average column without currency */
     SPP_HISTORICAL_RETAINED_COLUMN,
     SPP_HISTORICAL_RETAINED_AMOUNT, /* retenaid column without currency */
     SPP_HISTORICAL_BALANCE_COLOR,
-    SPP_HISTORICAL_DIV_COLUMN,
-    SPP_HISTORICAL_SUB_DIV_COLUMN,
+    SPP_HISTORICAL_ACCOUNT_NUMBER,
+    SPP_HISTORICAL_DIV_NUMBER,
+    SPP_HISTORICAL_SUB_DIV_NUMBER,
     SPP_HISTORICAL_NUM_COLUMNS
 };
 

Index: balance_estimate_data.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/balance_estimate_data.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- balance_estimate_data.c	20 Feb 2010 08:54:00 -0000	1.5
+++ balance_estimate_data.c	20 Feb 2010 22:19:46 -0000	1.6
@@ -28,6 +28,7 @@
 
 /*START_INCLUDE*/
 #include "balance_estimate_data.h"
+#include "./balance_estimate_tab.h"
 #include "./dialog.h"
 #include "./utils_dates.h"
 #include "./gsb_data_account.h"
@@ -51,13 +52,12 @@
 
 typedef struct _hist_div struct_hist_div;
 
-
 struct _hist_div
 {
     gint account_nb;
     gint div_number;
     gboolean div_full;
-    gint sub_div_nb;
+    gboolean div_edited;
     GHashTable *sub_div_list;
     gsb_real amount;
 };
@@ -120,7 +120,7 @@
     gchar *key;
     gchar *sub_key;
     struct_hist_div *shd;
-devel_debug_int (account_nb);
+
     if ( account_nb == 0 )
         key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL );
     else
@@ -132,7 +132,7 @@
         if ( sub_div_nb > 0 )
         {
             sub_key = utils_str_itoa ( sub_div_nb );
-            if (  !g_hash_table_lookup ( bet_hist_div_list, sub_key ) )
+            if (  !g_hash_table_lookup ( shd -> sub_div_list, sub_key ) )
             {
                 struct_hist_div *sub_shd;
 
@@ -142,7 +142,7 @@
                     dialogue_error_memory ( );
                     return FALSE;
                 }
-                sub_shd -> sub_div_nb = sub_div_nb;
+                sub_shd -> div_number = sub_div_nb;
                 sub_shd -> amount = amount;
                 g_hash_table_insert ( shd -> sub_div_list, sub_key, sub_shd );
             }
@@ -158,7 +158,6 @@
         }
         shd -> account_nb = account_nb;
         shd -> div_number = div_number;
-        shd -> sub_div_nb = sub_div_nb;
         if ( sub_div_nb > 0 )
         {
             struct_hist_div *sub_shd;
@@ -170,7 +169,7 @@
                 return FALSE;
             }
             sub_key = utils_str_itoa ( sub_div_nb );
-            sub_shd -> sub_div_nb = sub_div_nb;
+            sub_shd -> div_number = sub_div_nb;
             sub_shd -> amount = amount;
             g_hash_table_insert ( shd -> sub_div_list, sub_key, sub_shd );
         }
@@ -192,7 +191,7 @@
     gchar *key;
     char *sub_key;
     struct_hist_div *shd;
-devel_debug_int (account_nb);
+
     if ( account_nb == 0 )
         key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL );
     else
@@ -217,7 +216,7 @@
 
 
 /**
- *
+ * return TRUE si la division et sous division existe.
  *
  *
  *
@@ -265,12 +264,6 @@
  *
  *
  * */
-/**
- *
- *
- *
- *
- * */
 gboolean bet_data_set_div_ptr ( gint type_div )
 {
     if ( type_div == 0 )
@@ -332,6 +325,91 @@
  *
  *
  * */
+gboolean bet_data_get_div_edited ( gint account_nb, gint div_number, gint sub_div_nb )
+{
+    gchar *key;
+    struct_hist_div *shd;
+    gboolean edited;
+
+    if ( account_nb == 0 )
+        key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL );
+    else
+        key = g_strconcat ( utils_str_itoa ( account_nb ), ":",
+                        utils_str_itoa ( div_number ), NULL );
+
+    if ( ( shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) )
+    {
+        if ( sub_div_nb == 0 )
+            edited = shd -> div_edited;
+        else
+        {
+            gchar *sub_key;
+            struct_hist_div *sub_shd;
+
+            sub_key = utils_str_itoa ( sub_div_nb );
+            if ( ( sub_shd = g_hash_table_lookup ( shd -> sub_div_list, sub_key ) ) )
+                edited = sub_shd -> div_edited;
+            else
+                edited = FALSE;
+            g_free ( sub_key );
+        }
+    }
+    else
+        edited = FALSE;
+    g_free ( key );
+
+    return edited;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_data_set_div_edited ( gint account_nb,
+                        gint div_number,
+                        gint sub_div_nb,
+                        gboolean edited )
+{
+    gchar *key;
+    struct_hist_div *shd;
+
+    if ( account_nb == 0 )
+        key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL );
+    else
+        key = g_strconcat ( utils_str_itoa ( account_nb ), ":",
+                        utils_str_itoa ( div_number ), NULL );
+
+    if ( ( shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) )
+    {
+        if ( sub_div_nb == 0 )
+            shd -> div_edited = edited;
+        else
+        {
+            gchar *sub_key;
+            struct_hist_div *sub_shd;
+
+            sub_key = utils_str_itoa ( sub_div_nb );
+            if ( ( sub_shd = g_hash_table_lookup ( shd -> sub_div_list, sub_key ) ) )
+                sub_shd -> div_edited = edited;
+            g_free ( sub_key );
+        }
+    }
+
+    g_free ( key );
+
+    return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
 gsb_real bet_data_get_div_amount ( gint account_nb, gint div_number, gint sub_div_nb )
 {
     gchar *key;
@@ -445,7 +523,7 @@
 {
     gchar *key;
     struct_hist_div *shd;
-devel_debug_int (full);
+
     if ( account_nb == 0 )
         key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL );
     else
@@ -459,6 +537,26 @@
 }
 
 
+/**
+ *
+ *
+ *
+ *
+ * */
+gint bet_data_get_selected_currency ( void )
+{
+    gint selected_account;
+    gint currency_number;
+
+    selected_account = bet_parameter_get_account_selected ( );
+    if ( selected_account == -1 )
+        return 0;
+
+    currency_number = gsb_data_account_get_currency ( selected_account );
+
+    return currency_number;
+}
+
 
 /**
  * Ajoute les données de la transaction à la division et la sous division
@@ -534,6 +632,117 @@
  *
  *
  * */
+GString *bet_data_get_strings_to_save ( void )
+{
+    GString *string = NULL;
+    gchar *tmp_str = NULL;
+    GHashTableIter iter;
+    gpointer key, value;
+    gint i = 0;
+
+    g_hash_table_iter_init ( &iter, bet_hist_div_list );
+    while ( g_hash_table_iter_next ( &iter, &key, &value ) )
+    {
+        struct_hist_div *shd = ( struct_hist_div* ) value;
+
+        if ( g_hash_table_size ( shd -> sub_div_list ) == 0 )
+        {
+            tmp_str = g_markup_printf_escaped ( "\t\tHist=\"%d\" Ac=\"%d\" Div=\"%d\" Full=\"%d\""
+                        " Edit=\"%d\" Damount=\"%s\" SDiv=\"%d\" SEdit=\"%d\" SDamount=\"%s\"\n",
+                        i,
+                        shd -> account_nb,
+                        shd -> div_number,
+                        shd -> div_full,
+                        shd -> div_edited,
+                        gsb_real_get_string ( shd -> amount ),
+                        0, 0, "0.00" );
+            if ( string == NULL )
+                string = g_string_new ( tmp_str );
+            else
+                string = g_string_append ( string, tmp_str );
+
+        }
+        else
+        {
+            GHashTableIter new_iter;
+
+            g_hash_table_iter_init ( &new_iter, shd -> sub_div_list );
+            while ( g_hash_table_iter_next ( &new_iter, &key, &value ) )
+            {
+                struct_hist_div *sub_shd = ( struct_hist_div* ) value;
+
+                i++;
+                tmp_str = g_markup_printf_escaped ( "\t\tHist=\"%d\" Ac=\"%d\" Div=\"%d\" "
+                        "Full=\"%d\" Edit=\"%d\" Damount=\"%s\" SDiv=\"%d\" SEdit=\"%d\" "
+                        "SDamount=\"%s\"\n",
+                        i,
+                        shd -> account_nb,
+                        shd -> div_number,
+                        shd -> div_full,
+                        shd -> div_edited,
+                        gsb_real_get_string ( shd -> amount ),
+                        sub_shd -> div_number,
+                        sub_shd -> div_edited,
+                        gsb_real_get_string ( sub_shd -> amount ) );
+
+                if ( string == NULL )
+                    string = g_string_new ( tmp_str );
+                else
+                    string = g_string_append ( string, tmp_str );
+            }
+        }
+    }
+printf ("string =\n%s\n", string -> str );
+    return string;
+}
+
+
+/**
+ * supprime de la liste bet_hist_div_list les divisions sous divisions
+ * inexistantes dans list_div.
+ *
+ *
+ * */
+void bet_data_synchronise_hist_div_list ( GHashTable  *list_div )
+{
+    GHashTableIter iter;
+    gpointer key, value;
+    SH *sh = NULL;
+
+    g_hash_table_iter_init ( &iter, bet_hist_div_list );
+    while ( g_hash_table_iter_next ( &iter, &key, &value ) ) 
+    {
+        struct_hist_div *shd = ( struct_hist_div* ) value;
+        GHashTableIter new_iter;
+
+        sh = g_hash_table_lookup ( list_div, utils_str_itoa ( shd -> div_number ) );
+        if ( sh == NULL )
+            bet_data_remove_div_hist ( shd -> account_nb, shd -> div_number, 0 );
+        else
+        {
+            g_hash_table_iter_init ( &new_iter, shd -> sub_div_list );
+            while ( g_hash_table_iter_next ( &new_iter, &key, &value ) )
+            {
+                struct_hist_div *sub_shd = ( struct_hist_div* ) value;
+
+                if ( !g_hash_table_lookup ( sh -> list_sub_div, utils_str_itoa (
+                 sub_shd -> div_number ) ) )
+                {
+                    bet_data_remove_div_hist ( shd -> account_nb,
+                                shd -> div_number,
+                                sub_shd -> div_number );
+                    g_hash_table_iter_init ( &new_iter, shd -> sub_div_list );
+                }
+            }
+        }
+    }
+}
+/**
+ *
+ *
+ *
+ *
+ * */
 SBR *initialise_struct_bet_range ( void )
 {
 	SBR	*sbr;
@@ -567,6 +776,12 @@
 }
 
 
+/**
+ *
+ *
+ *
+ *
+ * */
 SH *initialise_struct_historical ( void )
 {
 	SH	*sh;
@@ -613,7 +828,7 @@
     shd -> account_nb = 0;
     shd -> div_number = 0;
     shd -> div_full = FALSE;
-    shd -> sub_div_nb = -1;
+    shd -> div_edited = FALSE;
     shd -> sub_div_list = g_hash_table_new_full ( g_str_hash,
                         g_str_equal,
                         (GDestroyNotify) g_free,

Index: balance_estimate_tab.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/balance_estimate_tab.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- balance_estimate_tab.c	20 Feb 2010 08:54:00 -0000	1.42
+++ balance_estimate_tab.c	20 Feb 2010 22:19:46 -0000	1.43
@@ -192,7 +192,7 @@
     GtkWidget *tree_view;
     GtkTreeModel *tree_model;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     /* find the selected account */
     tree_view = g_object_get_data ( G_OBJECT ( bet_container ), "bet_account_treeview" );
     tree_model = gtk_tree_view_get_model ( GTK_TREE_VIEW ( tree_view ) );
@@ -487,7 +487,7 @@
     GtkWidget *widget;
     const gchar *name;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     if ( button )
         g_signal_handlers_block_by_func ( G_OBJECT ( button ),
                         G_CALLBACK ( bet_parameter_duration_period_clicked ),
@@ -558,7 +558,7 @@
     GtkWidget *widget;
     const gchar *name;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     name = gtk_widget_get_name ( GTK_WIDGET ( togglebutton ) );
 
     ancestor = g_object_get_data ( G_OBJECT ( bet_container ), "bet_account_duration" );
@@ -609,7 +609,7 @@
     const gchar *name;
     gboolean toggled;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     etat.bet_months = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON ( spin_button ) );
 
     toggled = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( togglebutton ) );
@@ -871,7 +871,7 @@
     GtkTreeIter iter;
     gint account_nb;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( tree_selection ),
      &model, &iter ) )
         return;
@@ -906,7 +906,7 @@
     GtkCellRenderer *cell;
     GtkTreeViewColumn *column;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     tree_view = gtk_tree_view_new();
 
     tree_model = gtk_tree_store_new (SPP_ACCOUNT_TREE_NUM_COLUMNS,
@@ -961,7 +961,7 @@
     GtkTreeIter iter;
     GSList *tmp_list;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     tree_selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW ( tree_view ) );
     gtk_tree_store_clear ( GTK_TREE_STORE ( tree_model ) );
 
@@ -1014,7 +1014,7 @@
     GtkSizeGroup *size_group;
     gint iduration;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     size_group = gtk_size_group_new ( GTK_SIZE_GROUP_HORIZONTAL );
 
     main_vbox = gtk_vbox_new ( FALSE, 5 );
@@ -1240,7 +1240,7 @@
     GtkTreeIter iter;
     GSList* tmp_list;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     tmp_list = gsb_data_scheduled_get_scheduled_list();
 
     while (tmp_list)
@@ -1385,7 +1385,7 @@
     GtkTreeIter iter;
     GSList* tmp_list;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     /* search transactions of the account which are in the future */
     tmp_list = gsb_data_transaction_get_transactions_list ( );
 
@@ -1513,7 +1513,7 @@
     gchar *str_amount;
     gsb_real amount;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     date = gsb_date_get_last_day_of_month ( date_min );
 
     /* initialise les données de la ligne insérée */
@@ -1679,8 +1679,6 @@
     GtkTreeIter iter;
     gboolean select = FALSE;
 
-    devel_debug (NULL);
-
     if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( tree_selection ),
      &model, &iter ) )
         return;
@@ -1723,8 +1721,6 @@
     GtkTreeModel *model;
     GtkTreeIter iter;
 
-    devel_debug (NULL);
-
     if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( tree_selection ),
      &model, &iter ) )
         return;

Index: balance_estimate_hist.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/balance_estimate_hist.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- balance_estimate_hist.c	20 Feb 2010 08:54:00 -0000	1.2
+++ balance_estimate_hist.c	20 Feb 2010 22:19:46 -0000	1.3
@@ -76,6 +76,7 @@
                         gchar *path_string,
                         GtkTreeModel *store );
 static GtkWidget *bet_historical_get_data ( GtkWidget *container );
+static gboolean bet_historical_get_full_div ( gint account_nb, gint div_number );
 static void bet_historical_populate_div_model ( gpointer key,
                         gpointer value,
                         gpointer user_data);
@@ -232,7 +233,6 @@
     const gchar *name;
     gchar *title;
 
-
     devel_debug (NULL);
     name = gtk_widget_get_name ( GTK_WIDGET ( togglebutton ) );
     ancestor = g_object_get_data ( G_OBJECT ( bet_container ), "bet_historical_data" );
@@ -318,10 +318,11 @@
 {
     GtkTreeIter iter;
 
-    devel_debug (path_string);
+    //~ devel_debug (path_string);
     if ( gtk_tree_model_get_iter_from_string ( GTK_TREE_MODEL ( store ), &iter, path_string ) )
     {
         gchar *tmp_str;
+        gchar *str_average;
         gchar *str_amount;
         gint div;
         gint sub_div;
@@ -329,14 +330,14 @@
         gint account_nb;
         gboolean valeur;
 
-        account_nb = bet_parameter_get_account_selected ( );
-
         gtk_tree_model_get ( GTK_TREE_MODEL ( store ), &iter,
                         SPP_HISTORICAL_SELECT_COLUMN, &valeur,
                         SPP_HISTORICAL_AVERAGE_COLUMN, &tmp_str,
+                        SPP_HISTORICAL_AVERAGE_AMOUNT, &str_average,
                         SPP_HISTORICAL_RETAINED_AMOUNT, &str_amount,
-                        SPP_HISTORICAL_DIV_COLUMN, &div,
-                        SPP_HISTORICAL_SUB_DIV_COLUMN, &sub_div,
+                        SPP_HISTORICAL_ACCOUNT_NUMBER, &account_nb,
+                        SPP_HISTORICAL_DIV_NUMBER, &div,
+                        SPP_HISTORICAL_SUB_DIV_NUMBER, &sub_div,
                         -1 );
         valeur = 1 - valeur;
         if ( valeur == 1 )
@@ -352,10 +353,12 @@
         }
         else
         {
+            //~ printf ("str_amount = %s str_average = %s\n", str_amount, str_average);
             bet_data_remove_div_hist ( account_nb, div, sub_div );
             gtk_tree_store_set ( GTK_TREE_STORE ( store ), &iter,
                         SPP_HISTORICAL_SELECT_COLUMN, 0,
                         SPP_HISTORICAL_RETAINED_COLUMN, "",
+                        SPP_HISTORICAL_RETAINED_AMOUNT, str_average,
                         -1 );
         }
 
@@ -370,19 +373,22 @@
             {
                 gtk_tree_model_get ( GTK_TREE_MODEL ( store ), &fils_iter,
                                 SPP_HISTORICAL_AVERAGE_COLUMN, &tmp_str,
+                                SPP_HISTORICAL_AVERAGE_AMOUNT, &str_average,
                                 SPP_HISTORICAL_RETAINED_AMOUNT, &str_amount,
-                                SPP_HISTORICAL_DIV_COLUMN, &div,
-                                SPP_HISTORICAL_SUB_DIV_COLUMN, &sub_div,
+                                SPP_HISTORICAL_DIV_NUMBER, &div,
+                                SPP_HISTORICAL_SUB_DIV_NUMBER, &sub_div,
                                 -1 );
                 if ( valeur == 1 )
                 {
+                    //~ printf ("str_amount = %s\n", str_amount);
                     bet_data_add_div_hist ( account_nb,
                                 div,
                                 sub_div,
                                 gsb_real_get_from_string ( str_amount ) );
                     bet_data_set_div_full ( account_nb, div, TRUE );
+                    bet_data_set_div_edited ( account_nb, div, sub_div, FALSE );
                     gtk_tree_store_set ( GTK_TREE_STORE ( store ), &fils_iter,
-                                SPP_HISTORICAL_SELECT_COLUMN, 1,
+                                SPP_HISTORICAL_SELECT_COLUMN, TRUE,
                                 SPP_HISTORICAL_RETAINED_COLUMN, tmp_str,
                                 -1 );
                 }
@@ -391,8 +397,9 @@
                     bet_data_set_div_full ( account_nb, div, FALSE );
                     bet_data_remove_div_hist ( account_nb, div, sub_div );
                     gtk_tree_store_set ( GTK_TREE_STORE ( store ), &fils_iter,
-                                SPP_HISTORICAL_SELECT_COLUMN, 0,
+                                SPP_HISTORICAL_SELECT_COLUMN, FALSE,
                                 SPP_HISTORICAL_RETAINED_COLUMN, "",
+                                SPP_HISTORICAL_RETAINED_AMOUNT, str_average,
                                 -1 );
                 }
                 i++;
@@ -404,6 +411,7 @@
             gboolean fils_val;
             gboolean test = TRUE;
             gint i = 0;
+            gsb_real balance = null_real;
 
             if ( gtk_tree_model_iter_parent ( GTK_TREE_MODEL ( store ), &parent, &iter ) )
             {
@@ -411,12 +419,19 @@
                         &iter, &parent, i ) )
                 {
                     gtk_tree_model_get ( GTK_TREE_MODEL ( store ), &iter,
-                                SPP_HISTORICAL_SELECT_COLUMN, &fils_val, -1 );
+                                SPP_HISTORICAL_SELECT_COLUMN, &fils_val,
+                                SPP_HISTORICAL_RETAINED_AMOUNT, &str_amount,
+                                -1 );
                     if ( fils_val != valeur )
                     {
                         test = FALSE;
                         break;
                     }
+                    if ( valeur == 1 )
+                    {
+                        balance = gsb_real_add ( balance,
+                                gsb_real_get_from_string ( str_amount ) );
+                    }
                     i++;
                 }
                 if ( test == TRUE )
@@ -425,21 +440,28 @@
                                 SPP_HISTORICAL_SELECT_COLUMN, valeur, -1 );
                     if ( valeur == 1 )
                     {
-                        gtk_tree_model_get ( GTK_TREE_MODEL ( store ), &parent,
-                                SPP_HISTORICAL_AVERAGE_COLUMN, &tmp_str,
-                                -1 );
+                        GtkTreeView *tree_view;
+
+                        tree_view = g_object_get_data ( G_OBJECT ( bet_container ),
+                                "bet_historical_treeview" );
+                        tmp_str = gsb_real_get_string_with_currency ( balance,
+                                bet_data_get_selected_currency ( ), TRUE );
                         bet_data_set_div_full ( account_nb, div, TRUE );
                         gtk_tree_store_set ( GTK_TREE_STORE ( store ), &parent,
-                                SPP_HISTORICAL_SELECT_COLUMN, 1,
+                                SPP_HISTORICAL_SELECT_COLUMN, TRUE,
                                 SPP_HISTORICAL_RETAINED_COLUMN, tmp_str,
                                 -1 );
+                        gtk_tree_view_collapse_row ( tree_view,
+                                gtk_tree_model_get_path ( store, &parent ) );
+                        gtk_tree_selection_select_iter ( gtk_tree_view_get_selection (
+                                tree_view ), &parent );
                     }
                 }
                 else
                 {
                     bet_data_set_div_full ( account_nb, div, FALSE );
                     gtk_tree_store_set ( GTK_TREE_STORE ( store ), &parent,
-                                SPP_HISTORICAL_SELECT_COLUMN, 0,
+                                SPP_HISTORICAL_SELECT_COLUMN, FALSE,
                                 SPP_HISTORICAL_RETAINED_COLUMN, "",
                                 -1 );
                 }
@@ -449,6 +471,9 @@
         bet_array_refresh_estimate_tab ( );
     }
 
+    if ( etat.modification_fichier == 0 )
+        modification_fichier ( TRUE );
+
     return ( FALSE );
 }
 
@@ -485,7 +510,7 @@
     GtkTreeModel *model;
     GtkTreeIter iter;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     model = gtk_tree_view_get_model ( GTK_TREE_VIEW ( tree_view ) );
     if ( gtk_tree_model_get_iter_from_string ( GTK_TREE_MODEL ( model ), &iter, path_string ) )
     {
@@ -499,23 +524,26 @@
 
         gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
                         SPP_HISTORICAL_SELECT_COLUMN, &valeur,
-                        SPP_HISTORICAL_DIV_COLUMN, &div,
-                        SPP_HISTORICAL_SUB_DIV_COLUMN, &sub_div,
+                        SPP_HISTORICAL_DIV_NUMBER, &div,
+                        SPP_HISTORICAL_SUB_DIV_NUMBER, &sub_div,
                         -1 );
 
-        if ( valeur == FALSE )
-            return;
-
-        number = gsb_real_get_from_string ( new_text );
-
         /* find the selected account */
         selected_account = bet_parameter_get_account_selected ( );
         if ( selected_account == -1 )
             return;
-        currency_number = gsb_data_account_get_currency ( selected_account );
 
+        if ( valeur == FALSE )
+        {
+            bet_data_set_div_edited  ( selected_account, div, sub_div, FALSE );
+            return;
+        }
+
+        number = gsb_real_get_from_string ( new_text );
+        currency_number = gsb_data_account_get_currency ( selected_account );
         tmp_str = gsb_real_get_string_with_currency ( number, currency_number, TRUE );
 
+        bet_data_set_div_edited  ( selected_account, div, sub_div, TRUE );
         bet_data_set_div_amount ( selected_account, div, sub_div, number );
         gtk_tree_store_set ( GTK_TREE_STORE ( model ), &iter,
                             SPP_HISTORICAL_RETAINED_COLUMN, tmp_str,
@@ -524,6 +552,9 @@
 
         bet_array_refresh_estimate_tab ( );
     }
+
+    if ( etat.modification_fichier == 0 )
+        modification_fichier ( TRUE );
 }
 
 
@@ -543,7 +574,7 @@
     GtkTreeViewColumn *column;
     gchar *title;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     tree_view = gtk_tree_view_new ( );
     gtk_tree_view_set_rules_hint ( GTK_TREE_VIEW (tree_view), TRUE);
 
@@ -552,6 +583,7 @@
                         G_TYPE_STRING, G_TYPE_STRING,
                         G_TYPE_STRING, G_TYPE_STRING,
                         G_TYPE_STRING, G_TYPE_STRING,
+                        G_TYPE_STRING, G_TYPE_INT,
                         G_TYPE_INT, G_TYPE_INT );
     gtk_tree_view_set_model ( GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL ( tree_model ) );
     g_object_unref ( G_OBJECT ( tree_model ) );
@@ -695,7 +727,7 @@
     GSList* tmp_list;
     GHashTable  *list_div;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     /* récuperation du n° de compte à utiliser */
     selected_account = bet_parameter_get_account_selected ( );
     if ( selected_account == -1 )
@@ -766,6 +798,7 @@
         bet_data_populate_div ( transaction_number, TRUE, list_div );
     }
     bet_historical_affiche_div ( list_div, tree_view );
+    bet_data_synchronise_hist_div_list ( list_div );
 
     g_hash_table_remove_all ( list_div );
 }
@@ -781,7 +814,7 @@
 {
     GtkTreeModel *model;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     model = gtk_tree_view_get_model ( GTK_TREE_VIEW ( tree_view ) );
 
     g_hash_table_foreach ( list_div, bet_historical_populate_div_model, tree_view );
@@ -816,10 +849,11 @@
     gint account_nb;
     gsb_real period = { 12, 0 };
     gsb_real average;
+    gboolean sub_div_visible = FALSE;
 
     div = sh -> div;
     div_name = bet_data_get_div_name ( div, 0, FALSE );
-    account_nb = bet_parameter_get_account_selected ( );
+    account_nb = sh -> account_nb;
 
     titre = g_object_get_data ( G_OBJECT ( bet_container ), "bet_historical_period" );
 
@@ -827,9 +861,9 @@
     average = gsb_real_div ( sbr -> current_balance, period );
     str_amount = gsb_real_get_string ( average );
     str_balance = gsb_real_get_string_with_currency ( sbr -> current_balance, 
-                        gsb_data_account_get_currency ( sh -> account_nb ), TRUE );
+                        gsb_data_account_get_currency ( account_nb ), TRUE );
     str_average = gsb_real_get_string_with_currency ( average,
-                        gsb_data_account_get_currency ( sh -> account_nb ), TRUE );
+                        gsb_data_account_get_currency ( account_nb ), TRUE );
 
     gtk_tree_store_append ( GTK_TREE_STORE ( model ), &parent, NULL);
     gtk_tree_store_set ( GTK_TREE_STORE ( model ),
@@ -838,38 +872,48 @@
                         SPP_HISTORICAL_PERIOD_COLUMN, titre,
                         SPP_HISTORICAL_BALANCE_COLUMN, str_balance,
                         SPP_HISTORICAL_AVERAGE_COLUMN, str_average,
+                        SPP_HISTORICAL_AVERAGE_AMOUNT, str_amount,
                         SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
-                        SPP_HISTORICAL_DIV_COLUMN, div,
-                        SPP_HISTORICAL_SUB_DIV_COLUMN, 0,
+                        SPP_HISTORICAL_ACCOUNT_NUMBER, account_nb,
+                        SPP_HISTORICAL_DIV_NUMBER, div,
+                        SPP_HISTORICAL_SUB_DIV_NUMBER, 0,
                         -1);
-    if ( bet_data_search_div_hist ( account_nb, div, 0 ) ||
-     bet_data_get_div_full ( account_nb, div ) )
+
+    if ( g_hash_table_size ( sh -> list_sub_div ) == 1 )
     {
-        average = bet_data_get_div_amount ( account_nb, div, 0 );
-        if ( str_amount )
-            g_free ( str_amount );
-        str_amount = gsb_real_get_string ( average );
-        if ( str_average )
-            g_free ( str_average );
-        str_average = gsb_real_get_string_with_currency ( average,
-                        gsb_data_account_get_currency ( sh -> account_nb ), TRUE );
-        gtk_tree_store_set ( GTK_TREE_STORE ( model ),
-                        &parent,
-                        SPP_HISTORICAL_SELECT_COLUMN,
-                        bet_data_search_div_hist ( account_nb, div, 0 ) ||
-                        bet_data_get_div_full ( account_nb, div ),
-                        SPP_HISTORICAL_RETAINED_COLUMN, str_average,
-                        SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
-                        -1);
+
+        if ( bet_data_search_div_hist ( account_nb, div, 0 ) )
+        {
+            if ( bet_data_get_div_edited ( account_nb, div, 0 ) )
+            {
+                average = bet_data_get_div_amount ( account_nb, div, 0 );
+                if ( str_amount )
+                    g_free ( str_amount );
+                str_amount = gsb_real_get_string ( average );
+                if ( str_average )
+                    g_free ( str_average );
+                str_average = gsb_real_get_string_with_currency ( average,
+                                gsb_data_account_get_currency ( sh -> account_nb ), TRUE );
+            }
+            gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+                            &parent,
+                            SPP_HISTORICAL_SELECT_COLUMN, TRUE,
+                            SPP_HISTORICAL_RETAINED_COLUMN, str_average,
+                            SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
+                            -1);
+        }
+        g_free ( div_name );
+        g_free ( str_balance );
+        g_free ( str_average );
+        g_free ( str_amount );
+
+        return;
     }
+
     g_free ( div_name );
     g_free ( str_balance );
     g_free ( str_average );
     g_free ( str_amount );
-    if ( div == 27 )
-
-    if ( g_hash_table_size ( sh -> list_sub_div ) == 1 )
-        return;
 
     g_hash_table_iter_init ( &iter, sh -> list_sub_div );
     while ( g_hash_table_iter_next ( &iter, &sub_key, &sub_value ) ) 
@@ -903,36 +947,76 @@
                         SPP_HISTORICAL_PERIOD_COLUMN, titre,
                         SPP_HISTORICAL_BALANCE_COLUMN, str_balance,
                         SPP_HISTORICAL_AVERAGE_COLUMN, str_average,
+                        SPP_HISTORICAL_AVERAGE_AMOUNT, str_amount,
                         SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
-                        SPP_HISTORICAL_DIV_COLUMN, div,
-                        SPP_HISTORICAL_SUB_DIV_COLUMN, sub_sh -> div,
+                        SPP_HISTORICAL_ACCOUNT_NUMBER, account_nb,
+                        SPP_HISTORICAL_DIV_NUMBER, div,
+                        SPP_HISTORICAL_SUB_DIV_NUMBER, sub_sh -> div,
                         -1);
-    if ( bet_data_search_div_hist ( account_nb, div, sub_sh -> div ) )
-    {
-        average = bet_data_get_div_amount ( account_nb, div, sub_sh -> div );
-        if ( str_amount )
-            g_free ( str_amount );
-        str_amount = gsb_real_get_string ( average );
-        if ( str_average )
-            g_free ( str_average );
-        str_average = gsb_real_get_string_with_currency ( average,
-                        gsb_data_account_get_currency ( sh -> account_nb ), TRUE );
-        gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+        if ( bet_data_search_div_hist ( account_nb, div, sub_sh -> div ) )
+        {
+            if ( bet_data_get_div_edited ( account_nb, div, sub_sh -> div ) )
+            {
+                average = bet_data_get_div_amount ( account_nb, div, sub_sh -> div );
+                if ( str_amount )
+                    g_free ( str_amount );
+                str_amount = gsb_real_get_string ( average );
+                if ( str_average )
+                    g_free ( str_average );
+                str_average = gsb_real_get_string_with_currency ( average,
+                                gsb_data_account_get_currency ( sh -> account_nb ), TRUE );
+            }
+            gtk_tree_store_set ( GTK_TREE_STORE ( model ),
                         &fils,
-                        SPP_HISTORICAL_SELECT_COLUMN,
-                        bet_data_search_div_hist ( account_nb, div, sub_sh -> div ),
+                        SPP_HISTORICAL_SELECT_COLUMN, TRUE,
                         SPP_HISTORICAL_RETAINED_COLUMN, str_average,
                         SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
                         -1);
-        if ( bet_data_get_div_full ( account_nb, div ) == FALSE )
+            sub_div_visible = TRUE;
             gtk_tree_view_expand_to_path ( tree_view, gtk_tree_model_get_path ( model, &fils ) );
-    }
+        }
         g_free ( div_name );
         g_free ( str_balance );
         g_free ( str_average );
         g_free ( str_amount );
     }
+
+    if ( sub_div_visible && bet_historical_get_full_div ( account_nb, div ) )
+    {
+        if ( bet_data_get_div_edited ( account_nb, div, 0 ) )
+        {
+            average = bet_data_get_div_amount ( account_nb, div, 0 );
+            if ( str_amount )
+                g_free ( str_amount );
+            str_amount = gsb_real_get_string ( average );
+            if ( str_average )
+                g_free ( str_average );
+            str_average = gsb_real_get_string_with_currency ( average,
+                        gsb_data_account_get_currency ( sh -> account_nb ), TRUE );
+        }
+        else
+        {
+            average = gsb_real_div ( sbr -> current_balance, period );
+            if ( str_amount )
+                g_free ( str_amount );
+            str_amount = gsb_real_get_string ( average );
+            if ( str_average )
+                g_free ( str_average );
+            str_average = gsb_real_get_string_with_currency ( average,
+                        gsb_data_account_get_currency ( account_nb ), TRUE );
+        }
+            gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+                        &parent,
+                        SPP_HISTORICAL_SELECT_COLUMN, TRUE,
+                        SPP_HISTORICAL_RETAINED_COLUMN, str_average,
+                        SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
+                        -1);
+        gtk_tree_view_collapse_row ( tree_view, gtk_tree_model_get_path ( model, &parent ) );
+        gtk_tree_selection_select_iter ( gtk_tree_view_get_selection ( tree_view ), &parent );
+    }
 }
+
+
 /**
  * create and fill the list store of the fyear
  * come here mean that fyear_model_filter is NULL
@@ -945,7 +1029,7 @@
 {
     gchar *titre;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     /* the fyear list store, contains 3 columns :
      * FYEAR_COL_NAME : the name of the fyear
      * FYEAR_COL_NUMBER : the number of the fyear
@@ -980,7 +1064,7 @@
     gint fyear_number = 0;
     GtkTreeIter iter;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     if ( !gtk_combo_box_get_active_iter ( GTK_COMBO_BOX ( combo_box ), &iter ) )
         return 0;
 
@@ -1011,7 +1095,7 @@
     GtkTreeIter iter;
     GtkTreeIter fils_iter;
 
-    devel_debug (NULL);
+    //~ devel_debug (NULL);
     tree_view = g_object_get_data ( G_OBJECT ( bet_container ), "bet_historical_treeview" );
     model = gtk_tree_view_get_model ( GTK_TREE_VIEW ( tree_view ) );
 
@@ -1063,6 +1147,65 @@
  *
  *
  * */
+gboolean bet_historical_get_full_div ( gint account_nb, gint div_number )
+{
+    GtkWidget *tree_view;
+    GtkTreeModel *model;
+    GtkTreeIter iter;
+    GtkTreeIter fils_iter;
+    gint account_number;
+    gint div;
+    gboolean valeur;
+
+    tree_view = g_object_get_data ( G_OBJECT ( bet_container ), "bet_historical_treeview" );
+    model = gtk_tree_view_get_model ( GTK_TREE_VIEW ( tree_view ) );
+
+    if ( gtk_tree_model_get_iter_first ( GTK_TREE_MODEL ( model ), &iter ) )
+    {
+        do
+        {
+            gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
+                        SPP_HISTORICAL_SELECT_COLUMN, &valeur,
+                        SPP_HISTORICAL_ACCOUNT_NUMBER, &account_number,
+                        SPP_HISTORICAL_DIV_NUMBER, &div,
+                        -1 );
+            if ( valeur == TRUE )
+                return TRUE;
+            
+            else if ( account_nb == account_number && div == div_number )
+            {
+                if ( gtk_tree_model_iter_children ( GTK_TREE_MODEL ( model ), &fils_iter, &iter ) )
+                {
+                    do
+                    {
+                        gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &fils_iter,
+                                    SPP_HISTORICAL_SELECT_COLUMN, &valeur,
+                                    -1 );
+
+                        if ( valeur == FALSE )
+                        {
+                            return FALSE;
+                        }
+                    }
+                    while ( gtk_tree_model_iter_next (
+                            GTK_TREE_MODEL ( model ), &fils_iter ) );
+                }
+                return TRUE;
+            }
+            
+        } while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL ( model ), &iter ) );
+    }
+
+    return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
 /* Local Variables: */
 /* c-basic-offset: 4 */
 /* End: */



More information about the cvs mailing list