Beispiel #1
0
/**
 * Find a split in a splits list according to a specific amount and
 * account or category.  This is used to find splits pairs.
 *
 * \param split_list	Split list to lookup.
 * \param amount	Split amount to match against.
 * \param account	Account to match against.
 * \param categ		Category to match against.
 *
 * \return		A gnucash_split upon success.  NULL otherwise.
 */
struct gnucash_split * find_split ( GSList * split_list, GsbReal amount,
				    struct ImportAccount * account,
				    struct gnucash_category * categ )
{
  GSList * tmp;

  (void)account;
  tmp = split_list;
  while ( tmp )
    {
      struct gnucash_split * split = tmp -> data;
      if ( !gsb_real_cmp ( amount,
			   gsb_real_opposite (split -> amount))
	   &&
	   ! ( split -> account && split -> category ) &&
	   ! ( split -> category && categ ) )
	{
	  return split;
	}

      tmp = tmp -> next;
    }

  return NULL;
}
/** used to compare 2 iters and sort the by amount first, and
 * by date and no transaction after
 * always put the white line below
 * \param model the GtkTreeModel
 * \param iter_1
 * \param iter_2
 * \return -1 if iter_1 is above iter_2
 * */
gint gsb_transactions_list_sort_by_amount ( gint transaction_number_1,
                        gint transaction_number_2 )
{
    gint return_value;

    /* for the amounts, we have to check also the currency */
    return_value = gsb_real_cmp ( gsb_data_transaction_get_adjusted_amount ( transaction_number_2, -1),
				  gsb_data_transaction_get_adjusted_amount ( transaction_number_1, -1));

    if ( return_value )
	    return return_value;
    else
	    return gsb_transactions_list_sort_by_date_and_no (transaction_number_1, transaction_number_2);
}
Beispiel #3
0
/**
 * open a new grisbi file, don't check anything about another opened file that must
 * have been done before
 *
 * \para filename the name of the file
 *
 * \return TRUE ok, FALSE problem
 * */
gboolean gsb_file_open_file ( gchar *filename )
{
    GSList *list_tmp;

    devel_debug (filename);

    if ( !filename
	 ||
	 !strlen (filename))
	return FALSE;

    gsb_status_wait ( TRUE );
    gsb_status_message ( _("Loading accounts") );

    /* try to load the file */
    /* FIXME:BUG under Windows: for unknwon reason yet filename is cleared
     * when returning from gsb_file_load_open_file!
     * making application crashes! */

    if ( gsb_file_load_open_file (filename))
    {
        /* the file has been opened succesfully */
        /* we make a backup if necessary */
        if ( conf.sauvegarde_demarrage )
        {
            gsb_file_save_backup ();
            gsb_file_set_modified ( FALSE );
        }
    }
    else
    {
        /* Loading failed. */
        gsb_status_message ( _("Failed to load accounts") );

        if ( conf.sauvegarde_demarrage || conf.make_backup || conf.make_backup_every_minutes )
        {
            gchar *tmpstr = g_strdup_printf ( _("Error loading file '%s'"), filename);
            gchar *tmpstr2 = g_strdup_printf (
                                _("Grisbi was unable to load file. You should find the last "
                                  "backups in '%s', they are saved with date and time into "
                                  "their name so you should find easily the last backup "
                                  "saved.\n"
                                  "Please contact the Grisbi's team on [email protected] "
                                  "to find what happened to you current file."),
                                gsb_file_get_backup_path ());
            dialogue_error_hint ( tmpstr2, tmpstr );
            g_free ( tmpstr );
            g_free ( tmpstr2 );
            gsb_status_stop_wait ( TRUE );
            return FALSE;
        }
        else
        {
            gchar *tmpstr = g_strdup_printf ( _("Error loading file '%s'"), filename);
            gchar *tmpstr2;

            if (gsb_file_get_backup_path ())
            tmpstr2 = g_strdup_printf (
                            _("Grisbi was unable to load file and the backups seem not to "
                              "be activated... This is a bad thing.\nYour backup path is '%s', "
                              "try to find if earlier you had some backups in there ?\n"
                              "Please contact the Grisbi's team on [email protected] "
                              "to find what happened to you current file."),
                            gsb_file_get_backup_path ());
            else
            tmpstr2 = my_strdup ( _("Grisbi was unable to load file and the backups seem not "
                                    "to be activated... This is a bad thing.\n"
                                    "Please contact the Grisbi's team on "
                                    "[email protected] to find what happened to you "
                                    "current file."));

            dialogue_error_hint ( tmpstr2, tmpstr );
            g_free ( tmpstr );
            g_free ( tmpstr2 );
            gsb_status_stop_wait ( TRUE );
            return FALSE;
        }
    }

    /* ok, here the file or backup is loaded */
    gsb_status_message ( _("Checking schedulers"));

    /* the the name in the last opened files */
    gsb_file_append_name_to_opened_list ( filename );

    /* create the archives store data, ie the transaction wich will replace the archive in
     * the list of transactions */
    gsb_data_archive_store_create_list ();

    /* create all the gui */
    gsb_file_new_gui ();

    /* check the amounts of all the accounts */
    gsb_status_message ( _("Checking amounts"));
    list_tmp = gsb_data_account_get_list_accounts ();

    while ( list_tmp )
    {
	gint account_number;
	volatile gint value;

	account_number = gsb_data_account_get_no_account ( list_tmp -> data );

	/* set the minimum balances to be shown or not */
	value = gsb_real_cmp ( gsb_data_account_get_current_balance (account_number),
                          gsb_data_account_get_mini_balance_authorized (account_number) ) == -1;
    gsb_data_account_set_mini_balance_authorized_message ( account_number, value);
    value = gsb_real_cmp ( gsb_data_account_get_current_balance (account_number),
                          gsb_data_account_get_mini_balance_wanted (account_number) ) == -1;
    gsb_data_account_set_mini_balance_wanted_message ( account_number, value);
	list_tmp = list_tmp -> next;
    }

    /* set Grisbi title */
    gsb_main_set_grisbi_title ( -1 );

    /* update the main page */
    mise_a_jour_accueil (TRUE);

    /* for now, the flag for modification of the file is ok, but the menu couldn't be set
     * as sensitive/unsensitive so do it now */
    gsb_file_set_modified ( gsb_file_get_modified ( ) );

    gsb_status_message ( _("Done") );
    gsb_status_stop_wait ( TRUE );

    /* go to the home page */
    gsb_gui_navigation_set_selection ( GSB_HOME_PAGE, -1, NULL );

    /* set the focus to the selection tree at left */
    gtk_widget_grab_focus ( gsb_gui_navigation_get_tree_view ( ) );

    return TRUE;
}