2002-03-04 19:34:52 +00:00
|
|
|
/********************************************************************\
|
|
|
|
|
* gnc-entry-xml-v2.c -- entry xml i/o implementation *
|
|
|
|
|
* *
|
|
|
|
|
* Copyright (C) 2002 Derek Atkins <warlord@MIT.EDU> *
|
|
|
|
|
* *
|
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
|
* published by the Free Software Foundation; either version 2 of *
|
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU General Public License*
|
|
|
|
|
* along with this program; if not, contact: *
|
|
|
|
|
* *
|
|
|
|
|
* Free Software Foundation Voice: +1-617-542-5942 *
|
2005-11-17 05:35:02 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
2002-03-04 19:34:52 +00:00
|
|
|
* *
|
|
|
|
|
\********************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "gnc-xml-helper.h"
|
|
|
|
|
|
|
|
|
|
#include "sixtp.h"
|
|
|
|
|
#include "sixtp-utils.h"
|
|
|
|
|
#include "sixtp-parsers.h"
|
|
|
|
|
#include "sixtp-utils.h"
|
|
|
|
|
#include "sixtp-dom-parsers.h"
|
|
|
|
|
#include "sixtp-dom-generators.h"
|
|
|
|
|
|
|
|
|
|
#include "gnc-xml.h"
|
|
|
|
|
#include "io-gncxml-gen.h"
|
|
|
|
|
#include "io-gncxml-v2.h"
|
|
|
|
|
|
|
|
|
|
#include "gncEntryP.h"
|
|
|
|
|
#include "gncOrderP.h"
|
|
|
|
|
#include "gncInvoiceP.h"
|
2002-06-16 05:11:33 +00:00
|
|
|
#include "gncTaxTableP.h"
|
2002-03-04 19:34:52 +00:00
|
|
|
#include "gnc-entry-xml-v2.h"
|
|
|
|
|
#include "gnc-owner-xml-v2.h"
|
|
|
|
|
|
2003-10-19 05:13:59 +00:00
|
|
|
#define _GNC_MOD_NAME GNC_ID_ENTRY
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2005-11-02 03:32:36 +00:00
|
|
|
static QofLogModule log_module = GNC_MOD_IO;
|
2002-03-04 19:34:52 +00:00
|
|
|
|
|
|
|
|
const gchar *entry_version_string = "2.0.0";
|
|
|
|
|
|
|
|
|
|
/* ids */
|
|
|
|
|
#define gnc_entry_string "gnc:GncEntry"
|
|
|
|
|
#define entry_guid_string "entry:guid"
|
|
|
|
|
#define entry_date_string "entry:date"
|
|
|
|
|
#define entry_dateentered_string "entry:entered"
|
|
|
|
|
#define entry_description_string "entry:description"
|
|
|
|
|
#define entry_action_string "entry:action"
|
2002-06-17 04:04:05 +00:00
|
|
|
#define entry_notes_string "entry:notes"
|
2002-03-04 19:34:52 +00:00
|
|
|
#define entry_qty_string "entry:qty"
|
2002-09-14 05:32:37 +00:00
|
|
|
|
|
|
|
|
/* cust inv */
|
2002-07-11 15:11:33 +00:00
|
|
|
#define entry_invacct_string "entry:i-acct"
|
2002-09-14 05:32:37 +00:00
|
|
|
#define entry_iprice_string "entry:i-price"
|
|
|
|
|
#define entry_idiscount_string "entry:i-discount"
|
|
|
|
|
#define entry_idisctype_string "entry:i-disc-type"
|
|
|
|
|
#define entry_idischow_string "entry:i-disc-how"
|
|
|
|
|
#define entry_itaxable_string "entry:i-taxable"
|
|
|
|
|
#define entry_itaxincluded_string "entry:i-taxincluded"
|
|
|
|
|
#define entry_itaxtable_string "entry:i-taxtable"
|
|
|
|
|
|
|
|
|
|
/* vend bill */
|
2002-07-11 15:11:33 +00:00
|
|
|
#define entry_billacct_string "entry:b-acct"
|
2002-09-14 05:32:37 +00:00
|
|
|
#define entry_bprice_string "entry:b-price"
|
|
|
|
|
#define entry_btaxable_string "entry:b-taxable"
|
|
|
|
|
#define entry_btaxincluded_string "entry:b-taxincluded"
|
|
|
|
|
#define entry_btaxtable_string "entry:b-taxtable"
|
|
|
|
|
#define entry_billable_string "entry:billable"
|
|
|
|
|
#define entry_billto_string "entry:billto"
|
|
|
|
|
|
2003-03-03 04:58:55 +00:00
|
|
|
/* emp bill */
|
|
|
|
|
#define entry_billpayment_string "entry:b-pay"
|
|
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
/* other stuff */
|
2002-03-04 19:34:52 +00:00
|
|
|
#define entry_order_string "entry:order"
|
|
|
|
|
#define entry_invoice_string "entry:invoice"
|
2002-07-10 04:12:19 +00:00
|
|
|
#define entry_bill_string "entry:bill"
|
2003-09-11 17:37:01 +00:00
|
|
|
#define entry_slots_string "entry:slots"
|
2002-03-04 19:34:52 +00:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
|
|
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
if (str && strlen(str) > 0)
|
|
|
|
|
xmlAddChild (ptr, text_to_dom_tree (tag, str));
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
maybe_add_numeric (xmlNodePtr ptr, const char *tag, gnc_numeric num)
|
|
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
if (!gnc_numeric_zero_p (num))
|
|
|
|
|
xmlAddChild (ptr, gnc_numeric_to_dom_tree (tag, &num));
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static xmlNodePtr
|
|
|
|
|
entry_dom_tree_create (GncEntry *entry)
|
|
|
|
|
{
|
|
|
|
|
xmlNodePtr ret;
|
|
|
|
|
Timespec ts;
|
|
|
|
|
Account *acc;
|
2002-06-16 05:11:33 +00:00
|
|
|
GncTaxTable *taxtable;
|
2002-03-04 19:34:52 +00:00
|
|
|
GncOrder *order;
|
|
|
|
|
GncInvoice *invoice;
|
|
|
|
|
|
2005-11-02 03:32:36 +00:00
|
|
|
ret = xmlNewNode(NULL, BAD_CAST gnc_entry_string);
|
|
|
|
|
xmlSetProp(ret, BAD_CAST "version", BAD_CAST entry_version_string);
|
2002-03-04 19:34:52 +00:00
|
|
|
|
|
|
|
|
xmlAddChild(ret, guid_to_dom_tree(entry_guid_string,
|
2010-03-02 21:41:05 +00:00
|
|
|
qof_instance_get_guid(QOF_INSTANCE(entry))));
|
2002-03-04 19:34:52 +00:00
|
|
|
|
|
|
|
|
ts = gncEntryGetDate (entry);
|
|
|
|
|
xmlAddChild(ret, timespec_to_dom_tree (entry_date_string, &ts));
|
|
|
|
|
|
|
|
|
|
ts = gncEntryGetDateEntered (entry);
|
|
|
|
|
xmlAddChild(ret, timespec_to_dom_tree (entry_dateentered_string, &ts));
|
2010-03-02 21:41:05 +00:00
|
|
|
|
2002-03-04 19:34:52 +00:00
|
|
|
maybe_add_string (ret, entry_description_string,
|
2010-03-02 21:41:05 +00:00
|
|
|
gncEntryGetDescription (entry));
|
2002-03-04 19:34:52 +00:00
|
|
|
maybe_add_string (ret, entry_action_string, gncEntryGetAction (entry));
|
2002-06-17 04:04:05 +00:00
|
|
|
maybe_add_string (ret, entry_notes_string, gncEntryGetNotes (entry));
|
2002-03-04 19:34:52 +00:00
|
|
|
|
|
|
|
|
maybe_add_numeric (ret, entry_qty_string, gncEntryGetQuantity (entry));
|
|
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
/* cust invoice */
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2002-07-11 15:11:33 +00:00
|
|
|
acc = gncEntryGetInvAccount (entry);
|
2002-03-04 19:34:52 +00:00
|
|
|
if (acc)
|
2010-03-02 21:41:05 +00:00
|
|
|
xmlAddChild (ret, guid_to_dom_tree (entry_invacct_string,
|
|
|
|
|
qof_instance_get_guid(QOF_INSTANCE(acc))));
|
2002-07-11 15:11:33 +00:00
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
maybe_add_numeric (ret, entry_iprice_string, gncEntryGetInvPrice (entry));
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
maybe_add_numeric (ret, entry_idiscount_string, gncEntryGetInvDiscount (entry));
|
2010-03-02 21:41:05 +00:00
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
invoice = gncEntryGetInvoice (entry);
|
2010-03-02 21:41:05 +00:00
|
|
|
if (invoice)
|
|
|
|
|
{
|
|
|
|
|
xmlAddChild (ret, guid_to_dom_tree (entry_invoice_string,
|
|
|
|
|
qof_instance_get_guid(QOF_INSTANCE(invoice))));
|
|
|
|
|
|
|
|
|
|
xmlAddChild(ret, text_to_dom_tree(entry_idisctype_string,
|
|
|
|
|
gncAmountTypeToString (
|
|
|
|
|
gncEntryGetInvDiscountType (entry))));
|
|
|
|
|
xmlAddChild(ret, text_to_dom_tree(entry_idischow_string,
|
|
|
|
|
gncEntryDiscountHowToString (
|
|
|
|
|
gncEntryGetInvDiscountHow (entry))));
|
|
|
|
|
|
|
|
|
|
xmlAddChild(ret, int_to_dom_tree(entry_itaxable_string,
|
|
|
|
|
gncEntryGetInvTaxable (entry)));
|
|
|
|
|
xmlAddChild(ret, int_to_dom_tree(entry_itaxincluded_string,
|
|
|
|
|
gncEntryGetInvTaxIncluded (entry)));
|
2002-09-14 05:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
taxtable = gncEntryGetInvTaxTable (entry);
|
2002-06-16 05:11:33 +00:00
|
|
|
if (taxtable)
|
2010-03-02 21:41:05 +00:00
|
|
|
xmlAddChild (ret, guid_to_dom_tree (entry_itaxtable_string,
|
|
|
|
|
qof_instance_get_guid (QOF_INSTANCE(taxtable))));
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
/* vendor bills */
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
acc = gncEntryGetBillAccount (entry);
|
|
|
|
|
if (acc)
|
2010-03-02 21:41:05 +00:00
|
|
|
xmlAddChild (ret, guid_to_dom_tree (entry_billacct_string,
|
|
|
|
|
qof_instance_get_guid (QOF_INSTANCE(acc))));
|
2002-09-14 05:32:37 +00:00
|
|
|
|
|
|
|
|
maybe_add_numeric (ret, entry_bprice_string, gncEntryGetBillPrice (entry));
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2002-07-10 04:12:19 +00:00
|
|
|
invoice = gncEntryGetBill (entry);
|
2010-03-02 21:41:05 +00:00
|
|
|
if (invoice)
|
|
|
|
|
{
|
|
|
|
|
GncOwner *owner;
|
|
|
|
|
xmlAddChild (ret, guid_to_dom_tree (entry_bill_string,
|
|
|
|
|
qof_instance_get_guid(QOF_INSTANCE(invoice))));
|
|
|
|
|
xmlAddChild(ret, int_to_dom_tree(entry_billable_string,
|
|
|
|
|
gncEntryGetBillable (entry)));
|
|
|
|
|
owner = gncEntryGetBillTo (entry);
|
|
|
|
|
if (owner && owner->owner.undefined != NULL)
|
|
|
|
|
xmlAddChild (ret, gnc_owner_to_dom_tree (entry_billto_string, owner));
|
|
|
|
|
|
|
|
|
|
xmlAddChild(ret, int_to_dom_tree(entry_btaxable_string,
|
|
|
|
|
gncEntryGetBillTaxable (entry)));
|
|
|
|
|
xmlAddChild(ret, int_to_dom_tree(entry_btaxincluded_string,
|
|
|
|
|
gncEntryGetBillTaxIncluded (entry)));
|
|
|
|
|
maybe_add_string (ret, entry_billpayment_string,
|
|
|
|
|
gncEntryPaymentTypeToString (gncEntryGetBillPayment (entry)));
|
2002-07-10 17:32:59 +00:00
|
|
|
}
|
2002-07-10 04:12:19 +00:00
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
taxtable = gncEntryGetBillTaxTable (entry);
|
|
|
|
|
if (taxtable)
|
2010-03-02 21:41:05 +00:00
|
|
|
xmlAddChild (ret, guid_to_dom_tree (entry_btaxtable_string,
|
|
|
|
|
qof_instance_get_guid (QOF_INSTANCE(taxtable))));
|
2002-09-14 05:32:37 +00:00
|
|
|
|
|
|
|
|
/* Other stuff */
|
|
|
|
|
|
|
|
|
|
order = gncEntryGetOrder (entry);
|
|
|
|
|
if (order)
|
2010-03-02 21:41:05 +00:00
|
|
|
xmlAddChild (ret, guid_to_dom_tree (entry_order_string,
|
|
|
|
|
qof_instance_get_guid(QOF_INSTANCE (order))));
|
2002-09-14 05:32:37 +00:00
|
|
|
|
2002-03-04 19:34:52 +00:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
|
|
struct entry_pdata
|
|
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
GncEntry *entry;
|
|
|
|
|
QofBook *book;
|
|
|
|
|
Account *acc;
|
2002-03-04 19:34:52 +00:00
|
|
|
};
|
|
|
|
|
|
2003-09-01 15:09:25 +00:00
|
|
|
static inline gboolean
|
2002-03-04 19:34:52 +00:00
|
|
|
set_string(xmlNodePtr node, GncEntry* entry,
|
|
|
|
|
void (*func)(GncEntry *entry, const char *txt))
|
|
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
char* txt = dom_tree_to_text(node);
|
|
|
|
|
g_return_val_if_fail(txt, FALSE);
|
|
|
|
|
|
|
|
|
|
func(entry, txt);
|
|
|
|
|
g_free(txt);
|
|
|
|
|
return TRUE;
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
2003-09-01 15:09:25 +00:00
|
|
|
static inline gboolean
|
2002-03-04 19:34:52 +00:00
|
|
|
set_timespec(xmlNodePtr node, GncEntry* entry,
|
2010-03-02 21:41:05 +00:00
|
|
|
void (*func)(GncEntry *entry, Timespec ts))
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
Timespec ts = dom_tree_to_timespec (node);
|
|
|
|
|
if (!dom_tree_valid_timespec(&ts, node->name)) return FALSE;
|
|
|
|
|
|
|
|
|
|
func(entry, ts);
|
|
|
|
|
return TRUE;
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
2003-09-01 15:09:25 +00:00
|
|
|
static inline gboolean
|
2002-03-04 19:34:52 +00:00
|
|
|
set_numeric(xmlNodePtr node, GncEntry* entry,
|
2010-03-02 21:41:05 +00:00
|
|
|
void (*func)(GncEntry *entry, gnc_numeric num))
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
gnc_numeric* num = dom_tree_to_gnc_numeric(node);
|
|
|
|
|
g_return_val_if_fail(num, FALSE);
|
|
|
|
|
|
|
|
|
|
func(entry, *num);
|
|
|
|
|
g_free(num);
|
|
|
|
|
return TRUE;
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
2003-09-01 15:09:25 +00:00
|
|
|
static inline gboolean
|
2002-07-10 17:32:59 +00:00
|
|
|
set_boolean(xmlNodePtr node, GncEntry* entry,
|
2010-03-02 21:41:05 +00:00
|
|
|
void (*func)(GncEntry *entry, gboolean val))
|
2002-07-10 17:32:59 +00:00
|
|
|
{
|
|
|
|
|
gint64 val;
|
|
|
|
|
|
|
|
|
|
if (!dom_tree_to_integer(node, &val))
|
2010-03-02 21:41:05 +00:00
|
|
|
return FALSE;
|
2002-07-10 17:32:59 +00:00
|
|
|
func (entry, (gboolean)val);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-01 15:09:25 +00:00
|
|
|
static inline gboolean
|
2002-07-11 15:11:33 +00:00
|
|
|
set_account(xmlNodePtr node, struct entry_pdata *pdata,
|
2010-03-02 21:41:05 +00:00
|
|
|
void (*func)(GncEntry *entry, Account *acc))
|
2002-07-11 15:11:33 +00:00
|
|
|
{
|
2010-03-27 21:01:21 +00:00
|
|
|
GncGUID *guid;
|
2002-07-11 15:11:33 +00:00
|
|
|
Account * acc;
|
|
|
|
|
|
|
|
|
|
guid = dom_tree_to_guid (node);
|
|
|
|
|
g_return_val_if_fail (guid, FALSE);
|
|
|
|
|
acc = xaccAccountLookup (guid, pdata->book);
|
|
|
|
|
g_free (guid);
|
|
|
|
|
g_return_val_if_fail (acc, FALSE);
|
|
|
|
|
|
|
|
|
|
if (func)
|
2010-03-02 21:41:05 +00:00
|
|
|
func (pdata->entry, acc);
|
2002-07-11 15:11:33 +00:00
|
|
|
else
|
2010-03-02 21:41:05 +00:00
|
|
|
pdata->acc = acc;
|
2002-07-11 15:11:33 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-01 15:09:25 +00:00
|
|
|
static inline gboolean
|
2002-09-14 05:32:37 +00:00
|
|
|
set_taxtable (xmlNodePtr node, struct entry_pdata *pdata,
|
2010-03-02 21:41:05 +00:00
|
|
|
void (*func)(GncEntry *entry, GncTaxTable *taxtable))
|
2002-09-14 05:32:37 +00:00
|
|
|
{
|
2010-03-27 21:01:21 +00:00
|
|
|
GncGUID *guid;
|
2002-09-14 05:32:37 +00:00
|
|
|
GncTaxTable *taxtable;
|
|
|
|
|
|
|
|
|
|
guid = dom_tree_to_guid (node);
|
|
|
|
|
g_return_val_if_fail (guid, FALSE);
|
|
|
|
|
taxtable = gncTaxTableLookup (pdata->book, guid);
|
2010-03-02 21:41:05 +00:00
|
|
|
if (!taxtable)
|
|
|
|
|
{
|
|
|
|
|
taxtable = gncTaxTableCreate (pdata->book);
|
|
|
|
|
gncTaxTableBeginEdit (taxtable);
|
|
|
|
|
gncTaxTableSetGUID (taxtable, guid);
|
|
|
|
|
gncTaxTableCommitEdit (taxtable);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
gncTaxTableDecRef (taxtable);
|
2002-09-14 05:32:37 +00:00
|
|
|
|
|
|
|
|
func (pdata->entry, taxtable);
|
|
|
|
|
g_free(guid);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-04 19:34:52 +00:00
|
|
|
static gboolean
|
|
|
|
|
entry_guid_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
2010-03-27 21:01:21 +00:00
|
|
|
GncGUID *guid;
|
2002-03-04 19:34:52 +00:00
|
|
|
GncEntry *entry;
|
|
|
|
|
|
|
|
|
|
guid = dom_tree_to_guid(node);
|
|
|
|
|
g_return_val_if_fail (guid, FALSE);
|
|
|
|
|
entry = gncEntryLookup (pdata->book, guid);
|
2010-03-02 21:41:05 +00:00
|
|
|
if (entry)
|
|
|
|
|
{
|
|
|
|
|
gncEntryDestroy (pdata->entry);
|
|
|
|
|
pdata->entry = entry;
|
|
|
|
|
gncEntryBeginEdit (entry);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gncEntrySetGUID(pdata->entry, guid);
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free(guid);
|
2010-03-02 21:41:05 +00:00
|
|
|
|
2002-03-04 19:34:52 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
entry_date_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
|
|
|
|
|
|
|
|
|
return set_timespec(node, pdata->entry, gncEntrySetDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
entry_dateentered_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
|
|
|
|
|
|
|
|
|
return set_timespec(node, pdata->entry, gncEntrySetDateEntered);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
entry_description_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
|
|
|
|
|
|
|
|
|
return set_string(node, pdata->entry, gncEntrySetDescription);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
entry_action_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
|
|
|
|
|
|
|
|
|
return set_string(node, pdata->entry, gncEntrySetAction);
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-17 04:04:05 +00:00
|
|
|
static gboolean
|
|
|
|
|
entry_notes_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
|
|
|
|
|
|
|
|
|
return set_string(node, pdata->entry, gncEntrySetNotes);
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-04 19:34:52 +00:00
|
|
|
static gboolean
|
|
|
|
|
entry_qty_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
|
|
|
|
|
|
|
|
|
return set_numeric(node, pdata->entry, gncEntrySetQuantity);
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
/* Cust invoice */
|
|
|
|
|
|
2002-03-04 19:34:52 +00:00
|
|
|
static gboolean
|
2002-09-14 05:32:37 +00:00
|
|
|
entry_invacct_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
|
|
|
|
return set_account (node, pdata, gncEntrySetInvAccount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
entry_iprice_handler (xmlNodePtr node, gpointer entry_pdata)
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
|
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
return set_numeric(node, pdata->entry, gncEntrySetInvPrice);
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2002-09-14 05:32:37 +00:00
|
|
|
entry_idiscount_handler (xmlNodePtr node, gpointer entry_pdata)
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
|
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
return set_numeric(node, pdata->entry, gncEntrySetInvDiscount);
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2002-09-14 05:32:37 +00:00
|
|
|
entry_idisctype_handler (xmlNodePtr node, gpointer entry_pdata)
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
2002-07-01 18:31:48 +00:00
|
|
|
GncAmountType type;
|
|
|
|
|
char *str;
|
|
|
|
|
gboolean ret;
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2002-07-01 18:31:48 +00:00
|
|
|
str = dom_tree_to_text (node);
|
|
|
|
|
g_return_val_if_fail (str, FALSE);
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2002-07-01 18:31:48 +00:00
|
|
|
ret = gncAmountStringToType (str, &type);
|
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
|
|
if (ret)
|
2010-03-02 21:41:05 +00:00
|
|
|
gncEntrySetInvDiscountType(pdata->entry, type);
|
2002-07-01 18:31:48 +00:00
|
|
|
|
|
|
|
|
return ret;
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2002-09-14 05:32:37 +00:00
|
|
|
entry_idischow_handler (xmlNodePtr node, gpointer entry_pdata)
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
2002-07-01 18:31:48 +00:00
|
|
|
GncDiscountHow how;
|
|
|
|
|
char *str;
|
|
|
|
|
gboolean ret;
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2002-07-01 18:31:48 +00:00
|
|
|
str = dom_tree_to_text (node);
|
|
|
|
|
g_return_val_if_fail (str, FALSE);
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2002-07-01 18:31:48 +00:00
|
|
|
ret = gncEntryDiscountStringToHow (str, &how);
|
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
|
|
if (ret)
|
2010-03-02 21:41:05 +00:00
|
|
|
gncEntrySetInvDiscountHow(pdata->entry, how);
|
2002-07-01 18:31:48 +00:00
|
|
|
|
|
|
|
|
return ret;
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2002-09-14 05:32:37 +00:00
|
|
|
entry_itaxable_handler (xmlNodePtr node, gpointer entry_pdata)
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
2002-09-14 05:32:37 +00:00
|
|
|
return set_boolean (node, pdata->entry, gncEntrySetInvTaxable);
|
|
|
|
|
}
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
static gboolean
|
|
|
|
|
entry_itaxincluded_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
|
|
|
|
return set_boolean (node, pdata->entry, gncEntrySetInvTaxIncluded);
|
2002-07-11 15:11:33 +00:00
|
|
|
}
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2002-07-11 15:11:33 +00:00
|
|
|
static gboolean
|
2002-09-14 05:32:37 +00:00
|
|
|
entry_itaxtable_handler (xmlNodePtr node, gpointer entry_pdata)
|
2002-07-11 15:11:33 +00:00
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
2002-09-14 05:32:37 +00:00
|
|
|
return set_taxtable (node, pdata, gncEntrySetInvTaxTable);
|
2002-07-11 15:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
/* vendor bills */
|
|
|
|
|
|
2002-07-11 15:11:33 +00:00
|
|
|
static gboolean
|
|
|
|
|
entry_billacct_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
|
|
|
|
return set_account (node, pdata, gncEntrySetBillAccount);
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2002-09-14 05:32:37 +00:00
|
|
|
entry_bprice_handler (xmlNodePtr node, gpointer entry_pdata)
|
2002-06-16 05:11:33 +00:00
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
2002-09-14 05:32:37 +00:00
|
|
|
|
|
|
|
|
return set_numeric(node, pdata->entry, gncEntrySetBillPrice);
|
2002-06-16 05:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2002-09-14 05:32:37 +00:00
|
|
|
entry_btaxable_handler (xmlNodePtr node, gpointer entry_pdata)
|
2002-06-16 05:11:33 +00:00
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
2002-09-14 05:32:37 +00:00
|
|
|
return set_boolean (node, pdata->entry, gncEntrySetBillTaxable);
|
2002-06-16 05:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2002-09-14 05:32:37 +00:00
|
|
|
entry_btaxincluded_handler (xmlNodePtr node, gpointer entry_pdata)
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
2002-09-14 05:32:37 +00:00
|
|
|
return set_boolean (node, pdata->entry, gncEntrySetBillTaxIncluded);
|
|
|
|
|
}
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
static gboolean
|
|
|
|
|
entry_btaxtable_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
|
|
|
|
return set_taxtable (node, pdata, gncEntrySetBillTaxTable);
|
|
|
|
|
}
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
static gboolean
|
|
|
|
|
entry_billable_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
|
|
|
|
return set_boolean (node, pdata->entry, gncEntrySetBillable);
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
static gboolean
|
|
|
|
|
entry_billto_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
|
|
|
|
GncOwner billto;
|
|
|
|
|
gboolean ret;
|
2002-09-14 05:32:37 +00:00
|
|
|
|
2010-03-02 21:41:05 +00:00
|
|
|
ret = gnc_dom_tree_to_owner (node, &billto, pdata->book);
|
|
|
|
|
if (ret)
|
|
|
|
|
gncEntrySetBillTo (pdata->entry, &billto);
|
2002-09-14 05:32:37 +00:00
|
|
|
|
2010-03-02 21:41:05 +00:00
|
|
|
return ret;
|
2002-09-14 05:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-03 04:58:55 +00:00
|
|
|
/* employee bills */
|
|
|
|
|
static gboolean
|
|
|
|
|
entry_billpayment_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
|
|
|
|
GncEntryPaymentType type;
|
|
|
|
|
char *str;
|
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
|
|
str = dom_tree_to_text (node);
|
|
|
|
|
g_return_val_if_fail (str, FALSE);
|
|
|
|
|
|
|
|
|
|
ret = gncEntryPaymentStringToType (str, &type);
|
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
|
|
if (ret)
|
2010-03-02 21:41:05 +00:00
|
|
|
gncEntrySetBillPayment(pdata->entry, type);
|
2003-03-03 04:58:55 +00:00
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
/* The rest of the stuff */
|
|
|
|
|
|
2002-03-04 19:34:52 +00:00
|
|
|
static gboolean
|
|
|
|
|
entry_order_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
2010-03-27 21:01:21 +00:00
|
|
|
GncGUID *guid;
|
2002-03-04 19:34:52 +00:00
|
|
|
GncOrder *order;
|
|
|
|
|
|
|
|
|
|
guid = dom_tree_to_guid (node);
|
|
|
|
|
g_return_val_if_fail (guid, FALSE);
|
|
|
|
|
order = gncOrderLookup (pdata->book, guid);
|
2010-03-02 21:41:05 +00:00
|
|
|
if (!order)
|
|
|
|
|
{
|
|
|
|
|
order = gncOrderCreate (pdata->book);
|
|
|
|
|
gncOrderBeginEdit (order);
|
|
|
|
|
gncOrderSetGUID (order, guid);
|
|
|
|
|
gncOrderCommitEdit (order);
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
2002-11-03 20:21:42 +00:00
|
|
|
gncOrderBeginEdit (order);
|
2002-03-04 19:34:52 +00:00
|
|
|
gncOrderAddEntry (order, pdata->entry);
|
2002-06-21 19:00:34 +00:00
|
|
|
gncOrderCommitEdit (order);
|
2002-03-04 19:34:52 +00:00
|
|
|
|
|
|
|
|
g_free(guid);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
entry_invoice_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
2010-03-27 21:01:21 +00:00
|
|
|
GncGUID *guid;
|
2002-03-04 19:34:52 +00:00
|
|
|
GncInvoice *invoice;
|
|
|
|
|
|
|
|
|
|
guid = dom_tree_to_guid (node);
|
|
|
|
|
g_return_val_if_fail (guid, FALSE);
|
|
|
|
|
invoice = gncInvoiceLookup (pdata->book, guid);
|
2010-03-02 21:41:05 +00:00
|
|
|
if (!invoice)
|
|
|
|
|
{
|
|
|
|
|
invoice = gncInvoiceCreate (pdata->book);
|
|
|
|
|
gncInvoiceBeginEdit (invoice);
|
|
|
|
|
gncInvoiceSetGUID (invoice, guid);
|
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
2002-11-03 20:21:42 +00:00
|
|
|
gncInvoiceBeginEdit (invoice);
|
2002-03-04 19:34:52 +00:00
|
|
|
gncInvoiceAddEntry (invoice, pdata->entry);
|
2002-06-21 19:00:34 +00:00
|
|
|
gncInvoiceCommitEdit (invoice);
|
2002-03-04 19:34:52 +00:00
|
|
|
|
|
|
|
|
g_free(guid);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-10 04:12:19 +00:00
|
|
|
static gboolean
|
|
|
|
|
entry_bill_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
2010-03-27 21:01:21 +00:00
|
|
|
GncGUID *guid;
|
2002-07-10 04:12:19 +00:00
|
|
|
GncInvoice *invoice;
|
|
|
|
|
|
|
|
|
|
guid = dom_tree_to_guid (node);
|
|
|
|
|
g_return_val_if_fail (guid, FALSE);
|
|
|
|
|
invoice = gncInvoiceLookup (pdata->book, guid);
|
2010-03-02 21:41:05 +00:00
|
|
|
if (!invoice)
|
|
|
|
|
{
|
|
|
|
|
invoice = gncInvoiceCreate (pdata->book);
|
|
|
|
|
gncInvoiceBeginEdit (invoice);
|
|
|
|
|
gncInvoiceSetGUID (invoice, guid);
|
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2002-07-10 04:12:19 +00:00
|
|
|
}
|
2002-11-03 20:21:42 +00:00
|
|
|
gncInvoiceBeginEdit (invoice);
|
2002-07-10 04:12:19 +00:00
|
|
|
gncBillAddEntry (invoice, pdata->entry);
|
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
|
|
|
|
|
|
|
|
|
g_free(guid);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
/* Support for older XML versions */
|
|
|
|
|
|
2002-07-10 17:32:59 +00:00
|
|
|
static gboolean
|
2002-09-14 05:32:37 +00:00
|
|
|
entry_acct_handler (xmlNodePtr node, gpointer entry_pdata)
|
2002-07-10 17:32:59 +00:00
|
|
|
{
|
|
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
2002-09-14 05:32:37 +00:00
|
|
|
/* XXX: try to figure out if this is an 'invoice' or a 'bill' --
|
|
|
|
|
* we have to wait until the end!
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
return set_account (node, pdata, NULL);
|
2002-07-10 17:32:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2002-09-14 05:32:37 +00:00
|
|
|
entry_price_handler (xmlNodePtr node, gpointer entry_pdata)
|
2002-07-10 17:32:59 +00:00
|
|
|
{
|
2002-09-14 05:32:37 +00:00
|
|
|
struct entry_pdata *pdata = entry_pdata;
|
|
|
|
|
gboolean res;
|
2002-07-10 17:32:59 +00:00
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
/* just set both.. Don't worry about extra data if it's wrong */
|
|
|
|
|
res = set_numeric(node, pdata->entry, gncEntrySetInvPrice);
|
|
|
|
|
if (res)
|
2010-03-02 21:41:05 +00:00
|
|
|
gncEntrySetBillPrice (pdata->entry, gncEntryGetInvPrice (pdata->entry));
|
2002-09-14 05:32:37 +00:00
|
|
|
return res;
|
2002-07-10 17:32:59 +00:00
|
|
|
}
|
|
|
|
|
|
2003-09-11 17:37:01 +00:00
|
|
|
static gboolean
|
|
|
|
|
entry_slots_handler (xmlNodePtr node, gpointer entry_pdata)
|
|
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
return TRUE;
|
2003-09-11 17:37:01 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-02 21:41:05 +00:00
|
|
|
static struct dom_tree_handler entry_handlers_v2[] =
|
|
|
|
|
{
|
2002-03-04 19:34:52 +00:00
|
|
|
{ entry_guid_string, entry_guid_handler, 1, 0 },
|
|
|
|
|
{ entry_date_string, entry_date_handler, 1, 0 },
|
|
|
|
|
{ entry_dateentered_string, entry_dateentered_handler, 1, 0 },
|
|
|
|
|
{ entry_description_string, entry_description_handler, 0, 0 },
|
|
|
|
|
{ entry_action_string, entry_action_handler, 0, 0 },
|
2002-06-17 04:04:05 +00:00
|
|
|
{ entry_notes_string, entry_notes_handler, 0, 0 },
|
2002-03-04 19:34:52 +00:00
|
|
|
{ entry_qty_string, entry_qty_handler, 0, 0 },
|
2002-09-14 05:32:37 +00:00
|
|
|
|
|
|
|
|
/* cust invoice */
|
2002-07-11 15:11:33 +00:00
|
|
|
{ entry_invacct_string, entry_invacct_handler, 0, 0 },
|
2002-09-14 05:32:37 +00:00
|
|
|
{ entry_iprice_string, entry_iprice_handler, 0, 0 },
|
|
|
|
|
{ entry_idiscount_string, entry_idiscount_handler, 0, 0 },
|
|
|
|
|
{ entry_idisctype_string, entry_idisctype_handler, 0, 0 },
|
|
|
|
|
{ entry_idischow_string, entry_idischow_handler, 0, 0 },
|
|
|
|
|
{ entry_itaxable_string, entry_itaxable_handler, 0, 0 },
|
|
|
|
|
{ entry_itaxincluded_string, entry_itaxincluded_handler, 0, 0 },
|
|
|
|
|
{ entry_itaxtable_string, entry_itaxtable_handler, 0, 0 },
|
|
|
|
|
|
|
|
|
|
/* vendor invoice */
|
2002-07-11 15:11:33 +00:00
|
|
|
{ entry_billacct_string, entry_billacct_handler, 0, 0 },
|
2002-09-14 05:32:37 +00:00
|
|
|
{ entry_bprice_string, entry_bprice_handler, 0, 0 },
|
|
|
|
|
{ entry_btaxable_string, entry_btaxable_handler, 0, 0 },
|
|
|
|
|
{ entry_btaxincluded_string, entry_btaxincluded_handler, 0, 0 },
|
|
|
|
|
{ entry_btaxtable_string, entry_btaxtable_handler, 0, 0 },
|
|
|
|
|
{ entry_billable_string, entry_billable_handler, 0, 0 },
|
|
|
|
|
{ entry_billto_string, entry_billto_handler, 0, 0 },
|
|
|
|
|
|
2003-03-03 04:58:55 +00:00
|
|
|
/* employee stuff */
|
|
|
|
|
{ entry_billpayment_string, entry_billpayment_handler, 0, 0 },
|
|
|
|
|
|
2002-09-14 05:32:37 +00:00
|
|
|
/* Other stuff */
|
2002-03-04 19:34:52 +00:00
|
|
|
{ entry_order_string, entry_order_handler, 0, 0 },
|
|
|
|
|
{ entry_invoice_string, entry_invoice_handler, 0, 0 },
|
2002-07-10 04:12:19 +00:00
|
|
|
{ entry_bill_string, entry_bill_handler, 0, 0 },
|
2003-09-11 17:37:01 +00:00
|
|
|
{ entry_slots_string, entry_slots_handler, 0, 0 },
|
2002-09-14 05:32:37 +00:00
|
|
|
|
|
|
|
|
/* Old XML support */
|
|
|
|
|
{ "entry:acct", entry_acct_handler, 0, 0 },
|
|
|
|
|
{ "entry:price", entry_price_handler, 0, 0 },
|
|
|
|
|
{ "entry:discount", entry_idiscount_handler, 0, 0 },
|
|
|
|
|
{ "entry:disc-type", entry_idisctype_handler, 0, 0 },
|
|
|
|
|
{ "entry:disc-how", entry_idischow_handler, 0, 0 },
|
|
|
|
|
{ "entry:taxable", entry_itaxable_handler, 0, 0 },
|
|
|
|
|
{ "entry:taxincluded", entry_itaxincluded_handler, 0, 0 },
|
|
|
|
|
{ "entry:taxtable", entry_itaxtable_handler, 0, 0 },
|
2002-03-04 19:34:52 +00:00
|
|
|
{ NULL, 0, 0, 0 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static GncEntry*
|
2005-11-02 03:32:36 +00:00
|
|
|
dom_tree_to_entry (xmlNodePtr node, QofBook *book)
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
|
|
|
|
struct entry_pdata entry_pdata;
|
|
|
|
|
gboolean successful;
|
|
|
|
|
|
2002-06-16 05:11:33 +00:00
|
|
|
entry_pdata.entry = gncEntryCreate(book);
|
2002-03-04 19:34:52 +00:00
|
|
|
entry_pdata.book = book;
|
2002-07-11 15:11:33 +00:00
|
|
|
entry_pdata.acc = NULL;
|
2002-11-03 20:21:42 +00:00
|
|
|
gncEntryBeginEdit (entry_pdata.entry);
|
2002-03-04 19:34:52 +00:00
|
|
|
|
|
|
|
|
successful = dom_tree_generic_parse (node, entry_handlers_v2,
|
|
|
|
|
&entry_pdata);
|
2010-03-02 21:41:05 +00:00
|
|
|
if (entry_pdata.acc != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (gncEntryGetBill (entry_pdata.entry))
|
|
|
|
|
gncEntrySetBillAccount (entry_pdata.entry, entry_pdata.acc);
|
|
|
|
|
else
|
|
|
|
|
gncEntrySetInvAccount (entry_pdata.entry, entry_pdata.acc);
|
2002-07-11 15:11:33 +00:00
|
|
|
}
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2002-11-03 20:21:42 +00:00
|
|
|
if (successful)
|
2010-03-02 21:41:05 +00:00
|
|
|
gncEntryCommitEdit (entry_pdata.entry);
|
2002-11-03 20:21:42 +00:00
|
|
|
else
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
|
|
|
|
PERR ("failed to parse entry tree");
|
2002-06-16 05:11:33 +00:00
|
|
|
gncEntryDestroy (entry_pdata.entry);
|
|
|
|
|
entry_pdata.entry = NULL;
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
2002-06-16 05:11:33 +00:00
|
|
|
return entry_pdata.entry;
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gnc_entry_end_handler(gpointer data_for_children,
|
2010-03-02 21:41:05 +00:00
|
|
|
GSList* data_from_children, GSList* sibling_data,
|
|
|
|
|
gpointer parent_data, gpointer global_data,
|
|
|
|
|
gpointer *result, const gchar *tag)
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
|
|
|
|
GncEntry *entry;
|
|
|
|
|
xmlNodePtr tree = (xmlNodePtr)data_for_children;
|
|
|
|
|
gxpf_data *gdata = (gxpf_data*)global_data;
|
2005-11-02 03:32:36 +00:00
|
|
|
QofBook *book = gdata->bookdata;
|
2002-03-04 19:34:52 +00:00
|
|
|
|
|
|
|
|
|
2010-03-02 21:41:05 +00:00
|
|
|
if (parent_data)
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* OK. For some messed up reason this is getting called again with a
|
|
|
|
|
NULL tag. So we ignore those cases */
|
2010-03-02 21:41:05 +00:00
|
|
|
if (!tag)
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail(tree, FALSE);
|
|
|
|
|
|
|
|
|
|
entry = dom_tree_to_entry(tree, book);
|
2010-03-02 21:41:05 +00:00
|
|
|
if (entry != NULL)
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
|
|
|
|
gdata->cb(tag, gdata->parsedata, entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xmlFreeNode(tree);
|
|
|
|
|
|
|
|
|
|
return entry != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static sixtp *
|
|
|
|
|
entry_sixtp_parser_create(void)
|
|
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
return sixtp_dom_parser_new(gnc_entry_end_handler, NULL, NULL);
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2007-04-01 22:18:50 +00:00
|
|
|
do_count (QofInstance * entry_p, gpointer count_p)
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
int *count = count_p;
|
|
|
|
|
(*count)++;
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2005-11-02 03:32:36 +00:00
|
|
|
entry_get_count (QofBook *book)
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
int count = 0;
|
|
|
|
|
qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
|
|
|
|
return count;
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2007-04-01 22:18:50 +00:00
|
|
|
xml_add_entry (QofInstance * entry_p, gpointer out_p)
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
xmlNodePtr node;
|
|
|
|
|
GncEntry *entry = (GncEntry *) entry_p;
|
|
|
|
|
FILE *out = out_p;
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2010-03-02 21:41:05 +00:00
|
|
|
if (ferror(out))
|
|
|
|
|
return;
|
2010-01-31 18:37:28 +00:00
|
|
|
|
2010-03-02 21:41:05 +00:00
|
|
|
/* Don't save non-attached entries! */
|
|
|
|
|
if (!(gncEntryGetOrder (entry) || gncEntryGetInvoice (entry) ||
|
|
|
|
|
gncEntryGetBill (entry)))
|
|
|
|
|
return;
|
2002-03-04 19:34:52 +00:00
|
|
|
|
2010-03-02 21:41:05 +00:00
|
|
|
node = entry_dom_tree_create (entry);
|
|
|
|
|
xmlElemDump(out, NULL, node);
|
|
|
|
|
xmlFreeNode (node);
|
|
|
|
|
if (ferror(out) || fprintf(out, "\n") < 0)
|
|
|
|
|
return;
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-31 18:37:28 +00:00
|
|
|
static gboolean
|
2005-11-02 03:32:36 +00:00
|
|
|
entry_write (FILE *out, QofBook *book)
|
2002-03-04 19:34:52 +00:00
|
|
|
{
|
2011-01-11 20:40:19 +00:00
|
|
|
qof_object_foreach_sorted (_GNC_MOD_NAME, book, xml_add_entry, (gpointer) out);
|
2010-03-02 21:41:05 +00:00
|
|
|
return ferror(out) == 0;
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-31 18:37:28 +00:00
|
|
|
static gboolean
|
2005-11-02 03:32:36 +00:00
|
|
|
entry_ns(FILE *out)
|
|
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
g_return_val_if_fail(out, FALSE);
|
|
|
|
|
return gnc_xml2_write_namespace_decl(out, "entry");
|
2005-11-02 03:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
2002-03-04 19:34:52 +00:00
|
|
|
void
|
|
|
|
|
gnc_entry_xml_initialize (void)
|
|
|
|
|
{
|
2010-03-02 21:41:05 +00:00
|
|
|
static GncXmlDataType_t be_data =
|
|
|
|
|
{
|
|
|
|
|
GNC_FILE_BACKEND_VERS,
|
|
|
|
|
gnc_entry_string,
|
|
|
|
|
entry_sixtp_parser_create,
|
|
|
|
|
NULL, /* add_item */
|
|
|
|
|
entry_get_count,
|
|
|
|
|
entry_write,
|
|
|
|
|
NULL, /* scrub */
|
|
|
|
|
entry_ns,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
qof_object_register_backend (_GNC_MOD_NAME,
|
|
|
|
|
GNC_FILE_BACKEND,
|
|
|
|
|
&be_data);
|
2002-03-04 19:34:52 +00:00
|
|
|
}
|