[grisbi-cvs] [SCM] grisbi branch, master, updated. 41c0c63b1d556bbcb9b04faeea7a8df65be654b1
Pierre Biava
nobody at users.sourceforge.net
Fri Jul 9 22:39:19 CEST 2010
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 41c0c63b1d556bbcb9b04faeea7a8df65be654b1 (commit)
via 623729de6b298b058a67f0c166ad52aa7c6fc9df (commit)
from 66c6c461de3bfdabc165321b018a79789a83e37e (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 41c0c63b1d556bbcb9b04faeea7a8df65be654b1
Author: pbiava <pierre.biava at nerim.net>
Date: Fri Jul 9 09:08:09 2010 +0200
renaming files of budgetary module
commit 623729de6b298b058a67f0c166ad52aa7c6fc9df
Author: pbiava <pierre.biava at nerim.net>
Date: Fri Jul 9 08:37:40 2010 +0200
deleting the definition of lldiv_t already present in the Windows SDK
-----------------------------------------------------------------------
Changes:
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8cae295..050a053 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,11 +1,11 @@
src/accueil.c
src/affichage.c
src/affichage_liste.c
-src/balance_estimate_config.c
-src/balance_estimate_data.c
-src/balance_estimate_future.c
-src/balance_estimate_hist.c
-src/balance_estimate_tab.c
+src/bet_config.c
+src/bet_data.c
+src/bet_future.c
+src/bet_hist.c
+src/bet_tab.c
src/barre_outils.c
src/categories_onglet.c
src/classement_echeances.c
diff --git a/src/Makefile.am b/src/Makefile.am
index cec0928..3d83d03 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -68,7 +68,7 @@ libgrisbi_la_SOURCES = \
gsb_data_fyear.c \
gsb_data_import_rule.c \
gsb_data_mix.c \
- gsb_data_partial_balance.c \
+ gsb_data_partial_balance.c \
gsb_data_payee.c \
gsb_data_payment.c \
gsb_data_print_config.c \
@@ -141,32 +141,32 @@ libgrisbi_la_SOURCES = \
utils_font.c \
utils_operations.c \
utils_str.c \
- balance_estimate_config.c \
- balance_estimate_data.c \
- balance_estimate_future.c \
- balance_estimate_hist.c \
- balance_estimate_tab.c \
+ bet_config.c \
+ bet_data.c \
+ bet_future.c \
+ bet_hist.c \
+ bet_tab.c \
accueil.h \
affichage.h \
affichage_liste.h \
barre_outils.h \
- balance_estimate_config.h \
- balance_estimate_data.h \
- balance_estimate_future.h \
- balance_estimate_hist.h \
- balance_estimate_tab.h \
+ bet_config.h \
+ bet_data.h \
+ bet_future.h \
+ bet_hist.h \
+ bet_tab.h \
categories_onglet.h \
classement_echeances.h \
- csv_parse.h \
+ csv_parse.h \
custom_list.h \
erreur.h \
- etats_affiche.h \
- etats_csv.h \
- etats_html.h \
- export.h \
- export_csv.h \
- go-charmap-sel.h \
- go-optionmenu.h \
+ etats_affiche.h \
+ etats_csv.h \
+ etats_html.h \
+ export.h \
+ export_csv.h \
+ go-charmap-sel.h \
+ go-optionmenu.h \
gsb_account.h \
gsb_account_property.h \
gsb_archive_config.h \
@@ -184,7 +184,7 @@ libgrisbi_la_SOURCES = \
gsb_combo_box.h \
gsb_calendar.h \
gsb_calendar_entry.h \
- gsb_currency.h \
+ gsb_currency.h \
gsb_currency_config.h \
gsb_currency_link_config.h \
gsb_data_account.h \
@@ -199,7 +199,7 @@ libgrisbi_la_SOURCES = \
gsb_data_fyear.h \
gsb_data_import_rule.h \
gsb_data_mix.h \
- gsb_data_partial_balance.h \
+ gsb_data_partial_balance.h \
gsb_data_payee.h \
gsb_data_payment.h \
gsb_data_print_config.h \
@@ -225,14 +225,14 @@ libgrisbi_la_SOURCES = \
gsb_fyear_config.h \
gsb_payment_method.h \
gsb_payment_method_config.h \
- gsb_plugins.h \
+ gsb_plugins.h \
gsb_real.h \
gsb_reconcile.h \
gsb_reconcile_config.h \
gsb_reconcile_list.h \
gsb_reconcile_sort_config.h \
gsb_report.h \
- gsb_status.h \
+ gsb_status.h \
gsb_select_icon.h \
gsb_scheduler.h \
gsb_scheduler_list.h \
@@ -256,11 +256,11 @@ libgrisbi_la_SOURCES = \
imputation_budgetaire.h \
include.h \
menu.h \
- meta_budgetary.h \
- meta_categories.h \
- meta_payee.h \
- metatree.h \
- mouse.h \
+ meta_budgetary.h \
+ meta_categories.h \
+ meta_payee.h \
+ metatree.h \
+ mouse.h \
navigation.h \
parametres.h \
parse_cmdline.h \
@@ -285,7 +285,8 @@ libgrisbi_la_SOURCES = \
utils_files.h \
utils_font.h \
utils_operations.h \
- utils_str.h
+ utils_str.h \
+ bet_config.c
grisbi_SOURCES = \
main.c \
diff --git a/src/bet_config.c b/src/bet_config.c
new file mode 100644
index 0000000..bf10ac0
--- /dev/null
+++ b/src/bet_config.c
@@ -0,0 +1,1106 @@
+/* ************************************************************************** */
+/* */
+/* Copyright (C) 2007 Dominique Parisot */
+/* zionly at free.org */
+/* 2008-2010 Pierre Biava (grisbi at pierre.biava.name) */
+/* 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 */
+/* the Free Software Foundation; either version 2 of the License, or */
+/* (at your option) any later version. */
+/* */
+/* This program is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
+/* GNU General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU General Public License */
+/* along with this program; if not, write to the Free Software */
+/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+/* */
+/* ************************************************************************** */
+
+/* ./configure --with-balance-estimate */
+
+#include "include.h"
+#include <config.h>
+
+/*START_INCLUDE*/
+#include "bet_config.h"
+#include "bet_data.h"
+#include "bet_hist.h"
+#include "bet_tab.h"
+#include "utils_dates.h"
+#include "gsb_account.h"
+#include "gsb_automem.h"
+#include "gsb_data_account.h"
+#include "gsb_fyear.h"
+#include "navigation.h"
+#include "dialog.h"
+#include "traitement_variables.h"
+#include "utils.h"
+#include "utils_str.h"
+#include "bet_data.h"
+#include "structures.h"
+#include "include.h"
+#include "erreur.h"
+/*END_INCLUDE*/
+
+
+/*START_STATIC*/
+static gboolean bet_config_change_account ( GtkWidget *combo );
+static gint bet_config_get_account_from_combo ( void );
+static GtkWidget *bet_config_general_get_period_widget ( GtkWidget *container );
+static GtkWidget *bet_config_account_get_forecast_data ( gchar *title );
+static GtkWidget *bet_config_account_get_select_account ( gchar *title );
+static GtkWidget *bet_config_account_get_select_historical_data ( gchar *title );
+static GtkWidget *bet_config_get_select_labels_widget ( GtkWidget *container );
+static void bet_config_period_clicked ( GtkWidget *togglebutton, GtkWidget *button );
+static gboolean bet_config_select_label_changed ( GtkWidget *checkbutton,
+ gpointer data );
+static GtkWidget *bet_config_get_select_historical_data ( GtkWidget *container,
+ GtkWidget *notebook );
+static void bet_config_sensitive_account_parameters ( gint account_number, gboolean sensitive );
+static void bet_config_use_budget_toggle ( GtkToggleButton *button, GtkWidget *notebook );
+static void bet_config_initialise_duration_widget ( gint account_number,
+ GtkWidget *notebook );
+static void bet_config_initialise_select_historical_data ( gint account_number,
+ GtkWidget *notebook );
+/*END_STATIC*/
+
+/*START_EXTERN*/
+extern GtkWidget *account_page;
+extern GtkTreeModel *bet_fyear_model;
+extern GtkTreeModel *bet_fyear_model_filter;
+extern GtkWidget *notebook_general;
+/*END_EXTERN*/
+
+gchar* bet_duration_array[] = {
+ N_("Month"),
+ N_("Year"),
+ NULL
+};
+
+const gdouble prev_month_max = 60.0;
+
+/**
+ *
+ *
+ *
+ *
+ * */
+
+GtkWidget *bet_config_general_create_general_page ( void )
+{
+ GtkWidget *vbox;
+ GtkWidget *paddingbox;
+ GtkWidget *widget;
+
+
+ vbox = new_vbox_with_title_and_icon ( _("General Options"), "balance_estimate.png" );
+ gtk_container_set_border_width ( GTK_CONTAINER ( vbox ), 12 );
+
+ /* Calculation of period */
+ paddingbox = new_paddingbox_with_title ( vbox, FALSE, _("Common data") );
+
+ widget = bet_config_general_get_period_widget ( paddingbox );
+
+ /* add a separator */
+ gtk_box_pack_start ( GTK_BOX ( vbox ), gtk_hseparator_new (), FALSE, FALSE, 5 );
+
+ gtk_widget_show_all ( vbox );
+
+ return vbox;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+GtkWidget *bet_config_general_get_period_widget ( GtkWidget *container )
+{
+ GtkWidget *vbox;
+ GtkWidget *label;
+ GtkWidget *button_1, *button_2;
+ GtkWidget *hbox;
+ GtkSizeGroup *size_group;
+ gchar *text;
+
+ //~ devel_debug (NULL);
+ size_group = gtk_size_group_new ( GTK_SIZE_GROUP_HORIZONTAL );
+
+ vbox = gtk_vbox_new ( FALSE, 5 );
+ gtk_box_pack_start ( GTK_BOX ( container ), vbox, FALSE, FALSE, 5);
+
+ label = gtk_label_new ( _("Beginning of period") );
+ gtk_misc_set_alignment ( GTK_MISC ( label ), 0, 0.5);
+ gtk_label_set_justify ( GTK_LABEL ( label ), GTK_JUSTIFY_LEFT );
+ gtk_box_pack_start ( GTK_BOX ( vbox ), label, FALSE, FALSE, 5) ;
+
+ hbox = gtk_hbox_new ( FALSE, 5 );
+ gtk_box_pack_start ( GTK_BOX ( vbox ), hbox, FALSE, FALSE, 5) ;
+
+ button_1 = gtk_radio_button_new_with_label ( NULL,
+ _("1st day of month") );
+ gtk_widget_set_name ( button_1, "bet_period_button_1" );
+ gtk_size_group_add_widget ( GTK_SIZE_GROUP ( size_group ), button_1 );
+
+ button_2 = gtk_radio_button_new_with_label_from_widget (
+ GTK_RADIO_BUTTON ( button_1 ),
+ _("date today") );
+
+ if ( etat.bet_deb_period == 1 )
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button_1 ), TRUE );
+ else
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button_2 ), TRUE );
+
+ gtk_box_pack_start ( GTK_BOX ( hbox ), button_1, FALSE, FALSE, 5) ;
+ gtk_box_pack_start ( GTK_BOX ( hbox ), button_2, FALSE, FALSE, 5) ;
+
+ /*set the signals */
+ g_signal_connect (G_OBJECT ( button_1 ),
+ "released",
+ G_CALLBACK ( bet_config_period_clicked ),
+ NULL );
+ g_signal_connect (G_OBJECT ( button_2 ),
+ "released",
+ G_CALLBACK ( bet_config_period_clicked ),
+ NULL );
+
+ text = make_blue ( _("Note: This option is used if no starting date for forecasts.") );
+ label = gtk_label_new ( text );
+ gtk_label_set_use_markup ( GTK_LABEL(label), TRUE );
+ gtk_misc_set_alignment ( GTK_MISC ( label ), 0, 0.5);
+ gtk_label_set_justify ( GTK_LABEL ( label ), GTK_JUSTIFY_LEFT );
+ gtk_box_pack_start ( GTK_BOX ( vbox ), label, FALSE, FALSE, 5) ;
+ g_free ( text );
+
+ gtk_widget_show_all ( vbox );
+
+ return vbox;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+
+GtkWidget *bet_config_account_create_account_page ( void )
+{
+ GtkWidget *notebook;
+ GtkWidget *vbox_pref;
+ GtkWidget *vbox;
+ GtkWidget *widget;
+
+ vbox_pref = new_vbox_with_title_and_icon ( _("Accounts data"), "balance_estimate.png" );
+ gtk_container_set_border_width ( GTK_CONTAINER ( vbox_pref ), 12 );
+
+ /* set the choice of account */
+ widget = bet_config_account_get_select_account ( "Select an account" );
+ gtk_box_pack_start ( GTK_BOX ( vbox_pref ), widget, FALSE, FALSE, 0 );
+ gtk_widget_show_all ( vbox_pref );
+
+ notebook = gtk_notebook_new ( );
+ gtk_notebook_set_show_border ( GTK_NOTEBOOK ( notebook ), FALSE );
+ gtk_notebook_set_show_tabs ( GTK_NOTEBOOK ( notebook ), FALSE );
+ gtk_notebook_set_scrollable ( GTK_NOTEBOOK ( notebook ), TRUE );
+ gtk_box_pack_start ( GTK_BOX ( vbox_pref ), notebook, FALSE, FALSE, 0 );
+ g_object_set_data ( G_OBJECT ( account_page ), "config_notebook", notebook );
+
+ /* Data for the account of type GSB_TYPE_BANK, GSB_TYPE_CASH */
+ vbox = gtk_vbox_new ( FALSE, 0 );
+ gtk_notebook_append_page ( GTK_NOTEBOOK ( notebook ), vbox, NULL );
+
+ /* Data for the forecast */
+ widget = bet_config_account_get_forecast_data ( _("Data for the forecast") );
+ g_object_set_data ( G_OBJECT ( account_page ), "Data_for_forecast", widget );
+ gtk_box_pack_start ( GTK_BOX ( vbox ), widget, FALSE, FALSE, 0 );
+
+ /* Sources of historical data */
+ widget = bet_config_account_get_select_historical_data ( _("Sources of historical data") );
+ g_object_set_data ( G_OBJECT ( account_page ), "Data_for_historical", widget );
+ gtk_box_pack_start ( GTK_BOX ( vbox ), widget, FALSE, FALSE, 0 );
+
+ /* Data for the account of type GSB_TYPE_LIABILITIES */
+ vbox = gtk_vbox_new ( FALSE, 0 );
+ gtk_notebook_append_page ( GTK_NOTEBOOK ( notebook ), vbox, NULL );
+
+ widget = g_object_get_data ( G_OBJECT ( account_page ), "account_combo" );
+ bet_config_change_account ( widget );
+
+ gtk_widget_show_all ( notebook );
+
+ return vbox_pref;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+GtkWidget *bet_config_account_get_select_account ( gchar *title )
+{
+ GtkWidget *vbox;
+ GtkWidget *hbox;
+ GtkWidget *combo;
+ GtkWidget *button;
+ GtkWidget *paddingbox;
+ GtkWidget *label;
+ gint account_number;
+
+ vbox = gtk_vbox_new ( FALSE, 0 );
+
+ /* set the choice of account */
+ paddingbox = new_paddingbox_with_title ( vbox, FALSE, _(title) );
+
+ hbox = gtk_hbox_new ( FALSE, 5 );
+ gtk_box_pack_start ( GTK_BOX ( paddingbox ), hbox, FALSE, FALSE, 5 );
+
+ label = gtk_label_new (COLON(_("Account")));
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 1);
+ gtk_label_set_justify ( GTK_LABEL (label), GTK_JUSTIFY_LEFT );
+ gtk_box_pack_start ( GTK_BOX (hbox ), label, FALSE, FALSE, 0 );
+
+ combo = gsb_account_create_combo_list ( (GtkSignalFunc) bet_config_change_account,
+ NULL, FALSE );
+ g_object_set_data ( G_OBJECT ( account_page ), "account_combo", combo );
+ if ( ( account_number = gsb_gui_navigation_get_current_account ( ) ) == -1 )
+ gtk_combo_box_set_active ( GTK_COMBO_BOX ( combo ), 0 );
+ else
+ gsb_account_set_combo_account_number ( combo, account_number );
+ gtk_box_pack_start ( GTK_BOX ( hbox ), combo, FALSE, FALSE, 0 );
+
+ button = gtk_check_button_new_with_label ( _("Use the budget module") );
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button ), FALSE );
+ g_object_set_data ( G_OBJECT ( combo ), "bet_use_budget", button );
+ gtk_box_pack_start ( GTK_BOX ( hbox ), button, FALSE, FALSE, 5 );
+ g_signal_connect ( G_OBJECT ( button ),
+ "toggled",
+ G_CALLBACK ( bet_config_use_budget_toggle ),
+ combo );
+
+ return vbox;
+}
+
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+GtkWidget *bet_config_account_get_forecast_data ( gchar *title )
+{
+ GtkWidget *vbox;
+ GtkWidget *widget;
+ GtkWidget *paddingbox;
+
+ vbox = gtk_vbox_new ( FALSE, 0 );
+ paddingbox = new_paddingbox_with_title ( vbox, FALSE, _(title) );
+
+ /* Calculation of duration */
+ widget = bet_config_get_duration_widget ( SPP_ORIGIN_CONFIG );
+ gtk_box_pack_start ( GTK_BOX ( paddingbox ), widget, FALSE, FALSE, 0);
+
+ /* Select the labels of the list */
+ widget = bet_config_get_select_labels_widget ( paddingbox );
+
+ return vbox;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+GtkWidget *bet_config_get_duration_widget ( gint origin )
+{
+ GtkWidget *box = NULL;
+ GtkWidget *label;
+ GtkWidget *spin_button = NULL;
+ GtkWidget *widget = NULL;
+ GtkWidget *hbox;
+ GtkWidget *previous = NULL;
+ gpointer pointer = NULL;
+ gint iduration;
+
+ if ( origin == SPP_ORIGIN_CONFIG )
+ {
+ box = gtk_vbox_new ( FALSE, 0 );
+ pointer = GINT_TO_POINTER ( 0 );
+ }
+ else if ( origin == SPP_ORIGIN_ARRAY )
+ {
+ box = gtk_hbox_new ( FALSE, 0 );
+ pointer = GINT_TO_POINTER ( 1 );
+ }
+
+ /* partie mensuelle */
+ label = gtk_label_new ( _("Duration estimation") );
+ gtk_misc_set_alignment ( GTK_MISC ( label ), 0, 0.5);
+ gtk_label_set_justify ( GTK_LABEL ( label ), GTK_JUSTIFY_LEFT );
+ gtk_box_pack_start ( GTK_BOX ( box ), label, FALSE, FALSE, 5 ) ;
+
+ hbox = gtk_hbox_new ( FALSE, 5 );
+ gtk_box_pack_start ( GTK_BOX ( box ), hbox, FALSE, FALSE, 0 ) ;
+
+ spin_button = gtk_spin_button_new_with_range ( 1.0, prev_month_max, 1.0);
+ gtk_spin_button_set_value ( GTK_SPIN_BUTTON ( spin_button ), 1.0 );
+ gtk_box_pack_start ( GTK_BOX ( hbox ), spin_button, FALSE, FALSE, 0 );
+
+ for (iduration = 0; bet_duration_array[iduration] != NULL; iduration++)
+ {
+ if (previous == NULL)
+ {
+ widget = gtk_radio_button_new_with_label ( NULL,
+ _(bet_duration_array[iduration]) );
+ previous = widget;
+ }
+ else
+ {
+ widget = gtk_radio_button_new_with_label_from_widget (
+ GTK_RADIO_BUTTON ( previous ),
+ _(bet_duration_array[iduration]) );
+ }
+ gtk_widget_set_name ( widget, bet_duration_array[iduration] );
+ gtk_box_pack_start ( GTK_BOX ( hbox ), widget, FALSE, FALSE, 0 );
+ g_signal_connect (G_OBJECT ( widget ),
+ "released",
+ G_CALLBACK ( bet_config_duration_button_clicked ),
+ spin_button );
+ }
+
+ if ( origin == SPP_ORIGIN_CONFIG )
+ {
+
+ g_object_set_data ( G_OBJECT ( spin_button ), "bet_origin_signal", pointer );
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_config_account_previous",
+ previous );
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_config_account_widget",
+ widget );
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_config_account_spin_button",
+ spin_button );
+ }
+ else if ( origin == SPP_ORIGIN_ARRAY )
+ {
+ g_object_set_data ( G_OBJECT ( spin_button ), "bet_origin_signal", pointer );
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_account_previous", previous );
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_account_widget", widget );
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_account_spin_button", spin_button );
+ }
+
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( previous ), TRUE );
+
+ g_signal_connect ( G_OBJECT ( spin_button ),
+ "value-changed",
+ G_CALLBACK ( bet_config_duration_number_changed ),
+ pointer );
+ g_object_set_data ( G_OBJECT ( spin_button ), "pointer", pointer );
+
+ gtk_widget_show_all ( box );
+
+ return box;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_config_initialise_duration_widget ( gint account_number,
+ GtkWidget *notebook )
+{
+ GtkWidget *widget = NULL;
+ GtkWidget *button = NULL;
+ gpointer ptr = NULL;
+ gint param;
+ gint months;
+
+ param = gsb_data_account_get_bet_spin_range ( account_number );
+ months = gsb_data_account_get_bet_months ( account_number );
+ button = g_object_get_data ( G_OBJECT ( account_page ), "bet_config_account_spin_button" );
+
+ if ( button && G_IS_OBJECT ( button ) )
+ {
+ ptr = g_object_get_data ( G_OBJECT ( button ), "pointer" );
+ g_signal_handlers_block_by_func ( G_OBJECT ( button ),
+ G_CALLBACK ( bet_config_duration_number_changed ),
+ ptr );
+ }
+
+ if ( param == 0 )
+ {
+ widget = g_object_get_data ( G_OBJECT ( account_page ), "bet_config_account_previous" );
+ if ( widget && G_IS_OBJECT ( widget ) )
+ {
+ g_signal_handlers_block_by_func ( G_OBJECT ( widget ),
+ G_CALLBACK ( bet_config_duration_button_clicked ),
+ button );
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( widget ), TRUE );
+ }
+ if ( button )
+ {
+ gtk_spin_button_set_range ( GTK_SPIN_BUTTON ( button ), 1.0, prev_month_max );
+ gtk_spin_button_set_value ( GTK_SPIN_BUTTON ( button ), (gdouble) months );
+ }
+ }
+ else
+ {
+ widget = g_object_get_data ( G_OBJECT ( account_page ), "bet_config_account_widget" );
+ if ( widget && G_IS_OBJECT ( widget ) )
+ {
+ g_signal_handlers_block_by_func ( G_OBJECT ( widget ),
+ G_CALLBACK ( bet_config_duration_button_clicked ),
+ button );
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( widget ), TRUE );
+ }
+ if ( button )
+ {
+ gtk_spin_button_set_range ( GTK_SPIN_BUTTON ( button ), 1.0,
+ prev_month_max / 12.0 );
+ gtk_spin_button_set_value ( GTK_SPIN_BUTTON ( button ),
+ (gdouble) months / 12.0 );
+ }
+ }
+
+ if ( widget && G_IS_OBJECT ( widget ) )
+ g_signal_handlers_unblock_by_func ( G_OBJECT ( widget ),
+ G_CALLBACK ( bet_config_duration_button_clicked ),
+ button );
+ if ( button && G_IS_OBJECT ( button ) )
+ g_signal_handlers_unblock_by_func ( G_OBJECT ( button ),
+ G_CALLBACK ( bet_config_duration_number_changed ),
+ ptr );
+
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+GtkWidget *bet_config_get_select_labels_widget ( GtkWidget *container )
+{
+ GtkWidget *vbox;
+ GtkWidget *label;
+ GtkWidget *button;
+ gchar *text;
+ gint origine;
+ gint select;
+
+ vbox = gtk_vbox_new ( FALSE, 0 );
+ gtk_box_pack_start ( GTK_BOX ( container ), vbox, FALSE, FALSE, 0 );
+
+ /* set labels for transactions */
+ origine = SPP_ORIGIN_TRANSACTION;
+ select = gsb_data_account_get_bet_select_label ( bet_config_get_account_from_combo ( ),
+ origine );
+ label = gtk_label_new ( _("Labels for transactions") );
+ gtk_misc_set_alignment ( GTK_MISC ( label ), 0, 0.5);
+ gtk_label_set_justify ( GTK_LABEL ( label ), GTK_JUSTIFY_LEFT );
+ gtk_box_pack_start ( GTK_BOX ( vbox ), label, FALSE, FALSE, 5 );
+
+ button = gsb_automem_radiobutton3_new ( _("By default"),
+ _("Categories"),
+ _("Budgetary lines"),
+ &select,
+ G_CALLBACK ( bet_config_select_label_changed ),
+ GINT_TO_POINTER ( origine ) );
+ gtk_box_pack_start ( GTK_BOX ( vbox ), button, FALSE, FALSE, 0 );
+
+
+ /* set labels for scheduled */
+ origine = SPP_ORIGIN_SCHEDULED;
+ select = gsb_data_account_get_bet_select_label ( bet_config_get_account_from_combo ( ),
+ origine );
+ label = gtk_label_new ( _("Labels for scheduled transactions") );
+ gtk_misc_set_alignment ( GTK_MISC ( label ), 0, 0.5);
+ gtk_label_set_justify ( GTK_LABEL ( label ), GTK_JUSTIFY_LEFT );
+ gtk_box_pack_start ( GTK_BOX ( vbox ), label, FALSE, FALSE, 5 );
+
+ button = gsb_automem_radiobutton3_new ( _("By default"),
+ _("Categories"),
+ _("Budgetary lines"),
+ &select,
+ G_CALLBACK ( bet_config_select_label_changed ),
+ GINT_TO_POINTER ( origine ) );
+ gtk_box_pack_start ( GTK_BOX ( vbox ), button, FALSE, FALSE, 0 );
+
+ /* set labels for futur data */
+ origine = SPP_ORIGIN_FUTURE;
+ select = gsb_data_account_get_bet_select_label ( bet_config_get_account_from_combo ( ),
+ origine );
+ label = gtk_label_new ( _("Labels for futur data") );
+ gtk_misc_set_alignment ( GTK_MISC ( label ), 0, 0.5);
+ gtk_label_set_justify ( GTK_LABEL ( label ), GTK_JUSTIFY_LEFT );
+ gtk_box_pack_start ( GTK_BOX ( vbox ), label, FALSE, FALSE, 5 );
+
+ button = gsb_automem_radiobutton3_new ( _("By default"),
+ _("Categories"),
+ _("Budgetary lines"),
+ &select,
+ G_CALLBACK ( bet_config_select_label_changed ),
+ GINT_TO_POINTER ( origine ) );
+ gtk_box_pack_start ( GTK_BOX ( vbox ), button, FALSE, FALSE, 0 );
+
+ text = make_blue ( _("Order by default if the data are not zero: notes, payee, "
+ "category and budgetary line.") );
+ label = gtk_label_new ( text );
+ gtk_label_set_use_markup ( GTK_LABEL(label), TRUE );
+ gtk_misc_set_alignment ( GTK_MISC ( label ), 0, 0.5);
+ gtk_label_set_justify ( GTK_LABEL ( label ), GTK_JUSTIFY_LEFT );
+ gtk_box_pack_start ( GTK_BOX ( vbox ), label, FALSE, FALSE, 5 ) ;
+ g_free ( text );
+
+ gtk_widget_show_all ( vbox );
+
+ return vbox;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+GtkWidget *bet_config_account_get_select_historical_data ( gchar *title )
+{
+ GtkWidget *vbox;
+ GtkWidget *paddingbox;
+ GtkWidget *hbox;
+
+ vbox = gtk_vbox_new ( FALSE, 0 );
+
+ paddingbox = new_paddingbox_with_title ( vbox, FALSE, _(title) );
+ hbox = bet_config_get_select_historical_data ( paddingbox, account_page );
+
+ return vbox;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+GtkWidget *bet_config_get_select_historical_data ( GtkWidget *container,
+ GtkWidget *notebook )
+{
+ GtkWidget *widget;
+ GtkWidget *hbox;
+ GtkWidget *button_1, *button_2;
+ gchar *str_year;
+ gint year;
+
+ /* Choix des données sources */
+ hbox = gtk_hbox_new ( FALSE, 5 );
+ gtk_box_pack_start ( GTK_BOX ( container ), hbox, FALSE, FALSE, 0 );
+
+ button_1 = gtk_radio_button_new_with_label ( NULL,
+ _("Categories") );
+ gtk_widget_set_name ( button_1, "bet_hist_button_1" );
+ g_signal_connect (G_OBJECT ( button_1 ),
+ "released",
+ G_CALLBACK ( bet_config_origin_data_clicked ),
+ GINT_TO_POINTER ( 0 ) );
+
+ button_2 = gtk_radio_button_new_with_label_from_widget (
+ GTK_RADIO_BUTTON ( button_1 ),
+ _("Budgetary lines") );
+ g_signal_connect (G_OBJECT ( button_2 ),
+ "released",
+ G_CALLBACK ( bet_config_origin_data_clicked ),
+ GINT_TO_POINTER ( 0 ) );
+
+ g_object_set_data ( G_OBJECT ( notebook ), "bet_config_hist_button_1", button_1 );
+ g_object_set_data ( G_OBJECT ( notebook ), "bet_config_hist_button_2", button_2 );
+ gtk_box_pack_start ( GTK_BOX ( hbox ), button_1, FALSE, FALSE, 5) ;
+ gtk_box_pack_start ( GTK_BOX ( hbox ), button_2, FALSE, FALSE, 5) ;
+
+ /* création du sélecteur de périod */
+ widget = gsb_fyear_make_combobox_new ( bet_fyear_model_filter, TRUE );
+ gtk_widget_set_name ( GTK_WIDGET ( widget ), "bet_hist_fyear_combo" );
+ gtk_widget_set_tooltip_text ( GTK_WIDGET ( widget ),
+ SPACIFY(_("Choose the financial year or 12 months rolling") ) );
+ gtk_box_pack_start ( GTK_BOX ( hbox ), widget, FALSE, FALSE, 5);
+ g_object_set_data ( G_OBJECT ( notebook ), "bet_config_hist_fyear_combo", widget );
+
+ /* hide the present financial year */
+ year = g_date_get_year ( gdate_today ( ) );
+ str_year = utils_str_itoa ( year );
+ gsb_fyear_hide_iter_by_name ( bet_fyear_model, str_year );
+ g_free ( str_year );
+
+ /* set the signal */
+ g_signal_connect ( G_OBJECT ( widget ),
+ "changed",
+ G_CALLBACK ( bet_config_fyear_clicked ),
+ GINT_TO_POINTER ( 0 ) );
+
+ return hbox;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_config_initialise_select_historical_data ( gint account_number,
+ GtkWidget *notebook )
+{
+ GtkWidget *widget;
+ GtkWidget *button = NULL;
+ gint param;
+
+ param = gsb_data_account_get_bet_hist_data ( account_number );
+
+ if ( param == 1 )
+ button = g_object_get_data ( G_OBJECT ( notebook ), "bet_config_hist_button_2" );
+ else
+ button = g_object_get_data ( G_OBJECT ( notebook ), "bet_config_hist_button_1" );
+
+ if ( button )
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button ), TRUE );
+
+ param = gsb_data_account_get_bet_hist_fyear ( account_number );
+ widget = g_object_get_data ( G_OBJECT ( notebook ), "bet_config_hist_fyear_combo" );
+ bet_historical_set_fyear_from_combobox ( widget, param );
+}
+
+
+/*
+ * bet_config_duration_period_clicked
+ * This function is called when a radio button is called to change the inial period.
+ * It copies the new durations from the data parameter (of the radio button) into
+ * the bet_period property of the bet container
+ */
+void bet_config_period_clicked ( GtkWidget *togglebutton, GtkWidget *button )
+{
+ const gchar *name;
+
+ if ( button )
+ g_signal_handlers_block_by_func ( G_OBJECT ( button ),
+ G_CALLBACK ( bet_config_period_clicked ),
+ button );
+
+ name = gtk_widget_get_name ( GTK_WIDGET ( togglebutton ) );
+
+ if ( g_strcmp0 ( name, "bet_period_button_1" ) == 0 )
+ {
+ etat.bet_deb_period = 1;
+ }
+ else
+ {
+ etat.bet_deb_period = 2;
+ }
+ if ( button )
+ g_signal_handlers_unblock_by_func ( G_OBJECT ( button ),
+ G_CALLBACK ( bet_config_period_clicked ),
+ button );
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+}
+
+
+/*
+ * This function is called when a radio button is called to change the estimate duration.
+ * It copies the new durations from the data parameter (of the radio button) into
+ * the bet_months property of the bet container
+ */
+void bet_config_duration_button_clicked ( GtkWidget *togglebutton,
+ GtkWidget *spin_button )
+{
+ const gchar *name;
+ gpointer data;
+ gint account_number;
+ gint months;
+
+ name = gtk_widget_get_name ( GTK_WIDGET ( togglebutton ) );
+ data = g_object_get_data ( G_OBJECT ( spin_button ), "bet_origin_signal");
+
+ if ( GPOINTER_TO_INT ( data ) == 0 )
+ account_number = bet_config_get_account_from_combo ( );
+ else
+ account_number = gsb_gui_navigation_get_current_account ( );
+
+ g_signal_handlers_block_by_func ( G_OBJECT ( spin_button ),
+ G_CALLBACK ( bet_config_duration_number_changed ),
+ data );
+
+ if ( g_strcmp0 ( name, "Year" ) == 0 )
+ {
+ gsb_data_account_set_bet_spin_range ( account_number, 1 );
+ gtk_spin_button_set_range ( GTK_SPIN_BUTTON ( spin_button ), 1.0, prev_month_max / 12.0);
+ months = gsb_data_account_get_bet_months ( account_number );
+ if ( months > ( prev_month_max / 12.0 ) )
+ {
+ gint number;
+
+ number = months / 12;
+ if ( number < 1 )
+ number = 1;
+ else if ( months % 12 )
+ number ++;
+ gtk_spin_button_set_value ( GTK_SPIN_BUTTON ( spin_button ), number );
+ gsb_data_account_set_bet_months ( account_number, number * 12 );
+ }
+ else
+ gsb_data_account_set_bet_months ( account_number, months * 12 );
+ }
+ else
+ {
+ gsb_data_account_set_bet_spin_range ( account_number, 0 );
+ months = gsb_data_account_get_bet_months ( account_number );
+ gsb_data_account_set_bet_months ( account_number, months );
+ gtk_spin_button_set_range ( GTK_SPIN_BUTTON ( spin_button ), 1.0, prev_month_max );
+ }
+
+ g_signal_handlers_unblock_by_func ( G_OBJECT ( spin_button ),
+ G_CALLBACK ( bet_config_duration_number_changed ),
+ data );
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ bet_data_update_bet_module ( account_number, -1 );
+}
+
+
+/*
+ * bet_config_duration_button changed
+ * This function is called when a spin button is changed.
+ * It copies the new duration from the spin_button into the bet_months property of
+ * the bet container
+ */
+gboolean bet_config_duration_number_changed ( GtkWidget *spin_button,
+ gpointer data )
+{
+ gint account_number;
+ gint months;
+
+ if ( GPOINTER_TO_INT ( data ) == 0 )
+ account_number = bet_config_get_account_from_combo ( );
+ else
+ account_number = gsb_gui_navigation_get_current_account ( );
+
+ months = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON ( spin_button ) );
+ if ( gsb_data_account_get_bet_spin_range ( account_number ) == 1 )
+ months *= 12;
+
+ gsb_data_account_set_bet_months ( account_number, months );
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ bet_data_update_bet_module ( account_number, -1 );
+
+ return ( FALSE );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_config_origin_data_clicked ( GtkWidget *togglebutton, gpointer data )
+{
+ GtkTreeViewColumn *column;
+ const gchar *name;
+ gchar *title;
+ gint account_number;
+
+ if ( GPOINTER_TO_INT ( data ) == 0 )
+ account_number = bet_config_get_account_from_combo ( );
+ else
+ account_number = gsb_gui_navigation_get_current_account ( );
+
+ name = gtk_widget_get_name ( GTK_WIDGET ( togglebutton ) );
+
+ if ( g_strcmp0 ( name, "bet_hist_button_1" ) == 0 )
+ {
+ gsb_data_account_set_bet_hist_data ( account_number, 0 );
+ bet_data_set_div_ptr ( 0 );
+ title = g_strdup ( _("Category") );
+ }
+ else
+ {
+ gsb_data_account_set_bet_hist_data ( account_number, 1 );
+ bet_data_set_div_ptr ( 1 );
+ title = g_strdup ( _("Budgetary line") );
+ }
+
+ column = g_object_get_data ( G_OBJECT ( account_page ),
+ "historical_column_source" );
+ gtk_tree_view_column_set_title ( GTK_TREE_VIEW_COLUMN ( column ), title );
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ALL );
+ bet_data_update_bet_module ( account_number, -1 );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_config_fyear_clicked ( GtkWidget *combo, gpointer data )
+{
+ gint account_number;
+
+ if ( GPOINTER_TO_INT ( data ) == 0 )
+ account_number = bet_config_get_account_from_combo ( );
+ else
+ account_number = gsb_gui_navigation_get_current_account ( );
+
+ gsb_data_account_set_bet_hist_fyear ( account_number,
+ bet_historical_get_fyear_from_combobox ( combo ) );
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ALL );
+ bet_data_update_bet_module ( account_number, -1 );
+}
+
+
+/**
+ * callback called when changing the account from the button
+ * re-fill the page with the account data
+ *
+ * \param button
+ * \param null
+ *
+ * \return FALSE
+ * */
+gboolean bet_config_change_account ( GtkWidget *combo )
+{
+ GtkWidget *notebook;
+ GtkWidget *widget = NULL;
+ gint account_number;
+ gint bet_use_budget;
+ kind_account kind;
+
+ devel_debug (NULL);
+ widget = g_object_get_data ( G_OBJECT ( combo ), "bet_use_budget" );
+
+ if ( !GTK_IS_TOGGLE_BUTTON ( widget ) )
+ return FALSE;
+
+ account_number = gsb_account_get_combo_account_number ( combo );
+ bet_use_budget = gsb_data_account_get_bet_use_budget ( account_number );
+
+ switch ( bet_use_budget )
+ {
+ case -1:
+ gtk_widget_set_sensitive ( widget, FALSE );
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( widget ), FALSE );
+ bet_config_sensitive_account_parameters ( account_number, FALSE );
+ return FALSE;
+ break;
+ case 0:
+ gtk_widget_set_sensitive ( widget, TRUE );
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( widget ), FALSE );
+ bet_config_sensitive_account_parameters ( account_number, FALSE );
+ return FALSE;
+ break;
+ case 1:
+ gtk_widget_set_sensitive ( widget, TRUE );
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( widget ), TRUE );
+ bet_config_sensitive_account_parameters ( account_number, TRUE );
+ break;
+ }
+
+ kind = gsb_data_account_get_kind ( account_number );
+ notebook = g_object_get_data ( G_OBJECT ( account_page ), "config_notebook" );
+ switch ( kind )
+ {
+ case GSB_TYPE_BANK:
+ gtk_notebook_set_current_page ( GTK_NOTEBOOK ( notebook ), 0 );
+ bet_config_initialise_duration_widget ( account_number, account_page );
+ bet_config_initialise_select_historical_data ( account_number, account_page );
+ break;
+ case GSB_TYPE_CASH:
+ gtk_notebook_set_current_page ( GTK_NOTEBOOK ( notebook ), 0 );
+ bet_config_initialise_select_historical_data ( account_number, account_page );
+ break;
+ case GSB_TYPE_LIABILITIES:
+ gtk_notebook_set_current_page ( GTK_NOTEBOOK ( notebook ), 1 );
+ break;
+ case GSB_TYPE_ASSET:
+ break;
+ }
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gint bet_config_get_account_from_combo ( void )
+{
+ GtkWidget *combo;
+ gint account_number = -1;
+
+ combo = g_object_get_data ( G_OBJECT ( account_page ), "account_combo" );
+ account_number = gsb_account_get_combo_account_number ( combo );
+
+ return account_number;
+}
+
+
+/**
+ * called for a change in automem_radiobutton3
+ *
+ * \param checkbutton the button wich changed
+ * \param value_ptr a gint* wich is the value to set in the memory (0, 1 or 2)
+ *
+ * \return FALSE
+ * */
+gboolean bet_config_select_label_changed ( GtkWidget *checkbutton,
+ gpointer data )
+{
+ gint value;
+ gint origine;
+ gint account_number;
+
+ devel_debug (NULL);
+
+ /* we are on the active button, so save the value for it */
+ value = GPOINTER_TO_INT ( g_object_get_data ( G_OBJECT ( checkbutton ), "pointer" ) );
+ origine = GPOINTER_TO_INT ( data );
+ account_number = bet_config_get_account_from_combo ( );
+
+ gsb_data_account_set_bet_select_label ( account_number, origine, value );
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ bet_data_update_bet_module ( account_number, -1 );
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_config_sensitive_account_parameters ( gint account_number, gboolean sensitive )
+{
+ GtkWidget *widget = NULL;
+
+ if ( sensitive )
+ {
+ kind_account kind;
+
+ kind = gsb_data_account_get_kind ( account_number );
+ switch ( kind )
+ {
+ case GSB_TYPE_BANK:
+ widget = g_object_get_data ( G_OBJECT ( account_page ), "Data_for_forecast" );
+ gtk_widget_show_all ( widget );
+ widget = g_object_get_data ( G_OBJECT ( account_page ), "Data_for_historical" );
+ gtk_widget_show_all ( widget );
+ break;
+ case GSB_TYPE_CASH:
+ widget = g_object_get_data ( G_OBJECT ( account_page ), "Data_for_forecast" );
+ gtk_widget_hide_all ( widget );
+ widget = g_object_get_data ( G_OBJECT ( account_page ), "Data_for_historical" );
+ gtk_widget_show_all ( widget );
+ break;
+ case GSB_TYPE_LIABILITIES:
+ break;
+ case GSB_TYPE_ASSET:
+ break;
+ }
+ }
+ else
+ {
+ widget = g_object_get_data ( G_OBJECT ( account_page ), "Data_for_forecast" );
+ gtk_widget_hide_all ( widget );
+ widget = g_object_get_data ( G_OBJECT ( account_page ), "Data_for_historical" );
+ gtk_widget_hide_all ( widget );
+ }
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_config_use_budget_toggle ( GtkToggleButton *button, GtkWidget *combo )
+{
+ GtkWidget *widget;
+ gint account_number;
+
+ account_number = gsb_account_get_combo_account_number ( combo );
+
+ if ( gtk_toggle_button_get_active ( button ) )
+ {
+ gsb_data_account_set_bet_use_budget ( account_number, 1 );
+ bet_config_change_account ( combo );
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ALL );
+ }
+ else
+ {
+ bet_data_remove_all_bet_data ( account_number );
+ gsb_data_account_set_bet_use_budget ( account_number, 0 );
+ widget = g_object_get_data ( G_OBJECT ( account_page ), "Data_for_forecast" );
+ gtk_widget_hide_all ( widget );
+ widget = g_object_get_data ( G_OBJECT ( account_page ), "Data_for_historical" );
+ gtk_widget_hide_all ( widget );
+ }
+
+ if ( gsb_gui_navigation_get_current_account ( ) == account_number )
+ bet_data_select_bet_pages ( account_number );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+/* Local Variables: */
+/* c-basic-offset: 4 */
+/* End: */
diff --git a/src/bet_data.c b/src/bet_data.c
new file mode 100644
index 0000000..99dafea
--- /dev/null
+++ b/src/bet_data.c
@@ -0,0 +1,1812 @@
+/* ************************************************************************** */
+/* */
+/* Copyright (C) 2007 Dominique Parisot */
+/* zionly at free.org */
+/* 2008-2010 Pierre Biava (grisbi at pierre.biava.name) */
+/* 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 */
+/* the Free Software Foundation; either version 2 of the License, or */
+/* (at your option) any later version. */
+/* */
+/* This program is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
+/* GNU General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU General Public License */
+/* along with this program; if not, write to the Free Software */
+/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+/* */
+/* ************************************************************************** */
+
+/* ./configure --with-balance-estimate */
+
+#include "include.h"
+#include <config.h>
+
+/*START_INCLUDE*/
+#include "bet_data.h"
+#include "bet_hist.h"
+#include "bet_tab.h"
+#include "dialog.h"
+#include "gsb_data_account.h"
+#include "gsb_data_budget.h"
+#include "gsb_data_category.h"
+#include "gsb_data_mix.h"
+#include "gsb_data_transaction.h"
+#include "utils_dates.h"
+#include "navigation.h"
+#include "gsb_real.h"
+#include "traitement_variables.h"
+#include "gsb_file_save.h"
+#include "utils_str.h"
+#include "gsb_data_account.h"
+#include "gsb_scheduler_list.h"
+#include "erreur.h"
+#include "structures.h"
+/*END_INCLUDE*/
+
+
+/*START_STATIC*/
+static GDate *bet_data_futur_get_next_date ( struct_futur_data *scheduled,
+ const GDate *date,
+ const GDate *date_max );
+static struct_futur_data *bet_data_future_copy_struct ( struct_futur_data *scheduled );
+static void bet_data_future_set_max_number ( gint number );
+static gboolean bet_data_update_div ( SH *sh, gint transaction_number, gint sub_div );
+static void struct_free_bet_future ( struct_futur_data *scheduled );
+static void struct_free_bet_range ( SBR *sbr );
+static void struct_free_bet_transfert ( struct_transfert_data *transfert );
+static void struct_free_hist_div ( struct_hist_div *shd );
+static SH *struct_initialise_bet_historical ( void );
+/*END_STATIC*/
+
+
+/*START_EXTERN*/
+extern GtkWidget *account_page;
+extern GtkWidget *notebook_general;
+extern gsb_real null_real;
+/*END_EXTERN*/
+
+
+/* pointeurs définis en fonction du type de données catégories ou IB */
+gint (*ptr_div) ( gint transaction_num, gboolean is_transaction );
+gint (*ptr_sub_div) ( gint transaction_num, gboolean is_transaction );
+gchar* (*ptr_div_name) ( gint div_num, gint sub_div, const gchar *return_value_error );
+
+
+/* liste des div et sub_div cochées dans la vue des divisions */
+static GHashTable *bet_hist_div_list;
+
+/** the hashtable which contains all the bet_future structures */
+static GHashTable *bet_future_list;
+static gint future_number;
+
+/** the hashtable for account_balance */
+static GHashTable *bet_transfert_list;
+static gint transfert_number;
+
+
+/**
+ * Sélectionne les onglets du module gestion budgétaire en fonction du type de compte
+ *
+ */
+void bet_data_select_bet_pages ( gint account_number )
+{
+ GtkWidget *page;
+ GtkWidget *tree_view;
+ kind_account kind;
+ gint current_page;
+ gint bet_use_budget;
+
+ devel_debug_int ( account_number );
+
+ kind = gsb_data_account_get_kind ( account_number );
+ current_page = gtk_notebook_get_current_page ( GTK_NOTEBOOK ( account_page ) );
+ bet_use_budget = gsb_data_account_get_bet_use_budget ( account_number );
+ if ( bet_use_budget <= 0 )
+ kind = GSB_TYPE_ASSET;
+
+ tree_view = g_object_get_data ( G_OBJECT ( account_page ), "bet_estimate_treeview" );
+
+ switch ( kind )
+ {
+ case GSB_TYPE_BANK:
+ page = gtk_notebook_get_nth_page ( GTK_NOTEBOOK ( account_page ), GSB_ESTIMATE_PAGE );
+ gtk_widget_show ( page );
+ bet_array_list_select_path ( tree_view, NULL );
+ page = gtk_notebook_get_nth_page ( GTK_NOTEBOOK ( account_page ), GSB_HISTORICAL_PAGE );
+ gtk_widget_show ( page );
+ bet_historical_g_signal_unblock_tree_view ( );
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ALL );
+ if ( current_page < GSB_PROPERTIES_PAGE
+ &&
+ gsb_data_account_get_bet_use_budget ( account_number ) == FALSE )
+ gtk_notebook_set_current_page ( GTK_NOTEBOOK ( account_page ), GSB_TRANSACTIONS_PAGE );
+ break;
+ case GSB_TYPE_CASH:
+ page = gtk_notebook_get_nth_page ( GTK_NOTEBOOK ( account_page ), GSB_ESTIMATE_PAGE );
+ gtk_widget_hide ( page );
+ page = gtk_notebook_get_nth_page ( GTK_NOTEBOOK ( account_page ), GSB_HISTORICAL_PAGE );
+ gtk_widget_show ( page );
+ if ( current_page == GSB_ESTIMATE_PAGE )
+ gtk_notebook_set_current_page ( GTK_NOTEBOOK ( account_page ), GSB_HISTORICAL_PAGE );
+ bet_historical_g_signal_block_tree_view ( );
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_HISTORICAL );
+ break;
+ case GSB_TYPE_LIABILITIES:
+ page = gtk_notebook_get_nth_page ( GTK_NOTEBOOK ( account_page ), GSB_ESTIMATE_PAGE );
+ gtk_widget_show ( page );
+ bet_array_list_select_path ( tree_view, NULL );
+ if ( current_page == GSB_HISTORICAL_PAGE )
+ gtk_notebook_set_current_page ( GTK_NOTEBOOK ( account_page ), GSB_ESTIMATE_PAGE );
+ page = gtk_notebook_get_nth_page ( GTK_NOTEBOOK ( account_page ), GSB_HISTORICAL_PAGE );
+ gtk_widget_hide ( page );
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ break;
+ case GSB_TYPE_ASSET:
+ if ( current_page < GSB_PROPERTIES_PAGE )
+ gtk_notebook_set_current_page ( GTK_NOTEBOOK ( account_page ), GSB_TRANSACTIONS_PAGE );
+ page = gtk_notebook_get_nth_page ( GTK_NOTEBOOK ( account_page ), GSB_ESTIMATE_PAGE );
+ gtk_widget_hide ( page );
+ page = gtk_notebook_get_nth_page ( GTK_NOTEBOOK ( account_page ), GSB_HISTORICAL_PAGE );
+ gtk_widget_hide ( page );
+ break;
+ }
+}
+
+
+/*
+ * Met à jour les données à afficher dans les différentes vues du module
+ *
+ *
+ */
+void bet_data_update_bet_module ( gint account_number, guint page )
+{
+ gint type_maj;
+ kind_account kind;
+
+ devel_debug_int ( account_number );
+
+ /* test account number */
+ if ( account_number == -1 )
+ return;
+
+ type_maj = gsb_data_account_get_bet_maj ( account_number );
+ if ( type_maj == BET_MAJ_FALSE )
+ return;
+
+ kind = gsb_data_account_get_kind ( account_number );
+
+
+ if ( page == -1 && gsb_gui_navigation_get_current_page ( ) == GSB_ACCOUNT_PAGE )
+ page = gtk_notebook_get_current_page ( GTK_NOTEBOOK ( account_page ) );
+
+ switch ( page )
+ {
+ case GSB_ESTIMATE_PAGE:
+ bet_array_update_estimate_tab ( account_number, type_maj );
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_FALSE );
+ break;
+ case GSB_HISTORICAL_PAGE:
+ if ( type_maj == BET_MAJ_ALL )
+ {
+ bet_historical_populate_data ( account_number );
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ }
+ else if ( type_maj == BET_MAJ_HISTORICAL )
+ {
+ bet_historical_populate_data ( account_number );
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_FALSE );
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+
+/**
+ * used when we init all the global variables
+ *
+ * \param
+ *
+ * \return FALSE
+ * */
+gboolean bet_data_init_variables ( void )
+{
+ bet_hist_div_list = g_hash_table_new_full ( g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) struct_free_hist_div );
+ bet_future_list = g_hash_table_new_full ( g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) struct_free_bet_future );
+ future_number = 0;
+
+ bet_transfert_list = g_hash_table_new_full ( g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) struct_free_bet_transfert );
+ transfert_number = 0;
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_data_hist_add_div ( gint account_nb,
+ gint div_number,
+ gint sub_div_nb )
+{
+ gchar *key;
+ gchar *sub_key;
+ struct_hist_div *shd;
+
+ if ( account_nb == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( account_nb ), ":",
+ utils_str_itoa ( div_number ), NULL );
+
+ if ( ( shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) )
+ {
+ shd -> div_edited = FALSE;
+ shd -> amount = null_real;
+
+ if ( sub_div_nb > 0 )
+ {
+ sub_key = utils_str_itoa ( sub_div_nb );
+ if ( !g_hash_table_lookup ( shd -> sub_div_list, sub_key ) )
+ {
+ struct_hist_div *sub_shd;
+
+ sub_shd = struct_initialise_hist_div ( );
+ if ( !sub_shd )
+ {
+ dialogue_error_memory ( );
+ return FALSE;
+ }
+ sub_shd -> div_number = sub_div_nb;
+ g_hash_table_insert ( shd -> sub_div_list, sub_key, sub_shd );
+ }
+ else
+ {
+ shd -> div_edited = FALSE;
+ shd -> amount = null_real;
+ }
+ }
+ }
+ else
+ {
+ shd = struct_initialise_hist_div ( );
+ if ( !shd )
+ {
+ dialogue_error_memory ( );
+ return 0;
+ }
+ shd -> account_nb = account_nb;
+ shd -> div_number = div_number;
+ if ( sub_div_nb > 0 )
+ {
+ struct_hist_div *sub_shd;
+
+ sub_shd = struct_initialise_hist_div ( );
+ if ( !sub_shd )
+ {
+ dialogue_error_memory ( );
+ return FALSE;
+ }
+ sub_key = utils_str_itoa ( sub_div_nb );
+ sub_shd -> div_number = sub_div_nb;
+ g_hash_table_insert ( shd -> sub_div_list, sub_key, sub_shd );
+ }
+ g_hash_table_insert ( bet_hist_div_list, key, shd );
+ }
+
+ return TRUE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_data_insert_div_hist ( struct_hist_div *shd, struct_hist_div *sub_shd )
+{
+ gchar *key;
+ gchar *sub_key;
+ struct_hist_div *tmp_shd;
+
+ if ( shd -> account_nb == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( shd -> div_number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( shd -> account_nb ), ":",
+ utils_str_itoa ( shd -> div_number ), NULL );
+
+ if ( ( tmp_shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) )
+ {
+ tmp_shd -> div_edited = shd -> div_edited;
+ tmp_shd -> amount = shd -> amount;
+
+ if ( sub_shd )
+ {
+ sub_key = utils_str_itoa ( sub_shd -> div_number );
+ g_hash_table_insert ( tmp_shd -> sub_div_list, sub_key, sub_shd );
+ }
+ }
+ else
+ {
+ if ( sub_shd )
+ {
+ sub_key = utils_str_itoa ( sub_shd -> div_number );
+ g_hash_table_insert ( shd -> sub_div_list, sub_key, sub_shd );
+ }
+ g_hash_table_insert ( bet_hist_div_list, key, shd );
+ }
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_data_remove_div_hist ( gint account_nb, gint div_number, gint sub_div_nb )
+{
+ gchar *key;
+ char *sub_key;
+ struct_hist_div *shd;
+
+ if ( account_nb == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( account_nb ), ":",
+ utils_str_itoa ( div_number ), NULL );
+
+ if ( ( shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) )
+ {
+ if ( sub_div_nb > 0 )
+ {
+ sub_key = utils_str_itoa ( sub_div_nb );
+ g_hash_table_remove ( shd -> sub_div_list, sub_key );
+ }
+ if ( g_hash_table_size ( shd -> sub_div_list ) == 0 )
+ g_hash_table_remove ( bet_hist_div_list, key );
+ }
+ else
+ return FALSE;
+
+ return TRUE;
+}
+
+
+/**
+ * return TRUE si la division et sous division existe.
+ *
+ *
+ *
+ * */
+gboolean bet_data_search_div_hist ( gint account_nb, gint div_number, gint sub_div_nb )
+{
+ gchar *key;
+ gchar *sub_key;
+ struct_hist_div *shd;
+
+ if ( account_nb == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( account_nb ), ":",
+ utils_str_itoa ( div_number ), NULL );
+
+ if ( ( shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) )
+ {
+ if ( sub_div_nb == 0 )
+ {
+ g_free ( key );
+ return TRUE;
+ }
+ else if ( sub_div_nb > 0 );
+ {
+ sub_key = utils_str_itoa ( sub_div_nb );
+ if ( g_hash_table_lookup ( shd -> sub_div_list, sub_key ) )
+ {
+ g_free ( key );
+ g_free ( sub_key );
+ return TRUE;
+ }
+ g_free ( sub_key );
+ }
+ }
+
+ g_free ( key );
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_data_set_div_ptr ( gint type_div )
+{
+ if ( type_div == 0 )
+ {
+ ptr_div = &gsb_data_mix_get_category_number;
+ ptr_sub_div = &gsb_data_mix_get_sub_category_number;
+ ptr_div_name = &gsb_data_category_get_name;
+ }
+ else
+ {
+ ptr_div = &gsb_data_mix_get_budgetary_number;
+ ptr_sub_div = &gsb_data_mix_get_sub_budgetary_number;
+ ptr_div_name = &gsb_data_budget_get_name;
+ }
+
+ return FALSE;
+}
+/**
+ *
+ *
+ *
+ *
+ * */
+gint bet_data_get_div_number ( gint transaction_number, gboolean is_transaction )
+{
+ return ptr_div ( transaction_number, is_transaction );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gint bet_data_get_sub_div_nb ( gint transaction_number, gboolean is_transaction )
+{
+ return ptr_sub_div ( transaction_number, is_transaction );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gchar *bet_data_get_div_name ( gint div_num,
+ gint sub_div,
+ const gchar *return_value_error )
+{
+ return g_strdup ( ptr_div_name ( div_num, sub_div, NULL ) );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_data_get_div_edited ( gint account_nb, gint div_number, gint sub_div_nb )
+{
+ gchar *key;
+ struct_hist_div *shd;
+ gboolean edited;
+
+ if ( account_nb == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( account_nb ), ":",
+ utils_str_itoa ( div_number ), NULL );
+
+ if ( ( shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) )
+ {
+ if ( sub_div_nb == 0 )
+ edited = shd -> div_edited;
+ else
+ {
+ gchar *sub_key;
+ struct_hist_div *sub_shd;
+
+ sub_key = utils_str_itoa ( sub_div_nb );
+ if ( ( sub_shd = g_hash_table_lookup ( shd -> sub_div_list, sub_key ) ) )
+ edited = sub_shd -> div_edited;
+ else
+ edited = FALSE;
+ g_free ( sub_key );
+ }
+ }
+ else
+ edited = FALSE;
+ g_free ( key );
+
+ return edited;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_data_set_div_edited ( gint account_nb,
+ gint div_number,
+ gint sub_div_nb,
+ gboolean edited )
+{
+ gchar *key;
+ struct_hist_div *shd;
+
+ if ( account_nb == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( account_nb ), ":",
+ utils_str_itoa ( div_number ), NULL );
+
+ if ( ( shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) )
+ {
+ if ( sub_div_nb == 0 )
+ shd -> div_edited = edited;
+ else
+ {
+ gchar *sub_key;
+ struct_hist_div *sub_shd;
+
+ sub_key = utils_str_itoa ( sub_div_nb );
+ if ( ( sub_shd = g_hash_table_lookup ( shd -> sub_div_list, sub_key ) ) )
+ sub_shd -> div_edited = edited;
+ g_free ( sub_key );
+ }
+ }
+
+ g_free ( key );
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gsb_real bet_data_hist_get_div_amount ( gint account_nb, gint div_number, gint sub_div_nb )
+{
+ gchar *key;
+ struct_hist_div *shd;
+ gsb_real amount;
+
+ if ( account_nb == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( account_nb ), ":",
+ utils_str_itoa ( div_number ), NULL );
+
+ if ( ( shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) )
+ {
+ if ( sub_div_nb == 0 )
+ amount = shd -> amount;
+ else
+ {
+ gchar *sub_key;
+ struct_hist_div *sub_shd;
+
+ sub_key = utils_str_itoa ( sub_div_nb );
+ if ( ( sub_shd = g_hash_table_lookup ( shd -> sub_div_list, sub_key ) ) )
+ amount = sub_shd -> amount;
+ else
+ amount = null_real;
+ g_free ( sub_key );
+ }
+ }
+ else
+ amount = null_real;
+ g_free ( key );
+
+ return amount;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_data_set_div_amount ( gint account_nb,
+ gint div_number,
+ gint sub_div_nb,
+ gsb_real amount )
+{
+ gchar *key;
+ struct_hist_div *shd;
+
+ if ( account_nb == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( account_nb ), ":",
+ utils_str_itoa ( div_number ), NULL );
+
+ if ( ( shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) )
+ {
+ if ( sub_div_nb == 0 )
+ shd -> amount = amount;
+ else
+ {
+ gchar *sub_key;
+ struct_hist_div *sub_shd;
+
+ sub_key = utils_str_itoa ( sub_div_nb );
+ if ( ( sub_shd = g_hash_table_lookup ( shd -> sub_div_list, sub_key ) ) )
+ sub_shd -> amount = amount;
+ g_free ( sub_key );
+ }
+ }
+
+ g_free ( key );
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gint bet_data_get_selected_currency ( void )
+{
+ gint selected_account;
+ gint currency_number;
+
+ selected_account = gsb_gui_navigation_get_current_account ( );
+ if ( selected_account == -1 )
+ return 0;
+
+ currency_number = gsb_data_account_get_currency ( selected_account );
+
+ return currency_number;
+}
+
+
+/**
+ * Ajoute les données de la transaction à la division et la sous division
+ * création des nouvelles divisions et si existantes ajout des données
+ * par appel à bet_data_update_div ( )
+ *
+ * */
+gboolean bet_data_populate_div ( gint transaction_number,
+ gboolean is_transaction,
+ GHashTable *list_div )
+{
+ gint div = 0;
+ gint sub_div = 0;
+ SH *sh = NULL;
+
+ div = ptr_div ( transaction_number, is_transaction );
+ if ( div > 0 )
+ sub_div = ptr_sub_div ( transaction_number, is_transaction );
+ else
+ return FALSE;
+
+ if ( (sh = g_hash_table_lookup ( list_div, utils_str_itoa ( div ) ) ) )
+ bet_data_update_div ( sh, transaction_number, sub_div );
+ else
+ {
+ sh = struct_initialise_bet_historical ( );
+ sh -> div = div;
+ sh -> account_nb = gsb_data_transaction_get_account_number ( transaction_number );
+ bet_data_update_div ( sh, transaction_number, sub_div );
+ g_hash_table_insert ( list_div, utils_str_itoa ( div ), sh );
+ }
+
+ return FALSE;
+}
+
+
+/**
+ * Ajout des données à la division et création de la sous division si elle
+ * n'existe pas.
+ *
+ *
+ * */
+gboolean bet_data_update_div ( SH *sh, gint transaction_number, gint sub_div )
+{
+ SBR *sbr = ( SBR*) sh -> sbr;
+ gsb_real amount;
+ SH *tmp_sh = NULL;
+
+ amount = gsb_data_transaction_get_amount ( transaction_number );
+ sbr-> current_balance = gsb_real_add ( sbr -> current_balance, amount );
+
+ if ( sub_div < 1 )
+ return FALSE;
+
+ if ( ( tmp_sh = g_hash_table_lookup ( sh -> list_sub_div, utils_str_itoa ( sub_div ) ) ) )
+ bet_data_update_div ( tmp_sh, transaction_number, -1 );
+ else
+ {
+ tmp_sh = struct_initialise_bet_historical ( );
+ tmp_sh -> div = sub_div;
+ tmp_sh -> account_nb = gsb_data_transaction_get_account_number ( transaction_number );
+ bet_data_update_div ( tmp_sh, transaction_number, -1 );
+ g_hash_table_insert ( sh -> list_sub_div, utils_str_itoa ( sub_div ), tmp_sh );
+ }
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+GPtrArray *bet_data_get_strings_to_save ( void )
+{
+ GPtrArray *tab = NULL;
+ gchar *tmp_str = NULL;
+ GHashTableIter iter;
+ gpointer key, value;
+ gint index = 0;
+
+ if ( g_hash_table_size ( bet_hist_div_list ) == 0
+ &&
+ g_hash_table_size ( bet_future_list ) == 0
+ &&
+ g_hash_table_size ( bet_transfert_list ) == 0 )
+ return NULL;
+
+ tab = g_ptr_array_new ( );
+
+ g_hash_table_iter_init ( &iter, bet_hist_div_list );
+ while ( g_hash_table_iter_next ( &iter, &key, &value ) )
+ {
+ struct_hist_div *shd = ( struct_hist_div* ) value;
+
+ if ( g_hash_table_size ( shd -> sub_div_list ) == 0 )
+ {
+ tmp_str = g_markup_printf_escaped ( "\t<Bet_historical Nb=\"%d\" Ac=\"%d\" "
+ "Div=\"%d\" Edit=\"%d\" Damount=\"%s\" SDiv=\"%d\" "
+ "SEdit=\"%d\" SDamount=\"%s\" />\n",
+ tab -> len + 1,
+ shd -> account_nb,
+ shd -> div_number,
+ shd -> div_edited,
+ gsb_real_save_real_to_string ( shd -> amount, 2 ),
+ 0, 0, "0.00" );
+
+ g_ptr_array_add ( tab, tmp_str );
+ }
+ else
+ {
+ GHashTableIter new_iter;
+
+ g_hash_table_iter_init ( &new_iter, shd -> sub_div_list );
+ while ( g_hash_table_iter_next ( &new_iter, &key, &value ) )
+ {
+ struct_hist_div *sub_shd = ( struct_hist_div* ) value;
+
+ tmp_str = g_markup_printf_escaped ( "\t<Bet_historical Nb=\"%d\" Ac=\"%d\" "
+ "Div=\"%d\" Edit=\"%d\" Damount=\"%s\" SDiv=\"%d\" "
+ "SEdit=\"%d\" SDamount=\"%s\" />\n",
+ tab -> len + 1,
+ shd -> account_nb,
+ shd -> div_number,
+ shd -> div_edited,
+ gsb_real_save_real_to_string ( shd -> amount, 2 ),
+ sub_shd -> div_number,
+ sub_shd -> div_edited,
+ gsb_real_save_real_to_string ( sub_shd -> amount, 2 ) );
+
+ g_ptr_array_add ( tab, tmp_str );
+ }
+ }
+ }
+
+ g_hash_table_iter_init ( &iter, bet_future_list );
+ while ( g_hash_table_iter_next ( &iter, &key, &value ) )
+ {
+ struct_futur_data *scheduled = ( struct_futur_data* ) value;
+ gchar *amount;
+ gchar *date;
+ gchar *limit_date;
+
+ /* set the real */
+ amount = gsb_real_save_real_to_string ( scheduled -> amount, 2 );
+
+ /* set the dates */
+ date = gsb_format_gdate_safe ( scheduled -> date );
+ limit_date = gsb_format_gdate_safe ( scheduled -> limit_date );
+
+ tmp_str = g_markup_printf_escaped ( "\t<Bet_future Nb=\"%d\" Dt=\"%s\" Ac=\"%d\" "
+ "Am=\"%s\" Pa=\"%d\" IsT=\"%d\" Tra=\"%d\" Ca=\"%d\" Sca=\"%d\" "
+ "Pn=\"%d\" Fi=\"%d\" Bu=\"%d\" Sbu=\"%d\" No=\"%s\" Au=\"0\" "
+ "Pe=\"%d\" Pei=\"%d\" Pep=\"%d\" Dtl=\"%s\" Mo=\"%d\" />\n",
+ scheduled -> number,
+ my_safe_null_str ( date ),
+ scheduled -> account_number,
+ my_safe_null_str ( amount ),
+ scheduled -> party_number,
+ scheduled -> is_transfert,
+ scheduled -> account_transfert,
+ scheduled -> category_number,
+ scheduled -> sub_category_number,
+ scheduled -> payment_number,
+ scheduled -> fyear_number,
+ scheduled -> budgetary_number,
+ scheduled -> sub_budgetary_number,
+ my_safe_null_str ( scheduled -> notes ),
+ scheduled -> frequency,
+ scheduled -> user_interval,
+ scheduled -> user_entry,
+ my_safe_null_str ( limit_date ),
+ scheduled -> mother_row );
+
+ g_ptr_array_add ( tab, tmp_str );
+
+ g_free (amount);
+ g_free (date);
+ g_free (limit_date);
+ }
+
+ g_hash_table_iter_init ( &iter, bet_transfert_list );
+ index = 0;
+ while ( g_hash_table_iter_next ( &iter, &key, &value ) )
+ {
+ struct_transfert_data *transfert = ( struct_transfert_data* ) value;
+ gchar *date;
+
+ /* set the dates */
+ date = gsb_format_gdate_safe ( transfert -> date );
+
+ tmp_str = g_markup_printf_escaped ( "\t<Bet_transfert Nb=\"%d\" Dt=\"%s\" Ac=\"%d\" "
+ "Ty=\"%d\" Ra=\"%d\" Rt=\"%d\" Aim=\"%d\" Ca=\"%d\" Sca=\"%d\" "
+ "Bu=\"%d\" Sbu=\"%d\" />\n",
+ ++index,
+ my_safe_null_str ( date ),
+ transfert -> account_number,
+ transfert -> type,
+ transfert -> replace_account,
+ transfert -> replace_transaction,
+ transfert -> auto_inc_month,
+ transfert -> category_number,
+ transfert -> sub_category_number,
+ transfert -> budgetary_number,
+ transfert -> sub_budgetary_number );
+
+ g_ptr_array_add ( tab, tmp_str );
+
+ g_free (date);
+ }
+
+ return tab;
+}
+
+
+/**
+ * supprime de la liste bet_hist_div_list les divisions sous divisions
+ * inexistantes dans list_div.
+ *
+ *
+ * */
+void bet_data_synchronise_hist_div_list ( GHashTable *list_div )
+{
+ GHashTableIter iter;
+ gpointer key, value;
+ SH *sh = NULL;
+
+ g_hash_table_iter_init ( &iter, bet_hist_div_list );
+ while ( g_hash_table_iter_next ( &iter, &key, &value ) )
+ {
+ struct_hist_div *shd = ( struct_hist_div* ) value;
+ GHashTableIter new_iter;
+
+ sh = g_hash_table_lookup ( list_div, utils_str_itoa ( shd -> div_number ) );
+ if ( sh == NULL )
+ bet_data_remove_div_hist ( shd -> account_nb, shd -> div_number, 0 );
+ else
+ {
+ g_hash_table_iter_init ( &new_iter, shd -> sub_div_list );
+ while ( g_hash_table_iter_next ( &new_iter, &key, &value ) )
+ {
+ struct_hist_div *sub_shd = ( struct_hist_div* ) value;
+
+ if ( !g_hash_table_lookup ( sh -> list_sub_div, utils_str_itoa (
+ sub_shd -> div_number ) ) )
+ {
+ bet_data_remove_div_hist ( shd -> account_nb,
+ shd -> div_number,
+ sub_shd -> div_number );
+ g_hash_table_iter_init ( &new_iter, shd -> sub_div_list );
+ }
+ }
+ }
+ }
+}
+/**
+ *
+ *
+ *
+ *
+ * */
+SBR *struct_initialise_bet_range ( void )
+{
+ SBR *sbr;
+
+ sbr = g_malloc0 ( sizeof ( SBR ) );
+ sbr -> first_pass = TRUE;
+ sbr -> min_date = NULL;
+ sbr -> max_date = NULL;
+ sbr -> min_balance = null_real;
+ sbr -> max_balance = null_real;
+ sbr -> current_balance = null_real;
+
+ return sbr;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void struct_free_bet_range ( SBR *sbr )
+{
+ if ( sbr-> min_date )
+ g_date_free ( sbr-> min_date );
+ if ( sbr-> max_date )
+ g_date_free ( sbr-> max_date );
+
+ g_free ( sbr );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+SH *struct_initialise_bet_historical ( void )
+{
+ SH *sh;
+
+ sh = g_malloc0 ( sizeof ( SH ) );
+ sh -> sbr = struct_initialise_bet_range ( );
+ sh -> list_sub_div = g_hash_table_new_full ( g_str_hash,
+ g_str_equal,
+ NULL,
+ (GDestroyNotify) struct_free_bet_historical );
+ return sh;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void struct_free_bet_historical ( SH *sh )
+{
+
+ if ( sh -> sbr )
+ struct_free_bet_range ( sh -> sbr );
+ if ( sh -> list_sub_div )
+ g_hash_table_remove_all ( sh -> list_sub_div );
+
+ g_free ( sh );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+struct_hist_div *struct_initialise_hist_div ( void )
+{
+ struct_hist_div *shd;
+
+ shd = g_malloc0 ( sizeof ( struct_hist_div ) );
+ shd -> account_nb = 0;
+ shd -> div_number = 0;
+ shd -> div_edited = FALSE;
+ shd -> amount = null_real;
+ shd -> sub_div_list = g_hash_table_new_full ( g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) struct_free_hist_div );
+
+ return shd;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void struct_free_hist_div ( struct_hist_div *shd )
+{
+ if ( shd -> sub_div_list )
+ g_hash_table_remove_all ( shd -> sub_div_list );
+
+ g_free ( shd );
+}
+
+/**
+ *
+ *
+ *
+ *
+ * */
+struct_futur_data *struct_initialise_bet_future ( void )
+{
+ struct_futur_data *sfd;
+
+ sfd = g_malloc0 ( sizeof ( struct_futur_data ) );
+
+ sfd -> date = NULL;
+ sfd -> amount = null_real;
+ sfd -> notes = NULL;
+ sfd -> limit_date = NULL;
+
+ return sfd;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void struct_free_bet_future ( struct_futur_data *scheduled )
+{
+ if ( scheduled -> date )
+ g_date_free ( scheduled -> date );
+ if ( scheduled -> limit_date )
+ g_date_free ( scheduled -> limit_date );
+ if ( scheduled -> notes )
+ g_free ( scheduled -> notes );
+
+ g_free ( scheduled );
+}
+
+
+/**
+ * add lines creates in the bet_future_list
+ *
+ *
+ *
+ * */
+gboolean bet_data_future_add_lines ( struct_futur_data *scheduled )
+{
+ gchar *key;
+
+ future_number ++;
+
+ if ( scheduled -> frequency == 0 )
+ {
+ if ( scheduled -> account_number == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( future_number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( scheduled -> account_number ), ":",
+ utils_str_itoa ( future_number ), NULL );
+
+ scheduled -> number = future_number;
+ g_hash_table_insert ( bet_future_list, key, scheduled );
+ }
+ else
+ {
+ GDate *date;
+ GDate *date_max;
+ gint mother_row;
+ struct_futur_data *new_sch = NULL;
+
+ mother_row = future_number;
+
+ date_max = bet_data_array_get_date_max ( scheduled -> account_number );
+
+ /* we don't change the initial date */
+ date = gsb_date_copy ( scheduled -> date );
+ while ( date != NULL && g_date_valid ( date ) )
+ {
+ if ( scheduled -> account_number == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( future_number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( scheduled -> account_number ), ":",
+ utils_str_itoa ( future_number ), NULL );
+
+ if ( mother_row == future_number )
+ new_sch = scheduled;
+ else
+ new_sch -> mother_row = mother_row;
+
+ new_sch -> number = future_number;
+ g_hash_table_insert ( bet_future_list, key, new_sch );
+
+ date = bet_data_futur_get_next_date ( new_sch, date, date_max );
+ if ( date == NULL )
+ break;
+ future_number ++;
+ new_sch = bet_data_future_copy_struct ( scheduled );
+ new_sch -> date = date;
+ }
+ g_date_free ( date_max );
+ }
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+
+ return TRUE;
+}
+
+
+/**
+ * add lines from file
+ *
+ *
+ *
+ * */
+gboolean bet_data_future_set_lines_from_file ( struct_futur_data *scheduled )
+{
+ gchar *key;
+
+ if ( scheduled -> account_number == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( scheduled -> number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( scheduled -> account_number ), ":",
+ utils_str_itoa ( scheduled -> number ), NULL );
+
+ bet_data_future_set_max_number ( scheduled -> number );
+
+ g_hash_table_insert ( bet_future_list, key, scheduled );
+
+ return TRUE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_data_future_set_max_number ( gint number )
+{
+ if ( number > future_number )
+ future_number = number;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+GHashTable *bet_data_future_get_list ( void )
+{
+ return bet_future_list;
+}
+
+
+/**
+ * find and return the next date after the given date for the given futur data
+ *
+ *
+ * \param struct_futur_data
+ * \param date the current date, we want the next one after that one
+ *
+ * \return a newly allocated date, the next date or NULL if over the limit
+ * */
+GDate *bet_data_futur_get_next_date ( struct_futur_data *scheduled,
+ const GDate *date,
+ const GDate *date_max )
+{
+ GDate *return_date;
+
+ if ( !scheduled
+ ||
+ !scheduled -> frequency
+ ||
+ !date
+ ||
+ !g_date_valid ( date ) )
+ return NULL;
+
+ /* we don't change the initial date */
+ return_date = gsb_date_copy (date);
+
+ switch ( scheduled -> frequency )
+ {
+ case SCHEDULER_PERIODICITY_ONCE_VIEW:
+ return NULL;
+ break;
+
+ case SCHEDULER_PERIODICITY_WEEK_VIEW:
+ g_date_add_days ( return_date, 7 );
+ break;
+
+ case SCHEDULER_PERIODICITY_MONTH_VIEW:
+ g_date_add_months ( return_date, 1 );
+ break;
+
+ case SCHEDULER_PERIODICITY_TWO_MONTHS_VIEW:
+ g_date_add_months ( return_date, 2 );
+ break;
+
+ case SCHEDULER_PERIODICITY_TRIMESTER_VIEW:
+ g_date_add_months ( return_date, 3 );
+ break;
+
+ case SCHEDULER_PERIODICITY_YEAR_VIEW:
+ g_date_add_years ( return_date, 1 );
+ break;
+
+ case SCHEDULER_PERIODICITY_CUSTOM_VIEW:
+ if ( scheduled -> user_entry <= 0 )
+ {
+ g_date_free (return_date);
+ return NULL;
+ }
+
+ switch ( scheduled -> user_interval )
+ {
+ case PERIODICITY_DAYS:
+ g_date_add_days ( return_date, scheduled -> user_entry);
+ break;
+
+ case PERIODICITY_WEEKS:
+ g_date_add_days ( return_date, scheduled -> user_entry * 7 );
+ break;
+
+ case PERIODICITY_MONTHS:
+ g_date_add_months ( return_date, scheduled -> user_entry );
+ break;
+
+ case PERIODICITY_YEARS:
+ g_date_add_years ( return_date, scheduled -> user_entry );
+ break;
+ }
+ break;
+ }
+
+ if ( scheduled -> limit_date )
+ {
+
+ if ( g_date_compare ( return_date, scheduled -> limit_date ) > 0 )
+ {
+ g_date_free (return_date);
+ return_date = NULL;
+ }
+ }
+ else
+ {
+ if ( g_date_compare ( return_date, date_max ) > 0 )
+ {
+ g_date_free (return_date);
+ return_date = NULL;
+ }
+ }
+
+ return ( return_date );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+struct_futur_data *bet_data_future_copy_struct ( struct_futur_data *scheduled )
+{
+ struct_futur_data *new_scheduled;
+
+ new_scheduled = struct_initialise_bet_future ( );
+
+ if ( !new_scheduled )
+ {
+ dialogue_error_memory ();
+ return NULL;
+ }
+
+ new_scheduled -> number = scheduled -> number;
+ new_scheduled -> account_number = scheduled -> account_number;
+
+ if ( g_date_valid ( scheduled -> date ) )
+ new_scheduled -> date = gsb_date_copy ( scheduled -> date );
+ else
+ new_scheduled -> date = NULL;
+
+ new_scheduled -> amount = gsb_real_new ( scheduled -> amount.mantissa,
+ scheduled -> amount.exponent );
+ new_scheduled -> fyear_number = scheduled -> fyear_number;
+ new_scheduled -> payment_number = scheduled -> payment_number;
+
+ new_scheduled -> party_number = scheduled -> party_number;
+ new_scheduled -> is_transfert = scheduled -> is_transfert;
+ new_scheduled -> account_transfert = scheduled -> account_transfert;
+ new_scheduled -> category_number = scheduled -> category_number;
+ new_scheduled -> sub_category_number = scheduled -> sub_category_number;
+ new_scheduled -> budgetary_number = scheduled -> budgetary_number;
+ new_scheduled -> sub_budgetary_number = scheduled -> sub_budgetary_number;
+ new_scheduled -> notes = g_strdup ( scheduled -> notes );
+
+ new_scheduled -> frequency = scheduled -> frequency;
+ new_scheduled -> user_interval = scheduled -> user_interval;
+ new_scheduled -> user_entry = scheduled -> user_entry;
+
+ if ( scheduled -> limit_date && g_date_valid ( scheduled -> limit_date ) )
+ new_scheduled -> limit_date = gsb_date_copy ( scheduled -> limit_date );
+ else
+ new_scheduled -> limit_date = NULL;
+
+ new_scheduled -> mother_row = scheduled -> mother_row;
+
+ return new_scheduled;
+}
+/**
+ * supprime l'occurence sélectionnée.
+ *
+ * \param maj TRUE force la mise à jour
+ *
+ * */
+gboolean bet_data_future_remove_line ( gint account_number, gint number, gboolean maj )
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init ( &iter, bet_future_list );
+ while (g_hash_table_iter_next ( &iter, &key, &value ) )
+ {
+ struct_futur_data *scheduled = ( struct_futur_data *) value;
+
+ if ( number != scheduled -> number )
+ continue;
+
+ if ( account_number != scheduled -> account_number )
+ {
+ if ( scheduled -> is_transfert == 0
+ || ( scheduled -> is_transfert && account_number != scheduled -> account_transfert ) )
+ continue;
+ }
+
+ g_hash_table_iter_remove ( &iter );
+
+ break;
+ }
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+
+ if ( maj )
+ {
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ bet_data_update_bet_module ( account_number, GSB_ESTIMATE_PAGE );
+ }
+
+ return FALSE;
+}
+
+
+/**
+ * supprime touts les occurences de la ligne sélectionnée
+ *
+ *
+ *
+ * */
+gboolean bet_data_future_remove_lines ( gint account_number,
+ gint number,
+ gint mother_row )
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init ( &iter, bet_future_list );
+ while (g_hash_table_iter_next ( &iter, &key, &value ) )
+ {
+ struct_futur_data *scheduled = ( struct_futur_data *) value;
+
+ if ( account_number != scheduled -> account_number )
+ {
+ if ( scheduled -> is_transfert == 0
+ || ( scheduled -> is_transfert && account_number != scheduled -> account_transfert ) )
+ continue;
+ }
+
+ if ( number == scheduled -> number )
+ g_hash_table_iter_remove ( &iter );
+ else if ( number == scheduled -> mother_row )
+ g_hash_table_iter_remove ( &iter );
+ else if ( mother_row > 0 && mother_row == scheduled -> number )
+ g_hash_table_iter_remove ( &iter );
+ else if ( mother_row > 0 && mother_row == scheduled -> mother_row )
+ g_hash_table_iter_remove ( &iter );
+ }
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+
+ return FALSE;
+}
+
+
+/**
+ * retourne la date max d'interrogation pour les prévisions
+ *
+ *
+ *
+ * */
+GDate *bet_data_array_get_date_max ( gint account_number )
+{
+ GDate *date_min;
+ GDate *date_max;
+
+ date_min = gsb_data_account_get_bet_start_date ( account_number );
+
+ date_max = gsb_date_copy ( date_min );
+
+ if ( g_date_get_day ( date_min ) == 1 )
+ {
+ g_date_add_months (date_max, gsb_data_account_get_bet_months ( account_number ) - 1 );
+ date_max = gsb_date_get_last_day_of_month ( date_max );
+ }
+ else
+ {
+ g_date_add_months (date_max, gsb_data_account_get_bet_months ( account_number ) );
+ g_date_subtract_days ( date_max, 1 );
+ }
+
+ return date_max;
+}
+
+
+/**
+ * modify futures data lines
+ *
+ *
+ *
+ * */
+gboolean bet_data_future_modify_lines ( struct_futur_data *scheduled )
+{
+ gchar *key;
+
+ if ( scheduled -> account_number == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( scheduled -> number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( scheduled -> account_number ), ":",
+ utils_str_itoa ( scheduled -> number ), NULL );
+
+ g_hash_table_replace ( bet_future_list, key, scheduled );
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+
+ return TRUE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+struct_futur_data *bet_data_future_get_struct ( gint account_number, gint number )
+{
+ gchar *key;
+ struct_futur_data *scheduled;
+
+ if ( account_number == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( account_number ), ":",
+ utils_str_itoa ( number ), NULL );
+
+ if ( ( scheduled = g_hash_table_lookup ( bet_future_list, key ) ) )
+ return scheduled;
+ else
+ return NULL;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+struct_transfert_data *struct_initialise_bet_transfert ( void )
+{
+ struct_transfert_data *transfert;
+
+ transfert = g_malloc0 ( sizeof ( struct_transfert_data ) );
+
+ transfert -> date = NULL;
+
+ return transfert;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void struct_free_bet_transfert ( struct_transfert_data *transfert )
+{
+ if ( transfert -> date )
+ g_date_free ( transfert -> date );
+
+ g_free ( transfert );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+GHashTable *bet_data_transfert_get_list ( void )
+{
+ return bet_transfert_list;
+}
+
+
+/**
+ * add line in the bet_transfer_list
+ *
+ *
+ *
+ * */
+gboolean bet_data_transfert_add_line ( struct_transfert_data *transfert )
+{
+ gchar *key;
+
+ transfert_number ++;
+
+ if ( transfert -> account_number == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( transfert_number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( transfert -> account_number ), ":",
+ utils_str_itoa ( transfert_number ), NULL );
+
+ transfert -> number = transfert_number;
+ g_hash_table_insert ( bet_transfert_list, key, transfert );
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+
+ return TRUE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_data_transfert_remove_line ( gint account_number, gint number )
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init ( &iter, bet_transfert_list );
+ while (g_hash_table_iter_next ( &iter, &key, &value ) )
+ {
+ struct_transfert_data *transfert = ( struct_transfert_data *) value;
+
+ if ( account_number != transfert -> account_number
+ ||
+ number != transfert -> number)
+ continue;
+
+ g_hash_table_iter_remove ( &iter );
+
+ break;
+ }
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ bet_data_update_bet_module ( account_number, GSB_ESTIMATE_PAGE );
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_data_transfert_set_line_from_file ( struct_transfert_data *transfert )
+{
+ gchar *key;
+
+ if ( transfert -> account_number == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( transfert -> number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( transfert -> account_number ), ":",
+ utils_str_itoa ( transfert -> number ), NULL );
+
+ if ( transfert -> number > transfert_number )
+ transfert_number = transfert -> number;
+
+ g_hash_table_insert ( bet_transfert_list, key, transfert );
+
+ return TRUE;
+}
+
+
+/**
+ * modify transfert line
+ *
+ *
+ *
+ * */
+gboolean bet_data_transfert_modify_line ( struct_transfert_data *transfert )
+{
+ gchar *key;
+
+ if ( transfert -> account_number == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( transfert -> number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( transfert -> account_number ), ":",
+ utils_str_itoa ( transfert -> number ), NULL );
+
+ g_hash_table_replace ( bet_transfert_list, key, transfert );
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+
+ return TRUE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_data_transfert_update_date_if_necessary ( struct_transfert_data *transfert )
+{
+ GDate *date_jour_1;
+ GDate *tmp_date;
+
+ date_jour_1 = gdate_today ( );
+ g_date_set_day ( date_jour_1, 1 );
+ tmp_date = gsb_date_copy ( transfert -> date );
+
+ if ( g_date_get_month ( date_jour_1 ) == g_date_get_month ( tmp_date ) )
+ {
+ g_date_free ( transfert -> date );
+ g_date_add_months ( tmp_date, 1 );
+ transfert -> date = tmp_date;
+ }
+
+ g_date_free ( date_jour_1 );
+}
+
+
+/**
+ * supprime toutes les données du module pour le compte passé en paramètre.
+ *
+ *
+ *
+ * */
+gboolean bet_data_remove_all_bet_data ( gint account_number )
+{
+ GHashTable *tmp_list;
+ GHashTableIter iter;
+ gpointer key, value;
+
+ tmp_list = bet_hist_div_list;
+
+ g_hash_table_iter_init ( &iter, tmp_list );
+ while ( g_hash_table_iter_next ( &iter, &key, &value ) )
+ {
+ struct_hist_div *shd = ( struct_hist_div *) value;
+
+ if ( account_number != shd -> account_nb )
+ continue;
+
+ if ( g_hash_table_size ( shd -> sub_div_list ) == 0 )
+ {
+ g_hash_table_iter_remove ( &iter );
+ g_hash_table_iter_init ( &iter, tmp_list );
+ }
+ else
+ {
+ GHashTableIter new_iter;
+
+ g_hash_table_iter_init ( &new_iter, shd -> sub_div_list );
+ while ( g_hash_table_iter_next ( &new_iter, &key, &value ) )
+ {
+ g_hash_table_iter_remove ( &new_iter );
+ g_hash_table_iter_init ( &new_iter, shd -> sub_div_list );
+
+ if ( g_hash_table_size ( shd -> sub_div_list ) == 0 )
+ break;
+ }
+ }
+
+ if ( g_hash_table_size ( tmp_list ) == 0 )
+ break;
+ }
+
+ tmp_list = bet_future_list;
+
+ g_hash_table_iter_init ( &iter, tmp_list );
+ while ( g_hash_table_iter_next ( &iter, &key, &value ) )
+ {
+ struct_futur_data *scheduled = ( struct_futur_data *) value;
+
+ if ( account_number != scheduled -> account_number )
+ continue;
+
+ bet_data_future_remove_lines ( account_number, scheduled -> number,
+ scheduled -> mother_row );
+ g_hash_table_iter_init ( &iter, tmp_list );
+
+ if ( g_hash_table_size ( tmp_list ) == 0 )
+ break;
+ }
+
+ tmp_list = bet_transfert_list;
+
+ g_hash_table_iter_init ( &iter, tmp_list );
+ while ( g_hash_table_iter_next ( &iter, &key, &value ) )
+ {
+ struct_transfert_data *transfert = ( struct_transfert_data *) value;
+
+ if ( account_number != transfert -> account_number )
+ continue;
+
+ g_hash_table_iter_remove ( &iter );
+ g_hash_table_iter_init ( &iter, tmp_list );
+
+ if ( g_hash_table_size ( tmp_list ) == 0 )
+ return TRUE;
+ }
+
+ return TRUE;
+}
+
+
+/* Local Variables: */
+/* c-basic-offset: 4 */
+/* End: */
diff --git a/src/bet_future.c b/src/bet_future.c
new file mode 100644
index 0000000..5652747
--- /dev/null
+++ b/src/bet_future.c
@@ -0,0 +1,2577 @@
+/* ************************************************************************** */
+/* */
+/* Copyright (C) 2007 Dominique Parisot */
+/* zionly at free.org */
+/* 2008-2010 Pierre Biava (grisbi at pierre.biava.name) */
+/* 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 */
+/* the Free Software Foundation; either version 2 of the License, or */
+/* (at your option) any later version. */
+/* */
+/* This program is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
+/* GNU General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU General Public License */
+/* along with this program; if not, write to the Free Software */
+/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+/* */
+/* ************************************************************************** */
+
+/* ./configure --with-balance-estimate */
+
+#include "include.h"
+#include <config.h>
+
+/*START_INCLUDE*/
+#include "bet_future.h"
+#include "bet_data.h"
+#include "bet_tab.h"
+#include "dialog.h"
+#include "utils_dates.h"
+#include "gsb_calendar_entry.h"
+#include "gsb_combo_box.h"
+#include "gsb_data_account.h"
+#include "gsb_data_budget.h"
+#include "gsb_data_category.h"
+#include "gsb_data_currency_link.h"
+#include "gsb_data_partial_balance.h"
+#include "gsb_data_payee.h"
+#include "gsb_form.h"
+#include "gsb_form_scheduler.h"
+#include "gsb_form_widget.h"
+#include "gsb_fyear.h"
+#include "navigation.h"
+#include "gsb_payment_method.h"
+#include "gsb_real.h"
+#include "utils_editables.h"
+#include "gtk_combofix.h"
+#include "utils.h"
+#include "utils_str.h"
+#include "structures.h"
+#include "gsb_data_payment.h"
+#include "gsb_data_account.h"
+#include "gtk_combofix.h"
+#include "gsb_form_scheduler.h"
+#include "gsb_data_form.h"
+#include "include.h"
+#include "erreur.h"
+/*END_INCLUDE*/
+
+
+/*START_STATIC*/
+static gboolean bet_form_button_press_event ( GtkWidget *entry,
+ GdkEventButton *ev,
+ gint *ptr_origin );
+static gboolean bet_form_clean ( gint account_number );
+static gboolean bet_form_create_current_form ( GtkWidget *dialog,
+ GtkWidget *table,
+ gint account_number );
+static gboolean bet_form_create_scheduler_part ( GtkWidget *dialog, GtkWidget *table );
+static gboolean bet_form_entry_get_focus ( GtkWidget *entry,
+ GdkEventFocus *ev,
+ GtkWidget *dialog );
+static gboolean bet_form_entry_lose_focus ( GtkWidget *entry,
+ GdkEventFocus *ev,
+ gint *ptr_origin );
+static gboolean bet_form_key_press_event ( GtkWidget *widget,
+ GdkEventKey *ev,
+ gint *ptr_origin );
+static gboolean bet_form_scheduler_frequency_button_changed ( GtkWidget *combo_box,
+ GtkWidget *dialog );
+static GtkWidget *bet_form_scheduler_get_element_widget ( gint element_number );
+static GtkWidget *bet_form_widget_get_widget ( gint element_number );
+static GtkWidget *bet_future_create_dialog ( gint account_number );
+static gboolean bet_future_get_budget_data ( GtkWidget *widget,
+ gint struct_type,
+ gpointer *value );
+static gboolean bet_future_get_category_data ( GtkWidget *widget,
+ gint struct_type,
+ gpointer *value );
+static gboolean bet_future_set_form_data_from_line ( gint account_number,
+ gint number );
+static gboolean bet_future_take_data_from_form ( struct_futur_data *scheduled );
+//~ static void bet_transfert_auto_inc_toggle ( GtkToggleButton *button, gpointer data );
+static GtkWidget *bet_transfert_create_account_list_part ( GtkWidget *dialog, gint account_number );
+static GtkWidget *bet_transfert_create_dialog ( gint account_number );
+static gboolean bet_transfert_entry_lose_focus ( GtkWidget *entry,
+ GdkEventFocus *ev,
+ gint *ptr_origin );
+static void bet_transfert_replace_data_toggle ( GtkToggleButton *button, GtkWidget *dialog );
+static gboolean bet_transfert_selection_changed ( GtkTreeSelection *selection, GtkWidget *dialog );
+static gboolean bet_transfert_set_form_data_from_line ( gint account_number, gint number );
+static gboolean bet_transfert_take_data ( struct_transfert_data *transfert, GtkWidget *dialog );
+/*END_STATIC*/
+
+/*START_EXTERN*/
+extern gsb_real null_real;
+extern GtkWidget *window;
+/*END_EXTERN*/
+
+#define BET_SCHEDULED_WIDTH 4
+#define BET_SCHEDULED_HEIGHT 2
+static gint width = 250;
+
+
+/** contains the list of the scheduled elements, ie list of link
+ * between an element number and the pointer of its widget
+ * for now, this list if filled at the opening of grisbi and never erased */
+static GSList *bet_schedul_element_list = NULL;
+
+/** contains a list of struct_element according to the current form */
+static GSList *bet_form_list_widgets = NULL;
+
+static GtkWidget *bet_futur_dialog = NULL;
+static GtkWidget *bet_transfert_dialog = NULL;
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_future_initialise_dialog ( void )
+ {
+ if ( bet_futur_dialog != NULL )
+ {
+ gtk_widget_destroy ( bet_futur_dialog );
+ bet_futur_dialog = NULL;
+ }
+
+ if ( bet_transfert_dialog != NULL )
+ {
+ gtk_widget_destroy ( bet_transfert_dialog );
+ bet_transfert_dialog = NULL;
+ }
+ }
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_future_new_line_dialog ( GtkTreeModel *tab_model,
+ gchar *str_date )
+{
+ GtkWidget *widget;
+ gchar *tmp_str;
+ GDate *date;
+ GDate *date_jour;
+ gint result;
+ gint account_number;
+
+ account_number = gsb_gui_navigation_get_current_account ( );
+ if ( account_number == -1 )
+ return FALSE;
+
+ if ( bet_futur_dialog == NULL )
+ {
+ bet_futur_dialog = bet_future_create_dialog ( account_number );
+ }
+ else
+ {
+ bet_form_clean ( account_number );
+ gtk_widget_show ( bet_futur_dialog );
+ }
+
+ /* init data */
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_DATE );
+ date = gsb_parse_date_string ( str_date );
+ date_jour = gdate_today ( );
+
+ if ( g_date_valid ( date ) )
+ {
+ if ( g_date_compare ( date_jour, date ) >= 0 )
+ {
+ g_date_free ( date );
+ g_date_add_days ( date_jour, 1 );
+ date = date_jour;
+ }
+ }
+ else
+ {
+ g_date_add_days ( date_jour, 1 );
+ date = date_jour;
+ }
+
+ gsb_form_widget_set_empty ( widget, FALSE );
+ gsb_calendar_entry_set_date ( widget, date );
+
+ gtk_dialog_set_response_sensitive ( GTK_DIALOG ( bet_futur_dialog ),
+ GTK_RESPONSE_OK, FALSE );
+
+dialog_return:
+ result = gtk_dialog_run ( GTK_DIALOG ( bet_futur_dialog ));
+
+ if ( result == GTK_RESPONSE_OK )
+ {
+ struct_futur_data *scheduled;
+
+ scheduled = struct_initialise_bet_future ( );
+
+ if ( !scheduled )
+ {
+ dialogue_error_memory ();
+ gtk_widget_hide ( bet_futur_dialog );
+ return FALSE;
+ }
+
+ if ( bet_future_take_data_from_form ( scheduled ) == FALSE )
+ {
+ tmp_str = g_strdup ( _("Error: the frequency defined by the user or the amount is "
+ "not specified or the date is invalid.") );
+ dialogue_warning_hint ( tmp_str, _("One field is not filled in") );
+ g_free ( tmp_str );
+ goto dialog_return;
+ }
+ else
+ bet_data_future_add_lines ( scheduled );
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ bet_data_update_bet_module ( account_number, GSB_ESTIMATE_PAGE );
+ }
+
+ gtk_widget_hide ( bet_futur_dialog );
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+GtkWidget *bet_future_create_dialog ( gint account_number )
+{
+ GtkWidget *dialog;
+ GtkWidget *vbox;
+ GtkWidget *table;
+
+ /* Create the dialog */
+ dialog = gtk_dialog_new_with_buttons ( _("Enter a budget line"),
+ GTK_WINDOW ( window ),
+ GTK_DIALOG_MODAL,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OK, GTK_RESPONSE_OK,
+ NULL );
+
+ gtk_window_set_position ( GTK_WINDOW ( dialog ), GTK_WIN_POS_CENTER_ON_PARENT );
+ gtk_window_set_resizable ( GTK_WINDOW ( dialog ), TRUE );
+ gtk_dialog_set_default_response ( GTK_DIALOG ( dialog ), GTK_RESPONSE_OK );
+
+ vbox = gtk_vbox_new ( FALSE, 0 );
+ gtk_box_pack_start ( GTK_BOX ( GTK_DIALOG ( dialog )->vbox ), vbox, TRUE, TRUE, 0 );
+ gtk_container_set_border_width ( GTK_CONTAINER ( vbox ), 12 );
+
+ /* next we fill the bet_form */
+ table = gtk_table_new ( BET_SCHEDULED_HEIGHT, BET_SCHEDULED_WIDTH, FALSE );
+ gtk_table_set_col_spacings ( GTK_TABLE ( table ), 6 );
+ gtk_widget_show ( table );
+ gtk_box_pack_start ( GTK_BOX ( vbox ), table, FALSE, FALSE, 5 );
+
+ bet_form_create_scheduler_part ( dialog, table );
+ bet_form_create_current_form ( dialog, table, account_number );
+
+ gtk_widget_show ( vbox );
+
+ return dialog;
+ }
+
+
+/**
+ * create the scheduled part
+ *
+ * \param table a GtkTable with the dimension SCHEDULED_HEIGHT*SCHEDULED_WIDTH to be filled
+ *
+ * \return FALSE
+ * */
+gboolean bet_form_create_scheduler_part ( GtkWidget *dialog, GtkWidget *table )
+{
+
+ GtkWidget *separator;
+ GtkWidget *combo = NULL;
+ gint column;
+
+ devel_debug (NULL);
+ if (!table)
+ return FALSE;
+
+ /* ok, now fill the form
+ * we play with height and width, but for now it's fix : 6 columns and 1 line */
+ for ( column=0 ; column < SCHEDULED_WIDTH ; column++ )
+ {
+ GtkWidget *widget = NULL;
+ const gchar *tooltip_text = NULL;
+ gchar *text_frequency [] = { _("Once"), _("Weekly"), _("Monthly"), _("Bimonthly"),
+ _("Quarterly"), _("Yearly"), _("Custom"), NULL };
+ gchar *text_frequency_user [] = { _("Days"), _("Weeks"), _("Months"), _("Years"), NULL };
+ gint element_number;
+ struct_element *element;
+ /* on tient compte que le premier widget utile est le troisième du formulaire */
+ element_number = column + 2;
+
+ switch ( element_number )
+ {
+ case SCHEDULED_FORM_FREQUENCY_BUTTON:
+ widget = gsb_combo_box_new_with_index ( text_frequency,
+ G_CALLBACK ( bet_form_scheduler_frequency_button_changed ),
+ dialog );
+ combo = widget;
+ tooltip_text = SPACIFY( _("Frequency") );
+ gtk_widget_show ( widget );
+ break;
+
+ case SCHEDULED_FORM_LIMIT_DATE:
+ widget = gsb_calendar_entry_new ( FALSE );
+ gsb_form_widget_set_empty ( widget, TRUE );
+ gtk_entry_set_text ( GTK_ENTRY ( widget ),
+ _("Limit date") );
+ g_signal_connect ( G_OBJECT (widget),
+ "button-press-event",
+ G_CALLBACK ( gsb_form_scheduler_button_press_event ),
+ GINT_TO_POINTER (element_number));
+ g_signal_connect ( G_OBJECT (widget),
+ "focus-in-event",
+ G_CALLBACK ( gsb_form_entry_get_focus ),
+ GINT_TO_POINTER (element_number));
+ g_signal_connect_after ( G_OBJECT (widget),
+ "focus-out-event",
+ G_CALLBACK ( gsb_form_scheduler_entry_lose_focus ),
+ GINT_TO_POINTER (element_number));
+ tooltip_text = SPACIFY( _("Final date") );
+ gtk_widget_show ( widget );
+ break;
+
+ case SCHEDULED_FORM_FREQUENCY_USER_ENTRY:
+ widget = gtk_entry_new ();
+ gtk_entry_set_text ( GTK_ENTRY ( widget ),
+ _("Own frequency") );
+ gsb_form_widget_set_empty ( widget, TRUE );
+ g_signal_connect ( G_OBJECT (widget),
+ "focus-in-event",
+ G_CALLBACK (gsb_form_entry_get_focus),
+ GINT_TO_POINTER (element_number));
+ g_signal_connect_after ( G_OBJECT (widget),
+ "focus-out-event",
+ G_CALLBACK ( gsb_form_scheduler_entry_lose_focus),
+ GINT_TO_POINTER (element_number));
+ tooltip_text = SPACIFY( _("Custom frequency") );
+ break;
+
+ case SCHEDULED_FORM_FREQUENCY_USER_BUTTON:
+ widget = gsb_combo_box_new_with_index ( text_frequency_user,
+ NULL, NULL );
+ tooltip_text = SPACIFY( _("Custom frequency") );
+ gsb_combo_box_set_index ( widget, 2 );
+ break;
+ }
+
+ if (!widget)
+ continue;
+
+ if (tooltip_text)
+ gtk_widget_set_tooltip_text ( GTK_WIDGET (widget),
+ tooltip_text);
+
+ /* save the element */
+ element = g_malloc0 ( sizeof ( struct_element ) );
+ element -> element_number = element_number;
+ element -> element_widget = widget;
+ bet_schedul_element_list = g_slist_append ( bet_schedul_element_list, element );
+
+ /* set in the form */
+ gtk_table_attach ( GTK_TABLE (table),
+ widget,
+ column, column+1,
+ 0, 1,
+ GTK_EXPAND | GTK_FILL,
+ GTK_EXPAND | GTK_FILL,
+ 0, 0 );
+ }
+
+ separator = gtk_hseparator_new ( );
+ gtk_widget_show ( separator );
+ gtk_table_attach ( GTK_TABLE (table),
+ separator,
+ 0, 4,
+ 1, 2,
+ GTK_EXPAND | GTK_FILL,
+ GTK_EXPAND | GTK_FILL,
+ 0, 6);
+
+ gsb_combo_box_set_index ( combo, 0 );
+
+ return FALSE;
+}
+
+
+/**
+ * fill the form according to the account_number :
+ *
+ * \param account_number the number of account
+ *
+ * \return FALSE
+ * */
+gboolean bet_form_create_current_form ( GtkWidget *dialog,
+ GtkWidget *table,
+ gint account_number )
+{
+ GtkWidget *widget;
+ GtkWidget *credit;
+ gint element_number;
+ gint row = 2;
+ gint column = 0;;
+ struct_element *element;
+ GSList *tmp_list;
+
+ account_number = gsb_gui_navigation_get_current_account ( );
+
+ element_number = TRANSACTION_FORM_DATE;
+ widget = gsb_calendar_entry_new ( FALSE );
+ gtk_widget_show ( widget );
+ gtk_table_attach ( GTK_TABLE ( table ),
+ widget,
+ column, column+1,
+ row, row+1,
+ gsb_form_get_element_expandable ( element_number ),
+ gsb_form_get_element_expandable ( element_number ),
+ 0, 0);
+ element = g_malloc0 ( sizeof ( struct_element ) );
+ element -> element_number = element_number;
+ element -> element_widget = widget;
+ bet_form_list_widgets = g_slist_append ( bet_form_list_widgets, element );
+ column ++;
+
+ element_number = TRANSACTION_FORM_PARTY;
+ widget = gtk_combofix_new (
+ gsb_data_payee_get_name_and_report_list ( ) );
+ gtk_widget_set_size_request ( widget, width, -1 );
+ gtk_combofix_set_force_text ( GTK_COMBOFIX (widget), TRUE ); /* on ne peut pas créer d'item */
+ gtk_combofix_set_max_items ( GTK_COMBOFIX (widget),
+ etat.combofix_max_item );
+ gtk_combofix_set_case_sensitive ( GTK_COMBOFIX (widget),
+ etat.combofix_case_sensitive );
+ gtk_combofix_set_mixed_sort ( GTK_COMBOFIX (widget),
+ FALSE );
+ gtk_widget_show ( widget );
+ gtk_table_attach ( GTK_TABLE ( table ),
+ widget,
+ column, column+1,
+ row, row+1,
+ gsb_form_get_element_expandable ( element_number ),
+ gsb_form_get_element_expandable ( element_number ),
+ 0, 0);
+ element = g_malloc0 ( sizeof ( struct_element ) );
+ element -> element_number = element_number;
+ element -> element_widget = widget;
+ bet_form_list_widgets = g_slist_append ( bet_form_list_widgets, element );
+ column ++;
+
+ element_number = TRANSACTION_FORM_DEBIT;
+ widget = gtk_entry_new ( );
+ g_object_set_data ( G_OBJECT ( widget ), "element_number",
+ GINT_TO_POINTER ( TRANSACTION_FORM_DEBIT ) );
+ g_signal_connect ( G_OBJECT ( widget ),
+ "changed",
+ G_CALLBACK ( gsb_form_widget_amount_entry_changed ),
+ NULL );
+ gtk_widget_show ( widget );
+ gtk_table_attach ( GTK_TABLE ( table ),
+ widget,
+ column, column+1,
+ row, row+1,
+ gsb_form_get_element_expandable ( element_number ),
+ gsb_form_get_element_expandable ( element_number ),
+ 0, 0);
+ element = g_malloc0 ( sizeof ( struct_element ) );
+ element -> element_number = element_number;
+ element -> element_widget = widget;
+ bet_form_list_widgets = g_slist_append ( bet_form_list_widgets, element );
+ column ++;
+
+ element_number = TRANSACTION_FORM_CREDIT;
+ widget = gtk_entry_new ( );
+ credit = widget;
+ g_object_set_data ( G_OBJECT ( widget ), "element_number",
+ GINT_TO_POINTER ( TRANSACTION_FORM_CREDIT ) );
+ g_signal_connect ( G_OBJECT ( widget ),
+ "changed",
+ G_CALLBACK ( gsb_form_widget_amount_entry_changed ),
+ NULL );
+ gtk_widget_show ( widget );
+ gtk_table_attach ( GTK_TABLE ( table ),
+ widget,
+ column, column+1,
+ row, row+1,
+ gsb_form_get_element_expandable ( element_number ),
+ gsb_form_get_element_expandable ( element_number ),
+ 0, 0);
+ element = g_malloc0 ( sizeof ( struct_element ) );
+ element -> element_number = element_number;
+ element -> element_widget = widget;
+ bet_form_list_widgets = g_slist_append ( bet_form_list_widgets, element );
+ column = 0;
+ row ++;
+
+ element_number = TRANSACTION_FORM_EXERCICE;
+ widget = gsb_fyear_make_combobox (TRUE);
+ gtk_widget_set_tooltip_text ( GTK_WIDGET (widget),
+ SPACIFY(_("Choose the financial year")));
+ gtk_widget_show ( widget );
+ gtk_table_attach ( GTK_TABLE ( table ),
+ widget,
+ column, column+1,
+ row, row+1,
+ gsb_form_get_element_expandable ( element_number ),
+ gsb_form_get_element_expandable ( element_number ),
+ 0, 0);
+ element = g_malloc0 ( sizeof ( struct_element ) );
+ element -> element_number = element_number;
+ element -> element_widget = widget;
+ bet_form_list_widgets = g_slist_append ( bet_form_list_widgets, element );
+ column ++;
+
+ element_number = TRANSACTION_FORM_CATEGORY;
+ widget = gtk_combofix_new (
+ gsb_data_category_get_name_list ( TRUE, TRUE, TRUE, FALSE ) );
+ gtk_widget_set_size_request ( widget, width, -1 );
+ gtk_combofix_set_force_text ( GTK_COMBOFIX (widget), TRUE ); /* on ne peut pas créer d'item */
+ gtk_combofix_set_max_items ( GTK_COMBOFIX (widget),
+ etat.combofix_max_item );
+ gtk_combofix_set_case_sensitive ( GTK_COMBOFIX (widget),
+ etat.combofix_case_sensitive );
+ gtk_combofix_set_mixed_sort ( GTK_COMBOFIX (widget),
+ etat.combofix_mixed_sort );
+ gtk_widget_show ( widget );
+ gtk_table_attach ( GTK_TABLE ( table ),
+ widget,
+ column, column+1,
+ row, row+1,
+ gsb_form_get_element_expandable ( element_number ),
+ gsb_form_get_element_expandable ( element_number ),
+ 0, 0);
+ element = g_malloc0 ( sizeof ( struct_element ) );
+ element -> element_number = element_number;
+ element -> element_widget = widget;
+ bet_form_list_widgets = g_slist_append ( bet_form_list_widgets, element );
+ column ++;
+
+ element_number = TRANSACTION_FORM_TYPE;
+ widget = gtk_combo_box_new ();
+ gsb_payment_method_create_combo_list ( widget,
+ GSB_PAYMENT_DEBIT,
+ account_number, 0 );
+ gtk_combo_box_set_active ( GTK_COMBO_BOX (widget), 0 );
+ gtk_widget_set_tooltip_text ( GTK_WIDGET (widget),
+ SPACIFY(_("Choose the method of payment")));
+ gtk_widget_show ( widget );
+ gtk_table_attach ( GTK_TABLE ( table ),
+ widget,
+ column, column+1,
+ row, row+1,
+ gsb_form_get_element_expandable ( element_number ),
+ gsb_form_get_element_expandable ( element_number ),
+ 0, 0);
+
+ element = g_malloc0 ( sizeof ( struct_element ) );
+ element -> element_number = element_number;
+ element -> element_widget = widget;
+ bet_form_list_widgets = g_slist_append ( bet_form_list_widgets, element );
+ column = 1;
+ row ++;
+
+ element_number = TRANSACTION_FORM_BUDGET;
+ widget = gtk_combofix_new (
+ gsb_data_budget_get_name_list (TRUE, TRUE));
+ gtk_widget_set_size_request ( widget, width, -1 );
+ gtk_combofix_set_force_text ( GTK_COMBOFIX (widget), TRUE ); /* on ne peut pas créer d'item */
+ gtk_combofix_set_max_items ( GTK_COMBOFIX (widget),
+ etat.combofix_max_item );
+ gtk_combofix_set_case_sensitive ( GTK_COMBOFIX (widget),
+ etat.combofix_case_sensitive );
+ gtk_combofix_set_mixed_sort ( GTK_COMBOFIX (widget),
+ etat.combofix_mixed_sort );
+ gtk_widget_show ( widget );
+ gtk_table_attach ( GTK_TABLE ( table ),
+ widget,
+ column, column+1,
+ row, row+1,
+ gsb_form_get_element_expandable ( element_number ),
+ gsb_form_get_element_expandable ( element_number ),
+ 0, 0);
+ element = g_malloc0 ( sizeof ( struct_element ) );
+ element -> element_number = element_number;
+ element -> element_widget = widget;
+ bet_form_list_widgets = g_slist_append ( bet_form_list_widgets, element );
+ column = 0;
+ row ++;
+
+ element_number = TRANSACTION_FORM_NOTES;
+ widget = gtk_entry_new();
+ gtk_widget_show ( widget );
+ gtk_table_attach ( GTK_TABLE ( table ),
+ widget,
+ column, column+4,
+ row, row+1,
+ gsb_form_get_element_expandable ( element_number ),
+ gsb_form_get_element_expandable ( element_number ),
+ 0, 2);
+ element = g_malloc0 ( sizeof ( struct_element ) );
+ element -> element_number = element_number;
+ element -> element_widget = widget;
+ bet_form_list_widgets = g_slist_append ( bet_form_list_widgets, element );
+
+ tmp_list = bet_form_list_widgets;
+
+ while ( tmp_list )
+ {
+ struct_element*element;
+
+ element = tmp_list -> data;
+
+ widget = element -> element_widget;
+ if ( GTK_IS_ENTRY ( widget ))
+ {
+ g_signal_connect ( G_OBJECT ( widget ),
+ "focus-in-event",
+ G_CALLBACK ( bet_form_entry_get_focus ),
+ dialog );
+ g_signal_connect ( G_OBJECT ( widget ),
+ "focus-out-event",
+ G_CALLBACK ( bet_form_entry_lose_focus ),
+ GINT_TO_POINTER ( element -> element_number ) );
+ g_signal_connect ( G_OBJECT ( widget ),
+ "button-press-event",
+ G_CALLBACK ( bet_form_button_press_event ),
+ GINT_TO_POINTER ( element -> element_number ) );
+ g_signal_connect ( G_OBJECT ( widget ),
+ "key-press-event",
+ G_CALLBACK ( bet_form_key_press_event ),
+ GINT_TO_POINTER ( element -> element_number ) );
+ }
+ else
+ {
+ if ( GTK_IS_COMBOFIX ( widget ))
+ {
+ g_signal_connect ( G_OBJECT ( GTK_COMBOFIX ( widget ) -> entry ),
+ "focus-in-event",
+ G_CALLBACK ( bet_form_entry_get_focus ),
+ dialog );
+ g_signal_connect ( G_OBJECT ( GTK_COMBOFIX (widget ) -> entry ),
+ "focus-out-event",
+ G_CALLBACK ( bet_form_entry_lose_focus ),
+ GINT_TO_POINTER ( element -> element_number ) );
+ g_signal_connect ( G_OBJECT ( GTK_COMBOFIX (widget ) -> entry ),
+ "button-press-event",
+ G_CALLBACK ( bet_form_button_press_event ),
+ GINT_TO_POINTER ( element -> element_number ) );
+ g_signal_connect ( G_OBJECT ( GTK_COMBOFIX (widget ) -> entry ),
+ "key-press-event",
+ G_CALLBACK ( bet_form_key_press_event ),
+ GINT_TO_POINTER ( element -> element_number ) );
+ }
+ else
+ /* neither an entry, neither a combofix */
+ g_signal_connect ( G_OBJECT ( widget ),
+ "key-press-event",
+ G_CALLBACK ( bet_form_key_press_event ),
+ GINT_TO_POINTER ( element -> element_number ) );
+ }
+ tmp_list = tmp_list -> next;
+ }
+
+ bet_form_clean ( account_number );
+
+ return FALSE;
+}
+
+
+/**
+ * clean the form according to the account_number
+ * and set the default values
+ *
+ * \param account number
+ *
+ * \return FALSE
+ * */
+gboolean bet_form_clean ( gint account_number )
+{
+ GSList *tmp_list;
+
+ /* clean the scheduled widget */
+ tmp_list = bet_schedul_element_list;
+
+ while (tmp_list)
+ {
+ struct_element *element;
+
+ element = tmp_list -> data;
+
+ /* better to protect here if widget != NULL (bad experience...) */
+ if (element -> element_widget)
+ {
+ gtk_widget_set_sensitive ( element -> element_widget, TRUE );
+
+ switch (element -> element_number)
+ {
+ case SCHEDULED_FORM_FREQUENCY_BUTTON:
+ gsb_combo_box_set_index ( element -> element_widget, 0 );
+ break;
+ case SCHEDULED_FORM_LIMIT_DATE:
+ gsb_form_widget_set_empty ( element -> element_widget, TRUE );
+ gtk_entry_set_text ( GTK_ENTRY ( element -> element_widget ),
+ _("Limit date") );
+ break;
+ case SCHEDULED_FORM_FREQUENCY_USER_ENTRY:
+ gtk_entry_set_text ( GTK_ENTRY ( element -> element_widget ),
+ _("Own frequency") );
+ gsb_form_widget_set_empty ( element -> element_widget, TRUE );
+ break;
+ case SCHEDULED_FORM_FREQUENCY_USER_BUTTON:
+ gsb_combo_box_set_index ( element -> element_widget, 2 );
+ break;
+ }
+ }
+
+ tmp_list = tmp_list -> next;
+ }
+
+ /* clean the transactions widget */
+ tmp_list = bet_form_list_widgets;
+
+ while (tmp_list)
+ {
+ struct_element *element;
+
+ element = tmp_list -> data;
+
+ /* better to protect here if widget != NULL (bad experience...) */
+ if (element -> element_widget)
+ {
+ /* some widgets can be set unsensitive because of the children of splits,
+ * so resensitive all to be sure */
+ gtk_widget_set_sensitive ( element -> element_widget, TRUE );
+
+ switch (element -> element_number)
+ {
+ case TRANSACTION_FORM_DATE:
+ if ( !strlen ( gtk_entry_get_text ( GTK_ENTRY (
+ element -> element_widget ) ) ) )
+ {
+ gsb_form_widget_set_empty ( element -> element_widget, TRUE );
+ gtk_entry_set_text ( GTK_ENTRY ( element -> element_widget ), _("Date") );
+ }
+ break;
+
+ case TRANSACTION_FORM_EXERCICE:
+ /* editing a transaction can show some fyear wich shouldn't be showed,
+ * so hide them here */
+ gsb_fyear_update_fyear_list ();
+
+ /* set the combo_box on 'Automatic' */
+ gsb_fyear_set_combobox_history ( element -> element_widget, 0 );
+
+ break;
+
+ case TRANSACTION_FORM_PARTY:
+ gsb_form_widget_set_empty ( GTK_COMBOFIX ( element -> element_widget ) -> entry,
+ TRUE );
+ gtk_combofix_set_text ( GTK_COMBOFIX ( element -> element_widget ),
+ _("Payee") );
+ break;
+
+ case TRANSACTION_FORM_DEBIT:
+ gsb_form_widget_set_empty ( element -> element_widget,
+ TRUE );
+ gtk_entry_set_text ( GTK_ENTRY ( element -> element_widget ),
+ _("Debit") );
+ break;
+
+ case TRANSACTION_FORM_CREDIT:
+ gsb_form_widget_set_empty ( element -> element_widget,
+ TRUE );
+ gtk_entry_set_text ( GTK_ENTRY ( element -> element_widget ),
+ _("Credit") );
+ break;
+
+ case TRANSACTION_FORM_CATEGORY:
+ gsb_form_widget_set_empty ( GTK_COMBOFIX ( element -> element_widget ) -> entry,
+ TRUE );
+ gtk_combofix_set_text ( GTK_COMBOFIX ( element -> element_widget ),
+ _("Categories : Sub-categories") );
+ break;
+
+ case TRANSACTION_FORM_BUDGET:
+ gsb_form_widget_set_empty ( GTK_COMBOFIX ( element -> element_widget ) -> entry,
+ TRUE );
+ gtk_combofix_set_text ( GTK_COMBOFIX ( element -> element_widget ),
+ _("Budgetary line") );
+ break;
+
+ case TRANSACTION_FORM_NOTES:
+ gsb_form_widget_set_empty ( element -> element_widget,
+ TRUE );
+ gtk_entry_set_text ( GTK_ENTRY ( element -> element_widget ),
+ _("Notes") );
+ break;
+
+ case TRANSACTION_FORM_TYPE:
+ gsb_payment_method_set_combobox_history ( element -> element_widget,
+ gsb_data_account_get_default_debit (account_number));
+ break;
+
+ }
+ }
+ tmp_list = tmp_list -> next;
+ }
+
+ return FALSE;
+}
+
+
+/**
+ * called when the frequency button is changed
+ * show/hide the necessary widget according to its state
+ *
+ * \param combo_box
+ *
+ * \return FALSE
+ * */
+gboolean bet_form_scheduler_frequency_button_changed ( GtkWidget *combo_box,
+ GtkWidget *dialog )
+{
+ gchar *selected_item;
+
+ selected_item = gtk_combo_box_get_active_text ( GTK_COMBO_BOX ( combo_box ) );
+
+ if ( !strcmp ( selected_item, _("Once") ) )
+ {
+ gtk_widget_hide ( bet_form_scheduler_get_element_widget (
+ SCHEDULED_FORM_LIMIT_DATE ) );
+ gtk_widget_hide ( bet_form_scheduler_get_element_widget (
+ SCHEDULED_FORM_FREQUENCY_USER_ENTRY ) );
+ gtk_widget_hide ( bet_form_scheduler_get_element_widget (
+ SCHEDULED_FORM_FREQUENCY_USER_BUTTON ) );
+ }
+ else
+ {
+ gtk_widget_show ( bet_form_scheduler_get_element_widget (
+ SCHEDULED_FORM_LIMIT_DATE ) );
+
+ if ( !strcmp ( selected_item, _("Custom") ) )
+ {
+ gtk_widget_show ( bet_form_scheduler_get_element_widget (
+ SCHEDULED_FORM_FREQUENCY_USER_ENTRY));
+ gtk_widget_show ( bet_form_scheduler_get_element_widget (
+ SCHEDULED_FORM_FREQUENCY_USER_BUTTON ) );
+ }
+ else
+ {
+ gtk_widget_hide ( gsb_form_scheduler_get_element_widget (
+ SCHEDULED_FORM_FREQUENCY_USER_ENTRY ) );
+ gtk_widget_hide ( gsb_form_scheduler_get_element_widget (
+ SCHEDULED_FORM_FREQUENCY_USER_BUTTON ) );
+ }
+ }
+ g_free ( selected_item );
+ gtk_dialog_set_response_sensitive ( GTK_DIALOG ( dialog ), GTK_RESPONSE_OK, TRUE );
+
+ return FALSE;
+}
+
+
+/**
+ * called when an entry get the focus, if the entry is free,
+ * set it normal and erase the help content
+ *
+ * \param entry
+ *
+ * \return FALSE
+ * */
+gboolean bet_form_entry_get_focus ( GtkWidget *entry,
+ GdkEventFocus *ev,
+ GtkWidget *dialog )
+{
+ /* the entry can be a combofix or a real entry */
+ if (GTK_IS_COMBOFIX ( entry ))
+ {
+ if ( gsb_form_widget_check_empty (GTK_COMBOFIX (entry) -> entry))
+ {
+ gtk_combofix_set_text ( GTK_COMBOFIX (entry), "" );
+ gsb_form_widget_set_empty ( GTK_COMBOFIX (entry) -> entry, FALSE );
+ }
+ }
+ else
+ {
+ if ( gsb_form_widget_check_empty (entry) )
+ {
+ gtk_entry_set_text ( GTK_ENTRY (entry), "" );
+ gsb_form_widget_set_empty ( entry, FALSE );
+ }
+ }
+ /* sensitive the valid button */
+ if ( dialog && GTK_IS_DIALOG ( dialog ) )
+ gtk_dialog_set_response_sensitive ( GTK_DIALOG ( dialog ), GTK_RESPONSE_OK, TRUE );
+
+ return FALSE;
+}
+
+
+/**
+ * called when an entry lose the focus
+ *
+ * \param entry
+ * \param ev
+ * \param ptr_origin a pointer gint wich is the number of the element
+ *
+ * \return FALSE
+ * */
+gboolean bet_form_entry_lose_focus ( GtkWidget *entry,
+ GdkEventFocus *ev,
+ gint *ptr_origin )
+{
+ GtkWidget *widget;
+ gchar *string;
+ gint element_number;
+ gint account_number;
+
+ /* still not found, if change the content of the form, something come in entry
+ * wich is nothing, so protect here */
+ if ( !GTK_IS_WIDGET ( entry )
+ ||
+ !GTK_IS_ENTRY ( entry ))
+ return FALSE;
+
+ /* remove the selection */
+ gtk_editable_select_region ( GTK_EDITABLE ( entry ), 0, 0 );
+ element_number = GPOINTER_TO_INT ( ptr_origin );
+ account_number = gsb_form_get_account_number ();
+
+ /* sometimes the combofix popus stays showed, so remove here */
+ if ( element_number == TRANSACTION_FORM_PARTY
+ ||
+ element_number == TRANSACTION_FORM_CATEGORY
+ ||
+ element_number == TRANSACTION_FORM_BUDGET )
+ {
+ widget = bet_form_widget_get_widget ( element_number );
+ gtk_combofix_hide_popup ( GTK_COMBOFIX ( widget ) );
+ }
+
+ /* string will be filled only if the field is empty */
+ string = NULL;
+ switch ( element_number )
+ {
+ case TRANSACTION_FORM_DATE :
+ if ( !strlen ( gtk_entry_get_text ( GTK_ENTRY ( entry ) ) ) )
+ string = gsb_form_widget_get_name ( TRANSACTION_FORM_DATE );
+ break;
+
+ case TRANSACTION_FORM_PARTY :
+ if ( !strlen ( gtk_entry_get_text ( GTK_ENTRY ( entry ) ) ) )
+ string = gsb_form_widget_get_name ( TRANSACTION_FORM_PARTY );
+ break;
+
+ case TRANSACTION_FORM_DEBIT :
+ /* we change the payment method to adapt it for the debit */
+ if ( strlen ( gtk_entry_get_text ( GTK_ENTRY ( entry ) ) ) )
+ {
+ /* empty the credit */
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_CREDIT );
+ if ( !gsb_form_widget_check_empty ( widget ) )
+ {
+ gtk_entry_set_text ( GTK_ENTRY ( widget ),
+ gsb_form_widget_get_name ( TRANSACTION_FORM_CREDIT ) );
+ gsb_form_widget_set_empty ( widget, TRUE );
+ }
+
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_TYPE );
+
+ /* change the method of payment if necessary
+ * (if grey, it's a child of split so do nothing) */
+ if ( widget
+ &&
+ GTK_WIDGET_SENSITIVE ( widget ) )
+ {
+ /* change the signe of the method of payment and the contra */
+ if ( gsb_payment_method_get_combo_sign ( widget ) == GSB_PAYMENT_CREDIT )
+ {
+ gsb_payment_method_create_combo_list ( widget,
+ GSB_PAYMENT_DEBIT,
+ account_number, 0 );
+ }
+ }
+ gsb_form_check_auto_separator (entry);
+ }
+ else
+ {
+ /* si pas de nouveau débit on essaie de remettre l'ancien crédit */
+ if ( (string = gsb_form_widget_get_old_credit ( ) ) )
+ {
+ GtkWidget *widget_prov;
+
+ widget_prov = bet_form_widget_get_widget ( TRANSACTION_FORM_CREDIT );
+
+ gtk_entry_set_text ( GTK_ENTRY ( widget_prov ), string );
+ gsb_form_widget_set_empty ( widget_prov, FALSE );
+ g_free ( string );
+
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_TYPE );
+ if ( widget
+ &&
+ GTK_WIDGET_SENSITIVE ( widget ) )
+ {
+ /* change the signe of the method of payment and the contra */
+ if ( gsb_payment_method_get_combo_sign ( widget ) == GSB_PAYMENT_DEBIT )
+ {
+ gsb_payment_method_create_combo_list ( widget,
+ GSB_PAYMENT_CREDIT,
+ account_number, 0 );
+ }
+ }
+ }
+ string = gsb_form_widget_get_name ( TRANSACTION_FORM_DEBIT );
+ }
+ break;
+
+ case TRANSACTION_FORM_CREDIT :
+ /* we change the payment method to adapt it for the debit */
+ if ( strlen ( gtk_entry_get_text ( GTK_ENTRY ( entry ) ) ) )
+ {
+ /* empty the credit */
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_DEBIT );
+ if ( !gsb_form_widget_check_empty ( widget ) )
+ {
+ gtk_entry_set_text ( GTK_ENTRY ( widget ),
+ gsb_form_widget_get_name ( TRANSACTION_FORM_DEBIT ) );
+ gsb_form_widget_set_empty ( widget, TRUE );
+ }
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_TYPE);
+
+ /* change the method of payment if necessary
+ * (if grey, it's a child of split so do nothing) */
+ if ( widget
+ &&
+ GTK_WIDGET_SENSITIVE (widget))
+ {
+ /* change the signe of the method of payment and the contra */
+ if ( gsb_payment_method_get_combo_sign ( widget ) == GSB_PAYMENT_DEBIT )
+ {
+ gsb_payment_method_create_combo_list ( widget,
+ GSB_PAYMENT_CREDIT,
+ account_number, 0 );
+ }
+ }
+ gsb_form_check_auto_separator (entry);
+ }
+ else
+ {
+ /* si pas de nouveau credit on essaie de remettre l'ancien débit */
+ if ( (string = gsb_form_widget_get_old_debit ( ) ) )
+ {
+ GtkWidget * widget_prov;
+
+ widget_prov = bet_form_widget_get_widget ( TRANSACTION_FORM_DEBIT );
+
+ gtk_entry_set_text ( GTK_ENTRY ( widget_prov ), string );
+ gsb_form_widget_set_empty ( widget_prov, FALSE );
+ g_free ( string );
+
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_TYPE );
+ if ( widget
+ &&
+ GTK_WIDGET_SENSITIVE ( widget ) )
+ {
+ /* change the signe of the method of payment and the contra */
+ if ( gsb_payment_method_get_combo_sign ( widget ) == GSB_PAYMENT_CREDIT )
+ {
+ gsb_payment_method_create_combo_list ( widget,
+ GSB_PAYMENT_DEBIT,
+ account_number, 0 );
+ }
+ }
+ }
+ string = gsb_form_widget_get_name ( TRANSACTION_FORM_CREDIT );
+ }
+ break;
+
+ case TRANSACTION_FORM_CATEGORY :
+ if ( !strlen ( gtk_entry_get_text ( GTK_ENTRY ( entry ) ) ) )
+ string = gsb_form_widget_get_name ( TRANSACTION_FORM_CATEGORY );
+ break;
+
+ case TRANSACTION_FORM_BUDGET :
+ if ( !strlen ( gtk_entry_get_text ( GTK_ENTRY ( entry ) ) ) )
+ string = gsb_form_widget_get_name ( TRANSACTION_FORM_BUDGET );
+ break;
+
+ case TRANSACTION_FORM_NOTES :
+ if ( !strlen ( gtk_entry_get_text ( GTK_ENTRY ( entry ) ) ) )
+ string = _(gsb_form_widget_get_name ( element_number ) );
+ break;
+
+ default :
+ break;
+
+ }
+
+ /* if string is not NULL, the entry is empty so set the empty field to TRUE */
+ if ( string )
+ {
+ switch ( element_number)
+ {
+ case TRANSACTION_FORM_PARTY :
+ case TRANSACTION_FORM_CATEGORY :
+ case TRANSACTION_FORM_BUDGET :
+ /* need to work with the combofix to avoid some signals if we work
+ * directly on the entry */
+ gtk_combofix_set_text ( GTK_COMBOFIX (
+ bet_form_widget_get_widget ( element_number ) ),
+ _(string) );
+ break;
+
+ default:
+ gtk_entry_set_text ( GTK_ENTRY ( entry ), string );
+ break;
+ }
+ gsb_form_widget_set_empty ( entry, TRUE );
+ }
+
+ return FALSE;
+}
+
+
+/**
+ * return the widget of the element_number given in param,
+ * for the bet scheduler part of the form
+ *
+ * \param element_number
+ *
+ * \return a GtkWidget * or NULL
+ * */
+GtkWidget *bet_form_scheduler_get_element_widget ( gint element_number )
+{
+ return gsb_form_get_element_widget_from_list ( element_number,
+ bet_schedul_element_list );
+}
+
+
+/**
+ * return the pointer to the widget corresponding to the given element
+ *
+ * \param element_number
+ *
+ * \return the widget or NULL
+ * */
+GtkWidget *bet_form_widget_get_widget ( gint element_number )
+{
+ return gsb_form_get_element_widget_from_list ( element_number,
+ bet_form_list_widgets );
+}
+
+
+/**
+ * called when press a key on an element of the form
+ *
+ * \param widget wich receive the signal
+ * \param ev
+ * \param ptr_origin a pointer number of the element
+ *
+ * \return FALSE
+ * */
+gboolean bet_form_key_press_event ( GtkWidget *widget,
+ GdkEventKey *ev,
+ gint *ptr_origin )
+{
+ gint element_number;
+ gint account_number;
+ GtkWidget *widget_prov;
+
+ element_number = GPOINTER_TO_INT (ptr_origin);
+ account_number = gsb_form_get_account_number ();
+
+ /* if conf.entree = 1, entry finish the transaction, else does as tab */
+ if ( !conf.entree
+ &&
+ ( ev -> keyval == GDK_Return
+ ||
+ ev -> keyval == GDK_KP_Enter ))
+ ev->keyval = GDK_Tab ;
+
+ switch ( ev -> keyval )
+ {
+ case GDK_1:
+ case GDK_2:
+ case GDK_3:
+ case GDK_4:
+ case GDK_5:
+ case GDK_6:
+ case GDK_7:
+ case GDK_8:
+ case GDK_9:
+ case GDK_0:
+ switch ( element_number )
+ {
+ case TRANSACTION_FORM_DEBIT:
+ widget_prov = bet_form_widget_get_widget ( TRANSACTION_FORM_CREDIT );
+ if ( !gsb_form_widget_check_empty ( widget_prov ) )
+ {
+ gtk_entry_set_text ( GTK_ENTRY ( widget_prov ),
+ gsb_form_widget_get_name ( TRANSACTION_FORM_CREDIT ) );
+ gsb_form_widget_set_empty ( widget_prov, TRUE );
+ }
+ break;
+ case TRANSACTION_FORM_CREDIT:
+ widget_prov = bet_form_widget_get_widget ( TRANSACTION_FORM_DEBIT );
+ if ( !gsb_form_widget_check_empty ( widget_prov ) )
+ {
+ gtk_entry_set_text ( GTK_ENTRY (widget_prov),
+ gsb_form_widget_get_name (TRANSACTION_FORM_DEBIT));
+ gsb_form_widget_set_empty ( widget_prov, TRUE );
+ }
+ break;
+ }
+ break;
+ case GDK_Escape :
+ gsb_form_escape_form ();
+ break;
+
+ case GDK_KP_Enter :
+ case GDK_Return :
+
+ break;
+
+ case GDK_KP_Add:
+ case GDK_plus:
+ case GDK_equal: /* This should make all our US users happy */
+
+ /* increase the check of 1 */
+ if (element_number == TRANSACTION_FORM_CHEQUE)
+ {
+ increment_decrement_champ ( widget,
+ 1 );
+ return TRUE;
+ }
+ break;
+
+ case GDK_KP_Subtract:
+ case GDK_minus:
+
+ /* decrease the check of 1 */
+ if (element_number == TRANSACTION_FORM_CHEQUE)
+ {
+ increment_decrement_champ ( widget,
+ -1 );
+ return TRUE;
+ }
+ break;
+ }
+
+ return FALSE;
+}
+
+
+/**
+ * called when we press the button in an entry field in
+ * the form
+ *
+ * \param entry wich receive the signal
+ * \param ev can be NULL
+ * \param ptr_origin a pointer to int on the element_number
+ *
+ * \return FALSE
+ * */
+gboolean bet_form_button_press_event ( GtkWidget *entry,
+ GdkEventButton *ev,
+ gint *ptr_origin )
+{
+ GtkWidget *date_entry;
+ gint element_number;
+
+
+ element_number = GPOINTER_TO_INT ( ptr_origin );
+
+ /* set the current date into the date entry */
+ date_entry = bet_form_widget_get_widget (TRANSACTION_FORM_DATE);
+ if ( gsb_form_widget_check_empty ( date_entry ) )
+ {
+ gtk_entry_set_text ( GTK_ENTRY ( date_entry ), gsb_date_today ( ) );
+ gsb_form_widget_set_empty ( date_entry, FALSE );
+ }
+
+ return FALSE;
+}
+
+
+/**
+ * initialise les données du formulaire
+ *
+ *
+ *
+ * */
+gboolean bet_future_set_form_data_from_line ( gint account_number,
+ gint number )
+{
+ GtkWidget *widget;
+ GHashTable *future_list;
+ gchar *key;
+ const gchar *tmp_str;
+ struct_futur_data *scheduled;
+
+ if ( account_number == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( account_number ), ":",
+ utils_str_itoa ( number ), NULL );
+
+ future_list = bet_data_future_get_list ( );
+
+ scheduled = g_hash_table_lookup ( future_list, key );
+ if ( scheduled == NULL )
+ return FALSE;
+
+ /* On traite les données de la planification */
+ widget = bet_form_scheduler_get_element_widget ( SCHEDULED_FORM_FREQUENCY_BUTTON );
+ gsb_combo_box_set_index ( widget, scheduled -> frequency );
+ gtk_widget_set_sensitive ( widget, FALSE );
+
+ if ( scheduled -> frequency > 0 )
+ {
+ if ( scheduled -> limit_date && g_date_valid ( scheduled -> limit_date ) )
+ {
+ widget = bet_form_scheduler_get_element_widget ( SCHEDULED_FORM_LIMIT_DATE );
+ gsb_form_widget_set_empty ( widget, FALSE );
+ gsb_calendar_entry_set_date ( widget, scheduled -> limit_date );
+ gtk_widget_set_sensitive ( widget, FALSE );
+ }
+
+ if ( scheduled -> user_entry > 0 )
+ {
+ widget = bet_form_scheduler_get_element_widget (
+ SCHEDULED_FORM_FREQUENCY_USER_ENTRY );
+ gsb_form_widget_set_empty ( widget, FALSE );
+ gtk_entry_set_text ( GTK_ENTRY ( widget ),
+ utils_str_itoa ( scheduled -> user_entry ) );
+ gtk_widget_set_sensitive ( widget, FALSE );
+
+ widget = bet_form_scheduler_get_element_widget (
+ SCHEDULED_FORM_FREQUENCY_USER_BUTTON );
+ gsb_combo_box_set_index ( widget, scheduled -> user_interval );
+ gtk_widget_set_sensitive ( widget, FALSE );
+ }
+ }
+
+ /* On traite les données de transaction */
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_DATE );
+ gsb_calendar_entry_set_date ( widget, scheduled -> date );
+ gsb_form_widget_set_empty ( widget, FALSE );
+
+ if ( scheduled -> fyear_number > 0 )
+ {
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_EXERCICE );
+ gsb_fyear_set_combobox_history ( widget, scheduled -> fyear_number );
+ }
+
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_PARTY );
+ tmp_str = gsb_data_payee_get_name ( scheduled -> party_number, TRUE );
+ if ( tmp_str && strlen ( tmp_str ) )
+ {
+ gsb_form_widget_set_empty ( GTK_COMBOFIX ( widget ) -> entry, FALSE );
+ gtk_combofix_set_text ( GTK_COMBOFIX ( widget ), tmp_str );
+ gtk_editable_set_position ( GTK_EDITABLE ( GTK_COMBOFIX ( widget ) -> entry ), 0 );
+ }
+
+ if ( scheduled -> amount.mantissa < 0 )
+ {
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_DEBIT );
+ gtk_entry_set_text ( GTK_ENTRY ( widget ), gsb_real_get_string (
+ gsb_real_opposite ( scheduled -> amount ) ) );
+ }
+ else
+ {
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_CREDIT );
+ gtk_entry_set_text ( GTK_ENTRY ( widget ), gsb_real_get_string ( scheduled -> amount ) );
+ }
+ gsb_form_widget_set_empty ( widget, FALSE );
+
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_TYPE );
+ gsb_payment_method_set_combobox_history ( widget, scheduled -> payment_number );
+
+ if ( scheduled -> category_number > 0 )
+ {
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_CATEGORY );
+ gsb_form_widget_set_empty ( GTK_COMBOFIX ( widget ) -> entry, FALSE );
+ gtk_combofix_set_text ( GTK_COMBOFIX ( widget ),
+ gsb_data_category_get_name ( scheduled -> category_number,
+ scheduled -> sub_category_number, NULL) );
+ }
+ else if ( scheduled -> is_transfert )
+ {
+ gchar *tmp_str;
+
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_CATEGORY );
+ gsb_form_widget_set_empty ( GTK_COMBOFIX ( widget ) -> entry, FALSE );
+ tmp_str = g_strconcat ( _("Transfer"), " : ",
+ gsb_data_account_get_name ( scheduled -> account_transfert ),
+ NULL );
+
+ gtk_combofix_set_text ( GTK_COMBOFIX ( widget ), tmp_str );
+ g_free ( tmp_str );
+ }
+
+ if ( scheduled -> budgetary_number > 0 )
+ {
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_BUDGET );
+ gsb_form_widget_set_empty ( GTK_COMBOFIX ( widget ) -> entry, FALSE );
+ gtk_combofix_set_text ( GTK_COMBOFIX ( widget ),
+ gsb_data_budget_get_name ( scheduled -> budgetary_number,
+ scheduled -> sub_budgetary_number, NULL ) );
+ }
+
+ if ( scheduled -> notes && strlen ( scheduled -> notes ) > 0 )
+ {
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_NOTES );
+ gsb_form_widget_set_empty ( widget, FALSE );
+ gtk_entry_set_text ( GTK_ENTRY ( widget ), scheduled -> notes );
+ }
+
+ return TRUE;
+}
+
+
+/**
+ * récupère les données du formulaire
+ *
+ *
+ *
+ * */
+gboolean bet_future_take_data_from_form ( struct_futur_data *scheduled )
+{
+ GtkWidget *widget;
+
+ /* données liées au compte */
+ scheduled -> account_number = gsb_gui_navigation_get_current_account ( );
+
+ /* On traite les données de la planification */
+ widget = bet_form_scheduler_get_element_widget ( SCHEDULED_FORM_FREQUENCY_BUTTON );
+ scheduled -> frequency = gsb_combo_box_get_index ( widget );
+
+ switch ( scheduled -> frequency )
+ {
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ widget = bet_form_scheduler_get_element_widget ( SCHEDULED_FORM_LIMIT_DATE );
+ if ( gsb_form_widget_check_empty ( widget ) == FALSE )
+ scheduled -> limit_date = gsb_calendar_entry_get_date ( widget );
+ else
+ scheduled -> limit_date = NULL;
+ break;
+ case 6:
+ widget = bet_form_scheduler_get_element_widget ( SCHEDULED_FORM_LIMIT_DATE );
+ if ( gsb_form_widget_check_empty ( widget ) == FALSE )
+ scheduled -> limit_date = gsb_calendar_entry_get_date ( widget );
+ else
+ scheduled -> limit_date = NULL;
+
+ widget = bet_form_scheduler_get_element_widget (
+ SCHEDULED_FORM_FREQUENCY_USER_ENTRY );
+ if ( gsb_form_widget_check_empty ( widget ) == FALSE )
+ scheduled -> user_entry = utils_str_atoi (
+ gtk_entry_get_text ( GTK_ENTRY ( widget ) ) );
+ if ( scheduled -> user_entry )
+ {
+ widget = bet_form_scheduler_get_element_widget (
+ SCHEDULED_FORM_FREQUENCY_USER_BUTTON );
+ scheduled -> user_interval = gsb_combo_box_get_index ( widget );
+ }
+ else
+ return FALSE;
+ }
+
+ /* On traite les données de transaction */
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_DATE );
+ if ( gsb_form_widget_check_empty ( widget ) == FALSE )
+ {
+ GDate *date_tomorrow;
+
+ date_tomorrow = gsb_date_tomorrow ( );
+ scheduled -> date = gsb_calendar_entry_get_date ( widget );
+ if ( scheduled -> date == NULL
+ ||
+ g_date_compare ( scheduled -> date, date_tomorrow ) < 0 )
+ {
+ g_date_free ( date_tomorrow );
+ return FALSE;
+ }
+ g_date_free ( date_tomorrow );
+ }
+ else
+ return FALSE;
+
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_EXERCICE );
+ if ( gsb_form_widget_check_empty( widget ) == FALSE )
+ scheduled -> fyear_number = gsb_fyear_get_fyear_from_combobox ( widget,
+ scheduled -> date );
+ else
+ scheduled -> fyear_number = 0;
+
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_PARTY );
+ if ( gsb_form_widget_check_empty ( widget ) == FALSE )
+ scheduled -> party_number = gsb_data_payee_get_number_by_name (
+ gtk_combofix_get_text ( GTK_COMBOFIX ( widget ) ), TRUE );
+ else
+ scheduled -> party_number = 0;
+
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_DEBIT );
+ if ( gsb_form_widget_check_empty ( widget ) == FALSE )
+ {
+ gsb_form_check_auto_separator ( widget );
+ scheduled -> amount = gsb_real_opposite (
+ gsb_utils_edit_calculate_entry ( widget ) );
+ }
+ else
+ {
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_CREDIT );
+ if ( gsb_form_widget_check_empty ( widget ) == FALSE )
+ {
+ gsb_form_check_auto_separator ( widget );
+ scheduled -> amount = gsb_utils_edit_calculate_entry ( widget );
+ }
+ else
+ return FALSE;
+ }
+
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_TYPE );
+ if ( gsb_form_widget_check_empty( widget ) == FALSE )
+ scheduled -> payment_number =
+ gsb_payment_method_get_selected_number ( widget );
+ else
+ scheduled -> payment_number = 0;
+
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_CATEGORY );
+ if ( gsb_form_widget_check_empty( widget ) == FALSE )
+ bet_future_get_category_data ( widget, 0, ( gpointer ) scheduled );
+ else
+ {
+ scheduled -> category_number = 0;
+ scheduled -> sub_category_number = 0;
+ }
+
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_BUDGET );
+ if ( gsb_form_widget_check_empty( widget ) == FALSE )
+ bet_future_get_budget_data ( widget, 0, ( gpointer ) scheduled );
+ else
+ {
+ scheduled -> budgetary_number = 0;
+ scheduled -> sub_budgetary_number = 0;
+ }
+
+ widget = bet_form_widget_get_widget ( TRANSACTION_FORM_NOTES );
+ if ( gsb_form_widget_check_empty( widget ) == FALSE )
+ scheduled -> notes = g_strdup ( gtk_entry_get_text ( GTK_ENTRY ( widget ) ) );
+ else
+ scheduled -> notes = NULL;
+
+ return TRUE;
+}
+
+
+/**
+ * récupère l'imputation et la sous imputation budgétaire
+ *
+ *
+ * \return FALSE
+ * */
+gboolean bet_future_get_budget_data ( GtkWidget *widget,
+ gint struct_type,
+ gpointer *value )
+{
+ const gchar *string;
+ gchar **tab_char;
+ gint budgetary_number;
+ gint sub_budgetary_number;
+
+ string = gtk_combofix_get_text ( GTK_COMBOFIX ( widget ) );
+ if ( string && strlen ( string ) > 0 )
+ {
+ tab_char = g_strsplit ( string, " : ", 2 );
+ budgetary_number = gsb_data_budget_get_number_by_name (
+ tab_char[0], FALSE, 0 );
+
+ if ( tab_char[1] && strlen ( tab_char[1] ) )
+ sub_budgetary_number = gsb_data_budget_get_sub_budget_number_by_name (
+ budgetary_number, tab_char[1], FALSE );
+ else
+ sub_budgetary_number = 0;
+
+ g_strfreev ( tab_char );
+ }
+ else
+ {
+ budgetary_number = 0;
+ sub_budgetary_number = 0;
+ }
+
+ if ( struct_type == 0 )
+ {
+ struct_futur_data *sd = ( struct_futur_data *) value;
+
+ sd -> budgetary_number = budgetary_number;
+ sd -> sub_budgetary_number = sub_budgetary_number;
+ }
+ else if ( struct_type == 0 )
+ {
+ struct_transfert_data *sd = ( struct_transfert_data *) value;
+
+ sd -> budgetary_number = budgetary_number;
+ sd -> sub_budgetary_number = sub_budgetary_number;
+ }
+
+ return FALSE;
+}
+
+
+/**
+ * récupère la catégorie et la sous catégorie
+ *
+ *
+ * \return FALSE
+ * */
+gboolean bet_future_get_category_data ( GtkWidget *widget,
+ gint struct_type,
+ gpointer *value )
+{
+ const gchar *string;
+ gchar **tab_char;
+ gint category_number = 0;
+ gint sub_category_number = 0;
+
+ string = gtk_combofix_get_text ( GTK_COMBOFIX ( widget ) );
+
+ if ( struct_type == 0 )
+ {
+ struct_futur_data *sd = ( struct_futur_data *) value;
+
+ if ( string && strlen ( string ) > 0 )
+ {
+ tab_char = g_strsplit ( string, " : ", 2 );
+ if ( my_strcasecmp ( tab_char[0], _("Transfer") ) == 0 )
+ {
+ sd -> is_transfert = TRUE;
+ sd -> account_transfert = gsb_data_account_get_no_account_by_name ( tab_char[1] );
+ }
+ else
+ {
+ category_number = gsb_data_category_get_number_by_name (
+ tab_char[0], FALSE, 0 );
+
+ if ( tab_char[1] && strlen ( tab_char[1] ) )
+ sub_category_number = gsb_data_category_get_sub_category_number_by_name (
+ category_number, tab_char[1], FALSE );
+ else
+ sub_category_number = 0;
+ }
+
+ g_strfreev ( tab_char );
+ }
+ else
+ {
+ category_number = 0;
+ category_number = 0;
+ }
+
+ sd -> category_number = category_number;
+ sd -> sub_category_number = sub_category_number;
+ }
+ else if ( struct_type == 1 )
+ {
+ struct_transfert_data *sd = ( struct_transfert_data *) value;
+
+ if ( string && strlen ( string ) > 0 )
+ {
+ tab_char = g_strsplit ( string, " : ", 2 );
+ category_number = gsb_data_category_get_number_by_name (
+ tab_char[0], FALSE, 0 );
+
+ if ( tab_char[1] && strlen ( tab_char[1] ) )
+ sub_category_number = gsb_data_category_get_sub_category_number_by_name (
+ category_number, tab_char[1], FALSE );
+ else
+ sub_category_number = 0;
+
+ g_strfreev ( tab_char );
+ }
+ else
+ {
+ category_number = 0;
+ category_number = 0;
+ }
+
+ sd -> category_number = category_number;
+ sd -> sub_category_number = sub_category_number;
+ }
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_future_modify_line ( gint account_number,
+ gint number,
+ gint mother_row )
+{
+ gchar *tmp_str;
+ gint result;
+
+ if ( bet_futur_dialog == NULL )
+ {
+ bet_futur_dialog = bet_future_create_dialog ( account_number );
+ }
+ else
+ {
+ bet_form_clean ( account_number );
+ gtk_widget_show ( bet_futur_dialog );
+ }
+
+ /* init data */
+ bet_future_set_form_data_from_line ( account_number, number );
+
+dialog_return:
+ result = gtk_dialog_run ( GTK_DIALOG ( bet_futur_dialog ) );
+
+ if ( result == GTK_RESPONSE_OK )
+ {
+ struct_futur_data *scheduled;
+
+ scheduled = struct_initialise_bet_future ( );
+
+ if ( !scheduled )
+ {
+ dialogue_error_memory ();
+ gtk_widget_hide ( bet_futur_dialog );
+ return FALSE;
+ }
+
+ if ( bet_future_take_data_from_form ( scheduled ) == FALSE )
+ {
+ tmp_str = g_strdup ( _("Error: the frequency defined by the user or the amount is "
+ "not specified or the date is invalid.") );
+ dialogue_warning_hint ( tmp_str, _("One field is not filled in") );
+ g_free ( tmp_str );
+ goto dialog_return;
+ }
+ else
+ {
+ scheduled -> number = number;
+ scheduled -> mother_row = mother_row;
+ bet_data_future_modify_lines ( scheduled );
+ }
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ bet_data_update_bet_module ( account_number, GSB_ESTIMATE_PAGE );
+ }
+
+ gtk_widget_hide ( bet_futur_dialog );
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_transfert_new_line_dialog ( GtkTreeModel *tab_model,
+ gchar *str_date )
+{
+ GtkWidget *widget;
+ GDate *date;
+ GDate *date_jour;
+ gint account_number;
+ gint result;
+
+ account_number = gsb_gui_navigation_get_current_account ( );
+ if ( account_number == -1 )
+ return FALSE;
+
+ /* Create the dialog */
+ if ( bet_transfert_dialog == NULL )
+ {
+ bet_transfert_dialog = bet_transfert_create_dialog ( account_number );
+ }
+ else
+ {
+ gtk_widget_show ( bet_transfert_dialog );
+ }
+
+ /* init data */
+ widget = g_object_get_data ( G_OBJECT ( bet_transfert_dialog ), "date_entry" );
+ date = gsb_parse_date_string ( str_date );
+ date_jour = gdate_today ( );
+
+ if ( g_date_valid ( date ) == FALSE )
+ date = date_jour;
+
+ gsb_form_widget_set_empty ( widget, FALSE );
+ gsb_calendar_entry_set_date ( widget, date );
+
+ gtk_dialog_set_response_sensitive ( GTK_DIALOG ( bet_transfert_dialog ),
+ GTK_RESPONSE_OK, FALSE );
+
+dialog_return:
+ result = gtk_dialog_run ( GTK_DIALOG ( bet_transfert_dialog ) );
+
+ if ( result == GTK_RESPONSE_OK )
+ {
+ GtkWidget *tree_view;
+ gchar *tmp_str;
+ struct_transfert_data *transfert;
+
+ transfert = struct_initialise_bet_transfert ( );
+
+ if ( !transfert )
+ {
+ dialogue_error_memory ();
+ gtk_widget_hide ( bet_transfert_dialog );
+ return FALSE;
+ }
+ transfert -> account_number = account_number;
+
+ tree_view = g_object_get_data ( G_OBJECT ( bet_transfert_dialog ), "tree_view" );
+ if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION (
+ gtk_tree_view_get_selection ( GTK_TREE_VIEW ( tree_view ) ) ),
+ NULL, NULL ) )
+ {
+ tmp_str = g_strdup ( _("Error: You must select an account.") );
+ dialogue_warning_hint ( tmp_str, _("Missing data") );
+ g_free ( tmp_str );
+ gtk_dialog_set_response_sensitive ( GTK_DIALOG ( bet_transfert_dialog ),
+ GTK_RESPONSE_OK, FALSE );
+ goto dialog_return;
+ }
+ else if ( bet_transfert_take_data ( transfert, bet_transfert_dialog ) == FALSE )
+ {
+ tmp_str = g_strdup ( _("Error: the frequency defined by the user or the amount is "
+ "not specified or the date is invalid.") );
+ dialogue_warning_hint ( tmp_str, _("One field is not filled in") );
+ g_free ( tmp_str );
+ goto dialog_return;
+ }
+ else
+ bet_data_transfert_add_line ( transfert );
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ bet_data_update_bet_module ( account_number, GSB_ESTIMATE_PAGE );
+ }
+
+ gtk_widget_hide ( bet_transfert_dialog );
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+GtkWidget *bet_transfert_create_dialog ( gint account_number )
+{
+ GtkWidget *dialog;
+ GtkWidget *vbox;
+ GtkWidget *paddingbox;
+ GtkWidget *hbox;
+ GtkWidget *date_entry;
+ GtkWidget *button;
+ GtkWidget *combo;
+ GtkWidget *sw;
+ GtkWidget *tree_view;
+ GtkWidget *label;
+
+ /* Create the dialog */
+ dialog = gtk_dialog_new_with_buttons ( _("Select an account"),
+ GTK_WINDOW ( window ),
+ GTK_DIALOG_MODAL,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OK, GTK_RESPONSE_OK,
+ NULL );
+
+ gtk_window_set_position ( GTK_WINDOW ( dialog ), GTK_WIN_POS_CENTER_ON_PARENT );
+ gtk_window_set_resizable ( GTK_WINDOW ( dialog ), TRUE );
+ gtk_dialog_set_default_response ( GTK_DIALOG ( dialog ), GTK_RESPONSE_OK );
+
+ vbox = gtk_vbox_new ( FALSE, 0 );
+ gtk_box_pack_start ( GTK_BOX ( GTK_DIALOG ( dialog )->vbox ), vbox, TRUE, TRUE, 0 );
+ gtk_container_set_border_width ( GTK_CONTAINER ( vbox ), 12 );
+
+ /* list of accounts */
+ paddingbox = new_paddingbox_with_title (vbox, FALSE, _("List of accounts") );
+
+ hbox = gtk_hbox_new ( FALSE, 0 );
+ gtk_box_pack_start ( GTK_BOX ( paddingbox ), hbox, TRUE, TRUE, 5 );
+
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW ( sw ),
+ GTK_SHADOW_ETCHED_IN);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_ALWAYS);
+ gtk_box_pack_start ( GTK_BOX (hbox), sw, TRUE,TRUE, 0 );
+
+ /* create the account list */
+ tree_view = bet_transfert_create_account_list_part ( dialog, account_number );
+ gtk_container_add (GTK_CONTAINER ( sw ), tree_view );
+ gtk_container_set_resize_mode (GTK_CONTAINER ( sw ), GTK_RESIZE_PARENT );
+
+ /* Others data */
+ paddingbox = new_paddingbox_with_title (vbox, FALSE,
+ _("Effective date and data for the replacement of a planned operation") );
+
+ /* Effective Date */
+ hbox = gtk_hbox_new ( FALSE, 0 );
+ gtk_box_pack_start ( GTK_BOX ( paddingbox ), hbox, FALSE, TRUE, 5 );
+
+ label = gtk_label_new ( COLON( _("Effective date") ) );
+ gtk_box_pack_start ( GTK_BOX ( hbox ), label, FALSE, FALSE, 0 );
+
+ date_entry = gsb_calendar_entry_new ( FALSE );
+ g_object_set_data ( G_OBJECT ( dialog ), "date_entry", date_entry );
+ gtk_box_pack_start ( GTK_BOX ( hbox ), date_entry, FALSE, FALSE, 0 );
+
+ button = gtk_check_button_new_with_label ( _("Monthly auto-increment") );
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button ), FALSE );
+ g_object_set_data ( G_OBJECT ( dialog ), "bet_transfert_auto_inc", button );
+ gtk_box_pack_start ( GTK_BOX ( hbox ), button, FALSE, FALSE, 5 );
+ //~ g_signal_connect ( G_OBJECT ( button ),
+ //~ "toggled",
+ //~ G_CALLBACK ( bet_transfert_auto_inc_toggle ),
+ //~ NULL );
+
+ /* check button replace planned line */
+ button = gtk_check_button_new_with_label (
+ _("Check the box to replace a planned operation") );
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button ), FALSE );
+ g_object_set_data ( G_OBJECT ( dialog ), "bet_transfert_replace_data", button );
+ gtk_box_pack_start ( GTK_BOX ( paddingbox ), button, FALSE, FALSE, 0 );
+ g_signal_connect ( G_OBJECT ( button ),
+ "toggled",
+ G_CALLBACK ( bet_transfert_replace_data_toggle ),
+ dialog );
+
+ /* Line replaced */
+ hbox = gtk_hbox_new ( FALSE, 0 );
+ gtk_box_pack_start ( GTK_BOX ( paddingbox ), hbox, FALSE, TRUE, 5 );
+
+ combo = gtk_combofix_new (
+ gsb_data_category_get_name_list ( TRUE, TRUE, FALSE, FALSE ) );
+ gtk_widget_set_size_request ( combo, width, -1 );
+ gtk_combofix_set_force_text ( GTK_COMBOFIX ( combo ),
+ etat.combofix_force_category );
+ gtk_combofix_set_max_items ( GTK_COMBOFIX ( combo ),
+ etat.combofix_max_item );
+ gtk_combofix_set_case_sensitive ( GTK_COMBOFIX ( combo ),
+ etat.combofix_case_sensitive );
+ gtk_combofix_set_mixed_sort ( GTK_COMBOFIX ( combo ),
+ etat.combofix_mixed_sort );
+ gtk_box_pack_start ( GTK_BOX ( hbox ), combo, FALSE, FALSE, 0 );
+ gsb_form_widget_set_empty ( GTK_COMBOFIX ( combo ) -> entry, TRUE );
+ gtk_combofix_set_text ( GTK_COMBOFIX ( combo ), _("Categories : Sub-categories") );
+ g_object_set_data ( G_OBJECT ( GTK_COMBOFIX ( combo ) -> entry ), "combo", combo );
+ g_object_set_data ( G_OBJECT ( dialog ), "bet_transfert_category_combo", combo );
+
+ g_signal_connect ( G_OBJECT ( GTK_COMBOFIX ( combo ) -> entry ),
+ "focus-in-event",
+ G_CALLBACK ( bet_form_entry_get_focus ),
+ NULL );
+ g_signal_connect ( G_OBJECT ( GTK_COMBOFIX ( combo ) -> entry ),
+ "focus-out-event",
+ G_CALLBACK ( bet_transfert_entry_lose_focus ),
+ GINT_TO_POINTER ( TRANSACTION_FORM_CATEGORY ) );
+ gtk_widget_set_sensitive ( combo, FALSE );
+
+ combo = gtk_combofix_new (
+ gsb_data_budget_get_name_list ( TRUE, TRUE ) );
+ gtk_widget_set_size_request ( combo, width, -1 );
+ gtk_combofix_set_force_text ( GTK_COMBOFIX ( combo ),
+ etat.combofix_force_category );
+ gtk_combofix_set_max_items ( GTK_COMBOFIX ( combo ),
+ etat.combofix_max_item );
+ gtk_combofix_set_case_sensitive ( GTK_COMBOFIX ( combo ),
+ etat.combofix_case_sensitive );
+ gtk_combofix_set_mixed_sort ( GTK_COMBOFIX ( combo ),
+ etat.combofix_mixed_sort );
+ gtk_box_pack_start ( GTK_BOX ( hbox ), combo, FALSE, FALSE, 0 );
+ gsb_form_widget_set_empty ( GTK_COMBOFIX ( combo ) -> entry, TRUE );
+ gtk_combofix_set_text ( GTK_COMBOFIX ( combo ), _("Budgetary line") );
+ g_object_set_data ( G_OBJECT ( GTK_COMBOFIX ( combo ) -> entry ), "combo", combo );
+ g_object_set_data ( G_OBJECT ( dialog ), "bet_transfert_budget_combo", combo );
+
+ g_signal_connect ( G_OBJECT ( GTK_COMBOFIX ( combo ) -> entry ),
+ "focus-in-event",
+ G_CALLBACK ( bet_form_entry_get_focus ),
+ NULL );
+ g_signal_connect ( G_OBJECT ( GTK_COMBOFIX ( combo ) -> entry ),
+ "focus-out-event",
+ G_CALLBACK ( bet_transfert_entry_lose_focus ),
+ GINT_TO_POINTER ( TRANSACTION_FORM_BUDGET ) );
+ gtk_widget_set_sensitive ( combo, FALSE );
+
+ gtk_widget_show_all ( dialog );
+
+ return dialog;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+GtkWidget *bet_transfert_create_account_list_part ( GtkWidget *dialog, gint account_number )
+{
+ GtkWidget *tree_view;
+ GtkListStore *list_store;
+ GtkTreeViewColumn *column;
+ GtkCellRenderer *cell;
+ GtkTreeSelection *selection;
+ GSList *tmp_list;
+ gint nbre_rows = 0;
+
+ /* create the model */
+ list_store = gtk_list_store_new ( 4,
+ G_TYPE_STRING, /* account name */
+ G_TYPE_STRING, /* account kind : Cash account or Partial balance */
+ G_TYPE_INT, /* account_number or partial_balance_number */
+ G_TYPE_BOOLEAN ); /* FALSE = account, TRUE = partial balance */
+
+ /* populate the model if necessary */
+ tmp_list = gsb_data_account_get_list_accounts ( );
+ while ( tmp_list )
+ {
+ gint tmp_account_number;
+ kind_account type_compte;
+ GtkTreeIter iter;
+
+ tmp_account_number = gsb_data_account_get_no_account ( tmp_list -> data );
+
+ if ( tmp_account_number != account_number )
+ {
+ type_compte = gsb_data_account_get_kind ( tmp_account_number );
+ if ( type_compte == GSB_TYPE_CASH )
+ {
+ gtk_list_store_append ( list_store, &iter );
+ gtk_list_store_set ( list_store,
+ &iter,
+ 0, gsb_data_account_get_name ( tmp_account_number ),
+ 1, _("Cash account"),
+ 2, tmp_account_number,
+ 3, FALSE,
+ -1 );
+ nbre_rows ++;
+ }
+ }
+
+ tmp_list = tmp_list -> next;
+ }
+
+ tmp_list = gsb_data_partial_balance_get_list ( );
+ while ( tmp_list )
+ {
+ gint tmp_number;
+ kind_account type_compte;
+ GtkTreeIter iter;
+
+ tmp_number = gsb_data_partial_balance_get_number ( tmp_list -> data );
+ type_compte = gsb_data_partial_balance_get_kind ( tmp_number );
+ if ( type_compte == GSB_TYPE_CASH )
+ {
+ gtk_list_store_append ( list_store, &iter );
+ gtk_list_store_set ( list_store,
+ &iter,
+ 0, gsb_data_partial_balance_get_name ( tmp_number ),
+ 1, _("Partial balance"),
+ 2, tmp_number,
+ 3, TRUE,
+ -1 );
+ nbre_rows ++;
+ }
+
+ tmp_list = tmp_list -> next;
+ }
+
+ if ( nbre_rows == 0 )
+ return NULL;
+
+ /* create the treeview */
+ tree_view = gtk_tree_view_new_with_model ( GTK_TREE_MODEL ( list_store ) );
+ g_object_unref ( list_store );
+
+ gtk_tree_view_set_rules_hint ( GTK_TREE_VIEW ( tree_view ), TRUE );
+ gtk_widget_set_size_request ( tree_view, 400, 150 );
+ g_object_set_data ( G_OBJECT ( dialog ), "tree_view", tree_view );
+
+ /* Account_name */
+ cell = gtk_cell_renderer_text_new ( );
+ column = gtk_tree_view_column_new_with_attributes ( _("Name"),
+ cell, "text", 0, NULL );
+ gtk_tree_view_column_set_expand ( column, TRUE );
+ gtk_tree_view_column_set_alignment ( column, 0.5 );
+ gtk_tree_view_column_set_sort_column_id ( column, 0 );
+ gtk_tree_view_append_column ( GTK_TREE_VIEW ( tree_view ), column );
+
+ /* type of account */
+ cell = gtk_cell_renderer_text_new ( );
+ column = gtk_tree_view_column_new_with_attributes ( _("Type"),
+ cell, "text", 1, NULL );
+ gtk_tree_view_column_set_expand ( column, TRUE );
+ gtk_tree_view_column_set_alignment ( column, 0.5 );
+ gtk_tree_view_column_set_sort_column_id ( column, 1 );
+ gtk_tree_view_append_column ( GTK_TREE_VIEW ( tree_view ), column );
+
+ selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW ( tree_view ) );
+ g_signal_connect ( G_OBJECT ( selection ),
+ "changed",
+ G_CALLBACK ( bet_transfert_selection_changed ),
+ dialog );
+
+ return tree_view;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_transfert_selection_changed ( GtkTreeSelection *selection, GtkWidget *dialog )
+{
+ if ( !GTK_IS_DIALOG ( dialog ) )
+ return FALSE;
+
+ if ( gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( selection ), NULL, NULL ) )
+ gtk_dialog_set_response_sensitive ( GTK_DIALOG ( dialog ), GTK_RESPONSE_OK, TRUE );
+ else
+ gtk_dialog_set_response_sensitive ( GTK_DIALOG ( dialog ), GTK_RESPONSE_OK, FALSE );
+
+ return TRUE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_transfert_entry_lose_focus ( GtkWidget *entry,
+ GdkEventFocus *ev,
+ gint *ptr_origin )
+{
+ GtkWidget *widget;
+ gchar *string;
+ gint element_number;
+ gint account_number;
+
+ /* still not found, if change the content of the form, something come in entry
+ * wich is nothing, so protect here */
+ if ( !GTK_IS_WIDGET ( entry )
+ ||
+ !GTK_IS_ENTRY ( entry ) )
+ return FALSE;
+
+ /* remove the selection */
+ gtk_editable_select_region ( GTK_EDITABLE ( entry ), 0, 0 );
+
+ element_number = GPOINTER_TO_INT ( ptr_origin );
+ if ( element_number != TRANSACTION_FORM_CATEGORY
+ &&
+ element_number != TRANSACTION_FORM_BUDGET )
+ return FALSE;
+
+ widget = g_object_get_data ( G_OBJECT ( entry ), "combo" );
+ account_number = gsb_form_get_account_number ();
+
+ /* sometimes the combofix popus stays showed, so remove here */
+ gtk_combofix_hide_popup ( GTK_COMBOFIX ( widget ) );
+
+ /* string will be filled only if the field is empty */
+ string = NULL;
+ switch ( element_number )
+ {
+ case TRANSACTION_FORM_CATEGORY :
+ if ( !strlen ( gtk_entry_get_text ( GTK_ENTRY ( entry ) ) ) )
+ string = gsb_form_widget_get_name ( TRANSACTION_FORM_CATEGORY );
+ break;
+
+ case TRANSACTION_FORM_BUDGET :
+ if ( !strlen ( gtk_entry_get_text ( GTK_ENTRY ( entry ) ) ) )
+ string = gsb_form_widget_get_name ( TRANSACTION_FORM_BUDGET );
+ break;
+
+ default :
+ break;
+
+ }
+
+ /* if string is not NULL, the entry is empty so set the empty field to TRUE */
+ if ( string )
+ {
+ switch ( element_number)
+ {
+ case TRANSACTION_FORM_CATEGORY :
+ case TRANSACTION_FORM_BUDGET :
+ /* need to work with the combofix to avoid some signals if we work
+ * directly on the entry */
+ gtk_combofix_set_text ( GTK_COMBOFIX ( widget ), _(string) );
+ break;
+
+ default:
+ gtk_entry_set_text ( GTK_ENTRY ( entry ), string );
+ break;
+ }
+ gsb_form_widget_set_empty ( entry, TRUE );
+ }
+
+ return FALSE;
+}
+
+
+/**
+ * récupère les données du formulaire dialog
+ *
+ *
+ *\return TRUE if OK FALSE if error
+ * */
+gboolean bet_transfert_take_data ( struct_transfert_data *transfert, GtkWidget *dialog )
+{
+ GtkWidget *widget;
+ GtkTreeView *tree_view;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gint replace_account;
+ gint type;
+
+ tree_view = g_object_get_data ( G_OBJECT ( dialog ), "tree_view" );
+ gtk_tree_selection_get_selected ( GTK_TREE_SELECTION (
+ gtk_tree_view_get_selection ( GTK_TREE_VIEW ( tree_view ) ) ),
+ &model, &iter );
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
+ 2, &replace_account,
+ 3, &type,
+ -1 );
+ transfert -> replace_account = replace_account;
+ transfert -> type = type;
+
+ widget = g_object_get_data ( G_OBJECT ( dialog ), "date_entry" );
+ if ( gsb_form_widget_check_empty ( widget ) == FALSE )
+ {
+ transfert -> date = gsb_calendar_entry_get_date ( widget );
+ if ( transfert -> date == NULL )
+ return FALSE;
+ }
+ else
+ return FALSE;
+
+ widget = g_object_get_data ( G_OBJECT ( dialog ), "bet_transfert_category_combo" );
+ if ( gsb_form_widget_check_empty( widget ) == FALSE )
+ bet_future_get_category_data ( widget, 1, ( gpointer ) transfert );
+ else
+ {
+ transfert -> category_number = 0;
+ transfert -> sub_category_number = 0;
+ }
+
+ widget = g_object_get_data ( G_OBJECT ( dialog ), "bet_transfert_budget_combo" );
+ if ( gsb_form_widget_check_empty( widget ) == FALSE )
+ bet_future_get_budget_data ( widget, 1, ( gpointer ) transfert );
+ else
+ {
+ transfert -> budgetary_number = 0;
+ transfert -> sub_budgetary_number = 0;
+ }
+
+ widget = g_object_get_data ( G_OBJECT ( dialog ), "bet_transfert_auto_inc" );
+ transfert -> auto_inc_month = gtk_toggle_button_get_active (
+ GTK_TOGGLE_BUTTON ( widget ) );
+
+ widget = g_object_get_data ( G_OBJECT ( dialog ), "bet_transfert_replace_data" );
+ transfert -> replace_transaction = gtk_toggle_button_get_active (
+ GTK_TOGGLE_BUTTON ( widget ) );
+
+ return TRUE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gchar *gsb_transfert_get_str_amount ( struct_transfert_data *transfert, gsb_real amount )
+{
+ gchar *string = NULL;
+ gint currency;
+ gint replace_currency;
+
+ 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
+ {
+ gsb_real tmp_real = null_real;
+ gint link_number;
+
+ 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 ) );
+ }
+
+ string = gsb_real_get_string_with_currency ( tmp_real, currency, TRUE );
+ }
+
+ return string;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_transfert_modify_line ( gint account_number, gint number )
+{
+ gint result;
+
+ if ( bet_transfert_dialog == NULL )
+ bet_transfert_dialog = bet_transfert_create_dialog ( account_number );
+ else
+ gtk_widget_show ( bet_transfert_dialog );
+
+ /* init data */
+ bet_transfert_set_form_data_from_line ( account_number, number );
+
+dialog_return:
+ result = gtk_dialog_run ( GTK_DIALOG ( bet_transfert_dialog ) );
+
+ if ( result == GTK_RESPONSE_OK )
+ {
+ GtkWidget *tree_view;
+ gchar *tmp_str;
+ struct_transfert_data *transfert;
+
+ transfert = struct_initialise_bet_transfert ( );
+
+ if ( !transfert )
+ {
+ dialogue_error_memory ();
+ gtk_widget_hide ( bet_transfert_dialog );
+ return FALSE;
+ }
+ transfert -> account_number = account_number;
+
+ tree_view = g_object_get_data ( G_OBJECT ( bet_transfert_dialog ), "tree_view" );
+ if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION (
+ gtk_tree_view_get_selection ( GTK_TREE_VIEW ( tree_view ) ) ),
+ NULL, NULL ) )
+ {
+ tmp_str = g_strdup ( _("Error: You must select an account.") );
+ dialogue_warning_hint ( tmp_str, _("Missing data") );
+ g_free ( tmp_str );
+ gtk_dialog_set_response_sensitive ( GTK_DIALOG ( bet_transfert_dialog ),
+ GTK_RESPONSE_OK, FALSE );
+ goto dialog_return;
+ }
+ else if ( bet_transfert_take_data ( transfert, bet_transfert_dialog ) == FALSE )
+ {
+ tmp_str = g_strdup ( _("Error: the frequency defined by the user or the amount is "
+ "not specified or the date is invalid.") );
+ dialogue_warning_hint ( tmp_str, _("One field is not filled in") );
+ g_free ( tmp_str );
+ goto dialog_return;
+ }
+ else
+ {
+ transfert -> number = number;
+ bet_data_transfert_modify_line ( transfert );
+ }
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ bet_data_update_bet_module ( account_number, GSB_ESTIMATE_PAGE );
+ }
+
+ gtk_widget_hide ( bet_transfert_dialog );
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_transfert_set_form_data_from_line ( gint account_number, gint number )
+{
+ GtkWidget *widget;
+ GHashTable *transfert_list;
+ gchar *key;
+ struct_transfert_data *transfert;
+
+ if ( account_number == 0 )
+ key = g_strconcat ("0:", utils_str_itoa ( number ), NULL );
+ else
+ key = g_strconcat ( utils_str_itoa ( account_number ), ":",
+ utils_str_itoa ( number ), NULL );
+
+ transfert_list = bet_data_transfert_get_list ( );
+
+ transfert = g_hash_table_lookup ( transfert_list, key );
+ if ( transfert == NULL )
+ return FALSE;
+
+ widget = g_object_get_data ( G_OBJECT ( bet_transfert_dialog ), "date_entry" );
+ gsb_calendar_entry_set_date ( widget, transfert -> date );
+ gsb_form_widget_set_empty ( widget, FALSE );
+
+ widget = g_object_get_data ( G_OBJECT ( bet_transfert_dialog ),
+ "bet_transfert_category_combo" );
+ if ( transfert -> category_number > 0 )
+ {
+ gtk_combofix_set_text ( GTK_COMBOFIX ( widget ),
+ gsb_data_category_get_name ( transfert -> category_number,
+ transfert -> sub_category_number,
+ NULL ) );
+ gsb_form_widget_set_empty ( GTK_COMBOFIX ( widget ) -> entry, FALSE );
+ gtk_editable_set_position ( GTK_EDITABLE ( GTK_COMBOFIX ( widget ) -> entry), 0 );
+ }
+ else
+ {
+ gtk_combofix_set_text ( GTK_COMBOFIX ( widget ), _("Categories : Sub-categories") );
+ gsb_form_widget_set_empty ( GTK_COMBOFIX ( widget ) -> entry, TRUE );
+ }
+
+ gtk_widget_set_sensitive ( widget, transfert -> replace_transaction );
+
+ widget = g_object_get_data ( G_OBJECT ( bet_transfert_dialog ),
+ "bet_transfert_budget_combo" );
+ if ( transfert -> budgetary_number > 0 )
+ {
+ gtk_combofix_set_text ( GTK_COMBOFIX ( widget ),
+ gsb_data_budget_get_name ( transfert -> category_number,
+ transfert -> sub_category_number,
+ NULL ) );
+ gsb_form_widget_set_empty ( GTK_COMBOFIX ( widget ) -> entry, FALSE );
+ }
+ else
+ {
+ gtk_combofix_set_text ( GTK_COMBOFIX ( widget ), _("Budgetary line") );
+ gsb_form_widget_set_empty ( GTK_COMBOFIX ( widget ) -> entry, TRUE );
+ }
+
+ gtk_widget_set_sensitive ( widget, transfert -> replace_transaction );
+
+ widget = g_object_get_data ( G_OBJECT ( bet_transfert_dialog ),
+ "bet_transfert_auto_inc" );
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( widget ),
+ transfert -> auto_inc_month );
+
+ widget = g_object_get_data ( G_OBJECT ( bet_transfert_dialog ),
+ "bet_transfert_replace_data" );
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( widget ),
+ transfert -> replace_transaction );
+
+ return TRUE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+/*void bet_transfert_auto_inc_toggle ( GtkToggleButton *button, gpointer data )
+{
+ gint account_number;
+
+ account_number = gsb_gui_navigation_get_current_account ( );
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ bet_data_update_bet_module ( account_number, GSB_ESTIMATE_PAGE );
+}*/
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_transfert_replace_data_toggle ( GtkToggleButton *button, GtkWidget *dialog )
+{
+ GtkWidget *widget;
+
+ if ( gtk_toggle_button_get_active ( button ) )
+ {
+ widget = g_object_get_data ( G_OBJECT ( bet_transfert_dialog ),
+ "bet_transfert_category_combo" );
+ gtk_widget_set_sensitive ( widget, TRUE );
+ widget = g_object_get_data ( G_OBJECT ( bet_transfert_dialog ),
+ "bet_transfert_budget_combo" );
+ gtk_widget_set_sensitive ( widget, TRUE );
+ }
+ else
+ {
+ widget = g_object_get_data ( G_OBJECT ( bet_transfert_dialog ),
+ "bet_transfert_category_combo" );
+ gtk_widget_set_sensitive ( widget, FALSE );
+ widget = g_object_get_data ( G_OBJECT ( bet_transfert_dialog ),
+ "bet_transfert_budget_combo" );
+ gtk_widget_set_sensitive ( widget, FALSE );
+ }
+
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+
+/* Local Variables: */
+/* c-basic-offset: 4 */
+/* End: */
diff --git a/src/bet_future.h b/src/bet_future.h
new file mode 100644
index 0000000..af8a5e5
--- /dev/null
+++ b/src/bet_future.h
@@ -0,0 +1,26 @@
+#ifndef _BALANCE_ESTIMATE_FUTURE_H
+#define _BALANCE_ESTIMATE_FUTURE_H
+
+#include <gtk/gtk.h>
+
+/* START_INCLUDE_H */
+#include "gsb_real.h"
+#include "bet_data.h"
+/* END_INCLUDE_H */
+
+
+/* START_DECLARATION */
+void bet_future_initialise_dialog ( void );
+gboolean bet_future_modify_line ( gint account_number,
+ gint number,
+ gint mother_row );
+gboolean bet_future_new_line_dialog ( GtkTreeModel *tab_model,
+ gchar *str_date );
+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 );
+/* END_DECLARATION */
+
+#endif /*_BALANCE_ESTIMATE_FUTURE_H*/
+
diff --git a/src/bet_hist.c b/src/bet_hist.c
new file mode 100644
index 0000000..e21a31d
--- /dev/null
+++ b/src/bet_hist.c
@@ -0,0 +1,1672 @@
+/* ************************************************************************** */
+/* */
+/* Copyright (C) 2007 Dominique Parisot */
+/* zionly at free.org */
+/* 2008-2010 Pierre Biava (grisbi at pierre.biava.name) */
+/* 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 */
+/* the Free Software Foundation; either version 2 of the License, or */
+/* (at your option) any later version. */
+/* */
+/* This program is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
+/* GNU General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU General Public License */
+/* along with this program; if not, write to the Free Software */
+/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+/* */
+/* ************************************************************************** */
+
+/* ./configure --with-balance-estimate */
+
+#include "include.h"
+#include <config.h>
+
+/*START_INCLUDE*/
+#include "bet_hist.h"
+#include "bet_tab.h"
+#include "bet_config.h"
+#include "bet_data.h"
+#include "utils_dates.h"
+#include "gsb_data_account.h"
+#include "gsb_data_fyear.h"
+#include "gsb_data_transaction.h"
+#include "gsb_fyear.h"
+#include "gsb_real.h"
+#include "navigation.h"
+#include "traitement_variables.h"
+#include "utils_str.h"
+#include "gsb_fyear.h"
+#include "mouse.h"
+#include "structures.h"
+#include "include.h"
+#include "erreur.h"
+/*END_INCLUDE*/
+
+/*START_STATIC*/
+static void bet_historical_add_average_amount ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection );
+static void bet_historical_add_last_amount ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection );
+static gboolean bet_historical_affiche_div ( GHashTable *list_div, GtkWidget *tree_view );
+static gboolean bet_historical_amount_differ_average ( GtkTreeModel *model,
+ GtkTreeIter *iter );
+static gboolean bet_historical_button_press ( GtkWidget *tree_view,
+ GdkEventButton *ev );
+static void bet_historical_context_menu ( GtkWidget *tree_view );
+static void bet_historical_div_cell_edited (GtkCellRendererText *cell,
+ const gchar *path_string,
+ const gchar *new_text,
+ GtkWidget *tree_view );
+static void bet_historical_div_cell_editing_started (GtkCellRenderer *cell,
+ GtkCellEditable *editable,
+ const gchar *path_string,
+ GtkWidget *tree_view );
+static gboolean bet_historical_div_toggle_clicked ( GtkCellRendererToggle *renderer,
+ gchar *path_string,
+ GtkTreeModel *model );
+static gboolean bet_historical_fyear_create_combobox_store ( void );
+static gsb_real bet_historical_get_children_amount ( GtkTreeModel *model, GtkTreeIter *parent );
+static GtkWidget *bet_historical_get_data_tree_view ( GtkWidget *container );
+static gboolean bet_historical_get_full_div ( GtkTreeModel *model, GtkTreeIter *parent );
+static gboolean bet_historical_initializes_account_settings ( gint account_number );
+static void bet_historical_populate_div_model ( gpointer key,
+ gpointer value,
+ gpointer user_data );
+static void bet_historical_row_collapse_all ( GtkTreeView *tree_view,
+ GtkTreeIter *iter,
+ GtkTreeModel *model );
+static void bet_historical_row_expanded_event ( GtkTreeView *tree_view,
+ GtkTreeIter *iter,
+ GtkTreePath *path,
+ GtkTreeModel *model );
+static gboolean bet_historical_set_background_color ( GtkWidget *tree_view );
+static gboolean bet_historical_set_empty_sub_div ( GtkTreeModel *model, GtkTreeIter *parent );
+static gboolean bet_historical_set_full_sub_div ( GtkTreeModel *model, GtkTreeIter *parent );
+/*END_STATIC*/
+
+/*START_EXTERN*/
+extern GtkWidget *account_page;
+extern GdkColor couleur_fond[2];
+extern GtkWidget *notebook_general;
+extern gsb_real null_real;
+/*END_EXTERN*/
+
+/* blocage des signaux pour le tree_view pour les comptes de type GSB_TYPE_CASH */
+static gboolean hist_block_signal = FALSE;
+
+/**
+ * this is a tree model filter with 3 columns :
+ * the name, the number and a boolean to show it or not
+ * */
+GtkTreeModel *bet_fyear_model = NULL;
+
+/**
+ * this is a tree model filter from fyear_model_filter wich
+ * show only the financial years wich must be showed
+ * */
+GtkTreeModel *bet_fyear_model_filter = NULL;
+
+
+/**
+ * Create the historical page
+ *
+ *
+ *
+ * */
+GtkWidget *bet_historical_create_page ( void )
+{
+ GtkWidget *widget;
+ GtkWidget *page;
+ GtkWidget *hbox;
+ GtkWidget *align;
+ GtkWidget *label;
+ GtkWidget *button_1, *button_2;
+ GtkWidget *tree_view;
+ gchar *str_year;
+ gint year;
+ gpointer pointer;
+
+ devel_debug (NULL);
+ page = gtk_vbox_new ( FALSE, 5 );
+ gtk_widget_set_name ( page, "historical_page" );
+
+ /* titre de la page */
+ align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
+ gtk_box_pack_start ( GTK_BOX ( page ), align, FALSE, FALSE, 5) ;
+
+ label = gtk_label_new ( "bet_hist_title" );
+ gtk_container_add ( GTK_CONTAINER ( align ), label );
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_hist_title", label);
+
+ /* Choix des données sources */
+ align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
+ gtk_box_pack_start ( GTK_BOX ( page ), align, FALSE, FALSE, 5) ;
+
+ hbox = gtk_hbox_new ( FALSE, 5 );
+ gtk_container_add ( GTK_CONTAINER ( align ), hbox );
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_historical_data", hbox );
+
+ button_1 = gtk_radio_button_new_with_label ( NULL,
+ _("Categories") );
+ gtk_widget_set_name ( button_1, "bet_hist_button_1" );
+ g_signal_connect ( G_OBJECT ( button_1 ),
+ "released",
+ G_CALLBACK ( bet_config_origin_data_clicked ),
+ GINT_TO_POINTER ( 1 ) );
+
+ button_2 = gtk_radio_button_new_with_label_from_widget (
+ GTK_RADIO_BUTTON ( button_1 ),
+ _("Budgetary lines") );
+ g_signal_connect ( G_OBJECT ( button_2 ),
+ "released",
+ G_CALLBACK ( bet_config_origin_data_clicked ),
+ GINT_TO_POINTER ( 1 ) );
+
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_hist_button_1", button_1 );
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_hist_button_2", button_2 );
+ gtk_box_pack_start ( GTK_BOX ( hbox ), button_1, FALSE, FALSE, 5) ;
+ gtk_box_pack_start ( GTK_BOX ( hbox ), button_2, FALSE, FALSE, 5) ;
+
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button_1 ), TRUE );
+ bet_data_set_div_ptr ( 0 );
+
+ /* création du sélecteur de périod */
+ if ( bet_historical_fyear_create_combobox_store ( ) )
+ {
+ widget = gsb_fyear_make_combobox_new ( bet_fyear_model_filter, TRUE );
+ gtk_widget_set_name ( GTK_WIDGET ( widget ), "bet_hist_fyear_combo" );
+ gtk_widget_set_tooltip_text ( GTK_WIDGET ( widget ),
+ SPACIFY(_("Choose the financial year or 12 months rolling") ) );
+
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_hist_fyear_combo", widget );
+
+ gtk_box_pack_start ( GTK_BOX ( hbox ), widget, FALSE, FALSE, 5);
+
+ /* hide the present financial year */
+ year = g_date_get_year ( gdate_today ( ) );
+ str_year = utils_str_itoa ( year );
+ gsb_fyear_hide_iter_by_name ( bet_fyear_model, str_year );
+ g_free ( str_year );
+
+ /* set the signal */
+ pointer = GINT_TO_POINTER ( 1 );
+ g_object_set_data ( G_OBJECT ( widget ), "pointer", pointer );
+ g_signal_connect ( G_OBJECT ( widget ),
+ "changed",
+ G_CALLBACK (bet_config_fyear_clicked),
+ pointer );
+ }
+
+ /* création de la liste des données */
+ tree_view = bet_historical_get_data_tree_view ( page );
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_historical_treeview", tree_view );
+
+ gtk_widget_show_all ( page );
+
+ return page;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_historical_div_toggle_clicked ( GtkCellRendererToggle *renderer,
+ gchar *path_string,
+ GtkTreeModel *model )
+{
+ GtkTreeIter iter;
+
+ //~ devel_debug (path_string);
+ if ( gtk_tree_model_get_iter_from_string ( GTK_TREE_MODEL ( model ), &iter, path_string ) )
+ {
+ gchar *str_amount;
+ gchar *str_average;
+ gint div_number;
+ gint sub_div_nb;
+ gint nbre_fils;
+ gint account_number;
+ gboolean valeur;
+ gboolean col_edited;
+
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
+ SPP_HISTORICAL_SELECT_COLUMN, &valeur,
+ SPP_HISTORICAL_AVERAGE_COLUMN, &str_average,
+ SPP_HISTORICAL_AVERAGE_AMOUNT, &str_amount,
+ SPP_HISTORICAL_ACCOUNT_NUMBER, &account_number,
+ SPP_HISTORICAL_DIV_NUMBER, &div_number,
+ SPP_HISTORICAL_SUB_DIV_NUMBER, &sub_div_nb,
+ SPP_HISTORICAL_EDITED_COLUMN, &col_edited,
+ -1 );
+
+ if ( col_edited == FALSE && valeur == FALSE )
+ return FALSE;
+
+ if ( renderer )
+ valeur = 1 - valeur;
+
+ if ( valeur == 1 )
+ {
+ //~ printf ("avant - account_number = %d, div = %d, sub_div = %d\n",
+ //~ account_number, div, sub_div);
+ bet_data_hist_add_div ( account_number, div_number, sub_div_nb );
+ bet_data_set_div_amount ( account_number, div_number, sub_div_nb,
+ gsb_real_import_from_string ( str_amount ) );
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ), &iter,
+ SPP_HISTORICAL_SELECT_COLUMN, 1,
+ SPP_HISTORICAL_RETAINED_COLUMN, str_average,
+ SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
+ SPP_HISTORICAL_ACCOUNT_NUMBER, account_number,
+ SPP_HISTORICAL_DIV_NUMBER, div_number,
+ SPP_HISTORICAL_SUB_DIV_NUMBER, sub_div_nb,
+ -1 );
+ }
+ else
+ {
+ bet_data_remove_div_hist ( account_number, div_number, sub_div_nb );
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ), &iter,
+ SPP_HISTORICAL_SELECT_COLUMN, FALSE,
+ SPP_HISTORICAL_RETAINED_COLUMN, "",
+ SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
+ SPP_HISTORICAL_ACCOUNT_NUMBER, account_number,
+ SPP_HISTORICAL_DIV_NUMBER, div_number,
+ SPP_HISTORICAL_SUB_DIV_NUMBER, sub_div_nb,
+ SPP_HISTORICAL_EDITED_COLUMN, TRUE,
+ -1 );
+ }
+
+ nbre_fils = gtk_tree_model_iter_n_children ( GTK_TREE_MODEL ( model ), &iter );
+ if ( nbre_fils > 0 )
+ {
+ if ( valeur == 1 )
+ bet_historical_set_full_sub_div ( model, &iter );
+ else
+ bet_historical_set_empty_sub_div ( model, &iter );
+ }
+ else
+ {
+ GtkTreeIter parent;
+ gsb_real amount;
+
+ if ( gtk_tree_model_iter_parent ( GTK_TREE_MODEL ( model ), &parent, &iter ) )
+ {
+ if ( bet_historical_get_full_div ( model, &parent ) )
+ {
+ amount = bet_historical_get_children_amount ( model, &parent );
+ if ( str_amount )
+ g_free ( str_amount );
+ str_amount = gsb_real_save_real_to_string ( amount, 2 );
+ if ( str_average )
+ g_free ( str_average );
+ str_average = gsb_real_get_string_with_currency ( amount,
+ gsb_data_account_get_currency ( account_number ), TRUE );
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ &parent,
+ SPP_HISTORICAL_SELECT_COLUMN, TRUE,
+ SPP_HISTORICAL_RETAINED_COLUMN, str_average,
+ SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
+ -1);
+ if ( bet_historical_amount_differ_average ( model, &parent) )
+ bet_data_set_div_amount ( account_number, div_number, 0, amount );
+
+ bet_historical_row_collapse_all ( NULL, &parent, model );
+ }
+ else
+ {
+ bet_data_set_div_amount ( account_number, div_number, 0, null_real );
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ), &parent,
+ SPP_HISTORICAL_SELECT_COLUMN, FALSE,
+ SPP_HISTORICAL_RETAINED_COLUMN, "",
+ SPP_HISTORICAL_EDITED_COLUMN, TRUE,
+ -1 );
+ }
+ }
+ }
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ bet_data_update_bet_module ( account_number, GSB_HISTORICAL_PAGE );
+ }
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_historical_div_cell_editing_started (GtkCellRenderer *cell,
+ GtkCellEditable *editable,
+ const gchar *path_string,
+ GtkWidget *tree_view )
+{
+ if ( GTK_IS_ENTRY ( editable ) )
+ gtk_editable_delete_text ( GTK_EDITABLE ( editable ), 0, -1 );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_historical_div_cell_edited (GtkCellRendererText *cell,
+ const gchar *path_string,
+ const gchar *new_text,
+ GtkWidget *tree_view )
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ //~ devel_debug (new_text);
+ model = gtk_tree_view_get_model ( GTK_TREE_VIEW ( tree_view ) );
+ if ( gtk_tree_model_get_iter_from_string ( GTK_TREE_MODEL ( model ), &iter, path_string ) )
+ {
+ GtkTreeIter parent;
+ gboolean valeur;
+ gboolean edited;
+ gint account_number;
+ gint currency_number;
+ gint div_number;
+ gint sub_div_nb;
+ gchar *tmp_str;
+ gchar *str_amount;
+ gboolean is_parent = FALSE;
+ gsb_real number;
+
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
+ SPP_HISTORICAL_SELECT_COLUMN, &valeur,
+ SPP_HISTORICAL_ACCOUNT_NUMBER, &account_number,
+ SPP_HISTORICAL_DIV_NUMBER, &div_number,
+ SPP_HISTORICAL_SUB_DIV_NUMBER, &sub_div_nb,
+ SPP_HISTORICAL_EDITED_COLUMN, &edited,
+ -1 );
+
+ if ( edited == FALSE )
+ return;
+
+ is_parent = gtk_tree_model_iter_parent ( GTK_TREE_MODEL ( model ), &parent, &iter );
+ if ( is_parent == FALSE )
+ {
+ bet_historical_set_empty_sub_div ( model, &iter );
+ bet_historical_row_collapse_all ( GTK_TREE_VIEW ( tree_view ), &iter, model );
+ }
+
+ number = gsb_real_get_from_string ( new_text );
+ currency_number = gsb_data_account_get_currency ( account_number );
+ tmp_str = gsb_real_get_string_with_currency ( number, currency_number, TRUE );
+
+ if ( bet_data_search_div_hist ( account_number, div_number, sub_div_nb ) == FALSE )
+ bet_data_hist_add_div ( account_number, div_number, sub_div_nb );
+
+ bet_data_set_div_edited ( account_number, div_number, sub_div_nb, TRUE );
+ bet_data_set_div_amount ( account_number, div_number, sub_div_nb, number );
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ), &iter,
+ SPP_HISTORICAL_SELECT_COLUMN, TRUE,
+ SPP_HISTORICAL_RETAINED_COLUMN, tmp_str,
+ SPP_HISTORICAL_RETAINED_AMOUNT, new_text,
+ -1 );
+ g_free ( tmp_str );
+
+ if ( is_parent )
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ &parent,
+ SPP_HISTORICAL_EDITED_COLUMN, FALSE,
+ -1);
+
+ if ( is_parent && bet_historical_get_full_div ( model, &parent ) )
+ {
+ number = bet_historical_get_children_amount ( model, &parent );
+ bet_data_set_div_amount ( account_number, div_number, 0, number );
+ str_amount = gsb_real_save_real_to_string ( number, 2 );
+ tmp_str = gsb_real_get_string_with_currency ( number,
+ gsb_data_account_get_currency ( account_number ), TRUE );
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ &parent,
+ SPP_HISTORICAL_SELECT_COLUMN, TRUE,
+ SPP_HISTORICAL_RETAINED_COLUMN, tmp_str,
+ SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
+ SPP_HISTORICAL_EDITED_COLUMN, FALSE,
+ -1);
+ g_free ( str_amount );
+ g_free ( tmp_str );
+ }
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+ }
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+GtkWidget *bet_historical_get_data_tree_view ( GtkWidget *container )
+{
+ GtkWidget *scrolled_window;
+ GtkWidget *tree_view;
+ GtkTreeStore *tree_model;
+ GtkTreeSelection *tree_selection;
+ GtkCellRenderer *cell;
+ GtkTreeViewColumn *column;
+ gchar *title;
+
+ //~ devel_debug (NULL);
+ tree_view = gtk_tree_view_new ( );
+ gtk_tree_view_set_rules_hint ( GTK_TREE_VIEW (tree_view), TRUE);
+ g_object_set_data ( G_OBJECT ( account_page ), "hist_tree_view", tree_view );
+
+ tree_model = gtk_tree_store_new ( SPP_HISTORICAL_NUM_COLUMNS,
+ G_TYPE_BOOLEAN, /* SPP_HISTORICAL_SELECT_COLUMN */
+ G_TYPE_STRING, /* SPP_HISTORICAL_DESC_COLUMN */
+ G_TYPE_STRING, /* SPP_HISTORICAL_PERIOD_COLUMN */
+ G_TYPE_STRING, /* SPP_HISTORICAL_BALANCE_COLUMN */
+ G_TYPE_STRING, /* SPP_HISTORICAL_AVERAGE_COLUMN */
+ G_TYPE_STRING, /* SPP_HISTORICAL_AVERAGE_AMOUNT */
+ G_TYPE_STRING, /* SPP_HISTORICAL_RETAINED_COLUMN */
+ G_TYPE_STRING, /* SPP_HISTORICAL_RETAINED_AMOUNT */
+ G_TYPE_STRING, /* SPP_HISTORICAL_BALANCE_COLOR */
+ G_TYPE_INT, /* SPP_HISTORICAL_ACCOUNT_NUMBER */
+ G_TYPE_INT, /* SPP_HISTORICAL_DIV_NUMBER */
+ G_TYPE_INT, /* SPP_HISTORICAL_SUB_DIV_NUMBER */
+ G_TYPE_BOOLEAN, /* SPP_HISTORICAL_EDITED_COLUMN */
+ GDK_TYPE_COLOR ); /* SPP_HISTORICAL_BACKGROUND_COLOR */
+ gtk_tree_view_set_model ( GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL ( tree_model ) );
+ g_object_unref ( G_OBJECT ( tree_model ) );
+
+ gtk_tree_sortable_set_sort_column_id ( GTK_TREE_SORTABLE ( tree_model ),
+ SPP_HISTORICAL_DESC_COLUMN, GTK_SORT_ASCENDING );
+
+ tree_selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW ( tree_view ) );
+ gtk_tree_selection_set_mode ( tree_selection, GTK_SELECTION_SINGLE );
+
+ scrolled_window = gtk_scrolled_window_new ( NULL, NULL );
+ gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW ( scrolled_window ),
+ GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
+ gtk_widget_set_size_request ( scrolled_window, -1, 250 );
+ gtk_container_add ( GTK_CONTAINER ( scrolled_window ), tree_view );
+ gtk_box_pack_start ( GTK_BOX ( container ), scrolled_window, TRUE, TRUE, 15 );
+
+ /* create columns */
+ cell = gtk_cell_renderer_toggle_new ( );
+ g_object_set_data ( G_OBJECT ( account_page ), "toggle_cell", cell );
+ gtk_cell_renderer_toggle_set_radio ( GTK_CELL_RENDERER_TOGGLE ( cell ),
+ FALSE );
+ g_object_set (cell, "xalign", 0.5, NULL);
+ g_signal_connect ( cell,
+ "toggled",
+ G_CALLBACK (bet_historical_div_toggle_clicked),
+ tree_model );
+
+ column = gtk_tree_view_column_new_with_attributes ( _("Select"),
+ cell,
+ "active", SPP_HISTORICAL_SELECT_COLUMN,
+ "cell-background-gdk", SPP_HISTORICAL_BACKGROUND_COLOR,
+ NULL);
+ gtk_tree_view_column_set_alignment ( column, 0.5 );
+ gtk_tree_view_append_column ( GTK_TREE_VIEW ( tree_view ), column );
+ gtk_tree_view_column_set_resizable ( column, TRUE );
+
+ /* name of the div sous-div column*/
+ title = g_strdup ( _("Category") );
+ cell = gtk_cell_renderer_text_new ( );
+ column = gtk_tree_view_column_new_with_attributes ( title,
+ cell,
+ "text", SPP_HISTORICAL_DESC_COLUMN,
+ "cell-background-gdk", SPP_HISTORICAL_BACKGROUND_COLOR,
+ NULL);
+ g_object_set_data ( G_OBJECT ( account_page ), "historical_column_source",
+ column );
+ gtk_tree_view_append_column ( GTK_TREE_VIEW ( tree_view ),
+ GTK_TREE_VIEW_COLUMN ( column ) );
+ gtk_tree_view_column_set_expand ( GTK_TREE_VIEW_COLUMN ( column ), TRUE );
+ gtk_tree_view_column_set_resizable ( column, TRUE );
+
+ /* period analysis column */
+ cell = gtk_cell_renderer_text_new ( );
+ column = gtk_tree_view_column_new_with_attributes (
+ _("Period"), cell,
+ "text", SPP_HISTORICAL_PERIOD_COLUMN,
+ "cell-background-gdk", SPP_HISTORICAL_BACKGROUND_COLOR,
+ NULL);
+ g_object_set (cell, "xalign", 0.5, NULL);
+
+ gtk_tree_view_column_set_alignment ( column, 0.5 );
+ gtk_tree_view_append_column ( GTK_TREE_VIEW ( tree_view ),
+ GTK_TREE_VIEW_COLUMN ( column ) );
+ gtk_tree_view_column_set_expand ( GTK_TREE_VIEW_COLUMN ( column ), TRUE );
+ gtk_tree_view_column_set_resizable ( column, TRUE );
+
+ /* amount column */
+ cell = gtk_cell_renderer_text_new ( );
+ column = gtk_tree_view_column_new_with_attributes (
+ _("Amount"), cell,
+ "text", SPP_HISTORICAL_BALANCE_COLUMN,
+ "foreground", SPP_HISTORICAL_BALANCE_COLOR,
+ "cell-background-gdk", SPP_HISTORICAL_BACKGROUND_COLOR,
+ NULL);
+ gtk_tree_view_append_column ( GTK_TREE_VIEW ( tree_view ),
+ GTK_TREE_VIEW_COLUMN ( column ) );
+ g_object_set ( G_OBJECT ( GTK_CELL_RENDERER ( cell ) ), "xalign", 1.0, NULL );
+ gtk_tree_view_column_set_alignment ( column, 1 );
+ gtk_tree_view_column_set_clickable ( GTK_TREE_VIEW_COLUMN ( column ), TRUE );
+ gtk_tree_view_column_set_expand ( GTK_TREE_VIEW_COLUMN ( column ), TRUE );
+ gtk_tree_view_column_set_resizable ( column, TRUE );
+
+ /* average column */
+ cell = gtk_cell_renderer_text_new ( );
+ column = gtk_tree_view_column_new_with_attributes (
+ _("Average"), cell,
+ "text", SPP_HISTORICAL_AVERAGE_COLUMN,
+ "foreground", SPP_HISTORICAL_BALANCE_COLOR,
+ "cell-background-gdk", SPP_HISTORICAL_BACKGROUND_COLOR,
+ NULL);
+ gtk_tree_view_append_column ( GTK_TREE_VIEW ( tree_view ),
+ GTK_TREE_VIEW_COLUMN ( column ) );
+ g_object_set ( G_OBJECT ( GTK_CELL_RENDERER ( cell ) ), "xalign", 1.0, NULL );
+ gtk_tree_view_column_set_alignment ( column, 1 );
+ gtk_tree_view_column_set_clickable ( GTK_TREE_VIEW_COLUMN ( column ), TRUE );
+ gtk_tree_view_column_set_expand ( GTK_TREE_VIEW_COLUMN ( column ), TRUE );
+ gtk_tree_view_column_set_resizable ( column, TRUE );
+
+ /* amount retained column */
+ cell = gtk_cell_renderer_text_new ( );
+ g_object_set_data ( G_OBJECT ( account_page ), "edited_cell", cell );
+ column = gtk_tree_view_column_new_with_attributes (
+ _("Amount retained"), cell,
+ "text", SPP_HISTORICAL_RETAINED_COLUMN,
+ "foreground", SPP_HISTORICAL_BALANCE_COLOR,
+ "editable", SPP_HISTORICAL_EDITED_COLUMN,
+ "cell-background-gdk", SPP_HISTORICAL_BACKGROUND_COLOR,
+ NULL);
+ gtk_tree_view_append_column ( GTK_TREE_VIEW ( tree_view ),
+ GTK_TREE_VIEW_COLUMN ( column ) );
+ g_object_set ( G_OBJECT ( GTK_CELL_RENDERER ( cell ) ), "xalign", 1.0, NULL );
+ gtk_tree_view_column_set_alignment ( column, 1 );
+ gtk_tree_view_column_set_clickable ( GTK_TREE_VIEW_COLUMN ( column ), TRUE );
+ gtk_tree_view_column_set_expand ( GTK_TREE_VIEW_COLUMN ( column ), TRUE );
+ gtk_tree_view_column_set_resizable ( column, TRUE );
+
+ g_signal_connect ( cell,
+ "editing-started",
+ G_CALLBACK (bet_historical_div_cell_editing_started),
+ tree_view );
+ g_signal_connect ( cell,
+ "edited",
+ G_CALLBACK (bet_historical_div_cell_edited),
+ tree_view );
+
+ g_signal_connect ( G_OBJECT ( tree_view ),
+ "row-expanded",
+ G_CALLBACK ( bet_historical_row_expanded_event ),
+ tree_model );
+
+ g_signal_connect ( G_OBJECT ( tree_view ),
+ "button-press-event",
+ G_CALLBACK ( bet_historical_button_press ),
+ NULL );
+
+ gtk_widget_show_all ( scrolled_window );
+
+ return tree_view;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_historical_populate_data ( gint account_number )
+{
+ GtkWidget *tree_view;
+ GtkTreeModel *model;
+ gint fyear_number;
+ GDate *date_min;
+ GDate *date_max;
+ GSList* tmp_list;
+ GHashTable *list_div;
+
+ devel_debug_int ( account_number );
+ tree_view = g_object_get_data (G_OBJECT ( account_page ), "bet_historical_treeview" );
+ if ( GTK_IS_TREE_VIEW ( tree_view ) == FALSE )
+ return;
+
+ /* Initializes account settings */
+ bet_historical_initializes_account_settings ( account_number );
+
+ model = gtk_tree_view_get_model ( GTK_TREE_VIEW ( tree_view ) );
+ gtk_tree_store_clear ( GTK_TREE_STORE ( model ) );
+
+ /* calculate date_min and date_max */
+ fyear_number = gsb_data_account_get_bet_hist_fyear ( account_number );
+ if ( fyear_number == 0 )
+ {
+ date_min = gdate_today ( );
+ g_date_subtract_years ( date_min, 1 );
+ date_max = gdate_today ( );
+ g_date_subtract_days ( date_max, 1 );
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_historical_period",
+ g_strdup ( _("12 months rolling") ) );
+ }
+ else
+ {
+ date_min = gsb_data_fyear_get_beginning_date ( fyear_number );
+ date_max = gsb_data_fyear_get_end_date ( fyear_number );
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_historical_period",
+ g_strdup ( gsb_data_fyear_get_name ( fyear_number ) ) );
+ }
+ list_div = g_hash_table_new_full ( g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) struct_free_bet_historical );
+
+ /* search transactions of the account */
+ tmp_list = gsb_data_transaction_get_complete_transactions_list ( );
+ while ( tmp_list )
+ {
+ gint transaction_number;
+ gint tmp_account_number;
+ const GDate *date;
+
+ transaction_number = gsb_data_transaction_get_transaction_number (
+ tmp_list->data );
+ tmp_list = tmp_list -> next;
+
+ tmp_account_number = gsb_data_transaction_get_account_number (
+ transaction_number );
+ if ( tmp_account_number != account_number )
+ continue;
+
+ date = gsb_data_transaction_get_date ( transaction_number );
+ /* ignore transaction which are before date_min (today) */
+ if ( g_date_compare ( date, date_min ) <= 0 )
+ continue;
+ /* ignore transaction which are after date_max */
+ if ( g_date_compare (date, date_max ) > 0 )
+ continue;
+
+ /* ignore splitted transactions */
+ if ( gsb_data_transaction_get_mother_transaction_number (
+ transaction_number ) != 0 )
+ continue;
+
+ bet_data_populate_div ( transaction_number, TRUE, list_div );
+ }
+
+ bet_historical_affiche_div ( list_div, tree_view );
+ //~ bet_data_synchronise_hist_div_list ( list_div );
+
+ g_hash_table_remove_all ( list_div );
+
+ bet_historical_set_background_color ( tree_view );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_historical_affiche_div ( GHashTable *list_div, GtkWidget *tree_view )
+{
+ GtkTreeModel *model;
+
+ //~ devel_debug (NULL);
+ model = gtk_tree_view_get_model ( GTK_TREE_VIEW ( tree_view ) );
+
+ g_hash_table_foreach ( list_div, bet_historical_populate_div_model, tree_view );
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_historical_populate_div_model ( gpointer key,
+ gpointer value,
+ gpointer user_data )
+{
+ SH *sh = ( SH* ) value;
+ SBR *sbr = sh -> sbr;
+ GtkTreeView *tree_view = ( GtkTreeView * ) user_data;
+ GtkTreeModel *model;
+ GtkTreeIter parent;
+ GHashTableIter iter;
+ gpointer sub_key, sub_value;
+ gchar *div_name = NULL;
+ gchar *str_balance;
+ gchar *str_average;
+ gchar *str_amount;
+ gchar *str_retained = NULL;
+ gchar *titre;
+ gint div_number;
+ gint account_nb;
+ gboolean sub_div_visible = FALSE;
+ gboolean edited = TRUE;
+ gsb_real period = { 12, 0 };
+ gsb_real average;
+ gsb_real retained;
+ gsb_real amount;
+ kind_account kind;
+
+ div_number = sh -> div;
+ div_name = bet_data_get_div_name ( div_number, 0, NULL );
+ account_nb = sh -> account_nb;
+ kind = gsb_data_account_get_kind ( account_nb );
+ if ( kind == GSB_TYPE_CASH )
+ edited = FALSE;
+
+ titre = g_object_get_data ( G_OBJECT ( account_page ), "bet_historical_period" );
+
+ model = gtk_tree_view_get_model ( tree_view );
+
+ str_balance = gsb_real_get_string_with_currency ( sbr -> current_balance,
+ gsb_data_account_get_currency ( account_nb ), TRUE );
+ average = gsb_real_div ( sbr -> current_balance, period );
+ str_amount = gsb_real_save_real_to_string ( average, 2 );
+ str_average = gsb_real_get_string_with_currency ( average,
+ gsb_data_account_get_currency ( account_nb ), TRUE );
+
+ gtk_tree_store_append ( GTK_TREE_STORE ( model ), &parent, NULL);
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ &parent,
+ SPP_HISTORICAL_DESC_COLUMN, div_name,
+ SPP_HISTORICAL_PERIOD_COLUMN, titre,
+ SPP_HISTORICAL_BALANCE_COLUMN, str_balance,
+ SPP_HISTORICAL_AVERAGE_COLUMN, str_average,
+ SPP_HISTORICAL_AVERAGE_AMOUNT, str_amount,
+ SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
+ SPP_HISTORICAL_ACCOUNT_NUMBER, account_nb,
+ SPP_HISTORICAL_DIV_NUMBER, div_number,
+ SPP_HISTORICAL_SUB_DIV_NUMBER, 0,
+ SPP_HISTORICAL_EDITED_COLUMN, edited,
+ -1);
+
+ if ( bet_data_search_div_hist ( account_nb, div_number, 0 )
+ &&
+ ( bet_data_get_div_edited ( account_nb, div_number, 0 )
+ ||
+ g_hash_table_size ( sh -> list_sub_div ) <= 1 ) )
+ {
+ retained = bet_data_hist_get_div_amount ( account_nb, div_number, 0 );
+ if ( str_amount )
+ g_free ( str_amount );
+ str_amount = gsb_real_save_real_to_string ( retained, 2 );
+ str_retained = gsb_real_get_string_with_currency ( retained,
+ gsb_data_account_get_currency ( sh -> account_nb ), TRUE );
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ &parent,
+ SPP_HISTORICAL_SELECT_COLUMN, TRUE,
+ SPP_HISTORICAL_RETAINED_COLUMN, str_retained,
+ SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
+ -1);
+ g_free ( str_retained );
+ }
+
+ g_free ( div_name );
+ g_free ( str_average );
+ g_free ( str_amount );
+
+ if ( g_hash_table_size ( sh -> list_sub_div ) <= 1 )
+ return;
+
+ g_hash_table_iter_init ( &iter, sh -> list_sub_div );
+ while ( g_hash_table_iter_next ( &iter, &sub_key, &sub_value ) )
+ {
+ SH *sub_sh = ( SH* ) sub_value;
+ SBR *sub_sbr = sub_sh -> sbr;
+ GtkTreeIter fils;
+ gchar **tab_str = NULL;
+
+ div_name = bet_data_get_div_name ( div_number, sub_sh -> div, NULL );
+ //~ printf ("division = %d sub_div = %d div_name = %s\n",
+ //~ div_number, sub_sh -> div, div_name);
+ if ( div_name && g_utf8_strrchr ( div_name, -1, ':' ) )
+ {
+ tab_str = g_strsplit ( div_name, ":", 2 );
+ if ( g_strv_length ( tab_str ) > 1 )
+ {
+ if ( div_name )
+ g_free ( div_name );
+ div_name = g_strdup ( g_strstrip ( tab_str[1] ) );
+ }
+ if ( tab_str )
+ g_strfreev ( tab_str );
+ }
+
+ str_balance = gsb_real_get_string_with_currency ( sub_sbr -> current_balance,
+ gsb_data_account_get_currency ( sh -> account_nb ), TRUE );
+ average = gsb_real_div ( sub_sbr -> current_balance, period );
+ str_amount = gsb_real_save_real_to_string ( average, 2 );
+ str_average = gsb_real_get_string_with_currency ( average,
+ gsb_data_account_get_currency ( sh -> account_nb ), TRUE );
+
+ gtk_tree_store_append ( GTK_TREE_STORE ( model ), &fils, &parent );
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ &fils,
+ SPP_HISTORICAL_DESC_COLUMN, div_name,
+ SPP_HISTORICAL_BALANCE_COLUMN, str_balance,
+ SPP_HISTORICAL_AVERAGE_COLUMN, str_average,
+ SPP_HISTORICAL_AVERAGE_AMOUNT, str_amount,
+ SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
+ SPP_HISTORICAL_ACCOUNT_NUMBER, account_nb,
+ SPP_HISTORICAL_DIV_NUMBER, div_number,
+ SPP_HISTORICAL_SUB_DIV_NUMBER, sub_sh -> div,
+ SPP_HISTORICAL_EDITED_COLUMN, edited,
+ -1);
+
+ if ( bet_data_search_div_hist ( account_nb, div_number, sub_sh -> div ) )
+ {
+ if ( bet_data_get_div_edited ( account_nb, div_number, sub_sh -> div ) )
+ {
+ //~ printf ("account_nb = %d div_number = %d sub_sh -> div = %d\n", account_nb, div_number, sub_sh -> div );
+ retained = bet_data_hist_get_div_amount ( account_nb, div_number, sub_sh -> div );
+ if ( str_amount )
+ g_free ( str_amount );
+ str_amount = gsb_real_save_real_to_string ( retained, 2 );
+ str_retained = gsb_real_get_string_with_currency ( retained,
+ gsb_data_account_get_currency ( sh -> account_nb ), TRUE );
+
+ edited = FALSE;
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ &parent,
+ SPP_HISTORICAL_EDITED_COLUMN, edited,
+ -1);
+ }
+ else
+ {
+ bet_data_set_div_amount ( account_nb, div_number, sub_sh -> div, average );
+ str_retained = g_strdup ( str_average );
+ edited = TRUE;
+ }
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ &fils,
+ SPP_HISTORICAL_SELECT_COLUMN, TRUE,
+ SPP_HISTORICAL_RETAINED_COLUMN, str_retained,
+ SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
+ -1);
+ sub_div_visible = TRUE;
+ gtk_tree_view_expand_to_path ( tree_view, gtk_tree_model_get_path ( model, &fils ) );
+
+ g_free ( str_retained );
+ }
+ g_free ( div_name );
+ g_free ( str_balance );
+ g_free ( str_average );
+ g_free ( str_amount );
+ }
+
+ if ( sub_div_visible && bet_historical_get_full_div ( model, &parent ) )
+ {
+ amount = bet_historical_get_children_amount ( model, &parent );
+ if ( str_amount )
+ g_free ( str_amount );
+ str_amount = gsb_real_save_real_to_string ( amount, 2 );
+ str_retained = gsb_real_get_string_with_currency ( amount,
+ gsb_data_account_get_currency ( account_nb ), TRUE );
+
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ &parent,
+ SPP_HISTORICAL_SELECT_COLUMN, TRUE,
+ SPP_HISTORICAL_RETAINED_COLUMN, str_retained,
+ SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
+ SPP_HISTORICAL_EDITED_COLUMN, edited,
+ -1);
+ g_free ( str_amount );
+ g_free ( str_retained );
+
+ if ( edited )
+ {
+ gtk_tree_view_collapse_row ( tree_view, gtk_tree_model_get_path ( model, &parent ) );
+ gtk_tree_selection_select_iter ( gtk_tree_view_get_selection ( tree_view ), &parent );
+
+ }
+ }
+}
+
+
+/**
+ * create and fill the list store of the fyear
+ * come here mean that fyear_model_filter is NULL
+ *
+ * \param
+ *
+ * \return TRUE ok, FALSE problem
+ * */
+gboolean bet_historical_fyear_create_combobox_store ( void )
+{
+ gchar *titre;
+
+ //~ devel_debug (NULL);
+ /* the fyear list store, contains 3 columns :
+ * FYEAR_COL_NAME : the name of the fyear
+ * FYEAR_COL_NUMBER : the number of the fyear
+ * FYEAR_COL_VIEW : it tha fyear should be showed */
+
+ titre = g_strdup ( _("12 months rolling") );
+ bet_fyear_model = GTK_TREE_MODEL ( gtk_list_store_new ( 3,
+ G_TYPE_STRING,
+ G_TYPE_INT,
+ G_TYPE_BOOLEAN ));
+ bet_fyear_model_filter = gtk_tree_model_filter_new ( bet_fyear_model, NULL );
+ gtk_tree_model_filter_set_visible_column ( GTK_TREE_MODEL_FILTER (
+ bet_fyear_model_filter ),
+ FYEAR_COL_VIEW );
+ gsb_fyear_update_fyear_list_new ( bet_fyear_model,
+ bet_fyear_model_filter,
+ titre );
+ g_free ( titre );
+
+ return TRUE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gint bet_historical_get_fyear_from_combobox ( GtkWidget *combo_box )
+{
+ gint fyear_number = 0;
+ GtkTreeIter iter;
+
+ //~ devel_debug (NULL);
+ if ( !gtk_combo_box_get_active_iter ( GTK_COMBO_BOX ( combo_box ), &iter ) )
+ return 0;
+
+ if ( bet_fyear_model_filter )
+ {
+ gtk_tree_model_get ( GTK_TREE_MODEL ( bet_fyear_model_filter ),
+ &iter,
+ FYEAR_COL_NUMBER, &fyear_number,
+ -1 );
+ }
+
+ return fyear_number;
+}
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_historical_set_fyear_from_combobox ( GtkWidget *combo_box, gint fyear )
+{
+ gsb_fyear_select_iter_by_number ( combo_box,
+ bet_fyear_model,
+ bet_fyear_model_filter,
+ fyear );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_historical_refresh_data ( GtkTreeModel *tab_model,
+ GDate *date_min,
+ GDate *date_max )
+{
+ GtkWidget *tree_view;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GtkTreeIter fils_iter;
+
+ devel_debug (NULL);
+ tree_view = g_object_get_data ( G_OBJECT ( account_page ), "bet_historical_treeview" );
+ model = gtk_tree_view_get_model ( GTK_TREE_VIEW ( tree_view ) );
+
+ if ( gtk_tree_model_get_iter_first ( GTK_TREE_MODEL ( model ), &iter ) )
+ {
+ gboolean valeur;
+ gint account_number;
+
+ /* test du numero de compte */
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
+ SPP_HISTORICAL_ACCOUNT_NUMBER, &account_number,
+ -1 );
+ if ( account_number != gsb_gui_navigation_get_current_account ( ) )
+ return;
+
+ do
+ {
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
+ SPP_HISTORICAL_SELECT_COLUMN, &valeur,
+ -1 );
+ if ( valeur == 1 )
+ {
+ bet_array_list_add_new_hist_line ( tab_model,
+ GTK_TREE_MODEL ( model ), &iter,
+ date_min, date_max );
+ }
+ else if ( gtk_tree_model_iter_children (
+ GTK_TREE_MODEL ( model ),
+ &fils_iter, &iter ) )
+ {
+ do
+ {
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ),
+ &fils_iter,
+ SPP_HISTORICAL_SELECT_COLUMN, &valeur,
+ -1 );
+
+ if ( valeur == 1 )
+ {
+ bet_array_list_add_new_hist_line ( tab_model,
+ GTK_TREE_MODEL ( model ), &fils_iter,
+ date_min, date_max );
+ }
+ }
+ while ( gtk_tree_model_iter_next (
+ GTK_TREE_MODEL ( model ), &fils_iter ) );
+ }
+
+ } while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL ( model ), &iter ) );
+ }
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_historical_get_full_div ( GtkTreeModel *model, GtkTreeIter *parent )
+{
+ GtkTreeIter fils_iter;
+ gint valeur;
+
+ if ( gtk_tree_model_iter_children ( GTK_TREE_MODEL ( model ), &fils_iter, parent ) )
+ {
+ do
+ {
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &fils_iter,
+ SPP_HISTORICAL_SELECT_COLUMN, &valeur,
+ -1 );
+
+ if ( valeur == FALSE )
+ {
+ return FALSE;
+ }
+ }
+ while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL ( model ), &fils_iter ) );
+ }
+ return TRUE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_historical_set_full_sub_div ( GtkTreeModel *model, GtkTreeIter *parent )
+{
+ GtkTreeView *tree_view;
+ GtkTreeIter fils_iter;
+ gint edited;
+
+ if ( gtk_tree_model_iter_children ( GTK_TREE_MODEL ( model ), &fils_iter, parent ) )
+ {
+ gchar *str_amount;
+ gchar *str_retained;
+ gint account_nb;
+ gint div_number;
+ gint sub_div_nb;
+ gsb_real retained;
+
+ do
+ {
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &fils_iter,
+ SPP_HISTORICAL_AVERAGE_AMOUNT, &str_amount,
+ SPP_HISTORICAL_ACCOUNT_NUMBER, &account_nb,
+ SPP_HISTORICAL_DIV_NUMBER, &div_number,
+ SPP_HISTORICAL_SUB_DIV_NUMBER, &sub_div_nb,
+ SPP_HISTORICAL_EDITED_COLUMN, &edited,
+ -1 );
+
+ retained = gsb_real_import_from_string ( str_amount );
+ bet_data_hist_add_div ( account_nb, div_number, sub_div_nb );
+ bet_data_set_div_amount ( account_nb, div_number, sub_div_nb,
+ gsb_real_import_from_string ( str_amount ) );
+ str_retained = gsb_real_get_string_with_currency ( retained,
+ gsb_data_account_get_currency ( account_nb ), TRUE );
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ), &fils_iter,
+ SPP_HISTORICAL_SELECT_COLUMN, TRUE,
+ SPP_HISTORICAL_RETAINED_COLUMN, str_retained,
+ SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
+ -1 );
+ g_free ( str_amount );
+ g_free ( str_retained );
+ }
+ while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL ( model ), &fils_iter ) );
+ }
+
+ if ( edited )
+ {
+ tree_view = g_object_get_data ( G_OBJECT ( account_page ),
+ "bet_historical_treeview" );
+ gtk_tree_view_collapse_row ( tree_view,
+ gtk_tree_model_get_path ( model, parent ) );
+ gtk_tree_selection_select_iter ( gtk_tree_view_get_selection (
+ tree_view ), parent );
+ }
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_historical_set_empty_sub_div ( GtkTreeModel *model, GtkTreeIter *parent )
+{
+ GtkTreeIter fils_iter;
+
+ if ( gtk_tree_model_iter_children ( GTK_TREE_MODEL ( model ), &fils_iter, parent ) )
+ {
+ gchar *str_amount;
+ gint account_nb;
+ gint div_number;
+ gint sub_div_nb;
+
+ do
+ {
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &fils_iter,
+ SPP_HISTORICAL_AVERAGE_AMOUNT, &str_amount,
+ SPP_HISTORICAL_ACCOUNT_NUMBER, &account_nb,
+ SPP_HISTORICAL_DIV_NUMBER, &div_number,
+ SPP_HISTORICAL_SUB_DIV_NUMBER, &sub_div_nb,
+ -1 );
+ bet_data_remove_div_hist ( account_nb, div_number, sub_div_nb );
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ), &fils_iter,
+ SPP_HISTORICAL_SELECT_COLUMN, FALSE,
+ SPP_HISTORICAL_RETAINED_COLUMN, "",
+ SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
+ SPP_HISTORICAL_EDITED_COLUMN, TRUE,
+ -1 );
+ g_free ( str_amount );
+ }
+ while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL ( model ), &fils_iter ) );
+ }
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gsb_real bet_historical_get_children_amount ( GtkTreeModel *model, GtkTreeIter *parent )
+{
+ GtkTreeIter fils_iter;
+ gchar *str_amount;
+ gsb_real amount = null_real;
+
+ if ( gtk_tree_model_iter_children ( GTK_TREE_MODEL ( model ), &fils_iter, parent ) )
+ {
+ do
+ {
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &fils_iter,
+ SPP_HISTORICAL_RETAINED_AMOUNT, &str_amount,
+ -1 );
+ amount = gsb_real_add ( amount,
+ gsb_real_get_from_string ( str_amount ) );
+ }
+ while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL ( model ), &fils_iter ) );
+ }
+
+ return amount;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_historical_row_expanded_event ( GtkTreeView *tree_view,
+ GtkTreeIter *iter,
+ GtkTreePath *path,
+ GtkTreeModel *model )
+{
+ gint account_nb;
+ gint div_number;
+
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), iter,
+ SPP_HISTORICAL_ACCOUNT_NUMBER, &account_nb,
+ SPP_HISTORICAL_DIV_NUMBER, &div_number,
+ -1 );
+
+ if ( bet_data_get_div_edited ( account_nb, div_number, 0 ) == TRUE )
+ {
+ gtk_tree_view_collapse_row ( tree_view, path );
+ gtk_tree_selection_select_iter ( gtk_tree_view_get_selection ( tree_view ), iter );
+ }
+ bet_historical_set_background_color ( GTK_WIDGET ( tree_view ) );
+}
+
+
+/**
+ * Cette fonction compare le montant de la colonne montant retenu avec le montant
+ * de la colonne moyenne
+ *
+ * \ return O si egal -1 ou 1 si différent
+ * */
+gboolean bet_historical_amount_differ_average ( GtkTreeModel *model,
+ GtkTreeIter *iter )
+{
+ gchar *str_average;
+ gchar *str_amount;
+
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), iter,
+ SPP_HISTORICAL_AVERAGE_AMOUNT, &str_average,
+ SPP_HISTORICAL_RETAINED_AMOUNT, &str_amount,
+ -1 );
+
+ return gsb_real_cmp ( gsb_real_get_from_string ( str_average ),
+ gsb_real_get_from_string ( str_amount ) );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_historical_row_collapse_all ( GtkTreeView *tree_view,
+ GtkTreeIter *iter,
+ GtkTreeModel *model )
+{
+ if ( tree_view == NULL )
+ tree_view = g_object_get_data ( G_OBJECT ( account_page ), "bet_historical_treeview" );
+ gtk_tree_view_collapse_row ( tree_view,
+ gtk_tree_model_get_path ( model, iter ) );
+ gtk_tree_selection_select_iter ( gtk_tree_view_get_selection (
+ tree_view ), iter );
+}
+
+
+/**
+ * called when we press a button on the list
+ *
+ * \param tree_view
+ * \param ev
+ *
+ * \return FALSE
+ * */
+gboolean bet_historical_button_press ( GtkWidget *tree_view,
+ GdkEventButton *ev )
+{
+ /* show the popup */
+ if ( ev -> button == RIGHT_BUTTON )
+ bet_historical_context_menu ( tree_view );
+
+ return FALSE;
+}
+
+
+/**
+ * Pop up a menu with several actions to apply to historical list.
+ *
+ * \param
+ *
+ */
+void bet_historical_context_menu ( GtkWidget *tree_view )
+{
+ GtkWidget *menu, *menu_item;
+ GtkTreeModel *model;
+ GtkTreeSelection *tree_selection;
+ GtkTreeIter iter;
+
+ tree_selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW ( tree_view ) );
+
+ if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( tree_selection ),
+ &model, &iter ) )
+ return;
+
+ menu = gtk_menu_new ();
+
+ /* Add last amount menu */
+ menu_item = gtk_image_menu_item_new_with_label ( _("Assign the amount of the last operation") );
+ gtk_image_menu_item_set_image ( GTK_IMAGE_MENU_ITEM ( menu_item ),
+ gtk_image_new_from_stock ( GTK_STOCK_ADD,
+ GTK_ICON_SIZE_MENU ) );
+
+ g_signal_connect ( G_OBJECT ( menu_item ),
+ "activate",
+ G_CALLBACK ( bet_historical_add_last_amount ),
+ tree_selection );
+
+ if ( gtk_tree_model_iter_n_children ( model, &iter ) > 0 )
+ gtk_widget_set_sensitive ( menu_item, FALSE );
+ else
+ gtk_widget_set_sensitive ( menu_item, TRUE );
+
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), menu_item );
+
+ /* Separator */
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), gtk_separator_menu_item_new ( ) );
+ gtk_widget_show ( menu_item );
+
+
+ /* Add average amount menu */
+ menu_item = gtk_image_menu_item_new_with_label ( _("Copy the average amount") );
+ 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 ( bet_historical_add_average_amount ),
+ tree_selection );
+
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), menu_item );
+
+ /* Finish all. */
+ gtk_widget_show_all ( menu );
+ gtk_menu_popup ( GTK_MENU( menu ), NULL, NULL, NULL, NULL,
+ 3, gtk_get_current_event_time ( ) );
+}
+
+
+/**
+ * add the amount of the last transaction with the same division and sub-division
+ *
+ * /param menu item
+ * /param row selected
+ *
+ * */
+void bet_historical_add_last_amount ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection )
+{
+ GtkTreeModel *model;
+ GtkTreeIter parent;
+ GtkTreeIter iter;
+ gint account_number;
+ gint div_number;
+ gint sub_div_nb;
+ gint currency_number;
+ gchar *tmp_str;
+ gchar *str_amount;
+ gsb_real amount;
+
+ if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( tree_selection ),
+ &model, &iter ) )
+ return;
+
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
+ SPP_HISTORICAL_ACCOUNT_NUMBER, &account_number,
+ SPP_HISTORICAL_DIV_NUMBER, &div_number,
+ SPP_HISTORICAL_SUB_DIV_NUMBER, &sub_div_nb,
+ -1 );
+
+ amount = gsb_data_transaction_get_last_transaction_with_div_sub_div (
+ account_number,
+ div_number,
+ sub_div_nb,
+ gsb_data_account_get_bet_hist_data ( account_number ) );
+ str_amount = gsb_real_save_real_to_string ( amount, 2 );
+
+ currency_number = gsb_data_account_get_currency ( account_number );
+ tmp_str = gsb_real_get_string_with_currency ( amount, currency_number, TRUE );
+ //~ printf ("div = %d sub_div_nb = %d tmp_str = %s\n", div_number, sub_div_nb, tmp_str);
+ if ( bet_data_search_div_hist ( account_number, div_number, sub_div_nb ) == FALSE )
+ bet_data_hist_add_div ( account_number, div_number, sub_div_nb );
+
+ bet_data_set_div_edited ( account_number, div_number, sub_div_nb, TRUE );
+ bet_data_set_div_amount ( account_number, div_number, sub_div_nb, amount );
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ), &iter,
+ SPP_HISTORICAL_SELECT_COLUMN, TRUE,
+ SPP_HISTORICAL_RETAINED_COLUMN, tmp_str,
+ SPP_HISTORICAL_RETAINED_AMOUNT, str_amount,
+ SPP_HISTORICAL_ACCOUNT_NUMBER, account_number,
+ SPP_HISTORICAL_DIV_NUMBER, div_number,
+ SPP_HISTORICAL_SUB_DIV_NUMBER, sub_div_nb,
+ -1 );
+
+ if ( gtk_tree_model_iter_parent ( GTK_TREE_MODEL ( model ), &parent, &iter ) )
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ &parent,
+ SPP_HISTORICAL_EDITED_COLUMN, FALSE,
+ -1);
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+}
+
+
+/**
+ * add the average amount of the item
+ *
+ * /param menu item
+ * /param row selected
+ *
+ * */
+void bet_historical_add_average_amount ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection )
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gchar *path_string;
+
+ if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( tree_selection ),
+ &model, &iter ) )
+ return;
+
+ path_string = gtk_tree_path_to_string ( gtk_tree_model_get_path ( model, &iter ) );
+ if ( path_string )
+ bet_historical_div_toggle_clicked ( NULL, path_string, model );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_historical_initializes_account_settings ( gint account_number )
+{
+ GtkWidget *combo = NULL;
+ gint fyear_number;
+ gpointer pointer;
+
+ combo = g_object_get_data ( G_OBJECT ( account_page ), "bet_hist_fyear_combo" );
+
+ fyear_number = gsb_data_account_get_bet_hist_fyear ( account_number );
+
+ pointer = g_object_get_data ( G_OBJECT ( combo ), "pointer" );
+ g_signal_handlers_block_by_func ( G_OBJECT ( combo ),
+ G_CALLBACK ( bet_config_fyear_clicked ),
+ pointer );
+
+ gsb_fyear_select_iter_by_number ( combo,
+ bet_fyear_model,
+ bet_fyear_model_filter,
+ fyear_number );
+
+ g_signal_handlers_unblock_by_func ( G_OBJECT ( combo ),
+ G_CALLBACK ( bet_config_fyear_clicked ),
+ pointer );
+
+ return FALSE;
+}
+
+
+/**
+ * set the background colors of the list
+ *
+ * \param tree_view
+ *
+ * \return FALSE
+ * */
+gboolean bet_historical_set_background_color ( GtkWidget *tree_view )
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GtkTreeIter fils_iter;
+
+ if ( !tree_view )
+ return FALSE;
+
+ model = gtk_tree_view_get_model ( GTK_TREE_VIEW ( tree_view ) );
+
+ if ( gtk_tree_model_get_iter_first ( GTK_TREE_MODEL ( model ), &iter ) )
+ {
+ gint current_color = 0;
+
+ do
+ {
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ &iter,
+ SPP_HISTORICAL_BACKGROUND_COLOR, &couleur_fond[current_color],
+ -1 );
+ current_color = !current_color;
+
+ if ( gtk_tree_model_iter_children ( GTK_TREE_MODEL ( model ), &fils_iter, &iter )
+ &&
+ gtk_tree_view_row_expanded ( GTK_TREE_VIEW ( tree_view ),
+ gtk_tree_model_get_path ( GTK_TREE_MODEL ( model ), &iter ) ) )
+ {
+ do
+ {
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ &fils_iter,
+ SPP_HISTORICAL_BACKGROUND_COLOR, &couleur_fond[current_color],
+ -1 );
+ current_color = !current_color;
+ }
+ while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL ( model ), &fils_iter ) );
+ }
+ }
+ while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL ( model ), &iter ) );
+ }
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_historical_g_signal_block_tree_view ( void )
+{
+ GtkTreeView *tree_view;
+ gpointer cell;
+ GtkTreeModel *tree_model;
+
+ hist_block_signal = TRUE;
+ tree_view = g_object_get_data ( G_OBJECT ( account_page ), "hist_tree_view" );
+ tree_model = gtk_tree_view_get_model ( GTK_TREE_VIEW ( tree_view ) );
+
+ cell = g_object_get_data ( G_OBJECT ( account_page ), "toggle_cell" );
+ g_signal_handlers_block_by_func ( cell, bet_historical_div_toggle_clicked, tree_model );
+
+ cell = g_object_get_data ( G_OBJECT ( account_page ), "edited_cell" );
+ g_signal_handlers_block_by_func ( tree_view, bet_historical_button_press, NULL );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_historical_g_signal_unblock_tree_view ( void )
+{
+ GtkTreeView *tree_view;
+ gpointer cell;
+ GtkTreeModel *tree_model;
+
+ if ( hist_block_signal == FALSE )
+ return;
+
+ hist_block_signal = FALSE;
+ tree_view = g_object_get_data ( G_OBJECT ( account_page ), "hist_tree_view" );
+ tree_model = gtk_tree_view_get_model ( GTK_TREE_VIEW ( tree_view ) );
+ cell = g_object_get_data ( G_OBJECT ( account_page ), "toggle_cell" );
+
+ g_signal_handlers_unblock_by_func ( cell, bet_historical_div_toggle_clicked, tree_model );
+
+ cell = g_object_get_data ( G_OBJECT ( account_page ), "edited_cell" );
+ g_signal_handlers_unblock_by_func ( tree_view, bet_historical_button_press, NULL );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_historical_set_page_title ( gint account_number )
+{
+ GtkWidget * widget;
+ gchar *title;
+
+ title = g_strdup_printf (
+ _("Please select the data source for the account: \"%s\""),
+ gsb_data_account_get_name ( account_number ) );
+ widget = GTK_WIDGET ( g_object_get_data ( G_OBJECT ( account_page ), "bet_hist_title") );
+ gtk_label_set_label ( GTK_LABEL ( widget ), title );
+ g_free ( title );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+
+/* Local Variables: */
+/* c-basic-offset: 4 */
+/* End: */
diff --git a/src/bet_tab.c b/src/bet_tab.c
new file mode 100644
index 0000000..38dcc94
--- /dev/null
+++ b/src/bet_tab.c
@@ -0,0 +1,2646 @@
+/* ************************************************************************** */
+/* */
+/* Copyright (C) 2007 Dominique Parisot */
+/* zionly at free.org */
+/* 2008-2010 Pierre Biava (grisbi at pierre.biava.name) */
+/* 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 */
+/* the Free Software Foundation; either version 2 of the License, or */
+/* (at your option) any later version. */
+/* */
+/* This program is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
+/* GNU General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU General Public License */
+/* along with this program; if not, write to the Free Software */
+/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+/* */
+/* ************************************************************************** */
+
+/* ./configure --with-balance-estimate */
+
+/*
+ * prefix bet : Balance Estimate Tab
+ *
+ * TODO : change the color of each line in the graph :
+ * red if balance is less than 0.
+ * orange if balance is less than the minimum desired balance.
+ * TODO : add a select button to display the selected line in the array
+ * in the scheduler tab or in the account tab.
+ */
+
+#include "include.h"
+#include <config.h>
+
+/*START_INCLUDE*/
+#include "bet_tab.h"
+#include "bet_config.h"
+#include "bet_data.h"
+#include "bet_future.h"
+#include "bet_hist.h"
+#include "utils_dates.h"
+#include "gsb_calendar_entry.h"
+#include "gsb_data_account.h"
+#include "gsb_data_budget.h"
+#include "gsb_data_category.h"
+#include "gsb_data_partial_balance.h"
+#include "gsb_data_payee.h"
+#include "gsb_data_scheduled.h"
+#include "gsb_data_transaction.h"
+#include "navigation.h"
+#include "gsb_real.h"
+#include "gsb_scheduler.h"
+#include "gsb_scheduler_list.h"
+#include "gsb_transactions_list.h"
+#include "traitement_variables.h"
+#include "transaction_list_select.h"
+#include "structures.h"
+#include "fenetre_principale.h"
+#include "mouse.h"
+#include "include.h"
+#include "erreur.h"
+/*END_INCLUDE*/
+
+
+/*START_STATIC*/
+static void bet_array_adjust_hist_amount ( gint div_number,
+ gint sub_div_nb,
+ gsb_real amount,
+ GtkTreeModel *model );
+static void bet_array_auto_inc_month_toggle ( GtkToggleButton *togglebutton, gpointer data );
+static gint bet_array_date_sort_function ( GtkTreeModel *model,
+ GtkTreeIter *itera,
+ GtkTreeIter *iterb,
+ gpointer data );
+static gboolean bet_array_entry_key_press ( GtkWidget *entry,
+ GdkEventKey *ev,
+ gpointer data );
+static gboolean bet_array_initializes_account_settings ( gint account_number );
+static void bet_array_list_add_substract_menu ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection );
+static gboolean bet_array_list_button_press ( GtkWidget *tree_view,
+ GdkEventButton *ev );
+static void bet_array_list_change_menu ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection );
+static void bet_array_list_context_menu ( GtkWidget *tree_view );
+static void bet_array_list_delete_all_menu ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection );
+static void bet_array_list_delete_menu ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection );
+static gchar *bet_array_list_get_description ( gint account_number,
+ gint origine,
+ gpointer value );
+static void bet_array_list_insert_account_balance_menu ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection );
+static void bet_array_list_insert_menu ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection );
+static void bet_array_list_redo_menu ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection );
+static gboolean bet_array_list_replace_planned_line_by_transfert ( GtkTreeModel *tab_model,
+ struct_transfert_data *transfert );
+static gint bet_array_list_schedule_line ( gint origine, gint account_number, gint number );
+static void bet_array_list_schedule_selected_line ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection );
+static gboolean bet_array_list_set_background_color ( GtkWidget *tree_view );
+static void bet_array_list_traite_double_click ( GtkTreeView *tree_view );
+static void bet_array_list_update_balance ( GtkTreeModel *model );
+static void bet_array_refresh_estimate_tab ( gint account_number );
+static gboolean bet_array_refresh_futur_data ( GtkTreeModel *tab_model,
+ GDate *date_min,
+ GDate *date_max );
+static void bet_array_refresh_scheduled_data ( GtkTreeModel *tab_model,
+ gint selected_account,
+ GDate *date_min,
+ GDate *date_max );
+static void bet_array_refresh_transactions_data ( GtkTreeModel *tab_model,
+ gint selected_account,
+ GDate *date_min,
+ GDate *date_max );
+static gboolean bet_array_refresh_transfert_data ( GtkTreeModel *tab_model,
+ GDate *date_min,
+ GDate *date_max );
+static gboolean bet_array_sort_scheduled_transactions ( gint div_number,
+ gint sub_div_nb,
+ GtkTreeModel *model );
+static gboolean bet_array_start_date_focus_out ( GtkWidget *entry,
+ GdkEventFocus *ev,
+ gpointer data );
+static gboolean bet_array_update_average_column ( GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data );
+static GtkWidget *bet_array_create_tree_view ( void );
+/*END_STATIC*/
+
+/*START_EXTERN*/
+extern GtkWidget *account_page;
+extern gchar* bet_duration_array[];
+extern GdkColor couleur_bet_division;
+extern GdkColor couleur_bet_future;
+extern GdkColor couleur_bet_transfert;
+extern GdkColor couleur_fond[2];
+extern gint mise_a_jour_liste_echeances_auto_accueil;
+extern GtkWidget *notebook_general;
+extern gsb_real null_real;
+extern const gdouble prev_month_max;
+extern gint valeur_echelle_recherche_date_import;
+/*END_EXTERN*/
+
+enum bet_estimation_tree_columns {
+ SPP_ESTIMATE_TREE_SELECT_COLUMN, /* select column for the balance */
+ SPP_ESTIMATE_TREE_ORIGIN_DATA, /* origin of data : transaction, scheduled, hist, future */
+ SPP_ESTIMATE_TREE_DIVISION_COLUMN, /* div_number, transaction_number, futur_number, scheduled_number*/
+ SPP_ESTIMATE_TREE_SUB_DIV_COLUMN, /* sub_div_nb */
+ SPP_ESTIMATE_TREE_DATE_COLUMN,
+ SPP_ESTIMATE_TREE_DESC_COLUMN,
+ SPP_ESTIMATE_TREE_DEBIT_COLUMN,
+ SPP_ESTIMATE_TREE_CREDIT_COLUMN,
+ SPP_ESTIMATE_TREE_BALANCE_COLUMN,
+ SPP_ESTIMATE_TREE_SORT_DATE_COLUMN,
+ SPP_ESTIMATE_TREE_AMOUNT_COLUMN, /* the amount without currency */
+ SPP_ESTIMATE_TREE_BALANCE_COLOR,
+ SPP_ESTIMATE_TREE_BACKGROUND_COLOR,
+ SPP_ESTIMATE_TREE_NUM_COLUMNS,
+};
+
+
+/*
+ * Met à jour les données à afficher dans les différentes vues du module
+ *
+ *
+ */
+void bet_array_update_estimate_tab ( gint account_number, gint type_maj )
+{
+ devel_debug_int ( account_number );
+ /* test account number */
+
+ bet_array_initializes_account_settings ( account_number );
+ switch ( type_maj )
+ {
+ case BET_MAJ_ESTIMATE:
+ bet_array_refresh_estimate_tab ( account_number );
+ break;
+ case BET_MAJ_HISTORICAL:
+ bet_historical_populate_data ( account_number );
+ break;
+ case BET_MAJ_ALL:
+ bet_historical_populate_data ( account_number );
+ bet_array_refresh_estimate_tab ( account_number );
+ break;
+ }
+}
+
+
+/*
+ * bet_date_sort_function
+ * This function is called by the Tree Model to sort
+ * two lines by date.
+ */
+static gint bet_array_date_sort_function ( GtkTreeModel *model,
+ GtkTreeIter *itera,
+ GtkTreeIter *iterb,
+ gpointer data )
+{
+ GValue date_value_a = {0,};
+ GValue date_value_b = {0,};
+ GDate* date_a;
+ GDate* date_b;
+
+ if ( itera == NULL )
+ return -1;
+ if ( iterb == NULL)
+ return -1;
+
+ /* get first date to compare */
+ gtk_tree_model_get_value ( model, itera,
+ SPP_ESTIMATE_TREE_SORT_DATE_COLUMN, &date_value_a );
+ date_a = g_value_get_boxed ( &date_value_a );
+ if ( date_a == NULL )
+ return -1;
+
+ /* get second date to compare */
+ gtk_tree_model_get_value ( model, iterb, SPP_ESTIMATE_TREE_SORT_DATE_COLUMN, &date_value_b );
+ date_b = g_value_get_boxed ( &date_value_b );
+ if ( date_b == NULL )
+ return -1;
+
+ gint result = g_date_compare (date_b, date_a);
+
+ if ( result == 0 )
+ {
+ gint origine;
+ gchar *str_amount_a;
+ gchar *str_amount_b;
+ gsb_real amount_a = null_real;
+ gsb_real amount_b = null_real;
+
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), itera,
+ SPP_ESTIMATE_TREE_ORIGIN_DATA, &origine,
+ SPP_ESTIMATE_TREE_AMOUNT_COLUMN, &str_amount_a,
+ -1 );
+
+ if ( origine == SPP_ORIGIN_HISTORICAL )
+ {
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), iterb,
+ SPP_ESTIMATE_TREE_ORIGIN_DATA, &origine,
+ SPP_ESTIMATE_TREE_AMOUNT_COLUMN, &str_amount_b,
+ -1 );
+ if ( origine != SPP_ORIGIN_HISTORICAL )
+ result = -1;
+ else
+ {
+ amount_a = gsb_real_import_from_string ( str_amount_a );
+ amount_b = gsb_real_import_from_string ( str_amount_b );
+ result = - ( gsb_real_cmp ( amount_a, amount_b ) );
+ }
+
+ g_free ( str_amount_b );
+ }
+
+ g_free ( str_amount_a );
+ }
+
+ g_value_unset ( &date_value_b );
+ g_value_unset ( &date_value_a );
+
+ return result;
+}
+
+
+/*
+ * bet_array_update_average_column
+ *
+ * This function is called for each line of the array.
+ * It calculates the balance column by adding the amount of the line
+ * to the balance of the previous line.
+ * It calculates the minimum and the maximum values of the balance column.
+ */
+static gboolean bet_array_update_average_column ( GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data )
+{
+ gchar *str_balance = NULL;
+ gchar *tmp_str;
+ gchar *color_str = NULL;
+ gint selected_account;
+ gboolean select = FALSE;
+ SBR *tmp_range = (SBR*) data;
+ gsb_real amount;
+
+ if ( tmp_range -> first_pass )
+ {
+ tmp_range -> first_pass = FALSE;
+ return FALSE;
+ }
+
+ gtk_tree_model_get ( model, iter, SPP_ESTIMATE_TREE_SELECT_COLUMN, &select, -1 );
+ if ( select )
+ {
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ iter,
+ SPP_ESTIMATE_TREE_BALANCE_COLUMN, "",
+ -1 );
+
+ return FALSE;
+ }
+
+ selected_account = gsb_gui_navigation_get_current_account ( );
+ if ( selected_account == -1 )
+ return FALSE;
+
+ gtk_tree_model_get ( model, iter, SPP_ESTIMATE_TREE_AMOUNT_COLUMN, &tmp_str, -1 );
+
+ amount = gsb_real_get_from_string ( tmp_str );
+
+ tmp_range -> current_balance = gsb_real_add ( tmp_range -> current_balance, amount );
+ str_balance = gsb_real_get_string_with_currency ( tmp_range -> current_balance,
+ gsb_data_account_get_currency ( selected_account ), TRUE );
+
+ if ( tmp_range->current_balance.mantissa < 0 )
+ color_str = "red";
+ else
+ color_str = NULL;
+
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ iter,
+ SPP_ESTIMATE_TREE_BALANCE_COLUMN, str_balance,
+ SPP_ESTIMATE_TREE_BALANCE_COLOR, color_str,
+ -1 );
+ g_free ( str_balance );
+
+ return FALSE;
+}
+
+
+/*
+ * bet_array_refresh_estimate_tab
+ * This function clears the estimate array and calculates new estimates.
+ * It updates the estimate graph.
+ * This function is called when the refresh button is pressed and when
+ * the balance estimate tab is selected.
+ */
+void bet_array_refresh_estimate_tab ( gint account_number )
+{
+ GtkWidget *widget;
+ GtkWidget *tree_view;
+ GtkTreeIter iter;
+ GtkTreeModel *tree_model;
+ GtkTreePath *path = NULL;
+ gchar *color_str = NULL;
+ gchar *str_date_min;
+ gchar *str_date_max;
+ gchar *str_current_balance;
+ gchar *str_amount;
+ gchar *title;
+ gchar *tmp_str;
+ GDate *date_init;
+ GDate *date_min;
+ GDate *date_max;
+ gsb_real current_balance;
+ SBR *tmp_range;
+ GValue date_value = {0, };
+
+ devel_debug (NULL);
+
+ tmp_range = struct_initialise_bet_range ( );
+
+ /* calculate date_min and date_max with user choice */
+ date_min = gsb_data_account_get_bet_start_date ( account_number );
+
+ date_max = bet_data_array_get_date_max ( account_number );
+
+ widget = g_object_get_data ( G_OBJECT ( account_page ), "bet_initial_date");
+ gsb_calendar_entry_set_date ( widget, date_min );
+
+ str_date_min = gsb_format_gdate ( date_min );
+
+ /* sert à mettre en première ligne le solde de début de période */
+ date_init = gsb_date_copy ( date_min );
+ g_date_subtract_days ( date_init, 1 );
+
+ g_value_init ( &date_value, G_TYPE_DATE );
+ g_value_set_boxed ( &date_value, date_init );
+
+ str_date_max = gsb_format_gdate ( date_max );
+
+ /* current balance may be in the future if there are transactions
+ * in the future in the account. So we need to calculate the balance
+ * of today */
+ current_balance = gsb_data_account_calculate_current_day_balance (
+ account_number, date_min );
+
+ str_amount = gsb_real_save_real_to_string ( current_balance, 2 );
+ str_current_balance = gsb_real_get_string_with_currency ( current_balance,
+ gsb_data_account_get_currency ( account_number ), TRUE );
+
+ if ( current_balance.mantissa < 0 )
+ color_str = "red";
+ else
+ color_str = NULL;
+
+ /* set the titles of tabs module budget */
+ title = g_strdup_printf (
+ _("Balance estimate of the account \"%s\" from %s to %s"),
+ gsb_data_account_get_name ( account_number ),
+ str_date_min, str_date_max );
+
+ widget = GTK_WIDGET ( g_object_get_data ( G_OBJECT ( account_page ), "bet_array_title") );
+ gtk_label_set_label ( GTK_LABEL ( widget ), title );
+ g_free ( title );
+
+ tree_view = g_object_get_data ( G_OBJECT ( account_page ), "bet_estimate_treeview" );
+ if ( gtk_tree_selection_get_selected (
+ gtk_tree_view_get_selection ( GTK_TREE_VIEW ( tree_view ) ),
+ &tree_model, &iter ) )
+ path = gtk_tree_model_get_path ( tree_model, &iter );
+
+ /* clear the model */
+ gtk_tree_store_clear ( GTK_TREE_STORE ( tree_model ) );
+
+ tmp_str = g_strdup ( _("balance beginning of period") );
+ gtk_tree_store_append ( GTK_TREE_STORE ( tree_model ), &iter, NULL );
+ gtk_tree_store_set_value (GTK_TREE_STORE ( tree_model ), &iter,
+ SPP_ESTIMATE_TREE_SORT_DATE_COLUMN,
+ &date_value);
+ gtk_tree_store_set(GTK_TREE_STORE(tree_model), &iter,
+ SPP_ESTIMATE_TREE_DATE_COLUMN, str_date_min,
+ SPP_ESTIMATE_TREE_DESC_COLUMN, tmp_str,
+ SPP_ESTIMATE_TREE_BALANCE_COLUMN, str_current_balance,
+ SPP_ESTIMATE_TREE_AMOUNT_COLUMN, str_amount,
+ SPP_ESTIMATE_TREE_BALANCE_COLOR, color_str,
+ SPP_ESTIMATE_TREE_BACKGROUND_COLOR, &couleur_fond[0],
+ -1);
+
+ g_value_unset ( &date_value );
+ g_free ( str_date_min );
+ g_free ( str_date_max );
+ g_free ( tmp_str );
+ g_free ( str_current_balance );
+ g_free ( str_amount );
+
+ /* search data from the past */
+ bet_historical_refresh_data ( tree_model, date_min, date_max );
+
+ /* search data from the futur */
+ bet_array_refresh_futur_data ( tree_model, date_min, date_max );
+
+ /* search transactions of the account which are in the period */
+ bet_array_refresh_transactions_data ( tree_model,
+ account_number,
+ date_min,
+ date_max );
+
+ /* for each schedulded operation */
+ bet_array_refresh_scheduled_data ( tree_model,
+ account_number,
+ date_min,
+ date_max );
+
+ /* search data from a transfer */
+ bet_array_refresh_transfert_data ( tree_model, date_min, date_max );
+
+ g_date_free ( date_min );
+ g_date_free ( date_init );
+ g_date_free ( date_max );
+
+ /* Calculate the balance column */
+ tmp_range -> first_pass = TRUE;
+ tmp_range -> current_balance = current_balance;
+
+ gtk_tree_model_foreach ( GTK_TREE_MODEL ( tree_model ),
+ bet_array_update_average_column, tmp_range );
+
+ bet_array_list_set_background_color ( tree_view );
+ bet_array_list_select_path ( tree_view, path );
+ gtk_tree_path_free ( path );
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+GtkWidget *bet_array_create_page ( void )
+{
+ GtkWidget *page;
+ GtkWidget *widget = NULL;
+ GtkWidget *initial_date = NULL;
+ GtkWidget *hbox;
+ GtkWidget *align;
+ GtkWidget *label;
+ GtkWidget *tree_view;
+
+ devel_debug (NULL);
+ page = gtk_vbox_new ( FALSE, 5 );
+ gtk_widget_set_name ( page, "forecast_page" );
+
+ /* create the title */
+ align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
+ gtk_box_pack_start ( GTK_BOX ( page ), align, FALSE, FALSE, 5) ;
+
+ label = gtk_label_new ("Estimate array");
+ gtk_container_add ( GTK_CONTAINER ( align ), label );
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_array_title", label );
+
+ align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
+ gtk_box_pack_start ( GTK_BOX ( page ), align, FALSE, FALSE, 5) ;
+
+ /* set the duration widget */
+ hbox = bet_config_get_duration_widget ( SPP_ORIGIN_ARRAY );
+ gtk_container_add ( GTK_CONTAINER ( align ), hbox );
+
+ /* set the start date and the automatic change of month */
+ label = gtk_label_new ( COLON ( _("Start date" ) ) );
+ gtk_misc_set_padding ( GTK_MISC (label), 5, 0 );
+ gtk_box_pack_start ( GTK_BOX (hbox), label, FALSE, FALSE, 0 );
+
+ initial_date = gsb_calendar_entry_new ( FALSE );
+ g_signal_connect ( G_OBJECT ( initial_date ),
+ "focus-out-event",
+ G_CALLBACK ( bet_array_start_date_focus_out ),
+ NULL );
+ g_signal_connect ( G_OBJECT ( initial_date ),
+ "key-press-event",
+ G_CALLBACK ( bet_array_entry_key_press ),
+ NULL );
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_initial_date", initial_date );
+ gtk_box_pack_start ( GTK_BOX (hbox), initial_date, FALSE, FALSE, 0 );
+
+ widget = gtk_check_button_new ( );
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( widget ), FALSE );
+ gtk_widget_set_tooltip_text ( GTK_WIDGET ( widget ),
+ SPACIFY(_("Check the box to automatically change start date") ) );
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_auto_inc_month", widget );
+ gtk_box_pack_start ( GTK_BOX (hbox), widget, FALSE, FALSE, 0 );
+ g_signal_connect ( G_OBJECT ( widget ),
+ "toggled",
+ G_CALLBACK ( bet_array_auto_inc_month_toggle ),
+ NULL );
+
+ tree_view = bet_array_create_tree_view ( );
+ gtk_box_pack_start ( GTK_BOX ( page ), tree_view, TRUE, TRUE, 5 );
+
+ gtk_widget_show_all ( page );
+
+ return page;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+GtkWidget *bet_array_create_tree_view ( void )
+{
+ GtkWidget *scrolled_window;
+ GtkWidget *tree_view;
+ GtkTreeStore *tree_model;
+ GtkTreeModel *sortable;
+ GtkCellRenderer *cell;
+ GtkTreeViewColumn *column;
+
+ /* create the estimate treeview */
+ tree_view = gtk_tree_view_new ( );
+ gtk_tree_view_set_rules_hint ( GTK_TREE_VIEW ( tree_view ), TRUE );
+ g_object_set_data ( G_OBJECT ( account_page ), "bet_estimate_treeview", tree_view );
+
+ /* create the model */
+ tree_model = gtk_tree_store_new ( SPP_ESTIMATE_TREE_NUM_COLUMNS,
+ G_TYPE_BOOLEAN, /* SPP_ESTIMATE_TREE_SELECT_COLUMN */
+ G_TYPE_INT, /* SPP_ESTIMATE_TREE_ORIGIN_DATA */
+ G_TYPE_INT, /* SPP_ESTIMATE_TREE_DIVISION_COLUMN */
+ G_TYPE_INT, /* SPP_ESTIMATE_TREE_SUB_DIV_COLUMN */
+ G_TYPE_STRING, /* SPP_ESTIMATE_TREE_DATE_COLUMN */
+ G_TYPE_STRING, /* SPP_ESTIMATE_TREE_DESC_COLUMN */
+ G_TYPE_STRING, /* SPP_ESTIMATE_TREE_DEBIT_COLUMN */
+ G_TYPE_STRING, /* SPP_ESTIMATE_TREE_CREDIT_COLUMN */
+ G_TYPE_STRING, /* SPP_ESTIMATE_TREE_BALANCE_COLUMN */
+ G_TYPE_DATE, /* SPP_ESTIMATE_TREE_SORT_DATE_COLUMN */
+ G_TYPE_STRING, /* SPP_ESTIMATE_TREE_AMOUNT_COLUMN */
+ G_TYPE_STRING, /* SPP_ESTIMATE_TREE_BALANCE_COLOR */
+ GDK_TYPE_COLOR ); /* SPP_ESTIMATE_TREE_BACKGROUND_COLOR */
+
+ gtk_tree_view_set_model ( GTK_TREE_VIEW ( tree_view ), GTK_TREE_MODEL ( tree_model ) );
+ g_object_unref ( G_OBJECT ( tree_model ) );
+
+ /* sort by date */
+ sortable = gtk_tree_model_sort_new_with_model ( GTK_TREE_MODEL ( tree_model ) );
+ gtk_tree_sortable_set_sort_func ( GTK_TREE_SORTABLE ( tree_model ),
+ SPP_ESTIMATE_TREE_SORT_DATE_COLUMN,
+ (GtkTreeIterCompareFunc) bet_array_date_sort_function,
+ NULL, NULL );
+ gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(tree_model),
+ SPP_ESTIMATE_TREE_SORT_DATE_COLUMN, GTK_SORT_DESCENDING);
+
+ scrolled_window = gtk_scrolled_window_new ( NULL, NULL );
+ gtk_widget_show ( scrolled_window );
+ gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW ( scrolled_window ),
+ GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
+ gtk_container_add ( GTK_CONTAINER ( scrolled_window ), tree_view );
+ gtk_widget_show ( scrolled_window );
+
+ /* Date column */
+ cell = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes (
+ _("Date"), cell,
+ "text", SPP_ESTIMATE_TREE_DATE_COLUMN,
+ "cell-background-gdk", SPP_ESTIMATE_TREE_BACKGROUND_COLOR,
+ NULL);
+ g_object_set (cell, "xalign", 0.5, NULL);
+
+ gtk_tree_view_column_set_alignment ( column, 0.5 );
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view),
+ GTK_TREE_VIEW_COLUMN(column));
+ gtk_tree_view_column_set_resizable ( column, TRUE );
+
+ /* Description column */
+ cell = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes (
+ _("Description"), cell,
+ "text", SPP_ESTIMATE_TREE_DESC_COLUMN,
+ "cell-background-gdk", SPP_ESTIMATE_TREE_BACKGROUND_COLOR,
+ NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW ( tree_view ),
+ GTK_TREE_VIEW_COLUMN ( column ) );
+ gtk_tree_view_column_set_expand ( GTK_TREE_VIEW_COLUMN ( column ), TRUE );
+ gtk_tree_view_column_set_resizable ( column, TRUE );
+
+ /* Debit column */
+ cell = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes (
+ _("Debit"), cell,
+ "text", SPP_ESTIMATE_TREE_DEBIT_COLUMN,
+ "cell-background-gdk", SPP_ESTIMATE_TREE_BACKGROUND_COLOR,
+ NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view),
+ GTK_TREE_VIEW_COLUMN(column));
+ g_object_set(G_OBJECT(GTK_CELL_RENDERER(cell)), "xalign", 1.0, NULL );
+ gtk_tree_view_column_set_alignment(column, 1);
+ gtk_tree_view_column_set_expand(GTK_TREE_VIEW_COLUMN(column), FALSE);
+ gtk_tree_view_column_set_resizable ( column, TRUE );
+
+ /* Credit column */
+ cell = gtk_cell_renderer_text_new ();
+ g_object_set(G_OBJECT(GTK_CELL_RENDERER(cell)), "xalign", 1.0, NULL );
+ column = gtk_tree_view_column_new_with_attributes (
+ _("Credit"), cell,
+ "text", SPP_ESTIMATE_TREE_CREDIT_COLUMN,
+ "cell-background-gdk", SPP_ESTIMATE_TREE_BACKGROUND_COLOR,
+ NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view),
+ GTK_TREE_VIEW_COLUMN(column));
+ g_object_set(G_OBJECT(GTK_CELL_RENDERER(cell)), "xalign", 1.0, NULL );
+ gtk_tree_view_column_set_alignment ( column, 1 );
+ gtk_tree_view_column_set_expand(GTK_TREE_VIEW_COLUMN(column), FALSE);
+ gtk_tree_view_column_set_resizable ( column, TRUE );
+
+ /* Balance column */
+ cell = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes (
+ _("Balance"), cell,
+ "text", SPP_ESTIMATE_TREE_BALANCE_COLUMN,
+ "foreground", SPP_ESTIMATE_TREE_BALANCE_COLOR,
+ "cell-background-gdk", SPP_ESTIMATE_TREE_BACKGROUND_COLOR,
+ NULL);
+ gtk_tree_view_append_column ( GTK_TREE_VIEW ( tree_view ),
+ GTK_TREE_VIEW_COLUMN(column));
+ g_object_set(G_OBJECT(GTK_CELL_RENDERER(cell)), "xalign", 1.0, NULL );
+ gtk_tree_view_column_set_alignment(column, 1);
+ gtk_tree_view_column_set_expand(GTK_TREE_VIEW_COLUMN(column), FALSE);
+ gtk_tree_view_column_set_resizable ( column, TRUE );
+ g_signal_connect ( G_OBJECT ( tree_view ),
+ "button-press-event",
+ G_CALLBACK ( bet_array_list_button_press ),
+ NULL );
+
+ gtk_widget_show_all ( tree_view );
+
+ return scrolled_window;;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_array_refresh_scheduled_data ( GtkTreeModel *tab_model,
+ gint selected_account,
+ GDate *date_min,
+ GDate *date_max )
+{
+ GtkTreeIter iter;
+ GSList* tmp_list;
+
+ //~ devel_debug (NULL);
+ tmp_list = gsb_data_scheduled_get_scheduled_list ( );
+
+ while (tmp_list)
+ {
+ gchar *str_amount;
+ gchar *str_debit = NULL;
+ gchar *str_credit = NULL;
+ const gchar *str_description = NULL;
+ gchar *str_date;
+ gint scheduled_number;
+ gint account_number;
+ gint transfer_account_number;
+ gint div_number;
+ gint sub_div_nb;
+ GDate *date;
+ GValue date_value = {0, };
+ gsb_real amount;
+
+ scheduled_number = gsb_data_scheduled_get_scheduled_number ( tmp_list->data );
+
+ tmp_list = tmp_list->next;
+
+ /* ignore children scheduled operations */
+ if (gsb_data_scheduled_get_mother_scheduled_number ( scheduled_number ) )
+ continue;
+
+ /* ignores transactions replaced with historical data */
+ account_number = gsb_data_scheduled_get_account_number ( scheduled_number );
+
+ div_number = bet_data_get_div_number ( scheduled_number, FALSE );
+ sub_div_nb = bet_data_get_sub_div_nb ( scheduled_number, FALSE );
+
+ if ( div_number > 0
+ &&
+ bet_data_search_div_hist ( account_number, div_number, 0 )
+ &&
+ bet_array_sort_scheduled_transactions ( div_number, sub_div_nb, tab_model ) )
+ continue;
+
+ /* ignore scheduled operations of other account */
+ if ( gsb_data_scheduled_is_transfer ( scheduled_number ) )
+ {
+ transfer_account_number = gsb_data_scheduled_get_account_number_transfer (
+ scheduled_number );
+ if ( transfer_account_number == selected_account )
+ {
+ str_description = g_strdup_printf ( _("Transfer between account: %s\n"
+ "and account: %s"),
+ gsb_data_account_get_name ( transfer_account_number ),
+ gsb_data_account_get_name ( account_number ) );
+
+ amount = gsb_real_opposite ( gsb_data_scheduled_get_amount (
+ scheduled_number ) );
+ }
+ else if ( account_number == selected_account )
+ {
+ str_description = g_strdup_printf ( _("Transfer between account: %s\n"
+ "and account: %s"),
+ gsb_data_account_get_name ( account_number ),
+ gsb_data_account_get_name ( transfer_account_number ) );
+
+ amount = gsb_data_scheduled_get_amount ( scheduled_number );
+ }
+ else
+ continue;
+ }
+ else if ( account_number == selected_account )
+ {
+ str_description = bet_array_list_get_description ( account_number,
+ SPP_ORIGIN_SCHEDULED,
+ GINT_TO_POINTER ( scheduled_number ) );
+
+ amount = gsb_data_scheduled_get_amount ( scheduled_number );
+ }
+ else
+ continue;
+
+ str_amount = gsb_real_save_real_to_string ( amount, 2 );
+ if (amount.mantissa < 0)
+ str_debit = gsb_real_get_string_with_currency ( gsb_real_abs ( amount ),
+ gsb_data_scheduled_get_currency_number ( scheduled_number ), TRUE );
+ else
+ str_credit = gsb_real_get_string_with_currency ( gsb_real_abs ( amount ),
+ gsb_data_scheduled_get_currency_number ( scheduled_number ), TRUE );
+
+ /* calculate each instance of the scheduled operation
+ * in the range from date_min (today) to date_max */
+ date = gsb_data_scheduled_get_date ( scheduled_number );
+
+ while ( date != NULL && g_date_valid ( date ) )
+ {
+ if ( g_date_compare ( date, date_max ) > 0 )
+ break;
+ if ( g_date_compare ( date, date_min ) < 0 )
+ {
+ date = gsb_scheduler_get_next_date ( scheduled_number, date );
+ continue;
+ }
+ if ( g_date_valid ( date ) == FALSE )
+ return;
+ str_date = gsb_format_gdate ( date );
+
+ if ( date == NULL )
+ return;
+ g_value_init ( &date_value, G_TYPE_DATE );
+ g_value_set_boxed ( &date_value, date );
+
+ /* add a line in the estimate array */
+ gtk_tree_store_append ( GTK_TREE_STORE ( tab_model ), &iter, NULL );
+ gtk_tree_store_set_value ( GTK_TREE_STORE ( tab_model ), &iter,
+ SPP_ESTIMATE_TREE_SORT_DATE_COLUMN,
+ &date_value );
+ gtk_tree_store_set ( GTK_TREE_STORE ( tab_model ), &iter,
+ SPP_ESTIMATE_TREE_ORIGIN_DATA, SPP_ORIGIN_SCHEDULED,
+ SPP_ESTIMATE_TREE_DIVISION_COLUMN, scheduled_number,
+ SPP_ESTIMATE_TREE_SUB_DIV_COLUMN, 0,
+ SPP_ESTIMATE_TREE_DATE_COLUMN, str_date,
+ SPP_ESTIMATE_TREE_DESC_COLUMN, str_description,
+ SPP_ESTIMATE_TREE_DEBIT_COLUMN, str_debit,
+ SPP_ESTIMATE_TREE_CREDIT_COLUMN, str_credit,
+ SPP_ESTIMATE_TREE_AMOUNT_COLUMN, str_amount,
+ -1 );
+
+ g_value_unset ( &date_value );
+ g_free ( str_date );
+ date = gsb_scheduler_get_next_date ( scheduled_number, date );
+ }
+
+ g_free ( str_amount );
+ if ( str_credit )
+ g_free ( str_credit );
+ if ( str_debit )
+ g_free ( str_debit );
+ }
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_array_refresh_transactions_data ( GtkTreeModel *tab_model,
+ gint selected_account,
+ GDate *date_min,
+ GDate *date_max )
+{
+ GDate *date_jour_1;
+ GDate *date_comp;
+ GSList *tmp_list;
+
+ //~ devel_debug (NULL);
+ /* init dates */
+ date_jour_1 = gdate_today ( );
+ if ( g_date_get_day ( date_min ) > 1 )
+ g_date_set_day ( date_jour_1, 1 );
+ if ( g_date_compare ( date_jour_1, date_min ) < 0 )
+ date_comp = date_jour_1;
+ else
+ date_comp = date_min;
+
+ /* search transactions of the account which are in the period */
+ tmp_list = gsb_data_transaction_get_transactions_list ( );
+
+ while ( tmp_list )
+ {
+ GtkTreeIter iter;
+ gchar* str_amount;
+ gchar* str_debit = NULL;
+ gchar* str_credit = NULL;
+ gchar* str_description;
+ gchar* str_date;
+ gint transaction_number;
+ gint transfer_number;
+ gint account_number;
+ gint transfer_account_number;
+ gint div_number;
+ gint sub_div_nb;
+ const GDate *date;
+ GValue date_value = {0, };
+ gsb_real amount;
+
+ transaction_number = gsb_data_transaction_get_transaction_number ( tmp_list->data );
+ tmp_list = tmp_list -> next;
+
+ account_number = gsb_data_transaction_get_account_number ( transaction_number );
+ if ( account_number != selected_account )
+ continue;
+
+ date = gsb_data_transaction_get_date ( transaction_number );
+
+ /* ignore transaction which are after date_max */
+ if ( g_date_compare (date, date_max ) > 0 )
+ continue;
+
+ /* ignore splitted transactions */
+ if ( gsb_data_transaction_get_mother_transaction_number (
+ transaction_number ) != 0 )
+ continue;
+
+ /* Ignore transactions that are before date_com */
+ if ( g_date_compare ( date, date_comp ) < 0 )
+ continue;
+
+ /* ignores transactions replaced with historical data */
+ amount = gsb_data_transaction_get_amount ( transaction_number );
+
+ div_number = bet_data_get_div_number ( transaction_number, TRUE );
+ sub_div_nb = bet_data_get_sub_div_nb ( transaction_number, TRUE );
+ if ( div_number > 0
+ &&
+ bet_data_search_div_hist ( account_number, div_number, 0 ) )
+ {
+ if ( g_date_get_month ( date ) == g_date_get_month ( date_jour_1 ) )
+ bet_array_adjust_hist_amount ( div_number, sub_div_nb, amount, tab_model );
+ }
+
+ /* ignore transaction which are before date_min */
+ 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 );
+
+ str_amount = gsb_real_save_real_to_string ( amount, 2 );
+
+ if (amount.mantissa < 0)
+ str_debit = gsb_real_get_string_with_currency ( gsb_real_abs ( amount ),
+ gsb_data_transaction_get_currency_number ( transaction_number), TRUE );
+ else
+ str_credit = gsb_real_get_string_with_currency ( gsb_real_abs ( amount ),
+ gsb_data_transaction_get_currency_number (transaction_number), TRUE);
+
+ transfer_number =
+ gsb_data_transaction_get_contra_transaction_number (
+ transaction_number );
+ if ( transfer_number > 0 )
+ {
+ transfer_account_number = gsb_data_transaction_get_account_number (
+ transfer_number );
+ str_description = g_strdup_printf ( _("Transfer between account: %s\n"
+ "and account: %s"),
+ gsb_data_account_get_name ( account_number ),
+ gsb_data_account_get_name ( transfer_account_number ) );
+ }
+ else
+ {
+ str_description = bet_array_list_get_description ( account_number,
+ SPP_ORIGIN_TRANSACTION,
+ GINT_TO_POINTER ( transaction_number ) );
+ }
+
+ /* add a line in the estimate array */
+ gtk_tree_store_append ( GTK_TREE_STORE ( tab_model ), &iter, NULL );
+ gtk_tree_store_set_value ( GTK_TREE_STORE ( tab_model ), &iter,
+ SPP_ESTIMATE_TREE_SORT_DATE_COLUMN,
+ &date_value );
+ gtk_tree_store_set ( GTK_TREE_STORE ( tab_model ), &iter,
+ SPP_ESTIMATE_TREE_ORIGIN_DATA, SPP_ORIGIN_TRANSACTION,
+ SPP_ESTIMATE_TREE_DIVISION_COLUMN, transaction_number,
+ SPP_ESTIMATE_TREE_SUB_DIV_COLUMN, 0,
+ SPP_ESTIMATE_TREE_DATE_COLUMN, str_date,
+ SPP_ESTIMATE_TREE_DESC_COLUMN, str_description,
+ SPP_ESTIMATE_TREE_DEBIT_COLUMN, str_debit,
+ SPP_ESTIMATE_TREE_CREDIT_COLUMN, str_credit,
+ SPP_ESTIMATE_TREE_AMOUNT_COLUMN, str_amount,
+ -1 );
+
+ g_value_unset ( &date_value );
+ g_free ( str_date );
+ g_free ( str_amount );
+ g_free ( str_description );
+ if ( str_debit )
+ g_free ( str_debit );
+ if ( str_credit )
+ g_free ( str_credit );
+ }
+}
+
+
+/**
+ * Add a new line with historical data
+ *
+ *
+ *
+ * */
+void bet_array_list_add_new_hist_line ( GtkTreeModel *tab_model,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ GDate *date_min,
+ GDate *date_max )
+{
+ GtkTreeIter tab_iter;
+ GDate *date;
+ GDate *date_jour;
+ GValue date_value = {0, };
+ gchar *str_date;
+ gchar *str_description;
+ gchar *str_value;
+ gchar *str_debit = NULL;
+ gchar *str_credit = NULL;
+ gchar *str_amount;
+ gint div_number;
+ gint sub_div_nb;
+ gsb_real amount;
+
+ //~ devel_debug (NULL);
+ date_jour = gdate_today ( );
+ date = gsb_date_get_last_day_of_month ( date_min );
+
+ /* initialise les données de la ligne insérée */
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), iter,
+ SPP_HISTORICAL_DESC_COLUMN, &str_description,
+ SPP_HISTORICAL_RETAINED_COLUMN, &str_value,
+ SPP_HISTORICAL_RETAINED_AMOUNT, &str_amount,
+ SPP_HISTORICAL_DIV_NUMBER, &div_number,
+ SPP_HISTORICAL_SUB_DIV_NUMBER, &sub_div_nb,
+ -1 );
+
+ if ( sub_div_nb > 0 )
+ {
+ g_free ( str_description );
+ str_description = bet_data_get_div_name ( div_number, sub_div_nb, NULL );
+ }
+
+ amount = gsb_real_get_from_string ( str_amount );
+
+ if ( amount.mantissa < 0 )
+ str_debit = gsb_real_get_string_with_currency ( gsb_real_opposite ( amount ),
+ bet_data_get_selected_currency ( ), TRUE );
+ else
+ str_credit = str_value;
+
+ while ( date != NULL && g_date_valid ( date ) )
+ {
+ if ( g_date_compare ( date, date_max ) > 0 )
+ break;
+
+ if ( g_date_compare ( date, date_min ) < 0
+ ||
+ g_date_get_month ( date ) < g_date_get_month ( date_jour ) )
+ {
+ g_date_add_months ( date, 1 );
+ continue;
+ }
+
+ if ( g_date_valid ( date ) == FALSE )
+ return;
+
+ str_date = gsb_format_gdate ( date );
+
+ g_value_init ( &date_value, G_TYPE_DATE );
+ if ( date == NULL )
+ return;
+ g_value_set_boxed ( &date_value, date );
+
+ /* add a line in the estimate array */
+ gtk_tree_store_append ( GTK_TREE_STORE ( tab_model ), &tab_iter, NULL );
+ gtk_tree_store_set_value ( GTK_TREE_STORE ( tab_model ), &tab_iter,
+ SPP_ESTIMATE_TREE_SORT_DATE_COLUMN,
+ &date_value );
+ gtk_tree_store_set ( GTK_TREE_STORE ( tab_model ), &tab_iter,
+ SPP_ESTIMATE_TREE_ORIGIN_DATA, SPP_ORIGIN_HISTORICAL,
+ SPP_ESTIMATE_TREE_DIVISION_COLUMN, div_number,
+ SPP_ESTIMATE_TREE_SUB_DIV_COLUMN, sub_div_nb,
+ SPP_ESTIMATE_TREE_DATE_COLUMN, str_date,
+ SPP_ESTIMATE_TREE_DESC_COLUMN, str_description,
+ SPP_ESTIMATE_TREE_DEBIT_COLUMN, str_debit,
+ SPP_ESTIMATE_TREE_CREDIT_COLUMN, str_credit,
+ SPP_ESTIMATE_TREE_AMOUNT_COLUMN, str_amount,
+ -1);
+
+ g_value_unset ( &date_value );
+ g_free ( str_date );
+ g_date_add_months ( date, 1 );
+ date = gsb_date_get_last_day_of_month ( date );
+ }
+
+ g_free ( str_description );
+ if ( str_debit )
+ g_free ( str_debit );
+ g_free ( str_value );
+ g_free ( str_amount );
+}
+
+
+/**
+ * Ajoute la ligne future au tableau des résultats
+ *
+ *
+ *
+ * */
+gboolean bet_array_refresh_futur_data ( GtkTreeModel *tab_model,
+ GDate *date_min,
+ GDate *date_max )
+{
+ GHashTable *future_list;
+ GHashTableIter iter;
+ gpointer key, value;
+ gint account_number;
+
+ //~ devel_debug (NULL);
+
+ account_number = gsb_gui_navigation_get_current_account ( );
+ future_list = bet_data_future_get_list ( );
+
+ g_hash_table_iter_init ( &iter, future_list );
+ while ( g_hash_table_iter_next ( &iter, &key, &value ) )
+ {
+ struct_futur_data *scheduled = ( struct_futur_data *) value;
+ GtkTreeIter tab_iter;
+ GValue date_value = {0, };
+ gchar *str_debit = NULL;
+ gchar *str_credit = NULL;
+ gchar *str_date;
+ gchar *str_description;
+ gchar *str_amount;
+ GDate *date_tomorrow;
+ gsb_real amount;
+ gboolean inverse_amount = FALSE;
+
+ if ( account_number != scheduled -> account_number )
+ {
+ if ( scheduled -> is_transfert == 0
+ || ( scheduled -> is_transfert && account_number != scheduled -> account_transfert ) )
+ continue;
+ else
+ inverse_amount = TRUE;
+ }
+
+ date_tomorrow = gsb_date_tomorrow ( );
+ if ( g_date_compare ( scheduled -> date, date_tomorrow ) < 0 )
+ {
+ bet_data_future_remove_line ( account_number, scheduled -> number, FALSE );
+ g_hash_table_iter_init ( &iter, future_list );
+ g_date_free ( date_tomorrow );
+ if ( g_hash_table_size ( future_list ) == 0 )
+ return FALSE;
+ continue;
+ }
+ else
+ g_date_free ( date_tomorrow );
+
+ if ( g_date_compare ( scheduled -> date, date_max ) > 0 )
+ continue;
+ if ( g_date_compare ( scheduled -> date, date_min ) < 0 )
+ continue;
+
+ str_description = bet_array_list_get_description ( account_number,
+ SPP_ORIGIN_FUTURE,
+ value );
+
+ if ( inverse_amount )
+ amount = gsb_real_opposite ( scheduled -> amount );
+ else
+ amount = scheduled -> amount;
+
+ str_amount = gsb_real_save_real_to_string ( amount, 2 );
+
+ if ( amount.mantissa < 0 )
+ str_debit = gsb_real_get_string_with_currency ( gsb_real_opposite ( amount ),
+ bet_data_get_selected_currency ( ), TRUE );
+ else
+ str_credit = gsb_real_get_string_with_currency ( amount,
+ bet_data_get_selected_currency ( ), TRUE );
+
+ str_date = gsb_format_gdate ( scheduled -> date );
+
+ g_value_init ( &date_value, G_TYPE_DATE );
+ g_value_set_boxed ( &date_value, scheduled -> date );
+
+ /* add a line in the estimate array */
+ gtk_tree_store_append ( GTK_TREE_STORE ( tab_model ), &tab_iter, NULL );
+ gtk_tree_store_set_value ( GTK_TREE_STORE ( tab_model ), &tab_iter,
+ SPP_ESTIMATE_TREE_SORT_DATE_COLUMN,
+ &date_value );
+ gtk_tree_store_set ( GTK_TREE_STORE ( tab_model ), &tab_iter,
+ SPP_ESTIMATE_TREE_ORIGIN_DATA, SPP_ORIGIN_FUTURE,
+ SPP_ESTIMATE_TREE_DIVISION_COLUMN, scheduled -> number,
+ SPP_ESTIMATE_TREE_SUB_DIV_COLUMN, scheduled -> mother_row,
+ SPP_ESTIMATE_TREE_DATE_COLUMN, str_date,
+ SPP_ESTIMATE_TREE_DESC_COLUMN, str_description,
+ SPP_ESTIMATE_TREE_DEBIT_COLUMN, str_debit,
+ SPP_ESTIMATE_TREE_CREDIT_COLUMN, str_credit,
+ SPP_ESTIMATE_TREE_AMOUNT_COLUMN, str_amount,
+ -1);
+
+ g_value_unset ( &date_value );
+ g_free ( str_date );
+ g_free ( str_description );
+ g_free ( str_amount );
+ if ( str_debit )
+ g_free ( str_debit );
+ if ( str_credit )
+ g_free ( str_credit );
+ }
+
+ return TRUE;
+}
+
+
+/**
+ * called when we press a button on the list
+ *
+ * \param tree_view
+ * \param ev
+ *
+ * \return FALSE
+ * */
+gboolean bet_array_list_button_press ( GtkWidget *tree_view,
+ GdkEventButton *ev )
+{
+ /* show the popup */
+ if ( ev -> button == RIGHT_BUTTON )
+ bet_array_list_context_menu ( tree_view );
+ if ( ev -> type == GDK_2BUTTON_PRESS )
+ bet_array_list_traite_double_click ( GTK_TREE_VIEW ( tree_view ) );
+
+ return FALSE;
+}
+
+
+/**
+ * Pop up a menu with several actions to apply to array_list.
+ *
+ * \param
+ *
+ */
+void bet_array_list_context_menu ( GtkWidget *tree_view )
+{
+ GtkWidget *image;
+ GtkWidget *menu, *menu_item;
+ GtkTreeModel *model;
+ GtkTreeSelection *tree_selection;
+ GtkTreeIter iter;
+ GDate *date;
+ GDate *date_jour;
+ gchar *str_date;
+ gchar *tmp_str;
+ gboolean select = FALSE;
+ gint origine;
+
+ tree_selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW ( tree_view ) );
+
+ if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( tree_selection ),
+ &model, &iter ) )
+ return;
+
+ gtk_tree_model_get ( model, &iter,
+ SPP_ESTIMATE_TREE_SELECT_COLUMN, &select,
+ SPP_ESTIMATE_TREE_ORIGIN_DATA, &origine,
+ SPP_ESTIMATE_TREE_DATE_COLUMN, &str_date,
+ -1 );
+
+ date = gsb_parse_date_string ( str_date );
+ date_jour = gdate_today ( );
+
+ menu = gtk_menu_new ();
+
+ /* Add substract amount menu */
+ if ( select == FALSE )
+ {
+ menu_item = gtk_image_menu_item_new_with_label ( _("Subtract to the balance") );
+ gtk_image_menu_item_set_image ( GTK_IMAGE_MENU_ITEM ( menu_item ),
+ gtk_image_new_from_stock ( GTK_STOCK_REMOVE,
+ GTK_ICON_SIZE_MENU ) );
+ }
+ else
+ {
+ menu_item = gtk_image_menu_item_new_with_label ( _("Adding to the balance") );
+ gtk_image_menu_item_set_image ( GTK_IMAGE_MENU_ITEM ( menu_item ),
+ gtk_image_new_from_stock ( GTK_STOCK_ADD,
+ GTK_ICON_SIZE_MENU ) );
+ }
+ g_signal_connect ( G_OBJECT ( menu_item ),
+ "activate",
+ G_CALLBACK ( bet_array_list_add_substract_menu ),
+ tree_selection );
+
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), menu_item );
+
+ /* Separator */
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), gtk_separator_menu_item_new ( ) );
+ gtk_widget_show ( menu_item );
+
+ /* Insert Row */
+ menu_item = gtk_image_menu_item_new_with_label ( _("Insert Row") );
+ gtk_image_menu_item_set_image ( GTK_IMAGE_MENU_ITEM ( menu_item ),
+ gtk_image_new_from_stock ( GTK_STOCK_ADD,
+ GTK_ICON_SIZE_MENU ) );
+ g_signal_connect ( G_OBJECT ( menu_item ),
+ "activate",
+ G_CALLBACK ( bet_array_list_insert_menu ),
+ tree_selection );
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), menu_item );
+
+ /* Delete convert item */
+ switch ( origine )
+ {
+ case SPP_ORIGIN_TRANSACTION:
+ case SPP_ORIGIN_SCHEDULED:
+ if ( g_date_compare ( date, date_jour ) > 0 )
+ {
+ menu_item = gtk_image_menu_item_new_with_label ( _("Delete selection") );
+ gtk_image_menu_item_set_image ( GTK_IMAGE_MENU_ITEM ( menu_item ),
+ gtk_image_new_from_stock ( GTK_STOCK_DELETE,
+ GTK_ICON_SIZE_MENU ) );
+ g_signal_connect ( G_OBJECT ( menu_item ),
+ "activate",
+ G_CALLBACK ( bet_array_list_delete_menu ),
+ tree_selection );
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), menu_item );
+ }
+ break;
+ case SPP_ORIGIN_HISTORICAL:
+ menu_item = gtk_image_menu_item_new_with_label ( _("Delete selection") );
+ gtk_image_menu_item_set_image ( GTK_IMAGE_MENU_ITEM ( menu_item ),
+ gtk_image_new_from_stock ( GTK_STOCK_DELETE,
+ GTK_ICON_SIZE_MENU ) );
+ g_signal_connect ( G_OBJECT ( menu_item ),
+ "activate",
+ G_CALLBACK ( bet_array_list_delete_menu ),
+ tree_selection );
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), menu_item );
+ break;
+ case SPP_ORIGIN_FUTURE:
+ menu_item = gtk_image_menu_item_new_with_label ( _("Change selection") );
+ gtk_image_menu_item_set_image ( GTK_IMAGE_MENU_ITEM ( menu_item ),
+ gtk_image_new_from_stock ( GTK_STOCK_EDIT,
+ GTK_ICON_SIZE_MENU ) );
+ g_signal_connect ( G_OBJECT ( menu_item ),
+ "activate",
+ G_CALLBACK ( bet_array_list_change_menu ),
+ tree_selection );
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), menu_item );
+
+ menu_item = gtk_image_menu_item_new_with_label ( _("Delete selection") );
+ gtk_image_menu_item_set_image ( GTK_IMAGE_MENU_ITEM ( menu_item ),
+ gtk_image_new_from_stock ( GTK_STOCK_DELETE,
+ GTK_ICON_SIZE_MENU ) );
+ g_signal_connect ( G_OBJECT ( menu_item ),
+ "activate",
+ G_CALLBACK ( bet_array_list_delete_menu ),
+ tree_selection );
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), menu_item );
+
+ menu_item = gtk_image_menu_item_new_with_label (
+ _("Delete all occurences of the selection") );
+ gtk_image_menu_item_set_image ( GTK_IMAGE_MENU_ITEM ( menu_item ),
+ gtk_image_new_from_stock ( GTK_STOCK_DELETE,
+ GTK_ICON_SIZE_MENU ) );
+ g_signal_connect ( G_OBJECT ( menu_item ),
+ "activate",
+ G_CALLBACK ( bet_array_list_delete_all_menu ),
+ tree_selection );
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), menu_item );
+
+ /* Separator */
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), gtk_separator_menu_item_new() );
+
+ /* Convert to scheduled transaction */
+ menu_item = gtk_image_menu_item_new_with_label (
+ _("Convert selection to scheduled transaction") );
+ gtk_image_menu_item_set_image ( GTK_IMAGE_MENU_ITEM ( menu_item ),
+ gtk_image_new_from_stock ( GTK_STOCK_CONVERT,
+ GTK_ICON_SIZE_MENU ) );
+ g_signal_connect ( G_OBJECT ( menu_item ),
+ "activate",
+ G_CALLBACK ( bet_array_list_schedule_selected_line ),
+ tree_selection );
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), menu_item );
+ break;
+ }
+
+ /* Separator */
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), gtk_separator_menu_item_new ( ) );
+ gtk_widget_show ( menu_item );
+
+ /* Insert an account balance */
+ tmp_str = g_build_filename ( PIXMAPS_DIR, "ac_bank_16.png", NULL);
+ image = gtk_image_new_from_file ( tmp_str );
+ g_free ( tmp_str );
+ menu_item = gtk_image_menu_item_new_with_label (
+ _("Insert the balance of a cash account") );
+ gtk_image_menu_item_set_image ( GTK_IMAGE_MENU_ITEM ( menu_item ), image );
+ g_signal_connect ( G_OBJECT ( menu_item ),
+ "activate",
+ G_CALLBACK ( bet_array_list_insert_account_balance_menu ),
+ tree_selection );
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), menu_item );
+
+ if ( origine == SPP_ORIGIN_ACCOUNT )
+ {
+ menu_item = gtk_image_menu_item_new_with_label ( _("Delete selection") );
+ gtk_image_menu_item_set_image ( GTK_IMAGE_MENU_ITEM ( menu_item ),
+ gtk_image_new_from_stock ( GTK_STOCK_DELETE,
+ GTK_ICON_SIZE_MENU ) );
+ g_signal_connect ( G_OBJECT ( menu_item ),
+ "activate",
+ G_CALLBACK ( bet_array_list_delete_menu ),
+ tree_selection );
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), menu_item );
+ }
+
+ /* Separator */
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), gtk_separator_menu_item_new() );
+ gtk_widget_show ( menu_item );
+
+ /* redo item */
+ menu_item = gtk_image_menu_item_new_with_label ( _("Reset data") );
+ gtk_image_menu_item_set_image ( GTK_IMAGE_MENU_ITEM ( menu_item ),
+ gtk_image_new_from_stock ( GTK_STOCK_REFRESH,
+ GTK_ICON_SIZE_MENU ) );
+ g_signal_connect ( G_OBJECT ( menu_item ),
+ "activate",
+ G_CALLBACK ( bet_array_list_redo_menu ),
+ tree_selection );
+ gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), menu_item );
+
+ /* Finish all. */
+ gtk_widget_show_all ( menu );
+ gtk_menu_popup ( GTK_MENU( menu ), NULL, NULL, NULL, NULL, 3,
+ gtk_get_current_event_time ( ) );
+
+ g_date_free ( date_jour );
+}
+
+
+/**
+ * add or substract amount of the balance
+ *
+ * /param menu item
+ * /param row selected
+ *
+ * */
+void bet_array_list_add_substract_menu ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection )
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gboolean select = FALSE;
+
+ if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( tree_selection ),
+ &model, &iter ) )
+ return;
+
+ gtk_tree_model_get ( model, &iter, SPP_ESTIMATE_TREE_SELECT_COLUMN, &select, -1 );
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ), &iter,
+ SPP_ESTIMATE_TREE_SELECT_COLUMN, 1 - select,
+ -1);
+ bet_array_list_update_balance ( model );
+}
+
+
+void bet_array_list_change_menu ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection )
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gint origine;
+ gint number;
+ gint mother_row;
+
+ if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( tree_selection ),
+ &model, &iter ) )
+ return;
+
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
+ SPP_ESTIMATE_TREE_ORIGIN_DATA, &origine,
+ SPP_ESTIMATE_TREE_DIVISION_COLUMN, &number,
+ SPP_ESTIMATE_TREE_SUB_DIV_COLUMN, &mother_row,
+ -1 );
+
+ if ( origine == SPP_ORIGIN_TRANSACTION )
+ {
+ gtk_notebook_set_current_page ( GTK_NOTEBOOK ( account_page ), 0 );
+ transaction_list_select ( number );
+ gsb_transactions_list_edit_transaction ( number );
+ }
+ else if ( origine == SPP_ORIGIN_SCHEDULED )
+ {
+ gsb_gui_navigation_set_selection ( GSB_SCHEDULER_PAGE, 0, NULL );
+ gsb_scheduler_list_select ( number );
+ gsb_scheduler_list_edit_transaction ( number );
+ }
+ else if ( origine == SPP_ORIGIN_FUTURE )
+ bet_future_modify_line ( gsb_gui_navigation_get_current_account ( ), number, mother_row );
+ else if ( origine == SPP_ORIGIN_ACCOUNT )
+ bet_transfert_modify_line ( gsb_gui_navigation_get_current_account ( ), number );
+}
+
+
+/**
+ * delete a row
+ *
+ * /param menu item
+ * /param row selected
+ *
+ * */
+void bet_array_list_delete_menu ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection )
+{
+ GtkTreeView *tree_view;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gint origine;
+ gint number;
+
+ if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( tree_selection ),
+ &model, &iter ) )
+ return;
+
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
+ SPP_ESTIMATE_TREE_ORIGIN_DATA, &origine,
+ SPP_ESTIMATE_TREE_DIVISION_COLUMN, &number,
+ -1 );
+
+ if ( origine == SPP_ORIGIN_HISTORICAL )
+ {
+ gint account_number;
+ gint sub_div_nb;
+
+ account_number = gsb_gui_navigation_get_current_account ( );
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
+ SPP_ESTIMATE_TREE_SUB_DIV_COLUMN, &sub_div_nb,
+ -1 );
+ bet_data_remove_div_hist ( account_number, number, sub_div_nb );
+ gtk_tree_store_remove ( GTK_TREE_STORE ( model ), &iter );
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_HISTORICAL );
+ }
+ else if ( origine == SPP_ORIGIN_FUTURE )
+ {
+ bet_data_future_remove_line ( gsb_gui_navigation_get_current_account ( ), number, TRUE );
+ }
+ else if ( origine == SPP_ORIGIN_ACCOUNT )
+ {
+ bet_data_transfert_remove_line ( gsb_gui_navigation_get_current_account ( ), number );
+ }
+
+ tree_view = gtk_tree_selection_get_tree_view ( tree_selection );
+ bet_array_list_set_background_color ( GTK_WIDGET ( tree_view ) );
+ bet_array_list_update_balance ( model );
+}
+
+
+/**
+ * delete all occurences of future data row
+ *
+ * /param menu item
+ * /param row selected
+ *
+ * */
+void bet_array_list_delete_all_menu ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection )
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gint origine;
+ gint number;
+ gint mother_row;
+ gint account_number;
+
+ if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( tree_selection ), &model, &iter ) )
+ return;
+
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
+ SPP_ESTIMATE_TREE_ORIGIN_DATA, &origine,
+ SPP_ESTIMATE_TREE_DIVISION_COLUMN, &number,
+ SPP_ESTIMATE_TREE_SUB_DIV_COLUMN, &mother_row,
+ -1 );
+
+ if ( origine == SPP_ORIGIN_FUTURE )
+ {
+ account_number = gsb_gui_navigation_get_current_account ( );
+ bet_data_future_remove_lines ( account_number, number, mother_row );
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ bet_data_update_bet_module ( account_number, GSB_ESTIMATE_PAGE );
+ }
+}
+
+
+/**
+ * insert a row
+ *
+ * /param menu item
+ * /param row selected
+ *
+ * */
+void bet_array_list_insert_menu ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection )
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gchar *str_date;
+
+ if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( tree_selection ),
+ &model, &iter ) )
+ return;
+
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
+ SPP_ESTIMATE_TREE_DATE_COLUMN, &str_date,
+ -1 );
+
+ bet_future_new_line_dialog ( model, str_date );
+}
+
+
+/**
+ * insert an account balance
+ *
+ * /param menu item
+ * /param row selected
+ *
+ * */
+void bet_array_list_insert_account_balance_menu ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection )
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gchar *str_date;
+
+ if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( tree_selection ),
+ &model, &iter ) )
+ return;
+
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
+ SPP_ESTIMATE_TREE_DATE_COLUMN, &str_date,
+ -1 );
+
+ bet_transfert_new_line_dialog ( model, str_date );
+}
+
+
+/**
+ * init data
+ *
+ * /param menu item
+ * /param row selected
+ *
+ * */
+void bet_array_list_redo_menu ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection )
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gint account_number;
+
+ if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( tree_selection ),
+ &model, &iter ) )
+ return;
+
+ account_number = gsb_gui_navigation_get_current_account ( );
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ bet_data_update_bet_module ( account_number, GSB_ESTIMATE_PAGE );
+}
+
+
+/**
+ * Cette fonction recalcule le montant des données historiques en fonction de la
+ * consommation mensuelle précédente. affiche le nouveau montant si même signe ou 0
+ * et un message pour budget dépassé.
+ *
+ * */
+void bet_array_adjust_hist_amount ( gint div_number,
+ gint sub_div_nb,
+ gsb_real amount,
+ GtkTreeModel *model )
+{
+ GtkTreeIter iter;
+
+ if ( gtk_tree_model_get_iter_first ( GTK_TREE_MODEL ( model ), &iter ) )
+ {
+ gchar* str_date;
+ gchar *str_desc;
+ gchar* str_debit = NULL;
+ gchar* str_credit = NULL;
+ gchar *str_amount;
+ gchar *div_name;
+ GDate *date;
+ GDate *date_today;
+ gsb_real number;
+ gint sign = 1;
+ gint tmp_div_number;
+ gint tmp_sub_div_nb;
+
+ do
+ {
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ),
+ &iter,
+ SPP_ESTIMATE_TREE_DIVISION_COLUMN, &tmp_div_number,
+ SPP_ESTIMATE_TREE_SUB_DIV_COLUMN, &tmp_sub_div_nb,
+ SPP_ESTIMATE_TREE_DATE_COLUMN, &str_date,
+ SPP_ESTIMATE_TREE_DESC_COLUMN, &str_desc,
+ SPP_ESTIMATE_TREE_AMOUNT_COLUMN, &str_amount,
+ -1 );
+
+ if ( tmp_div_number == 0 || tmp_div_number != div_number )
+ continue;
+
+ if ( tmp_sub_div_nb == 0 || tmp_sub_div_nb == sub_div_nb )
+ {
+ div_name = bet_data_get_div_name ( tmp_div_number, tmp_sub_div_nb, FALSE );
+ //~ printf ("div_number = %d, sub_div_number = %d div_name = %s str_desc = %s\n",
+ //~ tmp_div_number, tmp_sub_div_nb, div_name, str_desc );
+ date = gsb_parse_date_string ( str_date );
+ date_today = gdate_today ( );
+ if ( g_date_get_month ( date ) - g_date_get_month ( date_today ) == 0 )
+ {
+ number = gsb_real_import_from_string ( str_amount );
+ if ( number .mantissa < 0 )
+ sign = -1;
+ number = gsb_real_sub ( number, amount );
+ if ( number.mantissa == 0 )
+ gtk_tree_store_remove ( GTK_TREE_STORE ( model ), &iter );
+ else
+ {
+ if ( str_amount )
+ g_free ( str_amount );
+ if ( str_desc )
+ g_free ( str_desc );
+
+ str_amount = gsb_real_save_real_to_string ( number, 2 );
+ if ( number.mantissa < 0 && sign < 0 )
+ {
+ str_debit = gsb_real_get_string_with_currency (
+ gsb_real_abs ( number ),
+ bet_data_get_selected_currency ( ),
+ TRUE );
+ str_desc = g_strconcat ( div_name, _(" (still available)"), NULL);
+ }
+ else if ( number.mantissa > 0 && sign > 0 )
+ {
+ str_credit = gsb_real_get_string_with_currency (
+ gsb_real_abs ( number ),
+ bet_data_get_selected_currency ( ),
+ TRUE );
+ str_desc = g_strconcat ( div_name, _(" (yet to receive)"), NULL);
+ }
+ else if ( sign == -1 )
+ {
+ str_debit = gsb_real_get_string_with_currency (
+ null_real,
+ bet_data_get_selected_currency ( ),
+ TRUE );
+ if ( str_amount )
+ g_free ( str_amount );
+ str_amount = g_strdup ( "0.00" );
+ str_desc = g_strconcat ( div_name, _(" (budget exceeded)"), NULL);
+ }
+ else
+ {
+ str_credit = gsb_real_get_string_with_currency (
+ null_real,
+ bet_data_get_selected_currency ( ),
+ TRUE );
+ if ( str_amount )
+ g_free ( str_amount );
+ str_amount = g_strdup ( "0.00" );
+ str_desc = g_strconcat ( div_name, _(" (budget exceeded)"), NULL);
+ }
+
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ), &iter,
+ SPP_ESTIMATE_TREE_DESC_COLUMN, str_desc,
+ SPP_ESTIMATE_TREE_DEBIT_COLUMN, str_debit,
+ SPP_ESTIMATE_TREE_CREDIT_COLUMN, str_credit,
+ SPP_ESTIMATE_TREE_AMOUNT_COLUMN, str_amount,
+ -1 );
+
+ g_free ( str_desc );
+ g_free ( str_credit );
+ g_free ( str_debit );
+ g_free ( str_amount );
+ }
+ g_free ( str_date );
+ g_free ( div_name );
+ break;
+ }
+ g_free ( div_name );
+ }
+ g_free ( str_date );
+ g_free ( str_desc );
+ g_free ( str_amount );
+ }
+ while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL ( model ), &iter ) );
+ }
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_array_list_update_balance ( GtkTreeModel *model )
+{
+ GtkTreeIter iter;
+
+ if ( gtk_tree_model_get_iter_first ( model, &iter) )
+ {
+ gchar *str_current_balance;
+ gsb_real current_balance;
+ SBR *tmp_range;
+
+ gtk_tree_model_get ( model, &iter,
+ SPP_ESTIMATE_TREE_AMOUNT_COLUMN, &str_current_balance, -1 );
+ current_balance = gsb_real_get_from_string ( str_current_balance );
+
+ tmp_range = struct_initialise_bet_range ( );
+ tmp_range -> first_pass = TRUE;
+ tmp_range -> current_balance = current_balance;
+
+ gtk_tree_model_foreach ( GTK_TREE_MODEL ( model ),
+ bet_array_update_average_column, tmp_range );
+ }
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_array_entry_key_press ( GtkWidget *entry,
+ GdkEventKey *ev,
+ gpointer data )
+{
+ gint account_nb;
+ GDate *date;
+
+ switch ( ev -> keyval )
+ {
+ case GDK_Escape :
+ account_nb = gsb_gui_navigation_get_current_account ( );
+ date = gsb_data_account_get_bet_start_date ( account_nb );
+ gtk_entry_set_text ( GTK_ENTRY ( entry ),
+ gsb_format_gdate ( date ) );
+ break;
+ case GDK_KP_Enter :
+ case GDK_Return :
+ bet_array_start_date_focus_out ( entry, NULL, data );
+ break;
+ }
+
+ return FALSE;
+}
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_array_start_date_focus_out ( GtkWidget *entry,
+ GdkEventFocus *ev,
+ gpointer data )
+{
+ gint account_number;
+ GDate *date;
+
+ devel_debug (gtk_entry_get_text ( GTK_ENTRY ( entry ) ));
+ gtk_editable_select_region ( GTK_EDITABLE ( entry ), 0, 0 );
+ account_number = gsb_gui_navigation_get_current_account ( );
+
+ date = gsb_parse_date_string ( gtk_entry_get_text ( GTK_ENTRY ( entry ) ) );
+ if ( gsb_data_account_get_bet_auto_inc_month ( account_number ) )
+ {
+ GDate *old_date;
+
+ old_date = gsb_data_account_get_bet_start_date ( account_number );
+ if ( g_date_compare ( date, old_date ) != 0 )
+ gsb_data_account_set_bet_auto_inc_month ( account_number, FALSE );
+ }
+
+ gsb_data_account_set_bet_start_date ( account_number, date );
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ bet_data_update_bet_module ( account_number, GSB_ESTIMATE_PAGE );
+
+ return FALSE;
+}
+
+
+/**
+ * select path in the list
+ *
+ * \param tree_view, path
+ *
+ * \return FALSE
+ * */
+gboolean bet_array_list_select_path ( GtkWidget *tree_view, GtkTreePath *path )
+{
+ GtkTreeSelection *selection;
+
+ selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW ( tree_view ) );
+
+ if ( path == NULL )
+ path = gtk_tree_path_new_from_string ( "0" );
+
+ gtk_widget_grab_focus ( tree_view );
+ gtk_tree_selection_select_path ( selection, path );
+
+ return FALSE;
+}
+
+
+/**
+ * set the background colors of the list
+ *
+ * \param tree_view
+ *
+ * \return FALSE
+ * */
+gboolean bet_array_list_set_background_color ( GtkWidget *tree_view )
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ if ( !tree_view )
+ return FALSE;
+
+ model = gtk_tree_view_get_model ( GTK_TREE_VIEW ( tree_view ));
+
+ if ( gtk_tree_model_get_iter_first ( GTK_TREE_MODEL ( model ), &iter ) )
+ {
+ gint origine;
+ gint current_color = 0;
+
+ do
+ {
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ),
+ &iter,
+ SPP_ESTIMATE_TREE_ORIGIN_DATA, &origine,
+ -1 );
+ switch ( origine )
+ {
+ case SPP_ORIGIN_TRANSACTION:
+ case SPP_ORIGIN_SCHEDULED:
+
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ &iter,
+ SPP_ESTIMATE_TREE_BACKGROUND_COLOR, &couleur_fond[current_color],
+ -1 );
+ current_color = !current_color;
+ break;
+ case SPP_ORIGIN_HISTORICAL:
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ &iter,
+ SPP_ESTIMATE_TREE_BACKGROUND_COLOR, &couleur_bet_division,
+ -1 );
+ break;
+ case SPP_ORIGIN_FUTURE:
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ &iter,
+ SPP_ESTIMATE_TREE_BACKGROUND_COLOR, &couleur_bet_future,
+ -1 );
+ break;
+ case SPP_ORIGIN_ACCOUNT:
+ gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+ &iter,
+ SPP_ESTIMATE_TREE_BACKGROUND_COLOR, &couleur_bet_transfert,
+ -1 );
+ break;
+ }
+ }
+ while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL ( model ), &iter ) );
+ }
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_array_initializes_account_settings ( gint account_number )
+{
+ GtkWidget *widget = NULL;
+ GtkWidget *button = NULL;
+ GtkWidget *toggled = NULL;
+ gpointer pointer;
+ gint param;
+ gint months;
+
+ //~ devel_debug_int ( account_number );
+ button = g_object_get_data ( G_OBJECT ( account_page ), "bet_account_spin_button" );
+
+ param = gsb_data_account_get_bet_spin_range ( account_number );
+ months = gsb_data_account_get_bet_months ( account_number );
+
+ g_signal_handlers_block_by_func ( G_OBJECT ( button ),
+ G_CALLBACK ( bet_config_duration_number_changed ),
+ GINT_TO_POINTER ( 1 ) );
+
+ if ( param == 0 )
+ {
+ widget = g_object_get_data ( G_OBJECT ( account_page ), "bet_account_previous" );
+ g_signal_handlers_block_by_func ( G_OBJECT ( widget ),
+ G_CALLBACK ( bet_config_duration_button_clicked ),
+ button );
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( widget ), TRUE );
+ gtk_spin_button_set_range ( GTK_SPIN_BUTTON ( button ), 1.0, prev_month_max );
+ gtk_spin_button_set_value ( GTK_SPIN_BUTTON ( button ),
+ (gdouble) months );
+ }
+ else
+ {
+ widget = g_object_get_data ( G_OBJECT ( account_page ), "bet_account_widget" );
+ g_signal_handlers_block_by_func ( G_OBJECT ( widget ),
+ G_CALLBACK ( bet_config_duration_button_clicked ),
+ button );
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( widget ), TRUE );
+ gtk_spin_button_set_range ( GTK_SPIN_BUTTON ( button ), 1.0, prev_month_max / 12.0 );
+ gtk_spin_button_set_value ( GTK_SPIN_BUTTON ( button ),
+ (gdouble) months / 12.0 );
+ }
+
+ g_signal_handlers_unblock_by_func ( G_OBJECT ( widget ),
+ G_CALLBACK ( bet_config_duration_button_clicked ),
+ button );
+ g_signal_handlers_unblock_by_func ( G_OBJECT ( button ),
+ G_CALLBACK ( bet_config_duration_number_changed ),
+ GINT_TO_POINTER ( 1 ) );
+
+ toggled = g_object_get_data ( G_OBJECT ( account_page ), "bet_auto_inc_month" );
+ g_signal_handlers_block_by_func ( G_OBJECT ( toggled ),
+ G_CALLBACK ( bet_array_auto_inc_month_toggle ),
+ NULL );
+
+ param = gsb_data_account_get_bet_auto_inc_month ( account_number );
+
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( toggled ), param );
+ g_signal_handlers_unblock_by_func ( G_OBJECT ( toggled ),
+ G_CALLBACK ( bet_array_auto_inc_month_toggle ),
+ NULL );
+
+ param = gsb_data_account_get_bet_hist_data ( account_number );
+
+ if ( param == 1 )
+ button = g_object_get_data ( G_OBJECT ( account_page ), "bet_hist_button_2" );
+ else
+ button = g_object_get_data ( G_OBJECT ( account_page ), "bet_hist_button_1" );
+
+ gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button ), TRUE );
+
+ param = gsb_data_account_get_bet_hist_fyear ( account_number );
+ widget = g_object_get_data ( G_OBJECT ( account_page ), "bet_hist_fyear_combo" );
+ pointer = g_object_get_data ( G_OBJECT ( widget ), "pointer" );
+ g_signal_handlers_block_by_func ( G_OBJECT ( widget ),
+ G_CALLBACK ( bet_config_fyear_clicked ),
+ pointer );
+
+ bet_historical_set_fyear_from_combobox ( widget, param );
+ g_signal_handlers_unblock_by_func ( G_OBJECT ( widget ),
+ G_CALLBACK ( bet_config_fyear_clicked ),
+ pointer );
+
+ return FALSE;
+}
+/**
+ * Cette fonction permet de sauter les opérations planifiées qui sont
+ * remplacées par des données historiques
+ *
+ * \return TRUE si l'opération doit être ignorée
+ * */
+gboolean bet_array_sort_scheduled_transactions ( gint div_number,
+ gint sub_div_nb,
+ GtkTreeModel *model )
+{
+ GtkTreeIter iter;
+
+ if ( gtk_tree_model_get_iter_first ( GTK_TREE_MODEL ( model ), &iter ) )
+ {
+ gint tmp_div_number;
+ gint tmp_sub_div_nb;
+
+ do
+ {
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ),
+ &iter,
+ SPP_ESTIMATE_TREE_DIVISION_COLUMN, &tmp_div_number,
+ SPP_ESTIMATE_TREE_SUB_DIV_COLUMN, &tmp_sub_div_nb,
+ -1 );
+
+ if ( tmp_div_number == 0 || tmp_div_number != div_number )
+ continue;
+
+ if ( tmp_sub_div_nb == 0 || tmp_sub_div_nb == sub_div_nb )
+ return TRUE;
+ }
+ while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL ( model ), &iter ) );
+ }
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_array_list_traite_double_click ( GtkTreeView *tree_view )
+{
+ GtkTreeSelection *selection;
+
+ selection = gtk_tree_view_get_selection ( tree_view );
+ bet_array_list_change_menu ( NULL, selection );
+}
+
+
+/**
+ * Convert selected line to a template of scheduled transaction.
+ *
+ */
+void bet_array_list_schedule_selected_line ( GtkWidget *menu_item,
+ GtkTreeSelection *tree_selection )
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gint origine;
+ gint number;
+ gint scheduled_number;
+
+ if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( tree_selection ), &model, &iter ) )
+ return;
+
+ gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
+ SPP_ESTIMATE_TREE_ORIGIN_DATA, &origine,
+ SPP_ESTIMATE_TREE_DIVISION_COLUMN, &number,
+ -1 );
+
+ scheduled_number = bet_array_list_schedule_line ( origine,
+ gsb_gui_navigation_get_current_account ( ),
+ number );
+
+ mise_a_jour_liste_echeances_auto_accueil = 1;
+
+ gsb_gui_navigation_set_selection ( GSB_SCHEDULER_PAGE, 0, NULL );
+ gsb_scheduler_list_select ( scheduled_number );
+ gsb_scheduler_list_edit_transaction ( scheduled_number );
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+}
+
+
+/**
+ * Convert future line to a template of scheduled transaction.
+ *
+ * \param transaction to use as a template.
+ *
+ * \return the number of the scheduled transaction
+ */
+gint bet_array_list_schedule_line ( gint origine, gint account_number, gint number )
+{
+ gint scheduled_number = 0;
+
+ scheduled_number = gsb_data_scheduled_new_scheduled ();
+
+ if ( !scheduled_number)
+ return FALSE;
+
+ if ( origine == SPP_ORIGIN_FUTURE )
+ {
+ struct_futur_data *scheduled;
+
+ scheduled = bet_data_future_get_struct ( account_number, number );
+ if ( scheduled == NULL )
+ return 0;
+
+ gsb_data_scheduled_set_account_number ( scheduled_number, scheduled -> account_number );
+ gsb_data_scheduled_set_date ( scheduled_number, scheduled -> date );
+ gsb_data_scheduled_set_amount ( scheduled_number, scheduled -> amount );
+ gsb_data_scheduled_set_currency_number ( scheduled_number,
+ gsb_data_account_get_currency ( account_number ) );
+ gsb_data_scheduled_set_party_number ( scheduled_number, scheduled -> party_number );
+ gsb_data_scheduled_set_category_number ( scheduled_number, scheduled -> category_number );
+ gsb_data_scheduled_set_sub_category_number ( scheduled_number, scheduled -> sub_category_number );
+ gsb_data_scheduled_set_notes ( scheduled_number, scheduled -> notes );
+ gsb_data_scheduled_set_method_of_payment_number ( scheduled_number, scheduled -> payment_number );
+ gsb_data_scheduled_set_financial_year_number ( scheduled_number, scheduled -> fyear_number );
+ gsb_data_scheduled_set_budgetary_number ( scheduled_number, scheduled -> budgetary_number );
+ gsb_data_scheduled_set_sub_budgetary_number ( scheduled_number, scheduled -> sub_budgetary_number );
+
+ /* par défaut, on met en manuel, pour éviter si l'utilisateur se gourre dans la date,
+ * (c'est le cas, à 0 avec g_malloc0) que l'opé soit enregistrée immédiatement */
+ gsb_data_scheduled_set_frequency ( scheduled_number, scheduled -> frequency );
+
+ }
+
+ return scheduled_number;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gchar *bet_array_list_get_description ( gint account_number,
+ gint origine,
+ gpointer value )
+{
+ gchar *desc = NULL;
+ gint type;
+
+ type = gsb_data_account_get_bet_select_label ( account_number, origine );
+
+ if ( origine == SPP_ORIGIN_TRANSACTION )
+ {
+ gint transaction_number = GPOINTER_TO_INT ( value );
+
+ switch ( type )
+ {
+ case 0:
+ desc = g_strdup ( gsb_data_transaction_get_notes ( transaction_number ) );
+ if ( desc && strlen ( desc ) )
+ break;
+
+ desc = g_strdup ( gsb_data_payee_get_name (
+ gsb_data_transaction_get_party_number (
+ transaction_number ), TRUE ) );
+ if ( desc && strlen ( desc ) )
+ break;
+
+ desc = g_strdup ( gsb_data_category_get_name (
+ gsb_data_transaction_get_category_number (
+ transaction_number ),
+ gsb_data_transaction_get_sub_category_number (
+ transaction_number ), NULL) );
+ if ( desc && strlen ( desc ) )
+ break;
+
+ desc = g_strdup ( gsb_data_budget_get_name (
+ gsb_data_transaction_get_budgetary_number (
+ transaction_number ),
+ gsb_data_transaction_get_sub_category_number (
+ transaction_number ),
+ _("No data by default") ) );
+ break;
+ case 1:
+ desc = g_strdup ( gsb_data_category_get_name (
+ gsb_data_transaction_get_category_number (
+ transaction_number ),
+ gsb_data_transaction_get_sub_category_number (
+ transaction_number ),
+ _("No category") ) );
+ break;
+ case 2:
+ desc = g_strdup ( gsb_data_budget_get_name (
+ gsb_data_transaction_get_budgetary_number (
+ transaction_number ),
+ gsb_data_transaction_get_sub_category_number (
+ transaction_number ),
+ _("No budgetary line") ) );
+ break;
+ }
+ }
+ else if ( origine == SPP_ORIGIN_SCHEDULED )
+ {
+ gint scheduled_number = GPOINTER_TO_INT ( value );
+
+ switch ( type )
+ {
+ case 0:
+ desc = g_strdup ( gsb_data_scheduled_get_notes ( scheduled_number ) );
+ if ( desc && strlen ( desc ) )
+ break;
+
+ desc = g_strdup ( gsb_data_payee_get_name (
+ gsb_data_scheduled_get_party_number (
+ scheduled_number ), TRUE ) );
+ if ( desc && strlen ( desc ) )
+ break;
+
+ desc = g_strdup ( gsb_data_category_get_name (
+ gsb_data_scheduled_get_category_number (
+ scheduled_number ),
+ gsb_data_scheduled_get_sub_category_number (
+ scheduled_number ), NULL) );
+ if ( desc && strlen ( desc ) )
+ break;
+
+ desc = g_strdup ( gsb_data_budget_get_name (
+ gsb_data_scheduled_get_budgetary_number (
+ scheduled_number ),
+ gsb_data_scheduled_get_sub_category_number (
+ scheduled_number ),
+ _("No data by default") ) );
+ break;
+ case 1:
+ desc = g_strdup ( gsb_data_category_get_name (
+ gsb_data_scheduled_get_category_number (
+ scheduled_number ),
+ gsb_data_scheduled_get_sub_category_number (
+ scheduled_number ),
+ _("No category") ) );
+ break;
+ case 2:
+ desc = g_strdup ( gsb_data_budget_get_name (
+ gsb_data_scheduled_get_budgetary_number (
+ scheduled_number ),
+ gsb_data_scheduled_get_sub_category_number (
+ scheduled_number ),
+ _("No budgetary line") ) );
+ break;
+ }
+ }
+ else if ( origine == SPP_ORIGIN_FUTURE )
+ {
+ struct_futur_data *scheduled = ( struct_futur_data * ) value;
+
+ if ( scheduled -> is_transfert )
+ {
+ if ( account_number == scheduled -> account_number )
+ desc = g_strdup_printf ( _("Transfer between account: %s\n"
+ "and account: %s"),
+ gsb_data_account_get_name ( account_number ),
+ gsb_data_account_get_name ( scheduled -> account_transfert ) );
+ else
+ desc = g_strdup_printf ( _("Transfer between account: %s\n"
+ "and account: %s"),
+ gsb_data_account_get_name ( scheduled -> account_transfert ),
+ gsb_data_account_get_name ( scheduled -> account_number ) );
+ }
+ else
+ {
+ switch ( type )
+ {
+ case 0:
+ desc = g_strdup ( scheduled -> notes );
+ if ( desc && strlen ( desc ) )
+ break;
+
+ desc = g_strdup ( gsb_data_payee_get_name (
+ scheduled -> party_number, TRUE ) );
+ if ( desc && strlen ( desc ) )
+ break;
+
+ desc = g_strdup ( gsb_data_category_get_name (
+ scheduled -> category_number,
+ scheduled -> sub_category_number, NULL) );
+ if ( desc && strlen ( desc ) )
+ break;
+
+ desc = g_strdup ( gsb_data_budget_get_name (
+ scheduled -> budgetary_number,
+ scheduled -> sub_budgetary_number,
+ _("No data by default") ) );
+ break;
+ case 1:
+ desc = g_strdup ( gsb_data_category_get_name (
+ scheduled -> category_number,
+ scheduled -> sub_category_number,
+ _("No category") ) );
+ break;
+ case 2:
+ desc = g_strdup ( gsb_data_budget_get_name (
+ scheduled -> budgetary_number,
+ scheduled -> sub_budgetary_number,
+ _("No budgetary line") ) );
+ break;
+ }
+ }
+ }
+ else if ( origine == SPP_ORIGIN_ACCOUNT )
+ {
+ struct_transfert_data *transfert = ( struct_transfert_data * ) value;
+
+ if ( transfert -> type == 0 )
+ desc = g_strdup_printf ("Solde du compte : %s",
+ gsb_data_account_get_name ( transfert -> replace_account ) );
+ else
+ desc = g_strdup_printf ("Solde partiel : %s",
+ gsb_data_partial_balance_get_name ( transfert -> replace_account ) );
+ }
+
+ return desc;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+void bet_array_auto_inc_month_toggle ( GtkToggleButton *togglebutton, gpointer data )
+{
+ gint account_number;
+ gboolean value;
+ gint auto_inc_month;
+
+ devel_debug_int (gtk_toggle_button_get_active ( togglebutton ));
+
+ account_number = gsb_gui_navigation_get_current_account ( );
+ auto_inc_month = gsb_data_account_get_bet_auto_inc_month ( account_number );
+
+ if ( ( value = gtk_toggle_button_get_active ( togglebutton ) ) != auto_inc_month )
+ {
+ gsb_data_account_set_bet_auto_inc_month ( account_number, value );
+
+ if ( value )
+ {
+ gsb_data_account_bet_update_initial_date_if_necessary ( account_number );
+ gsb_data_account_set_bet_maj ( account_number, BET_MAJ_ESTIMATE );
+ bet_data_update_bet_module ( account_number, GSB_ESTIMATE_PAGE );
+ }
+
+ if ( etat.modification_fichier == 0 )
+ modification_fichier ( TRUE );
+ }
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_array_refresh_transfert_data ( GtkTreeModel *tab_model,
+ GDate *date_min,
+ GDate *date_max )
+{
+ GHashTable *transfert_list;
+ GHashTableIter iter;
+ gpointer key, value;
+ gint account_number;
+
+ devel_debug (NULL);
+
+ account_number = gsb_gui_navigation_get_current_account ( );
+ transfert_list = bet_data_transfert_get_list ( );
+
+ g_hash_table_iter_init ( &iter, transfert_list );
+ while ( g_hash_table_iter_next ( &iter, &key, &value ) )
+ {
+ struct_transfert_data *transfert = ( struct_transfert_data *) value;
+ GtkTreeIter tab_iter;
+ GValue date_value = {0, };
+ gchar *str_debit = NULL;
+ gchar *str_credit = NULL;
+ gchar *str_date;
+ gchar *str_description;
+ gchar *str_amount;
+ gsb_real amount;
+
+ if ( account_number != transfert -> account_number )
+ continue;
+
+ if ( transfert -> auto_inc_month )
+ bet_data_transfert_update_date_if_necessary ( transfert );
+
+ if ( g_date_compare ( transfert -> date, date_max ) > 0 )
+ continue;
+ if ( g_date_compare ( transfert -> date, date_min ) < 0 )
+ continue;
+
+ str_description = bet_array_list_get_description ( transfert -> replace_account,
+ SPP_ORIGIN_ACCOUNT,
+ value );
+
+ if ( transfert -> type == 0 )
+ {
+ amount = gsb_data_account_get_current_balance ( transfert -> replace_account );
+ str_amount = gsb_real_save_real_to_string ( amount, 2 );
+ }
+ else
+ {
+ amount = gsb_data_partial_balance_get_current_amount (
+ transfert -> replace_account );
+ str_amount = gsb_real_save_real_to_string ( amount, 2 );
+ }
+
+ if ( amount.mantissa < 0 )
+ str_debit = gsb_transfert_get_str_amount ( transfert,
+ gsb_real_opposite ( amount ) );
+ else
+ str_credit = gsb_transfert_get_str_amount ( transfert, amount );
+
+ str_date = gsb_format_gdate ( transfert -> date );
+
+ g_value_init ( &date_value, G_TYPE_DATE );
+ g_value_set_boxed ( &date_value, transfert -> date );
+
+ /* add a line in the estimate array */
+ gtk_tree_store_append ( GTK_TREE_STORE ( tab_model ), &tab_iter, NULL );
+ gtk_tree_store_set_value ( GTK_TREE_STORE ( tab_model ), &tab_iter,
+ SPP_ESTIMATE_TREE_SORT_DATE_COLUMN,
+ &date_value );
+ gtk_tree_store_set ( GTK_TREE_STORE ( tab_model ), &tab_iter,
+ SPP_ESTIMATE_TREE_ORIGIN_DATA, SPP_ORIGIN_ACCOUNT,
+ SPP_ESTIMATE_TREE_DIVISION_COLUMN, transfert -> number,
+ SPP_ESTIMATE_TREE_DATE_COLUMN, str_date,
+ SPP_ESTIMATE_TREE_DESC_COLUMN, str_description,
+ SPP_ESTIMATE_TREE_DEBIT_COLUMN, str_debit,
+ SPP_ESTIMATE_TREE_CREDIT_COLUMN, str_credit,
+ SPP_ESTIMATE_TREE_AMOUNT_COLUMN, str_amount,
+ -1);
+
+ bet_array_list_replace_planned_line_by_transfert ( tab_model, transfert );
+ g_value_unset ( &date_value );
+ g_free ( str_date );
+ g_free ( str_description );
+ g_free ( str_amount );
+ if ( str_debit )
+ g_free ( str_debit );
+ if ( str_credit )
+ g_free ( str_credit );
+ }
+
+ return FALSE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean bet_array_list_replace_planned_line_by_transfert ( GtkTreeModel *tab_model,
+ struct_transfert_data *transfert )
+{
+ GtkTreeIter iter;
+
+ if ( gtk_tree_model_get_iter_first ( GTK_TREE_MODEL ( tab_model ), &iter ) )
+ {
+ GtkTreeIter *tmp_iter = NULL;
+ gchar* str_date;
+ GDate *date_debut_comparaison;
+ GDate *date_fin_comparaison;
+ GDate *date;
+ gint scheduled_number;
+ gint origine;
+
+ date_debut_comparaison = g_date_new_dmy ( g_date_get_day ( transfert -> date ),
+ g_date_get_month ( transfert -> date ),
+ g_date_get_year ( transfert -> date ));
+ g_date_subtract_days ( date_debut_comparaison,
+ valeur_echelle_recherche_date_import );
+
+ date_fin_comparaison = g_date_new_dmy ( g_date_get_day ( transfert -> date ),
+ g_date_get_month ( transfert -> date ),
+ g_date_get_year ( transfert -> date ));
+ g_date_add_days ( date_fin_comparaison,
+ valeur_echelle_recherche_date_import );
+
+ do
+ {
+ gtk_tree_model_get ( GTK_TREE_MODEL ( tab_model ),
+ &iter,
+ SPP_ESTIMATE_TREE_ORIGIN_DATA, &origine,
+ SPP_ESTIMATE_TREE_DIVISION_COLUMN, &scheduled_number,
+ SPP_ESTIMATE_TREE_DATE_COLUMN, &str_date,
+ -1 );
+
+ if ( origine != SPP_ORIGIN_SCHEDULED )
+ continue;
+
+ date = gsb_parse_date_string ( str_date );
+ if ( g_date_compare ( date, date_debut_comparaison ) < 0 )
+ continue;
+
+ if ( g_date_compare ( date, date_fin_comparaison ) > 0 )
+ {
+ if ( tmp_iter )
+ gtk_tree_store_remove ( GTK_TREE_STORE ( tab_model ), tmp_iter );
+ break;
+ }
+
+ if ( transfert -> category_number )
+ {
+ /* on cherche une opération par sa catégorie */
+ gint tmp_category_number;
+ gint tmp_sub_category_number;
+
+ tmp_category_number = gsb_data_scheduled_get_category_number ( scheduled_number );
+ if ( transfert -> sub_category_number )
+ tmp_sub_category_number = gsb_data_scheduled_get_sub_category_number (
+ scheduled_number );
+
+ if ( transfert -> category_number == tmp_category_number
+ &&
+ transfert -> sub_category_number == tmp_sub_category_number )
+ {
+ if ( g_date_compare ( date, transfert -> date ) == 0 )
+ {
+ gtk_tree_store_remove ( GTK_TREE_STORE ( tab_model ), &iter );
+ break;
+ }
+ tmp_iter = gtk_tree_iter_copy ( &iter );
+ }
+ }
+ else if ( transfert -> budgetary_number )
+ {
+ /* on cherche une opération par son IB */
+ gint tmp_budget_number;
+ gint tmp_sub_budget_number;
+
+ tmp_budget_number = gsb_data_scheduled_get_budgetary_number ( scheduled_number );
+ if ( transfert -> sub_budgetary_number )
+ tmp_sub_budget_number = gsb_data_scheduled_get_sub_budgetary_number (
+ scheduled_number );
+
+ if ( transfert -> budgetary_number == tmp_budget_number
+ &&
+ transfert -> sub_budgetary_number == tmp_sub_budget_number )
+ {
+ if ( g_date_compare ( date, transfert -> date ) == 0 )
+ {
+ gtk_tree_store_remove ( GTK_TREE_STORE ( tab_model ), &iter );
+ break;
+ }
+ tmp_iter = gtk_tree_iter_copy ( &iter );
+ }
+ }
+ }
+ while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL ( tab_model ), &iter ) );
+ }
+
+ return FALSE;
+}
+/* Local Variables: */
+/* c-basic-offset: 4 */
+/* End: */
diff --git a/src/fenetre_principale.c b/src/fenetre_principale.c
index 6429079..70d5d6e 100644
--- a/src/fenetre_principale.c
+++ b/src/fenetre_principale.c
@@ -25,9 +25,9 @@
/*START_INCLUDE*/
#include "fenetre_principale.h"
-#include "balance_estimate_tab.h"
-#include "balance_estimate_data.h"
-#include "balance_estimate_hist.h"
+#include "bet_tab.h"
+#include "bet_data.h"
+#include "bet_hist.h"
#include "navigation.h"
#include "gsb_transactions_list.h"
#include "accueil.h"
diff --git a/src/gsb_data_transaction.c b/src/gsb_data_tr
ansaction.c
index 60e91a3..b6d8d3f 100644
--- a/src/gsb_data_transaction.c
+++ b/src/gsb_data_transaction.c
@@ -31,7 +31,7 @@
/*START_INCLUDE*/
#include "gsb_data_transaction.h"
-#include "balance_estimate_data.h"
+#include "bet_data.h"
#include "classement_echeances.h"
#include "dialog.h"
#include "gsb_currency.h"
diff --git a/src/gsb_file_load.c b/src/gsb_file_load.c
index 6b1b121..a4c87b5 100644
--- a/src/gsb_file_load.c
+++ b/src/gsb_file_load.c
@@ -31,7 +31,7 @@
/*START_INCLUDE*/
#include "gsb_file_load.h"
-#include "balance_estimate_data.h"
+#include "bet_data.h"
#include "dialog.h"
#include "gsb_assistant_archive.h"
#include "gsb_assistant_first.h"
diff --git a/src/gsb_file_save.c b/src/gsb_file_save.c
index 4573088..b5895fd 100644
--- a/src/gsb_file_save.c
+++ b/src/gsb_file_save.c
@@ -33,7 +33,7 @@
/*START_INCLUDE*/
#include "gsb_file_save.h"
-#include "balance_estimate_data.h"
+#include "bet_data.h"
#include "dialog.h"
#include "gsb_data_account.h"
#include "gsb_data_archive.h"
diff --git a/src/gsb_form.c b/src/gsb_form.c
index d2ff745..908d959 100644
--- a/src/gsb_form.c
+++ b/src/gsb_form.c
@@ -32,7 +32,7 @@
/*START_INCLUDE*/
#include "gsb_form.h"
#include "accueil.h"
-#include "balance_estimate_data.h"
+#include "bet_data.h"
#include "dialog.h"
#include "gsb_calendar_entry.h"
#include "gsb_calendar.h"
diff --git a/src/gsb_real.c b/src/gsb_real.c
index b05083e..7c75198 100644
--- a/src/gsb_real.c
+++ b/src/gsb_real.c
@@ -48,20 +48,6 @@ glong gsb_real_power_10[] = { 1, 10, 100, 1000, 10000, 100000,
#define sizeofarray(x) (sizeof(x)/sizeof(*x))
#ifdef _MSC_VER
-typedef struct _lldiv_t
-{
- long long quot;
- long long rem;
-} lldiv_t;
-
-lldiv_t lldiv(long long numerator, long long denominator)
-{
- //TODO find a standard/efficient impl for this
- lldiv_t result;
- result.quot = numerator / denominator;
- result.rem = numerator % denominator;
- return result;
-}
#define lrint(x) (floor(x + 0.5))
#define rint(x) (floor(x + 0.5))
#endif//_MSC_VER
diff --git a/src/gsb_transactions_list.c b/src/gsb_transactions_list.c
index 8594ee6..7331ca7 100644
--- a/src/gsb_transactions_list.c
+++ b/src/gsb_transactions_list.c
@@ -26,7 +26,7 @@
/*START_INCLUDE*/
#include "gsb_transactions_list.h"
#include "accueil.h"
-#include "balance_estimate_data.h"
+#include "bet_data.h"
#include "utils_operations.h"
#include "dialog.h"
#include "affichage_liste.h"
diff --git a/src/import.c b/src/import.c
index ecb1a8f..29dda01 100644
--- a/src/import.c
+++ b/src/import.c
@@ -27,7 +27,7 @@
/*START_INCLUDE*/
#include "import.h"
#include "utils.h"
-#include "balance_estimate_data.h"
+#include "bet_data.h"
#include "import_csv.h"
#include "dialog.h"
#include "utils_file_selection.h"
diff --git a/src/navigation.c b/src/navigation.c
index af39a28..604c136 100644
--- a/src/navigation.c
+++ b/src/navigation.c
@@ -25,7 +25,7 @@
/*START_INCLUDE*/
#include "navigation.h"
-#include "balance_estimate_data.h"
+#include "bet_data.h"
#include "gsb_account_property.h"
#include "gsb_calendar.h"
#include "gsb_data_account.h"
diff --git a/src/parametres.c b/src/parametres.c
index fa3fee9..9e1d279 100644
--- a/src/parametres.c
+++ b/src/parametres.c
@@ -32,7 +32,7 @@
#include "parametres.h"
#include "menu.h"
#include "utils.h"
-#include "balance_estimate_config.h"
+#include "bet_config.h"
#include "dialog.h"
#include "gsb_archive_config.h"
#include "gsb_automem.h"
diff --git a/src/traitement_variables.c b/src/traitement_variables.c
index 05959f2..df54c39 100644
--- a/src/traitement_variables.c
+++ b/src/traitement_variables.c
@@ -29,8 +29,7 @@
/*START_INCLUDE*/
#include "traitement_variables.h"
-#include "balance_estimate_data.h"
-#include "balance_estimate_future.h"
+#include "bet_data.h"
#include "gsb_currency.h"
#include "gsb_data_account.h"
#include "gsb_data_archive.h"
hooks/post-receive
--
grisbi
More information about the cvs
mailing list