static xmlNodePtr
billterm_dom_tree_create (GncBillTerm *term)
{
    xmlNodePtr ret, data, kvpnode;

    ret = xmlNewNode(NULL, BAD_CAST gnc_billterm_string);
    xmlSetProp(ret, BAD_CAST "version", BAD_CAST billterm_version_string);

    maybe_add_guid(ret, billterm_guid_string, QOF_INSTANCE(term));
    xmlAddChild(ret, text_to_dom_tree (billterm_name_string,
                                       gncBillTermGetName (term)));
    xmlAddChild(ret, text_to_dom_tree (billterm_desc_string,
                                       gncBillTermGetDescription (term)));

    xmlAddChild(ret, int_to_dom_tree (billterm_refcount_string,
                                      gncBillTermGetRefcount (term)));
    xmlAddChild(ret, int_to_dom_tree (billterm_invisible_string,
                                      gncBillTermGetInvisible (term)));

    kvpnode = kvp_frame_to_dom_tree (billterm_slots_string,
                                     qof_instance_get_slots (QOF_INSTANCE(term)));
    if (kvpnode) xmlAddChild (ret, kvpnode);


    /* We should not be our own child */
    if (gncBillTermGetChild(term) != term)
        maybe_add_guid(ret, billterm_child_string,
                       QOF_INSTANCE(gncBillTermGetChild (term)));

    maybe_add_guid(ret, billterm_parent_string,
                   QOF_INSTANCE(gncBillTermGetParent (term)));

    switch (gncBillTermGetType (term))
    {
    case GNC_TERM_TYPE_DAYS:
        data = xmlNewChild (ret, NULL, BAD_CAST gnc_daystype_string, NULL);
        maybe_add_int (data, days_duedays_string, gncBillTermGetDueDays (term));
        maybe_add_int (data, days_discdays_string,
                       gncBillTermGetDiscountDays (term));
        maybe_add_numeric (data, days_discount_string,
                           gncBillTermGetDiscount (term));
        break;

    case GNC_TERM_TYPE_PROXIMO:
        data = xmlNewChild (ret, NULL, BAD_CAST gnc_proximotype_string, NULL);
        maybe_add_int (data, prox_dueday_string, gncBillTermGetDueDays (term));
        maybe_add_int (data, prox_discday_string,
                       gncBillTermGetDiscountDays (term));
        maybe_add_numeric (data, prox_discount_string,
                           gncBillTermGetDiscount (term));
        maybe_add_int (data, prox_cutoff_string, gncBillTermGetCutoff (term));
        break;
    }

    return ret;
}
Exemple #2
0
static xmlNodePtr
entry_dom_tree_create (GncEntry *entry)
{
    xmlNodePtr ret;
    Timespec ts;
    Account *acc;
    GncTaxTable *taxtable;
    GncOrder *order;
    GncInvoice *invoice;
    kvp_frame *kf;

    ret = xmlNewNode(NULL, BAD_CAST gnc_entry_string);
    xmlSetProp(ret, BAD_CAST "version", BAD_CAST entry_version_string);

    xmlAddChild(ret, guid_to_dom_tree(entry_guid_string,
                                      qof_instance_get_guid(QOF_INSTANCE(entry))));

    ts = gncEntryGetDate (entry);
    xmlAddChild(ret, timespec_to_dom_tree (entry_date_string, &ts));

    ts = gncEntryGetDateEntered (entry);
    xmlAddChild(ret, timespec_to_dom_tree (entry_dateentered_string, &ts));

    maybe_add_string (ret, entry_description_string,
                      gncEntryGetDescription (entry));
    maybe_add_string (ret, entry_action_string, gncEntryGetAction (entry));
    maybe_add_string (ret, entry_notes_string, gncEntryGetNotes (entry));

    maybe_add_numeric (ret, entry_qty_string, gncEntryGetQuantity (entry));

    /* cust invoice */

    acc = gncEntryGetInvAccount (entry);
    if (acc)
        xmlAddChild (ret, guid_to_dom_tree (entry_invacct_string,
                                            qof_instance_get_guid(QOF_INSTANCE(acc))));

    maybe_add_numeric (ret, entry_iprice_string, gncEntryGetInvPrice (entry));

    maybe_add_numeric (ret, entry_idiscount_string, gncEntryGetInvDiscount (entry));

    invoice = gncEntryGetInvoice (entry);
    if (invoice)
    {
        xmlAddChild (ret, guid_to_dom_tree (entry_invoice_string,
                                            qof_instance_get_guid(QOF_INSTANCE(invoice))));

        xmlAddChild(ret, text_to_dom_tree(entry_idisctype_string,
                                          gncAmountTypeToString (
                                              gncEntryGetInvDiscountType (entry))));
        xmlAddChild(ret, text_to_dom_tree(entry_idischow_string,
                                          gncEntryDiscountHowToString (
                                              gncEntryGetInvDiscountHow (entry))));

        xmlAddChild(ret, int_to_dom_tree(entry_itaxable_string,
                                         gncEntryGetInvTaxable (entry)));
        xmlAddChild(ret, int_to_dom_tree(entry_itaxincluded_string,
                                         gncEntryGetInvTaxIncluded (entry)));
    }

    taxtable = gncEntryGetInvTaxTable (entry);
    if (taxtable)
        xmlAddChild (ret, guid_to_dom_tree (entry_itaxtable_string,
                                            qof_instance_get_guid (QOF_INSTANCE(taxtable))));

    /* vendor bills */

    acc = gncEntryGetBillAccount (entry);
    if (acc)
        xmlAddChild (ret, guid_to_dom_tree (entry_billacct_string,
                                            qof_instance_get_guid (QOF_INSTANCE(acc))));

    maybe_add_numeric (ret, entry_bprice_string, gncEntryGetBillPrice (entry));

    invoice = gncEntryGetBill (entry);
    if (invoice)
    {
        GncOwner *owner;
        xmlAddChild (ret, guid_to_dom_tree (entry_bill_string,
                                            qof_instance_get_guid(QOF_INSTANCE(invoice))));
        xmlAddChild(ret, int_to_dom_tree(entry_billable_string,
                                         gncEntryGetBillable (entry)));
        owner = gncEntryGetBillTo (entry);
        if (owner && owner->owner.undefined != NULL)
            xmlAddChild (ret, gnc_owner_to_dom_tree (entry_billto_string, owner));

        xmlAddChild(ret, int_to_dom_tree(entry_btaxable_string,
                                         gncEntryGetBillTaxable (entry)));
        xmlAddChild(ret, int_to_dom_tree(entry_btaxincluded_string,
                                         gncEntryGetBillTaxIncluded (entry)));
        maybe_add_string (ret, entry_billpayment_string,
                          gncEntryPaymentTypeToString (gncEntryGetBillPayment (entry)));
    }

    taxtable = gncEntryGetBillTaxTable (entry);
    if (taxtable)
        xmlAddChild (ret, guid_to_dom_tree (entry_btaxtable_string,
                                            qof_instance_get_guid (QOF_INSTANCE(taxtable))));

    /* Other stuff */

    order = gncEntryGetOrder (entry);
    if (order)
        xmlAddChild (ret, guid_to_dom_tree (entry_order_string,
                                            qof_instance_get_guid(QOF_INSTANCE (order))));

    kf = qof_instance_get_slots (QOF_INSTANCE(entry));
    if (kf)
    {
        xmlNodePtr kvpnode = kvp_frame_to_dom_tree(entry_slots_string, kf);
        if (kvpnode)
        {
            xmlAddChild(ret, kvpnode);
        }
    }

    return ret;
}