コード例 #1
0
/**
 * Callback called when toggle the check button to split the neutral method of payments
 *
 * \param cell
 * \param path_str
 * \param tree_view
 *
 * \return FALSE
 */
gboolean gsb_reconcile_sort_config_neutral_toggled ( GtkCellRendererToggle *cell,
						     gchar *path_str,
						     GtkWidget *tree_view )
{
    GtkTreePath * treepath;
    GtkTreeIter iter;
    gboolean toggle;
    gint account_number;
    GSList *sorted_list_copy;
    GSList *tmp_list;
    GtkTreeModel *model;

    model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));

    /* invert the toggle */
    treepath = gtk_tree_path_new_from_string ( path_str );
    gtk_tree_model_get_iter ( GTK_TREE_MODEL (model),
			      &iter, treepath );

    gtk_tree_model_get (GTK_TREE_MODEL(model), &iter,
			RECONCILIATION_SORT_SPLIT_NEUTRAL_COLUMN, &toggle,
			RECONCILIATION_SORT_ACCOUNT_COLUMN, &account_number,
			-1);
    toggle ^= 1;
    gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
			RECONCILIATION_SORT_SPLIT_NEUTRAL_COLUMN, toggle,
			-1);

    /* and save it */
    gsb_data_account_set_split_neutral_payment ( account_number,
						 toggle );

    /* need to copy the sorted_list to avoid an infinite loop when add a negative payment neutral later */
    sorted_list_copy = g_slist_copy (gsb_data_account_get_sort_list (account_number));
    tmp_list = sorted_list_copy;

    while (tmp_list)
    {
	gint payment_number;

	payment_number = GPOINTER_TO_INT (tmp_list -> data);

	/* payment_number can be negative, so do for it abs */
	if ( gsb_data_payment_get_sign (abs (payment_number)) == GSB_PAYMENT_NEUTRAL )
	{
	    if (toggle)
		gsb_data_account_sort_list_add ( account_number,
						 -payment_number );
	    else
		if (payment_number < 0 )
		    gsb_data_account_sort_list_remove ( account_number,
							payment_number );
	}
	tmp_list = tmp_list -> next;
    }
    g_slist_free (sorted_list_copy);
    gsb_reconcile_sort_config_fill ();
    gsb_file_set_modified ( TRUE );
    return FALSE;
}
コード例 #2
0
/**
 * update the sort list of an account according to the model
 * called when change something in the order of method of payment
 *
 * \param account_number
 * \param model
 *
 * \return FALSE
 * */
gboolean gsb_reconcile_sort_config_update_account_sort_list ( gint account_number,
							      GtkTreeModel *model )
{
    GtkTreeIter iter;

    gsb_data_account_sort_list_free (account_number);

    if (gtk_tree_model_get_iter_first ( GTK_TREE_MODEL (model),
					&iter ))
    {
	/* first, we try to find the account line */
	do
	{
	    gint account_number_tmp;

	    gtk_tree_model_get ( GTK_TREE_MODEL(model), &iter,
				 RECONCILIATION_SORT_ACCOUNT_COLUMN, &account_number_tmp,
				 -1 );
	    if (account_number_tmp == account_number)
	    {
		/* ok, we are on the good account,
		 * now we append the method of payment in the same order as the list */
		GtkTreeIter iter_child;

		if (gtk_tree_model_iter_children ( GTK_TREE_MODEL (model), &iter_child, &iter))
		{
		    do
		    {
			gint payment_number;

			gtk_tree_model_get ( GTK_TREE_MODEL(model), &iter_child,
					     RECONCILIATION_SORT_TYPE_COLUMN, &payment_number,
					     -1 );
			gsb_data_account_sort_list_add ( account_number, payment_number );
		    }
		    while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter_child));
		}
	    }
	}
	while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter)
	       &&
	       !gsb_data_account_get_sort_list (account_number));
    }
    return FALSE;
}
コード例 #3
0
ファイル: gsb_account.c プロジェクト: philippedelorme/grisbi
/** that function delete the current account selected in the account properties
 * \param none
 * \return FALSE FALSE
 * */
gboolean gsb_account_delete ( void )
{
    gint deleted_account;
    gint page_number;
    GSList *list_tmp;
	gchar* tmpstr;

    deleted_account = gsb_gui_navigation_get_current_account ();

    tmpstr = g_strdup_printf (_("Delete account \"%s\"?"),
				     gsb_data_account_get_name ( deleted_account ) ) ;

    if ( !question_yes_no_hint ( tmpstr,
				        _("This will irreversibly remove this account and all operations "
                        "that were previously contained.  There is no undo for this. "
                        "Usually it's a better way to close an account."),
				        GTK_RESPONSE_NO ))
    {
        g_free ( tmpstr );
	    return FALSE;
    }
    g_free ( tmpstr );

    /* if the last account, close the file */
    if ( gsb_data_account_get_accounts_amount () == 1 )
    {
        gsb_file_set_modified ( FALSE );
        gsb_file_close ();
        return FALSE;
    }

    /* delete the schedules transactions on that account */
    list_tmp = gsb_data_scheduled_get_scheduled_list ();
    while (list_tmp)
    {
        gint scheduled_number;

        scheduled_number = gsb_data_scheduled_get_scheduled_number ( list_tmp -> data );

        if ( gsb_data_scheduled_get_account_number (scheduled_number) == deleted_account )
            gsb_data_scheduled_remove_scheduled (scheduled_number);

        list_tmp = list_tmp -> next;
    }


    /* remove all the transactions of that account */
    list_tmp = gsb_data_transaction_get_complete_transactions_list ();
    while (list_tmp)
    {
        gint transaction_number;

        transaction_number = gsb_data_transaction_get_transaction_number ( list_tmp -> data );

        /* better to go to the next transaction now */
        list_tmp = list_tmp -> next;

        if (gsb_data_transaction_get_account_number (transaction_number) == deleted_account)
        {
            gint contra_transaction_number;

            /* we are on a transaction on the deleted account, we delete that transaction,
             * but if it's a transfer, modify the contra-transaction to set transfer to deleted account */
            contra_transaction_number = gsb_data_transaction_get_contra_transaction_number (
                                        transaction_number);
            if (contra_transaction_number > 0)
            /* it's a transfer, modify the contra-transaction */
                gsb_data_transaction_set_contra_transaction_number ( contra_transaction_number, -1);

            /* now can remove the transaction */
            gsb_data_transaction_remove_transaction_without_check ( transaction_number );
        }
    }

    /* delete the payment_number */
    list_tmp = gsb_data_account_get_sort_list ( deleted_account );
    while (list_tmp)
    {
        gpointer ptr;
        gint payment_number;

        ptr = list_tmp -> data;
        payment_number = GPOINTER_TO_INT ( ptr );
        gsb_data_payment_remove ( payment_number );

        list_tmp = list_tmp -> next;
    }

    /* delete the account */
    gsb_data_account_delete ( deleted_account );

    /* check gsb_gui_navigation_get_current_account () and gsb_gui_navigation_get_current_account ()_onglet and put them
     * on the first account if they are on the deleted account */

    if ( gsb_gui_navigation_get_current_account () == deleted_account )
    {
        GtkWidget *notebook_general;

	/* update the transaction list */
    notebook_general = gsb_gui_get_general_notebook ( );
	page_number = gtk_notebook_get_current_page ( GTK_NOTEBOOK ( notebook_general ) );

	navigation_change_account ( gsb_data_account_first_number () );

	gtk_notebook_set_current_page ( GTK_NOTEBOOK ( notebook_general ), page_number );
    }

    /* update the buttons lists */
    gsb_menu_update_accounts_in_menus();

    /* Replace trees contents. */
    categories_fill_list ();
    budgetary_lines_fill_list ();
    payees_fill_list ();

    /* update the categories in lists */
    transaction_list_update_element (ELEMENT_CATEGORY);

    /* update the name of accounts in form */
    gsb_account_update_combo_list ( gsb_form_scheduler_get_element_widget (SCHEDULED_FORM_ACCOUNT),
				    FALSE );

    gsb_scheduler_list_fill_list (gsb_scheduler_list_get_tree_view ());
    mise_a_jour_liste_echeances_manuelles_accueil = 1;
    mise_a_jour_liste_comptes_accueil = 1;
    mise_a_jour_soldes_minimaux = 1;
    mise_a_jour_fin_comptes_passifs = 1;

    /* Update navigation pane. */
    gsb_gui_navigation_remove_account ( deleted_account );

    gsb_file_set_modified ( TRUE );
    return FALSE;
}
コード例 #4
0
/**
 * clear and fill the reconciliation tree with the accounts,
 * and for each account, set the method of payments in the good order
 *
 * \param
 *
 * \return
 */
void gsb_reconcile_sort_config_fill ( void )
{
    GtkTreeIter account_iter, payment_method_iter;
    GSList *list_tmp;
    GtkTreeModel *model;

    model = gtk_tree_view_get_model (GTK_TREE_VIEW (reconcile_treeview));

    gtk_tree_store_clear (GTK_TREE_STORE (model));
    list_tmp = gsb_data_account_get_list_accounts ();

    while ( list_tmp )
    {
	gint account_number;
	GSList *sorted_list;
	GSList *payment_list;
	gboolean visible;

	account_number = gsb_data_account_get_no_account ( list_tmp -> data );

	/* when no method of payment, hide the checkbuttons because non sense */
	payment_list = gsb_data_payment_get_list_for_account (account_number);
	if (payment_list)
	{
	    visible = TRUE;
	    g_slist_free (payment_list);
	}
	else
	    visible = FALSE;

	gtk_tree_store_append (GTK_TREE_STORE (model), &account_iter, NULL);
	gtk_tree_store_set (GTK_TREE_STORE (model), &account_iter,
			    RECONCILIATION_SORT_NAME_COLUMN, gsb_data_account_get_name (account_number),
			    RECONCILIATION_SORT_VISIBLE_COLUMN, visible,
			    RECONCILIATION_SORT_SORT_COLUMN, gsb_data_account_get_reconcile_sort_type(account_number),
			    RECONCILIATION_SORT_SPLIT_NEUTRAL_COLUMN, gsb_data_account_get_split_neutral_payment (account_number),
			    RECONCILIATION_SORT_ACCOUNT_COLUMN, account_number,
			    RECONCILIATION_SORT_TYPE_COLUMN, 0,
			    RECONCILIATION_SORT_SENSITIVE_COLUMN, visible,
			    -1 );

	/* the sorted list is a list of numbers of method of payment, in the good order */
	sorted_list = gsb_data_account_get_sort_list (account_number);

	while ( sorted_list )
	{
	    gint payment_number;

	    /* in the sorted list, a number can be negative, when split a neutral into 2 parts
	     * so payment number here can be negative for neutral payments */
	    payment_number = GPOINTER_TO_INT (sorted_list -> data);

	    if (payment_number)
	    {
		gchar *name = NULL;

		gtk_tree_store_append (GTK_TREE_STORE (model),
				       &payment_method_iter,
				       &account_iter);

		/* if split the neutrals, show here with the name */
		switch (gsb_data_payment_get_sign (abs (payment_number)))
		{
		    case GSB_PAYMENT_DEBIT:
		    case GSB_PAYMENT_CREDIT:
			name = my_strdup (gsb_data_payment_get_name (payment_number));
			break;

		    case GSB_PAYMENT_NEUTRAL:
			if (gsb_data_account_get_split_neutral_payment (account_number))
			{
			    /* the neutrals are splitted */
			    if (payment_number < 0)
				name = g_strconcat ( gsb_data_payment_get_name (-payment_number),
						     " ( - )", NULL );
			    else
				name = g_strconcat ( gsb_data_payment_get_name (payment_number),
						     " ( + )", NULL );
			}
			else
			    name = my_strdup (gsb_data_payment_get_name (payment_number));
			break;
		}

		gtk_tree_store_set (GTK_TREE_STORE (model), &payment_method_iter,
				    RECONCILIATION_SORT_NAME_COLUMN, name,
				    RECONCILIATION_SORT_VISIBLE_COLUMN, FALSE,
				    RECONCILIATION_SORT_SORT_COLUMN, FALSE,
				    RECONCILIATION_SORT_SPLIT_NEUTRAL_COLUMN, FALSE,
				    RECONCILIATION_SORT_ACCOUNT_COLUMN, account_number,
				    RECONCILIATION_SORT_TYPE_COLUMN, payment_number,
				    RECONCILIATION_SORT_SENSITIVE_COLUMN, TRUE,
				    -1 );
		if (name)
		    g_free (name);
	    }
	    sorted_list = sorted_list -> next;
	}

	if ( gtk_tree_model_iter_has_child( GTK_TREE_MODEL(model), &account_iter)
	     &&
	     gsb_data_account_get_reconcile_sort_type (account_number) )
	{
	    GtkTreePath * treepath;
	    treepath = gtk_tree_model_get_path (GTK_TREE_MODEL(model), &account_iter);
	    if ( treepath )
	    {
		gtk_tree_view_expand_row ( GTK_TREE_VIEW(reconcile_treeview), treepath, TRUE );
		gtk_tree_path_free ( treepath );
	    }
	}
	list_tmp = list_tmp -> next;
    }
}