static GncTaxTable *
taxtable_find_senior (GncTaxTable *table)
{
    GncTaxTable *temp, *parent, *gp = NULL;

    temp = table;
    do
    {
        /* See if "temp" is a grandchild */
        parent = gncTaxTableGetParent(temp);
        if (!parent)
            break;
        gp = gncTaxTableGetParent(parent);
        if (!gp)
            break;

        /* Yep, this is a grandchild.  Move up one generation and try again */
        temp = parent;
    }
    while (TRUE);

    /* Ok, at this point temp points to the most senior child and parent
     * should point to the top taxtable (and gp should be NULL).  If
     * parent is NULL then we are the most senior child (and have no
     * children), so do nothing.  If temp == table then there is no
     * grandparent, so do nothing.
     *
     * Do something if parent != NULL && temp != table
     */
    g_assert (gp == NULL);

    /* return the most senior table */
    return temp;
}
static xmlNodePtr
taxtable_dom_tree_create (GncTaxTable *table)
{
    xmlNodePtr ret, entries;
    GList *list;
    kvp_frame *kf;

    ret = xmlNewNode(NULL, BAD_CAST gnc_taxtable_string);
    xmlSetProp(ret, BAD_CAST "version", BAD_CAST taxtable_version_string);

    maybe_add_guid(ret, taxtable_guid_string, table);
    xmlAddChild(ret, text_to_dom_tree (taxtable_name_string,
                                       gncTaxTableGetName (table)));

    xmlAddChild(ret, int_to_dom_tree (taxtable_refcount_string,
                                      gncTaxTableGetRefcount (table)));
    xmlAddChild(ret, int_to_dom_tree (taxtable_invisible_string,
                                      gncTaxTableGetInvisible (table)));

    /* We should not be our own child */
    if (gncTaxTableGetChild(table) != table)
        maybe_add_guid(ret, taxtable_child_string, gncTaxTableGetChild (table));

    maybe_add_guid(ret, taxtable_parent_string, gncTaxTableGetParent (table));

    entries = xmlNewChild (ret, NULL, BAD_CAST taxtable_entries_string, NULL);
    for (list = gncTaxTableGetEntries (table); list; list = list->next)
    {
        GncTaxTableEntry *entry = list->data;
        xmlAddChild(entries, ttentry_dom_tree_create (entry));
    }

    kf = qof_instance_get_slots (QOF_INSTANCE(table));
    if (kf)
    {
        xmlNodePtr kvpnode = kvp_frame_to_dom_tree(taxtable_slots_string, kf);
        if (kvpnode)
        {
            xmlAddChild(ret, kvpnode);
        }
    }

    return ret;
}
Beispiel #3
0
static void
load_single_taxtable( GncSqlBackend* be, GncSqlRow* row,
                      GList** l_tt_needing_parents )
{
    const GncGUID* guid;
    GncTaxTable* tt;

    g_return_if_fail( be != NULL );
    g_return_if_fail( row != NULL );

    guid = gnc_sql_load_guid( be, row );
    tt = gncTaxTableLookup( be->book, guid );
    if ( tt == NULL )
    {
        tt = gncTaxTableCreate( be->book );
    }
    gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, tt, tt_col_table );
    gnc_sql_slots_load( be, QOF_INSTANCE(tt) );
    load_taxtable_entries( be, tt );

    /* If the tax table doesn't have a parent, it might be because it hasn't been loaded yet.
       If so, add this tax table to the list of tax tables with no parent, along with the parent
       GncGUID so that after they are all loaded, the parents can be fixed up. */
    if ( gncTaxTableGetParent( tt ) == NULL )
    {
        taxtable_parent_guid_struct* s = static_cast<decltype(s)>(
            g_malloc(sizeof(taxtable_parent_guid_struct)));
        g_assert( s != NULL );

        s->tt = tt;
        s->have_guid = FALSE;
        gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, s, tt_parent_col_table );
        if ( s->have_guid )
        {
            *l_tt_needing_parents = g_list_prepend( *l_tt_needing_parents, s );
        }
        else
        {
            g_free( s );
        }
    }

    qof_instance_mark_clean( QOF_INSTANCE(tt) );
}
Beispiel #4
0
static void
load_single_taxtable (GncSqlBackend* sql_be, GncSqlRow& row,
                      TaxTblParentGuidVec& l_tt_needing_parents)
{
    const GncGUID* guid;
    GncTaxTable* tt;

    g_return_if_fail (sql_be != NULL);

    guid = gnc_sql_load_guid (sql_be, row);
    tt = gncTaxTableLookup (sql_be->book(), guid);
    if (tt == nullptr)
    {
        tt = gncTaxTableCreate (sql_be->book());
    }
    gnc_sql_load_object (sql_be, row, GNC_ID_TAXTABLE, tt, tt_col_table);
    gnc_sql_slots_load (sql_be, QOF_INSTANCE (tt));
    load_taxtable_entries (sql_be, tt);

    /* If the tax table doesn't have a parent, it might be because it hasn't
       been loaded yet.  if so, add this tax table to the list of tax tables
       with no parent, along with the parent GncGUID so that after they are all
       loaded, the parents can be fixed up. */
    if (gncTaxTableGetParent (tt) == NULL)
    {
        TaxTblParentGuid s;

        s.tt = tt;
        s.have_guid = false;
        gnc_sql_load_object (sql_be, row, GNC_ID_TAXTABLE, &s,
                             tt_parent_col_table);
        if (s.have_guid)
            l_tt_needing_parents.push_back(new TaxTblParentGuid(s));

    }

    qof_instance_mark_clean (QOF_INSTANCE (tt));
}
Beispiel #5
0
static /*@ null @*//*@ dependent @*/ gpointer
bt_get_parent( gpointer pObject )
{
    const GncTaxTable* tt;
    const GncTaxTable* pParent;
    const GncGUID* parent_guid;

    g_return_val_if_fail( pObject != NULL, NULL );
    g_return_val_if_fail( GNC_IS_TAXTABLE(pObject), NULL );

    tt = GNC_TAXTABLE(pObject);
    pParent = gncTaxTableGetParent( tt );
    if ( pParent == NULL )
    {
        parent_guid = NULL;
    }
    else
    {
        parent_guid = qof_instance_get_guid( QOF_INSTANCE(pParent) );
    }

    return (gpointer)parent_guid;
}
static void
taxtable_scrub (QofBook *book)
{
    GList *list = NULL;
    GList *node;
    GncTaxTable *parent, *table;
    GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal);

    qof_object_foreach (GNC_ID_ENTRY, book, taxtable_scrub_entries, ht);
    qof_object_foreach (GNC_ID_CUSTOMER, book, taxtable_scrub_cust, ht);
    qof_object_foreach (GNC_ID_VENDOR, book, taxtable_scrub_vendor, ht);
    qof_object_foreach (GNC_ID_TAXTABLE, book, taxtable_scrub_cb, &list);

    /* destroy the list of "grandchildren" tax tables */
    for (node = list; node; node = node->next)
    {
        gchar guidstr[GUID_ENCODING_LENGTH+1];
        table = static_cast<decltype(table)>(node->data);

        guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(table)),guidstr);
        PINFO ("deleting grandchild taxtable: %s\n", guidstr);

        /* Make sure the parent has no children */
        parent = gncTaxTableGetParent(table);
        gncTaxTableSetChild(parent, NULL);

        /* Destroy this tax table */
        gncTaxTableBeginEdit(table);
        gncTaxTableDestroy(table);
    }

    /* reset the refcounts as necessary */
    g_hash_table_foreach(ht, taxtable_reset_refcount, NULL);

    g_list_free(list);
    g_hash_table_destroy(ht);
}
static xmlNodePtr
taxtable_dom_tree_create (GncTaxTable *table)
{
    xmlNodePtr ret, entries;
    GList *list;

    ret = xmlNewNode(NULL, BAD_CAST gnc_taxtable_string);
    xmlSetProp(ret, BAD_CAST "version", BAD_CAST taxtable_version_string);

    maybe_add_guid(ret, taxtable_guid_string, table);
    xmlAddChild(ret, text_to_dom_tree (taxtable_name_string,
                                       gncTaxTableGetName (table)));

    xmlAddChild(ret, int_to_dom_tree (taxtable_refcount_string,
                                      gncTaxTableGetRefcount (table)));
    xmlAddChild(ret, int_to_dom_tree (taxtable_invisible_string,
                                      gncTaxTableGetInvisible (table)));

    /* We should not be our own child */
    if (gncTaxTableGetChild(table) != table)
        maybe_add_guid(ret, taxtable_child_string, gncTaxTableGetChild (table));

    maybe_add_guid(ret, taxtable_parent_string, gncTaxTableGetParent (table));

    entries = xmlNewChild (ret, NULL, BAD_CAST taxtable_entries_string, NULL);
    for (list = gncTaxTableGetEntries (table); list; list = list->next)
    {
        GncTaxTableEntry *entry = static_cast<decltype(entry)>(list->data);
        xmlAddChild(entries, ttentry_dom_tree_create (entry));
    }

    /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
    xmlAddChild(ret, qof_instance_slots_to_dom_tree(taxtable_slots_string,
                                                    QOF_INSTANCE(table)));
    return ret;
}
static gboolean
taxtable_is_grandchild (GncTaxTable *table)
{
    return (gncTaxTableGetParent(gncTaxTableGetParent(table)) != NULL);
}