30 #include "TransactionP.hpp" 32 #include "gnc-lot-p.h" 34 #include "gnc-xml-helper.h" 37 #include "sixtp-utils.h" 38 #include "sixtp-parsers.h" 39 #include "sixtp-utils.h" 40 #include "sixtp-dom-parsers.h" 41 #include "sixtp-dom-generators.h" 45 #include "io-gncxml-gen.h" 47 #include "sixtp-dom-parsers.h" 49 [[maybe_unused]]
static const QofLogModule log_module =
G_LOG_DOMAIN;
50 const gchar* transaction_version_string =
"2.0.0";
53 add_gnc_num (xmlNodePtr node,
const gchar* tag, gnc_numeric num)
55 xmlAddChild (node, gnc_numeric_to_dom_tree (tag, &num));
59 add_time64 (xmlNodePtr node,
const gchar * tag,
time64 time, gboolean always)
62 xmlAddChild (node, time64_to_dom_tree (tag, time));
66 split_to_dom_tree (
const gchar* tag, Split* spl)
70 ret = xmlNewNode (NULL, BAD_CAST tag);
77 if (memo && g_strcmp0 (memo,
"") != 0)
79 xmlNewTextChild (ret, NULL, BAD_CAST
"split:memo",
80 checked_char_cast (memo));
88 if (action && g_strcmp0 (action,
"") != 0)
90 xmlNewTextChild (ret, NULL, BAD_CAST
"split:action",
91 checked_char_cast (action));
102 xmlNewTextChild (ret, NULL, BAD_CAST
"split:reconciled-state",
106 add_time64 (ret,
"split:reconcile-date",
116 xmlAddChild (ret, guid_to_dom_tree (
"split:account",
124 xmlAddChild (ret, guid_to_dom_tree (
"split:lot",
125 gnc_lot_get_guid (lot)));
129 xmlAddChild (ret, qof_instance_slots_to_dom_tree (
"split:slots",
130 QOF_INSTANCE (spl)));
135 add_trans_splits (xmlNodePtr node, Transaction* trn)
140 toaddto = xmlNewChild (node, NULL, BAD_CAST
"trn:splits", NULL);
144 Split* s =
static_cast<decltype (s)
> (n->data);
145 xmlAddChild (toaddto, split_to_dom_tree (
"trn:split", s));
150 gnc_transaction_dom_tree_create (Transaction* trn)
155 ret = xmlNewNode (NULL, BAD_CAST
"gnc:transaction");
157 xmlSetProp (ret, BAD_CAST
"version",
158 BAD_CAST transaction_version_string);
162 xmlAddChild (ret, commodity_ref_to_dom_tree (
"trn:currency",
165 if (str && (g_strcmp0 (str,
"") != 0))
167 xmlNewTextChild (ret, NULL, BAD_CAST
"trn:num",
168 checked_char_cast (str));
174 add_time64 (ret,
"trn:date-entered",
180 xmlNewTextChild (ret, NULL, BAD_CAST
"trn:description",
181 checked_char_cast (str));
186 xmlAddChild (ret, qof_instance_slots_to_dom_tree (
"trn:slots",
187 QOF_INSTANCE (trn)));
189 add_trans_splits (ret, trn);
202 static inline gboolean
203 set_spl_gnc_num (xmlNodePtr node, Split* spl,
204 void (*func) (Split* spl, gnc_numeric gn))
206 func (spl, dom_tree_to_gnc_numeric (node));
211 spl_id_handler (xmlNodePtr node, gpointer data)
213 struct split_pdata* pdata =
static_cast<decltype (pdata)
> (data);
214 auto tmp = dom_tree_to_guid (node);
215 g_return_val_if_fail (tmp, FALSE);
217 xaccSplitSetGUID (pdata->split, &*tmp);
223 spl_memo_handler (xmlNodePtr node, gpointer data)
225 struct split_pdata* pdata =
static_cast<decltype (pdata)
> (data);
230 spl_action_handler (xmlNodePtr node, gpointer data)
232 struct split_pdata* pdata =
static_cast<decltype (pdata)
> (data);
237 spl_reconciled_state_handler (xmlNodePtr node, gpointer data)
239 struct split_pdata* pdata =
static_cast<decltype (pdata)
> (data);
240 auto set_reconciled = [](Split* s,
const char *txt)
244 return apply_xmlnode_text (set_reconciled, pdata->split, node);
248 spl_reconcile_date_handler (xmlNodePtr node, gpointer data)
250 struct split_pdata* pdata =
static_cast<decltype (pdata)
> (data);
251 time64 time = dom_tree_to_time64 (node);
252 if (!dom_tree_valid_time64 (time, node->name)) time = 0;
258 spl_value_handler (xmlNodePtr node, gpointer data)
260 struct split_pdata* pdata =
static_cast<decltype (pdata)
> (data);
265 spl_quantity_handler (xmlNodePtr node, gpointer data)
267 struct split_pdata* pdata =
static_cast<decltype (pdata)
> (data);
271 gboolean gnc_transaction_xml_v2_testing = FALSE;
274 spl_account_handler (xmlNodePtr node, gpointer data)
276 struct split_pdata* pdata =
static_cast<decltype (pdata)
> (data);
277 auto id = dom_tree_to_guid (node);
280 g_return_val_if_fail (
id, FALSE);
283 if (!account && gnc_transaction_xml_v2_testing &&
287 xaccAccountSetGUID (account, &*
id);
298 spl_lot_handler (xmlNodePtr node, gpointer data)
300 struct split_pdata* pdata =
static_cast<decltype (pdata)
> (data);
301 auto id = dom_tree_to_guid (node);
304 g_return_val_if_fail (
id, FALSE);
306 lot = gnc_lot_lookup (&*
id, pdata->book);
307 if (!lot && gnc_transaction_xml_v2_testing &&
310 lot = gnc_lot_new (pdata->book);
311 gnc_lot_set_guid (lot, *
id);
320 spl_slots_handler (xmlNodePtr node, gpointer data)
322 struct split_pdata* pdata =
static_cast<decltype (pdata)
> (data);
325 successful = dom_tree_create_instance_slots (node,
326 QOF_INSTANCE (pdata->split));
327 g_return_val_if_fail (successful, FALSE);
334 {
"split:id", spl_id_handler, 1, 0 },
335 {
"split:memo", spl_memo_handler, 0, 0 },
336 {
"split:action", spl_action_handler, 0, 0 },
337 {
"split:reconciled-state", spl_reconciled_state_handler, 1, 0 },
338 {
"split:reconcile-date", spl_reconcile_date_handler, 0, 0 },
339 {
"split:value", spl_value_handler, 1, 0 },
340 {
"split:quantity", spl_quantity_handler, 1, 0 },
341 {
"split:account", spl_account_handler, 1, 0 },
342 {
"split:lot", spl_lot_handler, 0, 0 },
343 {
"split:slots", spl_slots_handler, 0, 0 },
344 { NULL, NULL, 0, 0 },
348 dom_tree_to_split (xmlNodePtr node, QofBook* book)
353 g_return_val_if_fail (book, NULL);
356 g_return_val_if_fail (ret, NULL);
362 if (dom_tree_generic_parse (node, spl_dom_handlers, &pdata))
382 set_tran_time64 (xmlNodePtr node, Transaction * trn,
383 void (*func) (Transaction *,
time64))
385 time64 time = dom_tree_to_time64 (node);
386 if (!dom_tree_valid_time64 (time, node->name)) time = 0;
392 trn_id_handler (xmlNodePtr node, gpointer
trans_pdata)
395 Transaction* trn = pdata->trans;
396 auto tmp = dom_tree_to_guid (node);
398 g_return_val_if_fail (tmp, FALSE);
400 xaccTransSetGUID ((Transaction*)trn, &*tmp);
406 trn_currency_handler (xmlNodePtr node, gpointer
trans_pdata)
409 Transaction* trn = pdata->trans;
412 ref = dom_tree_to_commodity_ref (node, pdata->book);
419 trn_num_handler (xmlNodePtr node, gpointer
trans_pdata)
422 Transaction* trn = pdata->trans;
428 trn_date_posted_handler (xmlNodePtr node, gpointer
trans_pdata)
431 Transaction* trn = pdata->trans;
437 trn_date_entered_handler (xmlNodePtr node, gpointer
trans_pdata)
440 Transaction* trn = pdata->trans;
446 trn_description_handler (xmlNodePtr node, gpointer
trans_pdata)
449 Transaction* trn = pdata->trans;
455 trn_slots_handler (xmlNodePtr node, gpointer
trans_pdata)
458 Transaction* trn = pdata->trans;
461 successful = dom_tree_create_instance_slots (node, QOF_INSTANCE (trn));
463 g_return_val_if_fail (successful, FALSE);
469 trn_splits_handler (xmlNodePtr node, gpointer
trans_pdata)
472 Transaction* trn = pdata->trans;
475 g_return_val_if_fail (node, FALSE);
476 g_return_val_if_fail (node->xmlChildrenNode, FALSE);
478 for (mark = node->xmlChildrenNode; mark; mark = mark->next)
482 if (g_strcmp0 (
"text", (
char*)mark->name) == 0)
485 if (g_strcmp0 (
"trn:split", (
char*)mark->name))
490 spl = dom_tree_to_split (mark, pdata->book);
506 {
"trn:id", trn_id_handler, 1, 0 },
507 {
"trn:currency", trn_currency_handler, 0, 0},
508 {
"trn:num", trn_num_handler, 0, 0 },
509 {
"trn:date-posted", trn_date_posted_handler, 1, 0 },
510 {
"trn:date-entered", trn_date_entered_handler, 1, 0 },
511 {
"trn:description", trn_description_handler, 0, 0 },
512 {
"trn:slots", trn_slots_handler, 0, 0 },
513 {
"trn:splits", trn_splits_handler, 1, 0 },
514 { NULL, NULL, 0, 0 },
518 gnc_transaction_end_handler (gpointer data_for_children,
519 GSList* data_from_children, GSList* sibling_data,
520 gpointer parent_data, gpointer global_data,
521 gpointer* result,
const gchar* tag)
523 Transaction* trn = NULL;
524 xmlNodePtr tree = (xmlNodePtr)data_for_children;
525 gxpf_data* gdata = (gxpf_data*)global_data;
539 g_return_val_if_fail (tree, FALSE);
541 trn = dom_tree_to_transaction (tree,
542 static_cast<QofBook*> (gdata->bookdata));
545 gdata->cb (tag, gdata->parsedata, trn);
554 dom_tree_to_transaction (xmlNodePtr node, QofBook* book)
560 g_return_val_if_fail (node, NULL);
561 g_return_val_if_fail (book, NULL);
564 g_return_val_if_fail (trn, NULL);
570 successful = dom_tree_generic_parse (node, trn_dom_handlers, &pdata);
576 xmlElemDump (stdout, NULL, node);
587 gnc_transaction_sixtp_parser_create (
void)
589 return sixtp_dom_parser_new (gnc_transaction_end_handler, NULL, NULL);
void xaccSplitSetValue(Split *split, gnc_numeric val)
The xaccSplitSetValue() method sets the value of this split in the transaction's commodity.
This is the private header for the account structure.
#define xaccTransAppendSplit(t, s)
Add a split to the transaction.
Transaction * xaccMallocTransaction(QofBook *book)
The xaccMallocTransaction() will malloc memory and initialize it.
void xaccSplitSetAction(Split *split, const char *actn)
The Action is an arbitrary user-assigned string.
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
gboolean xaccSplitDestroy(Split *split)
Destructor.
char xaccSplitGetReconcile(const Split *split)
Returns the value of the reconcile flag.
void gnc_lot_add_split(GNCLot *lot, Split *split)
Adds a split to this lot.
void xaccTransSetDescription(Transaction *trans, const char *desc)
Sets the transaction Description.
void xaccTransSetNum(Transaction *trans, const char *xnum)
Sets the transaction Number (or ID) field; rather than use this function directly, see 'gnc_set_num_action' in engine/engine-helpers.c & .h which takes a user-set book option for selecting the source for the num-cell (the transaction-number or the split-action field) in registers/reports into account automatically.
void xaccSplitSetReconcile(Split *split, char recn)
Set the reconcile flag.
const char * xaccTransGetNum(const Transaction *trans)
Gets the transaction Number (or ID) field; rather than use this function directly, see 'gnc_get_num_action' and 'gnc_get_action_num' in engine/engine-helpers.c & .h which takes a user-set book option for selecting the source for the num-cell (the transaction-number or the split-action field) in registers/reports into account automatically.
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
Set a new currency on a transaction.
void xaccTransDestroy(Transaction *trans)
Destroys a transaction.
#define xaccAccountGetGUID(X)
void xaccSplitSetAmount(Split *split, gnc_numeric amt)
The xaccSplitSetAmount() method sets the amount in the account's commodity that the split should have...
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
Given two GUIDs, return TRUE if they are non-NULL and equal.
void xaccSplitSetMemo(Split *split, const char *memo)
The memo is an arbitrary string associated with a split.
time64 xaccTransRetDatePosted(const Transaction *trans)
Retrieve the posted date of the transaction.
const char * xaccTransGetDescription(const Transaction *trans)
Gets the transaction Description.
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
#define xaccSplitGetGUID(X)
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
void xaccAccountSetCommoditySCU(Account *acc, int scu)
Set the SCU for the account.
Split * xaccMallocSplit(QofBook *book)
Constructor.
#define xaccTransGetGUID(X)
void xaccSplitSetDateReconciledSecs(Split *split, time64 secs)
Set the date on which this split was reconciled by specifying the time as time64. ...
time64 xaccSplitGetDateReconciled(const Split *split)
Retrieve the date when the Split was reconciled.
void xaccTransSetDatePostedSecs(Transaction *trans, time64 secs)
The xaccTransSetDatePostedSecs() method will modify the posted date of the transaction, specified by a time64 (see ctime(3)).
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction's commodity.
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
const GncGUID * guid_null(void)
Returns a GncGUID which is guaranteed to never reference any entity.
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Returns the valuation commodity of this transaction.
#define xaccAccountInsertSplit(acc, s)
The xaccAccountInsertSplit() method will insert the indicated split into the indicated account...
Account * xaccMallocAccount(QofBook *book)
Constructor.
const char * xaccSplitGetMemo(const Split *split)
Returns the memo string.
const char * xaccSplitGetAction(const Split *split)
Returns the action string.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
void xaccTransSetDateEnteredSecs(Transaction *trans, time64 secs)
Modify the date of when the transaction was entered.
time64 xaccTransRetDateEntered(const Transaction *trans)
Retrieve the date of when the transaction was entered.
API for Transactions and Splits (journal entries)
SplitList * xaccTransGetSplitList(const Transaction *trans)
The xaccTransGetSplitList() method returns a GList of the splits in a transaction.
GNCLot * xaccSplitGetLot(const Split *split)
Returns the pointer to the debited/credited Lot where this split belongs to, or NULL if it doesn't be...
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.
Account * xaccAccountLookup(const GncGUID *guid, QofBook *book)
The xaccAccountLookup() subroutine will return the account associated with the given id...