/* 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 = 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 xmlNodePtr invoice_dom_tree_create (GncInvoice* invoice) { xmlNodePtr ret; Timespec ts; Transaction* txn; GNCLot* lot; Account* acc; GncBillTerm* term; GncOwner* billto; gnc_numeric amt; ret = xmlNewNode (NULL, BAD_CAST gnc_invoice_string); xmlSetProp (ret, BAD_CAST "version", BAD_CAST invoice_version_string); xmlAddChild (ret, guid_to_dom_tree (invoice_guid_string, qof_instance_get_guid (QOF_INSTANCE (invoice)))); xmlAddChild (ret, text_to_dom_tree (invoice_id_string, gncInvoiceGetID (invoice))); xmlAddChild (ret, gnc_owner_to_dom_tree (invoice_owner_string, gncInvoiceGetOwner (invoice))); ts = gncInvoiceGetDateOpened (invoice); xmlAddChild (ret, timespec_to_dom_tree (invoice_opened_string, &ts)); maybe_add_timespec (ret, invoice_posted_string, gncInvoiceGetDatePosted (invoice)); term = gncInvoiceGetTerms (invoice); if (term) xmlAddChild (ret, guid_to_dom_tree (invoice_terms_string, qof_instance_get_guid (QOF_INSTANCE (term)))); maybe_add_string (ret, invoice_billing_id_string, gncInvoiceGetBillingID (invoice)); maybe_add_string (ret, invoice_notes_string, gncInvoiceGetNotes (invoice)); xmlAddChild (ret, int_to_dom_tree (invoice_active_string, gncInvoiceGetActive (invoice))); txn = gncInvoiceGetPostedTxn (invoice); if (txn) xmlAddChild (ret, guid_to_dom_tree (invoice_posttxn_string, xaccTransGetGUID (txn))); lot = gncInvoiceGetPostedLot (invoice); if (lot) xmlAddChild (ret, guid_to_dom_tree (invoice_postlot_string, gnc_lot_get_guid (lot))); acc = gncInvoiceGetPostedAcc (invoice); if (acc) xmlAddChild (ret, guid_to_dom_tree (invoice_postacc_string, qof_instance_get_guid (QOF_INSTANCE (acc)))); xmlAddChild (ret, commodity_ref_to_dom_tree (invoice_currency_string, gncInvoiceGetCurrency (invoice))); billto = gncInvoiceGetBillTo (invoice); if (billto && billto->owner.undefined != NULL) xmlAddChild (ret, gnc_owner_to_dom_tree (invoice_billto_string, billto)); amt = gncInvoiceGetToChargeAmount (invoice); if (! gnc_numeric_zero_p (amt)) xmlAddChild (ret, gnc_numeric_to_dom_tree (invoice_tochargeamt_string, &amt)); /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */ xmlAddChild (ret, qof_instance_slots_to_dom_tree (invoice_slots_string, QOF_INSTANCE (invoice))); return ret; }