static xmlNodePtr employee_dom_tree_create (GncEmployee *employee) { xmlNodePtr ret, kvpnode; gnc_numeric num; Account* ccard_acc; ret = xmlNewNode(NULL, BAD_CAST gnc_employee_string); xmlSetProp(ret, BAD_CAST "version", BAD_CAST employee_version_string); xmlAddChild(ret, guid_to_dom_tree(employee_guid_string, qof_instance_get_guid(QOF_INSTANCE (employee)))); xmlAddChild(ret, text_to_dom_tree(employee_username_string, gncEmployeeGetUsername (employee))); xmlAddChild(ret, text_to_dom_tree(employee_id_string, gncEmployeeGetID (employee))); xmlAddChild(ret, gnc_address_to_dom_tree(employee_addr_string, gncEmployeeGetAddr (employee))); maybe_add_string (ret, employee_language_string, gncEmployeeGetLanguage (employee)); maybe_add_string (ret, employee_acl_string, gncEmployeeGetAcl (employee)); xmlAddChild(ret, int_to_dom_tree(employee_active_string, gncEmployeeGetActive (employee))); num = gncEmployeeGetWorkday (employee); xmlAddChild(ret, gnc_numeric_to_dom_tree (employee_workday_string, &num)); num = gncEmployeeGetRate (employee); xmlAddChild(ret, gnc_numeric_to_dom_tree (employee_rate_string, &num)); xmlAddChild (ret, commodity_ref_to_dom_tree(employee_currency_string, gncEmployeeGetCurrency (employee))); ccard_acc = gncEmployeeGetCCard (employee); if (ccard_acc) xmlAddChild(ret, guid_to_dom_tree(employee_ccard_string, qof_instance_get_guid(QOF_INSTANCE(ccard_acc)))); kvpnode = kvp_frame_to_dom_tree (employee_slots_string, qof_instance_get_slots (QOF_INSTANCE(employee))); if (kvpnode) xmlAddChild (ret, kvpnode); return ret; }
static xmlNodePtr gnc_price_to_dom_tree(const xmlChar *tag, GNCPrice *price) { xmlNodePtr price_xml; const gchar *typestr, *sourcestr; xmlNodePtr tmpnode; gnc_commodity *commodity; gnc_commodity *currency; Timespec timesp; gnc_numeric value; if (!(tag && price)) return NULL; price_xml = xmlNewNode(NULL, tag); if (!price_xml) return NULL; commodity = gnc_price_get_commodity(price); currency = gnc_price_get_currency(price); if (!(commodity && currency)) return NULL; tmpnode = guid_to_dom_tree("price:id", gnc_price_get_guid(price)); if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL; tmpnode = commodity_ref_to_dom_tree("price:commodity", commodity); if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL; tmpnode = commodity_ref_to_dom_tree("price:currency", currency); if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL; timesp = gnc_price_get_time(price); tmpnode = timespec_to_dom_tree("price:time", ×p); if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL; sourcestr = gnc_price_get_source(price); if (sourcestr && (strlen(sourcestr) != 0)) { tmpnode = text_to_dom_tree("price:source", sourcestr); if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL; } typestr = gnc_price_get_typestr(price); if (typestr && (strlen(typestr) != 0)) { tmpnode = text_to_dom_tree("price:type", typestr); if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL; } value = gnc_price_get_value(price); tmpnode = gnc_numeric_to_dom_tree("price:value", &value); if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL; return price_xml; }
static gchar * test_gnc_nums_internal(gnc_numeric to_test) { gchar *ret = NULL; gnc_numeric *to_compare = NULL; xmlNodePtr to_gen = NULL; to_gen = gnc_numeric_to_dom_tree("test-num", &to_test); if (!to_gen) { ret = "no dom tree created"; } else { to_compare = dom_tree_to_gnc_numeric(to_gen); if (!to_compare) { ret = "no gnc_numeric parsed"; } else { if (!gnc_numeric_equal(to_test, *to_compare)) { ret = "numerics compared different"; } } } if (to_compare) { g_free(to_compare); } if (to_gen) { xmlFreeNode(to_gen); } return ret; }
static xmlNodePtr ttentry_dom_tree_create (GncTaxTableEntry *entry) { xmlNodePtr ret; Account *account; gnc_numeric amount; ret = xmlNewNode(NULL, BAD_CAST gnc_taxtableentry_string); account = gncTaxTableEntryGetAccount (entry); if (account) xmlAddChild(ret, guid_to_dom_tree (ttentry_account_string, qof_instance_get_guid (QOF_INSTANCE(account)))); amount = gncTaxTableEntryGetAmount (entry); xmlAddChild (ret, gnc_numeric_to_dom_tree (ttentry_amount_string, &amount)); xmlAddChild(ret, text_to_dom_tree (ttentry_type_string, gncAmountTypeToString ( gncTaxTableEntryGetType (entry)))); return ret; }
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; }
static void maybe_add_numeric (xmlNodePtr ptr, const char *tag, gnc_numeric num) { if (!gnc_numeric_zero_p (num)) xmlAddChild (ptr, gnc_numeric_to_dom_tree (tag, &num)); }
static xmlNodePtr customer_dom_tree_create (GncCustomer *cust) { xmlNodePtr ret, kvpnode; gnc_numeric num; GncBillTerm *term; GncTaxTable *taxtable; ret = xmlNewNode(NULL, BAD_CAST gnc_customer_string); xmlSetProp(ret, BAD_CAST "version", BAD_CAST customer_version_string); xmlAddChild(ret, guid_to_dom_tree(cust_guid_string, qof_instance_get_guid(QOF_INSTANCE(cust)))); xmlAddChild(ret, text_to_dom_tree(cust_name_string, gncCustomerGetName (cust))); xmlAddChild(ret, text_to_dom_tree(cust_id_string, gncCustomerGetID (cust))); xmlAddChild(ret, gnc_address_to_dom_tree(cust_addr_string, gncCustomerGetAddr (cust))); xmlAddChild(ret, gnc_address_to_dom_tree(cust_shipaddr_string, gncCustomerGetShipAddr (cust))); maybe_add_string (ret, cust_notes_string, gncCustomerGetNotes (cust)); term = gncCustomerGetTerms (cust); if (term) xmlAddChild(ret, guid_to_dom_tree(cust_terms_string, qof_instance_get_guid (QOF_INSTANCE(term)))); xmlAddChild(ret, text_to_dom_tree(cust_taxincluded_string, gncTaxIncludedTypeToString ( gncCustomerGetTaxIncluded (cust)))); xmlAddChild(ret, int_to_dom_tree(cust_active_string, gncCustomerGetActive (cust))); num = gncCustomerGetDiscount (cust); xmlAddChild(ret, gnc_numeric_to_dom_tree(cust_discount_string, &num)); num = gncCustomerGetCredit (cust); xmlAddChild(ret, gnc_numeric_to_dom_tree(cust_credit_string, &num)); xmlAddChild (ret, commodity_ref_to_dom_tree(cust_currency_string, gncCustomerGetCurrency (cust))); xmlAddChild (ret, int_to_dom_tree (cust_taxtableoverride_string, gncCustomerGetTaxTableOverride (cust))); taxtable = gncCustomerGetTaxTable (cust); if (taxtable) xmlAddChild (ret, guid_to_dom_tree (cust_taxtable_string, qof_instance_get_guid(QOF_INSTANCE(taxtable)))); kvpnode = kvp_frame_to_dom_tree (cust_slots_string, qof_instance_get_slots (QOF_INSTANCE(cust))); if (kvpnode) xmlAddChild (ret, kvpnode); return ret; }
static void add_gnc_num(xmlNodePtr node, const gchar *tag, gnc_numeric num) { xmlAddChild(node, gnc_numeric_to_dom_tree(tag, &num)); }