Ejemplo n.º 1
0
gboolean gsb_data_mix_set_financial_year_number ( gint transaction_number,
                        gint financial_year_number,
                        gboolean is_transaction )
{
    if ( is_transaction )
        return (gsb_data_transaction_set_financial_year_number ( transaction_number,
                        financial_year_number ) );
    else
        return (gsb_data_scheduled_set_financial_year_number ( transaction_number,
                        financial_year_number ) );
}
Ejemplo n.º 2
0
/**
 * associate all transactions without fyear to the corresponding
 * fyear
 *
 * \param
 *
 * \return FALSE
 * */
gboolean gsb_fyear_config_associate_transactions ( void )
{
    GSList *list_tmp;
    gint modification_number = 0;

    if (!question_yes_no_hint ( _("Automatic association of financial years?"),
				_("This function assigns each transaction without a financial year to the one related to its transaction date.  If no financial year matches, the transaction will not be changed."),
				GTK_RESPONSE_NO ))
	return FALSE;

    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);

	if (!gsb_data_transaction_get_financial_year_number (transaction_number))
	{
	    gint fyear_number;

	    fyear_number = gsb_data_fyear_get_from_date (gsb_data_transaction_get_date (transaction_number));
	    if (fyear_number)
	    {
		gsb_data_transaction_set_financial_year_number ( transaction_number,
								 fyear_number );
		modification_number++;
	    }
	}
	list_tmp = list_tmp -> next;
    }

    if (modification_number)
    {
	gchar* tmpstr = g_strdup_printf (_("%d transactions associated"),
				    modification_number);
	dialogue (  tmpstr );
	g_free ( tmpstr );
	transaction_list_update_element (ELEMENT_EXERCICE);
        gsb_file_set_modified ( TRUE );
    }
    else
	dialogue ( _("no transaction to associate"));
    return FALSE;
}
Ejemplo n.º 3
0
/**
 * called to remove a financial year, check before if
 * some transactions are associated with it and warn if yes
 *
 * \param tree_view
 *
 * \return FALSE
 * */
gboolean gsb_fyear_config_remove_fyear ( GtkWidget *tree_view )
{
    GtkTreeIter iter;
    GtkTreeModel *model;
    GtkTreeSelection *selection;
    gint fyear_number;
    gboolean warning_showed = FALSE;
    GSList *tmp_list;

    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
    gtk_tree_selection_get_selected ( GTK_TREE_SELECTION (selection),
				      &model,
				      &iter );
    gtk_tree_model_get ( GTK_TREE_MODEL (model),
			 &iter,
			 FYEAR_NUMBER_COLUMN, &fyear_number,
			 -1 );
    if (!fyear_number)
	return FALSE;

    /* first, we check if one transaction uses that financial year */
    tmp_list = gsb_data_transaction_get_complete_transactions_list ();

    while (tmp_list)
    {
	gint transaction_number;

	transaction_number = gsb_data_transaction_get_transaction_number (tmp_list -> data);

	if ( fyear_number
	     ==
	     gsb_data_transaction_get_financial_year_number (transaction_number))
	{
	    /* at the beginning warning_showed is FALSE and we show a warning,
	     * if the user doesn't want to continue, we go out of the while so cannot come
	     * here again ; but if he wants to continue, warning_showed is set to TRUE, we delete
	     * the financial year and continue to come here to set the fyear of the
	     * transactions to 0 */
	    if (warning_showed)
		gsb_data_transaction_set_financial_year_number (transaction_number, 0);
	    else
	    {
		gint result;

		result = question_yes_no_hint ( _("The selected financial year is used in the file"),
						_("If you really remove it, all the associated transactions will be without financial year.\nAre you sure?"),
						GTK_RESPONSE_NO );
		if (result)
		{
		    gsb_data_transaction_set_financial_year_number (transaction_number, 0);
		    warning_showed = TRUE;
		}
		else
		    break;
	    }
	}
	tmp_list = tmp_list -> next;
    }

    /* if warning_showed is FALSE, it's because none transaction have that fyear,
     * or we answer NO to the warning but in that case, tmp_list is non NULL */
    if (warning_showed
	||
	!tmp_list )
    {
	gsb_data_fyear_remove (fyear_number);

	gtk_list_store_remove ( GTK_LIST_STORE (model),
				&iter );
	gtk_widget_set_sensitive ( g_object_get_data ( G_OBJECT (model),
						       "paddingbox_details" ),
				   FALSE );
	gtk_widget_set_sensitive ( g_object_get_data ( G_OBJECT (model),
						       "remove_fyear_button" ),
				   FALSE );

	/* Update various menus */
	gsb_fyear_update_fyear_list ();
        gsb_file_set_modified ( TRUE );
    }
    return FALSE;
}
Ejemplo n.º 4
0
/**
 * create a new transaction and fill it directly from a scheduled transaction
 * (don't pass throw the form)
 * if it's a child of split, append it automatickly to the mother
 * 
 * \param scheduled_number the transaction we use to fill the new transaction
 * \param transaction_mother the number of the mother if it's a split child, 0 else
 *
 * \return the number of the new transaction
 * */
gint gsb_scheduler_create_transaction_from_scheduled_transaction ( gint scheduled_number,
								   gint transaction_mother )
{
    gint transaction_number, payment_number;
    gint account_number;

    account_number = gsb_data_scheduled_get_account_number (scheduled_number);

    transaction_number = gsb_data_transaction_new_transaction (account_number);

    /* begin to fill the new transaction */
    gsb_data_transaction_set_date ( transaction_number,
				    gsb_date_copy (gsb_data_scheduled_get_date (scheduled_number)));
    gsb_data_transaction_set_party_number ( transaction_number,
					    gsb_data_scheduled_get_party_number (scheduled_number));
    gsb_data_transaction_set_amount ( transaction_number,
				      gsb_data_scheduled_get_amount (scheduled_number));
    gsb_data_transaction_set_currency_number ( transaction_number,
					       gsb_data_scheduled_get_currency_number (scheduled_number));
    gsb_data_transaction_set_account_number ( transaction_number,
					      account_number );

    /* ask for change if necessary, only for normal transaction ; a child must have the same currency number
     * than the mother */
    if (!transaction_mother)
	gsb_currency_check_for_change ( transaction_number );

    gsb_data_transaction_set_method_of_payment_number ( transaction_number,
							gsb_data_scheduled_get_method_of_payment_number (scheduled_number));
    gsb_data_transaction_set_notes ( transaction_number,
				     gsb_data_scheduled_get_notes (scheduled_number));

    payment_number = gsb_data_scheduled_get_method_of_payment_number (scheduled_number);
    if ( payment_number )
    {
	if (gsb_data_payment_get_show_entry (payment_number))
	{
	    if (gsb_data_payment_get_automatic_numbering (payment_number))
	    {
		gchar* tmpstr;

		tmpstr = gsb_data_payment_incremente_last_number ( payment_number, 1 );
		gsb_data_transaction_set_method_of_payment_content ( transaction_number,
								     tmpstr);
		gsb_data_payment_set_last_number ( payment_number, tmpstr );
        g_free ( tmpstr );
	    }
	    else
		gsb_data_transaction_set_method_of_payment_content ( transaction_number,
								     gsb_data_scheduled_get_method_of_payment_content (
                                     scheduled_number ) );
	}
    }
    else
    {
	gsb_data_transaction_set_method_of_payment_content ( transaction_number,
							     gsb_data_scheduled_get_method_of_payment_content (
                                 scheduled_number ) );
    }
    gsb_data_transaction_set_automatic_transaction ( transaction_number,
						     gsb_data_scheduled_get_automatic_scheduled (scheduled_number));
    gsb_data_transaction_set_budgetary_number ( transaction_number,
						gsb_data_scheduled_get_budgetary_number (scheduled_number));
    gsb_data_transaction_set_sub_budgetary_number ( transaction_number,
						    gsb_data_scheduled_get_sub_budgetary_number (scheduled_number));

    /* if the financial year is automatic, we set it here */

    if ( gsb_data_scheduled_get_financial_year_number (scheduled_number) == -2 )
	gsb_data_transaction_set_financial_year_number ( transaction_number,
							 gsb_data_fyear_get_from_date ( gsb_data_transaction_get_date (transaction_number)));
    else
	gsb_data_transaction_set_financial_year_number ( transaction_number,
							 gsb_data_scheduled_get_financial_year_number (scheduled_number));

    /* get the category */

    gsb_scheduler_get_category_for_transaction_from_transaction ( transaction_number,
								  scheduled_number );

     /* set the mother split if exists */
    gsb_data_transaction_set_mother_transaction_number ( transaction_number,
							 transaction_mother );

    /* we show the new transaction in the tree view */
    gsb_transactions_list_append_new_transaction (transaction_number, TRUE);

    return transaction_number;
}