示例#1
0
xmlNodePtr
gnc_budget_dom_tree_create (GncBudget* bgt)
{
    xmlNodePtr ret;

    ENTER ("(budget=%p)", bgt);

    ret = xmlNewNode (NULL, BAD_CAST gnc_budget_string);
    xmlSetProp (ret, BAD_CAST "version", BAD_CAST budget_version_string);

    /* field: GncGUID */
    xmlAddChild (ret, guid_to_dom_tree (bgt_id_string,
                                        gnc_budget_get_guid (bgt)));
    /* field: char* name */
    xmlAddChild (ret, text_to_dom_tree (bgt_name_string,
                                        gnc_budget_get_name (bgt)));
    /* field: char* description */
    xmlAddChild (ret, text_to_dom_tree (bgt_description_string,
                                        gnc_budget_get_description (bgt)));
    /* field: guint num_periods */
    xmlAddChild (ret, guint_to_dom_tree (bgt_num_periods_string,
                                         gnc_budget_get_num_periods (bgt)));
    /* field: Recurrence*  */
    xmlAddChild (ret, recurrence_to_dom_tree (bgt_recurrence_string,
                                              gnc_budget_get_recurrence (bgt)));
    /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
    xmlAddChild (ret, qof_instance_slots_to_dom_tree (bgt_slots_string,
                                                      QOF_INSTANCE (bgt)));

    LEAVE (" ");
    return ret;
}
示例#2
0
/**
 * Saves the budget amounts for a budget.
 *
 * @param sql_be SQL backend
 * @param budget Budget
 */
static gboolean
save_budget_amounts (GncSqlBackend* sql_be, GncBudget* budget)
{
    GList* descendants;
    GList* node;
    budget_amount_info_t info;
    guint num_periods;
    gboolean is_ok = TRUE;;

    g_return_val_if_fail (sql_be != NULL, FALSE);
    g_return_val_if_fail (budget != NULL, FALSE);

    // Delete the amounts, then save
    delete_budget_amounts (sql_be, budget);

    info.budget = budget;
    num_periods = gnc_budget_get_num_periods (budget);
    descendants = gnc_account_get_descendants (gnc_book_get_root_account (
                                                   sql_be->book()));
    for (node = descendants; node != NULL && is_ok; node = g_list_next (node))
    {
        guint i;

        info.account = GNC_ACCOUNT (node->data);
        for (i = 0; i < num_periods && is_ok; i++)
        {
            if (gnc_budget_is_account_period_value_set (budget, info.account, i))
            {
                info.period_num = i;
                is_ok = sql_be->do_db_operation(OP_DB_INSERT, AMOUNTS_TABLE,
                                                "", &info,
                                                 budget_amounts_col_table);
            }
        }
    }
    g_list_free (descendants);

    return is_ok;
}