30 #include "gnc-xml-helper.h"
33 #include "sixtp-utils.h"
34 #include "sixtp-parsers.h"
35 #include "sixtp-utils.h"
36 #include "sixtp-dom-parsers.h"
37 #include "sixtp-dom-generators.h"
41 #include "io-gncxml-gen.h"
43 #include "sixtp-dom-parsers.h"
46 #include "TransactionP.h"
48 #include "gnc-lot-p.h"
50 const gchar *transaction_version_string =
"2.0.0";
56 add_gnc_num(xmlNodePtr node,
const gchar *tag,
gnc_numeric num)
58 xmlAddChild(node, gnc_numeric_to_dom_tree(tag, &num));
62 add_timespec(xmlNodePtr node,
const gchar *tag,
Timespec tms, gboolean always)
64 if (always || !((tms.tv_sec == 0) && (tms.tv_nsec == 0)))
66 xmlAddChild(node, timespec_to_dom_tree(tag, &tms));
71 split_to_dom_tree(
const gchar *tag,
Split *spl)
75 ret = xmlNewNode(NULL, BAD_CAST tag);
82 if (memo && g_strcmp0(memo,
"") != 0)
84 xmlNewTextChild(ret, NULL, BAD_CAST
"split:memo",
85 checked_char_cast (memo));
93 if (action && g_strcmp0(action,
"") != 0)
95 xmlNewTextChild(ret, NULL, BAD_CAST
"split:action",
96 checked_char_cast (action));
107 xmlNewTextChild(ret, NULL, BAD_CAST
"split:reconciled-state",
111 add_timespec(ret,
"split:reconcile-date",
121 xmlAddChild (ret, guid_to_dom_tree(
"split:account",
129 xmlAddChild (ret, guid_to_dom_tree(
"split:lot",
130 gnc_lot_get_guid(lot)));
134 xmlNodePtr kvpnode = kvp_frame_to_dom_tree(
"split:slots",
135 qof_instance_get_slots (QOF_INSTANCE (spl)));
138 xmlAddChild(ret, kvpnode);
146 add_trans_splits(xmlNodePtr node,
Transaction *trn)
151 toaddto = xmlNewChild(node, NULL, BAD_CAST
"trn:splits", NULL);
156 xmlAddChild(toaddto, split_to_dom_tree(
"trn:split", s));
166 ret = xmlNewNode(NULL, BAD_CAST
"gnc:transaction");
168 xmlSetProp(ret, BAD_CAST
"version",
169 BAD_CAST transaction_version_string);
173 xmlAddChild(ret, commodity_ref_to_dom_tree(
"trn:currency",
176 if (str && (g_strcmp0(str,
"") != 0))
178 xmlNewTextChild(ret, NULL, BAD_CAST
"trn:num",
179 checked_char_cast (str));
185 add_timespec(ret,
"trn:date-entered",
191 xmlNewTextChild(ret, NULL, BAD_CAST
"trn:description",
192 checked_char_cast (str));
197 xmlNodePtr kvpnode = kvp_frame_to_dom_tree(
"trn:slots",
198 qof_instance_get_slots (QOF_INSTANCE (trn)));
201 xmlAddChild(ret, kvpnode);
205 add_trans_splits(ret, trn);
218 static inline gboolean
219 set_spl_string(xmlNodePtr node,
Split *spl,
220 void (*func)(
Split *spl,
const char *txt))
222 gchar *tmp = dom_tree_to_text(node);
223 g_return_val_if_fail(tmp, FALSE);
232 static inline gboolean
233 set_spl_gnc_num(xmlNodePtr node,
Split* spl,
237 g_return_val_if_fail(num, FALSE);
247 spl_id_handler(xmlNodePtr node, gpointer data)
250 GncGUID *tmp = dom_tree_to_guid(node);
251 g_return_val_if_fail(tmp, FALSE);
253 xaccSplitSetGUID(pdata->split, tmp);
260 spl_memo_handler(xmlNodePtr node, gpointer data)
267 spl_action_handler(xmlNodePtr node, gpointer data)
274 spl_reconciled_state_handler(xmlNodePtr node, gpointer data)
277 gchar *tmp = dom_tree_to_text(node);
278 g_return_val_if_fail(tmp, FALSE);
288 spl_reconcile_date_handler(xmlNodePtr node, gpointer data)
293 ts = dom_tree_to_timespec(node);
294 if (!dom_tree_valid_timespec(&ts, node->name))
return FALSE;
302 spl_value_handler(xmlNodePtr node, gpointer data)
309 spl_quantity_handler(xmlNodePtr node, gpointer data)
315 gboolean gnc_transaction_xml_v2_testing = FALSE;
318 spl_account_handler(xmlNodePtr node, gpointer data)
321 GncGUID *
id = dom_tree_to_guid(node);
324 g_return_val_if_fail(
id, FALSE);
327 if (!account && gnc_transaction_xml_v2_testing &&
331 xaccAccountSetGUID (account,
id);
344 spl_lot_handler(xmlNodePtr node, gpointer data)
347 GncGUID *
id = dom_tree_to_guid(node);
350 g_return_val_if_fail(
id, FALSE);
352 lot = gnc_lot_lookup (
id, pdata->book);
353 if (!lot && gnc_transaction_xml_v2_testing &&
356 lot = gnc_lot_new (pdata->book);
357 gnc_lot_set_guid (lot, *
id);
368 spl_slots_handler(xmlNodePtr node, gpointer data)
373 successful = dom_tree_to_kvp_frame_given(node,
374 qof_instance_get_slots (QOF_INSTANCE (pdata->split)));
375 g_return_val_if_fail(successful, FALSE);
382 {
"split:id", spl_id_handler, 1, 0 },
383 {
"split:memo", spl_memo_handler, 0, 0 },
384 {
"split:action", spl_action_handler, 0, 0 },
385 {
"split:reconciled-state", spl_reconciled_state_handler, 1, 0 },
386 {
"split:reconcile-date", spl_reconcile_date_handler, 0, 0 },
387 {
"split:value", spl_value_handler, 1, 0 },
388 {
"split:quantity", spl_quantity_handler, 1, 0 },
389 {
"split:account", spl_account_handler, 1, 0 },
390 {
"split:lot", spl_lot_handler, 0, 0 },
391 {
"split:slots", spl_slots_handler, 0, 0 },
392 { NULL, NULL, 0, 0 },
396 dom_tree_to_split(xmlNodePtr node,
QofBook *book)
401 g_return_val_if_fail (book, NULL);
404 g_return_val_if_fail(ret, NULL);
410 if (dom_tree_generic_parse(node, spl_dom_handlers, &pdata))
429 static inline gboolean
435 tmp = dom_tree_to_text(node);
437 g_return_val_if_fail(tmp, FALSE);
446 static inline gboolean
452 tm = dom_tree_to_timespec(node);
454 if (!dom_tree_valid_timespec(&tm, node->name))
return FALSE;
462 trn_id_handler(xmlNodePtr node, gpointer
trans_pdata)
464 struct trans_pdata *pdata = trans_pdata;
466 GncGUID *tmp = dom_tree_to_guid(node);
468 g_return_val_if_fail(tmp, FALSE);
478 trn_currency_handler(xmlNodePtr node, gpointer trans_pdata)
480 struct trans_pdata *pdata = trans_pdata;
484 ref = dom_tree_to_commodity_ref(node, pdata->book);
491 trn_num_handler(xmlNodePtr node, gpointer trans_pdata)
493 struct trans_pdata *pdata = trans_pdata;
500 trn_date_posted_handler(xmlNodePtr node, gpointer trans_pdata)
502 struct trans_pdata *pdata = trans_pdata;
509 trn_date_entered_handler(xmlNodePtr node, gpointer trans_pdata)
511 struct trans_pdata *pdata = trans_pdata;
518 trn_description_handler(xmlNodePtr node, gpointer trans_pdata)
520 struct trans_pdata *pdata = trans_pdata;
527 trn_slots_handler(xmlNodePtr node, gpointer trans_pdata)
529 struct trans_pdata *pdata = trans_pdata;
533 successful = dom_tree_to_kvp_frame_given(node, qof_instance_get_slots (QOF_INSTANCE (trn)));
535 g_return_val_if_fail(successful, FALSE);
541 trn_splits_handler(xmlNodePtr node, gpointer trans_pdata)
543 struct trans_pdata *pdata = trans_pdata;
547 g_return_val_if_fail(node, FALSE);
548 g_return_val_if_fail(node->xmlChildrenNode, FALSE);
550 for (mark = node->xmlChildrenNode; mark; mark = mark->next)
554 if (g_strcmp0(
"text", (
char*)mark->name) == 0)
557 if (g_strcmp0(
"trn:split", (
char*)mark->name))
562 spl = dom_tree_to_split(mark, pdata->book);
578 {
"trn:id", trn_id_handler, 1, 0 },
579 {
"trn:currency", trn_currency_handler, 0, 0},
580 {
"trn:num", trn_num_handler, 0, 0 },
581 {
"trn:date-posted", trn_date_posted_handler, 1, 0 },
582 {
"trn:date-entered", trn_date_entered_handler, 1, 0 },
583 {
"trn:description", trn_description_handler, 0, 0 },
584 {
"trn:slots", trn_slots_handler, 0, 0 },
585 {
"trn:splits", trn_splits_handler, 1, 0 },
586 { NULL, NULL, 0, 0 },
590 gnc_transaction_end_handler(gpointer data_for_children,
591 GSList* data_from_children, GSList* sibling_data,
592 gpointer parent_data, gpointer global_data,
593 gpointer *result,
const gchar *tag)
596 xmlNodePtr tree = (xmlNodePtr)data_for_children;
611 g_return_val_if_fail(tree, FALSE);
613 trn = dom_tree_to_transaction(tree, gdata->bookdata);
616 gdata->cb(tag, gdata->parsedata, trn);
625 dom_tree_to_transaction( xmlNodePtr node,
QofBook *book )
629 struct trans_pdata pdata;
631 g_return_val_if_fail(node, NULL);
632 g_return_val_if_fail(book, NULL);
635 g_return_val_if_fail(trn, NULL);
641 successful = dom_tree_generic_parse(node, trn_dom_handlers, &pdata);
647 xmlElemDump(stdout, NULL, node);
658 gnc_transaction_sixtp_parser_create(
void)
660 return sixtp_dom_parser_new(gnc_transaction_end_handler, NULL, NULL);
void xaccSplitSetValue(Split *s, gnc_numeric amt)
#define xaccTransAppendSplit(t, s)
Transaction * xaccMallocTransaction(QofBook *book)
void xaccSplitSetAction(Split *split, const char *actn)
gboolean xaccSplitDestroy(Split *split)
Timespec xaccSplitRetDateReconciledTS(const Split *split)
char xaccSplitGetReconcile(const Split *split)
void gnc_lot_add_split(GNCLot *lot, Split *split)
void xaccTransSetDescription(Transaction *trans, const char *desc)
void xaccTransSetNum(Transaction *trans, const char *xnum)
Use a 64-bit unsigned int timespec.
void xaccSplitSetReconcile(Split *split, char recn)
const char * xaccTransGetNum(const Transaction *trans)
void xaccTransSetDateEnteredTS(Transaction *trans, const Timespec *ts)
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
void xaccTransDestroy(Transaction *trans)
#define xaccAccountGetGUID(X)
void xaccSplitSetAmount(Split *s, gnc_numeric amt)
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
void xaccSplitSetMemo(Split *split, const char *memo)
Timespec xaccTransRetDateEnteredTS(const Transaction *trans)
const char * xaccTransGetDescription(const Transaction *trans)
void xaccTransCommitEdit(Transaction *trans)
#define xaccSplitGetGUID(X)
void xaccTransBeginEdit(Transaction *trans)
void xaccAccountSetCommoditySCU(Account *acc, int scu)
Split * xaccMallocSplit(QofBook *book)
#define xaccTransGetGUID(X)
gnc_numeric xaccSplitGetValue(const Split *split)
Account * xaccSplitGetAccount(const Split *s)
const GncGUID * guid_null(void)
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
#define xaccAccountInsertSplit(acc, s)
struct KvpFrameImpl KvpFrame
Timespec xaccTransRetDatePostedTS(const Transaction *trans)
Account * xaccMallocAccount(QofBook *book)
void xaccSplitSetDateReconciledTS(Split *split, Timespec *ts)
const char * xaccSplitGetMemo(const Split *split)
const char * xaccSplitGetAction(const Split *split)
API for Transactions and Splits (journal entries)
SplitList * xaccTransGetSplitList(const Transaction *trans)
GNCLot * xaccSplitGetLot(const Split *split)
void xaccTransSetDatePostedTS(Transaction *trans, const Timespec *ts)
gnc_numeric xaccSplitGetAmount(const Split *split)
Account * xaccAccountLookup(const GncGUID *guid, QofBook *book)