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; }
void gnc_payment_window_fill_docs_list (PaymentWindow *pw) { GtkListStore *store; GList *list = NULL, *node; g_return_if_fail (pw->docs_list_tree_view && GTK_IS_TREE_VIEW(pw->docs_list_tree_view)); /* Get a list of open lots for this owner and post account */ if (pw->owner.owner.undefined) list = xaccAccountFindOpenLots (pw->post_acct, gncOwnerLotMatchOwnerFunc, &pw->owner, NULL); /* Clear the existing list */ store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(pw->docs_list_tree_view))); gtk_list_store_clear(store); /* Add the documents and overpayments to the tree view */ for (node = list; node; node = node->next) { GNCLot *lot = node->data; time64 doc_date_time = 0; const gchar *doc_type_str = NULL; const gchar *doc_id_str = NULL; const gchar *doc_deb_str = NULL; const gchar *doc_cred_str = NULL; GtkTreeIter iter; Timespec doc_date; GncInvoice *document; gnc_numeric value = gnc_numeric_zero(); gnc_numeric debit = gnc_numeric_zero(); gnc_numeric credit = gnc_numeric_zero(); /* Find the lot's document if it exists, * it could also be a prepayment lot. */ document = gncInvoiceGetInvoiceFromLot (lot); /* Find the document's date or pre-payment date */ if (document) doc_date = gncInvoiceGetDatePosted (document); else { /* Calculate the payment date based on the lot splits */ Transaction *trans = xaccSplitGetParent (gnc_lot_get_latest_split (lot)); if (trans) doc_date = xaccTransRetDatePostedTS (trans); else continue; /* No valid split in this lot, skip it */ } doc_date_time = timespecToTime64 (doc_date); /* Find the document type. No type means pre-payment in this case */ if (document) { doc_type_str = gncInvoiceGetTypeString (document); } else doc_type_str = _("Pre-Payment"); /* Find the document id. Empty for pre-payments. */ if (document) { doc_id_str = gncInvoiceGetID (document); } /* Find the debit/credit amount. * Invoices/vendor credit notes are debit (increasing the balance) * Customer credit notes/bills are credit (decreasing the balance) * Pre-payments are debit or credit depending on their sign */ value = gnc_lot_get_balance (lot); if (gnc_numeric_positive_p (value)) debit = value; else credit = gnc_numeric_neg (value); /* Only display non-zero debits/credits */ if (!gnc_numeric_zero_p (debit)) doc_deb_str = xaccPrintAmount (debit, gnc_default_print_info (FALSE)); if (!gnc_numeric_zero_p (credit)) doc_cred_str = xaccPrintAmount (credit, gnc_default_print_info (FALSE)); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, 0, doc_date_time, 1, doc_id_str, 2, doc_type_str, 3, doc_deb_str, 4, doc_cred_str, 5, (gpointer)lot, -1); } g_list_free (list); /* Highlight the preset invoice if it's in the new list */ gnc_payment_dialog_highlight_document (pw); }