[grisbi-cvs] grisbi/src file_obfuscate.c, 1.11, 1.12 gsb_assistant_first.c, 1.24, 1.25 gsb_data_account.c, 1.70, 1.71 gsb_data_account.h, 1.32, 1.33 gsb_data_reconcile.c, 1.17, 1.18 gsb_data_reconcile.h, 1.8, 1.9 gsb_data_transaction.c, 1.60, 1.61 gsb_file.c, 1.45, 1.46 gsb_file_load.c, 1.171, 1.172 gsb_form.c, 1.119, 1.120 gsb_form_transaction.c, 1.42, 1.43 gsb_reconcile.c, 1.35, 1.36 gsb_transactions_list.c, 1.159, 1.160 import.c, 1.275, 1.276 navigation.c, 1.118, 1.119 navigation.h, 1.20, 1.21 transaction_list.c, 1.34, 1.35

Pierre Biava pbiava at users.sourceforge.net
Fri May 8 11:35:13 CEST 2009


Update of /cvsroot/grisbi/grisbi/src
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv22417/src

Modified Files:
	file_obfuscate.c gsb_assistant_first.c gsb_data_account.c 
	gsb_data_account.h gsb_data_reconcile.c gsb_data_reconcile.h 
	gsb_data_transaction.c gsb_file.c gsb_file_load.c gsb_form.c 
	gsb_form_transaction.c gsb_reconcile.c gsb_transactions_list.c 
	import.c navigation.c navigation.h transaction_list.c 
Log Message:
fixes the bug 540 and changes the management of the updating of account balances

Index: navigation.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/navigation.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- navigation.h	31 Jan 2009 20:11:04 -0000	1.20
+++ navigation.h	8 May 2009 09:35:11 -0000	1.21
@@ -20,7 +20,7 @@
 void create_account_list ( GtkTreeModel * model );
 GtkWidget * create_navigation_pane ( void );
 void gsb_gui_navigation_add_account ( gint account_number,
-				      gboolean switch_to_account );
+                        gboolean switch_to_account );
 void gsb_gui_navigation_add_report ( gint report_number );
 gint gsb_gui_navigation_get_current_account ( void );
 gint gsb_gui_navigation_get_current_page ( void );
@@ -37,11 +37,11 @@
 void gsb_navigation_update_statement_label ( gint account_number );
 gboolean navigation_change_account ( gint *no_account );
 gboolean navigation_drag_data_received ( GtkTreeDragDest * drag_dest,
-					 GtkTreePath * dest_path,
-					 GtkSelectionData * selection_data );
+                        GtkTreePath * dest_path,
+                        GtkSelectionData * selection_data );
 gboolean navigation_row_drop_possible ( GtkTreeDragDest * drag_dest, 
-					GtkTreePath * dest_path,
-					GtkSelectionData * selection_data );
+                        GtkTreePath * dest_path,
+                        GtkSelectionData * selection_data );
 /* END_DECLARATION */
 
 #endif

Index: gsb_data_transaction.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_data_transaction.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- gsb_data_transaction.c	27 Apr 2009 19:41:03 -0000	1.60
+++ gsb_data_transaction.c	8 May 2009 09:35:10 -0000	1.61
@@ -665,9 +665,10 @@
     transaction = gsb_data_transaction_get_transaction_by_no ( transaction_number);
 
     if ( !transaction )
-	return FALSE;
+        return FALSE;
 
     transaction -> transaction_amount = amount;
+    gsb_data_account_set_balances_are_dirty ( transaction -> account_number );
     
     return TRUE;
 }
@@ -1432,24 +1433,25 @@
     if ( !transaction )
 	return FALSE;
 
+    gsb_data_account_set_balances_are_dirty ( transaction->account_number );
     transaction -> marked_transaction = marked_transaction;
 
     /* if the transaction is a split, change all the children */
     if (transaction -> split_of_transaction)
     {
-	GSList *tmp_list;
-	GSList *save_tmp_list;
+        GSList *tmp_list;
+        GSList *save_tmp_list;
 
-	tmp_list = gsb_data_transaction_get_children (transaction -> transaction_number, FALSE);
-	save_tmp_list = tmp_list;
+        tmp_list = gsb_data_transaction_get_children (transaction -> transaction_number, FALSE);
+        save_tmp_list = tmp_list;
 
-	while (tmp_list)
-	{
-	    transaction = tmp_list -> data;
-	    transaction -> marked_transaction = marked_transaction;
-	    tmp_list = tmp_list -> next;
-	}
-	g_slist_free (save_tmp_list);
+        while (tmp_list)
+        {
+            transaction = tmp_list -> data;
+            transaction -> marked_transaction = marked_transaction;
+            tmp_list = tmp_list -> next;
+        }
+        g_slist_free (save_tmp_list);
     }
 
     return TRUE;
@@ -2138,6 +2140,7 @@
 {
     if ( ! transaction )
         return;
+    gsb_data_account_set_balances_are_dirty ( transaction -> account_number );
     if ( transaction -> transaction_id )
         g_free ( transaction -> transaction_id );
     if ( transaction -> notes )

Index: file_obfuscate.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/file_obfuscate.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- file_obfuscate.c	27 Apr 2009 19:41:03 -0000	1.11
+++ file_obfuscate.c	8 May 2009 09:35:10 -0000	1.12
@@ -137,8 +137,6 @@
 		gsb_data_account_set_init_balance (account_number, null_real);
 		gsb_data_account_set_mini_balance_wanted (account_number, null_real);
 		gsb_data_account_set_mini_balance_authorized (account_number, null_real);
-		gsb_data_account_set_current_balance (account_number, null_real);
-		gsb_data_account_set_marked_balance (account_number, null_real);
 		gsb_data_account_set_bank_branch_code (account_number, NULL);
 		gsb_data_account_set_bank_account_number (account_number, NULL);
 		gsb_data_account_set_bank_account_key (account_number, NULL);

Index: gsb_assistant_first.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_assistant_first.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- gsb_assistant_first.c	27 Apr 2009 19:41:03 -0000	1.24
+++ gsb_assistant_first.c	8 May 2009 09:35:10 -0000	1.25
@@ -45,10 +45,14 @@
 /*START_STATIC*/
 static  gboolean gsb_assistant_first_enter_page_2 ( GtkWidget *assistant,
 						   gint new_page );
+static  gboolean gsb_assistant_first_enter_page_3 ( GtkWidget *assistant,
+						   gint new_page );
 static  GtkWidget *gsb_assistant_first_page_2 ( GtkWidget *assistant );
+static  GtkWidget *gsb_assistant_first_page_3 ( GtkWidget *assistant );
 /*END_STATIC*/
 
 /*START_EXTERN*/
+extern gboolean result_reconcile;
 extern GtkWidget *window;
 /*END_EXTERN*/
 
@@ -56,6 +60,7 @@
 {
     FIRST_ASSISTANT_INTRO= 0,
     FIRST_ASSISTANT_PAGE_2,
+    FIRST_ASSISTANT_PAGE_3,
     FIRST_ASSISTANT_PAGE_FINISH,
 };
 
@@ -149,8 +154,14 @@
 			     gsb_assistant_first_page_2 (assistant),
 			     FIRST_ASSISTANT_PAGE_2,
 			     FIRST_ASSISTANT_INTRO,
-			     0,
+			     FIRST_ASSISTANT_PAGE_3,
 			     G_CALLBACK (gsb_assistant_first_enter_page_2) );
+    gsb_assistant_add_page ( assistant,
+			     gsb_assistant_first_page_3 (assistant),
+			     FIRST_ASSISTANT_PAGE_3,
+			     FIRST_ASSISTANT_PAGE_2,
+			     0,
+			     G_CALLBACK (gsb_assistant_first_enter_page_3) );
 
     /* now we launch the assistant */
     return_value = gsb_assistant_run (assistant);
@@ -289,12 +300,82 @@
     gtk_box_pack_start ( GTK_BOX ( hbox ), button,
 			 FALSE, TRUE, 0);
 
+    gtk_widget_show_all (page);
+    return page;
+}
+
+
+/**
+ * create the page 3 of the first assistant
+ * this is the page for report error of reconcile import of an old grisbi file
+ *
+ * \param assistant the GtkWidget assistant
+ *
+ * \return a GtkWidget containing the page
+ * */
+static GtkWidget *gsb_assistant_first_page_3 ( GtkWidget *assistant )
+{
+    GtkWidget *page;
+    GtkWidget *vbox;
+    GtkWidget *label;
+    //~ GtkWidget *entry;
+    //~ GtkWidget *button;
+    GtkWidget *paddingbox;
+    //~ GtkWidget *table;
+    GtkSizeGroup *size_group;
+    //~ gchar *text;
+    GtkWidget *hbox;
+    GtkWidget *image;
+
+    page = gtk_hbox_new (FALSE, 15);
+    gtk_container_set_border_width ( GTK_CONTAINER (page), 10 );
+
+    size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+
+    vbox = new_vbox_with_title_and_icon ( _("Reconciliation"), "reconciliationlg.png" );
+    gtk_box_pack_start ( GTK_BOX (page), vbox, TRUE, TRUE, 0 );
+
+    paddingbox = new_paddingbox_with_title (vbox, FALSE,
+					    _("Error getting reconciliations"));
+
+    hbox = gtk_hbox_new ( FALSE, 15 );
+    gtk_box_pack_start ( GTK_BOX ( paddingbox ), hbox, FALSE, FALSE, 15 );
+
+    image = gtk_image_new_from_stock ( GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG );
+    gtk_box_pack_start ( GTK_BOX ( hbox ), image, FALSE, FALSE, 0);
+
+    label = gtk_label_new ( _("When importing the file from the previous version, "
+                              "Grisbi has found inconsistencies\n"
+                              "and could not restore all the reconciliatoins of one or "
+                              "more accounts.\n\n"
+                              "Although this has no impact on the integrity of data, "
+                              "wrong values can be found.\n\n"
+                              "Check in the \"Preferences\" for more information.") );
+    gtk_box_pack_start ( GTK_BOX ( hbox ), label, FALSE, FALSE, 0);
 
     gtk_widget_show_all (page);
     return page;
 }
 
 
+/**
+ * If error creating reconcilaitions, display the third page 
+ * otherwise exit normally
+ *
+ * \param assistant
+ * \param new_page
+ *
+ * \return FALSE
+ * */
+static gboolean gsb_assistant_first_enter_page_2 ( GtkWidget *assistant,
+						   gint new_page )
+{
+    if ( result_reconcile == TRUE )
+        gsb_assistant_change_button_next ( assistant, GTK_STOCK_GO_FORWARD, 
+				       GTK_RESPONSE_APPLY );
+
+    return FALSE;
+}
 
 /**
  * keep the forward button of the last page instead of
@@ -305,10 +386,9 @@
  *
  * \return FALSE
  * */
-static gboolean gsb_assistant_first_enter_page_2 ( GtkWidget *assistant,
+static gboolean gsb_assistant_first_enter_page_3 ( GtkWidget *assistant,
 						   gint new_page )
 {
-
     gsb_assistant_change_button_next ( assistant, GTK_STOCK_GO_FORWARD, 
 				       GTK_RESPONSE_APPLY );
 

Index: gsb_file.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_file.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- gsb_file.c	27 Apr 2009 19:41:03 -0000	1.45
+++ gsb_file.c	8 May 2009 09:35:10 -0000	1.46
@@ -434,8 +434,6 @@
 
 	account_number = gsb_data_account_get_no_account ( list_tmp -> data );
 
-	gsb_data_account_calculate_current_and_marked_balances (account_number);
-
 	/* set the minimum balances to be shown or not */
 	value = gsb_real_cmp ( gsb_data_account_get_current_balance (account_number), gsb_data_account_get_mini_balance_authorized (account_number)) == -1;
 		gsb_data_account_set_mini_balance_authorized_message ( account_number, value);

Index: gsb_form_transaction.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_form_transaction.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- gsb_form_transaction.c	4 May 2009 20:20:00 -0000	1.42
+++ gsb_form_transaction.c	8 May 2009 09:35:10 -0000	1.43
@@ -485,9 +485,6 @@
     else
 	gsb_transactions_list_update_transaction (contra_transaction_number);
 
-    /* recalculates the balance of the transfer account */
-    gsb_data_account_calculate_current_and_marked_balances ( account_transfer );
-
     return contra_transaction_number;
 }
 

Index: gsb_transactions_list.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_transactions_list.c,v
retrieving revision 1.159
retrieving revision 1.160
diff -u -d -r1.159 -r1.160
--- gsb_transactions_list.c	27 Apr 2009 19:41:03 -0000	1.159
+++ gsb_transactions_list.c	8 May 2009 09:35:10 -0000	1.160
@@ -611,11 +611,6 @@
     /* append the transaction to the tree view */
     transaction_list_append_transaction (transaction_number);
 
-    /*  set the new current balance */
-    gsb_data_account_set_current_balance ( account_number,
-					   gsb_real_add ( gsb_data_account_get_current_balance (account_number),
-							  gsb_data_transaction_get_adjusted_amount (transaction_number, -1)));
-
     /* update the transaction list only if the account is showed,
      * else it's because we execute a scheduled transaction and all
      * of that stuff will be done when we will show the account */
@@ -1449,17 +1444,11 @@
 
     if (gsb_data_transaction_get_marked_transaction (transaction_number))
     {
-	gsb_data_account_set_marked_balance ( account_number,
-					      gsb_real_sub ( gsb_data_account_get_marked_balance (account_number),
-							     amount ));
 	gsb_data_transaction_set_marked_transaction ( transaction_number,
 						      OPERATION_NORMALE );
     }
     else
     {
-	gsb_data_account_set_marked_balance ( account_number,
-					      gsb_real_add ( gsb_data_account_get_marked_balance (account_number),
-							     amount ));
 	gsb_data_transaction_set_marked_transaction ( transaction_number,
 						      OPERATION_POINTEE );
     }
@@ -1575,9 +1564,6 @@
     if ( gsb_data_transaction_get_marked_transaction ( transaction_number) == OPERATION_RAPPROCHEE)
     {
 	/* ok, this is a R transaction, we just un-R it but keep the reconcile_number into the transaction */
-	gsb_data_account_set_marked_balance ( account_number,
-					      gsb_real_sub ( gsb_data_account_get_marked_balance (account_number),
-							     amount ));
 	gsb_data_transaction_set_marked_transaction ( transaction_number,
 						      OPERATION_NORMALE );
 	transaction_list_set ( &iter,
@@ -1596,9 +1582,6 @@
 	if (!reconcile_number)
 	    return FALSE;
 
-	gsb_data_account_set_marked_balance ( account_number,
-					      gsb_real_add ( gsb_data_account_get_marked_balance (account_number),
-							     amount ));
 	gsb_data_transaction_set_marked_transaction ( transaction_number,
 						      OPERATION_RAPPROCHEE );
 	gsb_data_transaction_set_reconcile_number ( transaction_number,
@@ -2476,8 +2459,6 @@
 
 	update_transaction_in_trees (gsb_data_account_get_current_transaction_number (source_account));
 
-	gsb_data_account_calculate_current_and_marked_balances (source_account);
-
 	if (gsb_data_account_get_current_balance (source_account).mantissa < 0)
 	    string = g_strdup_printf ( "<span color=\"red\">%s</span>",
 				       gsb_real_get_string_with_currency ( gsb_data_account_get_current_balance (source_account),
@@ -2519,8 +2500,6 @@
 
 	update_transaction_in_trees (gsb_data_account_get_current_transaction_number (source_account));
 
-	gsb_data_account_calculate_current_and_marked_balances (source_account);
-
 	if (gsb_data_account_get_current_balance (source_account).mantissa < 0)
 	    string = g_strdup_printf ( "<span color=\"red\">%s</span>",
 				       gsb_real_get_string_with_currency ( gsb_data_account_get_current_balance (source_account),
@@ -2593,9 +2572,6 @@
 	current_account == target_account)
         gsb_transactions_list_update_tree_view ( current_account, FALSE );
 
-    /* recalculates the balance of the current account */
-    gsb_data_account_calculate_current_and_marked_balances (target_account);
-
     /* update the first page */
     mise_a_jour_liste_comptes_accueil = 1;
     mise_a_jour_soldes_minimaux = 1;

Index: gsb_form.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_form.c,v
retrieving revision 1.119
retrieving revision 1.120
diff -u -d -r1.119 -r1.120
--- gsb_form.c	27 Apr 2009 19:41:03 -0000	1.119
+++ gsb_form.c	8 May 2009 09:35:10 -0000	1.120
@@ -2267,18 +2267,6 @@
 							 mother_transaction,
 							 is_transaction );
 	}
-	else
-	{
-	    /* it's not a new transaction, if it's not a child split,
-	     * we remove the amount of that transaction from the balance of the account,
-	     * because later, the amount will be add again to the balance */
-	    if ( is_transaction
-		 &&
-		 !gsb_data_transaction_get_mother_transaction_number (transaction_number))
-            gsb_data_account_set_current_balance ( account_number,
-                        gsb_real_sub ( gsb_data_account_get_current_balance (account_number),
-                        gsb_data_transaction_get_adjusted_amount (transaction_number, -1)));
-	}
 
 	/* take the datas in the form, except the category */
 	gsb_form_take_datas_from_form ( transaction_number, is_transaction );
@@ -2379,9 +2367,6 @@
             transaction_list_show_toggle_mark (TRUE);
         else
         {
-            /* we are reconciling and it's a modification of transaction, need to 
-             * recalculate the marked balance */
-            gsb_data_account_calculate_marked_balance (account_number);
             gsb_reconcile_update_amounts (NULL, NULL);
         }
     }

Index: navigation.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/navigation.c,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- navigation.c	27 Apr 2009 19:41:03 -0000	1.118
+++ navigation.c	8 May 2009 09:35:11 -0000	1.119
@@ -63,40 +63,40 @@
 /*START_STATIC*/
 static void create_report_list ( GtkTreeModel * model, GtkTreeIter * reports_iter );
 static gboolean gsb_gui_navigation_check_key_press ( GtkWidget *tree_view,
-					      GdkEventKey *ev,
-					      GtkTreeModel *model );
+                        GdkEventKey *ev,
+                        GtkTreeModel *model );
 static  gboolean gsb_gui_navigation_remove_account_iterator ( GtkTreeModel * tree_model, 
-							     GtkTreePath *path, 
-							     GtkTreeIter *iter, 
-							     gpointer data );
+                        GtkTreePath *path, 
+                        GtkTreeIter *iter, 
+                        gpointer data );
 static  gboolean gsb_gui_navigation_remove_report_iterator ( GtkTreeModel * tree_model, 
-							     GtkTreePath *path, 
-							     GtkTreeIter *iter, 
-							     gpointer data );
+                        GtkTreePath *path, 
+                        GtkTreeIter *iter, 
+                        gpointer data );
 static gboolean gsb_gui_navigation_select_line ( GtkTreeSelection *selection,
-					  GtkTreeModel *model );
+                        GtkTreeModel *model );
 static void gsb_gui_navigation_set_selection_branch ( GtkTreeSelection * selection, 
-					       GtkTreeIter * iter, gint page, 
-					       gint account_number, gpointer report );
+					    GtkTreeIter * iter, gint page, 
+					    gint account_number, gpointer report );
 static void gsb_gui_navigation_update_account_iter ( GtkTreeModel * model, 
-					      GtkTreeIter * account_iter,
-					      gint account_number );
+                        GtkTreeIter * account_iter,
+                        gint account_number );
 static  gboolean gsb_gui_navigation_update_account_iterator ( GtkTreeModel * tree_model, 
-							     GtkTreePath *path, 
-							     GtkTreeIter *iter, 
-							     gpointer data );
+                        GtkTreePath *path, 
+                        GtkTreeIter *iter, 
+                        gpointer data );
 static void gsb_gui_navigation_update_report_iter ( GtkTreeModel * model, 
-					     GtkTreeIter * report_iter,
-					     gint report_number );
+                        GtkTreeIter * report_iter,
+                        gint report_number );
 static  gboolean gsb_gui_navigation_update_report_iterator ( GtkTreeModel * tree_model, 
-							    GtkTreePath *path, 
-							    GtkTreeIter *iter, 
-							    gpointer data );
+                        GtkTreePath *path, 
+                        GtkTreeIter *iter, 
+                        gpointer data );
 static gboolean navigation_sort_column ( GtkTreeModel * model, 
-				  GtkTreeIter * a, GtkTreeIter * b, 
-				  gpointer user_data );
+                        GtkTreeIter * a, GtkTreeIter * b, 
+                        gpointer user_data );
 static gboolean navigation_tree_drag_data_get ( GtkTreeDragSource * drag_source, GtkTreePath * path,
-					 GtkSelectionData * selection_data );
+                        GtkSelectionData * selection_data );
 /*END_STATIC*/
 
 
@@ -609,8 +609,8 @@
  *
  */
 gboolean navigation_sort_column ( GtkTreeModel * model, 
-				  GtkTreeIter * a, GtkTreeIter * b, 
-				  gpointer user_data )
+                        GtkTreeIter * a, GtkTreeIter * b, 
+                        gpointer user_data )
 {
     gint page_a, page_b, account_a, account_b, report_a, report_b;
 
@@ -668,9 +668,9 @@
  * \return TRUE if this iter matches.
  */
 static gboolean gsb_gui_navigation_update_account_iterator ( GtkTreeModel * tree_model, 
-							     GtkTreePath *path, 
-							     GtkTreeIter *iter, 
-							     gpointer data )
+                        GtkTreePath *path, 
+                        GtkTreeIter *iter, 
+                        gpointer data )
 {
     gint account_number;
 
@@ -702,9 +702,9 @@
  * \return TRUE if this iter matches.
  */
 static gboolean gsb_gui_navigation_update_report_iterator ( GtkTreeModel * tree_model, 
-							    GtkTreePath *path, 
-							    GtkTreeIter *iter, 
-							    gpointer data )
+                        GtkTreePath *path, 
+                        GtkTreeIter *iter, 
+                        gpointer data )
 {
     gint report_nb;
 
@@ -745,8 +745,8 @@
  * \param data		Number of report as a reference.
  */
 void gsb_gui_navigation_update_report_iter ( GtkTreeModel * model, 
-					     GtkTreeIter * report_iter,
-					     gint report_number )
+                        GtkTreeIter * report_iter,
+                        gint report_number )
 {
     gtk_tree_store_set(GTK_TREE_STORE(model), report_iter, 
 		       NAVIGATION_TEXT, gsb_data_report_get_report_name (report_number), 
@@ -772,9 +772,9 @@
  * \return TRUE if this iter matches.
  */
 static gboolean gsb_gui_navigation_remove_report_iterator ( GtkTreeModel * tree_model, 
-							     GtkTreePath *path, 
-							     GtkTreeIter *iter, 
-							     gpointer data )
+                        GtkTreePath *path, 
+                        GtkTreeIter *iter, 
+                        gpointer data )
 {
     gint report;
 
@@ -855,8 +855,8 @@
  * \param data		Number of account as a reference.
  */
 void gsb_gui_navigation_update_account_iter ( GtkTreeModel * model, 
-					      GtkTreeIter * account_iter,
-					      gint account_number )
+                        GtkTreeIter * account_iter,
+                        gint account_number )
 {
     GdkPixbuf * pixbuf = NULL;
 
@@ -889,9 +889,9 @@
  * \return TRUE if this iter matches.
  */
 static gboolean gsb_gui_navigation_remove_account_iterator ( GtkTreeModel * tree_model, 
-							     GtkTreePath *path, 
-							     GtkTreeIter *iter, 
-							     gpointer data )
+                        GtkTreePath *path, 
+                        GtkTreeIter *iter, 
+                        gpointer data )
 {
     gint account_number;
 
@@ -917,7 +917,7 @@
  * \param switch_to_account TRUE to show the account, FALSE to just create it
  */
 void gsb_gui_navigation_add_account ( gint account_number,
-				      gboolean switch_to_account )
+                        gboolean switch_to_account )
 {
     GtkTreeIter parent, iter;
 
@@ -1042,15 +1042,16 @@
     reconcile_number = gsb_data_reconcile_get_account_last_number (account_number);
     if (reconcile_number)
     {
-        gchar* tmpstr2 = gsb_format_gdate (gsb_data_reconcile_get_final_date (reconcile_number));
+        gchar* tmpstr2 = gsb_format_gdate (gsb_data_reconcile_get_final_date (
+                                            reconcile_number));
         gchar* tmpstr = g_strdup_printf ( _("Last statement: %s"), tmpstr2);
-	gtk_label_set_text ( GTK_LABEL ( label_last_statement ), tmpstr);
-	g_free ( tmpstr );
-	g_free ( tmpstr2 );
+        gtk_label_set_text ( GTK_LABEL ( label_last_statement ), tmpstr);
+        g_free ( tmpstr );
+        g_free ( tmpstr2 );
     }
     else
-	gtk_label_set_text ( GTK_LABEL ( label_last_statement ),
-			     _("Last statement: none") );
+        gtk_label_set_text ( GTK_LABEL ( label_last_statement ),
+                                            _("Last statement: none") );
 }
 
 
@@ -1120,7 +1121,7 @@
  * \return FALSE
  */
 gboolean gsb_gui_navigation_select_line ( GtkTreeSelection *selection,
-					  GtkTreeModel *model )
+                        GtkTreeModel *model )
 {
     GtkWidget * account_notebook;
     gint account_number, page_number;
@@ -1363,8 +1364,8 @@
  * \return		TRUE on success.
  */
 void gsb_gui_navigation_set_selection_branch ( GtkTreeSelection * selection, 
-					       GtkTreeIter * iter, gint page, 
-					       gint account_number, gpointer report )
+					    GtkTreeIter * iter, gint page, 
+					    gint account_number, gpointer report )
 {
     do 
     {
@@ -1499,8 +1500,8 @@
  * \return FALSE : the signal continue / TRUE : the signal is stopped here
  * */
 gboolean gsb_gui_navigation_check_key_press ( GtkWidget *tree_view,
-					      GdkEventKey *ev,
-					      GtkTreeModel *model )
+                        GdkEventKey *ev,
+                        GtkTreeModel *model )
 {
     gint page;
     GtkTreeIter iter;
@@ -1563,7 +1564,7 @@
  * \return FALSE, to allow future processing by the callback chain.
  */
 gboolean navigation_tree_drag_data_get ( GtkTreeDragSource * drag_source, GtkTreePath * path,
-					 GtkSelectionData * selection_data )
+                        GtkSelectionData * selection_data )
 {
     gchar *tmpstr = gtk_tree_path_to_string (path);
     gchar *tmpstr2 = g_strdup_printf ( "Orig path : %s", tmpstr);
@@ -1587,8 +1588,8 @@
  *
  */
 gboolean navigation_drag_data_received ( GtkTreeDragDest * drag_dest,
-					 GtkTreePath * dest_path,
-					 GtkSelectionData * selection_data )
+                        GtkTreePath * dest_path,
+                        GtkSelectionData * selection_data )
 {
     gchar *tmpstr = gtk_tree_path_to_string (dest_path);
     gchar *tmpstr2 = g_strdup_printf ( "Dest path : %s", tmpstr);
@@ -1650,8 +1651,8 @@
  *
  */
 gboolean navigation_row_drop_possible ( GtkTreeDragDest * drag_dest, 
-					GtkTreePath * dest_path,
-					GtkSelectionData * selection_data )
+                        GtkTreePath * dest_path,
+                        GtkSelectionData * selection_data )
 {
     if ( dest_path && selection_data )
     {

Index: gsb_reconcile.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_reconcile.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- gsb_reconcile.c	27 Apr 2009 19:41:03 -0000	1.35
+++ gsb_reconcile.c	8 May 2009 09:35:10 -0000	1.36
@@ -299,10 +299,6 @@
 
     account_number = gsb_gui_navigation_get_current_account ();
 
-    /* normally the marked balance is set all the time, but in case
-     * of bug, better to recalculate here because don't take too much time */
-    gsb_data_account_calculate_marked_balance (account_number);
-
     reconcile_number = gsb_data_reconcile_get_account_last_number (account_number);
 
     /* get the last reconcile number and try to increase the number in the name */

Index: import.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/import.c,v
retrieving revision 1.275
retrieving revision 1.276
diff -u -d -r1.275 -r1.276
--- import.c	27 Apr 2009 19:41:03 -0000	1.275
+++ import.c	8 May 2009 09:35:11 -0000	1.276
@@ -1368,9 +1368,6 @@
 		break;
 	}
 
-	/* update the current and marked balance */
-	gsb_data_account_calculate_current_and_marked_balances (account_number);
-
 	/* first, we create the rule if asked */
 	if (compte -> create_rule && compte -> action != IMPORT_CREATE_ACCOUNT)
 	{
@@ -1705,10 +1702,6 @@
     /* set the initial balance */
     gsb_data_account_set_init_balance ( account_number,
 					imported_account -> solde);
-    gsb_data_account_set_current_balance ( account_number,
-					   imported_account -> solde);
-    gsb_data_account_set_marked_balance ( account_number,
-					  imported_account -> solde);
 
     /* Use two lines view by default. */
     gsb_data_account_set_nb_rows ( account_number, 2 );
@@ -4012,8 +4005,6 @@
 		pointe_opes_importees (account);
 		break;
 	}
-	/* update the current and marked balance */
-	gsb_data_account_calculate_current_and_marked_balances (account_number);
 
 	/* save the charmap for the last file used */
 	gsb_data_import_rule_set_charmap (rule, charmap_imported);

Index: gsb_data_reconcile.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_data_reconcile.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- gsb_data_reconcile.c	27 Apr 2009 19:41:03 -0000	1.17
+++ gsb_data_reconcile.c	8 May 2009 09:35:10 -0000	1.18
@@ -1,8 +1,8 @@
 /* ************************************************************************** */
 /*                                                                            */
-/*     Copyright (C)	2000-2008 Cédric Auger (cedric at grisbi.org)	      */
-/*			2003-2008 Benjamin Drieu (bdrieu at april.org)	      */
-/* 			http://www.grisbi.org				      */
+/*     Copyright (C)	2000-2008 Cédric Auger (cedric at grisbi.org)	          */
+/*			2003-2008 Benjamin Drieu (bdrieu at april.org)	                      */
+/* 			http://www.grisbi.org				                              */
 /*                                                                            */
 /*  This program is free software; you can redistribute it and/or modify      */
 /*  it under the terms of the GNU General Public License as published by      */
@@ -58,6 +58,8 @@
 
 /*START_STATIC*/
 static  void _gsb_data_reconcile_free ( struct_reconcile *reconcile );
+static gint gsb_data_reconcile_cmp_int (struct_reconcile *reconcile_1,
+                                 struct_reconcile *reconcile_2);
 static gpointer gsb_data_reconcile_get_structure ( gint reconcile_number );
 static gint gsb_data_reconcile_max_number ( void );
 /*END_STATIC*/
@@ -539,11 +541,14 @@
 
     /* we free the last date */
     if ( reconcile -> reconcile_final_date )
-	g_date_free (reconcile -> reconcile_final_date);
+        g_date_free (reconcile -> reconcile_final_date);
 
     /* and copy the new one */
     reconcile -> reconcile_final_date = gsb_date_copy (date);
 
+    /* retrie la liste */
+    reconcile_list = g_list_sort ( reconcile_list, (GCompareFunc) gsb_data_reconcile_cmp_int );
+
     return TRUE;
 }
 
@@ -645,74 +650,17 @@
  * */
 gint gsb_data_reconcile_get_account_last_number ( gint account_number )
 {
-    GList *tmp;
-    gint number_tmp = 0;
-
-    tmp = reconcile_list;
-
-    while ( tmp )
-    {
-	struct_reconcile *reconcile;
-
-	reconcile = tmp -> data;
-
-	if ( reconcile -> account_number == account_number
-	     &&
-	     reconcile -> reconcile_number > number_tmp )
-	    number_tmp = reconcile -> reconcile_number;
-
-	tmp = tmp -> next;
-    }
-    return number_tmp;
-}
-
-
-/**
- * find the previous reconcile in the same account
- *
- * \param reconcile_number
- *
- * \return the previous reconcile or 0 if it was the first
- * */
-gint gsb_data_reconcile_get_previous ( gint reconcile_number )
-{
     GList *tmp_list;
-    struct_reconcile *reconcile;
-    gint account_number;
-
-    /* first we localize the GList struct of that reconcile */
-    tmp_list = reconcile_list;
-    while (tmp_list)
-    {
-	reconcile = tmp_list -> data;
-
-	if (reconcile -> reconcile_number == reconcile_number)
-	    break;
-	tmp_list = tmp_list -> next;
-    }
-
-    
-    /* ok, here tmp_list points normally on the GList of the reconcile */
-    if (!tmp_list)
-	return 0;
-
-    /* now, try to find the previous reconcile for the same account */
-    account_number = reconcile -> account_number;
-    tmp_list = tmp_list -> prev;
-
-    while (tmp_list)
-    {
-	reconcile = tmp_list -> data;
-
-	if (reconcile -> account_number == account_number)
-	    return reconcile -> reconcile_number;
-	tmp_list = tmp_list -> prev;
-    }
 
-    /* no previous, return 0 */
-    return 0;
+    tmp_list = g_list_last ( gsb_data_reconcile_get_sort_reconcile_list (
+                                        account_number) );
+    if ( tmp_list )
+        return GPOINTER_TO_INT ( tmp_list -> data );
+    else
+        return 0;
 }
 
+
 /**
  * try to find a reconcile wich contains the date given in param
  * for the given account
@@ -752,3 +700,68 @@
     }
     return 0;
 }
+
+
+/**
+ * renvoie la liste des rapprochements triée par date pour un compte donné
+ *
+ * \param account_number
+ *
+ * \return the reconcile list for that account
+ * */
+GList *gsb_data_reconcile_get_sort_reconcile_list ( gint account_number )
+{
+    GList *tmp_list;
+    GList *rec_list = NULL;
+    GList *new_list = NULL;
+    struct_reconcile *reconcile;
+
+    /* first we localize the GList struct of that reconcile */
+    tmp_list = reconcile_list;
+    while (tmp_list)
+    {
+        reconcile = tmp_list -> data;
+
+        if (reconcile -> account_number == account_number)
+        {
+            rec_list = g_list_insert_sorted ( rec_list, reconcile, 
+                                             (GCompareFunc) gsb_data_reconcile_cmp_int );
+        }
+	   
+        tmp_list = tmp_list -> next;
+    }
+
+    tmp_list = rec_list;
+    while (tmp_list)
+    {
+        reconcile = tmp_list -> data;
+        
+        new_list = g_list_append ( new_list, GINT_TO_POINTER (
+                                    reconcile -> reconcile_number) );
+        tmp_list = tmp_list -> next;
+    }
+    return new_list;
+}
+
+
+/**
+ * compare deux rapprochements par date
+ *
+ * \param reconcile_1, reconcile_2
+ *
+ * \return 0 -1 1 comme strcmp
+ * */
+gint gsb_data_reconcile_cmp_int (struct_reconcile *reconcile_1,
+                                 struct_reconcile *reconcile_2)
+{
+    if ( ! reconcile_1 -> reconcile_final_date )
+        return -1;
+    else if ( ! reconcile_2 -> reconcile_final_date )
+        return 1;
+    else
+        return g_date_compare ( reconcile_1 -> reconcile_final_date,
+                           reconcile_2 -> reconcile_final_date );
+}
+/* Local Variables: */
+/* c-basic-offset: 4 */
+/* End: */

Index: gsb_data_account.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_data_account.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- gsb_data_account.c	27 Apr 2009 19:41:03 -0000	1.70
+++ gsb_data_account.c	8 May 2009 09:35:10 -0000	1.71
@@ -76,6 +76,7 @@
     gsb_real 	init_balance;
     gsb_real 	mini_balance_wanted;
     gsb_real 	mini_balance_authorized;
+    gboolean    balances_are_dirty;
     gsb_real 	current_balance;
     gsb_real 	marked_balance;
 
@@ -117,6 +118,7 @@
 static void gsb_data_account_delete_all_accounts (void);
 static struct_account *gsb_data_account_get_structure ( gint no );
 static gint gsb_data_account_max_number ( void );
+static gsb_real gsb_data_account_calculate_current_and_marked_balances ( gint account_number );
 static gboolean gsb_data_account_set_default_sort_values ( gint account_number );
 static gboolean gsb_data_form_dup_sort_values ( gint origin_account,
 					 gint target_account );
@@ -820,10 +822,11 @@
 
     account = gsb_data_account_get_structure ( account_number );
 
-    if (!account )
-	return FALSE;
+    if ( !account )
+        return FALSE;
 
     account -> init_balance = balance;
+    account -> balances_are_dirty = TRUE;
 
     return TRUE;
 }
@@ -917,46 +920,23 @@
 }
 
 
-
 /**
- * get the current balance  of the account
- * 
- * \param account_number no of the account
- * 
- * \return balance or 0 if the account doesn't exist
- * */
-gsb_real gsb_data_account_get_current_balance ( gint account_number )
-{
-    struct_account *account;
-
-    account = gsb_data_account_get_structure ( account_number );
-
-    if (!account )
-	return null_real;
-
-    return account -> current_balance;
-}
-
-
-/**
- * set the current balance  of the account
+ * flag the current and marked balance dirty to force recompute
  * 
  * \param account_number no of the account
- * \param balance balance to set
  * 
  * \return TRUE, ok ; FALSE, problem
  * */
-gboolean gsb_data_account_set_current_balance ( gint account_number,
-						gsb_real balance )
+gboolean gsb_data_account_set_balances_are_dirty ( gint account_number )
 {
     struct_account *account;
 
     account = gsb_data_account_get_structure ( account_number );
 
     if (!account )
-	return FALSE;
+        return FALSE;
 
-    account -> current_balance = balance;
+    account -> balances_are_dirty = TRUE;
 
     return TRUE;
 }
@@ -965,8 +945,8 @@
 
 /**
  * calculate and fill in the account the current and marked balance of that account
- * it's faster than calling gsb_data_account_calculate_current_balance and
- * gsb_data_account_calculate_marked_balance because throw the list only one time
+ * it's faster than calling gsb_data_account_privatecalculate_current_balance and
+ * gsb_data_account_private_calculate_marked_balance because throw the list only one time
  * called especially to init that values
  * the value calculated will have the same exponent of the currency account
  *
@@ -982,10 +962,11 @@
     gsb_real marked_balance;
     gint floating_point;
 
+    devel_debug_int ( account_number );
     account = gsb_data_account_get_structure ( account_number );
 
-    if (!account )
-	return null_real;
+    if ( !account )
+        return null_real;
 
     floating_point = gsb_data_currency_get_floating_point (account -> currency);
 
@@ -1023,99 +1004,57 @@
 }
 
 
-
 /**
- * get the marked balance of the account
- * this is the total of all marked transactions (R, P and T)
+ * get the current balance  of the account
  * 
  * \param account_number no of the account
  * 
  * \return balance or 0 if the account doesn't exist
  * */
-gsb_real gsb_data_account_get_marked_balance ( gint account_number )
+gsb_real gsb_data_account_get_current_balance ( gint account_number )
 {
     struct_account *account;
 
     account = gsb_data_account_get_structure ( account_number );
 
-    if (!account )
-	return null_real;
+    if ( !account )
+        return null_real;
 
-    return account -> marked_balance;
+    if ( account -> balances_are_dirty )
+    {
+        gsb_data_account_calculate_current_and_marked_balances ( account_number );
+        account -> balances_are_dirty = FALSE;
+    }
+    return account -> current_balance;
 }
 
 
 /**
- * set the marked balance  of the account
+ * get the marked balance of the account
  * this is the total of all marked transactions (R, P and T)
  *
  * \param account_number no of the account
- * \param balance balance to set
- * 
- * \return TRUE, ok ; FALSE, problem
- * */
-gboolean gsb_data_account_set_marked_balance ( gint account_number,
-					       gsb_real balance )
-{
-    struct_account *account;
-
-    account = gsb_data_account_get_structure ( account_number );
-
-    if (!account )
-	return FALSE;
-
-    account -> marked_balance = balance;
-
-    return TRUE;
-}
-
-/**
- * calculate and fill in the account the marked balance of that account
- * the value calculated will have the same exponent of the currency account
- *
- * \param account_number
  *
- * \return the marked balance
+ * \return balance or 0 if the account doesn't exist
  * */
-gsb_real gsb_data_account_calculate_marked_balance ( gint account_number )
+gsb_real gsb_data_account_get_marked_balance ( gint account_number )
 {
     struct_account *account;
-    GSList *tmp_list;
-    gsb_real marked_balance;
-    gint floating_point;
 
     account = gsb_data_account_get_structure ( account_number );
 
-    if (!account )
-	return null_real;
-
-    floating_point = gsb_data_currency_get_floating_point (account -> currency);
-    marked_balance = gsb_real_adjust_exponent ( account -> init_balance,
-						floating_point );
-
-    tmp_list = gsb_data_transaction_get_complete_transactions_list ();
+    if ( !account )
+        return null_real;
 
-    while (tmp_list)
+    if( account -> balances_are_dirty )
     {
-	gint transaction_number;
-
-	transaction_number = gsb_data_transaction_get_transaction_number (tmp_list->data);
-
-	if ( gsb_data_transaction_get_account_number (transaction_number) == account_number
-	     &&
-	     !gsb_data_transaction_get_mother_transaction_number (transaction_number)
-	     &&
-	     gsb_data_transaction_get_marked_transaction (transaction_number))
-	    marked_balance = gsb_real_add ( marked_balance,
-					    gsb_data_transaction_get_adjusted_amount (transaction_number, floating_point));
-	tmp_list = tmp_list -> next;
+        gsb_data_account_calculate_current_and_marked_balances( account_number );
+        account -> balances_are_dirty = FALSE;
     }
-
-    account -> marked_balance = marked_balance;
-
-    return marked_balance;
+    return account -> marked_balance;
 }
 
+
 /**
  * calculate the amount of the marked T and P transactions, don't take care of R transactions
  * the value calculated will have the same exponent of the currency account

Index: gsb_file_load.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_file_load.c,v
retrieving revision 1.171
retrieving revision 1.172
diff -u -d -r1.171 -r1.172
--- gsb_file_load.c	3 May 2009 14:30:18 -0000	1.171
+++ gsb_file_load.c	8 May 2009 09:35:10 -0000	1.172
@@ -118,6 +118,9 @@
 					    const gchar *text );
 static void gsb_file_load_scheduled_transactions ( const gchar **attribute_names,
 					    const gchar **attribute_values );
+static gboolean gsb_file_load_set_last_reconcile_data ( gint account_number,
+                        GDate *final_date,
+                        gsb_real final_balance );
 static void gsb_file_load_start_element ( GMarkupParseContext *context,
                         const gchar *element_name,
                         const gchar **attribute_names,
@@ -221,6 +224,7 @@
     gsb_real final_balance;
 };
 
+gboolean result_reconcile = FALSE;
 static GSList *reconcile_conversion_list = NULL;
 static struct reconcile_conversion_struct *buffer_reconcile_conversion;
 
@@ -7000,6 +7004,7 @@
     gint currency_number;
     GSList *list_tmp;
     gint i;
+    GSList *list_tmp_account;
     GSList *list_tmp_transactions;
     GSList *list_tmp_scheduled;
     gint version_number;
@@ -7482,7 +7487,7 @@
 	     * hopefully, we can do that because each reconciled transaction has 
          * its number of reconcile */
 
-	    /* first step, fill the account numbers and try to fill the init 
+        /* first step, fill the account numbers and try to fill the init 
          * and final dates */
 	    list_tmp_transactions = gsb_data_transaction_get_complete_transactions_list ();
 	    while ( list_tmp_transactions )
@@ -7593,38 +7598,20 @@
             list_tmp_transactions = list_tmp_transactions -> next;
 	    }
 
-        /* second step, we find the last reconcile for each account and fill the final date "
-         * and final balance, so really no change for user because that is not calculated */
-	    list_tmp = reconcile_conversion_list;
-	    while ( list_tmp )
-	    {
-		struct reconcile_conversion_struct *reconcile;
-        gint reconcile_number;
-
-		reconcile = list_tmp -> data;
-        reconcile_number = gsb_data_reconcile_get_account_last_number (
-                        reconcile -> account_number );
-		gsb_data_reconcile_set_final_date ( reconcile_number,
-						    reconcile -> final_date );
-		gsb_data_reconcile_set_final_balance ( reconcile_number,
-						       reconcile -> final_balance );
-		list_tmp = list_tmp -> next;
-	    }
-
-	    /* after that, some reconciles can have the account number to -1 
+        /* second step, some reconciles can have the account number to -1 
          * if they hadn't any transactions associated to them,
 	     * we delete them here */
 	    dlist_tmp = gsb_data_reconcile_get_reconcile_list ();
 	    while (dlist_tmp)
 	    {
-		gint reconcile_number;
+            gint reconcile_number;
 
-		reconcile_number = gsb_data_reconcile_get_no_reconcile (dlist_tmp -> data);
+            reconcile_number = gsb_data_reconcile_get_no_reconcile (dlist_tmp -> data);
 
-		dlist_tmp = dlist_tmp -> next;
+            dlist_tmp = dlist_tmp -> next;
 
-		if (gsb_data_reconcile_get_account (reconcile_number) == -1)
-		    gsb_data_reconcile_remove (reconcile_number);
+            if (gsb_data_reconcile_get_account (reconcile_number) == -1)
+                gsb_data_reconcile_remove (reconcile_number);
 	    }
 
 	    /* third step, we want to fill the inital and final balance of
@@ -7635,37 +7622,91 @@
 	     * initial balance of the reconcile).
 	     * so run from the end and go to the start */
 
-	    list_tmp = gsb_data_account_get_list_accounts ();
-	    while (list_tmp)
+	    list_tmp_account = gsb_data_account_get_list_accounts ();
+	    while (list_tmp_account)
 	    {
             gint account_number;
             gint reconcile_number;
+            GList *rec_list = NULL;
+            struct reconcile_conversion_struct *reconcile;
 
-            account_number = gsb_data_account_get_no_account (list_tmp -> data);
+            account_number = gsb_data_account_get_no_account (list_tmp_account -> data);
+
+            list_tmp = reconcile_conversion_list;
+            while ( list_tmp )
+            {
+                gint reconcile_number;
+
+                reconcile = list_tmp -> data;
+
+                if ( reconcile -> account_number == account_number )
+                {
+                    const GDate *final_date;
+                    gint ecart_date;
+
+                    reconcile_number = gsb_data_reconcile_get_account_last_number (
+                                            reconcile -> account_number );
+                    final_date = gsb_data_reconcile_get_final_date ( reconcile_number );
+                    ecart_date = g_date_days_between ( final_date, reconcile -> final_date );
+                    if ( abs (ecart_date) < 10 )
+                    {
+                        gsb_data_reconcile_set_final_date ( reconcile_number,
+                                            reconcile -> final_date );
+                        gsb_data_reconcile_set_final_balance ( reconcile_number,
+                                            reconcile -> final_balance );
+                        result_reconcile = TRUE;
+                    }
+                    else
+                    {
+                        result_reconcile = gsb_file_load_set_last_reconcile_data (
+                                                account_number,
+                                                reconcile -> final_date,
+                                                reconcile -> final_balance);
+                    }
+                    break;
+                }
+                list_tmp = list_tmp -> next;
+            }
 
             /* for each account, we find the last reconcile number, get the 
              * final balance and calculate the initial balance, wich is the
              * final balance of the previous reconcile... */
-            reconcile_number = gsb_data_reconcile_get_account_last_number (
-                        account_number);
-            do
+
+            rec_list = g_list_last ( gsb_data_reconcile_get_sort_reconcile_list (
+                                        account_number) );
+            while (rec_list)
             {
                 gint previous_reconcile_number;
-
+                
+                reconcile_number = GPOINTER_TO_INT ( rec_list -> data );
                 gsb_data_reconcile_set_init_balance ( reconcile_number,
                         gsb_real_sub ( gsb_data_reconcile_get_final_balance (
                         reconcile_number),
                         gsb_data_reconcile_get_init_balance (
                         reconcile_number)));
-                previous_reconcile_number = gsb_data_reconcile_get_previous (reconcile_number);
-                if (previous_reconcile_number)
-                gsb_data_reconcile_set_final_balance ( previous_reconcile_number,
-                                       gsb_data_reconcile_get_init_balance (reconcile_number));
-                reconcile_number = previous_reconcile_number;
-            }
-            while (reconcile_number);
+                if (reconcile_number > 0)
+                    printf ("1 - N° %3d - date : initiale %s "
+                        "finale %s - solde : initial %9s final %9s\n" , 
+                        reconcile_number,
+                        gsb_format_gdate (gsb_data_reconcile_get_init_date (
+                        reconcile_number)),
+                        gsb_format_gdate (gsb_data_reconcile_get_final_date (
+                        reconcile_number)),
+                        gsb_real_get_string (gsb_data_reconcile_get_init_balance (
+                        reconcile_number)),
+                        gsb_real_get_string (gsb_data_reconcile_get_final_balance (
+                        reconcile_number)));
 
-            list_tmp = list_tmp -> next;
+                if ( rec_list -> prev )
+                {
+                    previous_reconcile_number = GPOINTER_TO_INT ( (rec_list -> prev) -> data );
+                    if (previous_reconcile_number)
+                        gsb_data_reconcile_set_final_balance ( previous_reconcile_number,
+                            gsb_data_reconcile_get_init_balance (reconcile_number));
+                }
+                rec_list = rec_list -> prev;
+            }
+            list_tmp_account = list_tmp_account -> next;
 	    }
 
 	    /*
@@ -7703,7 +7744,7 @@
 
 	default :
 	    /* we don't know here the release of that file, give the release needed */
-            tmpstr = g_strdup_printf ( _("Grisbi version %s is needed to open this file.\nYou are using version %s."),
+        tmpstr = g_strdup_printf ( _("Grisbi version %s is needed to open this file.\nYou are using version %s."),
 					       download_tmp_values.grisbi_version,
 					       VERSION );
 	    dialogue_error ( tmpstr);
@@ -7786,6 +7827,70 @@
     return 0;
 }
 
+
+/**
+ * il arrive que le dernier rapprochement effectué ne soit pas le dernier en date. Ce qui
+ * fausse la reconstruction des rapprochements. Dans ce cas on reconstitue le dernier
+ * rapprochement en date à partir du dernier rapprochement effectué.
+ *
+ * \param account_number
+ * \param final_date for account
+ * \param final_balance for account
+ *
+ * \return TRUE is OK
+ * */
+gboolean gsb_file_load_set_last_reconcile_data ( gint account_number,
+                        GDate *final_date,
+                        gsb_real final_balance )
+{
+    GList *rec_list;
+    gsb_real amount = final_balance;
+
+    devel_debug_int ( account_number );
+    rec_list = g_list_last ( gsb_data_reconcile_get_sort_reconcile_list (
+                                        account_number) );
+    while (rec_list)
+    {
+        gint reconcile_number_next;
+        gint reconcile_number;
+        const GDate *last_date_next;
+        const GDate *last_date;
+                
+        reconcile_number = GPOINTER_TO_INT ( rec_list -> data );
+        last_date = gsb_data_reconcile_get_final_date ( reconcile_number );        
+        if ( g_date_compare ( final_date, last_date ) >= 0 )
+        {
+            if ( rec_list -> next )
+            {
+                reconcile_number_next = GPOINTER_TO_INT ( (rec_list -> next) -> data );
+                if ( reconcile_number_next )
+                    last_date_next = gsb_data_reconcile_get_final_date ( reconcile_number_next );
+                if ( g_date_compare ( final_date, last_date_next ) < 0 )
+                {
+                    gsb_data_reconcile_set_final_balance ( 
+                            gsb_data_reconcile_get_account_last_number (account_number),
+                            amount );
+                    return TRUE;
+                }
+            }
+            else
+            {
+                gsb_data_reconcile_set_final_date ( reconcile_number, final_date );
+                gsb_data_reconcile_set_final_balance ( reconcile_number, final_balance );
+                return TRUE;
+            }
+        }
+        else
+        {
+            amount = gsb_real_add (  amount, gsb_data_reconcile_get_init_balance (
+                        reconcile_number));
+        }
+
+        rec_list = rec_list -> prev;
+    }
+
+    return FALSE;
+}
 /* Local Variables: */
 /* c-basic-offset: 4 */
 /* End: */

Index: gsb_data_reconcile.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_data_reconcile.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- gsb_data_reconcile.h	1 Oct 2008 12:34:08 -0000	1.8
+++ gsb_data_reconcile.h	8 May 2009 09:35:10 -0000	1.9
@@ -3,7 +3,7 @@
 
 
 /* START_INCLUDE_H */
-#include "././gsb_real.h"
+#include "./gsb_real.h"
 /* END_INCLUDE_H */
 
 /* START_DECLARATION */
@@ -18,8 +18,8 @@
 gint gsb_data_reconcile_get_number_by_date ( const GDate *date,
 					     gint account_number );
 gint gsb_data_reconcile_get_number_by_name ( const gchar *name );
-gint gsb_data_reconcile_get_previous ( gint reconcile_number );
 GList *gsb_data_reconcile_get_reconcile_list ( void );
+GList *gsb_data_reconcile_get_sort_reconcile_list ( gint account_number );
 gboolean gsb_data_reconcile_init_variables ( void );
 gint gsb_data_reconcile_new ( const gchar *name );
 gboolean gsb_data_reconcile_remove ( gint reconcile_number );

Index: transaction_list.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/transaction_list.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- transaction_list.c	4 May 2009 18:22:27 -0000	1.34
+++ transaction_list.c	8 May 2009 09:35:11 -0000	1.35
@@ -40,7 +40,6 @@
 #include "./gsb_data_account.h"
 #include "./gsb_data_archive.h"
 #include "./gsb_data_archive_store.h"
-#include "./gsb_data_category.h"
 #include "./gsb_data_currency.h"
 #include "./gsb_data_transaction.h"
 #include "./utils_dates.h"
@@ -894,10 +893,6 @@
 	gtk_tree_path_free(path);
     }
 
-    /* update the current balance of the account */
-    gsb_data_account_set_current_balance ( account_number,
-					   current_total );
-
     /* update the headings balance */
     if (gsb_data_account_get_current_balance (account_number).mantissa < 0)
 	string = g_strdup_printf ( "<span color=\"red\">%s</span>",

Index: gsb_data_account.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_data_account.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- gsb_data_account.h	4 Apr 2009 19:51:41 -0000	1.32
+++ gsb_data_account.h	8 May 2009 09:35:10 -0000	1.33
@@ -22,8 +22,6 @@
 
 
 /* START_DECLARATION */
-gsb_real gsb_data_account_calculate_current_and_marked_balances ( gint account_number );
-gsb_real gsb_data_account_calculate_marked_balance ( gint account_number );
 gsb_real gsb_data_account_calculate_waiting_marked_balance ( gint account_number );
 void gsb_data_account_change_account_icon ( GtkWidget *button, gpointer data );
 gint gsb_data_account_compare_position ( gint account_number_1,
@@ -82,6 +80,7 @@
 gboolean gsb_data_account_reorder ( GSList *new_order );
 gint gsb_data_account_set_account_number ( gint account_number,
 					   gint new_no );
+gboolean gsb_data_account_set_balances_are_dirty ( gint account_number );
 gboolean gsb_data_account_set_bank ( gint account_number,
 				     gint bank );
 gboolean gsb_data_account_set_bank_account_iban ( gint account_number, const gchar *iban );
@@ -97,8 +96,6 @@
 					const gchar *comment );
 gboolean gsb_data_account_set_currency ( gint account_number,
 					 gint currency );
-gboolean gsb_data_account_set_current_balance ( gint account_number,
-						gsb_real balance );
 gboolean gsb_data_account_set_current_transaction_number ( gint account_number,
 							   gint transaction_number );
 gboolean gsb_data_account_set_default_credit ( gint account_number,
@@ -120,8 +117,6 @@
 					     gsb_real balance );
 gboolean gsb_data_account_set_kind ( gint account_number,
 				     kind_account account_kind );
-gboolean gsb_data_account_set_marked_balance ( gint account_number,
-					       gsb_real balance );
 gboolean gsb_data_account_set_mini_balance_authorized ( gint account_number,
 							gsb_real balance );
 gboolean gsb_data_account_set_mini_balance_authorized_message ( gint account_number,



More information about the cvs mailing list