/** * fill the budget of the transaction from the string given in param * create the budget if necessary * if string is NULL, free the budget of the transaction * * \param transaction_number * \param string a string like "budget : sub_budget" * \param is_transaction TRUE if it's for a transaction, FALSE for a scheduled transaction * * \return * */ void gsb_data_budget_set_budget_from_string ( gint transaction_number, const gchar *string, gboolean is_transaction ) { gchar **tab_char; gint budget_number; /* the simpliest is to split in 2 parts, transaction and scheduled, * but the 2 parts are exactly the same, exept the call to the functions */ if (is_transaction) { if (!string || strlen ( string ) == 0 ) { gsb_data_transaction_set_budgetary_number ( transaction_number, 0 ); gsb_data_transaction_set_sub_budgetary_number ( transaction_number, 0 ); return; } tab_char = g_strsplit ( string, " : ", 2 ); /* we don't mind if tab_char exists and others, all the checks will be done in ...get_number_by_name */ budget_number = gsb_data_budget_get_number_by_name ( g_strstrip ( tab_char[0] ), TRUE, gsb_data_transaction_get_amount ( transaction_number ).mantissa < 0 ); gsb_data_transaction_set_budgetary_number ( transaction_number, budget_number ); if ( tab_char[1] ) gsb_data_transaction_set_sub_budgetary_number ( transaction_number, gsb_data_budget_get_sub_budget_number_by_name ( budget_number, g_strstrip (tab_char[1]), TRUE )); } else { if (!string) { gsb_data_scheduled_set_budgetary_number ( transaction_number, 0 ); gsb_data_scheduled_set_sub_budgetary_number ( transaction_number, 0 ); return; } tab_char = g_strsplit ( string, " : ", 2 ); /* we don't mind if tab_char exists and others, all the checks will be done in ...get_number_by_name */ budget_number = gsb_data_budget_get_number_by_name ( tab_char[0], TRUE, gsb_data_scheduled_get_amount (transaction_number).mantissa <0 ); gsb_data_scheduled_set_budgetary_number ( transaction_number, budget_number ); if ( tab_char[1] ) gsb_data_scheduled_set_sub_budgetary_number ( transaction_number, gsb_data_budget_get_sub_budget_number_by_name ( budget_number, tab_char[1], TRUE )); } g_strfreev (tab_char); }
gboolean gsb_data_mix_set_budgetary_number ( gint transaction_number, gint budgetary_number, gboolean is_transaction ) { if ( is_transaction ) return ( gsb_data_transaction_set_budgetary_number ( transaction_number, budgetary_number ) ); else return ( gsb_data_scheduled_set_budgetary_number ( transaction_number, budgetary_number ) ); }