[grisbi-cvs] [SCM] grisbi branch, master, updated. upstream_version_0_9_5-111-g273106f

Pierre Biava nobody at users.sourceforge.net
Sat Aug 18 20:35:47 CEST 2012


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, master has been updated
       via  273106f83eee218f2eb9edde9d47807d58e68cc2 (commit)
      from  79f237adda0b0d664779e990af76b84905efe314 (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 273106f83eee218f2eb9edde9d47807d58e68cc2
Author: pbiava <pierre.biava at nerim.net>
Date:   Sat Aug 18 20:34:48 2012 +0200

    Fixed a bug in calculating the balance of the main transaction

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

Changes:
diff --git a/src/bet_data.c b/src/bet_data.c
index 9d19f01..10e6f5c 100644
--- a/src/bet_data.c
+++ b/src/bet_data.c
@@ -1727,7 +1727,7 @@ static void bet_data_transfert_create_reset_credit_card ( struct_transfert_data
     /* replace_account is an account */
     if ( transfert -> type == 0 )
     {
-        amount = gsb_data_account_calculate_balance_at_date ( transfert->replace_account, date );
+        amount = gsb_data_account_get_balance_at_date ( transfert->replace_account, date );
         transaction_number = gsb_data_transaction_new_transaction ( transfert->replace_account );
         gsb_data_transaction_set_date ( transaction_number, date );
         gsb_data_transaction_set_amount ( transaction_number, gsb_real_opposite ( amount ) );
@@ -1777,7 +1777,7 @@ static void bet_data_transfert_create_reset_credit_card ( struct_transfert_data
         tab = g_strsplit ( gsb_data_partial_balance_get_liste_cptes ( transfert->replace_account ), ";", 0 );
 
         /* on calcule la balance de tous les comptes du pseudo compte */
-        balances = gsb_data_partial_balance_calculate_balance_at_date ( transfert->replace_account, date );
+        balances = gsb_data_partial_balance_calculate_balances_at_date ( transfert->replace_account, date );
 
         for ( i = 0; tab[i]; i++ )
         {
@@ -2066,8 +2066,13 @@ gchar *bet_data_get_str_amount_in_account_currency ( gsb_real amount,
 void bet_data_transfert_create_new_transaction ( struct_transfert_data *transfert )
 {
     gint transaction_number;
+    GDate *date;
     gsb_real amount;
 
+    date = gsb_date_copy ( transfert->date_bascule );
+    /* on enlève 1 jour pour la date de l'opération de remise à 0 du compte */
+    g_date_subtract_days ( date, 1 );
+
     transaction_number = gsb_data_transaction_new_transaction ( transfert->account_number );
 
     /* set the date */
@@ -2076,11 +2081,11 @@ void bet_data_transfert_create_new_transaction ( struct_transfert_data *transfer
     /* set the amount soit celui du compte carte soit celui du solde partiel */
     if ( transfert -> type == 0 )
     {
-        amount = gsb_data_account_get_current_balance ( transfert -> replace_account );
+        amount = gsb_data_account_get_balance_at_date ( transfert->replace_account, date );
     }
     else
     {
-        amount = gsb_data_partial_balance_get_current_amount ( transfert -> replace_account );
+        amount = gsb_data_partial_balance_get_balance_at_date ( transfert -> replace_account, date );
     }
     gsb_data_transaction_set_amount ( transaction_number, amount );
 
@@ -2089,12 +2094,7 @@ void bet_data_transfert_create_new_transaction ( struct_transfert_data *transfer
                         gsb_data_account_get_currency ( transfert->account_number ) );
 
     /* set the payement mode */
-    if ( amount.mantissa < 0 )
-        gsb_data_transaction_set_method_of_payment_number ( transaction_number,
-                        gsb_data_account_get_default_debit ( transfert->account_number ) );
-    else
-        gsb_data_transaction_set_method_of_payment_number ( transaction_number,
-                        gsb_data_account_get_default_credit ( transfert->account_number ) );
+        gsb_data_transaction_set_method_of_payment_number ( transaction_number, transfert->main_payment_number );
 
     /* set the payee */
     gsb_data_transaction_set_party_number ( transaction_number, transfert->main_payee_number );
diff --git a/src/gsb_data_account.c b/src/gsb_data_account.c
index 47b3da1..624f601 100644
--- a/src/gsb_data_account.c
+++ b/src/gsb_data_account.c
@@ -3715,7 +3715,7 @@ gboolean gsb_data_account_exists ( gint account_number )
  *
  * \return gsb_real         le solde du compte
  * */
-gsb_real gsb_data_account_calculate_balance_at_date ( gint account_number,
+gsb_real gsb_data_account_get_balance_at_date ( gint account_number,
                         GDate *date )
 {
     struct_account *account;
diff --git a/src/gsb_data_account.h b/src/gsb_data_account.h
index f739efd..c14b5bb 100644
--- a/src/gsb_data_account.h
+++ b/src/gsb_data_account.h
@@ -26,8 +26,6 @@ typedef enum _kind_account	kind_account;
 
 /* START_DECLARATION */
 gboolean gsb_data_account_bet_update_initial_date_if_necessary ( gint account_number );
-gsb_real gsb_data_account_calculate_balance_at_date ( gint account_number,
-                        GDate *date );
 gsb_real gsb_data_account_calculate_current_and_marked_balances ( gint account_number );
 gsb_real gsb_data_account_calculate_current_day_balance ( gint account_number,
                         GDate *day );
@@ -44,6 +42,8 @@ GtkWidget *gsb_data_account_get_account_icon_image ( gint account_number );
 GdkPixbuf *gsb_data_account_get_account_icon_pixbuf ( gint account_number );
 GdkPixbuf *gsb_data_account_get_account_standard_pixbuf ( kind_account account_kind );
 gint gsb_data_account_get_accounts_amount ( void );
+gsb_real gsb_data_account_get_balance_at_date ( gint account_number,
+                        GDate *date );
 gint gsb_data_account_get_bank ( gint account_number );
 gchar *gsb_data_account_get_bank_account_iban (gint account_number);
 gchar *gsb_data_account_get_bank_account_key ( gint account_number );
diff --git a/src/gsb_data_partial_balance.c b/src/gsb_data_partial_balance.c
index cb09279..33beb8c 100644
--- a/src/gsb_data_partial_balance.c
+++ b/src/gsb_data_partial_balance.c
@@ -1045,7 +1045,7 @@ gchar *gsb_data_partial_balance_get_marked_balance ( gint partial_balance_number
     if ( !partial_balance )
         return NULL;
 
-    if ( partial_balance -> liste_cptes == NULL || 
+    if ( partial_balance -> liste_cptes == NULL ||
      strlen ( partial_balance -> liste_cptes ) == 0 )
         return NULL;
 
@@ -1108,7 +1108,7 @@ gsb_real gsb_data_partial_balance_get_current_amount ( gint partial_balance_numb
     if ( !partial_balance )
         return null_real;
 
-    if ( partial_balance -> liste_cptes == NULL || 
+    if ( partial_balance -> liste_cptes == NULL ||
      strlen ( partial_balance -> liste_cptes ) == 0 )
         return null_real;
 
@@ -1272,7 +1272,7 @@ gboolean gsb_data_partial_balance_init_from_liste_cptes ( gint partial_balance_n
     if ( !partial_balance )
         return FALSE;
 
-    if ( partial_balance -> liste_cptes == NULL || 
+    if ( partial_balance -> liste_cptes == NULL ||
      strlen ( partial_balance -> liste_cptes ) == 0 )
         return FALSE;
 
@@ -1436,14 +1436,14 @@ gboolean gsb_data_partial_balance_move ( gint orig_partial_number, gint dest_pos
 
 
 /**
- * calcule le solde d'un solde partiel à une date donnée
+ * calcule le solde des comptes d'un solde partiel à une date donnée
  *
  * \param account_number    numéro du compte concerné
  * \param date              date de calcul du solde
  *
- * \return
+ * \return GPtrArray        un tableau avec le solde de chaque compte concerné
  * */
-GPtrArray *gsb_data_partial_balance_calculate_balance_at_date ( gint partial_balance_number,
+GPtrArray *gsb_data_partial_balance_calculate_balances_at_date ( gint partial_balance_number,
                         GDate *date )
 {
     GSList *tmp_list;
@@ -1787,6 +1787,65 @@ gint gsb_partial_balance_request_currency ( GtkWidget *parent )
 
     return currency_nb;
 }
+
+/**
+ * calcule le solde d'un solde partiel à une date donnée
+ *
+ * \param partial_balance_number    numéro du solde partiel concerné
+ * \param date                      date de calcul du solde
+ *
+ * \return gsb_real         le solde du solde partiel
+ * */
+gsb_real gsb_data_partial_balance_get_balance_at_date ( gint partial_balance_number,
+                        GDate *date )
+{
+    struct_partial_balance *partial_balance;
+    gsb_real solde = null_real;
+    gchar **tab;
+    gint i;
+
+    partial_balance = gsb_data_partial_balance_get_structure ( partial_balance_number );
+
+    if ( !partial_balance )
+        return null_real;
+
+    if ( partial_balance -> liste_cptes == NULL ||
+     strlen ( partial_balance -> liste_cptes ) == 0 )
+        return null_real;
+
+    tab = g_strsplit ( partial_balance -> liste_cptes, ";", 0 );
+    for ( i = 0; tab[i]; i++ )
+    {
+        gsb_real tmp_real;
+        gint account_number;
+        gint account_currency;
+        gint link_number;
+
+        account_number = utils_str_atoi ( tab[i] );
+        account_currency = gsb_data_account_get_currency ( account_number );
+        tmp_real = gsb_data_account_get_balance_at_date ( account_number, date );
+
+        if ( tmp_real.mantissa != 0 && partial_balance -> currency != account_currency )
+        {
+            if ( ( link_number = gsb_data_currency_link_search ( account_currency,
+                        partial_balance -> currency ) ) )
+            {
+                if ( gsb_data_currency_link_get_first_currency ( link_number) == account_currency )
+                    tmp_real = gsb_real_mul ( tmp_real,
+                                gsb_data_currency_link_get_change_rate ( link_number ) );
+                else
+                    tmp_real = gsb_real_div ( tmp_real,
+                                gsb_data_currency_link_get_change_rate ( link_number ) );
+            }
+        }
+        solde = gsb_real_add ( solde, tmp_real );
+    }
+    g_strfreev ( tab );
+
+    return solde;
+}
+
+
 /**
  *
  *
diff --git a/src/gsb_data_partial_balance.h b/src/gsb_data_partial_balance.h
index 2ce4cbb..a573088 100644
--- a/src/gsb_data_partial_balance.h
+++ b/src/gsb_data_partial_balance.h
@@ -8,7 +8,7 @@
 /* END_INCLUDE_H */
 
 /* START_DECLARATION */
-GPtrArray *gsb_data_partial_balance_calculate_balance_at_date ( gint partial_balance_number,
+GPtrArray *gsb_data_partial_balance_calculate_balances_at_date ( gint partial_balance_number,
                         GDate *date );
 gboolean gsb_data_partial_balance_drag_data_get ( GtkTreeDragSource * drag_source,
                         GtkTreePath * path,
@@ -16,6 +16,8 @@ gboolean gsb_data_partial_balance_drag_data_get ( GtkTreeDragSource * drag_sourc
 gboolean gsb_data_partial_balance_drag_data_received ( GtkTreeDragDest * drag_dest,
                         GtkTreePath * dest_path,
                         GtkSelectionData * selection_data );
+gsb_real gsb_data_partial_balance_get_balance_at_date ( gint partial_balance_number,
+                        GDate *date );
 gboolean gsb_data_partial_balance_get_colorise ( gint partial_balance_number );
 gint gsb_data_partial_balance_get_currency ( gint partial_balance_number );
 gsb_real gsb_data_partial_balance_get_current_amount ( gint partial_balance_number );


hooks/post-receive
-- 
grisbi


More information about the cvs mailing list