Esempio n. 1
0
/**
 * Signal triggered when user configure display grisbi title
 *
 * \param button	Radio button that triggered event.
 *
 * \return FALSE
 */
gboolean change_grisbi_title_type ( GtkRadioButton *button, GtkWidget *entry )
{
    if ( gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( button ) ) )
    {
        conf.display_grisbi_title = GPOINTER_TO_INT ( g_object_get_data 
                        ( G_OBJECT ( button ), "display" ) );
    }

    switch ( conf.display_grisbi_title )
    {
        case GSB_ACCOUNTS_TITLE:
            gtk_widget_set_sensitive ( entry, TRUE );
            if ( titre_fichier && strlen ( titre_fichier ) )
                gtk_entry_set_text ( GTK_ENTRY ( entry ), titre_fichier );
            else
            {
                gtk_entry_set_text ( GTK_ENTRY ( entry ), "" );
                titre_fichier = NULL;
            }
        break;
        case GSB_ACCOUNT_HOLDER:
            gtk_widget_set_sensitive ( entry, FALSE);
        break;
        case GSB_ACCOUNTS_FILE:
            gtk_widget_set_sensitive ( entry, FALSE);
        break;
    }

    /* set Grisbi title */
    gsb_main_set_grisbi_title ( gsb_gui_navigation_get_current_account ( ) );

    return FALSE;
}
Esempio n. 2
0
/**
 * Update the clickable list of closed accounts and target
 * accounts to move a transaction, in menu.
 *
 * \param
 * \return FALSE
 * */
gboolean gsb_menu_update_accounts_in_menus ( void )
{
    GSList *list_tmp;
    GtkActionGroup * action_group;

    if ( move_to_account_merge_id != -1 )
        gtk_ui_manager_remove_ui ( ui_manager, move_to_account_merge_id );

    move_to_account_merge_id = gtk_ui_manager_new_merge_id ( ui_manager );
    action_group = gtk_action_group_new ( "Group3" );

    /* create the closed accounts and accounts in the menu to move a transaction */
    list_tmp = gsb_data_account_get_list_accounts ();

    while ( list_tmp )
    {
        gint i;

        i = gsb_data_account_get_no_account ( list_tmp -> data );

        if ( !gsb_data_account_get_closed_account ( i ) )
        {
            gchar *tmp_name;
            gchar *account_name;
            GtkAction *action;

            tmp_name = g_strdup_printf ( "MoveToAccount%d", i );
            account_name = gsb_data_account_get_name ( i );
            if ( !account_name )
                account_name = _("Unnamed account");

            action = gtk_action_new ( tmp_name, account_name, "", "" );

            if ( gsb_gui_navigation_get_current_account () == i )
                gtk_action_set_sensitive ( action, FALSE );

            gtk_action_group_add_action ( action_group, action );
            g_signal_connect ( action,
                        "activate",
                        G_CALLBACK ( move_selected_operation_to_account_nb ),
                        GINT_TO_POINTER ( i ) );

            gtk_ui_manager_add_ui ( ui_manager,
                        move_to_account_merge_id,
                        "/menubar/EditMenu/MoveToAnotherAccount/",
                        tmp_name,
                        tmp_name,
                        GTK_UI_MANAGER_MENUITEM,
                        FALSE );
            g_free ( tmp_name );
        }

        list_tmp = list_tmp -> next;
    }

    gtk_ui_manager_insert_action_group ( ui_manager, action_group, 2 );
    gtk_ui_manager_ensure_update ( ui_manager );

    return FALSE;
}
Esempio n. 3
0
/**
 * called by a click on the column, used to sort the list
 *
 * \param model
 * \param iter_1
 * \param iter_2
 * \param column_number the number of the column (0 to CUSTOM_MODEL_VISIBLE_COLUMNS) we want to sort by
 *
 * \return -1 if iter_1 is above iter_2
 * */
gint gsb_transactions_list_sort (CustomRecord **a,
                        CustomRecord **b,
                        CustomList *custom_list)
{
    gint account_number;
    gint return_value;
    CustomRecord *record_1 = NULL;
    CustomRecord *record_2 = NULL;

    account_number = gsb_gui_navigation_get_current_account ();
    if (account_number == -1)
	/* normally cannot happen, except come here at the opening
	 * of grisbi, and must return 0 if we don't want a crash */
	return 0;

    /* i don't know why but sometimes there is a comparison between the 2 same rows... */
    if (*a == *b)
	return 0;

    /* first of all, check the archive */
    return_value = gsb_transactions_list_sort_check_archive ( *a, *b );
    if (!return_value)
    {
	/* check the general tests (white line...) */
	/* get the records */
	record_1 = *a;
	record_2 = *b;
	return_value = gsb_transactions_list_sort_general_test ( record_1, record_2 );
    }

    if (return_value)
    {
	/* we have already a returned value, but for archive or general test,
	 * the pos of the row need not to change, so must keep the return_value */
	return return_value;
    }
    else
    {
	/* get the transaction numbers */
	gint element_number;
	gint transaction_number_1 = gsb_data_transaction_get_transaction_number (record_1 -> transaction_pointer);
	gint transaction_number_2 = gsb_data_transaction_get_transaction_number (record_2 -> transaction_pointer);

	/* get the element used to sort the list */
	element_number = gsb_data_account_get_element_sort ( account_number,
							     custom_list -> sort_col);
	return_value = gsb_transactions_list_sort_by_no_sort ( transaction_number_1,
							       transaction_number_2,
							       element_number );
    }

    if (custom_list -> sort_order == GTK_SORT_DESCENDING)
	return_value = -return_value;
    return return_value;
}
Esempio n. 4
0
/**
 * callback called when the user click on 'Delete the reconciliation'
 * this will delete the selected reconciliation and will mark all the concerned
 * transactions as P
 *
 * \param button
 * \param tree_view
 *
 * \return FALSE
 * */
gboolean gsb_reconcile_config_delete ( GtkWidget *button,
				       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;
	gint account_number;

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

	if (reconcile_number)
	{
	    /* we are on a reconcile,
	     * we ask if the user want to continue and warn him */
	    gchar* tmpstr = g_strdup_printf (_("Caution, you are about to delete a reconciliation.\nIf you continue, the reconciliation %s will be erased and all the transactions marked by this reconciliation will be un-reconciled and marked P.\nAre you sure you want to continue?"),
							 gsb_data_reconcile_get_name (reconcile_number));
	    if (!question_yes_no (tmpstr, _("Delete reconciliation"),
					GTK_RESPONSE_NO ))
	    {
		g_free ( tmpstr );
		return FALSE;
	    }

	    /* ok we delete the reconcile
	     * this will automatickly remove it from the marked transactions */
	    gtk_tree_store_remove ( GTK_TREE_STORE (model),
				    &iter );
	    gsb_data_reconcile_remove (reconcile_number);

	    /* if we are on an account, we update the list */
	    account_number = gsb_gui_navigation_get_current_account ();
	    if (account_number != -1)
	    {
		gsb_transactions_list_update_tree_view (account_number, TRUE);

		/* update the last statement for that account */
		gsb_gui_navigation_update_statement_label (account_number);
	    }
            gsb_file_set_modified ( TRUE );
	}
    }

    return FALSE;
}
Esempio n. 5
0
/**
 * come here to cancel the reconciliation
 * come here too at the end of the finish reconcile to set the default values
 *
 * \param button not used
 * \param null not used
 *
 * \return FALSE
 * */
gboolean gsb_reconcile_cancel ( GtkWidget *button,
				        gpointer null )
{
    run.equilibrage = 0;

    /* save the final balance/new date for the next time the user will try to reconcile */
    run.reconcile_account_number = gsb_gui_navigation_get_current_account ();
    run.reconcile_final_balance = g_strdup ( gtk_entry_get_text ( GTK_ENTRY ( reconcile_final_balance_entry ) ) );
    run.reconcile_new_date = gsb_parse_date_string ( gtk_entry_get_text ( GTK_ENTRY ( reconcile_new_date_entry ) ) );

    /* set the normal color to the date entry */
    gsb_calendar_entry_set_color ( reconcile_new_date_entry, TRUE);

    /* restore the good sort of the list */
    if (transaction_list_sort_get_reconcile_sort ())
    {
        gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (reconcile_sort_list_button),
                           FALSE );
        gsb_reconcile_list_button_clicked (reconcile_sort_list_button, NULL);
    }

    transaction_list_show_toggle_mark (FALSE);

    /* restore the saved data */
    etat.retient_affichage_par_compte = reconcile_save_account_display;

    gsb_transactions_list_set_visible_rows_number ( reconcile_save_rows_number );

    if (reconcile_save_show_marked)
    {
        gsb_data_account_set_r (gsb_gui_navigation_get_current_account (), TRUE );
        mise_a_jour_affichage_r (TRUE);
    }

    /* Don't display uneeded widget for now. */
    gtk_widget_hide ( reconcile_panel );
    gsb_reconcile_sensitive (TRUE);

    return FALSE;
}
Esempio n. 6
0
/**
 * Show or hide display of lines archives.
 *
 * \return FALSE
 */
gboolean gsb_gui_toggle_show_archived ( void )
{
    gint current_account;

    if ( block_menu_cb )
	    return FALSE;

    current_account = gsb_gui_navigation_get_current_account ( );
    if ( current_account == -1 )
        return FALSE;

    if ( gsb_data_account_get_l ( current_account ) )
	    change_aspect_liste ( 8 );
    else
	    change_aspect_liste ( 7 );

    return FALSE;
}
Esempio n. 7
0
/**
 * Show or hide display of reconciled transactions.
 *
 * \return FALSE
 */
gboolean gsb_gui_toggle_show_reconciled ( void )
{
    gint current_account;

    if ( block_menu_cb )
	    return FALSE;

    current_account = gsb_gui_navigation_get_current_account ( );
    if ( current_account == -1 || run.equilibrage == 1 )
        return FALSE;

    if ( gsb_data_account_get_r ( current_account ) )
	    change_aspect_liste ( 6 );
    else
	    change_aspect_liste ( 5 );

    return FALSE;
}
Esempio n. 8
0
/**
 * Initialize user interface part when a new accounts file is created.
 */
void gsb_file_new_gui ( void )
{
    GtkWidget *main_vbox;
    GtkWidget *tree_view_widget;
    GtkWidget *notebook_general;

    /* dégrise les menus nécessaire */
    gsb_menu_set_menus_with_file_sensitive ( TRUE );

    /*     récupère l'organisation des colonnes  */
    recuperation_noms_colonnes_et_tips ();

    /* Create main widget. */
    gsb_status_message ( _("Creating main window") );
    main_vbox = g_object_get_data ( G_OBJECT ( run.window ), "main_vbox" );
    gtk_box_pack_start ( GTK_BOX ( main_vbox ), gsb_gui_create_general_widgets ( ), TRUE, TRUE, 0 );

    /* create the model */
    if (!transaction_list_create ())
    {
    dialogue_error (_("The model of the list couldn't be created... "
                        "Bad things will happen very soon..."));
    return;
    }

    /* Create transaction list. */
    tree_view_widget = gsb_transactions_list_make_gui_list ();
    gtk_box_pack_start ( GTK_BOX ( tree_view_vbox ),
                tree_view_widget,
                TRUE,
                TRUE,
                0 );
    gtk_widget_show ( tree_view_widget );

    navigation_change_account ( gsb_gui_navigation_get_current_account () );

    /* Display accounts in menus */
    gsb_menu_update_accounts_in_menus ();

    notebook_general = gsb_gui_get_general_notebook ( );
    gtk_notebook_set_current_page ( GTK_NOTEBOOK( notebook_general ), GSB_HOME_PAGE );

    gtk_widget_show ( notebook_general );
}
Esempio n. 9
0
/**
 *  Create a menu with the list of accounts.  This list is
 *  clickable and activates func if specified.
 *  used for now to add a submenu item in a main menu
 *
 * \param func Function to call when a line is selected
 * \param activate_currrent If set to TRUE, does not mark as
 *        unsensitive current account
 * \param include_closed If set to TRUE, include the closed accounts
 *
 * \return A newly created menu
 */
GtkWidget *gsb_account_create_menu_list ( GCallback func,
					  gboolean activate_currrent,
					  gboolean include_closed )
{
    GtkWidget *menu;
    GtkWidget *item;
    GSList *list_tmp;

    menu = gtk_menu_new ();

    list_tmp = gsb_data_account_get_list_accounts ();

    while ( list_tmp )
    {
	gint i;

	i = gsb_data_account_get_no_account ( list_tmp -> data );

	if (  i >= 0 && ( !gsb_data_account_get_closed_account (i) || include_closed ) )
	{
	    item = gtk_menu_item_new_with_label ( gsb_data_account_get_name (i));
	    g_object_set_data ( G_OBJECT ( item ),
				  "account_number",
				  GINT_TO_POINTER (i));
	    if ( func )
		g_signal_connect ( G_OBJECT ( item ), "activate", G_CALLBACK(func), NULL );
	    gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), item );

	    if ( !activate_currrent && 
		 gsb_gui_navigation_get_current_account () == i)
	    {
		gtk_widget_set_sensitive ( item, FALSE );
	    }      

	    gtk_widget_show ( item );
	}
	list_tmp = list_tmp -> next;
    }

    return ( menu );
}
Esempio n. 10
0
/**
 * update the labels according to the value in the account structure and the entries
 * so all the calculs must have been done before (for marked transactions)
 *
 * \param entry not used
 * \param null not used
 *
 * \return FALSE
 * */
gboolean gsb_reconcile_update_amounts ( GtkWidget *entry,
					    gpointer null )
{
    gsb_real amount;
    gint account_number;
    gint currency_number;
    const gchar *initial_balance;
    const gchar *final_balance;
    gchar *tmp_string;
	gchar* tmpstr;
    gboolean valide = FALSE;

    /* first get the current account number */
    account_number = gsb_gui_navigation_get_current_account ();

    /* fill the labels corresponding to the balances */
    initial_balance = gtk_entry_get_text ( GTK_ENTRY (reconcile_initial_balance_entry) );
    gtk_label_set_text ( GTK_LABEL ( reconcile_initial_balance_label ), initial_balance );

    if ( entry )
    {
        valide = gsb_form_widget_get_valide_amout_entry (
                        gtk_entry_get_text ( GTK_ENTRY ( entry ) ) );
        if ( valide )
        {
            /* the entry is valid, make it normal */
            gtk_widget_modify_base ( entry, GTK_STATE_NORMAL, NULL );
        }
        else
        {
            /* the entry is not valid, make it red */
            gtk_widget_modify_base ( entry, GTK_STATE_NORMAL, gsb_color_get_couleur ( "entry_error_color" ) );
            return FALSE;
        }
    }

    currency_number = gsb_data_account_get_currency ( account_number );
    amount = utils_real_get_calculate_entry ( reconcile_final_balance_entry );
    final_balance = utils_real_get_string_with_currency ( amount, currency_number, FALSE );
    gtk_label_set_text ( GTK_LABEL ( reconcile_final_balance_label ), final_balance );

    /* set the marked balance amount,
     * this is what we mark as P while reconciling, so it's the total marked balance
     * - the initial marked balance */
    tmp_string = utils_real_get_string_with_currency (
                        gsb_data_account_calculate_waiting_marked_balance ( account_number ),
                        currency_number,
                        FALSE );
    gtk_label_set_text ( GTK_LABEL ( reconcile_marked_balance_label ), tmp_string );
    g_free (tmp_string);

    /* calculate the variation balance and show it */
    amount = gsb_real_sub ( gsb_real_add (
                        utils_real_get_from_string ( initial_balance ),
					    gsb_data_account_calculate_waiting_marked_balance ( account_number ) ),
			            utils_real_get_from_string ( final_balance ) );

    tmpstr = utils_real_get_string_with_currency ( amount, currency_number, FALSE );
    gtk_label_set_text ( GTK_LABEL ( reconcile_variation_balance_label ), tmpstr);
    g_free ( tmpstr );

    if ( amount.mantissa )
	    gtk_widget_set_sensitive ( GTK_WIDGET ( reconcile_ok_button ), FALSE );
    else
	    gtk_widget_set_sensitive ( GTK_WIDGET ( reconcile_ok_button ), TRUE );
    return FALSE;
}
Esempio n. 11
0
/**
 * finish the reconciliation,
 * called by a click on the finish button
 *
 * \param button
 * \param null
 *
 * \return FALSE
 */
gboolean gsb_reconcile_finish_reconciliation ( GtkWidget *button,
					    gpointer null )
{
    GSList *list_tmp_transactions;
    GDate *date;
    gint account_number;
    gint reconcile_number;
    gsb_real real;
	gchar* tmpstr;

    account_number = gsb_gui_navigation_get_current_account ();

    if ( gsb_real_sub ( gsb_real_add ( utils_real_get_from_string (gtk_entry_get_text ( GTK_ENTRY ( reconcile_initial_balance_entry ))),
				       gsb_data_account_calculate_waiting_marked_balance (account_number)),
			utils_real_get_from_string (gtk_entry_get_text ( GTK_ENTRY ( reconcile_final_balance_entry )))).mantissa != 0 )
    {
	dialogue_warning_hint ( _("There is a variance in balances, check that both final balance and initial balance minus marked transactions are equal."),
				_("Reconciliation can't be completed.") );
	return FALSE;
    }

    /* get and check the reconcile name */
    reconcile_number = gsb_data_reconcile_get_number_by_name (gtk_entry_get_text ( GTK_ENTRY ( reconcile_number_entry )));
    if (reconcile_number)
    {
	dialogue_warning_hint ( _("There is already a reconcile with that name, you must use another name or let it free.\nIf the reconcile name is ending by a number,\nit will be automatically incremented."),
				_("Reconciliation can't be completed.") );
	return FALSE;
    }


    /* get and save the date */
    date = gsb_calendar_entry_get_date (reconcile_new_date_entry);
    if (!date)
    {
	gchar* tmpstr = g_strdup_printf ( _("Invalid date: '%s'"),
						  gtk_entry_get_text ( GTK_ENTRY ( reconcile_new_date_entry )));
	dialogue_warning_hint ( tmpstr,
				_("Reconciliation can't be completed.") );
	g_free ( tmpstr );
	return FALSE;
    }

    if (!strlen (gtk_entry_get_text ( GTK_ENTRY ( reconcile_number_entry ))))
    {
	dialogue_warning_hint ( _("You need to set a name to the reconciliation ; at least, set a number,\nit will be automatically incremented later"),
				_("Reconciliation can't be completed.") );
	return FALSE;
    }

    /* restore the good sort of the list */
    if (transaction_list_sort_get_reconcile_sort ())
    {
	gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (reconcile_sort_list_button),
				       FALSE );
	gsb_reconcile_list_button_clicked (reconcile_sort_list_button, NULL);
    }

    tmpstr = g_strdup_printf ( _("Last statement: %s"), gsb_format_gdate (date));
    gtk_label_set_text ( GTK_LABEL ( label_last_statement ),
			 tmpstr);
    g_free ( tmpstr );

    /* create the new reconcile structure */
    reconcile_number = gsb_data_reconcile_new (gtk_entry_get_text (GTK_ENTRY (reconcile_number_entry)));
    gsb_data_reconcile_set_account ( reconcile_number, account_number );

    /* set the variables of the reconcile */
    gsb_data_reconcile_set_final_date ( reconcile_number, date );
    g_date_free (date);

    date = gsb_parse_date_string (gtk_label_get_text (GTK_LABEL (reconcile_last_date_label)));
    gsb_data_reconcile_set_init_date ( reconcile_number, date );
    g_free (date);

    real = utils_real_get_from_string ( gtk_entry_get_text (
                        GTK_ENTRY ( reconcile_initial_balance_entry ) ) );
    gsb_data_reconcile_set_init_balance ( reconcile_number, real );

    real = utils_real_get_from_string ( gtk_entry_get_text (
                        GTK_ENTRY ( reconcile_final_balance_entry ) ) );
    gsb_data_reconcile_set_final_balance ( reconcile_number,
					   real );

    /* modify the reconciled transactions */
    list_tmp_transactions = gsb_data_transaction_get_transactions_list ();

    while ( list_tmp_transactions )
    {
	gint transaction_number_tmp;
	transaction_number_tmp = gsb_data_transaction_get_transaction_number (
                        list_tmp_transactions -> data);

	if ( gsb_data_transaction_get_account_number (transaction_number_tmp) == account_number
	     &&
	     ( gsb_data_transaction_get_marked_transaction (transaction_number_tmp) == OPERATION_POINTEE
	       ||
	       gsb_data_transaction_get_marked_transaction (transaction_number_tmp) == OPERATION_TELERAPPROCHEE ))
	{
	    gsb_data_transaction_set_marked_transaction ( transaction_number_tmp,
							  OPERATION_RAPPROCHEE );
	    gsb_data_transaction_set_reconcile_number ( transaction_number_tmp,
							reconcile_number );
	}
	list_tmp_transactions = list_tmp_transactions -> next;
    }

    /* update the P and T to R in the list */
    transaction_list_update_element (ELEMENT_MARK);

    run.mise_a_jour_liste_comptes_accueil = TRUE;

    /* go back to the normal transactions list */
    gsb_reconcile_cancel (NULL, NULL);

    /* reset records in run: to do after gsb_reconcile_cancel */
    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;

    gsb_file_set_modified ( TRUE );

    if ( reconcile_save_last_scheduled_convert )
    {
        gsb_gui_navigation_set_selection ( GSB_SCHEDULER_PAGE, 0, NULL );
        gsb_scheduler_list_select ( reconcile_save_last_scheduled_convert );
        gsb_scheduler_list_edit_transaction ( reconcile_save_last_scheduled_convert );
        reconcile_save_last_scheduled_convert = 0;
    }

    return FALSE;
}
Esempio n. 12
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;
}
Esempio n. 13
0
/**
 * Build the new label for the reconciliation, given the old one.
 * The expected format is NAME+NUMBER, so this function returns
 * a newly allocated string whose format is NAME+(NUMBER+1). It
 * preserves leading '0' for the NUMBER string.
 *
 * If this is the first label building (first reconciliation for
 * this account), then the function returns a standard string
 * of the account name (lower case) + '-1'.
 *
 * \param reconcile_number
 *
 * \return the new string label
 */
gchar *gsb_reconcile_build_label ( int reconcile_number )
{
    gchar *tmp;
    gchar *old_label;
    gchar *new_label;
    gchar format[6] = "%s%0d";
    int __reconcile_number;
    int __size;
    int __expand;

    /* old_label = NAME + NUMBER */
    old_label = g_strdup ( gsb_data_reconcile_get_name ( reconcile_number ) );
    /* return account NAME + '1' */
    if ( !old_label )
    {
        tmp = gsb_data_account_get_name ( gsb_gui_navigation_get_current_account () );
        new_label = g_strconcat ( tmp, "-1", NULL );
        tmp = new_label;
        while ( *tmp != '\0' )
        {
            if ( *tmp == ' ' )
                *tmp = '-';
            else
                *tmp = tolower ( *tmp );
            tmp ++;
        }
        return new_label;
    }

    /* we try to find some digits at the end of the name,
     * if found, get the biggest number until we find a non digit character */
    __expand = 1;
    tmp = old_label + ( strlen ( old_label ) - 1 ) * sizeof ( gchar );
    while ( isdigit ( *tmp ) && tmp >= old_label )
    {
        if ( *tmp != '9' )
            __expand = 0;
        tmp--;
    }
    tmp ++; /* step forward to the first digit */

    __reconcile_number = utils_str_atoi ( tmp ) + 1;

    /* if stage 99 -> 100 for example,
     * then we have to allocate one more byte */
    __size = strlen ( tmp ) + __expand;
    /* format string for the output (according NUMBER string length) */
    format[3] = 48 + __size;

    /* close the NAME string */
    *tmp = 0;
    /* NAME + NUMBER + '\0' */
    __size += strlen ( old_label ) * sizeof ( gchar ) + 1;
    new_label = g_malloc0 ( __size * sizeof ( gchar ) );
    sprintf ( new_label, format, old_label, __reconcile_number );

    /* replace ' ' by '0' in number */
    tmp = new_label + strlen ( old_label ) * sizeof ( gchar );
    while ( *tmp == ' ' )
        *tmp++ = '0';

    g_free ( old_label );

    return new_label;
}
Esempio n. 14
0
/**
 * save the file
 *
 * \param origine 0 from gsb_file_save (menu), -1 from gsb_file_close, -2 from gsb_file_save_as
 *
 * \return TRUE if ok, FALSE if problem
 * */
gboolean gsb_file_save_file ( gint origine )
{
    gint etat_force, result;
    gchar *nouveau_nom_enregistrement;

    devel_debug_int (origine);

    etat_force = 0;

    if ( ( !gsb_file_get_modified ( ) && origine != -2 ) ||
	 !gsb_data_account_get_accounts_amount () )
    {
	notice_debug ( "nothing done in gsb_file_save_file" );
	return ( TRUE );
    }

    /* si le fichier de comptes n'a pas de nom ou si on enregistre sous un nouveau nom */
    /*     c'est ici */

    if ( !nom_fichier_comptes || origine == -2 )
	nouveau_nom_enregistrement = gsb_file_dialog_ask_name ();
    else
	nouveau_nom_enregistrement = nom_fichier_comptes;

    if ( !nouveau_nom_enregistrement )
	return FALSE;

    /*     on vérifie que le fichier n'est pas locké */
    if ( etat.fichier_deja_ouvert
	 &&
	 !conf.force_enregistrement
	 &&
	 origine != -2 )
    {
        gchar* tmpstr1 = g_strdup_printf( _("Grisbi was unable to save this file because it is locked.  Please save it with another name or activate the \"%s\" option in preferences."),
					       _("Force saving of locked files" ) );
	gchar* tmpstr2 = g_strdup_printf( _("Can not save file \"%s\""),
					       nom_fichier_comptes );
	dialogue_error_hint ( tmpstr1,
			      tmpstr2 );
	g_free ( tmpstr1 );
	g_free ( tmpstr2 );
	return ( FALSE );
    }

        /* Si le fichier est un d'une version précédente de grisbi on demande si on l'efface */
    if ( copy_old_filename && strlen ( copy_old_filename ) > 0 )
    {
        gsb_file_save_remove_old_file ( copy_old_filename );
        g_free ( copy_old_filename );
        copy_old_filename = NULL;
    }

    /* make backup before saving if asked */
    if (conf.make_backup)
	gsb_file_save_backup();

    /*   on a maintenant un nom de fichier */
    /*     et on sait qu'on peut sauvegarder */
    gsb_status_message ( _("Saving file") );

    result = gsb_file_save_save_file ( nouveau_nom_enregistrement,
				       conf.compress_file,
				       FALSE );

    if ( result )
    {
	/* saving was right, so unlock the last name */
	gsb_file_util_modify_lock ( FALSE );

	nom_fichier_comptes = nouveau_nom_enregistrement;

	/* and lock the new name */
	gsb_file_util_modify_lock ( TRUE );

	/* update variables */
	etat.fichier_deja_ouvert = 0;
        gsb_file_set_modified ( FALSE );
	gsb_main_set_grisbi_title ( gsb_gui_navigation_get_current_account ( ) );
	gsb_file_append_name_to_opened_list ( nom_fichier_comptes );
    }

    gsb_status_message ( _("Done") );

    return ( result );
}
Esempio n. 15
0
/** 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;
}