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", &timesp);
    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;
}
Exemplo n.º 2
0
static void
test_dom_tree_to_commodity_ref(void)
{
    int i;
    for (i = 0; i < 20; i++)
    {
        gnc_commodity *test_com1;
        gchar *test_str1;
        gchar *test_str2;
        gnc_commodity *test_com2;
        xmlNodePtr test_node;
        QofBook *book;

        book = qof_book_new ();

        test_str1 = get_random_string();
        test_str2 = get_random_string();

        test_com1 = gnc_commodity_new(book, NULL, test_str1, test_str2, NULL, 0);
        test_node = commodity_ref_to_dom_tree("test-com", test_com1);

        test_com2 = dom_tree_to_commodity_ref_no_engine(test_node, book);

        do_test(gnc_commodity_equiv(test_com1, test_com2),
                "dom_tree_to_commodity_ref_no_engine");

        xmlFreeNode(test_node);
        gnc_commodity_destroy(test_com1);
        gnc_commodity_destroy(test_com2);
        g_free(test_str1);
        g_free(test_str2);

        qof_book_destroy (book);
    }
}
Exemplo n.º 3
0
static xmlNodePtr
vendor_dom_tree_create (GncVendor* vendor)
{
    xmlNodePtr ret;
    GncBillTerm* term;
    GncTaxTable* taxtable;

    ret = xmlNewNode (NULL, BAD_CAST gnc_vendor_string);
    xmlSetProp (ret, BAD_CAST "version", BAD_CAST vendor_version_string);

    xmlAddChild (ret, guid_to_dom_tree (vendor_guid_string,
                                        qof_instance_get_guid (QOF_INSTANCE (vendor))));

    xmlAddChild (ret, text_to_dom_tree (vendor_name_string,
                                        gncVendorGetName (vendor)));

    xmlAddChild (ret, text_to_dom_tree (vendor_id_string,
                                        gncVendorGetID (vendor)));

    xmlAddChild (ret, gnc_address_to_dom_tree (vendor_addr_string,
                                               gncVendorGetAddr (vendor)));

    maybe_add_string (ret, vendor_notes_string, gncVendorGetNotes (vendor));

    term = gncVendorGetTerms (vendor);
    if (term)
        xmlAddChild (ret, guid_to_dom_tree (vendor_terms_string,
                                            qof_instance_get_guid (QOF_INSTANCE (term))));

    xmlAddChild (ret, text_to_dom_tree (vendor_taxincluded_string,
                                        gncTaxIncludedTypeToString (
                                            gncVendorGetTaxIncluded (vendor))));

    xmlAddChild (ret, int_to_dom_tree (vendor_active_string,
                                       gncVendorGetActive (vendor)));

    xmlAddChild
    (ret,
     commodity_ref_to_dom_tree (vendor_currency_string,
                                gncVendorGetCurrency (vendor)));

    xmlAddChild (ret, int_to_dom_tree (vendor_taxtableoverride_string,
                                       gncVendorGetTaxTableOverride (vendor)));
    taxtable = gncVendorGetTaxTable (vendor);
    if (taxtable)
        xmlAddChild (ret, guid_to_dom_tree (vendor_taxtable_string,
                                            qof_instance_get_guid (QOF_INSTANCE (taxtable))));

    /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
    xmlAddChild (ret, qof_instance_slots_to_dom_tree (vendor_slots_string,
                                                      QOF_INSTANCE (vendor)));
    return ret;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
xmlNodePtr
gnc_transaction_dom_tree_create(Transaction *trn)
{
    xmlNodePtr ret;
    gchar *str = NULL;

    ret = xmlNewNode(NULL, BAD_CAST "gnc:transaction");

    xmlSetProp(ret, BAD_CAST "version",
	       BAD_CAST transaction_version_string);

    xmlAddChild(ret, guid_to_dom_tree("trn:id", xaccTransGetGUID(trn)));

    xmlAddChild(ret, commodity_ref_to_dom_tree("trn:currency",
                xaccTransGetCurrency(trn)));
    str = g_strdup (xaccTransGetNum(trn));
    if (str && (g_strcmp0(str, "") != 0))
    {
        xmlNewTextChild(ret, NULL, BAD_CAST "trn:num",
			checked_char_cast (str));
    }
    g_free (str);

    add_timespec(ret, "trn:date-posted", xaccTransRetDatePostedTS(trn), TRUE);

    add_timespec(ret, "trn:date-entered",
                 xaccTransRetDateEnteredTS(trn), TRUE);

    str = g_strdup (xaccTransGetDescription(trn));
    if (str)
    {
        xmlNewTextChild(ret, NULL, BAD_CAST "trn:description",
                        checked_char_cast (str));
    }
    g_free (str);

    {
        xmlNodePtr kvpnode = kvp_frame_to_dom_tree("trn:slots",
                             xaccTransGetSlots(trn));
        if (kvpnode)
        {
            xmlAddChild(ret, kvpnode);
        }
    }

    add_trans_splits(ret, trn);

    return ret;
}
xmlNodePtr
gnc_transaction_dom_tree_create (Transaction* trn)
{
    xmlNodePtr ret;
    gchar* str = NULL;

    ret = xmlNewNode (NULL, BAD_CAST "gnc:transaction");

    xmlSetProp (ret, BAD_CAST "version",
                BAD_CAST transaction_version_string);

    xmlAddChild (ret, guid_to_dom_tree ("trn:id", xaccTransGetGUID (trn)));

    xmlAddChild (ret, commodity_ref_to_dom_tree ("trn:currency",
                                                 xaccTransGetCurrency (trn)));
    str = g_strdup (xaccTransGetNum (trn));
    if (str && (g_strcmp0 (str, "") != 0))
    {
        xmlNewTextChild (ret, NULL, BAD_CAST "trn:num",
                         checked_char_cast (str));
    }
    g_free (str);

    add_timespec (ret, "trn:date-posted", xaccTransRetDatePostedTS (trn), TRUE);

    add_timespec (ret, "trn:date-entered",
                  xaccTransRetDateEnteredTS (trn), TRUE);

    str = g_strdup (xaccTransGetDescription (trn));
    if (str)
    {
        xmlNewTextChild (ret, NULL, BAD_CAST "trn:description",
                         checked_char_cast (str));
    }
    g_free (str);

    /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
    xmlAddChild (ret, qof_instance_slots_to_dom_tree ("trn:slots",
                                                      QOF_INSTANCE (trn)));

    add_trans_splits (ret, trn);

    return ret;
}
Exemplo n.º 7
0
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;
}
Exemplo n.º 8
0
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;
}