Example #1
0
/**
 * callback called when something change in the entries of the configuration of the reconcile
 *
 * \param tree_view
 *
 * \return FALSE
 * */
gboolean gsb_reconcile_config_update_line ( GtkWidget *entry,
					    GtkWidget *tree_view )
{
    GtkTreeIter iter;
    GtkTreeModel *model;
    GtkTreeSelection *selection;
    gboolean good;

    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
    good = gtk_tree_selection_get_selected (selection, &model, &iter);

    if (good)
    {
	gint reconcile_number;

	gtk_tree_model_get (model, &iter,
			    RECONCILIATION_RECONCILE_COLUMN, &reconcile_number,
			    -1 );

	if (reconcile_number)
	{
	    /* we are on a reconcile, change the line with the new values */
		gchar *init_date, *final_date;
		gchar *init_balance, *final_balance;

		init_date = gsb_format_gdate (gsb_data_reconcile_get_init_date (reconcile_number));
		final_date = gsb_format_gdate (gsb_data_reconcile_get_final_date (reconcile_number));
		init_balance = utils_real_get_string (gsb_data_reconcile_get_init_balance (reconcile_number));
		final_balance = utils_real_get_string (gsb_data_reconcile_get_final_balance (reconcile_number));

		gtk_tree_store_set ( GTK_TREE_STORE (model),
				     &iter,
				     RECONCILIATION_NAME_COLUMN, gsb_data_reconcile_get_name (reconcile_number),
				     RECONCILIATION_INIT_DATE_COLUMN, init_date,
				     RECONCILIATION_FINAL_DATE_COLUMN, final_date,
				     RECONCILIATION_INIT_BALANCE_COLUMN, init_balance,
				     RECONCILIATION_FINAL_BALANCE_COLUMN, final_balance,
				     -1 );
		g_free (init_date);
		g_free (final_date);
		g_free (init_balance);
		g_free (final_balance);

	}
    }

    return FALSE;
}
Example #2
0
/**
 * callback called when select a line in the tree
 * fill the entry of the name, dates and balances
 *
 * \param selection the GtkTreeSelection
 * \param table the GtkTable containing the widgets to set the value of the selection
 *
 * \return FALSE
 */
gboolean gsb_reconcile_config_select ( GtkTreeSelection *selection,
				       GtkWidget *table )
{
    GtkTreeIter iter;
    GtkTreeModel *model;
    gboolean good;

    good = gtk_tree_selection_get_selected (selection, &model, &iter);
    if (good)
    {
	gint reconcile_number;

	gtk_tree_model_get (model, &iter,
			    RECONCILIATION_RECONCILE_COLUMN, &reconcile_number,
			    -1 );

	if (reconcile_number)
	{
	    /* we are on a payment method, we fill the fields */
	    gsb_autofunc_entry_set_value ( reconcile_name_entry,
					   gsb_data_reconcile_get_name (reconcile_number),
					   reconcile_number );
	    gsb_autofunc_date_set ( reconcile_init_date_entry,
				    gsb_data_reconcile_get_init_date (reconcile_number),
				    reconcile_number);
	    gsb_autofunc_date_set ( reconcile_final_date_entry,
				    gsb_data_reconcile_get_final_date (reconcile_number),
				    reconcile_number );
	    gsb_autofunc_real_set ( reconcile_init_balance_entry,
				    gsb_data_reconcile_get_init_balance (reconcile_number),
				    reconcile_number );
	    gsb_autofunc_real_set ( reconcile_final_balance_entry,
				    gsb_data_reconcile_get_final_balance (reconcile_number),
				    reconcile_number );

	    /* we make the table sensitive */
	    gtk_widget_set_sensitive ( table, TRUE );
	}
	else
	    gtk_widget_set_sensitive ( table, FALSE );
    }
    else
	gtk_widget_set_sensitive ( table, FALSE );
    return FALSE;
}
Example #3
0
/**
 * start the reconciliation, called by a click on the
 * reconcile button
 *
 * \param button the button we click to come here
 * \param null not used
 *
 * \return FALSE
 * */
gboolean gsb_reconcile_run_reconciliation ( GtkWidget *button,
                        gpointer null )
{
    GDate *date;
    gint account_number;
    gint reconcile_number;
    gchar *label;
    gchar *string;
    gchar* tmpstr;

    account_number = gsb_gui_navigation_get_current_account ();
    reconcile_number = gsb_data_reconcile_get_account_last_number (account_number);

    label = gsb_reconcile_build_label ( reconcile_number );
    gtk_entry_set_text ( GTK_ENTRY ( reconcile_number_entry ), label );
    g_free ( label );

    /* reset records in run structure if user has changed of account */
    if (run.reconcile_account_number != account_number)
    {
        g_free (run.reconcile_final_balance);
        if (run.reconcile_new_date)
            g_date_free (run.reconcile_new_date);
        run.reconcile_final_balance = NULL;
        run.reconcile_new_date = NULL;
        run.reconcile_account_number = -1;
    }

    /* set last input date/amount if available */
    if (run.reconcile_new_date)
    {
        date = run.reconcile_new_date;
    }
    else
    {
        /* increase the last date of 1 month */
        date = gsb_date_copy (gsb_data_reconcile_get_final_date (reconcile_number));
        if (date)
        {
            GDate *today;
            gchar *string ;

            string = gsb_format_gdate ( date );
            gtk_label_set_text ( GTK_LABEL ( reconcile_last_date_label ),
                    string);
            gtk_widget_set_sensitive ( GTK_WIDGET ( reconcile_last_date_label ),
                    FALSE );
            g_free (string);
            g_date_add_months ( date, 1 );

            /* if etat.reconcile_end_date or the new date is after today, set today */
            today = gdate_today();
            if ( etat.reconcile_end_date || g_date_compare ( date, today) > 0 )
            {
                g_date_free (date);
                date = gdate_today();
            }
            else
                g_date_free (today);

            /* it's not the first reconciliation, set the old balance and unsensitive the old balance entry */
            tmpstr = utils_real_get_string (gsb_data_reconcile_get_final_balance (reconcile_number));
            gtk_entry_set_text ( GTK_ENTRY ( reconcile_initial_balance_entry ), tmpstr);
            g_free ( tmpstr );
            gtk_widget_set_sensitive ( GTK_WIDGET ( reconcile_initial_balance_entry ),
                    FALSE );
        }
        else
        {
            gtk_label_set_text ( GTK_LABEL ( reconcile_last_date_label ), _("None") );

            date = gdate_today();

            /* it's the first reconciliation, set the initial balance and make sensitive the old balance to change
             * it if necessary */
            tmpstr = utils_real_get_string ( gsb_data_account_get_init_balance (account_number, -1));
            gtk_entry_set_text ( GTK_ENTRY ( reconcile_initial_balance_entry ), tmpstr);
            g_free ( tmpstr );
            gtk_widget_set_sensitive ( GTK_WIDGET ( reconcile_initial_balance_entry ), TRUE );
        }
    }

    string = gsb_format_gdate (date);
    gtk_entry_set_text ( GTK_ENTRY ( reconcile_new_date_entry ),
			 string );
    g_free (string);
    g_date_free (date);

    /* set last input amount if available and if the account is the good one */
    gtk_entry_set_text ( GTK_ENTRY ( reconcile_final_balance_entry ),
            (run.reconcile_final_balance) ? run.reconcile_final_balance : "");
    g_free(run.reconcile_final_balance);

    /* set the title */
    tmpstr = g_markup_printf_escaped ( _(" <b>%s reconciliation</b> "),
					     gsb_data_account_get_name (account_number));
    gtk_label_set_markup ( GTK_LABEL (gtk_frame_get_label_widget (GTK_FRAME (reconcile_panel))),
			   tmpstr );
    g_free ( tmpstr );

    /* we go to the reconciliation mode */
    run.equilibrage = 1;

    /* set all the balances for reconciliation */
    gsb_reconcile_update_amounts (NULL, NULL);

    /* set the transactions list to reconciliation mode */
    /* only change the current account */
    reconcile_save_account_display = etat.retient_affichage_par_compte;
    etat.retient_affichage_par_compte = 1;

    /* hide the marked R transactions */
    reconcile_save_show_marked = gsb_data_account_get_r (account_number);
    if (reconcile_save_show_marked)
    {
        gsb_data_account_set_r (account_number, FALSE );
        mise_a_jour_affichage_r (FALSE);
    }

    /* 1 line on the transaction list */
    reconcile_save_rows_number = gsb_data_account_get_nb_rows (account_number);
    if (reconcile_save_rows_number != 1)
        gsb_transactions_list_set_visible_rows_number ( 1 );

    /* sort by method of payment if in conf */
    if (gsb_data_account_get_reconcile_sort_type (account_number))
	gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (reconcile_sort_list_button),
				       TRUE );

    gtk_widget_show_all ( reconcile_panel );

    transaction_list_show_toggle_mark (TRUE);

    /* unsensitive all that could change the account number */
    gsb_reconcile_sensitive (FALSE);

    gtk_widget_grab_focus ( GTK_WIDGET ( reconcile_number_entry ) );
    return FALSE;
}
/**
 * callback called by the button to launch the automatic association
 * between transactions and reconcile
 *
 * \param button
 * \param assistant
 *
 * \return FALSE
 * */
static gboolean gsb_assistant_reconcile_config_lauch_manu_asso ( GtkWidget *button,
                        GtkWidget *assistant )
{
    GList *tmp_list;
    GtkTreeIter iter;
    GtkTreeModel *model;
    GtkTreeSelection *selection;
    GList *path_list;
    gint account_number = -1;
    GtkWidget *dialog;
    GtkWidget *label;
    GtkWidget *scrolled_window;
    GtkWidget *dialog_tree_view;
    GtkListStore *dialog_store;
    gint return_value;
    gint i;
    enum dialog_column {
	DIALOG_NAME = 0,
	DIALOG_INIT_DATE,
	DIALOG_FINAL_DATE,
	DIALOG_RECONCILE_NUMBER,
	DIALOG_NB_COL
    };
    gint selected_reconcile_number;
    gint transaction_number;

    /* get the selection */
    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview_transactions_to_link));

    /* get the selected transactions */
    path_list = gtk_tree_selection_get_selected_rows ( GTK_TREE_SELECTION (selection),
						       &model );
    if (!path_list)
	return FALSE;

    /* ok, we have a selection, before continuing,
     * we check that all the transactions are on the same account */
    tmp_list = path_list;
    while (tmp_list)
    {
	GtkTreePath *path;

	path = tmp_list -> data;

	if (gtk_tree_model_get_iter ( GTK_TREE_MODEL (model),
				      &iter,
				      path ))
	{
	    gtk_tree_model_get ( GTK_TREE_MODEL (model),
				 &iter,
				 TRANSACTION_NUMBER, &transaction_number,
				 -1 );
	    if (account_number == -1)
		account_number = gsb_data_transaction_get_account_number (transaction_number);
	    else
	    {
		if (gsb_data_transaction_get_account_number (transaction_number) != account_number)
		{
		    dialogue_error (_("All the selected transactions have to belong to the same account !"));
		    /* erase the path_list */
		    g_list_foreach (path_list, (GFunc) gtk_tree_path_free, NULL);
		    g_list_free (path_list);
		    return FALSE;
		}
	    }
	}
	tmp_list = tmp_list -> next;
    }

    if (account_number == -1)
    {
	/* erase the path_list */
	g_list_foreach (path_list, (GFunc) gtk_tree_path_free, NULL);
	g_list_free (path_list);
	return FALSE;
    }

    /* ok, all the transactions belong to the same account, we can
     * show a dialog to select the reconcile */
    dialog = gtk_dialog_new_with_buttons ( _("Selection of a reconciliation"),
					   GTK_WINDOW ( assistant ),
					   GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
					   "gtk-cancel", GTK_RESPONSE_CANCEL,
					   "gtk-ok", GTK_RESPONSE_OK,
					   NULL );

    gtk_window_set_default_size ( GTK_WINDOW ( dialog ), 770, 412 );
    gtk_window_set_position ( GTK_WINDOW ( dialog ), GTK_WIN_POS_CENTER_ON_PARENT );
    gtk_window_set_resizable ( GTK_WINDOW ( dialog ), TRUE );
    gtk_container_set_border_width ( GTK_CONTAINER ( dialog ), 12 );

    label = gtk_label_new ( _("Select the reconciliation to associate to the selected transactions: ") );
    gtk_misc_set_alignment ( GTK_MISC ( label ), 0.0, 0.0 );
    gtk_box_pack_start ( GTK_BOX ( dialog_get_content_area ( dialog ) ),
			 label,
			 FALSE, FALSE,
			 10 );

    /* make the list */
    scrolled_window = gtk_scrolled_window_new (FALSE, FALSE);
    gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW (scrolled_window),
				     GTK_POLICY_AUTOMATIC,
				     GTK_POLICY_AUTOMATIC );
    gtk_box_pack_start ( GTK_BOX ( dialog_get_content_area ( dialog ) ),
			 scrolled_window,
			 TRUE, TRUE,
			 0 );

    dialog_store = gtk_list_store_new ( DIALOG_NB_COL,
					G_TYPE_STRING,
					G_TYPE_STRING,
					G_TYPE_STRING,
					G_TYPE_INT );
    dialog_tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (dialog_store));
    g_object_unref (G_OBJECT(dialog_store));
    gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (dialog_tree_view), TRUE);
    gtk_container_add ( GTK_CONTAINER (scrolled_window),
			dialog_tree_view );

    /* set the columns */
    for (i=DIALOG_NAME ; i<DIALOG_RECONCILE_NUMBER ; i++)
    {
	GtkTreeViewColumn *column;
	GtkCellRenderer *cell;
	gchar *titles[] = {
	    _("Reconciliation reference"), _("Initial date"), _("Final date")
	};
	gfloat alignment[] = {
	    COLUMN_LEFT, COLUMN_CENTER, COLUMN_CENTER
	};

	cell = gtk_cell_renderer_text_new ();
	g_object_set ( G_OBJECT (cell),
		       "xalign", alignment[i],
		       NULL );
	column = gtk_tree_view_column_new ();
	gtk_tree_view_column_set_sizing ( column,
					  GTK_TREE_VIEW_COLUMN_AUTOSIZE );
	gtk_tree_view_column_set_alignment ( column,
					     alignment[i] );
	gtk_tree_view_column_pack_start ( column, cell, TRUE );
	gtk_tree_view_column_set_title ( column, titles[i] );
	gtk_tree_view_column_set_attributes (column, cell,
					     "text", i,
					     NULL);
	gtk_tree_view_column_set_expand ( column, TRUE );
	gtk_tree_view_column_set_resizable ( column,
					     TRUE );
	gtk_tree_view_append_column ( GTK_TREE_VIEW(dialog_tree_view), column);
    }

    /* fill the tree view */
    tmp_list = gsb_data_reconcile_get_reconcile_list ();
    while (tmp_list)
    {
	gint reconcile_number;

	reconcile_number = gsb_data_reconcile_get_no_reconcile (tmp_list -> data);

	if (gsb_data_reconcile_get_account (reconcile_number) == account_number)
	{
	    gchar *init_date_str;
	    gchar *final_date_str;

	    init_date_str = gsb_format_gdate (gsb_data_reconcile_get_init_date (reconcile_number));
	    final_date_str = gsb_format_gdate (gsb_data_reconcile_get_final_date (reconcile_number));

	    gtk_list_store_append ( GTK_LIST_STORE (dialog_store),
				    &iter );
	    gtk_list_store_set ( GTK_LIST_STORE (dialog_store),
				 &iter,
				 DIALOG_NAME, gsb_data_reconcile_get_name (reconcile_number),
				 DIALOG_INIT_DATE, init_date_str,
				 DIALOG_FINAL_DATE, final_date_str,
				 DIALOG_RECONCILE_NUMBER, reconcile_number,
				 -1 );
	    g_free (init_date_str);
	    g_free (final_date_str);
	}
	tmp_list = tmp_list -> next;
    }

    gtk_widget_show_all (dialog);

    /* launch the dialog */
    return_value = gtk_dialog_run (GTK_DIALOG (dialog));

    if (return_value != GTK_RESPONSE_OK)
    {
	gtk_widget_destroy (dialog);
	return FALSE;
    }

    /* we get the selected reconcile */
    if (!gtk_tree_selection_get_selected ( gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog_tree_view)),
					   NULL,
					   &iter ))
    {
	dialogue_warning (_("No selection found, the transactions are not modified."));
	gtk_widget_destroy (dialog);
	return FALSE;
    }

    gtk_tree_model_get ( GTK_TREE_MODEL (dialog_store),
			 &iter,
			 DIALOG_RECONCILE_NUMBER, &selected_reconcile_number,
			 -1 );
    /* ok we have the reconcile number, we can destroy the dialog */
    gtk_widget_destroy (dialog);

    /* and now, fill the selected transactions with that reconcile number */
    tmp_list = g_list_last (path_list);
    while (tmp_list)
    {
	GtkTreePath *path;

	path = tmp_list -> data;

	if (gtk_tree_model_get_iter ( GTK_TREE_MODEL (model),
				      &iter,
				      path ))
	{
	    gtk_tree_model_get ( GTK_TREE_MODEL (model),
				 &iter,
				 TRANSACTION_NUMBER, &transaction_number,
				 -1 );
	    gtk_list_store_remove ( GTK_LIST_STORE (model),
				    &iter );
	    gsb_data_transaction_set_reconcile_number ( transaction_number,
							selected_reconcile_number );
	    transactions_to_link--;
	}
	tmp_list = tmp_list -> prev;
    }

    /* erase the path_list */
    g_list_foreach (path_list, (GFunc) gtk_tree_path_free, NULL);
    g_list_free (path_list);

    /* now there is 2 way :
     * either transactions_to_link is 0, we go directly to the succes page
     * either it's not null, and the user should create more reconciles */
    if (transactions_to_link)
    {
	gchar *string;

	/* update the labels */
	string = g_strdup_printf (_("Still %d transactions to link with a reconciliation."),
				  transactions_to_link);
	gtk_label_set_text ( GTK_LABEL (label_transactions_to_link_1),
			     string);
	gtk_label_set_text ( GTK_LABEL (label_transactions_to_link_3),
			     string);
	g_free (string);
	gtk_widget_grab_focus (treeview_transactions_to_link);
    }
    else
    {
	/* go to the success page */
	gsb_assistant_set_next ( assistant,
				 RECONCILE_ASSISTANT_MANUALLY_ASSOCIATE,
				 RECONCILE_ASSISTANT_SUCCESS );
	gsb_assistant_next_page (assistant);
    }
    return FALSE;
}
Example #5
0
/**
 * fill the reconcile list,
 * sort each reconcile in its account
 *
 * \param
 *
 * \return
 * */
void gsb_reconcile_config_fill ( void )
{
    GtkTreeModel *model;
    GSList *tmp_list;
	GrisbiWinEtat *w_etat;

    if (!reconcile_treeview)
		return;

	w_etat = (GrisbiWinEtat *) grisbi_win_get_w_etat ();
    model = gtk_tree_view_get_model ( GTK_TREE_VIEW (reconcile_treeview));
    gtk_tree_store_clear (GTK_TREE_STORE(model));

    /* we make a tree_model containing the accounts,
     * and for each account, all the reconciles */
    tmp_list = gsb_data_account_get_list_accounts ();
    while (tmp_list)
    {
	gint account_number;
	GtkTreeIter account_iter;
	GList *reconcile_list;

	account_number = gsb_data_account_get_no_account (tmp_list -> data);

	gtk_tree_store_append ( GTK_TREE_STORE (model),
				&account_iter,
				NULL );
	gtk_tree_store_set ( GTK_TREE_STORE (model),
			     &account_iter,
			     RECONCILIATION_NAME_COLUMN, gsb_data_account_get_name (account_number),
			     RECONCILIATION_WEIGHT_COLUMN, 800,
			     RECONCILIATION_ACCOUNT_COLUMN, account_number,
			     -1 );

	/* for each account, get the concerned reconciles */
	reconcile_list = gsb_data_reconcile_get_sort_reconcile_list (account_number);
    if (w_etat->reconcile_sort)
		reconcile_list = g_list_reverse (reconcile_list);

	while (reconcile_list)
	{
	    gint reconcile_number;

	    reconcile_number = GPOINTER_TO_INT (reconcile_list->data);

	    if (gsb_data_reconcile_get_account (reconcile_number) == account_number)
	    {
		GtkTreeIter reconcile_iter;
		gchar *init_date, *final_date;
		gchar *init_balance, *final_balance;

		init_date = gsb_format_gdate (gsb_data_reconcile_get_init_date (reconcile_number));
		final_date = gsb_format_gdate (gsb_data_reconcile_get_final_date (reconcile_number));
		init_balance = utils_real_get_string (gsb_data_reconcile_get_init_balance (reconcile_number));
		final_balance = utils_real_get_string (gsb_data_reconcile_get_final_balance (reconcile_number));

		gtk_tree_store_append ( GTK_TREE_STORE (model),
					&reconcile_iter,
					&account_iter );
		gtk_tree_store_set ( GTK_TREE_STORE (model),
				     &reconcile_iter,
				     RECONCILIATION_NAME_COLUMN, gsb_data_reconcile_get_name (reconcile_number),
				     RECONCILIATION_WEIGHT_COLUMN, 400,
				     RECONCILIATION_INIT_DATE_COLUMN, init_date,
				     RECONCILIATION_FINAL_DATE_COLUMN, final_date,
				     RECONCILIATION_INIT_BALANCE_COLUMN, init_balance,
				     RECONCILIATION_FINAL_BALANCE_COLUMN, final_balance,
				     RECONCILIATION_RECONCILE_COLUMN, reconcile_number,
				     RECONCILIATION_ACCOUNT_COLUMN, account_number,
				     -1 );
		g_free (init_date);
		g_free (final_date);
		g_free (init_balance);
		g_free (final_balance);
	    }
	    reconcile_list = reconcile_list -> next;
	}

	tmp_list = tmp_list -> next;
    }
}