[grisbi-cvs] grisbi/src gsb_form.c, 1.157, 1.158 gsb_real.c, 1.74, 1.75 gsb_transactions_list.c, 1.206, 1.207 transaction_list.c, 1.60, 1.61 transaction_list.h, 1.12, 1.13 transaction_list_sort.c, 1.3, 1.4

Pierre Biava pbiava at users.sourceforge.net
Sat Apr 10 23:03:17 CEST 2010


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

Modified Files:
	gsb_form.c gsb_real.c gsb_transactions_list.c 
	transaction_list.c transaction_list.h transaction_list_sort.c 
Log Message:
fixed bug 1043 and minor changes.

Index: transaction_list_sort.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/transaction_list_sort.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- transaction_list_sort.c	5 Apr 2010 21:24:53 -0000	1.3
+++ transaction_list_sort.c	10 Apr 2010 21:03:15 -0000	1.4
@@ -1,7 +1,7 @@
 /* ************************************************************************** */
 /*                                                                            */
-/*     Copyright (C)	2000-2008 Cédric Auger (cedric at grisbi.org)	      */
-/* 			http://www.grisbi.org				      */
+/*     Copyright (C)    2000-2008 Cédric Auger (cedric at grisbi.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      */
@@ -80,17 +80,17 @@
 
     /* resort */
     if (custom_list -> user_sort_reconcile)
-	g_qsort_with_data(custom_list->visibles_rows,
-			  custom_list->num_visibles_rows,
-			  sizeof(CustomRecord*),
-			  (GCompareDataFunc) gsb_reconcile_list_sort_func,
-			  custom_list);
+        g_qsort_with_data(custom_list->visibles_rows,
+                        custom_list->num_visibles_rows,
+                        sizeof(CustomRecord*),
+                        (GCompareDataFunc) gsb_reconcile_list_sort_func,
+                        custom_list);
     else
-	g_qsort_with_data(custom_list->visibles_rows,
-			  custom_list->num_visibles_rows,
-			  sizeof(CustomRecord*),
-			  (GCompareDataFunc) gsb_transactions_list_sort,
-			  custom_list);
+    g_qsort_with_data(custom_list->visibles_rows,
+                        custom_list->num_visibles_rows,
+                        sizeof(CustomRecord*),
+                        (GCompareDataFunc) gsb_transactions_list_sort,
+                        custom_list);
 
     /* let other objects know about the new order */
     neworder = g_new0(gint, custom_list->num_visibles_rows);
@@ -108,8 +108,12 @@
                         //~ gsb_format_gdate ( gsb_data_transaction_get_date (
                         //~ transaction_number ) ),
                         //~ transaction_number);
-	neworder[i] = (custom_list->visibles_rows[i])->filtered_pos;
-	(custom_list->visibles_rows[i])->filtered_pos = i;
+        //~ printf ("transaction_number = %d record -> filtered_pos = %d record -> line_in_transaction =%d\n",
+                        //~ gsb_data_transaction_get_transaction_number ( record -> transaction_pointer),
+                        //~ record -> filtered_pos,
+                        //~ record -> line_in_transaction);
+        neworder[i] = (custom_list->visibles_rows[i])->filtered_pos;
+        (custom_list->visibles_rows[i])->filtered_pos = i;
     }
 
     path = gtk_tree_path_new();
@@ -134,7 +138,7 @@
  * \return
  * */
 void transaction_list_sort_set_column ( gint new_sort_col,
-					GtkSortType new_sort_order )
+                        GtkSortType new_sort_order )
 {
     CustomList *custom_list;
 
@@ -177,7 +181,7 @@
  * \return
  * */
 void transaction_list_sort_get_column ( gint *sort_col,
-					GtkSortType *sort_order )
+                        GtkSortType *sort_order )
 {
     CustomList *custom_list;
 

Index: gsb_transactions_list.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_transactions_list.c,v
retrieving revision 1.206
retrieving revision 1.207
diff -u -d -r1.206 -r1.207
--- gsb_transactions_list.c	5 Apr 2010 21:24:53 -0000	1.206
+++ gsb_transactions_list.c	10 Apr 2010 21:03:15 -0000	1.207
@@ -958,15 +958,17 @@
      * we do that when open the form, so only the last line interest us */
     if (row_align < 0)
     {
-	path = transaction_list_select_get_path (gsb_data_account_get_nb_rows (gsb_gui_navigation_get_current_account())- 1);
-	if ( path )
-	{
-	    gtk_tree_view_scroll_to_cell ( GTK_TREE_VIEW (gsb_transactions_list_get_tree_view ()),
-					   path, NULL,
-					   FALSE, 0.0, 0.0 );
-	    gtk_tree_path_free (path);
-	}
-	return FALSE;
+        path = transaction_list_select_get_path ( transaction_list_get_last_line (
+                            gsb_data_account_get_nb_rows (
+                            gsb_gui_navigation_get_current_account ( ) ) ) );
+        if ( path )
+        {
+            gtk_tree_view_scroll_to_cell ( GTK_TREE_VIEW (gsb_transactions_list_get_tree_view ()),
+                           path, NULL,
+                           FALSE, 0.0, 0.0 );
+            gtk_tree_path_free (path);
+        }
+        return FALSE;
     }
 
     /* ok, we want to use row_align */
@@ -975,17 +977,19 @@
     /* if we are on a child, open the mother */
     mother_transaction = gsb_data_transaction_get_mother_transaction_number (transaction_number);
     if (mother_transaction)
-	gsb_transactions_list_switch_expander (mother_transaction);
+	    gsb_transactions_list_switch_expander (mother_transaction);
 
     /* if we are on white line, go to the end directly,
      * else at the opening, the white line is hidden */
     if (transaction_number == -1)
     {
-	path = transaction_list_select_get_path (gsb_data_account_get_nb_rows (gsb_gui_navigation_get_current_account())- 1);
-	row_align = 1.0;
+        path = transaction_list_select_get_path ( transaction_list_get_last_line (
+                            gsb_data_account_get_nb_rows (
+                            gsb_gui_navigation_get_current_account ( ) ) ) );
+        row_align = 1.0;
     }
     else
-	path = transaction_list_select_get_path (0);
+	    path = transaction_list_select_get_path (0);
 
     /* we need to use scroll_to_cell function because at this stade,
      * the tree view is not refreshed so all value with alignment don't work
@@ -1406,11 +1410,13 @@
 gboolean gsb_transactions_list_edit_transaction ( gint transaction_number )
 {
     devel_debug_int (transaction_number);
+
     gsb_gui_navigation_set_selection ( GSB_ACCOUNT_PAGE,
                         gsb_data_transaction_get_account_number ( transaction_number ),
                         NULL );
     transaction_list_select ( transaction_number );
     gsb_form_fill_by_transaction ( transaction_number, TRUE, TRUE );
+
     return FALSE;
 }
 
@@ -3312,7 +3318,7 @@
     {
         if ( gsb_data_account_get_l ( account_number ) )
 	        return ( gsb_data_archive_store_get_account_number (
-                        gsb_data_archive_store_get_number (transaction_ptr)) == account_number);
+                        gsb_data_archive_store_get_number ( transaction_ptr ) ) == account_number );
         else
             return FALSE;
     }
@@ -3321,11 +3327,11 @@
      * is not shown, so check the basics for the transaction, and show or not after the separator */
 
     /*  check now for transactions */
-    transaction_number = gsb_data_transaction_get_transaction_number (transaction_ptr);
+    transaction_number = gsb_data_transaction_get_transaction_number ( transaction_ptr );
 
     /* check the general white line (one for all the list, so no account number) */
     if ( transaction_number == -1 )
-	return ( line_in_transaction < nb_rows );
+	    return ( display_mode_check_line ( line_in_transaction, nb_rows ) );
 
     /* check the account */
     if ( gsb_data_transaction_get_account_number (transaction_number) != account_number )
@@ -3338,7 +3344,7 @@
 	return FALSE;
 
     /* 	    now we check if we show 1, 2, 3 or 4 lines */
-    return display_mode_check_line (line_in_transaction, nb_rows);
+    return display_mode_check_line ( line_in_transaction, nb_rows );
 }
 
 
@@ -3402,17 +3408,15 @@
 gboolean gsb_transactions_list_switch_expander ( gint transaction_number )
 {
     GtkTreePath *path;
-    gint last_line;
 
     devel_debug_int (transaction_number);
 
     if ( !gsb_data_transaction_get_split_of_transaction ( transaction_number ) )
 	    return FALSE;
 
-    last_line = transaction_list_get_last_line (
-                    gsb_data_account_get_nb_rows (
-                    gsb_gui_navigation_get_current_account ( ) ) );
-    path = transaction_model_get_path ( transaction_number, last_line );
+    path = transaction_list_select_get_path ( transaction_list_get_last_line (
+                            gsb_data_account_get_nb_rows (
+                            gsb_gui_navigation_get_current_account ( ) ) ) );
 
     if ( gtk_tree_view_row_expanded ( GTK_TREE_VIEW ( transactions_tree_view ), path ) )
 	    gtk_tree_view_collapse_row ( GTK_TREE_VIEW ( transactions_tree_view ), path );

Index: gsb_form.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_form.c,v
retrieving revision 1.157
retrieving revision 1.158
diff -u -d -r1.157 -r1.158
--- gsb_form.c	5 Apr 2010 21:24:53 -0000	1.157
+++ gsb_form.c	10 Apr 2010 21:03:14 -0000	1.158
@@ -83,6 +83,7 @@
 #include "./structures.h"
 #include "./erreur.h"
 #include "./gsb_form_widget.h"
+#include "./gsb_real.h"
 /*END_INCLUDE*/
 
 /*START_STATIC*/
@@ -107,6 +108,7 @@
 
 /*START_EXTERN*/
 extern GtkWidget * navigation_tree_view;
+extern gsb_real null_real;
 extern GtkWidget *window;
 /*END_EXTERN*/
 
@@ -2304,6 +2306,7 @@
     gint saved_scheduled_number = 0;
     gint source_transaction_number = -1;
     gint nbre_passage = 0;
+    gint mother_number;
 
     devel_debug (NULL);
 
@@ -2588,23 +2591,24 @@
 	 * we give the focus to the new white line created for that and
 	 * edit it, for that we need to open the transaction to select the
 	 * white line, and set it as current transaction */
-	if (gsb_data_mix_get_split_of_transaction (transaction_number, is_transaction))
+	if ( gsb_data_mix_get_split_of_transaction (transaction_number, is_transaction))
 	{
 	    /* it's a split */
 	    gint white_line_number;
 
 	    white_line_number = gsb_data_mix_get_white_line (transaction_number, is_transaction);
-	    if (is_transaction)
-            transaction_list_select (white_line_number);
+	    if ( is_transaction )
+            transaction_list_select ( white_line_number );
 	    else
             gsb_scheduler_list_select (white_line_number);
 	}
 
 	/* it was a new transaction, we save the last date entry */
-	gsb_date_set_last_date (gtk_entry_get_text ( GTK_ENTRY (gsb_form_widget_get_widget (TRANSACTION_FORM_DATE))));
+	gsb_date_set_last_date ( gtk_entry_get_text (
+                        GTK_ENTRY ( gsb_form_widget_get_widget ( TRANSACTION_FORM_DATE ) ) ) );
 
 	/* we need to use edit_transaction to make a new child split if necessary */
-	if (is_transaction)
+	if ( is_transaction)
 	    gsb_transactions_list_edit_transaction (
                         gsb_data_account_get_current_transaction_number (account_number) );
 	else
@@ -2613,20 +2617,29 @@
     else
         gsb_form_hide ();
 
+    /* on sort de la saisie des opérations filles si variance == 0 */
+    if ( is_transaction
+     &&
+     ( mother_number = gsb_data_transaction_get_mother_transaction_number ( transaction_number ) )
+     &&
+     transaction_list_get_variance ( gsb_data_account_get_current_transaction_number (
+                        account_number ) ) )
+        transaction_list_select ( mother_number );
+     
     /* if it was a modification of transaction, we need to update the sort and colors
      * (done automatically for new transaction) */
-    if (!new_transaction && !execute_scheduled)
+    if ( !new_transaction && !execute_scheduled )
         gsb_transactions_list_update_tree_view (account_number, TRUE);
 
     /* show the warnings */
-    if (is_transaction)
+    if ( is_transaction )
     {
         affiche_dialogue_soldes_minimaux ();
         update_transaction_in_trees (transaction_number);
     }
 
     /* as we modify or create a transaction, we invalidate the current report */
-    gsb_report_set_current (0);
+    gsb_report_set_current ( 0 );
 
 #ifdef ENABLE_BALANCE_ESTIMATE
     /* force the update module budget */
@@ -2641,6 +2654,7 @@
 
     if ( etat.modification_fichier == 0 )
         modification_fichier ( TRUE );
+
     return FALSE;
 }
 
@@ -2720,15 +2734,21 @@
 
     if ( widget && mother_number )
     {
+        gsb_real number = null_real;
+
+        if ( gsb_form_widget_check_empty ( widget ) == FALSE )
+            number = gsb_real_get_from_string ( gtk_entry_get_text ( GTK_ENTRY ( widget ) ) );
+            
 	    if ( gsb_form_widget_check_empty ( widget ) == TRUE
          ||
-         utils_str_atoi ( gtk_entry_get_text ( GTK_ENTRY ( widget ) ) ) == 0 )
+         number.mantissa == 0 )
         {
             widget = gsb_form_widget_get_widget ( TRANSACTION_FORM_CREDIT );
+            number = gsb_real_get_from_string ( gtk_entry_get_text ( GTK_ENTRY ( widget ) ) );
 
             if ( gsb_form_widget_check_empty ( widget ) == TRUE
              ||
-             utils_str_atoi ( gtk_entry_get_text ( GTK_ENTRY ( widget ) ) ) == 0 )
+             number.mantissa == 0 )
                 dialogue_error ( _("You must enter an amount.") );
 
             return (FALSE);

Index: gsb_real.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_real.c,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- gsb_real.c	5 Apr 2010 21:24:53 -0000	1.74
+++ gsb_real.c	10 Apr 2010 21:03:15 -0000	1.75
@@ -854,25 +854,6 @@
 
 
 /**
- * convert a gsb_real to a double
- *
- * \param number a gsb_real number
- *
- * \return the number in double format
- * */
-/*gdouble gsb_real_real_to_double ( gsb_real number )
-{
-    gdouble double_number;
-    gint i;
-
-    double_number = number.mantissa;
-    for ( i=0 ; i<number.exponent ; i++ )
-	double_number = double_number / 10;
-    return double_number;
-}*/
-
-
-/**
  * convert a double to a gsb_real
  *
  * \param number a gdouble number
@@ -890,26 +871,40 @@
     gdouble maxlong;
 
 	gsb_real real_number = {0, exp_add};
-    maxlong = G_MAXLONG / 10;
+    maxlong = G_MAXLONG / 100;
 
-	if(exp_add >=9)
+	if ( exp_add >= 9 )
 		return null_real;
 
-	while ( (modf (number, &tmp_double) ||
-		real_number.exponent < 0 ) &&
-		real_number.exponent < 9)
+    while ( real_number.exponent < 9 )
     {
-	number = number * 10;
-	real_number.exponent++;
+        decimal = modf ( number, &tmp_double );
 
-	if (fabs (number) > maxlong)
-	    number = rint (number);
+        if ( decimal == 0 )
+            break;
+        else if ( ( 1.0 - fabs ( decimal ) ) < 0.0000000001 )
+        {
+            if ( number > 0.0 )
+                number = tmp_double + 1;
+            else
+                number = tmp_double - 1;
+            break;
+        }
+        if ( real_number.exponent < 0 )
+            break;
+
+        number = number * 10;
+        real_number.exponent ++;
+
+        if ( fabs ( number ) > maxlong )
+            number = rint ( number );
     }
 	decimal = modf ( number, &tmp_double );
-	if ( ( (real_number.exponent == (9-exp_add)) ) && (decimal >= 0.5) )
-		real_number.mantissa = ((glong) number ) + 1;
+	if ( ( ( real_number.exponent == ( 9 - exp_add ) ) ) && ( decimal >= 0.5 ) )
+		real_number.mantissa = ( ( glong ) number ) + 1;
 	
-    real_number.mantissa = (glong) (number);
+    real_number.mantissa = ( glong ) ( number );
+
     return real_number;
 }
 
@@ -960,22 +955,6 @@
 }
 
 
-/**
- * div 1 by number
- *
- * \param number
- *
- * \return reverse of number
- * */
-/*gsb_real gsb_real_inverse ( gsb_real number )
-{
-    gsb_real number_tmp;
-
-    number_tmp = gsb_real_double_to_real ( 1.00 / gsb_real_real_to_double ( number ) );
-
-    return number_tmp;
-}*/
-
 /* Function to transform string into gsb_real */
 gsb_real gsb_str_to_real ( const gchar * str )
 {

Index: transaction_list.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/transaction_list.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- transaction_list.h	5 Apr 2010 21:24:53 -0000	1.12
+++ transaction_list.h	10 Apr 2010 21:03:15 -0000	1.13
@@ -13,6 +13,7 @@
 void transaction_list_filter ( gint account_number );
 gint transaction_list_get_last_line ( gint nb_rows );
 gint transaction_list_get_n_children ( gint transaction_number );
+gboolean transaction_list_get_variance ( gint transaction_number );
 gboolean transaction_list_redraw ( void );
 gboolean transaction_list_remove_archive ( gint archive_number );
 gboolean transaction_list_remove_transaction ( gint transaction_number );

Index: transaction_list.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/transaction_list.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- transaction_list.c	5 Apr 2010 21:24:53 -0000	1.60
+++ transaction_list.c	10 Apr 2010 21:03:15 -0000	1.61
@@ -436,8 +436,9 @@
 	}
 
 	/* update the white line */
-	if (transaction_number > 0)
-	    transaction_list_update_white_child (record -> mother_row -> children_rows[new_number_of_children -1]);
+	if ( transaction_number > 0 )
+	    transaction_list_update_white_child (
+                        record -> mother_row -> children_rows[new_number_of_children -1]);
 
 	/* delete the row of the tree view */
 	if (record -> mother_row -> filtered_pos != -1)
@@ -642,7 +643,7 @@
 	CustomRecord *record;
 	gboolean shown;
 	gboolean previous_shown;
-	guint last_pos_filtered_list; 
+	guint last_pos_filtered_list;
 
 	/* get the current record to check */
 	record = custom_list -> rows[current_pos_general_list];
@@ -714,13 +715,17 @@
 		     * the children were not associated to that row, we have to move them */
 		    if (record -> has_expander == FALSE)
 		    {
-			for (i=0 ; i < record -> number_of_children ; i++)
-			    ((CustomRecord *) record -> children_rows[i]) -> mother_row = record;
-			record -> has_expander = TRUE;
+                for (i=0 ; i < record -> number_of_children ; i++)
+			    	((CustomRecord *) record -> children_rows[i]) -> mother_row = record;
+			    record -> has_expander = TRUE;
 		    }
 		}
 		else
 		    record -> has_expander = FALSE;
+        //~ printf ("transaction_number = %d record -> filtered_pos = %d record -> line_in_transaction =%d\n",
+                        //~ gsb_data_transaction_get_transaction_number ( record -> transaction_pointer),
+                        //~ record -> filtered_pos,
+                        //~ record -> line_in_transaction);
 
 		/* the value of the row is set in memory, we update the tree view if necessary */
 		/* if the record was already shown and the position hasn't change, nothing to do */
@@ -878,7 +883,7 @@
 	 ||
 	 line_balance == -1 
 	 ||
-	 !display_mode_check_line (line_balance, gsb_data_account_get_nb_rows (account_number)))
+	 !display_mode_check_line ( line_balance, nb_rows ) )
 	return;
 
     /* begin to fill the iter for later */
@@ -892,53 +897,53 @@
 
     for (i=0 ; i < custom_list -> num_visibles_rows ; i++)
     {
-	CustomRecord *record;
-	gsb_real amount = null_real;
+        CustomRecord *record;
+        gsb_real amount = null_real;
 
-	record = custom_list -> visibles_rows[i];
+        record = custom_list -> visibles_rows[i];
 
-	/* a transaction is several rows, and an archive only one row
-	 * we come only one time for each transaction/archive */
-	if (record -> transaction_pointer == last_transaction_pointer
-	    ||
-	    gsb_data_transaction_get_transaction_number (record -> transaction_pointer) < 0)
-	    continue;
-	last_transaction_pointer = record -> transaction_pointer;
+        /* a transaction is several rows, and an archive only one row
+         * we come only one time for each transaction/archive */
+        if (record -> transaction_pointer == last_transaction_pointer
+            ||
+            gsb_data_transaction_get_transaction_number (record -> transaction_pointer) < 0 )
+            continue;
+        last_transaction_pointer = record -> transaction_pointer;
 
-	switch (record -> what_is_line)
-	{
-	    case IS_ARCHIVE:
-		amount = gsb_data_archive_store_get_balance (
-                        gsb_data_archive_store_get_number (record -> transaction_pointer));
-		break;
+        switch (record -> what_is_line)
+        {
+            case IS_ARCHIVE:
+            amount = gsb_data_archive_store_get_balance (
+                            gsb_data_archive_store_get_number (record -> transaction_pointer));
+            break;
 
-	    case IS_TRANSACTION:
-		amount = gsb_data_transaction_get_adjusted_amount (
-                        gsb_data_transaction_get_transaction_number (
-                        record -> transaction_pointer),
-                        floating_point);
-		/* go on the good row to set the amount */
-		record = record -> transaction_records[line_balance];
-		break;
-	}
+            case IS_TRANSACTION:
+            amount = gsb_data_transaction_get_adjusted_amount (
+                            gsb_data_transaction_get_transaction_number (
+                            record -> transaction_pointer),
+                            floating_point);
+            /* go on the good row to set the amount */
+            record = record -> transaction_records[line_balance];
+            break;
+        }
 
-	/* calculate the new balance */
-	current_total = gsb_real_add ( current_total,
-				       amount);
-	record -> visible_col[column_balance] = gsb_real_get_string_with_currency ( current_total,
-										    gsb_data_account_get_currency (account_number), TRUE);
-	if (current_total.mantissa >= 0)
-	    record -> amount_color = NULL;
-	else
-	    record -> amount_color = "red";
+        /* calculate the new balance */
+        current_total = gsb_real_add ( current_total,
+                           amount);
+        record -> visible_col[column_balance] = gsb_real_get_string_with_currency ( current_total,
+                                                gsb_data_account_get_currency (account_number), TRUE);
+        if (current_total.mantissa >= 0)
+            record -> amount_color = NULL;
+        else
+            record -> amount_color = "red";
 
-	/* inform the tree view the row has changed */
-	/* set the iter */
-	iter.user_data = record;
-	path = gtk_tree_path_new();
-	gtk_tree_path_append_index(path, record->filtered_pos);
-	gtk_tree_model_row_changed(GTK_TREE_MODEL(custom_list), path, &iter);
-	gtk_tree_path_free(path);
+        /* inform the tree view the row has changed */
+        /* set the iter */
+        iter.user_data = record;
+        path = gtk_tree_path_new();
+        gtk_tree_path_append_index(path, record->filtered_pos);
+        gtk_tree_model_row_changed(GTK_TREE_MODEL(custom_list), path, &iter);
+        gtk_tree_path_free(path);
     }
 
     /* update the headings balance */
@@ -987,6 +992,10 @@
     record = iter.user_data;
     if (!record)
 	return FALSE;
+    //~ printf ("transaction_number = %d record -> filtered_pos = %d record -> line_in_transaction = %d\n",
+        //~ transaction_number,
+        //~ record -> filtered_pos,
+        //~ record -> line_in_transaction);
 
     /* if the transaction is a split, we need to check if there are already children,
      * else we add the white line */
@@ -1004,7 +1013,8 @@
 
 	/* create and fill the white line record */
 	white_record = g_malloc0 (sizeof (CustomRecord));
-	white_record -> transaction_pointer = gsb_data_transaction_get_pointer_of_transaction (white_line_number);
+	white_record -> transaction_pointer = gsb_data_transaction_get_pointer_of_transaction (
+                        white_line_number);
 	white_record -> what_is_line = IS_TRANSACTION;
 	white_record -> row_bg = &split_background;
 
@@ -1041,81 +1051,81 @@
 	if (!record -> mother_row)
 	    record = record -> transaction_records[i];
 
-	if ( !record )
-	    return FALSE;
+        if ( !record )
+            return FALSE;
 
-	/* the tmp record will contain the new gchars of columns */
-	tmp_record = transaction_list_create_record (transaction_number, i);
+        /* the tmp record will contain the new gchars of columns */
+        tmp_record = transaction_list_create_record (transaction_number, i);
 
-	for (j=0 ; j<CUSTOM_MODEL_N_VISIBLES_COLUMN ; j++)
-	{
-	    if (record -> visible_col[j])
-		g_free (record -> visible_col[j]);
-	    record -> visible_col[j] = tmp_record -> visible_col[j];
-	}
+        for (j=0 ; j<CUSTOM_MODEL_N_VISIBLES_COLUMN ; j++)
+        {
+            if (record -> visible_col[j])
+                g_free (record -> visible_col[j]);
+            record -> visible_col[j] = tmp_record -> visible_col[j];
+        }
 
-	g_free (tmp_record);
+        g_free (tmp_record);
 
-	/* set the white line if necessary */
-	if (children_rows)
-	{
-	    record -> number_of_children = 1;
-	    record -> children_rows = children_rows;
-	}
+        /* set the white line if necessary */
+        if (children_rows)
+        {
+            record -> number_of_children = 1;
+            record -> children_rows = children_rows;
+        }
 
-	/* set the checkbox is the transaction is marked */
-	if (line_p == i)
-	    record -> checkbox_active = marked_transaction;
+        /* set the checkbox is the transaction is marked */
+        if (line_p == i)
+            record -> checkbox_active = marked_transaction;
 
-	/* inform the tree view we changed the row, only if visible */
-	if (record -> filtered_pos != -1)
-	{
-	    GtkTreePath *path = gtk_tree_path_new();
+        /* inform the tree view we changed the row, only if visible */
+        if (record -> filtered_pos != -1)
+        {
+            GtkTreePath *path = gtk_tree_path_new();
 
-	    /* if there is some children and we are the last row, set the expander */
-	    if (white_record
-		&&
-		i == (custom_list -> nb_rows_by_transaction -1 ))
-	    {
-		record -> has_expander = TRUE;
-		white_record -> mother_row = record;
-	    }
+            /* if there is some children and we are the last row, set the expander */
+            if ( white_record
+            &&
+            i == ( transaction_list_get_last_line ( custom_list -> nb_rows_by_transaction ) ) )
+            {
+                record -> has_expander = TRUE;
+                white_record -> mother_row = record;
+            }
 
-	    /* set the path */
-	    if (record -> mother_row)
-		/* it's a child, need to get the path of the mother */
-		gtk_tree_path_append_index (path, record -> mother_row -> filtered_pos);
-	    gtk_tree_path_append_index(path, record->filtered_pos);
+            /* set the path */
+            if (record -> mother_row)
+            /* it's a child, need to get the path of the mother */
+            gtk_tree_path_append_index (path, record -> mother_row -> filtered_pos);
+            gtk_tree_path_append_index(path, record->filtered_pos);
 
-	    /* set the iter */
-	    iter.user_data = record;
+            /* set the iter */
+            iter.user_data = record;
 
-	    /* update the transaction */
-	    gtk_tree_model_row_changed(GTK_TREE_MODEL(custom_list), path, &iter);
+            /* update the transaction */
+            gtk_tree_model_row_changed(GTK_TREE_MODEL(custom_list), path, &iter);
 
-	    /* if there is a child (white line), set the expander */
-	    if (record -> has_expander)
-		gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (custom_list),
-						      path, &iter);
-	    gtk_tree_path_free(path);
-	}
+            /* if there is a child (white line), set the expander */
+            if (record -> has_expander)
+            gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (custom_list),
+                                  path, &iter);
+            gtk_tree_path_free(path);
+        }
     }
 
     /* if the modification is on a child or a mother, update the white line */
     if (record -> mother_row || record -> number_of_children)
     {
-	/* we need now to recalculate the amount of split and update the white line */
-	CustomRecord *mother_record;
-	CustomRecord *white_record;
+        /* we need now to recalculate the amount of split and update the white line */
+        CustomRecord *mother_record;
+        CustomRecord *white_record;
 
-	/* get the mother if child */
-	if (record -> mother_row)
-	    mother_record = record -> mother_row;
-	else
-	    mother_record = record;
-	white_record = mother_record -> children_rows[mother_record -> number_of_children -1];
+        /* get the mother if child */
+        if (record -> mother_row)
+            mother_record = record -> mother_row;
+        else
+            mother_record = record;
+        white_record = mother_record -> children_rows[mother_record -> number_of_children -1];
 
-	transaction_list_update_white_child (white_record);
+        transaction_list_update_white_child (white_record);
     }
 
     /* set the checkbox is the transaction is marked */
@@ -1128,9 +1138,9 @@
         GtkTreePath *path = gtk_tree_path_new();
 
         /* if there is some children and we are the last row, set the expander */
-        if (white_record
-        &&
-        i == (custom_list -> nb_rows_by_transaction -1 ))
+        if ( white_record
+         &&
+         i == ( transaction_list_get_last_line ( custom_list -> nb_rows_by_transaction ) ) )
         {
         record -> has_expander = TRUE;
         white_record -> mother_row = record;
@@ -1154,12 +1164,15 @@
                               path, &iter);
         gtk_tree_path_free(path);
     }
+
     if (nb_rows == 1)
     {
-    /* we need now to recalculate the amount of split and update the white line */
-    CustomRecord *white_record = white_record = 
-                        record -> mother_row -> children_rows[record -> mother_row -> number_of_children -1];
-    transaction_list_update_white_child (white_record);
+        CustomRecord *white_record;
+
+        /* we need now to recalculate the amount of split and update the white line */
+        white_record = record -> mother_row -> children_rows[record -> 
+                            mother_row -> number_of_children -1];
+        transaction_list_update_white_child (white_record);
     }
 
     return TRUE;
@@ -1884,7 +1897,7 @@
     GdkColor *mother_text_color;
 
     if (!white_record)
-	return FALSE;
+	    return FALSE;
 
     mother_record = white_record -> mother_row;
 
@@ -1928,6 +1941,7 @@
 
     g_free (amount_string);
     g_free (variance_string);
+
     return TRUE;
 }
 
@@ -2066,3 +2080,65 @@
     }
     g_date_free ( date_jour ); 
 }
+
+
+/**
+ * retourne TRUE si la variance de l'opération ventilée == 0
+ *
+ *
+ *
+ * */
+gboolean transaction_list_get_variance ( gint transaction_number )
+{
+    CustomRecord *white_record = NULL;
+    CustomList *custom_list;
+    gsb_real total_split = null_real;
+    gsb_real variance;
+    CustomRecord *mother_record;
+    gint i;
+
+    custom_list = transaction_model_get_model ();
+
+    g_return_val_if_fail ( custom_list != NULL, FALSE );
+
+    /* if the selection didn't change, do nothing */
+    if ( gsb_data_transaction_get_transaction_number (custom_list -> selected_row) == 
+        transaction_number )
+        white_record = custom_list -> selected_row;
+
+    if ( !white_record )
+    {
+        GtkTreeIter iter;
+
+        if ( !transaction_model_get_transaction_iter ( &iter, transaction_number, 0 ) )
+	        return FALSE;
+	    white_record = iter.user_data;
+    }
+
+    mother_record = white_record -> mother_row;
+
+    for (i=0 ; i < mother_record -> number_of_children -1 ; i++)
+    {
+        CustomRecord *child_record;
+        gint child_number;
+
+        child_record = mother_record -> children_rows[i];
+        child_number = gsb_data_transaction_get_transaction_number (
+                        child_record -> transaction_pointer );
+        total_split = gsb_real_add ( total_split,
+                        gsb_data_transaction_get_amount ( child_number ) );
+    }
+
+    transaction_number = gsb_data_transaction_get_transaction_number (
+                        mother_record -> transaction_pointer);
+    variance = gsb_real_sub ( gsb_data_transaction_get_amount ( transaction_number ),
+			            total_split);
+
+    if ( variance.mantissa == 0 )
+        return TRUE;
+    else
+        return FALSE;
+}
+/* Local Variables: */
+/* c-basic-offset: 4 */
+/* End: */



More information about the cvs mailing list