29#include "gncCustomerP.h"
31#include "gncVendorP.h"
32#include "gncEmployeeP.h"
34#include "gnc-xml-helper.h"
36#include "sixtp-utils.h"
37#include "sixtp-parsers.h"
38#include "sixtp-utils.h"
39#include "sixtp-dom-parsers.h"
40#include "sixtp-dom-generators.h"
43#include "io-gncxml-gen.h"
46#include "gnc-owner-xml-v2.h"
48static QofLogModule log_module = GNC_MOD_IO;
50const gchar* owner_version_string =
"2.0.0";
53#define owner_type_string "owner:type"
54#define owner_id_string "owner:id"
57gnc_owner_to_dom_tree (
const char* tag,
const GncOwner* owner)
64 case GNC_OWNER_CUSTOMER:
65 type_str = GNC_ID_CUSTOMER;
68 type_str = GNC_ID_JOB;
70 case GNC_OWNER_VENDOR:
71 type_str = GNC_ID_VENDOR;
73 case GNC_OWNER_EMPLOYEE:
74 type_str = GNC_ID_EMPLOYEE;
81 ret = xmlNewNode (NULL, BAD_CAST tag);
82 xmlSetProp (ret, BAD_CAST
"version", BAD_CAST owner_version_string);
84 xmlAddChild (ret, text_to_dom_tree (owner_type_string, type_str));
85 xmlAddChild (ret, guid_to_dom_tree (owner_id_string,
100owner_type_handler (xmlNodePtr node, gpointer
owner_pdata)
104 auto init_owner_type = [](
GncOwner* owner,
const char* txt)
106 if (!g_strcmp0 (txt, GNC_ID_CUSTOMER))
107 gncOwnerInitCustomer (owner, NULL);
108 else if (!g_strcmp0 (txt, GNC_ID_JOB))
109 gncOwnerInitJob (owner, NULL);
110 else if (!g_strcmp0 (txt, GNC_ID_VENDOR))
111 gncOwnerInitVendor (owner, NULL);
112 else if (!g_strcmp0 (txt, GNC_ID_EMPLOYEE))
113 gncOwnerInitEmployee (owner, NULL);
115 return apply_xmlnode_text (init_owner_type, owner, node);
119owner_id_handler (xmlNodePtr node, gpointer
owner_pdata)
123 auto guid = dom_tree_to_guid (node);
124 g_return_val_if_fail (guid, FALSE);
128 case GNC_OWNER_CUSTOMER:
130 GncCustomer* cust = gncCustomerLookup (pdata->book, &*guid);
133 cust = gncCustomerCreate (pdata->book);
134 gncCustomerSetGUID (cust, &*guid);
136 gncOwnerInitCustomer (pdata->owner, cust);
141 GncJob* job = gncJobLookup (pdata->book, &*guid);
144 job = gncJobCreate (pdata->book);
145 gncJobSetGUID (job, &*guid);
147 gncOwnerInitJob (pdata->owner, job);
150 case GNC_OWNER_VENDOR:
152 GncVendor* vendor = gncVendorLookup (pdata->book, &*guid);
155 vendor = gncVendorCreate (pdata->book);
156 gncVendorSetGUID (vendor, &*guid);
158 gncOwnerInitVendor (pdata->owner, vendor);
161 case GNC_OWNER_EMPLOYEE:
163 GncEmployee* employee = gncEmployeeLookup (pdata->book, &*guid);
166 employee = gncEmployeeCreate (pdata->book);
167 gncEmployeeSetGUID (employee, &*guid);
169 gncOwnerInitEmployee (pdata->owner, employee);
182 { owner_type_string, owner_type_handler, 1, 0 },
183 { owner_id_string, owner_id_handler, 1, 0 },
196 successful = dom_tree_generic_parse (node, owner_handlers_v2,
201 PERR (
"failed to parse owner tree");
210 g_return_val_if_fail (out, FALSE);
211 return gnc_xml2_write_namespace_decl (out,
"owner");
215gnc_owner_xml_initialize (
void)
217 static GncXmlDataType_t be_data =
219 GNC_FILE_BACKEND_VERS,
229 gnc_xml_register_backend (be_data);
#define PERR(format, args...)
Log a serious error.
#define PWARN(format, args...)
Log a warning.
const GncGUID * gncOwnerGetGUID(const GncOwner *owner)
Get the GncGUID of the immediate owner.
GncOwnerType gncOwnerGetType(const GncOwner *owner)
Returns the GncOwnerType of this owner.
api for GnuCash version 2 XML-based file format
credit, discount and shipaddr are unique to GncCustomer id, name, notes, terms, addr,...