Exemplo n.º 1
0
void gsb_real_cunit__gsb_real_sub( void )
{
    GsbReal a = { -1, 0 };
    GsbReal b = { 31415, 4 };
    GsbReal r = gsb_real_sub ( a, b );
    CU_ASSERT_EQUAL ( -41415, r.mantissa );
    CU_ASSERT_EQUAL ( 4, r.exponent );

    a.mantissa = 0x7FFFFFFE;
    a.exponent = 0;
    b.mantissa = -1;
    b.exponent = 0;
    r = gsb_real_sub ( a, b );
    CU_ASSERT_EQUAL ( 0x7FFFFFFF, r.mantissa );
    CU_ASSERT_EQUAL ( 0, r.exponent );

    a.mantissa = 0x7FFFFFFF;
    a.exponent = 0;
    b.mantissa = -2;
    b.exponent = 0;
    r = gsb_real_sub ( a, b );
    CU_ASSERT_EQUAL ( 0x80000001, r.mantissa );
    CU_ASSERT_EQUAL ( 0, r.exponent );

    a.mantissa = 0x80000001;
    a.exponent = 0;
    b.mantissa = 2;
    b.exponent = 0;
    r = gsb_real_sub ( a, b );
    CU_ASSERT_EQUAL ( 0x7FFFFFFF, r.mantissa );
    CU_ASSERT_EQUAL  (0, r.exponent );

}
Exemplo n.º 2
0
/**
 * remove the given transaction to its payee in the counters
 * if the transaction has no payee, remove it to the blank payee
 *
 * \param transaction_number the transaction we want to work with
 *
 * \return
 * */
void gsb_data_payee_remove_transaction_from_payee ( gint transaction_number )
{
    struct_payee *payee;

    payee = gsb_data_payee_get_structure ( gsb_data_transaction_get_party_number (transaction_number));

    /* if no payee in that transaction, and it's neither a split, neither a transfer,
     * we work with empty_payee */

    if (!payee
            &&
            !gsb_data_transaction_get_split_of_transaction (transaction_number)
            && 
            gsb_data_transaction_get_contra_transaction_number (transaction_number) == 0)
        payee = empty_payee;

    if (payee)
    {
        payee -> payee_nb_transactions --;
        payee -> payee_balance = gsb_real_sub ( payee -> payee_balance,
                gsb_data_transaction_get_adjusted_amount_for_currency ( transaction_number,
                    payee_tree_currency (), -1));

        if ( !payee -> payee_nb_transactions ) /* Cope with float errors */
            payee -> payee_balance = null_real;
    }
}
Exemplo n.º 3
0
gboolean csv_import_parse_debit ( struct struct_ope_importation * ope, gchar * string )
{
    if ( !string )
        return FALSE;

    if ( strlen ( string ) > 0 )
    {
        ope -> montant = gsb_real_sub ( ope -> montant,
                        utils_real_get_from_string ( string ) );
    }

    return TRUE;
}
Exemplo n.º 4
0
/**
 * remove the given transaction to its budget in the counters
 * if the transaction has no budget, remove it to the blank budget
 *
 * \param transaction_number the transaction we want to work with
 *
 * \return
 * */
void gsb_data_budget_remove_transaction_from_budget ( gint transaction_number )
{
    struct_budget *budget;
    struct_sub_budget *sub_budget;

    budget = gsb_data_budget_get_structure ( gsb_data_transaction_get_budgetary_number (transaction_number));
    sub_budget = gsb_data_budget_get_sub_budget_structure ( gsb_data_transaction_get_budgetary_number (transaction_number),
							    gsb_data_transaction_get_sub_budgetary_number (transaction_number));

    if ( budget )
    {
	budget -> budget_nb_transactions --;
	budget -> budget_balance = gsb_real_sub ( budget -> budget_balance,
						  gsb_data_transaction_get_adjusted_amount_for_currency ( transaction_number,
													  budgetary_line_tree_currency (), -1));
	if ( !budget -> budget_nb_transactions ) /* Cope with float errors */
	    budget -> budget_balance = null_real;
    }

    if ( sub_budget )
    {
	sub_budget -> sub_budget_nb_transactions --;
	sub_budget -> sub_budget_balance = gsb_real_sub ( sub_budget -> sub_budget_balance,
							  gsb_data_transaction_get_adjusted_amount_for_currency ( transaction_number,
														  budgetary_line_tree_currency (), -1));
	if ( !sub_budget -> sub_budget_nb_transactions ) /* Cope with float errors */
	    sub_budget -> sub_budget_balance = null_real;
    }
    else
    {
	if ( budget )
	{
	    budget -> budget_nb_direct_transactions --;
	    budget -> budget_direct_balance = gsb_real_sub ( budget -> budget_direct_balance,
							     gsb_data_transaction_get_adjusted_amount_for_currency ( transaction_number,
														     budgetary_line_tree_currency (), -1));
	}
    }
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
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;
}