/* for each invoice, check the bill terms. If the bill terms are * grandchildren, then fix them to point to the most senior child */ static void billterm_scrub_invoices (QofInstance* invoice_p, gpointer ht_p) { GHashTable* ht = static_cast<decltype (ht)> (ht_p); GncInvoice* invoice = GNC_INVOICE (invoice_p); GncBillTerm* term, *new_bt; gint32 count; term = gncInvoiceGetTerms (invoice); if (term) { if (billterm_is_grandchild (term)) { gchar guidstr[GUID_ENCODING_LENGTH + 1]; guid_to_string_buff (qof_instance_get_guid (QOF_INSTANCE (invoice)), guidstr); PWARN ("Fixing i-billterm on invoice %s\n", guidstr); new_bt = billterm_find_senior (term); gncInvoiceBeginEdit (invoice); gncInvoiceSetTerms (invoice, new_bt); gncInvoiceCommitEdit (invoice); term = new_bt; } if (term) { count = GPOINTER_TO_INT (g_hash_table_lookup (ht, term)); count++; g_hash_table_insert (ht, term, GINT_TO_POINTER (count)); } } }
static void billterm_scrub_vendor (QofInstance * vendor_p, gpointer ht_p) { GHashTable *ht = ht_p; GncVendor *vendor = GNC_VENDOR(vendor_p); GncBillTerm *term; gint32 count; term = gncVendorGetTerms(vendor); if (term) { count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term)); count++; g_hash_table_insert(ht, term, GINT_TO_POINTER(count)); if (billterm_is_grandchild(term)) PWARN("vendor %s has grandchild billterm %s\n", guid_to_string(qof_instance_get_guid(QOF_INSTANCE(vendor))), guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term)))); } }
static void billterm_scrub_cust (QofInstance * cust_p, gpointer ht_p) { GHashTable *ht = ht_p; GncCustomer *cust = GNC_CUSTOMER(cust_p); GncBillTerm *term; gint32 count; term = gncCustomerGetTerms(cust); if (term) { count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term)); count++; g_hash_table_insert(ht, term, GINT_TO_POINTER(count)); if (billterm_is_grandchild(term)) PWARN("customer %s has grandchild billterm %s\n", guid_to_string(qof_instance_get_guid(QOF_INSTANCE(cust))), guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term)))); } }
/* build a list of bill terms that are grandchildren or bogus (empty entry list). */ static void billterm_scrub_cb (QofInstance *term_p, gpointer list_p) { GncBillTerm *term = GNC_BILLTERM(term_p); GList **list = list_p; if (billterm_is_grandchild(term)) { *list = g_list_prepend(*list, term); } else if (!gncBillTermGetType(term)) { GncBillTerm *t = gncBillTermGetParent(term); if (t) { /* Fix up the broken "copy" function */ gchar guidstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(term)),guidstr); PWARN("Fixing broken child billterm: %s", guidstr); gncBillTermBeginEdit(term); gncBillTermSetType(term, gncBillTermGetType(t)); gncBillTermSetDueDays (term, gncBillTermGetDueDays(t)); gncBillTermSetDiscountDays (term, gncBillTermGetDiscountDays(t)); gncBillTermSetDiscount (term, gncBillTermGetDiscount(t)); gncBillTermSetCutoff (term, gncBillTermGetCutoff(t)); gncBillTermCommitEdit(term); } else { /* No parent? Must be a standalone */ *list = g_list_prepend(*list, term); } } }
static void billterm_scrub_vendor (QofInstance* vendor_p, gpointer ht_p) { GHashTable* ht = static_cast<decltype (ht)> (ht_p); GncVendor* vendor = GNC_VENDOR (vendor_p); GncBillTerm* term; gint32 count; term = gncVendorGetTerms (vendor); if (term) { count = GPOINTER_TO_INT (g_hash_table_lookup (ht, term)); count++; g_hash_table_insert (ht, term, GINT_TO_POINTER (count)); if (billterm_is_grandchild (term)) { gchar vendstr[GUID_ENCODING_LENGTH + 1]; gchar termstr[GUID_ENCODING_LENGTH + 1]; guid_to_string_buff (qof_instance_get_guid (QOF_INSTANCE (vendor)), vendstr); guid_to_string_buff (qof_instance_get_guid (QOF_INSTANCE (term)), termstr); PWARN ("vendor %s has grandchild billterm %s\n", vendstr, termstr); } } }
static void billterm_scrub_cust (QofInstance* cust_p, gpointer ht_p) { GHashTable* ht = static_cast<decltype (ht)> (ht_p); GncCustomer* cust = GNC_CUSTOMER (cust_p); GncBillTerm* term; gint32 count; term = gncCustomerGetTerms (cust); if (term) { count = GPOINTER_TO_INT (g_hash_table_lookup (ht, term)); count++; g_hash_table_insert (ht, term, GINT_TO_POINTER (count)); if (billterm_is_grandchild (term)) { gchar custstr[GUID_ENCODING_LENGTH + 1]; gchar termstr[GUID_ENCODING_LENGTH + 1]; guid_to_string_buff (qof_instance_get_guid (QOF_INSTANCE (cust)), custstr); guid_to_string_buff (qof_instance_get_guid (QOF_INSTANCE (term)), termstr); PWARN ("customer %s has grandchild billterm %s\n", custstr, termstr); } } }