[grisbi-cvs] [SCM] grisbi branch, master, updated. upstream_version_0_9_5-91-g2957379
Pierre Biava
nobody at users.sourceforge.net
Mon May 28 23:01:26 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 29573799c797f84fee469dcc79bf950edebd8165 (commit)
via 7898df2da4b66e5dc1e27e5b45657be155d7b34f (commit)
from c4f41694463e1f60771ac13f428bfa4b42a02fe6 (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 29573799c797f84fee469dcc79bf950edebd8165
Author: pbiava <pierre.biava at nerim.net>
Date: Mon May 28 23:00:44 2012 +0200
bet_data.c: minor change when select a new account in the budgetary module
commit 7898df2da4b66e5dc1e27e5b45657be155d7b34f
Author: pbiava <pierre.biava at nerim.net>
Date: Mon May 28 22:51:53 2012 +0200
Changing the function of calculating the balance of a virtual account
-----------------------------------------------------------------------
Changes:
diff --git a/src/bet_data.c b/src/bet_data.c
index cb7c6b3..429eb25 100644
--- a/src/bet_data.c
+++ b/src/bet_data.c
@@ -138,7 +138,7 @@ void bet_data_select_bet_pages ( gint account_number )
page = gtk_notebook_get_nth_page ( GTK_NOTEBOOK ( account_page ), GSB_FINANCE_PAGE );
gtk_widget_hide ( page );
if ( current_page == GSB_ESTIMATE_PAGE || current_page == GSB_FINANCE_PAGE )
- gtk_notebook_set_current_page ( GTK_NOTEBOOK ( account_page ), GSB_HISTORICAL_PAGE );
+ gtk_notebook_set_current_page ( GTK_NOTEBOOK ( account_page ), GSB_TRANSACTIONS_PAGE );
bet_historical_g_signal_block_tree_view ( );
gsb_data_account_set_bet_maj ( account_number, BET_MAJ_HISTORICAL );
break;
@@ -150,7 +150,7 @@ void bet_data_select_bet_pages ( gint account_number )
page = gtk_notebook_get_nth_page ( GTK_NOTEBOOK ( account_page ), GSB_FINANCE_PAGE );
gtk_widget_show ( page );
if ( current_page == GSB_ESTIMATE_PAGE || current_page == GSB_HISTORICAL_PAGE )
- gtk_notebook_set_current_page ( GTK_NOTEBOOK ( account_page ), GSB_FINANCE_PAGE );
+ gtk_notebook_set_current_page ( GTK_NOTEBOOK ( account_page ), GSB_TRANSACTIONS_PAGE );
break;
default:
if ( current_page < GSB_PROPERTIES_PAGE )
@@ -1717,14 +1717,19 @@ gboolean bet_data_transfert_modify_line ( struct_transfert_data *transfert )
static void bet_data_transfert_create_reset_credit_card ( 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 );
+
/* replace_account is an account */
if ( transfert -> type == 0 )
{
- amount = gsb_data_account_get_current_balance ( transfert->replace_account );
+ amount = gsb_data_account_calculate_balance_at_date ( transfert->replace_account, date );
transaction_number = gsb_data_transaction_new_transaction ( transfert->replace_account );
- gsb_data_transaction_set_date ( transaction_number, transfert->date_bascule );
+ gsb_data_transaction_set_date ( transaction_number, date );
gsb_data_transaction_set_amount ( transaction_number, gsb_real_opposite ( amount ) );
/* set the currency */
@@ -1765,19 +1770,25 @@ static void bet_data_transfert_create_reset_credit_card ( struct_transfert_data
}
else
{
+ GPtrArray *balances;
gchar **tab;
- GDate *date;
gint i;
- date = gsb_date_copy ( transfert->date_bascule );
- g_date_subtract_days ( date, 1 );
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 );
+
for ( i = 0; tab[i]; i++ )
{
gint account_number;
+ gsb_real *balance;
account_number = utils_str_atoi ( tab[i] );
- amount = gsb_data_account_get_current_balance ( account_number );
+ balance = (gsb_real *) g_ptr_array_index ( balances, i );
+ amount.mantissa = balance->mantissa;
+ amount.exponent = balance->exponent;
+
transaction_number = gsb_data_transaction_new_transaction ( account_number );
gsb_data_transaction_set_date ( transaction_number, date );
gsb_data_transaction_set_amount ( transaction_number, gsb_real_opposite ( amount ) );
@@ -1819,8 +1830,9 @@ static void bet_data_transfert_create_reset_credit_card ( struct_transfert_data
gsb_transactions_list_append_new_transaction ( transaction_number, TRUE );
}
g_strfreev ( tab );
- g_date_free ( date );
+ g_ptr_array_free ( balances, TRUE );
}
+ g_date_free ( date );
}
diff --git a/src/gsb_data_account.c b/src/gsb_data_account.c
index cbe299c..d390b1b 100644
--- a/src/gsb_data_account.c
+++ b/src/gsb_data_account.c
@@ -3710,10 +3710,77 @@ gboolean gsb_data_account_exists ( gint account_number )
/**
+ * calcule le solde d'un compte à une date donnée
*
+ * \param account_number numéro du compte concerné
+ * \param date date de calcul du solde
*
+ * \return gsb_real le solde du compte
+ * */
+gsb_real gsb_data_account_calculate_balance_at_date ( gint account_number,
+ GDate *date )
+{
+ struct_account *account;
+ GSList *tmp_list;
+ gsb_real current_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);
+
+ current_balance = gsb_real_adjust_exponent ( account->init_balance, floating_point );
+
+ tmp_list = gsb_data_transaction_get_complete_transactions_list ();
+
+ while (tmp_list)
+ {
+ 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 )
+ {
+ tmp_list = tmp_list->next;
+ continue;
+ }
+
+ if ( g_date_compare ( gsb_data_transaction_get_value_date_or_date ( transaction_number ),
+ date ) > 0 )
+ {
+ tmp_list = tmp_list->next;
+ continue;
+ }
+
+ if ( gsb_data_transaction_get_mother_transaction_number ( transaction_number ) == 0 )
+ {
+ gsb_real adjusted_amout;
+ gsb_real tmp_balance;
+
+ adjusted_amout = gsb_data_transaction_get_adjusted_amount ( transaction_number, floating_point );
+ tmp_balance = gsb_real_add ( current_balance, adjusted_amout );
+
+ if ( tmp_balance.mantissa == error_real.mantissa )
+ return error_real;
+ else
+ current_balance = tmp_balance;
+ }
+ tmp_list = tmp_list->next;
+ }
+
+ return current_balance;
+}
+
+
+/**
*
*
+ * \param
+ *
+ * \return
* */
/* Local Variables: */
/* c-basic-offset: 4 */
diff --git a/src/gsb_data_account.h b/src/gsb_data_account.h
index 8fd6153..f739efd 100644
--- a/src/gsb_data_account.h
+++ b/src/gsb_data_account.h
@@ -26,6 +26,8 @@ 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 );
diff --git a/src/gsb_data_partial_balance.c b/src/gsb_data_partial_balance.c
index 145246c..00110f9 100644
--- a/src/gsb_data_partial_balance.c
+++ b/src/gsb_data_partial_balance.c
@@ -41,6 +41,7 @@
#include "gsb_data_account.h"
#include "gsb_data_currency.h"
#include "gsb_data_currency_link.h"
+#include "gsb_data_transaction.h"
#include "navigation.h"
#include "gsb_real.h"
#include "utils_real.h"
@@ -85,6 +86,7 @@ static void gsb_partial_balance_selectionne_cptes ( GtkWidget *tree_view,
/*END_STATIC*/
/*START_EXTERN*/
+extern gsb_real error_real;
extern gsb_real null_real;
/*END_EXTERN*/
@@ -1435,6 +1437,140 @@ gboolean gsb_data_partial_balance_move ( gint orig_partial_number, gint dest_pos
}
+/**
+ * calcule le solde d'un solde partiel à une date donnée
+ *
+ * \param account_number numéro du compte concerné
+ * \param date date de calcul du solde
+ *
+ * \return
+ * */
+GPtrArray *gsb_data_partial_balance_calculate_balance_at_date ( gint partial_balance_number,
+ GDate *date )
+{
+ GSList *tmp_list;
+ GPtrArray *current_balances;
+ GPtrArray *current_balances_later;
+ GArray *floating_points;
+ GArray *account_numbers;
+ gchar **tab;
+ gint i;
+ gint nbre_comptes;
+ struct_partial_balance *partial_balance;
+
+ partial_balance = gsb_data_partial_balance_get_structure ( partial_balance_number );
+
+ if ( !partial_balance_number )
+ return NULL;
+
+ tab = g_strsplit ( partial_balance->liste_cptes, ";", 0 );
+
+ nbre_comptes = g_strv_length ( tab );
+ if ( nbre_comptes )
+ {
+ floating_points = g_array_new ( FALSE, TRUE, sizeof ( gint ) );
+ account_numbers = g_array_new ( FALSE, TRUE, sizeof ( gint ) );
+ current_balances = g_ptr_array_new ();
+ current_balances_later = g_ptr_array_new ();
+ }
+ else
+ return NULL;
+
+ for ( i = 0; tab[i]; i++ )
+ {
+ gint account_number;
+ gint floating_point;
+ gsb_real *balance;
+ gsb_real tmp_balance;
+
+ /* on remplit le tableau des numeros des comptes */
+ account_number = utils_str_atoi ( tab[i] );
+ g_array_append_val ( account_numbers, account_number );
+
+ /* on remplit le tableau des données des devises */
+ floating_point = gsb_data_account_get_currency_floating_point ( account_number );
+ g_array_append_val ( floating_points, floating_point );
+
+ /* on initialise le tableau des soldes de chaque compte */
+ balance = g_malloc0 ( sizeof ( gsb_real ) );
+ tmp_balance = gsb_data_account_get_init_balance ( account_number, floating_point );
+ balance->mantissa = tmp_balance.mantissa;
+ balance->exponent = tmp_balance.exponent;
+ g_ptr_array_add ( current_balances, balance );
+
+ /* on initialise le tableau des soldes en erreur de chaque compte */
+ balance = g_malloc0 ( sizeof ( gsb_real ) );
+ balance->mantissa = null_real.mantissa;
+ balance->exponent = null_real.exponent;
+ g_ptr_array_add ( current_balances_later, balance );
+ }
+
+ tmp_list = gsb_data_transaction_get_complete_transactions_list ();
+
+ while (tmp_list)
+ {
+ gint transaction_number;
+
+ transaction_number = gsb_data_transaction_get_transaction_number ( tmp_list->data );
+
+ for ( i = 0; i < nbre_comptes; i++ )
+ {
+ gint account_number;
+ gboolean trouve = FALSE;
+
+ account_number = g_array_index ( account_numbers, gint, i );
+
+ if ( gsb_data_transaction_get_account_number ( transaction_number ) == account_number )
+ {
+ if ( g_date_compare ( gsb_data_transaction_get_value_date_or_date ( transaction_number ),
+ date ) <= 0 )
+ {
+ if ( gsb_data_transaction_get_mother_transaction_number ( transaction_number ) == 0 )
+ {
+ trouve = TRUE;
+ }
+ }
+ }
+ if ( trouve )
+ {
+ gint floating_point;
+ gsb_real adjusted_amout;
+ gsb_real tmp_balance;
+ gsb_real *balance;
+ gsb_real current_balance;
+
+ floating_point = g_array_index ( floating_points, gint, i );
+ balance = (gsb_real *) g_ptr_array_index ( current_balances, i );
+ current_balance.mantissa = balance->mantissa;
+ current_balance.exponent = balance->exponent;
+
+ adjusted_amout = gsb_data_transaction_get_adjusted_amount ( transaction_number, floating_point );
+ tmp_balance = gsb_real_add ( current_balance, adjusted_amout );
+
+ if ( tmp_balance.mantissa != error_real.mantissa )
+ {
+ balance->mantissa = tmp_balance.mantissa;
+ balance->exponent = tmp_balance.exponent;
+ }
+ else
+ {
+ gsb_real *balance_later;
+
+ balance_later = (gsb_real *) g_ptr_array_index ( current_balances_later, i );
+ balance_later->mantissa = G_MININT64;
+ balance_later->exponent = 0;
+ }
+ }
+ }
+ tmp_list = tmp_list->next;
+ }
+ g_array_free ( account_numbers, TRUE );
+ g_array_free ( floating_points, TRUE );
+
+ return current_balances;
+}
+
+
/*********************************************************************************************/
/* Interface */
/*********************************************************************************************/
@@ -1653,6 +1789,13 @@ gint gsb_partial_balance_request_currency ( GtkWidget *parent )
return currency_nb;
}
+/**
+ *
+ *
+ * \param
+ *
+ * \return
+ * */
/* Local Variables: */
/* c-basic-offset: 4 */
/* End: */
diff --git a/src/gsb_data_partial_balance.h b/src/gsb_data_partial_balance.h
index c8a3c0e..2ce4cbb 100644
--- a/src/gsb_data_partial_balance.h
+++ b/src/gsb_data_partial_balance.h
@@ -8,6 +8,8 @@
/* END_INCLUDE_H */
/* START_DECLARATION */
+GPtrArray *gsb_data_partial_balance_calculate_balance_at_date ( gint partial_balance_number,
+ GDate *date );
gboolean gsb_data_partial_balance_drag_data_get ( GtkTreeDragSource * drag_source,
GtkTreePath * path,
GtkSelectionData * selection_data );
hooks/post-receive
--
grisbi
More information about the cvs
mailing list