[grisbi-cvs] [SCM] grisbi branch, grisbi-0.8.x, updated. upstream_version_0_8_4-8-g0e85eda

Pierre Biava nobody at users.sourceforge.net
Tue Apr 12 22:07:50 CEST 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grisbi".

The branch, grisbi-0.8.x has been updated
       via  0e85eda520d761fbcc37f5f32818c7d6aa7dea89 (commit)
       via  459609b9b03f12a8e4fcae9faa63e4a537b2ffd4 (commit)
      from  7b3223e25116920826a0bee72ae9398dc06c9caa (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0e85eda520d761fbcc37f5f32818c7d6aa7dea89
Author: pbiava <pierre.biava at nerim.net>
Date:   Tue Apr 12 20:25:07 2011 +0200

    Added cloning of scheduled operations
    (cherry picked from commit 77f4631ec66959d70518424c5a04bf2beb96663c)

commit 459609b9b03f12a8e4fcae9faa63e4a537b2ffd4
Author: pbiava <pierre.biava at nerim.net>
Date:   Tue Apr 12 20:22:53 2011 +0200

    Fixed a bug of calculating balances with different currencies in the table estimates
    (cherry picked from commit 584c37eba0be3233df611becc2d7735fcce3ea88)

-----------------------------------------------------------------------

Changes:
diff --git a/src/bet_data.c b/src/bet_data.c
index d0067f3..2fcf77d 100644
--- a/src/bet_data.c
+++ b/src/bet_data.c
@@ -29,6 +29,7 @@
 
 /*START_INCLUDE*/
 #include "bet_data.h"
+#include "bet_future.h"
 #include "bet_hist.h"
 #include "bet_tab.h"
 #include "dialog.h"
@@ -37,6 +38,7 @@
 #include "gsb_data_budget.h"
 #include "gsb_data_category.h"
 #include "gsb_data_mix.h"
+#include "gsb_data_scheduled.h"
 #include "gsb_data_transaction.h"
 #include "utils_dates.h"
 #include "navigation.h"
@@ -1833,6 +1835,59 @@ gchar *bet_data_get_key ( gint account_number, gint div_number )
 }
 
 
+/**
+ *
+ *
+ *
+ *
+ * */
+gchar *bet_data_get_str_amount_in_account_currency ( gsb_real amount,
+                        gint account_number,
+                        gint line_number,
+                        gint origin )
+{
+    gchar *str_amount = NULL;
+    gint account_currency;
+    gint floating_point;
+    gsb_real new_amount;
+    
+    account_currency = gsb_data_account_get_currency ( account_number );
+    floating_point = gsb_data_account_get_currency_floating_point ( account_number );
+
+    switch ( origin )
+    {
+        case SPP_ORIGIN_TRANSACTION :
+            new_amount = gsb_data_transaction_get_adjusted_amount_for_currency ( line_number,
+                                    account_currency,
+                                    floating_point );
+        break;
+        case SPP_ORIGIN_SCHEDULED :
+            new_amount = gsb_data_scheduled_get_adjusted_amount_for_currency ( line_number,
+                                    account_currency,
+                                    floating_point );
+
+        break;
+        case SPP_ORIGIN_ACCOUNT :
+            if ( account_currency == line_number || amount.mantissa == 0 )
+            {
+                new_amount.mantissa = amount.mantissa;
+                new_amount.exponent = amount.exponent;
+            }
+            else
+                new_amount = gsb_transfert_get_str_amount ( amount,
+                                    account_currency,
+                                    line_number,
+                                    floating_point );
+
+        break;
+    }
+
+    str_amount = gsb_real_safe_real_to_string ( new_amount, floating_point );
+
+    return str_amount;
+}
+
+
 /* Local Variables: */
 /* c-basic-offset: 4 */
 /* End: */
diff --git a/src/bet_data.h b/src/bet_data.h
index b0d652b..b11b520 100644
--- a/src/bet_data.h
+++ b/src/bet_data.h
@@ -106,6 +106,10 @@ gchar *bet_data_get_div_name ( gint div_num,
 gint bet_data_get_div_number ( gint transaction_number, gboolean is_transaction );
 gint bet_data_get_div_type ( gint div_number );
 gint bet_data_get_selected_currency ( void );
+gchar *bet_data_get_str_amount_in_account_currency ( gsb_real amount,
+                        gint account_number,
+                        gint line_number,
+                        gint origin );
 GPtrArray *bet_data_get_strings_to_save ( void );
 gint bet_data_get_sub_div_nb ( gint transaction_number, gboolean is_transaction );
 gboolean bet_data_hist_add_div ( gint account_number,
diff --git a/src/bet_future.c b/src/bet_future.c
index 3c037f6..dfb88ad 100644
--- a/src/bet_future.c
+++ b/src/bet_future.c
@@ -2331,39 +2331,35 @@ gboolean bet_transfert_take_data (  struct_transfert_data *transfert, GtkWidget
  *
  *
  * */
-gchar *gsb_transfert_get_str_amount ( struct_transfert_data *transfert, gsb_real amount )
+gsb_real gsb_transfert_get_str_amount ( gsb_real amount,
+                        gint account_currency,
+                        gint replace_currency,
+                        gint floating_point )
 {
-    gchar *string = NULL;
-    gint currency;
-    gint replace_currency;
+    gsb_real tmp_real = null_real;
+    gint link_number;
 
-    currency = gsb_data_account_get_currency ( transfert -> account_number );
-    if ( transfert -> type == 0 )
-        replace_currency = gsb_data_account_get_currency ( transfert -> replace_account );
-    else
-        replace_currency = gsb_data_partial_balance_get_currency ( transfert -> replace_account );
-
-    if ( currency == replace_currency || amount.mantissa == 0 )
-        string = gsb_real_get_string_with_currency ( amount, currency, TRUE );
-    else
+    if ( ( link_number = gsb_data_currency_link_search ( account_currency, replace_currency ) ) )
+    {
+        if ( gsb_data_currency_link_get_first_currency ( link_number ) == replace_currency )
+            tmp_real = gsb_real_mul ( amount,
+                        gsb_data_currency_link_get_change_rate ( link_number ) );
+        else
+            tmp_real = gsb_real_div ( amount,
+                        gsb_data_currency_link_get_change_rate ( link_number ) );
+    }
+    else if ( account_currency > 0 && replace_currency > 0 )
     {
-        gsb_real tmp_real = null_real;
-        gint link_number;
+        gchar *tmp_str;
 
-        if ( ( link_number = gsb_data_currency_link_search ( currency, replace_currency ) ) )
-        {
-            if ( gsb_data_currency_link_get_first_currency ( link_number ) == currency )
-                tmp_real = gsb_real_mul ( amount,
-                            gsb_data_currency_link_get_change_rate ( link_number ) );
-            else
-                tmp_real = gsb_real_div ( amount,
-                            gsb_data_currency_link_get_change_rate ( link_number ) );
-        }
+        tmp_str = g_strdup ( _("Error: is missing one or more links between currencies.\n"
+                        "You need to fix it and start over.") );
+        dialogue_error ( tmp_str );
 
-        string = gsb_real_get_string_with_currency ( tmp_real, currency, TRUE );
+        g_free ( tmp_str );
     }
 
-    return string;
+    return tmp_real;
 }
 
 
diff --git a/src/bet_future.h b/src/bet_future.h
index af8a5e5..6cf5865 100644
--- a/src/bet_future.h
+++ b/src/bet_future.h
@@ -19,7 +19,10 @@ gboolean bet_future_new_line_dialog ( GtkTreeModel *tab_model,
 gboolean bet_transfert_modify_line ( gint account_number, gint number );
 gboolean bet_transfert_new_line_dialog ( GtkTreeModel *tab_model,
                         gchar *str_date );
-gchar *gsb_transfert_get_str_amount ( struct_transfert_data *transfert, gsb_real amount );
+gsb_real gsb_transfert_get_str_amount ( gsb_real amount,
+                        gint account_currency,
+                        gint replace_currency,
+                        gint floating_point );
 /* END_DECLARATION */
 
 #endif /*_BALANCE_ESTIMATE_FUTURE_H*/
diff --git a/src/bet_tab.c b/src/bet_tab.c
index 96304c7..4e0de62 100644
--- a/src/bet_tab.c
+++ b/src/bet_tab.c
@@ -864,9 +864,12 @@ void bet_array_refresh_scheduled_data ( GtkTreeModel *tab_model,
         else
             continue;
 
+        str_amount = bet_data_get_str_amount_in_account_currency ( amount,
+                        account_number,
+                        scheduled_number,
+                        SPP_ORIGIN_SCHEDULED );
+
         currency_number = gsb_data_scheduled_get_currency_number ( scheduled_number );
-        str_amount = gsb_real_safe_real_to_string ( amount, 
-                    gsb_data_currency_get_floating_point ( currency_number ) );
         if (amount.mantissa < 0)
             str_debit = gsb_real_get_string_with_currency ( gsb_real_abs ( amount ), currency_number, TRUE );
         else
@@ -1010,15 +1013,16 @@ void bet_array_refresh_transactions_data ( GtkTreeModel *tab_model,
         if ( g_date_compare ( date, date_min ) < 0 )
             continue;
 
-
         str_date = gsb_format_gdate ( date );
         g_value_init ( &date_value, G_TYPE_DATE );
         g_value_set_boxed ( &date_value, date );
 
-        currency_number = gsb_data_transaction_get_currency_number ( transaction_number);
-        str_amount = gsb_real_safe_real_to_string ( amount, 
-                    gsb_data_currency_get_floating_point ( currency_number ) );
+        str_amount = bet_data_get_str_amount_in_account_currency ( amount,
+                        account_number,
+                        transaction_number,
+                        SPP_ORIGIN_TRANSACTION );
 
+        currency_number = gsb_data_transaction_get_currency_number ( transaction_number);
         if (amount.mantissa < 0)
             str_debit = gsb_real_get_string_with_currency ( gsb_real_abs ( amount ), currency_number, TRUE );
         else
@@ -2587,6 +2591,8 @@ gboolean bet_array_refresh_transfert_data ( GtkTreeModel *tab_model,
         gchar *str_debit = NULL;
         gchar *str_credit = NULL;
         gchar *str_date;
+        gint currency_number;
+        gint replace_currency;
         gchar *str_description;
         gchar *str_amount;
         gsb_real amount;
@@ -2607,19 +2613,26 @@ gboolean bet_array_refresh_transfert_data ( GtkTreeModel *tab_model,
                         value );
 
         if ( transfert -> type == 0 )
+        {
             amount = gsb_data_account_get_current_balance ( transfert -> replace_account );
+            replace_currency = gsb_data_account_get_currency ( transfert -> replace_account );
+        }
         else
-            amount = gsb_data_partial_balance_get_current_amount (
-                        transfert -> replace_account );
+        {
+            amount = gsb_data_partial_balance_get_current_amount ( transfert -> replace_account );
+            replace_currency = gsb_data_partial_balance_get_currency ( transfert -> replace_account );
+        }
 
-        str_amount = gsb_real_safe_real_to_string ( amount,
-                        gsb_data_account_get_currency_floating_point ( account_number ) );
+        str_amount = bet_data_get_str_amount_in_account_currency ( amount,
+                        account_number,
+                        replace_currency,
+                        SPP_ORIGIN_ACCOUNT );
 
-        if ( amount.mantissa < 0 )
-            str_debit = gsb_transfert_get_str_amount ( transfert,
-                        gsb_real_opposite ( amount ) );
+        currency_number = gsb_data_account_get_currency ( transfert -> replace_account );
+        if (amount.mantissa < 0)
+            str_debit = gsb_real_get_string_with_currency ( gsb_real_abs ( amount ), currency_number, TRUE );
         else
-            str_credit = gsb_transfert_get_str_amount ( transfert, amount );
+            str_credit = gsb_real_get_string_with_currency ( amount, currency_number, TRUE);
 
         str_date = gsb_format_gdate ( transfert -> date );
 
diff --git a/src/gsb_data_scheduled.c b/src/gsb_data_scheduled.c
index 6659755..2528128 100644
--- a/src/gsb_data_scheduled.c
+++ b/src/gsb_data_scheduled.c
@@ -36,7 +36,9 @@
 /*START_INCLUDE*/
 #include "gsb_data_scheduled.h"
 #include "dialog.h"
+#include "gsb_currency.h"
 #include "gsb_data_currency.h"
+#include "gsb_data_currency_link.h"
 #include "gsb_real.h"
 #include "utils_dates.h"
 #include "utils_str.h"
@@ -1770,6 +1772,109 @@ gint gsb_data_scheduled_get_currency_floating_point ( gint scheduled_number )
 }
 
 
+/**
+ * get the amount of the scheduled, modified to be ok with the currency
+ * given in param 
+ * 
+ * \param scheduled_number 		the number of the scheduled
+ * \param return_currency_number 	the currency we want to adjust the transaction's amount
+ * \param return_exponent 		the exponent we want to have for the returned number, or -1 for the exponent of the returned currency
+ * 
+ * \return the amount of the transaction
+ * */
+gsb_real gsb_data_scheduled_get_adjusted_amount_for_currency ( gint scheduled_number,
+                        gint return_currency_number,
+                        gint return_exponent )
+{
+    struct_scheduled *scheduled;
+    gsb_real amount = null_real;
+    gint link_number;
+
+    if (return_exponent == -1)
+        return_exponent = gsb_data_currency_get_floating_point ( return_currency_number );
+
+    scheduled = gsb_data_scheduled_get_scheduled_by_no ( scheduled_number);
+
+    if ( ! (scheduled && return_currency_number ) )
+        return gsb_real_adjust_exponent  ( null_real, return_exponent );
+
+    /* if the transaction currency is the same of the account's one,
+     * we just return the transaction's amount */
+    if ( scheduled -> currency_number == return_currency_number )
+        return gsb_real_adjust_exponent  ( scheduled -> scheduled_amount,
+					   return_exponent );
+
+    /* now we can adjust the amount */
+    if ( ( link_number = gsb_data_currency_link_search ( scheduled -> currency_number,
+							return_currency_number ) ) )
+    {
+	/* there is a hard link between the transaction currency and the return currency */
+        if ( gsb_data_currency_link_get_first_currency ( link_number ) == scheduled -> currency_number )
+            amount = gsb_real_mul ( scheduled -> scheduled_amount,
+                        gsb_data_currency_link_get_change_rate ( link_number ) );
+        else
+            amount = gsb_real_div ( scheduled -> scheduled_amount,
+                        gsb_data_currency_link_get_change_rate (link_number));
+
+    }
+    else if ( return_currency_number > 0 && scheduled -> currency_number > 0 )
+    {
+        gchar *tmp_str;
+
+        tmp_str = g_strdup ( _("Error: is missing one or more links between currencies.\n"
+                        "You need to fix it and start over.") );
+        dialogue_error ( tmp_str );
+
+        g_free ( tmp_str );
+    }
+
+    return gsb_real_adjust_exponent  ( amount, return_exponent );
+}
+
+
+/**
+ * copy the content of a scheduled transaction into the second one
+ * the 2 scheduled transactions must exist before
+ * only the scheduled_number will be modified in the target transaction
+ *
+ * \param source_scheduled_number the transaction we want to copy
+ * \param target_scheduled_number the transaction we want to fill with the content of the first one
+ *
+ * \return TRUE if ok, FALSE else
+ * */
+gboolean gsb_data_scheduled_copy_scheduled ( gint source_scheduled_number,
+                        gint target_scheduled_number )
+{
+    struct_scheduled *source_scheduled;
+    struct_scheduled *target_scheduled;
+
+    source_scheduled = gsb_data_scheduled_get_scheduled_by_no ( source_scheduled_number );
+    target_scheduled = gsb_data_scheduled_get_scheduled_by_no ( target_scheduled_number );
+
+    if ( !source_scheduled || !target_scheduled )
+        return FALSE;
+
+    memcpy ( target_scheduled, source_scheduled, sizeof ( struct_scheduled ) );
+
+    target_scheduled -> scheduled_number = target_scheduled_number;
+
+    /* make a new copy of all the pointers */
+    if ( target_scheduled -> notes)
+        target_scheduled -> notes = my_strdup ( source_scheduled -> notes );
+
+    if ( target_scheduled -> date)
+        target_scheduled -> date = gsb_date_copy ( source_scheduled -> date );
+
+    if ( target_scheduled -> limit_date)
+        target_scheduled -> limit_date = gsb_date_copy ( source_scheduled -> limit_date );
+
+    if ( target_scheduled -> method_of_payment_content)
+        target_scheduled -> method_of_payment_content = my_strdup (
+                        source_scheduled -> method_of_payment_content );
+    return TRUE;
+}
+
+
 /* Local Variables: */
 /* c-basic-offset: 4 */
 /* End: */
diff --git a/src/gsb_data_scheduled.h b/src/gsb_data_scheduled.h
index cefe8e3..88825e4 100644
--- a/src/gsb_data_scheduled.h
+++ b/src/gsb_data_scheduled.h
@@ -7,8 +7,13 @@
 /* END_INCLUDE_H */
 
 /* START_DECLARATION */
+gboolean gsb_data_scheduled_copy_scheduled ( gint source_scheduled_number,
+                        gint target_scheduled_number );
 gint gsb_data_scheduled_get_account_number ( gint scheduled_number );
 gint gsb_data_scheduled_get_account_number_transfer ( gint scheduled_number );
+gsb_real gsb_data_scheduled_get_adjusted_amount_for_currency ( gint scheduled_number,
+                        gint return_currency_number,
+                        gint return_exponent );
 gsb_real gsb_data_scheduled_get_amount ( gint scheduled_number );
 gint gsb_data_scheduled_get_automatic_scheduled ( gint scheduled_number );
 gint gsb_data_scheduled_get_budgetary_number ( gint scheduled_number );
diff --git a/src/gsb_scheduler_list.c b/src/gsb_scheduler_list.c
index f1b2a82..a08b567 100644
--- a/src/gsb_scheduler_list.c
+++ b/src/gsb_scheduler_list.c
@@ -64,6 +64,8 @@
 /*START_STATIC*/
 static gboolean gsb_scheduler_list_button_press ( GtkWidget *tree_view,
                         GdkEventButton *ev );
+static gboolean gsb_scheduler_list_clone_selected_scheduled ( GtkWidget *menu_item,
+                        gint *scheduled_number );
 static void gsb_scheduler_list_create_list_columns ( GtkWidget *tree_view );
 static GtkTreeModel *gsb_scheduler_list_create_model ( void );
 static GtkWidget *gsb_scheduler_list_create_tree_view (void);
@@ -2133,6 +2135,19 @@ void popup_scheduled_context_menu ( void )
                         "activate",
                         G_CALLBACK ( gsb_scheduler_list_edit_transaction_by_pointer ),
                         GINT_TO_POINTER ( scheduled_number ) );
+
+    gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), menu_item );
+
+    /* Clone transaction */
+    menu_item = gtk_image_menu_item_new_with_label ( _("Clone transaction") );
+    gtk_image_menu_item_set_image ( GTK_IMAGE_MENU_ITEM ( menu_item ),
+                        gtk_image_new_from_stock ( GTK_STOCK_COPY,
+                        GTK_ICON_SIZE_MENU ));
+    g_signal_connect ( G_OBJECT ( menu_item ),
+                        "activate",
+                        G_CALLBACK ( gsb_scheduler_list_clone_selected_scheduled ),
+                        GINT_TO_POINTER ( scheduled_number ) );
+
     gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), menu_item );
 
     /* Separator */
@@ -2193,6 +2208,63 @@ void popup_scheduled_context_menu ( void )
     gtk_menu_popup ( GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, gtk_get_current_event_time());
 }
 
+
+/**
+ * Clone selected transaction if any.  Update user interface as well.
+ *
+ * \param menu_item
+ * \param null
+ *
+ * \return FALSE
+ */
+gboolean gsb_scheduler_list_clone_selected_scheduled ( GtkWidget *menu_item,
+                        gint *scheduled_number )
+{
+    gint new_scheduled_number;
+    gint tmp_scheduled_number;
+
+    tmp_scheduled_number = GPOINTER_TO_INT ( scheduled_number );
+    new_scheduled_number = gsb_data_scheduled_new_scheduled ( );
+
+    gsb_data_scheduled_copy_scheduled ( tmp_scheduled_number, new_scheduled_number );
+
+    if ( gsb_data_scheduled_get_split_of_scheduled ( tmp_scheduled_number ) )
+    {
+        GSList *tmp_list;
+
+        tmp_list = g_slist_copy ( gsb_data_scheduled_get_scheduled_list ( ) );
+
+        while ( tmp_list )
+        {
+            gint split_scheduled_number;
+
+            split_scheduled_number = gsb_data_scheduled_get_scheduled_number ( tmp_list -> data );
+
+            if ( gsb_data_scheduled_get_mother_scheduled_number (
+             split_scheduled_number ) == tmp_scheduled_number )
+            {
+                gint new_number;
+
+                new_number = gsb_data_scheduled_new_scheduled ( );
+                gsb_data_scheduled_copy_scheduled ( split_scheduled_number, new_number );
+                gsb_data_scheduled_set_mother_scheduled_number ( new_number, new_scheduled_number );
+            }
+
+            tmp_list = tmp_list -> next;
+        }
+    }
+
+    gsb_scheduler_list_fill_list ( gsb_scheduler_list_get_tree_view ( ) );
+    gsb_scheduler_list_set_background_color ( gsb_scheduler_list_get_tree_view ( ) );
+    gsb_scheduler_list_select ( new_scheduled_number );
+
+    if ( etat.modification_fichier == 0 )
+        modification_fichier ( TRUE );
+
+    return FALSE;
+}
+
+
 /**
  * Called to edit a specific transaction but the number of transaction
  * is passed via a pointer (by g_signal_connect)


hooks/post-receive
-- 
grisbi


More information about the cvs mailing list