GnuCash  5.6-150-g038405b370+
gnc-tax-table-xml-v2.cpp
1 /********************************************************************\
2  * gnc-tax-table-xml-v2.c -- tax table xml i/o implementation *
3  * *
4  * Copyright (C) 2002 Derek Atkins <warlord@MIT.EDU> *
5  * *
6  * This program is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU General Public License as *
8  * published by the Free Software Foundation; either version 2 of *
9  * the License, or (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License*
17  * along with this program; if not, contact: *
18  * *
19  * Free Software Foundation Voice: +1-617-542-5942 *
20  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
21  * Boston, MA 02110-1301, USA gnu@gnu.org *
22  * *
23 \********************************************************************/
24 #include <glib.h>
25 
26 #include <config.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include "gncEntry.h"
30 #include "gncTaxTableP.h"
31 
32 #include "gnc-xml-helper.h"
33 #include "sixtp.h"
34 #include "sixtp-utils.h"
35 #include "sixtp-parsers.h"
36 #include "sixtp-utils.h"
37 #include "sixtp-dom-parsers.h"
38 #include "sixtp-dom-generators.h"
39 
40 #include "gnc-xml.h"
41 #include "io-gncxml-gen.h"
42 #include "io-gncxml-v2.h"
43 
44 #include "gnc-tax-table-xml-v2.h"
45 
46 #define _GNC_MOD_NAME GNC_ID_TAXTABLE
47 
48 static QofLogModule log_module = GNC_MOD_IO;
49 
50 const gchar* taxtable_version_string = "2.0.0";
51 
52 /* ids */
53 #define gnc_taxtable_string "gnc:GncTaxTable"
54 #define taxtable_guid_string "taxtable:guid"
55 #define taxtable_name_string "taxtable:name"
56 #define taxtable_refcount_string "taxtable:refcount"
57 #define taxtable_invisible_string "taxtable:invisible"
58 #define taxtable_parent_string "taxtable:parent"
59 #define taxtable_child_string "taxtable:child"
60 #define taxtable_entries_string "taxtable:entries"
61 #define taxtable_slots_string "taxtable:slots"
62 
63 #define gnc_taxtableentry_string "gnc:GncTaxTableEntry"
64 #define ttentry_account_string "tte:acct"
65 #define ttentry_type_string "tte:type"
66 #define ttentry_amount_string "tte:amount"
67 
68 static void
69 maybe_add_guid (xmlNodePtr ptr, const char* tag, GncTaxTable* table)
70 {
71  if (table)
72  xmlAddChild (ptr, guid_to_dom_tree (tag,
73  qof_instance_get_guid (QOF_INSTANCE (table))));
74 }
75 
76 static xmlNodePtr
77 ttentry_dom_tree_create (GncTaxTableEntry* entry)
78 {
79  xmlNodePtr ret;
80  Account* account;
81  gnc_numeric amount;
82 
83  ret = xmlNewNode (NULL, BAD_CAST gnc_taxtableentry_string);
84 
85  account = gncTaxTableEntryGetAccount (entry);
86  if (account)
87  xmlAddChild (ret, guid_to_dom_tree (ttentry_account_string,
88  qof_instance_get_guid (QOF_INSTANCE (account))));
89 
90  amount = gncTaxTableEntryGetAmount (entry);
91  xmlAddChild (ret, gnc_numeric_to_dom_tree (ttentry_amount_string, &amount));
92 
93  xmlAddChild (ret, text_to_dom_tree (ttentry_type_string,
94  gncAmountTypeToString (
95  gncTaxTableEntryGetType (entry))));
96 
97  return ret;
98 }
99 
100 static xmlNodePtr
101 taxtable_dom_tree_create (GncTaxTable* table)
102 {
103  xmlNodePtr ret, entries;
104  GList* list;
105 
106  ret = xmlNewNode (NULL, BAD_CAST gnc_taxtable_string);
107  xmlSetProp (ret, BAD_CAST "version", BAD_CAST taxtable_version_string);
108 
109  maybe_add_guid (ret, taxtable_guid_string, table);
110  xmlAddChild (ret, text_to_dom_tree (taxtable_name_string,
111  gncTaxTableGetName (table)));
112 
113  xmlAddChild (ret, int_to_dom_tree (taxtable_refcount_string,
114  gncTaxTableGetRefcount (table)));
115  xmlAddChild (ret, int_to_dom_tree (taxtable_invisible_string,
116  gncTaxTableGetInvisible (table)));
117 
118  /* We should not be our own child */
119  if (gncTaxTableGetChild (table) != table)
120  maybe_add_guid (ret, taxtable_child_string, gncTaxTableGetChild (table));
121 
122  maybe_add_guid (ret, taxtable_parent_string, gncTaxTableGetParent (table));
123 
124  entries = xmlNewChild (ret, NULL, BAD_CAST taxtable_entries_string, NULL);
125  for (list = gncTaxTableGetEntries (table); list; list = list->next)
126  {
127  GncTaxTableEntry* entry = static_cast<decltype (entry)> (list->data);
128  xmlAddChild (entries, ttentry_dom_tree_create (entry));
129  }
130 
131  /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
132  xmlAddChild (ret, qof_instance_slots_to_dom_tree (taxtable_slots_string,
133  QOF_INSTANCE (table)));
134  return ret;
135 }
136 
137 /***********************************************************************/
138 
140 {
141  GncTaxTableEntry* ttentry;
142  QofBook* book;
143 };
144 
145 static gboolean
146 ttentry_acct_handler (xmlNodePtr node, gpointer ttentry_pdata)
147 {
148  struct ttentry_pdata* pdata = static_cast<decltype (pdata)> (ttentry_pdata);
149  GncGUID* guid;
150  Account* acc;
151 
152  guid = dom_tree_to_guid (node);
153  g_return_val_if_fail (guid, FALSE);
154  acc = xaccAccountLookup (guid, pdata->book);
155  guid_free (guid);
156  g_return_val_if_fail (acc, FALSE);
157 
158  gncTaxTableEntrySetAccount (pdata->ttentry, acc);
159  return TRUE;
160 }
161 
162 static gboolean
163 ttentry_type_handler (xmlNodePtr node, gpointer ttentry_pdata)
164 {
165  struct ttentry_pdata* pdata = static_cast<decltype (pdata)> (ttentry_pdata);
166  GncAmountType type;
167  char* str;
168  gboolean ret;
169 
170  str = dom_tree_to_text (node);
171  g_return_val_if_fail (str, FALSE);
172 
173  ret = gncAmountStringToType (str, &type);
174  g_free (str);
175 
176  if (ret)
177  gncTaxTableEntrySetType (pdata->ttentry, type);
178 
179  return ret;
180 }
181 
182 static gboolean
183 ttentry_amount_handler (xmlNodePtr node, gpointer ttentry_pdata)
184 {
185  struct ttentry_pdata* pdata = static_cast<decltype (pdata)> (ttentry_pdata);
186 
187  gncTaxTableEntrySetAmount (pdata->ttentry, dom_tree_to_gnc_numeric (node));
188  return TRUE;
189 }
190 
191 static struct dom_tree_handler ttentry_handlers_v2[] =
192 {
193  { ttentry_account_string, ttentry_acct_handler, 0, 0 },
194  { ttentry_type_string, ttentry_type_handler, 1, 0 },
195  { ttentry_amount_string, ttentry_amount_handler, 1, 0 },
196  { NULL, 0, 0, 0 }
197 };
198 
199 static GncTaxTableEntry*
200 dom_tree_to_ttentry (xmlNodePtr node, QofBook* book)
201 {
203  gboolean successful;
204 
205  ttentry_pdata.ttentry = gncTaxTableEntryCreate ();
206  ttentry_pdata.book = book;
207 
208  successful = dom_tree_generic_parse (node, ttentry_handlers_v2,
209  &ttentry_pdata);
210 
211  if (!successful)
212  {
213  PERR ("failed to parse tax table entry tree");
214  gncTaxTableEntryDestroy (ttentry_pdata.ttentry);
215  ttentry_pdata.ttentry = NULL;
216  }
217 
218  return ttentry_pdata.ttentry;
219 }
220 
221 /***********************************************************************/
222 
224 {
226  QofBook* book;
227 };
228 
229 static gboolean
230 set_parent_child (xmlNodePtr node, struct taxtable_pdata* pdata,
231  void (*func) (GncTaxTable*, GncTaxTable*))
232 {
233  GncGUID* guid;
235 
236  guid = dom_tree_to_guid (node);
237  g_return_val_if_fail (guid, FALSE);
238  table = gncTaxTableLookup (pdata->book, guid);
239 
240  /* Ignore pointers to self */
241  if (table == pdata->table)
242  {
243  PINFO ("found a self-referential parent/child; ignoring.\n");
244  return TRUE;
245  }
246 
247  if (!table)
248  {
249  table = gncTaxTableCreate (pdata->book);
250  gncTaxTableBeginEdit (table);
251  gncTaxTableSetGUID (table, guid);
252  gncTaxTableCommitEdit (table);
253  }
254  guid_free (guid);
255  g_return_val_if_fail (table, FALSE);
256  func (pdata->table, table);
257 
258  return TRUE;
259 }
260 
261 static gboolean
262 taxtable_guid_handler (xmlNodePtr node, gpointer taxtable_pdata)
263 {
264  struct taxtable_pdata* pdata = static_cast<decltype (pdata)> (taxtable_pdata);
265  GncGUID* guid;
267 
268  guid = dom_tree_to_guid (node);
269  g_return_val_if_fail (guid, FALSE);
270  table = gncTaxTableLookup (pdata->book, guid);
271  if (table)
272  {
273  gncTaxTableDestroy (pdata->table);
274  pdata->table = table;
275  gncTaxTableBeginEdit (table);
276  }
277  else
278  {
279  gncTaxTableSetGUID (pdata->table, guid);
280  }
281 
282  guid_free (guid);
283 
284  return TRUE;
285 }
286 
287 static gboolean
288 taxtable_name_handler (xmlNodePtr node, gpointer taxtable_pdata)
289 {
290  struct taxtable_pdata* pdata = static_cast<decltype (pdata)> (taxtable_pdata);
291  char* txt = dom_tree_to_text (node);
292  g_return_val_if_fail (txt, FALSE);
293 
294  gncTaxTableSetName (pdata->table, txt);
295  g_free (txt);
296  return TRUE;
297 }
298 
299 static gboolean
300 taxtable_refcount_handler (xmlNodePtr node, gpointer taxtable_pdata)
301 {
302  struct taxtable_pdata* pdata = static_cast<decltype (pdata)> (taxtable_pdata);
303  gint64 val;
304 
305  dom_tree_to_integer (node, &val);
306  gncTaxTableSetRefcount (pdata->table, val);
307  return TRUE;
308 }
309 
310 static gboolean
311 taxtable_invisible_handler (xmlNodePtr node, gpointer taxtable_pdata)
312 {
313  struct taxtable_pdata* pdata = static_cast<decltype (pdata)> (taxtable_pdata);
314  gint64 val;
315 
316  dom_tree_to_integer (node, &val);
317  if (val)
318  gncTaxTableMakeInvisible (pdata->table);
319  return TRUE;
320 }
321 
322 static gboolean
323 taxtable_parent_handler (xmlNodePtr node, gpointer taxtable_pdata)
324 {
325  struct taxtable_pdata* pdata = static_cast<decltype (pdata)> (taxtable_pdata);
326  return set_parent_child (node, pdata, gncTaxTableSetParent);
327 }
328 
329 static gboolean
330 taxtable_child_handler (xmlNodePtr node, gpointer taxtable_pdata)
331 {
332  struct taxtable_pdata* pdata = static_cast<decltype (pdata)> (taxtable_pdata);
333  return set_parent_child (node, pdata, gncTaxTableSetChild);
334 }
335 
336 static gboolean
337 taxtable_entries_handler (xmlNodePtr node, gpointer taxtable_pdata)
338 {
339  struct taxtable_pdata* pdata = static_cast<decltype (pdata)> (taxtable_pdata);
340  xmlNodePtr mark;
341 
342  g_return_val_if_fail (node, FALSE);
343  g_return_val_if_fail (node->xmlChildrenNode, FALSE);
344 
345  for (mark = node->xmlChildrenNode; mark; mark = mark->next)
346  {
347  GncTaxTableEntry* entry;
348 
349  if (g_strcmp0 ("text", (char*)mark->name) == 0)
350  continue;
351 
352  if (g_strcmp0 (gnc_taxtableentry_string, (char*)mark->name))
353  return FALSE;
354 
355  entry = dom_tree_to_ttentry (mark, pdata->book);
356 
357  if (entry)
358  gncTaxTableAddEntry (pdata->table, entry);
359  else
360  return FALSE;
361 
362  }
363  return TRUE;
364 }
365 
366 static gboolean
367 taxtable_slots_handler (xmlNodePtr node, gpointer taxtable_pdata)
368 {
369  struct taxtable_pdata* pdata = static_cast<decltype (pdata)> (taxtable_pdata);
370 
371  return dom_tree_create_instance_slots (node, QOF_INSTANCE (pdata->table));
372 }
373 
374 static struct dom_tree_handler taxtable_handlers_v2[] =
375 {
376  { taxtable_guid_string, taxtable_guid_handler, 1, 0 },
377  { taxtable_name_string, taxtable_name_handler, 1, 0 },
378  { taxtable_refcount_string, taxtable_refcount_handler, 1, 0 },
379  { taxtable_invisible_string, taxtable_invisible_handler, 1, 0 },
380  { taxtable_parent_string, taxtable_parent_handler, 0, 0 },
381  { taxtable_child_string, taxtable_child_handler, 0, 0 },
382  { taxtable_entries_string, taxtable_entries_handler, 1, 0 },
383  { taxtable_slots_string, taxtable_slots_handler, 0, 0 },
384  { NULL, 0, 0, 0 }
385 };
386 
387 static GncTaxTable*
388 dom_tree_to_taxtable (xmlNodePtr node, QofBook* book)
389 {
391  gboolean successful;
392 
393  taxtable_pdata.table = gncTaxTableCreate (book);
394  taxtable_pdata.book = book;
395  gncTaxTableBeginEdit (taxtable_pdata.table);
396 
397  successful = dom_tree_generic_parse (node, taxtable_handlers_v2,
398  &taxtable_pdata);
399 
400  if (successful)
401  gncTaxTableCommitEdit (taxtable_pdata.table);
402  else
403  {
404  PERR ("failed to parse tax table tree");
405  gncTaxTableDestroy (taxtable_pdata.table);
406  taxtable_pdata.table = NULL;
407  }
408 
409  return taxtable_pdata.table;
410 }
411 
412 static gboolean
413 gnc_taxtable_end_handler (gpointer data_for_children,
414  GSList* data_from_children, GSList* sibling_data,
415  gpointer parent_data, gpointer global_data,
416  gpointer* result, const gchar* tag)
417 {
419  xmlNodePtr tree = (xmlNodePtr)data_for_children;
420  gxpf_data* gdata = (gxpf_data*)global_data;
421  QofBook* book = static_cast<decltype (book)> (gdata->bookdata);
422 
423  if (parent_data)
424  {
425  return TRUE;
426  }
427 
428  /* OK. For some messed up reason this is getting called again with a
429  NULL tag. So we ignore those cases */
430  if (!tag)
431  {
432  return TRUE;
433  }
434 
435  g_return_val_if_fail (tree, FALSE);
436 
437  table = dom_tree_to_taxtable (tree, book);
438  if (table != NULL)
439  {
440  gdata->cb (tag, gdata->parsedata, table);
441  }
442 
443  xmlFreeNode (tree);
444 
445  return table != NULL;
446 }
447 
448 static sixtp*
449 taxtable_sixtp_parser_create (void)
450 {
451  return sixtp_dom_parser_new (gnc_taxtable_end_handler, NULL, NULL);
452 }
453 
454 static void
455 do_count (QofInstance* table_p, gpointer count_p)
456 {
457  int* count = static_cast<decltype (count)> (count_p);
458  (*count)++;
459 }
460 
461 static int
462 taxtable_get_count (QofBook* book)
463 {
464  int count = 0;
465  qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
466  return count;
467 }
468 
469 static void
470 xml_add_taxtable (QofInstance* table_p, gpointer out_p)
471 {
472  xmlNodePtr node;
473  GncTaxTable* table = (GncTaxTable*) table_p;
474  FILE* out = static_cast<decltype (out)> (out_p);
475 
476  if (ferror (out))
477  return;
478 
479  node = taxtable_dom_tree_create (table);
480  xmlElemDump (out, NULL, node);
481  xmlFreeNode (node);
482  if (ferror (out) || fprintf (out, "\n") < 0)
483  return;
484 }
485 
486 static gboolean
487 taxtable_write (FILE* out, QofBook* book)
488 {
489  qof_object_foreach_sorted (_GNC_MOD_NAME, book, xml_add_taxtable,
490  (gpointer) out);
491  return ferror (out) == 0;
492 }
493 
494 
495 static gboolean
496 taxtable_is_grandchild (GncTaxTable* table)
497 {
498  return (gncTaxTableGetParent (gncTaxTableGetParent (table)) != NULL);
499 }
500 
501 static GncTaxTable*
502 taxtable_find_senior (GncTaxTable* table)
503 {
504  GncTaxTable* temp, *parent, *gp = NULL;
505 
506  temp = table;
507  do
508  {
509  /* See if "temp" is a grandchild */
510  parent = gncTaxTableGetParent (temp);
511  if (!parent)
512  break;
513  gp = gncTaxTableGetParent (parent);
514  if (!gp)
515  break;
516 
517  /* Yep, this is a grandchild. Move up one generation and try again */
518  temp = parent;
519  }
520  while (TRUE);
521 
522  /* Ok, at this point temp points to the most senior child and parent
523  * should point to the top taxtable (and gp should be NULL). If
524  * parent is NULL then we are the most senior child (and have no
525  * children), so do nothing. If temp == table then there is no
526  * grandparent, so do nothing.
527  *
528  * Do something if parent != NULL && temp != table
529  */
530  g_assert (gp == NULL);
531 
532  /* return the most senior table */
533  return temp;
534 }
535 
536 /* build a list of tax tables that are grandchildren or bogus (empty entry list). */
537 static void
538 taxtable_scrub_cb (QofInstance* table_p, gpointer list_p)
539 {
540  GncTaxTable* table = GNC_TAXTABLE (table_p);
541  GList** list = static_cast<decltype (list)> (list_p);
542 
543  if (taxtable_is_grandchild (table) || gncTaxTableGetEntries (table) == NULL)
544  *list = g_list_prepend (*list, table);
545 }
546 
547 /* for each entry, check the tax tables. If the tax tables are
548  * grandchildren, then fix them to point to the most senior child
549  */
550 static void
551 taxtable_scrub_entries (QofInstance* entry_p, gpointer ht_p)
552 {
553  GHashTable* ht = static_cast<decltype (ht)> (ht_p);
554  GncEntry* entry = GNC_ENTRY (entry_p);
555  GncTaxTable* table, *new_tt;
556  gint32 count;
557 
558  table = gncEntryGetInvTaxTable (entry);
559  if (table)
560  {
561  if (taxtable_is_grandchild (table))
562  {
563  gchar guidstr[GUID_ENCODING_LENGTH + 1];
564  guid_to_string_buff (qof_instance_get_guid (QOF_INSTANCE (entry)), guidstr);
565  PINFO ("Fixing i-taxtable on entry %s\n", guidstr);
566  new_tt = taxtable_find_senior (table);
567  gncEntryBeginEdit (entry);
568  gncEntrySetInvTaxTable (entry, new_tt);
569  gncEntryCommitEdit (entry);
570  table = new_tt;
571  }
572  if (table)
573  {
574  count = GPOINTER_TO_INT (g_hash_table_lookup (ht, table));
575  count++;
576  g_hash_table_insert (ht, table, GINT_TO_POINTER (count));
577  }
578  }
579 
580  table = gncEntryGetBillTaxTable (entry);
581  if (table)
582  {
583  if (taxtable_is_grandchild (table))
584  {
585  gchar guidstr[GUID_ENCODING_LENGTH + 1];
586  guid_to_string_buff (qof_instance_get_guid (QOF_INSTANCE (entry)), guidstr);
587  PINFO ("Fixing b-taxtable on entry %s\n", guidstr);
588  new_tt = taxtable_find_senior (table);
589  gncEntryBeginEdit (entry);
590  gncEntrySetBillTaxTable (entry, new_tt);
591  gncEntryCommitEdit (entry);
592  table = new_tt;
593  }
594  if (table)
595  {
596  count = GPOINTER_TO_INT (g_hash_table_lookup (ht, table));
597  count++;
598  g_hash_table_insert (ht, table, GINT_TO_POINTER (count));
599  }
600  }
601 }
602 
603 static void
604 taxtable_scrub_cust (QofInstance* cust_p, gpointer ht_p)
605 {
606  GHashTable* ht = static_cast<decltype (ht)> (ht_p);
607  GncCustomer* cust = GNC_CUSTOMER (cust_p);
609  gint32 count;
610 
611  table = gncCustomerGetTaxTable (cust);
612  if (table)
613  {
614  count = GPOINTER_TO_INT (g_hash_table_lookup (ht, table));
615  count++;
616  g_hash_table_insert (ht, table, GINT_TO_POINTER (count));
617  }
618 }
619 
620 static void
621 taxtable_scrub_vendor (QofInstance* vendor_p, gpointer ht_p)
622 {
623  GHashTable* ht = static_cast<decltype (ht)> (ht_p);
624  GncVendor* vendor = GNC_VENDOR (vendor_p);
626  gint32 count;
627 
628  table = gncVendorGetTaxTable (vendor);
629  if (table)
630  {
631  count = GPOINTER_TO_INT (g_hash_table_lookup (ht, table));
632  count++;
633  g_hash_table_insert (ht, table, GINT_TO_POINTER (count));
634  }
635 }
636 
637 static void
638 taxtable_reset_refcount (gpointer key, gpointer value, gpointer notused)
639 {
640  GncTaxTable* table = static_cast<decltype (table)> (key);
641  gint32 count = GPOINTER_TO_INT (value);
642 
643  if (count != gncTaxTableGetRefcount (table) &&
644  !gncTaxTableGetInvisible (table))
645  {
646  gchar guidstr[GUID_ENCODING_LENGTH + 1];
647  guid_to_string_buff (qof_instance_get_guid (QOF_INSTANCE (table)), guidstr);
648  PWARN ("Fixing refcount on taxtable %s (%" G_GINT64_FORMAT " -> %d)\n",
649  guidstr, gncTaxTableGetRefcount (table), count);
650  gncTaxTableSetRefcount (table, count);
651  }
652 }
653 
654 static void
655 taxtable_scrub (QofBook* book)
656 {
657  GList* list = NULL;
658  GList* node;
659  GncTaxTable* parent, *table;
660  GHashTable* ht = g_hash_table_new (g_direct_hash, g_direct_equal);
661 
662  qof_object_foreach (GNC_ID_ENTRY, book, taxtable_scrub_entries, ht);
663  qof_object_foreach (GNC_ID_CUSTOMER, book, taxtable_scrub_cust, ht);
664  qof_object_foreach (GNC_ID_VENDOR, book, taxtable_scrub_vendor, ht);
665  qof_object_foreach (GNC_ID_TAXTABLE, book, taxtable_scrub_cb, &list);
666 
667  /* destroy the list of "grandchildren" tax tables */
668  for (node = list; node; node = node->next)
669  {
670  gchar guidstr[GUID_ENCODING_LENGTH + 1];
671  table = static_cast<decltype (table)> (node->data);
672 
673  guid_to_string_buff (qof_instance_get_guid (QOF_INSTANCE (table)), guidstr);
674  PINFO ("deleting grandchild taxtable: %s\n", guidstr);
675 
676  /* Make sure the parent has no children */
677  parent = gncTaxTableGetParent (table);
678  gncTaxTableSetChild (parent, NULL);
679 
680  /* Destroy this tax table */
681  gncTaxTableBeginEdit (table);
682  gncTaxTableDestroy (table);
683  }
684 
685  /* reset the refcounts as necessary */
686  g_hash_table_foreach (ht, taxtable_reset_refcount, NULL);
687 
688  g_list_free (list);
689  g_hash_table_destroy (ht);
690 }
691 
692 static gboolean
693 taxtable_ns (FILE* out)
694 {
695  g_return_val_if_fail (out, FALSE);
696  return
697  gnc_xml2_write_namespace_decl (out, "taxtable")
698  && gnc_xml2_write_namespace_decl (out, "tte");
699 }
700 
701 void
702 gnc_taxtable_xml_initialize (void)
703 {
704  static GncXmlDataType_t be_data =
705  {
706  GNC_FILE_BACKEND_VERS,
707  gnc_taxtable_string,
708  taxtable_sixtp_parser_create,
709  NULL, /* add_item */
710  taxtable_get_count,
711  taxtable_write,
712  taxtable_scrub,
713  taxtable_ns,
714  };
715 
716  gnc_xml_register_backend(be_data);
717 }
Definition: sixtp.h:129
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
#define PINFO(format, args...)
Print an informational note.
Definition: qoflog.h:256
STRUCTS.
gchar * guid_to_string_buff(const GncGUID *guid, gchar *str)
The guid_to_string_buff() routine puts a null-terminated string encoding of the id into the memory po...
Definition: guid.cpp:173
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250
void qof_object_foreach_sorted(QofIdTypeConst type_name, QofBook *book, QofInstanceForeachCB cb, gpointer user_data)
Invoke callback &#39;cb&#39; on each instance in guid orted order.
Definition: qofobject.cpp:223
api for GnuCash version 2 XML-based file format
#define GUID_ENCODING_LENGTH
Number of characters needed to encode a guid as a string not including the null terminator.
Definition: guid.h:84
void qof_object_foreach(QofIdTypeConst type_name, QofBook *book, QofInstanceForeachCB cb, gpointer user_data)
Invoke the callback &#39;cb&#39; on every instance ov a particular object type.
Definition: qofobject.cpp:185
credit, discount and shipaddr are unique to GncCustomer id, name, notes, terms, addr, currency, taxtable, taxtable_override taxincluded, active and jobs are identical to ::GncVendor.
Business Entry Interface.
The type used to store guids in C.
Definition: guid.h:75
GncAmountType
How to interpret the amount.
Definition: gncTaxTable.h:78
modtime is the internal date of the last modtime See libgnucash/engine/TaxTableBillTermImmutability.txt for an explanation of the following Code that handles refcount, parent, child, invisible and children is identical to that in ::GncBillTerm
Account * xaccAccountLookup(const GncGUID *guid, QofBook *book)
The xaccAccountLookup() subroutine will return the account associated with the given id...
Definition: Account.cpp:2052