/* for each entry, check the tax tables. If the tax tables are * grandchildren, then fix them to point to the most senior child */ static void taxtable_scrub_entries (QofInstance * entry_p, gpointer ht_p) { GHashTable *ht = static_cast<decltype(ht)>(ht_p); GncEntry *entry = GNC_ENTRY(entry_p); GncTaxTable *table, *new_tt; gint32 count; table = gncEntryGetInvTaxTable(entry); if (table) { if (taxtable_is_grandchild(table)) { gchar guidstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(entry)),guidstr); PINFO("Fixing i-taxtable on entry %s\n",guidstr); new_tt = taxtable_find_senior(table); gncEntryBeginEdit(entry); gncEntrySetInvTaxTable(entry, new_tt); gncEntryCommitEdit(entry); table = new_tt; } if (table) { count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table)); count++; g_hash_table_insert(ht, table, GINT_TO_POINTER(count)); } } table = gncEntryGetBillTaxTable(entry); if (table) { if (taxtable_is_grandchild(table)) { gchar guidstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(entry)),guidstr); PINFO("Fixing b-taxtable on entry %s\n",guidstr); new_tt = taxtable_find_senior(table); gncEntryBeginEdit(entry); gncEntrySetBillTaxTable(entry, new_tt); gncEntryCommitEdit(entry); table = new_tt; } if (table) { count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table)); count++; g_hash_table_insert(ht, table, GINT_TO_POINTER(count)); } } }
/* build a list of tax tables that are grandchildren or bogus (empty entry list). */ static void taxtable_scrub_cb (QofInstance * table_p, gpointer list_p) { GncTaxTable *table = GNC_TAXTABLE(table_p); GList **list = list_p; if (taxtable_is_grandchild(table) || gncTaxTableGetEntries(table) == NULL) *list = g_list_prepend(*list, table); }