[grisbi-cvs] grisbi/src balance_estimate_data.c, 1.6, 1.7 balance_estimate_data.h, 1.5, 1.6 balance_estimate_hist.c, 1.3, 1.4 gsb_file_load.c, 1.206, 1.207 gsb_file_save.c, 1.152, 1.153

Pierre Biava pbiava at users.sourceforge.net
Sun Feb 21 13:30:19 CET 2010


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

Modified Files:
	balance_estimate_data.c balance_estimate_data.h 
	balance_estimate_hist.c gsb_file_load.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.152
retrieving revision 1.153
diff -u -d -r1.152 -r1.153
--- gsb_file_save.c	20 Feb 2010 23:03:10 -0000	1.152
+++ gsb_file_save.c	21 Feb 2010 12:30:17 -0000	1.153
@@ -1947,7 +1947,8 @@
 
 	partial_balance_number = gsb_data_partial_balance_get_number ( list_tmp -> data );
 
-	new_string = g_markup_printf_escaped ( "\t<Partial_balance Nb=\"%d\" Na=\"%s\" Acc=\"%s\" Kind=\"%d\" Currency=\"%d\" Colorise=\"%d\" />\n",
+	new_string = g_markup_printf_escaped ( "\t<Partial_balance Nb=\"%d\" Na=\"%s\" "
+                           "Acc=\"%s\" Kind=\"%d\" Currency=\"%d\" Colorise=\"%d\" />\n",
 					       partial_balance_number,
 					       my_safe_null_str(gsb_data_partial_balance_get_name ( partial_balance_number )),
 					       my_safe_null_str(gsb_data_partial_balance_get_liste_cptes ( partial_balance_number )),
@@ -2609,17 +2610,12 @@
                         gchar **file_content )
 {
     gchar *new_string;
-    GString *lignes;
+    GPtrArray *tab;
+    gint i;
 
     /* save the general informations */
-    new_string = g_markup_printf_escaped ( "\t<Bet\n"
-                        "\t\tAc=\"%d\"\n"
-                        "\t\tBdte=\"%d\"\n"
-                        "\t\tEdte=\"%d\"\n"
-                        "\t\tNbre=\"%d\"\n"
-                        "\t\tUT=\"%d\"\n"
-                        "\t\tSD=\"%d\"\n"
-                        "\t\tFi=\"%d\"\n",
+    new_string = g_markup_printf_escaped ( "\t<Bet Ac=\"%d\" Ddte=\"%d\" Edte=\"%d\" "
+                        "Nbre=\"%d\" UT=\"%d\" SD=\"%d\" Fi=\"%d\" />\n",
     etat.bet_last_account,
     etat.bet_deb_period,
     etat.bet_end_period,
@@ -2628,19 +2624,29 @@
     etat.bet_hist_data,
     etat.bet_hist_fyear );
 
-    lignes = bet_data_get_strings_to_save ( );
-    if ( lignes && lignes -> str )
-        new_string = g_strconcat ( new_string, lignes -> str, "\t\t/>\n", NULL );
-    else
-        new_string = g_strconcat ( new_string, "\t\t/>\n", NULL );
+    /* append the new string to the file content */
+    iterator = gsb_file_save_append_part ( iterator,
+				        length_calculated,
+				        file_content,
+				        new_string );
 
-    /* append the new string to the file content
-     * and return the new iterator */
+    tab = bet_data_get_strings_to_save ( );
+    //~ printf ("tab -> len = %d\n", tab -> len);
 
-    return gsb_file_save_append_part ( iterator,
-				       length_calculated,
-				       file_content,
-				       new_string );
+    if ( tab == NULL )
+        return iterator;
+
+    for ( i = 0; i < tab -> len; i++ )
+    {
+        new_string = g_ptr_array_index ( tab, i );
+        iterator =  gsb_file_save_append_part ( iterator,
+				        length_calculated,
+				        file_content,
+				        new_string );
+    }
+
+    /* and return the new iterator */
+    return iterator;
 }
 
 

Index: balance_estimate_data.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/balance_estimate_data.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- balance_estimate_data.c	20 Feb 2010 22:19:46 -0000	1.6
+++ balance_estimate_data.c	21 Feb 2010 12:30:16 -0000	1.7
@@ -50,23 +50,10 @@
 #include "./utils.h"
 /*END_INCLUDE*/
 
-typedef struct _hist_div struct_hist_div;
-
-struct _hist_div
-{
-    gint account_nb;
-    gint div_number;
-    gboolean div_full;
-    gboolean div_edited;
-    GHashTable *sub_div_list;
-    gsb_real amount;
-};
-
 
 /*START_STATIC*/
 static gboolean bet_data_update_div ( SH *sh, gint transaction_number,
                         gint sub_div );
-static struct_hist_div *initialise_struct_hist_div ( void );
 static void free_struct_hist_div ( struct_hist_div *bet_hist_div );
 /*END_STATIC*/
 
@@ -186,6 +173,50 @@
  *
  *
  * */
+void bet_data_insert_div_hist ( struct_hist_div *shd, struct_hist_div *sub_shd )
+{
+    gchar *key;
+    gchar *sub_key;
+    struct_hist_div *tmp_shd;
+
+    if ( shd -> account_nb == 0 )
+        key = g_strconcat ("0:", utils_str_itoa ( shd -> div_number ), NULL );
+    else
+        key = g_strconcat ( utils_str_itoa ( shd -> account_nb ), ":",
+                        utils_str_itoa ( shd -> div_number ), NULL );
+
+    if ( ( tmp_shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) )
+    {
+        tmp_shd -> div_full = shd -> div_full;
+        tmp_shd -> div_edited = shd -> div_edited;
+        tmp_shd -> amount = shd -> amount;
+
+        if ( sub_shd )
+        {
+            sub_key = utils_str_itoa ( sub_shd -> div_number );
+            g_hash_table_insert ( tmp_shd -> sub_div_list, sub_key, sub_shd );
+        }
+    }
+    else
+    {
+        if ( sub_shd )
+        {
+            sub_key = utils_str_itoa ( sub_shd -> div_number );
+            g_hash_table_insert ( shd -> sub_div_list, sub_key, sub_shd );
+        }
+        g_hash_table_insert ( bet_hist_div_list, key, shd );
+    }
+    
+    //~ printf ("long bet_hist_div_list = %d\n", g_hash_table_size ( bet_hist_div_list ));
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
 gboolean bet_data_remove_div_hist ( gint account_nb, gint div_number, gint sub_div_nb )
 {
     gchar *key;
@@ -226,7 +257,7 @@
     gchar *key;
     gchar *sub_key;
     struct_hist_div *shd;
-    
+
     if ( account_nb == 0 )
         key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL );
     else
@@ -632,13 +663,18 @@
  *
  *
  * */
-GString *bet_data_get_strings_to_save ( void )
+GPtrArray *bet_data_get_strings_to_save ( void )
 {
-    GString *string = NULL;
+    GPtrArray *tab = NULL;
     gchar *tmp_str = NULL;
     GHashTableIter iter;
     gpointer key, value;
-    gint i = 0;
+
+    if ( g_hash_table_size ( bet_hist_div_list ) == 0 )
+        return NULL;
+
+    //~ printf ("long bet_hist_div_list = %d\n", g_hash_table_size ( bet_hist_div_list ));
+    tab = g_ptr_array_new ( );
 
     g_hash_table_iter_init ( &iter, bet_hist_div_list );
     while ( g_hash_table_iter_next ( &iter, &key, &value ) )
@@ -647,35 +683,33 @@
 
         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,
+            tmp_str = g_markup_printf_escaped ( "\t<Bet_historical Nb=\"%d\" Ac=\"%d\" "
+                        "Div=\"%d\"  Full=\"%d\" Edit=\"%d\" Damount=\"%s\" SDiv=\"%d\" "
+                        "SEdit=\"%d\" SDamount=\"%s\" />\n",
+                        tab -> len + 1,
                         shd -> account_nb,
                         shd -> div_number,
                         shd -> div_full,
                         shd -> div_edited,
-                        gsb_real_get_string ( shd -> amount ),
+                        gsb_real_save_real_to_string ( shd -> amount, 2 ),
                         0, 0, "0.00" );
-            if ( string == NULL )
-                string = g_string_new ( tmp_str );
-            else
-                string = g_string_append ( string, tmp_str );
 
+            g_ptr_array_add ( tab, tmp_str );
         }
         else
         {
             GHashTableIter new_iter;
 
+            //~ printf ("long shd -> sub_div_list = %d\n", g_hash_table_size ( shd -> sub_div_list ));
             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,
+                tmp_str = g_markup_printf_escaped ( "\t<Bet_historical Nb=\"%d\" Ac=\"%d\" "
+                        "Div=\"%d\"  Full=\"%d\" Edit=\"%d\" Damount=\"%s\" SDiv=\"%d\" "
+                        "SEdit=\"%d\" SDamount=\"%s\" />\n",
+                        tab -> len + 1,
                         shd -> account_nb,
                         shd -> div_number,
                         shd -> div_full,
@@ -683,17 +717,13 @@
                         gsb_real_get_string ( shd -> amount ),
                         sub_shd -> div_number,
                         sub_shd -> div_edited,
-                        gsb_real_get_string ( sub_shd -> amount ) );
+                        gsb_real_save_real_to_string ( sub_shd -> amount, 2 ) );
 
-                if ( string == NULL )
-                    string = g_string_new ( tmp_str );
-                else
-                    string = g_string_append ( string, tmp_str );
+                g_ptr_array_add ( tab, tmp_str );
             }
         }
     }
-printf ("string =\n%s\n", string -> str );
-    return string;
+    return tab;
 }
 
 

Index: balance_estimate_hist.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/balance_estimate_hist.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- balance_estimate_hist.c	20 Feb 2010 22:19:46 -0000	1.3
+++ balance_estimate_hist.c	21 Feb 2010 12:30:16 -0000	1.4
@@ -798,7 +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 );
+    //~ bet_data_synchronise_hist_div_list ( list_div );
 
     g_hash_table_remove_all ( list_div );
 }
@@ -879,9 +879,8 @@
                         SPP_HISTORICAL_SUB_DIV_NUMBER, 0,
                         -1);
 
-    if ( g_hash_table_size ( sh -> list_sub_div ) == 1 )
+    if ( g_hash_table_size ( sh -> list_sub_div ) <= 1 )
     {
-
         if ( bet_data_search_div_hist ( account_nb, div, 0 ) )
         {
             if ( bet_data_get_div_edited ( account_nb, div, 0 ) )
@@ -1169,10 +1168,7 @@
                         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 ( account_nb == account_number && div == div_number )
             {
                 if ( gtk_tree_model_iter_children ( GTK_TREE_MODEL ( model ), &fils_iter, &iter ) )
                 {

Index: gsb_file_load.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_file_load.c,v
retrieving revision 1.206
retrieving revision 1.207
diff -u -d -r1.206 -r1.207
--- gsb_file_load.c	31 Jan 2010 20:47:24 -0000	1.206
+++ gsb_file_load.c	21 Feb 2010 12:30:16 -0000	1.207
@@ -77,6 +77,7 @@
 #include "./gsb_real.h"
 #include "./gsb_currency_config.h"
 #include "./gsb_data_report.h"
+#include "./balance_estimate_data.h"
 /*END_INCLUDE*/
 
 /*START_STATIC*/
@@ -90,6 +91,8 @@
                         const gchar **attribute_values );
 static void gsb_file_load_bet_part ( const gchar **attribute_names,
                         const gchar **attribute_values );
+static void gsb_file_load_bet_historical ( const gchar **attribute_names,
+                        const gchar **attribute_values );
 static gboolean gsb_file_load_check_new_structure ( gchar *file_content );
 static void gsb_file_load_color_part ( const gchar **attribute_names,
                         const gchar **attribute_values );
@@ -627,6 +630,11 @@
         gsb_file_load_bet_part ( attribute_names, attribute_values );
         return;
     }
+    if ( !strcmp ( element_name, "Bet_historical" ) )
+    {
+        gsb_file_load_bet_historical ( attribute_names, attribute_values );
+        return;
+    }
 #endif /* ENABLE_BALANCE_ESTIMATE */
 
     if ( !strcmp ( element_name,
@@ -3602,7 +3610,7 @@
         continue;
     }
 
-    if ( !strcmp ( attribute_names[i], "Bdte" ) )
+    if ( !strcmp ( attribute_names[i], "Ddte" ) )
     {
         etat.bet_deb_period = utils_str_atoi ( attribute_values[i] );
         i++;
@@ -3653,6 +3661,110 @@
 
 
 /**
+ * load the historical balance part in the grisbi file
+ *
+ * \param attribute_names
+ * \param attribute_values
+ *
+ * */
+void gsb_file_load_bet_historical ( const gchar **attribute_names,
+                        const gchar **attribute_values )
+{
+    struct_hist_div *shd;
+    struct_hist_div *sub_shd = NULL;
+    gint i=0;
+    gint sub_div_nb;
+
+    if ( !attribute_names[i] )
+    return;
+
+    /* create the structure */
+    shd = initialise_struct_hist_div ( );
+
+    do
+    {
+    /*     we test at the beginning if the attribute_value is NULL, if yes, */
+    /*        go to the next */
+    if ( !strcmp ( attribute_values[i], "(null)") )
+    {
+        i++;
+        continue;
+    }
+
+    if ( !strcmp ( attribute_names[i], "Ac" ) )
+    {
+        shd -> account_nb = utils_str_atoi ( attribute_values[i] );
+        i++;
+        continue;
+    }
+
+    if ( !strcmp ( attribute_names[i], "Div" ) )
+    {
+        shd -> div_number = utils_str_atoi ( attribute_values[i] );
+        i++;
+        continue;
+    }
+
+    if ( !strcmp ( attribute_names[i], "Full" ) )
+    {
+        shd -> div_full = utils_str_atoi ( attribute_values[i] );
+        i++;
+        continue;
+    }
+
+    if ( !strcmp ( attribute_names[i], "Edit" ) )
+    {
+        shd -> div_edited = utils_str_atoi ( attribute_values[i] );
+        i++;
+        continue;
+    }
+
+    if ( !strcmp ( attribute_names[i], "Damount" ) )
+    {
+        shd -> amount = gsb_real_import_from_string ( attribute_values[i] );
+        i++;
+        continue;
+    }
+
+    if ( !strcmp ( attribute_names[i], "SDiv" ) )
+    {
+        sub_div_nb = utils_str_atoi ( attribute_values[i] );
+        if ( sub_div_nb > 0 )
+        {
+            sub_shd = initialise_struct_hist_div ( );
+            sub_shd -> div_number = sub_div_nb;
+            i++;
+            continue;
+        }
+        else
+            break;
+    }
+
+    if ( !strcmp ( attribute_names[i], "SEdit" ) )
+    {
+        sub_shd -> div_edited = utils_str_atoi ( attribute_values[i] );
+        i++;
+        continue;
+    }
+
+    if ( !strcmp ( attribute_names[i], "SDamount" ) )
+    {
+        sub_shd -> amount = gsb_real_import_from_string ( attribute_values[i] );
+        i++;
+        continue;
+    }
+
+    /* normally, shouldn't come here */
+    i++;
+    }
+
+    while ( attribute_names[i] );
+
+    bet_data_insert_div_hist ( shd, sub_shd );
+}
+
+
+/**
  * load the report structure in the grisbi file
  *
  * \param attribute_names

Index: balance_estimate_data.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/balance_estimate_data.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- balance_estimate_data.h	20 Feb 2010 22:19:46 -0000	1.5
+++ balance_estimate_data.h	21 Feb 2010 12:30:16 -0000	1.6
@@ -10,6 +10,8 @@
 
 typedef struct _bet_range           SBR;
 typedef struct _historical          SH;
+typedef struct _hist_div            struct_hist_div;
+
 
 struct _bet_range
 {
@@ -30,6 +32,17 @@
 };
 
 
+struct _hist_div
+{
+    gint account_nb;
+    gint div_number;
+    gboolean div_full;
+    gboolean div_edited;
+    GHashTable *sub_div_list;
+    gsb_real amount;
+};
+
+
 /* START_DECLARATION */
 gboolean bet_data_add_div_hist ( gint account_nb,
                         gint div_number,
@@ -43,9 +56,10 @@
 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 );
+GPtrArray *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 );
+void bet_data_insert_div_hist ( struct_hist_div *shd, struct_hist_div *sub_shd );
 gboolean bet_data_populate_div ( gint transaction_number,
                         gboolean is_transaction,
                         GHashTable  *list_div );
@@ -64,6 +78,7 @@
 void bet_data_synchronise_hist_div_list ( GHashTable  *list_div );
 SBR *initialise_struct_bet_range ( void );
 SH *initialise_struct_historical ( void );
+struct_hist_div *initialise_struct_hist_div ( void );
 void free_struct_bet_range ( SBR *sbr );
 void free_struct_historical ( SH *sh );
 



More information about the cvs mailing list